@naturalcycles/js-lib 15.103.0 → 15.105.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.
@@ -1,3 +1,4 @@
1
+ import { _assert } from '../error/assert.js';
1
2
  import { localDate } from './localDate.js';
2
3
  /**
3
4
  * Class that supports ISO8601 "Time interval" standard that looks like `2022-02-24/2022-03-30`.
@@ -21,9 +22,7 @@ export class DateInterval {
21
22
  if (d instanceof DateInterval)
22
23
  return d;
23
24
  const [start, end] = d.split('/');
24
- if (!end || !start) {
25
- throw new Error(`Cannot parse "${d}" into DateInterval`);
26
- }
25
+ _assert(end && start, `Cannot parse "${d}" into DateInterval`);
27
26
  return new DateInterval(localDate(start), localDate(end));
28
27
  }
29
28
  isSame(d) {
@@ -1,3 +1,4 @@
1
+ import { _assert } from '../error/assert.js';
1
2
  import { localTime } from './localTime.js';
2
3
  /**
3
4
  * Class that supports an "interval of time" between 2 timestamps - start and end.
@@ -34,9 +35,7 @@ export class TimeInterval {
34
35
  if (d instanceof TimeInterval)
35
36
  return d;
36
37
  const [start, end] = d.split('/').map(Number);
37
- if (!end || !start) {
38
- throw new Error(`Cannot parse "${d}" into TimeInterval`);
39
- }
38
+ _assert(end && start, `Cannot parse "${d}" into TimeInterval`);
40
39
  return new TimeInterval(start, end);
41
40
  }
42
41
  isSame(d) {
package/dist/enum.util.js CHANGED
@@ -1,3 +1,4 @@
1
+ // oxlint-disable nc/prefer-assert -- no runtime imports here, and the lookups run in hot paths: the message is only built on failure
1
2
  /**
2
3
  * Creates a runtime Enum object. A replacement for a native TypeScript enum,
3
4
  * which is not supported by type-stripping runtimes (e.g `node --experimental-strip-types`).
@@ -50,17 +50,24 @@ export declare class Fetcher {
50
50
  put: <T = unknown>(url: string, opt?: FetcherOptions) => Promise<T>;
51
51
  patch: <T = unknown>(url: string, opt?: FetcherOptions) => Promise<T>;
52
52
  delete: <T = unknown>(url: string, opt?: FetcherOptions) => Promise<T>;
53
+ /**
54
+ * HTTP QUERY method: like GET (safe and idempotent, hence retried by default),
55
+ * but with a request body (e.g `json`).
56
+ */
57
+ query: <T = unknown>(url: string, opt?: FetcherOptions) => Promise<T>;
53
58
  getText: (url: string, opt?: FetcherOptions) => Promise<string>;
54
59
  postText: (url: string, opt?: FetcherOptions) => Promise<string>;
55
60
  putText: (url: string, opt?: FetcherOptions) => Promise<string>;
56
61
  patchText: (url: string, opt?: FetcherOptions) => Promise<string>;
57
62
  deleteText: (url: string, opt?: FetcherOptions) => Promise<string>;
63
+ queryText: (url: string, opt?: FetcherOptions) => Promise<string>;
58
64
  getVoid: (url: string, opt?: FetcherOptions) => Promise<void>;
59
65
  postVoid: (url: string, opt?: FetcherOptions) => Promise<void>;
60
66
  putVoid: (url: string, opt?: FetcherOptions) => Promise<void>;
61
67
  patchVoid: (url: string, opt?: FetcherOptions) => Promise<void>;
62
68
  deleteVoid: (url: string, opt?: FetcherOptions) => Promise<void>;
63
69
  headVoid: (url: string, opt?: FetcherOptions) => Promise<void>;
70
+ queryVoid: (url: string, opt?: FetcherOptions) => Promise<void>;
64
71
  /**
65
72
  * Small convenience wrapper that allows to issue GraphQL queries.
66
73
  * In practice, all it does is:
@@ -122,12 +122,18 @@ export class Fetcher {
122
122
  put;
123
123
  patch;
124
124
  delete;
125
+ /**
126
+ * HTTP QUERY method: like GET (safe and idempotent, hence retried by default),
127
+ * but with a request body (e.g `json`).
128
+ */
129
+ query;
125
130
  // responseType=text
126
131
  getText;
127
132
  postText;
128
133
  putText;
129
134
  patchText;
130
135
  deleteText;
136
+ queryText;
131
137
  // responseType=void (no body fetching/parsing)
132
138
  getVoid;
133
139
  postVoid;
@@ -135,6 +141,7 @@ export class Fetcher {
135
141
  patchVoid;
136
142
  deleteVoid;
137
143
  headVoid;
144
+ queryVoid;
138
145
  /**
139
146
  * Small convenience wrapper that allows to issue GraphQL queries.
140
147
  * In practice, all it does is:
@@ -1,4 +1,4 @@
1
- export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD';
1
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'QUERY';
2
2
  export type HttpStatusFamily = 5 | 4 | 3 | 2 | 1;
3
3
  /**
4
4
  * Number, representing a valid Http status code (e.g 401, 500, etc)
@@ -1 +1,9 @@
1
- export const HTTP_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD'];
1
+ export const HTTP_METHODS = [
2
+ 'GET',
3
+ 'POST',
4
+ 'PUT',
5
+ 'PATCH',
6
+ 'DELETE',
7
+ 'HEAD',
8
+ 'QUERY',
9
+ ];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
3
  "type": "module",
4
- "version": "15.103.0",
4
+ "version": "15.105.0",
5
5
  "dependencies": {
6
6
  "tslib": "^2"
7
7
  },
@@ -14,7 +14,7 @@
14
14
  }
15
15
  },
16
16
  "devDependencies": {
17
- "@naturalcycles/dev-lib": "0.0.0",
17
+ "@naturalcycles/dev-lib": "20.73.0",
18
18
  "@types/node": "^26",
19
19
  "@types/semver": "^7",
20
20
  "rolldown": "^1",
@@ -1,3 +1,4 @@
1
+ import { _assert } from '../error/assert.js'
1
2
  import type { IsoDate } from '../types.js'
2
3
  import type { LocalDate, LocalDateInput, LocalDateUnit } from './localDate.js'
3
4
  import { localDate } from './localDate.js'
@@ -28,9 +29,7 @@ export class DateInterval {
28
29
 
29
30
  const [start, end] = d.split('/') as IsoDate[]
30
31
 
31
- if (!end || !start) {
32
- throw new Error(`Cannot parse "${d}" into DateInterval`)
33
- }
32
+ _assert(end && start, `Cannot parse "${d}" into DateInterval`)
34
33
 
35
34
  return new DateInterval(localDate(start), localDate(end))
36
35
  }
@@ -1,3 +1,4 @@
1
+ import { _assert } from '../error/assert.js'
1
2
  import type { UnixTimestamp } from '../types.js'
2
3
  import type { LocalTime, LocalTimeInput } from './localTime.js'
3
4
  import { localTime } from './localTime.js'
@@ -45,9 +46,7 @@ export class TimeInterval {
45
46
 
46
47
  const [start, end] = d.split('/').map(Number) as UnixTimestamp[]
47
48
 
48
- if (!end || !start) {
49
- throw new Error(`Cannot parse "${d}" into TimeInterval`)
50
- }
49
+ _assert(end && start, `Cannot parse "${d}" into TimeInterval`)
51
50
 
52
51
  return new TimeInterval(start, end)
53
52
  }
package/src/enum.util.ts CHANGED
@@ -1,3 +1,5 @@
1
+ // oxlint-disable nc/prefer-assert -- no runtime imports here, and the lookups run in hot paths: the message is only built on failure
2
+
1
3
  import type { AnyObject, Enum, NumberEnum, StringEnum } from './types.js'
2
4
 
3
5
  /**
@@ -175,6 +175,11 @@ export class Fetcher {
175
175
  put!: <T = unknown>(url: string, opt?: FetcherOptions) => Promise<T>
176
176
  patch!: <T = unknown>(url: string, opt?: FetcherOptions) => Promise<T>
177
177
  delete!: <T = unknown>(url: string, opt?: FetcherOptions) => Promise<T>
178
+ /**
179
+ * HTTP QUERY method: like GET (safe and idempotent, hence retried by default),
180
+ * but with a request body (e.g `json`).
181
+ */
182
+ query!: <T = unknown>(url: string, opt?: FetcherOptions) => Promise<T>
178
183
 
179
184
  // responseType=text
180
185
  getText!: (url: string, opt?: FetcherOptions) => Promise<string>
@@ -182,6 +187,7 @@ export class Fetcher {
182
187
  putText!: (url: string, opt?: FetcherOptions) => Promise<string>
183
188
  patchText!: (url: string, opt?: FetcherOptions) => Promise<string>
184
189
  deleteText!: (url: string, opt?: FetcherOptions) => Promise<string>
190
+ queryText!: (url: string, opt?: FetcherOptions) => Promise<string>
185
191
 
186
192
  // responseType=void (no body fetching/parsing)
187
193
  getVoid!: (url: string, opt?: FetcherOptions) => Promise<void>
@@ -190,6 +196,7 @@ export class Fetcher {
190
196
  patchVoid!: (url: string, opt?: FetcherOptions) => Promise<void>
191
197
  deleteVoid!: (url: string, opt?: FetcherOptions) => Promise<void>
192
198
  headVoid!: (url: string, opt?: FetcherOptions) => Promise<void>
199
+ queryVoid!: (url: string, opt?: FetcherOptions) => Promise<void>
193
200
 
194
201
  /**
195
202
  * Small convenience wrapper that allows to issue GraphQL queries.
@@ -1,5 +1,6 @@
1
1
  // Should be uppercase, because e.g this browser issue: https://github.com/axios/axios/issues/26
2
- export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD'
2
+ // QUERY is like GET (safe and idempotent), but with a request body: https://datatracker.ietf.org/doc/draft-ietf-httpbis-safe-method-w-body/
3
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'QUERY'
3
4
 
4
5
  export type HttpStatusFamily = 5 | 4 | 3 | 2 | 1
5
6
 
@@ -8,4 +9,12 @@ export type HttpStatusFamily = 5 | 4 | 3 | 2 | 1
8
9
  */
9
10
  export type HttpStatusCode = number
10
11
 
11
- export const HTTP_METHODS: readonly HttpMethod[] = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD']
12
+ export const HTTP_METHODS: readonly HttpMethod[] = [
13
+ 'GET',
14
+ 'POST',
15
+ 'PUT',
16
+ 'PATCH',
17
+ 'DELETE',
18
+ 'HEAD',
19
+ 'QUERY',
20
+ ]
package/src/qr/qr.ts CHANGED
@@ -15,6 +15,7 @@
15
15
 
16
16
  // oxlint-disable no-bitwise, prefer-math-trunc -- QR encoding (Galois field, BCH, bit packing) is
17
17
  // inherently bitwise; `(1 << 0)` terms mirror the spec's generator polynomials
18
+ // oxlint-disable nc/prefer-assert -- this module has no imports, to stay small when bundled on its own
18
19
 
19
20
  /// <reference lib="dom" preserve="true" />
20
21