@venizia/ardor-kernel 0.5.0-10 → 0.5.0-12
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/dist/base/applications/abstract.d.ts +3 -0
- package/dist/base/applications/abstract.js +3 -0
- package/dist/base/decorators/api.d.ts +6 -1
- package/dist/base/decorators/api.js +6 -1
- package/dist/base/providers/base.d.ts +6 -1
- package/dist/base/providers/base.js +6 -1
- package/dist/base/providers/role-permission.d.ts +3 -0
- package/dist/base/providers/role-permission.js +3 -0
- package/dist/base/services/auth.d.ts +3 -0
- package/dist/base/services/auth.js +3 -0
- package/dist/base/services/base.d.ts +6 -1
- package/dist/base/services/base.js +6 -1
- package/dist/base/services/network-request.d.ts +13 -2
- package/dist/base/services/network-request.js +13 -2
- package/dist/common/constants.d.ts +47 -8
- package/dist/common/constants.js +47 -8
- package/dist/common/keys.d.ts +9 -1
- package/dist/common/keys.js +9 -1
- package/dist/helpers/networks/auth-recovery.d.ts +3 -0
- package/dist/helpers/networks/auth-recovery.js +3 -0
- package/dist/testing.d.ts +21 -2
- package/dist/testing.js +21 -2
- package/dist/utilities/auth-token-store.d.ts +6 -1
- package/dist/utilities/auth-token-store.js +6 -1
- package/dist/utilities/browser-clipboard.d.ts +3 -0
- package/dist/utilities/browser-clipboard.js +3 -0
- package/dist/utilities/browser-storage.d.ts +3 -0
- package/dist/utilities/browser-storage.js +3 -0
- package/dist/utilities/browser.d.ts +6 -1
- package/dist/utilities/browser.js +6 -1
- package/dist/utilities/file.d.ts +6 -1
- package/dist/utilities/file.js +6 -1
- package/dist/utilities/network-response-reader.d.ts +6 -1
- package/dist/utilities/network-response-reader.js +6 -1
- package/dist/utilities/request-body-encoder.d.ts +6 -1
- package/dist/utilities/request-body-encoder.js +6 -1
- package/dist/utilities/runtime-config.d.ts +21 -5
- package/dist/utilities/runtime-config.js +18 -3
- package/dist/utilities/storage-codecs.d.ts +6 -1
- package/dist/utilities/storage-codecs.js +6 -1
- package/dist/utilities/value.d.ts +8 -2
- package/dist/utilities/value.js +6 -1
- package/package.json +12 -12
|
@@ -23,6 +23,9 @@ export interface IArtifactRegistration {
|
|
|
23
23
|
* Two ways to register, as in IGNIS: stereotype discovery, or `service()`/`repository()`/
|
|
24
24
|
* `dataSource()`/`component()` by hand. Both record the key on the class. Every kind defaults to
|
|
25
25
|
* SINGLETON (IGNIS's server uses transient): a hook resolves on every render.
|
|
26
|
+
*
|
|
27
|
+
* @useWhen you write the application class of an ARDOR app and register its services, repositories, data sources and components
|
|
28
|
+
* @insteadOf wiring the container by hand
|
|
26
29
|
*/
|
|
27
30
|
export declare abstract class AbstractArdorApplication extends Container {
|
|
28
31
|
/** The application's own bindings; `preConfigure` runs it last, so they win over discovered and feature bindings. */
|
|
@@ -15,6 +15,9 @@ const ArtifactIndexKinds = [
|
|
|
15
15
|
* Two ways to register, as in IGNIS: stereotype discovery, or `service()`/`repository()`/
|
|
16
16
|
* `dataSource()`/`component()` by hand. Both record the key on the class. Every kind defaults to
|
|
17
17
|
* SINGLETON (IGNIS's server uses transient): a hook resolves on every render.
|
|
18
|
+
*
|
|
19
|
+
* @useWhen you write the application class of an ARDOR app and register its services, repositories, data sources and components
|
|
20
|
+
* @insteadOf wiring the container by hand
|
|
18
21
|
*/
|
|
19
22
|
export class AbstractArdorApplication extends Container {
|
|
20
23
|
constructor() {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { BaseService } from '../services/index.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Logs a failing method with its name, and its `resource` when the class has one, then rethrows.
|
|
4
|
+
*
|
|
5
|
+
* @useWhen a method of a repository or service should log its failure with its name and rethrow
|
|
6
|
+
* @insteadOf a try and catch that only logs
|
|
7
|
+
*/
|
|
3
8
|
export declare const api: () => (_target: BaseService, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
4
9
|
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Logs a failing method with its name, and its `resource` when the class has one, then rethrows.
|
|
3
|
+
*
|
|
4
|
+
* @useWhen a method of a repository or service should log its failure with its name and rethrow
|
|
5
|
+
* @insteadOf a try and catch that only logs
|
|
6
|
+
*/
|
|
2
7
|
export const api = () => {
|
|
3
8
|
return (_target, propertyKey, descriptor) => {
|
|
4
9
|
const originalMethod = descriptor.value;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
2
2
|
import type { Container, IProvider } from '@venizia/ignis-inversion';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Base of a provider: `value` yields what the provider supplies, resolved through the container.
|
|
5
|
+
*
|
|
6
|
+
* @useWhen you write a provider that yields a value resolved through the container
|
|
7
|
+
* @insteadOf a hand-built singleton that reads the container
|
|
8
|
+
*/
|
|
4
9
|
export declare abstract class BaseProvider<T> extends BaseHelper implements IProvider<T> {
|
|
5
10
|
/** Produces the provided value. */
|
|
6
11
|
abstract value(container: Container): T;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Base of a provider: `value` yields what the provider supplies, resolved through the container.
|
|
4
|
+
*
|
|
5
|
+
* @useWhen you write a provider that yields a value resolved through the container
|
|
6
|
+
* @insteadOf a hand-built singleton that reads the container
|
|
7
|
+
*/
|
|
3
8
|
export class BaseProvider extends BaseHelper {
|
|
4
9
|
}
|
|
5
10
|
//# sourceMappingURL=base.js.map
|
|
@@ -45,6 +45,9 @@ import type { DefaultAuthService } from '../services/auth.js';
|
|
|
45
45
|
* }
|
|
46
46
|
* }
|
|
47
47
|
* ```
|
|
48
|
+
*
|
|
49
|
+
* @useWhen access is decided by roles whose grant patterns sit in a table the application writes
|
|
50
|
+
* @insteadOf a hand-written permission check in each screen
|
|
48
51
|
*/
|
|
49
52
|
export declare class RolePermissionProvider extends BaseHelper implements IPermissionProvider {
|
|
50
53
|
private readonly authService;
|
|
@@ -84,6 +84,9 @@ class GrantPattern {
|
|
|
84
84
|
* }
|
|
85
85
|
* }
|
|
86
86
|
* ```
|
|
87
|
+
*
|
|
88
|
+
* @useWhen access is decided by roles whose grant patterns sit in a table the application writes
|
|
89
|
+
* @insteadOf a hand-written permission check in each screen
|
|
87
90
|
*/
|
|
88
91
|
let RolePermissionProvider = RolePermissionProvider_1 = class RolePermissionProvider extends BaseHelper {
|
|
89
92
|
constructor(authService, options) {
|
|
@@ -7,6 +7,9 @@ export interface IAuthChange {
|
|
|
7
7
|
/**
|
|
8
8
|
* Keeps the signed-in session (token, identity, roles) in `localStorage`, everything under
|
|
9
9
|
* `keys.authPrefix`: `LocalStorageKeys.PREFIX_AUTH`, or `@app/auth/<id>/` when the application has an `id`.
|
|
10
|
+
*
|
|
11
|
+
* @useWhen you need the signed-in session (token, identity, roles) kept in `localStorage`
|
|
12
|
+
* @insteadOf reading and writing the token and roles in storage by hand
|
|
10
13
|
*/
|
|
11
14
|
export declare class DefaultAuthService extends BaseService {
|
|
12
15
|
private readonly listeners;
|
|
@@ -19,6 +19,9 @@ import { BaseService } from './base.js';
|
|
|
19
19
|
/**
|
|
20
20
|
* Keeps the signed-in session (token, identity, roles) in `localStorage`, everything under
|
|
21
21
|
* `keys.authPrefix`: `LocalStorageKeys.PREFIX_AUTH`, or `@app/auth/<id>/` when the application has an `id`.
|
|
22
|
+
*
|
|
23
|
+
* @useWhen you need the signed-in session (token, identity, roles) kept in `localStorage`
|
|
24
|
+
* @insteadOf reading and writing the token and roles in storage by hand
|
|
22
25
|
*/
|
|
23
26
|
let DefaultAuthService = DefaultAuthService_1 = class DefaultAuthService extends BaseService {
|
|
24
27
|
/** A subclass with its own constructor passes `info` on to `super(info)`; otherwise its keys are the unscoped ones. */
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Base of the services of an application; a `BaseHelper` with a scoped logger.
|
|
4
|
+
*
|
|
5
|
+
* @useWhen you write a service of the application and want a scoped logger
|
|
6
|
+
* @insteadOf a service class that creates its own logger
|
|
7
|
+
*/
|
|
3
8
|
export declare class BaseService extends BaseHelper {
|
|
4
9
|
}
|
|
5
10
|
//# sourceMappingURL=base.d.ts.map
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Base of the services of an application; a `BaseHelper` with a scoped logger.
|
|
4
|
+
*
|
|
5
|
+
* @useWhen you write a service of the application and want a scoped logger
|
|
6
|
+
* @insteadOf a service class that creates its own logger
|
|
7
|
+
*/
|
|
3
8
|
export class BaseService extends BaseHelper {
|
|
4
9
|
}
|
|
5
10
|
//# sourceMappingURL=base.js.map
|
|
@@ -3,9 +3,17 @@ import { type IApplicationInfo, type IAuthTokenRecord, type IAuthRecoveryOptions
|
|
|
3
3
|
import { type IEncodedBody, NetworkResponseReader } from '../../utilities/index.js';
|
|
4
4
|
import type { DefaultAuthService } from './auth.js';
|
|
5
5
|
import { BaseService } from './base.js';
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* The `normalized.code` of the 401 that answers a request whose session is gone: the user who sent it signed out or another user signed in while it was in flight.
|
|
8
|
+
*
|
|
9
|
+
* @useWhen you tell a request that failed because the session changed from any other 401
|
|
10
|
+
*/
|
|
7
11
|
export declare const SESSION_CHANGED_CODE = "ardor.network.session_changed";
|
|
8
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* The `normalized.code` of the 504 a request rejects with when it outlives the configured `timeout`.
|
|
14
|
+
*
|
|
15
|
+
* @useWhen you tell a request that timed out from any other failure
|
|
16
|
+
*/
|
|
9
17
|
export declare const NETWORK_TIMEOUT_CODE = "ardor.network.timeout";
|
|
10
18
|
/**
|
|
11
19
|
* Sends the requests of the data provider with its own sender. The repositories of
|
|
@@ -16,6 +24,9 @@ export declare const NETWORK_TIMEOUT_CODE = "ardor.network.timeout";
|
|
|
16
24
|
*
|
|
17
25
|
* The options hold data (the base URL, headers, the no-auth lists, the refresh path); behaviour is
|
|
18
26
|
* in the protected hooks, each taking one `opts` object, which a subclass overrides.
|
|
27
|
+
*
|
|
28
|
+
* @useWhen the data provider needs to send requests with timeout, auth recovery and normalized errors
|
|
29
|
+
* @insteadOf a hand-written `fetch` wrapper
|
|
19
30
|
*/
|
|
20
31
|
export declare class DefaultNetworkRequestService extends BaseService {
|
|
21
32
|
/** Resources sent without a token, matched exactly. */
|
|
@@ -7,9 +7,17 @@ import { App, LocalStorageKeys, RequestChannel, RequestCountData, RequestMethods
|
|
|
7
7
|
import { AuthRecoveryHelper } from '../../helpers/index.js';
|
|
8
8
|
import { AuthTokenStore, NetworkResponseReader, RequestBodyEncoder, } from '../../utilities/index.js';
|
|
9
9
|
import { BaseService } from './base.js';
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* The `normalized.code` of the 401 that answers a request whose session is gone: the user who sent it signed out or another user signed in while it was in flight.
|
|
12
|
+
*
|
|
13
|
+
* @useWhen you tell a request that failed because the session changed from any other 401
|
|
14
|
+
*/
|
|
11
15
|
export const SESSION_CHANGED_CODE = 'ardor.network.session_changed';
|
|
12
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The `normalized.code` of the 504 a request rejects with when it outlives the configured `timeout`.
|
|
18
|
+
*
|
|
19
|
+
* @useWhen you tell a request that timed out from any other failure
|
|
20
|
+
*/
|
|
13
21
|
export const NETWORK_TIMEOUT_CODE = 'ardor.network.timeout';
|
|
14
22
|
/**
|
|
15
23
|
* Sends the requests of the data provider with its own sender. The repositories of
|
|
@@ -20,6 +28,9 @@ export const NETWORK_TIMEOUT_CODE = 'ardor.network.timeout';
|
|
|
20
28
|
*
|
|
21
29
|
* The options hold data (the base URL, headers, the no-auth lists, the refresh path); behaviour is
|
|
22
30
|
* in the protected hooks, each taking one `opts` object, which a subclass overrides.
|
|
31
|
+
*
|
|
32
|
+
* @useWhen the data provider needs to send requests with timeout, auth recovery and normalized errors
|
|
33
|
+
* @insteadOf a hand-written `fetch` wrapper
|
|
23
34
|
*/
|
|
24
35
|
export class DefaultNetworkRequestService extends BaseService {
|
|
25
36
|
constructor(opts) {
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { ConstClass } from '@venizia/ignis-helpers/common';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Values of the running environment, read once when the module loads.
|
|
4
|
+
*
|
|
5
|
+
* @useWhen you need the runtime timezone, the default debounce time or the default token type
|
|
6
|
+
* @insteadOf a timezone, a debounce number or the string `'Bearer'` written by hand
|
|
7
|
+
*/
|
|
3
8
|
export declare class App {
|
|
4
9
|
/** The IANA name of the timezone of the runtime. */
|
|
5
10
|
static readonly TIMEZONE: string;
|
|
@@ -10,7 +15,12 @@ export declare class App {
|
|
|
10
15
|
/** The authorization scheme of a token that names none. */
|
|
11
16
|
static readonly TOKEN_TYPE = "Bearer";
|
|
12
17
|
}
|
|
13
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* HTTP methods.
|
|
20
|
+
*
|
|
21
|
+
* @useWhen you name an HTTP method
|
|
22
|
+
* @insteadOf string literals such as `'GET'`
|
|
23
|
+
*/
|
|
14
24
|
export declare class RequestMethods extends ConstClass {
|
|
15
25
|
static readonly HEAD = "HEAD";
|
|
16
26
|
static readonly OPTIONS = "OPTIONS";
|
|
@@ -20,7 +30,11 @@ export declare class RequestMethods extends ConstClass {
|
|
|
20
30
|
static readonly PATCH = "PATCH";
|
|
21
31
|
static readonly DELETE = "DELETE";
|
|
22
32
|
}
|
|
23
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* What a request is for, which decides how its response is read: `SEND`, and react-admin's data provider calls.
|
|
35
|
+
*
|
|
36
|
+
* @useWhen you say what a request is for, which decides how its response is read
|
|
37
|
+
*/
|
|
24
38
|
export declare class RequestTypes extends ConstClass {
|
|
25
39
|
/** A request that is not a react-admin call. */
|
|
26
40
|
static readonly SEND = "SEND";
|
|
@@ -34,14 +48,24 @@ export declare class RequestTypes extends ConstClass {
|
|
|
34
48
|
static readonly DELETE = "DELETE";
|
|
35
49
|
static readonly DELETE_MANY = "DELETE_MANY";
|
|
36
50
|
}
|
|
37
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* The Web Storage areas `BrowserStorage` reads and writes.
|
|
53
|
+
*
|
|
54
|
+
* @useWhen you pick `localStorage` or `sessionStorage` for `BrowserStorage`
|
|
55
|
+
* @insteadOf the strings `'local'` and `'session'`
|
|
56
|
+
*/
|
|
38
57
|
export declare class StorageAreas {
|
|
39
58
|
/** `localStorage`. */
|
|
40
59
|
static readonly LOCAL = "local";
|
|
41
60
|
/** `sessionStorage`. */
|
|
42
61
|
static readonly SESSION = "session";
|
|
43
62
|
}
|
|
44
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* How a request body is encoded; see `RequestBodyEncoder`.
|
|
65
|
+
*
|
|
66
|
+
* @useWhen you pick how a request body is encoded
|
|
67
|
+
* @insteadOf setting the `Content-Type` and stringifying by hand
|
|
68
|
+
*/
|
|
45
69
|
export declare class RequestBodyTypes extends ConstClass {
|
|
46
70
|
/** The body goes through as it is. */
|
|
47
71
|
static readonly NONE = "none";
|
|
@@ -50,17 +74,32 @@ export declare class RequestBodyTypes extends ConstClass {
|
|
|
50
74
|
static readonly JSON = "json";
|
|
51
75
|
static readonly BINARY = "binary";
|
|
52
76
|
}
|
|
53
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* Names of the build environments.
|
|
79
|
+
*
|
|
80
|
+
* @useWhen you compare the build environment by name
|
|
81
|
+
* @insteadOf string literals such as `'production'`
|
|
82
|
+
*/
|
|
54
83
|
export declare class Environments extends ConstClass {
|
|
55
84
|
static readonly DEVELOPMENT = "development";
|
|
56
85
|
static readonly PRODUCTION = "production";
|
|
57
86
|
}
|
|
58
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* The channels a request says it comes from, sent in `x-request-channel`.
|
|
89
|
+
*
|
|
90
|
+
* @useWhen you set the `x-request-channel` header of a request
|
|
91
|
+
* @insteadOf a header string written by hand
|
|
92
|
+
*/
|
|
59
93
|
export declare class RequestChannel extends ConstClass {
|
|
60
94
|
/** A browser application; what a request says unless `requestTracingChannel` is set. */
|
|
61
95
|
static readonly WEB = "100_WEB";
|
|
62
96
|
}
|
|
63
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* Whether a response carries a count, sent in `x-request-count`.
|
|
99
|
+
*
|
|
100
|
+
* @useWhen you ask for or read the `x-request-count` header
|
|
101
|
+
* @insteadOf a header string written by hand
|
|
102
|
+
*/
|
|
64
103
|
export declare class RequestCountData extends ConstClass {
|
|
65
104
|
/**
|
|
66
105
|
* @description Only the data is returned in the response body
|
package/dist/common/constants.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { ConstClass } from '@venizia/ignis-helpers/common';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Values of the running environment, read once when the module loads.
|
|
4
|
+
*
|
|
5
|
+
* @useWhen you need the runtime timezone, the default debounce time or the default token type
|
|
6
|
+
* @insteadOf a timezone, a debounce number or the string `'Bearer'` written by hand
|
|
7
|
+
*/
|
|
3
8
|
export class App {
|
|
4
9
|
/** The IANA name of the timezone of the runtime. */
|
|
5
10
|
static { this.TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone; }
|
|
@@ -10,7 +15,12 @@ export class App {
|
|
|
10
15
|
/** The authorization scheme of a token that names none. */
|
|
11
16
|
static { this.TOKEN_TYPE = 'Bearer'; }
|
|
12
17
|
}
|
|
13
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* HTTP methods.
|
|
20
|
+
*
|
|
21
|
+
* @useWhen you name an HTTP method
|
|
22
|
+
* @insteadOf string literals such as `'GET'`
|
|
23
|
+
*/
|
|
14
24
|
export class RequestMethods extends ConstClass {
|
|
15
25
|
static { this.HEAD = 'HEAD'; }
|
|
16
26
|
static { this.OPTIONS = 'OPTIONS'; }
|
|
@@ -20,7 +30,11 @@ export class RequestMethods extends ConstClass {
|
|
|
20
30
|
static { this.PATCH = 'PATCH'; }
|
|
21
31
|
static { this.DELETE = 'DELETE'; }
|
|
22
32
|
}
|
|
23
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* What a request is for, which decides how its response is read: `SEND`, and react-admin's data provider calls.
|
|
35
|
+
*
|
|
36
|
+
* @useWhen you say what a request is for, which decides how its response is read
|
|
37
|
+
*/
|
|
24
38
|
export class RequestTypes extends ConstClass {
|
|
25
39
|
/** A request that is not a react-admin call. */
|
|
26
40
|
static { this.SEND = 'SEND'; }
|
|
@@ -35,14 +49,24 @@ export class RequestTypes extends ConstClass {
|
|
|
35
49
|
static { this.DELETE = 'DELETE'; }
|
|
36
50
|
static { this.DELETE_MANY = 'DELETE_MANY'; }
|
|
37
51
|
}
|
|
38
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* The Web Storage areas `BrowserStorage` reads and writes.
|
|
54
|
+
*
|
|
55
|
+
* @useWhen you pick `localStorage` or `sessionStorage` for `BrowserStorage`
|
|
56
|
+
* @insteadOf the strings `'local'` and `'session'`
|
|
57
|
+
*/
|
|
39
58
|
export class StorageAreas {
|
|
40
59
|
/** `localStorage`. */
|
|
41
60
|
static { this.LOCAL = 'local'; }
|
|
42
61
|
/** `sessionStorage`. */
|
|
43
62
|
static { this.SESSION = 'session'; }
|
|
44
63
|
}
|
|
45
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* How a request body is encoded; see `RequestBodyEncoder`.
|
|
66
|
+
*
|
|
67
|
+
* @useWhen you pick how a request body is encoded
|
|
68
|
+
* @insteadOf setting the `Content-Type` and stringifying by hand
|
|
69
|
+
*/
|
|
46
70
|
export class RequestBodyTypes extends ConstClass {
|
|
47
71
|
/** The body goes through as it is. */
|
|
48
72
|
static { this.NONE = 'none'; }
|
|
@@ -51,17 +75,32 @@ export class RequestBodyTypes extends ConstClass {
|
|
|
51
75
|
static { this.JSON = 'json'; }
|
|
52
76
|
static { this.BINARY = 'binary'; }
|
|
53
77
|
}
|
|
54
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* Names of the build environments.
|
|
80
|
+
*
|
|
81
|
+
* @useWhen you compare the build environment by name
|
|
82
|
+
* @insteadOf string literals such as `'production'`
|
|
83
|
+
*/
|
|
55
84
|
export class Environments extends ConstClass {
|
|
56
85
|
static { this.DEVELOPMENT = 'development'; }
|
|
57
86
|
static { this.PRODUCTION = 'production'; }
|
|
58
87
|
}
|
|
59
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* The channels a request says it comes from, sent in `x-request-channel`.
|
|
90
|
+
*
|
|
91
|
+
* @useWhen you set the `x-request-channel` header of a request
|
|
92
|
+
* @insteadOf a header string written by hand
|
|
93
|
+
*/
|
|
60
94
|
export class RequestChannel extends ConstClass {
|
|
61
95
|
/** A browser application; what a request says unless `requestTracingChannel` is set. */
|
|
62
96
|
static { this.WEB = '100_WEB'; }
|
|
63
97
|
}
|
|
64
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* Whether a response carries a count, sent in `x-request-count`.
|
|
100
|
+
*
|
|
101
|
+
* @useWhen you ask for or read the `x-request-count` header
|
|
102
|
+
* @insteadOf a header string written by hand
|
|
103
|
+
*/
|
|
65
104
|
export class RequestCountData extends ConstClass {
|
|
66
105
|
/**
|
|
67
106
|
* @description Only the data is returned in the response body
|
package/dist/common/keys.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ export type TCoreBindingType<TName extends string> = TName extends keyof ICoreBi
|
|
|
13
13
|
/**
|
|
14
14
|
* The container keys the kernel binds and reads, each made by `BindingKeys.build<T>` with the type of
|
|
15
15
|
* its value.
|
|
16
|
+
*
|
|
17
|
+
* @useWhen you read or bind a key the kernel owns in the container
|
|
18
|
+
* @insteadOf a string key written by hand
|
|
16
19
|
*/
|
|
17
20
|
export declare class CoreBindings {
|
|
18
21
|
/** The application itself, bound by `preConfigure`. */
|
|
@@ -62,7 +65,12 @@ export interface IScopedKeys {
|
|
|
62
65
|
identity: string;
|
|
63
66
|
permission: string;
|
|
64
67
|
}
|
|
65
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* The `localStorage` keys the kernel owns.
|
|
70
|
+
*
|
|
71
|
+
* @useWhen you read a `localStorage` key the kernel owns
|
|
72
|
+
* @insteadOf a storage key string written by hand
|
|
73
|
+
*/
|
|
66
74
|
export declare class LocalStorageKeys {
|
|
67
75
|
/**
|
|
68
76
|
* The session keys of an application with no `id`: `DefaultAuthService.cleanUp` removes them, and
|
package/dist/common/keys.js
CHANGED
|
@@ -2,6 +2,9 @@ import { BindingKeys, getError } from '@venizia/ignis-inversion';
|
|
|
2
2
|
/**
|
|
3
3
|
* The container keys the kernel binds and reads, each made by `BindingKeys.build<T>` with the type of
|
|
4
4
|
* its value.
|
|
5
|
+
*
|
|
6
|
+
* @useWhen you read or bind a key the kernel owns in the container
|
|
7
|
+
* @insteadOf a string key written by hand
|
|
5
8
|
*/
|
|
6
9
|
export class CoreBindings {
|
|
7
10
|
/** The application itself, bound by `preConfigure`. */
|
|
@@ -53,7 +56,12 @@ export class CoreBindings {
|
|
|
53
56
|
key: '@app/application/options/permission',
|
|
54
57
|
}); }
|
|
55
58
|
}
|
|
56
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* The `localStorage` keys the kernel owns.
|
|
61
|
+
*
|
|
62
|
+
* @useWhen you read a `localStorage` key the kernel owns
|
|
63
|
+
* @insteadOf a storage key string written by hand
|
|
64
|
+
*/
|
|
57
65
|
export class LocalStorageKeys {
|
|
58
66
|
/**
|
|
59
67
|
* The session keys of an application with no `id`: `DefaultAuthService.cleanUp` removes them, and
|
|
@@ -3,6 +3,9 @@ import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
|
3
3
|
* What happens after a 401: one refresh shared by every request in flight, and which paths may
|
|
4
4
|
* recover at all. The callbacks are read when called, so a subclass override of the service hooks
|
|
5
5
|
* behind them takes effect.
|
|
6
|
+
*
|
|
7
|
+
* @useWhen a 401 must trigger one shared refresh for every request in flight
|
|
8
|
+
* @insteadOf a refresh and retry written by hand in each request
|
|
6
9
|
*/
|
|
7
10
|
export declare class AuthRecoveryHelper extends BaseHelper {
|
|
8
11
|
private readonly opts;
|
|
@@ -3,6 +3,9 @@ import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
|
3
3
|
* What happens after a 401: one refresh shared by every request in flight, and which paths may
|
|
4
4
|
* recover at all. The callbacks are read when called, so a subclass override of the service hooks
|
|
5
5
|
* behind them takes effect.
|
|
6
|
+
*
|
|
7
|
+
* @useWhen a 401 must trigger one shared refresh for every request in flight
|
|
8
|
+
* @insteadOf a refresh and retry written by hand in each request
|
|
6
9
|
*/
|
|
7
10
|
export class AuthRecoveryHelper extends BaseHelper {
|
|
8
11
|
constructor(opts) {
|
package/dist/testing.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ import type { TStorageArea } from './common/index.js';
|
|
|
3
3
|
* A `ResizeObserver` whose `observe()` records the element. `flush` delivers a size to the observers
|
|
4
4
|
* of an element; a callback runs at once, so code that waits for an animation frame still needs the
|
|
5
5
|
* test's own frame control.
|
|
6
|
+
*
|
|
7
|
+
* @useWhen a test needs a `ResizeObserver` it can drive
|
|
8
|
+
* @insteadOf a hand-written `ResizeObserver` stub in the test
|
|
6
9
|
*/
|
|
7
10
|
export declare class FakeResizeObserver implements ResizeObserver {
|
|
8
11
|
readonly callback: ResizeObserverCallback;
|
|
@@ -31,6 +34,9 @@ export declare class FakeResizeObserver implements ResizeObserver {
|
|
|
31
34
|
/**
|
|
32
35
|
* An `IntersectionObserver` whose `observe()` records the element and reports nothing by itself: `settle`
|
|
33
36
|
* delivers the first report of a browser, `flush` delivers an entry to the observers of an element.
|
|
37
|
+
*
|
|
38
|
+
* @useWhen a test needs an `IntersectionObserver` it can drive
|
|
39
|
+
* @insteadOf a hand-written `IntersectionObserver` stub in the test
|
|
34
40
|
*/
|
|
35
41
|
export declare class FakeIntersectionObserver implements IntersectionObserver {
|
|
36
42
|
#private;
|
|
@@ -72,7 +78,12 @@ export declare class FakeIntersectionObserver implements IntersectionObserver {
|
|
|
72
78
|
disconnect(): void;
|
|
73
79
|
takeRecords(): Array<IntersectionObserverEntry>;
|
|
74
80
|
}
|
|
75
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* The `MediaQueryList` that `matchMedia` answers under `FakeMatchMedia.install`: one per query, `false` until `set`.
|
|
83
|
+
*
|
|
84
|
+
* @useWhen a test needs `matchMedia` answers it can set per query
|
|
85
|
+
* @insteadOf a hand-written `window.matchMedia` stub in the test
|
|
86
|
+
*/
|
|
76
87
|
export declare class FakeMatchMedia extends EventTarget {
|
|
77
88
|
#private;
|
|
78
89
|
readonly media: string;
|
|
@@ -101,6 +112,9 @@ export declare class FakeMatchMedia extends EventTarget {
|
|
|
101
112
|
* `setItem` and `clear` throw `QuotaExceededError` and `removeItem` throw `SecurityError`. A key named like a member of the fake (`getItem`,
|
|
102
113
|
* `length`, `writes`, `failWrites` and the rest) would shadow it, so `setItem` throws a `TypeError`
|
|
103
114
|
* for it, where the real `Storage` accepts it.
|
|
115
|
+
*
|
|
116
|
+
* @useWhen a test needs a `Storage` that can fail on demand
|
|
117
|
+
* @insteadOf a hand-written `localStorage` stub in the test
|
|
104
118
|
*/
|
|
105
119
|
export declare class FakeStorage implements Storage {
|
|
106
120
|
#private;
|
|
@@ -122,7 +136,12 @@ export declare class FakeStorage implements Storage {
|
|
|
122
136
|
clear(): void;
|
|
123
137
|
key(index: number): string | null;
|
|
124
138
|
}
|
|
125
|
-
/**
|
|
139
|
+
/**
|
|
140
|
+
* A `navigator.clipboard` that keeps the text in memory; `isDenied` makes both methods reject as a refused permission does.
|
|
141
|
+
*
|
|
142
|
+
* @useWhen a test needs a `navigator.clipboard` that can be refused
|
|
143
|
+
* @insteadOf a hand-written `navigator.clipboard` stub in the test
|
|
144
|
+
*/
|
|
126
145
|
export declare class FakeClipboard {
|
|
127
146
|
/** The text of every `writeText`, in order. */
|
|
128
147
|
readonly written: Array<string>;
|
package/dist/testing.js
CHANGED
|
@@ -47,6 +47,9 @@ const drop = (opts) => {
|
|
|
47
47
|
* A `ResizeObserver` whose `observe()` records the element. `flush` delivers a size to the observers
|
|
48
48
|
* of an element; a callback runs at once, so code that waits for an animation frame still needs the
|
|
49
49
|
* test's own frame control.
|
|
50
|
+
*
|
|
51
|
+
* @useWhen a test needs a `ResizeObserver` it can drive
|
|
52
|
+
* @insteadOf a hand-written `ResizeObserver` stub in the test
|
|
50
53
|
*/
|
|
51
54
|
export class FakeResizeObserver {
|
|
52
55
|
/** The observers created since the last `install`, in creation order. */
|
|
@@ -116,6 +119,9 @@ const intersectionEntryOf = (opts) => {
|
|
|
116
119
|
/**
|
|
117
120
|
* An `IntersectionObserver` whose `observe()` records the element and reports nothing by itself: `settle`
|
|
118
121
|
* delivers the first report of a browser, `flush` delivers an entry to the observers of an element.
|
|
122
|
+
*
|
|
123
|
+
* @useWhen a test needs an `IntersectionObserver` it can drive
|
|
124
|
+
* @insteadOf a hand-written `IntersectionObserver` stub in the test
|
|
119
125
|
*/
|
|
120
126
|
export class FakeIntersectionObserver {
|
|
121
127
|
/** The observers created since the last `install`, in creation order. */
|
|
@@ -196,7 +202,12 @@ export class FakeIntersectionObserver {
|
|
|
196
202
|
return [];
|
|
197
203
|
}
|
|
198
204
|
}
|
|
199
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* The `MediaQueryList` that `matchMedia` answers under `FakeMatchMedia.install`: one per query, `false` until `set`.
|
|
207
|
+
*
|
|
208
|
+
* @useWhen a test needs `matchMedia` answers it can set per query
|
|
209
|
+
* @insteadOf a hand-written `window.matchMedia` stub in the test
|
|
210
|
+
*/
|
|
200
211
|
export class FakeMatchMedia extends EventTarget {
|
|
201
212
|
/** The queries asked since the last `install`, with the list each one got. */
|
|
202
213
|
static { this.queries = new Map(); }
|
|
@@ -250,6 +261,9 @@ export class FakeMatchMedia extends EventTarget {
|
|
|
250
261
|
* `setItem` and `clear` throw `QuotaExceededError` and `removeItem` throw `SecurityError`. A key named like a member of the fake (`getItem`,
|
|
251
262
|
* `length`, `writes`, `failWrites` and the rest) would shadow it, so `setItem` throws a `TypeError`
|
|
252
263
|
* for it, where the real `Storage` accepts it.
|
|
264
|
+
*
|
|
265
|
+
* @useWhen a test needs a `Storage` that can fail on demand
|
|
266
|
+
* @insteadOf a hand-written `localStorage` stub in the test
|
|
253
267
|
*/
|
|
254
268
|
export class FakeStorage {
|
|
255
269
|
#failReads = false;
|
|
@@ -336,7 +350,12 @@ export class FakeStorage {
|
|
|
336
350
|
}
|
|
337
351
|
}
|
|
338
352
|
}
|
|
339
|
-
/**
|
|
353
|
+
/**
|
|
354
|
+
* A `navigator.clipboard` that keeps the text in memory; `isDenied` makes both methods reject as a refused permission does.
|
|
355
|
+
*
|
|
356
|
+
* @useWhen a test needs a `navigator.clipboard` that can be refused
|
|
357
|
+
* @insteadOf a hand-written `navigator.clipboard` stub in the test
|
|
358
|
+
*/
|
|
340
359
|
export class FakeClipboard {
|
|
341
360
|
constructor() {
|
|
342
361
|
/** The text of every `writeText`, in order. */
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { type IAuthTokenRecord, type IdType } from '../common/index.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* The one place that reads and writes the stored auth token, with the browser guard.
|
|
4
|
+
*
|
|
5
|
+
* @useWhen you read or write the stored auth token
|
|
6
|
+
* @insteadOf reading `localStorage` for the token by hand
|
|
7
|
+
*/
|
|
3
8
|
export declare class AuthTokenStore {
|
|
4
9
|
private static readonly logger;
|
|
5
10
|
/** The stored token (under `key`, `LocalStorageKeys.KEY_AUTH_TOKEN` by default), or `undefined` when none is stored, it is unusable, or there is no `localStorage`. */
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { LoggerFactory } from '@venizia/ignis-helpers/core';
|
|
2
2
|
import { getError } from '@venizia/ignis-inversion';
|
|
3
3
|
import { LocalStorageKeys } from '../common/index.js';
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* The one place that reads and writes the stored auth token, with the browser guard.
|
|
6
|
+
*
|
|
7
|
+
* @useWhen you read or write the stored auth token
|
|
8
|
+
* @insteadOf reading `localStorage` for the token by hand
|
|
9
|
+
*/
|
|
5
10
|
export class AuthTokenStore {
|
|
6
11
|
static { this.logger = LoggerFactory.getLogger(['AuthTokenStore']); }
|
|
7
12
|
/** The stored token (under `key`, `LocalStorageKeys.KEY_AUTH_TOKEN` by default), or `undefined` when none is stored, it is unusable, or there is no `localStorage`. */
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
* (a server), no `navigator.clipboard` (an insecure context, an old WebView), a denied permission,
|
|
4
4
|
* a missing user gesture and an unfocused document all answer `false` or `undefined`. Nothing
|
|
5
5
|
* touches `navigator` at import.
|
|
6
|
+
*
|
|
7
|
+
* @useWhen code outside React copies text and must never throw
|
|
8
|
+
* @insteadOf `navigator.clipboard.writeText`
|
|
6
9
|
*/
|
|
7
10
|
export declare class BrowserClipboard {
|
|
8
11
|
/** The one catch: every refusal the browser can make is the case this class absorbs. */
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
* (a server), no `navigator.clipboard` (an insecure context, an old WebView), a denied permission,
|
|
4
4
|
* a missing user gesture and an unfocused document all answer `false` or `undefined`. Nothing
|
|
5
5
|
* touches `navigator` at import.
|
|
6
|
+
*
|
|
7
|
+
* @useWhen code outside React copies text and must never throw
|
|
8
|
+
* @insteadOf `navigator.clipboard.writeText`
|
|
6
9
|
*/
|
|
7
10
|
export class BrowserClipboard {
|
|
8
11
|
/** The one catch: every refusal the browser can make is the case this class absorbs. */
|
|
@@ -8,6 +8,9 @@ export interface IStorageChange {
|
|
|
8
8
|
* `localStorage` and `sessionStorage` that never throw: a missing area, a blocked accessor, a quota
|
|
9
9
|
* error or text the codec cannot read gives the fallback or `false`. Nothing touches `window` at
|
|
10
10
|
* import. A key under `LocalStorageKeys.PREFIX_AUTH` is the session and is never written here.
|
|
11
|
+
*
|
|
12
|
+
* @useWhen code outside React reads or writes `localStorage` or `sessionStorage` and must never throw
|
|
13
|
+
* @insteadOf `localStorage.getItem` and `setItem` with try and catch
|
|
11
14
|
*/
|
|
12
15
|
export declare class BrowserStorage {
|
|
13
16
|
private static readonly subs;
|
|
@@ -3,6 +3,9 @@ import { LocalStorageKeys, StorageAreas } from '../common/index.js';
|
|
|
3
3
|
* `localStorage` and `sessionStorage` that never throw: a missing area, a blocked accessor, a quota
|
|
4
4
|
* error or text the codec cannot read gives the fallback or `false`. Nothing touches `window` at
|
|
5
5
|
* import. A key under `LocalStorageKeys.PREFIX_AUTH` is the session and is never written here.
|
|
6
|
+
*
|
|
7
|
+
* @useWhen code outside React reads or writes `localStorage` or `sessionStorage` and must never throw
|
|
8
|
+
* @insteadOf `localStorage.getItem` and `setItem` with try and catch
|
|
6
9
|
*/
|
|
7
10
|
export class BrowserStorage {
|
|
8
11
|
static { this.subs = new Set(); }
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Checks of the runtime.
|
|
3
|
+
*
|
|
4
|
+
* @useWhen you check what runtime the code runs in (browser or server)
|
|
5
|
+
* @insteadOf `typeof window` checks
|
|
6
|
+
*/
|
|
2
7
|
export declare class BrowserUtility {
|
|
3
8
|
/** Whether a global `window` exists. */
|
|
4
9
|
static isBrowser(): boolean;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Checks of the runtime.
|
|
3
|
+
*
|
|
4
|
+
* @useWhen you check what runtime the code runs in (browser or server)
|
|
5
|
+
* @insteadOf `typeof window` checks
|
|
6
|
+
*/
|
|
2
7
|
export class BrowserUtility {
|
|
3
8
|
/** Whether a global `window` exists. */
|
|
4
9
|
static isBrowser() {
|
package/dist/utilities/file.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Helpers over `Blob` and file data.
|
|
3
|
+
*
|
|
4
|
+
* @useWhen you work with `Blob` and file data, such as a download or a size
|
|
5
|
+
* @insteadOf hand-written `Blob` and object URL code
|
|
6
|
+
*/
|
|
2
7
|
export declare class FileUtility {
|
|
3
8
|
/** How long a saved file's object URL lives, in milliseconds: a browser that starts the download later (Safari) still finds it. */
|
|
4
9
|
static readonly REVOKE_DELAY_MS = 30000;
|
package/dist/utilities/file.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { getError } from '@venizia/ignis-inversion';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Helpers over `Blob` and file data.
|
|
4
|
+
*
|
|
5
|
+
* @useWhen you work with `Blob` and file data, such as a download or a size
|
|
6
|
+
* @insteadOf hand-written `Blob` and object URL code
|
|
7
|
+
*/
|
|
3
8
|
export class FileUtility {
|
|
4
9
|
/** How long a saved file's object URL lives, in milliseconds: a browser that starts the download later (Safari) still finds it. */
|
|
5
10
|
static { this.REVOKE_DELAY_MS = 30_000; }
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { type INetworkResponse, RequestCountData, type TConstValue, type TRequestType } from '../common/index.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Reads a `Response` into an `INetworkResponse`, and an error response into an error.
|
|
4
|
+
*
|
|
5
|
+
* @useWhen you read a `Response` into a typed result or a typed error
|
|
6
|
+
* @insteadOf `response.json()` with hand-written error handling
|
|
7
|
+
*/
|
|
3
8
|
export declare class NetworkResponseReader {
|
|
4
9
|
/** The server wraps an error body under this key; both transports unwrap it. */
|
|
5
10
|
static readonly ERROR_ROOT_KEY = "error";
|
|
@@ -6,7 +6,12 @@ import { RequestCountData, RequestTypes, } from '../common/index.js';
|
|
|
6
6
|
const isCountedBody = (value) => {
|
|
7
7
|
return typeof value === 'object' && value !== null && 'data' in value && 'count' in value;
|
|
8
8
|
};
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Reads a `Response` into an `INetworkResponse`, and an error response into an error.
|
|
11
|
+
*
|
|
12
|
+
* @useWhen you read a `Response` into a typed result or a typed error
|
|
13
|
+
* @insteadOf `response.json()` with hand-written error handling
|
|
14
|
+
*/
|
|
10
15
|
export class NetworkResponseReader {
|
|
11
16
|
/** The server wraps an error body under this key; both transports unwrap it. */
|
|
12
17
|
static { this.ERROR_ROOT_KEY = 'error'; }
|
|
@@ -6,7 +6,12 @@ export interface IEncodedBody {
|
|
|
6
6
|
}
|
|
7
7
|
/** The body types that go through as they are, under the JSON content type. */
|
|
8
8
|
type TPassThroughBodyType = typeof RequestBodyTypes.JSON | typeof RequestBodyTypes.NONE | typeof RequestBodyTypes.BINARY;
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Turns a request body into what `fetch` sends, by `RequestBodyTypes`.
|
|
11
|
+
*
|
|
12
|
+
* @useWhen you turn a request body into what `fetch` sends
|
|
13
|
+
* @insteadOf `JSON.stringify` and `FormData` built by hand
|
|
14
|
+
*/
|
|
10
15
|
export declare class RequestBodyEncoder {
|
|
11
16
|
/**
|
|
12
17
|
* The body as it is sent and the content type to send it under. The overloads give the type of what
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { getError } from '@venizia/ignis-inversion';
|
|
2
2
|
import { RequestBodyTypes } from '../common/index.js';
|
|
3
3
|
import { ValueUtility } from './value.js';
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Turns a request body into what `fetch` sends, by `RequestBodyTypes`.
|
|
6
|
+
*
|
|
7
|
+
* @useWhen you turn a request body into what `fetch` sends
|
|
8
|
+
* @insteadOf `JSON.stringify` and `FormData` built by hand
|
|
9
|
+
*/
|
|
5
10
|
export class RequestBodyEncoder {
|
|
6
11
|
static encode(opts) {
|
|
7
12
|
const { bodyType, body } = opts;
|
|
@@ -1,11 +1,22 @@
|
|
|
1
|
+
import type { TNullable } from '@venizia/ignis-helpers/common';
|
|
1
2
|
/**
|
|
2
3
|
* The name `config.js` writes the runtime config under: `window.__APP_CONFIG__`, a record of strings.
|
|
3
4
|
* The preset image writes it at container start, from the environment variables that start with `VITE_`.
|
|
5
|
+
*
|
|
6
|
+
* @useWhen you need the name of the global the runtime config is written under
|
|
4
7
|
*/
|
|
5
8
|
export declare const RUNTIME_CONFIG_GLOBAL = "__APP_CONFIG__";
|
|
6
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* The `normalized.code` of the error `RuntimeConfig.getRequired` throws for a value that is not set; the key is in its `extra.key`.
|
|
11
|
+
*
|
|
12
|
+
* @useWhen you tell the error of a required config value that is not set from any other error
|
|
13
|
+
*/
|
|
7
14
|
export declare const RUNTIME_CONFIG_REQUIRED_CODE = "ardor.runtime_config.required";
|
|
8
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* The `normalized.code` of the error a `transform` of `RuntimeConfig` causes by throwing, or by answering `undefined` or `null` to `getRequired`; the key is in its `extra.key`, the value is never in the error.
|
|
17
|
+
*
|
|
18
|
+
* @useWhen you tell the error of a config value that failed its `transform` from any other error
|
|
19
|
+
*/
|
|
9
20
|
export declare const RUNTIME_CONFIG_INVALID_CODE = "ardor.runtime_config.invalid";
|
|
10
21
|
interface IRuntimeConfigReadOptions {
|
|
11
22
|
/** The name looked up in `window.__APP_CONFIG__` and in `buildTimeEnv`. */
|
|
@@ -13,7 +24,12 @@ interface IRuntimeConfigReadOptions {
|
|
|
13
24
|
/** The build-time source, normally `import.meta.env`. */
|
|
14
25
|
buildTimeEnv?: Record<string, unknown>;
|
|
15
26
|
}
|
|
16
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Reads configuration a deployment can change without a rebuild.
|
|
29
|
+
*
|
|
30
|
+
* @useWhen a value must change per deployment without a rebuild
|
|
31
|
+
* @insteadOf `import.meta.env` or `window.__APP_CONFIG__` read by hand
|
|
32
|
+
*/
|
|
17
33
|
export declare class RuntimeConfig {
|
|
18
34
|
/**
|
|
19
35
|
* One config value: the runtime one (`window.__APP_CONFIG__`), else the build-time one
|
|
@@ -34,7 +50,7 @@ export declare class RuntimeConfig {
|
|
|
34
50
|
transform?: undefined;
|
|
35
51
|
}): string | undefined;
|
|
36
52
|
static get<TValue>(opts: IRuntimeConfigReadOptions & {
|
|
37
|
-
transform: (raw: string | undefined) => TValue
|
|
53
|
+
transform: (raw: string | undefined) => TNullable<TValue>;
|
|
38
54
|
defaultValue: TValue;
|
|
39
55
|
}): TValue;
|
|
40
56
|
static get<TValue>(opts: IRuntimeConfigReadOptions & {
|
|
@@ -55,7 +71,7 @@ export declare class RuntimeConfig {
|
|
|
55
71
|
transform?: undefined;
|
|
56
72
|
}): string;
|
|
57
73
|
static getRequired<TValue>(opts: IRuntimeConfigReadOptions & {
|
|
58
|
-
transform: (raw: string) => TValue
|
|
74
|
+
transform: (raw: string) => TNullable<TValue>;
|
|
59
75
|
}): TValue;
|
|
60
76
|
}
|
|
61
77
|
export {};
|
|
@@ -2,11 +2,21 @@ import { getError } from '@venizia/ignis-inversion';
|
|
|
2
2
|
/**
|
|
3
3
|
* The name `config.js` writes the runtime config under: `window.__APP_CONFIG__`, a record of strings.
|
|
4
4
|
* The preset image writes it at container start, from the environment variables that start with `VITE_`.
|
|
5
|
+
*
|
|
6
|
+
* @useWhen you need the name of the global the runtime config is written under
|
|
5
7
|
*/
|
|
6
8
|
export const RUNTIME_CONFIG_GLOBAL = '__APP_CONFIG__';
|
|
7
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* The `normalized.code` of the error `RuntimeConfig.getRequired` throws for a value that is not set; the key is in its `extra.key`.
|
|
11
|
+
*
|
|
12
|
+
* @useWhen you tell the error of a required config value that is not set from any other error
|
|
13
|
+
*/
|
|
8
14
|
export const RUNTIME_CONFIG_REQUIRED_CODE = 'ardor.runtime_config.required';
|
|
9
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* The `normalized.code` of the error a `transform` of `RuntimeConfig` causes by throwing, or by answering `undefined` or `null` to `getRequired`; the key is in its `extra.key`, the value is never in the error.
|
|
17
|
+
*
|
|
18
|
+
* @useWhen you tell the error of a config value that failed its `transform` from any other error
|
|
19
|
+
*/
|
|
10
20
|
export const RUNTIME_CONFIG_INVALID_CODE = 'ardor.runtime_config.invalid';
|
|
11
21
|
const readString = (opts) => {
|
|
12
22
|
const { source, key } = opts;
|
|
@@ -38,7 +48,12 @@ const applyTransform = (opts) => {
|
|
|
38
48
|
});
|
|
39
49
|
}
|
|
40
50
|
};
|
|
41
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Reads configuration a deployment can change without a rebuild.
|
|
53
|
+
*
|
|
54
|
+
* @useWhen a value must change per deployment without a rebuild
|
|
55
|
+
* @insteadOf `import.meta.env` or `window.__APP_CONFIG__` read by hand
|
|
56
|
+
*/
|
|
42
57
|
export class RuntimeConfig {
|
|
43
58
|
static get(opts) {
|
|
44
59
|
const { key, defaultValue, transform } = opts;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { IStorageCodec } from '../common/index.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* The codecs `BrowserStorage` takes, in place of its JSON default.
|
|
4
|
+
*
|
|
5
|
+
* @useWhen `BrowserStorage` or `useStoredState` needs a codec other than JSON
|
|
6
|
+
* @insteadOf hand-written parse and stringify around storage
|
|
7
|
+
*/
|
|
3
8
|
export declare class StorageCodecs {
|
|
4
9
|
/** A bare string, not JSON. Create once; outside `allowed`, decode and encode throw. */
|
|
5
10
|
static text<TText extends string = string>(opts?: {
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { getError } from '@venizia/ignis-inversion';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* The codecs `BrowserStorage` takes, in place of its JSON default.
|
|
4
|
+
*
|
|
5
|
+
* @useWhen `BrowserStorage` or `useStoredState` needs a codec other than JSON
|
|
6
|
+
* @insteadOf hand-written parse and stringify around storage
|
|
7
|
+
*/
|
|
3
8
|
export class StorageCodecs {
|
|
4
9
|
/** A bare string, not JSON. Create once; outside `allowed`, decode and encode throw. */
|
|
5
10
|
static text(opts = {}) {
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import type { TNullable } from '@venizia/ignis-helpers/common';
|
|
2
|
+
/**
|
|
3
|
+
* Checks of a value's kind.
|
|
4
|
+
*
|
|
5
|
+
* @useWhen you check what type a value has
|
|
6
|
+
* @insteadOf repeated `typeof` chains
|
|
7
|
+
*/
|
|
2
8
|
export declare class ValueUtility {
|
|
3
9
|
/** Positional on purpose: a type predicate narrows its own parameter. */
|
|
4
|
-
static isDefined<TValue>(value: TValue
|
|
10
|
+
static isDefined<TValue>(value: TNullable<TValue>): value is TValue;
|
|
5
11
|
/** Positional on purpose: a type predicate narrows its own parameter. */
|
|
6
12
|
static isString(value: unknown): value is string;
|
|
7
13
|
/** A number, or a string that reads as a finite number. */
|
package/dist/utilities/value.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Checks of a value's kind.
|
|
3
|
+
*
|
|
4
|
+
* @useWhen you check what type a value has
|
|
5
|
+
* @insteadOf repeated `typeof` chains
|
|
6
|
+
*/
|
|
2
7
|
export class ValueUtility {
|
|
3
8
|
/** Positional on purpose: a type predicate narrows its own parameter. */
|
|
4
9
|
static isDefined(value) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/ardor-kernel",
|
|
3
|
-
"version": "0.5.0-
|
|
3
|
+
"version": "0.5.0-12",
|
|
4
4
|
"description": "ARDOR kernel - the isomorphic core of the ARDOR frontend framework: application base on IGNIS inversion, service and provider bases, request/auth constants, binding keys, the network request service, runtime config and the HTTP repository (from IGNIS). No React and no react-admin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ardor",
|
|
@@ -72,12 +72,12 @@
|
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@size-limit/preset-small-lib": "^14.2.0",
|
|
74
74
|
"@types/bun": "^1.4.5",
|
|
75
|
-
"@venizia/dev-configs": "^0.5.0-
|
|
76
|
-
"@venizia/ignis-connectors": "^0.5.0-
|
|
77
|
-
"@venizia/ignis-filter": "^0.5.0-
|
|
78
|
-
"@venizia/ignis-helpers": "^0.5.0-
|
|
79
|
-
"@venizia/ignis-inversion": "^0.5.0-
|
|
80
|
-
"@venizia/ignis-kernel": "^0.5.0-
|
|
75
|
+
"@venizia/dev-configs": "^0.5.0-8",
|
|
76
|
+
"@venizia/ignis-connectors": "^0.5.0-12",
|
|
77
|
+
"@venizia/ignis-filter": "^0.5.0-4",
|
|
78
|
+
"@venizia/ignis-helpers": "^0.5.0-10",
|
|
79
|
+
"@venizia/ignis-inversion": "^0.5.0-4",
|
|
80
|
+
"@venizia/ignis-kernel": "^0.5.0-11",
|
|
81
81
|
"eslint": "^10.13.0",
|
|
82
82
|
"oxlint": "1.89.0",
|
|
83
83
|
"oxlint-tsgolint": "7.0.2004",
|
|
@@ -87,11 +87,11 @@
|
|
|
87
87
|
"typescript": "^6.0.3"
|
|
88
88
|
},
|
|
89
89
|
"peerDependencies": {
|
|
90
|
-
"@venizia/ignis-connectors": "^0.5.0-
|
|
91
|
-
"@venizia/ignis-filter": "^0.5.0-
|
|
92
|
-
"@venizia/ignis-helpers": "^0.5.0-
|
|
93
|
-
"@venizia/ignis-inversion": "^0.5.0-
|
|
94
|
-
"@venizia/ignis-kernel": "^0.5.0-
|
|
90
|
+
"@venizia/ignis-connectors": "^0.5.0-12",
|
|
91
|
+
"@venizia/ignis-filter": "^0.5.0-4",
|
|
92
|
+
"@venizia/ignis-helpers": "^0.5.0-10",
|
|
93
|
+
"@venizia/ignis-inversion": "^0.5.0-4",
|
|
94
|
+
"@venizia/ignis-kernel": "^0.5.0-11",
|
|
95
95
|
"reflect-metadata": ">=0.2.2"
|
|
96
96
|
},
|
|
97
97
|
"peerDependenciesMeta": {
|