dn-react-router-toolkit 0.9.4 → 0.9.6
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/index.js +34 -25
- package/dist/api/index.mjs +34 -25
- package/dist/api/patch_resource_handler.d.mts +4 -3
- package/dist/api/patch_resource_handler.d.ts +4 -3
- package/dist/api/patch_resource_handler.js +6 -3
- package/dist/api/patch_resource_handler.mjs +6 -3
- package/dist/api/put_resource_handler.d.mts +3 -3
- package/dist/api/put_resource_handler.d.ts +3 -3
- package/dist/api/resource_handler.d.mts +4 -3
- package/dist/api/resource_handler.d.ts +4 -3
- package/dist/api/resource_handler.js +34 -25
- package/dist/api/resource_handler.mjs +34 -25
- package/dist/table/index.js +6 -2
- package/dist/table/index.mjs +6 -2
- package/dist/table/repository.d.mts +8 -6
- package/dist/table/repository.d.ts +8 -6
- package/dist/table/repository.js +6 -2
- package/dist/table/repository.mjs +6 -2
- package/package.json +1 -1
package/dist/api/index.js
CHANGED
|
@@ -438,7 +438,11 @@ function putResourceHandler({
|
|
|
438
438
|
// src/api/patch_resource_handler.ts
|
|
439
439
|
var import_gw_response3 = require("gw-response");
|
|
440
440
|
var import_drizzle_orm2 = require("drizzle-orm");
|
|
441
|
-
function patchResourceHandler({
|
|
441
|
+
function patchResourceHandler({
|
|
442
|
+
repository,
|
|
443
|
+
validators,
|
|
444
|
+
primaryKey
|
|
445
|
+
}) {
|
|
442
446
|
return async (existing, request) => {
|
|
443
447
|
const serilaizedParams = await request.json();
|
|
444
448
|
const params = deserialize(serilaizedParams) || {};
|
|
@@ -457,8 +461,7 @@ function patchResourceHandler({ repository, validators }) {
|
|
|
457
461
|
}
|
|
458
462
|
}
|
|
459
463
|
}
|
|
460
|
-
const item = await repository.
|
|
461
|
-
...existing,
|
|
464
|
+
const item = await repository.update(existing[primaryKey], {
|
|
462
465
|
...params
|
|
463
466
|
});
|
|
464
467
|
return (0, import_gw_response3.httpCreated)(item);
|
|
@@ -473,7 +476,8 @@ function resourceHandler({
|
|
|
473
476
|
existingConditions,
|
|
474
477
|
injectUserId,
|
|
475
478
|
roles,
|
|
476
|
-
isOwnedBy
|
|
479
|
+
isOwnedBy,
|
|
480
|
+
primaryKey
|
|
477
481
|
}) {
|
|
478
482
|
const loader = async ({ request }) => {
|
|
479
483
|
return (0, import_gw_result.ok)({});
|
|
@@ -485,29 +489,34 @@ function resourceHandler({
|
|
|
485
489
|
message: "\uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
486
490
|
});
|
|
487
491
|
}
|
|
488
|
-
const
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
}
|
|
497
|
-
switch (request.method) {
|
|
498
|
-
case "PATCH": {
|
|
499
|
-
const handler = patchResourceHandler({
|
|
500
|
-
repository,
|
|
501
|
-
validators
|
|
502
|
-
});
|
|
503
|
-
return handler(existing, request);
|
|
492
|
+
const pathname = new URL(request.url).pathname;
|
|
493
|
+
const segments = pathname.split("/").filter(Boolean);
|
|
494
|
+
if (segments.length === 3) {
|
|
495
|
+
const itemId = segments.at(-1);
|
|
496
|
+
if (itemId) {
|
|
497
|
+
const existing = await repository.find(itemId);
|
|
498
|
+
if (!existing) {
|
|
499
|
+
return (0, import_gw_response4.httpNotFound)();
|
|
504
500
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
return (0, import_gw_response4.httpNoContent)();
|
|
501
|
+
if (isOwnedBy && (!auth || !isOwnedBy(auth, existing))) {
|
|
502
|
+
return (0, import_gw_response4.httpForbidden)();
|
|
508
503
|
}
|
|
509
|
-
|
|
510
|
-
|
|
504
|
+
switch (request.method) {
|
|
505
|
+
case "PATCH": {
|
|
506
|
+
const handler = patchResourceHandler({
|
|
507
|
+
repository,
|
|
508
|
+
validators,
|
|
509
|
+
primaryKey
|
|
510
|
+
});
|
|
511
|
+
return handler(existing, request);
|
|
512
|
+
}
|
|
513
|
+
case "DELETE": {
|
|
514
|
+
await repository.delete(itemId);
|
|
515
|
+
return (0, import_gw_response4.httpNoContent)();
|
|
516
|
+
}
|
|
517
|
+
default: {
|
|
518
|
+
return (0, import_gw_response4.httpMethodNotAllowed)();
|
|
519
|
+
}
|
|
511
520
|
}
|
|
512
521
|
}
|
|
513
522
|
}
|
package/dist/api/index.mjs
CHANGED
|
@@ -434,7 +434,11 @@ function putResourceHandler({
|
|
|
434
434
|
// src/api/patch_resource_handler.ts
|
|
435
435
|
import { httpBadRequest as httpBadRequest2, httpCreated as httpCreated2 } from "gw-response";
|
|
436
436
|
import "drizzle-orm";
|
|
437
|
-
function patchResourceHandler({
|
|
437
|
+
function patchResourceHandler({
|
|
438
|
+
repository,
|
|
439
|
+
validators,
|
|
440
|
+
primaryKey
|
|
441
|
+
}) {
|
|
438
442
|
return async (existing, request) => {
|
|
439
443
|
const serilaizedParams = await request.json();
|
|
440
444
|
const params = deserialize(serilaizedParams) || {};
|
|
@@ -453,8 +457,7 @@ function patchResourceHandler({ repository, validators }) {
|
|
|
453
457
|
}
|
|
454
458
|
}
|
|
455
459
|
}
|
|
456
|
-
const item = await repository.
|
|
457
|
-
...existing,
|
|
460
|
+
const item = await repository.update(existing[primaryKey], {
|
|
458
461
|
...params
|
|
459
462
|
});
|
|
460
463
|
return httpCreated2(item);
|
|
@@ -469,7 +472,8 @@ function resourceHandler({
|
|
|
469
472
|
existingConditions,
|
|
470
473
|
injectUserId,
|
|
471
474
|
roles,
|
|
472
|
-
isOwnedBy
|
|
475
|
+
isOwnedBy,
|
|
476
|
+
primaryKey
|
|
473
477
|
}) {
|
|
474
478
|
const loader = async ({ request }) => {
|
|
475
479
|
return ok({});
|
|
@@ -481,29 +485,34 @@ function resourceHandler({
|
|
|
481
485
|
message: "\uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
482
486
|
});
|
|
483
487
|
}
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
switch (request.method) {
|
|
494
|
-
case "PATCH": {
|
|
495
|
-
const handler = patchResourceHandler({
|
|
496
|
-
repository,
|
|
497
|
-
validators
|
|
498
|
-
});
|
|
499
|
-
return handler(existing, request);
|
|
488
|
+
const pathname = new URL(request.url).pathname;
|
|
489
|
+
const segments = pathname.split("/").filter(Boolean);
|
|
490
|
+
if (segments.length === 3) {
|
|
491
|
+
const itemId = segments.at(-1);
|
|
492
|
+
if (itemId) {
|
|
493
|
+
const existing = await repository.find(itemId);
|
|
494
|
+
if (!existing) {
|
|
495
|
+
return httpNotFound3();
|
|
500
496
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
return httpNoContent();
|
|
497
|
+
if (isOwnedBy && (!auth || !isOwnedBy(auth, existing))) {
|
|
498
|
+
return httpForbidden2();
|
|
504
499
|
}
|
|
505
|
-
|
|
506
|
-
|
|
500
|
+
switch (request.method) {
|
|
501
|
+
case "PATCH": {
|
|
502
|
+
const handler = patchResourceHandler({
|
|
503
|
+
repository,
|
|
504
|
+
validators,
|
|
505
|
+
primaryKey
|
|
506
|
+
});
|
|
507
|
+
return handler(existing, request);
|
|
508
|
+
}
|
|
509
|
+
case "DELETE": {
|
|
510
|
+
await repository.delete(itemId);
|
|
511
|
+
return httpNoContent();
|
|
512
|
+
}
|
|
513
|
+
default: {
|
|
514
|
+
return httpMethodNotAllowed();
|
|
515
|
+
}
|
|
507
516
|
}
|
|
508
517
|
}
|
|
509
518
|
}
|
|
@@ -12,10 +12,11 @@ type PatchResourceValidators<T extends PgTableWithColumns<any>> = {
|
|
|
12
12
|
type PatchResourceExistingConditions<T extends PgTableWithColumns<any>> = {
|
|
13
13
|
[K in keyof InferSelectModel<T>]?: (value: InferSelectModel<T>[K]) => SQLWrapper;
|
|
14
14
|
};
|
|
15
|
-
type PatchResourceHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
16
|
-
repository: TableRepository<T, TSelect>;
|
|
15
|
+
type PatchResourceHandlerOptions<T extends PgTableWithColumns<any>, TSelect, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never> = {
|
|
16
|
+
repository: TableRepository<T, TSelect, TPrimaryKey>;
|
|
17
17
|
validators?: PatchResourceValidators<T>;
|
|
18
|
+
primaryKey: TPrimaryKey;
|
|
18
19
|
};
|
|
19
|
-
declare function patchResourceHandler<T extends PgTableWithColumns<any>, TSelect>({ repository, validators }: PatchResourceHandlerOptions<T, TSelect>): (existing: TSelect, request: Request) => Promise<Response>;
|
|
20
|
+
declare function patchResourceHandler<T extends PgTableWithColumns<any>, TSelect, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never>({ repository, validators, primaryKey, }: PatchResourceHandlerOptions<T, TSelect, TPrimaryKey>): (existing: TSelect, request: Request) => Promise<Response>;
|
|
20
21
|
|
|
21
22
|
export { type PatchResourceExistingConditions, type PatchResourceHandlerOptions, type PatchResourceValidators, patchResourceHandler };
|
|
@@ -12,10 +12,11 @@ type PatchResourceValidators<T extends PgTableWithColumns<any>> = {
|
|
|
12
12
|
type PatchResourceExistingConditions<T extends PgTableWithColumns<any>> = {
|
|
13
13
|
[K in keyof InferSelectModel<T>]?: (value: InferSelectModel<T>[K]) => SQLWrapper;
|
|
14
14
|
};
|
|
15
|
-
type PatchResourceHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
16
|
-
repository: TableRepository<T, TSelect>;
|
|
15
|
+
type PatchResourceHandlerOptions<T extends PgTableWithColumns<any>, TSelect, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never> = {
|
|
16
|
+
repository: TableRepository<T, TSelect, TPrimaryKey>;
|
|
17
17
|
validators?: PatchResourceValidators<T>;
|
|
18
|
+
primaryKey: TPrimaryKey;
|
|
18
19
|
};
|
|
19
|
-
declare function patchResourceHandler<T extends PgTableWithColumns<any>, TSelect>({ repository, validators }: PatchResourceHandlerOptions<T, TSelect>): (existing: TSelect, request: Request) => Promise<Response>;
|
|
20
|
+
declare function patchResourceHandler<T extends PgTableWithColumns<any>, TSelect, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never>({ repository, validators, primaryKey, }: PatchResourceHandlerOptions<T, TSelect, TPrimaryKey>): (existing: TSelect, request: Request) => Promise<Response>;
|
|
20
21
|
|
|
21
22
|
export { type PatchResourceExistingConditions, type PatchResourceHandlerOptions, type PatchResourceValidators, patchResourceHandler };
|
|
@@ -140,7 +140,11 @@ var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
|
140
140
|
|
|
141
141
|
// src/api/patch_resource_handler.ts
|
|
142
142
|
var import_drizzle_orm = require("drizzle-orm");
|
|
143
|
-
function patchResourceHandler({
|
|
143
|
+
function patchResourceHandler({
|
|
144
|
+
repository,
|
|
145
|
+
validators,
|
|
146
|
+
primaryKey
|
|
147
|
+
}) {
|
|
144
148
|
return async (existing, request) => {
|
|
145
149
|
const serilaizedParams = await request.json();
|
|
146
150
|
const params = deserialize(serilaizedParams) || {};
|
|
@@ -159,8 +163,7 @@ function patchResourceHandler({ repository, validators }) {
|
|
|
159
163
|
}
|
|
160
164
|
}
|
|
161
165
|
}
|
|
162
|
-
const item = await repository.
|
|
163
|
-
...existing,
|
|
166
|
+
const item = await repository.update(existing[primaryKey], {
|
|
164
167
|
...params
|
|
165
168
|
});
|
|
166
169
|
return (0, import_gw_response.httpCreated)(item);
|
|
@@ -113,7 +113,11 @@ import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs2 } from "react/jsx-run
|
|
|
113
113
|
|
|
114
114
|
// src/api/patch_resource_handler.ts
|
|
115
115
|
import "drizzle-orm";
|
|
116
|
-
function patchResourceHandler({
|
|
116
|
+
function patchResourceHandler({
|
|
117
|
+
repository,
|
|
118
|
+
validators,
|
|
119
|
+
primaryKey
|
|
120
|
+
}) {
|
|
117
121
|
return async (existing, request) => {
|
|
118
122
|
const serilaizedParams = await request.json();
|
|
119
123
|
const params = deserialize(serilaizedParams) || {};
|
|
@@ -132,8 +136,7 @@ function patchResourceHandler({ repository, validators }) {
|
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
138
|
}
|
|
135
|
-
const item = await repository.
|
|
136
|
-
...existing,
|
|
139
|
+
const item = await repository.update(existing[primaryKey], {
|
|
137
140
|
...params
|
|
138
141
|
});
|
|
139
142
|
return httpCreated(item);
|
|
@@ -13,13 +13,13 @@ type PutResourceValidators<T extends PgTableWithColumns<any>> = {
|
|
|
13
13
|
type PutResourceExistingConditions<T extends PgTableWithColumns<any>> = {
|
|
14
14
|
[K in keyof InferSelectModel<T>]?: (value: InferSelectModel<T>[K]) => SQLWrapper;
|
|
15
15
|
};
|
|
16
|
-
type PutResourceHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
17
|
-
repository: TableRepository<T, TSelect>;
|
|
16
|
+
type PutResourceHandlerOptions<T extends PgTableWithColumns<any>, TSelect, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never> = {
|
|
17
|
+
repository: TableRepository<T, TSelect, TPrimaryKey>;
|
|
18
18
|
validators?: PutResourceValidators<T>;
|
|
19
19
|
existingConditions?: PutResourceExistingConditions<T>;
|
|
20
20
|
injectUserId?: boolean;
|
|
21
21
|
isOwnedBy?: (auth: AccessTokenPayload, item: TSelect) => boolean;
|
|
22
22
|
};
|
|
23
|
-
declare function putResourceHandler<T extends PgTableWithColumns<any>, TSelect>({ repository, validators, existingConditions, injectUserId, isOwnedBy, }: PutResourceHandlerOptions<T, TSelect>): (auth: AccessTokenPayload | undefined, request: Request) => Promise<Response>;
|
|
23
|
+
declare function putResourceHandler<T extends PgTableWithColumns<any>, TSelect, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never>({ repository, validators, existingConditions, injectUserId, isOwnedBy, }: PutResourceHandlerOptions<T, TSelect, TPrimaryKey>): (auth: AccessTokenPayload | undefined, request: Request) => Promise<Response>;
|
|
24
24
|
|
|
25
25
|
export { type PutResourceExistingConditions, type PutResourceHandlerOptions, type PutResourceValidators, putResourceHandler };
|
|
@@ -13,13 +13,13 @@ type PutResourceValidators<T extends PgTableWithColumns<any>> = {
|
|
|
13
13
|
type PutResourceExistingConditions<T extends PgTableWithColumns<any>> = {
|
|
14
14
|
[K in keyof InferSelectModel<T>]?: (value: InferSelectModel<T>[K]) => SQLWrapper;
|
|
15
15
|
};
|
|
16
|
-
type PutResourceHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
17
|
-
repository: TableRepository<T, TSelect>;
|
|
16
|
+
type PutResourceHandlerOptions<T extends PgTableWithColumns<any>, TSelect, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never> = {
|
|
17
|
+
repository: TableRepository<T, TSelect, TPrimaryKey>;
|
|
18
18
|
validators?: PutResourceValidators<T>;
|
|
19
19
|
existingConditions?: PutResourceExistingConditions<T>;
|
|
20
20
|
injectUserId?: boolean;
|
|
21
21
|
isOwnedBy?: (auth: AccessTokenPayload, item: TSelect) => boolean;
|
|
22
22
|
};
|
|
23
|
-
declare function putResourceHandler<T extends PgTableWithColumns<any>, TSelect>({ repository, validators, existingConditions, injectUserId, isOwnedBy, }: PutResourceHandlerOptions<T, TSelect>): (auth: AccessTokenPayload | undefined, request: Request) => Promise<Response>;
|
|
23
|
+
declare function putResourceHandler<T extends PgTableWithColumns<any>, TSelect, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never>({ repository, validators, existingConditions, injectUserId, isOwnedBy, }: PutResourceHandlerOptions<T, TSelect, TPrimaryKey>): (auth: AccessTokenPayload | undefined, request: Request) => Promise<Response>;
|
|
24
24
|
|
|
25
25
|
export { type PutResourceExistingConditions, type PutResourceHandlerOptions, type PutResourceValidators, putResourceHandler };
|
|
@@ -9,16 +9,17 @@ import 'drizzle-orm';
|
|
|
9
9
|
import 'drizzle-orm/node-postgres';
|
|
10
10
|
import 'gw-auth/server';
|
|
11
11
|
|
|
12
|
-
type APIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
12
|
+
type APIHandlerOptions<T extends PgTableWithColumns<any>, TSelect, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never> = {
|
|
13
13
|
withAuthAction: WithAuthHandler<ActionFunctionArgs>;
|
|
14
|
-
repository: TableRepository<T, TSelect>;
|
|
14
|
+
repository: TableRepository<T, TSelect, TPrimaryKey>;
|
|
15
|
+
primaryKey: TPrimaryKey;
|
|
15
16
|
validators?: PutResourceValidators<T>;
|
|
16
17
|
existingConditions?: PutResourceExistingConditions<T>;
|
|
17
18
|
injectUserId?: boolean;
|
|
18
19
|
roles?: string[];
|
|
19
20
|
isOwnedBy?: (auth: AccessTokenPayload, item: TSelect) => boolean;
|
|
20
21
|
};
|
|
21
|
-
declare function resourceHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, validators, existingConditions, injectUserId, roles, isOwnedBy, }: APIHandlerOptions<T, TSelect>): {
|
|
22
|
+
declare function resourceHandler<T extends PgTableWithColumns<any>, TSelect, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never>({ withAuthAction, repository, validators, existingConditions, injectUserId, roles, isOwnedBy, primaryKey, }: APIHandlerOptions<T, TSelect, TPrimaryKey>): {
|
|
22
23
|
loader: ({ request }: LoaderFunctionArgs) => Promise<gw_result.Ok<{}>>;
|
|
23
24
|
action: (arg: ActionFunctionArgs<any>) => Promise<unknown> | unknown;
|
|
24
25
|
};
|
|
@@ -9,16 +9,17 @@ import 'drizzle-orm';
|
|
|
9
9
|
import 'drizzle-orm/node-postgres';
|
|
10
10
|
import 'gw-auth/server';
|
|
11
11
|
|
|
12
|
-
type APIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
12
|
+
type APIHandlerOptions<T extends PgTableWithColumns<any>, TSelect, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never> = {
|
|
13
13
|
withAuthAction: WithAuthHandler<ActionFunctionArgs>;
|
|
14
|
-
repository: TableRepository<T, TSelect>;
|
|
14
|
+
repository: TableRepository<T, TSelect, TPrimaryKey>;
|
|
15
|
+
primaryKey: TPrimaryKey;
|
|
15
16
|
validators?: PutResourceValidators<T>;
|
|
16
17
|
existingConditions?: PutResourceExistingConditions<T>;
|
|
17
18
|
injectUserId?: boolean;
|
|
18
19
|
roles?: string[];
|
|
19
20
|
isOwnedBy?: (auth: AccessTokenPayload, item: TSelect) => boolean;
|
|
20
21
|
};
|
|
21
|
-
declare function resourceHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, validators, existingConditions, injectUserId, roles, isOwnedBy, }: APIHandlerOptions<T, TSelect>): {
|
|
22
|
+
declare function resourceHandler<T extends PgTableWithColumns<any>, TSelect, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never>({ withAuthAction, repository, validators, existingConditions, injectUserId, roles, isOwnedBy, primaryKey, }: APIHandlerOptions<T, TSelect, TPrimaryKey>): {
|
|
22
23
|
loader: ({ request }: LoaderFunctionArgs) => Promise<gw_result.Ok<{}>>;
|
|
23
24
|
action: (arg: ActionFunctionArgs<any>) => Promise<unknown> | unknown;
|
|
24
25
|
};
|
|
@@ -216,7 +216,11 @@ function putResourceHandler({
|
|
|
216
216
|
// src/api/patch_resource_handler.ts
|
|
217
217
|
var import_gw_response2 = require("gw-response");
|
|
218
218
|
var import_drizzle_orm2 = require("drizzle-orm");
|
|
219
|
-
function patchResourceHandler({
|
|
219
|
+
function patchResourceHandler({
|
|
220
|
+
repository,
|
|
221
|
+
validators,
|
|
222
|
+
primaryKey
|
|
223
|
+
}) {
|
|
220
224
|
return async (existing, request) => {
|
|
221
225
|
const serilaizedParams = await request.json();
|
|
222
226
|
const params = deserialize(serilaizedParams) || {};
|
|
@@ -235,8 +239,7 @@ function patchResourceHandler({ repository, validators }) {
|
|
|
235
239
|
}
|
|
236
240
|
}
|
|
237
241
|
}
|
|
238
|
-
const item = await repository.
|
|
239
|
-
...existing,
|
|
242
|
+
const item = await repository.update(existing[primaryKey], {
|
|
240
243
|
...params
|
|
241
244
|
});
|
|
242
245
|
return (0, import_gw_response2.httpCreated)(item);
|
|
@@ -251,7 +254,8 @@ function resourceHandler({
|
|
|
251
254
|
existingConditions,
|
|
252
255
|
injectUserId,
|
|
253
256
|
roles,
|
|
254
|
-
isOwnedBy
|
|
257
|
+
isOwnedBy,
|
|
258
|
+
primaryKey
|
|
255
259
|
}) {
|
|
256
260
|
const loader = async ({ request }) => {
|
|
257
261
|
return (0, import_gw_result.ok)({});
|
|
@@ -263,29 +267,34 @@ function resourceHandler({
|
|
|
263
267
|
message: "\uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
264
268
|
});
|
|
265
269
|
}
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
switch (request.method) {
|
|
276
|
-
case "PATCH": {
|
|
277
|
-
const handler = patchResourceHandler({
|
|
278
|
-
repository,
|
|
279
|
-
validators
|
|
280
|
-
});
|
|
281
|
-
return handler(existing, request);
|
|
270
|
+
const pathname = new URL(request.url).pathname;
|
|
271
|
+
const segments = pathname.split("/").filter(Boolean);
|
|
272
|
+
if (segments.length === 3) {
|
|
273
|
+
const itemId = segments.at(-1);
|
|
274
|
+
if (itemId) {
|
|
275
|
+
const existing = await repository.find(itemId);
|
|
276
|
+
if (!existing) {
|
|
277
|
+
return (0, import_gw_response3.httpNotFound)();
|
|
282
278
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
return (0, import_gw_response3.httpNoContent)();
|
|
279
|
+
if (isOwnedBy && (!auth || !isOwnedBy(auth, existing))) {
|
|
280
|
+
return (0, import_gw_response3.httpForbidden)();
|
|
286
281
|
}
|
|
287
|
-
|
|
288
|
-
|
|
282
|
+
switch (request.method) {
|
|
283
|
+
case "PATCH": {
|
|
284
|
+
const handler = patchResourceHandler({
|
|
285
|
+
repository,
|
|
286
|
+
validators,
|
|
287
|
+
primaryKey
|
|
288
|
+
});
|
|
289
|
+
return handler(existing, request);
|
|
290
|
+
}
|
|
291
|
+
case "DELETE": {
|
|
292
|
+
await repository.delete(itemId);
|
|
293
|
+
return (0, import_gw_response3.httpNoContent)();
|
|
294
|
+
}
|
|
295
|
+
default: {
|
|
296
|
+
return (0, import_gw_response3.httpMethodNotAllowed)();
|
|
297
|
+
}
|
|
289
298
|
}
|
|
290
299
|
}
|
|
291
300
|
}
|
|
@@ -202,7 +202,11 @@ function putResourceHandler({
|
|
|
202
202
|
// src/api/patch_resource_handler.ts
|
|
203
203
|
import { httpBadRequest as httpBadRequest2, httpCreated as httpCreated2 } from "gw-response";
|
|
204
204
|
import "drizzle-orm";
|
|
205
|
-
function patchResourceHandler({
|
|
205
|
+
function patchResourceHandler({
|
|
206
|
+
repository,
|
|
207
|
+
validators,
|
|
208
|
+
primaryKey
|
|
209
|
+
}) {
|
|
206
210
|
return async (existing, request) => {
|
|
207
211
|
const serilaizedParams = await request.json();
|
|
208
212
|
const params = deserialize(serilaizedParams) || {};
|
|
@@ -221,8 +225,7 @@ function patchResourceHandler({ repository, validators }) {
|
|
|
221
225
|
}
|
|
222
226
|
}
|
|
223
227
|
}
|
|
224
|
-
const item = await repository.
|
|
225
|
-
...existing,
|
|
228
|
+
const item = await repository.update(existing[primaryKey], {
|
|
226
229
|
...params
|
|
227
230
|
});
|
|
228
231
|
return httpCreated2(item);
|
|
@@ -237,7 +240,8 @@ function resourceHandler({
|
|
|
237
240
|
existingConditions,
|
|
238
241
|
injectUserId,
|
|
239
242
|
roles,
|
|
240
|
-
isOwnedBy
|
|
243
|
+
isOwnedBy,
|
|
244
|
+
primaryKey
|
|
241
245
|
}) {
|
|
242
246
|
const loader = async ({ request }) => {
|
|
243
247
|
return ok({});
|
|
@@ -249,29 +253,34 @@ function resourceHandler({
|
|
|
249
253
|
message: "\uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
250
254
|
});
|
|
251
255
|
}
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
switch (request.method) {
|
|
262
|
-
case "PATCH": {
|
|
263
|
-
const handler = patchResourceHandler({
|
|
264
|
-
repository,
|
|
265
|
-
validators
|
|
266
|
-
});
|
|
267
|
-
return handler(existing, request);
|
|
256
|
+
const pathname = new URL(request.url).pathname;
|
|
257
|
+
const segments = pathname.split("/").filter(Boolean);
|
|
258
|
+
if (segments.length === 3) {
|
|
259
|
+
const itemId = segments.at(-1);
|
|
260
|
+
if (itemId) {
|
|
261
|
+
const existing = await repository.find(itemId);
|
|
262
|
+
if (!existing) {
|
|
263
|
+
return httpNotFound2();
|
|
268
264
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
return httpNoContent();
|
|
265
|
+
if (isOwnedBy && (!auth || !isOwnedBy(auth, existing))) {
|
|
266
|
+
return httpForbidden2();
|
|
272
267
|
}
|
|
273
|
-
|
|
274
|
-
|
|
268
|
+
switch (request.method) {
|
|
269
|
+
case "PATCH": {
|
|
270
|
+
const handler = patchResourceHandler({
|
|
271
|
+
repository,
|
|
272
|
+
validators,
|
|
273
|
+
primaryKey
|
|
274
|
+
});
|
|
275
|
+
return handler(existing, request);
|
|
276
|
+
}
|
|
277
|
+
case "DELETE": {
|
|
278
|
+
await repository.delete(itemId);
|
|
279
|
+
return httpNoContent();
|
|
280
|
+
}
|
|
281
|
+
default: {
|
|
282
|
+
return httpMethodNotAllowed();
|
|
283
|
+
}
|
|
275
284
|
}
|
|
276
285
|
}
|
|
277
286
|
}
|
package/dist/table/index.js
CHANGED
|
@@ -41,8 +41,8 @@ var BaseTableRepository = class {
|
|
|
41
41
|
this.schema = db._.fullSchema[schema];
|
|
42
42
|
this.pk = pk;
|
|
43
43
|
}
|
|
44
|
-
async find(
|
|
45
|
-
return await this.db.select().from(this.schema).where((0, import_drizzle_orm.eq)(this.schema[this.pk],
|
|
44
|
+
async find(pk) {
|
|
45
|
+
return await this.db.select().from(this.schema).where((0, import_drizzle_orm.eq)(this.schema[this.pk], pk)).limit(1).then((res) => res[0]);
|
|
46
46
|
}
|
|
47
47
|
async countTotal({ where }) {
|
|
48
48
|
const [{ total }] = await this.db.select({ total: (0, import_drizzle_orm.count)() }).from(this.schema).where(where);
|
|
@@ -77,6 +77,10 @@ var BaseTableRepository = class {
|
|
|
77
77
|
async delete(pk) {
|
|
78
78
|
await this.db.delete(this.schema).where((0, import_drizzle_orm.eq)(this.schema[this.pk], pk));
|
|
79
79
|
}
|
|
80
|
+
async update(pk, values) {
|
|
81
|
+
const [item] = await this.db.update(this.schema).set(values).where((0, import_drizzle_orm.eq)(this.schema[this.pk], pk)).returning();
|
|
82
|
+
return item;
|
|
83
|
+
}
|
|
80
84
|
async select(key) {
|
|
81
85
|
const rows = await this.db.select({ value: this.schema[key] }).from(this.schema).groupBy(this.schema[key]);
|
|
82
86
|
return rows.map((row) => row.value);
|
package/dist/table/index.mjs
CHANGED
|
@@ -14,8 +14,8 @@ var BaseTableRepository = class {
|
|
|
14
14
|
this.schema = db._.fullSchema[schema];
|
|
15
15
|
this.pk = pk;
|
|
16
16
|
}
|
|
17
|
-
async find(
|
|
18
|
-
return await this.db.select().from(this.schema).where(eq(this.schema[this.pk],
|
|
17
|
+
async find(pk) {
|
|
18
|
+
return await this.db.select().from(this.schema).where(eq(this.schema[this.pk], pk)).limit(1).then((res) => res[0]);
|
|
19
19
|
}
|
|
20
20
|
async countTotal({ where }) {
|
|
21
21
|
const [{ total }] = await this.db.select({ total: count() }).from(this.schema).where(where);
|
|
@@ -50,6 +50,10 @@ var BaseTableRepository = class {
|
|
|
50
50
|
async delete(pk) {
|
|
51
51
|
await this.db.delete(this.schema).where(eq(this.schema[this.pk], pk));
|
|
52
52
|
}
|
|
53
|
+
async update(pk, values) {
|
|
54
|
+
const [item] = await this.db.update(this.schema).set(values).where(eq(this.schema[this.pk], pk)).returning();
|
|
55
|
+
return item;
|
|
56
|
+
}
|
|
53
57
|
async select(key) {
|
|
54
58
|
const rows = await this.db.select({ value: this.schema[key] }).from(this.schema).groupBy(this.schema[key]);
|
|
55
59
|
return rows.map((row) => row.value);
|
|
@@ -12,30 +12,32 @@ type FindAllOptions<T extends PgTableWithColumns<any>> = {
|
|
|
12
12
|
type ColumnOf<T> = T extends PgTableWithColumns<infer TConfig> ? keyof TConfig["columns"] : never;
|
|
13
13
|
type SelectModelOf<T> = T extends TableRepository<infer TSelect, any> ? TSelect : never;
|
|
14
14
|
type InsertModelOf<T> = T extends TableRepository<any, infer TInsert> ? TInsert : never;
|
|
15
|
-
interface TableRepository<T extends PgTableWithColumns<any>, TSelect = InferSelectModel<T
|
|
15
|
+
interface TableRepository<T extends PgTableWithColumns<any>, TSelect = InferSelectModel<T>, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never> {
|
|
16
16
|
schema: T;
|
|
17
|
-
find: (
|
|
17
|
+
find: (pk: TSelect[TPrimaryKey]) => Promise<TSelect | undefined>;
|
|
18
18
|
countTotal: (options: {
|
|
19
19
|
where?: SQL<unknown>;
|
|
20
20
|
}) => Promise<number>;
|
|
21
21
|
findAll: (options: FindAllOptions<T>) => Promise<TSelect[]>;
|
|
22
22
|
save: (values: InferInsertModel<T>) => Promise<TSelect>;
|
|
23
|
-
|
|
23
|
+
update: (pk: TSelect[TPrimaryKey], values: Partial<InferInsertModel<T>>) => Promise<TSelect>;
|
|
24
|
+
delete: (pk: TSelect[TPrimaryKey]) => Promise<void>;
|
|
24
25
|
select(key: keyof InferSelectModel<T>): Promise<InferSelectModel<T>[typeof key][]>;
|
|
25
26
|
}
|
|
26
27
|
type SchemaOf<TDatabase extends NodePgDatabase<any>, TSchemaKey extends keyof TDatabase["_"]["fullSchema"]> = TDatabase["_"]["fullSchema"][TSchemaKey];
|
|
27
|
-
declare class BaseTableRepository<TDatabase extends NodePgDatabase<any>, TSchemaKey extends keyof TDatabase["_"]["fullSchema"], TSelect = InferSelectModel<SchemaOf<TDatabase, TSchemaKey>>, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never> implements TableRepository<SchemaOf<TDatabase, TSchemaKey
|
|
28
|
+
declare class BaseTableRepository<TDatabase extends NodePgDatabase<any>, TSchemaKey extends keyof TDatabase["_"]["fullSchema"], TSelect = InferSelectModel<SchemaOf<TDatabase, TSchemaKey>>, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never> implements TableRepository<SchemaOf<TDatabase, TSchemaKey>, TSelect, TPrimaryKey> {
|
|
28
29
|
db: TDatabase;
|
|
29
30
|
schema: SchemaOf<TDatabase, TSchemaKey>;
|
|
30
31
|
pk: TPrimaryKey;
|
|
31
32
|
constructor(db: TDatabase, schema: TSchemaKey, pk?: TPrimaryKey);
|
|
32
|
-
find(
|
|
33
|
+
find(pk: TSelect[TPrimaryKey]): Promise<TSelect | undefined>;
|
|
33
34
|
countTotal({ where }: {
|
|
34
35
|
where?: SQL<unknown>;
|
|
35
36
|
}): Promise<number>;
|
|
36
37
|
findAll(options: FindAllOptions<SchemaOf<TDatabase, TSchemaKey>>): Promise<TSelect[]>;
|
|
37
38
|
save(values: InferInsertModel<SchemaOf<TDatabase, TSchemaKey>>): Promise<TSelect>;
|
|
38
|
-
delete(pk:
|
|
39
|
+
delete(pk: TSelect[TPrimaryKey]): Promise<void>;
|
|
40
|
+
update(pk: TSelect[TPrimaryKey], values: Partial<InferInsertModel<SchemaOf<TDatabase, TSchemaKey>>>): Promise<TSelect>;
|
|
39
41
|
select(key: keyof InferSelectModel<SchemaOf<TDatabase, TSchemaKey>>): Promise<InferSelectModel<SchemaOf<TDatabase, TSchemaKey>>[typeof key][]>;
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -12,30 +12,32 @@ type FindAllOptions<T extends PgTableWithColumns<any>> = {
|
|
|
12
12
|
type ColumnOf<T> = T extends PgTableWithColumns<infer TConfig> ? keyof TConfig["columns"] : never;
|
|
13
13
|
type SelectModelOf<T> = T extends TableRepository<infer TSelect, any> ? TSelect : never;
|
|
14
14
|
type InsertModelOf<T> = T extends TableRepository<any, infer TInsert> ? TInsert : never;
|
|
15
|
-
interface TableRepository<T extends PgTableWithColumns<any>, TSelect = InferSelectModel<T
|
|
15
|
+
interface TableRepository<T extends PgTableWithColumns<any>, TSelect = InferSelectModel<T>, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never> {
|
|
16
16
|
schema: T;
|
|
17
|
-
find: (
|
|
17
|
+
find: (pk: TSelect[TPrimaryKey]) => Promise<TSelect | undefined>;
|
|
18
18
|
countTotal: (options: {
|
|
19
19
|
where?: SQL<unknown>;
|
|
20
20
|
}) => Promise<number>;
|
|
21
21
|
findAll: (options: FindAllOptions<T>) => Promise<TSelect[]>;
|
|
22
22
|
save: (values: InferInsertModel<T>) => Promise<TSelect>;
|
|
23
|
-
|
|
23
|
+
update: (pk: TSelect[TPrimaryKey], values: Partial<InferInsertModel<T>>) => Promise<TSelect>;
|
|
24
|
+
delete: (pk: TSelect[TPrimaryKey]) => Promise<void>;
|
|
24
25
|
select(key: keyof InferSelectModel<T>): Promise<InferSelectModel<T>[typeof key][]>;
|
|
25
26
|
}
|
|
26
27
|
type SchemaOf<TDatabase extends NodePgDatabase<any>, TSchemaKey extends keyof TDatabase["_"]["fullSchema"]> = TDatabase["_"]["fullSchema"][TSchemaKey];
|
|
27
|
-
declare class BaseTableRepository<TDatabase extends NodePgDatabase<any>, TSchemaKey extends keyof TDatabase["_"]["fullSchema"], TSelect = InferSelectModel<SchemaOf<TDatabase, TSchemaKey>>, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never> implements TableRepository<SchemaOf<TDatabase, TSchemaKey
|
|
28
|
+
declare class BaseTableRepository<TDatabase extends NodePgDatabase<any>, TSchemaKey extends keyof TDatabase["_"]["fullSchema"], TSelect = InferSelectModel<SchemaOf<TDatabase, TSchemaKey>>, TPrimaryKey extends keyof TSelect = "id" extends keyof TSelect ? "id" : never> implements TableRepository<SchemaOf<TDatabase, TSchemaKey>, TSelect, TPrimaryKey> {
|
|
28
29
|
db: TDatabase;
|
|
29
30
|
schema: SchemaOf<TDatabase, TSchemaKey>;
|
|
30
31
|
pk: TPrimaryKey;
|
|
31
32
|
constructor(db: TDatabase, schema: TSchemaKey, pk?: TPrimaryKey);
|
|
32
|
-
find(
|
|
33
|
+
find(pk: TSelect[TPrimaryKey]): Promise<TSelect | undefined>;
|
|
33
34
|
countTotal({ where }: {
|
|
34
35
|
where?: SQL<unknown>;
|
|
35
36
|
}): Promise<number>;
|
|
36
37
|
findAll(options: FindAllOptions<SchemaOf<TDatabase, TSchemaKey>>): Promise<TSelect[]>;
|
|
37
38
|
save(values: InferInsertModel<SchemaOf<TDatabase, TSchemaKey>>): Promise<TSelect>;
|
|
38
|
-
delete(pk:
|
|
39
|
+
delete(pk: TSelect[TPrimaryKey]): Promise<void>;
|
|
40
|
+
update(pk: TSelect[TPrimaryKey], values: Partial<InferInsertModel<SchemaOf<TDatabase, TSchemaKey>>>): Promise<TSelect>;
|
|
39
41
|
select(key: keyof InferSelectModel<SchemaOf<TDatabase, TSchemaKey>>): Promise<InferSelectModel<SchemaOf<TDatabase, TSchemaKey>>[typeof key][]>;
|
|
40
42
|
}
|
|
41
43
|
|
package/dist/table/repository.js
CHANGED
|
@@ -33,8 +33,8 @@ var BaseTableRepository = class {
|
|
|
33
33
|
this.schema = db._.fullSchema[schema];
|
|
34
34
|
this.pk = pk;
|
|
35
35
|
}
|
|
36
|
-
async find(
|
|
37
|
-
return await this.db.select().from(this.schema).where((0, import_drizzle_orm.eq)(this.schema[this.pk],
|
|
36
|
+
async find(pk) {
|
|
37
|
+
return await this.db.select().from(this.schema).where((0, import_drizzle_orm.eq)(this.schema[this.pk], pk)).limit(1).then((res) => res[0]);
|
|
38
38
|
}
|
|
39
39
|
async countTotal({ where }) {
|
|
40
40
|
const [{ total }] = await this.db.select({ total: (0, import_drizzle_orm.count)() }).from(this.schema).where(where);
|
|
@@ -69,6 +69,10 @@ var BaseTableRepository = class {
|
|
|
69
69
|
async delete(pk) {
|
|
70
70
|
await this.db.delete(this.schema).where((0, import_drizzle_orm.eq)(this.schema[this.pk], pk));
|
|
71
71
|
}
|
|
72
|
+
async update(pk, values) {
|
|
73
|
+
const [item] = await this.db.update(this.schema).set(values).where((0, import_drizzle_orm.eq)(this.schema[this.pk], pk)).returning();
|
|
74
|
+
return item;
|
|
75
|
+
}
|
|
72
76
|
async select(key) {
|
|
73
77
|
const rows = await this.db.select({ value: this.schema[key] }).from(this.schema).groupBy(this.schema[key]);
|
|
74
78
|
return rows.map((row) => row.value);
|
|
@@ -14,8 +14,8 @@ var BaseTableRepository = class {
|
|
|
14
14
|
this.schema = db._.fullSchema[schema];
|
|
15
15
|
this.pk = pk;
|
|
16
16
|
}
|
|
17
|
-
async find(
|
|
18
|
-
return await this.db.select().from(this.schema).where(eq(this.schema[this.pk],
|
|
17
|
+
async find(pk) {
|
|
18
|
+
return await this.db.select().from(this.schema).where(eq(this.schema[this.pk], pk)).limit(1).then((res) => res[0]);
|
|
19
19
|
}
|
|
20
20
|
async countTotal({ where }) {
|
|
21
21
|
const [{ total }] = await this.db.select({ total: count() }).from(this.schema).where(where);
|
|
@@ -50,6 +50,10 @@ var BaseTableRepository = class {
|
|
|
50
50
|
async delete(pk) {
|
|
51
51
|
await this.db.delete(this.schema).where(eq(this.schema[this.pk], pk));
|
|
52
52
|
}
|
|
53
|
+
async update(pk, values) {
|
|
54
|
+
const [item] = await this.db.update(this.schema).set(values).where(eq(this.schema[this.pk], pk)).returning();
|
|
55
|
+
return item;
|
|
56
|
+
}
|
|
53
57
|
async select(key) {
|
|
54
58
|
const rows = await this.db.select({ value: this.schema[key] }).from(this.schema).groupBy(this.schema[key]);
|
|
55
59
|
return rows.map((row) => row.value);
|