Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
cde2d1a
Added option to ReadOptions to use a custom json parser
czirker Aug 18, 2023
a0799bb
adding docs for ReadOptions.parser
czirker Aug 18, 2023
9281402
Added sdk.putEvents
czirker Sep 26, 2023
872dbb6
trying to get worker threads to work with webpack better
czirker Sep 26, 2023
6494a38
Fixing split issues in parse worker thread
czirker Sep 27, 2023
f050b08
Working a way to use worker threads that don't get messed up by webpack
czirker Sep 28, 2023
4e1f634
extra cleanup for webpack
czirker Sep 28, 2023
c5e016f
Code cleanup
czirker Sep 28, 2023
1ce7c7b
Making the interface better for configuring parse and download
czirker Oct 2, 2023
b166e22
Don't override fast_s3_buffer if it was set
czirker Oct 2, 2023
11cdcd7
more options merging
czirker Oct 2, 2023
3a55113
Merge pull request #189 from LeoPlatform/eature/faster-stream-parsing…
czirker Oct 2, 2023
b5b7e54
Fixing unit tests
czirker Oct 3, 2023
8fb427f
Removed 12.x node ci/cd
czirker Oct 3, 2023
1e46432
removed node 18.x from ci/cd for now
czirker Oct 3, 2023
0417755
not including source maps for webpacked task modules
czirker Oct 3, 2023
b54c2d6
Updating package-lock.json
czirker Oct 4, 2023
9b6f0f7
Updating node setup version
czirker Oct 4, 2023
bf0cf6c
Change git checkout action
czirker Oct 4, 2023
6273777
Fixing the npm publish action to run on node 16
czirker Oct 4, 2023
20c7515
Cleaning up UUID lib to use version 8 to get rid of warnings
czirker Oct 4, 2023
dead30d
Fixing alpha bugs. missing ?, and setting stream limit
czirker Nov 3, 2023
337dc98
Fixed number parsing to allow for floats
czirker Nov 3, 2023
5b5cd9b
fixing cron wrapper to use a common registry
czirker Nov 3, 2023
7df4c68
Fixing fromLeo to not modify the input param
czirker Nov 3, 2023
c008f4b
adding getOpts to the fromLeo type
czirker Nov 3, 2023
9c60a27
Merge pull request #190 from LeoPlatform/bug/faster-stream-parsing-fixes
czirker Nov 3, 2023
57f9072
update uuid to 8
czirker Nov 3, 2023
7237f31
Fixing packaging
czirker Nov 6, 2023
37b45d7
fixing rsf configs that come from secrets manager and have string obj…
czirker Nov 8, 2023
ddfbad8
Fixing issue with prefetching ddb page when at the end of stream
czirker Nov 13, 2023
7bf03d3
Using ls.pipeline instead of ls.pipe when chaining together s3 and gz…
czirker Nov 21, 2023
f8c2e29
Added missing ddb access to aws-sync
czirker Dec 11, 2023
9d6cf44
Merging in compressed firehose writes
czirker Jan 11, 2024
99705a4
Update configuration-builder.ts
czirker Jan 12, 2024
536a8f6
Merging updates from v7 back into v6
czirker Feb 1, 2024
c3adec7
removing unsed module that referenced aws-sdk v2
czirker Feb 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x]
node-version: [14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: CI/CD ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 12
node-version: 16
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm i aws-sdk@^2.581.0
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ package-lock.json
*.utest.js
docs/build/
/docs/build-docs.js
scripts/*
util-lambdas/*
12 changes: 12 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ export declare class RStreamsSdk {
putEvent: <T>(bot_id: string, outQueue: string, payload: Event<T> | T) => Promise<void>;


/**
* An async/await friendly function to write an array of events to a queue.
*
* @typeParam T The data to write as the payload of the event
* @param payloads The payloads of the events to write
* @param settings The botId and queue to use if payloas is a T[] instead of Event<T>[], and writeOptions for sdk.load()
* @method
* @todo example
*/
putEvents: <T>(payloads: (Event<T> | T)[], settings?: { botId?: string, queue?: string, writeOptions?: WriteOptions }) => Promise<void>;


/** @method */
throughAsync: typeof StreamUtil.throughAsync;

Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ function SDK(id, data, awsResourceConfig) {
putEvent: function(bot_id, queue, payload) {
return promisify(this.put).call(this, bot_id, queue, payload);
},
putEvents: function(payloads, settings = {}) {
return this.streams.pipeAsync(
this.streams.eventstream.readArray(payloads),
this.load(settings.botId, settings.queue, settings.writeOptions)
);
},
throughAsync: leoStream.throughAsync,
checkpoint: leoStream.toCheckpoint,
streams: leoStream,
Expand Down
13 changes: 9 additions & 4 deletions lib/aws-sdk-sync.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions lib/aws-sdk-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { spawnSync } from "child_process";
// use `module.require` to keep webpack from overriding the function.
// This isn't run within the bundle
// It is stringified and run in a different process
export function invoke(service: string, method: string, config: any, params: any) {
let AWS = module.require.call(module, "aws-sdk");
export function invoke(AWS: any, service: string, method: string, config: any, params: any) {
let hasLogged = false;
try {
new AWS[service](config)[method](params, (err: any, data: any) => {
Expand All @@ -30,7 +29,7 @@ export function invoke(service: string, method: string, config: any, params: any
}

function run(service: string, method: string, config: any, params: any) {
let fn = `(${invoke.toString()})("${service}", "${method}", ${JSON.stringify(config)}, ${JSON.stringify(params)})`;
let fn = `(${invoke.toString()})(require("aws-sdk"),"${service}", "${method}", ${JSON.stringify(config)}, ${JSON.stringify(params)})`;

// Spawn node with the function to run `node -e (()=>{})`
// Using `RESPONSE::{}::RESPONSE` to denote the response in the output
Expand Down Expand Up @@ -75,6 +74,13 @@ export class S3 extends Service<AWS.S3.ClientConfiguration> {
}
}


export class DynamoDB extends Service<AWS.DynamoDB.ClientConfiguration> {
putItem(): AWS.DynamoDB.PutItemOutput {
return this.invoke("putItem");
}
}

export default {
SecretsManager,
S3
Expand Down
4 changes: 3 additions & 1 deletion lib/aws-util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/aws-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export function error(err, options) {
if (typeof err.message === 'string' && err.message !== '') {
if (typeof options === 'string' || (options && options.message)) {
originalError = copy(err);
originalError.message = err.message;
if (originalError != null) {
originalError.message = err.message;
}
}
}
err.message = err.message || null;
Expand Down
28 changes: 20 additions & 8 deletions lib/configuration-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export class ConfigurationBuilder<T> {
g.rstreams_project_config_cache = {};
}

if (g.rsf_config_opts) {
Object.assign(options, g.rsf_config_opts);
} else if (process.env.RSF_CONFIG_OPTS) {
Object.assign(options, JSON.parse(process.env.RSF_CONFIG_OPTS));
}

if (this.data == null || this.data == "") {
if (process.env.RSF_CONFIG) {
this.data = process.env.RSF_CONFIG;
Expand Down Expand Up @@ -101,15 +107,15 @@ export class ConfigurationBuilder<T> {
region: options.region
}).getSecretValue({
SecretId: this.data
}).SecretString);
}).SecretString.replace(/"{/g, '{').replace(/}"/g, "}"));
logger.timeEnd("get-rsf-config");
}
}

// Allow extra env vars to be defined as RSF_CONFIG_some.new.field=my_value
Object.entries(process.env).forEach(([key, value]) => {
const a = (key.match(/^RSF_CONFIG_(.*)$/) || [])[1];
if (a) {
if (a && key != "RSF_CONFIG_OPTS") {
let parts = a.split(".");
let lastPart = parts.pop();
let parent = parts.reduce((a, b) => {
Expand Down Expand Up @@ -143,10 +149,11 @@ export class ConfigurationBuilder<T> {
let returnValue = {};
Object.getOwnPropertyNames(root).forEach(key => {
let value = root[key];
let origKey = key;

// convert string shorthand to full ResourceReference
if (typeof value === "string" && value.match(/^.+?::/)) {
let [service, key, type, opts] = value.split('::');
let [service, key, type, opts] = value.split(/(?<!AWS)::/);
type = type || "dynamic";
value = {
service,
Expand All @@ -160,6 +167,11 @@ export class ConfigurationBuilder<T> {
return all;
}, {}))
};

// If it isn't a valid reference, set it back
if (!this.isResourceReference(value)) {
value = root[origKey];
}
}

if (this.isResourceReference(value)) {
Expand Down Expand Up @@ -211,10 +223,10 @@ export class ConfigurationBuilder<T> {
}
}
private isResourceReference(value: any): boolean {
return value != null && typeof value === "object" && value.service && value.key && value.type && ConfigurationBuilder.Resolvers[value.service];
return value != null && typeof value === "object" && value.service && value.key && value.type && ConfigurationBuilder.Resolvers[value.service] != null;
}

static Resolvers = {
static Resolvers: Record<string, (ref: ResourceReference, cache: any) => any> = {
// ssm: (ref: ResourceReference) => {
// return process.env[`RS_ssm::${resolveKeywords(ref.key, ref.options)}`];
// },
Expand Down Expand Up @@ -256,7 +268,7 @@ export class ConfigurationBuilder<T> {
};
}

function resolveKeywords(template: string, data: any) {
export function resolveKeywords(template: string, data: any) {
const name = template.replace(/\${(.*?)}/g, function (match, field) {
let value = getDataSafe(data, field);
if (value != null && typeof value === "object") {
Expand All @@ -266,7 +278,7 @@ function resolveKeywords(template: string, data: any) {
}).replace(/[_-]{2,}/g, "");
return name;
}
function getDataSafe(data = {}, path = "") {
export function getDataSafe(data = {}, path = "") {
const pathArray = path.split(".").filter(a => a !== "");
if (pathArray.length === 0) {
return data;
Expand All @@ -281,7 +293,7 @@ const nullRegex = /^null$/;
const undefinedRegex = /^undefined$/;
const jsonRegex = /^{(.|\n)*}$/;

function inferTypes(node) {
export function inferTypes(node) {
let type = typeof node;
if (Array.isArray(node)) {
for (let i = 0; i < node.length; i++) {
Expand Down
Loading