From f76342fb4d83353e28a773e2ef235d1ae021064c Mon Sep 17 00:00:00 2001 From: Adam Matthiesen Date: Tue, 10 Dec 2024 22:12:59 -0800 Subject: [PATCH] progress --- packages/studiocms_core/package.json | 3 +- .../src/schemas/plugins/index.ts | 34 +++++++++++++++---- pnpm-lock.yaml | 3 ++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/packages/studiocms_core/package.json b/packages/studiocms_core/package.json index b64e3cd8d..2a00279cb 100644 --- a/packages/studiocms_core/package.json +++ b/packages/studiocms_core/package.json @@ -63,7 +63,8 @@ "remark-rehype": "catalog:studiocms-core", "mdast-util-to-hast": "catalog:studiocms-core", "@matthiesenxyz/astrodtsbuilder": "catalog:studiocms-shared", - "@matthiesenxyz/integration-utils": "catalog:studiocms-shared" + "@matthiesenxyz/integration-utils": "catalog:studiocms-shared", + "drizzle-orm": "^0.31.2" }, "peerDependencies": { "@astrojs/db": "catalog:min", diff --git a/packages/studiocms_core/src/schemas/plugins/index.ts b/packages/studiocms_core/src/schemas/plugins/index.ts index 7837952b3..e0c7d87ce 100644 --- a/packages/studiocms_core/src/schemas/plugins/index.ts +++ b/packages/studiocms_core/src/schemas/plugins/index.ts @@ -1,5 +1,6 @@ -import type { asDrizzleTable } from '@astrojs/db/runtime'; import { z } from 'astro/zod'; +import type { ColumnDataType } from 'drizzle-orm'; +import type { SQLiteColumn, SQLiteTableWithColumns } from 'drizzle-orm/sqlite-core'; import { SettingsFieldSchema, TransformFunction, ValidationFunction } from './shared'; export interface AstroIntegration { @@ -11,7 +12,30 @@ export interface AstroIntegration { } & Partial>; } -const DrizzleTableSchema = z.custom(); +type AsDrizzleTable = SQLiteTableWithColumns<{ + name: string; + schema: undefined; + columns: { + [x: string]: SQLiteColumn< + { + name: string; + tableName: string; + dataType: ColumnDataType; + columnType: string; + data: unknown; + driverParam: unknown; + notNull: false; + hasDefault: false; + enumValues: string[] | undefined; + baseColumn: never; + }, + object + >; + }; + dialect: 'sqlite'; +}>; + +const DrizzleTableSchema = z.custom<{ name: string; table: AsDrizzleTable }>(); const AstroIntegrationSchema = z.union([ z.custom(), @@ -99,11 +123,10 @@ export const StudioCMSPluginSchema = z.object({ * * @example * ```ts - * import { asDrizzleTable } from '@astrojs/db/utils'; * import { myTable } from '../dbTables'; * * { - * table: asDrizzleTable('myTable', myTable), + * table: { name: 'myTable', table: myTable }, * } */ table: DrizzleTableSchema, @@ -123,11 +146,10 @@ export const StudioCMSPluginSchema = z.object({ * * @example * ```ts - * import { asDrizzleTable } from '@astrojs/db/utils'; * import { myTable } from '../dbTables'; * * { - * table: asDrizzleTable('myTable', myTable), + * table: { name: 'myTable', table: myTable }, * } */ table: DrizzleTableSchema, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a0fc579f4..b114ac768 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -614,6 +614,9 @@ importers: astro-integration-kit: specifier: 'catalog:' version: 0.16.1(astro@4.16.14(@types/node@22.0.0)(rollup@4.21.0)(typescript@5.6.3)) + drizzle-orm: + specifier: ^0.31.2 + version: 0.31.4(@cloudflare/workers-types@4.20240725.0)(@libsql/client@0.14.0)(@opentelemetry/api@1.9.0)(@types/pg@8.6.1)(@types/react@18.3.5)(react@18.3.1) mdast-util-to-hast: specifier: catalog:studiocms-core version: 13.2.0