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.
Files changed (103) hide show
  1. package/dist/api/default_api_handler.d.mts +13 -0
  2. package/dist/api/default_api_handler.d.ts +13 -0
  3. package/dist/api/{create_handler.js → default_api_handler.js} +49 -52
  4. package/dist/api/{create_handler.mjs → default_api_handler.mjs} +45 -48
  5. package/dist/api/index.d.mts +8 -7
  6. package/dist/api/index.d.ts +8 -7
  7. package/dist/api/index.js +233 -147
  8. package/dist/api/index.mjs +238 -151
  9. package/dist/api/put_resource_handler.d.mts +25 -0
  10. package/dist/api/put_resource_handler.d.ts +25 -0
  11. package/dist/api/put_resource_handler.js +214 -0
  12. package/dist/api/put_resource_handler.mjs +194 -0
  13. package/dist/api/resource_handler.d.mts +26 -0
  14. package/dist/api/resource_handler.d.ts +26 -0
  15. package/dist/api/resource_handler.js +280 -0
  16. package/dist/api/resource_handler.mjs +265 -0
  17. package/dist/auth/cookie_manager.d.mts +1 -1
  18. package/dist/auth/cookie_manager.d.ts +1 -1
  19. package/dist/auth/index.d.mts +2 -2
  20. package/dist/auth/index.d.ts +2 -2
  21. package/dist/auth/index.js +18 -18
  22. package/dist/auth/index.mjs +18 -18
  23. package/dist/auth/with_auth.d.mts +2 -2
  24. package/dist/auth/with_auth.d.ts +2 -2
  25. package/dist/auth/with_auth.js +18 -18
  26. package/dist/auth/with_auth.mjs +18 -18
  27. package/dist/client/editor.d.mts +2 -2
  28. package/dist/client/editor.d.ts +2 -2
  29. package/dist/client/editor.js +9 -3
  30. package/dist/client/editor.mjs +9 -3
  31. package/dist/client/index.d.mts +2 -2
  32. package/dist/client/index.d.ts +2 -2
  33. package/dist/client/index.js +9 -3
  34. package/dist/client/index.mjs +9 -3
  35. package/dist/crud/crud_form.js +22 -4
  36. package/dist/crud/crud_form.mjs +11 -3
  37. package/dist/crud/crud_form_provider.js +16 -3
  38. package/dist/crud/crud_form_provider.mjs +14 -1
  39. package/dist/crud/index.js +22 -4
  40. package/dist/crud/index.mjs +11 -3
  41. package/dist/db/backup/index.d.mts +1 -1
  42. package/dist/db/backup/index.d.ts +1 -1
  43. package/dist/form/create_form_component.js +21 -2
  44. package/dist/form/create_form_component.mjs +10 -1
  45. package/dist/form/form_components.js +21 -2
  46. package/dist/form/form_components.mjs +10 -1
  47. package/dist/form/index.js +21 -2
  48. package/dist/form/index.mjs +10 -1
  49. package/dist/post/editor_toolbar.js +20 -3
  50. package/dist/post/editor_toolbar.mjs +9 -2
  51. package/dist/post/index.js +31 -11
  52. package/dist/post/index.mjs +19 -9
  53. package/dist/post/post_form_page.js +29 -11
  54. package/dist/post/post_form_page.mjs +17 -9
  55. package/dist/post/thumbnail_picker.js +21 -2
  56. package/dist/post/thumbnail_picker.mjs +10 -1
  57. package/dist/table/buttons.js +11 -14
  58. package/dist/table/buttons.mjs +10 -13
  59. package/dist/table/index.js +14 -18
  60. package/dist/table/index.mjs +13 -17
  61. package/dist/table/table.js +10 -4
  62. package/dist/table/table.mjs +5 -1
  63. package/dist/table/table_form.js +12 -18
  64. package/dist/table/table_form.mjs +9 -15
  65. package/dist/utils/cn.d.mts +3 -0
  66. package/dist/utils/cn.d.ts +3 -0
  67. package/dist/utils/cn.js +32 -0
  68. package/dist/utils/cn.mjs +7 -0
  69. package/dist/utils/date.d.mts +5 -0
  70. package/dist/utils/date.d.ts +5 -0
  71. package/dist/utils/date.js +65 -0
  72. package/dist/utils/date.mjs +29 -0
  73. package/dist/utils/index.d.mts +7 -0
  74. package/dist/utils/index.d.ts +7 -0
  75. package/dist/utils/index.js +116 -0
  76. package/dist/utils/index.mjs +73 -0
  77. package/dist/utils/korean.d.mts +6 -0
  78. package/dist/utils/korean.d.ts +6 -0
  79. package/dist/utils/korean.js +41 -0
  80. package/dist/utils/korean.mjs +16 -0
  81. package/dist/utils/singleton.d.mts +3 -0
  82. package/dist/utils/singleton.d.ts +3 -0
  83. package/dist/utils/singleton.js +37 -0
  84. package/dist/utils/singleton.mjs +12 -0
  85. package/dist/utils/sleep.d.mts +3 -0
  86. package/dist/utils/sleep.d.ts +3 -0
  87. package/dist/utils/sleep.js +32 -0
  88. package/dist/utils/sleep.mjs +7 -0
  89. package/dist/utils/slug.d.mts +3 -0
  90. package/dist/utils/slug.d.ts +3 -0
  91. package/dist/utils/slug.js +32 -0
  92. package/dist/utils/slug.mjs +7 -0
  93. package/package.json +8 -4
  94. package/dist/api/create_api_handler.d.mts +0 -30
  95. package/dist/api/create_api_handler.d.ts +0 -30
  96. package/dist/api/create_api_handler.js +0 -155
  97. package/dist/api/create_api_handler.mjs +0 -139
  98. package/dist/api/create_handler.d.mts +0 -13
  99. package/dist/api/create_handler.d.ts +0 -13
  100. package/dist/api/item_api_handler.d.mts +0 -21
  101. package/dist/api/item_api_handler.d.ts +0 -21
  102. package/dist/api/item_api_handler.js +0 -63
  103. package/dist/api/item_api_handler.mjs +0 -38
@@ -1,155 +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/api/create_api_handler.ts
21
- var create_api_handler_exports = {};
22
- __export(create_api_handler_exports, {
23
- apiHandler: () => apiHandler
24
- });
25
- module.exports = __toCommonJS(create_api_handler_exports);
26
- var import_http = require("dn-react-toolkit/http");
27
- var import_drizzle_orm = require("drizzle-orm");
28
- var import_uuid = require("uuid");
29
-
30
- // src/crud/serialize.ts
31
- function deserialize(data) {
32
- if (data === void 0) {
33
- return void 0;
34
- }
35
- if (typeof data === "object" && data !== null && "type" in data && "value" in data) {
36
- const { type, value } = data;
37
- switch (type) {
38
- case "null":
39
- return null;
40
- case "string":
41
- return value;
42
- case "number":
43
- return value;
44
- case "boolean":
45
- return value;
46
- case "date":
47
- return new Date(value);
48
- case "array":
49
- return value.map((item) => deserialize(item));
50
- case "object":
51
- return Object.entries(value).reduce(
52
- (acc, [key, value2]) => {
53
- return {
54
- ...acc,
55
- [key]: deserialize(value2)
56
- };
57
- },
58
- {}
59
- );
60
- default:
61
- return void 0;
62
- }
63
- }
64
- return void 0;
65
- }
66
-
67
- // src/api/create_api_handler.ts
68
- function apiHandler({
69
- withAuthAction,
70
- repository,
71
- validators,
72
- existingConditions,
73
- injectUserId,
74
- roles
75
- }) {
76
- const loader = async ({ request }) => {
77
- return {};
78
- };
79
- const action = withAuthAction((auth) => async ({ request }) => {
80
- if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
81
- throw (0, import_http.UNAUTHORIZED)();
82
- }
83
- switch (request.method) {
84
- case "POST":
85
- case "PUT": {
86
- try {
87
- const serilaizedParams = await request.json();
88
- const params = deserialize(serilaizedParams);
89
- if (validators) {
90
- const paramsForValidation = Object.keys(validators).filter(
91
- (key) => Object.prototype.hasOwnProperty.call(validators, key)
92
- );
93
- for (const paramKey of paramsForValidation) {
94
- const value = params[paramKey];
95
- const validator = validators[paramKey];
96
- if (validator?.validate && !validator.validate(value)) {
97
- throw (0, import_http.BAD_REQUEST)(
98
- validator.message ? validator.message(value) : void 0
99
- );
100
- }
101
- }
102
- }
103
- const itemId = params.id || (0, import_uuid.v4)();
104
- if (!params.id && existingConditions) {
105
- const paramsForExistenceCheck = Object.keys(
106
- existingConditions
107
- ).filter(
108
- (key) => Object.prototype.hasOwnProperty.call(params, key)
109
- );
110
- if (paramsForExistenceCheck.length > 0) {
111
- const where = (0, import_drizzle_orm.and)(
112
- ...paramsForExistenceCheck.reduce((acc, key) => {
113
- const condition = existingConditions[key];
114
- if (condition) {
115
- acc.push(condition(params[key]));
116
- }
117
- return acc;
118
- }, [])
119
- );
120
- const existing = await repository.findAll({
121
- limit: 1,
122
- where
123
- });
124
- if (existing.length > 0) {
125
- throw (0, import_http.CONFLICT)("\uC790\uB8CC\uAC00 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4.");
126
- }
127
- }
128
- }
129
- const values = {
130
- id: itemId,
131
- userId: injectUserId ? auth?.userId : void 0,
132
- ...params
133
- };
134
- const item = await repository.save(values);
135
- return (0, import_http.CREATED)(item);
136
- } catch (error) {
137
- if (error instanceof Error) {
138
- throw (0, import_http.INTERNAL_SERVER_ERROR)(error.message);
139
- }
140
- throw error;
141
- }
142
- }
143
- default:
144
- throw (0, import_http.METHOD_NOT_ALLOWED)();
145
- }
146
- });
147
- return {
148
- loader,
149
- action
150
- };
151
- }
152
- // Annotate the CommonJS export names for ESM import in node:
153
- 0 && (module.exports = {
154
- apiHandler
155
- });
@@ -1,139 +0,0 @@
1
- // src/api/create_api_handler.ts
2
- import {
3
- BAD_REQUEST,
4
- CONFLICT,
5
- CREATED,
6
- INTERNAL_SERVER_ERROR,
7
- METHOD_NOT_ALLOWED,
8
- UNAUTHORIZED
9
- } from "dn-react-toolkit/http";
10
- import {
11
- and
12
- } from "drizzle-orm";
13
- import { v4 } from "uuid";
14
-
15
- // src/crud/serialize.ts
16
- function deserialize(data) {
17
- if (data === void 0) {
18
- return void 0;
19
- }
20
- if (typeof data === "object" && data !== null && "type" in data && "value" in data) {
21
- const { type, value } = data;
22
- switch (type) {
23
- case "null":
24
- return null;
25
- case "string":
26
- return value;
27
- case "number":
28
- return value;
29
- case "boolean":
30
- return value;
31
- case "date":
32
- return new Date(value);
33
- case "array":
34
- return value.map((item) => deserialize(item));
35
- case "object":
36
- return Object.entries(value).reduce(
37
- (acc, [key, value2]) => {
38
- return {
39
- ...acc,
40
- [key]: deserialize(value2)
41
- };
42
- },
43
- {}
44
- );
45
- default:
46
- return void 0;
47
- }
48
- }
49
- return void 0;
50
- }
51
-
52
- // src/api/create_api_handler.ts
53
- function apiHandler({
54
- withAuthAction,
55
- repository,
56
- validators,
57
- existingConditions,
58
- injectUserId,
59
- roles
60
- }) {
61
- const loader = async ({ request }) => {
62
- return {};
63
- };
64
- const action = withAuthAction((auth) => async ({ request }) => {
65
- if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
66
- throw UNAUTHORIZED();
67
- }
68
- switch (request.method) {
69
- case "POST":
70
- case "PUT": {
71
- try {
72
- const serilaizedParams = await request.json();
73
- const params = deserialize(serilaizedParams);
74
- if (validators) {
75
- const paramsForValidation = Object.keys(validators).filter(
76
- (key) => Object.prototype.hasOwnProperty.call(validators, key)
77
- );
78
- for (const paramKey of paramsForValidation) {
79
- const value = params[paramKey];
80
- const validator = validators[paramKey];
81
- if (validator?.validate && !validator.validate(value)) {
82
- throw BAD_REQUEST(
83
- validator.message ? validator.message(value) : void 0
84
- );
85
- }
86
- }
87
- }
88
- const itemId = params.id || v4();
89
- if (!params.id && existingConditions) {
90
- const paramsForExistenceCheck = Object.keys(
91
- existingConditions
92
- ).filter(
93
- (key) => Object.prototype.hasOwnProperty.call(params, key)
94
- );
95
- if (paramsForExistenceCheck.length > 0) {
96
- const where = and(
97
- ...paramsForExistenceCheck.reduce((acc, key) => {
98
- const condition = existingConditions[key];
99
- if (condition) {
100
- acc.push(condition(params[key]));
101
- }
102
- return acc;
103
- }, [])
104
- );
105
- const existing = await repository.findAll({
106
- limit: 1,
107
- where
108
- });
109
- if (existing.length > 0) {
110
- throw CONFLICT("\uC790\uB8CC\uAC00 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4.");
111
- }
112
- }
113
- }
114
- const values = {
115
- id: itemId,
116
- userId: injectUserId ? auth?.userId : void 0,
117
- ...params
118
- };
119
- const item = await repository.save(values);
120
- return CREATED(item);
121
- } catch (error) {
122
- if (error instanceof Error) {
123
- throw INTERNAL_SERVER_ERROR(error.message);
124
- }
125
- throw error;
126
- }
127
- }
128
- default:
129
- throw METHOD_NOT_ALLOWED();
130
- }
131
- });
132
- return {
133
- loader,
134
- action
135
- };
136
- }
137
- export {
138
- apiHandler
139
- };
@@ -1,13 +0,0 @@
1
- import { LoaderFunctionArgs, ActionFunctionArgs } from 'react-router';
2
- import { AuthService, PasswordRecoveryService, ThirdpartyAuth, JWTManager, ThirdpartySignupTokenPayload } from 'dn-react-toolkit/auth/server';
3
- import { FileService } from 'dn-react-toolkit/file/server';
4
-
5
- declare const createAPIHandler: <TFile>({ authService, fileService, passwordRecoveryService, getThirdPartyAuth, signupTokenManager, }: {
6
- authService: AuthService<TFile>;
7
- fileService: FileService<TFile>;
8
- passwordRecoveryService: PasswordRecoveryService;
9
- getThirdPartyAuth: (provider: string) => ThirdpartyAuth;
10
- signupTokenManager: JWTManager<ThirdpartySignupTokenPayload>;
11
- }) => (args: LoaderFunctionArgs | ActionFunctionArgs) => Promise<Response | (({ request }: ActionFunctionArgs<any> | LoaderFunctionArgs<any>) => Promise<Response>)>;
12
-
13
- export { createAPIHandler };
@@ -1,13 +0,0 @@
1
- import { LoaderFunctionArgs, ActionFunctionArgs } from 'react-router';
2
- import { AuthService, PasswordRecoveryService, ThirdpartyAuth, JWTManager, ThirdpartySignupTokenPayload } from 'dn-react-toolkit/auth/server';
3
- import { FileService } from 'dn-react-toolkit/file/server';
4
-
5
- declare const createAPIHandler: <TFile>({ authService, fileService, passwordRecoveryService, getThirdPartyAuth, signupTokenManager, }: {
6
- authService: AuthService<TFile>;
7
- fileService: FileService<TFile>;
8
- passwordRecoveryService: PasswordRecoveryService;
9
- getThirdPartyAuth: (provider: string) => ThirdpartyAuth;
10
- signupTokenManager: JWTManager<ThirdpartySignupTokenPayload>;
11
- }) => (args: LoaderFunctionArgs | ActionFunctionArgs) => Promise<Response | (({ request }: ActionFunctionArgs<any> | LoaderFunctionArgs<any>) => Promise<Response>)>;
12
-
13
- export { createAPIHandler };
@@ -1,21 +0,0 @@
1
- import { LoaderFunctionArgs } from 'react-router';
2
- import { TableRepository } from '../table/repository.mjs';
3
- import { PgTableWithColumns } from 'drizzle-orm/pg-core';
4
- import { WithAuthHandler } from '../auth/with_auth.mjs';
5
- import { AccessTokenPayload } from 'dn-react-toolkit/auth';
6
- import 'drizzle-orm';
7
- import 'drizzle-orm/node-postgres';
8
- import 'dn-react-toolkit/auth/server';
9
-
10
- type ItemAPIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
11
- withAuthAction: WithAuthHandler<LoaderFunctionArgs>;
12
- repository: TableRepository<T, TSelect>;
13
- isOwnedBy?: (item: TSelect, auth: AccessTokenPayload | undefined) => boolean;
14
- roles?: string[];
15
- };
16
- declare function itemApiHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, isOwnedBy, roles, }: ItemAPIHandlerOptions<T, TSelect>): {
17
- loader: ({ request }: LoaderFunctionArgs) => Promise<{}>;
18
- action: (arg: LoaderFunctionArgs<any>) => Promise<unknown> | unknown;
19
- };
20
-
21
- export { type ItemAPIHandlerOptions, itemApiHandler };
@@ -1,21 +0,0 @@
1
- import { LoaderFunctionArgs } from 'react-router';
2
- import { TableRepository } from '../table/repository.js';
3
- import { PgTableWithColumns } from 'drizzle-orm/pg-core';
4
- import { WithAuthHandler } from '../auth/with_auth.js';
5
- import { AccessTokenPayload } from 'dn-react-toolkit/auth';
6
- import 'drizzle-orm';
7
- import 'drizzle-orm/node-postgres';
8
- import 'dn-react-toolkit/auth/server';
9
-
10
- type ItemAPIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
11
- withAuthAction: WithAuthHandler<LoaderFunctionArgs>;
12
- repository: TableRepository<T, TSelect>;
13
- isOwnedBy?: (item: TSelect, auth: AccessTokenPayload | undefined) => boolean;
14
- roles?: string[];
15
- };
16
- declare function itemApiHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, isOwnedBy, roles, }: ItemAPIHandlerOptions<T, TSelect>): {
17
- loader: ({ request }: LoaderFunctionArgs) => Promise<{}>;
18
- action: (arg: LoaderFunctionArgs<any>) => Promise<unknown> | unknown;
19
- };
20
-
21
- export { type ItemAPIHandlerOptions, itemApiHandler };
@@ -1,63 +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/api/item_api_handler.ts
21
- var item_api_handler_exports = {};
22
- __export(item_api_handler_exports, {
23
- itemApiHandler: () => itemApiHandler
24
- });
25
- module.exports = __toCommonJS(item_api_handler_exports);
26
- var import_http = require("dn-react-toolkit/http");
27
- function itemApiHandler({
28
- withAuthAction,
29
- repository,
30
- isOwnedBy,
31
- roles
32
- }) {
33
- const loader = async ({ request }) => {
34
- return {};
35
- };
36
- const action = withAuthAction((auth) => async ({ params, request }) => {
37
- if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
38
- throw (0, import_http.UNAUTHORIZED)();
39
- }
40
- const itemId = params.itemId;
41
- const existing = await repository.find(itemId);
42
- if (!existing) {
43
- throw (0, import_http.NOT_FOUND)();
44
- }
45
- if (isOwnedBy && !isOwnedBy(existing, auth)) {
46
- throw (0, import_http.FORBIDDEN)();
47
- }
48
- switch (request.method) {
49
- case "DELETE": {
50
- await repository.delete(itemId);
51
- return {};
52
- }
53
- }
54
- });
55
- return {
56
- loader,
57
- action
58
- };
59
- }
60
- // Annotate the CommonJS export names for ESM import in node:
61
- 0 && (module.exports = {
62
- itemApiHandler
63
- });
@@ -1,38 +0,0 @@
1
- // src/api/item_api_handler.ts
2
- import { FORBIDDEN, NOT_FOUND, UNAUTHORIZED } from "dn-react-toolkit/http";
3
- function itemApiHandler({
4
- withAuthAction,
5
- repository,
6
- isOwnedBy,
7
- roles
8
- }) {
9
- const loader = async ({ request }) => {
10
- return {};
11
- };
12
- const action = withAuthAction((auth) => async ({ params, request }) => {
13
- if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
14
- throw UNAUTHORIZED();
15
- }
16
- const itemId = params.itemId;
17
- const existing = await repository.find(itemId);
18
- if (!existing) {
19
- throw NOT_FOUND();
20
- }
21
- if (isOwnedBy && !isOwnedBy(existing, auth)) {
22
- throw FORBIDDEN();
23
- }
24
- switch (request.method) {
25
- case "DELETE": {
26
- await repository.delete(itemId);
27
- return {};
28
- }
29
- }
30
- });
31
- return {
32
- loader,
33
- action
34
- };
35
- }
36
- export {
37
- itemApiHandler
38
- };