MCPcopy
hub / github.com/prisma/prisma / loadOrInitializeCommandState

Function loadOrInitializeCommandState

packages/cli/src/utils/commandState.ts:17–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15 * The command state contains the timestamp of the first command issued.
16 */
17export async function loadOrInitializeCommandState(): Promise<CommandState> {
18 const filePath = getCommandStatePath()
19 const data = await fs.promises
20 .readFile(filePath, 'utf-8')
21 .catch((err) => (err.code === 'ENOENT' ? Promise.resolve(undefined) : Promise.reject(err)))
22 const state = data === undefined ? { firstCommandTimestamp: new Date().toISOString() } : JSON.parse(data)
23
24 if (data === undefined) {
25 await fs.promises.writeFile(filePath, JSON.stringify(state))
26 }
27
28 if (typeof state.firstCommandTimestamp === 'string') {
29 return state
30 } else {
31 throw new Error('Invalid command state schema')
32 }
33}
34
35/*
36 * Calculates the number of days since the first command was issued.

Callers 3

mainFunction · 0.90
handleNpsSurveyFunction · 0.90

Calls 3

getCommandStatePathFunction · 0.85
catchMethod · 0.80
parseMethod · 0.65

Tested by

no test coverage detected