@platformatic/db 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
@@ -404,11 +404,11 @@ export interface PlatformaticDatabaseConfig {
404
404
  telemetry?: {
405
405
  enabled?: boolean | string;
406
406
  /**
407
- * The name of the service. Defaults to the folder name if not specified.
407
+ * The name of the application. Defaults to the folder name if not specified.
408
408
  */
409
- serviceName: string;
409
+ applicationName: string;
410
410
  /**
411
- * The version of the service (optional)
411
+ * The version of the application (optional)
412
412
  */
413
413
  version?: string;
414
414
  /**
@@ -480,6 +480,9 @@ export interface PlatformaticDatabaseConfig {
480
480
  runtime?: {
481
481
  preload?: string | string[];
482
482
  basePath?: string;
483
+ services?: {
484
+ [k: string]: unknown;
485
+ }[];
483
486
  workers?: number | string;
484
487
  logger?: {
485
488
  level: (
@@ -567,7 +570,7 @@ export interface PlatformaticDatabaseConfig {
567
570
  restartOnError?: boolean | number;
568
571
  gracefulShutdown?: {
569
572
  runtime: number | string;
570
- service: number | string;
573
+ application: number | string;
571
574
  };
572
575
  health?: {
573
576
  enabled?: boolean | string;
@@ -686,11 +689,11 @@ export interface PlatformaticDatabaseConfig {
686
689
  telemetry?: {
687
690
  enabled?: boolean | string;
688
691
  /**
689
- * The name of the service. Defaults to the folder name if not specified.
692
+ * The name of the application. Defaults to the folder name if not specified.
690
693
  */
691
- serviceName: string;
694
+ applicationName: string;
692
695
  /**
693
- * The version of the service (optional)
696
+ * The version of the application (optional)
694
697
  */
695
698
  version?: string;
696
699
  /**
@@ -766,7 +769,7 @@ export interface PlatformaticDatabaseConfig {
766
769
  watchDisabled?: boolean;
767
770
  [k: string]: unknown;
768
771
  };
769
- serviceTimeout?: number | string;
772
+ applicationTimeout?: number | string;
770
773
  messagingTimeout?: number | string;
771
774
  env?: {
772
775
  [k: string]: string;
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DBAuthorizationPluginInterface } from '@platformatic/db-authorization'
2
2
  import { Configuration, ConfigurationOptions } from '@platformatic/foundation'
3
3
  import { BaseGenerator } from '@platformatic/generators'
4
- import { PlatformaticApplication, ServiceStackable } from '@platformatic/service'
4
+ import { PlatformaticApplication, ServiceCapability } from '@platformatic/service'
5
5
  import { SQLEventsPluginInterface } from '@platformatic/sql-events'
6
6
  import { Entities, SQLMapperPluginInterface } from '@platformatic/sql-mapper'
7
7
  import { JSONSchemaType } from 'ajv'
@@ -16,7 +16,7 @@ export type PlatformaticDatabaseMixin<T extends Entities> = SQLMapperPluginInter
16
16
  SQLEventsPluginInterface &
17
17
  DBAuthorizationPluginInterface
18
18
 
19
- export type DatabaseStackable = ServiceStackable<PlatformaticDatabaseConfig>
19
+ export type DatabaseCapability = ServiceCapability<PlatformaticDatabaseConfig>
20
20
 
21
21
  export type ServerInstance<T = {}> = FastifyInstance & {
22
22
  platformatic: PlatformaticApplication<PlatformaticDatabaseConfig> & PlatformaticDatabaseMixin<Entities> & T
@@ -38,11 +38,11 @@ export declare function create (
38
38
  root: string,
39
39
  source?: string | PlatformaticDatabaseConfig,
40
40
  context?: ConfigurationOptions
41
- ): Promise<ServiceStackable>
41
+ ): Promise<ServiceCapability>
42
42
 
43
43
  export declare const skipTelemetryHooks: boolean
44
44
 
45
- export declare function platformaticDatabase (app: FastifyInstance, stackable: DatabaseStackable): Promise<void>
45
+ export declare function platformaticDatabase (app: FastifyInstance, capability: DatabaseCapability): Promise<void>
46
46
 
47
47
  export declare class Generator extends BaseGenerator.BaseGenerator {}
48
48
 
package/index.js CHANGED
@@ -3,8 +3,8 @@ import { kMetadata, loadConfiguration as utilsLoadConfiguration } from '@platfor
3
3
  import { transform as serviceTransform } from '@platformatic/service'
4
4
  import { readFile } from 'node:fs/promises'
5
5
  import { resolve as resolvePath } from 'node:path'
6
+ import { DatabaseCapability } from './lib/capability.js'
6
7
  import { schema } from './lib/schema.js'
7
- import { DatabaseStackable } from './lib/stackable.js'
8
8
  import { upgrade } from './lib/upgrade.js'
9
9
 
10
10
  export async function transform (config) {
@@ -71,15 +71,15 @@ export async function loadConfiguration (configOrRoot, sourceOrConfig, context)
71
71
 
72
72
  export async function create (configOrRoot, sourceOrConfig, context) {
73
73
  const config = await loadConfiguration(configOrRoot, sourceOrConfig, context)
74
- return new DatabaseStackable(config[kMetadata].root, config, context)
74
+ return new DatabaseCapability(config[kMetadata].root, config, context)
75
75
  }
76
76
 
77
77
  export const skipTelemetryHooks = true
78
78
 
79
79
  export { platformaticDatabase } from './lib/application.js'
80
+ export { DatabaseCapability } from './lib/capability.js'
80
81
  export * from './lib/commands/index.js'
81
82
  export * from './lib/errors.js'
82
83
  export * as errors from './lib/errors.js'
83
84
  export { Generator } from './lib/generator.js'
84
85
  export { packageJson, schema, schemaComponents, version } from './lib/schema.js'
85
- export { DatabaseStackable } from './lib/stackable.js'
@@ -19,8 +19,8 @@ async function healthCheck (app) {
19
19
  }
20
20
  }
21
21
 
22
- export async function platformaticDatabase (app, stackable) {
23
- const config = await stackable.getConfig(true)
22
+ export async function platformaticDatabase (app, capability) {
23
+ const config = await capability.getConfig(true)
24
24
 
25
25
  let createSchemaLock = false
26
26
  await loadSchemaLock()
@@ -66,7 +66,7 @@ export async function platformaticDatabase (app, stackable) {
66
66
  }
67
67
 
68
68
  serverConfig.healthCheck.fn = healthCheck
69
- await stackable.updateContext({ serverConfig })
69
+ await capability.updateContext({ serverConfig })
70
70
  }
71
71
 
72
72
  if (createSchemaLock) {
@@ -85,7 +85,7 @@ export async function platformaticDatabase (app, stackable) {
85
85
  await app.register(auth, config.authorization)
86
86
  }
87
87
 
88
- await platformaticService(app, stackable)
88
+ await platformaticService(app, capability)
89
89
 
90
90
  if (Object.keys(app.platformatic.entities).length === 0) {
91
91
  app.log.warn(
@@ -1,8 +1,8 @@
1
- import { ServiceStackable } from '@platformatic/service'
1
+ import { ServiceCapability } from '@platformatic/service'
2
2
  import { platformaticDatabase } from './application.js'
3
3
  import { packageJson } from './schema.js'
4
4
 
5
- export class DatabaseStackable extends ServiceStackable {
5
+ export class DatabaseCapability extends ServiceCapability {
6
6
  constructor (root, config, context) {
7
7
  super(root, config, context)
8
8
  this.type = 'db'
@@ -20,16 +20,16 @@ export class DatabaseStackable extends ServiceStackable {
20
20
  }
21
21
 
22
22
  async getMeta () {
23
- const serviceMeta = await super.getMeta()
23
+ const applicationMeta = await super.getMeta()
24
24
  const connectionString = this.config.db?.connectionString
25
25
 
26
26
  if (connectionString) {
27
27
  return {
28
- ...serviceMeta,
28
+ ...applicationMeta,
29
29
  connectionStrings: [connectionString]
30
30
  }
31
31
  }
32
32
 
33
- return serviceMeta
33
+ return applicationMeta
34
34
  }
35
35
  }
package/lib/errors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import createError from '@fastify/error'
2
2
 
3
- const ERROR_PREFIX = 'PLT_DB'
3
+ export const ERROR_PREFIX = 'PLT_DB'
4
4
 
5
5
  export const MigrateMissingMigrationsError = createError(
6
6
  `${ERROR_PREFIX}_MIGRATE_ERROR`,
package/lib/generator.js CHANGED
@@ -195,7 +195,7 @@ export class Generator extends ServiceGenerator {
195
195
 
196
196
  async _getConfigFileContents () {
197
197
  const config = await super._getConfigFileContents()
198
- delete config.service
198
+ delete config.application
199
199
  config.$schema = `https://schemas.platformatic.dev/@platformatic/db/${this.platformaticVersion}.json`
200
200
 
201
201
  config.db = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/db",
3
- "version": "3.0.0-alpha.5",
3
+ "version": "3.0.0-alpha.8",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -21,8 +21,8 @@
21
21
  "@opentelemetry/api": "^1.9.0",
22
22
  "ajv": "^8.12.0",
23
23
  "bindings": "^1.5.0",
24
- "borp": "^0.20.0",
25
24
  "c8": "^10.0.0",
25
+ "cleaner-spec-reporter": "^0.5.0",
26
26
  "eslint": "9",
27
27
  "execa": "^9.0.0",
28
28
  "json-schema-to-typescript": "^15.0.0",
@@ -30,7 +30,7 @@
30
30
  "neostandard": "^0.12.0",
31
31
  "openapi-types": "^12.1.3",
32
32
  "split2": "^4.2.0",
33
- "tsd": "^0.32.0",
33
+ "tsd": "^0.33.0",
34
34
  "typescript": "^5.5.4",
35
35
  "undici": "^7.0.0",
36
36
  "vscode-json-languageservice": "^5.3.9",
@@ -66,27 +66,27 @@
66
66
  "rfdc": "^1.3.1",
67
67
  "rimraf": "^4.4.1",
68
68
  "semgrator": "^0.3.0",
69
- "@platformatic/basic": "3.0.0-alpha.5",
70
- "@platformatic/db-authorization": "3.0.0-alpha.5",
71
- "@platformatic/db-core": "3.0.0-alpha.5",
72
- "@platformatic/generators": "3.0.0-alpha.5",
73
- "@platformatic/service": "3.0.0-alpha.5",
74
- "@platformatic/sql-events": "3.0.0-alpha.5",
75
- "@platformatic/sql-graphql": "3.0.0-alpha.5",
76
- "@platformatic/sql-json-schema-mapper": "3.0.0-alpha.5",
77
- "@platformatic/sql-mapper": "3.0.0-alpha.5",
78
- "@platformatic/telemetry": "3.0.0-alpha.5",
79
- "@platformatic/foundation": "3.0.0-alpha.5",
80
- "@platformatic/sql-openapi": "3.0.0-alpha.5"
69
+ "@platformatic/basic": "3.0.0-alpha.8",
70
+ "@platformatic/db-core": "3.0.0-alpha.8",
71
+ "@platformatic/generators": "3.0.0-alpha.8",
72
+ "@platformatic/db-authorization": "3.0.0-alpha.8",
73
+ "@platformatic/service": "3.0.0-alpha.8",
74
+ "@platformatic/sql-events": "3.0.0-alpha.8",
75
+ "@platformatic/sql-graphql": "3.0.0-alpha.8",
76
+ "@platformatic/foundation": "3.0.0-alpha.8",
77
+ "@platformatic/sql-json-schema-mapper": "3.0.0-alpha.8",
78
+ "@platformatic/sql-mapper": "3.0.0-alpha.8",
79
+ "@platformatic/sql-openapi": "3.0.0-alpha.8",
80
+ "@platformatic/telemetry": "3.0.0-alpha.8"
81
81
  },
82
82
  "engines": {
83
83
  "node": ">=22.18.0"
84
84
  },
85
85
  "scripts": {
86
- "test": "pnpm run lint && borp -T --concurrency=1 --timeout 1200000",
86
+ "test": "node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/*.test.js test/**/*.test.js",
87
87
  "gen-schema": "node lib/schema.js > schema.json",
88
88
  "gen-types": "json2ts > config.d.ts < schema.json",
89
- "build": "pnpm run gen-schema && pnpm run gen-types",
89
+ "build": "npm run gen-schema && npm run gen-types",
90
90
  "lint": "eslint"
91
91
  }
92
92
  }
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/db/3.0.0-alpha.5.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/db/3.0.0-alpha.8.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Database Config",
5
5
  "type": "object",
@@ -1187,13 +1187,13 @@
1187
1187
  }
1188
1188
  ]
1189
1189
  },
1190
- "serviceName": {
1190
+ "applicationName": {
1191
1191
  "type": "string",
1192
- "description": "The name of the service. Defaults to the folder name if not specified."
1192
+ "description": "The name of the application. Defaults to the folder name if not specified."
1193
1193
  },
1194
1194
  "version": {
1195
1195
  "type": "string",
1196
- "description": "The version of the service (optional)"
1196
+ "description": "The version of the application (optional)"
1197
1197
  },
1198
1198
  "skip": {
1199
1199
  "type": "array",
@@ -1300,7 +1300,7 @@
1300
1300
  }
1301
1301
  },
1302
1302
  "required": [
1303
- "serviceName"
1303
+ "applicationName"
1304
1304
  ],
1305
1305
  "additionalProperties": false
1306
1306
  },
@@ -1325,6 +1325,242 @@
1325
1325
  "basePath": {
1326
1326
  "type": "string"
1327
1327
  },
1328
+ "services": {
1329
+ "type": "array",
1330
+ "items": {
1331
+ "type": "object",
1332
+ "anyOf": [
1333
+ {
1334
+ "required": [
1335
+ "id",
1336
+ "path"
1337
+ ]
1338
+ },
1339
+ {
1340
+ "required": [
1341
+ "id",
1342
+ "url"
1343
+ ]
1344
+ }
1345
+ ],
1346
+ "properties": {
1347
+ "id": {
1348
+ "type": "string"
1349
+ },
1350
+ "path": {
1351
+ "type": "string",
1352
+ "allowEmptyPaths": true,
1353
+ "resolvePath": true
1354
+ },
1355
+ "config": {
1356
+ "type": "string"
1357
+ },
1358
+ "url": {
1359
+ "type": "string"
1360
+ },
1361
+ "gitBranch": {
1362
+ "type": "string",
1363
+ "default": "main"
1364
+ },
1365
+ "useHttp": {
1366
+ "type": "boolean"
1367
+ },
1368
+ "workers": {
1369
+ "anyOf": [
1370
+ {
1371
+ "type": "number",
1372
+ "minimum": 1
1373
+ },
1374
+ {
1375
+ "type": "string"
1376
+ }
1377
+ ]
1378
+ },
1379
+ "health": {
1380
+ "type": "object",
1381
+ "default": {},
1382
+ "properties": {
1383
+ "enabled": {
1384
+ "anyOf": [
1385
+ {
1386
+ "type": "boolean"
1387
+ },
1388
+ {
1389
+ "type": "string"
1390
+ }
1391
+ ]
1392
+ },
1393
+ "interval": {
1394
+ "anyOf": [
1395
+ {
1396
+ "type": "number",
1397
+ "minimum": 0
1398
+ },
1399
+ {
1400
+ "type": "string"
1401
+ }
1402
+ ]
1403
+ },
1404
+ "gracePeriod": {
1405
+ "anyOf": [
1406
+ {
1407
+ "type": "number",
1408
+ "minimum": 0
1409
+ },
1410
+ {
1411
+ "type": "string"
1412
+ }
1413
+ ]
1414
+ },
1415
+ "maxUnhealthyChecks": {
1416
+ "anyOf": [
1417
+ {
1418
+ "type": "number",
1419
+ "minimum": 1
1420
+ },
1421
+ {
1422
+ "type": "string"
1423
+ }
1424
+ ]
1425
+ },
1426
+ "maxELU": {
1427
+ "anyOf": [
1428
+ {
1429
+ "type": "number",
1430
+ "minimum": 0,
1431
+ "maximum": 1
1432
+ },
1433
+ {
1434
+ "type": "string"
1435
+ }
1436
+ ]
1437
+ },
1438
+ "maxHeapUsed": {
1439
+ "anyOf": [
1440
+ {
1441
+ "type": "number",
1442
+ "minimum": 0,
1443
+ "maximum": 1
1444
+ },
1445
+ {
1446
+ "type": "string"
1447
+ }
1448
+ ]
1449
+ },
1450
+ "maxHeapTotal": {
1451
+ "anyOf": [
1452
+ {
1453
+ "type": "number",
1454
+ "minimum": 0
1455
+ },
1456
+ {
1457
+ "type": "string"
1458
+ }
1459
+ ]
1460
+ },
1461
+ "maxYoungGeneration": {
1462
+ "anyOf": [
1463
+ {
1464
+ "type": "number",
1465
+ "minimum": 0
1466
+ },
1467
+ {
1468
+ "type": "string"
1469
+ }
1470
+ ]
1471
+ }
1472
+ },
1473
+ "additionalProperties": false
1474
+ },
1475
+ "dependencies": {
1476
+ "type": "array",
1477
+ "items": {
1478
+ "type": "string"
1479
+ },
1480
+ "default": []
1481
+ },
1482
+ "arguments": {
1483
+ "type": "array",
1484
+ "items": {
1485
+ "type": "string"
1486
+ }
1487
+ },
1488
+ "env": {
1489
+ "type": "object",
1490
+ "additionalProperties": {
1491
+ "type": "string"
1492
+ }
1493
+ },
1494
+ "envfile": {
1495
+ "type": "string"
1496
+ },
1497
+ "sourceMaps": {
1498
+ "type": "boolean",
1499
+ "default": false
1500
+ },
1501
+ "packageManager": {
1502
+ "type": "string",
1503
+ "enum": [
1504
+ "npm",
1505
+ "pnpm",
1506
+ "yarn"
1507
+ ]
1508
+ },
1509
+ "preload": {
1510
+ "anyOf": [
1511
+ {
1512
+ "type": "string",
1513
+ "resolvePath": true
1514
+ },
1515
+ {
1516
+ "type": "array",
1517
+ "items": {
1518
+ "type": "string",
1519
+ "resolvePath": true
1520
+ }
1521
+ }
1522
+ ]
1523
+ },
1524
+ "nodeOptions": {
1525
+ "type": "string"
1526
+ },
1527
+ "telemetry": {
1528
+ "type": "object",
1529
+ "properties": {
1530
+ "instrumentations": {
1531
+ "type": "array",
1532
+ "description": "An array of instrumentations loaded if telemetry is enabled",
1533
+ "items": {
1534
+ "oneOf": [
1535
+ {
1536
+ "type": "string"
1537
+ },
1538
+ {
1539
+ "type": "object",
1540
+ "properties": {
1541
+ "package": {
1542
+ "type": "string"
1543
+ },
1544
+ "exportName": {
1545
+ "type": "string"
1546
+ },
1547
+ "options": {
1548
+ "type": "object",
1549
+ "additionalProperties": true
1550
+ }
1551
+ },
1552
+ "required": [
1553
+ "package"
1554
+ ]
1555
+ }
1556
+ ]
1557
+ }
1558
+ }
1559
+ }
1560
+ }
1561
+ }
1562
+ }
1563
+ },
1328
1564
  "workers": {
1329
1565
  "anyOf": [
1330
1566
  {
@@ -1639,7 +1875,7 @@
1639
1875
  ],
1640
1876
  "default": 10000
1641
1877
  },
1642
- "service": {
1878
+ "application": {
1643
1879
  "anyOf": [
1644
1880
  {
1645
1881
  "type": "number",
@@ -1655,7 +1891,7 @@
1655
1891
  "default": {},
1656
1892
  "required": [
1657
1893
  "runtime",
1658
- "service"
1894
+ "application"
1659
1895
  ],
1660
1896
  "additionalProperties": false
1661
1897
  },
@@ -2086,13 +2322,13 @@
2086
2322
  }
2087
2323
  ]
2088
2324
  },
2089
- "serviceName": {
2325
+ "applicationName": {
2090
2326
  "type": "string",
2091
- "description": "The name of the service. Defaults to the folder name if not specified."
2327
+ "description": "The name of the application. Defaults to the folder name if not specified."
2092
2328
  },
2093
2329
  "version": {
2094
2330
  "type": "string",
2095
- "description": "The version of the service (optional)"
2331
+ "description": "The version of the application (optional)"
2096
2332
  },
2097
2333
  "skip": {
2098
2334
  "type": "array",
@@ -2199,7 +2435,7 @@
2199
2435
  }
2200
2436
  },
2201
2437
  "required": [
2202
- "serviceName"
2438
+ "applicationName"
2203
2439
  ],
2204
2440
  "additionalProperties": false
2205
2441
  },
@@ -2220,7 +2456,7 @@
2220
2456
  }
2221
2457
  }
2222
2458
  },
2223
- "serviceTimeout": {
2459
+ "applicationTimeout": {
2224
2460
  "anyOf": [
2225
2461
  {
2226
2462
  "type": "number",