@platformatic/runtime 1.53.3 → 2.0.0-alpha.10

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 (178) hide show
  1. package/config.d.ts +284 -0
  2. package/eslint.config.js +8 -0
  3. package/fixtures/botched-start/platformatic.runtime.json +1 -1
  4. package/fixtures/botched-start/services/a/platformatic.service.json +1 -1
  5. package/fixtures/composerApp/platformatic.composer.json +1 -1
  6. package/fixtures/configs/{monorepo-hotreload.json → invalid-autoload-with-services.json} +8 -8
  7. package/fixtures/configs/invalid-entrypoint.json +1 -1
  8. package/fixtures/configs/invalid-schema-type.config.json +1 -1
  9. package/fixtures/configs/missing-property.config.json +1 -1
  10. package/fixtures/configs/missing-service-config.json +1 -1
  11. package/fixtures/configs/monorepo-composer-no-autoload.json +32 -0
  12. package/fixtures/configs/monorepo-composer.json +2 -2
  13. package/fixtures/configs/monorepo-create-cycle.json +2 -3
  14. package/fixtures/configs/monorepo-missing-dependencies.json +9 -0
  15. package/fixtures/configs/monorepo-no-cycles.json +2 -3
  16. package/fixtures/configs/monorepo-openapi.json +2 -2
  17. package/fixtures/configs/{hotreload.json → monorepo-watch-env.json} +2 -3
  18. package/fixtures/configs/monorepo-watch-single.json +12 -0
  19. package/fixtures/configs/monorepo-watch.json +26 -9
  20. package/fixtures/configs/monorepo-with-dependencies.json +2 -2
  21. package/fixtures/configs/{monorepo-client-without-id.json → monorepo-with-management-api-without-metrics.json} +5 -8
  22. package/fixtures/configs/monorepo-with-management-api.json +2 -3
  23. package/fixtures/configs/monorepo-with-metrics.json +1 -2
  24. package/fixtures/configs/monorepo.json +2 -3
  25. package/fixtures/configs/no-services.config.json +1 -1
  26. package/fixtures/configs/no-sources.config.json +1 -1
  27. package/fixtures/configs/service-throws-on-start.json +1 -1
  28. package/fixtures/configs/service-with-env-port.json +2 -3
  29. package/fixtures/configs/service-with-stdio.json +12 -0
  30. package/fixtures/configs/{monorepo-hotreload-env.json → watch.json} +2 -3
  31. package/fixtures/crash-on-bootstrap/platformatic.runtime.json +15 -0
  32. package/fixtures/crash-on-bootstrap/services/service-1/platformatic.service.json +14 -0
  33. package/fixtures/crash-on-bootstrap/services/service-1/plugin.js +5 -0
  34. package/fixtures/crash-on-bootstrap/services/service-2/platformatic.service.json +14 -0
  35. package/fixtures/crash-on-bootstrap/services/service-2/plugin.js +5 -0
  36. package/fixtures/dbApp/platformatic.db.json +1 -1
  37. package/fixtures/dbAppNoName/platformatic.db.json +1 -1
  38. package/fixtures/dbAppNoPackageJson/platformatic.db.json +1 -1
  39. package/fixtures/dbAppWithMigrationError/platformatic.db.json +1 -1
  40. package/fixtures/do-not-reload-dependencies/platformatic.service.json +1 -1
  41. package/fixtures/do-not-restart-on-crash/platformatic.runtime.json +3 -2
  42. package/fixtures/do-not-restart-on-crash/services/a/platformatic.service.json +1 -1
  43. package/fixtures/express/platformatic.runtime.json +1 -1
  44. package/fixtures/express/services/a/platformatic.service.json +1 -1
  45. package/fixtures/express/services/b/platformatic.service.json +1 -1
  46. package/fixtures/external-client/platformatic.service.json +1 -1
  47. package/fixtures/interceptors/idp.js +2 -2
  48. package/fixtures/interceptors/platformatic.runtime.json +1 -1
  49. package/fixtures/interceptors/services/a/platformatic.service.json +1 -1
  50. package/fixtures/interceptors-2/platformatic.runtime.json +1 -1
  51. package/fixtures/interceptors-2/services/a/platformatic.service.json +1 -1
  52. package/fixtures/leven/platformatic.runtime.json +2 -3
  53. package/fixtures/leven/services/deeply-spittle/platformatic.service.json +1 -1
  54. package/fixtures/leven/services/rainy-empire/platformatic.composer.json +1 -1
  55. package/fixtures/management-api/platformatic.json +8 -4
  56. package/fixtures/management-api/services/service-1/platformatic.json +1 -1
  57. package/fixtures/management-api/services/service-1/plugin.js +4 -3
  58. package/fixtures/management-api/services/service-2/platformatic.json +1 -1
  59. package/fixtures/management-api/services/service-db/platformatic.db.json +1 -1
  60. package/fixtures/management-api-custom-labels/platformatic.json +2 -3
  61. package/fixtures/management-api-custom-labels/services/service-1/platformatic.json +1 -1
  62. package/fixtures/management-api-custom-labels/services/service-1/plugin.js +4 -3
  63. package/fixtures/management-api-custom-labels/services/service-2/platformatic.json +1 -1
  64. package/fixtures/management-api-custom-labels/services/service-db/platformatic.db.json +1 -1
  65. package/fixtures/management-api-without-metrics/platformatic.json +3 -3
  66. package/fixtures/management-api-without-metrics/services/service-1/platformatic.json +1 -1
  67. package/fixtures/monorepo/composerApp/platformatic.composer.json +1 -2
  68. package/fixtures/monorepo/dbApp/platformatic.db.json +1 -1
  69. package/fixtures/monorepo/serviceApp/platformatic.service.json +3 -2
  70. package/fixtures/monorepo/serviceApp/with-logger/with-logger.cjs +2 -2
  71. package/fixtures/monorepo/serviceApp/with-logger/with-logger.d.ts +7 -7
  72. package/fixtures/monorepo/serviceAppWithLogger/platformatic.service.json +1 -1
  73. package/fixtures/monorepo/serviceAppWithLogger/plugin.js +12 -0
  74. package/fixtures/monorepo/serviceAppWithMultiplePlugins/platformatic.service.json +3 -2
  75. package/fixtures/monorepo-missing-dependencies/composer/platformatic.json +24 -0
  76. package/fixtures/monorepo-openapi/serviceAppWithoutOpenapi/platformatic.service.json +1 -1
  77. package/fixtures/monorepo-watch/service1/platformatic.service.json +1 -1
  78. package/fixtures/monorepo-with-dependencies/main/platformatic.json +1 -1
  79. package/fixtures/monorepo-with-dependencies/service-1/platformatic.json +1 -1
  80. package/fixtures/monorepo-with-dependencies/service-2/platformatic.json +1 -1
  81. package/fixtures/no-env.service.json +1 -1
  82. package/fixtures/preload/platformatic.runtime.json +1 -1
  83. package/fixtures/preload/services/a/platformatic.service.json +1 -1
  84. package/fixtures/prom-server/platformatic.json +2 -3
  85. package/fixtures/prom-server/services/service-1/platformatic.json +1 -1
  86. package/fixtures/prom-server/services/service-2/platformatic.json +1 -1
  87. package/fixtures/restart-on-crash/platformatic.runtime.json +1 -1
  88. package/fixtures/restart-on-crash/services/a/platformatic.service.json +1 -1
  89. package/fixtures/sample-runtime/package.json +1 -1
  90. package/fixtures/sample-runtime/platformatic.json +2 -3
  91. package/fixtures/sample-runtime/services/rival/package.json +1 -1
  92. package/fixtures/sample-runtime/services/rival/platformatic.json +1 -1
  93. package/fixtures/sample-runtime-with-2-services/package.json +1 -1
  94. package/fixtures/sample-runtime-with-2-services/platformatic.json +2 -3
  95. package/fixtures/sample-runtime-with-2-services/services/foobar/package.json +1 -1
  96. package/fixtures/sample-runtime-with-2-services/services/foobar/platformatic.json +1 -1
  97. package/fixtures/sample-runtime-with-2-services/services/rival/package.json +1 -1
  98. package/fixtures/sample-runtime-with-2-services/services/rival/platformatic.json +1 -1
  99. package/fixtures/server/logger-transport/platformatic.runtime.json +2 -3
  100. package/fixtures/server/logger-transport/services/echo/platformatic.service.json +1 -1
  101. package/fixtures/server/overrides-service/platformatic.runtime.json +2 -3
  102. package/fixtures/server/overrides-service/services/echo/platformatic.service.json +1 -1
  103. package/fixtures/server/runtime-server/platformatic.runtime.json +2 -3
  104. package/fixtures/server/runtime-server/services/echo/platformatic.service.json +1 -1
  105. package/fixtures/serviceAppThrowsOnStart/platformatic.service.json +1 -1
  106. package/fixtures/stackables/node_modules/foo/foo.js +2 -1
  107. package/fixtures/start-command-in-runtime.js +1 -1
  108. package/fixtures/stdio/platformatic.service.json +6 -0
  109. package/fixtures/stdio/plugin.js +24 -0
  110. package/fixtures/telemetry/platformatic.runtime.json +2 -3
  111. package/fixtures/telemetry/services/echo/platformatic.service.json +1 -1
  112. package/fixtures/telemetry/services/echo/routes/span.js +16 -2
  113. package/fixtures/telemetry/services/service-1/platformatic.service.json +19 -0
  114. package/fixtures/telemetry/services/service-1/routes/echo.js +7 -0
  115. package/fixtures/typescript/platformatic.runtime.json +2 -3
  116. package/fixtures/typescript/services/composer/platformatic.composer.json +1 -1
  117. package/fixtures/typescript/services/movies/global.d.ts +2 -3
  118. package/fixtures/typescript/services/movies/platformatic.db.json +1 -1
  119. package/fixtures/typescript/services/movies/types/Movie.d.ts +3 -3
  120. package/fixtures/typescript/services/movies/types/index.d.ts +6 -6
  121. package/fixtures/typescript/services/titles/client/client.d.ts +35 -35
  122. package/fixtures/typescript/services/titles/platformatic.service.json +1 -1
  123. package/fixtures/typescript-custom-flags/platformatic.runtime.json +2 -3
  124. package/fixtures/typescript-custom-flags/services/composer/platformatic.composer.json +1 -1
  125. package/fixtures/typescript-custom-flags/services/movies/global.d.ts +2 -3
  126. package/fixtures/typescript-custom-flags/services/movies/platformatic.db.json +1 -1
  127. package/fixtures/typescript-custom-flags/services/movies/types/Movie.d.ts +3 -3
  128. package/fixtures/typescript-custom-flags/services/movies/types/index.d.ts +6 -6
  129. package/fixtures/typescript-custom-flags/services/titles/client/client.d.ts +35 -35
  130. package/fixtures/typescript-custom-flags/services/titles/platformatic.service.json +1 -1
  131. package/fixtures/typescript-no-env/platformatic.runtime.json +2 -3
  132. package/fixtures/typescript-no-env/services/composer/platformatic.composer.json +1 -1
  133. package/fixtures/typescript-no-env/services/movies/global.d.ts +2 -3
  134. package/fixtures/typescript-no-env/services/movies/platformatic.db.json +1 -1
  135. package/fixtures/typescript-no-env/services/movies/types/Movie.d.ts +3 -3
  136. package/fixtures/typescript-no-env/services/movies/types/index.d.ts +6 -6
  137. package/fixtures/typescript-no-env/services/titles/client/client.d.ts +35 -35
  138. package/fixtures/typescript-no-env/services/titles/platformatic.service.json +1 -1
  139. package/index.d.ts +7 -8
  140. package/index.js +15 -10
  141. package/index.test-d.ts +10 -12
  142. package/lib/build-server.js +23 -15
  143. package/lib/compile.js +56 -13
  144. package/lib/config.js +27 -139
  145. package/lib/dependencies.js +59 -0
  146. package/lib/errors.js +6 -2
  147. package/lib/generator/errors.js +1 -1
  148. package/lib/generator/runtime-generator.d.ts +15 -15
  149. package/lib/generator/runtime-generator.js +81 -66
  150. package/lib/logger.js +55 -0
  151. package/lib/management-api.js +29 -44
  152. package/lib/prom-server.js +5 -9
  153. package/lib/runtime.js +1005 -0
  154. package/lib/schema.js +46 -44
  155. package/lib/start.js +49 -117
  156. package/lib/upgrade.js +4 -3
  157. package/lib/utils.js +49 -1
  158. package/lib/versions/v1.36.0.js +1 -1
  159. package/lib/versions/v1.5.0.js +1 -1
  160. package/lib/versions/v2.0.0.js +17 -0
  161. package/lib/worker/app.js +266 -0
  162. package/lib/worker/default-stackable.js +32 -0
  163. package/lib/worker/itc.js +149 -0
  164. package/lib/worker/main.js +129 -0
  165. package/lib/worker/metrics.js +106 -0
  166. package/lib/worker/symbols.js +7 -0
  167. package/package.json +44 -44
  168. package/runtime.mjs +11 -6
  169. package/schema.json +25 -13
  170. package/fixtures/monorepo/serviceApp/platformatic.service-client-without-id.json +0 -21
  171. package/lib/api-client.js +0 -497
  172. package/lib/api.js +0 -397
  173. package/lib/app.js +0 -365
  174. package/lib/load-config.js +0 -20
  175. package/lib/loader.mjs +0 -103
  176. package/lib/message-port-writable.js +0 -50
  177. package/lib/worker.js +0 -182
  178. /package/lib/{interceptors.js → worker/interceptors.js} +0 -0
@@ -1,10 +1,10 @@
1
1
  import { FastifyPluginAsync } from 'fastify'
2
2
 
3
3
  interface GetMoviesRequest {
4
- 'limit'?: number;
5
- 'offset'?: number;
6
- 'totalCount'?: boolean;
7
- 'fields'?: Array<string>;
4
+ limit?: number;
5
+ offset?: number;
6
+ totalCount?: boolean;
7
+ fields?: Array<string>;
8
8
  'where.id.eq'?: number;
9
9
  'where.id.neq'?: number;
10
10
  'where.id.gt'?: number;
@@ -29,22 +29,22 @@ interface GetMoviesRequest {
29
29
  }
30
30
 
31
31
  interface GetMoviesResponseOK {
32
- 'id'?: number;
33
- 'title': string;
32
+ id?: number;
33
+ title: string;
34
34
  }
35
35
 
36
36
  interface CreateMovieRequest {
37
- 'id'?: number;
38
- 'title': string;
37
+ id?: number;
38
+ title: string;
39
39
  }
40
40
 
41
41
  interface CreateMovieResponseOK {
42
- 'id'?: number;
43
- 'title': string;
42
+ id?: number;
43
+ title: string;
44
44
  }
45
45
 
46
46
  interface UpdateMoviesRequest {
47
- 'fields'?: Array<string>;
47
+ fields?: Array<string>;
48
48
  'where.id.eq'?: number;
49
49
  'where.id.neq'?: number;
50
50
  'where.id.gt'?: number;
@@ -64,44 +64,44 @@ interface UpdateMoviesRequest {
64
64
  'where.title.in'?: string;
65
65
  'where.title.nin'?: string;
66
66
  'where.or'?: Array<string>;
67
- 'id'?: number;
68
- 'title': string;
67
+ id?: number;
68
+ title: string;
69
69
  }
70
70
 
71
71
  interface UpdateMoviesResponseOK {
72
- 'id'?: number;
73
- 'title': string;
72
+ id?: number;
73
+ title: string;
74
74
  }
75
75
 
76
76
  interface GetMovieByIdRequest {
77
- 'fields'?: Array<string>;
78
- 'id': number;
77
+ fields?: Array<string>;
78
+ id: number;
79
79
  }
80
80
 
81
81
  interface GetMovieByIdResponseOK {
82
- 'id'?: number;
83
- 'title': string;
82
+ id?: number;
83
+ title: string;
84
84
  }
85
85
 
86
86
  interface UpdateMovieRequest {
87
- 'fields'?: Array<string>;
88
- 'id': number;
89
- 'title': string;
87
+ fields?: Array<string>;
88
+ id: number;
89
+ title: string;
90
90
  }
91
91
 
92
92
  interface UpdateMovieResponseOK {
93
- 'id'?: number;
94
- 'title': string;
93
+ id?: number;
94
+ title: string;
95
95
  }
96
96
 
97
97
  interface DeleteMoviesRequest {
98
- 'fields'?: Array<string>;
99
- 'id': number;
98
+ fields?: Array<string>;
99
+ id: number;
100
100
  }
101
101
 
102
102
  interface DeleteMoviesResponseOK {
103
- 'id'?: number;
104
- 'title': string;
103
+ id?: number;
104
+ title: string;
105
105
  }
106
106
 
107
107
  interface Client {
@@ -117,15 +117,15 @@ type ClientPlugin = FastifyPluginAsync<NonNullable<client.ClientOptions>>
117
117
 
118
118
  declare module 'fastify' {
119
119
  interface ConfigureClient {
120
- getHeaders(req: FastifyRequest, reply: FastifyReply): Promise<Record<string,string>>;
120
+ getHeaders(req: FastifyRequest, reply: FastifyReply): Promise<Record<string, string>>;
121
121
  }
122
122
  interface FastifyInstance {
123
- 'client': Client;
123
+ client: Client;
124
124
  configureClient(opts: ConfigureClient): unknown
125
125
  }
126
126
 
127
127
  interface FastifyRequest {
128
- 'client': Client;
128
+ client: Client;
129
129
  }
130
130
  }
131
131
 
@@ -133,9 +133,9 @@ declare namespace client {
133
133
  export interface ClientOptions {
134
134
  url: string
135
135
  }
136
- export const client: ClientPlugin;
137
- export { client as default };
136
+ export const client: ClientPlugin
137
+ export { client as default }
138
138
  }
139
139
 
140
- declare function client(...params: Parameters<ClientPlugin>): ReturnType<ClientPlugin>;
141
- export = client;
140
+ declare function client (...params: Parameters<ClientPlugin>): ReturnType<ClientPlugin>
141
+ export = client
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://platformatic.dev/schemas/v0.30.0/service",
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/service/1.52.0.json",
3
3
  "server": {
4
4
  "hostname": "{PLT_SERVER_HOSTNAME}",
5
5
  "port": "{PORT}",
@@ -1,8 +1,7 @@
1
1
  {
2
- "$schema": "https://platformatic.dev/schemas/v0.28.1/runtime",
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
3
  "entrypoint": "composer",
4
- "allowCycles": false,
5
- "hotReload": true,
4
+ "watch": true,
6
5
  "autoload": {
7
6
  "path": "services",
8
7
  "exclude": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://platformatic.dev/schemas/v0.28.1/composer",
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/composer/1.52.0.json",
3
3
  "server": {
4
4
  "hostname": "{PLT_SERVER_HOSTNAME}",
5
5
  "port": "{PORT}",
@@ -1,11 +1,10 @@
1
- import { Entity } from '@platformatic/sql-mapper';
2
- import graphqlPlugin from '@platformatic/sql-graphql'
1
+ import { Entity } from '@platformatic/sql-mapper'
3
2
  import { EntityTypes, Movie } from './types'
4
3
 
5
4
  declare module 'fastify' {
6
5
  interface FastifyInstance {
7
6
  getSchema<T extends 'Movie'>(schemaId: T): {
8
- '$id': string,
7
+ $id: string,
9
8
  title: string,
10
9
  description: string,
11
10
  type: string,
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://platformatic.dev/schemas/v0.28.1/db",
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/db/1.52.0.json",
3
3
  "server": {
4
4
  "hostname": "{PLT_SERVER_HOSTNAME}",
5
5
  "port": "{PORT}",
@@ -3,7 +3,7 @@
3
3
  * A Movie
4
4
  */
5
5
  declare interface Movie {
6
- id?: number;
7
- title: string;
6
+ id?: number;
7
+ title: string;
8
8
  }
9
- export { Movie };
9
+ export { Movie }
@@ -1,7 +1,7 @@
1
1
  import { Movie } from './Movie'
2
-
3
- interface EntityTypes {
4
- Movie:Movie
5
- }
6
-
7
- export { EntityTypes ,Movie }
2
+
3
+ interface EntityTypes {
4
+ Movie: Movie
5
+ }
6
+
7
+ export { EntityTypes, Movie }
@@ -1,10 +1,10 @@
1
1
  import { FastifyPluginAsync } from 'fastify'
2
2
 
3
3
  interface GetMoviesRequest {
4
- 'limit'?: number;
5
- 'offset'?: number;
6
- 'totalCount'?: boolean;
7
- 'fields'?: Array<string>;
4
+ limit?: number;
5
+ offset?: number;
6
+ totalCount?: boolean;
7
+ fields?: Array<string>;
8
8
  'where.id.eq'?: number;
9
9
  'where.id.neq'?: number;
10
10
  'where.id.gt'?: number;
@@ -29,22 +29,22 @@ interface GetMoviesRequest {
29
29
  }
30
30
 
31
31
  interface GetMoviesResponseOK {
32
- 'id'?: number;
33
- 'title': string;
32
+ id?: number;
33
+ title: string;
34
34
  }
35
35
 
36
36
  interface CreateMovieRequest {
37
- 'id'?: number;
38
- 'title': string;
37
+ id?: number;
38
+ title: string;
39
39
  }
40
40
 
41
41
  interface CreateMovieResponseOK {
42
- 'id'?: number;
43
- 'title': string;
42
+ id?: number;
43
+ title: string;
44
44
  }
45
45
 
46
46
  interface UpdateMoviesRequest {
47
- 'fields'?: Array<string>;
47
+ fields?: Array<string>;
48
48
  'where.id.eq'?: number;
49
49
  'where.id.neq'?: number;
50
50
  'where.id.gt'?: number;
@@ -64,44 +64,44 @@ interface UpdateMoviesRequest {
64
64
  'where.title.in'?: string;
65
65
  'where.title.nin'?: string;
66
66
  'where.or'?: Array<string>;
67
- 'id'?: number;
68
- 'title': string;
67
+ id?: number;
68
+ title: string;
69
69
  }
70
70
 
71
71
  interface UpdateMoviesResponseOK {
72
- 'id'?: number;
73
- 'title': string;
72
+ id?: number;
73
+ title: string;
74
74
  }
75
75
 
76
76
  interface GetMovieByIdRequest {
77
- 'fields'?: Array<string>;
78
- 'id': number;
77
+ fields?: Array<string>;
78
+ id: number;
79
79
  }
80
80
 
81
81
  interface GetMovieByIdResponseOK {
82
- 'id'?: number;
83
- 'title': string;
82
+ id?: number;
83
+ title: string;
84
84
  }
85
85
 
86
86
  interface UpdateMovieRequest {
87
- 'fields'?: Array<string>;
88
- 'id': number;
89
- 'title': string;
87
+ fields?: Array<string>;
88
+ id: number;
89
+ title: string;
90
90
  }
91
91
 
92
92
  interface UpdateMovieResponseOK {
93
- 'id'?: number;
94
- 'title': string;
93
+ id?: number;
94
+ title: string;
95
95
  }
96
96
 
97
97
  interface DeleteMoviesRequest {
98
- 'fields'?: Array<string>;
99
- 'id': number;
98
+ fields?: Array<string>;
99
+ id: number;
100
100
  }
101
101
 
102
102
  interface DeleteMoviesResponseOK {
103
- 'id'?: number;
104
- 'title': string;
103
+ id?: number;
104
+ title: string;
105
105
  }
106
106
 
107
107
  interface Client {
@@ -117,15 +117,15 @@ type ClientPlugin = FastifyPluginAsync<NonNullable<client.ClientOptions>>
117
117
 
118
118
  declare module 'fastify' {
119
119
  interface ConfigureClient {
120
- getHeaders(req: FastifyRequest, reply: FastifyReply): Promise<Record<string,string>>;
120
+ getHeaders(req: FastifyRequest, reply: FastifyReply): Promise<Record<string, string>>;
121
121
  }
122
122
  interface FastifyInstance {
123
- 'client': Client;
123
+ client: Client;
124
124
  configureClient(opts: ConfigureClient): unknown
125
125
  }
126
126
 
127
127
  interface FastifyRequest {
128
- 'client': Client;
128
+ client: Client;
129
129
  }
130
130
  }
131
131
 
@@ -133,9 +133,9 @@ declare namespace client {
133
133
  export interface ClientOptions {
134
134
  url: string
135
135
  }
136
- export const client: ClientPlugin;
137
- export { client as default };
136
+ export const client: ClientPlugin
137
+ export { client as default }
138
138
  }
139
139
 
140
- declare function client(...params: Parameters<ClientPlugin>): ReturnType<ClientPlugin>;
141
- export = client;
140
+ declare function client (...params: Parameters<ClientPlugin>): ReturnType<ClientPlugin>
141
+ export = client
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://platformatic.dev/schemas/v0.28.1/service",
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/service/1.52.0.json",
3
3
  "server": {
4
4
  "hostname": "{PLT_SERVER_HOSTNAME}",
5
5
  "port": "{PORT}",
package/index.d.ts CHANGED
@@ -11,13 +11,13 @@ export type pltRuntimeBuildServer = {
11
11
  }
12
12
 
13
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
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
21
  export const Generator: RuntimeGenerator.RuntimeGenerator
22
22
  }
23
23
 
@@ -42,4 +42,3 @@ export module errors {
42
42
  export const CannotMapSpecifierToAbsolutePathError: (specifier: string) => FastifyError
43
43
  export const NodeInspectorFlagsNotSupportedError: () => FastifyError
44
44
  }
45
-
package/index.js CHANGED
@@ -1,21 +1,26 @@
1
1
  'use strict'
2
+
2
3
  const { buildServer } = require('./lib/build-server')
3
- const { platformaticRuntime, wrapConfigInRuntimeConfig } = require('./lib/config')
4
- const { start, startCommand } = require('./lib/start')
5
- const RuntimeApi = require('./lib/api')
6
4
  const { compile } = require('./lib/compile')
7
- const { loadConfig } = require('./lib/load-config')
8
5
  const errors = require('./lib/errors')
6
+ const { platformaticRuntime, wrapConfigInRuntimeConfig } = require('./lib/config')
9
7
  const RuntimeGenerator = require('./lib/generator/runtime-generator')
8
+ const { Runtime } = require('./lib/runtime')
9
+ const { buildRuntime, start, startCommand } = require('./lib/start')
10
+ const symbols = require('./lib/worker/symbols')
11
+ const { loadConfig, getRuntimeLogsDir } = require('./lib/utils')
10
12
 
11
13
  module.exports.buildServer = buildServer
14
+ module.exports.buildRuntime = buildRuntime
15
+ module.exports.compile = compile
16
+ module.exports.errors = errors
17
+ module.exports.Generator = RuntimeGenerator
18
+ module.exports.getRuntimeLogsDir = getRuntimeLogsDir
19
+ module.exports.loadConfig = loadConfig
12
20
  module.exports.platformaticRuntime = platformaticRuntime
13
- module.exports.wrapConfigInRuntimeConfig = wrapConfigInRuntimeConfig
14
21
  module.exports.schema = platformaticRuntime.schema
15
- module.exports.RuntimeApi = RuntimeApi
16
22
  module.exports.start = start
17
23
  module.exports.startCommand = startCommand
18
- module.exports.compile = compile
19
- module.exports.loadConfig = loadConfig
20
- module.exports.errors = errors
21
- module.exports.Generator = RuntimeGenerator
24
+ module.exports.symbols = symbols
25
+ module.exports.Runtime = Runtime
26
+ module.exports.wrapConfigInRuntimeConfig = wrapConfigInRuntimeConfig
package/index.test-d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { expectError, expectType } from 'tsd';
2
- import { LightMyRequestResponse } from 'fastify';
3
- import { pltRuntimeBuildServer, errors } from '.';
1
+ import { expectError, expectType } from 'tsd'
2
+ import { LightMyRequestResponse } from 'fastify'
3
+ import { pltRuntimeBuildServer, errors } from '.'
4
4
  import { FastifyError } from '@fastify/error'
5
5
 
6
6
  const server: pltRuntimeBuildServer = {
@@ -9,19 +9,18 @@ const server: pltRuntimeBuildServer = {
9
9
  restart: async () => { },
10
10
  stop: async () => { },
11
11
  inject: async () => ({} as LightMyRequestResponse),
12
- };
12
+ }
13
13
 
14
- expectType<pltRuntimeBuildServer>(server);
15
- expectError<pltRuntimeBuildServer>({ ...server, address: 42 });
16
- expectError<pltRuntimeBuildServer>({ ...server, port: 'WRONG' });
17
- expectError<pltRuntimeBuildServer>({ ...server, restart: 'WRONG' });
18
- expectError<pltRuntimeBuildServer>({ ...server, stop: 'WRONG' });
19
- expectError<pltRuntimeBuildServer>({ ...server, inject: 'WRONG' });
14
+ expectType<pltRuntimeBuildServer>(server)
15
+ expectError<pltRuntimeBuildServer>({ ...server, address: 42 })
16
+ expectError<pltRuntimeBuildServer>({ ...server, port: 'WRONG' })
17
+ expectError<pltRuntimeBuildServer>({ ...server, restart: 'WRONG' })
18
+ expectError<pltRuntimeBuildServer>({ ...server, stop: 'WRONG' })
19
+ expectError<pltRuntimeBuildServer>({ ...server, inject: 'WRONG' })
20
20
 
21
21
  // Errors
22
22
  type ErrorWithNoParams = () => FastifyError
23
23
  type ErrorWithOneParam = (param: string) => FastifyError
24
- type ErrorWithOneAnyParam = (param: string) => FastifyError
25
24
  type ErrorWithTwoParams = (param1: string, param2: string) => FastifyError
26
25
 
27
26
  expectType<ErrorWithNoParams>(errors.RuntimeExitedError)
@@ -40,4 +39,3 @@ expectType<ErrorWithNoParams>(errors.InspectorPortError)
40
39
  expectType<ErrorWithNoParams>(errors.InspectorHostError)
41
40
  expectType<ErrorWithOneParam>(errors.CannotMapSpecifierToAbsolutePathError)
42
41
  expectType<ErrorWithNoParams>(errors.NodeInspectorFlagsNotSupportedError)
43
-
@@ -1,22 +1,19 @@
1
1
  'use strict'
2
2
 
3
+ const { createRequire } = require('node:module')
4
+ const { join } = require('node:path')
5
+
3
6
  const ConfigManager = require('@platformatic/config')
7
+
4
8
  const { platformaticRuntime } = require('./config')
5
9
  const { buildRuntime } = require('./start')
6
- const { buildServer: buildServerService } = require('@platformatic/service')
7
- const { loadConfig } = require('./load-config')
10
+ const { loadConfig } = require('./utils')
8
11
 
9
- async function buildServerRuntime (options = {}) {
10
- const {
11
- serviceMap,
12
- loggingPort,
13
- loggingMetadata
14
- } = options
12
+ async function buildServerRuntime (options = {}, args = undefined) {
13
+ const { serviceMap } = options
15
14
 
16
15
  if (!options.configManager) {
17
16
  delete options.serviceMap
18
- delete options.loggingPort
19
- delete options.loggingMetadata
20
17
 
21
18
  // Instantiate a new config manager from the current options.
22
19
  const cm = new ConfigManager({
@@ -25,8 +22,6 @@ async function buildServerRuntime (options = {}) {
25
22
  })
26
23
  await cm.parseAndValidate()
27
24
 
28
- cm.current.loggingPort = loggingPort
29
- cm.current.loggingMetadata = loggingMetadata
30
25
  cm.current.serviceMap = serviceMap
31
26
 
32
27
  if (typeof options === 'string') {
@@ -36,10 +31,14 @@ async function buildServerRuntime (options = {}) {
36
31
  }
37
32
  }
38
33
 
34
+ if (args) {
35
+ options.configManager.args = args
36
+ }
37
+
39
38
  return buildRuntime(options.configManager, options.env)
40
39
  }
41
40
 
42
- async function buildServer (options) {
41
+ async function buildServer (options, args) {
43
42
  if (typeof options === 'string') {
44
43
  const config = await loadConfig({}, ['-c', options])
45
44
  options = config.configManager.current
@@ -52,10 +51,19 @@ async function buildServer (options) {
52
51
  delete options.app
53
52
 
54
53
  if (app === platformaticRuntime || !app) {
55
- return buildServerRuntime(options)
54
+ return buildServerRuntime(options, args)
56
55
  }
57
56
 
58
- return buildServerService(options, app)
57
+ if (app.buildServer) {
58
+ return app.buildServer(options)
59
+ }
60
+
61
+ // App is a stackable. Hopefully we have `@platformatic/service` available.
62
+ const projectRoot = join(options.configManager.dirname, 'package.json')
63
+ const require = createRequire(projectRoot)
64
+ const { buildServer } = require('@platformatic/service')
65
+
66
+ return buildServer(options, app)
59
67
  }
60
68
 
61
69
  module.exports = { buildServer }
package/lib/compile.js CHANGED
@@ -1,16 +1,19 @@
1
1
  'use strict'
2
2
 
3
- const { tsCompiler } = require('@platformatic/service')
4
- const { loadConfig } = require('./load-config')
5
- const { dirname } = require('node:path')
3
+ const { createRequire } = require('node:module')
4
+ const { dirname, join } = require('node:path')
5
+ const { isatty } = require('node:tty')
6
+ const { pathToFileURL } = require('node:url')
6
7
 
8
+ const tsCompiler = require('@platformatic/ts-compiler')
7
9
  const pino = require('pino')
8
10
  const pretty = require('pino-pretty')
9
- const { isatty } = require('node:tty')
11
+
12
+ const { loadConfig } = require('./utils')
10
13
 
11
14
  async function compile (argv, logger) {
12
- const { configManager, configType } = await loadConfig({}, argv, {
13
- watch: false
15
+ const { configManager, configType, app } = await loadConfig({}, argv, {
16
+ watch: false,
14
17
  }, false)
15
18
  /* c8 ignore next */
16
19
  if (!logger) {
@@ -19,7 +22,7 @@ async function compile (argv, logger) {
19
22
  if (isatty(process.stdout.fd)) {
20
23
  stream = pretty({
21
24
  translateTime: 'SYS:HH:MM:ss',
22
- ignore: 'hostname,pid'
25
+ ignore: 'hostname,pid',
23
26
  })
24
27
  }
25
28
 
@@ -28,28 +31,68 @@ async function compile (argv, logger) {
28
31
 
29
32
  let compiled = false
30
33
  const compileOptions = {
31
- clean: argv.includes('--clean')
34
+ clean: argv.includes('--clean'),
32
35
  }
33
36
  if (configType === 'runtime') {
34
37
  for (const service of configManager.current.services) {
35
38
  const childLogger = logger.child({ name: service.id })
36
39
 
37
40
  const serviceConfigPath = service.config
38
- const { configManager } = await loadConfig({}, ['-c', serviceConfigPath], {
41
+ const { configManager, app } = await loadConfig({}, ['-c', serviceConfigPath], {
39
42
  onMissingEnv (key) {
40
43
  return service.localServiceEnvVars.get(key)
41
44
  },
42
- watch: false
45
+ watch: false,
43
46
  }, false)
44
47
 
45
- const serviceWasCompiled = await tsCompiler.compile(service.path, configManager.current, childLogger, compileOptions)
46
- compiled ||= serviceWasCompiled
48
+ const tsOptions = await extract(configManager, app)
49
+
50
+ if (tsOptions) {
51
+ const serviceWasCompiled = await tsCompiler.compile({
52
+ ...compileOptions,
53
+ ...tsOptions,
54
+ cwd: service.path,
55
+ logger: childLogger,
56
+ })
57
+ compiled ||= serviceWasCompiled
58
+ }
47
59
  }
48
60
  } else {
49
- compiled = await tsCompiler.compile(dirname(configManager.fullPath), configManager.current, logger, compileOptions)
61
+ const tsOptions = await extract(configManager, app)
62
+ if (tsOptions) {
63
+ compiled = await tsCompiler.compile({
64
+ ...compileOptions,
65
+ ...tsOptions,
66
+ cwd: dirname(configManager.fullPath),
67
+ logger,
68
+ })
69
+ }
50
70
  }
51
71
 
52
72
  return compiled
53
73
  }
54
74
 
75
+ async function extract (configManager, app) {
76
+ let extractTypeScriptCompileOptionsFromConfig = app.extractTypeScriptCompileOptionsFromConfig
77
+
78
+ if (!extractTypeScriptCompileOptionsFromConfig) {
79
+ // This is a bit of a hack, but it is needed to avoid a circular dependency
80
+ // it also allow for customizations if needed
81
+ const _require = createRequire(join(configManager.dirname, 'package.json'))
82
+ const toLoad = _require.resolve('@platformatic/service')
83
+ try {
84
+ extractTypeScriptCompileOptionsFromConfig = (await import(pathToFileURL(toLoad))).extractTypeScriptCompileOptionsFromConfig
85
+ } catch {
86
+ }
87
+ // If we can't load `@platformatic/service` we just return null
88
+ // and we won't be compiling typescript
89
+ }
90
+
91
+ if (!extractTypeScriptCompileOptionsFromConfig) {
92
+ return null
93
+ }
94
+
95
+ return extractTypeScriptCompileOptionsFromConfig(configManager.current)
96
+ }
97
+
55
98
  module.exports.compile = compile