@platformatic/runtime 3.31.0 → 3.32.0-alpha.1

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
@@ -275,6 +275,18 @@ export type PlatformaticRuntimeConfig = {
275
275
  maxSize?: number;
276
276
  maxEntrySize?: number;
277
277
  maxCount?: number;
278
+ /**
279
+ * Whitelist of origins to cache. Supports exact strings and regex patterns (e.g., "/https:\\/\\/.*\\.example\\.com/").
280
+ */
281
+ origins?: string[];
282
+ /**
283
+ * Default cache duration in seconds for responses without explicit expiration headers.
284
+ */
285
+ cacheByDefault?: number;
286
+ /**
287
+ * Cache type. "shared" caches may be shared between users, "private" caches are user-specific.
288
+ */
289
+ type?: "shared" | "private";
278
290
  [k: string]: unknown;
279
291
  };
280
292
  watch?: boolean | string;
package/lib/runtime.js CHANGED
@@ -72,6 +72,21 @@ const kInspectorOptions = Symbol('plt.runtime.worker.inspectorOptions')
72
72
 
73
73
  const MAX_LISTENERS_COUNT = 100
74
74
 
75
+ function parseOrigins (origins) {
76
+ if (!origins) return undefined
77
+
78
+ return origins.map(origin => {
79
+ // Check if the origin is a regex pattern (starts and ends with /)
80
+ if (origin.startsWith('/') && origin.lastIndexOf('/') > 0) {
81
+ const lastSlash = origin.lastIndexOf('/')
82
+ const pattern = origin.slice(1, lastSlash)
83
+ const flags = origin.slice(lastSlash + 1)
84
+ return new RegExp(pattern, flags)
85
+ }
86
+ return origin
87
+ })
88
+ }
89
+
75
90
  const MAX_CONCURRENCY = 5
76
91
  const MAX_BOOTSTRAP_ATTEMPTS = 5
77
92
  const IMMEDIATE_RESTART_MAX_THRESHOLD = 10
@@ -1500,7 +1515,10 @@ export class Runtime extends EventEmitter {
1500
1515
  interceptors.push(
1501
1516
  undiciInterceptors.cache({
1502
1517
  store: this.#sharedHttpCache,
1503
- methods: config.httpCache.methods ?? ['GET', 'HEAD']
1518
+ methods: config.httpCache.methods ?? ['GET', 'HEAD'],
1519
+ origins: parseOrigins(config.httpCache.origins),
1520
+ cacheByDefault: config.httpCache.cacheByDefault,
1521
+ type: config.httpCache.type
1504
1522
  })
1505
1523
  )
1506
1524
  }
@@ -178,7 +178,23 @@ function createThreadInterceptor (runtimeConfig) {
178
178
  return threadDispatcher
179
179
  }
180
180
 
181
+ function parseOrigins (origins) {
182
+ if (!origins) return undefined
183
+
184
+ return origins.map(origin => {
185
+ // Check if the origin is a regex pattern (starts and ends with /)
186
+ if (origin.startsWith('/') && origin.lastIndexOf('/') > 0) {
187
+ const lastSlash = origin.lastIndexOf('/')
188
+ const pattern = origin.slice(1, lastSlash)
189
+ const flags = origin.slice(lastSlash + 1)
190
+ return new RegExp(pattern, flags)
191
+ }
192
+ return origin
193
+ })
194
+ }
195
+
181
196
  function createHttpCacheInterceptor (runtimeConfig) {
197
+ const httpCache = runtimeConfig.httpCache
182
198
  const cacheInterceptor = httpCacheInterceptor({
183
199
  store: new RemoteCacheStore({
184
200
  onRequest: opts => {
@@ -192,7 +208,10 @@ function createHttpCacheInterceptor (runtimeConfig) {
192
208
  },
193
209
  logger: globalThis.platformatic.logger
194
210
  }),
195
- methods: runtimeConfig.httpCache.methods ?? ['GET', 'HEAD'],
211
+ methods: httpCache.methods ?? ['GET', 'HEAD'],
212
+ origins: parseOrigins(httpCache.origins),
213
+ cacheByDefault: httpCache.cacheByDefault,
214
+ type: httpCache.type,
196
215
  logger: globalThis.platformatic.logger
197
216
  })
198
217
  return cacheInterceptor
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "3.31.0",
3
+ "version": "3.32.0-alpha.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -35,14 +35,14 @@
35
35
  "typescript": "^5.5.4",
36
36
  "undici-oidc-interceptor": "^0.5.0",
37
37
  "why-is-node-running": "^2.2.2",
38
- "@platformatic/composer": "3.31.0",
39
- "@platformatic/db": "3.31.0",
40
- "@platformatic/gateway": "3.31.0",
41
- "@platformatic/node": "3.31.0",
42
- "@platformatic/sql-graphql": "3.31.0",
43
- "@platformatic/service": "3.31.0",
44
- "@platformatic/wattpm-pprof-capture": "3.31.0",
45
- "@platformatic/sql-mapper": "3.31.0"
38
+ "@platformatic/composer": "3.32.0-alpha.1",
39
+ "@platformatic/db": "3.32.0-alpha.1",
40
+ "@platformatic/gateway": "3.32.0-alpha.1",
41
+ "@platformatic/node": "3.32.0-alpha.1",
42
+ "@platformatic/service": "3.32.0-alpha.1",
43
+ "@platformatic/sql-graphql": "3.32.0-alpha.1",
44
+ "@platformatic/sql-mapper": "3.32.0-alpha.1",
45
+ "@platformatic/wattpm-pprof-capture": "3.32.0-alpha.1"
46
46
  },
47
47
  "dependencies": {
48
48
  "@fastify/accepts": "^5.0.0",
@@ -71,12 +71,12 @@
71
71
  "undici": "^7.0.0",
72
72
  "undici-thread-interceptor": "^1.0.0",
73
73
  "ws": "^8.16.0",
74
- "@platformatic/generators": "3.31.0",
75
- "@platformatic/basic": "3.31.0",
76
- "@platformatic/foundation": "3.31.0",
77
- "@platformatic/itc": "3.31.0",
78
- "@platformatic/metrics": "3.31.0",
79
- "@platformatic/telemetry": "3.31.0"
74
+ "@platformatic/basic": "3.32.0-alpha.1",
75
+ "@platformatic/foundation": "3.32.0-alpha.1",
76
+ "@platformatic/generators": "3.32.0-alpha.1",
77
+ "@platformatic/itc": "3.32.0-alpha.1",
78
+ "@platformatic/metrics": "3.32.0-alpha.1",
79
+ "@platformatic/telemetry": "3.32.0-alpha.1"
80
80
  },
81
81
  "engines": {
82
82
  "node": ">=22.19.0"
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/runtime/3.31.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/runtime/3.32.0-alpha.1.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Runtime Config",
5
5
  "type": "object",
@@ -2009,6 +2009,26 @@
2009
2009
  },
2010
2010
  "maxCount": {
2011
2011
  "type": "integer"
2012
+ },
2013
+ "origins": {
2014
+ "type": "array",
2015
+ "items": {
2016
+ "type": "string"
2017
+ },
2018
+ "description": "Whitelist of origins to cache. Supports exact strings and regex patterns (e.g., \"/https:\\\\/\\\\/.*\\\\.example\\\\.com/\")."
2019
+ },
2020
+ "cacheByDefault": {
2021
+ "type": "integer",
2022
+ "description": "Default cache duration in seconds for responses without explicit expiration headers."
2023
+ },
2024
+ "type": {
2025
+ "type": "string",
2026
+ "enum": [
2027
+ "shared",
2028
+ "private"
2029
+ ],
2030
+ "default": "shared",
2031
+ "description": "Cache type. \"shared\" caches may be shared between users, \"private\" caches are user-specific."
2012
2032
  }
2013
2033
  }
2014
2034
  }