@platformatic/db 2.72.0 → 3.0.0-alpha.1
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 +1 -19
- package/eslint.config.js +9 -5
- package/index.d.ts +56 -31
- package/index.js +67 -128
- package/lib/application.js +102 -0
- package/lib/commands/index.js +59 -0
- package/lib/commands/migrations-apply.js +62 -0
- package/lib/commands/migrations-create.js +48 -0
- package/lib/commands/print-schema.js +30 -0
- package/lib/commands/seed.js +88 -0
- package/lib/commands/types.js +21 -0
- package/lib/errors.js +15 -11
- package/lib/{generator/db-generator.js → generator.js} +57 -52
- package/lib/{migrator.mjs → migrator.js} +45 -37
- package/lib/{root-endpoint/index.js → root.js} +6 -7
- package/lib/schema.js +31 -21
- package/lib/stackable.js +14 -26
- package/lib/{generator/code-templates.js → templates.js} +47 -17
- package/lib/types.js +160 -0
- package/lib/upgrade.js +7 -10
- package/lib/utils.js +12 -23
- package/lib/versions/0.18.0.js +3 -5
- package/lib/versions/{from-zero-twenty-height-to-will-see.js → 0.28.0.js} +3 -5
- package/lib/versions/2.0.0.js +3 -5
- package/package.json +16 -23
- package/schema.json +2 -73
- package/tsconfig.json +16 -6
- package/.snapshots/810d795d512560f3863d8db472c81c27/0.json +0 -1
- package/.snapshots/810d795d512560f3863d8db472c81c27/1.json +0 -1
- package/db.mjs +0 -86
- package/help/compile.txt +0 -17
- package/help/create.txt +0 -13
- package/help/help.txt +0 -11
- package/help/migrations apply.txt +0 -45
- package/help/migrations create.txt +0 -27
- package/help/migrations.txt +0 -4
- package/help/schema.txt +0 -25
- package/help/seed.txt +0 -36
- package/help/start.txt +0 -47
- package/help/types.txt +0 -40
- package/index.test-d.ts +0 -43
- package/lib/adjust-config.js +0 -42
- package/lib/create.mjs +0 -89
- package/lib/gen-migration.mjs +0 -53
- package/lib/gen-schema.mjs +0 -68
- package/lib/gen-types.mjs +0 -202
- package/lib/generator/README.md +0 -38
- package/lib/generator.d.ts +0 -7
- package/lib/migrate.mjs +0 -87
- package/lib/seed.mjs +0 -90
- /package/{lib/root-endpoint/public → public}/images/dark_mode.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/favicon.ico +0 -0
- /package/{lib/root-endpoint/public → public}/images/light_mode.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/platformatic-logo-dark.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/platformatic-logo-light.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/triangle_dark.svg +0 -0
- /package/{lib/root-endpoint/public → public}/images/triangle_light.svg +0 -0
- /package/{lib/root-endpoint/public → public}/index.html +0 -0
package/lib/stackable.js
CHANGED
|
@@ -1,38 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
import { ServiceStackable } from '@platformatic/service'
|
|
2
|
+
import { platformaticDatabase } from './application.js'
|
|
3
|
+
import { packageJson } from './schema.js'
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
export class DatabaseStackable extends ServiceStackable {
|
|
6
|
+
constructor (root, config, context) {
|
|
7
|
+
super(root, config, context)
|
|
8
|
+
this.type = 'db'
|
|
9
|
+
this.version = packageJson.version
|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
constructor (options) {
|
|
7
|
-
super(options)
|
|
8
|
-
this.#updateConfig()
|
|
11
|
+
this.applicationFactory = this.context.applicationFactory ?? platformaticDatabase
|
|
9
12
|
}
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
updateContext (context) {
|
|
15
|
+
super.updateContext(context)
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (isProduction) {
|
|
18
|
-
if (config.autogenerate) {
|
|
19
|
-
config.autogenerate = false
|
|
20
|
-
}
|
|
17
|
+
if (this.context.isProduction && this.config.autogenerate) {
|
|
18
|
+
this.config.autogenerate = false
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
this.configManager.update(config)
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
async getMeta () {
|
|
27
|
-
await this.init()
|
|
28
|
-
await this.app.ready()
|
|
29
|
-
|
|
30
23
|
const serviceMeta = await super.getMeta()
|
|
31
|
-
|
|
32
|
-
const config = this.configManager.current
|
|
33
|
-
|
|
34
|
-
const dbConfig = config.db
|
|
35
|
-
const connectionString = dbConfig?.connectionString
|
|
24
|
+
const connectionString = this.config.db?.connectionString
|
|
36
25
|
|
|
37
26
|
if (connectionString) {
|
|
38
27
|
return {
|
|
@@ -44,4 +33,3 @@ class DbStackable extends ServiceStackable {
|
|
|
44
33
|
return serviceMeta
|
|
45
34
|
}
|
|
46
35
|
}
|
|
47
|
-
module.exports = { DbStackable }
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const jsHelperSqlite = {
|
|
1
|
+
export const jsHelperSqlite = {
|
|
4
2
|
requires: `
|
|
5
3
|
const os = require('node:os')
|
|
6
4
|
const path = require('node:path')
|
|
@@ -21,10 +19,10 @@ let counter = 0
|
|
|
21
19
|
t.after(async () => {
|
|
22
20
|
await fs.unlink(dbPath)
|
|
23
21
|
})
|
|
24
|
-
|
|
22
|
+
`
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
function jsHelperPostgres (connectionString) {
|
|
25
|
+
export function jsHelperPostgres (connectionString) {
|
|
28
26
|
return {
|
|
29
27
|
// TODO(mcollina): replace sql-mapper
|
|
30
28
|
requires: `
|
|
@@ -62,11 +60,11 @@ let counter = 0
|
|
|
62
60
|
\`)
|
|
63
61
|
await db.dispose()
|
|
64
62
|
})
|
|
65
|
-
|
|
63
|
+
`
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
function jsHelperMySQL (connectionString) {
|
|
67
|
+
export function jsHelperMySQL (connectionString) {
|
|
70
68
|
return {
|
|
71
69
|
// TODO(mcollina): replace sql-mapper
|
|
72
70
|
requires: `
|
|
@@ -104,11 +102,11 @@ let counter = 0
|
|
|
104
102
|
\`)
|
|
105
103
|
await db.dispose()
|
|
106
104
|
})
|
|
107
|
-
|
|
105
|
+
`
|
|
108
106
|
}
|
|
109
107
|
}
|
|
110
108
|
|
|
111
|
-
const moviesTestJS = `\
|
|
109
|
+
export const moviesTestJS = `\
|
|
112
110
|
'use strict'
|
|
113
111
|
|
|
114
112
|
const test = require('node:test')
|
|
@@ -160,7 +158,7 @@ test('movies', async (t) => {
|
|
|
160
158
|
})
|
|
161
159
|
`
|
|
162
160
|
|
|
163
|
-
const moviesTestTS = `\
|
|
161
|
+
export const moviesTestTS = `\
|
|
164
162
|
import test from 'node:test'
|
|
165
163
|
import assert from 'node:assert'
|
|
166
164
|
import { getServer } from '../helper'
|
|
@@ -210,10 +208,42 @@ test('movies', async (t) => {
|
|
|
210
208
|
})
|
|
211
209
|
`
|
|
212
210
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
211
|
+
export const README = `
|
|
212
|
+
# Platformatic DB API
|
|
213
|
+
|
|
214
|
+
This is a generated [Platformatic DB](https://docs.platformatic.dev/docs/db/overview) application.
|
|
215
|
+
|
|
216
|
+
## Requirements
|
|
217
|
+
|
|
218
|
+
Platformatic supports macOS, Linux and Windows ([WSL](https://docs.microsoft.com/windows/wsl/) recommended).
|
|
219
|
+
You'll need to have [Node.js](https://nodejs.org/) >= v18.8.0 or >= v20.6.0
|
|
220
|
+
|
|
221
|
+
## Setup
|
|
222
|
+
|
|
223
|
+
1. Install dependencies:
|
|
224
|
+
|
|
225
|
+
\`\`\`bash
|
|
226
|
+
npm install
|
|
227
|
+
\`\`\`
|
|
228
|
+
|
|
229
|
+
2. Apply migrations:
|
|
230
|
+
|
|
231
|
+
\`\`\`bash
|
|
232
|
+
npm run migrate
|
|
233
|
+
\`\`\`
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
## Usage
|
|
237
|
+
|
|
238
|
+
Run the API with:
|
|
239
|
+
|
|
240
|
+
\`\`\`bash
|
|
241
|
+
npm start
|
|
242
|
+
\`\`\`
|
|
243
|
+
|
|
244
|
+
### Explore
|
|
245
|
+
- ⚡ The Platformatic DB server is running at http://localhost:3042/
|
|
246
|
+
- 📔 View the REST API's Swagger documentation at http://localhost:3042/documentation/
|
|
247
|
+
- 🔍 Try out the GraphiQL web UI at http://localhost:3042/graphiql
|
|
248
|
+
|
|
249
|
+
`
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { mapOpenAPItoTypes, mapSQLEntityToJSONSchema } from '@platformatic/sql-json-schema-mapper'
|
|
2
|
+
import { createDirectory, isFileAccessible } from '@platformatic/utils'
|
|
3
|
+
import camelcase from 'camelcase'
|
|
4
|
+
import { readFile, readdir, unlink, writeFile } from 'node:fs/promises'
|
|
5
|
+
import { basename, join, relative, resolve, sep } from 'node:path'
|
|
6
|
+
import { setupDB } from './utils.js'
|
|
7
|
+
|
|
8
|
+
async function removeUnusedTypeFiles (entities, dir) {
|
|
9
|
+
const entityTypes = await readdir(dir)
|
|
10
|
+
const entityNames = Object.keys(entities)
|
|
11
|
+
const removedEntityNames = entityTypes.filter(
|
|
12
|
+
file => file !== 'index.d.ts' && !entityNames.includes(basename(file, '.d.ts'))
|
|
13
|
+
)
|
|
14
|
+
await Promise.all(removedEntityNames.map(file => unlink(join(dir, file))))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function generateEntityType (entity) {
|
|
18
|
+
const jsonSchema = mapSQLEntityToJSONSchema(entity)
|
|
19
|
+
const fieldDefinitions = Object.fromEntries(
|
|
20
|
+
Object.entries(entity.fields).map(([, value]) => [value.camelcase, value])
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
const tsCode = mapOpenAPItoTypes(jsonSchema, fieldDefinitions, { indentSpaces: 2 })
|
|
24
|
+
|
|
25
|
+
entity.name = camelcase(entity.name).replace(/^\w/, c => c.toUpperCase())
|
|
26
|
+
return tsCode.replaceAll(/^declare interface/gm, 'export interface')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function generateIndexTypes (entities) {
|
|
30
|
+
const allImports = []
|
|
31
|
+
const allExports = []
|
|
32
|
+
const entityMembers = []
|
|
33
|
+
const entityTypesMembers = []
|
|
34
|
+
const entitiesHooks = []
|
|
35
|
+
const schemaGetters = []
|
|
36
|
+
|
|
37
|
+
const values = Object.entries(entities)
|
|
38
|
+
.map(([file, entity]) => [file, entity.name])
|
|
39
|
+
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
40
|
+
|
|
41
|
+
for (const [name, type] of values) {
|
|
42
|
+
allImports.push(`import { ${type} } from './${name}'`)
|
|
43
|
+
allExports.push(`export { ${type} } from './${name}'`)
|
|
44
|
+
entityMembers.push(` ${name}: Entity<${type}>`)
|
|
45
|
+
entityTypesMembers.push(` ${name}: ${type}`)
|
|
46
|
+
entitiesHooks.push(` addEntityHooks(entityName: '${name}', hooks: EntityHooks<${type}>): any`)
|
|
47
|
+
schemaGetters.push(`getSchema(schemaId: '${name}'): {
|
|
48
|
+
'$id': string,
|
|
49
|
+
title: string,
|
|
50
|
+
description: string,
|
|
51
|
+
type: string,
|
|
52
|
+
properties: { [x in keyof ${type}]: { type: string, nullable?: boolean } },
|
|
53
|
+
required: string[]
|
|
54
|
+
}`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const content = `import { Entity, EntityHooks, Entities as DatabaseEntities, PlatformaticDatabaseConfig, PlatformaticDatabaseMixin } from '@platformatic/db'
|
|
58
|
+
import { PlatformaticApplication, PlatformaticServiceConfig } from '@platformatic/service'
|
|
59
|
+
import { FastifyInstance } from 'fastify'
|
|
60
|
+
|
|
61
|
+
${allImports.join('\n')}
|
|
62
|
+
|
|
63
|
+
${allExports.join('\n')}
|
|
64
|
+
|
|
65
|
+
export interface Entities extends DatabaseEntities {
|
|
66
|
+
${entityMembers.join('\n')}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface EntityTypes {
|
|
70
|
+
${entityTypesMembers.join('\n')}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface EntitiesHooks {
|
|
74
|
+
${entitiesHooks.join('\n')}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface SchemaGetters {
|
|
78
|
+
${schemaGetters.join('\n\n')}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type ServerInstance<Configuration = PlatformaticDatabaseConfig> = FastifyInstance & {
|
|
82
|
+
platformatic: PlatformaticApplication<Configuration> & PlatformaticDatabaseMixin<Entities> & EntitiesHooks & SchemaGetters
|
|
83
|
+
}
|
|
84
|
+
`
|
|
85
|
+
|
|
86
|
+
return content
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function generateEnvironmentTypes (folder) {
|
|
90
|
+
return `import { PlatformaticApplication, PlatformaticDatabaseConfig, PlatformaticDatabaseMixin } from "@platformatic/db";
|
|
91
|
+
import { Entities, EntitiesHooks, SchemaGetters } from "./${folder.replaceAll(sep, '/')}/index.js";
|
|
92
|
+
|
|
93
|
+
declare module "fastify" {
|
|
94
|
+
interface FastifyInstance {
|
|
95
|
+
platformatic: PlatformaticApplication<PlatformaticDatabaseConfig> & PlatformaticDatabaseMixin<Entities> & EntitiesHooks & SchemaGetters;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function writeFileIfChanged (filename, content) {
|
|
102
|
+
const isFileExists = await isFileAccessible(filename)
|
|
103
|
+
|
|
104
|
+
if (isFileExists) {
|
|
105
|
+
const fileContent = await readFile(filename, 'utf-8')
|
|
106
|
+
if (fileContent === content) {
|
|
107
|
+
return false
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
await writeFile(filename, content)
|
|
112
|
+
return true
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export async function execute ({ logger, config }) {
|
|
116
|
+
const wrap = await setupDB(logger, config.db)
|
|
117
|
+
const { db, entities } = wrap
|
|
118
|
+
|
|
119
|
+
const count = Object.keys(entities).length
|
|
120
|
+
if (count === 0) {
|
|
121
|
+
// do not generate types if no schema is found
|
|
122
|
+
return 0
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const typesFolderPath = resolve(process.cwd(), config.types?.dir ?? 'types')
|
|
126
|
+
|
|
127
|
+
// Prepare the types folder
|
|
128
|
+
if (await isFileAccessible(typesFolderPath)) {
|
|
129
|
+
await removeUnusedTypeFiles(entities, typesFolderPath)
|
|
130
|
+
} else {
|
|
131
|
+
await createDirectory(typesFolderPath)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Generate all entities
|
|
135
|
+
for (const [name, entity] of Object.entries(entities)) {
|
|
136
|
+
const types = await generateEntityType(entity)
|
|
137
|
+
const pathToFile = join(typesFolderPath, name + '.d.ts')
|
|
138
|
+
|
|
139
|
+
if (await writeFileIfChanged(pathToFile, types)) {
|
|
140
|
+
logger.info(`Generated type for ${entity.name} entity.`)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Generate index.d.ts
|
|
145
|
+
const indexFilePath = join(typesFolderPath, 'index.d.ts')
|
|
146
|
+
const indexTypes = await generateIndexTypes(entities)
|
|
147
|
+
if (await writeFileIfChanged(indexFilePath, indexTypes)) {
|
|
148
|
+
logger.info('Regenerated index.d.ts.')
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Generate plt-env.d.ts
|
|
152
|
+
const environmentPath = join(process.cwd(), 'plt-env.d.ts')
|
|
153
|
+
const pltEnvironment = await generateEnvironmentTypes(relative(process.cwd(), typesFolderPath))
|
|
154
|
+
if (await writeFileIfChanged(environmentPath, pltEnvironment)) {
|
|
155
|
+
logger.info('Regenerated plt-env.d.ts.')
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
await db.dispose()
|
|
159
|
+
return count
|
|
160
|
+
}
|
package/lib/upgrade.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import zeroSixteen from '@platformatic/service/lib/versions/0.16.0.js'
|
|
2
|
+
import { abstractLogger } from '@platformatic/utils'
|
|
3
|
+
import { join } from 'node:path'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
const zeroSixteen = require('@platformatic/service/lib/versions/0.16.0.js')
|
|
5
|
-
|
|
6
|
-
module.exports = async function upgrade (config, version) {
|
|
5
|
+
export async function upgrade (logger, config, version) {
|
|
7
6
|
const { semgrator, loadMigrationsFromPath } = await import('semgrator')
|
|
8
7
|
|
|
9
|
-
const iterator = loadMigrationsFromPath(join(
|
|
8
|
+
const iterator = loadMigrationsFromPath(join(import.meta.dirname, 'versions'))
|
|
10
9
|
|
|
11
|
-
const migrations = [
|
|
12
|
-
zeroSixteen,
|
|
13
|
-
]
|
|
10
|
+
const migrations = [zeroSixteen]
|
|
14
11
|
|
|
15
12
|
for await (const migration of iterator) {
|
|
16
13
|
migrations.push(migration)
|
|
@@ -20,7 +17,7 @@ module.exports = async function upgrade (config, version) {
|
|
|
20
17
|
version,
|
|
21
18
|
migrations,
|
|
22
19
|
input: config,
|
|
23
|
-
logger:
|
|
20
|
+
logger: logger?.child({ name: '@platformatic/db' }) ?? abstractLogger
|
|
24
21
|
})
|
|
25
22
|
|
|
26
23
|
let result
|
package/lib/utils.js
CHANGED
|
@@ -1,45 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
import { connect } from '@platformatic/db-core'
|
|
2
|
+
import { kMetadata } from '@platformatic/utils'
|
|
3
|
+
import fs from 'node:fs/promises'
|
|
4
|
+
import { dirname, join } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
const { join, dirname } = require('path')
|
|
5
|
-
const { fileURLToPath } = require('url')
|
|
6
|
-
const fs = require('fs/promises')
|
|
7
|
-
const { isFileAccessible } = require('@platformatic/utils')
|
|
8
|
-
|
|
9
|
-
async function setupDB (log, config) {
|
|
7
|
+
export async function setupDB (log, config) {
|
|
10
8
|
const { db, sql, entities, dbschema } = await connect({ ...config, log })
|
|
11
9
|
|
|
12
10
|
return {
|
|
13
11
|
db,
|
|
14
12
|
sql,
|
|
15
13
|
entities,
|
|
16
|
-
dbschema
|
|
14
|
+
dbschema
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
function urlDirname (url) {
|
|
18
|
+
export function urlDirname (url) {
|
|
21
19
|
return dirname(fileURLToPath(url))
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
function locateSchemaLock (
|
|
25
|
-
return
|
|
22
|
+
export function locateSchemaLock (config) {
|
|
23
|
+
return config.db.schemalock.path ?? join(config[kMetadata].root, 'schema.lock')
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
async function updateSchemaLock (logger,
|
|
29
|
-
const config = configManager.current
|
|
26
|
+
export async function updateSchemaLock (logger, config) {
|
|
30
27
|
if (config.db.schemalock) {
|
|
31
28
|
const conn = await setupDB(logger, { ...config.db, dbschema: null })
|
|
32
|
-
const schemaLockPath = locateSchemaLock(
|
|
29
|
+
const schemaLockPath = locateSchemaLock(config)
|
|
33
30
|
await fs.writeFile(schemaLockPath, JSON.stringify(conn.dbschema, null, 2))
|
|
34
31
|
|
|
35
32
|
await conn.db.dispose()
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
|
-
|
|
39
|
-
module.exports = {
|
|
40
|
-
setupDB,
|
|
41
|
-
isFileAccessible,
|
|
42
|
-
urlDirname,
|
|
43
|
-
updateSchemaLock,
|
|
44
|
-
locateSchemaLock,
|
|
45
|
-
}
|
package/lib/versions/0.18.0.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
module.exports.migration = {
|
|
1
|
+
export default {
|
|
4
2
|
version: '0.28.0',
|
|
5
|
-
up
|
|
3
|
+
up (config) {
|
|
6
4
|
if (config.watch !== false) {
|
|
7
5
|
config.watch = typeof config.watch === 'object' ? config.watch : {}
|
|
8
6
|
|
|
@@ -15,5 +13,5 @@ module.exports.migration = {
|
|
|
15
13
|
delete config.db?.dashboard
|
|
16
14
|
|
|
17
15
|
return config
|
|
18
|
-
}
|
|
16
|
+
}
|
|
19
17
|
}
|
package/lib/versions/2.0.0.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { version } from '../schema.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
3
|
+
export default {
|
|
6
4
|
version: '2.0.0',
|
|
7
5
|
up: function (config) {
|
|
8
|
-
config.$schema = `https://schemas.platformatic.dev/@platformatic/db/${
|
|
6
|
+
config.$schema = `https://schemas.platformatic.dev/@platformatic/db/${version}.json`
|
|
9
7
|
return config
|
|
10
8
|
}
|
|
11
9
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/db",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
|
-
"
|
|
8
|
-
"plt-db": "./db.mjs"
|
|
9
|
-
},
|
|
7
|
+
"type": "module",
|
|
10
8
|
"author": "Platformatic Inc. <oss@platformatic.dev> (https://platformatic.dev)",
|
|
11
9
|
"repository": {
|
|
12
10
|
"type": "git",
|
|
@@ -21,7 +19,6 @@
|
|
|
21
19
|
"@databases/pg": "^5.5.0",
|
|
22
20
|
"@databases/sql": "^3.3.0",
|
|
23
21
|
"@opentelemetry/api": "^1.8.0",
|
|
24
|
-
"@matteo.collina/snap": "^0.3.0",
|
|
25
22
|
"ajv": "^8.12.0",
|
|
26
23
|
"bindings": "^1.5.0",
|
|
27
24
|
"borp": "^0.20.0",
|
|
@@ -54,7 +51,6 @@
|
|
|
54
51
|
"code-block-writer": "^13.0.1",
|
|
55
52
|
"commist": "^3.2.0",
|
|
56
53
|
"console-table-printer": "^2.12.0",
|
|
57
|
-
"desm": "^1.3.1",
|
|
58
54
|
"env-schema": "^6.0.0",
|
|
59
55
|
"es-main": "^1.3.0",
|
|
60
56
|
"execa": "^9.0.0",
|
|
@@ -73,25 +69,22 @@
|
|
|
73
69
|
"rfdc": "^1.3.1",
|
|
74
70
|
"rimraf": "^4.4.1",
|
|
75
71
|
"semgrator": "^0.3.0",
|
|
76
|
-
"@platformatic/
|
|
77
|
-
"@platformatic/db-authorization": "
|
|
78
|
-
"@platformatic/
|
|
79
|
-
"@platformatic/
|
|
80
|
-
"@platformatic/service": "
|
|
81
|
-
"@platformatic/sql-events": "
|
|
82
|
-
"@platformatic/sql-graphql": "
|
|
83
|
-
"@platformatic/sql-json-schema-mapper": "
|
|
84
|
-
"@platformatic/sql-
|
|
85
|
-
"@platformatic/
|
|
86
|
-
"@platformatic/
|
|
87
|
-
"@platformatic/utils": "
|
|
88
|
-
"@platformatic/
|
|
72
|
+
"@platformatic/basic": "3.0.0-alpha.1",
|
|
73
|
+
"@platformatic/db-authorization": "3.0.0-alpha.1",
|
|
74
|
+
"@platformatic/generators": "3.0.0-alpha.1",
|
|
75
|
+
"@platformatic/db-core": "3.0.0-alpha.1",
|
|
76
|
+
"@platformatic/service": "3.0.0-alpha.1",
|
|
77
|
+
"@platformatic/sql-events": "3.0.0-alpha.1",
|
|
78
|
+
"@platformatic/sql-graphql": "3.0.0-alpha.1",
|
|
79
|
+
"@platformatic/sql-json-schema-mapper": "3.0.0-alpha.1",
|
|
80
|
+
"@platformatic/sql-mapper": "3.0.0-alpha.1",
|
|
81
|
+
"@platformatic/telemetry": "3.0.0-alpha.1",
|
|
82
|
+
"@platformatic/ts-compiler": "3.0.0-alpha.1",
|
|
83
|
+
"@platformatic/utils": "3.0.0-alpha.1",
|
|
84
|
+
"@platformatic/sql-openapi": "3.0.0-alpha.1"
|
|
89
85
|
},
|
|
90
86
|
"scripts": {
|
|
91
|
-
"test": "pnpm run lint && borp -T --concurrency=1 --timeout
|
|
92
|
-
"test:postgresql": "DB=postgresql borp -T --concurrency=1 --timeout=1200000",
|
|
93
|
-
"test:mariadb": "DB=mariadb borp -T --concurrency=1 --timeout=1200000",
|
|
94
|
-
"test:mysql": "DB=mysql borp -T --concurrency=1 --timeout=1200000",
|
|
87
|
+
"test": "pnpm run lint && borp -T --concurrency=1 --timeout 1200000",
|
|
95
88
|
"gen-schema": "node lib/schema.js > schema.json",
|
|
96
89
|
"gen-types": "json2ts > config.d.ts < schema.json",
|
|
97
90
|
"build": "pnpm run gen-schema && pnpm run gen-types",
|
package/schema.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://schemas.platformatic.dev/@platformatic/db/
|
|
2
|
+
"$id": "https://schemas.platformatic.dev/@platformatic/db/3.0.0-alpha.1.json",
|
|
3
3
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
|
-
"title": "Platformatic
|
|
4
|
+
"title": "Platformatic Database Config",
|
|
5
5
|
"type": "object",
|
|
6
6
|
"properties": {
|
|
7
7
|
"basePath": {
|
|
@@ -1038,77 +1038,6 @@
|
|
|
1038
1038
|
"dir"
|
|
1039
1039
|
]
|
|
1040
1040
|
},
|
|
1041
|
-
"metrics": {
|
|
1042
|
-
"anyOf": [
|
|
1043
|
-
{
|
|
1044
|
-
"type": "boolean"
|
|
1045
|
-
},
|
|
1046
|
-
{
|
|
1047
|
-
"type": "object",
|
|
1048
|
-
"properties": {
|
|
1049
|
-
"port": {
|
|
1050
|
-
"anyOf": [
|
|
1051
|
-
{
|
|
1052
|
-
"type": "integer"
|
|
1053
|
-
},
|
|
1054
|
-
{
|
|
1055
|
-
"type": "string"
|
|
1056
|
-
}
|
|
1057
|
-
]
|
|
1058
|
-
},
|
|
1059
|
-
"hostname": {
|
|
1060
|
-
"type": "string"
|
|
1061
|
-
},
|
|
1062
|
-
"endpoint": {
|
|
1063
|
-
"type": "string"
|
|
1064
|
-
},
|
|
1065
|
-
"server": {
|
|
1066
|
-
"type": "string",
|
|
1067
|
-
"enum": [
|
|
1068
|
-
"own",
|
|
1069
|
-
"parent",
|
|
1070
|
-
"hide"
|
|
1071
|
-
]
|
|
1072
|
-
},
|
|
1073
|
-
"defaultMetrics": {
|
|
1074
|
-
"type": "object",
|
|
1075
|
-
"properties": {
|
|
1076
|
-
"enabled": {
|
|
1077
|
-
"type": "boolean"
|
|
1078
|
-
}
|
|
1079
|
-
},
|
|
1080
|
-
"required": [
|
|
1081
|
-
"enabled"
|
|
1082
|
-
],
|
|
1083
|
-
"additionalProperties": false
|
|
1084
|
-
},
|
|
1085
|
-
"auth": {
|
|
1086
|
-
"type": "object",
|
|
1087
|
-
"properties": {
|
|
1088
|
-
"username": {
|
|
1089
|
-
"type": "string"
|
|
1090
|
-
},
|
|
1091
|
-
"password": {
|
|
1092
|
-
"type": "string"
|
|
1093
|
-
}
|
|
1094
|
-
},
|
|
1095
|
-
"additionalProperties": false,
|
|
1096
|
-
"required": [
|
|
1097
|
-
"username",
|
|
1098
|
-
"password"
|
|
1099
|
-
]
|
|
1100
|
-
},
|
|
1101
|
-
"labels": {
|
|
1102
|
-
"type": "object",
|
|
1103
|
-
"additionalProperties": {
|
|
1104
|
-
"type": "string"
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
},
|
|
1108
|
-
"additionalProperties": false
|
|
1109
|
-
}
|
|
1110
|
-
]
|
|
1111
|
-
},
|
|
1112
1041
|
"types": {
|
|
1113
1042
|
"type": "object",
|
|
1114
1043
|
"properties": {
|
package/tsconfig.json
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"module": "
|
|
4
|
-
"moduleResolution": "node",
|
|
3
|
+
"module": "commonjs",
|
|
5
4
|
"esModuleInterop": true,
|
|
6
|
-
"
|
|
7
|
-
"target": "
|
|
8
|
-
"outDir": "build",
|
|
5
|
+
"lib": ["es2022"],
|
|
6
|
+
"target": "es2022",
|
|
9
7
|
"sourceMap": true,
|
|
10
|
-
"
|
|
8
|
+
"pretty": true,
|
|
9
|
+
"noEmitOnError": true,
|
|
10
|
+
"incremental": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"outDir": "dist",
|
|
13
|
+
"skipLibCheck": true
|
|
14
|
+
},
|
|
15
|
+
"watchOptions": {
|
|
16
|
+
"watchFile": "fixedPollingInterval",
|
|
17
|
+
"watchDirectory": "fixedPollingInterval",
|
|
18
|
+
"fallbackPolling": "dynamicPriority",
|
|
19
|
+
"synchronousWatchDirectory": true,
|
|
20
|
+
"excludeDirectories": ["**/node_modules", "dist"]
|
|
11
21
|
}
|
|
12
22
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"type Query {\n getGraphById(id: ID!): Graph\n graphs(limit: LimitInt, offset: Int, orderBy: [GraphOrderByArguments], where: GraphWhereArguments): [Graph]\n countGraphs(where: GraphWhereArguments): graphsCount\n}\n\ntype Graph {\n id: ID\n name: String\n}\n\n\"\"\"\nLimit will be applied by default if not passed. If the provided value exceeds the maximum allowed value a validation error will be thrown\n\"\"\"\nscalar LimitInt\n\ninput GraphOrderByArguments {\n field: GraphOrderByField\n direction: OrderByDirection!\n}\n\nenum GraphOrderByField {\n id\n name\n}\n\nenum OrderByDirection {\n ASC\n DESC\n}\n\ninput GraphWhereArguments {\n id: GraphWhereArgumentsid\n name: GraphWhereArgumentsname\n or: [GraphWhereArgumentsOr]\n}\n\ninput GraphWhereArgumentsid {\n eq: ID\n neq: ID\n gt: ID\n gte: ID\n lt: ID\n lte: ID\n like: ID\n in: [ID]\n nin: [ID]\n}\n\ninput GraphWhereArgumentsname {\n eq: String\n neq: String\n gt: String\n gte: String\n lt: String\n lte: String\n like: String\n in: [String]\n nin: [String]\n}\n\ninput GraphWhereArgumentsOr {\n id: GraphWhereArgumentsid\n name: GraphWhereArgumentsname\n}\n\ntype graphsCount {\n total: Int\n}\n\ntype Mutation {\n saveGraph(input: GraphInput!): Graph\n insertGraphs(inputs: [GraphInput]!): [Graph]\n deleteGraphs(where: GraphWhereArguments): [Graph]\n}\n\ninput GraphInput {\n id: ID\n name: String\n}\n\ntype Subscription {\n graphSaved: Graph\n graphDeleted: GraphDeleted\n}\n\ntype GraphDeleted {\n id: ID\n}"
|