nuxt-auto-crud 1.1.1 → 1.2.1
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/dist/module.d.mts +6 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +7 -1
- package/dist/runtime/server/api/[model]/[id].delete.d.ts +1 -1
- package/dist/runtime/server/api/[model]/[id].delete.js +4 -0
- package/dist/runtime/server/api/[model]/[id].get.d.ts +1 -1
- package/dist/runtime/server/api/[model]/[id].get.js +4 -0
- package/dist/runtime/server/api/[model]/[id].patch.d.ts +1 -1
- package/dist/runtime/server/api/[model]/[id].patch.js +4 -0
- package/dist/runtime/server/api/[model]/index.get.d.ts +1 -1
- package/dist/runtime/server/api/[model]/index.get.js +3 -0
- package/dist/runtime/server/api/[model]/index.post.d.ts +1 -1
- package/dist/runtime/server/api/[model]/index.post.js +3 -0
- package/dist/runtime/server/types.d.ts +5 -0
- package/dist/runtime/server/types.js +0 -0
- package/dist/runtime/server/utils/modelMapper.d.ts +3 -1
- package/package.json +1 -1
- package/src/runtime/server/api/[model]/[id].delete.ts +9 -1
- package/src/runtime/server/api/[model]/[id].get.ts +9 -1
- package/src/runtime/server/api/[model]/[id].patch.ts +9 -1
- package/src/runtime/server/api/[model]/index.get.ts +6 -0
- package/src/runtime/server/api/[model]/index.post.ts +6 -0
- package/src/runtime/server/types.ts +5 -0
- package/src/runtime/server/utils/modelMapper.ts +4 -2
package/dist/module.d.mts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
|
|
3
3
|
interface ModuleOptions {
|
|
4
|
+
/**
|
|
4
5
|
/**
|
|
5
6
|
* Path to the database schema file
|
|
6
7
|
* @default 'server/database/schema'
|
|
7
8
|
*/
|
|
8
9
|
schemaPath?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Path to the drizzle instance file (must export useDrizzle)
|
|
12
|
+
* @default 'server/utils/drizzle'
|
|
13
|
+
*/
|
|
14
|
+
drizzlePath?: string;
|
|
9
15
|
}
|
|
10
16
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
11
17
|
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -6,7 +6,8 @@ const module$1 = defineNuxtModule({
|
|
|
6
6
|
configKey: "autoCrud"
|
|
7
7
|
},
|
|
8
8
|
defaults: {
|
|
9
|
-
schemaPath: "server/database/schema"
|
|
9
|
+
schemaPath: "server/database/schema",
|
|
10
|
+
drizzlePath: "server/utils/drizzle"
|
|
10
11
|
},
|
|
11
12
|
setup(options, nuxt) {
|
|
12
13
|
const resolver = createResolver(import.meta.url);
|
|
@@ -15,6 +16,11 @@ const module$1 = defineNuxtModule({
|
|
|
15
16
|
options.schemaPath
|
|
16
17
|
);
|
|
17
18
|
nuxt.options.alias["#site/schema"] = schemaPath;
|
|
19
|
+
const drizzlePath = resolver.resolve(
|
|
20
|
+
nuxt.options.rootDir,
|
|
21
|
+
options.drizzlePath
|
|
22
|
+
);
|
|
23
|
+
nuxt.options.alias["#site/drizzle"] = drizzlePath;
|
|
18
24
|
const apiDir = resolver.resolve("./runtime/server/api");
|
|
19
25
|
addServerHandler({
|
|
20
26
|
route: "/api/:model",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: any
|
|
1
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { eventHandler, getRouterParams, createError } from "h3";
|
|
2
|
+
import { eq } from "drizzle-orm";
|
|
3
|
+
import { getTableForModel, getModelSingularName } from "../../utils/modelMapper.js";
|
|
4
|
+
import { useDrizzle } from "#site/drizzle";
|
|
1
5
|
export default eventHandler(async (event) => {
|
|
2
6
|
const { model, id } = getRouterParams(event);
|
|
3
7
|
const table = getTableForModel(model);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: any
|
|
1
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { eventHandler, getRouterParams, createError } from "h3";
|
|
2
|
+
import { eq } from "drizzle-orm";
|
|
3
|
+
import { getTableForModel, getModelSingularName } from "../../utils/modelMapper.js";
|
|
4
|
+
import { useDrizzle } from "#site/drizzle";
|
|
1
5
|
export default eventHandler(async (event) => {
|
|
2
6
|
const { model, id } = getRouterParams(event);
|
|
3
7
|
const table = getTableForModel(model);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: any
|
|
1
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { eventHandler, getRouterParams, readBody } from "h3";
|
|
2
|
+
import { eq } from "drizzle-orm";
|
|
3
|
+
import { getTableForModel, filterUpdatableFields } from "../../utils/modelMapper.js";
|
|
4
|
+
import { useDrizzle } from "#site/drizzle";
|
|
1
5
|
export default eventHandler(async (event) => {
|
|
2
6
|
const { model, id } = getRouterParams(event);
|
|
3
7
|
const table = getTableForModel(model);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: any
|
|
1
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { eventHandler, getRouterParams } from "h3";
|
|
2
|
+
import { getTableForModel } from "../../utils/modelMapper.js";
|
|
3
|
+
import { useDrizzle } from "#site/drizzle";
|
|
1
4
|
export default eventHandler(async (event) => {
|
|
2
5
|
const { model } = getRouterParams(event);
|
|
3
6
|
const table = getTableForModel(model);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: any
|
|
1
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { eventHandler, getRouterParams, readBody } from "h3";
|
|
2
|
+
import { getTableForModel } from "../../utils/modelMapper.js";
|
|
3
|
+
import { useDrizzle } from "#site/drizzle";
|
|
1
4
|
export default eventHandler(async (event) => {
|
|
2
5
|
const { model } = getRouterParams(event);
|
|
3
6
|
const table = getTableForModel(model);
|
|
File without changes
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SQLiteTable } from 'drizzle-orm/sqlite-core';
|
|
1
2
|
/**
|
|
2
3
|
* Custom updatable fields configuration (optional)
|
|
3
4
|
* Only define here if you want to override the auto-detection
|
|
@@ -19,7 +20,7 @@ export declare const modelTableMap: Record<string, unknown>;
|
|
|
19
20
|
* @returns The corresponding database table
|
|
20
21
|
* @throws Error if model is not found
|
|
21
22
|
*/
|
|
22
|
-
export declare function getTableForModel(modelName: string):
|
|
23
|
+
export declare function getTableForModel(modelName: string): SQLiteTable;
|
|
23
24
|
/**
|
|
24
25
|
* Gets the updatable fields for a model
|
|
25
26
|
* @param modelName - The name of the model
|
|
@@ -44,6 +45,7 @@ export declare function getModelSingularName(modelName: string): string;
|
|
|
44
45
|
* Gets the plural name for a model
|
|
45
46
|
* @param modelName - The model name (singular or plural)
|
|
46
47
|
* @returns The plural name
|
|
48
|
+
* @return The plural name
|
|
47
49
|
*/
|
|
48
50
|
export declare function getModelPluralName(modelName: string): string;
|
|
49
51
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
// server/api/[model]/[id].delete.ts
|
|
2
|
+
import { eventHandler, getRouterParams, createError } from 'h3'
|
|
3
|
+
import { eq } from 'drizzle-orm'
|
|
4
|
+
import { getTableForModel, getModelSingularName } from '../../utils/modelMapper'
|
|
5
|
+
|
|
6
|
+
import type { TableWithId } from '../../types'
|
|
7
|
+
// @ts-expect-error - #site/drizzle is an alias defined by the module
|
|
8
|
+
import { useDrizzle } from '#site/drizzle'
|
|
9
|
+
|
|
2
10
|
export default eventHandler(async (event) => {
|
|
3
11
|
const { model, id } = getRouterParams(event)
|
|
4
|
-
const table = getTableForModel(model)
|
|
12
|
+
const table = getTableForModel(model) as TableWithId
|
|
5
13
|
const singularName = getModelSingularName(model)
|
|
6
14
|
|
|
7
15
|
const deletedRecord = await useDrizzle()
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
// server/api/[model]/[id].get.ts
|
|
2
|
+
import { eventHandler, getRouterParams, createError } from 'h3'
|
|
3
|
+
import { eq } from 'drizzle-orm'
|
|
4
|
+
import { getTableForModel, getModelSingularName } from '../../utils/modelMapper'
|
|
5
|
+
|
|
6
|
+
import type { TableWithId } from '../../types'
|
|
7
|
+
// @ts-expect-error - #site/drizzle is an alias defined by the module
|
|
8
|
+
import { useDrizzle } from '#site/drizzle'
|
|
9
|
+
|
|
2
10
|
export default eventHandler(async (event) => {
|
|
3
11
|
const { model, id } = getRouterParams(event)
|
|
4
|
-
const table = getTableForModel(model)
|
|
12
|
+
const table = getTableForModel(model) as TableWithId
|
|
5
13
|
const singularName = getModelSingularName(model)
|
|
6
14
|
|
|
7
15
|
const record = await useDrizzle()
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
// server/api/[model]/[id].patch.ts
|
|
2
|
+
import { eventHandler, getRouterParams, readBody } from 'h3'
|
|
3
|
+
import { eq } from 'drizzle-orm'
|
|
4
|
+
import { getTableForModel, filterUpdatableFields } from '../../utils/modelMapper'
|
|
5
|
+
|
|
6
|
+
import type { TableWithId } from '../../types'
|
|
7
|
+
// @ts-expect-error - #site/drizzle is an alias defined by the module
|
|
8
|
+
import { useDrizzle } from '#site/drizzle'
|
|
9
|
+
|
|
2
10
|
export default eventHandler(async (event) => {
|
|
3
11
|
const { model, id } = getRouterParams(event)
|
|
4
|
-
const table = getTableForModel(model)
|
|
12
|
+
const table = getTableForModel(model) as TableWithId
|
|
5
13
|
const body = await readBody(event)
|
|
6
14
|
|
|
7
15
|
// Filter to only allow updatable fields for this model
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
// server/api/[model]/index.get.ts
|
|
2
|
+
import { eventHandler, getRouterParams } from 'h3'
|
|
3
|
+
import { getTableForModel } from '../../utils/modelMapper'
|
|
4
|
+
|
|
5
|
+
// @ts-expect-error - #site/drizzle is an alias defined by the module
|
|
6
|
+
import { useDrizzle } from '#site/drizzle'
|
|
7
|
+
|
|
2
8
|
export default eventHandler(async (event) => {
|
|
3
9
|
const { model } = getRouterParams(event)
|
|
4
10
|
const table = getTableForModel(model)
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
// server/api/[model]/index.post.ts
|
|
2
|
+
import { eventHandler, getRouterParams, readBody } from 'h3'
|
|
3
|
+
import { getTableForModel } from '../../utils/modelMapper'
|
|
4
|
+
|
|
5
|
+
// @ts-expect-error - #site/drizzle is an alias defined by the module
|
|
6
|
+
import { useDrizzle } from '#site/drizzle'
|
|
7
|
+
|
|
2
8
|
export default eventHandler(async (event) => {
|
|
3
9
|
const { model } = getRouterParams(event)
|
|
4
10
|
const table = getTableForModel(model)
|
|
@@ -4,6 +4,7 @@ import * as schema from '#site/schema'
|
|
|
4
4
|
import pluralize from 'pluralize'
|
|
5
5
|
import { pascalCase } from 'scule'
|
|
6
6
|
import { getTableColumns as getDrizzleTableColumns } from 'drizzle-orm'
|
|
7
|
+
import type { SQLiteTable } from 'drizzle-orm/sqlite-core'
|
|
7
8
|
import { createError } from 'h3'
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -63,7 +64,7 @@ export const modelTableMap = buildModelTableMap()
|
|
|
63
64
|
* @returns The corresponding database table
|
|
64
65
|
* @throws Error if model is not found
|
|
65
66
|
*/
|
|
66
|
-
export function getTableForModel(modelName: string) {
|
|
67
|
+
export function getTableForModel(modelName: string): SQLiteTable {
|
|
67
68
|
const table = modelTableMap[modelName]
|
|
68
69
|
|
|
69
70
|
if (!table) {
|
|
@@ -74,7 +75,7 @@ export function getTableForModel(modelName: string) {
|
|
|
74
75
|
})
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
return table
|
|
78
|
+
return table as SQLiteTable
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
/**
|
|
@@ -149,6 +150,7 @@ export function getModelSingularName(modelName: string): string {
|
|
|
149
150
|
* Gets the plural name for a model
|
|
150
151
|
* @param modelName - The model name (singular or plural)
|
|
151
152
|
* @returns The plural name
|
|
153
|
+
* @return The plural name
|
|
152
154
|
*/
|
|
153
155
|
export function getModelPluralName(modelName: string): string {
|
|
154
156
|
return pluralize.plural(modelName)
|