diff --git a/.gitignore b/.gitignore index b986779..1fa1be5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ node_modules -__generated +src/__generated *.log -dist +lib docs .env diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..85c03a0 --- /dev/null +++ b/.npmignore @@ -0,0 +1,9 @@ +.github +node_modules +src +.env +.gitignore +.esbuild.js +openapitools.json +swagger.yml +tsconfig.json diff --git a/esbuild.js b/esbuild.js new file mode 100644 index 0000000..8ddfa1f --- /dev/null +++ b/esbuild.js @@ -0,0 +1,16 @@ +const esbuild = require("esbuild"); + +const { nodeExternalsPlugin } = require("esbuild-node-externals"); + +esbuild + .build({ + entryPoints: ["./src/index.ts"], + outfile: "lib/index.js", + bundle: true, + minify: true, + platform: "node", + sourcemap: true, + target: "node14", + plugins: [nodeExternalsPlugin()], + }) + .catch(() => process.exit(1)); diff --git a/package.json b/package.json index b4ccadd..b2623ec 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { "name": "@democracy-deutschland/bt-dip-sdk", - "version": "0.1.0-alpha.1", + "version": "0.1.0-alpha.5", "description": "Bundestag DIP - TypeScript SDK", - "main": "dist/index.js", + "main": "lib/index.js", "author": "Manuel Ruck ", "license": "Apache-2.0", "homepage": "https://github.com/demokratie-live/bt-dip-sdk", "repository": "https://github.com/demokratie-live/bt-dip-sdk", "scripts": { - "build": "tsc", + "build": "tsc && node esbuild.js", "gen": "yarn gen-sdk && yarn gen-docs", "gen-sdk": "openapi-generator-cli generate -o ./src/__generated -i ./swagger.yml -g typescript-axios --additional-properties=useSingleRequestParameter=true", "gen-docs": "typedoc --out docs src/index.ts", @@ -18,6 +18,8 @@ "@openapitools/openapi-generator-cli": "^2.3.3", "@types/node": "^15.12.2", "dotenv": "^10.0.0", + "esbuild": "^0.12.8", + "esbuild-node-externals": "^1.2.0", "ts-node-dev": "^1.1.6", "typedoc": "^0.20.36", "typescript": "4.2" diff --git a/src/tests/usage.ts b/src/tests/usage.ts index 2beb122..06c7cec 100644 --- a/src/tests/usage.ts +++ b/src/tests/usage.ts @@ -1,4 +1,5 @@ import { DipApi, Configuration } from "../index"; +import { VorgangResponse } from "../__generated"; const config = new Configuration({ apiKey: `ApiKey ${process.env.API_KEY}`, @@ -6,10 +7,21 @@ const config = new Configuration({ const api = new DipApi(config); -api - .getVorgaenge({ - fDatumStart: "2020-06-01", - fDatumEnd: "2020-06-20", - }) - .then(({ data }) => console.log(data)) - .catch(console.error); +let cursor: string | undefined = undefined; + +(async () => { + let hasNext: boolean = true; + let counter = 0; + while (hasNext) { + const { data } = (await api.getVorgaenge({ + cursor, + })) as any; + hasNext = cursor !== data.cursor; + cursor = data.cursor; + counter += data.documents.length; + + console.log( + `-${data.cursor}- ${counter}/${(data as VorgangResponse).numFound}` + ); + } +})(); diff --git a/tsconfig.json b/tsconfig.json index c83ec51..e1ebc0a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,10 +11,11 @@ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ "declaration": true /* Generates corresponding '.d.ts' file. */, + "emitDeclarationOnly": true, "declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */, "sourceMap": true /* Generates corresponding '.map' file. */, // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "./dist" /* Redirect output structure to the directory. */, + "outDir": "./lib" /* Redirect output structure to the directory. */, // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ @@ -69,5 +70,6 @@ "skipLibCheck": true /* Skip type checking of declaration files. */, "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ }, + "include": ["src"], "exclude": ["node_moddules", "src/__generated"] } diff --git a/yarn.lock b/yarn.lock index 9fd06f1..e9402f6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -429,6 +429,19 @@ error-ex@^1.2.0, error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" +esbuild-node-externals@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/esbuild-node-externals/-/esbuild-node-externals-1.2.0.tgz#7bdbc370b0e983737c3807dea377d7b08ac55f14" + integrity sha512-miyxgCJrAGp86WZX080EF+3eHsey8vJTfQEOZ3+oCmAm0FrlQSg4SPr2XHSi6kVFQJD/iqaF81ub3hz4WQca2A== + dependencies: + find-up "5.0.0" + tslib "2.1.0" + +esbuild@^0.12.8: + version "0.12.8" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.12.8.tgz#ac90da77cb3bfbf49ab815200bcef7ffe1a3348f" + integrity sha512-sx/LwlP/SWTGsd9G4RlOPrXnIihAJ2xwBUmzoqe2nWwbXORMQWtAGNJNYLBJJqa3e9PWvVzxdrtyFZJcr7D87g== + escalade@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" @@ -467,6 +480,14 @@ fill-range@^7.0.1: dependencies: to-regex-range "^5.0.1" +find-up@5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc" + integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng== + dependencies: + locate-path "^6.0.0" + path-exists "^4.0.0" + find-up@^1.0.0: version "1.1.2" resolved "https://registry.yarnpkg.com/find-up/-/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f" @@ -752,6 +773,13 @@ load-json-file@^1.0.0: pinkie-promise "^2.0.0" strip-bom "^2.0.0" +locate-path@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-6.0.0.tgz#55321eb309febbc59c4801d931a72452a681d286" + integrity sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw== + dependencies: + p-locate "^5.0.0" + lodash@4.17.21, lodash@^4.17.21: version "4.17.21" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" @@ -919,6 +947,20 @@ os-tmpdir@~1.0.2: resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ= +p-limit@^3.0.2: + version "3.1.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b" + integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ== + dependencies: + yocto-queue "^0.1.0" + +p-locate@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-5.0.0.tgz#83c8315c6785005e3bd021839411c9e110e6d834" + integrity sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw== + dependencies: + p-limit "^3.0.2" + parse-json@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-2.2.0.tgz#f480f40434ef80741f8469099f8dea18f55a4dc9" @@ -943,6 +985,11 @@ path-exists@^2.0.0: dependencies: pinkie-promise "^2.0.0" +path-exists@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" + integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== + path-is-absolute@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" @@ -1333,6 +1380,11 @@ tslib@1.13.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.13.0.tgz#c881e13cc7015894ed914862d276436fa9a47043" integrity sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q== +tslib@2.1.0, tslib@~2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a" + integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A== + tslib@2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.2.0.tgz#fb2c475977e35e241311ede2693cee1ec6698f5c" @@ -1343,11 +1395,6 @@ tslib@^1.9.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== -tslib@~2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a" - integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A== - type-fest@^0.21.3: version "0.21.3" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37" @@ -1481,3 +1528,8 @@ yn@3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q== + +yocto-queue@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" + integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==