@platformatic/globals 3.57.0 → 3.58.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.
- package/README.md +23 -6
- package/lib/index.d.ts +9 -1
- package/lib/index.js +8 -0
- package/package.json +11 -2
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @platformatic/globals
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Typed accessors for Platformatic runtime APIs.
|
|
4
|
+
|
|
5
|
+
Applications use `@platformatic/globals` to read runtime context, use the shared logger, exchange messages, register metrics, customize health checks, and publish metadata while running inside Watt or Platformatic Runtime.
|
|
4
6
|
|
|
5
7
|
## Install
|
|
6
8
|
|
|
@@ -10,16 +12,31 @@ npm install @platformatic/globals
|
|
|
10
12
|
|
|
11
13
|
## Usage
|
|
12
14
|
|
|
13
|
-
```
|
|
14
|
-
import { getApplicationId,
|
|
15
|
+
```js
|
|
16
|
+
import { getApplicationId, getLogger, getMessaging } from '@platformatic/globals'
|
|
15
17
|
|
|
16
18
|
const applicationId = getApplicationId()
|
|
17
|
-
const
|
|
18
|
-
const closing = getClosing()
|
|
19
|
+
const logger = getLogger()
|
|
19
20
|
const messaging = getMessaging()
|
|
21
|
+
|
|
22
|
+
logger.info({ applicationId }, 'Application started')
|
|
23
|
+
|
|
24
|
+
messaging.handle('ping', () => 'pong')
|
|
20
25
|
```
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
Runtime APIs are injected when the application runs inside Watt or Platformatic Runtime. Most getters throw when the requested API is not available. Pass `{ throwOnMissing: false }` to return `undefined` instead:
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import { getBasePath } from '@platformatic/globals'
|
|
31
|
+
|
|
32
|
+
const basePath = getBasePath({ throwOnMissing: false }) ?? ''
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Direct access through the legacy `globalThis.platformatic` object is still supported for compatibility, but deprecated. Use the typed getters and setters instead.
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
|
|
39
|
+
See the [Runtime APIs reference](https://docs.platformatic.dev/docs/reference/runtime/globals) for the complete API list and examples.
|
|
23
40
|
|
|
24
41
|
## License
|
|
25
42
|
|
package/lib/index.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export interface PlatformaticGlobal {
|
|
|
65
65
|
executable: string
|
|
66
66
|
runtimeId: number
|
|
67
67
|
nextVersion: { major: number, minor?: number }
|
|
68
|
-
exitOnUnhandledErrors: boolean
|
|
68
|
+
exitOnUnhandledErrors: boolean | number
|
|
69
69
|
reuseTcpPorts: boolean
|
|
70
70
|
|
|
71
71
|
// Service configuration
|
|
@@ -74,6 +74,8 @@ export interface PlatformaticGlobal {
|
|
|
74
74
|
additionalServerOptions: object
|
|
75
75
|
telemetryConfig: object
|
|
76
76
|
config: object
|
|
77
|
+
runtimeConfig: object
|
|
78
|
+
applicationConfig: object | null
|
|
77
79
|
applicationId: string
|
|
78
80
|
workerId: number | string
|
|
79
81
|
root: string
|
|
@@ -182,6 +184,12 @@ export declare function getTelemetryConfig (options: GlobalGetterOptions): Platf
|
|
|
182
184
|
export declare function getConfig (options?: RequiredGlobalGetterOptions): PlatformaticGlobal['config']
|
|
183
185
|
export declare function getConfig (options: OptionalGlobalGetterOptions): PlatformaticGlobal['config'] | undefined
|
|
184
186
|
export declare function getConfig (options: GlobalGetterOptions): PlatformaticGlobal['config'] | undefined
|
|
187
|
+
export declare function getRuntimeConfig (options?: RequiredGlobalGetterOptions): PlatformaticGlobal['runtimeConfig']
|
|
188
|
+
export declare function getRuntimeConfig (options: OptionalGlobalGetterOptions): PlatformaticGlobal['runtimeConfig'] | undefined
|
|
189
|
+
export declare function getRuntimeConfig (options: GlobalGetterOptions): PlatformaticGlobal['runtimeConfig'] | undefined
|
|
190
|
+
export declare function getApplicationConfig (options?: RequiredGlobalGetterOptions): PlatformaticGlobal['applicationConfig']
|
|
191
|
+
export declare function getApplicationConfig (options: OptionalGlobalGetterOptions): PlatformaticGlobal['applicationConfig'] | undefined
|
|
192
|
+
export declare function getApplicationConfig (options: GlobalGetterOptions): PlatformaticGlobal['applicationConfig'] | undefined
|
|
185
193
|
export declare function getApplicationId (options?: RequiredGlobalGetterOptions): PlatformaticGlobal['applicationId']
|
|
186
194
|
export declare function getApplicationId (options: OptionalGlobalGetterOptions): PlatformaticGlobal['applicationId'] | undefined
|
|
187
195
|
export declare function getApplicationId (options: GlobalGetterOptions): PlatformaticGlobal['applicationId'] | undefined
|
package/lib/index.js
CHANGED
|
@@ -87,6 +87,14 @@ export function getConfig (options) {
|
|
|
87
87
|
return getField('config', options)
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
export function getRuntimeConfig (options) {
|
|
91
|
+
return getField('runtimeConfig', options)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function getApplicationConfig (options) {
|
|
95
|
+
return getField('applicationConfig', options)
|
|
96
|
+
}
|
|
97
|
+
|
|
90
98
|
export function getApplicationId (options) {
|
|
91
99
|
return getField('applicationId', options)
|
|
92
100
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/globals",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.58.0",
|
|
4
4
|
"description": "Platformatic Global Object Getter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -21,7 +21,16 @@
|
|
|
21
21
|
"bugs": {
|
|
22
22
|
"url": "https://github.com/platformatic/platformatic/issues"
|
|
23
23
|
},
|
|
24
|
-
"homepage": "https://
|
|
24
|
+
"homepage": "https://docs.platformatic.dev/docs/reference/runtime/globals",
|
|
25
|
+
"keywords": [
|
|
26
|
+
"platformatic",
|
|
27
|
+
"watt",
|
|
28
|
+
"runtime",
|
|
29
|
+
"globals",
|
|
30
|
+
"logger",
|
|
31
|
+
"metrics",
|
|
32
|
+
"messaging"
|
|
33
|
+
],
|
|
25
34
|
"devDependencies": {
|
|
26
35
|
"@types/node": "^22.10.6",
|
|
27
36
|
"cleaner-spec-reporter": "^0.5.0",
|