@contember/cli 1.4.0-rc.1 → 1.4.0-rc.2
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/dist/src/commands/transfer/ExportCommand.d.ts +3 -0
- package/dist/src/commands/transfer/ExportCommand.d.ts.map +1 -1
- package/dist/src/commands/transfer/ExportCommand.js +17 -5
- package/dist/src/commands/transfer/ExportCommand.js.map +1 -1
- package/dist/src/commands/transfer/ImportCommand.d.ts +1 -0
- package/dist/src/commands/transfer/ImportCommand.d.ts.map +1 -1
- package/dist/src/commands/transfer/ImportCommand.js +8 -1
- package/dist/src/commands/transfer/ImportCommand.js.map +1 -1
- package/dist/src/commands/transfer/TransferCommand.d.ts +1 -0
- package/dist/src/commands/transfer/TransferCommand.d.ts.map +1 -1
- package/dist/src/commands/transfer/TransferCommand.js +9 -2
- package/dist/src/commands/transfer/TransferCommand.js.map +1 -1
- package/dist/src/commands/transfer/utils.d.ts +4 -3
- package/dist/src/commands/transfer/utils.d.ts.map +1 -1
- package/dist/src/commands/transfer/utils.js +6 -4
- package/dist/src/commands/transfer/utils.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/commands/transfer/ExportCommand.ts +22 -5
- package/src/commands/transfer/ImportCommand.ts +9 -1
- package/src/commands/transfer/TransferCommand.ts +10 -2
- package/src/commands/transfer/utils.ts +6 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/cli",
|
|
3
|
-
"version": "1.4.0-rc.
|
|
3
|
+
"version": "1.4.0-rc.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"bin": {
|
|
6
6
|
"contember": "./dist/src/run.js"
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
"tailwindcss": "^3.3.5"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@contember/cli-common": "1.4.0-rc.
|
|
24
|
-
"@contember/config-loader": "1.4.0-rc.
|
|
25
|
-
"@contember/database": "1.4.0-rc.
|
|
26
|
-
"@contember/dic": "1.4.0-rc.
|
|
27
|
-
"@contember/engine-content-api": "1.4.0-rc.
|
|
28
|
-
"@contember/migrations-client": "1.4.0-rc.
|
|
29
|
-
"@contember/schema": "1.4.0-rc.
|
|
30
|
-
"@contember/schema-migrations": "1.4.0-rc.
|
|
31
|
-
"@contember/schema-utils": "1.4.0-rc.
|
|
23
|
+
"@contember/cli-common": "1.4.0-rc.2",
|
|
24
|
+
"@contember/config-loader": "1.4.0-rc.2",
|
|
25
|
+
"@contember/database": "1.4.0-rc.2",
|
|
26
|
+
"@contember/dic": "1.4.0-rc.2",
|
|
27
|
+
"@contember/engine-content-api": "1.4.0-rc.2",
|
|
28
|
+
"@contember/migrations-client": "1.4.0-rc.2",
|
|
29
|
+
"@contember/schema": "1.4.0-rc.2",
|
|
30
|
+
"@contember/schema-migrations": "1.4.0-rc.2",
|
|
31
|
+
"@contember/schema-utils": "1.4.0-rc.2",
|
|
32
32
|
"@graphql-tools/schema": "^10.0.0",
|
|
33
33
|
"chalk": "^4.1.2",
|
|
34
34
|
"chalk-table": "^1.0.2",
|
|
@@ -4,13 +4,17 @@ import { dataExport, resolveProject } from './utils'
|
|
|
4
4
|
import { maskToken } from '../../utils/token'
|
|
5
5
|
import { pipeline } from 'node:stream/promises'
|
|
6
6
|
import { printProgressLine } from '../../utils/stdio'
|
|
7
|
+
import { createGunzip, createGzip } from 'node:zlib'
|
|
7
8
|
|
|
8
9
|
type Args = {
|
|
9
10
|
source?: string
|
|
10
11
|
}
|
|
11
12
|
type Options = {
|
|
12
13
|
'include-system'?: boolean
|
|
14
|
+
/** @deprecated */
|
|
13
15
|
'no-gzip'?: boolean
|
|
16
|
+
'no-gzip-output'?: boolean
|
|
17
|
+
'no-gzip-transfer'?: boolean
|
|
14
18
|
output?: string
|
|
15
19
|
}
|
|
16
20
|
|
|
@@ -28,7 +32,9 @@ export class ExportCommand extends Command<Args, Options> {
|
|
|
28
32
|
from.optional()
|
|
29
33
|
}
|
|
30
34
|
configuration.option('include-system').valueNone()
|
|
31
|
-
configuration.option('no-gzip').valueNone()
|
|
35
|
+
configuration.option('no-gzip').valueNone().deprecated()
|
|
36
|
+
configuration.option('no-gzip-transfer').valueNone()
|
|
37
|
+
configuration.option('no-gzip-output').valueNone()
|
|
32
38
|
configuration.option('output').valueRequired()
|
|
33
39
|
}
|
|
34
40
|
|
|
@@ -43,10 +49,16 @@ export class ExportCommand extends Command<Args, Options> {
|
|
|
43
49
|
console.log(`API URL: ${project.baseUrl}`)
|
|
44
50
|
console.log(`Token: ${maskToken(project.token)}`)
|
|
45
51
|
|
|
46
|
-
const
|
|
52
|
+
const gzipOutput = !input.getOption('no-gzip-output') && !input.getOption('no-gzip')
|
|
53
|
+
const gzipTransfer = !input.getOption('no-gzip-transfer')
|
|
54
|
+
|
|
47
55
|
const includeSystem = input.getOption('include-system') === true
|
|
48
56
|
|
|
49
|
-
const response = await dataExport({
|
|
57
|
+
const response = await dataExport({
|
|
58
|
+
project,
|
|
59
|
+
includeSystem,
|
|
60
|
+
gzip: gzipTransfer,
|
|
61
|
+
})
|
|
50
62
|
|
|
51
63
|
let transferred = 0
|
|
52
64
|
let start = Date.now()
|
|
@@ -62,11 +74,16 @@ export class ExportCommand extends Command<Args, Options> {
|
|
|
62
74
|
}
|
|
63
75
|
})
|
|
64
76
|
|
|
65
|
-
const fileName = input.getOption('output') ?? `${project.project}.jsonl${
|
|
77
|
+
const fileName = input.getOption('output') ?? `${project.project}.jsonl${gzipOutput ? '.gz' : ''}`
|
|
66
78
|
const fileStream = createWriteStream(fileName)
|
|
67
79
|
|
|
68
|
-
|
|
80
|
+
const responseStream = gzipOutput === gzipTransfer
|
|
81
|
+
? response
|
|
82
|
+
: response.pipe(gzipOutput ? createGzip() : createGunzip())
|
|
83
|
+
|
|
84
|
+
await pipeline(responseStream, fileStream)
|
|
69
85
|
|
|
70
86
|
console.log('\nExport done.')
|
|
87
|
+
console.log(`Data saved to ${fileName}`)
|
|
71
88
|
}
|
|
72
89
|
}
|
|
@@ -12,6 +12,7 @@ type Args = {
|
|
|
12
12
|
}
|
|
13
13
|
type Options = {
|
|
14
14
|
'yes': boolean
|
|
15
|
+
'no-gzip-transfer'?: boolean
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export class ImportCommand extends Command<Args, Options> {
|
|
@@ -28,6 +29,7 @@ export class ImportCommand extends Command<Args, Options> {
|
|
|
28
29
|
if (this.workspace.isSingleProjectMode()) {
|
|
29
30
|
from.optional()
|
|
30
31
|
}
|
|
32
|
+
configuration.option('no-gzip-transfer').valueNone()
|
|
31
33
|
configuration.option('yes').valueNone()
|
|
32
34
|
}
|
|
33
35
|
|
|
@@ -47,7 +49,13 @@ export class ImportCommand extends Command<Args, Options> {
|
|
|
47
49
|
const file = input.getArgument('file')
|
|
48
50
|
const baseInputStream = createReadStream(file)
|
|
49
51
|
const stream = (file.endsWith('.gz') ? baseInputStream.pipe(createGunzip()) : baseInputStream)
|
|
50
|
-
const
|
|
52
|
+
const gzipTransfer = !input.getOption('no-gzip-transfer')
|
|
53
|
+
const response = await dataImport({
|
|
54
|
+
stream: stream,
|
|
55
|
+
project,
|
|
56
|
+
printProgress: printProgressLine,
|
|
57
|
+
gzip: gzipTransfer,
|
|
58
|
+
})
|
|
51
59
|
console.log('')
|
|
52
60
|
const responseData = JSON.parse((await readStream(response)).toString())
|
|
53
61
|
if (responseData.ok) {
|
|
@@ -3,6 +3,7 @@ import { confirmImport, dataExport, dataImport, resolveProject } from './utils'
|
|
|
3
3
|
import { maskToken } from '../../utils/token'
|
|
4
4
|
import { printProgressLine } from '../../utils/stdio'
|
|
5
5
|
import { readStream } from '../../utils/stream'
|
|
6
|
+
import { createGunzip } from 'node:zlib'
|
|
6
7
|
|
|
7
8
|
type Args = {
|
|
8
9
|
source: string
|
|
@@ -10,6 +11,7 @@ type Args = {
|
|
|
10
11
|
}
|
|
11
12
|
type Options = {
|
|
12
13
|
'include-system'?: boolean
|
|
14
|
+
'no-gzip-transfer'?: boolean
|
|
13
15
|
yes: boolean
|
|
14
16
|
}
|
|
15
17
|
|
|
@@ -28,6 +30,7 @@ export class TransferCommand extends Command<Args, Options> {
|
|
|
28
30
|
target.optional()
|
|
29
31
|
}
|
|
30
32
|
configuration.option('include-system').valueNone()
|
|
33
|
+
configuration.option('no-gzip-transfer').valueNone()
|
|
31
34
|
configuration.option('yes').valueNone()
|
|
32
35
|
}
|
|
33
36
|
|
|
@@ -54,9 +57,14 @@ export class TransferCommand extends Command<Args, Options> {
|
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
const includeSystem = input.getOption('include-system') === true
|
|
57
|
-
const
|
|
60
|
+
const gzipTransfer = !input.getOption('no-gzip-transfer')
|
|
61
|
+
const exportResponse = (await dataExport({ project: sourceProject, includeSystem, gzip: gzipTransfer }))
|
|
62
|
+
const ungzipedResponse = gzipTransfer ? exportResponse.pipe(createGunzip()) : exportResponse
|
|
58
63
|
const importResponse = await dataImport({
|
|
59
|
-
stream:
|
|
64
|
+
stream: ungzipedResponse,
|
|
65
|
+
project: targetProject,
|
|
66
|
+
printProgress: printProgressLine,
|
|
67
|
+
gzip: gzipTransfer,
|
|
60
68
|
})
|
|
61
69
|
console.log('')
|
|
62
70
|
|
|
@@ -7,6 +7,7 @@ import { parseDsn } from '../../utils/dsn'
|
|
|
7
7
|
import { interactiveResolveInstanceEnvironmentFromInput } from '../../utils/instance'
|
|
8
8
|
import { interactiveResolveApiToken } from '../../utils/tenant'
|
|
9
9
|
import prompts from 'prompts'
|
|
10
|
+
import { createGzip } from 'node:zlib'
|
|
10
11
|
|
|
11
12
|
export type ProjectEndpoint = {
|
|
12
13
|
token: string
|
|
@@ -30,7 +31,7 @@ export const resolveProject = async ({ projectOrDsn, workspace }: { projectOrDsn
|
|
|
30
31
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
export const dataImport = async ({ printProgress, stream, project: { project, token, baseUrl } }: { stream: Readable; project: ProjectEndpoint; printProgress: (message: string) => void }) => {
|
|
34
|
+
export const dataImport = async ({ printProgress, stream, project: { project, token, baseUrl }, gzip }: { stream: Readable; project: ProjectEndpoint; printProgress: (message: string) => void; gzip: boolean }) => {
|
|
34
35
|
let table = ''
|
|
35
36
|
let rowCount = 0
|
|
36
37
|
let rowTotal = 0
|
|
@@ -71,17 +72,18 @@ export const dataImport = async ({ printProgress, stream, project: { project, to
|
|
|
71
72
|
token,
|
|
72
73
|
headers: {
|
|
73
74
|
'Content-type': 'application/x-ndjson',
|
|
75
|
+
...(gzip ? { 'Content-Encoding': 'gzip' } : {}),
|
|
74
76
|
},
|
|
75
|
-
body: inputStream,
|
|
77
|
+
body: gzip ? inputStream.pipe(createGzip()) : inputStream,
|
|
76
78
|
})
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
export const dataExport = async ({ project: { project, token, baseUrl },
|
|
81
|
+
export const dataExport = async ({ project: { project, token, baseUrl }, gzip, includeSystem }: { project: ProjectEndpoint; includeSystem: boolean; gzip: boolean }) => {
|
|
80
82
|
return await executeRequest({
|
|
81
83
|
url: `${baseUrl}/export`,
|
|
82
84
|
token,
|
|
83
85
|
headers: {
|
|
84
|
-
'Accept-Encoding':
|
|
86
|
+
'Accept-Encoding': gzip ? 'gzip' : 'identity',
|
|
85
87
|
'Content-type': 'application/json',
|
|
86
88
|
},
|
|
87
89
|
body: JSON.stringify({
|