-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
2,776 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ jobs: | |
bedrock | ||
budget | ||
checks | ||
cloudv2 | ||
cognito | ||
containers | ||
dynamodb | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
target/ | ||
node_modules/ | ||
*.snap.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Wing | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# cloudv2 | ||
|
||
This module contains a Wing-based implementation of the built-in `cloud` library. It's a work in progresss as part of a migration for our internal codebase. | ||
|
||
Here are the resources available so far: | ||
- Counter | ||
|
||
## Prerequisites | ||
|
||
* [winglang](https://winglang.io). | ||
|
||
## Installation | ||
|
||
```sh | ||
npm i @winglibs/cloudv2 | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
bring cloudv2 as cloud; | ||
|
||
let counter = new cloud.Counter(); | ||
``` | ||
|
||
## License | ||
|
||
This library is licensed under the [MIT License](./LICENSE). |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { | ||
UpdateItemCommand, | ||
GetItemCommand, | ||
DynamoDBClient, | ||
} from "@aws-sdk/client-dynamodb"; | ||
|
||
import types from "./counter-aws.extern"; | ||
|
||
const AMOUNT_TOKEN = "amount"; | ||
const INITIAL_VALUE_TOKEN = "initial"; | ||
const VALUE_ATTRIBUTE = "counter_value"; | ||
const SET_VALUE = "set_value"; | ||
|
||
const client = new DynamoDBClient(); | ||
|
||
export const _inc: types["_inc"] = async ( | ||
amount, | ||
key, | ||
tableName, | ||
hashKey, | ||
initial | ||
) => { | ||
const command = new UpdateItemCommand({ | ||
TableName: tableName, | ||
Key: { [hashKey]: { S: key } }, | ||
UpdateExpression: `SET ${VALUE_ATTRIBUTE} = if_not_exists(${VALUE_ATTRIBUTE}, :${INITIAL_VALUE_TOKEN}) + :${AMOUNT_TOKEN}`, | ||
ExpressionAttributeValues: { | ||
[`:${AMOUNT_TOKEN}`]: { N: `${amount}` }, | ||
[`:${INITIAL_VALUE_TOKEN}`]: { N: `${initial}` }, | ||
}, | ||
ReturnValues: "UPDATED_NEW", | ||
}); | ||
|
||
const result = await client.send(command); | ||
let newValue = result.Attributes?.[VALUE_ATTRIBUTE].N; | ||
if (!newValue) { | ||
throw new Error(`${VALUE_ATTRIBUTE} attribute not found on table.`); | ||
} | ||
|
||
// return the old value | ||
return parseInt(newValue) - amount; | ||
}; | ||
|
||
export const _dec: types["_dec"] = async ( | ||
amount, | ||
key, | ||
tableName, | ||
hashKey, | ||
initial | ||
) => { | ||
return _inc(-1 * amount, key, tableName, hashKey, initial); | ||
}; | ||
|
||
export const _peek: types["_peek"] = async ( | ||
key, | ||
tableName, | ||
hashKey, | ||
initial | ||
) => { | ||
const command = new GetItemCommand({ | ||
TableName: tableName, | ||
Key: { [hashKey]: { S: key } }, | ||
}); | ||
|
||
const result = await client.send(command); | ||
let value = result.Item?.[VALUE_ATTRIBUTE].N; | ||
if (!value) { | ||
return initial; | ||
} | ||
|
||
return parseInt(value); | ||
}; | ||
|
||
export const _set: types["_set"] = async (value, key, tableName, hashKey) => { | ||
const command = new UpdateItemCommand({ | ||
TableName: tableName, | ||
Key: { [hashKey]: { S: key } }, | ||
UpdateExpression: `SET ${VALUE_ATTRIBUTE} = :${SET_VALUE}`, | ||
ExpressionAttributeValues: { | ||
[`:${SET_VALUE}`]: { N: `${value}` }, | ||
}, | ||
ReturnValues: "UPDATED_NEW", | ||
}); | ||
|
||
await client.send(command); | ||
}; |
Oops, something went wrong.