@platformatic/runtime 0.45.1 → 0.46.2

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.
@@ -0,0 +1,4 @@
1
+ PLT_SERVER_HOSTNAME=127.0.0.1
2
+ PORT=3001
3
+ PLT_SERVER_LOGGER_LEVEL=info
4
+ DATABASE_URL=sqlite://./db.sqlite
@@ -0,0 +1,4 @@
1
+ PLT_SERVER_HOSTNAME=127.0.0.1
2
+ PORT=3001
3
+ PLT_SERVER_LOGGER_LEVEL=info
4
+ DATABASE_URL=sqlite://./db.sqlite
@@ -26,7 +26,7 @@
26
26
  "plugin.ts"
27
27
  ],
28
28
  "typescript": {
29
- "flags": ["-b"]
29
+ "flags": ["--outDir", "custom"]
30
30
  }
31
31
  },
32
32
  "types": {
@@ -5,8 +5,7 @@
5
5
  "target": "es2019",
6
6
  "sourceMap": true,
7
7
  "pretty": true,
8
- "noEmitOnError": true,
9
- "outDir": "dist"
8
+ "noEmitOnError": true
10
9
  },
11
10
  "watchOptions": {
12
11
  "watchFile": "fixedPollingInterval",
package/lib/compile.js CHANGED
@@ -33,11 +33,15 @@ async function compile (argv, logger) {
33
33
  for (const service of configManager.current.services) {
34
34
  const childLogger = logger.child({ name: service.id })
35
35
 
36
- const serviceConfig = await loadConfig({}, argv, {
36
+ const serviceConfigPath = service.config
37
+ const { configManager } = await loadConfig({}, ['-c', serviceConfigPath], {
38
+ onMissingEnv (key) {
39
+ return service.localServiceEnvVars.get(key)
40
+ },
37
41
  watch: false
38
42
  })
39
43
 
40
- const serviceWasCompiled = await tsCompiler.compile(service.path, serviceConfig.config, childLogger)
44
+ const serviceWasCompiled = await tsCompiler.compile(service.path, configManager.current, childLogger)
41
45
  compiled ||= serviceWasCompiled
42
46
  }
43
47
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "0.45.1",
3
+ "version": "0.46.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -24,8 +24,8 @@
24
24
  "standard": "^17.1.0",
25
25
  "tsd": "^0.29.0",
26
26
  "typescript": "^5.1.6",
27
- "@platformatic/sql-graphql": "0.45.1",
28
- "@platformatic/sql-mapper": "0.45.1"
27
+ "@platformatic/sql-graphql": "0.46.2",
28
+ "@platformatic/sql-mapper": "0.46.2"
29
29
  },
30
30
  "dependencies": {
31
31
  "@hapi/topo": "^6.0.2",
@@ -43,12 +43,12 @@
43
43
  "pino": "^8.14.1",
44
44
  "pino-pretty": "^10.0.0",
45
45
  "undici": "^5.22.1",
46
- "@platformatic/config": "0.45.1",
47
- "@platformatic/db": "0.45.1",
48
- "@platformatic/composer": "0.45.1",
49
- "@platformatic/service": "0.45.1",
50
- "@platformatic/utils": "0.45.1",
51
- "@platformatic/telemetry": "0.45.1"
46
+ "@platformatic/composer": "0.46.2",
47
+ "@platformatic/config": "0.46.2",
48
+ "@platformatic/db": "0.46.2",
49
+ "@platformatic/service": "0.46.2",
50
+ "@platformatic/telemetry": "0.46.2",
51
+ "@platformatic/utils": "0.46.2"
52
52
  },
53
53
  "standard": {
54
54
  "ignore": [
package/test/api.test.js DELETED
@@ -1,356 +0,0 @@
1
- 'use strict'
2
-
3
- const assert = require('node:assert')
4
- const { join } = require('node:path')
5
- const { test } = require('node:test')
6
-
7
- const { loadConfig } = require('@platformatic/config')
8
- const { buildServer, platformaticRuntime } = require('..')
9
- const fixturesDir = join(__dirname, '..', 'fixtures')
10
-
11
- // Each test runtime app adds own process listeners
12
- process.setMaxListeners(100)
13
-
14
- test('should get service details', async (t) => {
15
- const configFile = join(fixturesDir, 'configs', 'monorepo.json')
16
- const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
17
- const app = await buildServer(config.configManager.current)
18
-
19
- await app.start()
20
-
21
- t.after(async () => {
22
- await app.close()
23
- })
24
-
25
- const serviceDetails = await app.getServiceDetails('with-logger')
26
- assert.deepStrictEqual(serviceDetails, {
27
- id: 'with-logger',
28
- status: 'started',
29
- entrypoint: false,
30
- localUrl: 'http://with-logger.plt.local',
31
- dependencies: []
32
- })
33
- })
34
-
35
- test('should get service config', async (t) => {
36
- const configFile = join(fixturesDir, 'configs', 'monorepo.json')
37
- const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
38
- const app = await buildServer(config.configManager.current)
39
-
40
- await app.start()
41
-
42
- t.after(async () => {
43
- await app.close()
44
- })
45
-
46
- const serviceConfig = await app.getServiceConfig('with-logger')
47
-
48
- delete serviceConfig.$schema
49
-
50
- // TODO: should return correct logger config
51
- assert.deepStrictEqual(serviceConfig, {
52
- server: {
53
- hostname: '127.0.0.1',
54
- port: 0,
55
- logger: {},
56
- keepAliveTimeout: 5000
57
- },
58
- service: { openapi: true },
59
- plugins: {
60
- paths: [
61
- join(fixturesDir, 'monorepo', 'serviceAppWithLogger', 'plugin.js')
62
- ]
63
- },
64
- watch: {
65
- enabled: false
66
- }
67
- })
68
- })
69
-
70
- test('should fail to get service config if service is not started', async (t) => {
71
- const configFile = join(fixturesDir, 'configs', 'monorepo.json')
72
- const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
73
- const app = await buildServer(config.configManager.current)
74
-
75
- t.after(async () => {
76
- await app.close()
77
- })
78
-
79
- try {
80
- await app.getServiceConfig('with-logger')
81
- assert.fail('should have thrown')
82
- } catch (err) {
83
- assert.strictEqual(err.message, 'Service with id \'with-logger\' is not started')
84
- }
85
- })
86
-
87
- test('should get services topology', async (t) => {
88
- const configFile = join(fixturesDir, 'configs', 'monorepo.json')
89
- const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
90
- const app = await buildServer(config.configManager.current)
91
-
92
- await app.start()
93
-
94
- t.after(async () => {
95
- await app.close()
96
- })
97
-
98
- const topology = await app.getServices()
99
-
100
- assert.deepStrictEqual(topology, {
101
- entrypoint: 'serviceApp',
102
- services: [
103
- {
104
- id: 'serviceApp',
105
- status: 'started',
106
- entrypoint: true,
107
- localUrl: 'http://serviceApp.plt.local',
108
- dependencies: [
109
- {
110
- id: 'with-logger',
111
- url: 'http://with-logger.plt.local',
112
- local: true
113
- }
114
- ]
115
- },
116
- {
117
- id: 'with-logger',
118
- status: 'started',
119
- entrypoint: false,
120
- localUrl: 'http://with-logger.plt.local',
121
- dependencies: []
122
- },
123
- {
124
- id: 'multi-plugin-service',
125
- status: 'started',
126
- entrypoint: false,
127
- localUrl: 'http://multi-plugin-service.plt.local',
128
- dependencies: []
129
- }
130
- ]
131
- })
132
- })
133
-
134
- test('should stop service by service id', async (t) => {
135
- const configFile = join(fixturesDir, 'configs', 'monorepo.json')
136
- const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
137
- const app = await buildServer(config.configManager.current)
138
-
139
- await app.start()
140
-
141
- t.after(async () => {
142
- await app.close()
143
- })
144
-
145
- {
146
- const serviceDetails = await app.getServiceDetails('with-logger')
147
- assert.strictEqual(serviceDetails.status, 'started')
148
- }
149
-
150
- await app.stopService('with-logger')
151
-
152
- {
153
- const serviceDetails = await app.getServiceDetails('with-logger')
154
- assert.strictEqual(serviceDetails.status, 'stopped')
155
- }
156
- })
157
-
158
- test('should fail to stop service with a wrong id', async (t) => {
159
- const configFile = join(fixturesDir, 'configs', 'monorepo.json')
160
- const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
161
- const app = await buildServer(config.configManager.current)
162
-
163
- t.after(async () => {
164
- await app.close()
165
- })
166
-
167
- try {
168
- await app.stopService('wrong-service-id')
169
- assert.fail('should have thrown')
170
- } catch (err) {
171
- assert.strictEqual(err.message, 'Service with id \'wrong-service-id\' not found')
172
- }
173
- })
174
-
175
- test('should start stopped service by service id', async (t) => {
176
- const configFile = join(fixturesDir, 'configs', 'monorepo.json')
177
- const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
178
- const app = await buildServer(config.configManager.current)
179
-
180
- await app.start()
181
-
182
- t.after(async () => {
183
- await app.close()
184
- })
185
-
186
- await app.stopService('with-logger')
187
-
188
- {
189
- const serviceDetails = await app.getServiceDetails('with-logger')
190
- assert.strictEqual(serviceDetails.status, 'stopped')
191
- }
192
-
193
- await app.startService('with-logger')
194
-
195
- {
196
- const serviceDetails = await app.getServiceDetails('with-logger')
197
- assert.strictEqual(serviceDetails.status, 'started')
198
- }
199
- })
200
-
201
- test('should fail to start service with a wrong id', async (t) => {
202
- const configFile = join(fixturesDir, 'configs', 'monorepo.json')
203
- const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
204
- const app = await buildServer(config.configManager.current)
205
-
206
- t.after(async () => {
207
- await app.close()
208
- })
209
-
210
- try {
211
- await app.startService('wrong-service-id')
212
- assert.fail('should have thrown')
213
- } catch (err) {
214
- assert.strictEqual(err.message, 'Service with id \'wrong-service-id\' not found')
215
- }
216
- })
217
-
218
- test('should fail to start running service', async (t) => {
219
- const configFile = join(fixturesDir, 'configs', 'monorepo.json')
220
- const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
221
- const app = await buildServer(config.configManager.current)
222
-
223
- await app.start()
224
-
225
- t.after(async () => {
226
- await app.close()
227
- })
228
-
229
- try {
230
- await app.startService('with-logger')
231
- assert.fail('should have thrown')
232
- } catch (err) {
233
- assert.strictEqual(err.message, 'Application is already started')
234
- }
235
- })
236
-
237
- test('should inject request to service', async (t) => {
238
- const configFile = join(fixturesDir, 'configs', 'monorepo.json')
239
- const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
240
- const app = await buildServer(config.configManager.current)
241
-
242
- await app.start()
243
-
244
- t.after(async () => {
245
- await app.close()
246
- })
247
-
248
- const res = await app.inject('with-logger', {
249
- method: 'GET',
250
- url: '/'
251
- })
252
-
253
- assert.strictEqual(res.statusCode, 200)
254
- assert.strictEqual(res.statusMessage, 'OK')
255
-
256
- assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8')
257
- assert.strictEqual(res.headers['content-length'], '17')
258
- assert.strictEqual(res.headers.connection, 'keep-alive')
259
-
260
- assert.strictEqual(res.body, '{"hello":"world"}')
261
- assert.strictEqual(res.payload, '{"hello":"world"}')
262
- })
263
-
264
- test('should fail inject request is service is not started', async (t) => {
265
- const configFile = join(fixturesDir, 'configs', 'monorepo.json')
266
- const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
267
- const app = await buildServer(config.configManager.current)
268
-
269
- t.after(async () => {
270
- await app.close()
271
- })
272
-
273
- try {
274
- await app.inject('with-logger', { method: 'GET', url: '/' })
275
- } catch (err) {
276
- assert.strictEqual(err.message, 'Service with id \'with-logger\' is not started')
277
- }
278
- })
279
-
280
- test('does not wait forever if worker exits during api operation', async (t) => {
281
- const configFile = join(fixturesDir, 'configs', 'service-throws-on-start.json')
282
- const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
283
- const app = await buildServer(config.configManager.current)
284
-
285
- await assert.rejects(async () => {
286
- await app.start()
287
- }, /The runtime exited before the operation completed/)
288
- })
289
-
290
- test('should handle a lot of runtime api requests', async (t) => {
291
- const configFile = join(fixturesDir, 'configs', 'monorepo.json')
292
- const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
293
- const app = await buildServer(config.configManager.current)
294
-
295
- await app.start()
296
-
297
- t.after(async () => {
298
- await app.close()
299
- })
300
-
301
- const promises = []
302
- for (let i = 0; i < 100; i++) {
303
- promises.push(app.getServiceDetails('with-logger'))
304
- }
305
-
306
- await Promise.all(promises)
307
- })
308
-
309
- test('should get a service openapi schema', async (t) => {
310
- const configFile = join(fixturesDir, 'configs', 'monorepo.json')
311
- const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
312
- const app = await buildServer(config.configManager.current)
313
-
314
- await app.start()
315
-
316
- t.after(async () => {
317
- await app.close()
318
- })
319
-
320
- const openapiSchema = await app.getServiceOpenapiSchema('with-logger')
321
- assert.deepStrictEqual(openapiSchema, {
322
- openapi: '3.0.3',
323
- info: {
324
- title: 'Platformatic',
325
- description: 'This is a service built on top of Platformatic',
326
- version: '1.0.0'
327
- },
328
- components: { schemas: {} },
329
- paths: {
330
- '/': {
331
- get: {
332
- responses: {
333
- 200: {
334
- description: 'Default Response'
335
- }
336
- }
337
- }
338
- }
339
- }
340
- })
341
- })
342
-
343
- test('should fail to get a service openapi schema if service does not expose it', async (t) => {
344
- const configFile = join(fixturesDir, 'configs', 'monorepo-openapi.json')
345
- const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
346
- const app = await buildServer(config.configManager.current)
347
-
348
- await app.start()
349
-
350
- t.after(async () => {
351
- await app.close()
352
- })
353
-
354
- const openapiSchema = await app.getServiceOpenapiSchema('without-openapi')
355
- assert.strictEqual(openapiSchema, null)
356
- })