diff options
Diffstat (limited to 'packages/db/src/core')
-rw-r--r-- | packages/db/src/core/cli/commands/link/index.ts | 18 | ||||
-rw-r--r-- | packages/db/src/core/cli/commands/push/index.ts | 2 | ||||
-rw-r--r-- | packages/db/src/core/cli/commands/shell/index.ts | 2 | ||||
-rw-r--r-- | packages/db/src/core/cli/migration-queries.ts | 28 | ||||
-rw-r--r-- | packages/db/src/core/cli/print-help.ts | 4 | ||||
-rw-r--r-- | packages/db/src/core/consts.ts | 2 | ||||
-rw-r--r-- | packages/db/src/core/errors.ts | 6 | ||||
-rw-r--r-- | packages/db/src/core/integration/error-map.ts | 12 | ||||
-rw-r--r-- | packages/db/src/core/integration/index.ts | 6 | ||||
-rw-r--r-- | packages/db/src/core/integration/vite-plugin-db.ts | 4 | ||||
-rw-r--r-- | packages/db/src/core/integration/vite-plugin-inject-env-ts.ts | 6 | ||||
-rw-r--r-- | packages/db/src/core/load-file.ts | 2 | ||||
-rw-r--r-- | packages/db/src/core/queries.ts | 10 | ||||
-rw-r--r-- | packages/db/src/core/schemas.ts | 10 | ||||
-rw-r--r-- | packages/db/src/core/utils.ts | 4 |
15 files changed, 58 insertions, 58 deletions
diff --git a/packages/db/src/core/cli/commands/link/index.ts b/packages/db/src/core/cli/commands/link/index.ts index 78d64b537..d39b8c09a 100644 --- a/packages/db/src/core/cli/commands/link/index.ts +++ b/packages/db/src/core/cli/commands/link/index.ts @@ -69,12 +69,12 @@ async function getWorkspaces(sessionToken: string) { if (res.status === 401) { throw new Error( `${bgRed('Unauthorized')}\n\n Are you logged in?\n Run ${cyan( - 'astro login' - )} to authenticate and then try linking again.\n\n` + 'astro login', + )} to authenticate and then try linking again.\n\n`, ); } throw new Error(`Failed to fetch user workspace: ${res.status} ${res.statusText}`); - } + }, ); const { data, success } = (await response.json()) as Result<{ id: string; name: string }[]>; @@ -139,14 +139,14 @@ export async function createNewProject({ if (res.status === 401) { console.error( `${bgRed('Unauthorized')}\n\n Are you logged in?\n Run ${cyan( - 'astro login' - )} to authenticate and then try linking again.\n\n` + 'astro login', + )} to authenticate and then try linking again.\n\n`, ); process.exit(1); } console.error(`Failed to create project: ${res.status} ${res.statusText}`); process.exit(1); - } + }, ); const { data, success } = (await response.json()) as Result<{ id: string; idName: string }>; @@ -173,14 +173,14 @@ export async function promptExistingProjectName({ workspaceId }: { workspaceId: if (res.status === 401) { console.error( `${bgRed('Unauthorized')}\n\n Are you logged in?\n Run ${cyan( - 'astro login' - )} to authenticate and then try linking again.\n\n` + 'astro login', + )} to authenticate and then try linking again.\n\n`, ); process.exit(1); } console.error(`Failed to fetch projects: ${res.status} ${res.statusText}`); process.exit(1); - } + }, ); const { data, success } = (await response.json()) as Result< diff --git a/packages/db/src/core/cli/commands/push/index.ts b/packages/db/src/core/cli/commands/push/index.ts index bfccdf5f8..ecd101ece 100644 --- a/packages/db/src/core/cli/commands/push/index.ts +++ b/packages/db/src/core/cli/commands/push/index.ts @@ -110,7 +110,7 @@ async function pushSchema({ console.error(`${url.toString()} failed: ${res.status} ${res.statusText}`); console.error(await res.text()); throw new Error(`/db/push fetch failed: ${res.status} ${res.statusText}`); - } + }, ); const result = (await response.json()) as Result<never>; diff --git a/packages/db/src/core/cli/commands/shell/index.ts b/packages/db/src/core/cli/commands/shell/index.ts index 7a4115abc..e0a1a6086 100644 --- a/packages/db/src/core/cli/commands/shell/index.ts +++ b/packages/db/src/core/cli/commands/shell/index.ts @@ -35,7 +35,7 @@ export async function cmd({ const { ASTRO_DATABASE_FILE } = getAstroEnv(); const dbUrl = normalizeDatabaseUrl( ASTRO_DATABASE_FILE, - new URL(DB_PATH, astroConfig.root).href + new URL(DB_PATH, astroConfig.root).href, ); const db = createLocalDatabaseClient({ dbUrl }); const result = await db.run(sql.raw(query)); diff --git a/packages/db/src/core/cli/migration-queries.ts b/packages/db/src/core/cli/migration-queries.ts index f00d194bf..894c1d66f 100644 --- a/packages/db/src/core/cli/migration-queries.ts +++ b/packages/db/src/core/cli/migration-queries.ts @@ -61,7 +61,7 @@ export async function getMigrationQueries({ const addedTables = getAddedTables(oldSnapshot, newSnapshot); const droppedTables = getDroppedTables(oldSnapshot, newSnapshot); const notDeprecatedDroppedTables = Object.fromEntries( - Object.entries(droppedTables).filter(([, table]) => !table.deprecated) + Object.entries(droppedTables).filter(([, table]) => !table.deprecated), ); if (!isEmpty(addedTables) && !isEmpty(notDeprecatedDroppedTables)) { const oldTable = Object.keys(notDeprecatedDroppedTables)[0]; @@ -85,14 +85,14 @@ export async function getMigrationQueries({ const addedColumns = getAdded(oldTable.columns, newTable.columns); const droppedColumns = getDropped(oldTable.columns, newTable.columns); const notDeprecatedDroppedColumns = Object.fromEntries( - Object.entries(droppedColumns).filter(([, col]) => !col.schema.deprecated) + Object.entries(droppedColumns).filter(([, col]) => !col.schema.deprecated), ); if (!isEmpty(addedColumns) && !isEmpty(notDeprecatedDroppedColumns)) { throw new Error( RENAME_COLUMN_ERROR( `${tableName}.${Object.keys(addedColumns)[0]}`, - `${tableName}.${Object.keys(notDeprecatedDroppedColumns)[0]}` - ) + `${tableName}.${Object.keys(notDeprecatedDroppedColumns)[0]}`, + ), ); } const result = await getTableChangeQueries({ @@ -146,7 +146,7 @@ export async function getTableChangeQueries({ tableName, oldIndexes: oldTable.indexes, newIndexes: newTable.indexes, - }) + }), ); return { queries, confirmations }; } @@ -156,17 +156,17 @@ export async function getTableChangeQueries({ const { reason, columnName } = dataLossCheck; const reasonMsgs: Record<DataLossReason, string> = { 'added-required': `You added new required column '${color.bold( - tableName + '.' + columnName + tableName + '.' + columnName, )}' with no default value.\n This cannot be executed on an existing table.`, 'updated-type': `Updating existing column ${color.bold( - tableName + '.' + columnName + tableName + '.' + columnName, )} to a new type that cannot be handled automatically.`, }; confirmations.push(reasonMsgs[reason]); } const primaryKeyExists = Object.entries(newTable.columns).find(([, column]) => - hasPrimaryKey(column) + hasPrimaryKey(column), ); const droppedPrimaryKey = Object.entries(dropped).find(([, column]) => hasPrimaryKey(column)); @@ -229,7 +229,7 @@ function getDroppedTables(oldTables: DBSnapshot, newTables: DBSnapshot): Resolve function getAlterTableQueries( unescTableName: string, added: DBColumns, - dropped: DBColumns + dropped: DBColumns, ): string[] { const queries: string[] = []; const tableName = sqlite.escapeName(unescTableName); @@ -239,7 +239,7 @@ function getAlterTableQueries( const type = schemaTypeToSqlType(column.type); const q = `ALTER TABLE ${tableName} ADD COLUMN ${columnName} ${type}${getModifiers( columnName, - column + column, )}`; queries.push(q); } @@ -322,7 +322,7 @@ type DataLossResponse = function canRecreateTableWithoutDataLoss( added: DBColumns, - updated: UpdatedColumns + updated: UpdatedColumns, ): DataLossResponse { for (const [columnName, a] of Object.entries(added)) { if (hasPrimaryKey(a) && a.type !== 'number' && !hasDefault(a)) { @@ -404,7 +404,7 @@ const typeChangesWithoutQuery: Array<{ from: ColumnType; to: ColumnType }> = [ function canChangeTypeWithoutQuery(oldColumn: DBColumn, newColumn: DBColumn) { return typeChangesWithoutQuery.some( - ({ from, to }) => oldColumn.type === from && newColumn.type === to + ({ from, to }) => oldColumn.type === from && newColumn.type === to, ); } @@ -441,7 +441,7 @@ export async function getProductionCurrentSnapshot({ console.error(`${url.toString()} failed: ${res.status} ${res.statusText}`); console.error(await res.text()); throw new Error(`/db/schema fetch failed: ${res.status} ${res.statusText}`); - } + }, ); const result = (await response.json()) as Result<DBSnapshot>; @@ -479,7 +479,7 @@ export function formatDataLossMessage(confirmations: string[], isColor = true): messages.push(``); messages.push(`To resolve, revert these changes or update your schema, and re-run the command.`); messages.push( - `You may also run 'astro db push --force-reset' to ignore all warnings and force-push your local database schema to production instead. All data will be lost and the database will be reset.` + `You may also run 'astro db push --force-reset' to ignore all warnings and force-push your local database schema to production instead. All data will be lost and the database will be reset.`, ); let finalMessage = messages.join('\n'); if (!isColor) { diff --git a/packages/db/src/core/cli/print-help.ts b/packages/db/src/core/cli/print-help.ts index 8700301dd..4082380b2 100644 --- a/packages/db/src/core/cli/print-help.ts +++ b/packages/db/src/core/cli/print-help.ts @@ -41,8 +41,8 @@ export function printHelp({ message.push( linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green( - `v${process.env.PACKAGE_VERSION ?? ''}` - )} ${headline}` + `v${process.env.PACKAGE_VERSION ?? ''}`, + )} ${headline}`, ); } diff --git a/packages/db/src/core/consts.ts b/packages/db/src/core/consts.ts index c37f1b99d..703a91dca 100644 --- a/packages/db/src/core/consts.ts +++ b/packages/db/src/core/consts.ts @@ -1,7 +1,7 @@ import { readFileSync } from 'node:fs'; export const PACKAGE_NAME = JSON.parse( - readFileSync(new URL('../../package.json', import.meta.url), 'utf8') + readFileSync(new URL('../../package.json', import.meta.url), 'utf8'), ).name; export const RUNTIME_IMPORT = JSON.stringify(`${PACKAGE_NAME}/runtime`); diff --git a/packages/db/src/core/errors.ts b/packages/db/src/core/errors.ts index 5c8c196db..5272fd3c2 100644 --- a/packages/db/src/core/errors.ts +++ b/packages/db/src/core/errors.ts @@ -1,7 +1,7 @@ import { bold, cyan, red } from 'kleur/colors'; export const MISSING_EXECUTE_PATH_ERROR = `${red( - '▶ No file path provided.' + '▶ No file path provided.', )} Provide a path by running ${cyan('astro db execute <path>')}\n`; export const RENAME_TABLE_ERROR = (oldTable: string, newTable: string) => { @@ -28,7 +28,7 @@ export const RENAME_COLUMN_ERROR = (oldSelector: string, newSelector: string) => export const FILE_NOT_FOUND_ERROR = (path: string) => `${red('▶ File not found:')} ${bold(path)}\n`; export const SHELL_QUERY_MISSING_ERROR = `${red( - '▶ Please provide a query to execute using the --query flag.' + '▶ Please provide a query to execute using the --query flag.', )}\n`; export const EXEC_ERROR = (error: string) => { @@ -42,7 +42,7 @@ export const EXEC_DEFAULT_EXPORT_ERROR = (fileName: string) => { export const INTEGRATION_TABLE_CONFLICT_ERROR = ( integrationName: string, tableName: string, - isUserConflict: boolean + isUserConflict: boolean, ) => { return red('▶ Conflicting table name in integration ' + bold(integrationName)) + isUserConflict ? `\n A user-defined table named ${bold(tableName)} already exists` diff --git a/packages/db/src/core/integration/error-map.ts b/packages/db/src/core/integration/error-map.ts index e471fead5..d2697c9ca 100644 --- a/packages/db/src/core/integration/error-map.ts +++ b/packages/db/src/core/integration/error-map.ts @@ -37,7 +37,7 @@ export const errorMap: z.ZodErrorMap = (baseError, ctx) => { const messages: string[] = [ prefix( baseErrorPath, - typeOrLiteralErrByPath.size ? 'Did not match union:' : 'Did not match union.' + typeOrLiteralErrByPath.size ? 'Did not match union:' : 'Did not match union.', ), ]; return { @@ -51,8 +51,8 @@ export const errorMap: z.ZodErrorMap = (baseError, ctx) => { // Avoid printing the key again if it's a base error key === baseErrorPath ? `> ${getTypeOrLiteralMsg(error)}` - : `> ${prefix(key, getTypeOrLiteralMsg(error))}` - ) + : `> ${prefix(key, getTypeOrLiteralMsg(error))}`, + ), ) .join('\n'), }; @@ -65,7 +65,7 @@ export const errorMap: z.ZodErrorMap = (baseError, ctx) => { code: baseError.code, received: (baseError as any).received, expected: [baseError.expected], - }) + }), ), }; } else if (baseError.message) { @@ -81,11 +81,11 @@ const getTypeOrLiteralMsg = (error: TypeOrLiteralErrByPathEntry): string => { switch (error.code) { case 'invalid_type': return `Expected type \`${unionExpectedVals(expectedDeduped)}\`, received ${JSON.stringify( - error.received + error.received, )}`; case 'invalid_literal': return `Expected \`${unionExpectedVals(expectedDeduped)}\`, received ${JSON.stringify( - error.received + error.received, )}`; } }; diff --git a/packages/db/src/core/integration/index.ts b/packages/db/src/core/integration/index.ts index 9be71956f..19c712c80 100644 --- a/packages/db/src/core/integration/index.ts +++ b/packages/db/src/core/integration/index.ts @@ -141,12 +141,12 @@ function astroDBIntegration(): AstroIntegration { // Wait for dev server log before showing "connected". setTimeout(() => { logger.info( - connectToStudio ? 'Connected to remote database.' : 'New local database created.' + connectToStudio ? 'Connected to remote database.' : 'New local database created.', ); if (connectToStudio) return; const localSeedPaths = SEED_DEV_FILE_NAME.map( - (name) => new URL(name, getDbDirectoryUrl(root)) + (name) => new URL(name, getDbDirectoryUrl(root)), ); // Eager load astro:db module on startup if (seedFiles.get().length || localSeedPaths.find((path) => existsSync(path))) { @@ -224,7 +224,7 @@ async function getTempViteServer({ viteConfig }: { viteConfig: UserConfig }) { optimizeDeps: { noDiscovery: true }, ssr: { external: [] }, logLevel: 'silent', - }) + }), ); const hotSend = tempViteServer.hot.send; diff --git a/packages/db/src/core/integration/vite-plugin-db.ts b/packages/db/src/core/integration/vite-plugin-db.ts index cd334b4de..05cfa3ef0 100644 --- a/packages/db/src/core/integration/vite-plugin-db.ts +++ b/packages/db/src/core/integration/vite-plugin-db.ts @@ -178,8 +178,8 @@ function getStringifiedTableExports(tables: DBTables) { .map( ([name, table]) => `export const ${name} = asDrizzleTable(${JSON.stringify(name)}, ${JSON.stringify( - table - )}, false)` + table, + )}, false)`, ) .join('\n'); } diff --git a/packages/db/src/core/integration/vite-plugin-inject-env-ts.ts b/packages/db/src/core/integration/vite-plugin-inject-env-ts.ts index 58faa7045..14257d480 100644 --- a/packages/db/src/core/integration/vite-plugin-inject-env-ts.ts +++ b/packages/db/src/core/integration/vite-plugin-inject-env-ts.ts @@ -10,7 +10,7 @@ import type { VitePlugin } from '../utils.js'; export function vitePluginInjectEnvTs( { srcDir, root }: { srcDir: URL; root: URL }, - logger: AstroIntegrationLogger + logger: AstroIntegrationLogger, ): VitePlugin { return { name: 'db-inject-env-ts', @@ -32,7 +32,7 @@ export async function setUpEnvTs({ }) { const envTsPath = getEnvTsPath({ srcDir }); const envTsPathRelativetoRoot = normalizePath( - path.relative(fileURLToPath(root), fileURLToPath(envTsPath)) + path.relative(fileURLToPath(root), fileURLToPath(envTsPath)), ); if (existsSync(envTsPath)) { @@ -54,7 +54,7 @@ export async function setUpEnvTs({ function getDBTypeReference({ srcDir, dotAstroDir }: { srcDir: URL; dotAstroDir: URL }) { const dbTypesFile = new URL(DB_TYPES_FILE, dotAstroDir); const contentTypesRelativeToSrcDir = normalizePath( - path.relative(fileURLToPath(srcDir), fileURLToPath(dbTypesFile)) + path.relative(fileURLToPath(srcDir), fileURLToPath(dbTypesFile)), ); return `/// <reference path=${JSON.stringify(contentTypesRelativeToSrcDir)} />`; diff --git a/packages/db/src/core/load-file.ts b/packages/db/src/core/load-file.ts index cbdb6d243..b9fb0136c 100644 --- a/packages/db/src/core/load-file.ts +++ b/packages/db/src/core/load-file.ts @@ -69,7 +69,7 @@ export async function resolveDbConfig({ } async function loadUserConfigFile( - root: URL + root: URL, ): Promise<{ mod: { default?: unknown } | undefined; dependencies: string[] }> { let configFileUrl: URL | undefined; for (const fileName of CONFIG_FILE_NAMES) { diff --git a/packages/db/src/core/queries.ts b/packages/db/src/core/queries.ts index 70ea0cf0e..705205ee4 100644 --- a/packages/db/src/core/queries.ts +++ b/packages/db/src/core/queries.ts @@ -33,14 +33,14 @@ export function getCreateTableQuery(tableName: string, table: DBTable) { const colQueries = []; const colHasPrimaryKey = Object.entries(table.columns).find(([, column]) => - hasPrimaryKey(column) + hasPrimaryKey(column), ); if (!colHasPrimaryKey) { colQueries.push('_id INTEGER PRIMARY KEY'); } for (const [columnName, column] of Object.entries(table.columns)) { const colQuery = `${sqlite.escapeName(columnName)} ${schemaTypeToSqlType( - column.type + column.type, )}${getModifiers(columnName, column)}`; colQueries.push(colQuery); } @@ -59,7 +59,7 @@ export function getCreateIndexQueries(tableName: string, table: Pick<DBTable, 'i const unique = indexProps.unique ? 'UNIQUE ' : ''; const indexQuery = `CREATE ${unique}INDEX ${sqlite.escapeName( - indexName + indexName, )} ON ${sqlite.escapeName(tableName)} (${onCols.join(', ')})`; queries.push(indexQuery); } @@ -194,8 +194,8 @@ function getDefaultValueSql(columnName: string, column: DBColumnWithDefault): st // eslint-disable-next-line no-console console.log( `Invalid default value for column ${bold( - columnName - )}. Defaults must be valid JSON when using the \`json()\` type.` + columnName, + )}. Defaults must be valid JSON when using the \`json()\` type.`, ); process.exit(0); } diff --git a/packages/db/src/core/schemas.ts b/packages/db/src/core/schemas.ts index a2a8368fb..c9575a79a 100644 --- a/packages/db/src/core/schemas.ts +++ b/packages/db/src/core/schemas.ts @@ -15,7 +15,7 @@ const sqlSchema = z.instanceof(SQL<any>).transform( (sqlObj): SerializedSQL => ({ [SERIALIZED_SQL_KEY]: true, sql: sqlite.sqlToQuery(sqlObj).sql, - }) + }), ); const baseColumnSchema = z.object({ @@ -52,7 +52,7 @@ const numberColumnBaseSchema = baseColumnSchema.omit({ optional: true }).and( optional: z.literal(false).optional(), default: z.literal(undefined).optional(), }), - ]) + ]), ); export const numberColumnOptsSchema: z.ZodType< @@ -71,7 +71,7 @@ export const numberColumnOptsSchema: z.ZodType< .returns(z.lazy(() => numberColumnSchema)) .optional() .transform((fn) => fn?.()), - }) + }), ); export const numberColumnSchema = z.object({ @@ -99,7 +99,7 @@ const textColumnBaseSchema = baseColumnSchema primaryKey: z.literal(true), optional: z.literal(false).optional(), }), - ]) + ]), ); export const textColumnOptsSchema: z.ZodType< @@ -118,7 +118,7 @@ export const textColumnOptsSchema: z.ZodType< .returns(z.lazy(() => textColumnSchema)) .optional() .transform((fn) => fn?.()), - }) + }), ); export const textColumnSchema = z.object({ diff --git a/packages/db/src/core/utils.ts b/packages/db/src/core/utils.ts index c1cf56579..6229cb070 100644 --- a/packages/db/src/core/utils.ts +++ b/packages/db/src/core/utils.ts @@ -31,9 +31,9 @@ export type Result<T> = { success: true; data: T } | { success: false; data: unk */ export function mapObject<T, U = T>( item: Record<string, T>, - callback: (key: string, value: T) => U + callback: (key: string, value: T) => U, ): Record<string, U> { return Object.fromEntries( - Object.entries(item).map(([key, value]) => [key, callback(key, value)]) + Object.entries(item).map(([key, value]) => [key, callback(key, value)]), ); } |