Skip to content

Commit

Permalink
feat: pass data types (structs) by-value instead of by-ref (#376)
Browse files Browse the repository at this point in the history
Data types ("structs") are defined through a TypeScript interface that only contains properties and doesn't begin with an `I`. This change also adds a requirement that all properties (shallow) are marked `readonly`.

This allows passing around structs by-value safely because any consuming code would not expect to be able to write to the object.

Python already passes structs by value, especially in the context of when a struct is used as keyword arguments. This use case will also exist in Ruby.

This is also the general perception around data that's passed around in most programming languages.

To enforce this, the jsii compiler will now fail if a struct includes properties that are not marked `readonly`.

Both the Java and .NET generators have been modified to generate builders which allow users to construct structs by serializing them as JSON hashes instead of passed down by reference.

Existing compliance tests in all languages have been fixed.

This change fixes aws/aws-cdk#965 and fixes #375 by erasing any `null`s or `undefined` values from passed in objects, so they do not appear to have been defined at all. Added a compliance test called **erase-unset-data-values** to verify.

BREAKING CHANGE: all properties in interfaces which represent data types must be marked as `readonly`. Otherwise, jsii compilation will fail.
  • Loading branch information
Elad Ben-Israel authored Mar 20, 2019
1 parent b5d49de commit db3ccdf
Show file tree
Hide file tree
Showing 150 changed files with 8,787 additions and 8,849 deletions.
82 changes: 82 additions & 0 deletions foreach.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash
# --------------------------------------------------------------------------------------------------
#
# this wonderful tool allows you to execute a command for all modules in this repo
# in topological order, but has the incredible property of being stateful.
# this means that if a command fails, you can fix the issue and resume from where
# you left off.
#
# to start a session, run:
# foreach.sh COMMAND
#
# this will execute "COMMAND" for each module in the repo (cwd will be the directory of the module).
# if a task fails, it will stop, and then to resume, simply run `foreach.sh` again (with or without the same command).
#
# to reset the session (either when all tasks finished or if you wish to run a different session), run:
# rm -f ~/.foreach.*
#
# this will effectively delete the state files.
#
# --------------------------------------------------------------------------------------------------
set -euo pipefail
statefile="${HOME}/.foreach.state"
commandfile="${HOME}/.foreach.command"
command_arg="${@:-}"

function heading {
printf "\e[38;5;81m$@\e[0m\n"
}

function error {
printf "\e[91;5;81m$@\e[0m\n"
}

function success {
printf "\e[32;5;81m$@\e[0m\n"
}

if [ -f "${statefile}" ] && [ -f "${commandfile}" ]; then
command="$(cat ${commandfile})"
if [ ! -z "${command_arg}" ] && [ "${command}" != "${command_arg}" ]; then
error "error: there is still an active session for: \"${command}\". to reset:"
error " rm -f ~/.foreach.*"
exit 1
fi
fi

if [ ! -f "${statefile}" ] && [ ! -f "${commandfile}" ]; then
if [ ! -z "${command_arg}" ]; then
command="${command_arg}"
success "starting new session"
npx lerna ls --all --toposort -p > ${statefile}
echo "${command}" > ${commandfile}
else
error "no active session, use \"$(basename $0) COMMAND\" to start a new session"
exit 0
fi
fi

next="$(head -n1 ${statefile})"
if [ -z "${next}" ]; then
success "done (queue is empty). to reset:"
success " rm -f ~/.foreach.*"
exit 0
fi

remaining=$(cat ${statefile} | wc -l | xargs -n1)

heading "---------------------------------------------------------------------------------"
heading "${next}: ${command} (${remaining} remaining)"

(
cd ${next}
${command} || {
error "error: last command failed. fix problem and resume by executing:"
error " $0"
exit 1
}
)

tail -n +2 "${statefile}" > "${statefile}.tmp"
cp "${statefile}.tmp" "${statefile}"
exec $0
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lerna": "2.11.0",
"lerna": "3.13.1",
"packages": [
"packages/*"
],
Expand Down
Loading

0 comments on commit db3ccdf

Please sign in to comment.