core-nails 1.0.10 → 1.0.13
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/.github/workflows/publish.yml +32 -0
- package/dist/cli/generate/scaffold.js +14 -9
- package/dist/helpers/InitializeModel.d.ts +3 -8
- package/dist/helpers/InitializeModel.js +4 -4
- package/package.json +3 -2
- package/src/cli/generate/scaffold.ts +14 -9
- package/src/helpers/InitializeModel.ts +7 -35
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
paths:
|
|
8
|
+
- 'package.json'
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build-and-publish:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v3
|
|
16
|
+
|
|
17
|
+
- name: Setup Node.js
|
|
18
|
+
uses: actions/setup-node@v3
|
|
19
|
+
with:
|
|
20
|
+
node-version: 20
|
|
21
|
+
registry-url: https://registry.npmjs.org/
|
|
22
|
+
|
|
23
|
+
- name: Install dependencies
|
|
24
|
+
run: npm install
|
|
25
|
+
|
|
26
|
+
- name: Build dist
|
|
27
|
+
run: npm run build
|
|
28
|
+
|
|
29
|
+
- name: Publish to npm
|
|
30
|
+
run: npm publish
|
|
31
|
+
env:
|
|
32
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
@@ -82,22 +82,27 @@ export async function POST(req: Request) {
|
|
|
82
82
|
// --- 6️⃣ API [id]/route.ts ---
|
|
83
83
|
fs.mkdirSync(apiIdDir, { recursive: true });
|
|
84
84
|
const apiIdRoutePath = path.join(apiIdDir, "route.ts");
|
|
85
|
-
const apiIdRouteContent = `import
|
|
85
|
+
const apiIdRouteContent = `import { NextRequest } from "next/server";
|
|
86
|
+
import ${camelName}Controller from "@controller/${camelName}";
|
|
86
87
|
|
|
87
|
-
export async function GET(req:
|
|
88
|
-
|
|
88
|
+
export async function GET(req: NextRequest, context: { params: Promise<{ id: string }> }): Promise<Response> {
|
|
89
|
+
const { id } = await context.params;
|
|
90
|
+
return ${camelName}Controller.show_action(req, id);
|
|
89
91
|
}
|
|
90
92
|
|
|
91
|
-
export async function PATCH(req:
|
|
92
|
-
|
|
93
|
+
export async function PATCH(req: NextRequest, context: { params: Promise<{ id: string }> }): Promise<Response> {
|
|
94
|
+
const { id } = await context.params;
|
|
95
|
+
return ${camelName}Controller.update_action(req, id);
|
|
93
96
|
}
|
|
94
97
|
|
|
95
|
-
export async function PUT(req:
|
|
96
|
-
|
|
98
|
+
export async function PUT(req: NextRequest, context: { params: Promise<{ id: string }> }): Promise<Response> {
|
|
99
|
+
const { id } = await context.params;
|
|
100
|
+
return ${camelName}Controller.update_action(req, id);
|
|
97
101
|
}
|
|
98
102
|
|
|
99
|
-
export async function DELETE(req:
|
|
100
|
-
|
|
103
|
+
export async function DELETE(req: NextRequest, context: { params: Promise<{ id: string }> }): Promise<Response> {
|
|
104
|
+
const { id } = await context.params;
|
|
105
|
+
return ${camelName}Controller.destroy_action(req, id);
|
|
101
106
|
}
|
|
102
107
|
`;
|
|
103
108
|
fs.writeFileSync(apiIdRoutePath, apiIdRouteContent);
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { z, ZodObject, ZodRawShape } from "zod";
|
|
2
|
-
type
|
|
3
|
-
type WhereCondition<T> = {
|
|
4
|
-
field: keyof T;
|
|
5
|
-
operator: WhereOperator;
|
|
6
|
-
value: any;
|
|
7
|
-
};
|
|
2
|
+
type WhereCondition<T> = Partial<Record<keyof T, any>>;
|
|
8
3
|
declare function InitializeModel<TSchema extends ZodObject<ZodRawShape>>(opts: {
|
|
9
4
|
collection: string;
|
|
10
5
|
schema: TSchema;
|
|
@@ -21,10 +16,10 @@ declare function InitializeModel<TSchema extends ZodObject<ZodRawShape>>(opts: {
|
|
|
21
16
|
}) | null>;
|
|
22
17
|
update(data: Partial<z.core.output<TSchema>>, id: string): Promise<void>;
|
|
23
18
|
destroy(id: string): Promise<void>;
|
|
24
|
-
where(conditions: WhereCondition<z.core.output<TSchema>>
|
|
19
|
+
where(conditions: WhereCondition<z.core.output<TSchema>>): Promise<(z.core.output<TSchema> & {
|
|
25
20
|
id: string;
|
|
26
21
|
})[]>;
|
|
27
|
-
find_by(conditions: WhereCondition<z.core.output<TSchema>>
|
|
22
|
+
find_by(conditions: WhereCondition<z.core.output<TSchema>>): Promise<(z.core.output<TSchema> & {
|
|
28
23
|
id: string;
|
|
29
24
|
}) | null>;
|
|
30
25
|
};
|
|
@@ -74,16 +74,16 @@ function InitializeModel(opts) {
|
|
|
74
74
|
},
|
|
75
75
|
async where(conditions) {
|
|
76
76
|
let query = collection;
|
|
77
|
-
for (const
|
|
78
|
-
query = query.where(
|
|
77
|
+
for (const [field, value] of Object.entries(conditions)) {
|
|
78
|
+
query = query.where(field, "==", value);
|
|
79
79
|
}
|
|
80
80
|
const snapshot = await query.get();
|
|
81
81
|
return parseDocs(snapshot);
|
|
82
82
|
},
|
|
83
83
|
async find_by(conditions) {
|
|
84
84
|
let query = collection;
|
|
85
|
-
for (const
|
|
86
|
-
query = query.where(
|
|
85
|
+
for (const [field, value] of Object.entries(conditions)) {
|
|
86
|
+
query = query.where(field, "==", value);
|
|
87
87
|
}
|
|
88
88
|
const snapshot = await query.limit(1).get();
|
|
89
89
|
if (snapshot.empty)
|
package/package.json
CHANGED
|
@@ -110,22 +110,27 @@ export async function POST(req: Request) {
|
|
|
110
110
|
|
|
111
111
|
const apiIdRoutePath = path.join(apiIdDir, "route.ts");
|
|
112
112
|
|
|
113
|
-
const apiIdRouteContent = `import
|
|
113
|
+
const apiIdRouteContent = `import { NextRequest } from "next/server";
|
|
114
|
+
import ${camelName}Controller from "@controller/${camelName}";
|
|
114
115
|
|
|
115
|
-
export async function GET(req:
|
|
116
|
-
|
|
116
|
+
export async function GET(req: NextRequest, context: { params: Promise<{ id: string }> }): Promise<Response> {
|
|
117
|
+
const { id } = await context.params;
|
|
118
|
+
return ${camelName}Controller.show_action(req, id);
|
|
117
119
|
}
|
|
118
120
|
|
|
119
|
-
export async function PATCH(req:
|
|
120
|
-
|
|
121
|
+
export async function PATCH(req: NextRequest, context: { params: Promise<{ id: string }> }): Promise<Response> {
|
|
122
|
+
const { id } = await context.params;
|
|
123
|
+
return ${camelName}Controller.update_action(req, id);
|
|
121
124
|
}
|
|
122
125
|
|
|
123
|
-
export async function PUT(req:
|
|
124
|
-
|
|
126
|
+
export async function PUT(req: NextRequest, context: { params: Promise<{ id: string }> }): Promise<Response> {
|
|
127
|
+
const { id } = await context.params;
|
|
128
|
+
return ${camelName}Controller.update_action(req, id);
|
|
125
129
|
}
|
|
126
130
|
|
|
127
|
-
export async function DELETE(req:
|
|
128
|
-
|
|
131
|
+
export async function DELETE(req: NextRequest, context: { params: Promise<{ id: string }> }): Promise<Response> {
|
|
132
|
+
const { id } = await context.params;
|
|
133
|
+
return ${camelName}Controller.destroy_action(req, id);
|
|
129
134
|
}
|
|
130
135
|
`;
|
|
131
136
|
|
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
import { z, ZodObject, ZodRawShape } from "zod";
|
|
2
2
|
|
|
3
|
-
type
|
|
4
|
-
| "=="
|
|
5
|
-
| "!="
|
|
6
|
-
| "<"
|
|
7
|
-
| "<="
|
|
8
|
-
| ">"
|
|
9
|
-
| ">="
|
|
10
|
-
| "array-contains"
|
|
11
|
-
| "in"
|
|
12
|
-
| "not-in"
|
|
13
|
-
| "array-contains-any";
|
|
14
|
-
|
|
15
|
-
type WhereCondition<T> = {
|
|
16
|
-
field: keyof T;
|
|
17
|
-
operator: WhereOperator;
|
|
18
|
-
value: any;
|
|
19
|
-
};
|
|
3
|
+
type WhereCondition<T> = Partial<Record<keyof T, any>>;
|
|
20
4
|
|
|
21
5
|
function InitializeModel<TSchema extends ZodObject<ZodRawShape>>(opts: {
|
|
22
6
|
collection: string;
|
|
@@ -119,34 +103,22 @@ function InitializeModel<TSchema extends ZodObject<ZodRawShape>>(opts: {
|
|
|
119
103
|
await collection.doc(id).delete();
|
|
120
104
|
},
|
|
121
105
|
|
|
122
|
-
async where(
|
|
123
|
-
conditions: WhereCondition<T>[]
|
|
124
|
-
): Promise<WithId[]> {
|
|
106
|
+
async where(conditions: WhereCondition<T>): Promise<WithId[]> {
|
|
125
107
|
let query: any = collection;
|
|
126
108
|
|
|
127
|
-
for (const
|
|
128
|
-
query = query.where(
|
|
129
|
-
cond.field as string,
|
|
130
|
-
cond.operator,
|
|
131
|
-
cond.value
|
|
132
|
-
);
|
|
109
|
+
for (const [field, value] of Object.entries(conditions)) {
|
|
110
|
+
query = query.where(field, "==", value);
|
|
133
111
|
}
|
|
134
112
|
|
|
135
113
|
const snapshot = await query.get();
|
|
136
114
|
return parseDocs(snapshot);
|
|
137
115
|
},
|
|
138
116
|
|
|
139
|
-
async find_by(
|
|
140
|
-
conditions: WhereCondition<T>[]
|
|
141
|
-
): Promise<WithId | null> {
|
|
117
|
+
async find_by(conditions: WhereCondition<T>): Promise<WithId | null> {
|
|
142
118
|
let query: any = collection;
|
|
143
119
|
|
|
144
|
-
for (const
|
|
145
|
-
query = query.where(
|
|
146
|
-
cond.field as string,
|
|
147
|
-
cond.operator,
|
|
148
|
-
cond.value
|
|
149
|
-
);
|
|
120
|
+
for (const [field, value] of Object.entries(conditions)) {
|
|
121
|
+
query = query.where(field, "==", value);
|
|
150
122
|
}
|
|
151
123
|
|
|
152
124
|
const snapshot = await query.limit(1).get();
|