@platformatic/runtime 2.32.0 → 2.34.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,11 +5,11 @@
5
5
  * and run json-schema-to-typescript to regenerate this file.
6
6
  */
7
7
 
8
- export type HttpsSchemasPlatformaticDevPlatformaticRuntime2320Json = {
8
+ export type HttpsSchemasPlatformaticDevPlatformaticRuntime2340Json = {
9
9
  [k: string]: unknown;
10
10
  } & {
11
11
  $schema?: string;
12
- preload?: string;
12
+ preload?: string | string[];
13
13
  entrypoint?: string;
14
14
  basePath?: string;
15
15
  autoload?: {
@@ -30,6 +30,8 @@ export type HttpsSchemasPlatformaticDevPlatformaticRuntime2320Json = {
30
30
  maxHeapUsed?: number | string;
31
31
  maxHeapTotal?: number | string;
32
32
  };
33
+ preload?: string | string[];
34
+ nodeOptions?: string;
33
35
  };
34
36
  };
35
37
  };
package/lib/runtime.js CHANGED
@@ -992,6 +992,14 @@ class Runtime extends EventEmitter {
992
992
  execArgv.push('--enable-source-maps')
993
993
  }
994
994
 
995
+ const workerEnv = structuredClone(this.#env)
996
+
997
+ if (serviceConfig.nodeOptions?.trim().length > 0) {
998
+ const originalNodeOptions = workerEnv['NODE_OPTIONS'] ?? ''
999
+
1000
+ workerEnv['NODE_OPTIONS'] = `${originalNodeOptions} ${serviceConfig.nodeOptions}`.trim()
1001
+ }
1002
+
995
1003
  const worker = new Worker(kWorkerFile, {
996
1004
  workerData: {
997
1005
  config,
@@ -1011,7 +1019,7 @@ class Runtime extends EventEmitter {
1011
1019
  loggingPort
1012
1020
  },
1013
1021
  execArgv,
1014
- env: this.#env,
1022
+ env: workerEnv,
1015
1023
  transferList: [loggingPort],
1016
1024
  resourceLimits: {
1017
1025
  maxOldGenerationSizeMb: health.maxHeapTotal
package/lib/schema.js CHANGED
@@ -23,6 +23,19 @@ const workers = {
23
23
  ]
24
24
  }
25
25
 
26
+ const preload = {
27
+ anyOf: [
28
+ { type: 'string', resolvePath: true },
29
+ {
30
+ type: 'array',
31
+ items: {
32
+ type: 'string',
33
+ resolvePath: true
34
+ }
35
+ }
36
+ ]
37
+ }
38
+
26
39
  const services = {
27
40
  type: 'array',
28
41
  items: {
@@ -64,6 +77,10 @@ const services = {
64
77
  packageManager: {
65
78
  type: 'string',
66
79
  enum: ['npm', 'pnpm', 'yarn']
80
+ },
81
+ preload,
82
+ nodeOptions: {
83
+ type: 'string'
67
84
  }
68
85
  }
69
86
  }
@@ -79,10 +96,7 @@ const platformaticRuntimeSchema = {
79
96
  $schema: {
80
97
  type: 'string'
81
98
  },
82
- preload: {
83
- type: 'string',
84
- resolvePath: true
85
- },
99
+ preload,
86
100
  entrypoint: {
87
101
  type: 'string'
88
102
  },
@@ -122,7 +136,11 @@ const platformaticRuntimeSchema = {
122
136
  type: 'boolean'
123
137
  },
124
138
  workers,
125
- health: { ...health, default: undefined }
139
+ health: { ...health, default: undefined },
140
+ preload,
141
+ nodeOptions: {
142
+ type: 'string'
143
+ }
126
144
  }
127
145
  }
128
146
  }
@@ -17,9 +17,16 @@ async function createSharedStore (projectDir, httpCacheConfig = {}) {
17
17
 
18
18
  const { body, ...response } = cachedValue
19
19
 
20
- let payload = ''
20
+ const acc = []
21
21
  for await (const chunk of body) {
22
- payload += chunk
22
+ acc.push(chunk)
23
+ }
24
+
25
+ let payload
26
+ if (acc.length > 0 && typeof acc[0] === 'string') {
27
+ payload = acc.join('')
28
+ } else {
29
+ payload = Buffer.concat(acc)
23
30
  }
24
31
 
25
32
  return { response, payload }
@@ -33,8 +33,10 @@ class RemoteCacheStore {
33
33
  const itc = globalThis[kITC]
34
34
  if (!itc) return
35
35
 
36
+ const sanitizedRequest = this.#sanitizeRequest(request)
37
+
36
38
  const cachedValue = await itc.send('getHttpCacheValue', {
37
- request: this.#sanitizeRequest(request)
39
+ request: sanitizedRequest
38
40
  })
39
41
  if (!cachedValue) {
40
42
  try {
@@ -71,16 +73,22 @@ class RemoteCacheStore {
71
73
  const itc = globalThis[kITC]
72
74
  if (!itc) throw new Error('Cannot write to cache without an ITC instance')
73
75
 
74
- let payload = ''
76
+ const acc = []
75
77
 
76
78
  key = this.#sanitizeRequest(key)
77
79
 
78
80
  return new Writable({
79
81
  write (chunk, encoding, callback) {
80
- payload += chunk
82
+ acc.push(chunk)
81
83
  callback()
82
84
  },
83
85
  final (callback) {
86
+ let payload
87
+ if (acc.length > 0 && typeof acc[0] === 'string') {
88
+ payload = acc.join('')
89
+ } else {
90
+ payload = Buffer.concat(acc)
91
+ }
84
92
  itc.send('setHttpCacheValue', { request: key, response: value, payload })
85
93
  .then(() => callback())
86
94
  .catch((err) => callback(err))
@@ -75,10 +75,20 @@ function createLogger () {
75
75
  return loggerInstance
76
76
  }
77
77
 
78
- async function main () {
79
- if (config.preload) {
80
- await import(pathToFileURL(config.preload))
78
+ async function performPreloading (...sources) {
79
+ for (const source of sources) {
80
+ const preload = typeof source.preload === 'string' ? [source.preload] : source.preload
81
+
82
+ if (Array.isArray(preload)) {
83
+ for (const file of preload) {
84
+ await import(pathToFileURL(file))
85
+ }
86
+ }
81
87
  }
88
+ }
89
+
90
+ async function main () {
91
+ await performPreloading(config, workerData.serviceConfig)
82
92
 
83
93
  const service = workerData.serviceConfig
84
94
 
@@ -160,13 +170,13 @@ async function main () {
160
170
  getGlobalDispatcher().compose(
161
171
  httpCacheInterceptor({
162
172
  store: new RemoteCacheStore({
163
- onRequest: (opts) => {
173
+ onRequest: opts => {
164
174
  globalThis.platformatic?.onHttpCacheRequest?.(opts)
165
175
  },
166
- onCacheHit: (opts) => {
176
+ onCacheHit: opts => {
167
177
  globalThis.platformatic?.onHttpCacheHit?.(opts)
168
178
  },
169
- onCacheMiss: (opts) => {
179
+ onCacheMiss: opts => {
170
180
  globalThis.platformatic?.onHttpCacheMiss?.(opts)
171
181
  },
172
182
  logger: globalThis.platformatic.logger
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "2.32.0",
3
+ "version": "2.34.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -17,6 +17,7 @@
17
17
  },
18
18
  "homepage": "https://github.com/platformatic/platformatic#readme",
19
19
  "devDependencies": {
20
+ "@fastify/compress": "^8.0.0",
20
21
  "@fastify/express": "^4.0.0",
21
22
  "@fastify/formbody": "^8.0.0",
22
23
  "borp": "^0.19.0",
@@ -35,12 +36,12 @@
35
36
  "typescript": "^5.5.4",
36
37
  "undici-oidc-interceptor": "^0.5.0",
37
38
  "why-is-node-running": "^2.2.2",
38
- "@platformatic/composer": "2.32.0",
39
- "@platformatic/db": "2.32.0",
40
- "@platformatic/node": "2.32.0",
41
- "@platformatic/service": "2.32.0",
42
- "@platformatic/sql-graphql": "2.32.0",
43
- "@platformatic/sql-mapper": "2.32.0"
39
+ "@platformatic/composer": "2.34.0",
40
+ "@platformatic/db": "2.34.0",
41
+ "@platformatic/node": "2.34.0",
42
+ "@platformatic/sql-graphql": "2.34.0",
43
+ "@platformatic/service": "2.34.0",
44
+ "@platformatic/sql-mapper": "2.34.0"
44
45
  },
45
46
  "dependencies": {
46
47
  "@fastify/accepts": "^5.0.0",
@@ -72,15 +73,15 @@
72
73
  "tail-file-stream": "^0.2.0",
73
74
  "thread-cpu-usage": "^0.2.0",
74
75
  "undici": "^7.0.0",
75
- "undici-thread-interceptor": "^0.10.3",
76
+ "undici-thread-interceptor": "^0.11.0",
76
77
  "ws": "^8.16.0",
77
- "@platformatic/basic": "2.32.0",
78
- "@platformatic/generators": "2.32.0",
79
- "@platformatic/config": "2.32.0",
80
- "@platformatic/itc": "2.32.0",
81
- "@platformatic/ts-compiler": "2.32.0",
82
- "@platformatic/telemetry": "2.32.0",
83
- "@platformatic/utils": "2.32.0"
78
+ "@platformatic/basic": "2.34.0",
79
+ "@platformatic/config": "2.34.0",
80
+ "@platformatic/generators": "2.34.0",
81
+ "@platformatic/telemetry": "2.34.0",
82
+ "@platformatic/ts-compiler": "2.34.0",
83
+ "@platformatic/utils": "2.34.0",
84
+ "@platformatic/itc": "2.34.0"
84
85
  },
85
86
  "scripts": {
86
87
  "test": "npm run lint && borp --concurrency=1 --timeout=300000 && tsd",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/runtime/2.32.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/runtime/2.34.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "type": "object",
5
5
  "properties": {
@@ -7,8 +7,19 @@
7
7
  "type": "string"
8
8
  },
9
9
  "preload": {
10
- "type": "string",
11
- "resolvePath": true
10
+ "anyOf": [
11
+ {
12
+ "type": "string",
13
+ "resolvePath": true
14
+ },
15
+ {
16
+ "type": "array",
17
+ "items": {
18
+ "type": "string",
19
+ "resolvePath": true
20
+ }
21
+ }
22
+ ]
12
23
  },
13
24
  "entrypoint": {
14
25
  "type": "string"
@@ -153,6 +164,24 @@
153
164
  }
154
165
  },
155
166
  "additionalProperties": false
167
+ },
168
+ "preload": {
169
+ "anyOf": [
170
+ {
171
+ "type": "string",
172
+ "resolvePath": true
173
+ },
174
+ {
175
+ "type": "array",
176
+ "items": {
177
+ "type": "string",
178
+ "resolvePath": true
179
+ }
180
+ }
181
+ ]
182
+ },
183
+ "nodeOptions": {
184
+ "type": "string"
156
185
  }
157
186
  }
158
187
  }
@@ -321,6 +350,24 @@
321
350
  "pnpm",
322
351
  "yarn"
323
352
  ]
353
+ },
354
+ "preload": {
355
+ "anyOf": [
356
+ {
357
+ "type": "string",
358
+ "resolvePath": true
359
+ },
360
+ {
361
+ "type": "array",
362
+ "items": {
363
+ "type": "string",
364
+ "resolvePath": true
365
+ }
366
+ }
367
+ ]
368
+ },
369
+ "nodeOptions": {
370
+ "type": "string"
324
371
  }
325
372
  }
326
373
  }
@@ -499,6 +546,24 @@
499
546
  "pnpm",
500
547
  "yarn"
501
548
  ]
549
+ },
550
+ "preload": {
551
+ "anyOf": [
552
+ {
553
+ "type": "string",
554
+ "resolvePath": true
555
+ },
556
+ {
557
+ "type": "array",
558
+ "items": {
559
+ "type": "string",
560
+ "resolvePath": true
561
+ }
562
+ }
563
+ ]
564
+ },
565
+ "nodeOptions": {
566
+ "type": "string"
502
567
  }
503
568
  }
504
569
  }