@platformatic/node 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.
package/config.d.ts CHANGED
@@ -114,6 +114,9 @@ export interface PlatformaticNodeJsConfig {
114
114
  runtime?: {
115
115
  preload?: string | string[];
116
116
  basePath?: string;
117
+ services?: {
118
+ [k: string]: unknown;
119
+ }[];
117
120
  workers?: number | string;
118
121
  logger?: {
119
122
  level: (
@@ -201,7 +204,7 @@ export interface PlatformaticNodeJsConfig {
201
204
  restartOnError?: boolean | number;
202
205
  gracefulShutdown?: {
203
206
  runtime: number | string;
204
- service: number | string;
207
+ application: number | string;
205
208
  };
206
209
  health?: {
207
210
  enabled?: boolean | string;
@@ -320,11 +323,11 @@ export interface PlatformaticNodeJsConfig {
320
323
  telemetry?: {
321
324
  enabled?: boolean | string;
322
325
  /**
323
- * The name of the service. Defaults to the folder name if not specified.
326
+ * The name of the application. Defaults to the folder name if not specified.
324
327
  */
325
- serviceName: string;
328
+ applicationName: string;
326
329
  /**
327
- * The version of the service (optional)
330
+ * The version of the application (optional)
328
331
  */
329
332
  version?: string;
330
333
  /**
@@ -400,7 +403,7 @@ export interface PlatformaticNodeJsConfig {
400
403
  watchDisabled?: boolean;
401
404
  [k: string]: unknown;
402
405
  };
403
- serviceTimeout?: number | string;
406
+ applicationTimeout?: number | string;
404
407
  messagingTimeout?: number | string;
405
408
  env?: {
406
409
  [k: string]: string;
@@ -427,7 +430,7 @@ export interface PlatformaticNodeJsConfig {
427
430
  node?: {
428
431
  main?: string;
429
432
  /**
430
- * This Node.js application requires the Absolute URL from the Composer
433
+ * This Node.js application requires the Absolute URL from the Gateway
431
434
  */
432
435
  absoluteUrl?: boolean;
433
436
  dispatchViaHttp?: boolean;
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { transform as basicTransform, resolve, validationOptions } from '@platformatic/basic'
2
2
  import { kMetadata, loadConfiguration as utilsLoadConfiguration } from '@platformatic/foundation'
3
+ import { NodeCapability } from './lib/capability.js'
3
4
  import { schema } from './lib/schema.js'
4
- import { NodeStackable } from './lib/stackable.js'
5
5
 
6
6
  export async function transform (config, _schema, options) {
7
7
  config = await basicTransform(config, schema, options)
@@ -24,9 +24,9 @@ export async function loadConfiguration (configOrRoot, sourceOrConfig, context)
24
24
 
25
25
  export async function create (configOrRoot, sourceOrConfig, context) {
26
26
  const config = await loadConfiguration(configOrRoot, sourceOrConfig, context)
27
- return new NodeStackable(config[kMetadata].root, config, context)
27
+ return new NodeCapability(config[kMetadata].root, config, context)
28
28
  }
29
29
 
30
+ export * from './lib/capability.js'
30
31
  export { Generator } from './lib/generator.js'
31
32
  export { packageJson, schema, schemaComponents, version } from './lib/schema.js'
32
- export * from './lib/stackable.js'
@@ -1,5 +1,5 @@
1
1
  import {
2
- BaseStackable,
2
+ BaseCapability,
3
3
  cleanBasePath,
4
4
  createServerListener,
5
5
  ensureTrailingSlash,
@@ -14,7 +14,7 @@ import { readFile } from 'node:fs/promises'
14
14
  import { Server } from 'node:http'
15
15
  import { resolve as resolvePath } from 'node:path'
16
16
  import { version } from './schema.js'
17
- import { getTsconfig, ignoreDirs, isServiceBuildable } from './utils.js'
17
+ import { getTsconfig, ignoreDirs, isApplicationBuildable } from './utils.js'
18
18
 
19
19
  const validFields = [
20
20
  'main',
@@ -88,7 +88,7 @@ async function getEntrypointInformation (root) {
88
88
  return { entrypoint, hadEntrypointField }
89
89
  }
90
90
 
91
- export class NodeStackable extends BaseStackable {
91
+ export class NodeCapability extends BaseCapability {
92
92
  #module
93
93
  #app
94
94
  #server
@@ -116,13 +116,13 @@ export class NodeStackable extends BaseStackable {
116
116
 
117
117
  const config = this.config
118
118
 
119
- if (!this.isProduction && (await isServiceBuildable(this.root, config))) {
120
- this.logger.info(`Building service "${this.serviceId}" before starting in development mode ...`)
119
+ if (!this.isProduction && (await isApplicationBuildable(this.root, config))) {
120
+ this.logger.info(`Building application "${this.applicationId}" before starting in development mode ...`)
121
121
  try {
122
122
  await this.build()
123
123
  this.childManager = null
124
124
  } catch (e) {
125
- this.logger.error(`Error while building service "${this.serviceId}": ${e.message}`)
125
+ this.logger.error(`Error while building application "${this.applicationId}": ${e.message}`)
126
126
  }
127
127
  }
128
128
 
@@ -161,7 +161,7 @@ export class NodeStackable extends BaseStackable {
161
161
 
162
162
  if (config.node?.hasServer !== false && this.#module.hasServer !== false) {
163
163
  if (factory) {
164
- // We have build function, this Stackable will not use HTTP unless it is the entrypoint
164
+ // We have build function, this Capability will not use HTTP unless it is the entrypoint
165
165
  serverPromise.cancel()
166
166
 
167
167
  this.#app = await this.#module[factory]()
@@ -194,6 +194,8 @@ export class NodeStackable extends BaseStackable {
194
194
  }
195
195
 
196
196
  async stop () {
197
+ await super.stop()
198
+
197
199
  if (this.childManager) {
198
200
  return this.stopCommand()
199
201
  }
@@ -275,7 +277,7 @@ export class NodeStackable extends BaseStackable {
275
277
 
276
278
  getMeta () {
277
279
  return {
278
- composer: {
280
+ gateway: {
279
281
  tcp: typeof this.url !== 'undefined',
280
282
  url: this.url,
281
283
  prefix: this.basePath ?? this.#basePath,
@@ -339,7 +341,7 @@ export class NodeStackable extends BaseStackable {
339
341
  if (typeof this.workerId === 'undefined' || this.workerId === 0) {
340
342
  if (!entrypoint) {
341
343
  this.logger.error(
342
- `The service "${this.serviceId}" had no valid entrypoint defined in the package.json file and no valid entrypoint file was found.`
344
+ `The application "${this.applicationId}" had no valid entrypoint defined in the package.json file and no valid entrypoint file was found.`
343
345
  )
344
346
 
345
347
  process.exit(1)
@@ -347,7 +349,7 @@ export class NodeStackable extends BaseStackable {
347
349
 
348
350
  if (!hadEntrypointField) {
349
351
  this.logger.warn(
350
- `The service "${this.serviceId}" had no valid entrypoint defined in the package.json file. Falling back to the file "${entrypoint}".`
352
+ `The application "${this.applicationId}" had no valid entrypoint defined in the package.json file. Falling back to the file "${entrypoint}".`
351
353
  )
352
354
  }
353
355
  }
@@ -377,7 +379,7 @@ export class NodeStackable extends BaseStackable {
377
379
  return { enabled, path: this.root }
378
380
  }
379
381
 
380
- // ignore the outDir from tsconfig or service config if any
382
+ // ignore the outDir from tsconfig or application config if any
381
383
  let ignore = config.watch?.ignore
382
384
  if (!ignore) {
383
385
  const tsConfig = await getTsconfig(this.root, config)
package/lib/generator.js CHANGED
@@ -45,7 +45,7 @@ export class Generator extends BaseGenerator {
45
45
  file: 'package.json',
46
46
  contents: JSON.stringify(
47
47
  {
48
- name: `${this.config.serviceName}`,
48
+ name: `${this.config.applicationName}`,
49
49
  main,
50
50
  type: 'module',
51
51
  scripts: {
package/lib/schema.js CHANGED
@@ -13,7 +13,7 @@ const node = {
13
13
  type: 'string'
14
14
  },
15
15
  absoluteUrl: {
16
- description: 'This Node.js application requires the Absolute URL from the Composer',
16
+ description: 'This Node.js application requires the Absolute URL from the Gateway',
17
17
  type: 'boolean',
18
18
  default: false
19
19
  },
package/lib/utils.js CHANGED
@@ -2,8 +2,8 @@ import json5 from 'json5'
2
2
  import { readFile } from 'node:fs/promises'
3
3
  import path, { join } from 'node:path'
4
4
 
5
- export async function isServiceBuildable (serviceRoot, config) {
6
- // skip vite as stackable as it has its own build command
5
+ export async function isApplicationBuildable (applicationRoot, config) {
6
+ // skip vite as capability as it has its own build command
7
7
  if (config?.vite) {
8
8
  return false
9
9
  }
@@ -13,7 +13,7 @@ export async function isServiceBuildable (serviceRoot, config) {
13
13
  }
14
14
 
15
15
  // Check if package.json exists and has a build command
16
- const packageJsonPath = join(serviceRoot, 'package.json')
16
+ const packageJsonPath = join(applicationRoot, 'package.json')
17
17
 
18
18
  try {
19
19
  // File exists, try to read and parse it
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@platformatic/node",
3
- "version": "3.0.0-alpha.5",
4
- "description": "Platformatic Node.js Stackable",
3
+ "version": "3.0.0-alpha.8",
4
+ "description": "Platformatic Node.js Capability",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "repository": {
@@ -17,12 +17,12 @@
17
17
  "dependencies": {
18
18
  "json5": "^2.2.3",
19
19
  "light-my-request": "^6.0.0",
20
- "@platformatic/generators": "3.0.0-alpha.5",
21
- "@platformatic/foundation": "3.0.0-alpha.5",
22
- "@platformatic/basic": "3.0.0-alpha.5"
20
+ "@platformatic/basic": "3.0.0-alpha.8",
21
+ "@platformatic/foundation": "3.0.0-alpha.8",
22
+ "@platformatic/generators": "3.0.0-alpha.8"
23
23
  },
24
24
  "devDependencies": {
25
- "borp": "^0.20.0",
25
+ "cleaner-spec-reporter": "^0.5.0",
26
26
  "eslint": "9",
27
27
  "express": "^4.19.2",
28
28
  "fastify": "^5.0.0",
@@ -31,18 +31,17 @@
31
31
  "neostandard": "^0.12.0",
32
32
  "tsx": "^4.19.0",
33
33
  "typescript": "^5.5.4",
34
- "@platformatic/service": "3.0.0-alpha.5",
35
- "@platformatic/composer": "3.0.0-alpha.5"
34
+ "@platformatic/service": "3.0.0-alpha.8",
35
+ "@platformatic/gateway": "3.0.0-alpha.8"
36
36
  },
37
37
  "engines": {
38
38
  "node": ">=22.18.0"
39
39
  },
40
40
  "scripts": {
41
- "test": "pnpm run lint && borp --concurrency=1 --timeout 1200000",
42
- "coverage": "pnpm run lint && borp -C -X test -X test/fixtures --concurrency=1 --timeout 1200000",
41
+ "test": "node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/*.test.js test/**/*.test.js",
43
42
  "gen-schema": "node lib/schema.js > schema.json",
44
43
  "gen-types": "json2ts > config.d.ts < schema.json",
45
- "build": "pnpm run gen-schema && pnpm run gen-types",
44
+ "build": "npm run gen-schema && npm run gen-types",
46
45
  "lint": "eslint"
47
46
  }
48
47
  }
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/node/3.0.0-alpha.5.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/node/3.0.0-alpha.8.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Node.js Config",
5
5
  "type": "object",
@@ -386,6 +386,242 @@
386
386
  "basePath": {
387
387
  "type": "string"
388
388
  },
389
+ "services": {
390
+ "type": "array",
391
+ "items": {
392
+ "type": "object",
393
+ "anyOf": [
394
+ {
395
+ "required": [
396
+ "id",
397
+ "path"
398
+ ]
399
+ },
400
+ {
401
+ "required": [
402
+ "id",
403
+ "url"
404
+ ]
405
+ }
406
+ ],
407
+ "properties": {
408
+ "id": {
409
+ "type": "string"
410
+ },
411
+ "path": {
412
+ "type": "string",
413
+ "allowEmptyPaths": true,
414
+ "resolvePath": true
415
+ },
416
+ "config": {
417
+ "type": "string"
418
+ },
419
+ "url": {
420
+ "type": "string"
421
+ },
422
+ "gitBranch": {
423
+ "type": "string",
424
+ "default": "main"
425
+ },
426
+ "useHttp": {
427
+ "type": "boolean"
428
+ },
429
+ "workers": {
430
+ "anyOf": [
431
+ {
432
+ "type": "number",
433
+ "minimum": 1
434
+ },
435
+ {
436
+ "type": "string"
437
+ }
438
+ ]
439
+ },
440
+ "health": {
441
+ "type": "object",
442
+ "default": {},
443
+ "properties": {
444
+ "enabled": {
445
+ "anyOf": [
446
+ {
447
+ "type": "boolean"
448
+ },
449
+ {
450
+ "type": "string"
451
+ }
452
+ ]
453
+ },
454
+ "interval": {
455
+ "anyOf": [
456
+ {
457
+ "type": "number",
458
+ "minimum": 0
459
+ },
460
+ {
461
+ "type": "string"
462
+ }
463
+ ]
464
+ },
465
+ "gracePeriod": {
466
+ "anyOf": [
467
+ {
468
+ "type": "number",
469
+ "minimum": 0
470
+ },
471
+ {
472
+ "type": "string"
473
+ }
474
+ ]
475
+ },
476
+ "maxUnhealthyChecks": {
477
+ "anyOf": [
478
+ {
479
+ "type": "number",
480
+ "minimum": 1
481
+ },
482
+ {
483
+ "type": "string"
484
+ }
485
+ ]
486
+ },
487
+ "maxELU": {
488
+ "anyOf": [
489
+ {
490
+ "type": "number",
491
+ "minimum": 0,
492
+ "maximum": 1
493
+ },
494
+ {
495
+ "type": "string"
496
+ }
497
+ ]
498
+ },
499
+ "maxHeapUsed": {
500
+ "anyOf": [
501
+ {
502
+ "type": "number",
503
+ "minimum": 0,
504
+ "maximum": 1
505
+ },
506
+ {
507
+ "type": "string"
508
+ }
509
+ ]
510
+ },
511
+ "maxHeapTotal": {
512
+ "anyOf": [
513
+ {
514
+ "type": "number",
515
+ "minimum": 0
516
+ },
517
+ {
518
+ "type": "string"
519
+ }
520
+ ]
521
+ },
522
+ "maxYoungGeneration": {
523
+ "anyOf": [
524
+ {
525
+ "type": "number",
526
+ "minimum": 0
527
+ },
528
+ {
529
+ "type": "string"
530
+ }
531
+ ]
532
+ }
533
+ },
534
+ "additionalProperties": false
535
+ },
536
+ "dependencies": {
537
+ "type": "array",
538
+ "items": {
539
+ "type": "string"
540
+ },
541
+ "default": []
542
+ },
543
+ "arguments": {
544
+ "type": "array",
545
+ "items": {
546
+ "type": "string"
547
+ }
548
+ },
549
+ "env": {
550
+ "type": "object",
551
+ "additionalProperties": {
552
+ "type": "string"
553
+ }
554
+ },
555
+ "envfile": {
556
+ "type": "string"
557
+ },
558
+ "sourceMaps": {
559
+ "type": "boolean",
560
+ "default": false
561
+ },
562
+ "packageManager": {
563
+ "type": "string",
564
+ "enum": [
565
+ "npm",
566
+ "pnpm",
567
+ "yarn"
568
+ ]
569
+ },
570
+ "preload": {
571
+ "anyOf": [
572
+ {
573
+ "type": "string",
574
+ "resolvePath": true
575
+ },
576
+ {
577
+ "type": "array",
578
+ "items": {
579
+ "type": "string",
580
+ "resolvePath": true
581
+ }
582
+ }
583
+ ]
584
+ },
585
+ "nodeOptions": {
586
+ "type": "string"
587
+ },
588
+ "telemetry": {
589
+ "type": "object",
590
+ "properties": {
591
+ "instrumentations": {
592
+ "type": "array",
593
+ "description": "An array of instrumentations loaded if telemetry is enabled",
594
+ "items": {
595
+ "oneOf": [
596
+ {
597
+ "type": "string"
598
+ },
599
+ {
600
+ "type": "object",
601
+ "properties": {
602
+ "package": {
603
+ "type": "string"
604
+ },
605
+ "exportName": {
606
+ "type": "string"
607
+ },
608
+ "options": {
609
+ "type": "object",
610
+ "additionalProperties": true
611
+ }
612
+ },
613
+ "required": [
614
+ "package"
615
+ ]
616
+ }
617
+ ]
618
+ }
619
+ }
620
+ }
621
+ }
622
+ }
623
+ }
624
+ },
389
625
  "workers": {
390
626
  "anyOf": [
391
627
  {
@@ -700,7 +936,7 @@
700
936
  ],
701
937
  "default": 10000
702
938
  },
703
- "service": {
939
+ "application": {
704
940
  "anyOf": [
705
941
  {
706
942
  "type": "number",
@@ -716,7 +952,7 @@
716
952
  "default": {},
717
953
  "required": [
718
954
  "runtime",
719
- "service"
955
+ "application"
720
956
  ],
721
957
  "additionalProperties": false
722
958
  },
@@ -1147,13 +1383,13 @@
1147
1383
  }
1148
1384
  ]
1149
1385
  },
1150
- "serviceName": {
1386
+ "applicationName": {
1151
1387
  "type": "string",
1152
- "description": "The name of the service. Defaults to the folder name if not specified."
1388
+ "description": "The name of the application. Defaults to the folder name if not specified."
1153
1389
  },
1154
1390
  "version": {
1155
1391
  "type": "string",
1156
- "description": "The version of the service (optional)"
1392
+ "description": "The version of the application (optional)"
1157
1393
  },
1158
1394
  "skip": {
1159
1395
  "type": "array",
@@ -1260,7 +1496,7 @@
1260
1496
  }
1261
1497
  },
1262
1498
  "required": [
1263
- "serviceName"
1499
+ "applicationName"
1264
1500
  ],
1265
1501
  "additionalProperties": false
1266
1502
  },
@@ -1281,7 +1517,7 @@
1281
1517
  }
1282
1518
  }
1283
1519
  },
1284
- "serviceTimeout": {
1520
+ "applicationTimeout": {
1285
1521
  "anyOf": [
1286
1522
  {
1287
1523
  "type": "number",
@@ -1391,7 +1627,7 @@
1391
1627
  "type": "string"
1392
1628
  },
1393
1629
  "absoluteUrl": {
1394
- "description": "This Node.js application requires the Absolute URL from the Composer",
1630
+ "description": "This Node.js application requires the Absolute URL from the Gateway",
1395
1631
  "type": "boolean",
1396
1632
  "default": false
1397
1633
  },