diff --git a/.babelrc b/.babelrc deleted file mode 100644 index e5803af..0000000 --- a/.babelrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "presets": [ - [ - "@babel/preset-env", - { - "targets": ["last 2 versions"] - } - ] - ] -} diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index e97a08c..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,166 +0,0 @@ -{ - "root": true, - "parser": "@babel/eslint-parser", - - "parserOptions": { - "ecmaVersion": 7, - "ecmaFeatures": { - "experimentalObjectRestSpread": true, - "jsx": true - }, - "sourceType": "module" - }, - - "ignorePatterns": ["lib/*", "docs/*", "*.spec.js*"], - - "env": { - "browser": true, - "es6": true, - "mocha": true, - "node": true, - "jest": true - }, - - "plugins": [ - "promise", - "jest" - ], - - "globals": { - "document": false, - "navigator": false, - "window": false, - "jest/globals": true - }, - - "rules": { - "accessor-pairs": "error", - "arrow-spacing": ["error", { "before": true, "after": true }], - "block-spacing": ["error", "always"], - "brace-style": ["error", "1tbs", { "allowSingleLine": true }], - "camelcase": ["warn", { "properties": "always" }], - "comma-dangle": ["error", "never"], - "comma-spacing": ["error", { "before": false, "after": true }], - "comma-style": ["error", "last"], - "constructor-super": "error", - "curly": ["error", "multi-line"], - "dot-location": ["error", "property"], - "eol-last": "error", - "eqeqeq": ["error", "allow-null"], - "func-call-spacing": ["error", "never"], - "handle-callback-err": ["error", "^(err|error)$" ], - "indent": ["error", 2, { "SwitchCase": 1 }], - "key-spacing": ["error", { "beforeColon": false, "afterColon": true }], - "keyword-spacing": ["error", { "before": true, "after": true }], - "new-cap": ["error", { "newIsCap": true, "capIsNew": false }], - "new-parens": "error", - "no-array-constructor": "error", - "no-caller": "error", - "no-class-assign": "error", - "no-cond-assign": "error", - "no-const-assign": "error", - "no-constant-condition": ["error", { "checkLoops": false }], - "no-control-regex": "error", - "no-debugger": "error", - "no-delete-var": "error", - "no-dupe-args": "error", - "no-dupe-class-members": "error", - "no-dupe-keys": "error", - "no-duplicate-case": "error", - "no-duplicate-imports": "error", - "no-empty-character-class": "error", - "no-empty-pattern": "error", - "no-eval": "error", - "no-ex-assign": "error", - "no-extend-native": "error", - "no-extra-bind": "error", - "no-extra-boolean-cast": "error", - "no-extra-parens": ["error", "functions"], - "no-fallthrough": "error", - "no-floating-decimal": "error", - "no-func-assign": "error", - "no-global-assign": "error", - "no-implied-eval": "error", - "no-inner-declarations": ["error", "functions"], - "no-invalid-regexp": "error", - "no-irregular-whitespace": "error", - "no-iterator": "error", - "no-label-var": "error", - "no-labels": ["error", { "allowLoop": false, "allowSwitch": false }], - "no-lone-blocks": "error", - "no-mixed-spaces-and-tabs": "error", - "no-multi-spaces": "error", - "no-multi-str": "error", - "no-multiple-empty-lines": ["error", { "max": 1 }], - "no-native-reassign": "error", - "no-negated-in-lhs": "error", - "no-new": "error", - "no-new-func": "error", - "no-new-object": "error", - "no-new-require": "error", - "no-new-symbol": "error", - "no-new-wrappers": "error", - "no-obj-calls": "error", - "no-octal": "error", - "no-octal-escape": "error", - "no-path-concat": "error", - "no-proto": "error", - "no-redeclare": "error", - "no-regex-spaces": "error", - "no-return-assign": ["error", "except-parens"], - "no-self-assign": "error", - "no-self-compare": "error", - "no-sequences": "error", - "no-shadow-restricted-names": "error", - "no-sparse-arrays": "error", - "no-tabs": "error", - "no-template-curly-in-string": "error", - "no-this-before-super": "error", - "no-throw-literal": "error", - "no-trailing-spaces": "off", - "no-undef": "error", - "no-undef-init": "error", - "no-unexpected-multiline": "error", - "no-unmodified-loop-condition": "error", - "no-unneeded-ternary": ["error", { "defaultAssignment": false }], - "no-unreachable": "error", - "no-unsafe-finally": "error", - "no-unsafe-negation": "error", - "no-unused-vars": ["warn", { "vars": "all", "args": "none" }], - "no-useless-call": "error", - "no-useless-computed-key": "error", - "no-useless-constructor": "error", - "no-useless-escape": "error", - "no-useless-rename": "error", - "no-whitespace-before-property": "error", - "no-with": "error", - "object-property-newline": ["error", { "allowMultiplePropertiesPerLine": true }], - "one-var": ["error", { "initialized": "never" }], - "operator-linebreak": ["error", "after", { "overrides": { "?": "before", ":": "before", "||": "before", "&&": "before" } }], - "quotes": ["error", "double", { "avoidEscape": true, "allowTemplateLiterals": true }], - "rest-spread-spacing": ["error", "never"], - "semi": ["error", "always"], - "semi-spacing": ["error", { "before": false, "after": true }], - "space-before-blocks": ["error", "always"], - "space-before-function-paren": ["warn", {"anonymous": "always", "named": "never"}], - "space-in-parens": ["error", "never"], - "space-infix-ops": "error", - "space-unary-ops": ["error", { "words": true, "nonwords": false }], - "spaced-comment": ["warn", "always", { "line": { "markers": ["*package", "!", ","] }, "block": { "balanced": true, "markers": ["*package", "!", ","], "exceptions": ["*"] } }], - "template-curly-spacing": ["error", "never"], - "unicode-bom": ["error", "never"], - "use-isnan": "error", - "valid-typeof": "error", - "wrap-iife": ["error", "any", { "functionPrototypeMethods": true }], - "yield-star-spacing": ["error", "both"], - "yoda": ["error", "never"], - - "promise/param-names": "error", - - "jest/no-disabled-tests": "warn", - "jest/no-focused-tests": "error", - "jest/no-identical-title": "error", - "jest/prefer-to-have-length": "warn", - "jest/valid-expect": "error" - } -} \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2ed4a90 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,32 @@ +name: CI + +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +jobs: + lint-and-test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js from .nvmrc + uses: actions/setup-node@v4 + with: + node-version-file: ".nvmrc" + cache: "npm" + + - name: Install dependencies + run: npm ci + + - name: Run linting + run: npm run lint + + - name: Run format check + run: npm run format:check + + - name: Run tests + run: npm run test diff --git a/.jdoc.json b/.jdoc.json index 470f87b..b61bbac 100644 --- a/.jdoc.json +++ b/.jdoc.json @@ -1,7 +1,7 @@ { "templates": { - "default": { - "includeDate": false - } + "default": { + "includeDate": false + } } -} \ No newline at end of file +} diff --git a/.nvmrc b/.nvmrc index 80a9956..8ef0a52 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v20.16.0 +v24.11.1 diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..acc9023 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,6 @@ +node_modules +docs +dist +.git +package-lock.json +src/types.d.ts diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..b266ef3 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "semi": true, + "singleQuote": false, + "trailingComma": "none", + "printWidth": 120, + "tabWidth": 2 +} diff --git a/CHANGELOG.md b/CHANGELOG.md index f4ca868..e9f6fbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,100 +1,118 @@ # Release Notes +## 3.0.0 + +This Version includes several changes for a more modern JavaScript/TypeScript development experience. + +- migrated from CommonJS to ES Modules (ESM) - converted all `require()` to `import` statements and `module.exports` to `export` statements +- removed Babel compilation and dependencies (Node 18+ supports ESM natively) +- removed `./lib` folder - source files are now the distribution +- simplified build process - only generates `./docs` and TS type definitions but now in `./src` folder +- replaced jest with faster more modern vitest +- added Prettier for consistent code formatting (integrated with ESLint) +- removed `node-fetch` - using native global `fetch` (Node 18+) +- changed npm script `prepublishOnly` to `build` because this is doing all the necessary steps to prepare the change for publishing via git +- removed `sync-request` dependency and all synchronous blocking calls - now all operations are async using `async/await` and native `fetch` API + +### Migration Guide from v2.x to v3.0.0 + +See [migration guide](https://github.com/campudus/grud-structorizer/blob/HEAD/migration_v2_to_v3.md) for details. + ## 2.0.1 -* fixed `ColumnBuilder.showMemberColumns` method to return the `ColumnBuilder` instance +- fixed `ColumnBuilder.showMemberColumns` method to return the `ColumnBuilder` instance ## 2.0.0 -* **BREAKING CHANGE:** Upgraded Node to v20 and Babel to v7. This might break your build process if you are using an older version of Node or Babel. -* Upgraded Eslint to v8 and Jest to v29. +- **BREAKING CHANGE:** Upgraded Node to v20 and Babel to v7. This might break your build process if you are using an older version of Node or Babel. +- Upgraded Eslint to v8 and Jest to v29. ## 1.9.8 -* added method `.archiveCascade` to `ConstraintBuilder` -* added method `.finalCascade` to `ConstraintBuilder` -* added method `.decimalDigits` to `ColumnBuilder` -* added method `.showMemberColumns` to `ColumnBuilder` +- added method `.archiveCascade` to `ConstraintBuilder` +- added method `.finalCascade` to `ConstraintBuilder` +- added method `.decimalDigits` to `ColumnBuilder` +- added method `.showMemberColumns` to `ColumnBuilder` ## 1.9.7 -* added `AsyncApi` to implement the async version of the `.doCall` method +- added `AsyncApi` to implement the async version of the `.doCall` method ## 1.9.6 -* added type `"taxonomy"` to `TableBuilder` +- added type `"taxonomy"` to `TableBuilder` ## 1.9.5 -* added method `.hidden` to `ColumnBuilder` -* added method `.minLength` to `ColumnBuilder` -* added method `.maxLength` to `ColumnBuilder` +- added method `.hidden` to `ColumnBuilder` +- added method `.minLength` to `ColumnBuilder` +- added method `.maxLength` to `ColumnBuilder` ## 1.9.4 -* replaced old lib/syncApi.js by the new case-sensitive version lib/SyncApi.js +- replaced old lib/syncApi.js by the new case-sensitive version lib/SyncApi.js ## 1.9.2 -* added `headers` parameter to options in backward compatible manner (cookies and headers object will be merged). This adds the ability to pass for example authorization bearer to SyncApi (e.g.`{ "headers": { "Authorization": "Bearer eyJhbGciOiJSU...C6XZsFhVsxFw"}`) +- added `headers` parameter to options in backward compatible manner (cookies and headers object will be merged). This adds the ability to pass for example authorization bearer to SyncApi (e.g.`{ "headers": { "Authorization": "Bearer eyJhbGciOiJSU...C6XZsFhVsxFw"}`) ## 1.9.1 -* added property `rowId` to methods `getRow` and `getRows` so it can be used for further manipulation like updates/deletions/etc. +- added property `rowId` to methods `getRow` and `getRows` so it can be used for further manipulation like updates/deletions/etc. ## 1.9.0 -* added method `convertColumnToMultilanguage` and `convertColumnToSinglelanguage` to `Table` +- added method `convertColumnToMultilanguage` and `convertColumnToSinglelanguage` to `Table` ## 1.8.0 -* added tests for `Table` -* added method `getRows` for `Table` which returns an array of row objects zipped with column names -* added method `getRow` for `Table` returns a single row object depending on the parameter `id` +- added tests for `Table` +- added method `getRows` for `Table` which returns an array of row objects zipped with column names +- added method `getRow` for `Table` returns a single row object depending on the parameter `id` ## 1.7.1 -* fix bug in `Table.createRowByObj` if columnName is a special word like 'length' -* fix typos in `package.json` +- fix bug in `Table.createRowByObj` if columnName is a special word like 'length' +- fix typos in `package.json` ## 1.7.0 -* add ability to configure `formatPattern` on group columns +- add ability to configure `formatPattern` on group columns ## 1.6.0 -* add new parameter for options - * currently only cookies are implemented (e.g. `{ "cookies": { "cookie-name": { "value": "cookie-value" } }}`) -* rewrite syncApi to class implementation with better type support +- add new parameter for options + - currently only cookies are implemented (e.g. `{ "cookies": { "cookie-name": { "value": "cookie-value" } }}`) +- rewrite syncApi to class implementation with better type support ## 1.5.0 -* remove `minimist` dependency +- remove `minimist` dependency ## 1.4.0 -* add a typedef for `Column` -* add some tests for `ColumnBuilder` and remove `resetSchema` test -* add type definitions for multi-language methods `displayName()`, `description()`, etc. -* add argument checks for `languageType()` and `toOrdering()` +- add a typedef for `Column` +- add some tests for `ColumnBuilder` and remove `resetSchema` test +- add type definitions for multi-language methods `displayName()`, `description()`, etc. +- add argument checks for `languageType()` and `toOrdering()` ## 1.3.0 -* add TypeScript definitions +- add TypeScript definitions ## 1.2.0 -* add simple JSDoc comments and generate docs +- add simple JSDoc comments and generate docs ## 1.1.1 -* fix bug in `Table.createRowByObj` in error case +- fix bug in `Table.createRowByObj` in error case ## 1.1.0 -* add new method `toOrdering` to `ColumnBuilder` -* change npm script `prepare` to `prepublishOnly` b/c this shouldn't run on `npm install` +- add new method `toOrdering` to `ColumnBuilder` +- change npm script `prepare` to `prepublishOnly` b/c this shouldn't run on `npm install` ## 1.0.0 -* initial release +- initial release diff --git a/README.md b/README.md index c456cf7..3dbc5ba 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # grud-structorizer -Small synchronous JS SDK for building GRUD schemas +Async JS SDK for building GRUD schemas ## Documentation @@ -16,46 +16,49 @@ Currently we supports the following options: ```javascript // expressjs session cookie via cookies - const option = { "cookies": { "connect.sid": { "value":"s%3Al...PWgk;" } } } + const option = { cookies: { "connect.sid": { value: "s%3Al...PWgk;" } } }; ``` - **headers** allows to pass headers for requests ```javascript // expressjs session cookie via headers - const option = { "headers": { "Cookie": "connect.sid=s%3Al...PWgk;" } } + const option = { headers: { Cookie: "connect.sid=s%3Al...PWgk;" } }; // OAuth 2.0 bearer token - const option = { "headers": { "Authorization": "Bearer eyJhbG...ciOiJSUz" } } + const option = { headers: { Authorization: "Bearer eyJhbG...ciOiJSUz" } }; ``` ## Example ```javascript -const grudStructorizer = require('grud-structorizer'); +import grudStructorizer from "grud-structorizer"; -const options = { }; +const options = {}; const structorizer = grudStructorizer("http://localhost:8181", options); +const { TableBuilder, ColumnBuilder, ConstraintBuilder } = structorizer; -const TableBuilder = structorizer.TableBuilder; -const ColumnBuilder = structorizer.ColumnBuilder; -const ConstraintBuilder = structorizer.ConstraintBuilder; +const tableBuilder = new TableBuilder("newTable", "generic").displayName("de", "Neue Tabelle", "en", "New table"); +const newTable = await tableBuilder.create(); -const newTable = new TableBuilder("newTable", "generic") - .displayName("de", "Neue Tabelle", "en", "New table") - .create(); +await newTable.createColumns([new ColumnBuilder("rowIdentifier", "shorttext").displayName("de", "Name").identifier()]); +await newTable.createRowByObj({ rowIdentifier: "Test" }); +``` -newTable.createColumns([ - new ColumnBuilder("rowIdentifier", "shorttext") - .displayName("de", "Name") - .identifier() -]); +## Development -newTable.createRowByObj({rowIdentifier: "Test"}); -``` +### Making Changes + +1. **Edit source files** in `src/` directory +2. **Run build** (`npm run build`) to ensure types and docs are up to date to your changes: +3. **Publish changes** via git in a new PR + +### Migration Guide from v2.x to v3.0.0 + +See [migration guide](https://github.com/campudus/grud-structorizer/blob/HEAD/migration_v2_to_v3.md) for details. ## Changelog -See [CHANGELOG.md](https://github.com/campudus/grud-structorizer/blob/master/CHANGELOG.md) +See [CHANGELOG.md](https://github.com/campudus/grud-structorizer/blob/HEAD/CHANGELOG.md) ## License @@ -71,4 +74,4 @@ See [CHANGELOG.md](https://github.com/campudus/grud-structorizer/blob/master/CHA > distributed under the License is distributed on an "AS IS" BASIS, > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > See the License for the specific language governing permissions and -> limitations under the License. \ No newline at end of file +> limitations under the License. diff --git a/docs/Api.html b/docs/Api.html index 359540b..17ac1dd 100644 --- a/docs/Api.html +++ b/docs/Api.html @@ -29,7 +29,7 @@ @@ -77,7 +77,7 @@

new ApiSource:
@@ -234,6 +234,1564 @@
Parameters:
+

Methods

+ + + + + + +

(async) createColumn(tableId, columnObject) → {Promise.<object>}

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tableId + +
columnObject + +
+ + + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<object> + + + +
+
+ + + + + + + + + + +

(async) createColumns(tableId, columnObjArray) → {Promise.<Array>}

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tableId + +
columnObjArray + +
+ + + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Array> + + + +
+
+ + + + + + + + + + +

(async) createRow(tableId, columnIds, values) → {Promise.<number>}

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tableId + +
columnIds + +
values + +
+ + + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<number> + + + +
+
+ + + + + + + + + + +

(async) createRows(tableId, columnIds, rows) → {Promise.<Array.<number>>}

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tableId + +
columnIds + +
rows + +
+ + + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<Array.<number>> + + + +
+
+ + + + + + + + + + +

(async) createTable(name, hidden, displayName, type, group) → {Promise.<object>}

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +string + + + + +
hidden + + +boolean + + + + +
displayName + + +object + + + + + multi-language object
type + + +string + + + + +
group + + +number + + + + +
+ + + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<object> + + + +
+
+ + + + + + + + + + +

(async) doCall(method, url, jsonopt, nonceopt) → {Promise.<object>}

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
method + + +string + + + + + + + + + + +
url + + +string + + + + + + + + + + +
json + + +object + + + + + + + <optional>
+ + + + + +
nonce + + +string + + + + + + + <optional>
+ + + + + +
+ + + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<object> + + + +
+
+ + + + + + + + + + +

(async) fetchTable(tableId, includeRowsopt) → {Promise.<(object|undefined)>}

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
tableId + + +number + + + + + + + + + + + + +
includeRows + + +boolean + + + + + + + <optional>
+ + + + + +
+ + false + +
+ + + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<(object|undefined)> + + + +
+
+ + + + + + + + + + +

(async) resetSchema(nonce) → {Promise.<void>}

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
nonce + + +string + + + + +
+ + + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<void> + + + +
+
+ + + + + + + diff --git a/docs/Api.js.html b/docs/Api.js.html index c020d3a..5fb77c9 100644 --- a/docs/Api.js.html +++ b/docs/Api.js.html @@ -29,7 +29,7 @@ @@ -45,27 +45,23 @@

Api.js

-
"use strict";
-
-const _ = require("lodash");
+            
import _ from "lodash";
 
 /**
  * @typedef {object} ApiOptions
  * @property cookies {object}
  */
 
+/**
+ *
+ */
 class Api {
-
   /**
    *
    * @param baseUrl {string}
    * @param options {ApiOptions}
    */
   constructor(baseUrl, options) {
-    if (this.constructor === Api) {
-      throw new Error("Abstract class 'Api' cannot be instantiated!");
-    }
-
     this.baseUrl = baseUrl;
     this.cookies = _.get(options, ["cookies"], {});
     this.headers = _.get(options, ["headers"], {});
@@ -73,15 +69,167 @@ 

Api.js

_getRequestHeaders() { return { - "Cookie": _.map(this.cookies, ({value}, name) => { + Cookie: _.map(this.cookies, ({ value }, name) => { return name + "=" + value || "undefined"; }).join("; "), ...this.headers }; } + + /** + * + * @param method {string} + * @param url {string} + * @param [json] {object} + * @param [nonce] {string} + * @returns {Promise<object>} + */ + async doCall(method, url, json, nonce) { + const fullUrl = nonce ? this.baseUrl + url + "?" + new URLSearchParams({ nonce }) : this.baseUrl + url; + + const options = { + method: method, + headers: this._getRequestHeaders(), + body: json ? JSON.stringify(json) : undefined + }; + + const response = await fetch(fullUrl, options); + + return response.json(); + } + + /** + * + * @param nonce {string} + * @returns {Promise<void>} + */ + async resetSchema(nonce) { + return this.doCall("POST", "/system/reset", undefined, nonce); + } + + /** + * + * @param tableId {number} + * @param [includeRows=false] {boolean} + * @returns {Promise<object|undefined>} + */ + async fetchTable(tableId, includeRows = false) { + if (typeof tableId !== "number") { + throw new Error("parameter 'tableId' should be a number"); + } + + const table = await this.doCall("GET", "/tables/" + tableId); + + delete table["id"]; + delete table["status"]; + + const columns = await this.doCall("GET", "/tables/" + tableId + "/columns"); + + delete columns["status"]; + + Object.assign(table, columns); + + if (includeRows) { + const rows = await this.doCall("GET", "/tables/" + tableId + "/rows"); + + delete rows["page"]; + delete rows["status"]; + + Object.assign(table, rows); + } + + return table; + } + + /** + * + * @param name {string} + * @param hidden {boolean} + * @param displayName {object} multi-language object + * @param type {string} + * @param group {number} + * @returns {Promise<object>} + */ + async createTable(name, hidden, displayName, type, group) { + const json = { + name: name, + hidden: typeof hidden === "boolean" ? hidden : false + }; + + if (displayName && typeof displayName === "object") { + json["displayName"] = displayName; + } + + if (type && typeof type === "string") { + json["type"] = type; + } + + if (group && typeof group === "number") { + json["group"] = group; + } + + return this.doCall("POST", "/tables", json); + } + + /** + * + * @param tableId + * @param columnObjArray + * @returns {Promise<Array>} + */ + async createColumns(tableId, columnObjArray) { + const json = { + columns: columnObjArray + }; + + return (await this.doCall("POST", "/tables/" + tableId + "/columns", json)).columns; + } + + /** + * + * @param tableId + * @param columnObject + * @returns {Promise<object>} + */ + async createColumn(tableId, columnObject) { + const json = { + columns: [columnObject] + }; + + return (await this.doCall("POST", "/tables/" + tableId + "/columns", json)).columns[0]; + } + + /** + * + * @param tableId + * @param columnIds + * @param values + * @returns {Promise<number>} + */ + async createRow(tableId, columnIds, values) { + return (await this.createRows(tableId, columnIds, [values]))[0]; + } + + /** + * + * @param tableId + * @param columnIds + * @param rows + * @returns {Promise<Array<number>>} + */ + async createRows(tableId, columnIds, rows) { + const json = { + columns: columnIds.map((columnId) => ({ id: columnId })), + rows: rows.map((rowValues) => ({ values: rowValues })) + }; + + const result = await this.doCall("POST", "/tables/" + tableId + "/rows", json); + + return result.rows.map((row) => row.id); + } } -module.exports = Api; +export default Api;
diff --git a/docs/AsyncApi.html b/docs/AsyncApi.html deleted file mode 100644 index fb956ee..0000000 --- a/docs/AsyncApi.html +++ /dev/null @@ -1,511 +0,0 @@ - - - - - - AsyncApi - Documentation - - - - - - - - - - - - - - - - - - - - -
- -

AsyncApi

- - - - - - - -
- -
- -

- - AsyncApi - -

- - -
- -
- -
- - - - - -

new AsyncApi(baseUrl, options)

- - - - - - -
- - - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
baseUrl - - -string - - - - -
options - - -ApiOptions - - - - -
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -

Methods

- - - - - - -

(async) doCall(method, url, jsonopt, nonceopt)

- - - - - - -
- - - -
Source:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeAttributesDescription
method - - -string - - - - - - - - - - -
url - - -string - - - - - - - - - - -
json - - -object - - - - - - - <optional>
- - - - - -
nonce - - -string - - - - - - - <optional>
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - - - -
- -
- - - - - - - - - - - \ No newline at end of file diff --git a/docs/AsyncApi.js.html b/docs/AsyncApi.js.html deleted file mode 100644 index c32fc38..0000000 --- a/docs/AsyncApi.js.html +++ /dev/null @@ -1,118 +0,0 @@ - - - - - - AsyncApi.js - Documentation - - - - - - - - - - - - - - - - - - - - -
- -

AsyncApi.js

- - - - - - - -
-
-
"use strict";
-
-const fetch = require("node-fetch");
-
-const Api = require("./Api");
-
-/**
- *
- */
-class AsyncApi extends Api {
-
-  /**
-   *
-   * @param baseUrl {string}
-   * @param options {ApiOptions}
-   */
-  // eslint-disable-next-line no-useless-constructor
-  constructor(baseUrl, options) {
-    super(baseUrl, options);
-  }
-
-  /**
-   *
-   * @param method {string}
-   * @param url {string}
-   * @param [json] {object}
-   * @param [nonce] {string}
-   */
-  async doCall(method, url, json, nonce) {
-    const fullUrl = nonce
-      ? this.baseUrl + url + "?" + new URLSearchParams({nonce})
-      : this.baseUrl + url;
-
-    const options = {
-      method: method,
-      headers: this._getRequestHeaders(),
-      body: json ? JSON.stringify(json) : undefined
-    };
-
-    const response = await fetch(fullUrl, options);
-
-    return response.json();
-  }
-}
-
-module.exports = AsyncApi;
-
-
-
- - - - - - -
- -
- - - - - - - - - - - diff --git a/docs/ColumnBuilder.html b/docs/ColumnBuilder.html index a58e7a5..aaf097c 100644 --- a/docs/ColumnBuilder.html +++ b/docs/ColumnBuilder.html @@ -29,7 +29,7 @@ @@ -77,7 +77,7 @@

new Colu
Source:
@@ -254,7 +254,7 @@

addConst
Source:
@@ -408,7 +408,7 @@

decimalD
Source:
@@ -559,7 +559,7 @@

descriptio
Source:
@@ -722,7 +722,7 @@

displayNam
Source:
@@ -885,7 +885,7 @@

formatPa
Source:
@@ -1036,7 +1036,7 @@

groupsSource:
@@ -1187,7 +1187,7 @@

hiddenSource:
@@ -1358,7 +1358,7 @@

identifier<
Source:
@@ -1529,7 +1529,7 @@

languageT
Source:
@@ -1724,7 +1724,7 @@