Security News
UK Officials Consider Banning Ransomware Payments from Public Entities
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
@mrgrain/jsii-struct-builder
Advanced tools
Build jsii structs with ease.
Jsii doesn't support TypeScript Utility Types like Partial
or Omit
, making it difficult to re-use existing struct interfaces.
With this package, you can work around that limitation and create brand new struct interfaces based on the jsii specification of any existing structs, their parents, and your custom specification.
From jsii's perspective, these structs are completely new types. From a maintainer's perspective, they require the same minimal effort as utility types do. Everybody wins!
Install with:
npm install --save-dev @mrgrain/jsii-struct-builder
Use the jsii FQN to mix in an existing struct.
Use omit()
to remove any properties you are not interested in.
new ProjenStruct(project, { name: 'MyProjectOptions'})
.mixin(Struct.fromFqn('projen.typescript.TypeScriptProjectOptions'))
.omit('sampleCode', 'projenrcTs', 'projenrcTsOptions');
New properties can be added with a @jsii/spec
definition.
Complex types can be used and will be imported using their FQN.
Any existing properties of the same name will be replaced.
new ProjenStruct(project, { name: 'MyProjectOptions'})
.mixin(Struct.fromFqn('projen.typescript.TypeScriptProjectOptions'))
.add(
{
name: 'booleanSetting',
type: { primitive: jsii.PrimitiveType.Boolean }
},
{
name: 'complexSetting',
type: { fqn: "my_project.SomeEnum" }
}
);
Existing properties can be updated.
The provided partial @jsii/spec
definition will be deep merged with the existing spec.
A convenience rename()
method is provided.
An update()
of the name
field has the same effect and can be combined with other updates.
new ProjenStruct(project, { name: 'MyProjectOptions'})
.mixin(Struct.fromFqn('projen.typescript.TypeScriptProjectOptions'))
// Update a property
.update('typescriptVersion', { optional: false })
// Nested values can be updated
.update('sampleCode', {
docs: {
summary: 'New summary',
default: 'false',
}
}
)
// Rename a property
.rename('homepage', 'website'})
// ...this also does a rename
.update('eslint', {
name: 'lint',
optional: false,
});
Arbitrary predicate functions can be used to filter properties. Only properties that meet the condition are kept.
Use omit()
and only()
for easy name based filtering.
A convenience withoutDeprecated()
method is also provided.
new ProjenStruct(project, { name: 'MyProjectOptions'})
.mixin(Struct.fromFqn('projen.typescript.TypeScriptProjectOptions'))
// Keep properties using arbitrary filters
.filter((prop) => !prop.optional)
// Keep or omit properties by name
.only('projenrcTs', 'projenrcTsOptions')
.omit('sampleCode')
// Remove all deprecated properties
.withoutDeprecated();
It is not required to use projen with this package. You can use a renderer directly to create files:
const myProps = Struct.empty("@my-scope/my-pkg.MyFunctionProps")
.mixin(Struct.fromFqn("aws-cdk-lib.aws_lambda.FunctionProps"))
.withoutDeprecated();
const renderer = new TypeScriptRenderer();
fs.writeFileSync("my-props.ts", renderer.renderStruct(myProps));
Struct
and ProjenStruct
both share the same interface.
This allows some advanced applications.
For example you can manipulate the source for re-use:
const base = Struct.fromFqn('projen.typescript.TypeScriptProjectOptions');
base.omit('sampleCode', 'projenrcTs', 'projenrcTsOptions');
Or you can mix on ProjenStruct
with another:
const foo = new ProjenStruct(project, { name: 'Foo'})
const bar = new ProjenStruct(project, { name: 'Bar'})
bar.mixin(foo);
You can also use Struct
and ProjenStruct
as type of a property:
const foo = new ProjenStruct(project, { name: 'Foo'})
const bar = new ProjenStruct(project, { name: 'Bar'})
foo.add({
name: 'barSettings',
type: bar
});
The default configuration makes assumptions about the new interface that are usually okay.
For more complex scenarios fqn
, filePath
and importLocations
can be used to influence the rendered output.
new JsiiInterface(project, {
name: 'MyProjectOptions',
fqn: 'my_project.nested.location.MyProjectOptions',
filePath: 'src/nested/my-project-options.ts',
importLocations: {
'my_project': '../enums'
}
})
.add({
name: 'complexSetting',
type: { fqn: "my_project.SomeEnum" }
});
FAQs
Build jsii structs with ease
The npm package @mrgrain/jsii-struct-builder receives a total of 684 weekly downloads. As such, @mrgrain/jsii-struct-builder popularity was classified as not popular.
We found that @mrgrain/jsii-struct-builder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.