summaryrefslogtreecommitdiff
path: root/packages/db/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/db/src')
-rw-r--r--packages/db/src/core/cli/commands/gen/index.ts6
-rw-r--r--packages/db/src/core/cli/commands/link/index.ts4
-rw-r--r--packages/db/src/core/cli/commands/login/index.ts8
-rw-r--r--packages/db/src/core/cli/commands/logout/index.ts2
-rw-r--r--packages/db/src/core/cli/commands/push/index.ts16
-rw-r--r--packages/db/src/core/cli/commands/verify/index.ts6
-rw-r--r--packages/db/src/core/cli/migration-queries.ts36
-rw-r--r--packages/db/src/core/cli/migrations.ts4
-rw-r--r--packages/db/src/core/errors.ts2
-rw-r--r--packages/db/src/core/integration/file-url.ts6
-rw-r--r--packages/db/src/core/integration/index.ts24
-rw-r--r--packages/db/src/core/integration/typegen.ts2
-rw-r--r--packages/db/src/core/integration/vite-plugin-inject-env-ts.ts2
-rw-r--r--packages/db/src/core/queries.ts12
-rw-r--r--packages/db/src/core/tokens.ts2
-rw-r--r--packages/db/src/core/types.ts8
-rw-r--r--packages/db/src/runtime/db-client.ts6
-rw-r--r--packages/db/src/runtime/index.ts12
-rw-r--r--packages/db/src/runtime/types.ts4
19 files changed, 81 insertions, 81 deletions
diff --git a/packages/db/src/core/cli/commands/gen/index.ts b/packages/db/src/core/cli/commands/gen/index.ts
index 551350306..25f59be45 100644
--- a/packages/db/src/core/cli/commands/gen/index.ts
+++ b/packages/db/src/core/cli/commands/gen/index.ts
@@ -1,14 +1,14 @@
+import { writeFile } from 'node:fs/promises';
import type { AstroConfig } from 'astro';
+import { bgRed, red, reset } from 'kleur/colors';
import type { Arguments } from 'yargs-parser';
-import { writeFile } from 'node:fs/promises';
+import { getMigrationQueries } from '../../migration-queries.js';
import {
MIGRATIONS_CREATED,
MIGRATIONS_UP_TO_DATE,
getMigrationStatus,
initializeMigrationsDirectory,
} from '../../migrations.js';
-import { getMigrationQueries } from '../../migration-queries.js';
-import { bgRed, red, reset } from 'kleur/colors';
export async function cmd({ config }: { config: AstroConfig; flags: Arguments }) {
const migration = await getMigrationStatus(config);
diff --git a/packages/db/src/core/cli/commands/link/index.ts b/packages/db/src/core/cli/commands/link/index.ts
index ef32341e6..542782bd3 100644
--- a/packages/db/src/core/cli/commands/link/index.ts
+++ b/packages/db/src/core/cli/commands/link/index.ts
@@ -1,11 +1,11 @@
-import type { AstroConfig } from 'astro';
import { mkdir, writeFile } from 'node:fs/promises';
+import type { AstroConfig } from 'astro';
import { bgRed, cyan } from 'kleur/colors';
import prompts from 'prompts';
import type { Arguments } from 'yargs-parser';
+import { MISSING_SESSION_ID_ERROR } from '../../../errors.js';
import { PROJECT_ID_FILE, getSessionIdFromFile } from '../../../tokens.js';
import { getAstroStudioUrl } from '../../../utils.js';
-import { MISSING_SESSION_ID_ERROR } from '../../../errors.js';
export async function cmd({ flags }: { config: AstroConfig; flags: Arguments }) {
const linkUrl = new URL(getAstroStudioUrl() + '/auth/cli/link');
diff --git a/packages/db/src/core/cli/commands/login/index.ts b/packages/db/src/core/cli/commands/login/index.ts
index e9548772a..fb0f105bc 100644
--- a/packages/db/src/core/cli/commands/login/index.ts
+++ b/packages/db/src/core/cli/commands/login/index.ts
@@ -1,12 +1,12 @@
-import type { AstroConfig } from 'astro';
-import { cyan } from 'kleur/colors';
import { mkdir, writeFile } from 'node:fs/promises';
import { createServer } from 'node:http';
+import type { AstroConfig } from 'astro';
+import { cyan } from 'kleur/colors';
+import open from 'open';
import ora from 'ora';
import type { Arguments } from 'yargs-parser';
-import { getAstroStudioUrl } from '../../../utils.js';
-import open from 'open';
import { SESSION_LOGIN_FILE } from '../../../tokens.js';
+import { getAstroStudioUrl } from '../../../utils.js';
function serveAndResolveSession(): Promise<string> {
let resolve: (value: string | PromiseLike<string>) => void,
diff --git a/packages/db/src/core/cli/commands/logout/index.ts b/packages/db/src/core/cli/commands/logout/index.ts
index feae880cc..0881dcf4c 100644
--- a/packages/db/src/core/cli/commands/logout/index.ts
+++ b/packages/db/src/core/cli/commands/logout/index.ts
@@ -1,5 +1,5 @@
-import type { AstroConfig } from 'astro';
import { unlink } from 'node:fs/promises';
+import type { AstroConfig } from 'astro';
import type { Arguments } from 'yargs-parser';
import { SESSION_LOGIN_FILE } from '../../../tokens.js';
diff --git a/packages/db/src/core/cli/commands/push/index.ts b/packages/db/src/core/cli/commands/push/index.ts
index e0d6b9306..8c3f21e4d 100644
--- a/packages/db/src/core/cli/commands/push/index.ts
+++ b/packages/db/src/core/cli/commands/push/index.ts
@@ -1,27 +1,27 @@
-import { createClient, type InStatement } from '@libsql/client';
+import { type InStatement, createClient } from '@libsql/client';
import type { AstroConfig } from 'astro';
-import { drizzle as drizzleProxy } from 'drizzle-orm/sqlite-proxy';
import { drizzle as drizzleLibsql } from 'drizzle-orm/libsql';
import { SQLiteAsyncDialect } from 'drizzle-orm/sqlite-core';
+import { drizzle as drizzleProxy } from 'drizzle-orm/sqlite-proxy';
import { red } from 'kleur/colors';
import prompts from 'prompts';
import type { Arguments } from 'yargs-parser';
+import { MISSING_SESSION_ID_ERROR } from '../../../errors.js';
import { recreateTables, seedData } from '../../../queries.js';
import { getManagedAppTokenOrExit } from '../../../tokens.js';
-import { tablesSchema, type AstroConfigWithDB, type DBSnapshot } from '../../../types.js';
+import { type AstroConfigWithDB, type DBSnapshot, tablesSchema } from '../../../types.js';
import { getRemoteDatabaseUrl } from '../../../utils.js';
import { getMigrationQueries } from '../../migration-queries.js';
import {
+ MIGRATIONS_NOT_INITIALIZED,
+ MIGRATIONS_UP_TO_DATE,
+ MIGRATION_NEEDED,
createEmptySnapshot,
- getMigrations,
getMigrationStatus,
+ getMigrations,
loadInitialSnapshot,
loadMigration,
- MIGRATION_NEEDED,
- MIGRATIONS_NOT_INITIALIZED,
- MIGRATIONS_UP_TO_DATE,
} from '../../migrations.js';
-import { MISSING_SESSION_ID_ERROR } from '../../../errors.js';
export async function cmd({ config, flags }: { config: AstroConfig; flags: Arguments }) {
const isDryRun = flags.dryRun;
diff --git a/packages/db/src/core/cli/commands/verify/index.ts b/packages/db/src/core/cli/commands/verify/index.ts
index 96b4b6576..6d839d606 100644
--- a/packages/db/src/core/cli/commands/verify/index.ts
+++ b/packages/db/src/core/cli/commands/verify/index.ts
@@ -1,12 +1,12 @@
import type { AstroConfig } from 'astro';
import type { Arguments } from 'yargs-parser';
+import { getMigrationQueries } from '../../migration-queries.js';
import {
- getMigrationStatus,
- MIGRATION_NEEDED,
MIGRATIONS_NOT_INITIALIZED,
MIGRATIONS_UP_TO_DATE,
+ MIGRATION_NEEDED,
+ getMigrationStatus,
} from '../../migrations.js';
-import { getMigrationQueries } from '../../migration-queries.js';
export async function cmd({ config, flags }: { config: AstroConfig; flags: Arguments }) {
const status = await getMigrationStatus(config);
diff --git a/packages/db/src/core/cli/migration-queries.ts b/packages/db/src/core/cli/migration-queries.ts
index 7acd1dad3..e031108e4 100644
--- a/packages/db/src/core/cli/migration-queries.ts
+++ b/packages/db/src/core/cli/migration-queries.ts
@@ -1,23 +1,10 @@
-import * as color from 'kleur/colors';
import deepDiff from 'deep-diff';
-import {
- columnSchema,
- type BooleanColumn,
- type DBTable,
- type DBTables,
- type DBColumn,
- type DBColumns,
- type DBSnapshot,
- type DateColumn,
- type ColumnType,
- type Indexes,
- type JsonColumn,
- type NumberColumn,
- type TextColumn,
-} from '../types.js';
import { SQLiteAsyncDialect } from 'drizzle-orm/sqlite-core';
+import * as color from 'kleur/colors';
import { customAlphabet } from 'nanoid';
import prompts from 'prompts';
+import { hasPrimaryKey } from '../../runtime/index.js';
+import { isSerializedSQL } from '../../runtime/types.js';
import {
getCreateIndexQueries,
getCreateTableQuery,
@@ -26,8 +13,21 @@ import {
hasDefault,
schemaTypeToSqlType,
} from '../queries.js';
-import { hasPrimaryKey } from '../../runtime/index.js';
-import { isSerializedSQL } from '../../runtime/types.js';
+import {
+ type BooleanColumn,
+ type ColumnType,
+ type DBColumn,
+ type DBColumns,
+ type DBSnapshot,
+ type DBTable,
+ type DBTables,
+ type DateColumn,
+ type Indexes,
+ type JsonColumn,
+ type NumberColumn,
+ type TextColumn,
+ columnSchema,
+} from '../types.js';
const sqlite = new SQLiteAsyncDialect();
const genTempTableName = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10);
diff --git a/packages/db/src/core/cli/migrations.ts b/packages/db/src/core/cli/migrations.ts
index 8b57d4b63..671862b61 100644
--- a/packages/db/src/core/cli/migrations.ts
+++ b/packages/db/src/core/cli/migrations.ts
@@ -1,8 +1,8 @@
+import type { AstroConfig } from 'astro';
import deepDiff from 'deep-diff';
import { mkdir, readFile, readdir, writeFile } from 'fs/promises';
-import { tablesSchema, type DBSnapshot } from '../types.js';
-import type { AstroConfig } from 'astro';
import { cyan, green, yellow } from 'kleur/colors';
+import { type DBSnapshot, tablesSchema } from '../types.js';
const { applyChange, diff: generateDiff } = deepDiff;
export type MigrationStatus =
diff --git a/packages/db/src/core/errors.ts b/packages/db/src/core/errors.ts
index 2ac406b31..76a66d0dc 100644
--- a/packages/db/src/core/errors.ts
+++ b/packages/db/src/core/errors.ts
@@ -1,4 +1,4 @@
-import { cyan, bold, red, green, yellow } from 'kleur/colors';
+import { bold, cyan, green, red, yellow } from 'kleur/colors';
export const MISSING_SESSION_ID_ERROR = `${red('▶ Login required!')}
diff --git a/packages/db/src/core/integration/file-url.ts b/packages/db/src/core/integration/file-url.ts
index 7dc4b916e..06bc67de1 100644
--- a/packages/db/src/core/integration/file-url.ts
+++ b/packages/db/src/core/integration/file-url.ts
@@ -1,8 +1,8 @@
-import type { AstroConfig, AstroIntegration } from 'astro';
-import type { VitePlugin } from '../utils.js';
import fs from 'node:fs';
-import { pathToFileURL } from 'node:url';
import path from 'node:path';
+import { pathToFileURL } from 'node:url';
+import type { AstroConfig, AstroIntegration } from 'astro';
+import type { VitePlugin } from '../utils.js';
async function copyFile(toDir: URL, fromUrl: URL, toUrl: URL) {
await fs.promises.mkdir(toDir, { recursive: true });
diff --git a/packages/db/src/core/integration/index.ts b/packages/db/src/core/integration/index.ts
index 2ea1b74c7..d9cddfd72 100644
--- a/packages/db/src/core/integration/index.ts
+++ b/packages/db/src/core/integration/index.ts
@@ -1,21 +1,21 @@
-import type { AstroIntegration } from 'astro';
-import { vitePluginDb } from './vite-plugin-db.js';
-import { vitePluginInjectEnvTs } from './vite-plugin-inject-env-ts.js';
-import { typegen } from './typegen.js';
import { existsSync } from 'fs';
+import { dirname } from 'path';
+import { fileURLToPath } from 'url';
+import type { AstroIntegration } from 'astro';
import { mkdir, rm, writeFile } from 'fs/promises';
-import { DB_PATH } from '../consts.js';
+import { blue, yellow } from 'kleur/colors';
import { createLocalDatabaseClient } from '../../runtime/db-client.js';
-import { astroConfigWithDbSchema, type DBTables } from '../types.js';
-import { type VitePlugin } from '../utils.js';
+import { DB_PATH } from '../consts.js';
import { STUDIO_CONFIG_MISSING_WRITABLE_TABLE_ERROR, UNSAFE_WRITABLE_WARNING } from '../errors.js';
+import { recreateTables, seedData } from '../queries.js';
+import { type ManagedAppToken, getManagedAppTokenOrExit } from '../tokens.js';
+import { type DBTables, astroConfigWithDbSchema } from '../types.js';
+import { type VitePlugin } from '../utils.js';
import { errorMap } from './error-map.js';
-import { dirname } from 'path';
-import { fileURLToPath } from 'url';
-import { blue, yellow } from 'kleur/colors';
import { fileURLIntegration } from './file-url.js';
-import { recreateTables, seedData } from '../queries.js';
-import { getManagedAppTokenOrExit, type ManagedAppToken } from '../tokens.js';
+import { typegen } from './typegen.js';
+import { vitePluginDb } from './vite-plugin-db.js';
+import { vitePluginInjectEnvTs } from './vite-plugin-inject-env-ts.js';
function astroDBIntegration(): AstroIntegration {
let connectedToRemote = false;
diff --git a/packages/db/src/core/integration/typegen.ts b/packages/db/src/core/integration/typegen.ts
index ce53aa667..0436261e1 100644
--- a/packages/db/src/core/integration/typegen.ts
+++ b/packages/db/src/core/integration/typegen.ts
@@ -1,7 +1,7 @@
import { existsSync } from 'node:fs';
import { mkdir, writeFile } from 'node:fs/promises';
-import type { DBTable, DBTables } from '../types.js';
import { DB_TYPES_FILE, RUNTIME_DRIZZLE_IMPORT, RUNTIME_IMPORT } from '../consts.js';
+import type { DBTable, DBTables } from '../types.js';
export async function typegen({ tables, root }: { tables: DBTables; root: URL }) {
const content = `// This file is generated by \`studio sync\`
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 91fa1228f..1202e72d6 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
@@ -2,11 +2,11 @@ import { existsSync } from 'node:fs';
import { readFile, writeFile } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
+import type { AstroIntegrationLogger } from 'astro';
import { bold, cyan } from 'kleur/colors';
import { normalizePath } from 'vite';
import { DB_TYPES_FILE } from '../consts.js';
import type { VitePlugin } from '../utils.js';
-import type { AstroIntegrationLogger } from 'astro';
export function vitePluginInjectEnvTs(
{ srcDir, root }: { srcDir: URL; root: URL },
diff --git a/packages/db/src/core/queries.ts b/packages/db/src/core/queries.ts
index 9fd1003f6..f699a297a 100644
--- a/packages/db/src/core/queries.ts
+++ b/packages/db/src/core/queries.ts
@@ -1,19 +1,19 @@
+import type { AstroIntegrationLogger } from 'astro';
+import { type SQL, getTableName, sql } from 'drizzle-orm';
+import { SQLiteAsyncDialect, type SQLiteInsert } from 'drizzle-orm/sqlite-core';
import type { SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy';
+import { bold } from 'kleur/colors';
import {
type BooleanColumn,
+ type ColumnType,
+ type DBColumn,
type DBTable,
type DBTables,
- type DBColumn,
type DateColumn,
- type ColumnType,
type JsonColumn,
type NumberColumn,
type TextColumn,
} from '../core/types.js';
-import { bold } from 'kleur/colors';
-import { type SQL, sql, getTableName } from 'drizzle-orm';
-import { SQLiteAsyncDialect, type SQLiteInsert } from 'drizzle-orm/sqlite-core';
-import type { AstroIntegrationLogger } from 'astro';
import type {
ColumnsConfig,
DBUserConfig,
diff --git a/packages/db/src/core/tokens.ts b/packages/db/src/core/tokens.ts
index 6b1572309..d8be850a0 100644
--- a/packages/db/src/core/tokens.ts
+++ b/packages/db/src/core/tokens.ts
@@ -2,8 +2,8 @@ import { readFile } from 'node:fs/promises';
import { homedir } from 'node:os';
import { join } from 'node:path';
import { pathToFileURL } from 'node:url';
-import { getAstroStudioEnv, getAstroStudioUrl } from './utils.js';
import { MISSING_PROJECT_ID_ERROR, MISSING_SESSION_ID_ERROR } from './errors.js';
+import { getAstroStudioEnv, getAstroStudioUrl } from './utils.js';
export const SESSION_LOGIN_FILE = pathToFileURL(join(homedir(), '.astro', 'session-token'));
export const PROJECT_ID_FILE = pathToFileURL(join(process.cwd(), '.astro', 'link'));
diff --git a/packages/db/src/core/types.ts b/packages/db/src/core/types.ts
index ec2322ed5..a4896a8be 100644
--- a/packages/db/src/core/types.ts
+++ b/packages/db/src/core/types.ts
@@ -1,10 +1,10 @@
-import { SQLiteAsyncDialect, type SQLiteInsertValue } from 'drizzle-orm/sqlite-core';
import type { InferSelectModel } from 'drizzle-orm';
-import { collectionToTable, type SqliteDB, type Table } from '../runtime/index.js';
-import { z, type ZodTypeDef } from 'zod';
import { SQL } from 'drizzle-orm';
-import { errorMap } from './integration/error-map.js';
+import { SQLiteAsyncDialect, type SQLiteInsertValue } from 'drizzle-orm/sqlite-core';
+import { type ZodTypeDef, z } from 'zod';
+import { type SqliteDB, type Table, collectionToTable } from '../runtime/index.js';
import { SERIALIZED_SQL_KEY, type SerializedSQL } from '../runtime/types.js';
+import { errorMap } from './integration/error-map.js';
export type MaybePromise<T> = T | Promise<T>;
export type MaybeArray<T> = T | T[];
diff --git a/packages/db/src/runtime/db-client.ts b/packages/db/src/runtime/db-client.ts
index 28db1138f..905820676 100644
--- a/packages/db/src/runtime/db-client.ts
+++ b/packages/db/src/runtime/db-client.ts
@@ -1,12 +1,12 @@
import type { InStatement } from '@libsql/client';
import { createClient } from '@libsql/client';
-import { type DBTables } from '../core/types.js';
+import { getTableName } from 'drizzle-orm';
import type { LibSQLDatabase } from 'drizzle-orm/libsql';
import { drizzle as drizzleLibsql } from 'drizzle-orm/libsql';
-import { drizzle as drizzleProxy } from 'drizzle-orm/sqlite-proxy';
import { type SQLiteTable } from 'drizzle-orm/sqlite-core';
+import { drizzle as drizzleProxy } from 'drizzle-orm/sqlite-proxy';
import { z } from 'zod';
-import { getTableName } from 'drizzle-orm';
+import { type DBTables } from '../core/types.js';
const isWebContainer = !!process.versions?.webcontainer;
diff --git a/packages/db/src/runtime/index.ts b/packages/db/src/runtime/index.ts
index 99d2cf31e..7ab5264cd 100644
--- a/packages/db/src/runtime/index.ts
+++ b/packages/db/src/runtime/index.ts
@@ -1,16 +1,16 @@
-import type { SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy';
-import { type DBTable, type DBColumn } from '../core/types.js';
import { type ColumnBuilderBaseConfig, type ColumnDataType, sql } from 'drizzle-orm';
import {
+ type IndexBuilder,
+ type SQLiteColumnBuilderBase,
customType,
+ index,
integer,
sqliteTable,
text,
- index,
- type SQLiteColumnBuilderBase,
- type IndexBuilder,
} from 'drizzle-orm/sqlite-core';
-import { isSerializedSQL, type SerializedSQL } from './types.js';
+import type { SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy';
+import { type DBColumn, type DBTable } from '../core/types.js';
+import { type SerializedSQL, isSerializedSQL } from './types.js';
export { sql };
export type SqliteDB = SqliteRemoteDatabase;
diff --git a/packages/db/src/runtime/types.ts b/packages/db/src/runtime/types.ts
index 32ee6153b..9bc35bda6 100644
--- a/packages/db/src/runtime/types.ts
+++ b/packages/db/src/runtime/types.ts
@@ -1,6 +1,6 @@
-import type { ColumnDataType, ColumnBaseConfig } from 'drizzle-orm';
+import type { ColumnBaseConfig, ColumnDataType } from 'drizzle-orm';
import type { SQLiteColumn, SQLiteTableWithColumns } from 'drizzle-orm/sqlite-core';
-import type { DBColumn, ColumnsConfig } from '../core/types.js';
+import type { ColumnsConfig, DBColumn } from '../core/types.js';
type GeneratedConfig<T extends ColumnDataType = ColumnDataType> = Pick<
ColumnBaseConfig<T, string>,