dn-react-router-toolkit 0.9.1 → 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.
@@ -1,4 +1,4 @@
1
- // src/api/create_handler.ts
1
+ // src/api/default_api_handler.ts
2
2
  import {
3
3
  findAuthHandler,
4
4
  loginHandler,
@@ -71,13 +71,13 @@ function createWithStrictAuthHandler({ authService }) {
71
71
  // src/auth/cookie_manager.ts
72
72
  import { createCookie } from "react-router";
73
73
 
74
- // src/api/create_handler.ts
74
+ // src/api/default_api_handler.ts
75
75
  import {
76
76
  deleteFileHandler,
77
77
  uploadFileHandler
78
78
  } from "gw-file/server";
79
79
  import { httpNotFound } from "gw-response";
80
- var createAPIHandler = ({
80
+ var defaultAPIHandler = ({
81
81
  authService,
82
82
  fileService,
83
83
  passwordRecoveryService,
@@ -230,11 +230,31 @@ var createAPIHandler = ({
230
230
  return handler;
231
231
  };
232
232
 
233
- // src/api/create_api_handler.ts
233
+ // src/api/resource_handler.ts
234
234
  import {
235
- and
236
- } from "drizzle-orm";
237
- import { v4 } from "uuid";
235
+ httpForbidden as httpForbidden2,
236
+ httpMethodNotAllowed,
237
+ httpNoContent,
238
+ httpNotFound as httpNotFound3
239
+ } from "gw-response";
240
+ import { ok } from "gw-result";
241
+
242
+ // src/api/put_resource_handler.ts
243
+ import {
244
+ httpBadRequest,
245
+ httpConflict,
246
+ httpCreated,
247
+ httpForbidden,
248
+ httpNotFound as httpNotFound2
249
+ } from "gw-response";
250
+
251
+ // src/crud/crud_form_provider.tsx
252
+ import { useNavigate } from "react-router";
253
+ import { useStore } from "react-store-input";
254
+ import {
255
+ createContext,
256
+ useContext
257
+ } from "react";
238
258
 
239
259
  // src/crud/serialize.ts
240
260
  function deserialize(data) {
@@ -273,151 +293,197 @@ function deserialize(data) {
273
293
  return void 0;
274
294
  }
275
295
 
276
- // src/api/create_api_handler.ts
296
+ // src/crud/crud_form_provider.tsx
297
+ import { jsx } from "react/jsx-runtime";
298
+ var FormContext = createContext({});
299
+
300
+ // src/form/create_form_component.tsx
301
+ import "react";
302
+
303
+ // src/utils/cn.ts
304
+ function cn(...classes) {
305
+ return classes.filter(Boolean).join(" ").trim();
306
+ }
307
+
308
+ // src/utils/date.ts
309
+ import moment from "moment-timezone";
310
+
311
+ // src/form/create_form_component.tsx
312
+ import { jsx as jsx2 } from "react/jsx-runtime";
313
+ function createComponent(tag, options) {
314
+ return function FormComponent({ className, ...props }) {
315
+ const Tag = tag;
316
+ return /* @__PURE__ */ jsx2(Tag, { ...props, className: cn(options.className, className) });
317
+ };
318
+ }
319
+
320
+ // src/form/form_components.tsx
321
+ var FormEntry = createComponent("div", {
322
+ className: "flex-1"
323
+ });
324
+ var FormRow = createComponent("div", {
325
+ className: "flex-1 flex gap-4 mb-6"
326
+ });
327
+ var FormLabel = createComponent("label", {
328
+ className: "flex-1 font-semibold mb-2.5 block"
329
+ });
330
+
331
+ // src/crud/crud_form.tsx
332
+ import { useStoreComponent } from "react-store-input";
333
+
334
+ // src/client/env_loader.tsx
335
+ import { useRouteLoaderData } from "react-router";
336
+ import { jsx as jsx3 } from "react/jsx-runtime";
337
+
338
+ // src/client/file_input.tsx
277
339
  import {
278
- httpBadRequest,
279
- httpConflict,
280
- httpCreated,
281
- httpMethodNotAllowed,
282
- httpUnauthorized
283
- } from "gw-response";
284
- function apiHandler({
285
- withAuthAction,
340
+ useRef
341
+ } from "react";
342
+ import { Fragment, jsx as jsx4, jsxs } from "react/jsx-runtime";
343
+
344
+ // src/client/use_user_agent.tsx
345
+ import { useRouteLoaderData as useRouteLoaderData2 } from "react-router";
346
+
347
+ // src/client/store_text_editor.tsx
348
+ import {
349
+ TextEditor
350
+ } from "dn-react-text-editor";
351
+ import { useStoreController } from "react-store-input";
352
+ import { useImperativeHandle, useRef as useRef2 } from "react";
353
+ import { jsx as jsx5 } from "react/jsx-runtime";
354
+
355
+ // src/client/editor.tsx
356
+ import { generateMetadata } from "gw-file/client";
357
+
358
+ // src/crud/crud_form.tsx
359
+ import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
360
+
361
+ // src/api/put_resource_handler.ts
362
+ import {
363
+ and
364
+ } from "drizzle-orm";
365
+ import { v4 } from "uuid";
366
+ function putResourceHandler({
286
367
  repository,
287
368
  validators,
288
369
  existingConditions,
289
370
  injectUserId,
290
- roles
371
+ isOwnedBy
291
372
  }) {
292
- const loader = async ({ request }) => {
293
- return {};
294
- };
295
- const action = withAuthAction((auth) => async ({ request }) => {
296
- if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
297
- throw httpUnauthorized({
298
- code: "UNAUTHORIZED",
299
- message: "\uC778\uC99D\uC774 \uD544\uC694\uD569\uB2C8\uB2E4."
300
- });
373
+ return async (auth, request) => {
374
+ const serilaizedParams = await request.json();
375
+ const params = deserialize(serilaizedParams);
376
+ const itemId = params.id || v4();
377
+ if (params.id) {
378
+ const existing = await repository.find(itemId);
379
+ if (!existing) {
380
+ return httpNotFound2();
381
+ }
382
+ if (isOwnedBy && (!auth || !isOwnedBy(auth, existing))) {
383
+ return httpForbidden();
384
+ }
301
385
  }
302
- switch (request.method) {
303
- case "POST":
304
- case "PUT": {
305
- const serilaizedParams = await request.json();
306
- const params = deserialize(serilaizedParams);
307
- if (validators) {
308
- const paramsForValidation = Object.keys(validators).filter(
309
- (key) => Object.prototype.hasOwnProperty.call(validators, key)
310
- );
311
- for (const paramKey of paramsForValidation) {
312
- const value = params[paramKey];
313
- const validator = validators[paramKey];
314
- if (validator?.validate && !validator.validate(value)) {
315
- throw httpBadRequest({
316
- code: "BAD_REQUEST",
317
- message: validator.message ? validator.message(value) : "\uC798\uBABB\uB41C \uC694\uCCAD\uC785\uB2C8\uB2E4."
318
- });
319
- }
320
- }
386
+ if (validators) {
387
+ const paramsForValidation = Object.keys(validators).filter(
388
+ (key) => Object.prototype.hasOwnProperty.call(validators, key)
389
+ );
390
+ for (const paramKey of paramsForValidation) {
391
+ const value = params[paramKey];
392
+ const validator = validators[paramKey];
393
+ if (validator?.validate && !validator.validate(value)) {
394
+ return httpBadRequest({
395
+ code: "BAD_REQUEST",
396
+ message: validator.message ? validator.message(value) : "\uC798\uBABB\uB41C \uC694\uCCAD\uC785\uB2C8\uB2E4."
397
+ });
321
398
  }
322
- const itemId = params.id || v4();
323
- if (!params.id && existingConditions) {
324
- const paramsForExistenceCheck = Object.keys(
325
- existingConditions
326
- ).filter(
327
- (key) => Object.prototype.hasOwnProperty.call(params, key)
328
- );
329
- if (paramsForExistenceCheck.length > 0) {
330
- const where = and(
331
- ...paramsForExistenceCheck.reduce((acc, key) => {
332
- const condition = existingConditions[key];
333
- if (condition) {
334
- acc.push(condition(params[key]));
335
- }
336
- return acc;
337
- }, [])
338
- );
339
- const existing = await repository.findAll({
340
- limit: 1,
341
- where
342
- });
343
- if (existing.length > 0) {
344
- return httpConflict({
345
- code: "CONFLICT",
346
- message: "\uC790\uB8CC\uAC00 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4."
347
- });
399
+ }
400
+ }
401
+ if (!params.id && existingConditions) {
402
+ const paramsForExistenceCheck = Object.keys(existingConditions).filter(
403
+ (key) => Object.prototype.hasOwnProperty.call(params, key)
404
+ );
405
+ if (paramsForExistenceCheck.length > 0) {
406
+ const where = and(
407
+ ...paramsForExistenceCheck.reduce((acc, key) => {
408
+ const condition = existingConditions[key];
409
+ if (condition) {
410
+ acc.push(condition(params[key]));
348
411
  }
349
- }
412
+ return acc;
413
+ }, [])
414
+ );
415
+ const existing = await repository.findAll({
416
+ limit: 1,
417
+ where
418
+ });
419
+ if (existing.length > 0) {
420
+ return httpConflict();
350
421
  }
351
- const values = {
352
- id: itemId,
353
- userId: injectUserId ? auth?.userId : void 0,
354
- ...params
355
- };
356
- const item = await repository.save(values);
357
- return httpCreated(item);
358
422
  }
359
- default:
360
- throw httpMethodNotAllowed({
361
- code: "METHOD_NOT_ALLOWED",
362
- message: "\uD5C8\uC6A9\uB418\uC9C0 \uC54A\uC740 \uBA54\uC11C\uB4DC\uC785\uB2C8\uB2E4."
363
- });
364
423
  }
365
- });
366
- return {
367
- loader,
368
- action
424
+ const values = {
425
+ id: itemId,
426
+ userId: injectUserId ? auth?.userId : void 0,
427
+ ...params
428
+ };
429
+ const item = await repository.save(values);
430
+ return httpCreated(item);
369
431
  };
370
432
  }
371
433
 
372
- // src/api/item_api_handler.ts
373
- import {
374
- httpForbidden,
375
- httpMethodNotAllowed as httpMethodNotAllowed2,
376
- httpNoContent,
377
- httpNotFound as httpNotFound2,
378
- httpUnauthorized as httpUnauthorized2
379
- } from "gw-response";
380
- import { ok } from "gw-result";
381
- function itemApiHandler({
434
+ // src/api/resource_handler.ts
435
+ function resourceHandler({
382
436
  withAuthAction,
383
437
  repository,
384
- isOwnedBy,
385
- roles
438
+ validators,
439
+ existingConditions,
440
+ injectUserId,
441
+ roles,
442
+ isOwnedBy
386
443
  }) {
387
444
  const loader = async ({ request }) => {
388
445
  return ok({});
389
446
  };
390
- const action = withAuthAction((auth) => async ({ params, request }) => {
447
+ const action = withAuthAction((auth) => async ({ request, params }) => {
391
448
  if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
392
- return httpUnauthorized2({
393
- code: "UNAUTHORIZED",
394
- message: "\uC778\uC99D\uC774 \uD544\uC694\uD569\uB2C8\uB2E4."
395
- });
396
- }
397
- const itemId = params.itemId;
398
- const existing = await repository.find(itemId);
399
- if (!existing) {
400
- return httpNotFound2({
401
- code: "RESOURCE_NOT_FOUND",
402
- message: "\uC790\uB8CC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."
403
- });
404
- }
405
- if (isOwnedBy && !isOwnedBy(existing, auth)) {
406
- return httpForbidden({
449
+ return httpForbidden2({
407
450
  code: "FORBIDDEN",
408
451
  message: "\uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4."
409
452
  });
410
453
  }
454
+ const itemId = params.itemId;
455
+ if (itemId) {
456
+ const existing = await repository.find(itemId);
457
+ if (!existing) {
458
+ return httpNotFound3();
459
+ }
460
+ if (isOwnedBy && (!auth || !isOwnedBy(auth, existing))) {
461
+ return httpForbidden2();
462
+ }
463
+ switch (request.method) {
464
+ case "DELETE": {
465
+ await repository.delete(itemId);
466
+ return httpNoContent();
467
+ }
468
+ default: {
469
+ return httpMethodNotAllowed();
470
+ }
471
+ }
472
+ }
411
473
  switch (request.method) {
412
- case "DELETE": {
413
- await repository.delete(itemId);
414
- return httpNoContent();
474
+ case "POST":
475
+ case "PUT": {
476
+ const handler = putResourceHandler({
477
+ repository,
478
+ validators,
479
+ existingConditions,
480
+ injectUserId,
481
+ isOwnedBy
482
+ });
483
+ return handler(auth, request);
415
484
  }
416
485
  default: {
417
- return httpMethodNotAllowed2({
418
- code: "METHOD_NOT_ALLOWED",
419
- message: "\uD5C8\uC6A9\uB418\uC9C0 \uC54A\uC740 \uBA54\uC11C\uB4DC\uC785\uB2C8\uB2E4."
420
- });
486
+ return httpMethodNotAllowed();
421
487
  }
422
488
  }
423
489
  });
@@ -427,7 +493,7 @@ function itemApiHandler({
427
493
  };
428
494
  }
429
495
  export {
430
- apiHandler,
431
- createAPIHandler,
432
- itemApiHandler
496
+ defaultAPIHandler,
497
+ putResourceHandler,
498
+ resourceHandler
433
499
  };
@@ -0,0 +1,25 @@
1
+ import { InferSelectModel, SQLWrapper } from 'drizzle-orm';
2
+ import { AccessTokenPayload } from 'gw-auth';
3
+ import { PgTableWithColumns } from 'drizzle-orm/pg-core';
4
+ import { TableRepository } from '../table/repository.mjs';
5
+ import 'drizzle-orm/node-postgres';
6
+
7
+ type PutResourceValidators<T extends PgTableWithColumns<any>> = {
8
+ [K in keyof InferSelectModel<T>]?: {
9
+ validate?: (value?: InferSelectModel<T>[K]) => boolean;
10
+ message?: (value?: InferSelectModel<T>[K]) => string;
11
+ };
12
+ };
13
+ type PutResourceExistingConditions<T extends PgTableWithColumns<any>> = {
14
+ [K in keyof InferSelectModel<T>]?: (value: InferSelectModel<T>[K]) => SQLWrapper;
15
+ };
16
+ type PutResourceHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
17
+ repository: TableRepository<T, TSelect>;
18
+ validators?: PutResourceValidators<T>;
19
+ existingConditions?: PutResourceExistingConditions<T>;
20
+ injectUserId?: boolean;
21
+ isOwnedBy?: (auth: AccessTokenPayload, item: TSelect) => boolean;
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>;
24
+
25
+ export { type PutResourceExistingConditions, type PutResourceHandlerOptions, type PutResourceValidators, putResourceHandler };
@@ -0,0 +1,25 @@
1
+ import { InferSelectModel, SQLWrapper } from 'drizzle-orm';
2
+ import { AccessTokenPayload } from 'gw-auth';
3
+ import { PgTableWithColumns } from 'drizzle-orm/pg-core';
4
+ import { TableRepository } from '../table/repository.js';
5
+ import 'drizzle-orm/node-postgres';
6
+
7
+ type PutResourceValidators<T extends PgTableWithColumns<any>> = {
8
+ [K in keyof InferSelectModel<T>]?: {
9
+ validate?: (value?: InferSelectModel<T>[K]) => boolean;
10
+ message?: (value?: InferSelectModel<T>[K]) => string;
11
+ };
12
+ };
13
+ type PutResourceExistingConditions<T extends PgTableWithColumns<any>> = {
14
+ [K in keyof InferSelectModel<T>]?: (value: InferSelectModel<T>[K]) => SQLWrapper;
15
+ };
16
+ type PutResourceHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
17
+ repository: TableRepository<T, TSelect>;
18
+ validators?: PutResourceValidators<T>;
19
+ existingConditions?: PutResourceExistingConditions<T>;
20
+ injectUserId?: boolean;
21
+ isOwnedBy?: (auth: AccessTokenPayload, item: TSelect) => boolean;
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>;
24
+
25
+ export { type PutResourceExistingConditions, type PutResourceHandlerOptions, type PutResourceValidators, putResourceHandler };
@@ -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
+ });