-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
6ddc0fa
commit 3328249
Showing
39 changed files
with
2,454 additions
and
1,346 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"packages": ["packages/*"], | ||
"useNx": false, | ||
"version": "0.0.29" | ||
"version": "0.0.30" | ||
} |
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from '@datastream/aws/dynamodb' | ||
export * from '@datastream/aws/lambda' | ||
export * from '@datastream/aws/s3' | ||
export * from '@datastream/aws/sns' | ||
export * from '@datastream/aws/sqs' |
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,50 @@ | ||
import { createReadableStream } from '@datastream/core' | ||
import { | ||
LambdaClient, | ||
InvokeWithResponseStreamCommand | ||
} from '@aws-sdk/client-lambda' | ||
|
||
const awsClientDefaults = { | ||
// https://aws.amazon.com/compliance/fips/ | ||
useFipsEndpoint: [ | ||
'us-east-1', | ||
'us-east-2', | ||
'us-west-1', | ||
'us-west-2', | ||
'ca-central-1' | ||
].includes(process.env.AWS_REGION) | ||
} | ||
|
||
let defaultClient = new LambdaClient(awsClientDefaults) | ||
export const awsLambdaSetClient = (lambdaClient) => { | ||
defaultClient = lambdaClient | ||
} | ||
|
||
export const awsLambdaReadableStream = async (lambdaOptions, streamOptions) => { | ||
return createReadableStream(awsLambdaGenerator(lambdaOptions), streamOptions) | ||
} | ||
export const awsLambdaResponseStream = awsLambdaReadableStream | ||
|
||
async function * awsLambdaGenerator (lambdaOptions, streamOptions) { | ||
if (!Array.isArray(lambdaOptions)) lambdaOptions = [lambdaOptions] | ||
for (const options of lambdaOptions) { | ||
const response = await defaultClient.send( | ||
new InvokeWithResponseStreamCommand(options) | ||
) | ||
for await (const chunk of response.EventStream) { | ||
if (chunk?.PayloadChunk?.Payload) { | ||
yield chunk.PayloadChunk.Payload | ||
} else if (chunk?.InvokeComplete?.ErrorCode) { | ||
throw new Error(chunk.InvokeComplete.ErrorCode, { | ||
cause: chunk.InvokeComplete.ErrorDetails | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default { | ||
setClient: awsLambdaSetClient, | ||
readableStream: awsLambdaReadableStream, | ||
responseStream: awsLambdaReadableStream | ||
} |
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,50 @@ | ||
import test from 'node:test' | ||
import { deepEqual } from 'node:assert' | ||
// import sinon from 'sinon' | ||
import { mockClient } from 'aws-sdk-client-mock' | ||
import { | ||
LambdaClient, | ||
InvokeWithResponseStreamCommand | ||
} from '@aws-sdk/client-lambda' | ||
|
||
import { createReadableStream } from '@datastream/core' | ||
|
||
import { awsLambdaSetClient, awsLambdaReadableStream } from '@datastream/aws' | ||
|
||
let variant = 'unknown' | ||
for (const execArgv of process.execArgv) { | ||
const flag = '--conditions=' | ||
if (execArgv.includes(flag)) { | ||
variant = execArgv.replace(flag, '') | ||
} | ||
} | ||
|
||
test(`${variant}: awsLambdaReadableStream should return chunk`, async (t) => { | ||
const client = mockClient(LambdaClient) | ||
awsLambdaSetClient(client) | ||
|
||
const encoder = new TextEncoder() | ||
const decoder = new TextDecoder() | ||
|
||
client.on(InvokeWithResponseStreamCommand, {}).resolves({ | ||
EventStream: createReadableStream([ | ||
{ | ||
PayloadChunk: { | ||
Payload: encoder.encode('1') | ||
} | ||
}, | ||
{ | ||
PayloadChunk: { | ||
Payload: encoder.encode('2') | ||
} | ||
} | ||
]) | ||
}) | ||
|
||
let result = '' | ||
for await (const chunk of await awsLambdaReadableStream({})) { | ||
result += decoder.decode(chunk) | ||
} | ||
|
||
deepEqual(result, '12') | ||
}) |
Oops, something went wrong.