pulumi/sdk/nodejs/runtime/state.ts

354 lines
10 KiB
TypeScript
Raw Permalink Normal View History

// Copyright 2016-2022, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { AsyncLocalStorage } from "async_hooks";
NodeJS transforms (#15532) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> This adds a new experimental feature to the NodeJS SDK to register remote transform functions. These are currently all prefixed 'X' to show they're experimental. These transform functions will run even for resources created inside MLCs. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-07 08:52:34 +00:00
import { ICallbackServer } from "./callbacks";
import * as config from "./config";
import { Stack } from "./stack";
import * as engrpc from "../proto/engine_grpc_pb";
import * as resrpc from "../proto/resource_grpc_pb";
import type { ResourceModule, ResourcePackage } from "./rpc";
const nodeEnvKeys = {
project: "PULUMI_NODEJS_PROJECT",
stack: "PULUMI_NODEJS_STACK",
dryRun: "PULUMI_NODEJS_DRY_RUN",
queryMode: "PULUMI_NODEJS_QUERY_MODE",
parallel: "PULUMI_NODEJS_PARALLEL",
monitorAddr: "PULUMI_NODEJS_MONITOR",
engineAddr: "PULUMI_NODEJS_ENGINE",
syncDir: "PULUMI_NODEJS_SYNC",
// Unlike the values above, this value is not set by the CLI and is
// controlled via a user-set environment variable.
cacheDynamicProviders: "PULUMI_NODEJS_CACHE_DYNAMIC_PROVIDERS",
organization: "PULUMI_NODEJS_ORGANIZATION",
};
const pulumiEnvKeys = {
legacyApply: "PULUMI_ENABLE_LEGACY_APPLY",
};
/**
* @internal
*/
export const asyncLocalStorage = new AsyncLocalStorage<Store>();
/**
* @internal
*/
export interface WriteableOptions {
/**
* The name of the current project.
*/
project?: string;
/**
* The name of the current stack being deployed into.
*/
stack?: string;
/**
* The degree of parallelism for resource operations (default is serial).
*/
parallel?: number;
/**
* A connection string to the engine's RPC, in case we need to reestablish.
*/
engineAddr?: string;
/**
* A connection string to the monitor's RPC, in case we need to reestablish.
*/
monitorAddr?: string;
/**
* Whether we are performing a preview (true) or a real deployment (false).
*/
dryRun?: boolean;
/**
* True if we're in testing mode (allows execution without the CLI).
*/
testModeEnabled?: boolean;
/**
* True if we're in query mode (does not allow resource registration).
*/
queryMode?: boolean;
/**
* True if we will resolve missing outputs to inputs during preview.
*/
legacyApply?: boolean;
/**
* True if we will cache serialized dynamic providers on the program side.
*/
cacheDynamicProviders?: boolean;
/**
* The name of the current organization (if available).
*/
organization?: string;
/**
* The number of process listeners which can be registered before writing a
* warning.
*/
maximumProcessListeners: number;
/**
* A directory containing the send/receive files for making synchronous
* invokes to the engine.
*/
syncDir?: string;
}
/**
* @internal
*/
export interface Store {
settings: {
options: WriteableOptions;
Move nodejs feature checks to startup (#14856) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> We need to synchronously check for transform support in `registerStackTransformation` and resource constructors when adding remote transform support to node (c.f. https://github.com/pulumi/pulumi/pull/14303). This change changes all the feature checks to be done at startup and then accessed via just a field lookup. Adding the "transform" feature to this set is clearly simple. Sadly there's no single entry point to make these changes in. So we need to update entry point of construct/call, the entry point of programs, and test setup. Miss any one of these and current tests start failing. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-12-19 14:35:23 +00:00
monitor?: resrpc.IResourceMonitorClient;
engine?: engrpc.IEngineClient;
rpcDone: Promise<any>;
Move nodejs feature checks to startup (#14856) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> We need to synchronously check for transform support in `registerStackTransformation` and resource constructors when adding remote transform support to node (c.f. https://github.com/pulumi/pulumi/pull/14303). This change changes all the feature checks to be done at startup and then accessed via just a field lookup. Adding the "transform" feature to this set is clearly simple. Sadly there's no single entry point to make these changes in. So we need to update entry point of construct/call, the entry point of programs, and test setup. Miss any one of these and current tests start failing. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-12-19 14:35:23 +00:00
// Needed for legacy @pulumi/pulumi packages doing async feature checks.
featureSupport: Record<string, boolean>;
};
config: Record<string, string>;
stackResource?: Stack;
leakCandidates: Set<Promise<any>>;
Recover after a failed automatation run (#14702) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Fixes #12521 The log module for the nodejs SDK keeps track of an error count in a global, this should be stored in the stack's local store. ## Checklist - [ ] I have run `make tidy` to update any new dependencies - [ ] I have run `make lint` to verify my code passes the lint check - [ ] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-12-01 17:35:07 +00:00
logErrorCount: number;
Move nodejs feature checks to startup (#14856) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> We need to synchronously check for transform support in `registerStackTransformation` and resource constructors when adding remote transform support to node (c.f. https://github.com/pulumi/pulumi/pull/14303). This change changes all the feature checks to be done at startup and then accessed via just a field lookup. Adding the "transform" feature to this set is clearly simple. Sadly there's no single entry point to make these changes in. So we need to update entry point of construct/call, the entry point of programs, and test setup. Miss any one of these and current tests start failing. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-12-19 14:35:23 +00:00
/**
* Tells us if the resource monitor we are connected to is able to support
* secrets across its RPC interface. When it does, we marshal outputs marked
* with the secret bit in a special way.
Move nodejs feature checks to startup (#14856) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> We need to synchronously check for transform support in `registerStackTransformation` and resource constructors when adding remote transform support to node (c.f. https://github.com/pulumi/pulumi/pull/14303). This change changes all the feature checks to be done at startup and then accessed via just a field lookup. Adding the "transform" feature to this set is clearly simple. Sadly there's no single entry point to make these changes in. So we need to update entry point of construct/call, the entry point of programs, and test setup. Miss any one of these and current tests start failing. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-12-19 14:35:23 +00:00
*/
supportsSecrets: boolean;
/**
* Tells us if the resource monitor we are connected to is able to support
* resource references across its RPC interface. When it does, we marshal
* resources in a special way.
Move nodejs feature checks to startup (#14856) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> We need to synchronously check for transform support in `registerStackTransformation` and resource constructors when adding remote transform support to node (c.f. https://github.com/pulumi/pulumi/pull/14303). This change changes all the feature checks to be done at startup and then accessed via just a field lookup. Adding the "transform" feature to this set is clearly simple. Sadly there's no single entry point to make these changes in. So we need to update entry point of construct/call, the entry point of programs, and test setup. Miss any one of these and current tests start failing. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-12-19 14:35:23 +00:00
*/
supportsResourceReferences: boolean;
/**
* Tells u if the resource monitor we are connected to is able to support
* output values across its RPC interface. When it does, we marshal outputs
Move nodejs feature checks to startup (#14856) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> We need to synchronously check for transform support in `registerStackTransformation` and resource constructors when adding remote transform support to node (c.f. https://github.com/pulumi/pulumi/pull/14303). This change changes all the feature checks to be done at startup and then accessed via just a field lookup. Adding the "transform" feature to this set is clearly simple. Sadly there's no single entry point to make these changes in. So we need to update entry point of construct/call, the entry point of programs, and test setup. Miss any one of these and current tests start failing. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-12-19 14:35:23 +00:00
* in a special way.
*/
supportsOutputValues: boolean;
/**
* Tells us if the resource monitor we are connected to is able to support
* the `deletedWith` resource option across its RPC interface.
Move nodejs feature checks to startup (#14856) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> We need to synchronously check for transform support in `registerStackTransformation` and resource constructors when adding remote transform support to node (c.f. https://github.com/pulumi/pulumi/pull/14303). This change changes all the feature checks to be done at startup and then accessed via just a field lookup. Adding the "transform" feature to this set is clearly simple. Sadly there's no single entry point to make these changes in. So we need to update entry point of construct/call, the entry point of programs, and test setup. Miss any one of these and current tests start failing. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-12-19 14:35:23 +00:00
*/
supportsDeletedWith: boolean;
/**
* Tells us if the resource monitor we are connected to is able to support
* alias specs across its RPC interface. When it does, we marshal aliases in
* a special way.
Move nodejs feature checks to startup (#14856) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> We need to synchronously check for transform support in `registerStackTransformation` and resource constructors when adding remote transform support to node (c.f. https://github.com/pulumi/pulumi/pull/14303). This change changes all the feature checks to be done at startup and then accessed via just a field lookup. Adding the "transform" feature to this set is clearly simple. Sadly there's no single entry point to make these changes in. So we need to update entry point of construct/call, the entry point of programs, and test setup. Miss any one of these and current tests start failing. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-12-19 14:35:23 +00:00
*/
supportsAliasSpecs: boolean;
NodeJS transforms (#15532) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> This adds a new experimental feature to the NodeJS SDK to register remote transform functions. These are currently all prefixed 'X' to show they're experimental. These transform functions will run even for resources created inside MLCs. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-07 08:52:34 +00:00
/**
* Tells us if the resource monitor we are connected to is able to support
* remote transforms across its RPC interface. When it does, we marshal
NodeJS transforms (#15532) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> This adds a new experimental feature to the NodeJS SDK to register remote transform functions. These are currently all prefixed 'X' to show they're experimental. These transform functions will run even for resources created inside MLCs. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-07 08:52:34 +00:00
* transforms to the monitor instead of running them locally.
*/
supportsTransforms: boolean;
/**
* Tells us if the resource monitor we are connected to is able to support
* remote invoke transforms across its RPC interface. When it does, we marshal
* transforms to the monitor instead of running them locally.
*/
supportsInvokeTransforms: boolean;
NodeJS transforms (#15532) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> This adds a new experimental feature to the NodeJS SDK to register remote transform functions. These are currently all prefixed 'X' to show they're experimental. These transform functions will run even for resources created inside MLCs. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-07 08:52:34 +00:00
/**
* The callback service running for this deployment. This registers
* callbacks and forwards them to the engine.
NodeJS transforms (#15532) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> This adds a new experimental feature to the NodeJS SDK to register remote transform functions. These are currently all prefixed 'X' to show they're experimental. These transform functions will run even for resources created inside MLCs. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-07 08:52:34 +00:00
*/
callbacks?: ICallbackServer;
/**
* Tracks the list of resource packages that have been registered.
*/
resourcePackages: Map<string, ResourcePackage[]>;
/**
* Tracks the list of resource modules that have been registered.
*/
resourceModules: Map<string, ResourceModule[]>;
}
/**
* @internal
*/
export class LocalStore implements Store {
settings = {
options: {
organization: process.env[nodeEnvKeys.organization],
project: process.env[nodeEnvKeys.project] || "project",
stack: process.env[nodeEnvKeys.stack] || "stack",
dryRun: process.env[nodeEnvKeys.dryRun] === "true",
queryMode: process.env[nodeEnvKeys.queryMode] === "true",
monitorAddr: process.env[nodeEnvKeys.monitorAddr],
engineAddr: process.env[nodeEnvKeys.engineAddr],
syncDir: process.env[nodeEnvKeys.syncDir],
cacheDynamicProviders: process.env[nodeEnvKeys.cacheDynamicProviders] !== "false",
legacyApply: process.env[pulumiEnvKeys.legacyApply] === "true",
maximumProcessListeners: 30,
},
rpcDone: Promise.resolve(),
featureSupport: {},
};
config = {
[config.configEnvKey]: process.env[config.configEnvKey] || "",
[config.configSecretKeysEnvKey]: process.env[config.configSecretKeysEnvKey] || "",
};
stackResource = undefined;
/**
* Tracks the list of potential leak candidates.
*/
leakCandidates = new Set<Promise<any>>();
Recover after a failed automatation run (#14702) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Fixes #12521 The log module for the nodejs SDK keeps track of an error count in a global, this should be stored in the stack's local store. ## Checklist - [ ] I have run `make tidy` to update any new dependencies - [ ] I have run `make lint` to verify my code passes the lint check - [ ] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-12-01 17:35:07 +00:00
logErrorCount = 0;
Move nodejs feature checks to startup (#14856) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> We need to synchronously check for transform support in `registerStackTransformation` and resource constructors when adding remote transform support to node (c.f. https://github.com/pulumi/pulumi/pull/14303). This change changes all the feature checks to be done at startup and then accessed via just a field lookup. Adding the "transform" feature to this set is clearly simple. Sadly there's no single entry point to make these changes in. So we need to update entry point of construct/call, the entry point of programs, and test setup. Miss any one of these and current tests start failing. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-12-19 14:35:23 +00:00
supportsSecrets = false;
supportsResourceReferences = false;
supportsOutputValues = false;
supportsDeletedWith = false;
supportsAliasSpecs = false;
NodeJS transforms (#15532) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> This adds a new experimental feature to the NodeJS SDK to register remote transform functions. These are currently all prefixed 'X' to show they're experimental. These transform functions will run even for resources created inside MLCs. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-07 08:52:34 +00:00
supportsTransforms = false;
supportsInvokeTransforms = false;
resourcePackages = new Map<string, ResourcePackage[]>();
resourceModules = new Map<string, ResourceModule[]>();
}
/**
* Get the root stack resource for the current stack deployment.
*
* @internal
*/
export function getStackResource(): Stack | undefined {
const { stackResource } = getStore();
return stackResource;
}
/**
* Get the resource package map for the current stack deployment.
*
* @internal
*/
export function getResourcePackages(): Map<string, ResourcePackage[]> {
const store = getGlobalStore();
if (store.resourcePackages === undefined) {
// resourcePackages can be undefined if an older SDK where it was not defined is created it.
// In this case, we should initialize it to an empty map.
store.resourcePackages = new Map<string, ResourcePackage[]>();
}
return store.resourcePackages;
}
/**
* Get the resource module map for the current stack deployment.
*
* @internal
*/
export function getResourceModules(): Map<string, ResourceModule[]> {
const store = getGlobalStore();
if (store.resourceModules === undefined) {
// resourceModules can be undefined if an older SDK where it was not defined is created it.
// In this case, we should initialize it to an empty map.
store.resourceModules = new Map<string, ResourceModule[]>();
}
return store.resourceModules;
}
/**
* @internal
*/
export function setStackResource(newStackResource?: Stack) {
const localStore = getStore();
globalThis.stackResource = newStackResource;
localStore.stackResource = newStackResource;
}
declare global {
/* eslint-disable no-var */
var globalStore: Store;
var stackResource: Stack | undefined;
}
/**
* @internal
*/
export function getLocalStore(): Store | undefined {
return asyncLocalStorage.getStore();
}
(<any>getLocalStore).captureReplacement = () => {
const returnFunc = () => {
if (global.globalStore === undefined) {
global.globalStore = new LocalStore();
}
return global.globalStore;
};
return returnFunc;
};
/**
* @internal
*/
export const getStore = () => {
const localStore = getLocalStore();
if (localStore === undefined) {
if (global.globalStore === undefined) {
global.globalStore = new LocalStore();
}
return global.globalStore;
}
return localStore;
};
(<any>getStore).captureReplacement = () => {
const returnFunc = () => {
if (global.globalStore === undefined) {
global.globalStore = new LocalStore();
}
return global.globalStore;
};
return returnFunc;
};
/**
* @internal
*/
export const getGlobalStore = () => {
if (global.globalStore === undefined) {
global.globalStore = new LocalStore();
}
return global.globalStore;
};