@platformatic/runtime 0.28.1 → 0.30.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 (42) hide show
  1. package/fixtures/dbApp/platformatic.db.json +5 -0
  2. package/fixtures/dbApp/plugin.js +12 -0
  3. package/fixtures/monorepo/serviceApp/plugin.js +4 -0
  4. package/fixtures/start-command-in-runtime.js +2 -1
  5. package/fixtures/typescript/platformatic.runtime.json +12 -0
  6. package/fixtures/typescript/services/composer/platformatic.composer.json +28 -0
  7. package/fixtures/typescript/services/movies/global.d.ts +24 -0
  8. package/fixtures/typescript/services/movies/migrations/001.do.sql +6 -0
  9. package/fixtures/typescript/services/movies/migrations/001.undo.sql +3 -0
  10. package/fixtures/typescript/services/movies/platformatic.db.json +33 -0
  11. package/fixtures/typescript/services/movies/plugin.ts +5 -0
  12. package/fixtures/typescript/services/movies/tsconfig.json +21 -0
  13. package/fixtures/typescript/services/movies/types/Movie.d.ts +9 -0
  14. package/fixtures/typescript/services/movies/types/index.d.ts +7 -0
  15. package/fixtures/typescript/services/titles/client/client.d.ts +141 -0
  16. package/fixtures/typescript/services/titles/client/client.openapi.json +630 -0
  17. package/fixtures/typescript/services/titles/client/package.json +4 -0
  18. package/fixtures/typescript/services/titles/platformatic.service.json +31 -0
  19. package/fixtures/typescript/services/titles/plugins/example.ts +6 -0
  20. package/fixtures/typescript/services/titles/routes/root.ts +21 -0
  21. package/fixtures/typescript/services/titles/tsconfig.json +21 -0
  22. package/help/compile.txt +8 -0
  23. package/index.js +7 -7
  24. package/lib/api-client.js +91 -0
  25. package/lib/api.js +26 -77
  26. package/lib/app.js +6 -2
  27. package/lib/compile.js +43 -0
  28. package/lib/config.js +77 -14
  29. package/lib/message-port-writable.js +42 -0
  30. package/lib/start.js +38 -19
  31. package/lib/unified-api.js +2 -0
  32. package/lib/worker.js +25 -26
  33. package/package.json +12 -8
  34. package/runtime.mjs +4 -0
  35. package/test/api.test.js +12 -1
  36. package/test/app.test.js +1 -1
  37. package/test/cli/compile.test.mjs +65 -0
  38. package/test/cli/start.test.mjs +56 -0
  39. package/test/cli/validations.test.mjs +2 -1
  40. package/test/cli/watch.test.mjs +15 -12
  41. package/test/config.test.js +137 -1
  42. package/test/start.test.js +57 -0
@@ -0,0 +1,630 @@
1
+ {
2
+ "openapi": "3.0.3",
3
+ "info": {
4
+ "title": "Platformatic DB",
5
+ "description": "Exposing a SQL database as REST",
6
+ "version": "1.0.0"
7
+ },
8
+ "components": {
9
+ "schemas": {
10
+ "Movie": {
11
+ "title": "Movie",
12
+ "description": "A Movie",
13
+ "type": "object",
14
+ "properties": {
15
+ "id": {
16
+ "type": "integer"
17
+ },
18
+ "title": {
19
+ "type": "string"
20
+ }
21
+ },
22
+ "required": [
23
+ "title"
24
+ ]
25
+ }
26
+ }
27
+ },
28
+ "paths": {
29
+ "/movies/": {
30
+ "get": {
31
+ "operationId": "getMovies",
32
+ "parameters": [
33
+ {
34
+ "schema": {
35
+ "type": "integer"
36
+ },
37
+ "in": "query",
38
+ "name": "limit",
39
+ "required": false,
40
+ "description": "Limit will be applied by default if not passed. If the provided value exceeds the maximum allowed value a validation error will be thrown"
41
+ },
42
+ {
43
+ "schema": {
44
+ "type": "integer"
45
+ },
46
+ "in": "query",
47
+ "name": "offset",
48
+ "required": false
49
+ },
50
+ {
51
+ "schema": {
52
+ "type": "boolean",
53
+ "default": false
54
+ },
55
+ "in": "query",
56
+ "name": "totalCount",
57
+ "required": false
58
+ },
59
+ {
60
+ "schema": {
61
+ "type": "array",
62
+ "items": {
63
+ "type": "string",
64
+ "enum": [
65
+ "id",
66
+ "title"
67
+ ]
68
+ }
69
+ },
70
+ "in": "query",
71
+ "name": "fields",
72
+ "required": false
73
+ },
74
+ {
75
+ "schema": {
76
+ "type": "integer"
77
+ },
78
+ "in": "query",
79
+ "name": "where.id.eq",
80
+ "required": false
81
+ },
82
+ {
83
+ "schema": {
84
+ "type": "integer"
85
+ },
86
+ "in": "query",
87
+ "name": "where.id.neq",
88
+ "required": false
89
+ },
90
+ {
91
+ "schema": {
92
+ "type": "integer"
93
+ },
94
+ "in": "query",
95
+ "name": "where.id.gt",
96
+ "required": false
97
+ },
98
+ {
99
+ "schema": {
100
+ "type": "integer"
101
+ },
102
+ "in": "query",
103
+ "name": "where.id.gte",
104
+ "required": false
105
+ },
106
+ {
107
+ "schema": {
108
+ "type": "integer"
109
+ },
110
+ "in": "query",
111
+ "name": "where.id.lt",
112
+ "required": false
113
+ },
114
+ {
115
+ "schema": {
116
+ "type": "integer"
117
+ },
118
+ "in": "query",
119
+ "name": "where.id.lte",
120
+ "required": false
121
+ },
122
+ {
123
+ "schema": {
124
+ "type": "integer"
125
+ },
126
+ "in": "query",
127
+ "name": "where.id.like",
128
+ "required": false
129
+ },
130
+ {
131
+ "schema": {
132
+ "type": "string"
133
+ },
134
+ "in": "query",
135
+ "name": "where.id.in",
136
+ "required": false
137
+ },
138
+ {
139
+ "schema": {
140
+ "type": "string"
141
+ },
142
+ "in": "query",
143
+ "name": "where.id.nin",
144
+ "required": false
145
+ },
146
+ {
147
+ "schema": {
148
+ "type": "string"
149
+ },
150
+ "in": "query",
151
+ "name": "where.title.eq",
152
+ "required": false
153
+ },
154
+ {
155
+ "schema": {
156
+ "type": "string"
157
+ },
158
+ "in": "query",
159
+ "name": "where.title.neq",
160
+ "required": false
161
+ },
162
+ {
163
+ "schema": {
164
+ "type": "string"
165
+ },
166
+ "in": "query",
167
+ "name": "where.title.gt",
168
+ "required": false
169
+ },
170
+ {
171
+ "schema": {
172
+ "type": "string"
173
+ },
174
+ "in": "query",
175
+ "name": "where.title.gte",
176
+ "required": false
177
+ },
178
+ {
179
+ "schema": {
180
+ "type": "string"
181
+ },
182
+ "in": "query",
183
+ "name": "where.title.lt",
184
+ "required": false
185
+ },
186
+ {
187
+ "schema": {
188
+ "type": "string"
189
+ },
190
+ "in": "query",
191
+ "name": "where.title.lte",
192
+ "required": false
193
+ },
194
+ {
195
+ "schema": {
196
+ "type": "string"
197
+ },
198
+ "in": "query",
199
+ "name": "where.title.like",
200
+ "required": false
201
+ },
202
+ {
203
+ "schema": {
204
+ "type": "string"
205
+ },
206
+ "in": "query",
207
+ "name": "where.title.in",
208
+ "required": false
209
+ },
210
+ {
211
+ "schema": {
212
+ "type": "string"
213
+ },
214
+ "in": "query",
215
+ "name": "where.title.nin",
216
+ "required": false
217
+ },
218
+ {
219
+ "schema": {
220
+ "type": "array",
221
+ "items": {
222
+ "type": "string"
223
+ }
224
+ },
225
+ "in": "query",
226
+ "name": "where.or",
227
+ "required": false
228
+ },
229
+ {
230
+ "schema": {
231
+ "type": "string",
232
+ "enum": [
233
+ "asc",
234
+ "desc"
235
+ ]
236
+ },
237
+ "in": "query",
238
+ "name": "orderby.id",
239
+ "required": false
240
+ },
241
+ {
242
+ "schema": {
243
+ "type": "string",
244
+ "enum": [
245
+ "asc",
246
+ "desc"
247
+ ]
248
+ },
249
+ "in": "query",
250
+ "name": "orderby.title",
251
+ "required": false
252
+ }
253
+ ],
254
+ "responses": {
255
+ "200": {
256
+ "description": "Default Response",
257
+ "content": {
258
+ "application/json": {
259
+ "schema": {
260
+ "type": "array",
261
+ "items": {
262
+ "$ref": "#/components/schemas/Movie"
263
+ }
264
+ }
265
+ }
266
+ }
267
+ }
268
+ }
269
+ },
270
+ "post": {
271
+ "operationId": "createMovie",
272
+ "requestBody": {
273
+ "content": {
274
+ "application/json": {
275
+ "schema": {
276
+ "$ref": "#/components/schemas/Movie"
277
+ }
278
+ }
279
+ }
280
+ },
281
+ "responses": {
282
+ "200": {
283
+ "description": "Default Response",
284
+ "content": {
285
+ "application/json": {
286
+ "schema": {
287
+ "$ref": "#/components/schemas/Movie"
288
+ }
289
+ }
290
+ },
291
+ "links": {}
292
+ }
293
+ }
294
+ },
295
+ "put": {
296
+ "operationId": "updateMovies",
297
+ "requestBody": {
298
+ "content": {
299
+ "application/json": {
300
+ "schema": {
301
+ "$ref": "#/components/schemas/Movie"
302
+ }
303
+ }
304
+ }
305
+ },
306
+ "parameters": [
307
+ {
308
+ "schema": {
309
+ "type": "array",
310
+ "items": {
311
+ "type": "string",
312
+ "enum": [
313
+ "id",
314
+ "title"
315
+ ]
316
+ }
317
+ },
318
+ "in": "query",
319
+ "name": "fields",
320
+ "required": false
321
+ },
322
+ {
323
+ "schema": {
324
+ "type": "integer"
325
+ },
326
+ "in": "query",
327
+ "name": "where.id.eq",
328
+ "required": false
329
+ },
330
+ {
331
+ "schema": {
332
+ "type": "integer"
333
+ },
334
+ "in": "query",
335
+ "name": "where.id.neq",
336
+ "required": false
337
+ },
338
+ {
339
+ "schema": {
340
+ "type": "integer"
341
+ },
342
+ "in": "query",
343
+ "name": "where.id.gt",
344
+ "required": false
345
+ },
346
+ {
347
+ "schema": {
348
+ "type": "integer"
349
+ },
350
+ "in": "query",
351
+ "name": "where.id.gte",
352
+ "required": false
353
+ },
354
+ {
355
+ "schema": {
356
+ "type": "integer"
357
+ },
358
+ "in": "query",
359
+ "name": "where.id.lt",
360
+ "required": false
361
+ },
362
+ {
363
+ "schema": {
364
+ "type": "integer"
365
+ },
366
+ "in": "query",
367
+ "name": "where.id.lte",
368
+ "required": false
369
+ },
370
+ {
371
+ "schema": {
372
+ "type": "integer"
373
+ },
374
+ "in": "query",
375
+ "name": "where.id.like",
376
+ "required": false
377
+ },
378
+ {
379
+ "schema": {
380
+ "type": "string"
381
+ },
382
+ "in": "query",
383
+ "name": "where.id.in",
384
+ "required": false
385
+ },
386
+ {
387
+ "schema": {
388
+ "type": "string"
389
+ },
390
+ "in": "query",
391
+ "name": "where.id.nin",
392
+ "required": false
393
+ },
394
+ {
395
+ "schema": {
396
+ "type": "string"
397
+ },
398
+ "in": "query",
399
+ "name": "where.title.eq",
400
+ "required": false
401
+ },
402
+ {
403
+ "schema": {
404
+ "type": "string"
405
+ },
406
+ "in": "query",
407
+ "name": "where.title.neq",
408
+ "required": false
409
+ },
410
+ {
411
+ "schema": {
412
+ "type": "string"
413
+ },
414
+ "in": "query",
415
+ "name": "where.title.gt",
416
+ "required": false
417
+ },
418
+ {
419
+ "schema": {
420
+ "type": "string"
421
+ },
422
+ "in": "query",
423
+ "name": "where.title.gte",
424
+ "required": false
425
+ },
426
+ {
427
+ "schema": {
428
+ "type": "string"
429
+ },
430
+ "in": "query",
431
+ "name": "where.title.lt",
432
+ "required": false
433
+ },
434
+ {
435
+ "schema": {
436
+ "type": "string"
437
+ },
438
+ "in": "query",
439
+ "name": "where.title.lte",
440
+ "required": false
441
+ },
442
+ {
443
+ "schema": {
444
+ "type": "string"
445
+ },
446
+ "in": "query",
447
+ "name": "where.title.like",
448
+ "required": false
449
+ },
450
+ {
451
+ "schema": {
452
+ "type": "string"
453
+ },
454
+ "in": "query",
455
+ "name": "where.title.in",
456
+ "required": false
457
+ },
458
+ {
459
+ "schema": {
460
+ "type": "string"
461
+ },
462
+ "in": "query",
463
+ "name": "where.title.nin",
464
+ "required": false
465
+ },
466
+ {
467
+ "schema": {
468
+ "type": "array",
469
+ "items": {
470
+ "type": "string"
471
+ }
472
+ },
473
+ "in": "query",
474
+ "name": "where.or",
475
+ "required": false
476
+ }
477
+ ],
478
+ "responses": {
479
+ "200": {
480
+ "description": "Default Response",
481
+ "content": {
482
+ "application/json": {
483
+ "schema": {
484
+ "type": "array",
485
+ "items": {
486
+ "$ref": "#/components/schemas/Movie"
487
+ }
488
+ }
489
+ }
490
+ },
491
+ "links": {}
492
+ }
493
+ }
494
+ }
495
+ },
496
+ "/movies/{id}": {
497
+ "get": {
498
+ "operationId": "getMovieById",
499
+ "parameters": [
500
+ {
501
+ "schema": {
502
+ "type": "array",
503
+ "items": {
504
+ "type": "string",
505
+ "enum": [
506
+ "id",
507
+ "title"
508
+ ]
509
+ }
510
+ },
511
+ "in": "query",
512
+ "name": "fields",
513
+ "required": false
514
+ },
515
+ {
516
+ "schema": {
517
+ "type": "integer"
518
+ },
519
+ "in": "path",
520
+ "name": "id",
521
+ "required": true
522
+ }
523
+ ],
524
+ "responses": {
525
+ "200": {
526
+ "description": "Default Response",
527
+ "content": {
528
+ "application/json": {
529
+ "schema": {
530
+ "$ref": "#/components/schemas/Movie"
531
+ }
532
+ }
533
+ },
534
+ "links": {}
535
+ }
536
+ }
537
+ },
538
+ "put": {
539
+ "operationId": "updateMovie",
540
+ "requestBody": {
541
+ "content": {
542
+ "application/json": {
543
+ "schema": {
544
+ "$ref": "#/components/schemas/Movie"
545
+ }
546
+ }
547
+ }
548
+ },
549
+ "parameters": [
550
+ {
551
+ "schema": {
552
+ "type": "array",
553
+ "items": {
554
+ "type": "string",
555
+ "enum": [
556
+ "id",
557
+ "title"
558
+ ]
559
+ }
560
+ },
561
+ "in": "query",
562
+ "name": "fields",
563
+ "required": false
564
+ },
565
+ {
566
+ "schema": {
567
+ "type": "integer"
568
+ },
569
+ "in": "path",
570
+ "name": "id",
571
+ "required": true
572
+ }
573
+ ],
574
+ "responses": {
575
+ "200": {
576
+ "description": "Default Response",
577
+ "content": {
578
+ "application/json": {
579
+ "schema": {
580
+ "$ref": "#/components/schemas/Movie"
581
+ }
582
+ }
583
+ },
584
+ "links": {}
585
+ }
586
+ }
587
+ },
588
+ "delete": {
589
+ "operationId": "deleteMovies",
590
+ "parameters": [
591
+ {
592
+ "schema": {
593
+ "type": "array",
594
+ "items": {
595
+ "type": "string",
596
+ "enum": [
597
+ "id",
598
+ "title"
599
+ ]
600
+ }
601
+ },
602
+ "in": "query",
603
+ "name": "fields",
604
+ "required": false
605
+ },
606
+ {
607
+ "schema": {
608
+ "type": "integer"
609
+ },
610
+ "in": "path",
611
+ "name": "id",
612
+ "required": true
613
+ }
614
+ ],
615
+ "responses": {
616
+ "200": {
617
+ "description": "Default Response",
618
+ "content": {
619
+ "application/json": {
620
+ "schema": {
621
+ "$ref": "#/components/schemas/Movie"
622
+ }
623
+ }
624
+ }
625
+ }
626
+ }
627
+ }
628
+ }
629
+ }
630
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "client",
3
+ "types": "./client.d.ts"
4
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "$schema": "https://platformatic.dev/schemas/v0.28.1/service",
3
+ "server": {
4
+ "hostname": "{PLT_SERVER_HOSTNAME}",
5
+ "port": "{PORT}",
6
+ "logger": {
7
+ "level": "{PLT_SERVER_LOGGER_LEVEL}"
8
+ }
9
+ },
10
+ "service": {
11
+ "openapi": true
12
+ },
13
+ "plugins": {
14
+ "paths": [
15
+ {
16
+ "path": "./plugins",
17
+ "encapsulate": false
18
+ },
19
+ "./routes"
20
+ ],
21
+ "typescript": false
22
+ },
23
+ "clients": [
24
+ {
25
+ "schema": "client/client.openapi.json",
26
+ "name": "client",
27
+ "type": "openapi",
28
+ "serviceId": "movies"
29
+ }
30
+ ]
31
+ }
@@ -0,0 +1,6 @@
1
+ /// <reference types="@platformatic/service" />
2
+ import { FastifyInstance, FastifyPluginOptions } from 'fastify'
3
+
4
+ export default async function (fastify: FastifyInstance, opts: FastifyPluginOptions) {
5
+ fastify.decorate('example', 'foobar')
6
+ }
@@ -0,0 +1,21 @@
1
+ /// <reference types="@platformatic/service" />
2
+ /// <reference types="../client" />
3
+ import { FastifyInstance, FastifyPluginOptions } from 'fastify'
4
+
5
+ declare module 'fastify' {
6
+ interface FastifyInstance {
7
+ example: string
8
+ }
9
+ }
10
+
11
+ export default async function (fastify: FastifyInstance, opts: FastifyPluginOptions) {
12
+ fastify.get('/', async (request, reply) => {
13
+ return { hello: fastify.example }
14
+ })
15
+
16
+ fastify.get('/titles', async (request, reply) => {
17
+ const movies = await fastify.client.getMovies({})
18
+ const titles = movies.map((movie) => movie.title)
19
+ return { titles }
20
+ })
21
+ }