@contember/cli 2.1.0-alpha.15 → 2.1.0-alpha.16

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.
Files changed (191) hide show
  1. package/dist/development/src/commands/actions/ActionsGetEventCommand.cjs +31 -0
  2. package/dist/development/src/commands/actions/ActionsGetEventCommand.cjs.map +1 -0
  3. package/dist/development/src/commands/actions/ActionsGetEventCommand.js +31 -0
  4. package/dist/development/src/commands/actions/ActionsGetEventCommand.js.map +1 -0
  5. package/dist/development/src/commands/actions/ActionsListFailedEventsCommand.cjs +60 -0
  6. package/dist/development/src/commands/actions/ActionsListFailedEventsCommand.cjs.map +1 -0
  7. package/dist/development/src/commands/actions/ActionsListFailedEventsCommand.js +60 -0
  8. package/dist/development/src/commands/actions/ActionsListFailedEventsCommand.js.map +1 -0
  9. package/dist/development/src/commands/actions/ActionsListVariablesCommand.cjs +29 -0
  10. package/dist/development/src/commands/actions/ActionsListVariablesCommand.cjs.map +1 -0
  11. package/dist/development/src/commands/actions/ActionsListVariablesCommand.js +29 -0
  12. package/dist/development/src/commands/actions/ActionsListVariablesCommand.js.map +1 -0
  13. package/dist/development/src/commands/actions/ActionsRetryEventCommand.cjs +32 -0
  14. package/dist/development/src/commands/actions/ActionsRetryEventCommand.cjs.map +1 -0
  15. package/dist/development/src/commands/actions/ActionsRetryEventCommand.js +32 -0
  16. package/dist/development/src/commands/actions/ActionsRetryEventCommand.js.map +1 -0
  17. package/dist/development/src/commands/actions/ActionsSetVariablesCommand.cjs +40 -0
  18. package/dist/development/src/commands/actions/ActionsSetVariablesCommand.cjs.map +1 -0
  19. package/dist/development/src/commands/actions/ActionsSetVariablesCommand.js +40 -0
  20. package/dist/development/src/commands/actions/ActionsSetVariablesCommand.js.map +1 -0
  21. package/dist/development/src/commands/actions/ActionsStopEventCommand.cjs +32 -0
  22. package/dist/development/src/commands/actions/ActionsStopEventCommand.cjs.map +1 -0
  23. package/dist/development/src/commands/actions/ActionsStopEventCommand.js +32 -0
  24. package/dist/development/src/commands/actions/ActionsStopEventCommand.js.map +1 -0
  25. package/dist/development/src/commands/migrations/MigrationStatusCommand.cjs +1 -1
  26. package/dist/development/src/commands/migrations/MigrationStatusCommand.cjs.map +1 -1
  27. package/dist/development/src/commands/migrations/MigrationStatusCommand.js +1 -1
  28. package/dist/development/src/commands/migrations/MigrationStatusCommand.js.map +1 -1
  29. package/dist/development/src/commands/transfer/ExportCommand.cjs +7 -2
  30. package/dist/development/src/commands/transfer/ExportCommand.cjs.map +1 -1
  31. package/dist/development/src/commands/transfer/ExportCommand.js +8 -3
  32. package/dist/development/src/commands/transfer/ExportCommand.js.map +1 -1
  33. package/dist/development/src/commands/transfer/ImportCommand.cjs +7 -4
  34. package/dist/development/src/commands/transfer/ImportCommand.cjs.map +1 -1
  35. package/dist/development/src/commands/transfer/ImportCommand.js +5 -2
  36. package/dist/development/src/commands/transfer/ImportCommand.js.map +1 -1
  37. package/dist/development/src/commands/transfer/TransferCommand.cjs +4 -5
  38. package/dist/development/src/commands/transfer/TransferCommand.cjs.map +1 -1
  39. package/dist/development/src/commands/transfer/TransferCommand.js +4 -5
  40. package/dist/development/src/commands/transfer/TransferCommand.js.map +1 -1
  41. package/dist/development/src/dic.cjs +14 -2
  42. package/dist/development/src/dic.cjs.map +1 -1
  43. package/dist/development/src/dic.js +14 -2
  44. package/dist/development/src/dic.js.map +1 -1
  45. package/dist/development/src/lib/VersionChecker.cjs +7 -9
  46. package/dist/development/src/lib/VersionChecker.cjs.map +1 -1
  47. package/dist/development/src/lib/VersionChecker.js +7 -9
  48. package/dist/development/src/lib/VersionChecker.js.map +1 -1
  49. package/dist/development/src/lib/actions/ActionsClient.cjs +91 -0
  50. package/dist/development/src/lib/actions/ActionsClient.cjs.map +1 -0
  51. package/dist/development/src/lib/actions/ActionsClient.js +91 -0
  52. package/dist/development/src/lib/actions/ActionsClient.js.map +1 -0
  53. package/dist/development/src/lib/migrations/MigrationPrinter.cjs +7 -2
  54. package/dist/development/src/lib/migrations/MigrationPrinter.cjs.map +1 -1
  55. package/dist/development/src/lib/migrations/MigrationPrinter.js +7 -2
  56. package/dist/development/src/lib/migrations/MigrationPrinter.js.map +1 -1
  57. package/dist/development/src/lib/migrations/MigrationsStatusFacade.cjs +3 -3
  58. package/dist/development/src/lib/migrations/MigrationsStatusFacade.cjs.map +1 -1
  59. package/dist/development/src/lib/migrations/MigrationsStatusFacade.js +3 -3
  60. package/dist/development/src/lib/migrations/MigrationsStatusFacade.js.map +1 -1
  61. package/dist/development/src/lib/stream.cjs +0 -7
  62. package/dist/development/src/lib/stream.cjs.map +1 -1
  63. package/dist/development/src/lib/stream.js +1 -8
  64. package/dist/development/src/lib/stream.js.map +1 -1
  65. package/dist/development/src/lib/transfer/DataTransferClient.cjs +23 -34
  66. package/dist/development/src/lib/transfer/DataTransferClient.cjs.map +1 -1
  67. package/dist/development/src/lib/transfer/DataTransferClient.js +25 -36
  68. package/dist/development/src/lib/transfer/DataTransferClient.js.map +1 -1
  69. package/dist/production/src/commands/actions/ActionsGetEventCommand.cjs +31 -0
  70. package/dist/production/src/commands/actions/ActionsGetEventCommand.cjs.map +1 -0
  71. package/dist/production/src/commands/actions/ActionsGetEventCommand.js +31 -0
  72. package/dist/production/src/commands/actions/ActionsGetEventCommand.js.map +1 -0
  73. package/dist/production/src/commands/actions/ActionsListFailedEventsCommand.cjs +60 -0
  74. package/dist/production/src/commands/actions/ActionsListFailedEventsCommand.cjs.map +1 -0
  75. package/dist/production/src/commands/actions/ActionsListFailedEventsCommand.js +60 -0
  76. package/dist/production/src/commands/actions/ActionsListFailedEventsCommand.js.map +1 -0
  77. package/dist/production/src/commands/actions/ActionsListVariablesCommand.cjs +29 -0
  78. package/dist/production/src/commands/actions/ActionsListVariablesCommand.cjs.map +1 -0
  79. package/dist/production/src/commands/actions/ActionsListVariablesCommand.js +29 -0
  80. package/dist/production/src/commands/actions/ActionsListVariablesCommand.js.map +1 -0
  81. package/dist/production/src/commands/actions/ActionsRetryEventCommand.cjs +32 -0
  82. package/dist/production/src/commands/actions/ActionsRetryEventCommand.cjs.map +1 -0
  83. package/dist/production/src/commands/actions/ActionsRetryEventCommand.js +32 -0
  84. package/dist/production/src/commands/actions/ActionsRetryEventCommand.js.map +1 -0
  85. package/dist/production/src/commands/actions/ActionsSetVariablesCommand.cjs +40 -0
  86. package/dist/production/src/commands/actions/ActionsSetVariablesCommand.cjs.map +1 -0
  87. package/dist/production/src/commands/actions/ActionsSetVariablesCommand.js +40 -0
  88. package/dist/production/src/commands/actions/ActionsSetVariablesCommand.js.map +1 -0
  89. package/dist/production/src/commands/actions/ActionsStopEventCommand.cjs +32 -0
  90. package/dist/production/src/commands/actions/ActionsStopEventCommand.cjs.map +1 -0
  91. package/dist/production/src/commands/actions/ActionsStopEventCommand.js +32 -0
  92. package/dist/production/src/commands/actions/ActionsStopEventCommand.js.map +1 -0
  93. package/dist/production/src/commands/migrations/MigrationStatusCommand.cjs +1 -1
  94. package/dist/production/src/commands/migrations/MigrationStatusCommand.cjs.map +1 -1
  95. package/dist/production/src/commands/migrations/MigrationStatusCommand.js +1 -1
  96. package/dist/production/src/commands/migrations/MigrationStatusCommand.js.map +1 -1
  97. package/dist/production/src/commands/transfer/ExportCommand.cjs +7 -2
  98. package/dist/production/src/commands/transfer/ExportCommand.cjs.map +1 -1
  99. package/dist/production/src/commands/transfer/ExportCommand.js +8 -3
  100. package/dist/production/src/commands/transfer/ExportCommand.js.map +1 -1
  101. package/dist/production/src/commands/transfer/ImportCommand.cjs +7 -4
  102. package/dist/production/src/commands/transfer/ImportCommand.cjs.map +1 -1
  103. package/dist/production/src/commands/transfer/ImportCommand.js +5 -2
  104. package/dist/production/src/commands/transfer/ImportCommand.js.map +1 -1
  105. package/dist/production/src/commands/transfer/TransferCommand.cjs +4 -5
  106. package/dist/production/src/commands/transfer/TransferCommand.cjs.map +1 -1
  107. package/dist/production/src/commands/transfer/TransferCommand.js +4 -5
  108. package/dist/production/src/commands/transfer/TransferCommand.js.map +1 -1
  109. package/dist/production/src/dic.cjs +14 -2
  110. package/dist/production/src/dic.cjs.map +1 -1
  111. package/dist/production/src/dic.js +14 -2
  112. package/dist/production/src/dic.js.map +1 -1
  113. package/dist/production/src/lib/VersionChecker.cjs +7 -9
  114. package/dist/production/src/lib/VersionChecker.cjs.map +1 -1
  115. package/dist/production/src/lib/VersionChecker.js +7 -9
  116. package/dist/production/src/lib/VersionChecker.js.map +1 -1
  117. package/dist/production/src/lib/actions/ActionsClient.cjs +91 -0
  118. package/dist/production/src/lib/actions/ActionsClient.cjs.map +1 -0
  119. package/dist/production/src/lib/actions/ActionsClient.js +91 -0
  120. package/dist/production/src/lib/actions/ActionsClient.js.map +1 -0
  121. package/dist/production/src/lib/migrations/MigrationPrinter.cjs +7 -2
  122. package/dist/production/src/lib/migrations/MigrationPrinter.cjs.map +1 -1
  123. package/dist/production/src/lib/migrations/MigrationPrinter.js +7 -2
  124. package/dist/production/src/lib/migrations/MigrationPrinter.js.map +1 -1
  125. package/dist/production/src/lib/migrations/MigrationsStatusFacade.cjs +3 -3
  126. package/dist/production/src/lib/migrations/MigrationsStatusFacade.cjs.map +1 -1
  127. package/dist/production/src/lib/migrations/MigrationsStatusFacade.js +3 -3
  128. package/dist/production/src/lib/migrations/MigrationsStatusFacade.js.map +1 -1
  129. package/dist/production/src/lib/stream.cjs +0 -7
  130. package/dist/production/src/lib/stream.cjs.map +1 -1
  131. package/dist/production/src/lib/stream.js +1 -8
  132. package/dist/production/src/lib/stream.js.map +1 -1
  133. package/dist/production/src/lib/transfer/DataTransferClient.cjs +23 -34
  134. package/dist/production/src/lib/transfer/DataTransferClient.cjs.map +1 -1
  135. package/dist/production/src/lib/transfer/DataTransferClient.js +25 -36
  136. package/dist/production/src/lib/transfer/DataTransferClient.js.map +1 -1
  137. package/dist/types/commands/actions/ActionsGetEventCommand.d.ts +16 -0
  138. package/dist/types/commands/actions/ActionsGetEventCommand.d.ts.map +1 -0
  139. package/dist/types/commands/actions/ActionsListFailedEventsCommand.d.ts +15 -0
  140. package/dist/types/commands/actions/ActionsListFailedEventsCommand.d.ts.map +1 -0
  141. package/dist/types/commands/actions/ActionsListVariablesCommand.d.ts +14 -0
  142. package/dist/types/commands/actions/ActionsListVariablesCommand.d.ts.map +1 -0
  143. package/dist/types/commands/actions/ActionsRetryEventCommand.d.ts +16 -0
  144. package/dist/types/commands/actions/ActionsRetryEventCommand.d.ts.map +1 -0
  145. package/dist/types/commands/actions/ActionsSetVariablesCommand.d.ts +19 -0
  146. package/dist/types/commands/actions/ActionsSetVariablesCommand.d.ts.map +1 -0
  147. package/dist/types/commands/actions/ActionsStopEventCommand.d.ts +16 -0
  148. package/dist/types/commands/actions/ActionsStopEventCommand.d.ts.map +1 -0
  149. package/dist/types/commands/transfer/ExportCommand.d.ts.map +1 -1
  150. package/dist/types/commands/transfer/ImportCommand.d.ts.map +1 -1
  151. package/dist/types/commands/transfer/TransferCommand.d.ts.map +1 -1
  152. package/dist/types/dic.d.ts +18 -0
  153. package/dist/types/dic.d.ts.map +1 -1
  154. package/dist/types/lib/VersionChecker.d.ts.map +1 -1
  155. package/dist/types/lib/actions/ActionsClient.d.ts +33 -0
  156. package/dist/types/lib/actions/ActionsClient.d.ts.map +1 -0
  157. package/dist/types/lib/migrations/MigrationPrinter.d.ts +1 -1
  158. package/dist/types/lib/migrations/MigrationPrinter.d.ts.map +1 -1
  159. package/dist/types/lib/migrations/MigrationsStatusFacade.d.ts +3 -1
  160. package/dist/types/lib/migrations/MigrationsStatusFacade.d.ts.map +1 -1
  161. package/dist/types/lib/transfer/DataTransferClient.d.ts +2 -4
  162. package/dist/types/lib/transfer/DataTransferClient.d.ts.map +1 -1
  163. package/dist/types/tsconfig.tsbuildinfo +1 -1
  164. package/package.json +1 -1
  165. package/src/commands/actions/ActionsGetEventCommand.ts +42 -0
  166. package/src/commands/actions/ActionsListFailedEventsCommand.ts +70 -0
  167. package/src/commands/actions/ActionsListVariablesCommand.ts +37 -0
  168. package/src/commands/actions/ActionsRetryEventCommand.ts +42 -0
  169. package/src/commands/actions/ActionsSetVariablesCommand.ts +56 -0
  170. package/src/commands/actions/ActionsStopEventCommand.ts +42 -0
  171. package/src/commands/migrations/MigrationStatusCommand.ts +1 -1
  172. package/src/commands/transfer/ExportCommand.ts +9 -4
  173. package/src/commands/transfer/ImportCommand.ts +6 -1
  174. package/src/commands/transfer/TransferCommand.ts +4 -3
  175. package/src/dic.ts +27 -2
  176. package/src/lib/VersionChecker.ts +13 -9
  177. package/src/lib/actions/ActionsClient.ts +112 -0
  178. package/src/lib/migrations/MigrationPrinter.ts +7 -2
  179. package/src/lib/migrations/MigrationsStatusFacade.ts +4 -3
  180. package/src/lib/transfer/DataTransferClient.ts +24 -43
  181. package/dist/development/src/lib/migrations/migrations.cjs +0 -43
  182. package/dist/development/src/lib/migrations/migrations.cjs.map +0 -1
  183. package/dist/development/src/lib/migrations/migrations.js +0 -43
  184. package/dist/development/src/lib/migrations/migrations.js.map +0 -1
  185. package/dist/production/src/lib/migrations/migrations.cjs +0 -43
  186. package/dist/production/src/lib/migrations/migrations.cjs.map +0 -1
  187. package/dist/production/src/lib/migrations/migrations.js +0 -43
  188. package/dist/production/src/lib/migrations/migrations.js.map +0 -1
  189. package/dist/types/lib/migrations/migrations.d.ts +0 -3
  190. package/dist/types/lib/migrations/migrations.d.ts.map +0 -1
  191. package/src/lib/migrations/migrations.ts +0 -45
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contember/cli",
3
- "version": "2.1.0-alpha.15",
3
+ "version": "2.1.0-alpha.16",
4
4
  "license": "Apache-2.0",
5
5
  "bin": {
6
6
  "contember": "./dist/production/run.js"
@@ -0,0 +1,42 @@
1
+ import { Command, CommandConfiguration, Input } from '@contember/cli-common'
2
+ import { RemoteProjectResolver } from '../../lib/project/RemoteProjectResolver'
3
+ import { ActionsClient } from '../../lib/actions/ActionsClient'
4
+
5
+ type Args = {
6
+ eventId: string
7
+ }
8
+
9
+ type Options = {
10
+ project?: string
11
+ }
12
+
13
+ export class ActionsGetEventCommand extends Command<Args, Options> {
14
+ constructor(
15
+ private readonly remoteProjectResolver: RemoteProjectResolver,
16
+ ) {
17
+ super()
18
+ }
19
+
20
+ protected configure(configuration: CommandConfiguration<Args, Options>): void {
21
+ configuration.description('Get single event')
22
+ configuration.argument('eventId')
23
+ configuration.option('project').valueRequired()
24
+ }
25
+
26
+ protected async execute(input: Input<Args, Options>): Promise<void | number> {
27
+ const dsn = input.getOption('project')
28
+ const project = await this.remoteProjectResolver.resolve(dsn)
29
+ if (!project) {
30
+ throw `Project not defined`
31
+ }
32
+ const api = ActionsClient.create(project.endpoint, project.name, project.token)
33
+
34
+ const result = await api.getEvent(input.getArgument('eventId'))
35
+ if (!result) {
36
+ console.log('Event not found')
37
+ return 1
38
+ }
39
+ console.log(JSON.stringify(result, null, 2))
40
+
41
+ }
42
+ }
@@ -0,0 +1,70 @@
1
+ import { Command, CommandConfiguration, Input } from '@contember/cli-common'
2
+ import { RemoteProjectResolver } from '../../lib/project/RemoteProjectResolver'
3
+ import { ActionsClient } from '../../lib/actions/ActionsClient'
4
+ import chalkTable from 'chalk-table'
5
+ type Args = {
6
+ }
7
+
8
+ type Options = {
9
+ project?: string
10
+ json?: boolean
11
+ }
12
+
13
+ export class ActionsListFailedEventsCommand extends Command<Args, Options> {
14
+ constructor(
15
+ private readonly remoteProjectResolver: RemoteProjectResolver,
16
+ ) {
17
+ super()
18
+ }
19
+
20
+ protected configure(configuration: CommandConfiguration<Args, Options>): void {
21
+ configuration.description('Show failed events')
22
+ configuration.option('project').valueRequired()
23
+ configuration.option('json').valueNone()
24
+ }
25
+
26
+ protected async execute(input: Input<Args, Options>): Promise<void | number> {
27
+ const dsn = input.getOption('project')
28
+ const project = await this.remoteProjectResolver.resolve(dsn)
29
+ if (!project) {
30
+ throw `Project not defined`
31
+ }
32
+ const api = ActionsClient.create(project.endpoint, project.name, project.token)
33
+
34
+ const result = await api.listFailedEvents()
35
+ if (input.getOption('json')) {
36
+ console.log(JSON.stringify(result, null, 2))
37
+ return
38
+ }
39
+ if (result.length === 0) {
40
+ console.log('No failed events')
41
+ return
42
+ }
43
+ const table = chalkTable(
44
+ {
45
+ columns: [
46
+ { field: 'id', name: 'ID' },
47
+ { field: 'createdAt', name: 'Created at' },
48
+ { field: 'lastStateChange', name: 'Last state change' },
49
+ { field: 'visibleAt', name: 'Visible at' },
50
+ { field: 'numRetries', name: 'Retries' },
51
+ { field: 'state', name: 'State' },
52
+ { field: 'target', name: 'Target' },
53
+ { field: 'log', name: 'Log' },
54
+ ],
55
+ },
56
+ result.map(it => ({
57
+ id: it.id,
58
+ createdAt: it.createdAt,
59
+ lastStateChange: it.lastStateChange,
60
+ visibleAt: it.visibleAt || '',
61
+ numRetries: it.numRetries.toString(),
62
+ state: it.state,
63
+ target: it.target,
64
+ log: JSON.stringify(it.log.length > 0 ? it.log[it.log.length - 1] : {}),
65
+ })),
66
+ )
67
+ console.log(table)
68
+
69
+ }
70
+ }
@@ -0,0 +1,37 @@
1
+ import { Command, CommandConfiguration, Input } from '@contember/cli-common'
2
+ import { RemoteProjectResolver } from '../../lib/project/RemoteProjectResolver'
3
+ import { ActionsClient } from '../../lib/actions/ActionsClient'
4
+ import chalkTable from 'chalk-table'
5
+
6
+ type Args = {
7
+ }
8
+
9
+ type Options = {
10
+ project?: string
11
+ }
12
+
13
+ export class ActionsListVariablesCommand extends Command<Args, Options> {
14
+ constructor(
15
+ private readonly remoteProjectResolver: RemoteProjectResolver,
16
+ ) {
17
+ super()
18
+ }
19
+
20
+ protected configure(configuration: CommandConfiguration<Args, Options>): void {
21
+ configuration.description('Show action variables')
22
+ configuration.option('project').valueRequired()
23
+ }
24
+
25
+ protected async execute(input: Input<Args, Options>): Promise<void | number> {
26
+ const dsn = input.getOption('project')
27
+ const project = await this.remoteProjectResolver.resolve(dsn)
28
+ if (!project) {
29
+ throw `Project not defined`
30
+ }
31
+ const api = ActionsClient.create(project.endpoint, project.name, project.token)
32
+ const result = await api.listVariables()
33
+ console.log(chalkTable({
34
+ columns: ['name', 'value'],
35
+ }, result))
36
+ }
37
+ }
@@ -0,0 +1,42 @@
1
+ import { Command, CommandConfiguration, Input } from '@contember/cli-common'
2
+ import { RemoteProjectResolver } from '../../lib/project/RemoteProjectResolver'
3
+ import { ActionsClient } from '../../lib/actions/ActionsClient'
4
+ import chalkTable from 'chalk-table'
5
+ type Args = {
6
+ eventId: string
7
+ }
8
+
9
+ type Options = {
10
+ project?: string
11
+ }
12
+
13
+ export class ActionsRetryEventCommand extends Command<Args, Options> {
14
+ constructor(
15
+ private readonly remoteProjectResolver: RemoteProjectResolver,
16
+ ) {
17
+ super()
18
+ }
19
+
20
+ protected configure(configuration: CommandConfiguration<Args, Options>): void {
21
+ configuration.description('Retry given event')
22
+ configuration.argument('eventId')
23
+ configuration.option('project').valueRequired()
24
+ }
25
+
26
+ protected async execute(input: Input<Args, Options>): Promise<void | number> {
27
+ const dsn = input.getOption('project')
28
+ const project = await this.remoteProjectResolver.resolve(dsn)
29
+ if (!project) {
30
+ throw `Project not defined`
31
+ }
32
+ const api = ActionsClient.create(project.endpoint, project.name, project.token)
33
+
34
+ const result = await api.retryEvent(input.getArgument('eventId'))
35
+ if (result) {
36
+ console.log('Event requeued for processing')
37
+ } else {
38
+ console.log('Failed to requeue event. Check the event status')
39
+ return 1
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,56 @@
1
+ import { Command, CommandConfiguration, Input } from '@contember/cli-common'
2
+ import { RemoteProjectResolver } from '../../lib/project/RemoteProjectResolver'
3
+ import { ActionsClient } from '../../lib/actions/ActionsClient'
4
+
5
+ type Args = {
6
+ variables: string[]
7
+ }
8
+
9
+ type Options = {
10
+ project?: string
11
+ merge?: boolean
12
+ set?: boolean
13
+ ['append-only-missing']?: boolean
14
+ }
15
+
16
+ export class ActionsSetVariablesCommand extends Command<Args, Options> {
17
+ constructor(
18
+ private readonly remoteProjectResolver: RemoteProjectResolver,
19
+ ) {
20
+ super()
21
+ }
22
+
23
+ protected configure(configuration: CommandConfiguration<Args, Options>): void {
24
+ configuration.description('Set action variables')
25
+ configuration.option('project').valueRequired()
26
+ configuration.option('merge').valueNone().description('merges with new values (default behaviour)')
27
+ configuration.option('set').valueNone().description('replaces all variables')
28
+ configuration.option('append-only-missing').valueNone().description('appends values if not already exist')
29
+ configuration.argument('variables').variadic().description('variables to set, in the form of name=value')
30
+ }
31
+
32
+ protected async execute(input: Input<Args, Options>): Promise<void | number> {
33
+ const dsn = input.getOption('project')
34
+ const project = await this.remoteProjectResolver.resolve(dsn)
35
+ if (!project) {
36
+ throw `Project not defined`
37
+ }
38
+ const api = ActionsClient.create(project.endpoint, project.name, project.token)
39
+ const mode = input.getOption('merge')
40
+ ? 'MERGE' as const : input.getOption('set')
41
+ ? 'SET' as const : input.getOption('append-only-missing')
42
+ ? 'APPEND_ONLY_MISSING' as const : 'MERGE' as const
43
+
44
+ const variables = input.getArgument('variables').flatMap(it => it.split('\n')).filter(it => it.trim().length > 0)
45
+ const result = await api.setVariables(variables.map(it => {
46
+ const [name, value] = it.split('=')
47
+ return { name, value }
48
+ }), mode)
49
+ if (result) {
50
+ console.log('Success')
51
+ } else {
52
+ console.error('Failed')
53
+ return 1
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,42 @@
1
+ import { Command, CommandConfiguration, Input } from '@contember/cli-common'
2
+ import { RemoteProjectResolver } from '../../lib/project/RemoteProjectResolver'
3
+ import { ActionsClient } from '../../lib/actions/ActionsClient'
4
+ import chalkTable from 'chalk-table'
5
+ type Args = {
6
+ eventId: string
7
+ }
8
+
9
+ type Options = {
10
+ project?: string
11
+ }
12
+
13
+ export class ActionsStopEventCommand extends Command<Args, Options> {
14
+ constructor(
15
+ private readonly remoteProjectResolver: RemoteProjectResolver,
16
+ ) {
17
+ super()
18
+ }
19
+
20
+ protected configure(configuration: CommandConfiguration<Args, Options>): void {
21
+ configuration.description('Stop given event')
22
+ configuration.argument('eventId')
23
+ configuration.option('project').valueRequired()
24
+ }
25
+
26
+ protected async execute(input: Input<Args, Options>): Promise<void | number> {
27
+ const dsn = input.getOption('project')
28
+ const project = await this.remoteProjectResolver.resolve(dsn)
29
+ if (!project) {
30
+ throw `Project not defined`
31
+ }
32
+ const api = ActionsClient.create(project.endpoint, project.name, project.token)
33
+
34
+ const result = await api.stopEvent(input.getArgument('eventId'))
35
+ if (result) {
36
+ console.log('Event stopped')
37
+ } else {
38
+ console.log('Failed to stop event. Check the event id.')
39
+ return 1
40
+ }
41
+ }
42
+ }
@@ -78,7 +78,7 @@ export class MigrationStatusCommand extends Command<Args, Options> {
78
78
  ])
79
79
  : status.allMigrations
80
80
 
81
- this.migrationPrinter.printStatusTable(filtered)
81
+ console.log(this.migrationPrinter.printStatusTable(filtered))
82
82
 
83
83
  const hasErrors = status.errorMigrations.length > 0
84
84
 
@@ -6,6 +6,7 @@ import { printProgressLine } from '../../lib/transfer/stdio'
6
6
  import { createGunzip, createGzip } from 'node:zlib'
7
7
  import { RemoteProjectResolver } from '../../lib/project/RemoteProjectResolver'
8
8
  import { DataTransferClient } from '../../lib/transfer/DataTransferClient'
9
+ import { Readable } from 'node:stream'
9
10
 
10
11
  type Args = {
11
12
  source?: string
@@ -64,12 +65,16 @@ export class ExportCommand extends Command<Args, Options> {
64
65
  includeSystem,
65
66
  gzip: gzipTransfer,
66
67
  })
68
+ if (!response.body) {
69
+ throw new Error('Response does not contain a readable stream.')
70
+ }
67
71
 
68
72
  let transferred = 0
69
73
  let start = Date.now()
70
74
  let lastMbReported = 0
71
75
  console.log('')
72
- response.on('data', chunk => {
76
+ const stream = Readable.fromWeb(response.body as any)
77
+ stream.on('data', chunk => {
73
78
  transferred += chunk.length
74
79
  const currentMb = Math.floor(transferred / 1024 / 1024)
75
80
  if (currentMb > lastMbReported) {
@@ -82,9 +87,9 @@ export class ExportCommand extends Command<Args, Options> {
82
87
  const fileName = input.getOption('output') ?? `${project.name}.jsonl${gzipOutput ? '.gz' : ''}`
83
88
  const fileStream = createWriteStream(fileName)
84
89
 
85
- const responseStream = gzipOutput === gzipTransfer
86
- ? response
87
- : response.pipe(gzipOutput ? createGzip() : createGunzip())
90
+ const responseStream = !gzipOutput
91
+ ? stream
92
+ : stream.pipe(createGzip())
88
93
 
89
94
  await pipeline(responseStream, fileStream)
90
95
 
@@ -52,6 +52,10 @@ export class ImportCommand extends Command<Args, Options> {
52
52
  const file = input.getArgument('file')
53
53
  const baseInputStream = createReadStream(file)
54
54
  const stream = (file.endsWith('.gz') ? baseInputStream.pipe(createGunzip()) : baseInputStream)
55
+ stream.on('error', (err: any) => {
56
+ console.error('Error in import stream:', err)
57
+ })
58
+
55
59
  const gzipTransfer = !input.getOption('no-gzip-transfer')
56
60
  const response = await this.dataTransferClient.dataImport({
57
61
  stream: stream,
@@ -60,12 +64,13 @@ export class ImportCommand extends Command<Args, Options> {
60
64
  gzip: gzipTransfer,
61
65
  })
62
66
  console.log('')
63
- const responseData = JSON.parse((await readStream(response)).toString())
67
+ const responseData = await response.json()
64
68
  if (responseData.ok) {
65
69
  console.log('Import done.')
66
70
  } else {
67
71
  console.error('Import failed:')
68
72
  console.log(responseData)
73
+ return 1
69
74
  }
70
75
  }
71
76
  }
@@ -6,6 +6,7 @@ import { readStream } from '../../lib/stream'
6
6
  import { createGunzip } from 'node:zlib'
7
7
  import { RemoteProjectResolver } from '../../lib/project/RemoteProjectResolver'
8
8
  import { DataTransferClient } from '../../lib/transfer/DataTransferClient'
9
+ import { Duplex, Readable } from 'node:stream'
9
10
 
10
11
  type Args = {
11
12
  source: string
@@ -73,16 +74,16 @@ export class TransferCommand extends Command<Args, Options> {
73
74
  excludeTables: input.getOption('exclude-table') ?? [],
74
75
  gzip: gzipTransfer,
75
76
  }))
76
- const ungzipedResponse = gzipTransfer ? exportResponse.pipe(createGunzip()) : exportResponse
77
+ const stream = Readable.fromWeb(exportResponse.body! as any)
77
78
  const importResponse = await this.dataTransferClient.dataImport({
78
- stream: ungzipedResponse,
79
+ stream: stream,
79
80
  project: targetProject,
80
81
  printProgress: printProgressLine,
81
82
  gzip: gzipTransfer,
82
83
  })
83
84
  console.log('')
84
85
 
85
- const responseData = JSON.parse((await readStream(importResponse)).toString())
86
+ const responseData = await importResponse.json()
86
87
  if (responseData.ok) {
87
88
  console.log('Transfer done.')
88
89
  } else {
package/src/dic.ts CHANGED
@@ -66,6 +66,12 @@ import { RemoteProjectProvider } from './lib/project/RemoteProjectProvider'
66
66
  import { SystemClientProvider } from './lib/SystemClientProvider'
67
67
  import { TenantClientProvider } from './lib/TenantClientProvider'
68
68
  import { Workspace } from './lib/workspace/Workspace'
69
+ import { ActionsListVariablesCommand } from './commands/actions/ActionsListVariablesCommand'
70
+ import { ActionsSetVariablesCommand } from './commands/actions/ActionsSetVariablesCommand'
71
+ import { ActionsListFailedEventsCommand } from './commands/actions/ActionsListFailedEventsCommand'
72
+ import { ActionsRetryEventCommand } from './commands/actions/ActionsRetryEventCommand'
73
+ import { ActionsGetEventCommand } from './commands/actions/ActionsGetEventCommand'
74
+ import { ActionsStopEventCommand } from './commands/actions/ActionsStopEventCommand'
69
75
 
70
76
  const jsSample = `
71
77
  export const query = \`\`
@@ -169,8 +175,8 @@ export const createContainer = ({ env, version, runtime, workspace }: {
169
175
  new MigrationExecutor())
170
176
  .addService('migrationsStatusResolver', () =>
171
177
  new MigrationsStatusResolver())
172
- .addService('migrationsStatusFacade', ({ systemClientProvider, migrationsResolver, migrationsStatusResolver }) =>
173
- new MigrationsStatusFacade(systemClientProvider, migrationsResolver, migrationsStatusResolver))
178
+ .addService('migrationsStatusFacade', ({ systemClientProvider, migrationsResolver, migrationsStatusResolver, migrationPrinter }) =>
179
+ new MigrationsStatusFacade(systemClientProvider, migrationsResolver, migrationsStatusResolver, migrationPrinter))
174
180
  .addService('migrationExecutionFacade', ({ systemClientProvider, tenantClientProvider, remoteProjectProvider, schemaVersionBuilder, migrationPrinter, migrationsExecutor, migrationsStatusFacade }) =>
175
181
  new MigrationExecutionFacade(systemClientProvider, tenantClientProvider, remoteProjectProvider, schemaVersionBuilder, migrationPrinter, migrationsExecutor, migrationsStatusFacade))
176
182
  .addService('migrationsValidator', ({ migrationDescriber, schemaMigrator }) =>
@@ -218,6 +224,19 @@ export const createContainer = ({ env, version, runtime, workspace }: {
218
224
  new TransferCommand(remoteProjectResolver, dataTransferClient))
219
225
  .addService('workspaceUpdateCommand', ({ packageWorkspaceResolver, dockerComposeManager }) =>
220
226
  new WorkspaceUpdateApiCommand(packageWorkspaceResolver, dockerComposeManager))
227
+ .addService('actionsListVariables', ({ remoteProjectResolver }) =>
228
+ new ActionsListVariablesCommand(remoteProjectResolver))
229
+ .addService('actionsSetVariables', ({ remoteProjectResolver }) =>
230
+ new ActionsSetVariablesCommand(remoteProjectResolver))
231
+ .addService('actionsListFailedEvents', ({ remoteProjectResolver }) =>
232
+ new ActionsListFailedEventsCommand(remoteProjectResolver))
233
+ .addService('actionsRetryEvent', ({ remoteProjectResolver }) =>
234
+ new ActionsRetryEventCommand(remoteProjectResolver))
235
+ .addService('actionsGetEvent', ({ remoteProjectResolver }) =>
236
+ new ActionsGetEventCommand(remoteProjectResolver))
237
+ .addService('actionsStopEvent', ({ remoteProjectResolver }) =>
238
+ new ActionsStopEventCommand(remoteProjectResolver))
239
+
221
240
  .addService('commandList', dic => {
222
241
  const commands: CommandFactoryList = {
223
242
  ['deploy']: () => dic.deployCommand,
@@ -236,6 +255,12 @@ export const createContainer = ({ env, version, runtime, workspace }: {
236
255
  ['project:validate']: () => dic.projectValidateCommand,
237
256
  ['project:print-schema']: () => dic.projectPrintSchemaCommand,
238
257
  ['project:generate-doc']: () => dic.projectGenerateDocumentationCommand,
258
+ ['actions:list-variables']: () => dic.actionsListVariables,
259
+ ['actions:set-variables']: () => dic.actionsSetVariables,
260
+ ['actions:failed-events']: () => dic.actionsListFailedEvents,
261
+ ['actions:retry-event']: () => dic.actionsRetryEvent,
262
+ ['actions:get-event']: () => dic.actionsGetEvent,
263
+ ['actions:stop-event']: () => dic.actionsStopEvent,
239
264
  }
240
265
  return commands
241
266
  })
@@ -46,17 +46,13 @@ export class VersionChecker {
46
46
  if (!def.image) {
47
47
  continue
48
48
  }
49
- const [image, version] = def.image.split(':')
50
- if (!version || !contemberDockerImages.includes(image)) {
49
+ const [image, tag] = def.image.split(':')
50
+ if (!tag || !contemberDockerImages.includes(image)) {
51
51
  continue
52
52
  }
53
- const versionParts = version.split(/[.-]/)
54
- if (versionParts[versionParts.length - 1] === 'debian') {
55
- versionParts.pop()
56
- }
57
- const cliVersionParts = cliVersion.split(/[.-]/).slice(0, versionParts.length)
58
- if (versionParts.join('.') !== cliVersionParts.join('.')) {
59
- errors.push(`Docker service ${name} with image ${image}:${version} does not match version of CLI ${cliVersion}.`)
53
+
54
+ if (extractVersion(tag) !== cliVersion) {
55
+ errors.push(`Docker service ${name} with image ${image}:${tag} does not match version of CLI ${cliVersion}.`)
60
56
  }
61
57
  }
62
58
  }
@@ -69,3 +65,11 @@ Please make sure all dependencies are up to date.\nIf you are really certain abo
69
65
  }
70
66
 
71
67
  }
68
+
69
+
70
+ const extractVersion = (tag: string) => {
71
+ // e.g.
72
+ // 2.1.0-alpha.15-foo-bar => 2.1.0-alpha.15
73
+ // 2.1.0-debian => 2.1.0
74
+ return tag.match(/^\d+\.\d+\.\d+(-\w+\.\d+)?/)?.[0] ?? tag
75
+ }
@@ -0,0 +1,112 @@
1
+ import { GraphQlClient } from '@contember/graphql-client'
2
+
3
+ const createActionsApiUrl = (url: string, project: string) => {
4
+ if (url.endsWith('/')) {
5
+ url = url.substring(0, url.length - 1)
6
+ }
7
+
8
+ return url + '/actions/' + project
9
+ }
10
+ export class ActionsClient {
11
+ constructor(private readonly apiClient: GraphQlClient) {
12
+ }
13
+
14
+ public static create(url: string, project: string, apiToken: string): ActionsClient {
15
+ const graphqlClient = new GraphQlClient({ url: createActionsApiUrl(url, project), apiToken })
16
+ return new ActionsClient(graphqlClient)
17
+ }
18
+
19
+ public async listVariables(): Promise<{ name: string; value: string }[]> {
20
+ const query = `query {
21
+ variables {
22
+ name
23
+ value
24
+ }
25
+ }`
26
+ const result = await this.apiClient.execute<{
27
+ variables: Array<{ name: string; value: string }>
28
+ }>(query)
29
+ return result.variables
30
+ }
31
+
32
+ public async setVariables(variables: { name: string; value: string }[], mode: 'MERGE' | 'SET' | 'APPEND_ONLY_MISSING'): Promise<boolean> {
33
+ const query = `mutation($variables: [VariableInput!]!, $mode: SetVariablesMode) {
34
+ setVariables(args: { variables: $variables, mode: $mode }) {
35
+ ok
36
+ }
37
+ }`
38
+ const result = await this.apiClient.execute<{ setVariables: { ok: boolean } }>(query, { variables: { mode, variables } })
39
+ return result.setVariables.ok
40
+ }
41
+
42
+ public async listFailedEvents({ offset, limit }: { offset?: number; limit?: number } = {}): Promise<Event[]> {
43
+ const query = `query($offset: Int, $limit: Int) {
44
+ failedEvents(args: { offset: $offset, limit: $limit }) {
45
+ id
46
+ createdAt
47
+ lastStateChange
48
+ visibleAt
49
+ numRetries
50
+ state
51
+ target
52
+ payload
53
+ log
54
+ }
55
+ }`
56
+ const result = await this.apiClient.execute<{
57
+ failedEvents: Event[]
58
+ }>(query, { variables: { offset, limit } })
59
+ return result.failedEvents
60
+ }
61
+
62
+ public async retryEvent(id: string): Promise<boolean> {
63
+ const query = `mutation($id: UUID!) {
64
+ retryEvent(id: $id) {
65
+ ok
66
+ }
67
+ }`
68
+ const result = await this.apiClient.execute<{ retryEvent: { ok: boolean } }>(query, { variables: { id } })
69
+ return result.retryEvent.ok
70
+ }
71
+
72
+ public async stopEvent(id: string): Promise<boolean> {
73
+ const query = `mutation($id: UUID!) {
74
+ stopEvent(id: $id) {
75
+ ok
76
+ }
77
+ }`
78
+ const result = await this.apiClient.execute<{ stopEvent: { ok: boolean } }>(query, { variables: { id } })
79
+ return result.stopEvent.ok
80
+ }
81
+
82
+
83
+ public async getEvent(id: string): Promise<Event | null> {
84
+ const query = `query($id: UUID!) {
85
+ event(id: $id) {
86
+ id
87
+ createdAt
88
+ lastStateChange
89
+ visibleAt
90
+ numRetries
91
+ state
92
+ target
93
+ payload
94
+ log
95
+ }
96
+ }`
97
+ const result = await this.apiClient.execute<{ event: Event | null }>(query, { variables: { id } })
98
+ return result.event
99
+ }
100
+ }
101
+
102
+ export type Event = {
103
+ id: string
104
+ createdAt: string
105
+ lastStateChange: string
106
+ visibleAt: string | null
107
+ numRetries: number
108
+ state: 'retrying' | 'failed'
109
+ target: string
110
+ payload: any
111
+ log: any
112
+ }
@@ -50,7 +50,7 @@ export class MigrationPrinter {
50
50
  }
51
51
 
52
52
  printStatusTable = (migrations: AnyMigrationStatus[]) => {
53
- const table = chalkTable(
53
+ return chalkTable(
54
54
  {
55
55
  columns: ['status', 'migration', 'info'],
56
56
  },
@@ -78,12 +78,17 @@ export class MigrationPrinter {
78
78
  }
79
79
  case MigrationState.TO_EXECUTE_ERROR:
80
80
  return { status: chalk.bgRedBright.white('ERROR'), migration: it.name, info: it.errorMessage }
81
+ case MigrationState.SKIP_EMPTY:
82
+ return {
83
+ status: chalk.bgYellow.white('Skip'),
84
+ migration: it.name,
85
+ info: `Skipped because empty`,
86
+ }
81
87
  default:
82
88
  assertNever(it)
83
89
  }
84
90
  }),
85
91
  )
86
- console.log(table)
87
92
  }
88
93
 
89
94
  }
@@ -1,12 +1,13 @@
1
- import { MigrationsResolver, MigrationsStatusResolver, SystemClient } from '@contember/migrations-client'
2
- import { createMigrationStatusTable } from './migrations'
1
+ import { MigrationsResolver, MigrationsStatusResolver } from '@contember/migrations-client'
3
2
  import { SystemClientProvider } from '../SystemClientProvider'
3
+ import { MigrationPrinter } from './MigrationPrinter'
4
4
 
5
5
  export class MigrationsStatusFacade {
6
6
  constructor(
7
7
  private readonly systemClientProvider: SystemClientProvider,
8
8
  private readonly migrationsResolver: MigrationsResolver,
9
9
  private readonly migrationsStatusResolver: MigrationsStatusResolver,
10
+ private readonly migrationPrinter: MigrationPrinter,
10
11
  ) {
11
12
  }
12
13
 
@@ -16,7 +17,7 @@ export class MigrationsStatusFacade {
16
17
  const localMigrations = await this.migrationsResolver.getMigrationFiles()
17
18
  const status = await this.migrationsStatusResolver.getMigrationsStatus(executedMigrations, localMigrations, force)
18
19
  if (status.errorMigrations.length > 0 && !allowError) {
19
- console.error(createMigrationStatusTable(status.errorMigrations))
20
+ console.error(this.migrationPrinter.printStatusTable(status.errorMigrations))
20
21
  if (!force) {
21
22
  throw `Cannot execute migrations`
22
23
  }