@coalescesoftware/coa 1.0.153 → 1.0.157
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/package.json +2 -2
- package/src/CLIProfile.ts +172 -0
- package/src/CommonCLI.ts +133 -0
- package/src/Deploy.ts +84 -0
- package/src/Package.ts +1017 -0
- package/src/Plan.ts +29 -0
- package/src/Refresh.ts +67 -0
- package/src/RunOutput.ts +81 -0
- package/src/index.tsx +556 -0
- package/bin/CLIProfile.js +0 -161
- package/bin/CommonCLI.js +0 -139
- package/bin/Deploy.js +0 -71
- package/bin/Package.js +0 -757
- package/bin/Plan.js +0 -41
- package/bin/Refresh.js +0 -66
- package/bin/RunOutput.js +0 -86
- package/bin/index.js +0 -488
package/src/Plan.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as Shared from "@coalescesoftware/shared"
|
|
2
|
+
import fs from "fs"
|
|
3
|
+
|
|
4
|
+
export const CreatePlan = (
|
|
5
|
+
path: string,
|
|
6
|
+
environmentID: number,
|
|
7
|
+
token: string,
|
|
8
|
+
message: string,
|
|
9
|
+
runtimeParameters: Shared.Runner.TRunTimeParametersStringType
|
|
10
|
+
) => {
|
|
11
|
+
const fsSettings: Shared.GitOperations.Filesystem = {
|
|
12
|
+
fs: fs,
|
|
13
|
+
dir: path,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return Shared.DeployOperations.CreatePlanCLI(
|
|
17
|
+
environmentID,
|
|
18
|
+
fsSettings,
|
|
19
|
+
token,
|
|
20
|
+
Shared.Templates.PlatformType.snowflake,
|
|
21
|
+
runtimeParameters,
|
|
22
|
+
)
|
|
23
|
+
.then(result => {
|
|
24
|
+
const { plan } = result
|
|
25
|
+
plan.gitInfo = { commit: { message: message }, oid: "" }
|
|
26
|
+
|
|
27
|
+
return result
|
|
28
|
+
})
|
|
29
|
+
}
|
package/src/Refresh.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as Shared from "@coalescesoftware/shared"
|
|
2
|
+
import * as CommonCLI from "./CommonCLI"
|
|
3
|
+
const CryptoJS = require("crypto-js")
|
|
4
|
+
const v8 = require("v8")
|
|
5
|
+
|
|
6
|
+
Shared.Snowflake.CryptoJS = CryptoJS
|
|
7
|
+
Shared.Snowflake.salt = CryptoJS.lib.WordArray.random(128 / 8)
|
|
8
|
+
Shared.Snowflake.v8 = v8
|
|
9
|
+
|
|
10
|
+
const LogCLI = Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI)
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param token
|
|
14
|
+
* @param runInfo
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export const RefreshWithCLI = (
|
|
18
|
+
token: string,
|
|
19
|
+
runInfo: Shared.Runner.IRunInfo,
|
|
20
|
+
): Promise<Shared.SchedulerOperations.IRunCounterAndRunCompletion> => {
|
|
21
|
+
let firebase: any
|
|
22
|
+
let logContext: Shared.Logging.LogContext
|
|
23
|
+
let RunSQL: Shared.RunStepHelpers.TRunSQL, teamDetailsStored: Shared.ConnectionOperations.ITeamInfoAndFirebase
|
|
24
|
+
|
|
25
|
+
return Shared.SchedulerOperations.AuthenticateFirebaseTokenAndRetrieveTeamInfoForCLI(
|
|
26
|
+
token,
|
|
27
|
+
undefined,
|
|
28
|
+
)
|
|
29
|
+
.then((teamInfoAndFirebase: Shared.ConnectionOperations.ITeamInfoAndFirebase) => {
|
|
30
|
+
teamDetailsStored = teamInfoAndFirebase
|
|
31
|
+
const { teamInfo: { fbUserID: userID, fbTeamID: teamID } } = teamInfoAndFirebase
|
|
32
|
+
firebase = teamInfoAndFirebase.firebase
|
|
33
|
+
const environmentID: string = runInfo.runDetails.environmentID!
|
|
34
|
+
logContext = Shared.Logging.CreateLogContext(teamID, environmentID, userID)
|
|
35
|
+
const connectionCache: Shared.Snowflake.ConnectionStorageClass =
|
|
36
|
+
new Shared.Snowflake.ConnectionStorageClass()
|
|
37
|
+
|
|
38
|
+
RunSQL = Shared.SQLExecutorCreators.CreateRunSQLWithoutScheduler(
|
|
39
|
+
teamInfoAndFirebase,
|
|
40
|
+
connectionCache,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
LogCLI.infoContext(logContext, "Starting refresh (CLI)")
|
|
44
|
+
|
|
45
|
+
return CommonCLI.GetUserConnectionForCLI(
|
|
46
|
+
userID,
|
|
47
|
+
runInfo
|
|
48
|
+
)
|
|
49
|
+
})
|
|
50
|
+
.then((connection: Shared.ConnectionOperations.IUserConnection) => {
|
|
51
|
+
return Shared.SchedulerOperations.BECLI_HandleRefresh(
|
|
52
|
+
runInfo,
|
|
53
|
+
teamDetailsStored,
|
|
54
|
+
RunSQL,
|
|
55
|
+
connection,
|
|
56
|
+
)
|
|
57
|
+
})
|
|
58
|
+
.then(({ runCounter, runCompletion }: Shared.SchedulerOperations.IRunCounterAndRunCompletion) => {
|
|
59
|
+
const cleanupPromise = CommonCLI.CleanupCLIJob(runCompletion, firebase, logContext, "Refresh")
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
runCounter,
|
|
63
|
+
runCompletion: cleanupPromise,
|
|
64
|
+
logContext,
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
}
|
package/src/RunOutput.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as Shared from '@coalescesoftware/shared'
|
|
2
|
+
import * as RunTypes from 'runtypes'
|
|
3
|
+
|
|
4
|
+
const CLILogger = Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI)
|
|
5
|
+
|
|
6
|
+
//convert from firestore shape to run output shape
|
|
7
|
+
const cleanRunResult = (nodeID:string,runResult:Shared.RunnerOperations.RunResultInterface):Shared.RunsTypes.TRunResultOutput=> {
|
|
8
|
+
return {
|
|
9
|
+
nodeID,
|
|
10
|
+
queryResultSequence:runResult.queryResultSequence
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const GetRunOutputForRunCounter = (firestore: any, teamID, runID: Shared.Runs.TRunID): Promise<Shared.RunsTypes.TRunOutput> => {
|
|
16
|
+
let runData: Partial<Shared.RunsTypes.TRunOutput>
|
|
17
|
+
return Shared.Runs.getRun(firestore, teamID, runID).get()
|
|
18
|
+
.then((runDataResult/*query snapshot*/) => {
|
|
19
|
+
if (!runDataResult.docs.length) {
|
|
20
|
+
const errorMessage = `wasnt able to get exactly one run for runID ${runID}`
|
|
21
|
+
CLILogger.emergContext({
|
|
22
|
+
orgID: teamID
|
|
23
|
+
}, errorMessage)
|
|
24
|
+
throw new Error(errorMessage)
|
|
25
|
+
}
|
|
26
|
+
const runInfo = runDataResult.docs[0].data()
|
|
27
|
+
runData = {
|
|
28
|
+
runResults: {
|
|
29
|
+
runStartTime: runInfo.runStartTime,
|
|
30
|
+
runEndTime: runInfo.runEndTime,
|
|
31
|
+
runType: runInfo.runType,
|
|
32
|
+
runStatus: runInfo.runStatus,
|
|
33
|
+
runID: runInfo.id,
|
|
34
|
+
runResults: []
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return Shared.Runs.getRunRunResultsCollection(firestore,
|
|
38
|
+
teamID, runID.toString())
|
|
39
|
+
.get().then((queryResult/*querySnapshot*/) => {
|
|
40
|
+
let runResults= {}
|
|
41
|
+
queryResult.docs.forEach((runResultDoc) => {
|
|
42
|
+
|
|
43
|
+
const stepCounter = runResultDoc.id
|
|
44
|
+
const runResult = runResultDoc.data()
|
|
45
|
+
Shared.RunsTypes.RunResult.check(runResult)
|
|
46
|
+
runResults[stepCounter] = cleanRunResult(stepCounter,
|
|
47
|
+
runResult as Shared.RunnerOperations.RunResultInterface
|
|
48
|
+
)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const executionSequence = Shared.Runs.GetExecutionSequenceFromRunResults(runResults)
|
|
52
|
+
runData.runResults!.runResults = executionSequence.map((stepCounter) => {
|
|
53
|
+
return runResults[stepCounter]
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
}).then(() => {
|
|
57
|
+
return runData as Shared.RunsTypes.TRunOutput;
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const SaveRunOutputToFile = (runOutputFileLocation: string,
|
|
62
|
+
runIDString: string, token: string
|
|
63
|
+
): Promise<void> => {
|
|
64
|
+
return Shared.SchedulerOperations.AuthenticateFirebaseTokenAndRetrieveTeamInfoForCLI(token,
|
|
65
|
+
undefined
|
|
66
|
+
).then((authInfo: Shared.ConnectionOperations.ITeamInfoAndFirebase) => {
|
|
67
|
+
const { teamInfo, firebase } = authInfo
|
|
68
|
+
const teamID = teamInfo.fbTeamID
|
|
69
|
+
const firestore = firebase.firestore()
|
|
70
|
+
const runID = parseInt(runIDString)
|
|
71
|
+
return GetRunOutputForRunCounter(firestore,
|
|
72
|
+
teamID,
|
|
73
|
+
runID
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
}).then((runOutput: Shared.RunsTypes.TRunOutput) => {
|
|
77
|
+
Shared.RunsTypes.RRunOutput.check(runOutput)
|
|
78
|
+
const runOutputJSON = Shared.Common.StringifyFirestoreObject(runOutput)
|
|
79
|
+
return Shared.Common.WriteFile(runOutputFileLocation , runOutputJSON + "\n")
|
|
80
|
+
})
|
|
81
|
+
}
|