Skip to content
Snippets Groups Projects
Verified Commit daf062b2 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

chore: commit save point

parent 18583969
No related branches found
No related tags found
No related merge requests found
Showing
with 264 additions and 126 deletions
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
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
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
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
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
import {Valid} from '@schukai/monster/source/constraints/valid.mjs';
new Valid().isValid()
.then(() => console.log(true))
.catch(() => console.log(false));
// ↦ true
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
import {Datasource} from '@schukai/monster/source/data/datasource.mjs'
class MyDatasource extends Datasource {
}
const ds = new MyDatasource();
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' }
// }
// ]
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
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);
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
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
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
......@@ -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
......
/**
* 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
......
/**
* 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
......
/**
* 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
......
/**
* 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
......
/**
* 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment