@pryv/boiler 1.2.5 → 1.2.6

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.d.ts +196 -182
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pryv/boiler",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "private": false,
5
5
  "description": "Logging and config boilerplate library for Node.js apps and services at Pryv",
6
6
  "keywords": [
package/src/index.d.ts CHANGED
@@ -3,208 +3,222 @@
3
3
  * [BSD-3-Clause](https://github.com/pryv/pryv-boiler/blob/master/LICENSE)
4
4
  */
5
5
 
6
- export = boiler;
6
+ // ----- Exported Types (for ESM: import type { Config, Logger } from '@pryv/boiler') -----
7
+
8
+ export interface InitOptions {
9
+ /** The name of the application, used by Logger and debug */
10
+ appName: string;
11
+ /** Directory to use to look for configs (default, env) */
12
+ baseConfigDir?: string;
13
+ /** Directory to use for `file://` relative paths */
14
+ baseFilesDir?: string;
15
+ /** Array of extra config sources to load */
16
+ extraConfigs?: Array<ConfigFile | ConfigPlugin | ConfigPluginAsync | ConfigData | ConfigRemoteURL | ConfigRemoteURLFromKey | ConfigFileAsync>;
17
+ }
18
+
19
+ export interface ConfigFile {
20
+ /** Scope for nconf hierarchical load */
21
+ scope: string;
22
+ /** The config file path (.yml, .json, .js) */
23
+ file: string;
24
+ }
25
+
26
+ export interface ConfigFileAsync {
27
+ /** Scope for nconf hierarchical load */
28
+ scope: string;
29
+ /** The async config file path (.js that exports an async function) */
30
+ fileAsync: string;
31
+ }
32
+
33
+ export interface ConfigPlugin {
34
+ plugin: {
35
+ /** Function that takes the Config instance and returns the plugin name */
36
+ load: (config: Config) => string;
37
+ };
38
+ }
39
+
40
+ export interface ConfigPluginAsync {
41
+ pluginAsync: {
42
+ /** Async function that takes the Config instance and returns the plugin name */
43
+ load: (config: Config) => Promise<string>;
44
+ };
45
+ }
46
+
47
+ export interface ConfigData {
48
+ /** Scope for nconf hierarchical load */
49
+ scope: string;
50
+ /** Key to load data under. If null, loaded at root of the config */
51
+ key?: string;
52
+ /** The data to load */
53
+ data: object;
54
+ }
55
+
56
+ export interface ConfigRemoteURL {
57
+ /** Scope for nconf hierarchical load */
58
+ scope: string;
59
+ /** Key to load result of URL under. If null, loaded at root of the config */
60
+ key?: string;
61
+ /** The URL to the config definition */
62
+ url: string;
63
+ }
64
+
65
+ export interface ConfigRemoteURLFromKey {
66
+ /** Scope for nconf hierarchical load */
67
+ scope: string;
68
+ /** Key to load result of URL under. If null, override */
69
+ key?: string;
70
+ /** Retrieve URL from config matching this key */
71
+ urlFromKey: string;
72
+ }
73
+
74
+ export interface ScopeAndValue {
75
+ value: unknown;
76
+ scope: string;
77
+ info: string;
78
+ }
79
+
80
+ /** Type alias for extra config entries */
81
+ export type ExtraConfig = ConfigFile | ConfigPlugin | ConfigPluginAsync | ConfigData | ConfigRemoteURL | ConfigRemoteURLFromKey | ConfigFileAsync;
82
+
83
+ export interface Config {
84
+ /** The nconf store instance */
85
+ store: unknown;
86
+ /** The logger instance for config */
87
+ logger: Logger;
88
+ /** Base directory for config files */
89
+ baseConfigDir: string;
90
+
91
+ /**
92
+ * Return true if key has a value
93
+ * @param key - The config key to check
94
+ */
95
+ has(key: string): boolean;
96
+
97
+ /**
98
+ * Retrieve value
99
+ * @param key - The config key. If no key is provided, all the config is returned
100
+ */
101
+ get(key?: string): unknown;
102
+ get<T>(key: string): T;
7
103
 
8
- declare const boiler: {
104
+ /**
105
+ * Retrieve value and store info that applies
106
+ * @param key - The config key
107
+ */
108
+ getScopeAndValue(key: string): ScopeAndValue | null;
109
+
110
+ /**
111
+ * Set value
112
+ * @param key - The config key
113
+ * @param value - The value to set
114
+ */
115
+ set(key: string, value: unknown): void;
116
+
117
+ /**
118
+ * Inject test config and override any other option
119
+ * @param configObject - The config object to inject for testing
120
+ */
121
+ injectTestConfig(configObject: object): void;
122
+
123
+ /**
124
+ * Replace a scope config set
125
+ * @param scope - The scope to replace
126
+ * @param configObject - The new config object for the scope
127
+ */
128
+ replaceScopeConfig(scope: string, configObject: object): void;
129
+ }
130
+
131
+ export interface Logger {
132
+ /** The name of this logger */
133
+ name: string;
134
+ /** The parent logger, if any */
135
+ parent: Logger | null;
136
+
137
+ /**
138
+ * Log a message at the specified level
139
+ * @param level - The log level
140
+ * @param message - The log message
141
+ * @param context - Additional context
142
+ */
143
+ log(level: string, message: string, ...context: unknown[]): void;
144
+
145
+ /**
146
+ * Log an info message
147
+ * @param message - The log message
148
+ * @param context - Additional context
149
+ */
150
+ info(message: string, ...context: unknown[]): void;
151
+
152
+ /**
153
+ * Log a warning message
154
+ * @param message - The log message
155
+ * @param context - Additional context
156
+ */
157
+ warn(message: string, ...context: unknown[]): void;
158
+
159
+ /**
160
+ * Log an error message
161
+ * @param message - The log message
162
+ * @param context - Additional context
163
+ */
164
+ error(message: string, ...context: unknown[]): void;
165
+
166
+ /**
167
+ * Log a debug message
168
+ * @param message - The log message
169
+ * @param context - Additional context
170
+ */
171
+ debug(message: string, ...context: unknown[]): void;
172
+
173
+ /**
174
+ * Get a "sub" Logger
175
+ * @param name - The name of the child logger
176
+ */
177
+ getLogger(name: string): Logger;
178
+
179
+ /**
180
+ * Dump objects with file and line for debugging
181
+ */
182
+ inspect(...args: unknown[]): void;
183
+ }
184
+
185
+ /** The Boiler instance type (returned by init()) */
186
+ export interface Boiler {
9
187
  /**
10
188
  * Get a Logger
11
189
  * @param name - The name of the logger
12
190
  */
13
- getLogger: (name?: string) => boiler.Logger;
191
+ getLogger: (name?: string) => Logger;
14
192
 
15
193
  /**
16
194
  * Preferred way to get the configuration.
17
195
  * Waits until the configuration is fully initialized.
18
196
  */
19
- getConfig: () => Promise<boiler.Config>;
197
+ getConfig: () => Promise<Config>;
20
198
 
21
199
  /**
22
200
  * Get the configuration.
23
201
  * If the configuration is not fully initialized, throws an error (or warns if warnOnly is true).
24
202
  * @param warnOnly - Only warns about potential misuse of config instead of throwing
25
203
  */
26
- getConfigUnsafe: (warnOnly?: boolean) => boiler.Config;
204
+ getConfigUnsafe: (warnOnly?: boolean) => Config;
27
205
 
28
206
  /**
29
207
  * Initialize Boiler. Should be called just once when starting an app.
30
208
  * @param options - Initialization options
31
209
  * @param fullyLoadedCallback - Called when the config is fully loaded
32
210
  */
33
- init: (options: boiler.InitOptions, fullyLoadedCallback?: (config: boiler.Config) => void) => typeof boiler;
34
- };
35
-
36
- declare namespace boiler {
37
- interface InitOptions {
38
- /** The name of the application, used by Logger and debug */
39
- appName: string;
40
- /** Directory to use to look for configs (default, env) */
41
- baseConfigDir?: string;
42
- /** Directory to use for `file://` relative paths */
43
- baseFilesDir?: string;
44
- /** Array of extra config sources to load */
45
- extraConfigs?: Array<ConfigFile | ConfigPlugin | ConfigPluginAsync | ConfigData | ConfigRemoteURL | ConfigRemoteURLFromKey | ConfigFileAsync>;
46
- }
47
-
48
- interface ConfigFile {
49
- /** Scope for nconf hierarchical load */
50
- scope: string;
51
- /** The config file path (.yml, .json, .js) */
52
- file: string;
53
- }
54
-
55
- interface ConfigFileAsync {
56
- /** Scope for nconf hierarchical load */
57
- scope: string;
58
- /** The async config file path (.js that exports an async function) */
59
- fileAsync: string;
60
- }
61
-
62
- interface ConfigPlugin {
63
- plugin: {
64
- /** Function that takes the Config instance and returns the plugin name */
65
- load: (config: Config) => string;
66
- };
67
- }
68
-
69
- interface ConfigPluginAsync {
70
- pluginAsync: {
71
- /** Async function that takes the Config instance and returns the plugin name */
72
- load: (config: Config) => Promise<string>;
73
- };
74
- }
75
-
76
- interface ConfigData {
77
- /** Scope for nconf hierarchical load */
78
- scope: string;
79
- /** Key to load data under. If null, loaded at root of the config */
80
- key?: string;
81
- /** The data to load */
82
- data: object;
83
- }
84
-
85
- interface ConfigRemoteURL {
86
- /** Scope for nconf hierarchical load */
87
- scope: string;
88
- /** Key to load result of URL under. If null, loaded at root of the config */
89
- key?: string;
90
- /** The URL to the config definition */
91
- url: string;
92
- }
93
-
94
- interface ConfigRemoteURLFromKey {
95
- /** Scope for nconf hierarchical load */
96
- scope: string;
97
- /** Key to load result of URL under. If null, override */
98
- key?: string;
99
- /** Retrieve URL from config matching this key */
100
- urlFromKey: string;
101
- }
102
-
103
- interface ScopeAndValue {
104
- value: unknown;
105
- scope: string;
106
- info: string;
107
- }
108
-
109
- class Config {
110
- /** The nconf store instance */
111
- store: unknown;
112
- /** The logger instance for config */
113
- logger: Logger;
114
- /** Base directory for config files */
115
- baseConfigDir: string;
116
-
117
- /**
118
- * Return true if key has a value
119
- * @param key - The config key to check
120
- */
121
- has(key: string): boolean;
122
-
123
- /**
124
- * Retrieve value
125
- * @param key - The config key. If no key is provided, all the config is returned
126
- */
127
- get(key?: string): unknown;
128
- get<T>(key: string): T | undefined;
129
-
130
- /**
131
- * Retrieve value and store info that applies
132
- * @param key - The config key
133
- */
134
- getScopeAndValue(key: string): ScopeAndValue | null;
135
-
136
- /**
137
- * Set value
138
- * @param key - The config key
139
- * @param value - The value to set
140
- */
141
- set(key: string, value: unknown): void;
142
-
143
- /**
144
- * Inject test config and override any other option
145
- * @param configObject - The config object to inject for testing
146
- */
147
- injectTestConfig(configObject: object): void;
148
-
149
- /**
150
- * Replace a scope config set
151
- * @param scope - The scope to replace
152
- * @param configObject - The new config object for the scope
153
- */
154
- replaceScopeConfig(scope: string, configObject: object): void;
155
- }
156
-
157
- class Logger {
158
- /** The name of this logger */
159
- name: string;
160
- /** The parent logger, if any */
161
- parent: Logger | null;
162
-
163
- /**
164
- * Log a message at the specified level
165
- * @param level - The log level
166
- * @param message - The log message
167
- * @param context - Additional context
168
- */
169
- log(level: string, message: string, ...context: unknown[]): void;
170
-
171
- /**
172
- * Log an info message
173
- * @param message - The log message
174
- * @param context - Additional context
175
- */
176
- info(message: string, ...context: unknown[]): void;
177
-
178
- /**
179
- * Log a warning message
180
- * @param message - The log message
181
- * @param context - Additional context
182
- */
183
- warn(message: string, ...context: unknown[]): void;
184
-
185
- /**
186
- * Log an error message
187
- * @param message - The log message
188
- * @param context - Additional context
189
- */
190
- error(message: string, ...context: unknown[]): void;
191
-
192
- /**
193
- * Log a debug message
194
- * @param message - The log message
195
- * @param context - Additional context
196
- */
197
- debug(message: string, ...context: unknown[]): void;
198
-
199
- /**
200
- * Get a "sub" Logger
201
- * @param name - The name of the child logger
202
- */
203
- getLogger(name: string): Logger;
204
-
205
- /**
206
- * Dump objects with file and line for debugging
207
- */
208
- inspect(...args: unknown[]): void;
209
- }
211
+ init: (options: InitOptions, fullyLoadedCallback?: (config: Config) => void) => Boiler;
210
212
  }
213
+
214
+ // ----- Module-level functions (for: const { getConfig, getLogger } = boiler) -----
215
+
216
+ export function getLogger(name?: string): Logger;
217
+ export function getConfig(): Promise<Config>;
218
+ export function getConfigUnsafe(warnOnly?: boolean): Config;
219
+ export function init(options: InitOptions, fullyLoadedCallback?: (config: Config) => void): Boiler;
220
+
221
+ // ----- Default Export (for: import boiler from '@pryv/boiler') -----
222
+
223
+ declare const boiler: Boiler;
224
+ export default boiler;