dn-react-router-toolkit 0.7.14 → 0.8.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.
- package/dist/api/create_api_handler.d.mts +5 -4
- package/dist/api/create_api_handler.d.ts +5 -4
- package/dist/api/create_api_handler.js +0 -1
- package/dist/api/create_api_handler.mjs +0 -1
- package/dist/api/index.d.mts +1 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +0 -2
- package/dist/api/index.mjs +0 -2
- package/dist/api/item_api_handler.d.mts +5 -4
- package/dist/api/item_api_handler.d.ts +5 -4
- package/dist/api/item_api_handler.js +0 -1
- package/dist/api/item_api_handler.mjs +0 -1
- package/dist/auth/cookie_manager.d.mts +2 -1
- package/dist/auth/cookie_manager.d.ts +2 -1
- package/dist/auth/cookie_manager.js +9 -3
- package/dist/auth/cookie_manager.mjs +9 -3
- package/dist/auth/index.js +9 -3
- package/dist/auth/index.mjs +9 -3
- package/dist/crud/crud_form.js +1 -1
- package/dist/crud/crud_form.mjs +1 -1
- package/dist/crud/crud_loader.d.mts +6 -5
- package/dist/crud/crud_loader.d.ts +6 -5
- package/dist/crud/crud_loader.js +46 -34
- package/dist/crud/crud_loader.mjs +46 -34
- package/dist/crud/crud_page.d.mts +3 -2
- package/dist/crud/crud_page.d.ts +3 -2
- package/dist/crud/crud_page.js +226 -198
- package/dist/crud/crud_page.mjs +224 -202
- package/dist/crud/generate_handlers.d.mts +3 -2
- package/dist/crud/generate_handlers.d.ts +3 -2
- package/dist/crud/generate_pages.d.mts +2 -1
- package/dist/crud/generate_pages.d.ts +2 -1
- package/dist/crud/index.d.mts +5 -3
- package/dist/crud/index.d.ts +5 -3
- package/dist/crud/index.js +246 -206
- package/dist/crud/index.mjs +252 -218
- package/dist/post/index.js +65 -58
- package/dist/post/index.mjs +68 -67
- package/dist/post/post_form_page.js +65 -58
- package/dist/post/post_form_page.mjs +68 -67
- package/dist/table/index.d.mts +7 -3
- package/dist/table/index.d.ts +7 -3
- package/dist/table/index.js +153 -105
- package/dist/table/index.mjs +149 -110
- package/dist/table/item_loader.d.mts +5 -4
- package/dist/table/item_loader.d.ts +5 -4
- package/dist/table/load_table.d.mts +30 -0
- package/dist/table/load_table.d.ts +30 -0
- package/dist/table/load_table.js +67 -0
- package/dist/table/load_table.mjs +45 -0
- package/dist/table/loader.d.mts +7 -15
- package/dist/table/loader.d.ts +7 -15
- package/dist/table/loader.js +47 -31
- package/dist/table/loader.mjs +46 -32
- package/dist/table/page.d.mts +6 -16
- package/dist/table/page.d.ts +6 -16
- package/dist/table/page.js +193 -165
- package/dist/table/page.mjs +194 -172
- package/dist/table/repository.d.mts +13 -11
- package/dist/table/repository.d.ts +13 -11
- package/dist/table/repository.js +1 -1
- package/dist/table/repository.mjs +1 -1
- package/dist/table/table_form.d.mts +13 -0
- package/dist/table/table_form.d.ts +13 -0
- package/dist/table/table_form.js +295 -0
- package/dist/table/table_form.mjs +270 -0
- package/dist/table/use_table.d.mts +4 -0
- package/dist/table/use_table.d.ts +4 -0
- package/dist/table/use_table.js +43 -0
- package/dist/table/use_table.mjs +18 -0
- package/package.json +3 -3
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InferSelectModel, SQLWrapper } from 'drizzle-orm';
|
|
2
2
|
import { ActionFunctionArgs, LoaderFunctionArgs } from 'react-router';
|
|
3
3
|
import { TableRepository } from '../table/repository.mjs';
|
|
4
|
+
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
4
5
|
import { WithAuthHandler } from '../auth/with_auth.mjs';
|
|
5
|
-
import 'drizzle-orm/
|
|
6
|
+
import 'drizzle-orm/node-postgres';
|
|
6
7
|
import 'dn-react-toolkit/auth';
|
|
7
8
|
import 'dn-react-toolkit/auth/server';
|
|
8
9
|
|
|
9
|
-
type APIHandlerOptions<T extends
|
|
10
|
+
type APIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
10
11
|
withAuthAction: WithAuthHandler<ActionFunctionArgs>;
|
|
11
12
|
repository: TableRepository<T, TSelect>;
|
|
12
13
|
validators?: {
|
|
@@ -21,7 +22,7 @@ type APIHandlerOptions<T extends Table, TSelect> = {
|
|
|
21
22
|
injectUserId?: boolean;
|
|
22
23
|
roles?: string[];
|
|
23
24
|
};
|
|
24
|
-
declare function apiHandler<T extends
|
|
25
|
+
declare function apiHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, validators, existingConditions, injectUserId, roles, }: APIHandlerOptions<T, TSelect>): {
|
|
25
26
|
loader: ({ request }: LoaderFunctionArgs) => Promise<{}>;
|
|
26
27
|
action: (arg: ActionFunctionArgs<any>) => Promise<unknown> | unknown;
|
|
27
28
|
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InferSelectModel, SQLWrapper } from 'drizzle-orm';
|
|
2
2
|
import { ActionFunctionArgs, LoaderFunctionArgs } from 'react-router';
|
|
3
3
|
import { TableRepository } from '../table/repository.js';
|
|
4
|
+
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
4
5
|
import { WithAuthHandler } from '../auth/with_auth.js';
|
|
5
|
-
import 'drizzle-orm/
|
|
6
|
+
import 'drizzle-orm/node-postgres';
|
|
6
7
|
import 'dn-react-toolkit/auth';
|
|
7
8
|
import 'dn-react-toolkit/auth/server';
|
|
8
9
|
|
|
9
|
-
type APIHandlerOptions<T extends
|
|
10
|
+
type APIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
10
11
|
withAuthAction: WithAuthHandler<ActionFunctionArgs>;
|
|
11
12
|
repository: TableRepository<T, TSelect>;
|
|
12
13
|
validators?: {
|
|
@@ -21,7 +22,7 @@ type APIHandlerOptions<T extends Table, TSelect> = {
|
|
|
21
22
|
injectUserId?: boolean;
|
|
22
23
|
roles?: string[];
|
|
23
24
|
};
|
|
24
|
-
declare function apiHandler<T extends
|
|
25
|
+
declare function apiHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, validators, existingConditions, injectUserId, roles, }: APIHandlerOptions<T, TSelect>): {
|
|
25
26
|
loader: ({ request }: LoaderFunctionArgs) => Promise<{}>;
|
|
26
27
|
action: (arg: ActionFunctionArgs<any>) => Promise<unknown> | unknown;
|
|
27
28
|
};
|
|
@@ -25,7 +25,6 @@ __export(create_api_handler_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(create_api_handler_exports);
|
|
26
26
|
var import_http = require("dn-react-toolkit/http");
|
|
27
27
|
var import_drizzle_orm = require("drizzle-orm");
|
|
28
|
-
var import_react_router = require("react-router");
|
|
29
28
|
var import_uuid = require("uuid");
|
|
30
29
|
|
|
31
30
|
// src/crud/serialize.ts
|
package/dist/api/index.d.mts
CHANGED
|
@@ -6,6 +6,7 @@ import 'dn-react-toolkit/auth/server';
|
|
|
6
6
|
import 'dn-react-toolkit/file/server';
|
|
7
7
|
import 'drizzle-orm';
|
|
8
8
|
import '../table/repository.mjs';
|
|
9
|
+
import 'drizzle-orm/node-postgres';
|
|
9
10
|
import 'drizzle-orm/pg-core';
|
|
10
11
|
import '../auth/with_auth.mjs';
|
|
11
12
|
import 'dn-react-toolkit/auth';
|
package/dist/api/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import 'dn-react-toolkit/auth/server';
|
|
|
6
6
|
import 'dn-react-toolkit/file/server';
|
|
7
7
|
import 'drizzle-orm';
|
|
8
8
|
import '../table/repository.js';
|
|
9
|
+
import 'drizzle-orm/node-postgres';
|
|
9
10
|
import 'drizzle-orm/pg-core';
|
|
10
11
|
import '../auth/with_auth.js';
|
|
11
12
|
import 'dn-react-toolkit/auth';
|
package/dist/api/index.js
CHANGED
|
@@ -250,7 +250,6 @@ var createAPIHandler = ({
|
|
|
250
250
|
// src/api/create_api_handler.ts
|
|
251
251
|
var import_http2 = require("dn-react-toolkit/http");
|
|
252
252
|
var import_drizzle_orm = require("drizzle-orm");
|
|
253
|
-
var import_react_router2 = require("react-router");
|
|
254
253
|
var import_uuid = require("uuid");
|
|
255
254
|
|
|
256
255
|
// src/crud/serialize.ts
|
|
@@ -378,7 +377,6 @@ function apiHandler({
|
|
|
378
377
|
|
|
379
378
|
// src/api/item_api_handler.ts
|
|
380
379
|
var import_http3 = require("dn-react-toolkit/http");
|
|
381
|
-
var import_react_router3 = require("react-router");
|
|
382
380
|
function itemApiHandler({
|
|
383
381
|
withAuthAction,
|
|
384
382
|
repository
|
package/dist/api/index.mjs
CHANGED
|
@@ -245,7 +245,6 @@ import {
|
|
|
245
245
|
import {
|
|
246
246
|
and
|
|
247
247
|
} from "drizzle-orm";
|
|
248
|
-
import "react-router";
|
|
249
248
|
import { v4 } from "uuid";
|
|
250
249
|
|
|
251
250
|
// src/crud/serialize.ts
|
|
@@ -373,7 +372,6 @@ function apiHandler({
|
|
|
373
372
|
|
|
374
373
|
// src/api/item_api_handler.ts
|
|
375
374
|
import { UNAUTHORIZED as UNAUTHORIZED2 } from "dn-react-toolkit/http";
|
|
376
|
-
import "react-router";
|
|
377
375
|
function itemApiHandler({
|
|
378
376
|
withAuthAction,
|
|
379
377
|
repository
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { Table } from 'drizzle-orm';
|
|
2
1
|
import { LoaderFunctionArgs } from 'react-router';
|
|
3
2
|
import { TableRepository } from '../table/repository.mjs';
|
|
3
|
+
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
4
4
|
import { WithAuthHandler } from '../auth/with_auth.mjs';
|
|
5
|
-
import 'drizzle-orm
|
|
5
|
+
import 'drizzle-orm';
|
|
6
|
+
import 'drizzle-orm/node-postgres';
|
|
6
7
|
import 'dn-react-toolkit/auth';
|
|
7
8
|
import 'dn-react-toolkit/auth/server';
|
|
8
9
|
|
|
9
|
-
type ItemAPIHandlerOptions<T extends
|
|
10
|
+
type ItemAPIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
10
11
|
withAuthAction: WithAuthHandler<LoaderFunctionArgs>;
|
|
11
12
|
repository: TableRepository<T, TSelect>;
|
|
12
13
|
};
|
|
13
|
-
declare function itemApiHandler<T extends
|
|
14
|
+
declare function itemApiHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, }: ItemAPIHandlerOptions<T, TSelect>): {
|
|
14
15
|
loader: ({ request }: LoaderFunctionArgs) => Promise<{}>;
|
|
15
16
|
action: (arg: LoaderFunctionArgs<any>) => Promise<unknown> | unknown;
|
|
16
17
|
};
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { Table } from 'drizzle-orm';
|
|
2
1
|
import { LoaderFunctionArgs } from 'react-router';
|
|
3
2
|
import { TableRepository } from '../table/repository.js';
|
|
3
|
+
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
4
4
|
import { WithAuthHandler } from '../auth/with_auth.js';
|
|
5
|
-
import 'drizzle-orm
|
|
5
|
+
import 'drizzle-orm';
|
|
6
|
+
import 'drizzle-orm/node-postgres';
|
|
6
7
|
import 'dn-react-toolkit/auth';
|
|
7
8
|
import 'dn-react-toolkit/auth/server';
|
|
8
9
|
|
|
9
|
-
type ItemAPIHandlerOptions<T extends
|
|
10
|
+
type ItemAPIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
10
11
|
withAuthAction: WithAuthHandler<LoaderFunctionArgs>;
|
|
11
12
|
repository: TableRepository<T, TSelect>;
|
|
12
13
|
};
|
|
13
|
-
declare function itemApiHandler<T extends
|
|
14
|
+
declare function itemApiHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, }: ItemAPIHandlerOptions<T, TSelect>): {
|
|
14
15
|
loader: ({ request }: LoaderFunctionArgs) => Promise<{}>;
|
|
15
16
|
action: (arg: LoaderFunctionArgs<any>) => Promise<unknown> | unknown;
|
|
16
17
|
};
|
|
@@ -24,7 +24,6 @@ __export(item_api_handler_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(item_api_handler_exports);
|
|
26
26
|
var import_http = require("dn-react-toolkit/http");
|
|
27
|
-
var import_react_router = require("react-router");
|
|
28
27
|
function itemApiHandler({
|
|
29
28
|
withAuthAction,
|
|
30
29
|
repository
|
|
@@ -6,7 +6,8 @@ declare class ReactRouterCookieManager implements CookieManager {
|
|
|
6
6
|
options: SerializeOptions;
|
|
7
7
|
private cookie;
|
|
8
8
|
constructor(name: string);
|
|
9
|
-
|
|
9
|
+
parseFromRequest(request: Request, parseOptions?: ParseOptions | undefined): Promise<string | undefined>;
|
|
10
|
+
parse(cookieHeader: string, parseOptions?: ParseOptions | undefined): Promise<string | undefined>;
|
|
10
11
|
serialize(value: string | undefined, serializeOptions?: SerializeOptions | undefined): Promise<string>;
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -6,7 +6,8 @@ declare class ReactRouterCookieManager implements CookieManager {
|
|
|
6
6
|
options: SerializeOptions;
|
|
7
7
|
private cookie;
|
|
8
8
|
constructor(name: string);
|
|
9
|
-
|
|
9
|
+
parseFromRequest(request: Request, parseOptions?: ParseOptions | undefined): Promise<string | undefined>;
|
|
10
|
+
parse(cookieHeader: string, parseOptions?: ParseOptions | undefined): Promise<string | undefined>;
|
|
10
11
|
serialize(value: string | undefined, serializeOptions?: SerializeOptions | undefined): Promise<string>;
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -38,9 +38,15 @@ var ReactRouterCookieManager = class {
|
|
|
38
38
|
};
|
|
39
39
|
this.cookie = (0, import_react_router.createCookie)(this.name, this.options);
|
|
40
40
|
}
|
|
41
|
-
async
|
|
42
|
-
const
|
|
43
|
-
|
|
41
|
+
async parseFromRequest(request, parseOptions) {
|
|
42
|
+
const cookieHeader = request.headers.get("Cookie");
|
|
43
|
+
if (!cookieHeader) {
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
return this.parse(cookieHeader, parseOptions);
|
|
47
|
+
}
|
|
48
|
+
async parse(cookieHeader, parseOptions) {
|
|
49
|
+
return this.cookie.parse(cookieHeader, parseOptions) || void 0;
|
|
44
50
|
}
|
|
45
51
|
async serialize(value, serializeOptions) {
|
|
46
52
|
return this.cookie.serialize(value, {
|
|
@@ -14,9 +14,15 @@ var ReactRouterCookieManager = class {
|
|
|
14
14
|
};
|
|
15
15
|
this.cookie = createCookie(this.name, this.options);
|
|
16
16
|
}
|
|
17
|
-
async
|
|
18
|
-
const
|
|
19
|
-
|
|
17
|
+
async parseFromRequest(request, parseOptions) {
|
|
18
|
+
const cookieHeader = request.headers.get("Cookie");
|
|
19
|
+
if (!cookieHeader) {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
return this.parse(cookieHeader, parseOptions);
|
|
23
|
+
}
|
|
24
|
+
async parse(cookieHeader, parseOptions) {
|
|
25
|
+
return this.cookie.parse(cookieHeader, parseOptions) || void 0;
|
|
20
26
|
}
|
|
21
27
|
async serialize(value, serializeOptions) {
|
|
22
28
|
return this.cookie.serialize(value, {
|
package/dist/auth/index.js
CHANGED
|
@@ -97,9 +97,15 @@ var ReactRouterCookieManager = class {
|
|
|
97
97
|
};
|
|
98
98
|
this.cookie = (0, import_react_router.createCookie)(this.name, this.options);
|
|
99
99
|
}
|
|
100
|
-
async
|
|
101
|
-
const
|
|
102
|
-
|
|
100
|
+
async parseFromRequest(request, parseOptions) {
|
|
101
|
+
const cookieHeader = request.headers.get("Cookie");
|
|
102
|
+
if (!cookieHeader) {
|
|
103
|
+
return void 0;
|
|
104
|
+
}
|
|
105
|
+
return this.parse(cookieHeader, parseOptions);
|
|
106
|
+
}
|
|
107
|
+
async parse(cookieHeader, parseOptions) {
|
|
108
|
+
return this.cookie.parse(cookieHeader, parseOptions) || void 0;
|
|
103
109
|
}
|
|
104
110
|
async serialize(value, serializeOptions) {
|
|
105
111
|
return this.cookie.serialize(value, {
|
package/dist/auth/index.mjs
CHANGED
|
@@ -70,9 +70,15 @@ var ReactRouterCookieManager = class {
|
|
|
70
70
|
};
|
|
71
71
|
this.cookie = createCookie(this.name, this.options);
|
|
72
72
|
}
|
|
73
|
-
async
|
|
74
|
-
const
|
|
75
|
-
|
|
73
|
+
async parseFromRequest(request, parseOptions) {
|
|
74
|
+
const cookieHeader = request.headers.get("Cookie");
|
|
75
|
+
if (!cookieHeader) {
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
return this.parse(cookieHeader, parseOptions);
|
|
79
|
+
}
|
|
80
|
+
async parse(cookieHeader, parseOptions) {
|
|
81
|
+
return this.cookie.parse(cookieHeader, parseOptions) || void 0;
|
|
76
82
|
}
|
|
77
83
|
async serialize(value, serializeOptions) {
|
|
78
84
|
return this.cookie.serialize(value, {
|
package/dist/crud/crud_form.js
CHANGED
|
@@ -231,7 +231,7 @@ function CrudForm({
|
|
|
231
231
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FormRow, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(FormEntry, { children: [
|
|
232
232
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FormLabel, { children: value.label }, name),
|
|
233
233
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(InputComponent, {})
|
|
234
|
-
] }) });
|
|
234
|
+
] }) }, name);
|
|
235
235
|
}
|
|
236
236
|
) }) })
|
|
237
237
|
] });
|
package/dist/crud/crud_form.mjs
CHANGED
|
@@ -212,7 +212,7 @@ function CrudForm({
|
|
|
212
212
|
return /* @__PURE__ */ jsx6(FormRow, { children: /* @__PURE__ */ jsxs2(FormEntry, { children: [
|
|
213
213
|
/* @__PURE__ */ jsx6(FormLabel, { children: value.label }, name),
|
|
214
214
|
/* @__PURE__ */ jsx6(InputComponent, {})
|
|
215
|
-
] }) });
|
|
215
|
+
] }) }, name);
|
|
216
216
|
}
|
|
217
217
|
) }) })
|
|
218
218
|
] });
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { LoaderFunctionArgs, LoaderFunction } from 'react-router';
|
|
2
|
-
import { TableLoaderOptions } from '../table/loader.mjs';
|
|
3
2
|
import { TableItemLoaderOptions } from '../table/item_loader.mjs';
|
|
4
|
-
import { Table } from 'drizzle-orm';
|
|
5
3
|
import { TableRepository } from '../table/repository.mjs';
|
|
4
|
+
import { TableLoaderOptions } from '../table/load_table.mjs';
|
|
5
|
+
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
6
6
|
import { APIHandlerOptions } from '../api/create_api_handler.mjs';
|
|
7
|
-
import 'drizzle-orm
|
|
7
|
+
import 'drizzle-orm';
|
|
8
|
+
import 'drizzle-orm/node-postgres';
|
|
8
9
|
import '../auth/with_auth.mjs';
|
|
9
10
|
import 'dn-react-toolkit/auth';
|
|
10
11
|
import 'dn-react-toolkit/auth/server';
|
|
11
12
|
|
|
12
|
-
type CrudHandlerOptions<T extends
|
|
13
|
+
type CrudHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
13
14
|
repository: TableRepository<T, TSelect>;
|
|
14
15
|
apiHandlerOptions: Omit<APIHandlerOptions<T, TSelect>, "repository">;
|
|
15
16
|
loaderOptions: Omit<TableLoaderOptions<T, TSelect>, "repository"> & {
|
|
@@ -20,6 +21,6 @@ type CrudHandlerOptions<T extends Table, TSelect> = {
|
|
|
20
21
|
};
|
|
21
22
|
};
|
|
22
23
|
type CrudHandler = (prefix: string) => (args: LoaderFunctionArgs) => Promise<any>;
|
|
23
|
-
declare function crudHandler<T extends
|
|
24
|
+
declare function crudHandler<T extends PgTableWithColumns<any>, TSelect>({ repository, apiHandlerOptions, loaderOptions, itemLoaderOptions, }: CrudHandlerOptions<T, TSelect>): (prefix: string) => (args: LoaderFunctionArgs) => Promise<unknown>;
|
|
24
25
|
|
|
25
26
|
export { type CrudHandler, type CrudHandlerOptions, crudHandler };
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { LoaderFunctionArgs, LoaderFunction } from 'react-router';
|
|
2
|
-
import { TableLoaderOptions } from '../table/loader.js';
|
|
3
2
|
import { TableItemLoaderOptions } from '../table/item_loader.js';
|
|
4
|
-
import { Table } from 'drizzle-orm';
|
|
5
3
|
import { TableRepository } from '../table/repository.js';
|
|
4
|
+
import { TableLoaderOptions } from '../table/load_table.js';
|
|
5
|
+
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
6
6
|
import { APIHandlerOptions } from '../api/create_api_handler.js';
|
|
7
|
-
import 'drizzle-orm
|
|
7
|
+
import 'drizzle-orm';
|
|
8
|
+
import 'drizzle-orm/node-postgres';
|
|
8
9
|
import '../auth/with_auth.js';
|
|
9
10
|
import 'dn-react-toolkit/auth';
|
|
10
11
|
import 'dn-react-toolkit/auth/server';
|
|
11
12
|
|
|
12
|
-
type CrudHandlerOptions<T extends
|
|
13
|
+
type CrudHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
13
14
|
repository: TableRepository<T, TSelect>;
|
|
14
15
|
apiHandlerOptions: Omit<APIHandlerOptions<T, TSelect>, "repository">;
|
|
15
16
|
loaderOptions: Omit<TableLoaderOptions<T, TSelect>, "repository"> & {
|
|
@@ -20,6 +21,6 @@ type CrudHandlerOptions<T extends Table, TSelect> = {
|
|
|
20
21
|
};
|
|
21
22
|
};
|
|
22
23
|
type CrudHandler = (prefix: string) => (args: LoaderFunctionArgs) => Promise<any>;
|
|
23
|
-
declare function crudHandler<T extends
|
|
24
|
+
declare function crudHandler<T extends PgTableWithColumns<any>, TSelect>({ repository, apiHandlerOptions, loaderOptions, itemLoaderOptions, }: CrudHandlerOptions<T, TSelect>): (prefix: string) => (args: LoaderFunctionArgs) => Promise<unknown>;
|
|
24
25
|
|
|
25
26
|
export { type CrudHandler, type CrudHandlerOptions, crudHandler };
|
package/dist/crud/crud_loader.js
CHANGED
|
@@ -24,45 +24,59 @@ __export(crud_loader_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(crud_loader_exports);
|
|
26
26
|
|
|
27
|
-
// src/table/
|
|
27
|
+
// src/table/load_table.tsx
|
|
28
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 whereClauses = (0, import_drizzle_orm.and)(
|
|
42
|
+
searchKey && query ? (0, import_drizzle_orm.ilike)(
|
|
43
|
+
repository.schema[searchKey],
|
|
44
|
+
`%${query}%`
|
|
45
|
+
) : void 0,
|
|
46
|
+
...where ?? []
|
|
47
|
+
);
|
|
48
|
+
const total = await repository.countTotal({ where: whereClauses });
|
|
49
|
+
const items = await repository.findAll({
|
|
50
|
+
orderBy,
|
|
51
|
+
direction,
|
|
52
|
+
limit,
|
|
53
|
+
offset,
|
|
54
|
+
where: whereClauses
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
items,
|
|
58
|
+
total,
|
|
59
|
+
limit,
|
|
60
|
+
offset,
|
|
61
|
+
orderBy,
|
|
62
|
+
direction,
|
|
63
|
+
searchKey
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/table/loader.tsx
|
|
29
68
|
function tableLoader({
|
|
30
69
|
repository,
|
|
31
|
-
|
|
70
|
+
options
|
|
32
71
|
}) {
|
|
33
72
|
return async ({ request }) => {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const offset = Number(searchParams.get("offset") ?? "0");
|
|
39
|
-
const orderBy = searchParams.get("orderBy") ?? defaultOrderBy;
|
|
40
|
-
const direction = searchParams.get("direction") ?? defaultDirection;
|
|
41
|
-
const whereClauses = (0, import_drizzle_orm.and)(
|
|
42
|
-
searchKey && query ? (0, import_drizzle_orm.ilike)(
|
|
43
|
-
repository.schema[searchKey],
|
|
44
|
-
`%${query}%`
|
|
45
|
-
) : void 0,
|
|
46
|
-
...where ?? []
|
|
47
|
-
);
|
|
48
|
-
const total = await repository.countTotal({ where: whereClauses });
|
|
49
|
-
const items = await repository.findAll({
|
|
50
|
-
orderBy,
|
|
51
|
-
direction,
|
|
52
|
-
limit,
|
|
53
|
-
offset,
|
|
54
|
-
where: whereClauses
|
|
73
|
+
const table = await loadTable({
|
|
74
|
+
request,
|
|
75
|
+
repository,
|
|
76
|
+
options
|
|
55
77
|
});
|
|
56
78
|
return {
|
|
57
|
-
table
|
|
58
|
-
items,
|
|
59
|
-
total,
|
|
60
|
-
limit,
|
|
61
|
-
offset,
|
|
62
|
-
orderBy,
|
|
63
|
-
direction,
|
|
64
|
-
searchKey
|
|
65
|
-
}
|
|
79
|
+
table
|
|
66
80
|
};
|
|
67
81
|
};
|
|
68
82
|
}
|
|
@@ -86,7 +100,6 @@ var tableItemloader = ({
|
|
|
86
100
|
// src/api/create_api_handler.ts
|
|
87
101
|
var import_http = require("dn-react-toolkit/http");
|
|
88
102
|
var import_drizzle_orm2 = require("drizzle-orm");
|
|
89
|
-
var import_react_router = require("react-router");
|
|
90
103
|
var import_uuid = require("uuid");
|
|
91
104
|
|
|
92
105
|
// src/crud/serialize.ts
|
|
@@ -214,7 +227,6 @@ function apiHandler({
|
|
|
214
227
|
|
|
215
228
|
// src/api/item_api_handler.ts
|
|
216
229
|
var import_http2 = require("dn-react-toolkit/http");
|
|
217
|
-
var import_react_router2 = require("react-router");
|
|
218
230
|
function itemApiHandler({
|
|
219
231
|
withAuthAction,
|
|
220
232
|
repository
|
|
@@ -1,45 +1,59 @@
|
|
|
1
|
-
// src/table/
|
|
1
|
+
// src/table/load_table.tsx
|
|
2
2
|
import {
|
|
3
3
|
and,
|
|
4
4
|
ilike
|
|
5
5
|
} from "drizzle-orm";
|
|
6
|
+
async function loadTable({
|
|
7
|
+
request,
|
|
8
|
+
repository,
|
|
9
|
+
options
|
|
10
|
+
}) {
|
|
11
|
+
const searchParams = new URL(request.url).searchParams;
|
|
12
|
+
const { where, searchKey, defaultOrderBy, defaultDirection } = options;
|
|
13
|
+
const query = searchParams.get("query") ?? void 0;
|
|
14
|
+
const limit = Number(searchParams.get("limit") ?? "20");
|
|
15
|
+
const offset = Number(searchParams.get("offset") ?? "0");
|
|
16
|
+
const orderBy = searchParams.get("orderBy") ?? defaultOrderBy;
|
|
17
|
+
const direction = searchParams.get("direction") ?? defaultDirection;
|
|
18
|
+
const whereClauses = and(
|
|
19
|
+
searchKey && query ? ilike(
|
|
20
|
+
repository.schema[searchKey],
|
|
21
|
+
`%${query}%`
|
|
22
|
+
) : void 0,
|
|
23
|
+
...where ?? []
|
|
24
|
+
);
|
|
25
|
+
const total = await repository.countTotal({ where: whereClauses });
|
|
26
|
+
const items = await repository.findAll({
|
|
27
|
+
orderBy,
|
|
28
|
+
direction,
|
|
29
|
+
limit,
|
|
30
|
+
offset,
|
|
31
|
+
where: whereClauses
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
items,
|
|
35
|
+
total,
|
|
36
|
+
limit,
|
|
37
|
+
offset,
|
|
38
|
+
orderBy,
|
|
39
|
+
direction,
|
|
40
|
+
searchKey
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/table/loader.tsx
|
|
6
45
|
function tableLoader({
|
|
7
46
|
repository,
|
|
8
|
-
|
|
47
|
+
options
|
|
9
48
|
}) {
|
|
10
49
|
return async ({ request }) => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const offset = Number(searchParams.get("offset") ?? "0");
|
|
16
|
-
const orderBy = searchParams.get("orderBy") ?? defaultOrderBy;
|
|
17
|
-
const direction = searchParams.get("direction") ?? defaultDirection;
|
|
18
|
-
const whereClauses = and(
|
|
19
|
-
searchKey && query ? ilike(
|
|
20
|
-
repository.schema[searchKey],
|
|
21
|
-
`%${query}%`
|
|
22
|
-
) : void 0,
|
|
23
|
-
...where ?? []
|
|
24
|
-
);
|
|
25
|
-
const total = await repository.countTotal({ where: whereClauses });
|
|
26
|
-
const items = await repository.findAll({
|
|
27
|
-
orderBy,
|
|
28
|
-
direction,
|
|
29
|
-
limit,
|
|
30
|
-
offset,
|
|
31
|
-
where: whereClauses
|
|
50
|
+
const table = await loadTable({
|
|
51
|
+
request,
|
|
52
|
+
repository,
|
|
53
|
+
options
|
|
32
54
|
});
|
|
33
55
|
return {
|
|
34
|
-
table
|
|
35
|
-
items,
|
|
36
|
-
total,
|
|
37
|
-
limit,
|
|
38
|
-
offset,
|
|
39
|
-
orderBy,
|
|
40
|
-
direction,
|
|
41
|
-
searchKey
|
|
42
|
-
}
|
|
56
|
+
table
|
|
43
57
|
};
|
|
44
58
|
};
|
|
45
59
|
}
|
|
@@ -72,7 +86,6 @@ import {
|
|
|
72
86
|
import {
|
|
73
87
|
and as and2
|
|
74
88
|
} from "drizzle-orm";
|
|
75
|
-
import "react-router";
|
|
76
89
|
import { v4 } from "uuid";
|
|
77
90
|
|
|
78
91
|
// src/crud/serialize.ts
|
|
@@ -200,7 +213,6 @@ function apiHandler({
|
|
|
200
213
|
|
|
201
214
|
// src/api/item_api_handler.ts
|
|
202
215
|
import { UNAUTHORIZED as UNAUTHORIZED2 } from "dn-react-toolkit/http";
|
|
203
|
-
import "react-router";
|
|
204
216
|
function itemApiHandler({
|
|
205
217
|
withAuthAction,
|
|
206
218
|
repository
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { FormContextProps, CrudFormProps } from './crud_form_provider.mjs';
|
|
2
|
-
import { TablePageOptions } from '../table/page.mjs';
|
|
3
2
|
import { FC, ReactNode } from 'react';
|
|
3
|
+
import { TablePageOptions } from '../table/table_form.mjs';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react-store-input';
|
|
6
6
|
import '../table/table.mjs';
|
|
7
|
+
import '../table/use_table.mjs';
|
|
7
8
|
|
|
8
9
|
type CrudPageOptions<TModel> = {
|
|
9
10
|
name: string;
|
|
10
11
|
primaryKey: keyof TModel;
|
|
11
|
-
tablePageOptions:
|
|
12
|
+
tablePageOptions: TablePageOptions<TModel>;
|
|
12
13
|
formOptions: {
|
|
13
14
|
form?: FC<{
|
|
14
15
|
form: FormContextProps<TModel>;
|
package/dist/crud/crud_page.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { FormContextProps, CrudFormProps } from './crud_form_provider.js';
|
|
2
|
-
import { TablePageOptions } from '../table/page.js';
|
|
3
2
|
import { FC, ReactNode } from 'react';
|
|
3
|
+
import { TablePageOptions } from '../table/table_form.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react-store-input';
|
|
6
6
|
import '../table/table.js';
|
|
7
|
+
import '../table/use_table.js';
|
|
7
8
|
|
|
8
9
|
type CrudPageOptions<TModel> = {
|
|
9
10
|
name: string;
|
|
10
11
|
primaryKey: keyof TModel;
|
|
11
|
-
tablePageOptions:
|
|
12
|
+
tablePageOptions: TablePageOptions<TModel>;
|
|
12
13
|
formOptions: {
|
|
13
14
|
form?: FC<{
|
|
14
15
|
form: FormContextProps<TModel>;
|