dn-react-router-toolkit 0.9.0 → 0.9.2
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/default_api_handler.d.mts +13 -0
- package/dist/api/default_api_handler.d.ts +13 -0
- package/dist/api/{create_handler.js → default_api_handler.js} +49 -52
- package/dist/api/{create_handler.mjs → default_api_handler.mjs} +45 -48
- package/dist/api/index.d.mts +8 -7
- package/dist/api/index.d.ts +8 -7
- package/dist/api/index.js +233 -147
- package/dist/api/index.mjs +238 -151
- package/dist/api/put_resource_handler.d.mts +25 -0
- package/dist/api/put_resource_handler.d.ts +25 -0
- package/dist/api/put_resource_handler.js +214 -0
- package/dist/api/put_resource_handler.mjs +194 -0
- package/dist/api/resource_handler.d.mts +26 -0
- package/dist/api/resource_handler.d.ts +26 -0
- package/dist/api/resource_handler.js +280 -0
- package/dist/api/resource_handler.mjs +265 -0
- package/dist/auth/cookie_manager.d.mts +1 -1
- package/dist/auth/cookie_manager.d.ts +1 -1
- package/dist/auth/index.d.mts +2 -2
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +18 -18
- package/dist/auth/index.mjs +18 -18
- package/dist/auth/with_auth.d.mts +2 -2
- package/dist/auth/with_auth.d.ts +2 -2
- package/dist/auth/with_auth.js +18 -18
- package/dist/auth/with_auth.mjs +18 -18
- package/dist/client/editor.d.mts +2 -2
- package/dist/client/editor.d.ts +2 -2
- package/dist/client/editor.js +9 -3
- package/dist/client/editor.mjs +9 -3
- package/dist/client/index.d.mts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +9 -3
- package/dist/client/index.mjs +9 -3
- package/dist/crud/crud_form.js +22 -4
- package/dist/crud/crud_form.mjs +11 -3
- package/dist/crud/crud_form_provider.js +16 -3
- package/dist/crud/crud_form_provider.mjs +14 -1
- package/dist/crud/index.js +22 -4
- package/dist/crud/index.mjs +11 -3
- package/dist/db/backup/index.d.mts +1 -1
- package/dist/db/backup/index.d.ts +1 -1
- package/dist/form/create_form_component.js +21 -2
- package/dist/form/create_form_component.mjs +10 -1
- package/dist/form/form_components.js +21 -2
- package/dist/form/form_components.mjs +10 -1
- package/dist/form/index.js +21 -2
- package/dist/form/index.mjs +10 -1
- package/dist/post/editor_toolbar.js +20 -3
- package/dist/post/editor_toolbar.mjs +9 -2
- package/dist/post/index.js +31 -11
- package/dist/post/index.mjs +19 -9
- package/dist/post/post_form_page.js +29 -11
- package/dist/post/post_form_page.mjs +17 -9
- package/dist/post/thumbnail_picker.js +21 -2
- package/dist/post/thumbnail_picker.mjs +10 -1
- package/dist/table/buttons.js +11 -14
- package/dist/table/buttons.mjs +10 -13
- package/dist/table/index.js +14 -18
- package/dist/table/index.mjs +13 -17
- package/dist/table/table.js +10 -4
- package/dist/table/table.mjs +5 -1
- package/dist/table/table_form.js +12 -18
- package/dist/table/table_form.mjs +9 -15
- package/dist/utils/cn.d.mts +3 -0
- package/dist/utils/cn.d.ts +3 -0
- package/dist/utils/cn.js +32 -0
- package/dist/utils/cn.mjs +7 -0
- package/dist/utils/date.d.mts +5 -0
- package/dist/utils/date.d.ts +5 -0
- package/dist/utils/date.js +65 -0
- package/dist/utils/date.mjs +29 -0
- package/dist/utils/index.d.mts +7 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +116 -0
- package/dist/utils/index.mjs +73 -0
- package/dist/utils/korean.d.mts +6 -0
- package/dist/utils/korean.d.ts +6 -0
- package/dist/utils/korean.js +41 -0
- package/dist/utils/korean.mjs +16 -0
- package/dist/utils/singleton.d.mts +3 -0
- package/dist/utils/singleton.d.ts +3 -0
- package/dist/utils/singleton.js +37 -0
- package/dist/utils/singleton.mjs +12 -0
- package/dist/utils/sleep.d.mts +3 -0
- package/dist/utils/sleep.d.ts +3 -0
- package/dist/utils/sleep.js +32 -0
- package/dist/utils/sleep.mjs +7 -0
- package/dist/utils/slug.d.mts +3 -0
- package/dist/utils/slug.d.ts +3 -0
- package/dist/utils/slug.js +32 -0
- package/dist/utils/slug.mjs +7 -0
- package/package.json +8 -4
- package/dist/api/create_api_handler.d.mts +0 -30
- package/dist/api/create_api_handler.d.ts +0 -30
- package/dist/api/create_api_handler.js +0 -155
- package/dist/api/create_api_handler.mjs +0 -139
- package/dist/api/create_handler.d.mts +0 -13
- package/dist/api/create_handler.d.ts +0 -13
- package/dist/api/item_api_handler.d.mts +0 -21
- package/dist/api/item_api_handler.d.ts +0 -21
- package/dist/api/item_api_handler.js +0 -63
- package/dist/api/item_api_handler.mjs +0 -38
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/api/put_resource_handler.ts
|
|
31
|
+
var put_resource_handler_exports = {};
|
|
32
|
+
__export(put_resource_handler_exports, {
|
|
33
|
+
putResourceHandler: () => putResourceHandler
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(put_resource_handler_exports);
|
|
36
|
+
var import_gw_response = require("gw-response");
|
|
37
|
+
|
|
38
|
+
// src/crud/crud_form_provider.tsx
|
|
39
|
+
var import_react_router = require("react-router");
|
|
40
|
+
var import_react_store_input = require("react-store-input");
|
|
41
|
+
var import_react = require("react");
|
|
42
|
+
|
|
43
|
+
// src/crud/serialize.ts
|
|
44
|
+
function deserialize(data) {
|
|
45
|
+
if (data === void 0) {
|
|
46
|
+
return void 0;
|
|
47
|
+
}
|
|
48
|
+
if (typeof data === "object" && data !== null && "type" in data && "value" in data) {
|
|
49
|
+
const { type, value } = data;
|
|
50
|
+
switch (type) {
|
|
51
|
+
case "null":
|
|
52
|
+
return null;
|
|
53
|
+
case "string":
|
|
54
|
+
return value;
|
|
55
|
+
case "number":
|
|
56
|
+
return value;
|
|
57
|
+
case "boolean":
|
|
58
|
+
return value;
|
|
59
|
+
case "date":
|
|
60
|
+
return new Date(value);
|
|
61
|
+
case "array":
|
|
62
|
+
return value.map((item) => deserialize(item));
|
|
63
|
+
case "object":
|
|
64
|
+
return Object.entries(value).reduce(
|
|
65
|
+
(acc, [key, value2]) => {
|
|
66
|
+
return {
|
|
67
|
+
...acc,
|
|
68
|
+
[key]: deserialize(value2)
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
{}
|
|
72
|
+
);
|
|
73
|
+
default:
|
|
74
|
+
return void 0;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return void 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/crud/crud_form_provider.tsx
|
|
81
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
82
|
+
var FormContext = (0, import_react.createContext)({});
|
|
83
|
+
|
|
84
|
+
// src/form/create_form_component.tsx
|
|
85
|
+
var import_react2 = require("react");
|
|
86
|
+
|
|
87
|
+
// src/utils/cn.ts
|
|
88
|
+
function cn(...classes) {
|
|
89
|
+
return classes.filter(Boolean).join(" ").trim();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/utils/date.ts
|
|
93
|
+
var import_moment_timezone = __toESM(require("moment-timezone"));
|
|
94
|
+
|
|
95
|
+
// src/form/create_form_component.tsx
|
|
96
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
97
|
+
function createComponent(tag, options) {
|
|
98
|
+
return function FormComponent({ className, ...props }) {
|
|
99
|
+
const Tag = tag;
|
|
100
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Tag, { ...props, className: cn(options.className, className) });
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/form/form_components.tsx
|
|
105
|
+
var FormEntry = createComponent("div", {
|
|
106
|
+
className: "flex-1"
|
|
107
|
+
});
|
|
108
|
+
var FormRow = createComponent("div", {
|
|
109
|
+
className: "flex-1 flex gap-4 mb-6"
|
|
110
|
+
});
|
|
111
|
+
var FormLabel = createComponent("label", {
|
|
112
|
+
className: "flex-1 font-semibold mb-2.5 block"
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// src/crud/crud_form.tsx
|
|
116
|
+
var import_react_store_input3 = require("react-store-input");
|
|
117
|
+
|
|
118
|
+
// src/client/env_loader.tsx
|
|
119
|
+
var import_react_router2 = require("react-router");
|
|
120
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
121
|
+
|
|
122
|
+
// src/client/file_input.tsx
|
|
123
|
+
var import_react3 = require("react");
|
|
124
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
125
|
+
|
|
126
|
+
// src/client/use_user_agent.tsx
|
|
127
|
+
var import_react_router3 = require("react-router");
|
|
128
|
+
|
|
129
|
+
// src/client/store_text_editor.tsx
|
|
130
|
+
var import_dn_react_text_editor = require("dn-react-text-editor");
|
|
131
|
+
var import_react_store_input2 = require("react-store-input");
|
|
132
|
+
var import_react4 = require("react");
|
|
133
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
134
|
+
|
|
135
|
+
// src/client/editor.tsx
|
|
136
|
+
var import_client = require("gw-file/client");
|
|
137
|
+
|
|
138
|
+
// src/crud/crud_form.tsx
|
|
139
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
140
|
+
|
|
141
|
+
// src/api/put_resource_handler.ts
|
|
142
|
+
var import_drizzle_orm = require("drizzle-orm");
|
|
143
|
+
var import_uuid = require("uuid");
|
|
144
|
+
function putResourceHandler({
|
|
145
|
+
repository,
|
|
146
|
+
validators,
|
|
147
|
+
existingConditions,
|
|
148
|
+
injectUserId,
|
|
149
|
+
isOwnedBy
|
|
150
|
+
}) {
|
|
151
|
+
return async (auth, request) => {
|
|
152
|
+
const serilaizedParams = await request.json();
|
|
153
|
+
const params = deserialize(serilaizedParams);
|
|
154
|
+
const itemId = params.id || (0, import_uuid.v4)();
|
|
155
|
+
if (params.id) {
|
|
156
|
+
const existing = await repository.find(itemId);
|
|
157
|
+
if (!existing) {
|
|
158
|
+
return (0, import_gw_response.httpNotFound)();
|
|
159
|
+
}
|
|
160
|
+
if (isOwnedBy && (!auth || !isOwnedBy(auth, existing))) {
|
|
161
|
+
return (0, import_gw_response.httpForbidden)();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (validators) {
|
|
165
|
+
const paramsForValidation = Object.keys(validators).filter(
|
|
166
|
+
(key) => Object.prototype.hasOwnProperty.call(validators, key)
|
|
167
|
+
);
|
|
168
|
+
for (const paramKey of paramsForValidation) {
|
|
169
|
+
const value = params[paramKey];
|
|
170
|
+
const validator = validators[paramKey];
|
|
171
|
+
if (validator?.validate && !validator.validate(value)) {
|
|
172
|
+
return (0, import_gw_response.httpBadRequest)({
|
|
173
|
+
code: "BAD_REQUEST",
|
|
174
|
+
message: validator.message ? validator.message(value) : "\uC798\uBABB\uB41C \uC694\uCCAD\uC785\uB2C8\uB2E4."
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (!params.id && existingConditions) {
|
|
180
|
+
const paramsForExistenceCheck = Object.keys(existingConditions).filter(
|
|
181
|
+
(key) => Object.prototype.hasOwnProperty.call(params, key)
|
|
182
|
+
);
|
|
183
|
+
if (paramsForExistenceCheck.length > 0) {
|
|
184
|
+
const where = (0, import_drizzle_orm.and)(
|
|
185
|
+
...paramsForExistenceCheck.reduce((acc, key) => {
|
|
186
|
+
const condition = existingConditions[key];
|
|
187
|
+
if (condition) {
|
|
188
|
+
acc.push(condition(params[key]));
|
|
189
|
+
}
|
|
190
|
+
return acc;
|
|
191
|
+
}, [])
|
|
192
|
+
);
|
|
193
|
+
const existing = await repository.findAll({
|
|
194
|
+
limit: 1,
|
|
195
|
+
where
|
|
196
|
+
});
|
|
197
|
+
if (existing.length > 0) {
|
|
198
|
+
return (0, import_gw_response.httpConflict)();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const values = {
|
|
203
|
+
id: itemId,
|
|
204
|
+
userId: injectUserId ? auth?.userId : void 0,
|
|
205
|
+
...params
|
|
206
|
+
};
|
|
207
|
+
const item = await repository.save(values);
|
|
208
|
+
return (0, import_gw_response.httpCreated)(item);
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
212
|
+
0 && (module.exports = {
|
|
213
|
+
putResourceHandler
|
|
214
|
+
});
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// src/api/put_resource_handler.ts
|
|
2
|
+
import {
|
|
3
|
+
httpBadRequest,
|
|
4
|
+
httpConflict,
|
|
5
|
+
httpCreated,
|
|
6
|
+
httpForbidden,
|
|
7
|
+
httpNotFound
|
|
8
|
+
} from "gw-response";
|
|
9
|
+
|
|
10
|
+
// src/crud/crud_form_provider.tsx
|
|
11
|
+
import { useNavigate } from "react-router";
|
|
12
|
+
import { useStore } from "react-store-input";
|
|
13
|
+
import {
|
|
14
|
+
createContext,
|
|
15
|
+
useContext
|
|
16
|
+
} from "react";
|
|
17
|
+
|
|
18
|
+
// src/crud/serialize.ts
|
|
19
|
+
function deserialize(data) {
|
|
20
|
+
if (data === void 0) {
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
if (typeof data === "object" && data !== null && "type" in data && "value" in data) {
|
|
24
|
+
const { type, value } = data;
|
|
25
|
+
switch (type) {
|
|
26
|
+
case "null":
|
|
27
|
+
return null;
|
|
28
|
+
case "string":
|
|
29
|
+
return value;
|
|
30
|
+
case "number":
|
|
31
|
+
return value;
|
|
32
|
+
case "boolean":
|
|
33
|
+
return value;
|
|
34
|
+
case "date":
|
|
35
|
+
return new Date(value);
|
|
36
|
+
case "array":
|
|
37
|
+
return value.map((item) => deserialize(item));
|
|
38
|
+
case "object":
|
|
39
|
+
return Object.entries(value).reduce(
|
|
40
|
+
(acc, [key, value2]) => {
|
|
41
|
+
return {
|
|
42
|
+
...acc,
|
|
43
|
+
[key]: deserialize(value2)
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
{}
|
|
47
|
+
);
|
|
48
|
+
default:
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return void 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/crud/crud_form_provider.tsx
|
|
56
|
+
import { jsx } from "react/jsx-runtime";
|
|
57
|
+
var FormContext = createContext({});
|
|
58
|
+
|
|
59
|
+
// src/form/create_form_component.tsx
|
|
60
|
+
import "react";
|
|
61
|
+
|
|
62
|
+
// src/utils/cn.ts
|
|
63
|
+
function cn(...classes) {
|
|
64
|
+
return classes.filter(Boolean).join(" ").trim();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/utils/date.ts
|
|
68
|
+
import moment from "moment-timezone";
|
|
69
|
+
|
|
70
|
+
// src/form/create_form_component.tsx
|
|
71
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
72
|
+
function createComponent(tag, options) {
|
|
73
|
+
return function FormComponent({ className, ...props }) {
|
|
74
|
+
const Tag = tag;
|
|
75
|
+
return /* @__PURE__ */ jsx2(Tag, { ...props, className: cn(options.className, className) });
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/form/form_components.tsx
|
|
80
|
+
var FormEntry = createComponent("div", {
|
|
81
|
+
className: "flex-1"
|
|
82
|
+
});
|
|
83
|
+
var FormRow = createComponent("div", {
|
|
84
|
+
className: "flex-1 flex gap-4 mb-6"
|
|
85
|
+
});
|
|
86
|
+
var FormLabel = createComponent("label", {
|
|
87
|
+
className: "flex-1 font-semibold mb-2.5 block"
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// src/crud/crud_form.tsx
|
|
91
|
+
import { useStoreComponent } from "react-store-input";
|
|
92
|
+
|
|
93
|
+
// src/client/env_loader.tsx
|
|
94
|
+
import { useRouteLoaderData } from "react-router";
|
|
95
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
96
|
+
|
|
97
|
+
// src/client/file_input.tsx
|
|
98
|
+
import {
|
|
99
|
+
useRef
|
|
100
|
+
} from "react";
|
|
101
|
+
import { Fragment, jsx as jsx4, jsxs } from "react/jsx-runtime";
|
|
102
|
+
|
|
103
|
+
// src/client/use_user_agent.tsx
|
|
104
|
+
import { useRouteLoaderData as useRouteLoaderData2 } from "react-router";
|
|
105
|
+
|
|
106
|
+
// src/client/store_text_editor.tsx
|
|
107
|
+
import {
|
|
108
|
+
TextEditor
|
|
109
|
+
} from "dn-react-text-editor";
|
|
110
|
+
import { useStoreController } from "react-store-input";
|
|
111
|
+
import { useImperativeHandle, useRef as useRef2 } from "react";
|
|
112
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
113
|
+
|
|
114
|
+
// src/client/editor.tsx
|
|
115
|
+
import { generateMetadata } from "gw-file/client";
|
|
116
|
+
|
|
117
|
+
// src/crud/crud_form.tsx
|
|
118
|
+
import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
119
|
+
|
|
120
|
+
// src/api/put_resource_handler.ts
|
|
121
|
+
import {
|
|
122
|
+
and
|
|
123
|
+
} from "drizzle-orm";
|
|
124
|
+
import { v4 } from "uuid";
|
|
125
|
+
function putResourceHandler({
|
|
126
|
+
repository,
|
|
127
|
+
validators,
|
|
128
|
+
existingConditions,
|
|
129
|
+
injectUserId,
|
|
130
|
+
isOwnedBy
|
|
131
|
+
}) {
|
|
132
|
+
return async (auth, request) => {
|
|
133
|
+
const serilaizedParams = await request.json();
|
|
134
|
+
const params = deserialize(serilaizedParams);
|
|
135
|
+
const itemId = params.id || v4();
|
|
136
|
+
if (params.id) {
|
|
137
|
+
const existing = await repository.find(itemId);
|
|
138
|
+
if (!existing) {
|
|
139
|
+
return httpNotFound();
|
|
140
|
+
}
|
|
141
|
+
if (isOwnedBy && (!auth || !isOwnedBy(auth, existing))) {
|
|
142
|
+
return httpForbidden();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (validators) {
|
|
146
|
+
const paramsForValidation = Object.keys(validators).filter(
|
|
147
|
+
(key) => Object.prototype.hasOwnProperty.call(validators, key)
|
|
148
|
+
);
|
|
149
|
+
for (const paramKey of paramsForValidation) {
|
|
150
|
+
const value = params[paramKey];
|
|
151
|
+
const validator = validators[paramKey];
|
|
152
|
+
if (validator?.validate && !validator.validate(value)) {
|
|
153
|
+
return httpBadRequest({
|
|
154
|
+
code: "BAD_REQUEST",
|
|
155
|
+
message: validator.message ? validator.message(value) : "\uC798\uBABB\uB41C \uC694\uCCAD\uC785\uB2C8\uB2E4."
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (!params.id && existingConditions) {
|
|
161
|
+
const paramsForExistenceCheck = Object.keys(existingConditions).filter(
|
|
162
|
+
(key) => Object.prototype.hasOwnProperty.call(params, key)
|
|
163
|
+
);
|
|
164
|
+
if (paramsForExistenceCheck.length > 0) {
|
|
165
|
+
const where = and(
|
|
166
|
+
...paramsForExistenceCheck.reduce((acc, key) => {
|
|
167
|
+
const condition = existingConditions[key];
|
|
168
|
+
if (condition) {
|
|
169
|
+
acc.push(condition(params[key]));
|
|
170
|
+
}
|
|
171
|
+
return acc;
|
|
172
|
+
}, [])
|
|
173
|
+
);
|
|
174
|
+
const existing = await repository.findAll({
|
|
175
|
+
limit: 1,
|
|
176
|
+
where
|
|
177
|
+
});
|
|
178
|
+
if (existing.length > 0) {
|
|
179
|
+
return httpConflict();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const values = {
|
|
184
|
+
id: itemId,
|
|
185
|
+
userId: injectUserId ? auth?.userId : void 0,
|
|
186
|
+
...params
|
|
187
|
+
};
|
|
188
|
+
const item = await repository.save(values);
|
|
189
|
+
return httpCreated(item);
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
export {
|
|
193
|
+
putResourceHandler
|
|
194
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as gw_result from 'gw-result';
|
|
2
|
+
import { ActionFunctionArgs, LoaderFunctionArgs } from 'react-router';
|
|
3
|
+
import { TableRepository } from '../table/repository.mjs';
|
|
4
|
+
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
5
|
+
import { WithAuthHandler } from '../auth/with_auth.mjs';
|
|
6
|
+
import { PutResourceValidators, PutResourceExistingConditions } from './put_resource_handler.mjs';
|
|
7
|
+
import { AccessTokenPayload } from 'gw-auth';
|
|
8
|
+
import 'drizzle-orm';
|
|
9
|
+
import 'drizzle-orm/node-postgres';
|
|
10
|
+
import 'gw-auth/server';
|
|
11
|
+
|
|
12
|
+
type APIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
13
|
+
withAuthAction: WithAuthHandler<ActionFunctionArgs>;
|
|
14
|
+
repository: TableRepository<T, TSelect>;
|
|
15
|
+
validators?: PutResourceValidators<T>;
|
|
16
|
+
existingConditions?: PutResourceExistingConditions<T>;
|
|
17
|
+
injectUserId?: boolean;
|
|
18
|
+
roles?: string[];
|
|
19
|
+
isOwnedBy?: (auth: AccessTokenPayload, item: TSelect) => boolean;
|
|
20
|
+
};
|
|
21
|
+
declare function resourceHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, validators, existingConditions, injectUserId, roles, isOwnedBy, }: APIHandlerOptions<T, TSelect>): {
|
|
22
|
+
loader: ({ request }: LoaderFunctionArgs) => Promise<gw_result.Ok<{}>>;
|
|
23
|
+
action: (arg: ActionFunctionArgs<any>) => Promise<unknown> | unknown;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { type APIHandlerOptions, resourceHandler };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as gw_result from 'gw-result';
|
|
2
|
+
import { ActionFunctionArgs, LoaderFunctionArgs } from 'react-router';
|
|
3
|
+
import { TableRepository } from '../table/repository.js';
|
|
4
|
+
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
5
|
+
import { WithAuthHandler } from '../auth/with_auth.js';
|
|
6
|
+
import { PutResourceValidators, PutResourceExistingConditions } from './put_resource_handler.js';
|
|
7
|
+
import { AccessTokenPayload } from 'gw-auth';
|
|
8
|
+
import 'drizzle-orm';
|
|
9
|
+
import 'drizzle-orm/node-postgres';
|
|
10
|
+
import 'gw-auth/server';
|
|
11
|
+
|
|
12
|
+
type APIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
13
|
+
withAuthAction: WithAuthHandler<ActionFunctionArgs>;
|
|
14
|
+
repository: TableRepository<T, TSelect>;
|
|
15
|
+
validators?: PutResourceValidators<T>;
|
|
16
|
+
existingConditions?: PutResourceExistingConditions<T>;
|
|
17
|
+
injectUserId?: boolean;
|
|
18
|
+
roles?: string[];
|
|
19
|
+
isOwnedBy?: (auth: AccessTokenPayload, item: TSelect) => boolean;
|
|
20
|
+
};
|
|
21
|
+
declare function resourceHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, validators, existingConditions, injectUserId, roles, isOwnedBy, }: APIHandlerOptions<T, TSelect>): {
|
|
22
|
+
loader: ({ request }: LoaderFunctionArgs) => Promise<gw_result.Ok<{}>>;
|
|
23
|
+
action: (arg: ActionFunctionArgs<any>) => Promise<unknown> | unknown;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { type APIHandlerOptions, resourceHandler };
|