nuxt-auto-crud 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -23,21 +23,20 @@
|
|
|
23
23
|
#### SQLite
|
|
24
24
|
```bash
|
|
25
25
|
npx nuxi init -t gh:clifordpereira/nac-starter my-app
|
|
26
|
+
cd my-app
|
|
26
27
|
```
|
|
27
28
|
|
|
28
29
|
#### MySQL
|
|
29
|
-
|
|
30
|
-
npx nuxi init -t gh:clifordpereira/nac-starter-mysql my-app
|
|
31
|
-
```
|
|
30
|
+
Visit [nac-starter-mysql](https://github.com/clifordpereira/nac-starter-mysql) for instructions.
|
|
32
31
|
|
|
33
32
|
### Option B: Manual Installation
|
|
34
33
|
|
|
35
34
|
```bash
|
|
36
35
|
bun create nuxt@latest my-app
|
|
36
|
+
cd my-app
|
|
37
37
|
npx nuxi module add hub
|
|
38
38
|
bun add drizzle-orm@beta @libsql/client nuxt-auto-crud
|
|
39
|
-
bun add -D drizzle-kit@beta
|
|
40
|
-
|
|
39
|
+
bun add -D drizzle-kit@beta typescript
|
|
41
40
|
```
|
|
42
41
|
> Mysql users may replace `@libsql/client` with `mysql2`
|
|
43
42
|
|
|
@@ -70,7 +69,6 @@ export const users = sqliteTable('users', {
|
|
|
70
69
|
id: integer().primaryKey({ autoIncrement: true }),
|
|
71
70
|
name: text().notNull(),
|
|
72
71
|
email: text().notNull().unique(),
|
|
73
|
-
password: text().notNull(),
|
|
74
72
|
avatar: text().notNull(),
|
|
75
73
|
createdAt: integer({ mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
|
|
76
74
|
})
|
|
@@ -82,30 +80,51 @@ export const users = sqliteTable('users', {
|
|
|
82
80
|
Define your schema in `server/db/schema.ts`:
|
|
83
81
|
|
|
84
82
|
```typescript
|
|
85
|
-
import { mysqlTable,
|
|
83
|
+
import { mysqlTable, serial, timestamp, varchar } from 'drizzle-orm/mysql-core'
|
|
86
84
|
|
|
87
85
|
export const users = mysqlTable('users', {
|
|
88
86
|
id: serial().primaryKey(),
|
|
89
|
-
name:
|
|
90
|
-
email:
|
|
91
|
-
|
|
92
|
-
avatar: text().notNull(),
|
|
87
|
+
name: varchar('name', { length: 255 }).notNull(),
|
|
88
|
+
email: varchar('email', { length: 255 }).notNull().unique(),
|
|
89
|
+
avatar: varchar('avatar', { length: 512 }).notNull(),
|
|
93
90
|
createdAt: timestamp().notNull().defaultNow(),
|
|
94
91
|
})
|
|
95
92
|
|
|
96
93
|
```
|
|
97
94
|
|
|
95
|
+
#### Using Docker for MySQL
|
|
96
|
+
|
|
97
|
+
> Note: Ensure hub.db is set to 'mysql' in nuxt.config.ts.
|
|
98
|
+
|
|
99
|
+
If Docker is installed, place the [docker-compose.yml](https://github.com/clifordpereira/nac-starter-mysql/blob/main/docker-compose.yml) in your project root.
|
|
100
|
+
|
|
101
|
+
Execute the following to manage the MySQL service:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# Start service
|
|
105
|
+
docker compose up -d
|
|
106
|
+
|
|
107
|
+
# Stop service
|
|
108
|
+
# docker compose down
|
|
109
|
+
|
|
110
|
+
# Purge data
|
|
111
|
+
# docker compose down -v
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Create a .env file with the following content:
|
|
115
|
+
|
|
116
|
+
```env
|
|
117
|
+
DATABASE_URL="mysql://root:root@127.0.0.1:3306/nac_db"
|
|
118
|
+
```
|
|
119
|
+
|
|
98
120
|
### Generate Migrations and Start Dev Server
|
|
99
121
|
After installing (either option), run the following commands:
|
|
100
122
|
|
|
101
123
|
```bash
|
|
102
|
-
cd my-app
|
|
103
124
|
nuxt db generate
|
|
104
125
|
nuxt dev
|
|
105
126
|
|
|
106
127
|
```
|
|
107
|
-
> If you encounter `Error: Cannot find module 'typescript'`, install it using `bun add -D typescript`.
|
|
108
|
-
|
|
109
128
|
---
|
|
110
129
|
|
|
111
130
|
## 🌐 Data APIs (Dynamic RESTful CRUD)
|
package/dist/module.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getColumns, Table, is, getTableName } from "drizzle-orm";
|
|
2
|
-
import { createInsertSchema } from "drizzle-zod";
|
|
2
|
+
import { createInsertSchema } from "drizzle-orm/zod";
|
|
3
3
|
import { useRuntimeConfig } from "#imports";
|
|
4
4
|
import * as schema from "#nac/schema";
|
|
5
5
|
import { NAC_SYSTEM_TABLES } from "./constants.js";
|
|
@@ -1,42 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { type Table } from 'drizzle-orm';
|
|
3
3
|
export declare function resolveValidatedSchema(table: Table, intent?: 'insert' | 'patch'): z.ZodObject<{
|
|
4
|
-
[x: number]: z.ZodArray<z.
|
|
5
|
-
[x: string]: z.ZodString | z.ZodNumber | z.ZodBoolean | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
6
|
-
}, {
|
|
7
|
-
out: {};
|
|
8
|
-
in: {};
|
|
9
|
-
}> | z.ZodBoolean | z.ZodType<import("drizzle-zod").Json, unknown, z.core.$ZodTypeInternals<import("drizzle-zod").Json, unknown>> | z.ZodInt | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>> | z.ZodOptional<z.ZodArray<z.ZodDate | z.ZodString | z.ZodNumber | z.ZodUUID | z.ZodTuple<[z.ZodNumber, z.ZodNumber], null> | z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null> | z.ZodType<Buffer<ArrayBufferLike>, unknown, z.core.$ZodTypeInternals<Buffer<ArrayBufferLike>, unknown>> | z.ZodArray<z.ZodString | z.ZodNumber | z.ZodBoolean | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>> | z.ZodType<any, any, z.core.$ZodTypeInternals<any, any>> | z.ZodObject<{
|
|
10
|
-
[x: string]: z.ZodString | z.ZodNumber | z.ZodBoolean | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
11
|
-
}, {
|
|
12
|
-
out: {};
|
|
13
|
-
in: {};
|
|
14
|
-
}> | z.ZodBoolean | z.ZodType<import("drizzle-zod").Json, unknown, z.core.$ZodTypeInternals<import("drizzle-zod").Json, unknown>> | z.ZodInt | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>> | z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodDate | z.ZodString | z.ZodNumber | z.ZodUUID | z.ZodTuple<[z.ZodNumber, z.ZodNumber], null> | z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null> | z.ZodType<Buffer<ArrayBufferLike>, unknown, z.core.$ZodTypeInternals<Buffer<ArrayBufferLike>, unknown>> | z.ZodArray<z.ZodString | z.ZodNumber | z.ZodBoolean | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>> | z.ZodType<any, any, z.core.$ZodTypeInternals<any, any>> | z.ZodObject<{
|
|
15
|
-
[x: string]: z.ZodString | z.ZodNumber | z.ZodBoolean | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
16
|
-
}, {
|
|
17
|
-
out: {};
|
|
18
|
-
in: {};
|
|
19
|
-
}> | z.ZodBoolean | z.ZodType<import("drizzle-zod").Json, unknown, z.core.$ZodTypeInternals<import("drizzle-zod").Json, unknown>> | z.ZodInt | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>>;
|
|
20
|
-
}, {
|
|
21
|
-
out: {};
|
|
22
|
-
in: {};
|
|
23
|
-
}> | z.ZodObject<{
|
|
24
|
-
[x: number]: z.ZodOptional<z.ZodArray<z.ZodDate | z.ZodString | z.ZodNumber | z.ZodUUID | z.ZodTuple<[z.ZodNumber, z.ZodNumber], null> | z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null> | z.ZodType<Buffer<ArrayBufferLike>, unknown, z.core.$ZodTypeInternals<Buffer<ArrayBufferLike>, unknown>> | z.ZodArray<z.ZodString | z.ZodNumber | z.ZodBoolean | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>> | z.ZodType<any, any, z.core.$ZodTypeInternals<any, any>> | z.ZodObject<{
|
|
25
|
-
[x: string]: z.ZodString | z.ZodNumber | z.ZodBoolean | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
26
|
-
}, {
|
|
27
|
-
out: {};
|
|
28
|
-
in: {};
|
|
29
|
-
}> | z.ZodBoolean | z.ZodType<import("drizzle-zod").Json, unknown, z.core.$ZodTypeInternals<import("drizzle-zod").Json, unknown>> | z.ZodInt | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>> | z.ZodOptional<z.ZodArray<z.ZodDate | z.ZodString | z.ZodNumber | z.ZodUUID | z.ZodTuple<[z.ZodNumber, z.ZodNumber], null> | z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null> | z.ZodType<Buffer<ArrayBufferLike>, unknown, z.core.$ZodTypeInternals<Buffer<ArrayBufferLike>, unknown>> | z.ZodArray<z.ZodString | z.ZodNumber | z.ZodBoolean | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>> | z.ZodType<any, any, z.core.$ZodTypeInternals<any, any>> | z.ZodObject<{
|
|
30
|
-
[x: string]: z.ZodString | z.ZodNumber | z.ZodBoolean | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
31
|
-
}, {
|
|
32
|
-
out: {};
|
|
33
|
-
in: {};
|
|
34
|
-
}> | z.ZodBoolean | z.ZodType<import("drizzle-zod").Json, unknown, z.core.$ZodTypeInternals<import("drizzle-zod").Json, unknown>> | z.ZodInt | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>> | z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodDate | z.ZodString | z.ZodNumber | z.ZodUUID | z.ZodTuple<[z.ZodNumber, z.ZodNumber], null> | z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null> | z.ZodType<Buffer<ArrayBufferLike>, unknown, z.core.$ZodTypeInternals<Buffer<ArrayBufferLike>, unknown>> | z.ZodArray<z.ZodString | z.ZodNumber | z.ZodBoolean | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>> | z.ZodType<any, any, z.core.$ZodTypeInternals<any, any>> | z.ZodObject<{
|
|
35
|
-
[x: string]: z.ZodString | z.ZodNumber | z.ZodBoolean | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
36
|
-
}, {
|
|
37
|
-
out: {};
|
|
38
|
-
in: {};
|
|
39
|
-
}> | z.ZodBoolean | z.ZodType<import("drizzle-zod").Json, unknown, z.core.$ZodTypeInternals<import("drizzle-zod").Json, unknown>> | z.ZodInt | z.ZodBigInt | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>>>;
|
|
4
|
+
[x: number]: z.ZodNumber | z.ZodBigInt | z.ZodArray<z.ZodAny> | z.ZodBoolean | z.ZodObject<{}, z.core.$loose> | z.ZodString | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> | z.ZodCoercedNumber<unknown> | z.ZodCoercedBigInt<unknown> | z.ZodCoercedBoolean<unknown> | z.ZodCoercedString<unknown> | z.ZodOptional<z.ZodNumber | z.ZodBigInt | z.ZodArray<z.ZodAny> | z.ZodBoolean | z.ZodObject<{}, z.core.$loose> | z.ZodString | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> | z.ZodCoercedNumber<unknown> | z.ZodCoercedBigInt<unknown> | z.ZodCoercedBoolean<unknown> | z.ZodCoercedString<unknown>> | z.ZodOptional<z.ZodNullable<z.ZodNumber | z.ZodBigInt | z.ZodArray<z.ZodAny> | z.ZodBoolean | z.ZodObject<{}, z.core.$loose> | z.ZodString | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> | z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> | z.ZodCoercedNumber<unknown> | z.ZodCoercedBigInt<unknown> | z.ZodCoercedBoolean<unknown> | z.ZodCoercedString<unknown>>>;
|
|
40
5
|
}, {
|
|
41
6
|
out: {};
|
|
42
7
|
in: {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { createSchemaFactory } from "drizzle-zod";
|
|
2
|
+
import { createSchemaFactory } from "drizzle-orm/zod";
|
|
3
3
|
import { getColumns } from "drizzle-orm";
|
|
4
4
|
import { useRuntimeConfig } from "#imports";
|
|
5
5
|
const { createInsertSchema } = createSchemaFactory();
|
|
@@ -8,13 +8,12 @@ export function resolveValidatedSchema(table, intent = "insert") {
|
|
|
8
8
|
const timestampOverrides = Object.fromEntries(
|
|
9
9
|
Object.entries(columns).filter(([_, col]) => col.mode === "timestamp").map(([name]) => [
|
|
10
10
|
name,
|
|
11
|
-
// 1. Add .optional() so Zod doesn't fail when the field is missing from the request
|
|
12
11
|
z.union([z.date(), z.string(), z.number()]).pipe(z.coerce.date()).optional()
|
|
13
12
|
])
|
|
14
13
|
);
|
|
15
14
|
const baseSchema = createInsertSchema(table, timestampOverrides);
|
|
16
15
|
const { formHiddenFields } = useRuntimeConfig().public.autoCrud;
|
|
17
|
-
const fieldsToOmit = formHiddenFields.filter((f) =>
|
|
16
|
+
const fieldsToOmit = formHiddenFields.filter((f) => f in columns);
|
|
18
17
|
const sanitizedSchema = baseSchema.omit(
|
|
19
18
|
Object.fromEntries(fieldsToOmit.map((f) => [f, true]))
|
|
20
19
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-auto-crud",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Dynamic RESTful CRUD APIs for Nuxt without code generation, fully schema-driven.",
|
|
5
5
|
"author": "Cliford Pereira",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,7 +48,6 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@nuxt/kit": "^4.3.1",
|
|
51
|
-
"drizzle-zod": "^0.8.3",
|
|
52
51
|
"mysql2": "^3.18.2",
|
|
53
52
|
"pluralize": "^8.0.0",
|
|
54
53
|
"zod": "^4.3.6"
|
|
@@ -73,12 +72,12 @@
|
|
|
73
72
|
"@nuxthub/core": "^0.10.6",
|
|
74
73
|
"@types/better-sqlite3": "^7.6.13",
|
|
75
74
|
"@types/node": "latest",
|
|
76
|
-
"@vue/test-utils": "^2.4.6",
|
|
77
75
|
"@types/pluralize": "^0.0.33",
|
|
76
|
+
"@vue/test-utils": "^2.4.6",
|
|
78
77
|
"better-sqlite3": "^12.6.2",
|
|
79
78
|
"changelogen": "^0.6.2",
|
|
80
|
-
"drizzle-kit": "^1.0.0-beta.
|
|
81
|
-
"drizzle-orm": "^1.0.0-beta.
|
|
79
|
+
"drizzle-kit": "^1.0.0-beta.16-ea816b6",
|
|
80
|
+
"drizzle-orm": "^1.0.0-beta.16-ea816b6",
|
|
82
81
|
"eslint": "^10.0.0",
|
|
83
82
|
"happy-dom": "^20.6.2",
|
|
84
83
|
"nuxt": "^4.3.1",
|