@platformatic/runtime 3.0.0-alpha.5 → 3.0.0-alpha.8

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.
@@ -1,9 +1,7 @@
1
- 'use strict'
2
-
3
- class RoundRobinMap extends Map {
1
+ export class RoundRobinMap extends Map {
4
2
  #instances
5
3
 
6
- constructor (iterable, instances) {
4
+ constructor (iterable, instances = {}) {
7
5
  super(iterable)
8
6
  this.#instances = instances
9
7
  }
@@ -12,29 +10,37 @@ class RoundRobinMap extends Map {
12
10
  return { ...this.#instances }
13
11
  }
14
12
 
15
- configure (services) {
13
+ configure (applications) {
16
14
  this.#instances = {}
17
15
 
18
- for (const service of services) {
19
- this.#instances[service.id] = { next: service.next ?? 0, count: service.workers }
16
+ for (const application of applications) {
17
+ this.#instances[application.id] = { next: application.next ?? 0, count: application.workers }
20
18
  }
21
19
  }
22
20
 
23
- getCount (service) {
24
- return this.#instances[service].count
21
+ getCount (application) {
22
+ if (!this.#instances[application]) {
23
+ return null
24
+ }
25
+
26
+ return this.#instances[application].count
25
27
  }
26
28
 
27
- setCount (service, count) {
28
- this.#instances[service].count = count
29
+ setCount (application, count) {
30
+ if (!this.#instances[application]) {
31
+ throw new Error(`Application ${application} is not configured.`)
32
+ }
33
+
34
+ this.#instances[application].count = count
29
35
  }
30
36
 
31
- next (service) {
32
- if (!this.#instances[service]) {
33
- return undefined
37
+ next (application) {
38
+ if (!this.#instances[application]) {
39
+ return null
34
40
  }
35
41
 
36
42
  let worker
37
- let { next, count } = this.#instances[service]
43
+ let { next, count } = this.#instances[application]
38
44
 
39
45
  // Try count times to get the next worker. This is to handle the case where a worker is being restarted.
40
46
  for (let i = 0; i < count; i++) {
@@ -43,16 +49,14 @@ class RoundRobinMap extends Map {
43
49
  next = 0
44
50
  }
45
51
 
46
- worker = this.get(`${service}:${current}`)
52
+ worker = this.get(`${application}:${current}`)
47
53
 
48
54
  if (worker) {
49
55
  break
50
56
  }
51
57
  }
52
58
 
53
- this.#instances[service].next = next
59
+ this.#instances[application].next = next
54
60
  return worker
55
61
  }
56
62
  }
57
-
58
- module.exports = { RoundRobinMap }
@@ -1,8 +1,6 @@
1
- 'use strict'
1
+ import { kITC } from './symbols.js'
2
2
 
3
- const { kITC } = require('./symbols')
4
-
5
- class SharedContext {
3
+ export class SharedContext {
6
4
  constructor () {
7
5
  this.sharedContext = null
8
6
  }
@@ -22,5 +20,3 @@ class SharedContext {
22
20
  this.sharedContext = context
23
21
  }
24
22
  }
25
-
26
- module.exports = { SharedContext }
@@ -1,33 +1,16 @@
1
- 'use strict'
2
-
3
- const kConfig = Symbol.for('plt.runtime.config')
4
- const kId = Symbol.for('plt.runtime.id') // This is also used to detect if we are running in a Platformatic runtime thread
5
- const kFullId = Symbol.for('plt.runtime.fullId')
6
- const kServiceId = Symbol.for('plt.runtime.service.id')
7
- const kWorkerId = Symbol.for('plt.runtime.worker.id')
8
- const kITC = Symbol.for('plt.runtime.itc')
9
- const kHealthCheckTimer = Symbol.for('plt.runtime.worker.healthCheckTimer')
10
- const kWorkerStatus = Symbol('plt.runtime.worker.status')
11
- const kInterceptors = Symbol.for('plt.runtime.worker.interceptors')
12
- const kLastELU = Symbol.for('plt.runtime.worker.lastELU')
1
+ export const kConfig = Symbol.for('plt.runtime.config')
2
+ export const kId = Symbol.for('plt.runtime.id') // This is also used to detect if we are running in a Platformatic runtime thread
3
+ export const kFullId = Symbol.for('plt.runtime.fullId')
4
+ export const kApplicationId = Symbol.for('plt.runtime.application.id')
5
+ export const kWorkerId = Symbol.for('plt.runtime.worker.id')
6
+ export const kITC = Symbol.for('plt.runtime.itc')
7
+ export const kHealthCheckTimer = Symbol.for('plt.runtime.worker.healthCheckTimer')
8
+ export const kWorkerStatus = Symbol('plt.runtime.worker.status')
9
+ export const kInterceptors = Symbol.for('plt.runtime.worker.interceptors')
10
+ export const kLastELU = Symbol.for('plt.runtime.worker.lastELU')
13
11
 
14
12
  // This string marker should be safe to use since it belongs to Unicode private area
15
- const kStderrMarker = '\ue002'
13
+ export const kStderrMarker = '\ue002'
16
14
 
17
15
  // Note that this is used to create a BroadcastChannel so it must be a string
18
- const kWorkersBroadcast = 'plt.runtime.workers'
19
-
20
- module.exports = {
21
- kConfig,
22
- kId,
23
- kFullId,
24
- kServiceId,
25
- kWorkerId,
26
- kITC,
27
- kHealthCheckTimer,
28
- kLastELU,
29
- kWorkerStatus,
30
- kStderrMarker,
31
- kInterceptors,
32
- kWorkersBroadcast
33
- }
16
+ export const kWorkersBroadcast = 'plt.runtime.workers'
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "3.0.0-alpha.5",
3
+ "version": "3.0.0-alpha.8",
4
4
  "description": "",
5
5
  "main": "index.js",
6
+ "type": "module",
6
7
  "author": "Platformatic Inc. <oss@platformatic.dev> (https://platformatic.dev)",
7
8
  "repository": {
8
9
  "type": "git",
@@ -18,8 +19,8 @@
18
19
  "@fastify/express": "^4.0.0",
19
20
  "@fastify/formbody": "^8.0.0",
20
21
  "autocannon": "^8.0.0",
21
- "borp": "^0.20.0",
22
22
  "c8": "^10.0.0",
23
+ "cleaner-spec-reporter": "^0.5.0",
23
24
  "eslint": "9",
24
25
  "execa": "^9.0.0",
25
26
  "express": "^4.18.3",
@@ -33,18 +34,19 @@
33
34
  "typescript": "^5.5.4",
34
35
  "undici-oidc-interceptor": "^0.5.0",
35
36
  "why-is-node-running": "^2.2.2",
36
- "@platformatic/composer": "3.0.0-alpha.5",
37
- "@platformatic/db": "3.0.0-alpha.5",
38
- "@platformatic/node": "3.0.0-alpha.5",
39
- "@platformatic/service": "3.0.0-alpha.5",
40
- "@platformatic/sql-graphql": "3.0.0-alpha.5",
41
- "@platformatic/sql-mapper": "3.0.0-alpha.5"
37
+ "@platformatic/composer": "3.0.0-alpha.8",
38
+ "@platformatic/gateway": "3.0.0-alpha.8",
39
+ "@platformatic/db": "3.0.0-alpha.8",
40
+ "@platformatic/node": "3.0.0-alpha.8",
41
+ "@platformatic/service": "3.0.0-alpha.8",
42
+ "@platformatic/sql-graphql": "3.0.0-alpha.8",
43
+ "@platformatic/sql-mapper": "3.0.0-alpha.8",
44
+ "@platformatic/wattpm-pprof-capture": "3.0.0-alpha.8"
42
45
  },
43
46
  "dependencies": {
44
47
  "@fastify/accepts": "^5.0.0",
45
48
  "@fastify/error": "^4.0.0",
46
49
  "@fastify/websocket": "^11.0.0",
47
- "@hapi/topo": "^6.0.2",
48
50
  "@opentelemetry/api": "^1.9.0",
49
51
  "@platformatic/undici-cache-memory": "^0.8.1",
50
52
  "@watchable/unpromise": "^1.0.2",
@@ -68,27 +70,26 @@
68
70
  "undici": "^7.0.0",
69
71
  "undici-thread-interceptor": "^0.14.0",
70
72
  "ws": "^8.16.0",
71
- "@platformatic/foundation": "3.0.0-alpha.5",
72
- "@platformatic/generators": "3.0.0-alpha.5",
73
- "@platformatic/metrics": "3.0.0-alpha.5",
74
- "@platformatic/telemetry": "3.0.0-alpha.5",
75
- "@platformatic/itc": "3.0.0-alpha.5",
76
- "@platformatic/basic": "3.0.0-alpha.5"
73
+ "@platformatic/basic": "3.0.0-alpha.8",
74
+ "@platformatic/generators": "3.0.0-alpha.8",
75
+ "@platformatic/itc": "3.0.0-alpha.8",
76
+ "@platformatic/telemetry": "3.0.0-alpha.8",
77
+ "@platformatic/metrics": "3.0.0-alpha.8",
78
+ "@platformatic/foundation": "3.0.0-alpha.8"
77
79
  },
78
80
  "engines": {
79
81
  "node": ">=22.18.0"
80
82
  },
81
83
  "scripts": {
82
- "test": "pnpm run lint && borp --concurrency=1 --timeout=1200000",
83
- "test:main": "borp --concurrency=1 --timeout=1200000 test/*.test.js test/*.test.mjs test/versions/*.test.js test/versions/*.test.mjs",
84
- "test:api": "borp --concurrency=1 --timeout=1200000 test/api/*.test.js test/api/*.test.mjs test/management-api/*.test.js test/management-api/*.test.mjs",
85
- "test:cli": "borp --concurrency=1 --timeout=1200000 test/cli/*.test.js test/cli/*.test.mjs test/cli/**/*.test.js test/cli/**/*.test.mjs",
86
- "test:start": "borp --concurrency=1 --reporter=tap --timeout=1200000 test/start/*.test.js test/start/*.test.mjs",
87
- "test:multiple-workers": "borp --concurrency=1 --timeout=1200000 test/multiple-workers/*.test.js test/multiple-workers/*.test.mjs",
88
- "coverage": "pnpm run lint && borp -X fixtures -X test -C --concurrency=1 --timeout=1200000 ",
84
+ "test": "npm run test:main && npm run test:api && npm run test:cli && npm run test:start && npm run test:multiple-workers",
85
+ "test:main": "node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/*.test.js test/versions/*.test.js",
86
+ "test:api": "node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/api/*.test.js test/management-api/*.test.js",
87
+ "test:cli": "node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/cli/*.test.js test/cli/**/*.test.js",
88
+ "test:start": "node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/start/*.test.js",
89
+ "test:multiple-workers": "node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/multiple-workers/*.test.js",
89
90
  "gen-schema": "node lib/schema.js > schema.json",
90
91
  "gen-types": "json2ts > config.d.ts < schema.json",
91
- "build": "pnpm run gen-schema && pnpm run gen-types",
92
+ "build": "npm run gen-schema && npm run gen-types",
92
93
  "lint": "eslint"
93
94
  }
94
95
  }
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/runtime/3.0.0-alpha.5.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/runtime/3.0.0-alpha.8.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Runtime Config",
5
5
  "type": "object",
@@ -186,6 +186,12 @@
186
186
  }
187
187
  ]
188
188
  },
189
+ "dependencies": {
190
+ "type": "array",
191
+ "items": {
192
+ "type": "string"
193
+ }
194
+ },
189
195
  "arguments": {
190
196
  "type": "array",
191
197
  "items": {
@@ -200,7 +206,7 @@
200
206
  }
201
207
  }
202
208
  },
203
- "services": {
209
+ "applications": {
204
210
  "type": "array",
205
211
  "items": {
206
212
  "type": "object",
@@ -347,6 +353,13 @@
347
353
  },
348
354
  "additionalProperties": false
349
355
  },
356
+ "dependencies": {
357
+ "type": "array",
358
+ "items": {
359
+ "type": "string"
360
+ },
361
+ "default": []
362
+ },
350
363
  "arguments": {
351
364
  "type": "array",
352
365
  "items": {
@@ -429,17 +442,241 @@
429
442
  }
430
443
  }
431
444
  },
432
- "workers": {
433
- "anyOf": [
434
- {
435
- "type": "number",
436
- "minimum": 1
437
- },
438
- {
439
- "type": "string"
445
+ "services": {
446
+ "type": "array",
447
+ "items": {
448
+ "type": "object",
449
+ "anyOf": [
450
+ {
451
+ "required": [
452
+ "id",
453
+ "path"
454
+ ]
455
+ },
456
+ {
457
+ "required": [
458
+ "id",
459
+ "url"
460
+ ]
461
+ }
462
+ ],
463
+ "properties": {
464
+ "id": {
465
+ "type": "string"
466
+ },
467
+ "path": {
468
+ "type": "string",
469
+ "allowEmptyPaths": true,
470
+ "resolvePath": true
471
+ },
472
+ "config": {
473
+ "type": "string"
474
+ },
475
+ "url": {
476
+ "type": "string"
477
+ },
478
+ "gitBranch": {
479
+ "type": "string",
480
+ "default": "main"
481
+ },
482
+ "useHttp": {
483
+ "type": "boolean"
484
+ },
485
+ "workers": {
486
+ "anyOf": [
487
+ {
488
+ "type": "number",
489
+ "minimum": 1
490
+ },
491
+ {
492
+ "type": "string"
493
+ }
494
+ ]
495
+ },
496
+ "health": {
497
+ "type": "object",
498
+ "default": {},
499
+ "properties": {
500
+ "enabled": {
501
+ "anyOf": [
502
+ {
503
+ "type": "boolean"
504
+ },
505
+ {
506
+ "type": "string"
507
+ }
508
+ ]
509
+ },
510
+ "interval": {
511
+ "anyOf": [
512
+ {
513
+ "type": "number",
514
+ "minimum": 0
515
+ },
516
+ {
517
+ "type": "string"
518
+ }
519
+ ]
520
+ },
521
+ "gracePeriod": {
522
+ "anyOf": [
523
+ {
524
+ "type": "number",
525
+ "minimum": 0
526
+ },
527
+ {
528
+ "type": "string"
529
+ }
530
+ ]
531
+ },
532
+ "maxUnhealthyChecks": {
533
+ "anyOf": [
534
+ {
535
+ "type": "number",
536
+ "minimum": 1
537
+ },
538
+ {
539
+ "type": "string"
540
+ }
541
+ ]
542
+ },
543
+ "maxELU": {
544
+ "anyOf": [
545
+ {
546
+ "type": "number",
547
+ "minimum": 0,
548
+ "maximum": 1
549
+ },
550
+ {
551
+ "type": "string"
552
+ }
553
+ ]
554
+ },
555
+ "maxHeapUsed": {
556
+ "anyOf": [
557
+ {
558
+ "type": "number",
559
+ "minimum": 0,
560
+ "maximum": 1
561
+ },
562
+ {
563
+ "type": "string"
564
+ }
565
+ ]
566
+ },
567
+ "maxHeapTotal": {
568
+ "anyOf": [
569
+ {
570
+ "type": "number",
571
+ "minimum": 0
572
+ },
573
+ {
574
+ "type": "string"
575
+ }
576
+ ]
577
+ },
578
+ "maxYoungGeneration": {
579
+ "anyOf": [
580
+ {
581
+ "type": "number",
582
+ "minimum": 0
583
+ },
584
+ {
585
+ "type": "string"
586
+ }
587
+ ]
588
+ }
589
+ },
590
+ "additionalProperties": false
591
+ },
592
+ "dependencies": {
593
+ "type": "array",
594
+ "items": {
595
+ "type": "string"
596
+ },
597
+ "default": []
598
+ },
599
+ "arguments": {
600
+ "type": "array",
601
+ "items": {
602
+ "type": "string"
603
+ }
604
+ },
605
+ "env": {
606
+ "type": "object",
607
+ "additionalProperties": {
608
+ "type": "string"
609
+ }
610
+ },
611
+ "envfile": {
612
+ "type": "string"
613
+ },
614
+ "sourceMaps": {
615
+ "type": "boolean",
616
+ "default": false
617
+ },
618
+ "packageManager": {
619
+ "type": "string",
620
+ "enum": [
621
+ "npm",
622
+ "pnpm",
623
+ "yarn"
624
+ ]
625
+ },
626
+ "preload": {
627
+ "anyOf": [
628
+ {
629
+ "type": "string",
630
+ "resolvePath": true
631
+ },
632
+ {
633
+ "type": "array",
634
+ "items": {
635
+ "type": "string",
636
+ "resolvePath": true
637
+ }
638
+ }
639
+ ]
640
+ },
641
+ "nodeOptions": {
642
+ "type": "string"
643
+ },
644
+ "telemetry": {
645
+ "type": "object",
646
+ "properties": {
647
+ "instrumentations": {
648
+ "type": "array",
649
+ "description": "An array of instrumentations loaded if telemetry is enabled",
650
+ "items": {
651
+ "oneOf": [
652
+ {
653
+ "type": "string"
654
+ },
655
+ {
656
+ "type": "object",
657
+ "properties": {
658
+ "package": {
659
+ "type": "string"
660
+ },
661
+ "exportName": {
662
+ "type": "string"
663
+ },
664
+ "options": {
665
+ "type": "object",
666
+ "additionalProperties": true
667
+ }
668
+ },
669
+ "required": [
670
+ "package"
671
+ ]
672
+ }
673
+ ]
674
+ }
675
+ }
676
+ }
677
+ }
440
678
  }
441
- ],
442
- "default": 1
679
+ }
443
680
  },
444
681
  "web": {
445
682
  "type": "array",
@@ -588,6 +825,13 @@
588
825
  },
589
826
  "additionalProperties": false
590
827
  },
828
+ "dependencies": {
829
+ "type": "array",
830
+ "items": {
831
+ "type": "string"
832
+ },
833
+ "default": []
834
+ },
591
835
  "arguments": {
592
836
  "type": "array",
593
837
  "items": {
@@ -670,6 +914,18 @@
670
914
  }
671
915
  }
672
916
  },
917
+ "workers": {
918
+ "anyOf": [
919
+ {
920
+ "type": "number",
921
+ "minimum": 1
922
+ },
923
+ {
924
+ "type": "string"
925
+ }
926
+ ],
927
+ "default": 1
928
+ },
673
929
  "logger": {
674
930
  "type": "object",
675
931
  "properties": {
@@ -976,7 +1232,7 @@
976
1232
  ],
977
1233
  "default": 10000
978
1234
  },
979
- "service": {
1235
+ "application": {
980
1236
  "anyOf": [
981
1237
  {
982
1238
  "type": "number",
@@ -992,7 +1248,7 @@
992
1248
  "default": {},
993
1249
  "required": [
994
1250
  "runtime",
995
- "service"
1251
+ "application"
996
1252
  ],
997
1253
  "additionalProperties": false
998
1254
  },
@@ -1423,13 +1679,13 @@
1423
1679
  }
1424
1680
  ]
1425
1681
  },
1426
- "serviceName": {
1682
+ "applicationName": {
1427
1683
  "type": "string",
1428
- "description": "The name of the service. Defaults to the folder name if not specified."
1684
+ "description": "The name of the application. Defaults to the folder name if not specified."
1429
1685
  },
1430
1686
  "version": {
1431
1687
  "type": "string",
1432
- "description": "The version of the service (optional)"
1688
+ "description": "The version of the application (optional)"
1433
1689
  },
1434
1690
  "skip": {
1435
1691
  "type": "array",
@@ -1536,7 +1792,7 @@
1536
1792
  }
1537
1793
  },
1538
1794
  "required": [
1539
- "serviceName"
1795
+ "applicationName"
1540
1796
  ],
1541
1797
  "additionalProperties": false
1542
1798
  },
@@ -1557,7 +1813,7 @@
1557
1813
  }
1558
1814
  }
1559
1815
  },
1560
- "serviceTimeout": {
1816
+ "applicationTimeout": {
1561
1817
  "anyOf": [
1562
1818
  {
1563
1819
  "type": "number",
@@ -1581,7 +1837,7 @@
1581
1837
  ],
1582
1838
  "default": 30000
1583
1839
  },
1584
- "resolvedServicesBasePath": {
1840
+ "resolvedApplicationsBasePath": {
1585
1841
  "type": "string",
1586
1842
  "default": "external"
1587
1843
  },
@@ -1668,6 +1924,11 @@
1668
1924
  "autoload"
1669
1925
  ]
1670
1926
  },
1927
+ {
1928
+ "required": [
1929
+ "applications"
1930
+ ]
1931
+ },
1671
1932
  {
1672
1933
  "required": [
1673
1934
  "services"