@platformatic/runtime 2.71.0 → 2.71.1-alpha.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/config.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * and run json-schema-to-typescript to regenerate this file.
6
6
  */
7
7
 
8
- export type HttpsSchemasPlatformaticDevPlatformaticRuntime2710Json = {
8
+ export type HttpsSchemasPlatformaticDevPlatformaticRuntime2711Alpha0Json = {
9
9
  [k: string]: unknown;
10
10
  } & {
11
11
  $schema?: string;
package/lib/runtime.js CHANGED
@@ -83,6 +83,7 @@ class Runtime extends EventEmitter {
83
83
  servicesConfigsPatches
84
84
  #scheduler
85
85
  #stdio
86
+ #sharedContext
86
87
 
87
88
  constructor (configManager, runtimeLogsDir, env) {
88
89
  super()
@@ -120,8 +121,11 @@ class Runtime extends EventEmitter {
120
121
  getHttpCacheValue: this.#getHttpCacheValue.bind(this),
121
122
  setHttpCacheValue: this.#setHttpCacheValue.bind(this),
122
123
  deleteHttpCacheValue: this.#deleteHttpCacheValue.bind(this),
123
- invalidateHttpCache: this.invalidateHttpCache.bind(this)
124
+ invalidateHttpCache: this.invalidateHttpCache.bind(this),
125
+ updateSharedContext: this.updateSharedContext.bind(this),
126
+ getSharedContext: this.getSharedContext.bind(this)
124
127
  }
128
+ this.#sharedContext = {}
125
129
  }
126
130
 
127
131
  async init () {
@@ -1081,6 +1085,35 @@ class Runtime extends EventEmitter {
1081
1085
  return super.emit(event, payload)
1082
1086
  }
1083
1087
 
1088
+ async updateSharedContext (options = {}) {
1089
+ const { context, overwrite = false } = options
1090
+
1091
+ const sharedContext = overwrite ? {} : this.#sharedContext
1092
+ Object.assign(sharedContext, context)
1093
+
1094
+ this.#sharedContext = sharedContext
1095
+
1096
+ const promises = []
1097
+ for (const worker of this.#workers.values()) {
1098
+ promises.push(
1099
+ sendViaITC(worker, 'setSharedContext', sharedContext)
1100
+ )
1101
+ }
1102
+
1103
+ const results = await Promise.allSettled(promises)
1104
+ for (const result of results) {
1105
+ if (result.status === 'rejected') {
1106
+ this.logger.error({ err: result.reason }, 'Cannot update shared context')
1107
+ }
1108
+ }
1109
+
1110
+ return sharedContext
1111
+ }
1112
+
1113
+ getSharedContext () {
1114
+ return this.#sharedContext
1115
+ }
1116
+
1084
1117
  async #setDispatcher (undiciConfig) {
1085
1118
  const config = this.#configManager.current
1086
1119
 
package/lib/worker/itc.js CHANGED
@@ -56,7 +56,7 @@ async function waitEventFromITC (worker, event) {
56
56
  return safeHandleInITC(worker, () => once(worker[kITC], event))
57
57
  }
58
58
 
59
- function setupITC (app, service, dispatcher) {
59
+ function setupITC (app, service, dispatcher, sharedContext) {
60
60
  const messaging = new MessagingITC(app.appConfig.id, workerData.config)
61
61
 
62
62
  Object.assign(globalThis.platformatic ?? {}, {
@@ -210,6 +210,10 @@ function setupITC (app, service, dispatcher) {
210
210
  }
211
211
  },
212
212
 
213
+ setSharedContext (context) {
214
+ sharedContext._set(context)
215
+ },
216
+
213
217
  saveMessagingChannel (channel) {
214
218
  messaging.addSource(channel)
215
219
  }
@@ -23,6 +23,7 @@ const pino = require('pino')
23
23
  const { fetch } = require('undici')
24
24
 
25
25
  const { PlatformaticApp } = require('./app')
26
+ const { SharedContext } = require('./shared-context')
26
27
  const { setupITC } = require('./itc')
27
28
  const { setDispatcher } = require('./interceptors')
28
29
  const { kId, kITC, kStderrMarker } = require('./symbols')
@@ -189,8 +190,15 @@ async function main () {
189
190
  }
190
191
  }
191
192
 
193
+ const sharedContext = new SharedContext()
194
+ // Limit the amount of methods a user can call
195
+ globalThis.platformatic.sharedContext = {
196
+ get: () => sharedContext.get(),
197
+ update: (...args) => sharedContext.update(...args)
198
+ }
199
+
192
200
  // Setup interaction with parent port
193
- const itc = setupITC(app, service, threadDispatcher)
201
+ const itc = setupITC(app, service, threadDispatcher, sharedContext)
194
202
  globalThis[kITC] = itc
195
203
 
196
204
  // Get the dependencies
@@ -0,0 +1,26 @@
1
+ 'use strict'
2
+
3
+ const { kITC } = require('./symbols')
4
+
5
+ class SharedContext {
6
+ constructor () {
7
+ this.sharedContext = null
8
+ }
9
+
10
+ update (context, options = {}) {
11
+ return globalThis[kITC].send('updateSharedContext', { ...options, context })
12
+ }
13
+
14
+ get () {
15
+ if (this.sharedContext === null) {
16
+ this.sharedContext = globalThis[kITC].send('getSharedContext')
17
+ }
18
+ return this.sharedContext
19
+ }
20
+
21
+ _set (context) {
22
+ this.sharedContext = context
23
+ }
24
+ }
25
+
26
+ module.exports = { SharedContext }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "2.71.0",
3
+ "version": "2.71.1-alpha.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -37,12 +37,12 @@
37
37
  "typescript": "^5.5.4",
38
38
  "undici-oidc-interceptor": "^0.5.0",
39
39
  "why-is-node-running": "^2.2.2",
40
- "@platformatic/composer": "2.71.0",
41
- "@platformatic/db": "2.71.0",
42
- "@platformatic/node": "2.71.0",
43
- "@platformatic/service": "2.71.0",
44
- "@platformatic/sql-graphql": "2.71.0",
45
- "@platformatic/sql-mapper": "2.71.0"
40
+ "@platformatic/db": "2.71.1-alpha.0",
41
+ "@platformatic/node": "2.71.1-alpha.0",
42
+ "@platformatic/sql-graphql": "2.71.1-alpha.0",
43
+ "@platformatic/sql-mapper": "2.71.1-alpha.0",
44
+ "@platformatic/composer": "2.71.1-alpha.0",
45
+ "@platformatic/service": "2.71.1-alpha.0"
46
46
  },
47
47
  "dependencies": {
48
48
  "@fastify/accepts": "^5.0.0",
@@ -76,14 +76,14 @@
76
76
  "undici": "^7.0.0",
77
77
  "undici-thread-interceptor": "^0.14.0",
78
78
  "ws": "^8.16.0",
79
- "@platformatic/basic": "2.71.0",
80
- "@platformatic/config": "2.71.0",
81
- "@platformatic/generators": "2.71.0",
82
- "@platformatic/metrics": "2.71.0",
83
- "@platformatic/itc": "2.71.0",
84
- "@platformatic/telemetry": "2.71.0",
85
- "@platformatic/utils": "2.71.0",
86
- "@platformatic/ts-compiler": "2.71.0"
79
+ "@platformatic/basic": "2.71.1-alpha.0",
80
+ "@platformatic/config": "2.71.1-alpha.0",
81
+ "@platformatic/generators": "2.71.1-alpha.0",
82
+ "@platformatic/metrics": "2.71.1-alpha.0",
83
+ "@platformatic/itc": "2.71.1-alpha.0",
84
+ "@platformatic/telemetry": "2.71.1-alpha.0",
85
+ "@platformatic/utils": "2.71.1-alpha.0",
86
+ "@platformatic/ts-compiler": "2.71.1-alpha.0"
87
87
  },
88
88
  "scripts": {
89
89
  "test": "pnpm run lint && borp --concurrency=1 --timeout=1200000 && tsd",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/runtime/2.71.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/runtime/2.71.1-alpha.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "type": "object",
5
5
  "properties": {