Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Adammatthiesen committed Dec 11, 2024
1 parent 2efecee commit f76342f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/studiocms_core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 28 additions & 6 deletions packages/studiocms_core/src/schemas/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -11,7 +12,30 @@ export interface AstroIntegration {
} & Partial<Record<string, unknown>>;
}

const DrizzleTableSchema = z.custom<typeof asDrizzleTable>();
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<AstroIntegration>(),
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f76342f

Please sign in to comment.