@platformatic/runtime 3.4.1 → 3.5.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.
Files changed (49) hide show
  1. package/README.md +1 -1
  2. package/config.d.ts +224 -77
  3. package/eslint.config.js +3 -5
  4. package/index.d.ts +73 -24
  5. package/index.js +173 -29
  6. package/lib/config.js +279 -197
  7. package/lib/errors.js +126 -34
  8. package/lib/generator.js +640 -0
  9. package/lib/logger.js +43 -41
  10. package/lib/management-api.js +109 -118
  11. package/lib/prom-server.js +202 -16
  12. package/lib/runtime.js +1963 -585
  13. package/lib/scheduler.js +119 -0
  14. package/lib/schema.js +22 -234
  15. package/lib/shared-http-cache.js +43 -0
  16. package/lib/upgrade.js +6 -8
  17. package/lib/utils.js +6 -61
  18. package/lib/version.js +7 -0
  19. package/lib/versions/v1.36.0.js +2 -4
  20. package/lib/versions/v1.5.0.js +2 -4
  21. package/lib/versions/v2.0.0.js +3 -5
  22. package/lib/versions/v3.0.0.js +16 -0
  23. package/lib/worker/controller.js +302 -0
  24. package/lib/worker/http-cache.js +171 -0
  25. package/lib/worker/interceptors.js +190 -10
  26. package/lib/worker/itc.js +146 -59
  27. package/lib/worker/main.js +220 -81
  28. package/lib/worker/messaging.js +182 -0
  29. package/lib/worker/round-robin-map.js +62 -0
  30. package/lib/worker/shared-context.js +22 -0
  31. package/lib/worker/symbols.js +14 -5
  32. package/package.json +47 -38
  33. package/schema.json +1383 -55
  34. package/help/compile.txt +0 -8
  35. package/help/help.txt +0 -5
  36. package/help/start.txt +0 -21
  37. package/index.test-d.ts +0 -41
  38. package/lib/build-server.js +0 -69
  39. package/lib/compile.js +0 -98
  40. package/lib/dependencies.js +0 -59
  41. package/lib/generator/README.md +0 -32
  42. package/lib/generator/errors.js +0 -10
  43. package/lib/generator/runtime-generator.d.ts +0 -37
  44. package/lib/generator/runtime-generator.js +0 -498
  45. package/lib/start.js +0 -190
  46. package/lib/worker/app.js +0 -278
  47. package/lib/worker/default-stackable.js +0 -33
  48. package/lib/worker/metrics.js +0 -122
  49. package/runtime.mjs +0 -54
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @platformatic/runtime
2
2
 
3
- Check out the full documentation for Platformatic Runtime on [our website](https://docs.platformatic.dev/docs/runtime/overview).
3
+ Check out the full documentation for Platformatic Runtime on [our website](https://docs.platformatic.dev/docs/reference/runtime/overview).
4
4
 
5
5
  ## Install
6
6
 
package/config.d.ts CHANGED
@@ -5,12 +5,13 @@
5
5
  * and run json-schema-to-typescript to regenerate this file.
6
6
  */
7
7
 
8
- export type HttpsSchemasPlatformaticDevPlatformaticRuntime341Json = {
8
+ export type PlatformaticRuntimeConfig = {
9
9
  [k: string]: unknown;
10
10
  } & {
11
11
  $schema?: string;
12
- preload?: string;
12
+ preload?: string | string[];
13
13
  entrypoint?: string;
14
+ basePath?: string;
14
15
  autoload?: {
15
16
  path: string;
16
17
  exclude?: string[];
@@ -19,15 +20,34 @@ export type HttpsSchemasPlatformaticDevPlatformaticRuntime341Json = {
19
20
  id: string;
20
21
  config?: string;
21
22
  useHttp?: boolean;
23
+ workers?: number | string;
24
+ health?: {
25
+ enabled?: boolean | string;
26
+ interval?: number | string;
27
+ gracePeriod?: number | string;
28
+ maxUnhealthyChecks?: number | string;
29
+ maxELU?: number | string;
30
+ maxHeapUsed?: number | string;
31
+ maxHeapTotal?: number | string;
32
+ maxYoungGeneration?: number | string;
33
+ };
34
+ preload?: string | string[];
35
+ dependencies?: string[];
36
+ arguments?: string[];
37
+ nodeOptions?: string;
22
38
  };
23
39
  };
24
40
  };
41
+ applications?: {
42
+ [k: string]: unknown;
43
+ }[];
25
44
  services?: {
26
45
  [k: string]: unknown;
27
46
  }[];
28
47
  web?: {
29
48
  [k: string]: unknown;
30
49
  }[];
50
+ workers?: number | string;
31
51
  logger?: {
32
52
  level: (
33
53
  | ("fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent")
@@ -50,8 +70,6 @@ export type HttpsSchemasPlatformaticDevPlatformaticRuntime341Json = {
50
70
  [k: string]: unknown;
51
71
  };
52
72
  level?: string;
53
- additionalProperties?: never;
54
- [k: string]: unknown;
55
73
  }[];
56
74
  options?: {
57
75
  [k: string]: unknown;
@@ -63,6 +81,22 @@ export type HttpsSchemasPlatformaticDevPlatformaticRuntime341Json = {
63
81
  [k: string]: unknown;
64
82
  };
65
83
  };
84
+ formatters?: {
85
+ path: string;
86
+ };
87
+ timestamp?: "epochTime" | "unixTime" | "nullTime" | "isoTime";
88
+ redact?: {
89
+ paths: string[];
90
+ censor?: string;
91
+ };
92
+ base?: {
93
+ [k: string]: unknown;
94
+ } | null;
95
+ messageKey?: string;
96
+ customLevels?: {
97
+ [k: string]: unknown;
98
+ };
99
+ captureStdio?: boolean;
66
100
  [k: string]: unknown;
67
101
  };
68
102
  server?: {
@@ -70,6 +104,7 @@ export type HttpsSchemasPlatformaticDevPlatformaticRuntime341Json = {
70
104
  port?: number | string;
71
105
  http2?: boolean;
72
106
  https?: {
107
+ allowHTTP1?: boolean;
73
108
  key:
74
109
  | string
75
110
  | {
@@ -92,23 +127,79 @@ export type HttpsSchemasPlatformaticDevPlatformaticRuntime341Json = {
92
127
  path?: string;
93
128
  }
94
129
  )[];
130
+ requestCert?: boolean;
131
+ rejectUnauthorized?: boolean;
95
132
  };
96
133
  };
134
+ startTimeout?: number;
97
135
  restartOnError?: boolean | number;
136
+ exitOnUnhandledErrors?: boolean;
137
+ gracefulShutdown?: {
138
+ runtime: number | string;
139
+ application: number | string;
140
+ };
141
+ health?: {
142
+ enabled?: boolean | string;
143
+ interval?: number | string;
144
+ gracePeriod?: number | string;
145
+ maxUnhealthyChecks?: number | string;
146
+ maxELU?: number | string;
147
+ maxHeapUsed?: number | string;
148
+ maxHeapTotal?: number | string;
149
+ maxYoungGeneration?: number | string;
150
+ };
98
151
  undici?: {
99
152
  agentOptions?: {
100
153
  [k: string]: unknown;
101
154
  };
102
155
  interceptors?:
103
- | UndiciInterceptor[]
104
156
  | {
105
- Client?: UndiciInterceptor[];
106
- Pool?: UndiciInterceptor[];
107
- Agent?: UndiciInterceptor[];
157
+ module: string;
158
+ options: {
159
+ [k: string]: unknown;
160
+ };
161
+ [k: string]: unknown;
162
+ }[]
163
+ | {
164
+ Client?: {
165
+ module: string;
166
+ options: {
167
+ [k: string]: unknown;
168
+ };
169
+ [k: string]: unknown;
170
+ }[];
171
+ Pool?: {
172
+ module: string;
173
+ options: {
174
+ [k: string]: unknown;
175
+ };
176
+ [k: string]: unknown;
177
+ }[];
178
+ Agent?: {
179
+ module: string;
180
+ options: {
181
+ [k: string]: unknown;
182
+ };
183
+ [k: string]: unknown;
184
+ }[];
108
185
  [k: string]: unknown;
109
186
  };
110
187
  [k: string]: unknown;
111
188
  };
189
+ httpCache?:
190
+ | boolean
191
+ | {
192
+ store?: string;
193
+ /**
194
+ * @minItems 1
195
+ */
196
+ methods?: [string, ...string[]];
197
+ cacheTagsHeader?: string;
198
+ maxSize?: number;
199
+ maxEntrySize?: number;
200
+ maxCount?: number;
201
+ [k: string]: unknown;
202
+ };
112
203
  watch?: boolean | string;
113
204
  managementApi?:
114
205
  | boolean
@@ -122,6 +213,7 @@ export type HttpsSchemasPlatformaticDevPlatformaticRuntime341Json = {
122
213
  | boolean
123
214
  | {
124
215
  port?: number | string;
216
+ enabled?: boolean | string;
125
217
  hostname?: string;
126
218
  endpoint?: string;
127
219
  auth?: {
@@ -131,88 +223,143 @@ export type HttpsSchemasPlatformaticDevPlatformaticRuntime341Json = {
131
223
  labels?: {
132
224
  [k: string]: string;
133
225
  };
226
+ /**
227
+ * The label name to use for the application identifier in metrics (e.g., applicationId, serviceId)
228
+ */
229
+ applicationLabel?: string;
230
+ readiness?:
231
+ | boolean
232
+ | {
233
+ endpoint?: string;
234
+ success?: {
235
+ statusCode?: number;
236
+ body?: string;
237
+ };
238
+ fail?: {
239
+ statusCode?: number;
240
+ body?: string;
241
+ };
242
+ };
243
+ liveness?:
244
+ | boolean
245
+ | {
246
+ endpoint?: string;
247
+ success?: {
248
+ statusCode?: number;
249
+ body?: string;
250
+ };
251
+ fail?: {
252
+ statusCode?: number;
253
+ body?: string;
254
+ };
255
+ };
256
+ plugins?: string[];
134
257
  };
135
- telemetry?: OpenTelemetry;
136
- inspectorOptions?: {
137
- host?: string;
138
- port?: number;
139
- breakFirstLine?: boolean;
140
- watchDisabled?: boolean;
141
- [k: string]: unknown;
142
- };
143
- };
144
-
145
- export interface UndiciInterceptor {
146
- module: string;
147
- options: {
148
- [k: string]: unknown;
149
- };
150
- [k: string]: unknown;
151
- }
152
- export interface OpenTelemetry {
153
- /**
154
- * The name of the service. Defaults to the folder name if not specified.
155
- */
156
- serviceName: string;
157
- /**
158
- * The version of the service (optional)
159
- */
160
- version?: string;
161
- /**
162
- * An array of paths to skip when creating spans. Useful for health checks and other endpoints that do not need to be traced.
163
- */
164
- skip?: {
258
+ telemetry?: {
259
+ enabled?: boolean | string;
165
260
  /**
166
- * The path to skip. Can be a string or a regex.
261
+ * The name of the application. Defaults to the folder name if not specified.
167
262
  */
168
- path?: string;
263
+ applicationName: string;
169
264
  /**
170
- * HTTP method to skip
265
+ * The version of the application (optional)
171
266
  */
172
- method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
173
- [k: string]: unknown;
174
- }[];
175
- exporter?:
176
- | {
177
- type?: "console" | "otlp" | "zipkin" | "memory";
178
- /**
179
- * Options for the exporter. These are passed directly to the exporter.
180
- */
181
- options?: {
182
- /**
183
- * The URL to send the traces to. Not used for console or memory exporters.
184
- */
185
- url?: string;
267
+ version?: string;
268
+ /**
269
+ * An array of paths to skip when creating spans. Useful for health checks and other endpoints that do not need to be traced.
270
+ */
271
+ skip?: {
272
+ /**
273
+ * The path to skip. Can be a string or a regex.
274
+ */
275
+ path?: string;
276
+ /**
277
+ * HTTP method to skip
278
+ */
279
+ method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
280
+ [k: string]: unknown;
281
+ }[];
282
+ exporter?:
283
+ | {
284
+ type?: "console" | "otlp" | "zipkin" | "memory" | "file";
186
285
  /**
187
- * Headers to send to the exporter. Not used for console or memory exporters.
286
+ * Options for the exporter. These are passed directly to the exporter.
188
287
  */
189
- headers?: {
288
+ options?: {
289
+ /**
290
+ * The URL to send the traces to. Not used for console or memory exporters.
291
+ */
292
+ url?: string;
293
+ /**
294
+ * Headers to send to the exporter. Not used for console or memory exporters.
295
+ */
296
+ headers?: {
297
+ [k: string]: unknown;
298
+ };
299
+ /**
300
+ * The path to write the traces to. Only for file exporter.
301
+ */
302
+ path?: string;
190
303
  [k: string]: unknown;
191
304
  };
305
+ additionalProperties?: never;
192
306
  [k: string]: unknown;
193
- };
194
- additionalProperties?: never;
195
- [k: string]: unknown;
196
- }[]
197
- | {
198
- type?: "console" | "otlp" | "zipkin" | "memory";
199
- /**
200
- * Options for the exporter. These are passed directly to the exporter.
201
- */
202
- options?: {
203
- /**
204
- * The URL to send the traces to. Not used for console or memory exporters.
205
- */
206
- url?: string;
307
+ }[]
308
+ | {
309
+ type?: "console" | "otlp" | "zipkin" | "memory" | "file";
207
310
  /**
208
- * Headers to send to the exporter. Not used for console or memory exporters.
311
+ * Options for the exporter. These are passed directly to the exporter.
209
312
  */
210
- headers?: {
313
+ options?: {
314
+ /**
315
+ * The URL to send the traces to. Not used for console or memory exporters.
316
+ */
317
+ url?: string;
318
+ /**
319
+ * Headers to send to the exporter. Not used for console or memory exporters.
320
+ */
321
+ headers?: {
322
+ [k: string]: unknown;
323
+ };
324
+ /**
325
+ * The path to write the traces to. Only for file exporter.
326
+ */
327
+ path?: string;
211
328
  [k: string]: unknown;
212
329
  };
330
+ additionalProperties?: never;
213
331
  [k: string]: unknown;
214
332
  };
215
- additionalProperties?: never;
216
- [k: string]: unknown;
217
- };
218
- }
333
+ };
334
+ inspectorOptions?: {
335
+ host?: string;
336
+ port?: number;
337
+ breakFirstLine?: boolean;
338
+ watchDisabled?: boolean;
339
+ [k: string]: unknown;
340
+ };
341
+ applicationTimeout?: number | string;
342
+ messagingTimeout?: number | string;
343
+ resolvedApplicationsBasePath?: string;
344
+ env?: {
345
+ [k: string]: string;
346
+ };
347
+ sourceMaps?: boolean;
348
+ scheduler?: {
349
+ enabled?: boolean | string;
350
+ name: string;
351
+ cron: string;
352
+ callbackUrl: string;
353
+ method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
354
+ headers?: {
355
+ [k: string]: string;
356
+ };
357
+ body?:
358
+ | string
359
+ | {
360
+ [k: string]: unknown;
361
+ };
362
+ maxRetries?: number;
363
+ [k: string]: unknown;
364
+ }[];
365
+ };
package/eslint.config.js CHANGED
@@ -1,8 +1,6 @@
1
- 'use strict'
1
+ import neostandard from 'neostandard'
2
2
 
3
- const neostandard = require('neostandard')
4
-
5
- module.exports = neostandard({
3
+ export default neostandard({
6
4
  ts: true,
7
- ignores: [...neostandard.resolveIgnoresFromGitignore(), 'test/tmp/**/*', 'dist/**/*'],
5
+ ignores: [...neostandard.resolveIgnoresFromGitignore(), 'test/tmp/**/*', 'dist/**/*']
8
6
  })
package/index.d.ts CHANGED
@@ -1,37 +1,40 @@
1
- import { InjectOptions, LightMyRequestResponse } from 'fastify'
2
1
  import { FastifyError } from '@fastify/error'
3
- import { BaseLogger } from 'pino'
4
- import { RuntimeGenerator } from './lib/generator/runtime-generator'
5
- export type pltRuntimeBuildServer = {
6
- address: string
7
- port: number
8
- restart: () => Promise<void>
9
- stop: () => Promise<void>
10
- inject: (opts: InjectOptions | string) => Promise<LightMyRequestResponse>
2
+ import { Configuration, ConfigurationOptions, logFatalError, parseArgs } from '@platformatic/foundation'
3
+ import { BaseGenerator } from '@platformatic/generators'
4
+ import { JSONSchemaType } from 'ajv'
5
+ import * as colorette from 'colorette'
6
+ import { Logger } from 'pino'
7
+ import { PlatformaticRuntimeConfig } from './config'
8
+
9
+ export type RuntimeConfiguration = Promise<Configuration<PlatformaticRuntimeConfig>>
10
+
11
+ export type ApplicationCommandContext = {
12
+ colorette: typeof colorette
13
+ parseArgs: typeof parseArgs
14
+ logFatalError: typeof logFatalError
11
15
  }
12
16
 
13
- declare module '@platformatic/runtime' {
14
- export function buildServer (opts: object): Promise<pltRuntimeBuildServer>
15
- export function start (args: object): Promise<object>
16
- export function startCommand (args: object): Promise<void>
17
- export function loadConfig (minimistConfig: object, args: object, store: object, overrides: object, replaceEnv: boolean): void
18
- export function compile (argv: string[], logger: BaseLogger): void
19
- export function platformaticRuntime (): Promise<void>
20
- export function wrapConfigInRuntimeConfig (args: object): object
21
- export const Generator: RuntimeGenerator.RuntimeGenerator
17
+ export type ApplicationCommand = (
18
+ logger: Logger,
19
+ configuration: Configuration<unknown>,
20
+ args: string[],
21
+ context: ApplicationCommandContext
22
+ ) => Promise<void>
23
+
24
+ export interface ApplicationsCommands {
25
+ applications: Record<string, Configuration<unknown>>
26
+ commands: Record<string, ApplicationCommand>
27
+ help: Record<string, string | (() => string)>
22
28
  }
23
29
 
24
- /**
25
- * All the errors thrown by the plugin.
26
- */
27
30
  export module errors {
28
31
  export const RuntimeExitedError: () => FastifyError
29
32
  export const UnknownRuntimeAPICommandError: (command: string) => FastifyError
30
- export const ServiceNotFoundError: (id: string) => FastifyError
31
- export const ServiceNotStartedError: (id: string) => FastifyError
33
+ export const ApplicationNotFoundError: (id: string) => FastifyError
34
+ export const ApplicationNotStartedError: (id: string) => FastifyError
32
35
  export const FailedToRetrieveOpenAPISchemaError: (id: string, error: string) => FastifyError
33
36
  export const ApplicationAlreadyStartedError: () => FastifyError
34
- export const ApplicationNotStartedError: () => FastifyError
37
+ export const RuntimeNotStartedError: () => FastifyError
35
38
  export const ConfigPathMustBeStringError: () => FastifyError
36
39
  export const NoConfigFileFoundError: (id: string) => FastifyError
37
40
  export const InvalidEntrypointError: (entrypoint: string) => FastifyError
@@ -43,3 +46,49 @@ export module errors {
43
46
  export const CannotMapSpecifierToAbsolutePathError: (specifier: string) => FastifyError
44
47
  export const NodeInspectorFlagsNotSupportedError: () => FastifyError
45
48
  }
49
+
50
+ export module symbols {
51
+ export declare const kConfig: unique symbol
52
+ export declare const kId: unique symbol
53
+ export declare const kFullId: unique symbol
54
+ export declare const kApplicationId: unique symbol
55
+ export declare const kWorkerId: unique symbol
56
+ export declare const kITC: unique symbol
57
+ export declare const kHealthCheckTimer: unique symbol
58
+ export declare const kLastELU: unique symbol
59
+ export declare const kWorkerStatus: unique symbol
60
+ export declare const kStderrMarker: string
61
+ export declare const kInterceptors: unique symbol
62
+ export declare const kWorkersBroadcast: unique symbol
63
+ }
64
+
65
+ export class Generator extends BaseGenerator {}
66
+
67
+ export class WrappedGenerator extends BaseGenerator {}
68
+
69
+ export declare const schema: JSONSchemaType<PlatformaticRuntimeConfig>
70
+
71
+ export declare class Runtime {}
72
+
73
+ export function wrapInRuntimeConfig (
74
+ config: Configuration<unknown>,
75
+ context?: ConfigurationOptions
76
+ ): Promise<RuntimeConfiguration>
77
+
78
+ export declare const version: string
79
+
80
+ export declare function loadConfiguration (
81
+ root: string | PlatformaticRuntimeConfig,
82
+ source?: string | PlatformaticRuntimeConfig,
83
+ context?: ConfigurationOptions
84
+ ): Promise<RuntimeConfiguration>
85
+
86
+ export function create (
87
+ root: string,
88
+ source?: string | PlatformaticRuntimeConfig,
89
+ context?: ConfigurationOptions
90
+ ): Promise<Runtime>
91
+
92
+ export declare function transform (config: RuntimeConfiguration): Promise<RuntimeConfiguration>
93
+
94
+ export declare function loadApplicationsCommands (): Promise<ApplicationsCommands>