Commit Graph

61 Commits

Author SHA1 Message Date
Will Jones 26ff81961b
Improve TypeDocs for `sdk/nodejs/runtime` ()
This commit improves the TypeScript TypeDocs for `runtime` modules in
the NodeJS SDK. Specifically:

* It adds documentation to interfaces, properties, etc. that are missing
it.

* It transforms would-be TypeDoc comments erroneously written using
either `/*` (a single asterisk) or `//` (a normal line comment) to
actual TypeDoc comments.

* It standardises on TypeDoc's `{@link Name}` syntax for linking
identifiers, as opposed to the mixture of backticks and square brackets
we have today.

* It fixes typos and generally cleans up the formatting here and there,
as well as introducing more consistency where the same concepts crop up
in multiple places.
2024-07-15 11:27:47 +00:00
Julien P 742c7609a2
Don't load punycode module in function serialization code ()
<!--- 
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 https://github.com/pulumi/pulumi/issues/15545

https://nodejs.org/api/deprecations.html#dep0040-nodepunycode-module

## 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. -->
2024-05-08 16:38:35 +00:00
Julien P 29dfdcae72
Serialize function values obtained from Function.bind ()
<!--- 
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

When encountering a function obtained via `Function.bind` we previously
failed to serialise the function because we could not get the function
text.

This PR uses the v8 debugger API to grab the internal
`[[TargetFunction]]` property to obtain the original function and
re-bind it.

This does currently not handle successive binds like

```(function f() { ... }).bind("a").bind("b")```

Ref https://github.com/pulumi/pulumi/issues/5294

## 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. -->
- [ ] 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-04-10 11:17:53 +00:00
Julien P ba78d97a93
Handle serialization of aliases for well known native functions ()
# Description

Emit expressions for aliased native functions
https://github.com/pulumi/pulumi/issues/5294#issuecomment-2031404191

## 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-04-08 15:06:40 +00:00
Julien P 2d8e09d834
Update builtin module list for function serialization ()
<!--- 
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

Update the list of node modules detected as builtin during function
serialisation.

This helps with some of the cases in
https://github.com/pulumi/pulumi/issues/5294 (notably trying to use
`fs/promises`).

## 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. -->
- [ ] 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. -->
2024-04-02 08:28:18 +00:00
Robbie McKinstry 9658df87e7
This commit safely replaces empty interfaces with type aliases.
Empty interfaces have no effect, even when they are subtyping
other interfaces. An empty interface is always equivalent to its supertype.
They can be safely replaced with type aliases, which better express
the semantic equivalence between the two types.
2023-05-11 23:10:00 -04:00
Robbie McKinstry 2e40af5687
Eliminate postfix-!!
The non-null assertion operator ("!") has no effect
if applied twice. !! as a postfix operation does nothing.
This commit eliminates usage of that syntactic form.
2023-05-11 00:01:41 -04:00
Robbie McKinstry d6fd384e63
Eliminate unnecessary double negations.
This commit removes instances of prefix-!! where the value
would already be coerced into a boolean. It also removes
instances where the "optional chaining" operator (?.)
would suffice.
2023-05-09 18:35:59 -04:00
Robbie McKinstry e05a3bd81c
Apply autoformat
This commit applies the Rome autoformatter to the Node SDK.
These changes are automatically produced. To reproduce these
changes, run `make format` from inside sdk/nodejs.
2023-04-28 18:27:10 -04:00
Kyle Pitzen 5cfad4a909 fix: Allows for parallel pulumi programs to run in the node runtime 2022-10-13 07:15:25 -04:00
Anton Tayanovskyy 301d918e25
Make sure import pulumi/pulumi does not necessarily import typescript () 2022-07-22 09:30:54 -04:00
Daniel Bradley 350274c996
Tidy Nodejs SDK imports ()
* Remove unused nodejs SDK imports

Quick audit to find all unused imports in files

- Remove unused `protobufjs` dependency - we use `google-protobuf` and `@grpc/grpc-js`.

* Eliminate additional unused code
2022-05-30 09:31:28 +01:00
CommanderRoot ab276c43d9
Replace deprecated String.prototype.substr() ()
String.prototype.substr() is deprecated (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) so we replace it with similar functions which aren't deprecated.
Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
2022-03-19 10:04:27 +00:00
Kyle Dixler c8280936dc
JavaScript fnSerialization match package.json exports ()
* Added support for complying with nodejs package.json exports field if provided.

Co-authored-by: Kyle Dixler <kyle@pulumi.com>
Co-authored-by: Ian Wahbe <ian@wahbe.com>
2022-02-08 10:22:56 -08:00
Anton Tayanovskyy 08df93f33e
Work around node SDK tsc failure () 2022-01-04 14:53:41 -05:00
Horace Lee a92a005d68
Use ESlint instead of TSlint ()
Migrated TSlint configs to ESlint ones using [tslint-to-eslint-config](https://github.com/typescript-eslint/tslint-to-eslint-config) tool, and refined the configs to better match the current coding style.

Changes:
- [member-delimiter-style](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-delimiter-style.md#options) that as suggested default for type definition to be  with `semicolon`
- Indentation fixes that is enforced by [eslint-indent](https://eslint.org/docs/rules/indent#options)
- Added dependencies for ESlint with Typescript
- Removed TSlint
2021-08-10 11:31:59 -07:00
PND c6062ea1d5
[sdk/nodejs] Fix a bug in closure serialization. ()
Co-authored-by: Komal <komal@pulumi.com>
Co-authored-by: Luke Hoban <luke@pulumi.com>
2021-07-15 18:20:09 -07:00
Luke Hoban 1ef2f10543
Allow `serializeFunction` to capture secrets ()
Adds an opt-in `allowSecrets` flag to `serializeFunction` to allow it to capture secrets.  If passed, `serializeFunction` will now report back whether it captured any secrets.  This information can be used by callers to wrap the resulting text in a Secret value.

Fixes .
2020-12-31 09:37:25 +11:00
Justin Van Patten 9abcca345a
Mark internal APIs `@internal` to filter from API docs ()
Also:

 - Cleaned up existing tags so they're consistently at the bottom of doc comments where they should be
 - Cleaned up some unused imports while I was taking a pass over the files
 - Marked one function `@deprecated` that should be deprecated
2020-01-26 09:06:35 -08:00
CyrusNajmabadi 3639d1e998
Serialized function parameter count. () 2019-05-20 22:19:22 -04:00
Matt Ellis 825a461b2e Fix a SxS issue with `isSecret`
Because of our Proxy types, every output will return something when
you call `.isSecret` on it. However, if you call it on an output from
a version of `@pulumi/pulumi` which did not support secrets, the thing
you will get back is not undefined but rather an `Output` which wraps
undefined.

Because of this, care must be taken when reading this property and so
a small helper is introduced and used in places we care about.
2019-05-13 15:45:08 -07:00
Matt Ellis 1af821db9c Don't capture secret outputs in closures.
Until  is addressed, we will just disallow capturing secret
outputs when we serialize closures.
2019-05-13 15:45:08 -07:00
CyrusNajmabadi 42812f9b28
Work around a legal code pattern that previous versions of TypeScript complain about. () 2019-04-08 11:21:01 -07:00
CyrusNajmabadi be1c3eb05b
Add support for serializing bigints () 2019-03-22 15:33:37 -07:00
CyrusNajmabadi 3bb8759b23
Implement rtti checks more consistently () 2019-02-28 14:56:35 -08:00
CyrusNajmabadi 3d1df982de
Incorrect closure serialization when object referenced through different functions. () 2019-02-28 11:11:43 -08:00
CyrusNajmabadi aa3c6d0ba6
Converting an Output to a string or JSON now produces a warning . () 2019-02-27 16:00:54 -08:00
CyrusNajmabadi 0d2d1eb61a
Rolling back toString/toJSON change ()
* Revert "Make toString and toJSON internal ()"

This reverts commit 7579b84f73.

* Revert "Update error message to point at docs. ()"

This reverts commit 9156c26a2e.

* Revert "Throw on Output.toString and toJSON ()"

This reverts commit c33b4505c0.
2019-02-27 14:53:56 -08:00
CyrusNajmabadi c33b4505c0
Throw on Output.toString and toJSON () 2019-02-26 19:24:21 -08:00
CyrusNajmabadi 5211954f3a
Break out Resource and Output into their own files () 2019-01-31 18:08:17 -08:00
CyrusNajmabadi 901a238fd5
Get closure serialiation working in Node11 ()
* Make v8 primitives async as there is no way to avoid async in node11.

* Simplify API.

* Move processing of well-known globals into the v8 layer.
We'll need this so that we can map from RemoteObjectIds back to these well known values.

* Remove unnecesssary check.

* Cleanup comments and extract helper.

* Introduce helper bridge method for the simple case of making an entry for a string.

* Make functions async.  They'll need to be async once we move to the Inspector api.

* Make functions async.  They'll need to be async once we move to the Inspector api.

* Make functions async.  They'll need to be async once we move to the Inspector api.

* Move property access behind helpers so they can move to the Inspector API in the future.

* Only call function when we know we have a Function.  Remove redundant null check.

* Properly serialize certain special JavaScript number values that JSON serialization cannot handle.

* Only marshall across the 'source' and 'flags' for a RegExp when serializing.

* Add a simple test to validate a regex without flags.

* Extract functionality into helper method.

* Add test with complex output scenarios.

* Output serialization needs to avoid recursively trying to serialize a serialized value.

* Introduce indirection for introspecting properties of an object.

* Use our own introspection API for examining an Array.

* Hide direct property access through API indirection.

* Produce values like the v8 Inspector does.

* Compute the module map asynchronously.  Will need that when mapping mirrors instead.

* Cleanup a little code in closure creation.

* Get serialization working on Node11 (except function locations).

* Run tests in the same order on <v11 and >=v11

* Make tests run on multiple versions of node.

* Rename file to make PR simpler to review.

* Cleanup.

* Be more careful with global state.

* Remove commented line.

* Only allow getting a session when on Node11 or above.

* Promisify methods.
2018-11-01 15:46:21 -07:00
CyrusNajmabadi 7efd3ddf05
Cleanup a little code in closure creation. () 2018-10-28 13:02:04 -07:00
CyrusNajmabadi 13d9043771
Produce values like the v8 Inspector does. () 2018-10-28 01:01:48 -07:00
CyrusNajmabadi 1d7f35352d
Properly serialize certain special JavaScript number values that JSON serialization cannot handle. () 2018-10-26 23:46:57 -07:00
CyrusNajmabadi 43674dcef5
Switch to upath so that all paths are in unix-format () 2018-10-03 12:06:55 -07:00
CyrusNajmabadi d305b30f21 Revert RunError behavior. Introduce new ResourceError for errors assiated with a resource. ()
* Revert RunError behavior.  Introduce new ResourceError for errors associated with a resource.

* Fix docs.

* Use resource error.

* Use ResourceError in more places.

* Use ResourceError in a few more places.

* Throw a resource error.

* Make required.

* Revert this.

* Lint.

* Only report errors once.

* Better comment.
2018-09-24 16:57:20 -07:00
CyrusNajmabadi 9d0dc65f49
Provide helper to compute whihc sub-packages should be included even if we would exclude a higher package. () 2018-09-05 12:54:28 -07:00
CyrusNajmabadi ddd83fafc4
Support serializing regex instances. () 2018-09-03 23:14:00 -07:00
CyrusNajmabadi 8aed774f09
Properly capture modules that are in a non-local node_modules path. () 2018-08-21 12:43:52 -07:00
CyrusNajmabadi 152fde0867
Strip off the node_modules prefix from our require() calls. () 2018-08-07 20:27:02 -04:00
CyrusNajmabadi c57aef785b
Ensure we can capture non-built-in modules with 'require'. () 2018-08-02 16:25:49 -04:00
CyrusNajmabadi d19942f2b0
Go back to capturing *non-user* modules by 'require' reference. () 2018-07-31 11:37:46 -04:00
CyrusNajmabadi 48df5bfe1e
Update pulumi/pulumi to run on Nodejs v10. () 2018-07-25 16:55:20 -07:00
CyrusNajmabadi d79dbdce35
Rollback PRs ()
* Revert "Parallelize much more of resource creation in the JS language provider SDK ()"

This reverts commit 4edd244a26.

* Revert "Process our async-work-queue in parallel. ()"

This reverts commit b8c1cb9574.
2018-07-11 18:33:53 -07:00
CyrusNajmabadi b8c1cb9574
Process our async-work-queue in parallel. () 2018-07-10 15:42:11 -07:00
CyrusNajmabadi 4cebc381ae
Do a better job preventing serialization of unnecessary objects in closure serialization () 2018-06-20 12:57:57 -07:00
Luke Hoban 858e321110
Make RTTI markers internal ()
Fixes .
2018-06-07 21:34:06 -07:00
Luke Hoban 076d8887c9
Compute required packages during closure serialization ()
Closure serialization now keeps track of the `require`d packages it sees in the function bodies that are serialized during a call to `serializeFunction`.

Also, replaces `serializeFunctionAsync` with `serializeFunction` which accepts richer parameters and return type, deprecating the former API (but leaving it available for now to avoid a breaking change).
2018-06-03 21:55:37 -07:00
Pat Gavlin a16a880518
Discriminate unknown values in the JS runtime. ()
These changes add support for distinguishing an output property with
an unknown value from an output property with a known value that is
undefined.

In a broad sense, the Pulumi property type system is just JSON with the
addition of unknown values. Notably absent, however, are undefined
values. As it stands, our marshalers between JavaScript and Pulumi
property values treat all undefined JavaScript values as unknown Pulumi
values. Unfortunately, this conflates two very different concepts:
unknown Pulumi values are intended to represent values of output
properties that are unknown at time of preview, _not_ values that are
known but undefined. This results in difficulty reasoning about when
transforms are run on output properties as well as confusing output in
the `diff` view of Pulumi preview (user-specifed undefined values are
rendered as unknown values).

As it turns out, we already have a way to decide whether or not an
Output value is known or not: Output.performApply. These changes rename
this property to `isKnown`, clarify its meaning, and take advantage of
the result to decide whether or not an Output value should marshal as
an unknown Pulumi value.

This also allowed these changes to improve the serialization of
undefined object keys and array elements s.t. we better match JavaScript
to JSON serialization behavior (undefined object keys are omitted;
undefined array elements are marshaled as `null`).

Fixes https://github.com/pulumi/pulumi-cloud/issues/483.
2018-05-23 14:47:40 -07:00
joeduffy 5967259795 Add license headers 2018-05-22 15:02:47 -07:00