diff --git a/typescript/argsTest/README.md b/typescript/argsTest/README.md new file mode 100644 index 0000000..08088a5 --- /dev/null +++ b/typescript/argsTest/README.md @@ -0,0 +1,54 @@ +# Sequence returns input in hex format + +## Running + +Open three terminals and run the following commands: + +### The First Terminal + +```bash +# start sth by executing command... +scramjet-transform-hub + +# ...or use script +cd transform-hub +npm run start -P 8000 +``` + +### The Second terminal + +```bash +# go to 'hexdump' directory +cd samples/hexdump + +# install dependencies +npm install + +# transpile TS->JS and copy node_modules and package.json to dist/ +npm run build + +# deploy the Sequence from the dist/ directory, which contains transpiled code, package.json and node_modules +si seq deploy dist +# copy instance _id - you'll use this in 3rd terminal window + +# see the Instance output +si inst output - +``` + +### The third terminal + +```bash +# replace INSTANCE_ID with actual instance ID and pipe scramjet.ico as binary to instance input +si inst input scramjet.ico -t application/octet-stream + +# In another terminal +si inst output +``` + +Check output in second terminal to see hex format of scramjet.ico file. + +## Expected output + +```bash +0000010001001010000001002000680400001600000028000000100000002000000001002000000000000004000000000000000000000000000000000000fffffffffffffffffffffffff9fbffffe1eefdfffffffffffefeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe9f3feffffffffffcce2fcffd7e9fcfffffffdfffdfdfdfffefefdfffefdfcfffffffefffffffffffffffffffffffffffffffffffffffffffefeffffffffffffddecfdffc0dcfbffa3caf7ff7cb5f5ffe8f4fffffffffffffefefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffefeffffffffffffa6ccf8ff4198f9ff3896ffffaca39effe7c39ffff0e4daffe6ceb8fffaf5f0fffffffffffffffefffffffffffffffffffffffffffffffffffefeffffffffffffe4f1ffff6c9fdbffa98666ffbb6c1fffb06822ffb46b26ffb0641cfff1e3d5fffffffffffefefdfffffffffffffffffffffffffffffffffffffffffffefefeffffffffffc98d51ffa95300ffb3702fffb7702dffb56f2bffb56d29fff0e2d5fffffffffffefefdfffffffffffffffffffffffffffffffffffffffffffffefeffffffffffbe8854ffa5580cffad641dffb6702effb56f2bffb36a24ffefdfd0fffffffffffefdfdfffffffffffffffffffffffffffffffffffefdfcffffffffffe2c8b0ffa14f00ffab6118ffaa6018ffaf6823ffb7712fffb26822ffedddccfffffffffffefdfdfffffffffffffffffffffffffffffffffffefefdffffffffffe9d6c3ffbf864fffaa5f15ffa45405ffa85c12ffb4702effb1661effdcbb9afffffffffffefdfcfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0e3d7ffd0a77effae6620ffa85c12ffb46d2affbf8146fffdfbf8fffffffffffffffefffffffffffffffffffffffffffffffffffffffffffefdfdfffefefdfffffefefffffffffff3e8deffb26e2cffab6017ffb46c26ffe5ccb4fffffffffffefdfcfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffefdfdfffdfcfafffffffffff5ece3ffb57434ffa95b10ffca9766fffffffffffffefefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffefdfcfffffffffff6eee7ffb7793bffae631bfff1e3d5fffffffffffefefdfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffefdfcfffffffffff8f2ecffb77738ffcd9d6ffffffffffffefdfcfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffefdfcfffffffffff7f1ebffc69361fff4e9defffffffffffefefdfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffefdfcfffffffffff5ebe2ffecdbcafffffffffffefefeff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +``` diff --git a/typescript/argsTest/package.json b/typescript/argsTest/package.json new file mode 100644 index 0000000..59288b8 --- /dev/null +++ b/typescript/argsTest/package.json @@ -0,0 +1,41 @@ +{ + "name": "@scramjet/args_test", + "version": "0.22.0", + "description": "Testing app for arg params passed to sth", + "keywords": ["dump", "hex", "streaming"], + "main": "index.js", + "args": [1, {"objectKey": "objectValue"}, "testString"], + "scripts": { + "build": "tsc -p tsconfig.json", + "postbuild": "cp package.json dist/ && (cd dist && npm i --omit=dev)", + "pack": "si seq pack ./dist/", + "clean": "rm -rf ./dist ./*.tar.gz", + "test": "ts-node ./test", + "pack:pub": "DIST_DIR=${DIST_DIR:-.}; si seq pack ./dist -o ${DIST_DIR}/$(basename $(readlink -f ../))-$(basename $(readlink -f .)).tar.gz" + }, + "assets": [ + "scramjet.ico" + ], + "engines": { + "node": ">=10" + }, + "scramjet": { + "image": "node" + }, + "author": "Eryk ", + "license": "GPL-3.0", + "devDependencies": { + "@scramjet/types": "^0.26.1", + "@scramjet/cli": "^0.26.1", + "@types/node": "15.12.5", + "ts-node": "^10.9.1", + "typescript": "^4.5.5" + }, + "dependencies": { + "scramjet": "^4.36.6" + }, + "repository": { + "type": "git", + "url": "https://github.com/scramjetorg/transform-hub.git" + } +} diff --git a/typescript/argsTest/scramjet.ico b/typescript/argsTest/scramjet.ico new file mode 100644 index 0000000..b685b3d Binary files /dev/null and b/typescript/argsTest/scramjet.ico differ diff --git a/typescript/argsTest/src/index.ts b/typescript/argsTest/src/index.ts new file mode 100644 index 0000000..d501264 --- /dev/null +++ b/typescript/argsTest/src/index.ts @@ -0,0 +1,13 @@ +import { PassThrough } from "stream"; + +const app = async function (input, argNumber, argObject, argString) { + const outputStream = new PassThrough(); + input.pipe(outputStream); + + this.logger.debug(`argNumber: ${argNumber}`); + this.logger.debug(`argObject: ${JSON.stringify(argObject)}`); + this.logger.debug(`argString: ${argString}`); + return outputStream; +}; + +export default app; diff --git a/typescript/argsTest/test/index.ts b/typescript/argsTest/test/index.ts new file mode 100644 index 0000000..331de5a --- /dev/null +++ b/typescript/argsTest/test/index.ts @@ -0,0 +1,17 @@ +import { createReadStream } from "fs"; +import app from "../src"; + +async function runTest() { + const context = { + logger: { + debug: console.log, + error: console.error, + } + } + + const readFile = createReadStream("scramjet.ico"); + const read = app.bind(context); + (await read(readFile)).on("data", chunk => console.log(chunk)); +} + +runTest(); diff --git a/typescript/argsTest/tsconfig.json b/typescript/argsTest/tsconfig.json new file mode 100644 index 0000000..0e15de0 --- /dev/null +++ b/typescript/argsTest/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "outDir": "./dist", + "esModuleInterop": true, + "allowSyntheticDefaultImports": true + }, + "include": ["./src"], + "exclude": ["node_modules"] +}