dn-react-router-toolkit 0.6.2 → 0.6.4
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/api/create_api_handler.js +55 -43
- package/dist/api/create_api_handler.mjs +56 -43
- package/dist/crud/crud_form_provider.js +22 -9
- package/dist/crud/crud_form_provider.mjs +22 -9
- package/dist/crud/crud_loader.js +55 -43
- package/dist/crud/crud_loader.mjs +56 -43
- package/dist/crud/crud_page.js +22 -9
- package/dist/crud/crud_page.mjs +22 -9
- package/dist/crud/index.js +77 -52
- package/dist/crud/index.mjs +78 -52
- package/package.json +93 -93
|
@@ -83,53 +83,65 @@ function apiHandler({
|
|
|
83
83
|
switch (request.method) {
|
|
84
84
|
case "POST":
|
|
85
85
|
case "PUT": {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
86
|
+
try {
|
|
87
|
+
const serilaizedParams = await request.json();
|
|
88
|
+
const params = deserialize(serilaizedParams);
|
|
89
|
+
if (validators) {
|
|
90
|
+
const paramsForValidation = Object.keys(
|
|
91
|
+
validators
|
|
92
|
+
).filter(
|
|
93
|
+
(key) => Object.prototype.hasOwnProperty.call(
|
|
94
|
+
validators,
|
|
95
|
+
key
|
|
96
|
+
)
|
|
97
|
+
);
|
|
98
|
+
for (const paramKey of paramsForValidation) {
|
|
99
|
+
const value = params[paramKey];
|
|
100
|
+
const validator = validators[paramKey];
|
|
101
|
+
if (validator?.validate && !validator.validate(value)) {
|
|
102
|
+
throw (0, import_http.BAD_REQUEST)(
|
|
103
|
+
validator.message ? validator.message(value) : void 0
|
|
104
|
+
);
|
|
105
|
+
}
|
|
99
106
|
}
|
|
100
107
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
108
|
+
const itemId = params.id || (0, import_uuid.v4)();
|
|
109
|
+
if (!params.id && existingConditions) {
|
|
110
|
+
const paramsForExistenceCheck = Object.keys(
|
|
111
|
+
existingConditions
|
|
112
|
+
).filter(
|
|
113
|
+
(key) => Object.prototype.hasOwnProperty.call(params, key)
|
|
114
|
+
);
|
|
115
|
+
const where = (0, import_drizzle_orm.and)(
|
|
116
|
+
...paramsForExistenceCheck.reduce((acc, key) => {
|
|
117
|
+
const condition = existingConditions[key];
|
|
118
|
+
if (condition) {
|
|
119
|
+
acc.push(condition(params[key]));
|
|
120
|
+
}
|
|
121
|
+
return acc;
|
|
122
|
+
}, [])
|
|
123
|
+
);
|
|
124
|
+
const existing = await repository.findAll({
|
|
125
|
+
limit: 1,
|
|
126
|
+
where
|
|
127
|
+
});
|
|
128
|
+
if (existing.length > 0) {
|
|
129
|
+
throw (0, import_http.CONFLICT)("\uC790\uB8CC\uAC00 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4.");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const values = {
|
|
133
|
+
id: itemId,
|
|
134
|
+
userId: injectUserId ? auth.userId : void 0,
|
|
135
|
+
...params
|
|
136
|
+
};
|
|
137
|
+
const item = await repository.save(values);
|
|
138
|
+
return (0, import_http.CREATED)(item);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (error instanceof Error) {
|
|
141
|
+
throw (0, import_http.INTERNAL_SERVER_ERROR)(error.message);
|
|
124
142
|
}
|
|
143
|
+
throw error;
|
|
125
144
|
}
|
|
126
|
-
const values = {
|
|
127
|
-
id: itemId,
|
|
128
|
-
userId: injectUserId ? auth.userId : void 0,
|
|
129
|
-
...params
|
|
130
|
-
};
|
|
131
|
-
const item = await repository.save(values);
|
|
132
|
-
return (0, import_http.CREATED)(item);
|
|
133
145
|
}
|
|
134
146
|
default:
|
|
135
147
|
throw (0, import_http.METHOD_NOT_ALLOWED)();
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
BAD_REQUEST,
|
|
4
4
|
CONFLICT,
|
|
5
5
|
CREATED,
|
|
6
|
+
INTERNAL_SERVER_ERROR,
|
|
6
7
|
METHOD_NOT_ALLOWED
|
|
7
8
|
} from "dn-react-toolkit/http";
|
|
8
9
|
import {
|
|
@@ -68,53 +69,65 @@ function apiHandler({
|
|
|
68
69
|
switch (request.method) {
|
|
69
70
|
case "POST":
|
|
70
71
|
case "PUT": {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
72
|
+
try {
|
|
73
|
+
const serilaizedParams = await request.json();
|
|
74
|
+
const params = deserialize(serilaizedParams);
|
|
75
|
+
if (validators) {
|
|
76
|
+
const paramsForValidation = Object.keys(
|
|
77
|
+
validators
|
|
78
|
+
).filter(
|
|
79
|
+
(key) => Object.prototype.hasOwnProperty.call(
|
|
80
|
+
validators,
|
|
81
|
+
key
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
for (const paramKey of paramsForValidation) {
|
|
85
|
+
const value = params[paramKey];
|
|
86
|
+
const validator = validators[paramKey];
|
|
87
|
+
if (validator?.validate && !validator.validate(value)) {
|
|
88
|
+
throw BAD_REQUEST(
|
|
89
|
+
validator.message ? validator.message(value) : void 0
|
|
90
|
+
);
|
|
91
|
+
}
|
|
84
92
|
}
|
|
85
93
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
94
|
+
const itemId = params.id || v4();
|
|
95
|
+
if (!params.id && existingConditions) {
|
|
96
|
+
const paramsForExistenceCheck = Object.keys(
|
|
97
|
+
existingConditions
|
|
98
|
+
).filter(
|
|
99
|
+
(key) => Object.prototype.hasOwnProperty.call(params, key)
|
|
100
|
+
);
|
|
101
|
+
const where = and(
|
|
102
|
+
...paramsForExistenceCheck.reduce((acc, key) => {
|
|
103
|
+
const condition = existingConditions[key];
|
|
104
|
+
if (condition) {
|
|
105
|
+
acc.push(condition(params[key]));
|
|
106
|
+
}
|
|
107
|
+
return acc;
|
|
108
|
+
}, [])
|
|
109
|
+
);
|
|
110
|
+
const existing = await repository.findAll({
|
|
111
|
+
limit: 1,
|
|
112
|
+
where
|
|
113
|
+
});
|
|
114
|
+
if (existing.length > 0) {
|
|
115
|
+
throw CONFLICT("\uC790\uB8CC\uAC00 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4.");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const values = {
|
|
119
|
+
id: itemId,
|
|
120
|
+
userId: injectUserId ? auth.userId : void 0,
|
|
121
|
+
...params
|
|
122
|
+
};
|
|
123
|
+
const item = await repository.save(values);
|
|
124
|
+
return CREATED(item);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (error instanceof Error) {
|
|
127
|
+
throw INTERNAL_SERVER_ERROR(error.message);
|
|
109
128
|
}
|
|
129
|
+
throw error;
|
|
110
130
|
}
|
|
111
|
-
const values = {
|
|
112
|
-
id: itemId,
|
|
113
|
-
userId: injectUserId ? auth.userId : void 0,
|
|
114
|
-
...params
|
|
115
|
-
};
|
|
116
|
-
const item = await repository.save(values);
|
|
117
|
-
return CREATED(item);
|
|
118
131
|
}
|
|
119
132
|
default:
|
|
120
133
|
throw METHOD_NOT_ALLOWED();
|
|
@@ -112,15 +112,28 @@ function CrudFormProvider({
|
|
|
112
112
|
children
|
|
113
113
|
}) {
|
|
114
114
|
const apiPrefix = `/api${prefix}`;
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
115
|
+
const createInitialState = () => {
|
|
116
|
+
return Object.keys(item || columns).reduce((acc, key) => {
|
|
117
|
+
const value = item ? item[key] : void 0;
|
|
118
|
+
if (columns[key]?.defaultValue !== void 0) {
|
|
119
|
+
if (typeof value === "number") {
|
|
120
|
+
return {
|
|
121
|
+
...acc,
|
|
122
|
+
[key]: value ?? columns[key]?.defaultValue
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
...acc,
|
|
127
|
+
[key]: value || columns[key]?.defaultValue
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
...acc,
|
|
132
|
+
[key]: value
|
|
133
|
+
};
|
|
134
|
+
}, {});
|
|
135
|
+
};
|
|
136
|
+
const store = (0, import_react_store_input.useStore)(createInitialState());
|
|
124
137
|
const navigate = (0, import_react_router.useNavigate)();
|
|
125
138
|
const submit = async () => {
|
|
126
139
|
const res = await fetch(apiPrefix, {
|
|
@@ -76,15 +76,28 @@ function CrudFormProvider({
|
|
|
76
76
|
children
|
|
77
77
|
}) {
|
|
78
78
|
const apiPrefix = `/api${prefix}`;
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
const createInitialState = () => {
|
|
80
|
+
return Object.keys(item || columns).reduce((acc, key) => {
|
|
81
|
+
const value = item ? item[key] : void 0;
|
|
82
|
+
if (columns[key]?.defaultValue !== void 0) {
|
|
83
|
+
if (typeof value === "number") {
|
|
84
|
+
return {
|
|
85
|
+
...acc,
|
|
86
|
+
[key]: value ?? columns[key]?.defaultValue
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
...acc,
|
|
91
|
+
[key]: value || columns[key]?.defaultValue
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
...acc,
|
|
96
|
+
[key]: value
|
|
97
|
+
};
|
|
98
|
+
}, {});
|
|
99
|
+
};
|
|
100
|
+
const store = useStore(createInitialState());
|
|
88
101
|
const navigate = useNavigate();
|
|
89
102
|
const submit = async () => {
|
|
90
103
|
const res = await fetch(apiPrefix, {
|
package/dist/crud/crud_loader.js
CHANGED
|
@@ -144,53 +144,65 @@ function apiHandler({
|
|
|
144
144
|
switch (request.method) {
|
|
145
145
|
case "POST":
|
|
146
146
|
case "PUT": {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
147
|
+
try {
|
|
148
|
+
const serilaizedParams = await request.json();
|
|
149
|
+
const params = deserialize(serilaizedParams);
|
|
150
|
+
if (validators) {
|
|
151
|
+
const paramsForValidation = Object.keys(
|
|
152
|
+
validators
|
|
153
|
+
).filter(
|
|
154
|
+
(key) => Object.prototype.hasOwnProperty.call(
|
|
155
|
+
validators,
|
|
156
|
+
key
|
|
157
|
+
)
|
|
158
|
+
);
|
|
159
|
+
for (const paramKey of paramsForValidation) {
|
|
160
|
+
const value = params[paramKey];
|
|
161
|
+
const validator = validators[paramKey];
|
|
162
|
+
if (validator?.validate && !validator.validate(value)) {
|
|
163
|
+
throw (0, import_http.BAD_REQUEST)(
|
|
164
|
+
validator.message ? validator.message(value) : void 0
|
|
165
|
+
);
|
|
166
|
+
}
|
|
160
167
|
}
|
|
161
168
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
169
|
+
const itemId = params.id || (0, import_uuid.v4)();
|
|
170
|
+
if (!params.id && existingConditions) {
|
|
171
|
+
const paramsForExistenceCheck = Object.keys(
|
|
172
|
+
existingConditions
|
|
173
|
+
).filter(
|
|
174
|
+
(key) => Object.prototype.hasOwnProperty.call(params, key)
|
|
175
|
+
);
|
|
176
|
+
const where = (0, import_drizzle_orm2.and)(
|
|
177
|
+
...paramsForExistenceCheck.reduce((acc, key) => {
|
|
178
|
+
const condition = existingConditions[key];
|
|
179
|
+
if (condition) {
|
|
180
|
+
acc.push(condition(params[key]));
|
|
181
|
+
}
|
|
182
|
+
return acc;
|
|
183
|
+
}, [])
|
|
184
|
+
);
|
|
185
|
+
const existing = await repository.findAll({
|
|
186
|
+
limit: 1,
|
|
187
|
+
where
|
|
188
|
+
});
|
|
189
|
+
if (existing.length > 0) {
|
|
190
|
+
throw (0, import_http.CONFLICT)("\uC790\uB8CC\uAC00 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4.");
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const values = {
|
|
194
|
+
id: itemId,
|
|
195
|
+
userId: injectUserId ? auth.userId : void 0,
|
|
196
|
+
...params
|
|
197
|
+
};
|
|
198
|
+
const item = await repository.save(values);
|
|
199
|
+
return (0, import_http.CREATED)(item);
|
|
200
|
+
} catch (error) {
|
|
201
|
+
if (error instanceof Error) {
|
|
202
|
+
throw (0, import_http.INTERNAL_SERVER_ERROR)(error.message);
|
|
185
203
|
}
|
|
204
|
+
throw error;
|
|
186
205
|
}
|
|
187
|
-
const values = {
|
|
188
|
-
id: itemId,
|
|
189
|
-
userId: injectUserId ? auth.userId : void 0,
|
|
190
|
-
...params
|
|
191
|
-
};
|
|
192
|
-
const item = await repository.save(values);
|
|
193
|
-
return (0, import_http.CREATED)(item);
|
|
194
206
|
}
|
|
195
207
|
default:
|
|
196
208
|
throw (0, import_http.METHOD_NOT_ALLOWED)();
|
|
@@ -65,6 +65,7 @@ import {
|
|
|
65
65
|
BAD_REQUEST,
|
|
66
66
|
CONFLICT,
|
|
67
67
|
CREATED,
|
|
68
|
+
INTERNAL_SERVER_ERROR,
|
|
68
69
|
METHOD_NOT_ALLOWED
|
|
69
70
|
} from "dn-react-toolkit/http";
|
|
70
71
|
import {
|
|
@@ -130,53 +131,65 @@ function apiHandler({
|
|
|
130
131
|
switch (request.method) {
|
|
131
132
|
case "POST":
|
|
132
133
|
case "PUT": {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
134
|
+
try {
|
|
135
|
+
const serilaizedParams = await request.json();
|
|
136
|
+
const params = deserialize(serilaizedParams);
|
|
137
|
+
if (validators) {
|
|
138
|
+
const paramsForValidation = Object.keys(
|
|
139
|
+
validators
|
|
140
|
+
).filter(
|
|
141
|
+
(key) => Object.prototype.hasOwnProperty.call(
|
|
142
|
+
validators,
|
|
143
|
+
key
|
|
144
|
+
)
|
|
145
|
+
);
|
|
146
|
+
for (const paramKey of paramsForValidation) {
|
|
147
|
+
const value = params[paramKey];
|
|
148
|
+
const validator = validators[paramKey];
|
|
149
|
+
if (validator?.validate && !validator.validate(value)) {
|
|
150
|
+
throw BAD_REQUEST(
|
|
151
|
+
validator.message ? validator.message(value) : void 0
|
|
152
|
+
);
|
|
153
|
+
}
|
|
146
154
|
}
|
|
147
155
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
156
|
+
const itemId = params.id || v4();
|
|
157
|
+
if (!params.id && existingConditions) {
|
|
158
|
+
const paramsForExistenceCheck = Object.keys(
|
|
159
|
+
existingConditions
|
|
160
|
+
).filter(
|
|
161
|
+
(key) => Object.prototype.hasOwnProperty.call(params, key)
|
|
162
|
+
);
|
|
163
|
+
const where = and2(
|
|
164
|
+
...paramsForExistenceCheck.reduce((acc, key) => {
|
|
165
|
+
const condition = existingConditions[key];
|
|
166
|
+
if (condition) {
|
|
167
|
+
acc.push(condition(params[key]));
|
|
168
|
+
}
|
|
169
|
+
return acc;
|
|
170
|
+
}, [])
|
|
171
|
+
);
|
|
172
|
+
const existing = await repository.findAll({
|
|
173
|
+
limit: 1,
|
|
174
|
+
where
|
|
175
|
+
});
|
|
176
|
+
if (existing.length > 0) {
|
|
177
|
+
throw CONFLICT("\uC790\uB8CC\uAC00 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4.");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const values = {
|
|
181
|
+
id: itemId,
|
|
182
|
+
userId: injectUserId ? auth.userId : void 0,
|
|
183
|
+
...params
|
|
184
|
+
};
|
|
185
|
+
const item = await repository.save(values);
|
|
186
|
+
return CREATED(item);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
if (error instanceof Error) {
|
|
189
|
+
throw INTERNAL_SERVER_ERROR(error.message);
|
|
171
190
|
}
|
|
191
|
+
throw error;
|
|
172
192
|
}
|
|
173
|
-
const values = {
|
|
174
|
-
id: itemId,
|
|
175
|
-
userId: injectUserId ? auth.userId : void 0,
|
|
176
|
-
...params
|
|
177
|
-
};
|
|
178
|
-
const item = await repository.save(values);
|
|
179
|
-
return CREATED(item);
|
|
180
193
|
}
|
|
181
194
|
default:
|
|
182
195
|
throw METHOD_NOT_ALLOWED();
|
package/dist/crud/crud_page.js
CHANGED
|
@@ -113,15 +113,28 @@ function CrudFormProvider({
|
|
|
113
113
|
children
|
|
114
114
|
}) {
|
|
115
115
|
const apiPrefix = `/api${prefix}`;
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
116
|
+
const createInitialState = () => {
|
|
117
|
+
return Object.keys(item || columns).reduce((acc, key) => {
|
|
118
|
+
const value = item ? item[key] : void 0;
|
|
119
|
+
if (columns[key]?.defaultValue !== void 0) {
|
|
120
|
+
if (typeof value === "number") {
|
|
121
|
+
return {
|
|
122
|
+
...acc,
|
|
123
|
+
[key]: value ?? columns[key]?.defaultValue
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
...acc,
|
|
128
|
+
[key]: value || columns[key]?.defaultValue
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
...acc,
|
|
133
|
+
[key]: value
|
|
134
|
+
};
|
|
135
|
+
}, {});
|
|
136
|
+
};
|
|
137
|
+
const store = (0, import_react_store_input.useStore)(createInitialState());
|
|
125
138
|
const navigate = (0, import_react_router.useNavigate)();
|
|
126
139
|
const submit = async () => {
|
|
127
140
|
const res = await fetch(apiPrefix, {
|
package/dist/crud/crud_page.mjs
CHANGED
|
@@ -79,15 +79,28 @@ function CrudFormProvider({
|
|
|
79
79
|
children
|
|
80
80
|
}) {
|
|
81
81
|
const apiPrefix = `/api${prefix}`;
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
82
|
+
const createInitialState = () => {
|
|
83
|
+
return Object.keys(item || columns).reduce((acc, key) => {
|
|
84
|
+
const value = item ? item[key] : void 0;
|
|
85
|
+
if (columns[key]?.defaultValue !== void 0) {
|
|
86
|
+
if (typeof value === "number") {
|
|
87
|
+
return {
|
|
88
|
+
...acc,
|
|
89
|
+
[key]: value ?? columns[key]?.defaultValue
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
...acc,
|
|
94
|
+
[key]: value || columns[key]?.defaultValue
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
...acc,
|
|
99
|
+
[key]: value
|
|
100
|
+
};
|
|
101
|
+
}, {});
|
|
102
|
+
};
|
|
103
|
+
const store = useStore(createInitialState());
|
|
91
104
|
const navigate = useNavigate();
|
|
92
105
|
const submit = async () => {
|
|
93
106
|
const res = await fetch(apiPrefix, {
|
package/dist/crud/index.js
CHANGED
|
@@ -153,15 +153,28 @@ function CrudFormProvider({
|
|
|
153
153
|
children
|
|
154
154
|
}) {
|
|
155
155
|
const apiPrefix = `/api${prefix2}`;
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
156
|
+
const createInitialState = () => {
|
|
157
|
+
return Object.keys(item || columns).reduce((acc, key) => {
|
|
158
|
+
const value = item ? item[key] : void 0;
|
|
159
|
+
if (columns[key]?.defaultValue !== void 0) {
|
|
160
|
+
if (typeof value === "number") {
|
|
161
|
+
return {
|
|
162
|
+
...acc,
|
|
163
|
+
[key]: value ?? columns[key]?.defaultValue
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
...acc,
|
|
168
|
+
[key]: value || columns[key]?.defaultValue
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
...acc,
|
|
173
|
+
[key]: value
|
|
174
|
+
};
|
|
175
|
+
}, {});
|
|
176
|
+
};
|
|
177
|
+
const store = (0, import_react_store_input.useStore)(createInitialState());
|
|
165
178
|
const navigate = (0, import_react_router.useNavigate)();
|
|
166
179
|
const submit = async () => {
|
|
167
180
|
const res = await fetch(apiPrefix, {
|
|
@@ -441,53 +454,65 @@ function apiHandler({
|
|
|
441
454
|
switch (request.method) {
|
|
442
455
|
case "POST":
|
|
443
456
|
case "PUT": {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
+
try {
|
|
458
|
+
const serilaizedParams = await request.json();
|
|
459
|
+
const params = deserialize(serilaizedParams);
|
|
460
|
+
if (validators) {
|
|
461
|
+
const paramsForValidation = Object.keys(
|
|
462
|
+
validators
|
|
463
|
+
).filter(
|
|
464
|
+
(key) => Object.prototype.hasOwnProperty.call(
|
|
465
|
+
validators,
|
|
466
|
+
key
|
|
467
|
+
)
|
|
468
|
+
);
|
|
469
|
+
for (const paramKey of paramsForValidation) {
|
|
470
|
+
const value = params[paramKey];
|
|
471
|
+
const validator = validators[paramKey];
|
|
472
|
+
if (validator?.validate && !validator.validate(value)) {
|
|
473
|
+
throw (0, import_http.BAD_REQUEST)(
|
|
474
|
+
validator.message ? validator.message(value) : void 0
|
|
475
|
+
);
|
|
476
|
+
}
|
|
457
477
|
}
|
|
458
478
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
479
|
+
const itemId = params.id || (0, import_uuid.v4)();
|
|
480
|
+
if (!params.id && existingConditions) {
|
|
481
|
+
const paramsForExistenceCheck = Object.keys(
|
|
482
|
+
existingConditions
|
|
483
|
+
).filter(
|
|
484
|
+
(key) => Object.prototype.hasOwnProperty.call(params, key)
|
|
485
|
+
);
|
|
486
|
+
const where = (0, import_drizzle_orm2.and)(
|
|
487
|
+
...paramsForExistenceCheck.reduce((acc, key) => {
|
|
488
|
+
const condition = existingConditions[key];
|
|
489
|
+
if (condition) {
|
|
490
|
+
acc.push(condition(params[key]));
|
|
491
|
+
}
|
|
492
|
+
return acc;
|
|
493
|
+
}, [])
|
|
494
|
+
);
|
|
495
|
+
const existing = await repository.findAll({
|
|
496
|
+
limit: 1,
|
|
497
|
+
where
|
|
498
|
+
});
|
|
499
|
+
if (existing.length > 0) {
|
|
500
|
+
throw (0, import_http.CONFLICT)("\uC790\uB8CC\uAC00 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4.");
|
|
501
|
+
}
|
|
482
502
|
}
|
|
503
|
+
const values = {
|
|
504
|
+
id: itemId,
|
|
505
|
+
userId: injectUserId ? auth.userId : void 0,
|
|
506
|
+
...params
|
|
507
|
+
};
|
|
508
|
+
const item = await repository.save(values);
|
|
509
|
+
return (0, import_http.CREATED)(item);
|
|
510
|
+
} catch (error) {
|
|
511
|
+
if (error instanceof Error) {
|
|
512
|
+
throw (0, import_http.INTERNAL_SERVER_ERROR)(error.message);
|
|
513
|
+
}
|
|
514
|
+
throw error;
|
|
483
515
|
}
|
|
484
|
-
const values = {
|
|
485
|
-
id: itemId,
|
|
486
|
-
userId: injectUserId ? auth.userId : void 0,
|
|
487
|
-
...params
|
|
488
|
-
};
|
|
489
|
-
const item = await repository.save(values);
|
|
490
|
-
return (0, import_http.CREATED)(item);
|
|
491
516
|
}
|
|
492
517
|
default:
|
|
493
518
|
throw (0, import_http.METHOD_NOT_ALLOWED)();
|
package/dist/crud/index.mjs
CHANGED
|
@@ -111,15 +111,28 @@ function CrudFormProvider({
|
|
|
111
111
|
children
|
|
112
112
|
}) {
|
|
113
113
|
const apiPrefix = `/api${prefix2}`;
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
114
|
+
const createInitialState = () => {
|
|
115
|
+
return Object.keys(item || columns).reduce((acc, key) => {
|
|
116
|
+
const value = item ? item[key] : void 0;
|
|
117
|
+
if (columns[key]?.defaultValue !== void 0) {
|
|
118
|
+
if (typeof value === "number") {
|
|
119
|
+
return {
|
|
120
|
+
...acc,
|
|
121
|
+
[key]: value ?? columns[key]?.defaultValue
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
...acc,
|
|
126
|
+
[key]: value || columns[key]?.defaultValue
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
...acc,
|
|
131
|
+
[key]: value
|
|
132
|
+
};
|
|
133
|
+
}, {});
|
|
134
|
+
};
|
|
135
|
+
const store = useStore(createInitialState());
|
|
123
136
|
const navigate = useNavigate();
|
|
124
137
|
const submit = async () => {
|
|
125
138
|
const res = await fetch(apiPrefix, {
|
|
@@ -385,6 +398,7 @@ import {
|
|
|
385
398
|
BAD_REQUEST,
|
|
386
399
|
CONFLICT,
|
|
387
400
|
CREATED,
|
|
401
|
+
INTERNAL_SERVER_ERROR,
|
|
388
402
|
METHOD_NOT_ALLOWED
|
|
389
403
|
} from "dn-react-toolkit/http";
|
|
390
404
|
import {
|
|
@@ -411,53 +425,65 @@ function apiHandler({
|
|
|
411
425
|
switch (request.method) {
|
|
412
426
|
case "POST":
|
|
413
427
|
case "PUT": {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
428
|
+
try {
|
|
429
|
+
const serilaizedParams = await request.json();
|
|
430
|
+
const params = deserialize(serilaizedParams);
|
|
431
|
+
if (validators) {
|
|
432
|
+
const paramsForValidation = Object.keys(
|
|
433
|
+
validators
|
|
434
|
+
).filter(
|
|
435
|
+
(key) => Object.prototype.hasOwnProperty.call(
|
|
436
|
+
validators,
|
|
437
|
+
key
|
|
438
|
+
)
|
|
439
|
+
);
|
|
440
|
+
for (const paramKey of paramsForValidation) {
|
|
441
|
+
const value = params[paramKey];
|
|
442
|
+
const validator = validators[paramKey];
|
|
443
|
+
if (validator?.validate && !validator.validate(value)) {
|
|
444
|
+
throw BAD_REQUEST(
|
|
445
|
+
validator.message ? validator.message(value) : void 0
|
|
446
|
+
);
|
|
447
|
+
}
|
|
427
448
|
}
|
|
428
449
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
450
|
+
const itemId = params.id || v4();
|
|
451
|
+
if (!params.id && existingConditions) {
|
|
452
|
+
const paramsForExistenceCheck = Object.keys(
|
|
453
|
+
existingConditions
|
|
454
|
+
).filter(
|
|
455
|
+
(key) => Object.prototype.hasOwnProperty.call(params, key)
|
|
456
|
+
);
|
|
457
|
+
const where = and2(
|
|
458
|
+
...paramsForExistenceCheck.reduce((acc, key) => {
|
|
459
|
+
const condition = existingConditions[key];
|
|
460
|
+
if (condition) {
|
|
461
|
+
acc.push(condition(params[key]));
|
|
462
|
+
}
|
|
463
|
+
return acc;
|
|
464
|
+
}, [])
|
|
465
|
+
);
|
|
466
|
+
const existing = await repository.findAll({
|
|
467
|
+
limit: 1,
|
|
468
|
+
where
|
|
469
|
+
});
|
|
470
|
+
if (existing.length > 0) {
|
|
471
|
+
throw CONFLICT("\uC790\uB8CC\uAC00 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4.");
|
|
472
|
+
}
|
|
452
473
|
}
|
|
474
|
+
const values = {
|
|
475
|
+
id: itemId,
|
|
476
|
+
userId: injectUserId ? auth.userId : void 0,
|
|
477
|
+
...params
|
|
478
|
+
};
|
|
479
|
+
const item = await repository.save(values);
|
|
480
|
+
return CREATED(item);
|
|
481
|
+
} catch (error) {
|
|
482
|
+
if (error instanceof Error) {
|
|
483
|
+
throw INTERNAL_SERVER_ERROR(error.message);
|
|
484
|
+
}
|
|
485
|
+
throw error;
|
|
453
486
|
}
|
|
454
|
-
const values = {
|
|
455
|
-
id: itemId,
|
|
456
|
-
userId: injectUserId ? auth.userId : void 0,
|
|
457
|
-
...params
|
|
458
|
-
};
|
|
459
|
-
const item = await repository.save(values);
|
|
460
|
-
return CREATED(item);
|
|
461
487
|
}
|
|
462
488
|
default:
|
|
463
489
|
throw METHOD_NOT_ALLOWED();
|
package/package.json
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
"name": "dn-react-router-toolkit",
|
|
3
|
+
"version": "0.6.4",
|
|
4
|
+
"types": "./dist/index.d.ts",
|
|
5
|
+
"main": "./dist/index.mjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./auth": {
|
|
14
|
+
"types": "./dist/auth/index.d.ts",
|
|
15
|
+
"import": "./dist/auth/index.mjs",
|
|
16
|
+
"require": "./dist/auth/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./api": {
|
|
19
|
+
"types": "./dist/api/index.d.ts",
|
|
20
|
+
"import": "./dist/api/index.mjs",
|
|
21
|
+
"require": "./dist/api/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./client": {
|
|
24
|
+
"types": "./dist/client/index.d.ts",
|
|
25
|
+
"import": "./dist/client/index.mjs",
|
|
26
|
+
"require": "./dist/client/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./seo": {
|
|
29
|
+
"types": "./dist/seo/index.d.ts",
|
|
30
|
+
"import": "./dist/seo/index.mjs",
|
|
31
|
+
"require": "./dist/seo/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./db": {
|
|
34
|
+
"types": "./dist/db/index.d.ts",
|
|
35
|
+
"import": "./dist/db/index.mjs",
|
|
36
|
+
"require": "./dist/db/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./db/backup": {
|
|
39
|
+
"types": "./dist/db/backup/index.d.ts",
|
|
40
|
+
"import": "./dist/db/backup/index.mjs",
|
|
41
|
+
"require": "./dist/db/backup/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./table": {
|
|
44
|
+
"types": "./dist/table/index.d.ts",
|
|
45
|
+
"import": "./dist/table/index.mjs",
|
|
46
|
+
"require": "./dist/table/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./crud": {
|
|
49
|
+
"types": "./dist/crud/index.d.ts",
|
|
50
|
+
"import": "./dist/crud/index.mjs",
|
|
51
|
+
"require": "./dist/crud/index.js"
|
|
52
|
+
},
|
|
53
|
+
"./post": {
|
|
54
|
+
"types": "./dist/post/index.d.ts",
|
|
55
|
+
"import": "./dist/post/index.mjs",
|
|
56
|
+
"require": "./dist/post/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./form": {
|
|
59
|
+
"types": "./dist/form/index.d.ts",
|
|
60
|
+
"import": "./dist/form/index.mjs",
|
|
61
|
+
"require": "./dist/form/index.js"
|
|
62
|
+
}
|
|
12
63
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"require": "./dist/auth/index.js"
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsup",
|
|
66
|
+
"dev": "tsup --watch"
|
|
17
67
|
},
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"require": "./dist/api/index.js"
|
|
68
|
+
"repository": {
|
|
69
|
+
"type": "git",
|
|
70
|
+
"url": "git+https://github.com/dndnsoft/dn-react-router-toolkit.git"
|
|
22
71
|
},
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
72
|
+
"author": "",
|
|
73
|
+
"license": "MIT",
|
|
74
|
+
"bugs": {
|
|
75
|
+
"url": "https://github.com/dndnsoft/dn-react-router-toolkit/issues"
|
|
27
76
|
},
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
77
|
+
"homepage": "https://github.com/dndnsoft/dn-react-router-toolkit#readme",
|
|
78
|
+
"description": "",
|
|
79
|
+
"devDependencies": {
|
|
80
|
+
"@types/node": "^24.10.1",
|
|
81
|
+
"@types/react": "^19",
|
|
82
|
+
"@types/react-dom": "^19",
|
|
83
|
+
"schema-dts": "^1.1.5",
|
|
84
|
+
"tsup": "^8.5.1",
|
|
85
|
+
"typescript": "^5.7.3"
|
|
32
86
|
},
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
87
|
+
"dependencies": {
|
|
88
|
+
"@react-router/dev": "^7.11.0",
|
|
89
|
+
"dn-react-text-editor": "^0.2.4",
|
|
90
|
+
"dn-react-toolkit": "^0.2.49",
|
|
91
|
+
"pg": "^8.16.3",
|
|
92
|
+
"react-store-input": "^0.1.7",
|
|
93
|
+
"uuid": "^13.0.0"
|
|
37
94
|
},
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"./table": {
|
|
44
|
-
"types": "./dist/table/index.d.ts",
|
|
45
|
-
"import": "./dist/table/index.mjs",
|
|
46
|
-
"require": "./dist/table/index.js"
|
|
47
|
-
},
|
|
48
|
-
"./crud": {
|
|
49
|
-
"types": "./dist/crud/index.d.ts",
|
|
50
|
-
"import": "./dist/crud/index.mjs",
|
|
51
|
-
"require": "./dist/crud/index.js"
|
|
52
|
-
},
|
|
53
|
-
"./post": {
|
|
54
|
-
"types": "./dist/post/index.d.ts",
|
|
55
|
-
"import": "./dist/post/index.mjs",
|
|
56
|
-
"require": "./dist/post/index.js"
|
|
57
|
-
},
|
|
58
|
-
"./form": {
|
|
59
|
-
"types": "./dist/form/index.d.ts",
|
|
60
|
-
"import": "./dist/form/index.mjs",
|
|
61
|
-
"require": "./dist/form/index.js"
|
|
95
|
+
"peerDependencies": {
|
|
96
|
+
"drizzle-orm": "^0.45.1",
|
|
97
|
+
"react": "^19",
|
|
98
|
+
"react-dom": "^19",
|
|
99
|
+
"react-router": "^7"
|
|
62
100
|
}
|
|
63
|
-
|
|
64
|
-
"scripts": {
|
|
65
|
-
"build": "tsup",
|
|
66
|
-
"dev": "tsup --watch"
|
|
67
|
-
},
|
|
68
|
-
"repository": {
|
|
69
|
-
"type": "git",
|
|
70
|
-
"url": "git+https://github.com/dndnsoft/dn-react-router-toolkit.git"
|
|
71
|
-
},
|
|
72
|
-
"author": "",
|
|
73
|
-
"license": "MIT",
|
|
74
|
-
"bugs": {
|
|
75
|
-
"url": "https://github.com/dndnsoft/dn-react-router-toolkit/issues"
|
|
76
|
-
},
|
|
77
|
-
"homepage": "https://github.com/dndnsoft/dn-react-router-toolkit#readme",
|
|
78
|
-
"description": "",
|
|
79
|
-
"devDependencies": {
|
|
80
|
-
"@types/node": "^24.10.1",
|
|
81
|
-
"@types/react": "^19",
|
|
82
|
-
"@types/react-dom": "^19",
|
|
83
|
-
"schema-dts": "^1.1.5",
|
|
84
|
-
"tsup": "^8.5.1",
|
|
85
|
-
"typescript": "^5.7.3"
|
|
86
|
-
},
|
|
87
|
-
"dependencies": {
|
|
88
|
-
"@react-router/dev": "^7.11.0",
|
|
89
|
-
"dn-react-text-editor": "^0.2.3",
|
|
90
|
-
"dn-react-toolkit": "^0.2.49",
|
|
91
|
-
"pg": "^8.16.3",
|
|
92
|
-
"react-store-input": "^0.1.7",
|
|
93
|
-
"uuid": "^13.0.0"
|
|
94
|
-
},
|
|
95
|
-
"peerDependencies": {
|
|
96
|
-
"drizzle-orm": "^0.45.1",
|
|
97
|
-
"react": "^19",
|
|
98
|
-
"react-dom": "^19",
|
|
99
|
-
"react-router": "^7"
|
|
100
|
-
}
|
|
101
|
-
}
|
|
101
|
+
}
|