@bitblit/ratchet-misc 4.0.99-alpha → 4.0.102-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.
Files changed (32) hide show
  1. package/dist/{types/build → build}/ratchet-misc-info.d.ts +1 -1
  2. package/dist/{types/handlebars → handlebars}/handlebars-ratchet.d.ts +0 -14
  3. package/dist/{es/handlebars → handlebars}/handlebars-ratchet.js +4 -4
  4. package/dist/handlebars/handlebars-ratchet.spec.d.ts +1 -0
  5. package/dist/handlebars/handlebars-ratchet.spec.js +107 -0
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.js +1 -0
  8. package/dist/{types/model-validator → model-validator}/model-validator.d.ts +0 -3
  9. package/dist/{es/model-validator → model-validator}/model-validator.js +4 -1
  10. package/dist/model-validator/model-validator.spec.d.ts +1 -0
  11. package/dist/model-validator/model-validator.spec.js +34 -0
  12. package/dist/{types/rxjs → rxjs}/observable-ratchet.d.ts +1 -6
  13. package/dist/{es/rxjs → rxjs}/observable-ratchet.js +1 -1
  14. package/dist/rxjs/observable-ratchet.spec.d.ts +1 -0
  15. package/dist/rxjs/observable-ratchet.spec.js +18 -0
  16. package/dist/{es/rxjs → rxjs}/rxjs-ratchet.js +1 -1
  17. package/dist/rxjs/rxjs-ratchet.spec.d.ts +1 -0
  18. package/dist/rxjs/rxjs-ratchet.spec.js +16 -0
  19. package/package.json +16 -15
  20. package/dist/cjs/build/ratchet-misc-info.js +0 -18
  21. package/dist/cjs/handlebars/handlebars-ratchet.js +0 -115
  22. package/dist/cjs/index.js +0 -8
  23. package/dist/cjs/model-validator/model-validator.js +0 -55
  24. package/dist/cjs/rxjs/observable-ratchet.js +0 -20
  25. package/dist/cjs/rxjs/rxjs-ratchet.js +0 -40
  26. package/dist/es/index.js +0 -5
  27. package/dist/tsconfig.cjs.tsbuildinfo +0 -1
  28. package/dist/tsconfig.es.tsbuildinfo +0 -1
  29. package/dist/tsconfig.types.tsbuildinfo +0 -1
  30. package/dist/types/index.d.ts +0 -8
  31. /package/dist/{es/build → build}/ratchet-misc-info.js +0 -0
  32. /package/dist/{types/rxjs → rxjs}/rxjs-ratchet.d.ts +0 -0
@@ -1,4 +1,4 @@
1
- import { BuildInformation } from '@bitblit/ratchet-common';
1
+ import { BuildInformation } from '@bitblit/ratchet-common/dist/build/build-information.js';
2
2
  export declare class RatchetMiscInfo {
3
3
  private constructor();
4
4
  static buildInformation(): BuildInformation;
@@ -18,19 +18,5 @@ export declare class HandlebarsRatchet {
18
18
  static and(...args: any[]): boolean;
19
19
  static or(...args: any[]): boolean;
20
20
  static formatBytes(v1: number): string;
21
- /**
22
- * Soo... why have a implementation of reverse polish notation for Handlebars? Well basically
23
- * because handlebars does not support doing math internally, and sometimes I want to be able
24
- * to do arbitrarily complex math inside my template, and even if I have functions like
25
- * add and div, I cannot do things like this in templates (usually):
26
- * add 5 (div 10 8)
27
- * because handlebars typically will not do the parens correctly. So, when you use RPN, there
28
- * are no parenthesis, operation order is handled by the stack, so you can put pretty much anything
29
- * you want in here
30
- *
31
- * And spare me any lectures about the evils of ANY logic in templates... if you send them my way, I'll assume you
32
- * are someone who has spent your whole life working in a university system and never having to make a payroll
33
- * @param args
34
- */
35
21
  static reversePolishNotation(...args: any[]): string;
36
22
  }
@@ -1,7 +1,7 @@
1
- import { StringRatchet } from '@bitblit/ratchet-common';
2
- import { NumberRatchet } from '@bitblit/ratchet-common';
3
- import { ErrorRatchet } from '@bitblit/ratchet-common';
4
- import { Logger } from '@bitblit/ratchet-common';
1
+ import { StringRatchet } from '@bitblit/ratchet-common/dist/lang/string-ratchet.js';
2
+ import { NumberRatchet } from '@bitblit/ratchet-common/dist/lang/number-ratchet.js';
3
+ import { ErrorRatchet } from '@bitblit/ratchet-common/dist/lang/error-ratchet.js';
4
+ import { Logger } from '@bitblit/ratchet-common/dist/logger/logger.js';
5
5
  export class HandlebarsRatchet {
6
6
  constructor() { }
7
7
  static functionMap() {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,107 @@
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
+ });
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,3 @@
1
- /**
2
- * Helper for validating endpoints
3
- */
4
1
  export declare class ModelValidator {
5
2
  private allModels;
6
3
  constructor(allModels: any);
@@ -1,7 +1,10 @@
1
1
  import Validator from 'swagger-model-validator';
2
2
  import yaml from 'js-yaml';
3
- import { ErrorRatchet, Logger, MapRatchet } from '@bitblit/ratchet-common';
3
+ import { Logger } from '@bitblit/ratchet-common/dist/logger/logger.js';
4
+ import { ErrorRatchet } from '@bitblit/ratchet-common/dist/lang/error-ratchet.js';
5
+ import { MapRatchet } from '@bitblit/ratchet-common/dist/lang/map-ratchet.js';
4
6
  export class ModelValidator {
7
+ allModels;
5
8
  constructor(allModels) {
6
9
  this.allModels = allModels;
7
10
  if (!allModels || Object.keys(allModels).length == 0) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ import { ModelValidator } from './model-validator.js';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { Logger } from '@bitblit/ratchet-common/dist/logger/logger.js';
5
+ import { EsmRatchet } from '@bitblit/ratchet-common/dist/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(), '../../../../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,10 +1,5 @@
1
1
  import { Observable } from 'rxjs';
2
- import { TimeoutToken } from '@bitblit/ratchet-common';
3
- /**
4
- * A class for simplifying working with rxjs observables.
5
- *
6
- * Contributed by William Weiss <npm@codification.org>
7
- */
2
+ import { TimeoutToken } from '@bitblit/ratchet-common/dist/lang/timeout-token.js';
8
3
  export declare class ObservableRatchet {
9
4
  static timeout<T>(srcObservable: Observable<T | TimeoutToken>, title: string, timeoutMillis: number): Observable<T | TimeoutToken>;
10
5
  static createTimeoutObservable<T>(title: string, timeoutMillis: number): Observable<T | TimeoutToken>;
@@ -1,5 +1,5 @@
1
1
  import { Observable, race } from 'rxjs';
2
- import { TimeoutToken } from '@bitblit/ratchet-common';
2
+ import { TimeoutToken } from '@bitblit/ratchet-common/dist/lang/timeout-token.js';
3
3
  export class ObservableRatchet {
4
4
  static timeout(srcObservable, title, timeoutMillis) {
5
5
  const rval = race(srcObservable, this.createTimeoutObservable(title, timeoutMillis));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import { timer } from 'rxjs';
2
+ import { ObservableRatchet } from './observable-ratchet.js';
3
+ import { TimeoutToken } from '@bitblit/ratchet-common/dist/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
+ });
@@ -1,4 +1,4 @@
1
- import { MapRatchet } from '@bitblit/ratchet-common';
1
+ import { MapRatchet } from '@bitblit/ratchet-common/dist/lang/map-ratchet.js';
2
2
  export class RxjsRatchet {
3
3
  static safeUnsubscribe(sub) {
4
4
  return MapRatchet.safeCallFunction(sub, 'unsubscribe');
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { BehaviorSubject } from 'rxjs';
2
+ import { RxjsRatchet } from './rxjs-ratchet.js';
3
+ import { PromiseRatchet } from '@bitblit/ratchet-common/dist/lang/promise-ratchet.js';
4
+ import { Logger } from '@bitblit/ratchet-common/dist/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
+ });
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@bitblit/ratchet-misc",
3
- "version": "4.0.99-alpha",
3
+ "version": "4.0.102-alpha",
4
4
  "description": "Ratchet miscellaneous tooling that requires smallish dependant libraries",
5
5
  "sideEffects": false,
6
- "main": "./dist/cjs/index.js",
7
- "module": "./dist/esm/index.js",
8
- "types": "./dist/types/index.d.ts",
6
+ "type": "module",
7
+ "module": "index.js",
9
8
  "files": [
10
- "dist/*"
9
+ "dist/*",
10
+ "includes/*"
11
11
  ],
12
12
  "contributors": [
13
13
  "Christopher Weiss <bitblit@gmail.com>",
@@ -31,15 +31,14 @@
31
31
  "scripts": {
32
32
  "watch": "tsc-watch",
33
33
  "clean": "shx rm -Rf dist",
34
- "test": "jest",
34
+ "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
35
35
  "docs": "typedoc",
36
36
  "lint": "eslint src/**/*.ts",
37
37
  "lint-fix": "eslint --fix src/**/*.ts",
38
- "generate-barrels": "barrelsby -q --delete -d src -e .*\\.spec\\.ts",
39
- "build": "yarn run generate-barrels && concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
40
- "build:cjs": "tsc -p tsconfig.cjs.json",
41
- "build:es": "tsc -p tsconfig.es.json",
42
- "build:types": "tsc -p tsconfig.types.json"
38
+ "__generate-barrels": "barrelsby -q --delete -d src -e .*\\.spec\\.ts",
39
+ "__build": "yarn run generate-barrels && tsc",
40
+ "build": "tsc",
41
+ "force-build": "tsc --build --force"
43
42
  },
44
43
  "repository": {
45
44
  "type": "git",
@@ -60,14 +59,16 @@
60
59
  "dependencies": {
61
60
  "handlebars": "4.7.7",
62
61
  "handlebars-layouts": "3.1.4",
62
+ "js-yaml": "4.1.0",
63
63
  "rxjs": "7.8.0",
64
64
  "swagger-model-validator": "3.0.21"
65
65
  },
66
66
  "peerDependencies": {
67
- "handlebars": "4.7.7",
68
- "handlebars-layouts": "3.1.4",
69
- "rxjs": "7.8.0",
70
- "swagger-model-validator": "3.0.21"
67
+ "handlebars": "^4.7.7",
68
+ "handlebars-layouts": "^3.1.4",
69
+ "js-yaml": "^4.1.0",
70
+ "rxjs": "^7.8.0",
71
+ "swagger-model-validator": "^3.0.21"
71
72
  },
72
73
  "resolutions": {},
73
74
  "devDependencies": {}
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RatchetMiscInfo = void 0;
4
- class RatchetMiscInfo {
5
- constructor() { }
6
- static buildInformation() {
7
- const val = {
8
- version: 'LOCAL-SNAPSHOT',
9
- hash: 'LOCAL-HASH',
10
- branch: 'LOCAL-BRANCH',
11
- tag: 'LOCAL-TAG',
12
- timeBuiltISO: 'LOCAL-TIME-ISO',
13
- notes: 'LOCAL-NOTES',
14
- };
15
- return val;
16
- }
17
- }
18
- exports.RatchetMiscInfo = RatchetMiscInfo;
@@ -1,115 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HandlebarsRatchet = void 0;
4
- const ratchet_common_1 = require("@bitblit/ratchet-common");
5
- const ratchet_common_2 = require("@bitblit/ratchet-common");
6
- const ratchet_common_3 = require("@bitblit/ratchet-common");
7
- const ratchet_common_4 = require("@bitblit/ratchet-common");
8
- class HandlebarsRatchet {
9
- constructor() { }
10
- static functionMap() {
11
- return {
12
- eq: HandlebarsRatchet.equal,
13
- ne: HandlebarsRatchet.notEqual,
14
- lt: HandlebarsRatchet.lessThan,
15
- gt: HandlebarsRatchet.greaterThan,
16
- lte: HandlebarsRatchet.lessThanEqual,
17
- gte: HandlebarsRatchet.greaterThanEqual,
18
- and: HandlebarsRatchet.and,
19
- or: HandlebarsRatchet.or,
20
- formatBytes: HandlebarsRatchet.formatBytes,
21
- rpn: HandlebarsRatchet.reversePolishNotation,
22
- add: HandlebarsRatchet.add,
23
- sub: HandlebarsRatchet.sub,
24
- mul: HandlebarsRatchet.mul,
25
- div: HandlebarsRatchet.div,
26
- mod: HandlebarsRatchet.mod,
27
- maxNum: HandlebarsRatchet.maxNum,
28
- minNum: HandlebarsRatchet.minNum,
29
- };
30
- }
31
- static registerAll(handlebars) {
32
- handlebars.registerHelper(HandlebarsRatchet.functionMap());
33
- }
34
- static add(v1, v2) {
35
- return ratchet_common_2.NumberRatchet.safeNumber(v1) + ratchet_common_2.NumberRatchet.safeNumber(v2);
36
- }
37
- static sub(v1, v2) {
38
- return ratchet_common_2.NumberRatchet.safeNumber(v1) - ratchet_common_2.NumberRatchet.safeNumber(v2);
39
- }
40
- static mul(v1, v2) {
41
- return ratchet_common_2.NumberRatchet.safeNumber(v1) * ratchet_common_2.NumberRatchet.safeNumber(v2);
42
- }
43
- static div(v1, v2) {
44
- return ratchet_common_2.NumberRatchet.safeNumber(v1) / ratchet_common_2.NumberRatchet.safeNumber(v2);
45
- }
46
- static mod(v1, v2) {
47
- return ratchet_common_2.NumberRatchet.safeNumber(v1) % ratchet_common_2.NumberRatchet.safeNumber(v2);
48
- }
49
- static equal(v1, v2) {
50
- return v1 === v2;
51
- }
52
- static notEqual(v1, v2) {
53
- return v1 !== v2;
54
- }
55
- static lessThan(v1, v2) {
56
- return v1 < v2;
57
- }
58
- static lessThanEqual(v1, v2) {
59
- return v1 <= v2;
60
- }
61
- static greaterThan(v1, v2) {
62
- return v1 > v2;
63
- }
64
- static greaterThanEqual(v1, v2) {
65
- return v1 >= v2;
66
- }
67
- static maxNum(...args) {
68
- return Math.max(...args.slice(0, -1));
69
- }
70
- static minNum(...args) {
71
- return Math.min(...args.slice(0, -1));
72
- }
73
- static and(...args) {
74
- return Array.prototype.every.call(args, Boolean);
75
- }
76
- static or(...args) {
77
- return Array.prototype.slice.call(args, 0, -1).some(Boolean);
78
- }
79
- static formatBytes(v1) {
80
- return ratchet_common_1.StringRatchet.formatBytes(v1);
81
- }
82
- static reversePolishNotation(...args) {
83
- var _a;
84
- let rval = null;
85
- try {
86
- const fns = Object.assign({}, HandlebarsRatchet.functionMap());
87
- delete fns['formatBytes'];
88
- const stack = [];
89
- for (let i = 0; i < args.length - 1; i++) {
90
- const a = args[i];
91
- if (fns[a]) {
92
- if (stack.length > 1) {
93
- const op2 = stack.pop();
94
- const op1 = stack.pop();
95
- const res = fns[a](op1, op2, {});
96
- stack.push(res);
97
- }
98
- else {
99
- ratchet_common_3.ErrorRatchet.throwFormattedErr('Cannot execute operation %s - not enough args', a);
100
- }
101
- }
102
- else {
103
- stack.push(a);
104
- }
105
- }
106
- rval = stack.pop();
107
- }
108
- catch (err) {
109
- ratchet_common_4.Logger.error('Failed to execute RPN: %s', err, err);
110
- rval = ((_a = ratchet_common_3.ErrorRatchet.asErr(err)) === null || _a === void 0 ? void 0 : _a.message) || 'Failure';
111
- }
112
- return rval;
113
- }
114
- }
115
- exports.HandlebarsRatchet = HandlebarsRatchet;
package/dist/cjs/index.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./build/ratchet-misc-info"), exports);
5
- tslib_1.__exportStar(require("./handlebars/handlebars-ratchet"), exports);
6
- tslib_1.__exportStar(require("./model-validator/model-validator"), exports);
7
- tslib_1.__exportStar(require("./rxjs/observable-ratchet"), exports);
8
- tslib_1.__exportStar(require("./rxjs/rxjs-ratchet"), exports);
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModelValidator = void 0;
4
- const tslib_1 = require("tslib");
5
- const swagger_model_validator_1 = tslib_1.__importDefault(require("swagger-model-validator"));
6
- const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
7
- const ratchet_common_1 = require("@bitblit/ratchet-common");
8
- class ModelValidator {
9
- constructor(allModels) {
10
- this.allModels = allModels;
11
- if (!allModels || Object.keys(allModels).length == 0) {
12
- ratchet_common_1.ErrorRatchet.throwFormattedErr('Cannot create model validator, passed models was null/empty : %j', allModels);
13
- }
14
- }
15
- static createFromYamlString(yamlString, rootPath) {
16
- const src = js_yaml_1.default.load(yamlString);
17
- const modelSrc = rootPath && rootPath.length > 0 ? ratchet_common_1.MapRatchet.findValue(src, rootPath) : src;
18
- return ModelValidator.createFromParsedObject(modelSrc);
19
- }
20
- static createFromParsedObject(parsedObject) {
21
- return new ModelValidator(parsedObject);
22
- }
23
- get modelNames() {
24
- return Object.keys(this.allModels);
25
- }
26
- addModel(modelName, model) {
27
- this.allModels[modelName] = model;
28
- }
29
- fetchModel(modelName) {
30
- return this.allModels[modelName];
31
- }
32
- validate(modelName, modelObject, emptyAllowed = false, extraPropertiesAllowed = true) {
33
- let rval = [];
34
- ratchet_common_1.Logger.silly('Validating model %s all definitions are : %j', modelName, this.allModels);
35
- const modelEmpty = !modelObject || Object.keys(modelObject).length === 0;
36
- if (modelEmpty) {
37
- if (!emptyAllowed) {
38
- rval.push('Empty / null object sent, but empty not allowed here');
39
- }
40
- }
41
- else {
42
- if (this.allModels && modelName && this.allModels[modelName]) {
43
- const validation = new swagger_model_validator_1.default().validate(modelObject, this.allModels[modelName], this.allModels, emptyAllowed, extraPropertiesAllowed);
44
- if (validation.errorCount > 0) {
45
- rval = validation.errors.map((e) => e.message);
46
- }
47
- }
48
- else {
49
- rval = ['Model named "' + modelName + '" not present in schema'];
50
- }
51
- }
52
- return rval;
53
- }
54
- }
55
- exports.ModelValidator = ModelValidator;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ObservableRatchet = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const ratchet_common_1 = require("@bitblit/ratchet-common");
6
- class ObservableRatchet {
7
- static timeout(srcObservable, title, timeoutMillis) {
8
- const rval = (0, rxjs_1.race)(srcObservable, this.createTimeoutObservable(title, timeoutMillis));
9
- return rval;
10
- }
11
- static createTimeoutObservable(title, timeoutMillis) {
12
- return rxjs_1.Observable.create((observer) => {
13
- const id = setTimeout(() => {
14
- clearTimeout(id);
15
- observer.next(new ratchet_common_1.TimeoutToken(title, timeoutMillis));
16
- }, timeoutMillis);
17
- });
18
- }
19
- }
20
- exports.ObservableRatchet = ObservableRatchet;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RxjsRatchet = void 0;
4
- const ratchet_common_1 = require("@bitblit/ratchet-common");
5
- class RxjsRatchet {
6
- static safeUnsubscribe(sub) {
7
- return ratchet_common_1.MapRatchet.safeCallFunction(sub, 'unsubscribe');
8
- }
9
- static async waitForNonNullOnSubject(subject) {
10
- if (!!subject.value) {
11
- return subject.value;
12
- }
13
- else {
14
- return new Promise((resolve, reject) => {
15
- const innerSub = subject.subscribe((val) => {
16
- if (!!val) {
17
- RxjsRatchet.safeUnsubscribe(innerSub);
18
- resolve(val);
19
- }
20
- });
21
- });
22
- }
23
- }
24
- static async waitForTargetValueOnSubject(subject, targetValue) {
25
- if (subject.value === targetValue) {
26
- return subject.value;
27
- }
28
- else {
29
- return new Promise((resolve, reject) => {
30
- const innerSub = subject.subscribe((val) => {
31
- if (val === targetValue) {
32
- RxjsRatchet.safeUnsubscribe(innerSub);
33
- resolve(val);
34
- }
35
- });
36
- });
37
- }
38
- }
39
- }
40
- exports.RxjsRatchet = RxjsRatchet;
package/dist/es/index.js DELETED
@@ -1,5 +0,0 @@
1
- export * from './build/ratchet-misc-info';
2
- export * from './handlebars/handlebars-ratchet';
3
- export * from './model-validator/model-validator';
4
- export * from './rxjs/observable-ratchet';
5
- export * from './rxjs/rxjs-ratchet';