appflare 0.2.9 → 0.2.11

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.
@@ -108,8 +108,9 @@ export async function runMigrate(
108
108
  loadedConfig.outDirAbs,
109
109
  "drizzle.config.ts",
110
110
  );
111
+ const npxCmd = process.platform === "win32" ? "npx.cmd" : "npx";
111
112
  const drizzleGenerate = Bun.spawn(
112
- ["drizzle-kit", "generate", "--config", drizzleConfigPath],
113
+ [npxCmd, "drizzle-kit", "generate", "--config", drizzleConfigPath],
113
114
  {
114
115
  cwd: packageDir,
115
116
  stdin: "inherit",
@@ -126,7 +127,14 @@ export async function runMigrate(
126
127
  }
127
128
 
128
129
  const databaseName = loadedConfig.config.database[0].databaseName;
129
- const wranglerArgs = ["wrangler", "d1", "migrations", "apply", databaseName];
130
+ const wranglerArgs = [
131
+ npxCmd,
132
+ "wrangler",
133
+ "d1",
134
+ "migrations",
135
+ "apply",
136
+ databaseName,
137
+ ];
130
138
 
131
139
  if (options.local) {
132
140
  wranglerArgs.push("--local");
@@ -190,7 +198,9 @@ export async function runAddAdmin(
190
198
  ].join(" ");
191
199
 
192
200
  const databaseName = loadedConfig.config.database[0].databaseName;
201
+ const npxCmd = process.platform === "win32" ? "npx.cmd" : "npx";
193
202
  const wranglerArgs = [
203
+ npxCmd,
194
204
  "wrangler",
195
205
  "d1",
196
206
  "execute",
package/cli/index.ts CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env bun
2
1
  import { Command } from "commander";
3
2
  import { runBuild, runDev, runMigrate, runAddAdmin } from "./commands/index";
4
3
 
@@ -105,4 +104,9 @@ program
105
104
  });
106
105
  });
107
106
 
108
- await program.parseAsync(process.argv);
107
+ (async () => {
108
+ await program.parseAsync(process.argv);
109
+ })().catch((error) => {
110
+ console.error(error);
111
+ process.exit(1);
112
+ });
@@ -1,6 +1,5 @@
1
1
  import { DiscoveredHandlerOperation } from "../../../../utils/handler-discovery";
2
2
  import { buildFunctionPage } from "./render-page";
3
- import { buildExecutionLogic } from "./execute-handler";
4
3
 
5
4
  export function buildFunctionRoutes(
6
5
  handlers: DiscoveredHandlerOperation[],
@@ -11,10 +10,6 @@ export function buildFunctionRoutes(
11
10
  return `
12
11
  adminApp.get('/functions${h.routePath}', (c) => {
13
12
  ${buildFunctionPage(h)}
14
- });
15
-
16
- adminApp.post('/functions/execute${h.routePath}', async (c) => {
17
- ${buildExecutionLogic(h)}
18
13
  });`;
19
14
  });
20
15
 
@@ -19,7 +19,7 @@ export function buildFunctionPage(h: DiscoveredHandlerOperation): string {
19
19
  </div>
20
20
  </div>
21
21
 
22
- ${renderScripts()}
22
+ ${renderScripts(h)}
23
23
  \`;
24
24
 
25
25
  if (c.req.header('hx-request')) {
@@ -1,65 +1,169 @@
1
1
  import { DiscoveredHandlerOperation } from "../../../../../utils/handler-discovery";
2
2
 
3
+ function renderArgInputType(type: string): string {
4
+ if (type === "boolean") return "checkbox";
5
+ if (type === "number") return "number";
6
+ return "text";
7
+ }
8
+
9
+ function renderArgRows(h: DiscoveredHandlerOperation): string {
10
+ const fields = h.args ?? [];
11
+ if (fields.length === 0) {
12
+ return `
13
+ <div class="text-[11px] opacity-30 italic py-2">No arguments defined for this ${h.kind}.</div>
14
+ `;
15
+ }
16
+
17
+ return fields
18
+ .map((field) => {
19
+ const inputType = renderArgInputType(field.type);
20
+ const isCheckbox = inputType === "checkbox";
21
+ const label = `${field.name}${field.optional ? "" : " *"}`;
22
+ const badge =
23
+ field.type !== "unknown"
24
+ ? `<span class="badge badge-xs badge-ghost font-mono opacity-40 ml-1">${field.type}</span>`
25
+ : "";
26
+
27
+ if (isCheckbox) {
28
+ return `
29
+ <div class="flex items-center gap-3 py-1">
30
+ <input
31
+ type="checkbox"
32
+ data-arg-key="${field.name}"
33
+ data-arg-type="boolean"
34
+ class="checkbox checkbox-sm checkbox-primary"
35
+ ${field.defaultValue === "true" ? "checked" : ""}
36
+ />
37
+ <span class="text-sm font-mono opacity-70">${field.name}${badge}</span>
38
+ ${field.optional ? '<span class="text-[10px] opacity-30 italic ml-auto">optional</span>' : ""}
39
+ </div>
40
+ `;
41
+ }
42
+
43
+ return `
44
+ <div class="form-control">
45
+ <label class="label py-0.5">
46
+ <span class="label-text text-[11px] font-mono font-semibold">${label}${badge}</span>
47
+ ${field.optional ? '<span class="label-text-alt text-[10px] opacity-30 italic">optional</span>' : ""}
48
+ </label>
49
+ <input
50
+ type="${inputType}"
51
+ placeholder="${field.defaultValue ?? ""}"
52
+ data-arg-key="${field.name}"
53
+ data-arg-type="${field.type}"
54
+ value="${field.defaultValue ?? ""}"
55
+ class="input input-sm input-bordered font-mono w-full bg-base-200/30 focus:bg-base-100 focus:border-primary transition-all rounded-xl border-base-200"
56
+ ${!field.optional ? "required" : ""}
57
+ />
58
+ </div>
59
+ `;
60
+ })
61
+ .join("\n");
62
+ }
63
+
64
+ function renderArgumentsSection(h: DiscoveredHandlerOperation): string {
65
+ return `
66
+ <div class="space-y-4">
67
+ <div class="flex items-center justify-between">
68
+ <div class="flex flex-col">
69
+ <span class="text-[11px] font-bold uppercase tracking-wider opacity-40">Arguments</span>
70
+ <span class="text-[10px] font-mono opacity-30">${h.kind}</span>
71
+ </div>
72
+ <label class="flex items-center gap-2 cursor-pointer select-none group" title="Enable realtime updates via WebSocket">
73
+ <span class="text-[10px] font-bold uppercase tracking-wider opacity-40 group-hover:opacity-70 transition-opacity">Realtime</span>
74
+ <input type="checkbox" id="realtime-toggle" class="toggle toggle-xs toggle-success" onchange="toggleRealtime(this.checked)" />
75
+ </label>
76
+ </div>
77
+ <div id="args-rows" class="flex flex-col gap-3">
78
+ ${renderArgRows(h)}
79
+ </div>
80
+ <p class="text-[11px] opacity-30 mt-2 italic">Values are sent as ${h.kind === "query" ? "query string params" : "JSON request body"}.</p>
81
+ </div>
82
+ `;
83
+ }
84
+
85
+ function renderBearerTokenSection(): string {
86
+ return `
87
+ <div class="space-y-4">
88
+ <label class="text-[11px] font-bold uppercase tracking-wider opacity-40 block">Bearer Token <span class="font-normal normal-case">(optional)</span></label>
89
+ <div class="relative group">
90
+ <input
91
+ type="password"
92
+ name="token"
93
+ id="bearer-token-input"
94
+ class="input input-sm input-bordered font-mono text-sm w-full bg-base-200/30 focus:bg-base-100 focus:border-primary transition-all rounded-xl border-base-200 pr-9"
95
+ placeholder="eyJhbGciOi..."
96
+ />
97
+ <button type="button" onclick="toggleTokenVisibility()" class="absolute right-2.5 top-1/2 -translate-y-1/2 opacity-30 hover:opacity-70 transition-opacity">
98
+ <iconify-icon id="token-eye-icon" icon="solar:eye-linear" width="15" height="15"></iconify-icon>
99
+ </button>
100
+ </div>
101
+ <p class="text-[10px] opacity-30 italic">Token will be included in the Authorization header.</p>
102
+ </div>
103
+ `;
104
+ }
105
+
106
+ function renderCustomHeadersSection(): string {
107
+ return `
108
+ <div class="space-y-4">
109
+ <div class="flex items-center justify-between">
110
+ <span class="text-[11px] font-bold uppercase tracking-wider opacity-40">Custom Headers</span>
111
+ <button type="button" onclick="addHeaderRow()" class="btn btn-xs btn-ghost gap-1 opacity-50 hover:opacity-100">
112
+ <iconify-icon icon="solar:add-circle-linear" width="14" height="14"></iconify-icon>
113
+ Add
114
+ </button>
115
+ </div>
116
+ <div id="headers-rows" class="flex flex-col gap-2">
117
+ <!-- populated by addHeaderRow() -->
118
+ </div>
119
+ <p id="headers-error" class="text-[11px] text-error mt-1.5 hidden"></p>
120
+ </div>
121
+ `;
122
+ }
123
+
3
124
  export function renderRequestPanel(h: DiscoveredHandlerOperation): string {
4
125
  return `
5
- <div class="card bg-base-100 border border-base-200 shadow-sm overflow-hidden">
6
- <div class="px-5 py-4 border-b border-base-200 bg-base-200/20 flex items-center justify-between">
7
- <h3 class="text-xs font-bold uppercase tracking-widest opacity-40">Request Parameters</h3>
126
+ <div class="card bg-base-100 border border-base-200 shadow-sm overflow-hidden flex flex-col h-full">
127
+ <div class="px-5 py-3 border-b border-base-200 bg-base-200/20 flex items-center justify-between flex-none">
128
+ <h3 class="text-xs font-bold uppercase tracking-widest opacity-40">Request</h3>
8
129
  <iconify-icon icon="solar:settings-linear" width="16" height="16" class="opacity-30"></iconify-icon>
9
130
  </div>
10
- <div class="p-5">
11
- <form hx-post="/admin/functions/execute${h.routePath}" hx-target="#execution-result" hx-ext="json-enc" class="flex flex-col gap-5">
12
- <div class="form-control">
13
- <label class="label pt-0">
14
- <span class="label-text text-[11px] font-bold uppercase tracking-wider opacity-40">Arguments (JSON)</span>
15
- </label>
16
- <div class="relative group">
17
- <textarea
18
- name="args"
19
- class="textarea textarea-bordered font-mono text-sm w-full min-h-[160px] bg-base-200/30 focus:bg-base-100 focus:border-primary transition-all rounded-xl border-base-200"
20
- placeholder='{ }'
21
- >{}</textarea>
22
- <div class="absolute right-3 top-3 opacity-0 group-hover:opacity-40 transition-opacity pointer-events-none">
23
- <iconify-icon icon="solar:code-file-linear" width="18" height="18"></iconify-icon>
24
- </div>
131
+
132
+ <div class="flex-1 overflow-hidden flex flex-col">
133
+ <form id="fn-form" onsubmit="return false" class="flex flex-col h-full">
134
+ <!-- Tabs Navigation -->
135
+ <div class="px-5 pt-4 flex-none">
136
+ <div role="tablist" class="tabs tabs-box bg-base-200/50 p-1 rounded-xl">
137
+ <a role="tab" id="req-tab-btn-args" class="tab tab-active !text-[10px] !font-bold uppercase tracking-wider h-8" onclick="switchRequestTab('args')">Args</a>
138
+ <a role="tab" id="req-tab-btn-auth" class="tab !text-[10px] !font-bold uppercase tracking-wider h-8" onclick="switchRequestTab('auth')">Auth</a>
139
+ <a role="tab" id="req-tab-btn-headers" class="tab !text-[10px] !font-bold uppercase tracking-wider h-8" onclick="switchRequestTab('headers')">Headers</a>
25
140
  </div>
26
- <label class="label">
27
- <span class="label-text-alt opacity-40 italic">Provide the JSON arguments for this ${h.kind}</span>
28
- </label>
29
141
  </div>
30
142
 
31
- <div class="form-control">
32
- <label class="label pt-0">
33
- <span class="label-text text-[11px] font-bold uppercase tracking-wider opacity-40">Bearer Token (Optional)</span>
34
- </label>
35
- <div class="relative group">
36
- <input type="text" name="token" class="input input-sm input-bordered font-mono text-sm w-full bg-base-200/30 focus:bg-base-100 focus:border-primary transition-all rounded-xl border-base-200" placeholder="e.g. eyJhbGciOi..." />
37
- <div class="absolute right-3 top-1/2 -translate-y-1/2 opacity-0 group-hover:opacity-40 transition-opacity pointer-events-none">
38
- <iconify-icon icon="solar:key-linear" width="16" height="16"></iconify-icon>
39
- </div>
143
+ <!-- Tab Content -->
144
+ <div class="flex-1 overflow-y-auto">
145
+ <div id="request-tab-args" class="p-5">
146
+ ${renderArgumentsSection(h)}
40
147
  </div>
41
- </div>
42
-
43
- <div class="form-control">
44
- <label class="label pt-0">
45
- <span class="label-text text-[11px] font-bold uppercase tracking-wider opacity-40">Custom Headers (JSON)</span>
46
- </label>
47
- <div class="relative group">
48
- <textarea
49
- name="headers"
50
- class="textarea textarea-bordered font-mono text-sm w-full min-h-[80px] bg-base-200/30 focus:bg-base-100 focus:border-primary transition-all rounded-xl border-base-200"
51
- placeholder='{ "x-custom-header": "value" }'
52
- ></textarea>
53
- <div class="absolute right-3 top-3 opacity-0 group-hover:opacity-40 transition-opacity pointer-events-none">
54
- <iconify-icon icon="solar:list-linear" width="18" height="18"></iconify-icon>
55
- </div>
148
+ <div id="request-tab-auth" class="p-5 hidden">
149
+ ${renderBearerTokenSection()}
150
+ </div>
151
+ <div id="request-tab-headers" class="p-5 hidden">
152
+ ${renderCustomHeadersSection()}
56
153
  </div>
57
154
  </div>
58
155
 
59
- <button type="submit" class="btn btn-primary w-full gap-2 rounded-xl shadow-lg shadow-primary/20 hover:shadow-xl hover:shadow-primary/30 transition-all font-semibold">
60
- <iconify-icon icon="solar:play-bold" width="18" height="18"></iconify-icon>
61
- Run ${h.kind}
62
- </button>
156
+ <!-- Submit Button (Fixed at bottom) -->
157
+ <div class="p-5 border-t border-base-200 mt-auto bg-base-200/5">
158
+ <button
159
+ type="button"
160
+ onclick="executeFn()"
161
+ class="btn btn-primary w-full gap-2 rounded-xl shadow-lg shadow-primary/20 hover:shadow-xl hover:shadow-primary/30 transition-all font-semibold"
162
+ >
163
+ <iconify-icon icon="solar:play-bold" width="18" height="18"></iconify-icon>
164
+ Run ${h.kind}
165
+ </button>
166
+ </div>
63
167
  </form>
64
168
  </div>
65
169
  </div>
@@ -1,18 +1,84 @@
1
1
  export function renderResultPanel(): string {
2
2
  return `
3
3
  <div class="card bg-base-100 border border-base-200 shadow-sm overflow-hidden flex flex-col">
4
- <div class="px-5 py-4 border-b border-base-200 bg-base-200/20 flex items-center justify-between">
5
- <h3 class="text-xs font-bold uppercase tracking-widest opacity-40">Result</h3>
6
- <div class="flex items-center gap-2">
4
+ <!-- Panel Header -->
5
+ <div class="px-5 py-3 border-b border-base-200 bg-base-200/20 flex items-center justify-between">
6
+ <h3 class="text-xs font-bold uppercase tracking-widest opacity-40">Response</h3>
7
+ <div class="flex items-center gap-3">
8
+ <span id="res-status-badge" class="hidden"></span>
9
+ <span id="res-elapsed-badge" class="hidden text-xs font-mono opacity-50"></span>
7
10
  <div class="w-1.5 h-1.5 rounded-full bg-success animate-pulse opacity-0" id="execution-indicator"></div>
8
- <iconify-icon icon="solar:box-minimalistic-linear" width="16" height="16" class="opacity-30"></iconify-icon>
9
11
  </div>
10
12
  </div>
11
- <div class="flex-1 p-0 relative min-h-[300px] bg-neutral/5" id="execution-result">
12
- <div class="absolute inset-0 flex flex-col items-center justify-center opacity-20 pointer-events-none p-10 text-center">
13
- <iconify-icon icon="solar:course-down-bold-duotone" width="48" height="48" class="mb-3"></iconify-icon>
14
- <p class="text-xs font-semibold uppercase tracking-widest">Execute To See Output</p>
13
+
14
+ <!-- Tabs -->
15
+ <div role="tablist" class="tabs tabs-bordered tabs-sm px-4 pt-1 bg-base-200/10 border-b border-base-200">
16
+ <a role="tab" class="tab tab-active text-xs font-semibold" id="tab-body" onclick="switchResultTab('body')">Body</a>
17
+ <a role="tab" class="tab text-xs font-semibold" id="tab-resp-headers" onclick="switchResultTab('headers')">Headers</a>
18
+ <a role="tab" class="tab text-xs font-semibold" id="tab-info" onclick="switchResultTab('info')">Info</a>
19
+ <a role="tab" class="tab text-xs font-semibold gap-1.5" id="tab-realtime" onclick="switchResultTab('realtime')">
20
+ <span class="w-1.5 h-1.5 rounded-full bg-base-content/20 transition-colors duration-300" id="rt-dot"></span>
21
+ Realtime
22
+ </a>
23
+ </div>
24
+
25
+ <!-- Tab Panes -->
26
+ <div class="flex-1 relative min-h-[300px]">
27
+
28
+ <!-- Body Tab -->
29
+ <div id="result-tab-body" class="result-tab-pane absolute inset-0 overflow-auto">
30
+ <div class="absolute inset-0 flex flex-col items-center justify-center opacity-20 pointer-events-none p-10 text-center" id="result-empty-state">
31
+ <iconify-icon icon="solar:course-down-bold-duotone" width="48" height="48" class="mb-3"></iconify-icon>
32
+ <p class="text-xs font-semibold uppercase tracking-widest">Execute To See Output</p>
33
+ </div>
34
+ <div id="result-body-content" class="hidden h-full font-mono text-sm p-4 overflow-auto"></div>
35
+ </div>
36
+
37
+ <!-- Headers Tab -->
38
+ <div id="result-tab-headers" class="result-tab-pane absolute inset-0 overflow-auto hidden">
39
+ <div id="result-headers-content" class="p-4">
40
+ <div class="flex flex-col items-center justify-center h-40 opacity-20 text-center pointer-events-none">
41
+ <iconify-icon icon="solar:list-check-bold-duotone" width="36" height="36" class="mb-2"></iconify-icon>
42
+ <p class="text-xs font-semibold uppercase tracking-widest">No Response Yet</p>
43
+ </div>
44
+ </div>
45
+ </div>
46
+
47
+ <!-- Info Tab -->
48
+ <div id="result-tab-info" class="result-tab-pane absolute inset-0 overflow-auto hidden">
49
+ <div id="result-info-content" class="p-4">
50
+ <div class="flex flex-col items-center justify-center h-40 opacity-20 text-center pointer-events-none">
51
+ <iconify-icon icon="solar:info-circle-bold-duotone" width="36" height="36" class="mb-2"></iconify-icon>
52
+ <p class="text-xs font-semibold uppercase tracking-widest">No Response Yet</p>
53
+ </div>
54
+ </div>
55
+ </div>
56
+
57
+ <!-- Realtime Tab -->
58
+ <div id="result-tab-realtime" class="result-tab-pane absolute inset-0 overflow-auto hidden flex flex-col">
59
+ <!-- Connection status bar -->
60
+ <div class="flex items-center justify-between px-4 py-2 border-b border-base-200 bg-base-200/10 flex-none">
61
+ <div class="flex items-center gap-2">
62
+ <div class="w-2 h-2 rounded-full bg-base-content/20 transition-all duration-300" id="rt-status-dot"></div>
63
+ <span class="text-[10px] font-mono uppercase tracking-wider opacity-50" id="rt-status-text">Disconnected</span>
64
+ </div>
65
+ <div class="flex items-center gap-2">
66
+ <span class="text-[10px] font-mono opacity-30" id="rt-event-count" class="hidden">0 events</span>
67
+ <button type="button" onclick="clearRealtimeLog()" class="btn btn-xs btn-ghost opacity-40 hover:opacity-100 px-2 h-6 min-h-0">
68
+ <iconify-icon icon="solar:trash-bin-minimalistic-linear" width="12" height="12"></iconify-icon>
69
+ Clear
70
+ </button>
71
+ </div>
72
+ </div>
73
+ <!-- Events log -->
74
+ <div id="rt-log" class="flex-1 overflow-y-auto p-3 flex flex-col gap-1.5 font-mono text-xs">
75
+ <div id="rt-empty-state" class="flex flex-col items-center justify-center h-full opacity-20 text-center pointer-events-none gap-2">
76
+ <iconify-icon icon="solar:pulse-2-bold-duotone" width="40" height="40"></iconify-icon>
77
+ <p class="text-xs font-semibold uppercase tracking-widest">Enable Realtime in Request Panel</p>
78
+ </div>
79
+ </div>
15
80
  </div>
81
+
16
82
  </div>
17
83
  </div>
18
84
  `;