@naturalcycles/js-lib 14.274.1 → 14.275.0

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.
@@ -35,6 +35,7 @@
35
35
  "resolveJsonModule": true,
36
36
  "suppressImplicitAnyIndexErrors": false,
37
37
  "noUncheckedIndexedAccess": true,
38
+ "noUncheckedSideEffectImports": true,
38
39
  "noPropertyAccessFromIndexSignature": true,
39
40
  "noImplicitOverride": true,
40
41
 
package/dist/bot.js CHANGED
@@ -11,9 +11,13 @@ const botRegex = /bot|spider|crawl|headless|electron|phantom|slimer|proximic|cin
11
11
  * @experimental
12
12
  */
13
13
  class BotDetectionService {
14
+ cfg;
14
15
  constructor(cfg = {}) {
15
16
  this.cfg = cfg;
16
17
  }
18
+ // memoized results
19
+ botReason;
20
+ cdp;
17
21
  isBotOrCDP() {
18
22
  return !!this.getBotReason() || this.isCDP();
19
23
  }
@@ -17,8 +17,6 @@ const NOOP = () => { };
17
17
  */
18
18
  class AdminService {
19
19
  constructor(cfg) {
20
- this.adminMode = false;
21
- this.listening = false;
22
20
  this.cfg = {
23
21
  predicate: e => e.ctrlKey && e.key === 'L',
24
22
  persistToLocalStorage: true,
@@ -30,6 +28,9 @@ class AdminService {
30
28
  ...cfg,
31
29
  };
32
30
  }
31
+ cfg;
32
+ adminMode = false;
33
+ listening = false;
33
34
  /**
34
35
  * Start listening to keyboard events to toggle AdminMode when detected.
35
36
  */
@@ -7,6 +7,7 @@ exports.FetchTranslationLoader = void 0;
7
7
  * ${baseUrl}/${locale}.json
8
8
  */
9
9
  class FetchTranslationLoader {
10
+ fetcher;
10
11
  constructor(fetcher) {
11
12
  this.fetcher = fetcher;
12
13
  }
@@ -18,6 +18,12 @@ class TranslationService {
18
18
  };
19
19
  this.currentLocale = cfg.currentLocale || cfg.defaultLocale;
20
20
  }
21
+ cfg;
22
+ /**
23
+ * Cache of loaded locales
24
+ */
25
+ locales;
26
+ currentLocale;
21
27
  /**
22
28
  * Manually set locale data, bypassing the TranslationLoader.
23
29
  */
@@ -10,7 +10,6 @@ exports.ImageFitter = void 0;
10
10
  */
11
11
  class ImageFitter {
12
12
  constructor(cfg) {
13
- this.containerWidth = -1;
14
13
  this.cfg = {
15
14
  maxHeight: 300,
16
15
  margin: 8,
@@ -19,6 +18,9 @@ class ImageFitter {
19
18
  this.resizeObserver = new ResizeObserver(entries => this.update(entries));
20
19
  this.resizeObserver.observe(cfg.containerElement);
21
20
  }
21
+ cfg;
22
+ resizeObserver;
23
+ containerWidth = -1;
22
24
  stop() {
23
25
  this.resizeObserver.disconnect();
24
26
  }
@@ -8,6 +8,8 @@ const localDate_1 = require("./localDate");
8
8
  * @experimental
9
9
  */
10
10
  class DateInterval {
11
+ start;
12
+ end;
11
13
  constructor(start, end) {
12
14
  this.start = start;
13
15
  this.end = end;
@@ -15,6 +15,9 @@ const COMPACT_DATE_REGEX = /^(\d\d\d\d)(\d\d)(\d\d)$/;
15
15
  * It is timezone-independent.
16
16
  */
17
17
  class LocalDate {
18
+ year;
19
+ month;
20
+ day;
18
21
  constructor(year, month, day) {
19
22
  this.year = year;
20
23
  this.month = month;
@@ -37,6 +37,7 @@ const DATE_TIME_REGEX_LOOSE = /^(\d{4})-(\d{2})-(\d{2})([Tt\s](\d{2}):?(\d{2})?:
37
37
  const DATE_TIME_REGEX_STRICT = /^(\d{4})-(\d{2})-(\d{2})[Tt\s](\d{2}):(\d{2}):(\d{2})/;
38
38
  const DATE_REGEX_STRICT = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
39
39
  class LocalTime {
40
+ $date;
40
41
  constructor($date) {
41
42
  this.$date = $date;
42
43
  }
@@ -9,6 +9,8 @@ const localTime_1 = require("./localTime");
9
9
  * @experimental
10
10
  */
11
11
  class TimeInterval {
12
+ $start;
13
+ $end;
12
14
  constructor($start, $end) {
13
15
  this.$start = $start;
14
16
  this.$end = $end;
@@ -13,6 +13,12 @@ const localTime_1 = require("./localTime");
13
13
  * Can be pretty-printed as Date, Time or DateAndTime.
14
14
  */
15
15
  class WallTime {
16
+ year;
17
+ month;
18
+ day;
19
+ hour;
20
+ minute;
21
+ second;
16
22
  constructor(obj) {
17
23
  Object.assign(this, obj);
18
24
  }
@@ -58,9 +58,7 @@ export class ObjectMemoCache implements MemoCache {
58
58
  }
59
59
  */
60
60
  class MapMemoCache {
61
- constructor() {
62
- this.m = new Map();
63
- }
61
+ m = new Map();
64
62
  has(k) {
65
63
  return this.m.has(k);
66
64
  }
@@ -81,10 +79,11 @@ exports.MapMemoCache = MapMemoCache;
81
79
  * because the point of AsyncMemoCache is to have an **async** backed cache.
82
80
  */
83
81
  class MapAsyncMemoCache {
82
+ delay;
84
83
  constructor(delay = 0) {
85
84
  this.delay = delay;
86
- this.m = new Map();
87
85
  }
86
+ m = new Map();
88
87
  async get(k) {
89
88
  await (0, pDelay_1.pDelay)(this.delay);
90
89
  if (!this.m.has(k))
@@ -33,6 +33,14 @@ class DeviceIdService {
33
33
  };
34
34
  this.init();
35
35
  }
36
+ cfg;
37
+ /**
38
+ * `deviceId` is null only in anomalous cases, e.g when localStorage is not available (due to e.g "out of disk space" on device).
39
+ * In all other cases it should be defined and stable (persisted indefinitely between multiple visits).
40
+ *
41
+ * It is null if the service is run on the server side.
42
+ */
43
+ deviceId;
36
44
  /**
37
45
  * Selects this device based on "deterministic random selection", according to the defined `rate`.
38
46
  * Rate is a floating number between 0 and 1.
@@ -237,6 +237,11 @@ function _errorDataAppend(err, data) {
237
237
  * Based on: https://medium.com/@xpl/javascript-deriving-from-error-properly-8d2f8f315801
238
238
  */
239
239
  class AppError extends Error {
240
+ data;
241
+ /**
242
+ * `cause` here is normalized to be an ErrorObject
243
+ */
244
+ cause;
240
245
  /**
241
246
  * Experimental alternative static constructor.
242
247
  */
@@ -41,8 +41,8 @@ class Fetcher {
41
41
  *
42
42
  * Version is to be incremented every time a difference in behaviour (or a bugfix) is done.
43
43
  */
44
- static { this.VERSION = 2; }
45
- static { this.userAgent = (0, env_1.isServerSide)() ? `fetcher${this.VERSION}` : undefined; }
44
+ static VERSION = 2;
45
+ static userAgent = (0, env_1.isServerSide)() ? `fetcher${this.VERSION}` : undefined;
46
46
  constructor(cfg = {}) {
47
47
  if (typeof globalThis.fetch !== 'function') {
48
48
  throw new TypeError('globalThis.fetch is not available');
@@ -103,9 +103,30 @@ class Fetcher {
103
103
  (this.cfg.hooks.onError ||= []).push(hook);
104
104
  return this;
105
105
  }
106
+ cfg;
106
107
  static create(cfg = {}) {
107
108
  return new Fetcher(cfg);
108
109
  }
110
+ // These methods are generated dynamically in the constructor
111
+ // These default methods use responseType=json
112
+ get;
113
+ post;
114
+ put;
115
+ patch;
116
+ delete;
117
+ // responseType=text
118
+ getText;
119
+ postText;
120
+ putText;
121
+ patchText;
122
+ deleteText;
123
+ // responseType=void (no body fetching/parsing)
124
+ getVoid;
125
+ postVoid;
126
+ putVoid;
127
+ patchVoid;
128
+ deleteVoid;
129
+ headVoid;
109
130
  /**
110
131
  * Small convenience wrapper that allows to issue GraphQL queries.
111
132
  * In practice, all it does is:
package/dist/index.d.ts CHANGED
@@ -94,9 +94,3 @@ export * from './typeFest';
94
94
  export * from './types';
95
95
  export * from './unit/size.util';
96
96
  export * from './web';
97
- export * from './zod/zod.shared.schemas';
98
- export * from './zod/zod.util';
99
- import type { ZodIssue } from 'zod';
100
- import { z, ZodError, ZodSchema } from 'zod';
101
- export { z, ZodError, ZodSchema };
102
- export type { ZodIssue };
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZodSchema = exports.ZodError = exports.z = void 0;
4
3
  const tslib_1 = require("tslib");
5
4
  tslib_1.__exportStar(require("./abort"), exports);
6
5
  tslib_1.__exportStar(require("./array/array.util"), exports);
@@ -98,9 +97,3 @@ tslib_1.__exportStar(require("./typeFest"), exports);
98
97
  tslib_1.__exportStar(require("./types"), exports);
99
98
  tslib_1.__exportStar(require("./unit/size.util"), exports);
100
99
  tslib_1.__exportStar(require("./web"), exports);
101
- tslib_1.__exportStar(require("./zod/zod.shared.schemas"), exports);
102
- tslib_1.__exportStar(require("./zod/zod.util"), exports);
103
- const zod_1 = require("zod");
104
- Object.defineProperty(exports, "z", { enumerable: true, get: function () { return zod_1.z; } });
105
- Object.defineProperty(exports, "ZodError", { enumerable: true, get: function () { return zod_1.ZodError; } });
106
- Object.defineProperty(exports, "ZodSchema", { enumerable: true, get: function () { return zod_1.ZodSchema; } });
@@ -13,6 +13,7 @@ const types_1 = require("../types");
13
13
  * @experimental
14
14
  */
15
15
  class AsyncIterable2 {
16
+ it;
16
17
  constructor(it) {
17
18
  this.it = it;
18
19
  }
@@ -11,6 +11,7 @@ const types_1 = require("../types");
11
11
  * @experimental
12
12
  */
13
13
  class Iterable2 {
14
+ it;
14
15
  constructor(it) {
15
16
  this.it = it;
16
17
  }
@@ -86,6 +86,7 @@ exports.jsonSchema = {
86
86
  },
87
87
  };
88
88
  class JsonSchemaAnyBuilder {
89
+ schema;
89
90
  constructor(schema) {
90
91
  this.schema = schema;
91
92
  }
@@ -165,16 +166,6 @@ class JsonSchemaNumberBuilder extends JsonSchemaAnyBuilder {
165
166
  super({
166
167
  type: 'number',
167
168
  });
168
- this.int32 = () => this.format('int32');
169
- this.int64 = () => this.format('int64');
170
- this.float = () => this.format('float');
171
- this.double = () => this.format('double');
172
- this.unixTimestamp = () => this.format('unixTimestamp');
173
- this.unixTimestamp2000 = () => this.format('unixTimestamp2000');
174
- this.unixTimestampMillis = () => this.format('unixTimestampMillis');
175
- this.unixTimestampMillis2000 = () => this.format('unixTimestampMillis2000');
176
- this.utcOffset = () => this.format('utcOffset');
177
- this.utcOffsetHours = () => this.format('utcOffsetHours');
178
169
  }
179
170
  integer() {
180
171
  Object.assign(this.schema, { type: 'integer' });
@@ -211,6 +202,16 @@ class JsonSchemaNumberBuilder extends JsonSchemaAnyBuilder {
211
202
  Object.assign(this.schema, { format });
212
203
  return this;
213
204
  }
205
+ int32 = () => this.format('int32');
206
+ int64 = () => this.format('int64');
207
+ float = () => this.format('float');
208
+ double = () => this.format('double');
209
+ unixTimestamp = () => this.format('unixTimestamp');
210
+ unixTimestamp2000 = () => this.format('unixTimestamp2000');
211
+ unixTimestampMillis = () => this.format('unixTimestampMillis');
212
+ unixTimestampMillis2000 = () => this.format('unixTimestampMillis2000');
213
+ utcOffset = () => this.format('utcOffset');
214
+ utcOffsetHours = () => this.format('utcOffsetHours');
214
215
  }
215
216
  exports.JsonSchemaNumberBuilder = JsonSchemaNumberBuilder;
216
217
  class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder {
@@ -218,21 +219,6 @@ class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder {
218
219
  super({
219
220
  type: 'string',
220
221
  });
221
- this.email = () => this.format('email');
222
- this.date = () => this.format('date');
223
- this.url = () => this.format('url');
224
- this.ipv4 = () => this.format('ipv4');
225
- this.ipv6 = () => this.format('ipv6');
226
- this.password = () => this.format('password');
227
- this.id = () => this.format('id');
228
- this.slug = () => this.format('slug');
229
- this.semVer = () => this.format('semVer');
230
- this.languageTag = () => this.format('languageTag');
231
- this.countryCode = () => this.format('countryCode');
232
- this.currency = () => this.format('currency');
233
- this.trim = (trim = true) => this.transformModify('trim', trim);
234
- this.toLowerCase = (toLowerCase = true) => this.transformModify('toLowerCase', toLowerCase);
235
- this.toUpperCase = (toUpperCase = true) => this.transformModify('toUpperCase', toUpperCase);
236
222
  }
237
223
  pattern(pattern) {
238
224
  Object.assign(this.schema, { pattern });
@@ -254,6 +240,21 @@ class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder {
254
240
  Object.assign(this.schema, { format });
255
241
  return this;
256
242
  }
243
+ email = () => this.format('email');
244
+ date = () => this.format('date');
245
+ url = () => this.format('url');
246
+ ipv4 = () => this.format('ipv4');
247
+ ipv6 = () => this.format('ipv6');
248
+ password = () => this.format('password');
249
+ id = () => this.format('id');
250
+ slug = () => this.format('slug');
251
+ semVer = () => this.format('semVer');
252
+ languageTag = () => this.format('languageTag');
253
+ countryCode = () => this.format('countryCode');
254
+ currency = () => this.format('currency');
255
+ trim = (trim = true) => this.transformModify('trim', trim);
256
+ toLowerCase = (toLowerCase = true) => this.transformModify('toLowerCase', toLowerCase);
257
+ toUpperCase = (toUpperCase = true) => this.transformModify('toUpperCase', toUpperCase);
257
258
  transformModify(t, add) {
258
259
  if (add) {
259
260
  this.schema.transform = (0, array_util_1._uniq)([...(this.schema.transform || []), t]);
@@ -8,10 +8,8 @@ exports.AccumulatingAverage = void 0;
8
8
  * @experimental
9
9
  */
10
10
  class AccumulatingAverage {
11
- constructor() {
12
- this.total = 0;
13
- this.count = 0;
14
- }
11
+ total = 0;
12
+ count = 0;
15
13
  /**
16
14
  * Returns the current average.
17
15
  * Returns 0 if no values have been added.
package/dist/math/sma.js CHANGED
@@ -5,14 +5,16 @@ exports.SimpleMovingAverage = void 0;
5
5
  * Implements a Simple Moving Average algorithm.
6
6
  */
7
7
  class SimpleMovingAverage {
8
+ size;
9
+ data;
8
10
  constructor(size, data = []) {
9
11
  this.size = size;
10
12
  this.data = data;
11
- /**
12
- * Next index of array to push to
13
- */
14
- this.nextIndex = 0;
15
13
  }
14
+ /**
15
+ * Next index of array to push to
16
+ */
17
+ nextIndex = 0;
16
18
  /**
17
19
  * Current average (calculated on the fly).
18
20
  * Returns 0 (not undefined) for empty data.
@@ -10,15 +10,16 @@ const index_1 = require("../index");
10
10
  *
11
11
  */
12
12
  class Stack {
13
+ size;
13
14
  constructor(size) {
14
15
  this.size = size;
15
- /**
16
- * Index of a slot to get written TO next.
17
- * Currently this slot contains OLDEST item (if any).
18
- */
19
- this.nextIndex = 0;
20
- this.items = [];
21
16
  }
17
+ /**
18
+ * Index of a slot to get written TO next.
19
+ * Currently this slot contains OLDEST item (if any).
20
+ */
21
+ nextIndex = 0;
22
+ items = [];
22
23
  push(item) {
23
24
  this.items[this.nextIndex] = item;
24
25
  this.nextIndex = this.nextIndex === this.size - 1 ? 0 : this.nextIndex + 1;
@@ -14,10 +14,11 @@ exports.abortable = abortable;
14
14
  * @experimental
15
15
  */
16
16
  class Abortable {
17
+ onAbort;
17
18
  constructor(onAbort) {
18
19
  this.onAbort = onAbort;
19
- this.aborted = false;
20
20
  }
21
+ aborted = false;
21
22
  abort() {
22
23
  if (this.aborted)
23
24
  return;
@@ -13,9 +13,6 @@ const pDefer_1 = require("./pDefer");
13
13
  */
14
14
  class PQueue {
15
15
  constructor(cfg) {
16
- this.inFlight = 0;
17
- this.queue = [];
18
- this.onIdleListeners = [];
19
16
  this.cfg = {
20
17
  // concurrency: Number.MAX_SAFE_INTEGER,
21
18
  errorMode: errorMode_1.ErrorMode.THROW_IMMEDIATELY,
@@ -28,9 +25,13 @@ class PQueue {
28
25
  this.debug = () => { };
29
26
  }
30
27
  }
28
+ cfg;
31
29
  debug(...args) {
32
30
  this.cfg.logger.log(...args);
33
31
  }
32
+ inFlight = 0;
33
+ queue = [];
34
+ onIdleListeners = [];
34
35
  get queueSize() {
35
36
  return this.queue.length;
36
37
  }
package/dist/semver.js CHANGED
@@ -21,14 +21,9 @@ const assert_1 = require("./error/assert");
21
21
  * @experimental
22
22
  */
23
23
  class Semver {
24
+ tokens;
24
25
  constructor(tokens) {
25
26
  this.tokens = tokens;
26
- this.isAfter = (other) => this.compare(other) > 0;
27
- this.isSameOrAfter = (other) => this.compare(other) >= 0;
28
- this.isBefore = (other) => this.compare(other) < 0;
29
- this.isSameOrBefore = (other) => this.compare(other) <= 0;
30
- this.isSame = (other) => this.compare(other) === 0;
31
- this.toJSON = () => this.toString();
32
27
  }
33
28
  get major() {
34
29
  return this.tokens[0];
@@ -39,6 +34,11 @@ class Semver {
39
34
  get patch() {
40
35
  return this.tokens[2];
41
36
  }
37
+ isAfter = (other) => this.compare(other) > 0;
38
+ isSameOrAfter = (other) => this.compare(other) >= 0;
39
+ isBefore = (other) => this.compare(other) < 0;
40
+ isSameOrBefore = (other) => this.compare(other) <= 0;
41
+ isSame = (other) => this.compare(other) === 0;
42
42
  /**
43
43
  * Returns 1 if this > other
44
44
  * returns 0 if they are equal
@@ -54,6 +54,7 @@ class Semver {
54
54
  }
55
55
  return 0;
56
56
  }
57
+ toJSON = () => this.toString();
57
58
  toString() {
58
59
  return this.tokens.join('.');
59
60
  }
@@ -16,6 +16,7 @@ exports.MissingValueError = void 0;
16
16
  exports.pupa = pupa;
17
17
  const escape_1 = require("./escape");
18
18
  class MissingValueError extends Error {
19
+ key;
19
20
  constructor(key) {
20
21
  super(`Missing a value for ${key ? `the placeholder: ${key}` : 'a placeholder'}`);
21
22
  this.key = key;
package/dist/web.js CHANGED
@@ -16,6 +16,7 @@ exports.InMemoryWebStorage = void 0;
16
16
  * @experimental
17
17
  */
18
18
  class InMemoryWebStorage {
19
+ data;
19
20
  constructor(data = {}) {
20
21
  this.data = data;
21
22
  }
@@ -0,0 +1,6 @@
1
+ export * from './zod.shared.schemas';
2
+ export * from './zod.util';
3
+ import type { ZodIssue } from 'zod';
4
+ import { z, ZodError, ZodSchema } from 'zod';
5
+ export { z, ZodError, ZodSchema };
6
+ export type { ZodIssue };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZodSchema = exports.ZodError = exports.z = void 0;
4
+ const tslib_1 = require("tslib");
5
+ tslib_1.__exportStar(require("./zod.shared.schemas"), exports);
6
+ tslib_1.__exportStar(require("./zod.util"), exports);
7
+ const zod_1 = require("zod");
8
+ Object.defineProperty(exports, "z", { enumerable: true, get: function () { return zod_1.z; } });
9
+ Object.defineProperty(exports, "ZodError", { enumerable: true, get: function () { return zod_1.ZodError; } });
10
+ Object.defineProperty(exports, "ZodSchema", { enumerable: true, get: function () { return zod_1.ZodSchema; } });
@@ -28,6 +28,8 @@ function zSafeValidate(value, schema) {
28
28
  };
29
29
  }
30
30
  class ZodValidationError extends zod_1.ZodError {
31
+ value;
32
+ schema;
31
33
  constructor(issues, value, schema) {
32
34
  super(issues);
33
35
  this.value = value;
package/dist-esm/index.js CHANGED
@@ -94,7 +94,3 @@ export * from './typeFest';
94
94
  export * from './types';
95
95
  export * from './unit/size.util';
96
96
  export * from './web';
97
- export * from './zod/zod.shared.schemas';
98
- export * from './zod/zod.util';
99
- import { z, ZodError, ZodSchema } from 'zod';
100
- export { z, ZodError, ZodSchema };
@@ -0,0 +1,4 @@
1
+ export * from './zod.shared.schemas';
2
+ export * from './zod.util';
3
+ import { z, ZodError, ZodSchema } from 'zod';
4
+ export { z, ZodError, ZodSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.274.1",
3
+ "version": "14.275.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build-esm-cjs",
@@ -406,7 +406,7 @@ export class HttpRequestError extends AppError<HttpRequestErrorData> {
406
406
  * so it always has a cause.
407
407
  * (for dev convenience)
408
408
  */
409
- override cause!: ErrorObject
409
+ declare cause: ErrorObject
410
410
  }
411
411
 
412
412
  export class AssertionError extends AppError {
package/src/index.ts CHANGED
@@ -94,10 +94,3 @@ export * from './typeFest'
94
94
  export * from './types'
95
95
  export * from './unit/size.util'
96
96
  export * from './web'
97
- export * from './zod/zod.shared.schemas'
98
- export * from './zod/zod.util'
99
- import type { ZodIssue } from 'zod'
100
- import { z, ZodError, ZodSchema } from 'zod'
101
-
102
- export { z, ZodError, ZodSchema }
103
- export type { ZodIssue }
@@ -0,0 +1,7 @@
1
+ export * from './zod.shared.schemas'
2
+ export * from './zod.util'
3
+ import type { ZodIssue } from 'zod'
4
+ import { z, ZodError, ZodSchema } from 'zod'
5
+
6
+ export { z, ZodError, ZodSchema }
7
+ export type { ZodIssue }