diff --git a/application/example/constraints/andoperator.mjs b/application/example/constraints/andoperator.mjs new file mode 100644 index 0000000000000000000000000000000000000000..0c930c4e2f5b35c0e52bde5293534159b206c158 --- /dev/null +++ b/application/example/constraints/andoperator.mjs @@ -0,0 +1,17 @@ +import {Valid} from '@schukai/monster/source/constraints/valid.mjs'; +import {Invalid} from '@schukai/monster/source/constraints/invalid.mjs'; +import {AndOperator} from '@schukai/monster/source/constraints/andoperator.mjs'; + +new AndOperator( + new Valid(), new Valid()).isValid() + .then(() => console.log(true)) + .catch(() => console.log(false)); +// ↦ true + +new AndOperator( + new Invalid(), new Valid()).isValid() + .then(() => console.log(true)) + .catch(() => console.log(false)); +// ↦ false + + diff --git a/application/example/constraints/invalid.mjs b/application/example/constraints/invalid.mjs new file mode 100644 index 0000000000000000000000000000000000000000..61a9e09e5b6d4c56292630d8fed69f6a903c79d2 --- /dev/null +++ b/application/example/constraints/invalid.mjs @@ -0,0 +1,6 @@ +import {Invalid} from '@schukai/monster/source/constraints/invalid.mjs'; + +new Invalid().isValid() + .then(() => console.log(true)) + .catch(() => console.log(false)); +// ↦ false \ No newline at end of file diff --git a/application/example/constraints/isarray.mjs b/application/example/constraints/isarray.mjs new file mode 100644 index 0000000000000000000000000000000000000000..3a92e3c84ebb9704000ba89b953f8fff24396b3f --- /dev/null +++ b/application/example/constraints/isarray.mjs @@ -0,0 +1,11 @@ +import {IsArray} from '@schukai/monster/source/constraints/isarray.mjs'; + +new IsArray() + .isValid([]) + .then(() => console.log(true)); +// ↦ true + +new IsArray() + .isValid(99) + .catch(e => console.log(e)); +// ↦ 99 \ No newline at end of file diff --git a/application/example/constraints/isobject.mjs b/application/example/constraints/isobject.mjs new file mode 100644 index 0000000000000000000000000000000000000000..cbca5bf7a8b2c463ca47dd12e4c76a1f800989fc --- /dev/null +++ b/application/example/constraints/isobject.mjs @@ -0,0 +1,12 @@ +import {IsObject} from '@schukai/monster/source/constraints/isobject.mjs'; + +new IsObject() + .isValid({}) + .then(() => console.log(true)); +// ↦ true + + +new IsObject() + .isValid(99) + .catch(e => console.log(e)); +// ↦ 99 \ No newline at end of file diff --git a/application/example/constraints/oroperator.mjs b/application/example/constraints/oroperator.mjs new file mode 100644 index 0000000000000000000000000000000000000000..c68e987c0cda82bf6c3a8008e8f16ad5c4877229 --- /dev/null +++ b/application/example/constraints/oroperator.mjs @@ -0,0 +1,15 @@ +import {Valid} from '@schukai/monster/source/constraints/valid.mjs'; +import {Invalid} from '@schukai/monster/source/constraints/invalid.mjs'; +import {OrOperator} from '@schukai/monster/source/constraints/oroperator.mjs'; + +new OrOperator( + new Valid(), new Invalid()).isValid() + .then(() => console.log(true)) + .catch(() => console.log(false)); +// ↦ true + +new OrOperator( + new Invalid(), new Invalid()).isValid() + .then(() => console.log(true)) + .catch(() => console.log(false)); +// ↦ false \ No newline at end of file diff --git a/application/example/constraints/valid.mjs b/application/example/constraints/valid.mjs new file mode 100644 index 0000000000000000000000000000000000000000..df8d2dc1aa63d3ca4d6e9641e51f6d003f7afa5c --- /dev/null +++ b/application/example/constraints/valid.mjs @@ -0,0 +1,6 @@ +import {Valid} from '@schukai/monster/source/constraints/valid.mjs'; + +new Valid().isValid() + .then(() => console.log(true)) + .catch(() => console.log(false)); +// ↦ true diff --git a/application/example/data/buildmap.mjs b/application/example/data/buildmap.mjs new file mode 100644 index 0000000000000000000000000000000000000000..8bb28084615511614f8afcb9ec408f382d917b57 --- /dev/null +++ b/application/example/data/buildmap.mjs @@ -0,0 +1,67 @@ +import {buildMap} from '@schukai/monster/source/data/buildmap.mjs'; +// a typical data structure as reported by an api + +let map; +let obj = { + "data": [ + { + "id": 10, + "name": "Cassandra", + "address": { + "street": "493-4105 Vulputate Street", + "city": "Saumur", + "zip": "52628" + } + }, + { + "id": 20, + "name": "Holly", + "address": { + "street": "1762 Eget Rd.", + "city": "Schwalbach", + "zip": "952340" + } + }, + { + "id": 30, + "name": "Guy", + "address": { + "street": "957-388 Sollicitudin Avenue", + "city": "Panchià", + "zip": "420729" + } + } + ] +}; + +// The function is passed this data structure and with the help of the selector `'data.*'` the data to be considered are selected. +// The key is given by a simple definition `'id'` and the value is given by a template `'${name} (${address.zip} ${address.city})'`. +map = buildMap(obj, 'data.*', '${name} (${address.zip} ${address.city})', 'id'); +console.log(map); + +// ↦ Map(3) { +// '10' => 'Cassandra (52628 Saumur)', +// '20' => 'Holly (952340 Schwalbach)', +// '30' => 'Guy (420729 Panchià)' +// } + +// If no key is specified, the key from the selection, here the array index, is taken. +map = buildMap(obj, 'data.*', '${name} (${address.zip} ${address.city})'); +console.log(map); + +// ↦ Map(3) { +// '0' => 'Cassandra (52628 Saumur)', +// '1' => 'Holly (952340 Schwalbach)', +// '2' => 'Guy (420729 Panchià)' +// } + +// a filter (function(value, key) {}) can be specified to accept only defined entries. +map = buildMap(obj, 'data.*', '${name} (${address.zip} ${address.city})', 'id', function (value, key) { + return (value['id'] >= 20) ? true : false +}); +console.log(map); + +// ↦ Map(2) { +// 20 => 'Holly (952340 Schwalbach)', +// 30 => 'Guy (420729 Panchià)' +// } \ No newline at end of file diff --git a/application/example/data/datasource.mjs b/application/example/data/datasource.mjs new file mode 100644 index 0000000000000000000000000000000000000000..fbc71de8f8f981a724d6472c58fa6704cbc1ebe3 --- /dev/null +++ b/application/example/data/datasource.mjs @@ -0,0 +1,7 @@ +import {Datasource} from '@schukai/monster/source/data/datasource.mjs' + +class MyDatasource extends Datasource { + +} + +const ds = new MyDatasource(); diff --git a/application/example/data/diff.mjs b/application/example/data/diff.mjs new file mode 100644 index 0000000000000000000000000000000000000000..fae2ed65afbaee5b0c530ee306e4cdca4892912b --- /dev/null +++ b/application/example/data/diff.mjs @@ -0,0 +1,39 @@ +import {Diff} from '@schukai/monster/source/data/diff.mjs'; + +// given are two objects x and y. + +let x = { + a: 1, + b: "Hello!" +} + +let y = { + a: 2, + c: true +} + +// These two objects can be compared with each other. + +console.log(Diff(x, y)); + +// the result is then the following + +// +// [ +// { +// operator: 'update', +// path: [ 'a' ], +// first: { value: 1, type: 'number' }, +// second: { value: 2, type: 'number' } +// }, +// { +// operator: 'delete', +// path: [ 'b' ], +// first: { value: 'Hello!', type: 'string' } +// }, +// { +// operator: 'add', +// path: [ 'c' ], +// second: { value: true, type: 'boolean' } +// } +// ] diff --git a/application/example/data/pathfinder-1.mjs b/application/example/data/pathfinder-1.mjs new file mode 100644 index 0000000000000000000000000000000000000000..f6cfe5e159c7377bb256c5c2d4ced1a962a49688 --- /dev/null +++ b/application/example/data/pathfinder-1.mjs @@ -0,0 +1,23 @@ +import {Pathfinder} from '@schukai/monster/source/data/pathfinder.mjs'; + +let value = new Pathfinder({ + a: { + b: { + f: [ + { + g: false, + } + ], + } + } +}).getVia("a.b.f.0.g"); + +console.log(value); +// ↦ false + +try { + new Pathfinder({}).getVia("a.b.f.0.g"); +} catch (e) { + console.log(e.toString()); + // ↦ Error: the journey is not at its end (b.f.0.g) +} \ No newline at end of file diff --git a/application/example/data/pathfinder-2.mjs b/application/example/data/pathfinder-2.mjs new file mode 100644 index 0000000000000000000000000000000000000000..b90b3ac18a9efba7f53a832c7a1366cd1087b4b1 --- /dev/null +++ b/application/example/data/pathfinder-2.mjs @@ -0,0 +1,19 @@ +import {Pathfinder} from '@schukai/monster/source/data/pathfinder.mjs'; + +let p = new Pathfinder({ + a: { + x: [ + {c: 1}, {c: 2} + ], + y: true + }, + b: { + x: [ + {c: 1, d: false}, {c: 2} + ], + y: true + }, +}); + +let r = p.getVia("*.x.*.c"); +console.log(r); diff --git a/application/example/data/pipe.mjs b/application/example/data/pipe.mjs new file mode 100644 index 0000000000000000000000000000000000000000..6628a7cb024a641f6f84f597bfd904d4eef3fedb --- /dev/null +++ b/application/example/data/pipe.mjs @@ -0,0 +1,14 @@ +import {Pipe} from '@schukai/monster/source/data/pipe.mjs'; + +let obj = { + a: { + b: { + c: { + d: "world" + } + } + } +} + +console.log(new Pipe('path:a.b.c.d | toupper | prefix:Hello\\ ').run(obj)); +// ↦ Hello WORLD diff --git a/application/example/data/storage/restapi.mjs b/application/example/data/storage/restapi.mjs new file mode 100644 index 0000000000000000000000000000000000000000..983e632687fdd39e9159a5da0a8f5fb4b6a86285 --- /dev/null +++ b/application/example/data/storage/restapi.mjs @@ -0,0 +1,11 @@ +import {RestAPI} from '@schukai/monster/source/data/datasource/restapi.mjs'; + +const ds = new RestAPI({ + url: 'https://httpbin.org/get' +}, { + url: 'https://httpbin.org/post' +}); + +ds.set({flag: true}) +ds.write().then(() => console.log('done')); +ds.read().then(() => console.log('done')); \ No newline at end of file diff --git a/application/example/data/transformer.mjs b/application/example/data/transformer.mjs new file mode 100644 index 0000000000000000000000000000000000000000..74b3c9fdbf62554323e42e762cc65e55acd69170 --- /dev/null +++ b/application/example/data/transformer.mjs @@ -0,0 +1,9 @@ +import {Transformer} from '@schukai/monster/source/data/transformer.mjs'; + +const transformer = new Transformer("tolower") + +console.log(transformer.run("HELLO")) +// ↦ hello + +console.log(transformer.run("WORLD")) +// ↦ world \ No newline at end of file diff --git a/application/source/constraints/abstractoperator.mjs b/application/source/constraints/abstractoperator.mjs index 88878cdab5616e96658667af644b09e141d998d9..6b600fb655a04cf2c01557b6d5be3e59d3d51f1e 100644 --- a/application/source/constraints/abstractoperator.mjs +++ b/application/source/constraints/abstractoperator.mjs @@ -14,7 +14,8 @@ export {AbstractOperator} * * The uniform API of the constraints allows chains to be formed. * - * Operators allow you to link constraints together. for example, you can check whether a value is an object or an array. each operator has two operands that are linked together. + * Operators allow you to link constraints together. for example, you can check whether a value is + * an object or an array. each operator has two operands that are linked together. * * @license AGPLv3 * @since 1.3.0 diff --git a/application/source/constraints/andoperator.mjs b/application/source/constraints/andoperator.mjs index 61ca1fb31baeb696d7d95db5fe73747a408e2dca..cf9b2f62e53c37d47d5708f243f1a8d6b6e5f4fc 100644 --- a/application/source/constraints/andoperator.mjs +++ b/application/source/constraints/andoperator.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,7 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - import {AbstractOperator} from "./abstractoperator.mjs"; export {AndOperator} @@ -17,33 +14,9 @@ export {AndOperator} * * The uniform API of the constraints allows chains to be formed. * - * The AndOperator is used to link several contraints. The constraint is fulfilled if all constraints of the operators are fulfilled. - * - * ``` - * <script type="module"> - * import {AndOperator} from '@schukai/monster/source/constraints/andoperator.mjs'; - * new AndOperator(); - * </script> - * ``` - * - * @example - * - * import {Valid} from '@schukai/monster/source/constraints/valid.mjs'; - * import {Invalid} from '@schukai/monster/source/constraints/invalid.mjs'; - * import {AndOperator} from '@schukai/monster/source/constraints/andoperator.mjs'; - * - * new AndOperator( - * new Valid(), new Valid()).isValid() - * .then(()=>console.log(true)) - * .catch(()=>console.log(false)); - * // ↦ true - * - * new AndOperator( - * new Invalid(), new Valid()).isValid() - * .then(()=>console.log(true)) - * .catch(()=>console.log(false)); - * // ↦ false + * The AndOperator is used to link several constraints. The constraint is fulfilled if all constraints of the operators are fulfilled. * + * @externalExample ../../example/constraints/andoperator.mjs * @license AGPLv3 * @since 1.3.0 * @copyright schukai GmbH diff --git a/application/source/constraints/invalid.mjs b/application/source/constraints/invalid.mjs index f6cc8e569ab9f9148175093d3e72122b3f10ea9f..e9cc096ddd38a6b9b603c981c052de519c4d0448 100644 --- a/application/source/constraints/invalid.mjs +++ b/application/source/constraints/invalid.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,7 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - import {AbstractConstraint} from "./abstract.mjs"; export {Invalid} @@ -19,22 +16,7 @@ export {Invalid} * * The invalid constraint allows an always invalid query to be performed. this constraint is mainly intended for testing. * - * ``` - * <script type="module"> - * import {Invalid} from '@schukai/monster/source/constraints/invalid.mjs'; - * new Invalid(); - * </script> - * ``` - * - * @example - * - * import {Invalid} from '@schukai/monster/source/constraints/invalid.mjs'; - * - * new Invalid().isValid() - * .then(()=>console.log(true)) - * .catch(()=>console.log(false)); - * // ↦ false - * + * @externalExample ../../example/constraints/invalid.mjs * @license AGPLv3 * @since 1.3.0 * @copyright schukai GmbH diff --git a/application/source/constraints/isarray.mjs b/application/source/constraints/isarray.mjs index ee0be16ce2332d4d7f78efbb0eab2dd8084ed388..4dccec00ff43cd37eb630b59431c8b32bcd6a4be 100644 --- a/application/source/constraints/isarray.mjs +++ b/application/source/constraints/isarray.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,7 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - import {isArray} from "../types/is.mjs"; import {AbstractConstraint} from "./abstract.mjs"; @@ -18,27 +15,7 @@ export {IsArray} * * The uniform API of the constraints allows chains to be formed. * - * ``` - * <script type="module"> - * import {IsArray} from '@schukai/monster/source/constraints/isarray.mjs'; - * console.log(new IsArray()) - * </script> - * ``` - * - * @example - * - * import {IsArray} from '@schukai/monster/source/constraints/isarray.mjs'; - * - * new IsArray() - * .isValid([]) - * .then(()=>console.log(true)); - * // ↦ true - * - * new IsArray() - * .isValid(99) - * .catch(e=>console.log(e)); - * // ↦ 99 - * + * @externalExample ../../example/constraints/isarray.mjs * @license AGPLv3 * @since 1.3.0 * @copyright schukai GmbH diff --git a/application/source/constraints/isobject.mjs b/application/source/constraints/isobject.mjs index 39a9a3b5c9c875999e64e59011f5bad4538e877d..ef888fe1552bc6ed5d6924755ac32c1785bbc406 100644 --- a/application/source/constraints/isobject.mjs +++ b/application/source/constraints/isobject.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,7 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - import {isObject} from "../types/is.mjs"; import {AbstractConstraint} from "./abstract.mjs"; @@ -18,28 +15,7 @@ export {IsObject} * * The uniform API of the constraints allows chains to be formed. * - * ``` - * <script type="module"> - * import {IsObject} from '@schukai/monster/source/constraints/isobject.mjs'; - * console.log(new IsObject()) - * </script> - * ``` - * - * @example - * - * import {IsObject} from '@schukai/monster/source/constraints/isobject.mjs'; - * - * new IsObject() - * .isValid({}) - * .then(()=>console.log(true)); - * // ↦ true - * - * - * new IsObject() - * .isValid(99) - * .catch(e=>console.log(e)); - * // ↦ 99 - * + * @externalExample ../../example/constraints/isobject.mjs * @license AGPLv3 * @since 1.3.0 * @copyright schukai GmbH diff --git a/application/source/constraints/oroperator.mjs b/application/source/constraints/oroperator.mjs index a8858f55988e49d59a11285a00fea6576968554d..0b776a84b09103e3ed328a53d111c80cf369ffb9 100644 --- a/application/source/constraints/oroperator.mjs +++ b/application/source/constraints/oroperator.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,7 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - import {AbstractOperator} from "./abstractoperator.mjs"; export {OrOperator} @@ -19,31 +16,7 @@ export {OrOperator} * * The OrOperator is used to link several constraints. The constraint is fulfilled if one of the constraints is fulfilled. * - * ``` - * <script type="module"> - * import {OrOperator} from '@schukai/monster/source/constraint/oroperator.mjs'; - * new OrOperator(); - * </script> - * ``` - * - * @example - * - * import {Valid} from '@schukai/monster/source/constraints/valid.mjs'; - * import {Invalid} from '@schukai/monster/source/constraints/invalid.mjs'; - * import {OrOperator} from '@schukai/monster/source/constraints/oroperator.mjs'; - * - * new OrOperator( - * new Valid(), new Invalid()).isValid() - * .then(()=>console.log(true)) - * .catch(()=>console.log(false)); - * // ↦ true - * - * new OrOperator( - * new Invalid(), new Invalid()).isValid() - * .then(()=>console.log(true)) - * .catch(()=>console.log(false)); - * // ↦ false - * + * @externalExample ../../example/constraints/oroperator.mjs * @license AGPLv3 * @since 1.3.0 * @copyright schukai GmbH diff --git a/application/source/constraints/valid.mjs b/application/source/constraints/valid.mjs index 8fa2153f2d3e34aa27bc6b1fb6a043808c07a084..b2e825b125fd61391bdf982eb3f118b3e4d4eeee 100644 --- a/application/source/constraints/valid.mjs +++ b/application/source/constraints/valid.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,7 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - import {AbstractConstraint} from "./abstract.mjs"; export {Valid} @@ -19,22 +16,7 @@ export {Valid} * * The valid constraint allows an always valid query to be performed. this constraint is mainly intended for testing. * - * ``` - * <script type="module"> - * import {Valid} from '@schukai/monster/source/constraints/valid.mjs'; - * new Valid(); - * </script> - * ``` - * - * @example - * - * import {Valid} from '@schukai/monster/source/constraints/valid.mjs'; - * - * new Valid().isValid() - * .then(()=>console.log(true)) - * .catch(()=>console.log(false)); - * // ↦ true - * + * @externalExample ../../example/constraints/valid.mjs * @license AGPLv3 * @since 1.3.0 * @copyright schukai GmbH diff --git a/application/source/data/buildmap.mjs b/application/source/data/buildmap.mjs index 24134f0c5daf9e471909eae1c96502220d42c4f0..08f10a4f955a5dc1cef9e7e4531ac2e05a2764c1 100644 --- a/application/source/data/buildmap.mjs +++ b/application/source/data/buildmap.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,8 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - - import {isFunction, isObject, isString} from "../types/is.mjs"; import {validateString} from "../types/validate.mjs"; import {clone} from "../util/clone.mjs"; @@ -29,87 +25,12 @@ const PARENT = '^'; * Either a simple definition `a.b.c` or a template `${a.b.c}` can be specified as the path. * Key and value can be either a definition or a template. The key does not have to be defined. * - * ``` - * <script type="module"> - * import {buildMap} from '@schukai/monster/source/data/buildmap.mjs'; - * console.log(buildMap()) - * </script> - * ``` - * - * The templates determine the appearance of the keys and the value of the map. Either a single value `id` can be taken or a composite key `${id} ${name}` can be used. + * The templates determine the appearance of the keys and the value of the map. Either a single value + * `id` can be taken or a composite key `${id} ${name}` can be used. * * If you want to access values of the parent data set, you have to use the `^` character `${id} ${^.name}`. * - * @example - * - * import {buildMap} from '@schukai/monster/source/data/buildmap.mjs'; - * // a typical data structure as reported by an api - * - * let map; - * let obj = { - * "data": [ - * { - * "id": 10, - * "name": "Cassandra", - * "address": { - * "street": "493-4105 Vulputate Street", - * "city": "Saumur", - * "zip": "52628" - * } - * }, - * { - * "id": 20, - * "name": "Holly", - * "address": { - * "street": "1762 Eget Rd.", - * "city": "Schwalbach", - * "zip": "952340" - * } - * }, - * { - * "id": 30, - * "name": "Guy", - * "address": { - * "street": "957-388 Sollicitudin Avenue", - * "city": "Panchià", - * "zip": "420729" - * } - * } - * ] - * }; - * - * // The function is passed this data structure and with the help of the selector `'data.*'` the data to be considered are selected. - * // The key is given by a simple definition `'id'` and the value is given by a template `'${name} (${address.zip} ${address.city})'`. - * map = buildMap(obj, 'data.*', '${name} (${address.zip} ${address.city})', 'id'); - * console.log(map); - * - * // ↦ Map(3) { - * // '10' => 'Cassandra (52628 Saumur)', - * // '20' => 'Holly (952340 Schwalbach)', - * // '30' => 'Guy (420729 Panchià)' - * // } - * - * // If no key is specified, the key from the selection, here the array index, is taken. - * map = buildMap(obj, 'data.*', '${name} (${address.zip} ${address.city})'); - * console.log(map); - * - * // ↦ Map(3) { - * // '0' => 'Cassandra (52628 Saumur)', - * // '1' => 'Holly (952340 Schwalbach)', - * // '2' => 'Guy (420729 Panchià)' - * // } - * - * // a filter (function(value, key) {}) can be specified to accept only defined entries. - * map = buildMap(obj, 'data.*', '${name} (${address.zip} ${address.city})', 'id', function (value, key) { - * return (value['id'] >= 20) ? true : false - * }); - * console.log(map); - * - * // ↦ Map(2) { - * // 20 => 'Holly (952340 Schwalbach)', - * // 30 => 'Guy (420729 Panchià)' - * // } - * + * @externalExample ../../example/data/buildmap.mjs * @param {*} subject * @param {string|Monster.Data~exampleSelectorCallback} selector * @param {string} [valueTemplate] diff --git a/application/source/data/buildtree.mjs b/application/source/data/buildtree.mjs index 3180338f93a4968239cbffe2e5d8292b786241ac..ba0501069d813815b344204c4ea81c43f36fbf7d 100644 --- a/application/source/data/buildtree.mjs +++ b/application/source/data/buildtree.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,8 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - - import {isArray, isObject} from "../types/is.mjs"; import {Node} from "../types/node.mjs"; import {NodeList} from "../types/nodelist.mjs"; @@ -39,13 +35,6 @@ const rootSymbol = Symbol('root'); /** * With the help of the function `buildTree()`, nodes can be easily created from data objects. * - * ``` - * <script type="module"> - * import {buildTree} from '@schukai/monster/source/data/buildtree.mjs'; - * buildTree() - * </script> - * ``` - * * @param {*} subject * @param {string|Monster.Data~exampleSelectorCallback} selector * @param {string} idKey diff --git a/application/source/data/datasource.mjs b/application/source/data/datasource.mjs index e5afebb52902cca1ac67f9f2a9c8d16daddae3f8..de41840cb77c14acae481f7af3e00d641af4b913 100644 --- a/application/source/data/datasource.mjs +++ b/application/source/data/datasource.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,7 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - import {internalSymbol} from "../constants.mjs"; import {Base} from "../types/base.mjs"; @@ -32,24 +29,7 @@ const internalDataSymbol = Symbol('internalData'); /** * The datasource class is the basis for dealing with different data sources. * It provides a unified interface for accessing data - * - * ``` - * <script type="module"> - * import {Datasource} from '@schukai/monster/source/data/datasource.mjs'; - * new Datasource() - * </script> - * ``` - * - * @example - * - * import {Datasource} from '@schukai/monster/source/data/datasource.mjs' - * - * class MyDatasource extends Datasource { - * - * } - * - * const ds = new MyDatasource(); - * + * @externalExample ../../example/data/datasource.mjs * @license AGPLv3 * @since 1.22.0 * @copyright schukai GmbH diff --git a/application/source/data/datasource/namespace.mjs b/application/source/data/datasource/namespace.mjs index bad1f4a4beceaa4a3e1835bbdd36d285e1f86845..54ee63b89009f464143dbc64ee26c6f43d4c40d3 100644 --- a/application/source/data/datasource/namespace.mjs +++ b/application/source/data/datasource/namespace.mjs @@ -1,5 +1,3 @@ - - /** * Namespace for datasources * diff --git a/application/source/data/datasource/restapi.mjs b/application/source/data/datasource/restapi.mjs index 32ffdb4a648bb0db19405828485689e46334aa65..1c1a34add9f79eb9a9dbdd2ea48b9d789c8bb460 100644 --- a/application/source/data/datasource/restapi.mjs +++ b/application/source/data/datasource/restapi.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,7 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - import {internalSymbol} from "../../constants.mjs"; import {isObject} from "../../types/is.mjs"; import {Datasource} from "../datasource.mjs"; @@ -19,28 +16,8 @@ export {RestAPI} /** * The RestAPI is a class that enables a REST API server. - * - * ``` - * <script type="module"> - * import {RestAPI} from '@schukai/monster/source/data/datasource/restapi.mjs'; - * new RestAPI() - * </script> - * ``` - * - * @example - * - * import {RestAPI} from '@schukai/monster/source/data/datasource/restapi.mjs'; - * - * const ds = new RestAPI({ - * url: 'https://httpbin.org/get' - * },{ - * url: 'https://httpbin.org/post' - * }); - * - * ds.set({flag:true}) - * ds.write().then(()=>console.log('done')); - * ds.read().then(()=>console.log('done')); * + * @externalExample ../../../example/data/storage/restapi.mjs * @license AGPLv3 * @since 1.22.0 * @copyright schukai GmbH diff --git a/application/source/data/datasource/restapi/namespace.mjs b/application/source/data/datasource/restapi/namespace.mjs index 33bc88f80c2132cd483e2fe94ac53daf7211166c..6fc912fbf35aab76ed8ec00ec1ea5dd2f94cd745 100644 --- a/application/source/data/datasource/restapi/namespace.mjs +++ b/application/source/data/datasource/restapi/namespace.mjs @@ -1,5 +1,3 @@ - - /** * Namespace for storages * diff --git a/application/source/data/datasource/restapi/writeerror.mjs b/application/source/data/datasource/restapi/writeerror.mjs index 41f8028a1aa7f844856f944501863801463b5842..2240d81995ac06e3f9e34b6d3a5c580934c18f37 100644 --- a/application/source/data/datasource/restapi/writeerror.mjs +++ b/application/source/data/datasource/restapi/writeerror.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,7 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - import {internalSymbol} from "../../../constants.mjs"; export {WriteError} diff --git a/application/source/data/datasource/storage.mjs b/application/source/data/datasource/storage.mjs index 6f219fe16a7ec6fc3d671e43384188b54e9a9dbe..0327c917e39530e4c3ad1e3bb738b2ece0476734 100644 --- a/application/source/data/datasource/storage.mjs +++ b/application/source/data/datasource/storage.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,7 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - import {internalSymbol} from "../../constants.mjs"; import {validateString} from "../../types/validate.mjs"; import {Datasource} from "../datasource.mjs"; @@ -23,19 +20,6 @@ const storageObjectSymbol = Symbol('storageObject'); /** * The class represents a record. * - * ``` - * <script type="module"> - * import {Storage} from '@schukai/monster/source/data/datasource/storage.mjs'; - * new Storage() - * </script> - * ``` - * - * @example - * - * import {Storage} from '@schukai/monster/source/data/datasource/storage.mjs'; - * - * new Datasource(); - * * @license AGPLv3 * @since 1.22.0 * @copyright schukai GmbH diff --git a/application/source/data/datasource/storage/localstorage.mjs b/application/source/data/datasource/storage/localstorage.mjs index edfd99a9a172541df5e14e6dcf4a88931829f332..9e5cd8a696319b2471196df1d065f8e3e1a6ff6d 100644 --- a/application/source/data/datasource/storage/localstorage.mjs +++ b/application/source/data/datasource/storage/localstorage.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,7 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - import {internalSymbol} from "../../../constants.mjs"; import {getGlobalObject} from "../../../types/global.mjs"; import {Datasource} from "../../datasource.mjs"; @@ -18,13 +15,6 @@ export {LocalStorage} /** * The LocalStorage Datasource provides a data store in the browser localStorage. * - * ``` - * <script type="module"> - * import {LocalStorage} from '@schukai/monster/source/data/datasource/storage/localstorage.mjs'; - * new LocalStorage() - * </script> - * ``` - * * @license AGPLv3 * @since 1.22.0 * @copyright schukai GmbH diff --git a/application/source/data/datasource/storage/namespace.mjs b/application/source/data/datasource/storage/namespace.mjs index ddc916814baeeff7bf8f52e52c8b244b24378592..0540ceffd5c517fbdcc29571ae15a5879c4138c5 100644 --- a/application/source/data/datasource/storage/namespace.mjs +++ b/application/source/data/datasource/storage/namespace.mjs @@ -1,5 +1,3 @@ - - /** * Namespace for storages * diff --git a/application/source/data/datasource/storage/sessionstorage.mjs b/application/source/data/datasource/storage/sessionstorage.mjs index 6dd704a88b40e8f9f2a4ad6b4424a5bfb93064c1..c63de52a0589bcb763abc7b06a12d6a40b695af1 100644 --- a/application/source/data/datasource/storage/sessionstorage.mjs +++ b/application/source/data/datasource/storage/sessionstorage.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,7 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - import {internalSymbol} from "../../../constants.mjs"; import {getGlobalObject} from "../../../types/global.mjs"; import {Datasource} from "../../datasource.mjs"; @@ -17,13 +14,6 @@ export {SessionStorage} /** * The SessionStorage class provides a data source that uses the SessionStorage API on the client. - * - * ``` - * <script type="module"> - * import {SessionStorage} from '@schukai/monster/source/data/datasource/storage/sessionstorage.mjs'; - * new SessionStorage() - * </script> - * ``` * * @license AGPLv3 * @since 1.22.0 diff --git a/application/source/data/diff.mjs b/application/source/data/diff.mjs index ec1a65856ed3ca275ba6127f8e96c3be1ea2da00..a6bc923234557cbc74ee20a770fb3a86fee0e4ec 100644 --- a/application/source/data/diff.mjs +++ b/application/source/data/diff.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,8 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - - import {isArray, isObject} from "../types/is.mjs"; import {typeOf} from "../types/typeof.mjs"; @@ -26,48 +22,7 @@ export {diff} * </script> * ``` * - * @example - * - * import {Diff} from '@schukai/monster/source/data/diff.mjs'; - * - * // given are two objects x and y. - * - * let x = { - * a: 1, - * b: "Hello!" - * } - * - * let y = { - * a: 2, - * c: true - * } - * - * // These two objects can be compared with each other. - * - * console.log(Diff(x, y)); - * - * // the result is then the following - * - * // - * // [ - * // { - * // operator: 'update', - * // path: [ 'a' ], - * // first: { value: 1, type: 'number' }, - * // second: { value: 2, type: 'number' } - * // }, - * // { - * // operator: 'delete', - * // path: [ 'b' ], - * // first: { value: 'Hello!', type: 'string' } - * // }, - * // { - * // operator: 'add', - * // path: [ 'c' ], - * // second: { value: true, type: 'boolean' } - * // } - * // ] - * + * @externalExample ../../example/data/diff.mjs * @param {*} first * @param {*} second * @return {array} diff --git a/application/source/data/extend.mjs b/application/source/data/extend.mjs index 918d18c8a27ea8ca6dab2ca76ad89bcf523ac564..4824f1bef9285f9b0b76712a99f1165d0243983d 100644 --- a/application/source/data/extend.mjs +++ b/application/source/data/extend.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,7 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - import {isArray, isObject} from "../types/is.mjs"; import {typeOf} from "../types/typeof.mjs"; @@ -17,13 +14,6 @@ export {extend} * Extend copies all enumerable own properties from one or * more source objects to a target object. It returns the modified target object. * - * ``` - * <script type="module"> - * import {extend} from '@schukai/monster/source/data/extend.mjs'; - * extend(a, b) - * </script> - * ``` - * * @param {object} target * @param {object} * @return {object} diff --git a/application/source/data/pathfinder.mjs b/application/source/data/pathfinder.mjs index dabf4a602016219f202b0a3237e75ff1b85f15b4..ef16b67d43bb5b8ad28521d3febdd5046856621e 100644 --- a/application/source/data/pathfinder.mjs +++ b/application/source/data/pathfinder.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,7 +5,6 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - import {Base} from '../types/base.mjs'; import {isArray, isInteger, isObject, isPrimitive} from '../types/is.mjs'; import {Stack} from "../types/stack.mjs"; @@ -31,13 +28,6 @@ const WILDCARD = '*'; /** * Pathfinder is a class to find a path to an object. - * - * ``` - * <script type="module"> - * import {Pathfinder} from '@schukai/monster/source/data/pathfinder.mjs'; - * console.log(new Pathfinder()) - * </script> - * ``` * * With the help of the pathfinder, values can be read and written from an object construct. * @@ -74,54 +64,8 @@ const WILDCARD = '*'; * new Pathfinder(obj).setVia('a.b.0.c', true); // ↦ {a:{b:[{c:true}]}} * ``` * - * @example - * - * import {Pathfinder} from '@schukai/monster/source/data/pathfinder.mjs'; - * - * let value = new Pathfinder({ - * a: { - * b: { - * f: [ - * { - * g: false, - * } - * ], - * } - * } - * }).getVia("a.b.f.0.g"); - * - * console.log(value); - * // ↦ false - * - * try { - * new Pathfinder({}).getVia("a.b.f.0.g"); - * } catch(e) { - * console.log(e.toString()); - * // ↦ Error: the journey is not at its end (b.f.0.g) - * } - * - * @example - * - * import {Pathfinder} from '@schukai/monster/source/data/pathfinder.mjs'; - * - * let p = new Pathfinder({ - * a: { - * x: [ - * {c: 1}, {c: 2} - * ], - * y: true - * }, - * b: { - * x: [ - * {c: 1, d: false}, {c: 2} - * ], - * y: true - * }, - * }); - * - * let r = p.getVia("*.x.*.c"); - * console.log(r); - * + * @externalExample ../../example/data/pathfinder-1.mjs + * @externalExample ../../example/data/pathfinder-2.mjs * @license AGPLv3 * @since 1.4.0 * @copyright schukai GmbH diff --git a/application/source/data/pipe.mjs b/application/source/data/pipe.mjs index 155b114d2c4f213c90db0560d5071bcfddf0a4e3..ff326d1751f32051afcbd32aad9943261baea6dd 100644 --- a/application/source/data/pipe.mjs +++ b/application/source/data/pipe.mjs @@ -1,5 +1,3 @@ - - /** * Copyright schukai GmbH and contributors 2022. All Rights Reserved. * Node module: @schukai/monster @@ -7,47 +5,27 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ - - import {Base} from '../types/base.mjs'; import {validateString} from '../types/validate.mjs'; import {Transformer} from './transformer.mjs'; export {Pipe} +/** + * @private + * @type {string} + */ const DELIMITER = '|'; /** * The pipe class makes it possible to combine several processing steps. * - * ``` - * <script type="module"> - * import {Pipe} from '@schukai/monster/source/data/pipe.mjs'; - * new Pipe() - * </script> - * ``` - * * A pipe consists of commands whose input and output are connected with the pipe symbol `|`. * * With the Pipe, processing steps can be combined. Here, the value of an object is accessed via the pathfinder (path command). * the word is then converted to uppercase letters and a prefix Hello is added. the two backslash safe the space char. * - * @example - * import {Pipe} from '@schukai/monster/source/data/pipe.mjs'; - * - * let obj = { - * a: { - * b: { - * c: { - * d: "world" - * } - * } - * } - * } - * - * console.log(new Pipe('path:a.b.c.d | toupper | prefix:Hello\\ ').run(obj)); - * // ↦ Hello WORLD - * + * @externalExample ../../example/data/pipe.mjs * @license AGPLv3 * @since 1.5.0 * @copyright schukai GmbH @@ -56,7 +34,6 @@ const DELIMITER = '|'; class Pipe extends Base { /** - * * @param {string} pipe a pipe consists of commands whose input and output are connected with the pipe symbol `|`. * @throws {TypeError} */ @@ -72,7 +49,6 @@ class Pipe extends Base { } /** - * * @param {string} name * @param {function} callback * @param {object} context diff --git a/application/source/data/transformer.mjs b/application/source/data/transformer.mjs index 83f1f17de59cfadf70fb19090e8d2a4b88cf9417..363b67ef4650b70cbcc04c28377e3800aed40313 100644 --- a/application/source/data/transformer.mjs +++ b/application/source/data/transformer.mjs @@ -27,13 +27,6 @@ export {Transformer} /** * The transformer class is a swiss army knife for manipulating values. especially in combination with the pipe, processing chains can be built up. * - * ``` - * <script type="module"> - * import {Transformer} from '@schukai/monster/source/data/transformer.mjs'; - * new Transformer() - * </script> - * ``` - * * A simple example is the conversion of all characters to lowercase. for this purpose the command `tolower` must be used. * * ``` @@ -113,18 +106,7 @@ export {Transformer} * global['crypto'] = new Crypto.Crypto(); * ``` * - * @example - * - * import {Transformer} from '@schukai/monster/source/data/transformer.mjs'; - * - * const transformer = new Transformer("tolower") - * - * console.log(transformer.run("HELLO")) - * // ↦ hello - * - * console.log(transformer.run("WORLD")) - * // ↦ world - * + * @externalExample ../../example/data/transformer.mjs * @license AGPLv3 * @since 1.5.0 * @copyright schukai GmbH diff --git a/development/package.json b/development/package.json index 7ff7e83cd97682dbcb8b0f535f085126175fb836..30379e35ef9bafe1541bce04c80ed1fb982adc89 100644 --- a/development/package.json +++ b/development/package.json @@ -31,6 +31,7 @@ "fs": "^0.0.1-security", "graphviz": "^0.0.9", "jsdoc": "^3.6.11", + "jsdoc-external-example": "github:volker-schukai/jsdoc-external-example", "jsdoc-plantuml": "^1.0.2", "jsdom": "^19.0.0", "jsdom-global": "^3.0.2", diff --git a/development/pnpm-lock.yaml b/development/pnpm-lock.yaml index 11425d320e741307c8d15449ef2d1ee567450c56..678087e545912be131516e4650961217d5bc0f36 100644 --- a/development/pnpm-lock.yaml +++ b/development/pnpm-lock.yaml @@ -10,10 +10,12 @@ specifiers: create-polyfill-service-url: ^2.2.6 crypt: ^0.0.2 esbuild: ^0.14.53 + examples-plugin-jsdoc: ^1.0.4 flow-bin: ^0.184.0 fs: ^0.0.1-security graphviz: ^0.0.9 jsdoc: ^3.6.11 + jsdoc-external-example: github:volker-schukai/jsdoc-external-example jsdoc-plantuml: ^1.0.2 jsdom: ^19.0.0 jsdom-global: ^3.0.2 @@ -34,10 +36,12 @@ devDependencies: create-polyfill-service-url: 2.2.6 crypt: 0.0.2 esbuild: 0.14.53 + examples-plugin-jsdoc: 1.0.4 flow-bin: 0.184.0 fs: 0.0.1-security graphviz: 0.0.9 jsdoc: 3.6.11 + jsdoc-external-example: github.com/volker-schukai/jsdoc-external-example/91fd194a706b54d6fe30f41aad9a0851c571b360 jsdoc-plantuml: 1.0.2_jsdoc@3.6.11 jsdom: 19.0.0 jsdom-global: 3.0.2_jsdom@19.0.0 @@ -431,6 +435,11 @@ packages: engines: {node: '>=0.4.0'} dev: true + /acorn-walk/8.2.0: + resolution: {integrity: sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==} + engines: {node: '>=0.4.0'} + dev: true + /acorn/7.4.1: resolution: {integrity: sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==} engines: {node: '>=0.4.0'} @@ -1241,6 +1250,12 @@ packages: engines: {node: '>=6'} dev: true + /examples-plugin-jsdoc/1.0.4: + resolution: {integrity: sha512-7B5Uq8uwnPplGjnuwlxzlKHR3clexNpacF0MmRKyYTrPJz84Q5Jw2UwgZhhjtnqjWUWw1pkl4UWknuqssCcdKg==} + dependencies: + vm2: 3.9.10 + dev: true + /execa/4.1.0: resolution: {integrity: sha512-j5W0//W7f8UxAn8hXVnwG8tLwdiUy4FJLcSupCg6maBYZDpyBvTApK7KyuI4bKj8KOh1r2YH+6ucuYtJv1bTZA==} engines: {node: '>=10'} @@ -2848,6 +2863,15 @@ packages: convert-source-map: 1.8.0 dev: true + /vm2/3.9.10: + resolution: {integrity: sha512-AuECTSvwu2OHLAZYhG716YzwodKCIJxB6u1zG7PgSQwIgAlEaoXH52bxdcvT8GkGjnYK7r7yWDW0m0sOsPuBjQ==} + engines: {node: '>=6.0'} + hasBin: true + dependencies: + acorn: 8.8.0 + acorn-walk: 8.2.0 + dev: true + /w3c-hr-time/1.0.2: resolution: {integrity: sha512-z8P5DvDNjKDoFIHK7q8r8lackT6l+jo/Ye3HOle7l9nICP9lf1Ci25fy9vHd0JOWewkIFzXIEig3TdKT7JQ5fQ==} dependencies: @@ -3101,3 +3125,9 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} dev: true + + github.com/volker-schukai/jsdoc-external-example/91fd194a706b54d6fe30f41aad9a0851c571b360: + resolution: {tarball: https://codeload.github.com/volker-schukai/jsdoc-external-example/tar.gz/91fd194a706b54d6fe30f41aad9a0851c571b360} + name: jsdoc-external-example + version: 0.0.1 + dev: true diff --git a/documentation/config/jsdoc.json b/documentation/config/jsdoc.json index d8edebd409990b7043f3204306f5a8ed5eeb8543..674f837663fef69a4508d646ac3337474512567a 100644 --- a/documentation/config/jsdoc.json +++ b/documentation/config/jsdoc.json @@ -10,7 +10,8 @@ "plugins": [ "plugins/markdown", "jsdoc-plantuml", - "plugins/summarize" + "plugins/summarize", + "jsdoc-external-example" ], "sourceType": "module", "opts": { @@ -18,7 +19,7 @@ "encoding": "utf8", "destination": "../deployment/build/docs/", "recurse": true, - "verbose": true, + "verbose": false, "theme_opts": { "default_theme": "dark", "title": "Monster ",