Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion examples/erp/db/schema/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { relations } from 'drizzle-orm'
import { boolean, pgTable, text, timestamp, uuid, varchar } from 'drizzle-orm/pg-core'
import {
boolean,
date,
decimal,
pgEnum,
pgTable,
text,
time,
timestamp,
uuid,
varchar,
} from 'drizzle-orm/pg-core'

const timestamps = {
updatedAt: timestamp().defaultNow(),
Expand Down Expand Up @@ -94,3 +105,15 @@ export const categoryTags = pgTable('categoryTags', {
export const categoryTagsRelations = relations(categoryTags, ({ one }) => ({
category: one(categories, { fields: [categoryTags.category], references: [categories.id] }),
}))

export const typesEnum = pgEnum('types', ['fruit', 'vegetable', 'meat', 'dairy', 'grain', 'other'])
export const foods = pgTable('foods', {
id: uuid('id').primaryKey().defaultRandom(),
name: varchar().notNull(),
isCooked: boolean('is_cooked').notNull(),
cookingTypes: typesEnum().notNull().default('other'),
cookingDuration: decimal({ mode: 'number' }).notNull(),
// TODO: Make type infer for {mode:"string" | "date"}
cookingDate: date().notNull().defaultNow(), // YYYY-MM-DD
cookingTime: time().notNull().defaultNow(), // 00:00:00 - 24:00:00
})
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CREATE TYPE "public"."types" AS ENUM('fruit', 'vegetable', 'meat', 'dairy', 'grain', 'other');--> statement-breakpoint
CREATE TABLE "account" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"account_id" text NOT NULL,
Expand Down Expand Up @@ -33,6 +34,16 @@ CREATE TABLE "categoryTags" (
"deletedAt" timestamp
);
--> statement-breakpoint
CREATE TABLE "foods" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"name" varchar NOT NULL,
"is_cooked" boolean NOT NULL,
"cookingTypes" "types" DEFAULT 'other' NOT NULL,
"cookingDuration" numeric NOT NULL,
"cookingDate" date DEFAULT now() NOT NULL,
"cookingTime" time DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "posts" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"title" varchar,
Expand Down
77 changes: 75 additions & 2 deletions examples/erp/drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "bf9131bb-df6e-47d0-ad81-e80d0b387a87",
"id": "0d8c965b-6573-4b45-913d-05b3fcc77e06",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
Expand Down Expand Up @@ -250,6 +250,66 @@
"checkConstraints": {},
"isRLSEnabled": false
},
"public.foods": {
"name": "foods",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"name": {
"name": "name",
"type": "varchar",
"primaryKey": false,
"notNull": true
},
"is_cooked": {
"name": "is_cooked",
"type": "boolean",
"primaryKey": false,
"notNull": true
},
"cookingTypes": {
"name": "cookingTypes",
"type": "types",
"typeSchema": "public",
"primaryKey": false,
"notNull": true,
"default": "'other'"
},
"cookingDuration": {
"name": "cookingDuration",
"type": "numeric",
"primaryKey": false,
"notNull": true
},
"cookingDate": {
"name": "cookingDate",
"type": "date",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"cookingTime": {
"name": "cookingTime",
"type": "time",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.posts": {
"name": "posts",
"schema": "",
Expand Down Expand Up @@ -565,7 +625,20 @@
"isRLSEnabled": false
}
},
"enums": {},
"enums": {
"public.types": {
"name": "types",
"schema": "public",
"values": [
"fruit",
"vegetable",
"meat",
"dairy",
"grain",
"other"
]
}
},
"schemas": {},
"sequences": {},
"roles": {},
Expand Down
4 changes: 2 additions & 2 deletions examples/erp/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"idx": 0,
"version": "7",
"when": 1747986947161,
"tag": "0000_freezing_the_order",
"when": 1748256471330,
"tag": "0000_damp_talon",
"breakpoints": true
}
]
Expand Down
51 changes: 51 additions & 0 deletions examples/erp/drizzlify/collections/foods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { builder } from '../helper'

export const foodsCollection = builder.collection('foods', {
slug: 'foods',
primaryField: 'id',
fields: builder.fields('foods', (fb) => ({
id: fb.columns('id', {
type: 'text',
label: 'Food ID',
placeholder: 'ID',
default: '123',
}),
name: fb.columns('name', {
type: 'text',
label: 'Food name',
create: 'enabled',
update: 'disabled',
}),
isCooked: fb.columns('isCooked', {
type: 'checkbox',
label: 'Food cooked',
default: true,
description: 'Is the food cooked?',
}),
cookingTypes: fb.columns('cookingTypes', {
type: 'selectText',
label: 'Cooking types',
options: (args) => {
const res = args.db._.schema?.foods.columns.cookingTypes.enumValues || []

return res.map((v) => ({ label: v, value: v }))
},
}),
cookingDuration: fb.columns('cookingDuration', {
type: 'number',
label: 'Cooking duration',
placeholder: 'Duration (Seconds)',
default: 10,
}),
cookingDate: fb.columns('cookingDate', {
type: 'date',
label: 'Cooking date',
default: new Date('2025-04-24'),
}),
cookingTime: fb.columns('cookingTime', {
type: 'time',
label: 'Cooking time',
default: new Date(),
}),
})),
})
2 changes: 1 addition & 1 deletion examples/erp/src/app/(admin)/playground/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ interface PlaygroundPageProps {
searchParams: Promise<{ [key: string]: string | string[] }>
}

export default async function Playground(props: PlaygroundPageProps) {
export default async function Playground(_props: PlaygroundPageProps) {
return <UIPlayground />
}
9 changes: 8 additions & 1 deletion packages/core/src/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
export type OptionCallback<
TType extends string | number,
TContext extends Record<string, unknown> = {},
> = (args: TContext) => Promise<Array<{ label: string; value: TType }>>
TReturn extends Array<{ label: string; value: TType }> = Array<{ label: string; value: TType }>,
> = (args: TContext) => Promise<TReturn> | TReturn

export type FieldsWithFieldName<TFields extends Record<string, FieldBase>> = {
[TKey in keyof TFields]: TFields[TKey] & { fieldName: string }
Expand Down Expand Up @@ -56,8 +57,10 @@ export type FieldMutateMode =
export type FieldBase = {
label?: string
placeholder?: string
isRequired?: boolean
update?: FieldMutateMode
create?: FieldMutateMode
description?: string
}

export interface FieldColumnStringCollectionOptions<
Expand All @@ -79,6 +82,10 @@ export interface FieldColumnStringCollectionOptions<
type: 'time'
default?: Date
} & FieldBase
date: {
type: 'date'
default?: Date
} & FieldBase
media: {
type: 'media'
mimeTypes: string[]
Expand Down
3 changes: 3 additions & 0 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
"dependencies": {
"@hookform/resolvers": "^5.0.1",
"@intentui/icons": "^1.10.31",
"@internationalized/date": "^3.8.1",
"@kivotos/core": "workspace:^",
"@phosphor-icons/react": "^2.1.8",
"@radix-ui/react-slot": "^1.2.0",
"@react-aria/i18n": "^3.12.9",
"@react-stately/calendar": "^3.8.1",
"@tanstack/react-query": "^5.71.5",
"@tanstack/react-table": "^8.21.2",
"@tanstack/react-virtual": "^3.13.6",
Expand Down
Loading