@bitblit/ratchet-misc 4.0.115-alpha → 4.0.119-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/build/ratchet-misc-info.d.ts +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.mjs +5 -0
- package/lib/index.mjs.map +1 -0
- package/lib/rxjs/observable-ratchet.d.ts +1 -1
- package/package.json +9 -10
- package/lib/build/ratchet-misc-info.js +0 -14
- package/lib/handlebars/handlebars-ratchet.js +0 -110
- package/lib/handlebars/handlebars-ratchet.spec.js +0 -107
- package/lib/index.js +0 -1
- package/lib/model-validator/model-validator.js +0 -53
- package/lib/model-validator/model-validator.spec.js +0 -34
- package/lib/rxjs/observable-ratchet.js +0 -16
- package/lib/rxjs/observable-ratchet.spec.js +0 -18
- package/lib/rxjs/rxjs-ratchet.js +0 -36
- package/lib/rxjs/rxjs-ratchet.spec.js +0 -16
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
import { TimeoutToken } from '@bitblit/ratchet-common
|
|
2
|
+
import { TimeoutToken } from '@bitblit/ratchet-common';
|
|
3
3
|
export declare class ObservableRatchet {
|
|
4
4
|
static timeout<T>(srcObservable: Observable<T | TimeoutToken>, title: string, timeoutMillis: number): Observable<T | TimeoutToken>;
|
|
5
5
|
static createTimeoutObservable<T>(title: string, timeoutMillis: number): Observable<T | TimeoutToken>;
|
package/package.json
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitblit/ratchet-misc",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.119-alpha",
|
|
4
4
|
"description": "Ratchet miscellaneous tooling that requires smallish dependant libraries",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
|
-
"module": "index.js",
|
|
8
7
|
"files": [
|
|
9
8
|
"lib/*",
|
|
10
9
|
"bin/*"
|
|
11
10
|
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/index.d.ts",
|
|
14
|
+
"import": "./lib/index.mjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
12
17
|
"contributors": [
|
|
13
18
|
"Christopher Weiss <bitblit@gmail.com>",
|
|
14
19
|
"William Weiss <npm@codification.org>",
|
|
@@ -35,9 +40,8 @@
|
|
|
35
40
|
"docs": "typedoc",
|
|
36
41
|
"lint": "eslint src/**/*.ts",
|
|
37
42
|
"lint-fix": "eslint --fix src/**/*.ts",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"build": "tsc",
|
|
43
|
+
"generate-barrels": "barrelsby -q --delete -d src -e .*\\.spec\\.ts && sed -i 's/\\x27;/.js\\x27;/' src/index.ts",
|
|
44
|
+
"build": "yarn clean && yarn generate-barrels && rollup -c rollup.config.js",
|
|
41
45
|
"force-build": "tsc --build --force"
|
|
42
46
|
},
|
|
43
47
|
"repository": {
|
|
@@ -64,11 +68,6 @@
|
|
|
64
68
|
"swagger-model-validator": "3.0.21"
|
|
65
69
|
},
|
|
66
70
|
"peerDependencies": {
|
|
67
|
-
"handlebars": "^4.7.7",
|
|
68
|
-
"handlebars-layouts": "^3.1.4",
|
|
69
|
-
"js-yaml": "^4.1.0",
|
|
70
|
-
"rxjs": "^7.8.1",
|
|
71
|
-
"swagger-model-validator": "^3.0.21"
|
|
72
71
|
},
|
|
73
72
|
"resolutions": {},
|
|
74
73
|
"devDependencies": {}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export class RatchetMiscInfo {
|
|
2
|
-
constructor() { }
|
|
3
|
-
static buildInformation() {
|
|
4
|
-
const val = {
|
|
5
|
-
version: 'LOCAL-SNAPSHOT',
|
|
6
|
-
hash: 'LOCAL-HASH',
|
|
7
|
-
branch: 'LOCAL-BRANCH',
|
|
8
|
-
tag: 'LOCAL-TAG',
|
|
9
|
-
timeBuiltISO: 'LOCAL-TIME-ISO',
|
|
10
|
-
notes: 'LOCAL-NOTES',
|
|
11
|
-
};
|
|
12
|
-
return val;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
|
|
2
|
-
import { NumberRatchet } from '@bitblit/ratchet-common/lib/lang/number-ratchet.js';
|
|
3
|
-
import { ErrorRatchet } from '@bitblit/ratchet-common/lib/lang/error-ratchet.js';
|
|
4
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
5
|
-
export class HandlebarsRatchet {
|
|
6
|
-
constructor() { }
|
|
7
|
-
static functionMap() {
|
|
8
|
-
return {
|
|
9
|
-
eq: HandlebarsRatchet.equal,
|
|
10
|
-
ne: HandlebarsRatchet.notEqual,
|
|
11
|
-
lt: HandlebarsRatchet.lessThan,
|
|
12
|
-
gt: HandlebarsRatchet.greaterThan,
|
|
13
|
-
lte: HandlebarsRatchet.lessThanEqual,
|
|
14
|
-
gte: HandlebarsRatchet.greaterThanEqual,
|
|
15
|
-
and: HandlebarsRatchet.and,
|
|
16
|
-
or: HandlebarsRatchet.or,
|
|
17
|
-
formatBytes: HandlebarsRatchet.formatBytes,
|
|
18
|
-
rpn: HandlebarsRatchet.reversePolishNotation,
|
|
19
|
-
add: HandlebarsRatchet.add,
|
|
20
|
-
sub: HandlebarsRatchet.sub,
|
|
21
|
-
mul: HandlebarsRatchet.mul,
|
|
22
|
-
div: HandlebarsRatchet.div,
|
|
23
|
-
mod: HandlebarsRatchet.mod,
|
|
24
|
-
maxNum: HandlebarsRatchet.maxNum,
|
|
25
|
-
minNum: HandlebarsRatchet.minNum,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
static registerAll(handlebars) {
|
|
29
|
-
handlebars.registerHelper(HandlebarsRatchet.functionMap());
|
|
30
|
-
}
|
|
31
|
-
static add(v1, v2) {
|
|
32
|
-
return NumberRatchet.safeNumber(v1) + NumberRatchet.safeNumber(v2);
|
|
33
|
-
}
|
|
34
|
-
static sub(v1, v2) {
|
|
35
|
-
return NumberRatchet.safeNumber(v1) - NumberRatchet.safeNumber(v2);
|
|
36
|
-
}
|
|
37
|
-
static mul(v1, v2) {
|
|
38
|
-
return NumberRatchet.safeNumber(v1) * NumberRatchet.safeNumber(v2);
|
|
39
|
-
}
|
|
40
|
-
static div(v1, v2) {
|
|
41
|
-
return NumberRatchet.safeNumber(v1) / NumberRatchet.safeNumber(v2);
|
|
42
|
-
}
|
|
43
|
-
static mod(v1, v2) {
|
|
44
|
-
return NumberRatchet.safeNumber(v1) % NumberRatchet.safeNumber(v2);
|
|
45
|
-
}
|
|
46
|
-
static equal(v1, v2) {
|
|
47
|
-
return v1 === v2;
|
|
48
|
-
}
|
|
49
|
-
static notEqual(v1, v2) {
|
|
50
|
-
return v1 !== v2;
|
|
51
|
-
}
|
|
52
|
-
static lessThan(v1, v2) {
|
|
53
|
-
return v1 < v2;
|
|
54
|
-
}
|
|
55
|
-
static lessThanEqual(v1, v2) {
|
|
56
|
-
return v1 <= v2;
|
|
57
|
-
}
|
|
58
|
-
static greaterThan(v1, v2) {
|
|
59
|
-
return v1 > v2;
|
|
60
|
-
}
|
|
61
|
-
static greaterThanEqual(v1, v2) {
|
|
62
|
-
return v1 >= v2;
|
|
63
|
-
}
|
|
64
|
-
static maxNum(...args) {
|
|
65
|
-
return Math.max(...args.slice(0, -1));
|
|
66
|
-
}
|
|
67
|
-
static minNum(...args) {
|
|
68
|
-
return Math.min(...args.slice(0, -1));
|
|
69
|
-
}
|
|
70
|
-
static and(...args) {
|
|
71
|
-
return Array.prototype.every.call(args, Boolean);
|
|
72
|
-
}
|
|
73
|
-
static or(...args) {
|
|
74
|
-
return Array.prototype.slice.call(args, 0, -1).some(Boolean);
|
|
75
|
-
}
|
|
76
|
-
static formatBytes(v1) {
|
|
77
|
-
return StringRatchet.formatBytes(v1);
|
|
78
|
-
}
|
|
79
|
-
static reversePolishNotation(...args) {
|
|
80
|
-
let rval = null;
|
|
81
|
-
try {
|
|
82
|
-
const fns = Object.assign({}, HandlebarsRatchet.functionMap());
|
|
83
|
-
delete fns['formatBytes'];
|
|
84
|
-
const stack = [];
|
|
85
|
-
for (let i = 0; i < args.length - 1; i++) {
|
|
86
|
-
const a = args[i];
|
|
87
|
-
if (fns[a]) {
|
|
88
|
-
if (stack.length > 1) {
|
|
89
|
-
const op2 = stack.pop();
|
|
90
|
-
const op1 = stack.pop();
|
|
91
|
-
const res = fns[a](op1, op2, {});
|
|
92
|
-
stack.push(res);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
ErrorRatchet.throwFormattedErr('Cannot execute operation %s - not enough args', a);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
stack.push(a);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
rval = stack.pop();
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
Logger.error('Failed to execute RPN: %s', err, err);
|
|
106
|
-
rval = ErrorRatchet.asErr(err)?.message || 'Failure';
|
|
107
|
-
}
|
|
108
|
-
return rval;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import handlebars from 'handlebars';
|
|
2
|
-
import { HandlebarsRatchet } from './handlebars-ratchet.js';
|
|
3
|
-
describe('#handlebarsService', () => {
|
|
4
|
-
it('should test equal', async () => {
|
|
5
|
-
handlebars.registerHelper('eq', HandlebarsRatchet.equal);
|
|
6
|
-
const out1 = handlebars.compile('{{eq 1 2}}')({});
|
|
7
|
-
expect(out1).toEqual('false');
|
|
8
|
-
const out2 = handlebars.compile('{{eq 1 1}}')({});
|
|
9
|
-
expect(out2).toEqual('true');
|
|
10
|
-
const out3 = handlebars.compile('{{eq 1 a}}')({ a: 1 });
|
|
11
|
-
expect(out3).toEqual('true');
|
|
12
|
-
});
|
|
13
|
-
it('should test notequal', async () => {
|
|
14
|
-
handlebars.registerHelper('ne', HandlebarsRatchet.notEqual);
|
|
15
|
-
const out1 = handlebars.compile('{{ne 1 2}}')({});
|
|
16
|
-
expect(out1).toEqual('true');
|
|
17
|
-
const out2 = handlebars.compile('{{ne 1 1}}')({});
|
|
18
|
-
expect(out2).toEqual('false');
|
|
19
|
-
const out3 = handlebars.compile('{{ne 1 a}}')({ a: 1 });
|
|
20
|
-
expect(out3).toEqual('false');
|
|
21
|
-
});
|
|
22
|
-
it('should test less-than/less-than-equal', async () => {
|
|
23
|
-
handlebars.registerHelper('lt', HandlebarsRatchet.lessThan);
|
|
24
|
-
handlebars.registerHelper('lte', HandlebarsRatchet.lessThanEqual);
|
|
25
|
-
const out1 = handlebars.compile('{{lt 1 2}}')({});
|
|
26
|
-
expect(out1).toEqual('true');
|
|
27
|
-
const out2 = handlebars.compile('{{lt 1 1}}')({});
|
|
28
|
-
expect(out2).toEqual('false');
|
|
29
|
-
const out3 = handlebars.compile('{{lte 1 1}}')({});
|
|
30
|
-
expect(out3).toEqual('true');
|
|
31
|
-
const out4 = handlebars.compile('{{lt 20 1}}')({});
|
|
32
|
-
expect(out4).toEqual('false');
|
|
33
|
-
});
|
|
34
|
-
it('should test greater-than/greater-than-equal', async () => {
|
|
35
|
-
handlebars.registerHelper('gt', HandlebarsRatchet.greaterThan);
|
|
36
|
-
handlebars.registerHelper('gte', HandlebarsRatchet.greaterThanEqual);
|
|
37
|
-
const out1 = handlebars.compile('{{gt 2 1}}')({});
|
|
38
|
-
expect(out1).toEqual('true');
|
|
39
|
-
const out2 = handlebars.compile('{{gt 1 1}}')({});
|
|
40
|
-
expect(out2).toEqual('false');
|
|
41
|
-
const out3 = handlebars.compile('{{gte 1 1}}')({});
|
|
42
|
-
expect(out3).toEqual('true');
|
|
43
|
-
const out4 = handlebars.compile('{{gt 1 20}}')({});
|
|
44
|
-
expect(out4).toEqual('false');
|
|
45
|
-
});
|
|
46
|
-
it('should test and/or', async () => {
|
|
47
|
-
handlebars.registerHelper('and', HandlebarsRatchet.and);
|
|
48
|
-
handlebars.registerHelper('or', HandlebarsRatchet.or);
|
|
49
|
-
const out1 = handlebars.compile('{{and true true}}')({});
|
|
50
|
-
expect(out1).toEqual('true');
|
|
51
|
-
const out2 = handlebars.compile('{{and true false}}')({});
|
|
52
|
-
expect(out2).toEqual('false');
|
|
53
|
-
const out3 = handlebars.compile('{{and false false}}')({});
|
|
54
|
-
expect(out3).toEqual('false');
|
|
55
|
-
const out4 = handlebars.compile('{{or true true}}')({});
|
|
56
|
-
expect(out4).toEqual('true');
|
|
57
|
-
const out5 = handlebars.compile('{{or true false}}')({});
|
|
58
|
-
expect(out5).toEqual('true');
|
|
59
|
-
const out6 = handlebars.compile('{{or false false}}')({});
|
|
60
|
-
expect(out6).toEqual('false');
|
|
61
|
-
const out7 = handlebars.compile('{{and true true true true}}')({});
|
|
62
|
-
expect(out7).toEqual('true');
|
|
63
|
-
const out8 = handlebars.compile('{{or true false true false}}')({});
|
|
64
|
-
expect(out8).toEqual('true');
|
|
65
|
-
});
|
|
66
|
-
it('should test formatBytes', async () => {
|
|
67
|
-
handlebars.registerHelper('formatBytes', HandlebarsRatchet.formatBytes);
|
|
68
|
-
const out1 = handlebars.compile('{{formatBytes 10}}')({});
|
|
69
|
-
expect(out1).toEqual('10 Bytes');
|
|
70
|
-
const out2 = handlebars.compile('{{formatBytes 1040}}')({});
|
|
71
|
-
expect(out2).toEqual('1.02 KB');
|
|
72
|
-
const out3 = handlebars.compile('{{formatBytes 2100000}}')({});
|
|
73
|
-
expect(out3).toEqual('2 MB');
|
|
74
|
-
const out4 = handlebars.compile('{{formatBytes 3300000000}}')({});
|
|
75
|
-
expect(out4).toEqual('3.07 GB');
|
|
76
|
-
});
|
|
77
|
-
it('should test mat', async () => {
|
|
78
|
-
HandlebarsRatchet.registerAll(handlebars);
|
|
79
|
-
const add = handlebars.compile('{{add 2 1}}')({});
|
|
80
|
-
expect(add).toEqual('3');
|
|
81
|
-
const sub1 = handlebars.compile('{{sub 1 2}}')({});
|
|
82
|
-
expect(sub1).toEqual('-1');
|
|
83
|
-
const sub2 = handlebars.compile('{{sub 2 1}}')({});
|
|
84
|
-
expect(sub2).toEqual('1');
|
|
85
|
-
const mul = handlebars.compile('{{mul 2 3}}')({});
|
|
86
|
-
expect(mul).toEqual('6');
|
|
87
|
-
const div1 = handlebars.compile('{{div 2 1}}')({});
|
|
88
|
-
expect(div1).toEqual('2');
|
|
89
|
-
const div2 = handlebars.compile('{{div 1 2}}')({});
|
|
90
|
-
expect(div2).toEqual('0.5');
|
|
91
|
-
const mod = handlebars.compile('{{mod 3 2}}')({});
|
|
92
|
-
expect(mod).toEqual('1');
|
|
93
|
-
const maxNum = handlebars.compile('{{maxNum 2 1 8 5 7}}')({});
|
|
94
|
-
expect(maxNum).toEqual('8');
|
|
95
|
-
const minNum = handlebars.compile('{{minNum 2 1 8 5 7}}')({});
|
|
96
|
-
expect(minNum).toEqual('1');
|
|
97
|
-
});
|
|
98
|
-
it('should test rpn', async () => {
|
|
99
|
-
handlebars.registerHelper('rpn', HandlebarsRatchet.reversePolishNotation);
|
|
100
|
-
const out1 = handlebars.compile('{{rpn 5 10 "maxNum" 10 "add" 3 "sub"}}')({});
|
|
101
|
-
expect(out1).toEqual('17');
|
|
102
|
-
const out2 = handlebars.compile('{{rpn n1 n2 "div" n3 "mul" 6 "mod"}}')({ n1: 10, n2: 5, n3: '10' });
|
|
103
|
-
expect(out2).toEqual('2');
|
|
104
|
-
const out3 = handlebars.compile('{{rpn 1 "div"}}')({});
|
|
105
|
-
expect(out3).toEqual('Cannot execute operation div - not enough args');
|
|
106
|
-
});
|
|
107
|
-
});
|
package/lib/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import Validator from 'swagger-model-validator';
|
|
2
|
-
import yaml from 'js-yaml';
|
|
3
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
4
|
-
import { ErrorRatchet } from '@bitblit/ratchet-common/lib/lang/error-ratchet.js';
|
|
5
|
-
import { MapRatchet } from '@bitblit/ratchet-common/lib/lang/map-ratchet.js';
|
|
6
|
-
export class ModelValidator {
|
|
7
|
-
allModels;
|
|
8
|
-
constructor(allModels) {
|
|
9
|
-
this.allModels = allModels;
|
|
10
|
-
if (!allModels || Object.keys(allModels).length == 0) {
|
|
11
|
-
ErrorRatchet.throwFormattedErr('Cannot create model validator, passed models was null/empty : %j', allModels);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
static createFromYamlString(yamlString, rootPath) {
|
|
15
|
-
const src = yaml.load(yamlString);
|
|
16
|
-
const modelSrc = rootPath && rootPath.length > 0 ? MapRatchet.findValue(src, rootPath) : src;
|
|
17
|
-
return ModelValidator.createFromParsedObject(modelSrc);
|
|
18
|
-
}
|
|
19
|
-
static createFromParsedObject(parsedObject) {
|
|
20
|
-
return new ModelValidator(parsedObject);
|
|
21
|
-
}
|
|
22
|
-
get modelNames() {
|
|
23
|
-
return Object.keys(this.allModels);
|
|
24
|
-
}
|
|
25
|
-
addModel(modelName, model) {
|
|
26
|
-
this.allModels[modelName] = model;
|
|
27
|
-
}
|
|
28
|
-
fetchModel(modelName) {
|
|
29
|
-
return this.allModels[modelName];
|
|
30
|
-
}
|
|
31
|
-
validate(modelName, modelObject, emptyAllowed = false, extraPropertiesAllowed = true) {
|
|
32
|
-
let rval = [];
|
|
33
|
-
Logger.silly('Validating model %s all definitions are : %j', modelName, this.allModels);
|
|
34
|
-
const modelEmpty = !modelObject || Object.keys(modelObject).length === 0;
|
|
35
|
-
if (modelEmpty) {
|
|
36
|
-
if (!emptyAllowed) {
|
|
37
|
-
rval.push('Empty / null object sent, but empty not allowed here');
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
if (this.allModels && modelName && this.allModels[modelName]) {
|
|
42
|
-
const validation = new Validator().validate(modelObject, this.allModels[modelName], this.allModels, emptyAllowed, extraPropertiesAllowed);
|
|
43
|
-
if (validation.errorCount > 0) {
|
|
44
|
-
rval = validation.errors.map((e) => e.message);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
rval = ['Model named "' + modelName + '" not present in schema'];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return rval;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ModelValidator } from './model-validator.js';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
5
|
-
import { EsmRatchet } from '@bitblit/ratchet-common/lib/lang/esm-ratchet.js';
|
|
6
|
-
describe('#modelValidator', function () {
|
|
7
|
-
it('should list an error', function () {
|
|
8
|
-
const yamlString = fs
|
|
9
|
-
.readFileSync(path.join(EsmRatchet.fetchDirName(import.meta.url), '../../../../test-data/sample-objects.spec.yaml'))
|
|
10
|
-
.toString();
|
|
11
|
-
const validator = ModelValidator.createFromYamlString(yamlString, ['ModelObjects']);
|
|
12
|
-
const shouldPass = {
|
|
13
|
-
numberField: 7,
|
|
14
|
-
stringField: 'xxx',
|
|
15
|
-
};
|
|
16
|
-
const shouldFail = {
|
|
17
|
-
numberField: 70,
|
|
18
|
-
stringField: 'xxx',
|
|
19
|
-
};
|
|
20
|
-
const errShouldPass = validator.validate('SimpleItem', shouldPass, false, true);
|
|
21
|
-
const errShouldFail = validator.validate('SimpleItem', shouldFail, false, true);
|
|
22
|
-
Logger.silly('shouldPass: %j', errShouldPass);
|
|
23
|
-
Logger.silly('shouldFail: %j', errShouldFail);
|
|
24
|
-
expect(errShouldPass).toBeTruthy();
|
|
25
|
-
expect(errShouldPass.length).toEqual(0);
|
|
26
|
-
expect(errShouldFail).toBeTruthy();
|
|
27
|
-
expect(errShouldFail.length).toEqual(1);
|
|
28
|
-
const modelNames = validator.modelNames;
|
|
29
|
-
expect(modelNames.length).toEqual(2);
|
|
30
|
-
expect(modelNames.includes('SimpleItem')).toBeTruthy();
|
|
31
|
-
expect(modelNames.includes('ApiErrorResponse')).toBeTruthy();
|
|
32
|
-
expect(modelNames.includes('XYZ')).toBeFalsy();
|
|
33
|
-
});
|
|
34
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Observable, race } from 'rxjs';
|
|
2
|
-
import { TimeoutToken } from '@bitblit/ratchet-common/lib/lang/timeout-token.js';
|
|
3
|
-
export class ObservableRatchet {
|
|
4
|
-
static timeout(srcObservable, title, timeoutMillis) {
|
|
5
|
-
const rval = race(srcObservable, this.createTimeoutObservable(title, timeoutMillis));
|
|
6
|
-
return rval;
|
|
7
|
-
}
|
|
8
|
-
static createTimeoutObservable(title, timeoutMillis) {
|
|
9
|
-
return Observable.create((observer) => {
|
|
10
|
-
const id = setTimeout(() => {
|
|
11
|
-
clearTimeout(id);
|
|
12
|
-
observer.next(new TimeoutToken(title, timeoutMillis));
|
|
13
|
-
}, timeoutMillis);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { timer } from 'rxjs';
|
|
2
|
-
import { ObservableRatchet } from './observable-ratchet.js';
|
|
3
|
-
import { TimeoutToken } from '@bitblit/ratchet-common/lib/lang/timeout-token.js';
|
|
4
|
-
describe('#timeout', function () {
|
|
5
|
-
it('should correctly return before timeout', function () {
|
|
6
|
-
const src = timer(1000);
|
|
7
|
-
const timeoutOb = ObservableRatchet.timeout(src, '1000ms interval', 1500);
|
|
8
|
-
timeoutOb.subscribe((result) => expect(result).toEqual(0));
|
|
9
|
-
});
|
|
10
|
-
it('should correctly returns null after timeout', function () {
|
|
11
|
-
const src = timer(1500);
|
|
12
|
-
const timeoutOb = ObservableRatchet.timeout(src, '1500ms interval', 1000);
|
|
13
|
-
timeoutOb.subscribe((result) => {
|
|
14
|
-
expect(result).toBeTruthy();
|
|
15
|
-
expect(result instanceof TimeoutToken).toBeTruthy();
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
});
|
package/lib/rxjs/rxjs-ratchet.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { MapRatchet } from '@bitblit/ratchet-common/lib/lang/map-ratchet.js';
|
|
2
|
-
export class RxjsRatchet {
|
|
3
|
-
static safeUnsubscribe(sub) {
|
|
4
|
-
return MapRatchet.safeCallFunction(sub, 'unsubscribe');
|
|
5
|
-
}
|
|
6
|
-
static async waitForNonNullOnSubject(subject) {
|
|
7
|
-
if (!!subject.value) {
|
|
8
|
-
return subject.value;
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
const innerSub = subject.subscribe((val) => {
|
|
13
|
-
if (!!val) {
|
|
14
|
-
RxjsRatchet.safeUnsubscribe(innerSub);
|
|
15
|
-
resolve(val);
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
static async waitForTargetValueOnSubject(subject, targetValue) {
|
|
22
|
-
if (subject.value === targetValue) {
|
|
23
|
-
return subject.value;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
const innerSub = subject.subscribe((val) => {
|
|
28
|
-
if (val === targetValue) {
|
|
29
|
-
RxjsRatchet.safeUnsubscribe(innerSub);
|
|
30
|
-
resolve(val);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { BehaviorSubject } from 'rxjs';
|
|
2
|
-
import { RxjsRatchet } from './rxjs-ratchet.js';
|
|
3
|
-
import { PromiseRatchet } from '@bitblit/ratchet-common/lib/lang/promise-ratchet.js';
|
|
4
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
5
|
-
describe('#waitForNonNullOnSubject', function () {
|
|
6
|
-
it('should resolve after 1 second', async () => {
|
|
7
|
-
const sub = new BehaviorSubject(null);
|
|
8
|
-
const testFn = PromiseRatchet.wait(1000).then((r) => {
|
|
9
|
-
sub.next(5);
|
|
10
|
-
});
|
|
11
|
-
Logger.info('Waiting for non-null');
|
|
12
|
-
const result = await RxjsRatchet.waitForNonNullOnSubject(sub);
|
|
13
|
-
Logger.info('Got %d', result);
|
|
14
|
-
expect(result).toEqual(5);
|
|
15
|
-
}, 10000);
|
|
16
|
-
});
|