Skip to content

Commit

Permalink
fix: extern typing bug (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr authored Feb 8, 2024
1 parent 18a02a5 commit 88883c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions dynamo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ const client = new DynamoDBClient({});

// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/command/PutItemCommand/
export async function _putItem(tableName, item) {
const command = new PutItemCommand({
const putItemInput = {
TableName: tableName,
Item: item,
});
console.log(command);

};
console.log(putItemInput);
const command = new PutItemCommand(putItemInput);
const response = await client.send(command);
console.log(response);
return response;
}

// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/command/GetItemCommand/
export async function _getItem(tableName, key) {
const command = new GetItemCommand({
const getItemInput = {
TableName: tableName,
Key: key,
});
console.log(command);
};
console.log(getItemInput);
const command = new GetItemCommand(getItemInput);

const response = await client.send(command);
console.log(response);
Expand All @@ -33,10 +34,11 @@ export async function _getItem(tableName, key) {

// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/command/ScanCommand/
export async function _scan(tableName) {
const command = new ScanCommand({
const scanInput = {
TableName: tableName,
});
console.log(command);
};
console.log(scanInput);
const command = new ScanCommand(scanInput);

const response = await client.send(command);
console.log(response);
Expand Down
4 changes: 2 additions & 2 deletions dynamodb.w
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub class DynamoDBTableAws {
}

extern "./dynamo.js" static inflight _putItem(tableName: str, item: Json): void;
extern "./dynamo.js" static inflight _getItem(tableName: str, key: Json): Map<Map<Map<str>>>;
extern "./dynamo.js" static inflight _getItem(tableName: str, key: Json): Map<Map<Map<str>>>?;
extern "./dynamo.js" static inflight _scan(tableName: str): Map<Array<Map<Map<str>>>>;

pub inflight putItem(item: Map<Attribute>) {
Expand All @@ -104,7 +104,7 @@ pub class DynamoDBTableAws {
pub inflight getItem(key: Map<Attribute>): Map<Attribute> {
let json = this._itemToJson(key);
let result = DynamoDBTableAws._getItem(this.tableName, json);
return this._rawMapToItem(result.get("Item"));
return this._rawMapToItem(result?.get("Item") ?? {});
}

pub inflight scan(): Array<Map<Attribute>> {
Expand Down

0 comments on commit 88883c5

Please sign in to comment.