@niyamulahsan/create-deskapp 1.2.5 → 1.2.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.
Files changed (104) hide show
  1. package/package.json +1 -1
  2. package/template/.env.example +20 -13
  3. package/template/AGENTS.md +699 -0
  4. package/template/package.json +3 -0
  5. package/template/src/config/app.ts +26 -24
  6. package/template/src/config/winsetup.ts +93 -91
  7. package/template/src/core/api/binding-error.ts +57 -0
  8. package/template/src/core/api/bindings.generated.ts +2 -0
  9. package/template/src/core/api/generate.manifest.ts +84 -80
  10. package/template/src/core/api/registry.ts +58 -48
  11. package/template/src/core/config.ts +101 -99
  12. package/template/src/core/database/aggregate.ts +89 -85
  13. package/template/src/core/database/config.ts +50 -48
  14. package/template/src/core/database/connection.ts +116 -114
  15. package/template/src/core/database/migrate-hooks.ts +86 -84
  16. package/template/src/core/database/paginate.ts +226 -224
  17. package/template/src/core/database/reset.ts +21 -19
  18. package/template/src/core/database/seed.ts +169 -167
  19. package/template/src/core/database/status.ts +37 -35
  20. package/template/src/core/env.ts +108 -106
  21. package/template/src/core/facade.ts +63 -61
  22. package/template/src/core/maker/db/fresh.ts +10 -8
  23. package/template/src/core/maker/db/generate.ts +13 -11
  24. package/template/src/core/maker/db/helpers.ts +92 -96
  25. package/template/src/core/maker/db/migrate.ts +37 -35
  26. package/template/src/core/maker/db/mod.ts +93 -91
  27. package/template/src/core/maker/db/module-migrate.ts +56 -54
  28. package/template/src/core/maker/db/push.ts +23 -21
  29. package/template/src/core/maker/db/reset.ts +8 -6
  30. package/template/src/core/maker/db/seed.ts +9 -7
  31. package/template/src/core/maker/db/status.ts +8 -6
  32. package/template/src/core/maker/help.ts +59 -57
  33. package/template/src/core/maker/make/controller.ts +25 -22
  34. package/template/src/core/maker/make/helpers.ts +97 -91
  35. package/template/src/core/maker/make/mod.ts +69 -67
  36. package/template/src/core/maker/make/model.ts +16 -14
  37. package/template/src/core/maker/make/module.ts +53 -39
  38. package/template/src/core/maker/make/seeder.ts +23 -21
  39. package/template/src/core/maker/make/test.ts +33 -30
  40. package/template/src/core/maker/mod.ts +85 -83
  41. package/template/src/core/maker/run/mod.ts +134 -132
  42. package/template/src/core/maker/stub.ts +26 -24
  43. package/template/src/core/maker/stubs/controller/controller.controller.stub +57 -55
  44. package/template/src/core/maker/stubs/controller/controller.schema.stub +18 -13
  45. package/template/src/core/maker/stubs/facade/facade.stub +21 -0
  46. package/template/src/core/maker/stubs/model/model.stub +10 -8
  47. package/template/src/core/maker/stubs/seeder/seeder.stub +18 -16
  48. package/template/src/core/maker/stubs/test/test.stub +9 -7
  49. package/template/src/core/maker/sync-config.ts +93 -94
  50. package/template/src/core/utils/password.ts +29 -27
  51. package/template/src/core/utils/playwright.ts +123 -121
  52. package/template/src/core/utils/queue.ts +68 -66
  53. package/template/src/core/utils/scheduler.ts +62 -60
  54. package/template/src/core/utils/storage.ts +3 -1
  55. package/template/src/core/utils/validation.ts +37 -35
  56. package/template/src/database/schema.ts +2 -0
  57. package/template/src/main.ts +120 -118
  58. package/template/src/modules/app/__tests__/demo.controller.test.ts +75 -0
  59. package/template/src/modules/app/__tests__/net.controller.test.ts +65 -0
  60. package/template/src/modules/app/__tests__/playwright.controller.test.ts +50 -0
  61. package/template/src/modules/app/__tests__/storage.controller.test.ts +114 -0
  62. package/template/src/modules/app/__tests__/window.controller.test.ts +98 -0
  63. package/template/src/modules/app/controllers/demo.controller.ts +120 -118
  64. package/template/src/modules/app/controllers/net.controller.ts +50 -48
  65. package/template/src/modules/app/controllers/playwright.controller.ts +142 -140
  66. package/template/src/modules/app/controllers/storage.controller.ts +231 -229
  67. package/template/src/modules/app/controllers/window.controller.ts +2 -0
  68. package/template/src/modules/app/facade.ts +21 -0
  69. package/template/src/preload.ts +25 -2
  70. package/template/src/ui/src/App.vue +4 -2
  71. package/template/src/ui/src/app.ts +38 -23
  72. package/template/src/ui/src/bindings.d.ts +18 -16
  73. package/template/src/ui/src/components/Button.vue +34 -32
  74. package/template/src/ui/src/components/Checkbox.vue +26 -29
  75. package/template/src/ui/src/components/Input.vue +221 -227
  76. package/template/src/ui/src/components/InputGroup.vue +141 -0
  77. package/template/src/ui/src/components/InputPasswordToggle.vue +204 -0
  78. package/template/src/ui/src/components/Modal.vue +65 -55
  79. package/template/src/ui/src/components/Spinner.vue +44 -42
  80. package/template/src/ui/src/components/Switch.vue +62 -65
  81. package/template/src/ui/src/components/TextArea.vue +108 -121
  82. package/template/src/ui/src/components/Toast.vue +55 -56
  83. package/template/src/ui/src/components/datatable/DataTableSkeleton.vue +100 -98
  84. package/template/src/ui/src/components/datatable/Pagination.vue +153 -125
  85. package/template/src/ui/src/components/datatable/SelectOpption.vue +36 -35
  86. package/template/src/ui/src/components/datatable/index.vue +336 -258
  87. package/template/src/ui/src/env.d.ts +16 -13
  88. package/template/src/ui/src/global.d.ts +21 -2
  89. package/template/src/ui/src/helpers/nformatter.ts +12 -10
  90. package/template/src/ui/src/pages/dashboard/index.vue +690 -687
  91. package/template/src/ui/src/plugins/browserDetect.ts +57 -0
  92. package/template/src/ui/src/plugins/gum.ts +576 -549
  93. package/template/src/ui/src/plugins/pulse.ts +2 -0
  94. package/template/src/ui/src/plugins/routeProgress.ts +89 -0
  95. package/template/src/ui/src/router/index.ts +44 -25
  96. package/template/src/ui/src/stores/example.ts +2 -0
  97. package/template/src/ui/vite.config.ts +40 -38
  98. package/template/src/window/app-menu.ts +89 -87
  99. package/template/src/window/config.ts +14 -12
  100. package/template/src/window/context-menu.ts +23 -21
  101. package/template/src/window/dialogs.ts +92 -90
  102. package/template/src/window/manager.ts +2 -0
  103. package/template/src/window/native.ts +47 -45
  104. package/template/src/window/tray.ts +132 -130
@@ -1,224 +1,226 @@
1
- /**
2
- * database/paginate.ts - nexgen-style pagination, mirroring nexgen's
3
- * framework/database/paginate.ts but without a request/HTTP context (bindings
4
- * call handlers directly, so pagination here is callback- or table-based).
5
- *
6
- * Core is `paginate.query`: it normalizes page/per_page, clamps with
7
- * maxPerPage, computes URL meta + links, then runs the caller's
8
- * `total()` and `data(limit, offset)` callbacks. Import from the facade:
9
- *
10
- * import { paginate } from "@/core/facade.ts";
11
- * await paginate.table(schema.users, { page: 2 });
12
- * await paginate.query({ total, data });
13
- * await paginate.model({ table: schema.users, query: db.query.users });
14
- */
15
-
16
- import { count, getTableColumns, type SQL, sql } from "drizzle-orm";
17
- import type { SQLiteTable } from "drizzle-orm/sqlite-core";
18
- import { db } from "@/core/facade";
19
-
20
- export type PaginateInput = {
21
- page?: number;
22
- perPage?: number;
23
- maxPerPage?: number;
24
- path?: string;
25
- };
26
-
27
- export type PaginatedResult<T> = {
28
- current_page: number;
29
- data: T[];
30
- first_page_url: string | null;
31
- from: number | null;
32
- last_page: number;
33
- last_page_url: string | null;
34
- next_page_url: string | null;
35
- path: string;
36
- per_page: number;
37
- prev_page_url: string | null;
38
- to: number | null;
39
- total: number;
40
- };
41
-
42
- export type PaginateQueryOptions<T> = PaginateInput & {
43
- total: () => Promise<number>;
44
- data: (limit: number, offset: number) => Promise<T[]>;
45
- };
46
-
47
- export type PaginateTableOptions = PaginateInput & {
48
- where?: SQL<unknown>;
49
- orderBy?: unknown[];
50
- };
51
-
52
- export type PaginateModelOptions<T = unknown> = PaginateInput & {
53
- table?: SQLiteTable;
54
- query?: { findMany: (args: Record<string, unknown>) => Promise<T[]> };
55
- where?: SQL<unknown>;
56
- with?: Record<string, unknown>;
57
- columns?: Record<string, unknown>;
58
- extras?: Record<string, unknown>;
59
- orderBy?: unknown;
60
- total?: () => Promise<number>;
61
- data?: (params: { limit: number; offset: number }) => Promise<T[]>;
62
- };
63
-
64
- function toPositiveInt(value: unknown, fallback: number): number {
65
- const parsed = Number(value);
66
- if (!Number.isFinite(parsed) || parsed < 1) return fallback;
67
- return Math.floor(parsed);
68
- }
69
-
70
- function pageUrl(path: string | undefined, page: number, perPage: number): string | null {
71
- if (!path) return null;
72
- const delimiter = path.includes("?") ? "&" : "?";
73
- return `${path}${delimiter}page=${page}&per_page=${perPage}`;
74
- }
75
-
76
- /**
77
- * Pagination namespace - nexgen-style envelope for Drizzle, surfaced through
78
- * the facade. Access: `paginate.query`, `paginate.table`, `paginate.model`.
79
- */
80
- export const paginate = {
81
- /**
82
- * Generic paginator for custom `total()`/`data(limit, offset)` callbacks.
83
- * Controllers/services compose any query (joins, filters, aggregates) and
84
- * get a consistent nexgen-style envelope back.
85
- */
86
- query<T = unknown>(options: PaginateQueryOptions<T>): Promise<PaginatedResult<T>> {
87
- return paginateQuery<T>(options);
88
- },
89
-
90
- /**
91
- * Paginates a full Drizzle table with optional `where` filter and `orderBy`.
92
- * Runs a count query plus the paged select. table must be a SCHEMA table
93
- * object: `import * as schema from "@/database/schema.ts"` then `schema.users`.
94
- */
95
- table<T = unknown>(table: SQLiteTable, options: PaginateTableOptions = {}): Promise<PaginatedResult<T>> {
96
- return paginateTable<T>(table, options);
97
- },
98
-
99
- /**
100
- * nexgen-style pagination for Drizzle RELATIONAL queries - mirrors nexgen's
101
- * paginateModel. Counts via `table` (+ `where`), then pages through
102
- * `db.query.<table>.findMany({ limit, offset, where, with, columns, extras,
103
- * orderBy })` for eager-loaded resources.
104
- */
105
- model<T = unknown>(options: PaginateModelOptions<T>): Promise<PaginatedResult<T>> {
106
- return paginateModel<T>(options);
107
- }
108
- };
109
-
110
- /** Generic paginator for custom `total()`/`data(limit, offset)` callbacks. */
111
- async function paginateQuery<T = unknown>(options: PaginateQueryOptions<T>): Promise<PaginatedResult<T>> {
112
- const maxPerPage = toPositiveInt(options.maxPerPage, 100);
113
- const perPage = Math.min(toPositiveInt(options.perPage, 15), maxPerPage);
114
- const page = toPositiveInt(options.page, 1);
115
-
116
- const total = Number(await options.total());
117
- const lastPage = Math.max(1, Math.ceil(total / perPage));
118
- const currentPage = Math.min(page, lastPage);
119
- const safeOffset = (currentPage - 1) * perPage;
120
- const data = await options.data(perPage, safeOffset);
121
-
122
- const from = total === 0 ? null : safeOffset + 1;
123
- const to = total === 0 ? null : safeOffset + data.length;
124
- const path = options.path || "";
125
- const firstPageUrl = pageUrl(path, 1, perPage);
126
- const lastPageUrl = pageUrl(path, lastPage, perPage);
127
- const prevPageUrl = currentPage > 1 ? pageUrl(path, currentPage - 1, perPage) : null;
128
- const nextPageUrl = currentPage < lastPage ? pageUrl(path, currentPage + 1, perPage) : null;
129
-
130
- return {
131
- current_page: currentPage,
132
- data,
133
- first_page_url: firstPageUrl,
134
- from,
135
- last_page: lastPage,
136
- last_page_url: lastPageUrl,
137
- next_page_url: nextPageUrl,
138
- path,
139
- per_page: perPage,
140
- prev_page_url: prevPageUrl,
141
- to,
142
- total
143
- };
144
- }
145
-
146
- /** Paginates a full Drizzle table with optional `where` filter and `orderBy`. */
147
- function paginateTable<T = unknown>(table: SQLiteTable, options: PaginateTableOptions = {}): Promise<PaginatedResult<T>> {
148
- return paginateQuery<T>({
149
- page: options.page,
150
- perPage: options.perPage,
151
- maxPerPage: options.maxPerPage,
152
- path: options.path,
153
- total: async () => {
154
- // deno-lint-ignore no-explicit-any
155
- let totalQuery: any = db.select({ total: count() }).from(table);
156
- if (options.where) totalQuery = totalQuery.where(options.where);
157
- const totalRow = await totalQuery;
158
- return Number(totalRow[0]?.total ?? 0);
159
- },
160
- data: (limit, offset) => {
161
- // deno-lint-ignore no-explicit-any
162
- let dataQuery: any = db.select(getTableColumns(table)).from(table);
163
- if (options.where) dataQuery = dataQuery.where(options.where);
164
- if (options.orderBy?.length) dataQuery = dataQuery.orderBy(...options.orderBy);
165
- return dataQuery.limit(limit).offset(offset);
166
- }
167
- });
168
- }
169
-
170
- /**
171
- * nexgen-style pagination for Drizzle RELATIONAL queries - mirrors nexgen's
172
- * paginateModel. Counts via `table` (+ `where`), then pages through
173
- * `db.query.<table>.findMany({ limit, offset, where, with, columns, extras,
174
- * orderBy })` for eager-loaded resources.
175
- *
176
- * Supply either callbacks (`total`/`data`) or the declarative pair
177
- * (`table` + `query`) - the same fallbacks engine uses:
178
- *
179
- * import * as schema from "@/database/schema.ts";
180
- * const page = await paginate.model({
181
- * page: 2, perPage: 15,
182
- * table: schema.users,
183
- * query: db.query.users,
184
- * where: sql`active = true`,
185
- * with: { posts: true },
186
- * orderBy: (t, { desc }) => desc(t.createdAt),
187
- * });
188
- */
189
- function paginateModel<T = unknown>(options: PaginateModelOptions<T>): Promise<PaginatedResult<T>> {
190
- return paginateQuery<T>({
191
- page: options.page,
192
- perPage: options.perPage,
193
- maxPerPage: options.maxPerPage,
194
- path: options.path,
195
- total: async () => {
196
- if (options.total) return Number(await options.total());
197
- if (!options.table) {
198
- throw new Error("paginate.model requires either table or total callback");
199
- }
200
- // deno-lint-ignore no-explicit-any
201
- let totalQuery: any = db.select({ total: count() }).from(options.table);
202
- if (options.where) totalQuery = totalQuery.where(options.where);
203
- const [row] = await totalQuery;
204
- return Number(row?.total ?? 0);
205
- },
206
- data: (limit, offset) => {
207
- if (options.data) return options.data({ limit, offset });
208
- if (!options.query) {
209
- throw new Error("paginate.model requires either query or data callback");
210
- }
211
- const args: Record<string, unknown> = { limit, offset };
212
- if (options.where) args.where = options.where;
213
- if (options.with) args.with = options.with;
214
- if (options.columns) args.columns = options.columns;
215
- if (options.extras) args.extras = options.extras;
216
- if (options.orderBy) args.orderBy = options.orderBy;
217
- return options.query.findMany(args);
218
- }
219
- });
220
- }
221
-
222
- // `sql` is re-exported so callers writing `where: sql` filters don't need a
223
- // second drizzle import: import { paginate, sql } from "@/core/facade.ts".
224
- export { sql };
1
+ // ./src/core/database/paginate.ts
2
+
3
+ /**
4
+ * database/paginate.ts - nexgen-style pagination, mirroring nexgen's
5
+ * framework/database/paginate.ts but without a request/HTTP context (bindings
6
+ * call handlers directly, so pagination here is callback- or table-based).
7
+ *
8
+ * Core is `paginate.query`: it normalizes page/per_page, clamps with
9
+ * maxPerPage, computes URL meta + links, then runs the caller's
10
+ * `total()` and `data(limit, offset)` callbacks. Import from the facade:
11
+ *
12
+ * import { paginate } from "@/core/facade.ts";
13
+ * await paginate.table(schema.users, { page: 2 });
14
+ * await paginate.query({ total, data });
15
+ * await paginate.model({ table: schema.users, query: db.query.users });
16
+ */
17
+
18
+ import { count, getTableColumns, type SQL, sql } from "drizzle-orm";
19
+ import type { SQLiteTable } from "drizzle-orm/sqlite-core";
20
+ import { db } from "@/core/facade";
21
+
22
+ export type PaginateInput = {
23
+ page?: number;
24
+ perPage?: number;
25
+ maxPerPage?: number;
26
+ path?: string;
27
+ };
28
+
29
+ export type PaginatedResult<T> = {
30
+ current_page: number;
31
+ data: T[];
32
+ first_page_url: string | null;
33
+ from: number | null;
34
+ last_page: number;
35
+ last_page_url: string | null;
36
+ next_page_url: string | null;
37
+ path: string;
38
+ per_page: number;
39
+ prev_page_url: string | null;
40
+ to: number | null;
41
+ total: number;
42
+ };
43
+
44
+ export type PaginateQueryOptions<T> = PaginateInput & {
45
+ total: () => Promise<number>;
46
+ data: (limit: number, offset: number) => Promise<T[]>;
47
+ };
48
+
49
+ export type PaginateTableOptions = PaginateInput & {
50
+ where?: SQL<unknown>;
51
+ orderBy?: unknown[];
52
+ };
53
+
54
+ export type PaginateModelOptions<T = unknown> = PaginateInput & {
55
+ table?: SQLiteTable;
56
+ query?: { findMany: (args: Record<string, unknown>) => Promise<T[]> };
57
+ where?: SQL<unknown>;
58
+ with?: Record<string, unknown>;
59
+ columns?: Record<string, unknown>;
60
+ extras?: Record<string, unknown>;
61
+ orderBy?: unknown;
62
+ total?: () => Promise<number>;
63
+ data?: (params: { limit: number; offset: number }) => Promise<T[]>;
64
+ };
65
+
66
+ function toPositiveInt(value: unknown, fallback: number): number {
67
+ const parsed = Number(value);
68
+ if (!Number.isFinite(parsed) || parsed < 1) return fallback;
69
+ return Math.floor(parsed);
70
+ }
71
+
72
+ function pageUrl(path: string | undefined, page: number, perPage: number): string | null {
73
+ if (!path) return null;
74
+ const delimiter = path.includes("?") ? "&" : "?";
75
+ return `${path}${delimiter}page=${page}&per_page=${perPage}`;
76
+ }
77
+
78
+ /**
79
+ * Pagination namespace - nexgen-style envelope for Drizzle, surfaced through
80
+ * the facade. Access: `paginate.query`, `paginate.table`, `paginate.model`.
81
+ */
82
+ export const paginate = {
83
+ /**
84
+ * Generic paginator for custom `total()`/`data(limit, offset)` callbacks.
85
+ * Controllers/services compose any query (joins, filters, aggregates) and
86
+ * get a consistent nexgen-style envelope back.
87
+ */
88
+ query<T = unknown>(options: PaginateQueryOptions<T>): Promise<PaginatedResult<T>> {
89
+ return paginateQuery<T>(options);
90
+ },
91
+
92
+ /**
93
+ * Paginates a full Drizzle table with optional `where` filter and `orderBy`.
94
+ * Runs a count query plus the paged select. table must be a SCHEMA table
95
+ * object: `import * as schema from "@/database/schema.ts"` then `schema.users`.
96
+ */
97
+ table<T = unknown>(table: SQLiteTable, options: PaginateTableOptions = {}): Promise<PaginatedResult<T>> {
98
+ return paginateTable<T>(table, options);
99
+ },
100
+
101
+ /**
102
+ * nexgen-style pagination for Drizzle RELATIONAL queries - mirrors nexgen's
103
+ * paginateModel. Counts via `table` (+ `where`), then pages through
104
+ * `db.query.<table>.findMany({ limit, offset, where, with, columns, extras,
105
+ * orderBy })` for eager-loaded resources.
106
+ */
107
+ model<T = unknown>(options: PaginateModelOptions<T>): Promise<PaginatedResult<T>> {
108
+ return paginateModel<T>(options);
109
+ }
110
+ };
111
+
112
+ /** Generic paginator for custom `total()`/`data(limit, offset)` callbacks. */
113
+ async function paginateQuery<T = unknown>(options: PaginateQueryOptions<T>): Promise<PaginatedResult<T>> {
114
+ const maxPerPage = toPositiveInt(options.maxPerPage, 100);
115
+ const perPage = Math.min(toPositiveInt(options.perPage, 15), maxPerPage);
116
+ const page = toPositiveInt(options.page, 1);
117
+
118
+ const total = Number(await options.total());
119
+ const lastPage = Math.max(1, Math.ceil(total / perPage));
120
+ const currentPage = Math.min(page, lastPage);
121
+ const safeOffset = (currentPage - 1) * perPage;
122
+ const data = await options.data(perPage, safeOffset);
123
+
124
+ const from = total === 0 ? null : safeOffset + 1;
125
+ const to = total === 0 ? null : safeOffset + data.length;
126
+ const path = options.path || "";
127
+ const firstPageUrl = pageUrl(path, 1, perPage);
128
+ const lastPageUrl = pageUrl(path, lastPage, perPage);
129
+ const prevPageUrl = currentPage > 1 ? pageUrl(path, currentPage - 1, perPage) : null;
130
+ const nextPageUrl = currentPage < lastPage ? pageUrl(path, currentPage + 1, perPage) : null;
131
+
132
+ return {
133
+ current_page: currentPage,
134
+ data,
135
+ first_page_url: firstPageUrl,
136
+ from,
137
+ last_page: lastPage,
138
+ last_page_url: lastPageUrl,
139
+ next_page_url: nextPageUrl,
140
+ path,
141
+ per_page: perPage,
142
+ prev_page_url: prevPageUrl,
143
+ to,
144
+ total
145
+ };
146
+ }
147
+
148
+ /** Paginates a full Drizzle table with optional `where` filter and `orderBy`. */
149
+ function paginateTable<T = unknown>(table: SQLiteTable, options: PaginateTableOptions = {}): Promise<PaginatedResult<T>> {
150
+ return paginateQuery<T>({
151
+ page: options.page,
152
+ perPage: options.perPage,
153
+ maxPerPage: options.maxPerPage,
154
+ path: options.path,
155
+ total: async () => {
156
+ // deno-lint-ignore no-explicit-any
157
+ let totalQuery: any = db.select({ total: count() }).from(table);
158
+ if (options.where) totalQuery = totalQuery.where(options.where);
159
+ const totalRow = await totalQuery;
160
+ return Number(totalRow[0]?.total ?? 0);
161
+ },
162
+ data: (limit, offset) => {
163
+ // deno-lint-ignore no-explicit-any
164
+ let dataQuery: any = db.select(getTableColumns(table)).from(table);
165
+ if (options.where) dataQuery = dataQuery.where(options.where);
166
+ if (options.orderBy?.length) dataQuery = dataQuery.orderBy(...options.orderBy);
167
+ return dataQuery.limit(limit).offset(offset);
168
+ }
169
+ });
170
+ }
171
+
172
+ /**
173
+ * nexgen-style pagination for Drizzle RELATIONAL queries - mirrors nexgen's
174
+ * paginateModel. Counts via `table` (+ `where`), then pages through
175
+ * `db.query.<table>.findMany({ limit, offset, where, with, columns, extras,
176
+ * orderBy })` for eager-loaded resources.
177
+ *
178
+ * Supply either callbacks (`total`/`data`) or the declarative pair
179
+ * (`table` + `query`) - the same fallbacks engine uses:
180
+ *
181
+ * import * as schema from "@/database/schema.ts";
182
+ * const page = await paginate.model({
183
+ * page: 2, perPage: 15,
184
+ * table: schema.users,
185
+ * query: db.query.users,
186
+ * where: sql`active = true`,
187
+ * with: { posts: true },
188
+ * orderBy: (t, { desc }) => desc(t.createdAt),
189
+ * });
190
+ */
191
+ function paginateModel<T = unknown>(options: PaginateModelOptions<T>): Promise<PaginatedResult<T>> {
192
+ return paginateQuery<T>({
193
+ page: options.page,
194
+ perPage: options.perPage,
195
+ maxPerPage: options.maxPerPage,
196
+ path: options.path,
197
+ total: async () => {
198
+ if (options.total) return Number(await options.total());
199
+ if (!options.table) {
200
+ throw new Error("paginate.model requires either table or total callback");
201
+ }
202
+ // deno-lint-ignore no-explicit-any
203
+ let totalQuery: any = db.select({ total: count() }).from(options.table);
204
+ if (options.where) totalQuery = totalQuery.where(options.where);
205
+ const [row] = await totalQuery;
206
+ return Number(row?.total ?? 0);
207
+ },
208
+ data: (limit, offset) => {
209
+ if (options.data) return options.data({ limit, offset });
210
+ if (!options.query) {
211
+ throw new Error("paginate.model requires either query or data callback");
212
+ }
213
+ const args: Record<string, unknown> = { limit, offset };
214
+ if (options.where) args.where = options.where;
215
+ if (options.with) args.with = options.with;
216
+ if (options.columns) args.columns = options.columns;
217
+ if (options.extras) args.extras = options.extras;
218
+ if (options.orderBy) args.orderBy = options.orderBy;
219
+ return options.query.findMany(args);
220
+ }
221
+ });
222
+ }
223
+
224
+ // `sql` is re-exported so callers writing `where: sql` filters don't need a
225
+ // second drizzle import: import { paginate, sql } from "@/core/facade.ts".
226
+ export { sql };
@@ -1,19 +1,21 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { sqliteFile } from "@/core/database/config";
4
-
5
- const raw = sqliteFile();
6
- const file = path.resolve(process.cwd(), raw);
7
-
8
- try {
9
- fs.unlinkSync(file);
10
- console.log(`[db:reset] removed database file: ${file}`);
11
- } catch (error: any) {
12
- if (error.code === "ENOENT") {
13
- console.log(`[db:reset] no database file to remove: ${file}`);
14
- } else {
15
- console.error(`[db:reset] failed to remove database file: ${file}`);
16
- console.error(error);
17
- process.exit(1);
18
- }
19
- }
1
+ // ./src/core/database/reset.ts
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { sqliteFile } from "@/core/database/config";
6
+
7
+ const raw = sqliteFile();
8
+ const file = path.resolve(process.cwd(), raw);
9
+
10
+ try {
11
+ fs.unlinkSync(file);
12
+ console.log(`[db:reset] removed database file: ${file}`);
13
+ } catch (error: any) {
14
+ if (error.code === "ENOENT") {
15
+ console.log(`[db:reset] no database file to remove: ${file}`);
16
+ } else {
17
+ console.error(`[db:reset] failed to remove database file: ${file}`);
18
+ console.error(error);
19
+ process.exit(1);
20
+ }
21
+ }