@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
@@ -0,0 +1,114 @@
1
+ // ./src/modules/app/__tests__/storage.controller.test.ts
2
+
3
+ import { beforeEach, describe, expect, it, vi } from "vitest";
4
+
5
+ const mocks = vi.hoisted(() => {
6
+ const files = {
7
+ readBinaryFile: vi.fn(async () => Buffer.from("hello")),
8
+ fileMeta: vi.fn(async () => ({ size: 5, isFile: true, modifiedAt: new Date(0) })),
9
+ pathExists: vi.fn(async () => false),
10
+ writeTextFile: vi.fn(async () => undefined),
11
+ uploadFile: vi.fn(async () => "/uploads/f.txt"),
12
+ downloadFile: vi.fn(async (_s: string, d: string) => d),
13
+ removePath: vi.fn(async () => undefined),
14
+ listFiles: vi.fn(async () => ["a"]),
15
+ listDirectories: vi.fn(async () => ["d"]),
16
+ };
17
+ const pickers = {
18
+ open: vi.fn(async () => "/src.txt"),
19
+ save: vi.fn(async () => "/dst.txt"),
20
+ folder: vi.fn(async () => "/dir"),
21
+ };
22
+ const storage = {
23
+ init: vi.fn(async () => undefined),
24
+ put: vi.fn(async () => "k"),
25
+ get: vi.fn(async () => Buffer.from('{"a":1}')),
26
+ exists: vi.fn(async () => false),
27
+ files: vi.fn(async () => ["f"]),
28
+ directories: vi.fn(async () => ["d"]),
29
+ generateForDownload: vi.fn(async () => "generated/x"),
30
+ consumeGenerated: vi.fn(async () => Buffer.from("gen")),
31
+ delete: vi.fn(async () => undefined),
32
+ disk: vi.fn(() => ({ path: vi.fn(() => "/private") })),
33
+ };
34
+ return { files, pickers, storage };
35
+ });
36
+
37
+ vi.mock("@/core/facade", () => ({ files: mocks.files, pickers: mocks.pickers, storage: mocks.storage }));
38
+ vi.mock("node:fs", () => ({ default: { existsSync: () => true } }));
39
+ vi.mock("node:fs/promises", async (importOriginal) => {
40
+ const actual = await importOriginal<typeof import("node:fs/promises")>();
41
+ return { ...actual, default: actual, mkdtemp: vi.fn(async () => "/tmp/t") };
42
+ });
43
+ vi.mock("node:os", async (importOriginal) => {
44
+ const actual = await importOriginal<typeof import("node:os")>();
45
+ return { ...actual, default: { ...actual, tmpdir: () => "/tmp" }, tmpdir: () => "/tmp" };
46
+ });
47
+
48
+ import * as ctrl from "@/modules/app/controllers/storage.controller";
49
+
50
+ describe("app storage.controller", () => {
51
+ beforeEach(() => {
52
+ vi.clearAllMocks();
53
+ mocks.pickers.open.mockReset().mockResolvedValue("/src.txt");
54
+ mocks.pickers.save.mockReset().mockResolvedValue("/dst.txt");
55
+ mocks.pickers.folder.mockReset().mockResolvedValue("/dir");
56
+ mocks.files.downloadFile.mockReset().mockImplementation(async (_s: string, d: string) => d);
57
+ mocks.files.uploadFile.mockReset().mockResolvedValue("/uploads/f.txt");
58
+ mocks.files.removePath.mockReset().mockResolvedValue(undefined);
59
+ mocks.files.listFiles.mockReset().mockResolvedValue(["a"]);
60
+ mocks.files.listDirectories.mockReset().mockResolvedValue(["d"]);
61
+ mocks.files.readBinaryFile.mockReset().mockResolvedValue(Buffer.from("hello"));
62
+ mocks.files.fileMeta.mockReset().mockResolvedValue({ size: 5, isFile: true, modifiedAt: new Date(0) } as any);
63
+ mocks.files.pathExists.mockReset().mockResolvedValue(false);
64
+ mocks.files.writeTextFile.mockReset().mockResolvedValue(undefined);
65
+ mocks.storage.disk.mockReset().mockReturnValue({ path: vi.fn(() => "/private") } as any);
66
+ });
67
+
68
+ it("exposes handlers", () => {
69
+ expect(ctrl.handlers.open).toBe(ctrl.open);
70
+ expect(ctrl.handlers.appSave).toBe(ctrl.appSave);
71
+ });
72
+
73
+ it("open/save cancel and success paths", async () => {
74
+ mocks.pickers.open.mockResolvedValueOnce(null);
75
+ expect(await ctrl.open()).toMatchObject({ ok: false, error: "cancelled" });
76
+ mocks.pickers.open.mockResolvedValue("/src.txt");
77
+ expect(await ctrl.open()).toMatchObject({ ok: true, path: "/src.txt" });
78
+
79
+ mocks.pickers.save.mockResolvedValueOnce(null);
80
+ expect(await ctrl.save()).toMatchObject({ ok: false, error: "cancelled" });
81
+ mocks.pickers.save.mockResolvedValue("/dst.txt");
82
+ expect(await ctrl.save()).toMatchObject({ ok: true, path: "/dst.txt" });
83
+ });
84
+
85
+ it("upload/download/remove/list", async () => {
86
+ mocks.pickers.open.mockResolvedValueOnce(null);
87
+ expect(await ctrl.upload()).toMatchObject({ ok: false, error: "cancelled" });
88
+ mocks.pickers.open.mockResolvedValueOnce("/src.txt");
89
+ expect(await ctrl.upload()).toMatchObject({ ok: true, dest: "/uploads/f.txt" });
90
+
91
+ mocks.pickers.save.mockResolvedValueOnce(null);
92
+ expect(await ctrl.download("https://example.com/file.txt")).toMatchObject({ ok: false, error: "cancelled" });
93
+ mocks.pickers.save.mockResolvedValueOnce("/dst.txt");
94
+ expect(await ctrl.download("https://example.com/file.txt")).toMatchObject({ ok: true });
95
+
96
+ mocks.pickers.open.mockResolvedValueOnce(null);
97
+ expect(await ctrl.remove()).toMatchObject({ ok: false, error: "cancelled" });
98
+ mocks.pickers.open.mockResolvedValue("/src.txt");
99
+ expect(await ctrl.remove()).toMatchObject({ ok: true });
100
+
101
+ mocks.pickers.folder.mockResolvedValueOnce(null);
102
+ expect(await ctrl.list()).toMatchObject({ ok: false, error: "cancelled" });
103
+ mocks.pickers.folder.mockResolvedValueOnce("/dir");
104
+ expect(await ctrl.list()).toMatchObject({ ok: true, files: ["a"] });
105
+ });
106
+
107
+ it("app-managed helpers", async () => {
108
+ expect(await ctrl.appSave()).toMatchObject({ ok: true });
109
+ expect(await ctrl.appLoad()).toMatchObject({ ok: true });
110
+ expect(await ctrl.appList()).toMatchObject({ ok: true });
111
+ expect(await ctrl.appExport()).toMatchObject({ ok: true });
112
+ expect(await ctrl.appDelete()).toMatchObject({ ok: true });
113
+ });
114
+ });
@@ -0,0 +1,98 @@
1
+ // ./src/modules/app/__tests__/window.controller.test.ts
2
+
3
+ import { beforeEach, describe, expect, it, vi } from "vitest";
4
+
5
+ const mocks = vi.hoisted(() => {
6
+ const setTitle = vi.fn();
7
+ const setSize = vi.fn();
8
+ const setAlwaysOnTop = vi.fn();
9
+ const isAlwaysOnTop = vi.fn(() => false);
10
+ const focus = vi.fn();
11
+ const loadURL = vi.fn();
12
+ const winObj = { setTitle, setSize, setAlwaysOnTop, isAlwaysOnTop, focus, loadURL };
13
+ const openWindow = vi.fn(async (_arg?: any) => winObj);
14
+ const installAppMenu = vi.fn();
15
+ const createAppTray = vi.fn();
16
+ const confirmDialog = vi.fn(async () => true);
17
+ const alertDialog = vi.fn(async () => undefined);
18
+ const quit = vi.fn();
19
+ return { winObj, openWindow, installAppMenu, createAppTray, confirmDialog, alertDialog, quit, setTitle, setSize, setAlwaysOnTop, isAlwaysOnTop, focus, loadURL };
20
+ });
21
+
22
+ vi.mock("electron", () => ({ app: { quit: mocks.quit } }));
23
+ vi.mock("@/core/config", () => ({ config: { appName: "Deskapp", appKebab: "deskapp" } }));
24
+ vi.mock("@/core/facade", () => ({
25
+ chrome: {
26
+ installAppMenu: mocks.installAppMenu,
27
+ createAppTray: mocks.createAppTray,
28
+ confirmDialog: mocks.confirmDialog,
29
+ alertDialog: mocks.alertDialog,
30
+ },
31
+ win: { getWindow: () => mocks.winObj, openWindow: mocks.openWindow },
32
+ }));
33
+
34
+ import * as ctrl from "@/modules/app/controllers/window.controller";
35
+
36
+ describe("app window.controller", () => {
37
+ beforeEach(() => vi.clearAllMocks());
38
+
39
+ it("exposes handlers", () => {
40
+ expect(ctrl.handlers.setTitle).toBe(ctrl.setTitle);
41
+ expect(ctrl.handlers.quit).toBe(ctrl.quit);
42
+ expect(Object.keys(ctrl.handlers).sort()).toEqual([
43
+ "alertSomething",
44
+ "confirmSomething",
45
+ "createTray",
46
+ "focus",
47
+ "installMenu",
48
+ "open",
49
+ "openUrl",
50
+ "quit",
51
+ "setSize",
52
+ "setTitle",
53
+ "showContextMenu",
54
+ "toggleAlwaysOnTop",
55
+ ]);
56
+ });
57
+
58
+ it("window controls act on the target window", () => {
59
+ ctrl.setTitle("hi");
60
+ expect(mocks.setTitle).toHaveBeenCalledWith("hi");
61
+ ctrl.setSize(100, 200);
62
+ expect(mocks.setSize).toHaveBeenCalledWith(100, 200);
63
+ mocks.isAlwaysOnTop.mockReturnValueOnce(false);
64
+ ctrl.toggleAlwaysOnTop();
65
+ expect(mocks.setAlwaysOnTop).toHaveBeenCalledWith(true);
66
+ ctrl.focus();
67
+ expect(mocks.focus).toHaveBeenCalled();
68
+ });
69
+
70
+ it("open resolves presets and openUrl validates protocols", async () => {
71
+ expect(await ctrl.open("settings")).toBe(true);
72
+ expect(mocks.openWindow).toHaveBeenCalledWith("settings");
73
+ expect(await ctrl.open(123 as any)).toBe(false);
74
+
75
+ expect(await ctrl.openUrl("ftp://bad")).toBe(false);
76
+ expect(await ctrl.openUrl("not-a-url")).toBe(false);
77
+ expect(await ctrl.openUrl("https://example.com")).toBe(true);
78
+ expect(mocks.loadURL).toHaveBeenCalledWith("https://example.com/");
79
+ });
80
+
81
+ it("menus/tray/dialog helpers delegate to chrome", async () => {
82
+ ctrl.installMenu();
83
+ expect(mocks.installAppMenu).toHaveBeenCalledWith(mocks.winObj);
84
+ ctrl.showContextMenu(); // no-op
85
+ expect(ctrl.createTray()).toBe(true);
86
+ expect(mocks.createAppTray).toHaveBeenCalled();
87
+
88
+ expect(await ctrl.confirmSomething("sure?")).toBe(true);
89
+ expect(mocks.confirmDialog).toHaveBeenCalledWith("sure?");
90
+ await ctrl.alertSomething("hi");
91
+ expect(mocks.alertDialog).toHaveBeenCalledWith("hi");
92
+ });
93
+
94
+ it("quit quits the app", () => {
95
+ ctrl.quit();
96
+ expect(mocks.quit).toHaveBeenCalled();
97
+ });
98
+ });
@@ -1,118 +1,120 @@
1
- import { cron, queue as queueApi } from "@/core/facade";
2
-
3
- /**
4
- * demo.controller.ts (app module) - queue & cron sample handlers.
5
- *
6
- * Demonstrates the reusable facade primitives from inside real bindings:
7
- * - `app.demo.queue` runs a bounded-concurrency in-process queue
8
- * - `app.demo.schedule` ticks a cron every second for N seconds, then stops
9
- *
10
- * The pattern here is what an app module would use in production:
11
- * import { queue, cron } from "@/core/facade.ts" in your own controller.
12
- */
13
-
14
- const sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
15
-
16
- export const queue = async (opts?: { items?: string[]; concurrency?: number; delayMs?: number }): Promise<Record<string, unknown>> => {
17
- const items = opts?.items && opts.items.length > 0 ? opts.items : ["a", "b", "c"];
18
- const concurrency = Math.min(Math.max(opts?.concurrency ?? 2, 1), 8);
19
- const delayMs = Math.min(Math.max(opts?.delayMs ?? 50, 0), 1000);
20
- const started = Date.now();
21
-
22
- const q = queueApi.create<string>({ concurrency });
23
- const results = await Promise.all(
24
- items.map((name) =>
25
- q.add(async () => {
26
- await sleep(delayMs);
27
- return `processed ${name}`;
28
- })
29
- )
30
- );
31
-
32
- return { ok: true, results, concurrency, durationMs: Date.now() - started };
33
- };
34
-
35
- export const schedule = async (opts?: { seconds?: number }): Promise<Record<string, unknown>> => {
36
- const seconds = Math.min(Math.max(opts?.seconds ?? 2, 1), 10);
37
- let ticks = 0;
38
-
39
- const job = cron.schedule("demo.tick", "* * * * * *", () => {
40
- ticks += 1;
41
- });
42
- await sleep(seconds * 1000);
43
- job.stop();
44
-
45
- return { ok: true, name: "demo.tick", expression: "* * * * * *", ticked: ticks, seconds };
46
- };
47
-
48
- /**
49
- * demo.controller.ts (app module) - gum data-table sample handlers.
50
- *
51
- * `app.demo.table` serves the same paginated envelope `paginate.*` produces
52
- * (`data/current_page/last_page/per_page/total/from/to/path`), so the UI
53
- * <DataTable> can bind to it with zero ceremony. Rows are generated in memory
54
- * here so the starter needs no migration; a real module does exactly the same
55
- * with a Drizzle model + paginate.model (see docs/guide/gum.md).
56
- */
57
-
58
- interface DemoRow {
59
- id: number;
60
- name: string;
61
- email: string;
62
- role: string;
63
- created: string;
64
- }
65
-
66
- const demoSeed = Array.from({ length: 137 }, (_, i) => ({
67
- id: i + 1,
68
- name: ["Ava", "Leo", "Mia", "Noah", "Zara", "Ivan", "Eli", "Ruth", "Omar", "Nia"][i % 10] + ` ${i + 1}`,
69
- email: `user${i + 1}@example.com`,
70
- role: ["admin", "editor", "viewer"][i % 3],
71
- created: `2026-${String((i % 12) + 1).padStart(2, "0")}-${String((i % 28) + 1).padStart(2, "0")}`
72
- }));
73
-
74
- let demoRows: DemoRow[] = structuredClone(demoSeed);
75
-
76
- function toPositiveInt(value: unknown, fallback: number): number {
77
- const parsed = Number(value);
78
- if (!Number.isFinite(parsed) || parsed < 1) return fallback;
79
- return Math.floor(parsed);
80
- }
81
-
82
- export const table = (opts?: { page?: number; size?: number; search?: string }): Record<string, unknown> => {
83
- const perPage = Math.min(toPositiveInt(opts?.size, 15), 100);
84
- const page = toPositiveInt(opts?.page, 1);
85
- const search = String(opts?.search ?? "")
86
- .trim()
87
- .toLowerCase();
88
-
89
- const all = search
90
- ? demoRows.filter((row) => [row.name, row.email, row.role].some((value) => value.toLowerCase().includes(search)))
91
- : demoRows;
92
-
93
- const total = all.length;
94
- const lastPage = Math.max(1, Math.ceil(total / perPage));
95
- const currentPage = Math.min(page, lastPage);
96
- const offset = (currentPage - 1) * perPage;
97
- const data = all.slice(offset, offset + perPage);
98
-
99
- return {
100
- data,
101
- current_page: currentPage,
102
- last_page: lastPage,
103
- per_page: perPage,
104
- total,
105
- from: total === 0 ? null : offset + 1,
106
- to: total === 0 ? null : offset + data.length,
107
- path: "app.demo.table"
108
- };
109
- };
110
-
111
- export const destroy = (opts?: { ids?: Array<string | number> }): Record<string, unknown> => {
112
- const ids = new Set((opts?.ids ?? []).map((id) => String(id)));
113
- const before = demoRows.length;
114
- demoRows = demoRows.filter((row) => !ids.has(String(row.id)));
115
- return { ok: true, removed: before - demoRows.length };
116
- };
117
-
118
- export const handlers = { queue, schedule, table, destroy };
1
+ // ./src/modules/app/controllers/demo.controller.ts
2
+
3
+ import { cron, queue as queueApi } from "@/core/facade";
4
+
5
+ /**
6
+ * demo.controller.ts (app module) - queue & cron sample handlers.
7
+ *
8
+ * Demonstrates the reusable facade primitives from inside real bindings:
9
+ * - `app.demo.queue` runs a bounded-concurrency in-process queue
10
+ * - `app.demo.schedule` ticks a cron every second for N seconds, then stops
11
+ *
12
+ * The pattern here is what an app module would use in production:
13
+ * import { queue, cron } from "@/core/facade.ts" in your own controller.
14
+ */
15
+
16
+ const sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
17
+
18
+ export const queue = async (opts?: { items?: string[]; concurrency?: number; delayMs?: number }): Promise<Record<string, unknown>> => {
19
+ const items = opts?.items && opts.items.length > 0 ? opts.items : ["a", "b", "c"];
20
+ const concurrency = Math.min(Math.max(opts?.concurrency ?? 2, 1), 8);
21
+ const delayMs = Math.min(Math.max(opts?.delayMs ?? 50, 0), 1000);
22
+ const started = Date.now();
23
+
24
+ const q = queueApi.create<string>({ concurrency });
25
+ const results = await Promise.all(
26
+ items.map((name) =>
27
+ q.add(async () => {
28
+ await sleep(delayMs);
29
+ return `processed ${name}`;
30
+ })
31
+ )
32
+ );
33
+
34
+ return { ok: true, results, concurrency, durationMs: Date.now() - started };
35
+ };
36
+
37
+ export const schedule = async (opts?: { seconds?: number }): Promise<Record<string, unknown>> => {
38
+ const seconds = Math.min(Math.max(opts?.seconds ?? 2, 1), 10);
39
+ let ticks = 0;
40
+
41
+ const job = cron.schedule("demo.tick", "* * * * * *", () => {
42
+ ticks += 1;
43
+ });
44
+ await sleep(seconds * 1000);
45
+ job.stop();
46
+
47
+ return { ok: true, name: "demo.tick", expression: "* * * * * *", ticked: ticks, seconds };
48
+ };
49
+
50
+ /**
51
+ * demo.controller.ts (app module) - gum data-table sample handlers.
52
+ *
53
+ * `app.demo.table` serves the same paginated envelope `paginate.*` produces
54
+ * (`data/current_page/last_page/per_page/total/from/to/path`), so the UI
55
+ * <DataTable> can bind to it with zero ceremony. Rows are generated in memory
56
+ * here so the starter needs no migration; a real module does exactly the same
57
+ * with a Drizzle model + paginate.model (see docs/guide/gum.md).
58
+ */
59
+
60
+ interface DemoRow {
61
+ id: number;
62
+ name: string;
63
+ email: string;
64
+ role: string;
65
+ created: string;
66
+ }
67
+
68
+ const demoSeed = Array.from({ length: 137 }, (_, i) => ({
69
+ id: i + 1,
70
+ name: `${["Ava", "Leo", "Mia", "Noah", "Zara", "Ivan", "Eli", "Ruth", "Omar", "Nia"][i % 10]} ${i + 1}`,
71
+ email: `user${i + 1}@example.com`,
72
+ role: ["admin", "editor", "viewer"][i % 3],
73
+ created: `2026-${String((i % 12) + 1).padStart(2, "0")}-${String((i % 28) + 1).padStart(2, "0")}`
74
+ }));
75
+
76
+ let demoRows: DemoRow[] = structuredClone(demoSeed);
77
+
78
+ function toPositiveInt(value: unknown, fallback: number): number {
79
+ const parsed = Number(value);
80
+ if (!Number.isFinite(parsed) || parsed < 1) return fallback;
81
+ return Math.floor(parsed);
82
+ }
83
+
84
+ export const table = (opts?: { page?: number; size?: number; search?: string }): Record<string, unknown> => {
85
+ const perPage = Math.min(toPositiveInt(opts?.size, 15), 100);
86
+ const page = toPositiveInt(opts?.page, 1);
87
+ const search = String(opts?.search ?? "")
88
+ .trim()
89
+ .toLowerCase();
90
+
91
+ const all = search
92
+ ? demoRows.filter((row) => [row.name, row.email, row.role].some((value) => value.toLowerCase().includes(search)))
93
+ : demoRows;
94
+
95
+ const total = all.length;
96
+ const lastPage = Math.max(1, Math.ceil(total / perPage));
97
+ const currentPage = Math.min(page, lastPage);
98
+ const offset = (currentPage - 1) * perPage;
99
+ const data = all.slice(offset, offset + perPage);
100
+
101
+ return {
102
+ data,
103
+ current_page: currentPage,
104
+ last_page: lastPage,
105
+ per_page: perPage,
106
+ total,
107
+ from: total === 0 ? null : offset + 1,
108
+ to: total === 0 ? null : offset + data.length,
109
+ path: "app.demo.table"
110
+ };
111
+ };
112
+
113
+ export const destroy = (opts?: { ids?: Array<string | number> }): Record<string, unknown> => {
114
+ const ids = new Set((opts?.ids ?? []).map((id) => String(id)));
115
+ const before = demoRows.length;
116
+ demoRows = demoRows.filter((row) => !ids.has(String(row.id)));
117
+ return { ok: true, removed: before - demoRows.length };
118
+ };
119
+
120
+ export const handlers = { queue, schedule, table, destroy };
@@ -1,48 +1,50 @@
1
- /**
2
- * net.controller.ts (app module) - backend proxy for server API calls.
3
- *
4
- * The webview's own fetch() can be blocked by CORS on cross-origin APIs.
5
- * Calling the API on the Deno backend avoids CORS entirely: the frontend asks
6
- * `app.net.fetchJson(url)`, the backend fetches it, and the JSON-safe payload
7
- * comes back through the bindings. The two demo handlers:
8
- *
9
- * fetchJson(url) -> app.net.fetchJson any http(s) URL (JSON or text)
10
- * placeholder() -> app.net.placeholder jsonplaceholder.typicode.com
11
- *
12
- * See src/ui/src/App.vue for the matching "Server / API" demo section.
13
- */
14
-
15
- const MAX_BODY = 50_000;
16
-
17
- /** Proxy one http(s) fetch from the backend; returns JSON (or text) safely. */
18
- export const fetchJson = async (url: string | undefined): Promise<Record<string, unknown>> => {
19
- const clean = (url ?? "").trim();
20
- if (!/^https?:\/\//i.test(clean)) {
21
- return { ok: false, action: "fetch", error: "enter a valid http(s) URL" };
22
- }
23
- try {
24
- const res = await fetch(clean, { headers: { Accept: "application/json" } });
25
- const text = await res.text();
26
- let data: unknown;
27
- if (text.length <= MAX_BODY) {
28
- try {
29
- data = JSON.parse(text);
30
- } catch {
31
- data = text;
32
- }
33
- } else {
34
- data = `${text.slice(0, 2000)}... (truncated, ${text.length} bytes)`;
35
- }
36
- return { ok: res.ok, status: res.status, url: clean, bytes: text.length, data };
37
- } catch (error) {
38
- return { ok: false, action: "fetch", url: clean, error: String(error) };
39
- }
40
- };
41
-
42
- /** One-click demo against JSONPlaceholder (no input needed). */
43
- export const placeholder = async (): Promise<Record<string, unknown>> => {
44
- return await fetchJson("https://jsonplaceholder.typicode.com/todos/1");
45
- };
46
-
47
- /** Handlers exposed to the frontend via the bindings registry. */
48
- export const handlers = { fetchJson, placeholder };
1
+ // ./src/modules/app/controllers/net.controller.ts
2
+
3
+ /**
4
+ * net.controller.ts (app module) - backend proxy for server API calls.
5
+ *
6
+ * The webview's own fetch() can be blocked by CORS on cross-origin APIs.
7
+ * Calling the API on the Deno backend avoids CORS entirely: the frontend asks
8
+ * `app.net.fetchJson(url)`, the backend fetches it, and the JSON-safe payload
9
+ * comes back through the bindings. The two demo handlers:
10
+ *
11
+ * fetchJson(url) -> app.net.fetchJson any http(s) URL (JSON or text)
12
+ * placeholder() -> app.net.placeholder jsonplaceholder.typicode.com
13
+ *
14
+ * See src/ui/src/App.vue for the matching "Server / API" demo section.
15
+ */
16
+
17
+ const MAX_BODY = 50_000;
18
+
19
+ /** Proxy one http(s) fetch from the backend; returns JSON (or text) safely. */
20
+ export const fetchJson = async (url: string | undefined): Promise<Record<string, unknown>> => {
21
+ const clean = (url ?? "").trim();
22
+ if (!/^https?:\/\//i.test(clean)) {
23
+ return { ok: false, action: "fetch", error: "enter a valid http(s) URL" };
24
+ }
25
+ try {
26
+ const res = await fetch(clean, { headers: { Accept: "application/json" } });
27
+ const text = await res.text();
28
+ let data: unknown;
29
+ if (text.length <= MAX_BODY) {
30
+ try {
31
+ data = JSON.parse(text);
32
+ } catch {
33
+ data = text;
34
+ }
35
+ } else {
36
+ data = `${text.slice(0, 2000)}... (truncated, ${text.length} bytes)`;
37
+ }
38
+ return { ok: res.ok, status: res.status, url: clean, bytes: text.length, data };
39
+ } catch (error) {
40
+ return { ok: false, action: "fetch", url: clean, error: String(error) };
41
+ }
42
+ };
43
+
44
+ /** One-click demo against JSONPlaceholder (no input needed). */
45
+ export const placeholder = async (): Promise<Record<string, unknown>> => {
46
+ return await fetchJson("https://jsonplaceholder.typicode.com/todos/1");
47
+ };
48
+
49
+ /** Handlers exposed to the frontend via the bindings registry. */
50
+ export const handlers = { fetchJson, placeholder };