dn-react-router-toolkit 0.8.1 → 0.9.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.
Files changed (53) hide show
  1. package/dist/crud/index.d.mts +0 -20
  2. package/dist/crud/index.d.ts +0 -20
  3. package/dist/crud/index.js +12 -8587
  4. package/dist/crud/index.mjs +0 -8596
  5. package/dist/post/index.js +67 -7705
  6. package/dist/post/index.mjs +54 -7718
  7. package/dist/post/post_form_page.js +67 -7705
  8. package/dist/post/post_form_page.mjs +54 -7718
  9. package/dist/table/index.d.mts +0 -2
  10. package/dist/table/index.d.ts +0 -2
  11. package/dist/table/index.js +12 -79
  12. package/dist/table/index.mjs +12 -77
  13. package/dist/table/load_table.d.mts +1 -1
  14. package/dist/table/load_table.d.ts +1 -1
  15. package/dist/table/load_table.js +2 -2
  16. package/dist/table/load_table.mjs +2 -2
  17. package/dist/table/loader.js +2 -2
  18. package/dist/table/loader.mjs +2 -2
  19. package/dist/table/table.d.mts +2 -2
  20. package/dist/table/table.d.ts +2 -2
  21. package/dist/table/table.js +6 -23
  22. package/dist/table/table.mjs +6 -23
  23. package/dist/table/table_form.js +6 -23
  24. package/dist/table/table_form.mjs +6 -23
  25. package/package.json +2 -2
  26. package/dist/crud/crud_loader.d.mts +0 -26
  27. package/dist/crud/crud_loader.d.ts +0 -26
  28. package/dist/crud/crud_loader.js +0 -351
  29. package/dist/crud/crud_loader.mjs +0 -337
  30. package/dist/crud/crud_page.d.mts +0 -32
  31. package/dist/crud/crud_page.d.ts +0 -32
  32. package/dist/crud/crud_page.js +0 -776
  33. package/dist/crud/crud_page.mjs +0 -758
  34. package/dist/crud/generate_handlers.d.mts +0 -16
  35. package/dist/crud/generate_handlers.d.ts +0 -16
  36. package/dist/crud/generate_handlers.js +0 -39
  37. package/dist/crud/generate_handlers.mjs +0 -14
  38. package/dist/crud/generate_pages.d.mts +0 -19
  39. package/dist/crud/generate_pages.d.ts +0 -19
  40. package/dist/crud/generate_pages.js +0 -55
  41. package/dist/crud/generate_pages.mjs +0 -30
  42. package/dist/crud/generate_routes.d.mts +0 -5
  43. package/dist/crud/generate_routes.d.ts +0 -5
  44. package/dist/crud/generate_routes.js +0 -7639
  45. package/dist/crud/generate_routes.mjs +0 -7627
  46. package/dist/table/item_loader.d.mts +0 -14
  47. package/dist/table/item_loader.d.ts +0 -14
  48. package/dist/table/item_loader.js +0 -43
  49. package/dist/table/item_loader.mjs +0 -18
  50. package/dist/table/page.d.mts +0 -16
  51. package/dist/table/page.d.ts +0 -16
  52. package/dist/table/page.js +0 -375
  53. package/dist/table/page.mjs +0 -350
@@ -49,10 +49,7 @@ function Table({
49
49
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
50
50
  "table",
51
51
  {
52
- className: (0, import_utils.cn)(
53
- className,
54
- "text-[15px] border-separate border-spacing-0"
55
- ),
52
+ className: (0, import_utils.cn)(className, "text-[15px] border-separate border-spacing-0"),
56
53
  children: [
57
54
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: keys.map((key) => {
58
55
  const value = columns[key];
@@ -91,13 +88,11 @@ function Table({
91
88
  }
92
89
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: reactNode });
93
90
  }
94
- const filter = filters[key];
91
+ const filter = filters?.[key];
95
92
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
96
93
  "th",
97
94
  {
98
- className: (0, import_utils.cn)(
99
- "py-4 border-y font-normal align-top"
100
- ),
95
+ className: (0, import_utils.cn)("py-4 border-y font-normal align-top"),
101
96
  children: [
102
97
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Head, {}),
103
98
  filter && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "px-3 mt-4", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
@@ -108,12 +103,7 @@ function Table({
108
103
  const value2 = e.target.value;
109
104
  setSearchParams((prev) => {
110
105
  if (value2) {
111
- prev.set(
112
- key,
113
- encodeURIComponent(
114
- value2
115
- )
116
- );
106
+ prev.set(key, encodeURIComponent(value2));
117
107
  } else {
118
108
  prev.delete(key);
119
109
  }
@@ -122,14 +112,7 @@ function Table({
122
112
  },
123
113
  children: [
124
114
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: "\uC804\uCCB4" }),
125
- filter.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
126
- "option",
127
- {
128
- value: option,
129
- children: option
130
- },
131
- option
132
- ))
115
+ filter.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: option, children: option }, option))
133
116
  ]
134
117
  }
135
118
  ) })
@@ -168,7 +151,7 @@ function Table({
168
151
  className: "block content-center px-4 w-full h-full",
169
152
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Content, {})
170
153
  }
171
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Content, {});
154
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "px-4 w-full h-full content-center", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Content, {}) });
172
155
  const cell = Mapper ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Mapper, { item, index: i2, children: linkedContent }) : linkedContent;
173
156
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { className: "px-0 h-14 border-b", children: cell }, key);
174
157
  }) }, i))
@@ -25,10 +25,7 @@ function Table({
25
25
  return /* @__PURE__ */ jsxs(
26
26
  "table",
27
27
  {
28
- className: cn(
29
- className,
30
- "text-[15px] border-separate border-spacing-0"
31
- ),
28
+ className: cn(className, "text-[15px] border-separate border-spacing-0"),
32
29
  children: [
33
30
  /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: keys.map((key) => {
34
31
  const value = columns[key];
@@ -67,13 +64,11 @@ function Table({
67
64
  }
68
65
  return /* @__PURE__ */ jsx(Fragment, { children: reactNode });
69
66
  }
70
- const filter = filters[key];
67
+ const filter = filters?.[key];
71
68
  return /* @__PURE__ */ jsxs(
72
69
  "th",
73
70
  {
74
- className: cn(
75
- "py-4 border-y font-normal align-top"
76
- ),
71
+ className: cn("py-4 border-y font-normal align-top"),
77
72
  children: [
78
73
  /* @__PURE__ */ jsx(Head, {}),
79
74
  filter && /* @__PURE__ */ jsx("div", { className: "px-3 mt-4", children: /* @__PURE__ */ jsxs(
@@ -84,12 +79,7 @@ function Table({
84
79
  const value2 = e.target.value;
85
80
  setSearchParams((prev) => {
86
81
  if (value2) {
87
- prev.set(
88
- key,
89
- encodeURIComponent(
90
- value2
91
- )
92
- );
82
+ prev.set(key, encodeURIComponent(value2));
93
83
  } else {
94
84
  prev.delete(key);
95
85
  }
@@ -98,14 +88,7 @@ function Table({
98
88
  },
99
89
  children: [
100
90
  /* @__PURE__ */ jsx("option", { value: "", children: "\uC804\uCCB4" }),
101
- filter.map((option) => /* @__PURE__ */ jsx(
102
- "option",
103
- {
104
- value: option,
105
- children: option
106
- },
107
- option
108
- ))
91
+ filter.map((option) => /* @__PURE__ */ jsx("option", { value: option, children: option }, option))
109
92
  ]
110
93
  }
111
94
  ) })
@@ -144,7 +127,7 @@ function Table({
144
127
  className: "block content-center px-4 w-full h-full",
145
128
  children: /* @__PURE__ */ jsx(Content, {})
146
129
  }
147
- ) : /* @__PURE__ */ jsx(Content, {});
130
+ ) : /* @__PURE__ */ jsx("div", { className: "px-4 w-full h-full content-center", children: /* @__PURE__ */ jsx(Content, {}) });
148
131
  const cell = Mapper ? /* @__PURE__ */ jsx(Mapper, { item, index: i2, children: linkedContent }) : linkedContent;
149
132
  return /* @__PURE__ */ jsx("td", { className: "px-0 h-14 border-b", children: cell }, key);
150
133
  }) }, i))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dn-react-router-toolkit",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "types": "./dist/index.d.ts",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.js",
@@ -100,4 +100,4 @@
100
100
  "react-dom": "^19",
101
101
  "react-router": "^7.13.1"
102
102
  }
103
- }
103
+ }
@@ -1,26 +0,0 @@
1
- import { LoaderFunctionArgs, LoaderFunction } from 'react-router';
2
- import { TableItemLoaderOptions } from '../table/item_loader.mjs';
3
- import { TableRepository } from '../table/repository.mjs';
4
- import { TableLoaderOptions } from '../table/load_table.mjs';
5
- import { PgTableWithColumns } from 'drizzle-orm/pg-core';
6
- import { APIHandlerOptions } from '../api/create_api_handler.mjs';
7
- import 'drizzle-orm';
8
- import 'drizzle-orm/node-postgres';
9
- import '../auth/with_auth.mjs';
10
- import 'dn-react-toolkit/auth';
11
- import 'dn-react-toolkit/auth/server';
12
-
13
- type CrudHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
14
- repository: TableRepository<T, TSelect>;
15
- apiHandlerOptions: Omit<APIHandlerOptions<T, TSelect>, "repository">;
16
- loaderOptions: Omit<TableLoaderOptions<T, TSelect>, "repository"> & {
17
- loader?: LoaderFunction;
18
- };
19
- itemLoaderOptions: Omit<TableItemLoaderOptions<T, TSelect>, "repository"> & {
20
- loader?: LoaderFunction;
21
- };
22
- };
23
- type CrudHandler = (prefix: string) => (args: LoaderFunctionArgs) => Promise<any>;
24
- declare function crudHandler<T extends PgTableWithColumns<any>, TSelect>({ repository, apiHandlerOptions, loaderOptions, itemLoaderOptions, }: CrudHandlerOptions<T, TSelect>): (prefix: string) => (args: LoaderFunctionArgs) => Promise<unknown>;
25
-
26
- export { type CrudHandler, type CrudHandlerOptions, crudHandler };
@@ -1,26 +0,0 @@
1
- import { LoaderFunctionArgs, LoaderFunction } from 'react-router';
2
- import { TableItemLoaderOptions } from '../table/item_loader.js';
3
- import { TableRepository } from '../table/repository.js';
4
- import { TableLoaderOptions } from '../table/load_table.js';
5
- import { PgTableWithColumns } from 'drizzle-orm/pg-core';
6
- import { APIHandlerOptions } from '../api/create_api_handler.js';
7
- import 'drizzle-orm';
8
- import 'drizzle-orm/node-postgres';
9
- import '../auth/with_auth.js';
10
- import 'dn-react-toolkit/auth';
11
- import 'dn-react-toolkit/auth/server';
12
-
13
- type CrudHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
14
- repository: TableRepository<T, TSelect>;
15
- apiHandlerOptions: Omit<APIHandlerOptions<T, TSelect>, "repository">;
16
- loaderOptions: Omit<TableLoaderOptions<T, TSelect>, "repository"> & {
17
- loader?: LoaderFunction;
18
- };
19
- itemLoaderOptions: Omit<TableItemLoaderOptions<T, TSelect>, "repository"> & {
20
- loader?: LoaderFunction;
21
- };
22
- };
23
- type CrudHandler = (prefix: string) => (args: LoaderFunctionArgs) => Promise<any>;
24
- declare function crudHandler<T extends PgTableWithColumns<any>, TSelect>({ repository, apiHandlerOptions, loaderOptions, itemLoaderOptions, }: CrudHandlerOptions<T, TSelect>): (prefix: string) => (args: LoaderFunctionArgs) => Promise<unknown>;
25
-
26
- export { type CrudHandler, type CrudHandlerOptions, crudHandler };
@@ -1,351 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/crud/crud_loader.tsx
21
- var crud_loader_exports = {};
22
- __export(crud_loader_exports, {
23
- crudHandler: () => crudHandler
24
- });
25
- module.exports = __toCommonJS(crud_loader_exports);
26
-
27
- // src/table/load_table.tsx
28
- var import_drizzle_orm = require("drizzle-orm");
29
- async function loadTable({
30
- request,
31
- repository,
32
- options
33
- }) {
34
- const searchParams = new URL(request.url).searchParams;
35
- const { where, searchKey, defaultOrderBy, defaultDirection } = options;
36
- const query = searchParams.get("query") ?? void 0;
37
- const limit = Number(searchParams.get("limit") ?? "20");
38
- const offset = Number(searchParams.get("offset") ?? "0");
39
- const orderBy = searchParams.get("orderBy") ?? defaultOrderBy;
40
- const direction = searchParams.get("direction") ?? defaultDirection;
41
- const filterWhere = Object.entries(options.filters ?? {}).map(([key, value]) => {
42
- const param = searchParams.get(key);
43
- if (param) {
44
- return (0, import_drizzle_orm.eq)(
45
- repository.schema[key],
46
- decodeURIComponent(param)
47
- );
48
- }
49
- return void 0;
50
- }).filter(Boolean);
51
- const whereClauses = (0, import_drizzle_orm.and)(
52
- searchKey && query ? (0, import_drizzle_orm.ilike)(
53
- repository.schema[searchKey],
54
- `%${query}%`
55
- ) : void 0,
56
- ...filterWhere,
57
- ...where ?? []
58
- );
59
- const total = await repository.countTotal({ where: whereClauses });
60
- const items = await repository.findAll({
61
- orderBy,
62
- direction,
63
- limit,
64
- offset,
65
- where: whereClauses
66
- });
67
- const filters = Object.fromEntries(
68
- await Promise.all(
69
- Object.keys(options.filters ?? {}).map(async (key) => {
70
- const values = await repository.select(key);
71
- return [key, values.filter(Boolean)];
72
- })
73
- )
74
- );
75
- return {
76
- items,
77
- total,
78
- limit,
79
- offset,
80
- orderBy,
81
- direction,
82
- searchKey,
83
- filters
84
- };
85
- }
86
-
87
- // src/table/loader.tsx
88
- function tableLoader({
89
- repository,
90
- options
91
- }) {
92
- return async ({ request }) => {
93
- const table = await loadTable({
94
- request,
95
- repository,
96
- options
97
- });
98
- return {
99
- table
100
- };
101
- };
102
- }
103
-
104
- // src/table/item_loader.tsx
105
- var tableItemloader = ({
106
- repository
107
- }) => {
108
- return async (args) => {
109
- const { params } = args;
110
- if (params["itemId"] === "new") {
111
- return { item: void 0 };
112
- }
113
- const item = params["itemId"] ? await repository.find(params["itemId"]) : void 0;
114
- return {
115
- item
116
- };
117
- };
118
- };
119
-
120
- // src/api/create_api_handler.ts
121
- var import_http = require("dn-react-toolkit/http");
122
- var import_drizzle_orm2 = require("drizzle-orm");
123
- var import_uuid = require("uuid");
124
-
125
- // src/crud/serialize.ts
126
- function deserialize(data) {
127
- if (data === void 0) {
128
- return void 0;
129
- }
130
- if (typeof data === "object" && data !== null && "type" in data && "value" in data) {
131
- const { type, value } = data;
132
- switch (type) {
133
- case "null":
134
- return null;
135
- case "string":
136
- return value;
137
- case "number":
138
- return value;
139
- case "boolean":
140
- return value;
141
- case "date":
142
- return new Date(value);
143
- case "array":
144
- return value.map((item) => deserialize(item));
145
- case "object":
146
- return Object.entries(value).reduce(
147
- (acc, [key, value2]) => {
148
- return {
149
- ...acc,
150
- [key]: deserialize(value2)
151
- };
152
- },
153
- {}
154
- );
155
- default:
156
- return void 0;
157
- }
158
- }
159
- return void 0;
160
- }
161
-
162
- // src/api/create_api_handler.ts
163
- function apiHandler({
164
- withAuthAction,
165
- repository,
166
- validators,
167
- existingConditions,
168
- injectUserId,
169
- roles
170
- }) {
171
- const loader = async ({ request }) => {
172
- return {};
173
- };
174
- const action = withAuthAction((auth) => async ({ request }) => {
175
- if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
176
- throw (0, import_http.UNAUTHORIZED)();
177
- }
178
- switch (request.method) {
179
- case "POST":
180
- case "PUT": {
181
- try {
182
- const serilaizedParams = await request.json();
183
- const params = deserialize(serilaizedParams);
184
- if (validators) {
185
- const paramsForValidation = Object.keys(validators).filter(
186
- (key) => Object.prototype.hasOwnProperty.call(validators, key)
187
- );
188
- for (const paramKey of paramsForValidation) {
189
- const value = params[paramKey];
190
- const validator = validators[paramKey];
191
- if (validator?.validate && !validator.validate(value)) {
192
- throw (0, import_http.BAD_REQUEST)(
193
- validator.message ? validator.message(value) : void 0
194
- );
195
- }
196
- }
197
- }
198
- const itemId = params.id || (0, import_uuid.v4)();
199
- if (!params.id && existingConditions) {
200
- const paramsForExistenceCheck = Object.keys(
201
- existingConditions
202
- ).filter(
203
- (key) => Object.prototype.hasOwnProperty.call(params, key)
204
- );
205
- if (paramsForExistenceCheck.length > 0) {
206
- const where = (0, import_drizzle_orm2.and)(
207
- ...paramsForExistenceCheck.reduce((acc, key) => {
208
- const condition = existingConditions[key];
209
- if (condition) {
210
- acc.push(condition(params[key]));
211
- }
212
- return acc;
213
- }, [])
214
- );
215
- const existing = await repository.findAll({
216
- limit: 1,
217
- where
218
- });
219
- if (existing.length > 0) {
220
- throw (0, import_http.CONFLICT)("\uC790\uB8CC\uAC00 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4.");
221
- }
222
- }
223
- }
224
- const values = {
225
- id: itemId,
226
- userId: injectUserId ? auth?.userId : void 0,
227
- ...params
228
- };
229
- const item = await repository.save(values);
230
- return (0, import_http.CREATED)(item);
231
- } catch (error) {
232
- if (error instanceof Error) {
233
- throw (0, import_http.INTERNAL_SERVER_ERROR)(error.message);
234
- }
235
- throw error;
236
- }
237
- }
238
- default:
239
- throw (0, import_http.METHOD_NOT_ALLOWED)();
240
- }
241
- });
242
- return {
243
- loader,
244
- action
245
- };
246
- }
247
-
248
- // src/api/item_api_handler.ts
249
- var import_http2 = require("dn-react-toolkit/http");
250
- function itemApiHandler({
251
- withAuthAction,
252
- repository,
253
- isOwnedBy,
254
- roles
255
- }) {
256
- const loader = async ({ request }) => {
257
- return {};
258
- };
259
- const action = withAuthAction((auth) => async ({ params, request }) => {
260
- if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
261
- throw (0, import_http2.UNAUTHORIZED)();
262
- }
263
- const itemId = params.itemId;
264
- const existing = await repository.find(itemId);
265
- if (!existing) {
266
- throw (0, import_http2.NOT_FOUND)();
267
- }
268
- if (isOwnedBy && !isOwnedBy(existing, auth)) {
269
- throw (0, import_http2.FORBIDDEN)();
270
- }
271
- switch (request.method) {
272
- case "DELETE": {
273
- await repository.delete(itemId);
274
- return {};
275
- }
276
- }
277
- });
278
- return {
279
- loader,
280
- action
281
- };
282
- }
283
-
284
- // src/crud/crud_loader.tsx
285
- function crudHandler({
286
- repository,
287
- apiHandlerOptions,
288
- loaderOptions,
289
- itemLoaderOptions
290
- }) {
291
- return (prefix) => async (args) => {
292
- const pattern = args.unstable_pattern;
293
- if (pattern === `/api${prefix}`) {
294
- const { loader, action } = apiHandler({
295
- repository,
296
- ...apiHandlerOptions
297
- });
298
- if (args.request.method === "GET") {
299
- return loader(args);
300
- } else {
301
- return action(args);
302
- }
303
- }
304
- if (pattern.startsWith(`/api${prefix}`)) {
305
- const { loader, action } = itemApiHandler({
306
- repository,
307
- ...apiHandlerOptions
308
- });
309
- if (args.request.method === "GET") {
310
- return loader(args);
311
- } else {
312
- return action(args);
313
- }
314
- }
315
- if (pattern === prefix) {
316
- const body = await tableLoader({
317
- ...loaderOptions,
318
- repository
319
- })(args);
320
- if (loaderOptions.loader) {
321
- const result = await loaderOptions.loader(args);
322
- if (typeof result === "object") {
323
- return {
324
- ...result,
325
- ...body
326
- };
327
- }
328
- }
329
- return body;
330
- }
331
- if (pattern.startsWith(prefix)) {
332
- const body = await tableItemloader({ ...itemLoaderOptions, repository })(
333
- args
334
- );
335
- if (itemLoaderOptions.loader) {
336
- const result = await itemLoaderOptions.loader(args);
337
- if (typeof result === "object") {
338
- return {
339
- ...result,
340
- ...body
341
- };
342
- }
343
- }
344
- return body;
345
- }
346
- };
347
- }
348
- // Annotate the CommonJS export names for ESM import in node:
349
- 0 && (module.exports = {
350
- crudHandler
351
- });