mrgrain / jsii-struct-builder Goto Github PK
View Code? Open in Web Editor NEWBuild jsii structs with ease.
Home Page: https://www.npmjs.com/package/@mrgrain/jsii-struct-builder
License: Apache License 2.0
Build jsii structs with ease.
Home Page: https://www.npmjs.com/package/@mrgrain/jsii-struct-builder
License: Apache License 2.0
A common use-case for this package is using it with an AWS CDK Construct Library with Projen. However, it's not immediately clear how to use it. The README shows new ProjenStruct
, but it doesn't say where to write that code.
.update('old', { name: 'new' })
works but .rename('old', 'new')
would be more descriptive.
Should have a withoutDeprecated()
helper to remove all deprecated.
Also might be worth adding a generic filter
method that can be used for any kind of omits.
First of all, this is fantastic. ๐ ๐
I started messing around with this when it was the first iteration (before the rename), and I could have sworn that the first cut supported implementing a jsii interface as a TS Partial - make every property optional. I can't seem to get that same behavior with this new version. Have I just officially lost it, or did that behavior get dropped in the transition?
Here's an example of what I'm doing right now:
new ProjenStruct(project, { name: "TokenAuthorizerProps" })
.mixin(Struct.fromFqn("aws-cdk-lib.aws_apigateway.TokenAuthorizerProps"))
.withoutDeprecated();
And I'd like that produced interface to have all mixed-in properties as optional.
For example:
requiredNodejsProps.mixin(
Struct.fromFqn("aws-cdk-lib.aws_lambda_nodejs.NodejsFunctionProps")
.withoutDeprecated()
.update("description", { optional: false })
);
Leaves the docstring in the produced code:
/**
* A description of the function.
* @default - No description.
* @stability stable
*/
readonly description: string;
If optional: false
, I think we could assume this (docs
param):
requiredNodejsProps.mixin(
Struct.fromFqn("aws-cdk-lib.aws_lambda_nodejs.NodejsFunctionProps")
.withoutDeprecated()
.update("description", { optional: false, docs: { default: undefined } })
);
Hi, thanks so much for this library! Has really helped cdk-nextjs offer a flexible/customizable L3 construct to deploy Next.js on AWS.
Given the example from the docs:
new ProjenStruct(project, { name: 'MyProjectOptions' })
.mixin(Struct.fromFqn('projen.typescript.TypeScriptProjectOptions'))
.omit('sampleCode', 'projenrcTs', 'projenrcTsOptions');
How could I adjust this example to create a new interface from a local file like:
new ProjenStruct(project, { name: 'MyProjectOptions' })
.mixin(Struct.fromLocal('./my/file/path/TypeScriptProjectOptions.ts'))
.omit('sampleCode', 'projenrcTs', 'projenrcTsOptions');
Hello, First of love the library. Overriding projen properties is/was a pain point of ours. We set the new default properties by hand and even enforce some but having it reflected in the generated docs is hard. With this library it's easy thanks for that.
Using it however I think I found a bug as every property in the generated Struct has the @stability experimental
doc annotation attached to it.
Using this code I'm trying to generate a new Struct extending from projen.typescript.TypeScriptProjectOptions
.
export class NodeLibraryBlocProjenOptions extends ProjenStruct {
constructor(project: typescript.TypeScriptProject, options?: ProjenStructOptions) {
const defaultOptions: ProjenStructOptions = {
name: 'NodeLibraryProjenOptions',
filePath: './src/blocs/node-library/node-library.projen-options.ts',
};
super(project, { ...defaultOptions, ...options });
this.mixin(Struct.fromFqn('projen.typescript.TypeScriptProjectOptions'));
}
}
This generates this Struct and every property now has the @stability experimental
tag.
/**
* NodeLibraryProjenOptions
*/
export interface NodeLibraryProjenOptions {
/**
* TypeScript version to use.
* NOTE: Typescript is not semantically versioned and should remain on the
* same minor, so we recommend using a `~` dependency (e.g. `~1.2.3`).
* @default "latest"
* @stability experimental
*/
readonly typescriptVersion?: string;
/**
* The name of the development tsconfig.json file.
* @default "tsconfig.dev.json"
* @stability experimental
*/
readonly tsconfigDevFile?: string;
/**
* Custom tsconfig options for the development tsconfig.json file (used for testing).
* @default - use the production tsconfig options
* @stability experimental
*/
readonly tsconfigDev?: javascript.TypescriptConfigOptions;
/**
* Custom TSConfig.
* @default - default options
* @stability experimental
*/
readonly tsconfig?: javascript.TypescriptConfigOptions;
I can remove it for individual properties by manually setting the stability to undefined in an update function.
Hi, thank you for your recommendation, to try your module.
After playing around I found out, that loading a struct from current module instead of external dependency is not working.
Now I open (as wished) an issue. Here is my error output just in case.
new ProjenStruct(gcixProject, { name: 'ArtifactsReportType', filePath: 'src/core/artifactsreport.ts' })
.mixin(Struct.fromFqn('gcix.ArtifactsReport'));
The struct I want to load is in src/core/artifacts.ts
, the .jsii is inside my root directory. I looked the Fqn up from inside the .jssi file. But all I get is:
Error: Cannot find module 'gcix/.jsii'
Require stack:
- $HOME_DIR/node_modules/@mrgrain/jsii-struct-builder/lib/private/assembly.js
- $HOME_DIR/node_modules/@mrgrain/jsii-struct-builder/lib/private/index.js
- $HOME_DIR/node_modules/@mrgrain/jsii-struct-builder/lib/builder/struct.js
- $HOME_DIR/node_modules/@mrgrain/jsii-struct-builder/lib/builder/index.js
- $HOME_DIR/node_modules/@mrgrain/jsii-struct-builder/lib/index.js
- $HOME_DIR/.projenrc.ts
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] ($HOME_DIR/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
at Function.resolve (node:internal/modules/cjs/helpers:116:19)
at assemblyPath ($HOME_DIR/node_modules/@mrgrain/jsii-struct-builder/src/private/assembly.ts:15:31)
at loadAssembly ($HOME_DIR/node_modules/@mrgrain/jsii-struct-builder/src/private/assembly.ts:20:44)
at loadInterface ($HOME_DIR/node_modules/@mrgrain/jsii-struct-builder/src/private/assembly.ts:27:15)
at findInterface ($HOME_DIR/node_modules/@mrgrain/jsii-struct-builder/src/private/assembly.ts:46:16)
at Function.fromFqn ($HOME_DIR/node_modules/@mrgrain/jsii-struct-builder/src/builder/struct.ts:113:33)
at Object.<anonymous> ($HOME_DIR/.projenrc.ts:49:118)
at Module._compile (node:internal/modules/cjs/loader:1256:14) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'$HOME_DIR/node_modules/@mrgrain/jsii-struct-builder/lib/private/assembly.js',
'$HOME_DIR/node_modules/@mrgrain/jsii-struct-builder/lib/private/index.js',
'$HOME_DIR/node_modules/@mrgrain/jsii-struct-builder/lib/builder/struct.js',
'$HOME_DIR/node_modules/@mrgrain/jsii-struct-builder/lib/builder/index.js',
'$HOME_DIR/node_modules/@mrgrain/jsii-struct-builder/lib/index.js',
'$HOME_DIR/.projenrc.ts'
]
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.