@niyamulahsan/create-deskapp 0.0.0-stage → 1.2.1

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 (132) hide show
  1. package/README.md +49 -2
  2. package/bin/create.js +136 -0
  3. package/package.json +14 -4
  4. package/template/.env +13 -0
  5. package/template/.env.example +13 -0
  6. package/template/.vscode/extensions.json +6 -0
  7. package/template/.vscode/settings.json +37 -0
  8. package/template/LICENSE +21 -0
  9. package/template/README.md +29 -0
  10. package/template/biome.json +99 -0
  11. package/template/drizzle.config.ts +32 -0
  12. package/template/gitignore-stub +19 -0
  13. package/template/package.json +111 -0
  14. package/template/scripts/build-electron.mjs +55 -0
  15. package/template/scripts/dev-electron.mjs +53 -0
  16. package/template/scripts/installer.nsh +14 -0
  17. package/template/src/config/app.ts +24 -0
  18. package/template/src/core/api/bindings.generated.ts +23 -0
  19. package/template/src/core/api/generate.manifest.ts +86 -0
  20. package/template/src/core/api/registry.ts +48 -0
  21. package/template/src/core/config.ts +99 -0
  22. package/template/src/core/database/aggregate.ts +85 -0
  23. package/template/src/core/database/config.ts +48 -0
  24. package/template/src/core/database/connection.ts +114 -0
  25. package/template/src/core/database/migrate-hooks.ts +84 -0
  26. package/template/src/core/database/paginate.ts +224 -0
  27. package/template/src/core/database/reset.ts +19 -0
  28. package/template/src/core/database/seed.ts +169 -0
  29. package/template/src/core/database/status.ts +32 -0
  30. package/template/src/core/env.ts +106 -0
  31. package/template/src/core/facade.ts +59 -0
  32. package/template/src/core/maker/db/fresh.ts +8 -0
  33. package/template/src/core/maker/db/generate.ts +11 -0
  34. package/template/src/core/maker/db/helpers.ts +96 -0
  35. package/template/src/core/maker/db/migrate.ts +36 -0
  36. package/template/src/core/maker/db/mod.ts +63 -0
  37. package/template/src/core/maker/db/module-migrate.ts +53 -0
  38. package/template/src/core/maker/db/push.ts +21 -0
  39. package/template/src/core/maker/db/reset.ts +6 -0
  40. package/template/src/core/maker/db/seed.ts +7 -0
  41. package/template/src/core/maker/db/status.ts +6 -0
  42. package/template/src/core/maker/help.ts +66 -0
  43. package/template/src/core/maker/make/controller.ts +27 -0
  44. package/template/src/core/maker/make/helpers.ts +93 -0
  45. package/template/src/core/maker/make/mod.ts +68 -0
  46. package/template/src/core/maker/make/model.ts +14 -0
  47. package/template/src/core/maker/make/module.ts +62 -0
  48. package/template/src/core/maker/make/seeder.ts +21 -0
  49. package/template/src/core/maker/make/test.ts +30 -0
  50. package/template/src/core/maker/mod.ts +83 -0
  51. package/template/src/core/maker/run/mod.ts +112 -0
  52. package/template/src/core/maker/stub.ts +24 -0
  53. package/template/src/core/maker/stubs/controller/controller.controller.stub +55 -0
  54. package/template/src/core/maker/stubs/controller/controller.schema.stub +13 -0
  55. package/template/src/core/maker/stubs/model/model.stub +8 -0
  56. package/template/src/core/maker/stubs/seeder/seeder.stub +16 -0
  57. package/template/src/core/maker/stubs/test/test.stub +7 -0
  58. package/template/src/core/maker/sync-config.ts +94 -0
  59. package/template/src/core/utils/password.ts +27 -0
  60. package/template/src/core/utils/playwright.ts +121 -0
  61. package/template/src/core/utils/queue.ts +59 -0
  62. package/template/src/core/utils/scheduler.ts +70 -0
  63. package/template/src/core/utils/storage.ts +599 -0
  64. package/template/src/core/utils/validation.ts +35 -0
  65. package/template/src/database/migrations/sqlite/meta/_journal.json +1 -0
  66. package/template/src/database/schema.ts +6 -0
  67. package/template/src/icons/apple-touch-icon.png +0 -0
  68. package/template/src/icons/deskapp.png +0 -0
  69. package/template/src/icons/favicon-96x96.png +0 -0
  70. package/template/src/icons/favicon.ico +0 -0
  71. package/template/src/icons/favicon.svg +1 -0
  72. package/template/src/icons/site.webmanifest +21 -0
  73. package/template/src/icons/tray.png +0 -0
  74. package/template/src/icons/web-app-manifest-192x192.png +0 -0
  75. package/template/src/icons/web-app-manifest-512x512.png +0 -0
  76. package/template/src/main.ts +116 -0
  77. package/template/src/modules/app/controllers/demo.controller.ts +118 -0
  78. package/template/src/modules/app/controllers/net.controller.ts +48 -0
  79. package/template/src/modules/app/controllers/playwright.controller.ts +140 -0
  80. package/template/src/modules/app/controllers/storage.controller.ts +229 -0
  81. package/template/src/modules/app/controllers/window.controller.ts +107 -0
  82. package/template/src/preload.ts +35 -0
  83. package/template/src/storage/.gitkeep +1 -0
  84. package/template/src/storage/app/private/.gitkeep +1 -0
  85. package/template/src/storage/app/private/samples/.gitkeep +1 -0
  86. package/template/src/storage/app/private/samples/state.json +5 -0
  87. package/template/src/storage/app/private/uploads/.gitkeep +1 -0
  88. package/template/src/storage/app/public/.gitkeep +1 -0
  89. package/template/src/storage/app/tmp/generated/.gitkeep +1 -0
  90. package/template/src/storage/logs/.gitkeep +0 -0
  91. package/template/src/storage/logs/app.log +0 -0
  92. package/template/src/storage/logs/fatal.log +0 -0
  93. package/template/src/ui/.vscode/extensions.json +3 -0
  94. package/template/src/ui/index.html +14 -0
  95. package/template/src/ui/public/icons.svg +24 -0
  96. package/template/src/ui/src/App.vue +3 -0
  97. package/template/src/ui/src/app.ts +23 -0
  98. package/template/src/ui/src/assets/fonts/public-sans/public-sans-latin-ext.woff2 +0 -0
  99. package/template/src/ui/src/assets/fonts/public-sans/public-sans-latin.woff2 +0 -0
  100. package/template/src/ui/src/assets/images/deskapp.png +0 -0
  101. package/template/src/ui/src/assets/images/favicon/favicon.ico +0 -0
  102. package/template/src/ui/src/assets/scss/custom.scss +186 -0
  103. package/template/src/ui/src/bindings.d.ts +16 -0
  104. package/template/src/ui/src/components/Button.vue +32 -0
  105. package/template/src/ui/src/components/Checkbox.vue +29 -0
  106. package/template/src/ui/src/components/Input.vue +227 -0
  107. package/template/src/ui/src/components/Modal.vue +55 -0
  108. package/template/src/ui/src/components/Spinner.vue +42 -0
  109. package/template/src/ui/src/components/Switch.vue +65 -0
  110. package/template/src/ui/src/components/TextArea.vue +121 -0
  111. package/template/src/ui/src/components/Toast.vue +56 -0
  112. package/template/src/ui/src/components/datatable/DataTableSkeleton.vue +98 -0
  113. package/template/src/ui/src/components/datatable/Pagination.vue +125 -0
  114. package/template/src/ui/src/components/datatable/SelectOpption.vue +35 -0
  115. package/template/src/ui/src/components/datatable/index.vue +258 -0
  116. package/template/src/ui/src/env.d.ts +13 -0
  117. package/template/src/ui/src/global.d.ts +35 -0
  118. package/template/src/ui/src/helpers/nformatter.ts +10 -0
  119. package/template/src/ui/src/pages/dashboard/index.vue +687 -0
  120. package/template/src/ui/src/plugins/gum.ts +549 -0
  121. package/template/src/ui/src/plugins/gum.ts.bak +683 -0
  122. package/template/src/ui/src/plugins/pulse.ts +148 -0
  123. package/template/src/ui/src/router/index.ts +25 -0
  124. package/template/src/ui/src/stores/example.ts +27 -0
  125. package/template/src/ui/tsconfig.json +15 -0
  126. package/template/src/ui/vite.config.ts +38 -0
  127. package/template/src/window/config.ts +71 -0
  128. package/template/src/window/dialogs.ts +67 -0
  129. package/template/src/window/manager.ts +139 -0
  130. package/template/src/window/native.ts +215 -0
  131. package/template/tsconfig.json +22 -0
  132. package/template/vitest.config.ts +34 -0
@@ -0,0 +1,224 @@
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, sql, type 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 };
@@ -0,0 +1,19 @@
1
+ import { sqliteFile } from "@/core/database/config";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
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
+ }
@@ -0,0 +1,169 @@
1
+ // deno-lint-ignore-file no-explicit-any
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { pathToFileURL } from "node:url";
5
+ import { db } from "@/core/database/connection";
6
+
7
+ const NAME_SYMBOL = Symbol.for("drizzle:Name");
8
+ const FK_SYMBOLS = [Symbol.for("drizzle:SQLiteInlineForeignKeys")];
9
+
10
+ interface SeederEntry {
11
+ name: string;
12
+ module: string;
13
+ execute: () => Promise<void>;
14
+ tableName?: string;
15
+ dependsOn: string[];
16
+ }
17
+
18
+ const SRC_PATH = path.resolve(process.cwd(), "src");
19
+
20
+ function walkTs(dir: string, out: string[]): void {
21
+ try {
22
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
23
+ const full = path.join(dir, entry.name);
24
+ if (entry.isDirectory()) {
25
+ walkTs(full, out);
26
+ } else if (entry.isFile() && entry.name.endsWith(".ts")) {
27
+ out.push(full);
28
+ }
29
+ }
30
+ } catch {}
31
+ }
32
+
33
+ function getTableDeps(table: any): string[] {
34
+ for (const sym of FK_SYMBOLS) {
35
+ const fks = table?.[sym] as any[] | undefined;
36
+ if (!fks || fks.length === 0) continue;
37
+ const deps: string[] = [];
38
+ for (const fk of fks) {
39
+ const ref = fk.reference();
40
+ const name = ref?.foreignTable?.[NAME_SYMBOL] as string | undefined;
41
+ if (name && !deps.includes(name)) deps.push(name);
42
+ }
43
+ return deps;
44
+ }
45
+ return [];
46
+ }
47
+
48
+ function discoverSeederFiles(): string[] {
49
+ const files: string[] = [];
50
+ const modulesDir = path.join(SRC_PATH, "modules");
51
+ const coreDir = path.join(SRC_PATH, "core");
52
+
53
+ if (fs.existsSync(modulesDir)) {
54
+ for (const moduleDir of fs.readdirSync(modulesDir, { withFileTypes: true })) {
55
+ if (!moduleDir.isDirectory()) continue;
56
+ walkTs(path.join(modulesDir, moduleDir.name, "database", "seeders"), files);
57
+ }
58
+ }
59
+ if (fs.existsSync(coreDir)) {
60
+ for (const areaDir of fs.readdirSync(coreDir, { withFileTypes: true })) {
61
+ if (!areaDir.isDirectory()) continue;
62
+ walkTs(path.join(coreDir, areaDir.name, "database", "seeders"), files);
63
+ }
64
+ }
65
+ return files.sort();
66
+ }
67
+
68
+ function moduleNameOf(file: string): string {
69
+ const rel = path.relative(SRC_PATH, file).replace(/\\/g, "/");
70
+ const root = rel.startsWith("core/") ? "core" : "modules";
71
+ return rel.slice(root.length + 1).split("/")[0];
72
+ }
73
+
74
+ // Parse `--module=blog` from process.argv
75
+ const moduleArg = process.argv.find((arg) => arg.startsWith("--module="));
76
+ const moduleName = moduleArg?.split("=")[1]?.trim();
77
+
78
+ const seedFiles = moduleName
79
+ ? discoverSeederFiles().filter((f) => moduleNameOf(f) === moduleName)
80
+ : discoverSeederFiles();
81
+
82
+ await db.init();
83
+
84
+ try {
85
+ const seeders: SeederEntry[] = [];
86
+ for (const file of seedFiles) {
87
+ const mod = await import(pathToFileURL(file).href);
88
+ if (typeof mod.default !== "function") continue;
89
+
90
+ const table: any = mod.table;
91
+ const rawName = path.basename(file).replace(/\.ts$/, "");
92
+ seeders.push({
93
+ name: rawName.replace(/\.seed$/, ""),
94
+ module: moduleNameOf(file),
95
+ execute: () => mod.default(),
96
+ tableName: table?.[NAME_SYMBOL] as string | undefined,
97
+ dependsOn: table ? getTableDeps(table) : [],
98
+ });
99
+ }
100
+
101
+ if (seeders.length === 0) {
102
+ console.log(`No seeders found${moduleName ? ` for module ${moduleName}` : ""}`);
103
+ process.exit(0);
104
+ }
105
+
106
+ const tableToSeeder = new Map<string, SeederEntry>();
107
+ for (const s of seeders) {
108
+ if (s.tableName) tableToSeeder.set(s.tableName, s);
109
+ }
110
+
111
+ const resolvedDeps = new Map<SeederEntry, SeederEntry[]>();
112
+ for (const s of seeders) {
113
+ const deps: SeederEntry[] = [];
114
+ for (const dep of s.dependsOn) {
115
+ const depSeeder = tableToSeeder.get(dep);
116
+ if (depSeeder && depSeeder !== s && !deps.includes(depSeeder)) {
117
+ deps.push(depSeeder);
118
+ }
119
+ }
120
+ resolvedDeps.set(s, deps);
121
+ }
122
+
123
+ const inDegree = new Map<SeederEntry, number>();
124
+ const adj = new Map<SeederEntry, SeederEntry[]>();
125
+
126
+ for (const s of seeders) {
127
+ inDegree.set(s, 0);
128
+ adj.set(s, []);
129
+ }
130
+
131
+ for (const s of seeders) {
132
+ for (const dep of resolvedDeps.get(s)!) {
133
+ if (!adj.has(dep)) continue;
134
+ adj.get(dep)!.push(s);
135
+ inDegree.set(s, inDegree.get(s)! + 1);
136
+ }
137
+ }
138
+
139
+ const queue: SeederEntry[] = [];
140
+ for (const [s, deg] of inDegree) {
141
+ if (deg === 0) queue.push(s);
142
+ }
143
+
144
+ const sorted: SeederEntry[] = [];
145
+ while (queue.length > 0) {
146
+ const s = queue.shift()!;
147
+ sorted.push(s);
148
+ for (const next of adj.get(s)!) {
149
+ const newDeg = inDegree.get(next)! - 1;
150
+ inDegree.set(next, newDeg);
151
+ if (newDeg === 0) queue.push(next);
152
+ }
153
+ }
154
+
155
+ if (sorted.length !== seeders.length) {
156
+ const seeded = new Set(sorted.map((s) => s.name));
157
+ const missing = seeders.filter((s) => !seeded.has(s.name)).map((s) => s.name);
158
+ console.error(`Circular dependency detected among seeders: ${missing.join(", ")}`);
159
+ process.exit(1);
160
+ }
161
+
162
+ for (const s of sorted) {
163
+ await s.execute();
164
+ }
165
+
166
+ console.log(`Executed ${sorted.length} seeder file(s)${moduleName ? ` for module ${moduleName}` : ""}`);
167
+ } finally {
168
+ await db.close();
169
+ }
@@ -0,0 +1,32 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const MIGRATION_DIR = path.join(process.cwd(), "src", "database", "migrations", "sqlite");
6
+
7
+ export function listMigrations(dir = MIGRATION_DIR): string[] {
8
+ try {
9
+ return fs.readdirSync(dir).filter((name) => name.endsWith(".sql")).sort();
10
+ } catch {
11
+ return [];
12
+ }
13
+ }
14
+
15
+ function isMain(): boolean {
16
+ try {
17
+ const arg = process.argv[1];
18
+ if (!arg) return false;
19
+ return path.resolve(arg) === path.resolve(fileURLToPath(import.meta.url));
20
+ } catch {
21
+ return false;
22
+ }
23
+ }
24
+
25
+ if (isMain()) {
26
+ const found = listMigrations();
27
+ if (found.length === 0) console.log("No generated migration files found.");
28
+ else {
29
+ console.log("Generated migrations:");
30
+ for (const file of found) console.log(` - ${file}`);
31
+ }
32
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * env.ts - runtime environment bootstrapping.
3
+ *
4
+ * Migrated from Deno to Node.js/Electron.
5
+ * Uses `dotenv` to load `.env` files from stable locations.
6
+ */
7
+
8
+ import fs from "node:fs";
9
+ import { createRequire } from "node:module";
10
+ import { dirname, join, resolve } from "node:path";
11
+ import { config as loadDotenv } from "dotenv";
12
+
13
+ function getElectronApp(): any {
14
+ try {
15
+ const req = typeof require !== "undefined" ? require : createRequire(process.cwd() + "/");
16
+ const e = req("electron");
17
+ if (e && typeof e === "object" && typeof e.app?.getPath === "function") return e.app;
18
+ } catch {}
19
+ return undefined;
20
+ }
21
+
22
+ /** True when running inside the Electron runtime. */
23
+ export function isDesktopRuntime(): boolean {
24
+ return !!getElectronApp();
25
+ }
26
+
27
+ /** True only for a real packaged app. */
28
+ function bundledDesktopApp(): boolean {
29
+ const app = getElectronApp();
30
+ return !!app?.isPackaged;
31
+ }
32
+
33
+ function findProjectRoot(start: string): string | undefined {
34
+ let dir = resolve(start);
35
+ for (let i = 0; i < 8; i++) {
36
+ try {
37
+ if (fs.statSync(join(dir, "package.json")).isFile()) return dir;
38
+ } catch {}
39
+ const parent = dirname(dir);
40
+ if (parent === dir) break;
41
+ dir = parent;
42
+ }
43
+ return undefined;
44
+ }
45
+
46
+ /** The app/project root in development, executable/resources dir when packaged. */
47
+ export function appBaseDir(): string {
48
+ const override = process.env.APP_BASE_DIR?.trim();
49
+ if (override) return resolve(override);
50
+
51
+ const electronApp = getElectronApp();
52
+ if (electronApp?.isPackaged) {
53
+ return dirname(electronApp.getPath("exe"));
54
+ }
55
+
56
+ // Dev: prefer cwd (npm scripts run from project root), then locate package.json.
57
+ const cwd = resolve(process.cwd());
58
+ if (fs.existsSync(join(cwd, "package.json"))) return cwd;
59
+
60
+ try {
61
+ if (electronApp) {
62
+ const found = findProjectRoot(electronApp.getAppPath());
63
+ if (found) return found;
64
+ }
65
+ } catch {}
66
+
67
+ return cwd;
68
+ }
69
+
70
+ const envState: { path: string | null; tried: boolean } = { path: null, tried: false };
71
+
72
+ /**
73
+ * Load the first `.env` found next to the app (bundled) or at the project
74
+ * root (dev); never overrides variables already present in the environment.
75
+ * Returns the resolved path, or null when no `.env` exists. Idempotent.
76
+ */
77
+ export function loadEnv(): string | null {
78
+ if (envState.tried) return envState.path;
79
+ envState.tried = true;
80
+
81
+ const electronApp = getElectronApp();
82
+ const base = appBaseDir();
83
+ const candidates = [
84
+ process.env.APP_BASE_DIR?.trim(),
85
+ electronApp?.isPackaged ? dirname(electronApp.getPath("exe")) : undefined,
86
+ base,
87
+ electronApp?.getAppPath ? electronApp.getAppPath() : undefined,
88
+ resolve(process.cwd()),
89
+ ].filter((dir): dir is string => Boolean(dir) && dir.length > 0);
90
+
91
+ for (const dir of [...new Set(candidates)]) {
92
+ const envPath = join(dir, ".env");
93
+ try {
94
+ if (!fs.statSync(envPath).isFile()) continue;
95
+ loadDotenv({ path: envPath });
96
+ envState.path = envPath;
97
+ return envPath;
98
+ } catch {}
99
+ }
100
+ return null;
101
+ }
102
+
103
+ /** The runtime `.env` path that was loaded (null until loadEnv runs / none). */
104
+ export function envPath(): string | null {
105
+ return envState.tried ? envState.path : null;
106
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * facade - central public API surface for framework consumers.
3
+ *
4
+ * App-layer code (module controllers, jobs, schedules, models) should import
5
+ * its framework utilities from here in one place instead of reaching into core
6
+ * internals. Each service is surfaced as it gets implemented; only what is
7
+ * actually implemented is re-exported so the facade stays truthful.
8
+ */
9
+
10
+ // Configuration
11
+
12
+ // Database (query client + lifecycle: `db.init()` / `db.close()`)
13
+ export { type DrizzleDatabase, db } from "@/core/database/connection";
14
+ // Pagination (nexgen-style envelope); `sql` for where filters
15
+ export {
16
+ type PaginatedResult,
17
+ type PaginateInput,
18
+ type PaginateModelOptions,
19
+ type PaginateQueryOptions,
20
+ type PaginateTableOptions,
21
+ paginate,
22
+ sql
23
+ } from "@/core/database/paginate";
24
+ // Security / hashing utilities
25
+ export { pass } from "@/core/utils/password";
26
+ // Browser automation (Playwright): locate the bundled Chromium + extensions
27
+ export { chromium } from "@/core/utils/playwright";
28
+ // Concurrency / job queue
29
+ export { type Queue, type QueueTask, queue } from "@/core/utils/queue";
30
+ // Cron scheduling (backed by croner)
31
+ export { type CronHandle, cron } from "@/core/utils/scheduler";
32
+ // File / storage utilities
33
+ // 1) User-file layer: operate on ANY path the user picks
34
+ // 2) App-managed layer: the app's own internal state (private + tmp)
35
+ export { type Disk, type FileData, files, storage } from "@/core/utils/storage";
36
+ // Validation (zod schemas + runner: `validate.z`, `validate.run`)
37
+ export { validate } from "@/core/utils/validation";
38
+ // Native Windows file/folder pickers (Explorer-style Open / Save As / folder)
39
+ export {
40
+ type PickFolderOptions,
41
+ type PickOpenOptions,
42
+ type PickSaveOptions,
43
+ pickers
44
+ } from "@/window/dialogs";
45
+ // Desktop window control
46
+ export {
47
+ type BrowserWindowOptions,
48
+ type DesktopWindow,
49
+ win
50
+ } from "@/window/manager";
51
+ // Desktop-native APIs: menu item types, tray, dialogs, and chrome setup
52
+ export {
53
+ chrome,
54
+ type DesktopTray,
55
+ type MenuActionItem,
56
+ type MenuItem,
57
+ type MenuRole,
58
+ type MenuSubmenu
59
+ } from "@/window/native";
@@ -0,0 +1,8 @@
1
+ import { runScript } from "@/core/maker/db/helpers.ts";
2
+ import { migrate } from "@/core/maker/db/migrate.ts";
3
+
4
+ /** db:fresh - reset DB, then generate, migrate, hooks; seed only with --seed. */
5
+ export async function fresh(seed = false): Promise<void> {
6
+ await runScript("src/core/database/reset.ts");
7
+ await migrate(seed);
8
+ }
@@ -0,0 +1,11 @@
1
+ import { generateMigrations, generateSchema } from "@/core/maker/db/helpers.ts";
2
+
3
+ /** db:schema - regenerate src/database/schema.ts from all models. */
4
+ export async function schema(): Promise<void> {
5
+ await generateSchema();
6
+ }
7
+
8
+ /** db:generate - regenerate schema and create migration SQL. */
9
+ export async function generate(): Promise<void> {
10
+ await generateMigrations();
11
+ }