@platformatic/db 3.0.0-alpha.5 → 3.0.0-alpha.6

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.6",
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",
@@ -66,24 +66,24 @@
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.6",
70
+ "@platformatic/db-core": "3.0.0-alpha.6",
71
+ "@platformatic/foundation": "3.0.0-alpha.6",
72
+ "@platformatic/db-authorization": "3.0.0-alpha.6",
73
+ "@platformatic/generators": "3.0.0-alpha.6",
74
+ "@platformatic/service": "3.0.0-alpha.6",
75
+ "@platformatic/sql-events": "3.0.0-alpha.6",
76
+ "@platformatic/sql-graphql": "3.0.0-alpha.6",
77
+ "@platformatic/sql-json-schema-mapper": "3.0.0-alpha.6",
78
+ "@platformatic/sql-mapper": "3.0.0-alpha.6",
79
+ "@platformatic/sql-openapi": "3.0.0-alpha.6",
80
+ "@platformatic/telemetry": "3.0.0-alpha.6"
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
89
  "build": "pnpm run gen-schema && pnpm run gen-types",
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.6.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,235 @@
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
+ "arguments": {
1476
+ "type": "array",
1477
+ "items": {
1478
+ "type": "string"
1479
+ }
1480
+ },
1481
+ "env": {
1482
+ "type": "object",
1483
+ "additionalProperties": {
1484
+ "type": "string"
1485
+ }
1486
+ },
1487
+ "envfile": {
1488
+ "type": "string"
1489
+ },
1490
+ "sourceMaps": {
1491
+ "type": "boolean",
1492
+ "default": false
1493
+ },
1494
+ "packageManager": {
1495
+ "type": "string",
1496
+ "enum": [
1497
+ "npm",
1498
+ "pnpm",
1499
+ "yarn"
1500
+ ]
1501
+ },
1502
+ "preload": {
1503
+ "anyOf": [
1504
+ {
1505
+ "type": "string",
1506
+ "resolvePath": true
1507
+ },
1508
+ {
1509
+ "type": "array",
1510
+ "items": {
1511
+ "type": "string",
1512
+ "resolvePath": true
1513
+ }
1514
+ }
1515
+ ]
1516
+ },
1517
+ "nodeOptions": {
1518
+ "type": "string"
1519
+ },
1520
+ "telemetry": {
1521
+ "type": "object",
1522
+ "properties": {
1523
+ "instrumentations": {
1524
+ "type": "array",
1525
+ "description": "An array of instrumentations loaded if telemetry is enabled",
1526
+ "items": {
1527
+ "oneOf": [
1528
+ {
1529
+ "type": "string"
1530
+ },
1531
+ {
1532
+ "type": "object",
1533
+ "properties": {
1534
+ "package": {
1535
+ "type": "string"
1536
+ },
1537
+ "exportName": {
1538
+ "type": "string"
1539
+ },
1540
+ "options": {
1541
+ "type": "object",
1542
+ "additionalProperties": true
1543
+ }
1544
+ },
1545
+ "required": [
1546
+ "package"
1547
+ ]
1548
+ }
1549
+ ]
1550
+ }
1551
+ }
1552
+ }
1553
+ }
1554
+ }
1555
+ }
1556
+ },
1328
1557
  "workers": {
1329
1558
  "anyOf": [
1330
1559
  {
@@ -1639,7 +1868,7 @@
1639
1868
  ],
1640
1869
  "default": 10000
1641
1870
  },
1642
- "service": {
1871
+ "application": {
1643
1872
  "anyOf": [
1644
1873
  {
1645
1874
  "type": "number",
@@ -1655,7 +1884,7 @@
1655
1884
  "default": {},
1656
1885
  "required": [
1657
1886
  "runtime",
1658
- "service"
1887
+ "application"
1659
1888
  ],
1660
1889
  "additionalProperties": false
1661
1890
  },
@@ -2086,13 +2315,13 @@
2086
2315
  }
2087
2316
  ]
2088
2317
  },
2089
- "serviceName": {
2318
+ "applicationName": {
2090
2319
  "type": "string",
2091
- "description": "The name of the service. Defaults to the folder name if not specified."
2320
+ "description": "The name of the application. Defaults to the folder name if not specified."
2092
2321
  },
2093
2322
  "version": {
2094
2323
  "type": "string",
2095
- "description": "The version of the service (optional)"
2324
+ "description": "The version of the application (optional)"
2096
2325
  },
2097
2326
  "skip": {
2098
2327
  "type": "array",
@@ -2199,7 +2428,7 @@
2199
2428
  }
2200
2429
  },
2201
2430
  "required": [
2202
- "serviceName"
2431
+ "applicationName"
2203
2432
  ],
2204
2433
  "additionalProperties": false
2205
2434
  },
@@ -2220,7 +2449,7 @@
2220
2449
  }
2221
2450
  }
2222
2451
  },
2223
- "serviceTimeout": {
2452
+ "applicationTimeout": {
2224
2453
  "anyOf": [
2225
2454
  {
2226
2455
  "type": "number",