@bitblit/ratchet-common 6.1.196-alpha → 6.1.198-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 (60) hide show
  1. package/lib/2d/matrix-factory.d.ts +1 -1
  2. package/lib/2d/matrix-factory.js +12 -12
  3. package/lib/2d/matrix-factory.js.map +1 -1
  4. package/lib/2d/plane-2d.d.ts +1 -1
  5. package/lib/2d/ratchet-2d.d.ts +6 -6
  6. package/lib/2d/ratchet-2d.js +16 -14
  7. package/lib/2d/ratchet-2d.js.map +1 -1
  8. package/lib/lang/base64-ratchet.js.map +1 -1
  9. package/lib/lang/boolean-ratchet.js +2 -2
  10. package/lib/lang/boolean-ratchet.js.map +1 -1
  11. package/lib/lang/global-ratchet.js +1 -1
  12. package/lib/lang/global-ratchet.js.map +1 -1
  13. package/lib/lang/map-ratchet.js +1 -1
  14. package/lib/lang/map-ratchet.js.map +1 -1
  15. package/lib/lang/number-ratchet.js +1 -1
  16. package/lib/lang/number-ratchet.js.map +1 -1
  17. package/lib/lang/promise-ratchet.js +1 -1
  18. package/lib/lang/promise-ratchet.js.map +1 -1
  19. package/lib/lang/simple-encryption-ratchet.js +6 -4
  20. package/lib/lang/simple-encryption-ratchet.js.map +1 -1
  21. package/lib/lang/stop-watch.js.map +1 -1
  22. package/lib/lang/string-ratchet.js +1 -1
  23. package/lib/lang/string-ratchet.js.map +1 -1
  24. package/lib/logger/logger-instance.js.map +1 -1
  25. package/lib/logger/logger-ring-buffer.js +2 -2
  26. package/lib/logger/logger-ring-buffer.js.map +1 -1
  27. package/lib/logger/logger.js.map +1 -1
  28. package/lib/mail/mailer.js +1 -1
  29. package/lib/mail/mailer.js.map +1 -1
  30. package/lib/network/restful-api-http-error.js +1 -1
  31. package/lib/network/restful-api-http-error.js.map +1 -1
  32. package/lib/transform/transform-ratchet.js +1 -1
  33. package/lib/transform/transform-ratchet.js.map +1 -1
  34. package/lib/typing/exact-and-require-all.d.ts +2 -2
  35. package/package.json +6 -2
  36. package/src/2d/matrix-factory.ts +19 -24
  37. package/src/2d/plane-2d-type.ts +1 -1
  38. package/src/2d/plane-2d.ts +1 -1
  39. package/src/2d/ratchet-2d.spec.ts +21 -12
  40. package/src/2d/ratchet-2d.ts +34 -25
  41. package/src/2d/transformation-matrix.ts +1 -1
  42. package/src/lang/base64-ratchet.ts +0 -1
  43. package/src/lang/boolean-ratchet.ts +2 -2
  44. package/src/lang/global-ratchet.ts +1 -1
  45. package/src/lang/map-ratchet.ts +3 -3
  46. package/src/lang/number-ratchet.ts +1 -1
  47. package/src/lang/promise-ratchet.ts +1 -1
  48. package/src/lang/simple-encryption-ratchet.ts +28 -34
  49. package/src/lang/stop-watch.ts +1 -1
  50. package/src/lang/string-ratchet.spec.ts +1 -2
  51. package/src/lang/string-ratchet.ts +2 -4
  52. package/src/logger/logger-instance.ts +3 -5
  53. package/src/logger/logger-ring-buffer.ts +3 -3
  54. package/src/logger/logger.ts +0 -2
  55. package/src/mail/mailer.ts +1 -1
  56. package/src/network/restful-api-http-error.ts +1 -1
  57. package/src/transform/transform-ratchet.ts +1 -1
  58. package/src/typing/exact-and-require-all.ts +3 -3
  59. package/src/typing/exact.ts +1 -2
  60. package/src/typing/require-all.ts +1 -1
@@ -6,7 +6,7 @@ import { NumberRatchet } from './number-ratchet.js';
6
6
 
7
7
  export class BooleanRatchet {
8
8
  public static allTrue(vals: boolean[], emptyArraysReturn = false): boolean {
9
- let rval: boolean = null;
9
+ let rval: boolean;
10
10
  if (vals) {
11
11
  if (vals.length > 0) {
12
12
  rval = vals.reduce((a, i) => a && i, true);
@@ -21,7 +21,7 @@ export class BooleanRatchet {
21
21
  }
22
22
 
23
23
  public static anyTrue(vals: boolean[], emptyArraysReturn = false): boolean {
24
- let rval: boolean = null;
24
+ let rval: boolean;
25
25
  if (vals) {
26
26
  if (vals.length > 0) {
27
27
  rval = vals.reduce((a, i) => a || i, false);
@@ -36,7 +36,7 @@ export class GlobalRatchet {
36
36
  rval = process; // Final failover, not really a great option
37
37
  }
38
38
  } catch (err) {
39
- throw new Error('Should not happen - error thrown trying to find global : '+ err);
39
+ throw new Error('Should not happen - error thrown trying to find global : ' + err, { cause: err });
40
40
  }
41
41
  if (!rval) {
42
42
  if (returnNullOnNone) {
@@ -5,7 +5,7 @@
5
5
  import { KeyValue } from './key-value.js';
6
6
  import { Logger } from '../logger/logger.js';
7
7
  import { ErrorRatchet } from './error-ratchet.js';
8
- import { StringRatchet } from "./string-ratchet.ts";
8
+ import { StringRatchet } from './string-ratchet.ts';
9
9
 
10
10
  export class MapRatchet {
11
11
  // Takes any map with keys that are nested and expands them
@@ -205,9 +205,9 @@ export class MapRatchet {
205
205
  return rval;
206
206
  }
207
207
 
208
- public static snakeCaseKeysToCamelCase(obj:any):any {
208
+ public static snakeCaseKeysToCamelCase(obj: any): any {
209
209
  if (Array.isArray(obj)) {
210
- return obj.map(v => StringRatchet.snakeCaseToCamelCase(v));
210
+ return obj.map((v) => StringRatchet.snakeCaseToCamelCase(v));
211
211
  } else if (obj !== null && obj.constructor === Object) {
212
212
  return Object.entries(obj).reduce((acc, [key, value]) => {
213
213
  const camelKey = key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
@@ -67,7 +67,7 @@ export class NumberRatchet {
67
67
  }
68
68
 
69
69
  public static safeNumberOpt(input: any, optionPart?: Partial<SafeNumberOptions>): number {
70
- let rval: number = undefined;
70
+ let rval: number;
71
71
  const opts: SafeNumberOptions = Object.assign({}, NumberRatchet.DEFAULT_SAFE_NUMBER_OPTIONS, optionPart || {});
72
72
  if (input === null) {
73
73
  rval = opts.returnValueForNull;
@@ -107,7 +107,7 @@ export class PromiseRatchet {
107
107
  return false;
108
108
  }
109
109
 
110
- let curVal: any = null;
110
+ let curVal: any;
111
111
  try {
112
112
  curVal = testFunction(count);
113
113
  } catch (err) {
@@ -1,18 +1,23 @@
1
- import { RequireRatchet } from "./require-ratchet.ts";
2
- import { NumberRatchet } from "./number-ratchet.ts";
3
- import { Base64Ratchet } from "./base64-ratchet.ts";
1
+ import { RequireRatchet } from './require-ratchet.ts';
2
+ import { NumberRatchet } from './number-ratchet.ts';
3
+ import { Base64Ratchet } from './base64-ratchet.ts';
4
4
 
5
5
  /**
6
6
  * A VERY simple wrapper for doing basic AES-GCM encryption on arbitrary text -
7
7
  * useful for slugs, etc., since the same code should work both in Node.js and
8
8
  * most modern browsers
9
9
  */
10
- export class SimpleEncryptionRatchet{
10
+ export class SimpleEncryptionRatchet {
11
11
  private sharedKey: Promise<CryptoKey>;
12
12
 
13
- constructor(sharedRawKey: string | Promise<string>, private urlSafe:boolean = false, private ivLength: number = 12) { // Recommended for AES-GCM
13
+ constructor(
14
+ sharedRawKey: string | Promise<string>,
15
+ private urlSafe: boolean = false,
16
+ private ivLength: number = 12,
17
+ ) {
18
+ // Recommended for AES-GCM
14
19
  RequireRatchet.notNullOrUndefined(sharedRawKey);
15
- RequireRatchet.true(ivLength>=12, 'ivLength must be at least 12');
20
+ RequireRatchet.true(ivLength >= 12, 'ivLength must be at least 12');
16
21
  this.sharedKey = this.createSharedKey(sharedRawKey);
17
22
  }
18
23
 
@@ -28,25 +33,24 @@ export class SimpleEncryptionRatchet{
28
33
 
29
34
  // Converts base64 to ArrayBuffer
30
35
  private base64ToBuf(base64: string): Uint8Array<ArrayBuffer> {
31
- return new Uint8Array(atob(base64).split('').map(c => c.charCodeAt(0)));
36
+ return new Uint8Array(
37
+ atob(base64)
38
+ .split('')
39
+ .map((c) => c.charCodeAt(0)),
40
+ );
32
41
  }
33
42
 
34
-
35
43
  // Encrypt a string with a shared key
36
44
  public async encrypt(data: string): Promise<string> {
37
- const iv:Uint8Array<ArrayBuffer> = crypto.getRandomValues(new Uint8Array(this.ivLength));
38
- const encoded:Uint8Array<ArrayBuffer> = this.strToBuf(data);
45
+ const iv: Uint8Array<ArrayBuffer> = crypto.getRandomValues(new Uint8Array(this.ivLength));
46
+ const encoded: Uint8Array<ArrayBuffer> = this.strToBuf(data);
39
47
  const key: CryptoKey = await this.sharedKey;
40
- const ciphertext = await crypto.subtle.encrypt(
41
- { name: "AES-GCM", iv },
42
- key,
43
- encoded
44
- );
48
+ const ciphertext = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, encoded);
45
49
  const ivMsg: string = this.bufToBase64(iv.buffer);
46
50
  const dataMsg: string = this.bufToBase64(ciphertext);
47
51
 
48
52
  // Format it up in a way that can be unrolled later
49
- let rval: string = ivMsg.length+'K'+ivMsg+dataMsg;
53
+ let rval: string = ivMsg.length + 'K' + ivMsg + dataMsg;
50
54
  if (this.urlSafe) {
51
55
  rval = Base64Ratchet.encodeStringToBase64UrlString(rval);
52
56
  }
@@ -56,20 +60,16 @@ export class SimpleEncryptionRatchet{
56
60
  // Decrypt a string with the shared key
57
61
  public async decrypt(encryptedValueIn: string): Promise<string> {
58
62
  const encryptedValue: string = this.urlSafe ? Base64Ratchet.decodeBase64UrlStringToString(encryptedValueIn) : encryptedValueIn;
59
- const split: number = encryptedValue?.indexOf('K')
60
- if (!split || split<1) {
61
- throw new Error('Invalid split : '+split);
63
+ const split: number = encryptedValue?.indexOf('K');
64
+ if (!split || split < 1) {
65
+ throw new Error('Invalid split : ' + split);
62
66
  }
63
67
  const ivLen: number = NumberRatchet.safeNumber(encryptedValue.substring(0, split));
64
- const iv: string = encryptedValue.substring(split+1, split+1+ivLen);
65
- const data: string = encryptedValue.substring(split+1+ivLen);
68
+ const iv: string = encryptedValue.substring(split + 1, split + 1 + ivLen);
69
+ const data: string = encryptedValue.substring(split + 1 + ivLen);
66
70
 
67
71
  const key: CryptoKey = await this.sharedKey;
68
- const decrypted = await crypto.subtle.decrypt(
69
- { name: "AES-GCM", iv: this.base64ToBuf(iv) },
70
- key,
71
- this.base64ToBuf(data)
72
- );
72
+ const decrypted = await crypto.subtle.decrypt({ name: 'AES-GCM', iv: this.base64ToBuf(iv) }, key, this.base64ToBuf(data));
73
73
  return new TextDecoder().decode(decrypted);
74
74
  }
75
75
 
@@ -77,12 +77,6 @@ export class SimpleEncryptionRatchet{
77
77
  private async createSharedKey(rawKeyIn: string | Promise<string>): Promise<CryptoKey> {
78
78
  const rawKey: string = typeof rawKeyIn === 'string' ? rawKeyIn : await rawKeyIn;
79
79
  const keyMaterial = this.strToBuf(rawKey.padEnd(32, '0').slice(0, 32)); // 256-bit key
80
- return crypto.subtle.importKey(
81
- "raw",
82
- keyMaterial,
83
- "AES-GCM",
84
- false,
85
- ["encrypt", "decrypt"]
86
- );
80
+ return crypto.subtle.importKey('raw', keyMaterial, 'AES-GCM', false, ['encrypt', 'decrypt']);
87
81
  }
88
- }
82
+ }
@@ -24,7 +24,7 @@ export class StopWatch {
24
24
  // move the create-time into the past for testing things. Might have
25
25
  // some other uses, not really sure
26
26
  public moveCreateTime(offset: number): number {
27
- this._createTime+=offset;
27
+ this._createTime += offset;
28
28
  return this._createTime;
29
29
  }
30
30
 
@@ -84,7 +84,6 @@ describe('#randomGeneration', function () {
84
84
  expect(result).toBeTruthy();
85
85
  expect(result.length).toEqual(12);
86
86
  });
87
-
88
87
  });
89
88
 
90
89
  describe('#leadingZeros', function () {
@@ -226,7 +225,7 @@ describe('substring finder', () => {
226
225
 
227
226
  describe('alphabet checker', () => {
228
227
  test('should detect bad chars', () => {
229
- expect(StringRatchet.stringContainsOnly())
228
+ expect(StringRatchet.stringContainsOnly());
230
229
  expect(StringRatchet.longestNonOverlappingRepeatingSubstring('abc123abc')).toEqual('abc');
231
230
  expect(StringRatchet.longestNonOverlappingRepeatingSubstring('abc123456')).toEqual(null);
232
231
  });
@@ -187,7 +187,7 @@ export class StringRatchet {
187
187
  * @param len - Desired length of the random string.
188
188
  * @returns The generated random string.
189
189
  */
190
- public static createRandomStringFromAlphabet(alphabet: string, len:number = 10): string {
190
+ public static createRandomStringFromAlphabet(alphabet: string, len: number = 10): string {
191
191
  RequireRatchet.notNullUndefinedOrOnlyWhitespaceString(alphabet, 'Alphabet may not be empty');
192
192
  let rval: string = '';
193
193
 
@@ -195,7 +195,6 @@ export class StringRatchet {
195
195
  rval += alphabet.charAt(Math.floor(Math.random() * alphabet.length));
196
196
  }
197
197
  return rval;
198
-
199
198
  }
200
199
 
201
200
  /**
@@ -527,7 +526,7 @@ export class StringRatchet {
527
526
  * @returns A JSON string representation of the input, or an error message if circular references are found.
528
527
  */
529
528
  public static circSafeJsonStringify(input: any): string {
530
- let rval: string = null;
529
+ let rval: string;
531
530
  try {
532
531
  rval = JSON.stringify(input);
533
532
  } catch (err) {
@@ -667,5 +666,4 @@ export class StringRatchet {
667
666
  public static snakeCaseToCamelCase(str) {
668
667
  return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
669
668
  }
670
-
671
669
  }
@@ -31,19 +31,17 @@ export class LoggerInstance {
31
31
  this.options = inOptions; // MUST use the setter here
32
32
  }
33
33
 
34
-
35
34
  public findMessagesMatchingInBuffer(regex: RegExp): LogMessage[] {
36
35
  if (!this._ringBuffer) {
37
- throw new Error('Called findMessagesMatchingInBuffer with no ring buffer configured')
36
+ throw new Error('Called findMessagesMatchingInBuffer with no ring buffer configured');
38
37
  }
39
38
  return this._ringBuffer.findMessagesMatchingInBuffer(regex);
40
39
  }
41
40
 
42
41
  public hasMessageMatchingInBuffer(regex: RegExp): boolean {
43
- return this.findMessagesMatchingInBuffer(regex).length>0;
42
+ return this.findMessagesMatchingInBuffer(regex).length > 0;
44
43
  }
45
44
 
46
-
47
45
  public levelIsEnabled(level: LoggerLevelName): boolean {
48
46
  return LoggerUtil.levelIsEnabled(level, this._level);
49
47
  }
@@ -195,7 +193,7 @@ export class LoggerInstance {
195
193
  fn(rval);
196
194
  }
197
195
  // If it was logged out, or it wasn't but the formatter says to still put it in the ringbuffer...
198
- if (this._ringBuffer && (rval || this.options.formatType===LogMessageFormatType.RingBufferOnly)) {
196
+ if (this._ringBuffer && (rval || this.options.formatType === LogMessageFormatType.RingBufferOnly)) {
199
197
  this._ringBuffer.addToRingBuffer(msg);
200
198
  }
201
199
  } else {
@@ -18,12 +18,12 @@ export class LoggerRingBuffer {
18
18
  }
19
19
 
20
20
  public findMessagesMatchingInBuffer(regex: RegExp): LogMessage[] {
21
- const rval: LogMessage[] = this._buffer.filter(s=>s.messageSource.match(regex));
21
+ const rval: LogMessage[] = this._buffer.filter((s) => s.messageSource.match(regex));
22
22
  return rval;
23
23
  }
24
24
 
25
25
  public hasMessageMatchingInBuffer(regex: RegExp): boolean {
26
- return this.findMessagesMatchingInBuffer(regex).length>0;
26
+ return this.findMessagesMatchingInBuffer(regex).length > 0;
27
27
  }
28
28
 
29
29
  public get currentIndex(): number {
@@ -43,7 +43,7 @@ export class LoggerRingBuffer {
43
43
  }
44
44
 
45
45
  public getMessages(inStartFrom: number = null, clear = false, reverseSort = false): LogMessage[] {
46
- let rval: LogMessage[] = null;
46
+ let rval: LogMessage[];
47
47
  if (this._bufferIdx < this._bufferSize) {
48
48
  const start: number = inStartFrom == null ? 0 : inStartFrom;
49
49
  rval = this._buffer.slice(start, this._bufferIdx); // Use slice to get a copy (should use below too)
@@ -32,7 +32,6 @@ export class Logger {
32
32
  preProcessors: [],
33
33
  };
34
34
 
35
-
36
35
  public static findMessagesMatchingInBuffer(regex: RegExp): LogMessage[] {
37
36
  return Logger.getLogger().findMessagesMatchingInBuffer(regex);
38
37
  }
@@ -41,7 +40,6 @@ export class Logger {
41
40
  return Logger.getLogger().hasMessageMatchingInBuffer(regex);
42
41
  }
43
42
 
44
-
45
43
  public static applyDefaultsToOptions(input?: Partial<LoggerOptions>): LoggerOptions {
46
44
  const rval: LoggerOptions = input || {};
47
45
  rval.initialLevel = rval.initialLevel ?? Logger.DEFAULT_OPTIONS.initialLevel;
@@ -152,7 +152,7 @@ export class Mailer<T, R> implements MailerLike<T, R> {
152
152
  public async sendEmail(inRts: ReadyToSendEmail): Promise<SendEmailResult<T, R>> {
153
153
  RequireRatchet.notNullOrUndefined(inRts, 'RTS must be defined');
154
154
  RequireRatchet.notNullOrUndefined(inRts.destinationAddresses, 'Destination addresses must be defined');
155
- let rval: SendEmailResult<T, R> = null;
155
+ let rval: SendEmailResult<T, R>;
156
156
 
157
157
  const resolved: ResolvedReadyToSendEmail = await this.resolveReadyToSendEmail(inRts);
158
158
  try {
@@ -80,7 +80,7 @@ export class RestfulApiHttpError<T = void> extends Error {
80
80
  }
81
81
 
82
82
  public static wrapError<T = void>(err: Error): RestfulApiHttpError<T> {
83
- let rval: RestfulApiHttpError<T> = null;
83
+ let rval: RestfulApiHttpError<T>;
84
84
  if (RestfulApiHttpError.objectIsRestfulApiHttpError(err)) {
85
85
  rval = err as RestfulApiHttpError<T>;
86
86
  } else {
@@ -19,7 +19,7 @@ export class TransformRatchet {
19
19
  }
20
20
 
21
21
  private static transformGeneric(toTransform: any, rules: TransformRule[] = [], isKey: boolean, context: any): any {
22
- let rval: any = null;
22
+ let rval: any;
23
23
  const type: string = typeof toTransform;
24
24
  switch (type) {
25
25
  case 'undefined':
@@ -1,9 +1,9 @@
1
- import { RequireAll } from "./require-all.ts";
2
- import { Exact } from "./exact.ts";
1
+ import { RequireAll } from './require-all.ts';
2
+ import { Exact } from './exact.ts';
3
3
 
4
4
  /**
5
5
  * This is used in a "satisfy" clause to make sure that an object
6
6
  * contains all the fields in T and does not contain any fields
7
7
  * not in T
8
8
  */
9
- export type ExactAndRequireAll<T> = Exact<RequireAll<T>>;
9
+ export type ExactAndRequireAll<T> = Exact<RequireAll<T>>;
@@ -2,5 +2,4 @@
2
2
  * This is used in a "satisfy" clause to make sure that an object
3
3
  * DOES NOT contain any fields that the referred type doesn't have
4
4
  */
5
- export type Exact<T extends object> =
6
- T & Partial<Record<Exclude<string, keyof T>, never>>;
5
+ export type Exact<T extends object> = T & Partial<Record<Exclude<string, keyof T>, never>>;
@@ -4,4 +4,4 @@
4
4
  */
5
5
  export type RequireAll<T> = {
6
6
  [K in keyof T]-?: NonNullable<T[K]>;
7
- };
7
+ };