create-feedbax 0.1.0 → 0.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 (251) hide show
  1. package/LICENSE +201 -21
  2. package/README.md +11 -1
  3. package/dist/cli.js +3283 -22
  4. package/dist/index.js +3394 -160
  5. package/package.json +40 -14
  6. package/template/.feedbax-template.sha256 +1 -0
  7. package/template/.gitignore.template +6 -0
  8. package/template/.npmignore.template +5 -0
  9. package/template/.prettierignore.template +4 -0
  10. package/template/AGENTS.md +13 -0
  11. package/template/CONNECTED.md +404 -0
  12. package/template/LICENSE +201 -0
  13. package/template/README.md +56 -5
  14. package/template/components.json +25 -0
  15. package/template/eslint.config.mjs +48 -0
  16. package/template/migrations/0001_connected.sql +6 -0
  17. package/template/migrations/0002_participation.sql +8 -0
  18. package/template/migrations/0003_images.sql +3 -0
  19. package/template/migrations/0004_followed_status.sql +9 -0
  20. package/template/package.json +74 -14
  21. package/template/public/feedbax-mark.svg +4 -0
  22. package/template/public/robots.txt +3 -0
  23. package/template/src/authorized-draft-post.test.tsx +212 -0
  24. package/template/src/authorized-draft-post.tsx +205 -0
  25. package/template/src/authorized-draft-query.ts +74 -0
  26. package/template/src/browser-post-state.test.ts +120 -0
  27. package/template/src/browser-post-state.ts +134 -0
  28. package/template/src/browser-vote-state.test.ts +14 -0
  29. package/template/src/browser-vote-state.ts +27 -0
  30. package/template/src/capability-authorization-error.ts +3 -0
  31. package/template/src/changelog-page.test.tsx +139 -0
  32. package/template/src/changelog-page.tsx +228 -0
  33. package/template/src/changelog-query.ts +13 -0
  34. package/template/src/changelog-runtime.ts +27 -0
  35. package/template/src/cloudflare-turnstile.ts +31 -0
  36. package/template/src/cloudflare-workers-test.ts +3 -0
  37. package/template/src/cloudflare-workers.d.ts +24 -0
  38. package/template/src/comment-creation.test.tsx +311 -0
  39. package/template/src/comment-profile.ts +5 -0
  40. package/template/src/comment-thread-page.ts +28 -0
  41. package/template/src/components/command-palette-context.tsx +71 -0
  42. package/template/src/components/command-palette.tsx +275 -0
  43. package/template/src/components/connected-identity-provider.tsx +108 -0
  44. package/template/src/components/create-post-trigger.tsx +44 -0
  45. package/template/src/components/device-profile-provider.tsx +324 -0
  46. package/template/src/components/follow-post-button.tsx +89 -0
  47. package/template/src/components/header.tsx +97 -0
  48. package/template/src/components/image-attachments.tsx +187 -0
  49. package/template/src/components/loader.tsx +53 -0
  50. package/template/src/components/notification-inbox.tsx +232 -0
  51. package/template/src/components/portal-footer.tsx +14 -0
  52. package/template/src/components/profile-menu.tsx +119 -0
  53. package/template/src/components/ui/components/alert-dialog.tsx +185 -0
  54. package/template/src/components/ui/components/attachment.tsx +207 -0
  55. package/template/src/components/ui/components/avatar.tsx +107 -0
  56. package/template/src/components/ui/components/badge.tsx +52 -0
  57. package/template/src/components/ui/components/bubble.tsx +128 -0
  58. package/template/src/components/ui/components/button-group.tsx +87 -0
  59. package/template/src/components/ui/components/button.tsx +56 -0
  60. package/template/src/components/ui/components/card.tsx +103 -0
  61. package/template/src/components/ui/components/checkbox.tsx +26 -0
  62. package/template/src/components/ui/components/command.tsx +195 -0
  63. package/template/src/components/ui/components/dialog.tsx +154 -0
  64. package/template/src/components/ui/components/drawer.tsx +229 -0
  65. package/template/src/components/ui/components/dropdown-menu.tsx +270 -0
  66. package/template/src/components/ui/components/empty.tsx +101 -0
  67. package/template/src/components/ui/components/field.tsx +236 -0
  68. package/template/src/components/ui/components/input-group.tsx +155 -0
  69. package/template/src/components/ui/components/input.tsx +20 -0
  70. package/template/src/components/ui/components/item.tsx +201 -0
  71. package/template/src/components/ui/components/kbd.tsx +26 -0
  72. package/template/src/components/ui/components/label.tsx +18 -0
  73. package/template/src/components/ui/components/marker.tsx +71 -0
  74. package/template/src/components/ui/components/message-scroller.tsx +128 -0
  75. package/template/src/components/ui/components/message.tsx +92 -0
  76. package/template/src/components/ui/components/native-select.tsx +65 -0
  77. package/template/src/components/ui/components/popover.tsx +88 -0
  78. package/template/src/components/ui/components/portal-primitives.test.tsx +85 -0
  79. package/template/src/components/ui/components/radio-group.tsx +36 -0
  80. package/template/src/components/ui/components/scroll-area.tsx +51 -0
  81. package/template/src/components/ui/components/secondary-form-actions.test.tsx +23 -0
  82. package/template/src/components/ui/components/select.tsx +199 -0
  83. package/template/src/components/ui/components/separator.tsx +23 -0
  84. package/template/src/components/ui/components/sheet.tsx +135 -0
  85. package/template/src/components/ui/components/skeleton.tsx +13 -0
  86. package/template/src/components/ui/components/sonner.tsx +43 -0
  87. package/template/src/components/ui/components/spinner.tsx +16 -0
  88. package/template/src/components/ui/components/switch.tsx +29 -0
  89. package/template/src/components/ui/components/tabs.tsx +80 -0
  90. package/template/src/components/ui/components/textarea.tsx +18 -0
  91. package/template/src/components/ui/components/tooltip.tsx +64 -0
  92. package/template/src/components/ui/hooks/.gitkeep +0 -0
  93. package/template/src/components/ui/lib/utils.ts +6 -0
  94. package/template/src/components/ui/styles/globals.css +151 -0
  95. package/template/src/connected-identity.test.ts +144 -0
  96. package/template/src/connected-identity.ts +122 -0
  97. package/template/src/connected-participation.test.tsx +67 -0
  98. package/template/src/connected-runtime.test.ts +241 -0
  99. package/template/src/connected-runtime.ts +176 -0
  100. package/template/src/connected-social.test.tsx +158 -0
  101. package/template/src/create-post-overlay.tsx +82 -0
  102. package/template/src/draft-post-list.tsx +39 -0
  103. package/template/src/feedback-cache-invalidation.test.ts +185 -0
  104. package/template/src/feedback-cache-invalidation.ts +98 -0
  105. package/template/src/feedback-runtime.ts +105 -0
  106. package/template/src/feedbax/changelog/index.test.ts +156 -0
  107. package/template/src/feedbax/changelog/index.ts +206 -0
  108. package/template/src/feedbax/changelog/notion-changelog.test.ts +395 -0
  109. package/template/src/feedbax/changelog/notion-changelog.ts +400 -0
  110. package/template/src/feedbax/config/index.test.ts +139 -0
  111. package/template/src/feedbax/config/index.ts +364 -0
  112. package/template/src/feedbax/feedback/connected-feedback.ts +206 -0
  113. package/template/src/feedbax/feedback/connected.test.ts +272 -0
  114. package/template/src/feedbax/feedback/connected.ts +215 -0
  115. package/template/src/feedbax/feedback/email-delivery.test.ts +65 -0
  116. package/template/src/feedbax/feedback/email-delivery.ts +66 -0
  117. package/template/src/feedbax/feedback/feedback-storage.ts +43 -0
  118. package/template/src/feedbax/feedback/identity-handoff.test.ts +81 -0
  119. package/template/src/feedbax/feedback/identity-handoff.ts +119 -0
  120. package/template/src/feedbax/feedback/image-feedback.ts +101 -0
  121. package/template/src/feedbax/feedback/images.test.ts +223 -0
  122. package/template/src/feedbax/feedback/images.ts +324 -0
  123. package/template/src/feedbax/feedback/index.test.ts +900 -0
  124. package/template/src/feedbax/feedback/index.ts +996 -0
  125. package/template/src/feedbax/feedback/notion-comments.test.ts +171 -0
  126. package/template/src/feedbax/feedback/notion-comments.ts +231 -0
  127. package/template/src/feedbax/feedback/notion-data-source.test.ts +364 -0
  128. package/template/src/feedbax/feedback/notion-data-source.ts +458 -0
  129. package/template/src/feedbax/feedback/notion-feedback.test.ts +998 -0
  130. package/template/src/feedbax/feedback/notion-feedback.ts +651 -0
  131. package/template/src/feedbax/feedback/notion-image-review.ts +55 -0
  132. package/template/src/feedbax/feedback/notion-request.ts +74 -0
  133. package/template/src/feedbax/feedback/participation.test.ts +653 -0
  134. package/template/src/feedbax/feedback/participation.ts +502 -0
  135. package/template/src/feedbax.test-fixture.ts +64 -0
  136. package/template/src/feedbax.ts +69 -0
  137. package/template/src/images-runtime.test.ts +133 -0
  138. package/template/src/images-runtime.ts +125 -0
  139. package/template/src/index.css +1795 -0
  140. package/template/src/lazy-create-post-overlay.tsx +6 -0
  141. package/template/src/lazy-post-detail-overlay.tsx +21 -0
  142. package/template/src/masked-post-link.tsx +27 -0
  143. package/template/src/overlay-post-detail.test.tsx +181 -0
  144. package/template/src/overlay-post-detail.tsx +43 -0
  145. package/template/src/participation-client.ts +63 -0
  146. package/template/src/participation-runtime.test.ts +35 -0
  147. package/template/src/participation-runtime.ts +255 -0
  148. package/template/src/portal-comments.test.ts +375 -0
  149. package/template/src/portal-comments.ts +403 -0
  150. package/template/src/portal-features.test.tsx +150 -0
  151. package/template/src/portal-feedback-form.tsx +530 -0
  152. package/template/src/portal-feedback-runtime.test.ts +32 -0
  153. package/template/src/portal-feedback-runtime.ts +58 -0
  154. package/template/src/portal-feedback-server-function.ts +96 -0
  155. package/template/src/portal-feedback-submission.test.ts +307 -0
  156. package/template/src/portal-feedback-submission.ts +224 -0
  157. package/template/src/portal-head.ts +58 -0
  158. package/template/src/portal-server-entry.ts +68 -0
  159. package/template/src/portal-voting.test.ts +106 -0
  160. package/template/src/portal-voting.ts +149 -0
  161. package/template/src/post-badges.tsx +27 -0
  162. package/template/src/post-creation-flow.test.tsx +230 -0
  163. package/template/src/post-creation-flow.tsx +88 -0
  164. package/template/src/post-detail-content.test.tsx +233 -0
  165. package/template/src/post-detail-content.tsx +162 -0
  166. package/template/src/post-detail-overlay.test.tsx +114 -0
  167. package/template/src/post-detail-overlay.tsx +67 -0
  168. package/template/src/post-detail-query.ts +34 -0
  169. package/template/src/post-feed-controls.test.tsx +239 -0
  170. package/template/src/post-feed-controls.tsx +298 -0
  171. package/template/src/post-presentation.ts +37 -0
  172. package/template/src/post-queries.test.ts +158 -0
  173. package/template/src/post-queries.ts +26 -0
  174. package/template/src/post-results.tsx +165 -0
  175. package/template/src/public-cache-policy.test.ts +148 -0
  176. package/template/src/public-cache-policy.ts +119 -0
  177. package/template/src/public-cache-tags.ts +7 -0
  178. package/template/src/public-changelog-page.ts +15 -0
  179. package/template/src/public-changelog-server-function.ts +27 -0
  180. package/template/src/public-date.ts +11 -0
  181. package/template/src/public-failure-state.test.tsx +69 -0
  182. package/template/src/public-feedback-index.tsx +94 -0
  183. package/template/src/public-feedback-page.test.tsx +355 -0
  184. package/template/src/public-feedback-page.ts +86 -0
  185. package/template/src/public-feedback-server-function.ts +22 -0
  186. package/template/src/public-portal-error.tsx +27 -0
  187. package/template/src/public-post-detail-skeleton.tsx +54 -0
  188. package/template/src/public-post-detail.tsx +772 -0
  189. package/template/src/public-post-page.test.tsx +173 -0
  190. package/template/src/public-post-page.ts +15 -0
  191. package/template/src/public-post-route.test.tsx +250 -0
  192. package/template/src/public-post-route.tsx +158 -0
  193. package/template/src/public-post-server-function.ts +48 -0
  194. package/template/src/public-post-unavailable.tsx +10 -0
  195. package/template/src/public-roadmap-page.test.tsx +139 -0
  196. package/template/src/public-roadmap-page.ts +24 -0
  197. package/template/src/public-roadmap-route.test.tsx +254 -0
  198. package/template/src/public-roadmap-route.tsx +50 -0
  199. package/template/src/public-roadmap-server-function.ts +44 -0
  200. package/template/src/public-roadmap-view.tsx +411 -0
  201. package/template/src/public-shell.test.tsx +544 -0
  202. package/template/src/roadmap-query.ts +21 -0
  203. package/template/src/root-branding.test.ts +53 -0
  204. package/template/src/routeTree.gen.ts +177 -0
  205. package/template/src/routed-post-creation-form.tsx +28 -0
  206. package/template/src/router.tsx +27 -0
  207. package/template/src/routes/__root.tsx +114 -0
  208. package/template/src/routes/changelog.tsx +39 -0
  209. package/template/src/routes/email-preferences.tsx +77 -0
  210. package/template/src/routes/index.tsx +61 -0
  211. package/template/src/routes/p.$slug.tsx +16 -0
  212. package/template/src/routes/roadmap.tsx +11 -0
  213. package/template/src/routes/submit.tsx +28 -0
  214. package/template/src/safe-public-failure.ts +47 -0
  215. package/template/src/server.ts +151 -0
  216. package/template/src/similar-posts.tsx +45 -0
  217. package/template/src/submit-route.test.tsx +134 -0
  218. package/template/src/trusted-feedback-handler.test.ts +425 -0
  219. package/template/src/trusted-feedback-handler.ts +181 -0
  220. package/template/src/trusted-feedback-runtime.ts +17 -0
  221. package/template/src/turnstile-configuration.test.ts +37 -0
  222. package/template/src/turnstile-configuration.ts +19 -0
  223. package/template/src/use-media-query.ts +17 -0
  224. package/template/src/vote-toggle.test.tsx +171 -0
  225. package/template/src/vote-toggle.tsx +244 -0
  226. package/template/tsconfig.json +45 -0
  227. package/template/vite.config.ts +20 -0
  228. package/template/vitest.config.ts +4 -0
  229. package/template/vitest.setup.ts +3 -0
  230. package/template/wrangler.jsonc +35 -0
  231. package/dist/cli.d.ts +0 -3
  232. package/dist/cli.d.ts.map +0 -1
  233. package/dist/cli.js.map +0 -1
  234. package/dist/index.d.ts +0 -21
  235. package/dist/index.d.ts.map +0 -1
  236. package/dist/index.js.map +0 -1
  237. package/template/.env.example +0 -4
  238. package/template/apps/portal/components.json +0 -20
  239. package/template/apps/portal/package.json +0 -31
  240. package/template/apps/portal/src/lib/utils.ts +0 -6
  241. package/template/apps/portal/src/routeTree.gen.ts +0 -59
  242. package/template/apps/portal/src/router.tsx +0 -10
  243. package/template/apps/portal/src/routes/__root.tsx +0 -31
  244. package/template/apps/portal/src/routes/index.tsx +0 -35
  245. package/template/apps/portal/src/styles.css +0 -91
  246. package/template/apps/portal/tsconfig.json +0 -15
  247. package/template/apps/portal/vite.config.ts +0 -13
  248. package/template/feedbax.config.ts +0 -13
  249. package/template/feedbax.jsonc +0 -11
  250. package/template/pnpm-workspace.yaml +0 -3
  251. package/template/turbo.json +0 -8
package/dist/cli.js CHANGED
@@ -1,28 +1,3289 @@
1
1
  #!/usr/bin/env node
2
- import { createInterface } from 'node:readline/promises';
3
- import { createProject, resolveCreateOptions, resolveInteractiveCreateOptions, } from './index.js';
4
- try {
5
- const argv = process.argv.slice(2);
6
- const interactive = process.stdin.isTTY && process.stdout.isTTY;
7
- const options = interactive
8
- ? await (async () => {
9
- const terminal = createInterface({
10
- input: process.stdin,
11
- output: process.stdout,
2
+
3
+ // src/cli.ts
4
+ import * as prompt from "@clack/prompts";
5
+ import { spawn } from "node:child_process";
6
+ import { readFile as readFile3 } from "node:fs/promises";
7
+ import { basename as basename2, resolve as resolve2 } from "node:path";
8
+
9
+ // src/index.ts
10
+ import { createHash, randomBytes } from "node:crypto";
11
+ import { readFile as readFile2, readdir as readdir2, writeFile as writeFile2 } from "node:fs/promises";
12
+
13
+ // ../config/src/index.ts
14
+ var rootKeys = [
15
+ "connected",
16
+ "product",
17
+ "theme",
18
+ "notion",
19
+ "changelog",
20
+ "features",
21
+ "submissions",
22
+ "turnstile"
23
+ ];
24
+ var featureKeys = ["voting", "comments", "changelog"];
25
+ var feedbackPropertyKeys = [
26
+ "title",
27
+ "slug",
28
+ "description",
29
+ "type",
30
+ "status",
31
+ "published",
32
+ "voteCount",
33
+ "teamResponse",
34
+ "releaseNotesUrl",
35
+ "submitterName",
36
+ "submitterEmail",
37
+ "source",
38
+ "externalId",
39
+ "editTokenHash",
40
+ "createdAt",
41
+ "updatedAt"
42
+ ];
43
+ var changelogPropertyKeys = [
44
+ "title",
45
+ "slug",
46
+ "date",
47
+ "summary",
48
+ "body",
49
+ "labels",
50
+ "image",
51
+ "published",
52
+ "createdAt",
53
+ "updatedAt"
54
+ ];
55
+ function defineFeedbax(config) {
56
+ const value = object(config, "Feedbax configuration");
57
+ rejectUnknown(value, rootKeys, "Feedbax configuration");
58
+ const product = object(value.product, "product");
59
+ rejectUnknown(
60
+ product,
61
+ ["name", "description", "logo", "siteUrl", "supportUrl", "privacyUrl"],
62
+ "product"
63
+ );
64
+ const validatedProduct = {
65
+ name: text(product.name, "product.name"),
66
+ description: text(product.description, "product.description"),
67
+ logo: publicUrl(product.logo, "product.logo", true),
68
+ ...optionalPublicUrl(product, "siteUrl"),
69
+ ...optionalPublicUrl(product, "supportUrl"),
70
+ ...optionalPublicUrl(product, "privacyUrl")
71
+ };
72
+ let connected;
73
+ if (value.connected !== void 0) {
74
+ const input = object(value.connected, "connected");
75
+ rejectUnknown(
76
+ input,
77
+ ["issuer", "loginUrl", "email", "images", "processing"],
78
+ "connected"
79
+ );
80
+ const issuer = publicUrl(input.issuer, "connected.issuer", false);
81
+ const loginUrl = publicUrl(input.loginUrl, "connected.loginUrl", false);
82
+ if (!validatedProduct.siteUrl)
83
+ throw new Error("Connected Profile requires product.siteUrl.");
84
+ if (new URL(loginUrl).username || new URL(loginUrl).password || new URL(loginUrl).hash)
85
+ throw new Error(
86
+ "connected.loginUrl must not contain credentials or a fragment."
87
+ );
88
+ let email;
89
+ if (input.email !== void 0) {
90
+ const sender = object(input.email, "connected.email");
91
+ rejectUnknown(
92
+ sender,
93
+ ["provider", "from", "endpoint"],
94
+ "connected.email"
95
+ );
96
+ if (!["cloudflare", "resend", "custom"].includes(String(sender.provider)))
97
+ throw new Error(
98
+ "connected.email.provider must be cloudflare, resend, or custom."
99
+ );
100
+ const from = text(sender.from, "connected.email.from");
101
+ if (from.length > 254 || !/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(from))
102
+ throw new Error(
103
+ "connected.email.from must be a plain sender email address."
104
+ );
105
+ const endpoint = sender.endpoint === void 0 ? void 0 : publicUrl(sender.endpoint, "connected.email.endpoint", false);
106
+ if (sender.provider === "custom" && !endpoint)
107
+ throw new Error("Custom email requires connected.email.endpoint.");
108
+ if (sender.provider !== "custom" && endpoint)
109
+ throw new Error("Only custom email uses connected.email.endpoint.");
110
+ if (endpoint && (new URL(endpoint).username || new URL(endpoint).password || new URL(endpoint).hash))
111
+ throw new Error(
112
+ "Custom email endpoint must not contain credentials or a fragment."
113
+ );
114
+ email = {
115
+ provider: sender.provider,
116
+ from,
117
+ ...endpoint ? { endpoint } : {}
118
+ };
119
+ }
120
+ if (input.images !== void 0 && typeof input.images !== "boolean")
121
+ throw new Error("connected.images must be true or false.");
122
+ if (input.processing !== void 0 && input.processing !== "small" && input.processing !== "standard")
123
+ throw new Error("connected.processing must be small or standard.");
124
+ connected = {
125
+ issuer,
126
+ loginUrl,
127
+ ...input.processing !== void 0 ? { processing: input.processing } : {},
128
+ ...email ? { email } : {},
129
+ ...input.images !== void 0 ? { images: input.images } : {}
130
+ };
131
+ }
132
+ const theme = object(value.theme, "theme");
133
+ rejectUnknown(theme, ["preset"], "theme");
134
+ const notion = storage(
135
+ value.notion,
136
+ feedbackPropertyKeys,
137
+ "notion"
138
+ );
139
+ const features = object(value.features, "features");
140
+ rejectUnknown(features, featureKeys, "features");
141
+ const validatedFeatures = Object.fromEntries(
142
+ featureKeys.map((key) => {
143
+ if (typeof features[key] !== "boolean")
144
+ throw new Error(`features.${key} must be true or false.`);
145
+ return [key, features[key]];
146
+ })
147
+ );
148
+ const changelog = value.changelog === void 0 ? void 0 : storage(
149
+ value.changelog,
150
+ changelogPropertyKeys,
151
+ "changelog"
152
+ );
153
+ if (validatedFeatures.changelog && !changelog)
154
+ throw new Error(
155
+ "Changelog is enabled but changelog storage is not configured. Add changelog identifiers and property mappings, or set features.changelog to false."
156
+ );
157
+ const submissions = object(value.submissions, "submissions");
158
+ rejectUnknown(
159
+ submissions,
160
+ ["moderation", "maxTitleLength", "maxDescriptionLength"],
161
+ "submissions"
162
+ );
163
+ if (submissions.moderation !== "required")
164
+ throw new Error('submissions.moderation must be "required".');
165
+ const turnstile = object(value.turnstile, "turnstile");
166
+ rejectUnknown(turnstile, ["enabled", "siteKey"], "turnstile");
167
+ if (typeof turnstile.enabled !== "boolean")
168
+ throw new Error("turnstile.enabled must be true or false.");
169
+ const siteKey = turnstile.siteKey === void 0 ? void 0 : text(turnstile.siteKey, "turnstile.siteKey");
170
+ if (turnstile.enabled && !siteKey)
171
+ throw new Error("Turnstile is enabled but turnstile.siteKey is missing.");
172
+ return {
173
+ product: validatedProduct,
174
+ ...connected ? { connected } : {},
175
+ theme: { preset: text(theme.preset, "theme.preset") },
176
+ notion,
177
+ ...changelog ? { changelog } : {},
178
+ features: validatedFeatures,
179
+ submissions: {
180
+ moderation: "required",
181
+ maxTitleLength: positiveInteger(
182
+ submissions.maxTitleLength,
183
+ "submissions.maxTitleLength"
184
+ ),
185
+ maxDescriptionLength: positiveInteger(
186
+ submissions.maxDescriptionLength,
187
+ "submissions.maxDescriptionLength"
188
+ )
189
+ },
190
+ turnstile: { enabled: turnstile.enabled, ...siteKey ? { siteKey } : {} }
191
+ };
192
+ }
193
+ function storage(value, keys, label) {
194
+ const input = object(value, label);
195
+ rejectUnknown(input, ["databaseId", "dataSourceId", "properties"], label);
196
+ const properties = object(input.properties, `${label}.properties`);
197
+ rejectUnknown(properties, keys, `${label}.properties`);
198
+ for (const key of keys) text(properties[key], `${label}.properties.${key}`);
199
+ return {
200
+ databaseId: text(input.databaseId, `${label}.databaseId`),
201
+ dataSourceId: text(input.dataSourceId, `${label}.dataSourceId`),
202
+ properties: { ...properties }
203
+ };
204
+ }
205
+ function object(value, label) {
206
+ if (!value || typeof value !== "object" || Array.isArray(value))
207
+ throw new Error(`${label} must be an object.`);
208
+ return value;
209
+ }
210
+ function text(value, label) {
211
+ if (typeof value !== "string" || !value.trim())
212
+ throw new Error(`${label} must be a non-empty string.`);
213
+ return value.trim();
214
+ }
215
+ function positiveInteger(value, label) {
216
+ if (!Number.isInteger(value) || Number(value) <= 0)
217
+ throw new Error(`${label} must be a positive integer.`);
218
+ return Number(value);
219
+ }
220
+ function rejectUnknown(value, allowed, label) {
221
+ const key = Object.keys(value).find(
222
+ (candidate) => !allowed.includes(candidate)
223
+ );
224
+ if (key) throw new Error(`Unknown ${label} key "${key}".`);
225
+ }
226
+ function optionalPublicUrl(value, key) {
227
+ return value[key] === void 0 ? {} : { [key]: publicUrl(value[key], `product.${key}`, false) };
228
+ }
229
+ function publicUrl(value, label, allowRelative) {
230
+ const url = text(value, label);
231
+ if (allowRelative && url.startsWith("/") && !url.startsWith("//") && !url.includes("\\") && !Array.from(url).some((character) => character.charCodeAt(0) <= 32))
232
+ return url;
233
+ try {
234
+ if (new URL(url).protocol === "https:") return url;
235
+ } catch {
236
+ }
237
+ throw new Error(
238
+ `${label} must be ${allowRelative ? "root-relative or " : ""}an HTTPS URL.`
239
+ );
240
+ }
241
+
242
+ // src/index.ts
243
+ import { basename, join as join2 } from "node:path";
244
+
245
+ // src/template.ts
246
+ import { parse } from "jsonc-parser";
247
+ import {
248
+ cp,
249
+ mkdir,
250
+ readFile,
251
+ readdir,
252
+ rm,
253
+ stat,
254
+ writeFile
255
+ } from "node:fs/promises";
256
+ import { dirname, join, relative, resolve } from "node:path";
257
+ import { fileURLToPath } from "node:url";
258
+ var packagedTemplateDirectory = resolve(
259
+ dirname(fileURLToPath(import.meta.url)),
260
+ "../template"
261
+ );
262
+ async function copyPackagedTemplate(destination, packaged = packagedTemplateDirectory) {
263
+ const target = resolve(destination);
264
+ await mkdir(target, { recursive: true });
265
+ if ((await readdir(target)).length)
266
+ throw new Error(
267
+ `Refusing to generate into non-empty destination: ${target}`
268
+ );
269
+ await cp(packaged, target, { recursive: true });
270
+ await renameIgnoreTemplates(target);
271
+ }
272
+ async function renameIgnoreTemplates(target) {
273
+ const { rename } = await import("node:fs/promises");
274
+ for (const name of [".gitignore", ".npmignore", ".prettierignore"])
275
+ await rename(join(target, `${name}.template`), join(target, name));
276
+ }
277
+
278
+ // ../feedback/src/notion-request.ts
279
+ var MAX_ATTEMPTS = 3;
280
+ var BASE_BACKOFF_MILLISECONDS = 250;
281
+ var MAX_BACKOFF_MILLISECONDS = 2e3;
282
+ async function requestNotion(input, init = {}, {
283
+ request,
284
+ retry = {},
285
+ operation
286
+ }) {
287
+ const sleep = retry.sleep ?? defaultSleep;
288
+ const random = retry.random ?? Math.random;
289
+ for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt += 1) {
290
+ const response = await request(input, init);
291
+ if (!isRetryableNotionFailure(response.status, operation)) return response;
292
+ if (attempt === MAX_ATTEMPTS) {
293
+ throw new Error(
294
+ `Notion request failed after ${MAX_ATTEMPTS} attempts (${response.status}).`
295
+ );
296
+ }
297
+ await sleep(retryDelayMilliseconds(response, attempt, random));
298
+ }
299
+ throw new Error("Notion request retry loop ended unexpectedly.");
300
+ }
301
+ function isRetryableNotionFailure(status, operation) {
302
+ return status === 429 || status === 529 && operation === "idempotent";
303
+ }
304
+ function retryDelayMilliseconds(response, attempt, random) {
305
+ const retryAfter = response.headers.get("Retry-After");
306
+ if (retryAfter) {
307
+ const seconds = Number(retryAfter);
308
+ if (Number.isFinite(seconds) && seconds >= 0) return seconds * 1e3;
309
+ }
310
+ return exponentialDelayMilliseconds(attempt, random);
311
+ }
312
+ function exponentialDelayMilliseconds(attempt, random) {
313
+ const ceiling = Math.min(
314
+ BASE_BACKOFF_MILLISECONDS * 2 ** (attempt - 1),
315
+ MAX_BACKOFF_MILLISECONDS
316
+ );
317
+ return Math.round(ceiling / 2 + random() * (ceiling / 2));
318
+ }
319
+ async function defaultSleep(milliseconds) {
320
+ await new Promise((resolve3) => setTimeout(resolve3, milliseconds));
321
+ }
322
+
323
+ // ../feedback/src/notion-data-source.ts
324
+ var NOTION_API_URL = "https://api.notion.com/v1";
325
+ var NOTION_API_VERSION = "2026-03-11";
326
+ var canonicalProperties = {
327
+ title: { name: "Title", type: "title", schema: { title: {} } },
328
+ slug: { name: "Slug", type: "rich_text", schema: { rich_text: {} } },
329
+ description: {
330
+ name: "Description",
331
+ type: "rich_text",
332
+ schema: { rich_text: {} }
333
+ },
334
+ type: {
335
+ name: "Type",
336
+ type: "select",
337
+ schema: {
338
+ select: {
339
+ options: [
340
+ { name: "Feature Request" },
341
+ { name: "Bug Report" },
342
+ { name: "General Feedback" }
343
+ ]
344
+ }
345
+ }
346
+ },
347
+ status: {
348
+ name: "Status",
349
+ type: "select",
350
+ schema: {
351
+ select: {
352
+ options: [
353
+ { name: "New" },
354
+ { name: "Reviewing" },
355
+ { name: "Planned" },
356
+ { name: "In Progress" },
357
+ { name: "Shipped" },
358
+ { name: "Closed" }
359
+ ]
360
+ }
361
+ }
362
+ },
363
+ published: {
364
+ name: "Published",
365
+ type: "checkbox",
366
+ schema: { checkbox: {} }
367
+ },
368
+ voteCount: {
369
+ name: "Vote Count",
370
+ type: "number",
371
+ schema: { number: { format: "number" } }
372
+ },
373
+ teamResponse: {
374
+ name: "Team Response",
375
+ type: "rich_text",
376
+ schema: { rich_text: {} }
377
+ },
378
+ releaseNotesUrl: {
379
+ name: "Release Notes URL",
380
+ type: "url",
381
+ schema: { url: {} }
382
+ },
383
+ submitterName: {
384
+ name: "Submitter Name",
385
+ type: "rich_text",
386
+ schema: { rich_text: {} }
387
+ },
388
+ submitterEmail: {
389
+ name: "Submitter Email",
390
+ type: "email",
391
+ schema: { email: {} }
392
+ },
393
+ source: {
394
+ name: "Source",
395
+ type: "select",
396
+ schema: {
397
+ select: {
398
+ options: [{ name: "Portal" }, { name: "API" }, { name: "Team" }]
399
+ }
400
+ }
401
+ },
402
+ externalId: {
403
+ name: "External ID",
404
+ type: "rich_text",
405
+ schema: { rich_text: {} }
406
+ },
407
+ editTokenHash: {
408
+ name: "Edit Token Hash",
409
+ type: "rich_text",
410
+ schema: { rich_text: {} }
411
+ },
412
+ createdAt: {
413
+ name: "Created At",
414
+ type: "created_time",
415
+ schema: { created_time: {} }
416
+ },
417
+ updatedAt: {
418
+ name: "Updated At",
419
+ type: "last_edited_time",
420
+ schema: { last_edited_time: {} }
421
+ }
422
+ };
423
+ var feedbackWorkflowProperties = {
424
+ Owner: { people: {} },
425
+ Priority: {
426
+ select: {
427
+ options: [
428
+ { name: "Urgent" },
429
+ { name: "High" },
430
+ { name: "Medium" },
431
+ { name: "Low" }
432
+ ]
433
+ }
434
+ },
435
+ "Strategic Theme": { multi_select: { options: [] } },
436
+ "Participant Segment": { multi_select: { options: [] } },
437
+ Impact: {
438
+ select: {
439
+ options: [{ name: "High" }, { name: "Medium" }, { name: "Low" }]
440
+ }
441
+ },
442
+ Effort: {
443
+ select: {
444
+ options: [{ name: "Small" }, { name: "Medium" }, { name: "Large" }]
445
+ }
446
+ },
447
+ "Decision Note": { rich_text: {} },
448
+ "Needs Follow-up": { checkbox: {} }
449
+ };
450
+ async function createNotionFeedbackDataSource({
451
+ token,
452
+ parentPageId,
453
+ request = fetch,
454
+ retry
455
+ }) {
456
+ const response = await requestNotion(
457
+ `${NOTION_API_URL}/databases`,
458
+ {
459
+ method: "POST",
460
+ headers: notionHeaders(token),
461
+ body: JSON.stringify({
462
+ parent: { type: "page_id", page_id: parentPageId },
463
+ title: [{ type: "text", text: { content: "Feedback" } }],
464
+ initial_data_source: {
465
+ properties: {
466
+ ...Object.fromEntries(
467
+ Object.values(canonicalProperties).map(({ name, schema }) => [
468
+ name,
469
+ schema
470
+ ])
471
+ ),
472
+ ...feedbackWorkflowProperties
473
+ }
474
+ }
475
+ })
476
+ },
477
+ { request, retry, operation: "create" }
478
+ );
479
+ const database = await readNotionResponse(response);
480
+ if (typeof database.id !== "string") {
481
+ throw new Error("Notion did not return the created Feedback database.");
482
+ }
483
+ const dataSourceId = firstDataSourceId(database);
484
+ const dataSourceResponse = await requestNotion(
485
+ `${NOTION_API_URL}/data_sources/${dataSourceId}`,
486
+ { method: "GET", headers: notionHeaders(token) },
487
+ { request, retry, operation: "idempotent" }
488
+ );
489
+ const dataSource = await readNotionResponse(dataSourceResponse);
490
+ return configurationFromCanonicalNames(dataSource, database.id);
491
+ }
492
+ async function createFeedbackWorkflowViews({
493
+ token,
494
+ databaseId,
495
+ dataSourceId,
496
+ propertyIds: propertyIds2,
497
+ request = fetch
498
+ }) {
499
+ const views = [
500
+ {
501
+ name: "Inbox",
502
+ type: "table",
503
+ filter: selectFilter(propertyIds2.status, "New"),
504
+ sorts: [{ property: propertyIds2.createdAt, direction: "descending" }]
505
+ },
506
+ {
507
+ name: "Reviewing",
508
+ type: "table",
509
+ filter: selectFilter(propertyIds2.status, "Reviewing"),
510
+ sorts: [{ property: propertyIds2.updatedAt, direction: "descending" }]
511
+ },
512
+ {
513
+ name: "Prioritization",
514
+ type: "table",
515
+ filter: {
516
+ or: [
517
+ selectFilter(propertyIds2.status, "Reviewing"),
518
+ selectFilter(propertyIds2.status, "Planned")
519
+ ]
520
+ },
521
+ sorts: [
522
+ { property: "Priority", direction: "ascending" },
523
+ { property: propertyIds2.voteCount, direction: "descending" }
524
+ ]
525
+ },
526
+ {
527
+ name: "Follow-up",
528
+ type: "table",
529
+ filter: { property: "Needs Follow-up", checkbox: { equals: true } }
530
+ },
531
+ {
532
+ name: "Roadmap",
533
+ type: "board",
534
+ filter: {
535
+ or: ["Planned", "In Progress", "Shipped"].map(
536
+ (status) => selectFilter(propertyIds2.status, status)
537
+ )
538
+ },
539
+ configuration: {
540
+ type: "board",
541
+ group_by: {
542
+ type: "select",
543
+ property_id: propertyIds2.status,
544
+ group_by: "option",
545
+ sort: { type: "manual" }
546
+ }
547
+ }
548
+ },
549
+ {
550
+ name: "Shipped",
551
+ type: "table",
552
+ filter: selectFilter(propertyIds2.status, "Shipped"),
553
+ sorts: [{ property: propertyIds2.updatedAt, direction: "descending" }]
554
+ }
555
+ ];
556
+ for (const view of views) {
557
+ const response = await requestNotion(
558
+ `${NOTION_API_URL}/views`,
559
+ {
560
+ method: "POST",
561
+ headers: notionHeaders(token),
562
+ body: JSON.stringify({
563
+ database_id: databaseId,
564
+ data_source_id: dataSourceId,
565
+ ...view
566
+ })
567
+ },
568
+ { request, operation: "create" }
569
+ );
570
+ await readNotionResponse(response);
571
+ }
572
+ }
573
+ function selectFilter(property, value) {
574
+ return { property, select: { equals: value } };
575
+ }
576
+ async function validateNotionFeedbackDataSource({
577
+ token,
578
+ dataSourceId,
579
+ propertyIds: propertyIds2,
580
+ request = fetch,
581
+ retry
582
+ }) {
583
+ const response = await requestNotion(
584
+ `${NOTION_API_URL}/data_sources/${dataSourceId}`,
585
+ {
586
+ method: "GET",
587
+ headers: notionHeaders(token)
588
+ },
589
+ { request, retry, operation: "idempotent" }
590
+ );
591
+ const dataSource = await readNotionResponse(response);
592
+ const properties = dataSource.properties;
593
+ if (typeof dataSource.id !== "string" || !isPropertyMap(properties)) {
594
+ throw new Error(
595
+ "Notion returned an invalid Feedback Data Source response."
596
+ );
597
+ }
598
+ const propertiesById = new Map(
599
+ Object.values(properties).filter(
600
+ (property) => Boolean(property) && typeof property.id === "string"
601
+ ).map((property) => [property.id, property])
602
+ );
603
+ const repairs = [];
604
+ for (const [key, { name, type }] of Object.entries(canonicalProperties)) {
605
+ const configuredId = propertyIds2[key];
606
+ const property = propertiesById.get(configuredId);
607
+ if (!property) {
608
+ repairs.push(
609
+ `Restore the "${name}" property with ID "${configuredId}" and type "${type}", then update the configured property ID if Notion assigns a new one.`
610
+ );
611
+ } else if (property.type !== type) {
612
+ repairs.push(
613
+ `Change the property configured as "${name}" (ID "${configuredId}") from "${String(property.type)}" to "${type}", or restore a ${type} property and configure its ID.`
614
+ );
615
+ }
616
+ }
617
+ if (repairs.length > 0) {
618
+ throw new Error(repairs.join("\n"));
619
+ }
620
+ return {
621
+ databaseId: databaseIdFromDataSource(dataSource),
622
+ dataSourceId,
623
+ propertyIds: { ...propertyIds2 }
624
+ };
625
+ }
626
+ function notionHeaders(token) {
627
+ return {
628
+ Authorization: `Bearer ${token}`,
629
+ "Content-Type": "application/json",
630
+ "Notion-Version": NOTION_API_VERSION
631
+ };
632
+ }
633
+ async function readNotionResponse(response) {
634
+ const body = await response.json();
635
+ if (!response.ok) {
636
+ throw new Error(
637
+ `Notion rejected the Feedback Data Source request (${response.status}).`
638
+ );
639
+ }
640
+ if (!body || typeof body !== "object") {
641
+ throw new Error(
642
+ "Notion returned an invalid Feedback Data Source response."
643
+ );
644
+ }
645
+ return body;
646
+ }
647
+ function firstDataSourceId(database) {
648
+ const dataSources = Reflect.get(database, "data_sources");
649
+ const firstDataSource = Array.isArray(dataSources) ? dataSources[0] : void 0;
650
+ const id = firstDataSource && typeof firstDataSource === "object" ? Reflect.get(firstDataSource, "id") : void 0;
651
+ if (typeof id !== "string") {
652
+ throw new Error("Notion did not return the created Feedback Data Source.");
653
+ }
654
+ return id;
655
+ }
656
+ function configurationFromCanonicalNames(dataSource, databaseId) {
657
+ const properties = dataSource.properties;
658
+ if (typeof dataSource.id !== "string" || !isPropertyMap(properties)) {
659
+ throw new Error(
660
+ "Notion returned an invalid Feedback Data Source response."
661
+ );
662
+ }
663
+ return {
664
+ databaseId,
665
+ dataSourceId: dataSource.id,
666
+ propertyIds: Object.fromEntries(
667
+ Object.entries(canonicalProperties).map(([key, { name }]) => {
668
+ const property = properties[name];
669
+ if (!property || typeof property.id !== "string") {
670
+ throw new Error(
671
+ `Notion did not return the required ${name} property.`
672
+ );
673
+ }
674
+ return [key, property.id];
675
+ })
676
+ )
677
+ };
678
+ }
679
+ function databaseIdFromDataSource(dataSource) {
680
+ const parent = dataSource.parent;
681
+ const databaseId = parent && typeof parent === "object" ? Reflect.get(parent, "database_id") : void 0;
682
+ if (typeof databaseId !== "string") {
683
+ throw new Error(
684
+ "Notion did not return the Feedback Data Source parent database."
685
+ );
686
+ }
687
+ return databaseId;
688
+ }
689
+ function isPropertyMap(value) {
690
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
691
+ }
692
+
693
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/entity.js
694
+ var entityKind = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
695
+ function is(value, type) {
696
+ if (!value || typeof value !== "object") {
697
+ return false;
698
+ }
699
+ if (value instanceof type) {
700
+ return true;
701
+ }
702
+ if (!Object.prototype.hasOwnProperty.call(type, entityKind)) {
703
+ throw new Error(
704
+ `Class "${type.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`
705
+ );
706
+ }
707
+ let cls = Object.getPrototypeOf(value).constructor;
708
+ if (cls) {
709
+ while (cls) {
710
+ if (entityKind in cls && cls[entityKind] === type[entityKind]) {
711
+ return true;
712
+ }
713
+ cls = Object.getPrototypeOf(cls);
714
+ }
715
+ }
716
+ return false;
717
+ }
718
+
719
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/column.js
720
+ var Column = class {
721
+ constructor(table, config) {
722
+ this.table = table;
723
+ this.config = config;
724
+ this.name = config.name;
725
+ this.keyAsName = config.keyAsName;
726
+ this.notNull = config.notNull;
727
+ this.default = config.default;
728
+ this.defaultFn = config.defaultFn;
729
+ this.onUpdateFn = config.onUpdateFn;
730
+ this.hasDefault = config.hasDefault;
731
+ this.primary = config.primaryKey;
732
+ this.isUnique = config.isUnique;
733
+ this.uniqueName = config.uniqueName;
734
+ this.uniqueType = config.uniqueType;
735
+ this.dataType = config.dataType;
736
+ this.columnType = config.columnType;
737
+ this.generated = config.generated;
738
+ this.generatedIdentity = config.generatedIdentity;
739
+ }
740
+ static [entityKind] = "Column";
741
+ name;
742
+ keyAsName;
743
+ primary;
744
+ notNull;
745
+ default;
746
+ defaultFn;
747
+ onUpdateFn;
748
+ hasDefault;
749
+ isUnique;
750
+ uniqueName;
751
+ uniqueType;
752
+ dataType;
753
+ columnType;
754
+ enumValues = void 0;
755
+ generated = void 0;
756
+ generatedIdentity = void 0;
757
+ config;
758
+ mapFromDriverValue(value) {
759
+ return value;
760
+ }
761
+ mapToDriverValue(value) {
762
+ return value;
763
+ }
764
+ // ** @internal */
765
+ shouldDisableInsert() {
766
+ return this.config.generated !== void 0 && this.config.generated.type !== "byDefault";
767
+ }
768
+ };
769
+
770
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/column-builder.js
771
+ var ColumnBuilder = class {
772
+ static [entityKind] = "ColumnBuilder";
773
+ config;
774
+ constructor(name, dataType, columnType) {
775
+ this.config = {
776
+ name,
777
+ keyAsName: name === "",
778
+ notNull: false,
779
+ default: void 0,
780
+ hasDefault: false,
781
+ primaryKey: false,
782
+ isUnique: false,
783
+ uniqueName: void 0,
784
+ uniqueType: void 0,
785
+ dataType,
786
+ columnType,
787
+ generated: void 0
788
+ };
789
+ }
790
+ /**
791
+ * Changes the data type of the column. Commonly used with `json` columns. Also, useful for branded types.
792
+ *
793
+ * @example
794
+ * ```ts
795
+ * const users = pgTable('users', {
796
+ * id: integer('id').$type<UserId>().primaryKey(),
797
+ * details: json('details').$type<UserDetails>().notNull(),
798
+ * });
799
+ * ```
800
+ */
801
+ $type() {
802
+ return this;
803
+ }
804
+ /**
805
+ * Adds a `not null` clause to the column definition.
806
+ *
807
+ * Affects the `select` model of the table - columns *without* `not null` will be nullable on select.
808
+ */
809
+ notNull() {
810
+ this.config.notNull = true;
811
+ return this;
812
+ }
813
+ /**
814
+ * Adds a `default <value>` clause to the column definition.
815
+ *
816
+ * Affects the `insert` model of the table - columns *with* `default` are optional on insert.
817
+ *
818
+ * If you need to set a dynamic default value, use {@link $defaultFn} instead.
819
+ */
820
+ default(value) {
821
+ this.config.default = value;
822
+ this.config.hasDefault = true;
823
+ return this;
824
+ }
825
+ /**
826
+ * Adds a dynamic default value to the column.
827
+ * The function will be called when the row is inserted, and the returned value will be used as the column value.
828
+ *
829
+ * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
830
+ */
831
+ $defaultFn(fn) {
832
+ this.config.defaultFn = fn;
833
+ this.config.hasDefault = true;
834
+ return this;
835
+ }
836
+ /**
837
+ * Alias for {@link $defaultFn}.
838
+ */
839
+ $default = this.$defaultFn;
840
+ /**
841
+ * Adds a dynamic update value to the column.
842
+ * The function will be called when the row is updated, and the returned value will be used as the column value if none is provided.
843
+ * If no `default` (or `$defaultFn`) value is provided, the function will be called when the row is inserted as well, and the returned value will be used as the column value.
844
+ *
845
+ * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
846
+ */
847
+ $onUpdateFn(fn) {
848
+ this.config.onUpdateFn = fn;
849
+ this.config.hasDefault = true;
850
+ return this;
851
+ }
852
+ /**
853
+ * Alias for {@link $onUpdateFn}.
854
+ */
855
+ $onUpdate = this.$onUpdateFn;
856
+ /**
857
+ * Adds a `primary key` clause to the column definition. This implicitly makes the column `not null`.
858
+ *
859
+ * In SQLite, `integer primary key` implicitly makes the column auto-incrementing.
860
+ */
861
+ primaryKey() {
862
+ this.config.primaryKey = true;
863
+ this.config.notNull = true;
864
+ return this;
865
+ }
866
+ /** @internal Sets the name of the column to the key within the table definition if a name was not given. */
867
+ setName(name) {
868
+ if (this.config.name !== "") return;
869
+ this.config.name = name;
870
+ }
871
+ };
872
+
873
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/table.utils.js
874
+ var TableName = /* @__PURE__ */ Symbol.for("drizzle:Name");
875
+
876
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/pg-core/foreign-keys.js
877
+ var ForeignKeyBuilder = class {
878
+ static [entityKind] = "PgForeignKeyBuilder";
879
+ /** @internal */
880
+ reference;
881
+ /** @internal */
882
+ _onUpdate = "no action";
883
+ /** @internal */
884
+ _onDelete = "no action";
885
+ constructor(config, actions) {
886
+ this.reference = () => {
887
+ const { name, columns, foreignColumns } = config();
888
+ return { name, columns, foreignTable: foreignColumns[0].table, foreignColumns };
889
+ };
890
+ if (actions) {
891
+ this._onUpdate = actions.onUpdate;
892
+ this._onDelete = actions.onDelete;
893
+ }
894
+ }
895
+ onUpdate(action) {
896
+ this._onUpdate = action === void 0 ? "no action" : action;
897
+ return this;
898
+ }
899
+ onDelete(action) {
900
+ this._onDelete = action === void 0 ? "no action" : action;
901
+ return this;
902
+ }
903
+ /** @internal */
904
+ build(table) {
905
+ return new ForeignKey(table, this);
906
+ }
907
+ };
908
+ var ForeignKey = class {
909
+ constructor(table, builder) {
910
+ this.table = table;
911
+ this.reference = builder.reference;
912
+ this.onUpdate = builder._onUpdate;
913
+ this.onDelete = builder._onDelete;
914
+ }
915
+ static [entityKind] = "PgForeignKey";
916
+ reference;
917
+ onUpdate;
918
+ onDelete;
919
+ getName() {
920
+ const { name, columns, foreignColumns } = this.reference();
921
+ const columnNames = columns.map((column) => column.name);
922
+ const foreignColumnNames = foreignColumns.map((column) => column.name);
923
+ const chunks = [
924
+ this.table[TableName],
925
+ ...columnNames,
926
+ foreignColumns[0].table[TableName],
927
+ ...foreignColumnNames
928
+ ];
929
+ return name ?? `${chunks.join("_")}_fk`;
930
+ }
931
+ };
932
+
933
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/tracing-utils.js
934
+ function iife(fn, ...args) {
935
+ return fn(...args);
936
+ }
937
+
938
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/pg-core/unique-constraint.js
939
+ function uniqueKeyName(table, columns) {
940
+ return `${table[TableName]}_${columns.join("_")}_unique`;
941
+ }
942
+ var UniqueConstraintBuilder = class {
943
+ constructor(columns, name) {
944
+ this.name = name;
945
+ this.columns = columns;
946
+ }
947
+ static [entityKind] = "PgUniqueConstraintBuilder";
948
+ /** @internal */
949
+ columns;
950
+ /** @internal */
951
+ nullsNotDistinctConfig = false;
952
+ nullsNotDistinct() {
953
+ this.nullsNotDistinctConfig = true;
954
+ return this;
955
+ }
956
+ /** @internal */
957
+ build(table) {
958
+ return new UniqueConstraint(table, this.columns, this.nullsNotDistinctConfig, this.name);
959
+ }
960
+ };
961
+ var UniqueOnConstraintBuilder = class {
962
+ static [entityKind] = "PgUniqueOnConstraintBuilder";
963
+ /** @internal */
964
+ name;
965
+ constructor(name) {
966
+ this.name = name;
967
+ }
968
+ on(...columns) {
969
+ return new UniqueConstraintBuilder(columns, this.name);
970
+ }
971
+ };
972
+ var UniqueConstraint = class {
973
+ constructor(table, columns, nullsNotDistinct, name) {
974
+ this.table = table;
975
+ this.columns = columns;
976
+ this.name = name ?? uniqueKeyName(this.table, this.columns.map((column) => column.name));
977
+ this.nullsNotDistinct = nullsNotDistinct;
978
+ }
979
+ static [entityKind] = "PgUniqueConstraint";
980
+ columns;
981
+ name;
982
+ nullsNotDistinct = false;
983
+ getName() {
984
+ return this.name;
985
+ }
986
+ };
987
+
988
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/pg-core/utils/array.js
989
+ function parsePgArrayValue(arrayString, startFrom, inQuotes) {
990
+ for (let i = startFrom; i < arrayString.length; i++) {
991
+ const char = arrayString[i];
992
+ if (char === "\\") {
993
+ i++;
994
+ continue;
995
+ }
996
+ if (char === '"') {
997
+ return [arrayString.slice(startFrom, i).replace(/\\/g, ""), i + 1];
998
+ }
999
+ if (inQuotes) {
1000
+ continue;
1001
+ }
1002
+ if (char === "," || char === "}") {
1003
+ return [arrayString.slice(startFrom, i).replace(/\\/g, ""), i];
1004
+ }
1005
+ }
1006
+ return [arrayString.slice(startFrom).replace(/\\/g, ""), arrayString.length];
1007
+ }
1008
+ function parsePgNestedArray(arrayString, startFrom = 0) {
1009
+ const result = [];
1010
+ let i = startFrom;
1011
+ let lastCharIsComma = false;
1012
+ while (i < arrayString.length) {
1013
+ const char = arrayString[i];
1014
+ if (char === ",") {
1015
+ if (lastCharIsComma || i === startFrom) {
1016
+ result.push("");
1017
+ }
1018
+ lastCharIsComma = true;
1019
+ i++;
1020
+ continue;
1021
+ }
1022
+ lastCharIsComma = false;
1023
+ if (char === "\\") {
1024
+ i += 2;
1025
+ continue;
1026
+ }
1027
+ if (char === '"') {
1028
+ const [value2, startFrom2] = parsePgArrayValue(arrayString, i + 1, true);
1029
+ result.push(value2);
1030
+ i = startFrom2;
1031
+ continue;
1032
+ }
1033
+ if (char === "}") {
1034
+ return [result, i + 1];
1035
+ }
1036
+ if (char === "{") {
1037
+ const [value2, startFrom2] = parsePgNestedArray(arrayString, i + 1);
1038
+ result.push(value2);
1039
+ i = startFrom2;
1040
+ continue;
1041
+ }
1042
+ const [value, newStartFrom] = parsePgArrayValue(arrayString, i, false);
1043
+ result.push(value);
1044
+ i = newStartFrom;
1045
+ }
1046
+ return [result, i];
1047
+ }
1048
+ function parsePgArray(arrayString) {
1049
+ const [result] = parsePgNestedArray(arrayString, 1);
1050
+ return result;
1051
+ }
1052
+ function makePgArray(array) {
1053
+ return `{${array.map((item) => {
1054
+ if (Array.isArray(item)) {
1055
+ return makePgArray(item);
1056
+ }
1057
+ if (typeof item === "string") {
1058
+ return `"${item.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
1059
+ }
1060
+ return `${item}`;
1061
+ }).join(",")}}`;
1062
+ }
1063
+
1064
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/pg-core/columns/common.js
1065
+ var PgColumnBuilder = class extends ColumnBuilder {
1066
+ foreignKeyConfigs = [];
1067
+ static [entityKind] = "PgColumnBuilder";
1068
+ array(size) {
1069
+ return new PgArrayBuilder(this.config.name, this, size);
1070
+ }
1071
+ references(ref, actions = {}) {
1072
+ this.foreignKeyConfigs.push({ ref, actions });
1073
+ return this;
1074
+ }
1075
+ unique(name, config) {
1076
+ this.config.isUnique = true;
1077
+ this.config.uniqueName = name;
1078
+ this.config.uniqueType = config?.nulls;
1079
+ return this;
1080
+ }
1081
+ generatedAlwaysAs(as) {
1082
+ this.config.generated = {
1083
+ as,
1084
+ type: "always",
1085
+ mode: "stored"
1086
+ };
1087
+ return this;
1088
+ }
1089
+ /** @internal */
1090
+ buildForeignKeys(column, table) {
1091
+ return this.foreignKeyConfigs.map(({ ref, actions }) => {
1092
+ return iife(
1093
+ (ref2, actions2) => {
1094
+ const builder = new ForeignKeyBuilder(() => {
1095
+ const foreignColumn = ref2();
1096
+ return { columns: [column], foreignColumns: [foreignColumn] };
1097
+ });
1098
+ if (actions2.onUpdate) {
1099
+ builder.onUpdate(actions2.onUpdate);
1100
+ }
1101
+ if (actions2.onDelete) {
1102
+ builder.onDelete(actions2.onDelete);
1103
+ }
1104
+ return builder.build(table);
1105
+ },
1106
+ ref,
1107
+ actions
1108
+ );
1109
+ });
1110
+ }
1111
+ /** @internal */
1112
+ buildExtraConfigColumn(table) {
1113
+ return new ExtraConfigColumn(table, this.config);
1114
+ }
1115
+ };
1116
+ var PgColumn = class extends Column {
1117
+ constructor(table, config) {
1118
+ if (!config.uniqueName) {
1119
+ config.uniqueName = uniqueKeyName(table, [config.name]);
1120
+ }
1121
+ super(table, config);
1122
+ this.table = table;
1123
+ }
1124
+ static [entityKind] = "PgColumn";
1125
+ };
1126
+ var ExtraConfigColumn = class extends PgColumn {
1127
+ static [entityKind] = "ExtraConfigColumn";
1128
+ getSQLType() {
1129
+ return this.getSQLType();
1130
+ }
1131
+ indexConfig = {
1132
+ order: this.config.order ?? "asc",
1133
+ nulls: this.config.nulls ?? "last",
1134
+ opClass: this.config.opClass
1135
+ };
1136
+ defaultConfig = {
1137
+ order: "asc",
1138
+ nulls: "last",
1139
+ opClass: void 0
1140
+ };
1141
+ asc() {
1142
+ this.indexConfig.order = "asc";
1143
+ return this;
1144
+ }
1145
+ desc() {
1146
+ this.indexConfig.order = "desc";
1147
+ return this;
1148
+ }
1149
+ nullsFirst() {
1150
+ this.indexConfig.nulls = "first";
1151
+ return this;
1152
+ }
1153
+ nullsLast() {
1154
+ this.indexConfig.nulls = "last";
1155
+ return this;
1156
+ }
1157
+ /**
1158
+ * ### PostgreSQL documentation quote
1159
+ *
1160
+ * > An operator class with optional parameters can be specified for each column of an index.
1161
+ * The operator class identifies the operators to be used by the index for that column.
1162
+ * For example, a B-tree index on four-byte integers would use the int4_ops class;
1163
+ * this operator class includes comparison functions for four-byte integers.
1164
+ * In practice the default operator class for the column's data type is usually sufficient.
1165
+ * The main point of having operator classes is that for some data types, there could be more than one meaningful ordering.
1166
+ * For example, we might want to sort a complex-number data type either by absolute value or by real part.
1167
+ * We could do this by defining two operator classes for the data type and then selecting the proper class when creating an index.
1168
+ * More information about operator classes check:
1169
+ *
1170
+ * ### Useful links
1171
+ * https://www.postgresql.org/docs/current/sql-createindex.html
1172
+ *
1173
+ * https://www.postgresql.org/docs/current/indexes-opclass.html
1174
+ *
1175
+ * https://www.postgresql.org/docs/current/xindex.html
1176
+ *
1177
+ * ### Additional types
1178
+ * If you have the `pg_vector` extension installed in your database, you can use the
1179
+ * `vector_l2_ops`, `vector_ip_ops`, `vector_cosine_ops`, `vector_l1_ops`, `bit_hamming_ops`, `bit_jaccard_ops`, `halfvec_l2_ops`, `sparsevec_l2_ops` options, which are predefined types.
1180
+ *
1181
+ * **You can always specify any string you want in the operator class, in case Drizzle doesn't have it natively in its types**
1182
+ *
1183
+ * @param opClass
1184
+ * @returns
1185
+ */
1186
+ op(opClass) {
1187
+ this.indexConfig.opClass = opClass;
1188
+ return this;
1189
+ }
1190
+ };
1191
+ var IndexedColumn = class {
1192
+ static [entityKind] = "IndexedColumn";
1193
+ constructor(name, keyAsName, type, indexConfig) {
1194
+ this.name = name;
1195
+ this.keyAsName = keyAsName;
1196
+ this.type = type;
1197
+ this.indexConfig = indexConfig;
1198
+ }
1199
+ name;
1200
+ keyAsName;
1201
+ type;
1202
+ indexConfig;
1203
+ };
1204
+ var PgArrayBuilder = class extends PgColumnBuilder {
1205
+ static [entityKind] = "PgArrayBuilder";
1206
+ constructor(name, baseBuilder, size) {
1207
+ super(name, "array", "PgArray");
1208
+ this.config.baseBuilder = baseBuilder;
1209
+ this.config.size = size;
1210
+ }
1211
+ /** @internal */
1212
+ build(table) {
1213
+ const baseColumn = this.config.baseBuilder.build(table);
1214
+ return new PgArray(
1215
+ table,
1216
+ this.config,
1217
+ baseColumn
1218
+ );
1219
+ }
1220
+ };
1221
+ var PgArray = class _PgArray extends PgColumn {
1222
+ constructor(table, config, baseColumn, range) {
1223
+ super(table, config);
1224
+ this.baseColumn = baseColumn;
1225
+ this.range = range;
1226
+ this.size = config.size;
1227
+ }
1228
+ size;
1229
+ static [entityKind] = "PgArray";
1230
+ getSQLType() {
1231
+ return `${this.baseColumn.getSQLType()}[${typeof this.size === "number" ? this.size : ""}]`;
1232
+ }
1233
+ mapFromDriverValue(value) {
1234
+ if (typeof value === "string") {
1235
+ value = parsePgArray(value);
1236
+ }
1237
+ return value.map((v) => this.baseColumn.mapFromDriverValue(v));
1238
+ }
1239
+ mapToDriverValue(value, isNestedArray = false) {
1240
+ const a = value.map(
1241
+ (v) => v === null ? null : is(this.baseColumn, _PgArray) ? this.baseColumn.mapToDriverValue(v, true) : this.baseColumn.mapToDriverValue(v)
1242
+ );
1243
+ if (isNestedArray) return a;
1244
+ return makePgArray(a);
1245
+ }
1246
+ };
1247
+
1248
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/pg-core/columns/enum.js
1249
+ var PgEnumObjectColumnBuilder = class extends PgColumnBuilder {
1250
+ static [entityKind] = "PgEnumObjectColumnBuilder";
1251
+ constructor(name, enumInstance) {
1252
+ super(name, "string", "PgEnumObjectColumn");
1253
+ this.config.enum = enumInstance;
1254
+ }
1255
+ /** @internal */
1256
+ build(table) {
1257
+ return new PgEnumObjectColumn(
1258
+ table,
1259
+ this.config
1260
+ );
1261
+ }
1262
+ };
1263
+ var PgEnumObjectColumn = class extends PgColumn {
1264
+ static [entityKind] = "PgEnumObjectColumn";
1265
+ enum;
1266
+ enumValues = this.config.enum.enumValues;
1267
+ constructor(table, config) {
1268
+ super(table, config);
1269
+ this.enum = config.enum;
1270
+ }
1271
+ getSQLType() {
1272
+ return this.enum.enumName;
1273
+ }
1274
+ };
1275
+ var isPgEnumSym = /* @__PURE__ */ Symbol.for("drizzle:isPgEnum");
1276
+ function isPgEnum(obj) {
1277
+ return !!obj && typeof obj === "function" && isPgEnumSym in obj && obj[isPgEnumSym] === true;
1278
+ }
1279
+ var PgEnumColumnBuilder = class extends PgColumnBuilder {
1280
+ static [entityKind] = "PgEnumColumnBuilder";
1281
+ constructor(name, enumInstance) {
1282
+ super(name, "string", "PgEnumColumn");
1283
+ this.config.enum = enumInstance;
1284
+ }
1285
+ /** @internal */
1286
+ build(table) {
1287
+ return new PgEnumColumn(
1288
+ table,
1289
+ this.config
1290
+ );
1291
+ }
1292
+ };
1293
+ var PgEnumColumn = class extends PgColumn {
1294
+ static [entityKind] = "PgEnumColumn";
1295
+ enum = this.config.enum;
1296
+ enumValues = this.config.enum.enumValues;
1297
+ constructor(table, config) {
1298
+ super(table, config);
1299
+ this.enum = config.enum;
1300
+ }
1301
+ getSQLType() {
1302
+ return this.enum.enumName;
1303
+ }
1304
+ };
1305
+
1306
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/subquery.js
1307
+ var Subquery = class {
1308
+ static [entityKind] = "Subquery";
1309
+ constructor(sql2, fields, alias, isWith = false, usedTables = []) {
1310
+ this._ = {
1311
+ brand: "Subquery",
1312
+ sql: sql2,
1313
+ selectedFields: fields,
1314
+ alias,
1315
+ isWith,
1316
+ usedTables
1317
+ };
1318
+ }
1319
+ // getSQL(): SQL<unknown> {
1320
+ // return new SQL([this]);
1321
+ // }
1322
+ };
1323
+ var WithSubquery = class extends Subquery {
1324
+ static [entityKind] = "WithSubquery";
1325
+ };
1326
+
1327
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/version.js
1328
+ var version = "0.45.2";
1329
+
1330
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/tracing.js
1331
+ var otel;
1332
+ var rawTracer;
1333
+ var tracer = {
1334
+ startActiveSpan(name, fn) {
1335
+ if (!otel) {
1336
+ return fn();
1337
+ }
1338
+ if (!rawTracer) {
1339
+ rawTracer = otel.trace.getTracer("drizzle-orm", version);
1340
+ }
1341
+ return iife(
1342
+ (otel2, rawTracer2) => rawTracer2.startActiveSpan(
1343
+ name,
1344
+ (span) => {
1345
+ try {
1346
+ return fn(span);
1347
+ } catch (e) {
1348
+ span.setStatus({
1349
+ code: otel2.SpanStatusCode.ERROR,
1350
+ message: e instanceof Error ? e.message : "Unknown error"
1351
+ // eslint-disable-line no-instanceof/no-instanceof
12
1352
  });
13
- try {
14
- return await resolveInteractiveCreateOptions(argv, async (question, defaultValue) => terminal.question(`${question} [${defaultValue}]: `));
1353
+ throw e;
1354
+ } finally {
1355
+ span.end();
1356
+ }
1357
+ }
1358
+ ),
1359
+ otel,
1360
+ rawTracer
1361
+ );
1362
+ }
1363
+ };
1364
+
1365
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/view-common.js
1366
+ var ViewBaseConfig = /* @__PURE__ */ Symbol.for("drizzle:ViewBaseConfig");
1367
+
1368
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/table.js
1369
+ var Schema = /* @__PURE__ */ Symbol.for("drizzle:Schema");
1370
+ var Columns = /* @__PURE__ */ Symbol.for("drizzle:Columns");
1371
+ var ExtraConfigColumns = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigColumns");
1372
+ var OriginalName = /* @__PURE__ */ Symbol.for("drizzle:OriginalName");
1373
+ var BaseName = /* @__PURE__ */ Symbol.for("drizzle:BaseName");
1374
+ var IsAlias = /* @__PURE__ */ Symbol.for("drizzle:IsAlias");
1375
+ var ExtraConfigBuilder = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigBuilder");
1376
+ var IsDrizzleTable = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleTable");
1377
+ var Table = class {
1378
+ static [entityKind] = "Table";
1379
+ /** @internal */
1380
+ static Symbol = {
1381
+ Name: TableName,
1382
+ Schema,
1383
+ OriginalName,
1384
+ Columns,
1385
+ ExtraConfigColumns,
1386
+ BaseName,
1387
+ IsAlias,
1388
+ ExtraConfigBuilder
1389
+ };
1390
+ /**
1391
+ * @internal
1392
+ * Can be changed if the table is aliased.
1393
+ */
1394
+ [TableName];
1395
+ /**
1396
+ * @internal
1397
+ * Used to store the original name of the table, before any aliasing.
1398
+ */
1399
+ [OriginalName];
1400
+ /** @internal */
1401
+ [Schema];
1402
+ /** @internal */
1403
+ [Columns];
1404
+ /** @internal */
1405
+ [ExtraConfigColumns];
1406
+ /**
1407
+ * @internal
1408
+ * Used to store the table name before the transformation via the `tableCreator` functions.
1409
+ */
1410
+ [BaseName];
1411
+ /** @internal */
1412
+ [IsAlias] = false;
1413
+ /** @internal */
1414
+ [IsDrizzleTable] = true;
1415
+ /** @internal */
1416
+ [ExtraConfigBuilder] = void 0;
1417
+ constructor(name, schema, baseName) {
1418
+ this[TableName] = this[OriginalName] = name;
1419
+ this[Schema] = schema;
1420
+ this[BaseName] = baseName;
1421
+ }
1422
+ };
1423
+
1424
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/sql/sql.js
1425
+ var FakePrimitiveParam = class {
1426
+ static [entityKind] = "FakePrimitiveParam";
1427
+ };
1428
+ function isSQLWrapper(value) {
1429
+ return value !== null && value !== void 0 && typeof value.getSQL === "function";
1430
+ }
1431
+ function mergeQueries(queries) {
1432
+ const result = { sql: "", params: [] };
1433
+ for (const query of queries) {
1434
+ result.sql += query.sql;
1435
+ result.params.push(...query.params);
1436
+ if (query.typings?.length) {
1437
+ if (!result.typings) {
1438
+ result.typings = [];
1439
+ }
1440
+ result.typings.push(...query.typings);
1441
+ }
1442
+ }
1443
+ return result;
1444
+ }
1445
+ var StringChunk = class {
1446
+ static [entityKind] = "StringChunk";
1447
+ value;
1448
+ constructor(value) {
1449
+ this.value = Array.isArray(value) ? value : [value];
1450
+ }
1451
+ getSQL() {
1452
+ return new SQL([this]);
1453
+ }
1454
+ };
1455
+ var SQL = class _SQL {
1456
+ constructor(queryChunks) {
1457
+ this.queryChunks = queryChunks;
1458
+ for (const chunk of queryChunks) {
1459
+ if (is(chunk, Table)) {
1460
+ const schemaName = chunk[Table.Symbol.Schema];
1461
+ this.usedTables.push(
1462
+ schemaName === void 0 ? chunk[Table.Symbol.Name] : schemaName + "." + chunk[Table.Symbol.Name]
1463
+ );
1464
+ }
1465
+ }
1466
+ }
1467
+ static [entityKind] = "SQL";
1468
+ /** @internal */
1469
+ decoder = noopDecoder;
1470
+ shouldInlineParams = false;
1471
+ /** @internal */
1472
+ usedTables = [];
1473
+ append(query) {
1474
+ this.queryChunks.push(...query.queryChunks);
1475
+ return this;
1476
+ }
1477
+ toQuery(config) {
1478
+ return tracer.startActiveSpan("drizzle.buildSQL", (span) => {
1479
+ const query = this.buildQueryFromSourceParams(this.queryChunks, config);
1480
+ span?.setAttributes({
1481
+ "drizzle.query.text": query.sql,
1482
+ "drizzle.query.params": JSON.stringify(query.params)
1483
+ });
1484
+ return query;
1485
+ });
1486
+ }
1487
+ buildQueryFromSourceParams(chunks, _config) {
1488
+ const config = Object.assign({}, _config, {
1489
+ inlineParams: _config.inlineParams || this.shouldInlineParams,
1490
+ paramStartIndex: _config.paramStartIndex || { value: 0 }
1491
+ });
1492
+ const {
1493
+ casing,
1494
+ escapeName,
1495
+ escapeParam,
1496
+ prepareTyping,
1497
+ inlineParams,
1498
+ paramStartIndex
1499
+ } = config;
1500
+ return mergeQueries(chunks.map((chunk) => {
1501
+ if (is(chunk, StringChunk)) {
1502
+ return { sql: chunk.value.join(""), params: [] };
1503
+ }
1504
+ if (is(chunk, Name)) {
1505
+ return { sql: escapeName(chunk.value), params: [] };
1506
+ }
1507
+ if (chunk === void 0) {
1508
+ return { sql: "", params: [] };
1509
+ }
1510
+ if (Array.isArray(chunk)) {
1511
+ const result = [new StringChunk("(")];
1512
+ for (const [i, p] of chunk.entries()) {
1513
+ result.push(p);
1514
+ if (i < chunk.length - 1) {
1515
+ result.push(new StringChunk(", "));
1516
+ }
1517
+ }
1518
+ result.push(new StringChunk(")"));
1519
+ return this.buildQueryFromSourceParams(result, config);
1520
+ }
1521
+ if (is(chunk, _SQL)) {
1522
+ return this.buildQueryFromSourceParams(chunk.queryChunks, {
1523
+ ...config,
1524
+ inlineParams: inlineParams || chunk.shouldInlineParams
1525
+ });
1526
+ }
1527
+ if (is(chunk, Table)) {
1528
+ const schemaName = chunk[Table.Symbol.Schema];
1529
+ const tableName = chunk[Table.Symbol.Name];
1530
+ return {
1531
+ sql: schemaName === void 0 || chunk[IsAlias] ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
1532
+ params: []
1533
+ };
1534
+ }
1535
+ if (is(chunk, Column)) {
1536
+ const columnName = casing.getColumnCasing(chunk);
1537
+ if (_config.invokeSource === "indexes") {
1538
+ return { sql: escapeName(columnName), params: [] };
1539
+ }
1540
+ const schemaName = chunk.table[Table.Symbol.Schema];
1541
+ return {
1542
+ sql: chunk.table[IsAlias] || schemaName === void 0 ? escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName) : escapeName(schemaName) + "." + escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName),
1543
+ params: []
1544
+ };
1545
+ }
1546
+ if (is(chunk, View)) {
1547
+ const schemaName = chunk[ViewBaseConfig].schema;
1548
+ const viewName = chunk[ViewBaseConfig].name;
1549
+ return {
1550
+ sql: schemaName === void 0 || chunk[ViewBaseConfig].isAlias ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
1551
+ params: []
1552
+ };
1553
+ }
1554
+ if (is(chunk, Param)) {
1555
+ if (is(chunk.value, Placeholder)) {
1556
+ return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
1557
+ }
1558
+ const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
1559
+ if (is(mappedValue, _SQL)) {
1560
+ return this.buildQueryFromSourceParams([mappedValue], config);
1561
+ }
1562
+ if (inlineParams) {
1563
+ return { sql: this.mapInlineParam(mappedValue, config), params: [] };
1564
+ }
1565
+ let typings = ["none"];
1566
+ if (prepareTyping) {
1567
+ typings = [prepareTyping(chunk.encoder)];
1568
+ }
1569
+ return { sql: escapeParam(paramStartIndex.value++, mappedValue), params: [mappedValue], typings };
1570
+ }
1571
+ if (is(chunk, Placeholder)) {
1572
+ return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
1573
+ }
1574
+ if (is(chunk, _SQL.Aliased) && chunk.fieldAlias !== void 0) {
1575
+ return { sql: escapeName(chunk.fieldAlias), params: [] };
1576
+ }
1577
+ if (is(chunk, Subquery)) {
1578
+ if (chunk._.isWith) {
1579
+ return { sql: escapeName(chunk._.alias), params: [] };
1580
+ }
1581
+ return this.buildQueryFromSourceParams([
1582
+ new StringChunk("("),
1583
+ chunk._.sql,
1584
+ new StringChunk(") "),
1585
+ new Name(chunk._.alias)
1586
+ ], config);
1587
+ }
1588
+ if (isPgEnum(chunk)) {
1589
+ if (chunk.schema) {
1590
+ return { sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName), params: [] };
1591
+ }
1592
+ return { sql: escapeName(chunk.enumName), params: [] };
1593
+ }
1594
+ if (isSQLWrapper(chunk)) {
1595
+ if (chunk.shouldOmitSQLParens?.()) {
1596
+ return this.buildQueryFromSourceParams([chunk.getSQL()], config);
1597
+ }
1598
+ return this.buildQueryFromSourceParams([
1599
+ new StringChunk("("),
1600
+ chunk.getSQL(),
1601
+ new StringChunk(")")
1602
+ ], config);
1603
+ }
1604
+ if (inlineParams) {
1605
+ return { sql: this.mapInlineParam(chunk, config), params: [] };
1606
+ }
1607
+ return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
1608
+ }));
1609
+ }
1610
+ mapInlineParam(chunk, { escapeString }) {
1611
+ if (chunk === null) {
1612
+ return "null";
1613
+ }
1614
+ if (typeof chunk === "number" || typeof chunk === "boolean") {
1615
+ return chunk.toString();
1616
+ }
1617
+ if (typeof chunk === "string") {
1618
+ return escapeString(chunk);
1619
+ }
1620
+ if (typeof chunk === "object") {
1621
+ const mappedValueAsString = chunk.toString();
1622
+ if (mappedValueAsString === "[object Object]") {
1623
+ return escapeString(JSON.stringify(chunk));
1624
+ }
1625
+ return escapeString(mappedValueAsString);
1626
+ }
1627
+ throw new Error("Unexpected param value: " + chunk);
1628
+ }
1629
+ getSQL() {
1630
+ return this;
1631
+ }
1632
+ as(alias) {
1633
+ if (alias === void 0) {
1634
+ return this;
1635
+ }
1636
+ return new _SQL.Aliased(this, alias);
1637
+ }
1638
+ mapWith(decoder) {
1639
+ this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
1640
+ return this;
1641
+ }
1642
+ inlineParams() {
1643
+ this.shouldInlineParams = true;
1644
+ return this;
1645
+ }
1646
+ /**
1647
+ * This method is used to conditionally include a part of the query.
1648
+ *
1649
+ * @param condition - Condition to check
1650
+ * @returns itself if the condition is `true`, otherwise `undefined`
1651
+ */
1652
+ if(condition) {
1653
+ return condition ? this : void 0;
1654
+ }
1655
+ };
1656
+ var Name = class {
1657
+ constructor(value) {
1658
+ this.value = value;
1659
+ }
1660
+ static [entityKind] = "Name";
1661
+ brand;
1662
+ getSQL() {
1663
+ return new SQL([this]);
1664
+ }
1665
+ };
1666
+ var noopDecoder = {
1667
+ mapFromDriverValue: (value) => value
1668
+ };
1669
+ var noopEncoder = {
1670
+ mapToDriverValue: (value) => value
1671
+ };
1672
+ var noopMapper = {
1673
+ ...noopDecoder,
1674
+ ...noopEncoder
1675
+ };
1676
+ var Param = class {
1677
+ /**
1678
+ * @param value - Parameter value
1679
+ * @param encoder - Encoder to convert the value to a driver parameter
1680
+ */
1681
+ constructor(value, encoder = noopEncoder) {
1682
+ this.value = value;
1683
+ this.encoder = encoder;
1684
+ }
1685
+ static [entityKind] = "Param";
1686
+ brand;
1687
+ getSQL() {
1688
+ return new SQL([this]);
1689
+ }
1690
+ };
1691
+ function sql(strings, ...params) {
1692
+ const queryChunks = [];
1693
+ if (params.length > 0 || strings.length > 0 && strings[0] !== "") {
1694
+ queryChunks.push(new StringChunk(strings[0]));
1695
+ }
1696
+ for (const [paramIndex, param2] of params.entries()) {
1697
+ queryChunks.push(param2, new StringChunk(strings[paramIndex + 1]));
1698
+ }
1699
+ return new SQL(queryChunks);
1700
+ }
1701
+ ((sql2) => {
1702
+ function empty() {
1703
+ return new SQL([]);
1704
+ }
1705
+ sql2.empty = empty;
1706
+ function fromList(list) {
1707
+ return new SQL(list);
1708
+ }
1709
+ sql2.fromList = fromList;
1710
+ function raw(str) {
1711
+ return new SQL([new StringChunk(str)]);
1712
+ }
1713
+ sql2.raw = raw;
1714
+ function join3(chunks, separator) {
1715
+ const result = [];
1716
+ for (const [i, chunk] of chunks.entries()) {
1717
+ if (i > 0 && separator !== void 0) {
1718
+ result.push(separator);
1719
+ }
1720
+ result.push(chunk);
1721
+ }
1722
+ return new SQL(result);
1723
+ }
1724
+ sql2.join = join3;
1725
+ function identifier(value) {
1726
+ return new Name(value);
1727
+ }
1728
+ sql2.identifier = identifier;
1729
+ function placeholder2(name2) {
1730
+ return new Placeholder(name2);
1731
+ }
1732
+ sql2.placeholder = placeholder2;
1733
+ function param2(value, encoder) {
1734
+ return new Param(value, encoder);
1735
+ }
1736
+ sql2.param = param2;
1737
+ })(sql || (sql = {}));
1738
+ ((SQL2) => {
1739
+ class Aliased {
1740
+ constructor(sql2, fieldAlias) {
1741
+ this.sql = sql2;
1742
+ this.fieldAlias = fieldAlias;
1743
+ }
1744
+ static [entityKind] = "SQL.Aliased";
1745
+ /** @internal */
1746
+ isSelectionField = false;
1747
+ getSQL() {
1748
+ return this.sql;
1749
+ }
1750
+ /** @internal */
1751
+ clone() {
1752
+ return new Aliased(this.sql, this.fieldAlias);
1753
+ }
1754
+ }
1755
+ SQL2.Aliased = Aliased;
1756
+ })(SQL || (SQL = {}));
1757
+ var Placeholder = class {
1758
+ constructor(name2) {
1759
+ this.name = name2;
1760
+ }
1761
+ static [entityKind] = "Placeholder";
1762
+ getSQL() {
1763
+ return new SQL([this]);
1764
+ }
1765
+ };
1766
+ var IsDrizzleView = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleView");
1767
+ var View = class {
1768
+ static [entityKind] = "View";
1769
+ /** @internal */
1770
+ [ViewBaseConfig];
1771
+ /** @internal */
1772
+ [IsDrizzleView] = true;
1773
+ constructor({ name: name2, schema, selectedFields, query }) {
1774
+ this[ViewBaseConfig] = {
1775
+ name: name2,
1776
+ originalName: name2,
1777
+ schema,
1778
+ selectedFields,
1779
+ query,
1780
+ isExisting: !query,
1781
+ isAlias: false
1782
+ };
1783
+ }
1784
+ getSQL() {
1785
+ return new SQL([this]);
1786
+ }
1787
+ };
1788
+ Column.prototype.getSQL = function() {
1789
+ return new SQL([this]);
1790
+ };
1791
+ Table.prototype.getSQL = function() {
1792
+ return new SQL([this]);
1793
+ };
1794
+ Subquery.prototype.getSQL = function() {
1795
+ return new SQL([this]);
1796
+ };
1797
+
1798
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/utils.js
1799
+ function getColumnNameAndConfig(a, b) {
1800
+ return {
1801
+ name: typeof a === "string" && a.length > 0 ? a : "",
1802
+ config: typeof a === "object" ? a : b
1803
+ };
1804
+ }
1805
+ var textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder();
1806
+
1807
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/sqlite-core/foreign-keys.js
1808
+ var ForeignKeyBuilder2 = class {
1809
+ static [entityKind] = "SQLiteForeignKeyBuilder";
1810
+ /** @internal */
1811
+ reference;
1812
+ /** @internal */
1813
+ _onUpdate;
1814
+ /** @internal */
1815
+ _onDelete;
1816
+ constructor(config, actions) {
1817
+ this.reference = () => {
1818
+ const { name, columns, foreignColumns } = config();
1819
+ return { name, columns, foreignTable: foreignColumns[0].table, foreignColumns };
1820
+ };
1821
+ if (actions) {
1822
+ this._onUpdate = actions.onUpdate;
1823
+ this._onDelete = actions.onDelete;
1824
+ }
1825
+ }
1826
+ onUpdate(action) {
1827
+ this._onUpdate = action;
1828
+ return this;
1829
+ }
1830
+ onDelete(action) {
1831
+ this._onDelete = action;
1832
+ return this;
1833
+ }
1834
+ /** @internal */
1835
+ build(table) {
1836
+ return new ForeignKey2(table, this);
1837
+ }
1838
+ };
1839
+ var ForeignKey2 = class {
1840
+ constructor(table, builder) {
1841
+ this.table = table;
1842
+ this.reference = builder.reference;
1843
+ this.onUpdate = builder._onUpdate;
1844
+ this.onDelete = builder._onDelete;
1845
+ }
1846
+ static [entityKind] = "SQLiteForeignKey";
1847
+ reference;
1848
+ onUpdate;
1849
+ onDelete;
1850
+ getName() {
1851
+ const { name, columns, foreignColumns } = this.reference();
1852
+ const columnNames = columns.map((column) => column.name);
1853
+ const foreignColumnNames = foreignColumns.map((column) => column.name);
1854
+ const chunks = [
1855
+ this.table[TableName],
1856
+ ...columnNames,
1857
+ foreignColumns[0].table[TableName],
1858
+ ...foreignColumnNames
1859
+ ];
1860
+ return name ?? `${chunks.join("_")}_fk`;
1861
+ }
1862
+ };
1863
+
1864
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/sqlite-core/unique-constraint.js
1865
+ function uniqueKeyName2(table, columns) {
1866
+ return `${table[TableName]}_${columns.join("_")}_unique`;
1867
+ }
1868
+ var UniqueConstraintBuilder2 = class {
1869
+ constructor(columns, name) {
1870
+ this.name = name;
1871
+ this.columns = columns;
1872
+ }
1873
+ static [entityKind] = "SQLiteUniqueConstraintBuilder";
1874
+ /** @internal */
1875
+ columns;
1876
+ /** @internal */
1877
+ build(table) {
1878
+ return new UniqueConstraint2(table, this.columns, this.name);
1879
+ }
1880
+ };
1881
+ var UniqueOnConstraintBuilder2 = class {
1882
+ static [entityKind] = "SQLiteUniqueOnConstraintBuilder";
1883
+ /** @internal */
1884
+ name;
1885
+ constructor(name) {
1886
+ this.name = name;
1887
+ }
1888
+ on(...columns) {
1889
+ return new UniqueConstraintBuilder2(columns, this.name);
1890
+ }
1891
+ };
1892
+ var UniqueConstraint2 = class {
1893
+ constructor(table, columns, name) {
1894
+ this.table = table;
1895
+ this.columns = columns;
1896
+ this.name = name ?? uniqueKeyName2(this.table, this.columns.map((column) => column.name));
1897
+ }
1898
+ static [entityKind] = "SQLiteUniqueConstraint";
1899
+ columns;
1900
+ name;
1901
+ getName() {
1902
+ return this.name;
1903
+ }
1904
+ };
1905
+
1906
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/sqlite-core/columns/common.js
1907
+ var SQLiteColumnBuilder = class extends ColumnBuilder {
1908
+ static [entityKind] = "SQLiteColumnBuilder";
1909
+ foreignKeyConfigs = [];
1910
+ references(ref, actions = {}) {
1911
+ this.foreignKeyConfigs.push({ ref, actions });
1912
+ return this;
1913
+ }
1914
+ unique(name) {
1915
+ this.config.isUnique = true;
1916
+ this.config.uniqueName = name;
1917
+ return this;
1918
+ }
1919
+ generatedAlwaysAs(as, config) {
1920
+ this.config.generated = {
1921
+ as,
1922
+ type: "always",
1923
+ mode: config?.mode ?? "virtual"
1924
+ };
1925
+ return this;
1926
+ }
1927
+ /** @internal */
1928
+ buildForeignKeys(column, table) {
1929
+ return this.foreignKeyConfigs.map(({ ref, actions }) => {
1930
+ return ((ref2, actions2) => {
1931
+ const builder = new ForeignKeyBuilder2(() => {
1932
+ const foreignColumn = ref2();
1933
+ return { columns: [column], foreignColumns: [foreignColumn] };
1934
+ });
1935
+ if (actions2.onUpdate) {
1936
+ builder.onUpdate(actions2.onUpdate);
1937
+ }
1938
+ if (actions2.onDelete) {
1939
+ builder.onDelete(actions2.onDelete);
1940
+ }
1941
+ return builder.build(table);
1942
+ })(ref, actions);
1943
+ });
1944
+ }
1945
+ };
1946
+ var SQLiteColumn = class extends Column {
1947
+ constructor(table, config) {
1948
+ if (!config.uniqueName) {
1949
+ config.uniqueName = uniqueKeyName2(table, [config.name]);
1950
+ }
1951
+ super(table, config);
1952
+ this.table = table;
1953
+ }
1954
+ static [entityKind] = "SQLiteColumn";
1955
+ };
1956
+
1957
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/sqlite-core/columns/blob.js
1958
+ var SQLiteBigIntBuilder = class extends SQLiteColumnBuilder {
1959
+ static [entityKind] = "SQLiteBigIntBuilder";
1960
+ constructor(name) {
1961
+ super(name, "bigint", "SQLiteBigInt");
1962
+ }
1963
+ /** @internal */
1964
+ build(table) {
1965
+ return new SQLiteBigInt(table, this.config);
1966
+ }
1967
+ };
1968
+ var SQLiteBigInt = class extends SQLiteColumn {
1969
+ static [entityKind] = "SQLiteBigInt";
1970
+ getSQLType() {
1971
+ return "blob";
1972
+ }
1973
+ mapFromDriverValue(value) {
1974
+ if (typeof Buffer !== "undefined" && Buffer.from) {
1975
+ const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
1976
+ return BigInt(buf.toString("utf8"));
1977
+ }
1978
+ return BigInt(textDecoder.decode(value));
1979
+ }
1980
+ mapToDriverValue(value) {
1981
+ return Buffer.from(value.toString());
1982
+ }
1983
+ };
1984
+ var SQLiteBlobJsonBuilder = class extends SQLiteColumnBuilder {
1985
+ static [entityKind] = "SQLiteBlobJsonBuilder";
1986
+ constructor(name) {
1987
+ super(name, "json", "SQLiteBlobJson");
1988
+ }
1989
+ /** @internal */
1990
+ build(table) {
1991
+ return new SQLiteBlobJson(
1992
+ table,
1993
+ this.config
1994
+ );
1995
+ }
1996
+ };
1997
+ var SQLiteBlobJson = class extends SQLiteColumn {
1998
+ static [entityKind] = "SQLiteBlobJson";
1999
+ getSQLType() {
2000
+ return "blob";
2001
+ }
2002
+ mapFromDriverValue(value) {
2003
+ if (typeof Buffer !== "undefined" && Buffer.from) {
2004
+ const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
2005
+ return JSON.parse(buf.toString("utf8"));
2006
+ }
2007
+ return JSON.parse(textDecoder.decode(value));
2008
+ }
2009
+ mapToDriverValue(value) {
2010
+ return Buffer.from(JSON.stringify(value));
2011
+ }
2012
+ };
2013
+ var SQLiteBlobBufferBuilder = class extends SQLiteColumnBuilder {
2014
+ static [entityKind] = "SQLiteBlobBufferBuilder";
2015
+ constructor(name) {
2016
+ super(name, "buffer", "SQLiteBlobBuffer");
2017
+ }
2018
+ /** @internal */
2019
+ build(table) {
2020
+ return new SQLiteBlobBuffer(table, this.config);
2021
+ }
2022
+ };
2023
+ var SQLiteBlobBuffer = class extends SQLiteColumn {
2024
+ static [entityKind] = "SQLiteBlobBuffer";
2025
+ mapFromDriverValue(value) {
2026
+ if (Buffer.isBuffer(value)) {
2027
+ return value;
2028
+ }
2029
+ return Buffer.from(value);
2030
+ }
2031
+ getSQLType() {
2032
+ return "blob";
2033
+ }
2034
+ };
2035
+ function blob(a, b) {
2036
+ const { name, config } = getColumnNameAndConfig(a, b);
2037
+ if (config?.mode === "json") {
2038
+ return new SQLiteBlobJsonBuilder(name);
2039
+ }
2040
+ if (config?.mode === "bigint") {
2041
+ return new SQLiteBigIntBuilder(name);
2042
+ }
2043
+ return new SQLiteBlobBufferBuilder(name);
2044
+ }
2045
+
2046
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/sqlite-core/columns/custom.js
2047
+ var SQLiteCustomColumnBuilder = class extends SQLiteColumnBuilder {
2048
+ static [entityKind] = "SQLiteCustomColumnBuilder";
2049
+ constructor(name, fieldConfig, customTypeParams) {
2050
+ super(name, "custom", "SQLiteCustomColumn");
2051
+ this.config.fieldConfig = fieldConfig;
2052
+ this.config.customTypeParams = customTypeParams;
2053
+ }
2054
+ /** @internal */
2055
+ build(table) {
2056
+ return new SQLiteCustomColumn(
2057
+ table,
2058
+ this.config
2059
+ );
2060
+ }
2061
+ };
2062
+ var SQLiteCustomColumn = class extends SQLiteColumn {
2063
+ static [entityKind] = "SQLiteCustomColumn";
2064
+ sqlName;
2065
+ mapTo;
2066
+ mapFrom;
2067
+ constructor(table, config) {
2068
+ super(table, config);
2069
+ this.sqlName = config.customTypeParams.dataType(config.fieldConfig);
2070
+ this.mapTo = config.customTypeParams.toDriver;
2071
+ this.mapFrom = config.customTypeParams.fromDriver;
2072
+ }
2073
+ getSQLType() {
2074
+ return this.sqlName;
2075
+ }
2076
+ mapFromDriverValue(value) {
2077
+ return typeof this.mapFrom === "function" ? this.mapFrom(value) : value;
2078
+ }
2079
+ mapToDriverValue(value) {
2080
+ return typeof this.mapTo === "function" ? this.mapTo(value) : value;
2081
+ }
2082
+ };
2083
+ function customType(customTypeParams) {
2084
+ return (a, b) => {
2085
+ const { name, config } = getColumnNameAndConfig(a, b);
2086
+ return new SQLiteCustomColumnBuilder(
2087
+ name,
2088
+ config,
2089
+ customTypeParams
2090
+ );
2091
+ };
2092
+ }
2093
+
2094
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/sqlite-core/columns/integer.js
2095
+ var SQLiteBaseIntegerBuilder = class extends SQLiteColumnBuilder {
2096
+ static [entityKind] = "SQLiteBaseIntegerBuilder";
2097
+ constructor(name, dataType, columnType) {
2098
+ super(name, dataType, columnType);
2099
+ this.config.autoIncrement = false;
2100
+ }
2101
+ primaryKey(config) {
2102
+ if (config?.autoIncrement) {
2103
+ this.config.autoIncrement = true;
2104
+ }
2105
+ this.config.hasDefault = true;
2106
+ return super.primaryKey();
2107
+ }
2108
+ };
2109
+ var SQLiteBaseInteger = class extends SQLiteColumn {
2110
+ static [entityKind] = "SQLiteBaseInteger";
2111
+ autoIncrement = this.config.autoIncrement;
2112
+ getSQLType() {
2113
+ return "integer";
2114
+ }
2115
+ };
2116
+ var SQLiteIntegerBuilder = class extends SQLiteBaseIntegerBuilder {
2117
+ static [entityKind] = "SQLiteIntegerBuilder";
2118
+ constructor(name) {
2119
+ super(name, "number", "SQLiteInteger");
2120
+ }
2121
+ build(table) {
2122
+ return new SQLiteInteger(
2123
+ table,
2124
+ this.config
2125
+ );
2126
+ }
2127
+ };
2128
+ var SQLiteInteger = class extends SQLiteBaseInteger {
2129
+ static [entityKind] = "SQLiteInteger";
2130
+ };
2131
+ var SQLiteTimestampBuilder = class extends SQLiteBaseIntegerBuilder {
2132
+ static [entityKind] = "SQLiteTimestampBuilder";
2133
+ constructor(name, mode) {
2134
+ super(name, "date", "SQLiteTimestamp");
2135
+ this.config.mode = mode;
2136
+ }
2137
+ /**
2138
+ * @deprecated Use `default()` with your own expression instead.
2139
+ *
2140
+ * Adds `DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer))` to the column, which is the current epoch timestamp in milliseconds.
2141
+ */
2142
+ defaultNow() {
2143
+ return this.default(sql`(cast((julianday('now') - 2440587.5)*86400000 as integer))`);
2144
+ }
2145
+ build(table) {
2146
+ return new SQLiteTimestamp(
2147
+ table,
2148
+ this.config
2149
+ );
2150
+ }
2151
+ };
2152
+ var SQLiteTimestamp = class extends SQLiteBaseInteger {
2153
+ static [entityKind] = "SQLiteTimestamp";
2154
+ mode = this.config.mode;
2155
+ mapFromDriverValue(value) {
2156
+ if (this.config.mode === "timestamp") {
2157
+ return new Date(value * 1e3);
2158
+ }
2159
+ return new Date(value);
2160
+ }
2161
+ mapToDriverValue(value) {
2162
+ const unix = value.getTime();
2163
+ if (this.config.mode === "timestamp") {
2164
+ return Math.floor(unix / 1e3);
2165
+ }
2166
+ return unix;
2167
+ }
2168
+ };
2169
+ var SQLiteBooleanBuilder = class extends SQLiteBaseIntegerBuilder {
2170
+ static [entityKind] = "SQLiteBooleanBuilder";
2171
+ constructor(name, mode) {
2172
+ super(name, "boolean", "SQLiteBoolean");
2173
+ this.config.mode = mode;
2174
+ }
2175
+ build(table) {
2176
+ return new SQLiteBoolean(
2177
+ table,
2178
+ this.config
2179
+ );
2180
+ }
2181
+ };
2182
+ var SQLiteBoolean = class extends SQLiteBaseInteger {
2183
+ static [entityKind] = "SQLiteBoolean";
2184
+ mode = this.config.mode;
2185
+ mapFromDriverValue(value) {
2186
+ return Number(value) === 1;
2187
+ }
2188
+ mapToDriverValue(value) {
2189
+ return value ? 1 : 0;
2190
+ }
2191
+ };
2192
+ function integer(a, b) {
2193
+ const { name, config } = getColumnNameAndConfig(a, b);
2194
+ if (config?.mode === "timestamp" || config?.mode === "timestamp_ms") {
2195
+ return new SQLiteTimestampBuilder(name, config.mode);
2196
+ }
2197
+ if (config?.mode === "boolean") {
2198
+ return new SQLiteBooleanBuilder(name, config.mode);
2199
+ }
2200
+ return new SQLiteIntegerBuilder(name);
2201
+ }
2202
+
2203
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/sqlite-core/columns/numeric.js
2204
+ var SQLiteNumericBuilder = class extends SQLiteColumnBuilder {
2205
+ static [entityKind] = "SQLiteNumericBuilder";
2206
+ constructor(name) {
2207
+ super(name, "string", "SQLiteNumeric");
2208
+ }
2209
+ /** @internal */
2210
+ build(table) {
2211
+ return new SQLiteNumeric(
2212
+ table,
2213
+ this.config
2214
+ );
2215
+ }
2216
+ };
2217
+ var SQLiteNumeric = class extends SQLiteColumn {
2218
+ static [entityKind] = "SQLiteNumeric";
2219
+ mapFromDriverValue(value) {
2220
+ if (typeof value === "string") return value;
2221
+ return String(value);
2222
+ }
2223
+ getSQLType() {
2224
+ return "numeric";
2225
+ }
2226
+ };
2227
+ var SQLiteNumericNumberBuilder = class extends SQLiteColumnBuilder {
2228
+ static [entityKind] = "SQLiteNumericNumberBuilder";
2229
+ constructor(name) {
2230
+ super(name, "number", "SQLiteNumericNumber");
2231
+ }
2232
+ /** @internal */
2233
+ build(table) {
2234
+ return new SQLiteNumericNumber(
2235
+ table,
2236
+ this.config
2237
+ );
2238
+ }
2239
+ };
2240
+ var SQLiteNumericNumber = class extends SQLiteColumn {
2241
+ static [entityKind] = "SQLiteNumericNumber";
2242
+ mapFromDriverValue(value) {
2243
+ if (typeof value === "number") return value;
2244
+ return Number(value);
2245
+ }
2246
+ mapToDriverValue = String;
2247
+ getSQLType() {
2248
+ return "numeric";
2249
+ }
2250
+ };
2251
+ var SQLiteNumericBigIntBuilder = class extends SQLiteColumnBuilder {
2252
+ static [entityKind] = "SQLiteNumericBigIntBuilder";
2253
+ constructor(name) {
2254
+ super(name, "bigint", "SQLiteNumericBigInt");
2255
+ }
2256
+ /** @internal */
2257
+ build(table) {
2258
+ return new SQLiteNumericBigInt(
2259
+ table,
2260
+ this.config
2261
+ );
2262
+ }
2263
+ };
2264
+ var SQLiteNumericBigInt = class extends SQLiteColumn {
2265
+ static [entityKind] = "SQLiteNumericBigInt";
2266
+ mapFromDriverValue = BigInt;
2267
+ mapToDriverValue = String;
2268
+ getSQLType() {
2269
+ return "numeric";
2270
+ }
2271
+ };
2272
+ function numeric(a, b) {
2273
+ const { name, config } = getColumnNameAndConfig(a, b);
2274
+ const mode = config?.mode;
2275
+ return mode === "number" ? new SQLiteNumericNumberBuilder(name) : mode === "bigint" ? new SQLiteNumericBigIntBuilder(name) : new SQLiteNumericBuilder(name);
2276
+ }
2277
+
2278
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/sqlite-core/columns/real.js
2279
+ var SQLiteRealBuilder = class extends SQLiteColumnBuilder {
2280
+ static [entityKind] = "SQLiteRealBuilder";
2281
+ constructor(name) {
2282
+ super(name, "number", "SQLiteReal");
2283
+ }
2284
+ /** @internal */
2285
+ build(table) {
2286
+ return new SQLiteReal(table, this.config);
2287
+ }
2288
+ };
2289
+ var SQLiteReal = class extends SQLiteColumn {
2290
+ static [entityKind] = "SQLiteReal";
2291
+ getSQLType() {
2292
+ return "real";
2293
+ }
2294
+ };
2295
+ function real(name) {
2296
+ return new SQLiteRealBuilder(name ?? "");
2297
+ }
2298
+
2299
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/sqlite-core/columns/text.js
2300
+ var SQLiteTextBuilder = class extends SQLiteColumnBuilder {
2301
+ static [entityKind] = "SQLiteTextBuilder";
2302
+ constructor(name, config) {
2303
+ super(name, "string", "SQLiteText");
2304
+ this.config.enumValues = config.enum;
2305
+ this.config.length = config.length;
2306
+ }
2307
+ /** @internal */
2308
+ build(table) {
2309
+ return new SQLiteText(
2310
+ table,
2311
+ this.config
2312
+ );
2313
+ }
2314
+ };
2315
+ var SQLiteText = class extends SQLiteColumn {
2316
+ static [entityKind] = "SQLiteText";
2317
+ enumValues = this.config.enumValues;
2318
+ length = this.config.length;
2319
+ constructor(table, config) {
2320
+ super(table, config);
2321
+ }
2322
+ getSQLType() {
2323
+ return `text${this.config.length ? `(${this.config.length})` : ""}`;
2324
+ }
2325
+ };
2326
+ var SQLiteTextJsonBuilder = class extends SQLiteColumnBuilder {
2327
+ static [entityKind] = "SQLiteTextJsonBuilder";
2328
+ constructor(name) {
2329
+ super(name, "json", "SQLiteTextJson");
2330
+ }
2331
+ /** @internal */
2332
+ build(table) {
2333
+ return new SQLiteTextJson(
2334
+ table,
2335
+ this.config
2336
+ );
2337
+ }
2338
+ };
2339
+ var SQLiteTextJson = class extends SQLiteColumn {
2340
+ static [entityKind] = "SQLiteTextJson";
2341
+ getSQLType() {
2342
+ return "text";
2343
+ }
2344
+ mapFromDriverValue(value) {
2345
+ return JSON.parse(value);
2346
+ }
2347
+ mapToDriverValue(value) {
2348
+ return JSON.stringify(value);
2349
+ }
2350
+ };
2351
+ function text2(a, b = {}) {
2352
+ const { name, config } = getColumnNameAndConfig(a, b);
2353
+ if (config.mode === "json") {
2354
+ return new SQLiteTextJsonBuilder(name);
2355
+ }
2356
+ return new SQLiteTextBuilder(name, config);
2357
+ }
2358
+
2359
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/sqlite-core/columns/all.js
2360
+ function getSQLiteColumnBuilders() {
2361
+ return {
2362
+ blob,
2363
+ customType,
2364
+ integer,
2365
+ numeric,
2366
+ real,
2367
+ text: text2
2368
+ };
2369
+ }
2370
+
2371
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/sqlite-core/table.js
2372
+ var InlineForeignKeys = /* @__PURE__ */ Symbol.for("drizzle:SQLiteInlineForeignKeys");
2373
+ var SQLiteTable = class extends Table {
2374
+ static [entityKind] = "SQLiteTable";
2375
+ /** @internal */
2376
+ static Symbol = Object.assign({}, Table.Symbol, {
2377
+ InlineForeignKeys
2378
+ });
2379
+ /** @internal */
2380
+ [Table.Symbol.Columns];
2381
+ /** @internal */
2382
+ [InlineForeignKeys] = [];
2383
+ /** @internal */
2384
+ [Table.Symbol.ExtraConfigBuilder] = void 0;
2385
+ };
2386
+ function sqliteTableBase(name, columns, extraConfig, schema, baseName = name) {
2387
+ const rawTable = new SQLiteTable(name, schema, baseName);
2388
+ const parsedColumns = typeof columns === "function" ? columns(getSQLiteColumnBuilders()) : columns;
2389
+ const builtColumns = Object.fromEntries(
2390
+ Object.entries(parsedColumns).map(([name2, colBuilderBase]) => {
2391
+ const colBuilder = colBuilderBase;
2392
+ colBuilder.setName(name2);
2393
+ const column = colBuilder.build(rawTable);
2394
+ rawTable[InlineForeignKeys].push(...colBuilder.buildForeignKeys(column, rawTable));
2395
+ return [name2, column];
2396
+ })
2397
+ );
2398
+ const table = Object.assign(rawTable, builtColumns);
2399
+ table[Table.Symbol.Columns] = builtColumns;
2400
+ table[Table.Symbol.ExtraConfigColumns] = builtColumns;
2401
+ if (extraConfig) {
2402
+ table[SQLiteTable.Symbol.ExtraConfigBuilder] = extraConfig;
2403
+ }
2404
+ return table;
2405
+ }
2406
+ var sqliteTable = (name, columns, extraConfig) => {
2407
+ return sqliteTableBase(name, columns, extraConfig);
2408
+ };
2409
+
2410
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/sqlite-core/primary-keys.js
2411
+ function primaryKey(...config) {
2412
+ if (config[0].columns) {
2413
+ return new PrimaryKeyBuilder(config[0].columns, config[0].name);
2414
+ }
2415
+ return new PrimaryKeyBuilder(config);
2416
+ }
2417
+ var PrimaryKeyBuilder = class {
2418
+ static [entityKind] = "SQLitePrimaryKeyBuilder";
2419
+ /** @internal */
2420
+ columns;
2421
+ /** @internal */
2422
+ name;
2423
+ constructor(columns, name) {
2424
+ this.columns = columns;
2425
+ this.name = name;
2426
+ }
2427
+ /** @internal */
2428
+ build(table) {
2429
+ return new PrimaryKey(table, this.columns, this.name);
2430
+ }
2431
+ };
2432
+ var PrimaryKey = class {
2433
+ constructor(table, columns, name) {
2434
+ this.table = table;
2435
+ this.columns = columns;
2436
+ this.name = name;
2437
+ }
2438
+ static [entityKind] = "SQLitePrimaryKey";
2439
+ columns;
2440
+ name;
2441
+ getName() {
2442
+ return this.name ?? `${this.table[SQLiteTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
2443
+ }
2444
+ };
2445
+
2446
+ // ../feedback/src/connected.ts
2447
+ var participants = sqliteTable("participants", {
2448
+ subject: text2("subject").primaryKey(),
2449
+ displayName: text2("display_name").notNull()
2450
+ });
2451
+ var contacts = sqliteTable("participant_contacts", {
2452
+ subject: text2("subject").primaryKey(),
2453
+ email: text2("email"),
2454
+ emailEnabled: integer("email_enabled").notNull().default(0)
2455
+ });
2456
+ var nonces = sqliteTable("identity_nonces", {
2457
+ nonce: text2("nonce").primaryKey(),
2458
+ expiresAt: integer("expires_at").notNull()
2459
+ });
2460
+ var sessions = sqliteTable("participant_sessions", {
2461
+ tokenHash: text2("token_hash").primaryKey(),
2462
+ subject: text2("subject").notNull().references(() => participants.subject),
2463
+ expiresAt: integer("expires_at").notNull()
2464
+ });
2465
+ var votes = sqliteTable(
2466
+ "participant_votes",
2467
+ {
2468
+ postSlug: text2("post_slug").notNull(),
2469
+ subject: text2("subject").notNull().references(() => participants.subject)
2470
+ },
2471
+ (t) => [primaryKey({ columns: [t.postSlug, t.subject] })]
2472
+ );
2473
+ var attribution = sqliteTable("comment_attribution", {
2474
+ commentId: text2("comment_id").primaryKey(),
2475
+ subject: text2("subject").notNull().references(() => participants.subject),
2476
+ displayName: text2("display_name").notNull()
2477
+ });
2478
+
2479
+ // ../feedback/src/images.ts
2480
+ var limit = 5 * 1024 * 1024;
2481
+
2482
+ // ../feedback/src/index.ts
2483
+ var postCreationQueue = Promise.resolve();
2484
+
2485
+ // ../changelog/src/notion-changelog.ts
2486
+ var NOTION_API_URL2 = "https://api.notion.com/v1";
2487
+ var NOTION_API_VERSION2 = "2026-03-11";
2488
+ var canonicalProperties2 = {
2489
+ title: { name: "Title", type: "title", schema: { title: {} } },
2490
+ slug: { name: "Slug", type: "rich_text", schema: { rich_text: {} } },
2491
+ date: { name: "Date", type: "date", schema: { date: {} } },
2492
+ summary: {
2493
+ name: "Summary",
2494
+ type: "rich_text",
2495
+ schema: { rich_text: {} }
2496
+ },
2497
+ body: { name: "Body", type: "rich_text", schema: { rich_text: {} } },
2498
+ labels: {
2499
+ name: "Labels",
2500
+ type: "multi_select",
2501
+ schema: { multi_select: { options: [] } }
2502
+ },
2503
+ image: { name: "Image", type: "files", schema: { files: {} } },
2504
+ published: {
2505
+ name: "Published",
2506
+ type: "checkbox",
2507
+ schema: { checkbox: {} }
2508
+ },
2509
+ createdAt: {
2510
+ name: "Created At",
2511
+ type: "created_time",
2512
+ schema: { created_time: {} }
2513
+ },
2514
+ updatedAt: {
2515
+ name: "Updated At",
2516
+ type: "last_edited_time",
2517
+ schema: { last_edited_time: {} }
2518
+ }
2519
+ };
2520
+ async function createNotionChangelogDataSource({
2521
+ token,
2522
+ databaseId,
2523
+ request = fetch
2524
+ }) {
2525
+ const response = await request(`${NOTION_API_URL2}/data_sources`, {
2526
+ method: "POST",
2527
+ headers: notionHeaders2(token),
2528
+ body: JSON.stringify({
2529
+ parent: { database_id: databaseId },
2530
+ title: [{ type: "text", text: { content: "Changelog" } }],
2531
+ properties: Object.fromEntries(
2532
+ Object.values(canonicalProperties2).map(({ name, schema }) => [
2533
+ name,
2534
+ schema
2535
+ ])
2536
+ )
2537
+ })
2538
+ });
2539
+ return configurationFromResponse(
2540
+ await readObject(response, "Changelog Data Source"),
2541
+ databaseId
2542
+ );
2543
+ }
2544
+ async function validateNotionChangelogDataSource({
2545
+ token,
2546
+ dataSourceId,
2547
+ propertyIds: propertyIds2,
2548
+ request = fetch
2549
+ }) {
2550
+ const response = await request(
2551
+ `${NOTION_API_URL2}/data_sources/${dataSourceId}`,
2552
+ { headers: notionHeaders2(token) }
2553
+ );
2554
+ const dataSource = await readObject(response, "Changelog Data Source");
2555
+ const properties = recordAt(dataSource, "properties");
2556
+ const propertiesById = new Map(
2557
+ Object.values(properties).flatMap((property) => {
2558
+ if (!isRecord(property) || typeof property.id !== "string") return [];
2559
+ return [[property.id, property]];
2560
+ })
2561
+ );
2562
+ const repairs = [];
2563
+ for (const [key, { name, type }] of Object.entries(canonicalProperties2)) {
2564
+ const configuredId = propertyIds2[key];
2565
+ const property = propertiesById.get(configuredId);
2566
+ if (!property) {
2567
+ repairs.push(
2568
+ `Restore the "${name}" property with ID "${configuredId}" and type "${type}", then update the configured property ID if Notion assigns a new one.`
2569
+ );
2570
+ } else if (property.type !== type) {
2571
+ repairs.push(
2572
+ `Change the property configured as "${name}" (ID "${configuredId}") from "${String(property.type)}" to "${type}", or restore a ${type} property and configure its ID.`
2573
+ );
2574
+ }
2575
+ }
2576
+ if (repairs.length) throw new Error(repairs.join("\n"));
2577
+ return {
2578
+ databaseId: databaseIdFromResponse(dataSource),
2579
+ dataSourceId,
2580
+ propertyIds: { ...propertyIds2 }
2581
+ };
2582
+ }
2583
+ function configurationFromResponse(dataSource, databaseId) {
2584
+ const properties = recordAt(dataSource, "properties");
2585
+ return {
2586
+ databaseId,
2587
+ dataSourceId: requiredString(dataSource.id),
2588
+ propertyIds: Object.fromEntries(
2589
+ Object.entries(canonicalProperties2).map(([key, { name }]) => [
2590
+ key,
2591
+ requiredString(recordAt(properties, name).id)
2592
+ ])
2593
+ )
2594
+ };
2595
+ }
2596
+ function databaseIdFromResponse(dataSource) {
2597
+ return requiredString(recordAt(dataSource, "parent").database_id);
2598
+ }
2599
+ function notionHeaders2(token) {
2600
+ return {
2601
+ Authorization: `Bearer ${token}`,
2602
+ "Content-Type": "application/json",
2603
+ "Notion-Version": NOTION_API_VERSION2
2604
+ };
2605
+ }
2606
+ async function readObject(response, subject) {
2607
+ const body = await response.json();
2608
+ if (!response.ok) {
2609
+ throw new Error(
2610
+ `Notion rejected the ${subject} request (${response.status}).`
2611
+ );
2612
+ }
2613
+ if (!isRecord(body))
2614
+ throw new Error(`Notion returned an invalid ${subject} response.`);
2615
+ return body;
2616
+ }
2617
+ function recordAt(value, key) {
2618
+ return record(value[key]);
2619
+ }
2620
+ function record(value) {
2621
+ if (!isRecord(value))
2622
+ throw new Error("Notion returned an invalid Changelog response.");
2623
+ return value;
2624
+ }
2625
+ function requiredString(value) {
2626
+ if (typeof value !== "string")
2627
+ throw new Error("Notion returned an invalid Changelog response.");
2628
+ return value;
2629
+ }
2630
+ function isRecord(value) {
2631
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2632
+ }
2633
+
2634
+ // src/index.ts
2635
+ function defaultProcessingQueueName(workerName) {
2636
+ return workerName.length <= 55 ? `${workerName}-updates` : `${workerName.slice(0, 46)}-${createHash("sha256").update(workerName).digest("hex").slice(0, 8)}-updates`;
2637
+ }
2638
+ async function provisionGuidedInstallation({
2639
+ destination,
2640
+ product,
2641
+ themePreset,
2642
+ workerName,
2643
+ commentProbePageId,
2644
+ connected,
2645
+ features,
2646
+ feedbackSelection,
2647
+ changelogSelection,
2648
+ notionToken,
2649
+ turnstile,
2650
+ preview,
2651
+ request = fetch
2652
+ }) {
2653
+ try {
2654
+ if ((await readdir2(destination)).length)
2655
+ throw new Error(
2656
+ `Refusing to generate into non-empty destination: ${destination}`
2657
+ );
2658
+ } catch (error) {
2659
+ if (error.code !== "ENOENT") throw error;
2660
+ }
2661
+ if (product.siteUrl && new URL(product.siteUrl).protocol !== "https:")
2662
+ throw new Error("product.siteUrl must be an HTTPS URL.");
2663
+ if (connected) {
2664
+ if (!product.siteUrl || connected.handoffSecret.length < 32 || !/^[0-9a-f-]{36}$/i.test(connected.databaseId) || !connected.databaseName.trim())
2665
+ throw new Error(
2666
+ "Connected setup requires a public site URL, dedicated D1 identifiers, and a handoff secret of at least 32 characters."
2667
+ );
2668
+ for (const url of [connected.issuer, connected.loginUrl])
2669
+ if (new URL(url).protocol !== "https:" || new URL(url).username || new URL(url).password)
2670
+ throw new Error(
2671
+ "Connected identity URLs must use HTTPS without credentials."
2672
+ );
2673
+ }
2674
+ if (connected?.email) {
2675
+ const sender = connected.email;
2676
+ if (!["cloudflare", "resend", "custom"].includes(sender.provider) || !/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(sender.from))
2677
+ throw new Error(
2678
+ "Choose cloudflare, resend, or custom and a plain sender email address."
2679
+ );
2680
+ if (sender.provider !== "cloudflare" && !sender.secret?.trim())
2681
+ throw new Error(
2682
+ "Resend and custom delivery require a server-only email secret."
2683
+ );
2684
+ if (sender.provider === "custom" && (!sender.endpoint || new URL(sender.endpoint).protocol !== "https:" || new URL(sender.endpoint).username || new URL(sender.endpoint).password || new URL(sender.endpoint).hash))
2685
+ throw new Error(
2686
+ "Custom delivery requires an HTTPS endpoint without credentials or fragments."
2687
+ );
2688
+ }
2689
+ if (connected?.imageBucket && !/^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$/.test(connected.imageBucket))
2690
+ throw new Error(
2691
+ "Use a dedicated private R2 bucket name of 3\u201363 lowercase letters, digits, or hyphens."
2692
+ );
2693
+ const targetName = workerName ?? basename(destination).toLowerCase().replace(/[^a-z0-9-]/g, "-");
2694
+ if (!/^[a-z0-9][a-z0-9-]{0,62}$/.test(targetName))
2695
+ throw new Error(
2696
+ "Worker name must contain 1\u201363 lowercase letters, numbers, or hyphens."
2697
+ );
2698
+ const processingQueue = connected && connected.processing !== "standard" ? connected.queueName ?? defaultProcessingQueueName(targetName) : void 0;
2699
+ if (processingQueue && !/^[a-z0-9][a-z0-9-]{0,62}$/.test(processingQueue))
2700
+ throw new Error(
2701
+ "Processing queue name must contain 1\u201363 lowercase letters, numbers, or hyphens."
2702
+ );
2703
+ const approved = await preview(
2704
+ feedbackSelection.kind === "create" ? `Create the canonical Feedback Data Source inside Notion page ${feedbackSelection.parentPageId}.` : `Validate existing Feedback Data Source ${feedbackSelection.configuration.dataSourceId} without changing it.`
2705
+ );
2706
+ if (!approved)
2707
+ throw new Error(
2708
+ "Feedback setup was not approved. No local files were created."
2709
+ );
2710
+ const feedback = feedbackSelection.kind === "create" ? await createNotionFeedbackDataSource({
2711
+ token: notionToken,
2712
+ parentPageId: feedbackSelection.parentPageId,
2713
+ request
2714
+ }) : await validateNotionFeedbackDataSource({
2715
+ token: notionToken,
2716
+ ...feedbackSelection.configuration,
2717
+ request
2718
+ });
2719
+ if (feedbackSelection.kind === "create") {
2720
+ if (!await preview(
2721
+ "Create six Notion team views: Inbox, Reviewing, Prioritization, Follow-up, Roadmap, and Shipped."
2722
+ ))
2723
+ throw new Error("Workflow view creation was not approved.");
2724
+ await createFeedbackWorkflowViews({
2725
+ token: notionToken,
2726
+ ...feedback,
2727
+ request
2728
+ });
2729
+ }
2730
+ await verifySelectedCommentCapabilities(features, {
2731
+ token: notionToken,
2732
+ pageId: commentProbePageId ?? (feedbackSelection.kind === "create" ? feedbackSelection.parentPageId : feedback.databaseId),
2733
+ request,
2734
+ command: "setup"
2735
+ });
2736
+ const changelog = await configureChangelogStorage({
2737
+ features,
2738
+ selection: changelogSelection ?? (features.changelog ? { kind: "create", databaseId: feedback.databaseId } : void 0),
2739
+ token: notionToken,
2740
+ request,
2741
+ preview
2742
+ });
2743
+ await copyPackagedTemplate(destination);
2744
+ const wranglerPath = join2(destination, "wrangler.jsonc");
2745
+ const wrangler = JSON.parse(await readFile2(wranglerPath, "utf8"));
2746
+ await writeFile2(
2747
+ wranglerPath,
2748
+ JSON.stringify(
2749
+ {
2750
+ ...wrangler,
2751
+ name: targetName,
2752
+ ...connected ? {
2753
+ triggers: { crons: ["*/5 * * * *"] },
2754
+ ...processingQueue ? {
2755
+ queues: {
2756
+ producers: [
2757
+ { binding: "FEEDBAX_UPDATES", queue: processingQueue }
2758
+ ],
2759
+ consumers: [
2760
+ {
2761
+ queue: processingQueue,
2762
+ max_batch_size: 1,
2763
+ max_batch_timeout: 1,
2764
+ max_retries: 3,
2765
+ max_concurrency: 1,
2766
+ retry_delay: 60
2767
+ }
2768
+ ]
15
2769
  }
16
- finally {
17
- terminal.close();
2770
+ } : {},
2771
+ ...connected.email?.provider === "cloudflare" ? {
2772
+ send_email: [
2773
+ {
2774
+ name: "FEEDBAX_EMAIL",
2775
+ allowed_sender_addresses: [connected.email.from]
2776
+ }
2777
+ ]
2778
+ } : {},
2779
+ ...connected.imageBucket ? {
2780
+ r2_buckets: [
2781
+ {
2782
+ binding: "FEEDBAX_IMAGES",
2783
+ bucket_name: connected.imageBucket
2784
+ }
2785
+ ]
2786
+ } : {},
2787
+ d1_databases: [
2788
+ {
2789
+ binding: "FEEDBAX_DB",
2790
+ database_id: connected.databaseId,
2791
+ database_name: connected.databaseName,
2792
+ migrations_dir: "migrations"
18
2793
  }
19
- })()
20
- : resolveCreateOptions(argv);
21
- const result = await createProject(options);
22
- process.stdout.write(`Created Feedbax in ${result.destination}\n\n${result.nextSteps.join('\n')}\n`);
2794
+ ]
2795
+ } : {}
2796
+ },
2797
+ null,
2798
+ 2
2799
+ ) + "\n"
2800
+ );
2801
+ const apiKey = randomBytes(32).toString("base64url");
2802
+ const signingSecret = randomBytes(32).toString("base64url");
2803
+ const values = {
2804
+ NOTION_TOKEN: notionToken,
2805
+ NOTION_FEEDBACK_DATABASE_ID: feedback.databaseId,
2806
+ NOTION_FEEDBACK_DATA_SOURCE_ID: feedback.dataSourceId,
2807
+ ...prefixProperties("NOTION_FEEDBACK", feedback.propertyIds),
2808
+ FEEDBAX_API_KEY_HASH: createHash("sha256").update(apiKey).digest("base64url"),
2809
+ PARTICIPATION_SIGNING_SECRET: signingSecret,
2810
+ ...connected ? { IDENTITY_HANDOFF_SECRET: connected.handoffSecret } : {},
2811
+ ...connected?.email?.secret ? { EMAIL_PROVIDER_SECRET: connected.email.secret } : {},
2812
+ FEEDBAX_VOTING_ENABLED: String(features.voting),
2813
+ FEEDBAX_COMMENTS_ENABLED: String(features.comments),
2814
+ FEEDBAX_CHANGELOG_ENABLED: String(features.changelog),
2815
+ ...turnstile.siteKey ? { VITE_TURNSTILE_SITE_KEY: turnstile.siteKey } : {},
2816
+ ...turnstile.secretKey ? { TURNSTILE_SECRET_KEY: turnstile.secretKey } : {},
2817
+ ...changelog ? {
2818
+ NOTION_CHANGELOG_DATABASE_ID: changelog.databaseId,
2819
+ NOTION_CHANGELOG_DATA_SOURCE_ID: changelog.dataSourceId,
2820
+ ...prefixProperties("NOTION_CHANGELOG", changelog.propertyIds)
2821
+ } : {}
2822
+ };
2823
+ await writeFile2(
2824
+ join2(destination, ".dev.vars"),
2825
+ Object.entries(values).map(([key, value]) => `${key}=${JSON.stringify(value)}`).join("\n") + "\n",
2826
+ { mode: 384 }
2827
+ );
2828
+ const configuration = defineFeedbax({
2829
+ product: { ...product, logo: "/feedbax-mark.svg" },
2830
+ theme: { preset: themePreset },
2831
+ ...connected ? {
2832
+ connected: {
2833
+ processing: connected.processing ?? "small",
2834
+ issuer: connected.issuer,
2835
+ loginUrl: connected.loginUrl,
2836
+ ...connected.email ? {
2837
+ email: {
2838
+ provider: connected.email.provider,
2839
+ from: connected.email.from,
2840
+ ...connected.email.endpoint ? { endpoint: connected.email.endpoint } : {}
2841
+ }
2842
+ } : {},
2843
+ ...connected.imageBucket ? { images: true } : {}
2844
+ }
2845
+ } : {},
2846
+ notion: {
2847
+ databaseId: feedback.databaseId,
2848
+ dataSourceId: feedback.dataSourceId,
2849
+ properties: feedback.propertyIds
2850
+ },
2851
+ ...changelog ? {
2852
+ changelog: {
2853
+ databaseId: changelog.databaseId,
2854
+ dataSourceId: changelog.dataSourceId,
2855
+ properties: changelog.propertyIds
2856
+ }
2857
+ } : {},
2858
+ features,
2859
+ submissions: {
2860
+ moderation: "required",
2861
+ maxTitleLength: 160,
2862
+ maxDescriptionLength: 5e3
2863
+ },
2864
+ turnstile: {
2865
+ enabled: Boolean(turnstile.siteKey),
2866
+ ...turnstile.siteKey ? { siteKey: turnstile.siteKey } : {}
2867
+ }
2868
+ });
2869
+ await writeFile2(
2870
+ join2(destination, "src/feedbax.ts"),
2871
+ `import { defineFeedbax } from "@feedbax/config";
2872
+
2873
+ export default defineFeedbax(${JSON.stringify(configuration, null, 2)});
2874
+ `
2875
+ );
2876
+ const probePage = commentProbePageId ?? (feedbackSelection.kind === "create" ? feedbackSelection.parentPageId : feedback.databaseId);
2877
+ await writeFile2(
2878
+ join2(destination, ".dev.vars"),
2879
+ `NOTION_COMMENT_CAPABILITY_PROBE_PAGE_ID=${JSON.stringify(probePage)}
2880
+ `,
2881
+ { flag: "a", mode: 384 }
2882
+ );
2883
+ return { apiKey, feedback, changelog, processingQueue };
2884
+ }
2885
+ function prefixProperties(prefix, properties) {
2886
+ return Object.fromEntries(
2887
+ Object.entries(properties).map(([key, value]) => [
2888
+ `${prefix}_${key.replace(/[A-Z]/g, (letter) => `_${letter}`).toUpperCase()}_PROPERTY_ID`,
2889
+ value
2890
+ ])
2891
+ );
2892
+ }
2893
+ var featureChoices = [
2894
+ { key: "voting", label: "Voting", initialValue: true },
2895
+ { key: "comments", label: "Comments", initialValue: true },
2896
+ { key: "changelog", label: "Changelog", initialValue: true }
2897
+ ];
2898
+ async function collectFeatureSelection(prompter) {
2899
+ const selections = [];
2900
+ for (const { key, label, initialValue } of featureChoices) {
2901
+ selections.push([
2902
+ key,
2903
+ await prompter.confirm({
2904
+ message: `Enable ${label}?`,
2905
+ initialValue
2906
+ })
2907
+ ]);
2908
+ }
2909
+ return Object.fromEntries(selections);
2910
+ }
2911
+ async function verifySelectedCommentCapabilities(features, {
2912
+ token,
2913
+ pageId,
2914
+ request = fetch,
2915
+ command = "setup"
2916
+ }) {
2917
+ if (!features.comments) return;
2918
+ const headers = {
2919
+ Authorization: `Bearer ${token}`,
2920
+ "Notion-Version": "2026-03-11"
2921
+ };
2922
+ const readResponse = await request(
2923
+ `https://api.notion.com/v1/comments?block_id=${encodeURIComponent(pageId)}&page_size=1`,
2924
+ { headers }
2925
+ );
2926
+ if (!readResponse.ok) {
2927
+ if (readResponse.status === 403)
2928
+ assertEnabledCommentCapabilities({
2929
+ commentsEnabled: true,
2930
+ capabilities: { readComments: false, insertComments: true },
2931
+ command
2932
+ });
2933
+ throw new Error(
2934
+ `Notion Comment read check failed (HTTP ${readResponse.status}). Verify a shared page ID and connection access.`
2935
+ );
2936
+ }
2937
+ if (command === "doctor") {
2938
+ assertEnabledCommentCapabilities({
2939
+ commentsEnabled: true,
2940
+ capabilities: {
2941
+ readComments: readResponse.status !== 403,
2942
+ // Setup proves Insert comments before enabling the capability. Doctor
2943
+ // deliberately avoids a write-method probe and verifies the live read path.
2944
+ insertComments: true
2945
+ },
2946
+ command
2947
+ });
2948
+ return;
2949
+ }
2950
+ const insertResponse = await request("https://api.notion.com/v1/comments", {
2951
+ method: "POST",
2952
+ headers: { ...headers, "Content-Type": "application/json" },
2953
+ body: "{}"
2954
+ });
2955
+ if (insertResponse.status !== 400 && insertResponse.status !== 403)
2956
+ throw new Error(
2957
+ `Notion Comment insert capability check failed (HTTP ${insertResponse.status}).`
2958
+ );
2959
+ const capabilities = {
2960
+ readComments: readResponse.status !== 403,
2961
+ insertComments: insertResponse.status !== 403
2962
+ };
2963
+ assertEnabledCommentCapabilities({
2964
+ commentsEnabled: true,
2965
+ capabilities,
2966
+ command
2967
+ });
2968
+ }
2969
+ function assertEnabledCommentCapabilities({
2970
+ commentsEnabled,
2971
+ capabilities,
2972
+ command = "setup"
2973
+ }) {
2974
+ if (!commentsEnabled) return;
2975
+ const missing = [
2976
+ ...capabilities.readComments ? [] : ["Read comments"],
2977
+ ...capabilities.insertComments ? [] : ["Insert comments"]
2978
+ ];
2979
+ if (missing.length === 0) return;
2980
+ const retry = command === "doctor" ? "rerun doctor. No changes were made." : "retry setup.";
2981
+ throw new Error(
2982
+ `Enable ${missing.join(" and ")} in the Notion connection settings, then ${retry}`
2983
+ );
2984
+ }
2985
+ async function configureChangelogStorage({
2986
+ features,
2987
+ selection,
2988
+ token,
2989
+ request = fetch,
2990
+ preview
2991
+ }) {
2992
+ if (!features.changelog) return;
2993
+ if (!selection) {
2994
+ throw new Error(
2995
+ "Choose an existing compatible Changelog Data Source or create one beside Feedback."
2996
+ );
2997
+ }
2998
+ if (selection.kind === "existing") {
2999
+ return validateNotionChangelogDataSource({
3000
+ token,
3001
+ dataSourceId: selection.dataSourceId,
3002
+ propertyIds: selection.propertyIds,
3003
+ request
3004
+ });
3005
+ }
3006
+ const approved = await preview(
3007
+ `Create an empty Changelog Data Source beside Feedback in Feedbax Database ${selection.databaseId}. No sample entries will be published.`
3008
+ );
3009
+ if (!approved) throw new Error("Changelog creation was not approved.");
3010
+ return createNotionChangelogDataSource({
3011
+ token,
3012
+ databaseId: selection.databaseId,
3013
+ request
3014
+ });
3015
+ }
3016
+
3017
+ // src/cli.ts
3018
+ try {
3019
+ const args = process.argv.slice(2);
3020
+ if (args.includes("--help") || args.includes("-h")) {
3021
+ console.log(
3022
+ "Usage: create-feedbax [directory] [--template-only]\nGuided setup prompts for a destination, product, Notion connection, features, and deployment.\n--template-only copies source without external requests or installing dependencies."
3023
+ );
3024
+ } else if (args.includes("--version")) {
3025
+ console.log(
3026
+ JSON.parse(
3027
+ await readFile3(new URL("../package.json", import.meta.url), "utf8")
3028
+ ).version
3029
+ );
3030
+ } else {
3031
+ if (args.some((arg) => arg.startsWith("-") && arg !== "--template-only"))
3032
+ throw new Error("Unknown option. Run create-feedbax --help.");
3033
+ const destination = resolve2(
3034
+ args.find((arg) => !arg.startsWith("-")) ?? await text4("Project directory", "my-feedback")
3035
+ );
3036
+ if (args.includes("--template-only")) {
3037
+ await copyPackagedTemplate(destination);
3038
+ console.log(`Created a flat Feedbax application in ${destination}.`);
3039
+ } else {
3040
+ prompt.intro("Create a Feedbax portal");
3041
+ const product = {
3042
+ name: await text4("Product name", "My product"),
3043
+ description: await text4(
3044
+ "Public description",
3045
+ "Share feedback and follow product progress."
3046
+ ),
3047
+ siteUrl: await text4(
3048
+ "Public portal URL (your workers.dev URL or custom domain)",
3049
+ "https://my-feedback.example.workers.dev"
3050
+ )
3051
+ };
3052
+ const workerName = await text4(
3053
+ "Cloudflare Worker name (choose a distinct name for this product)",
3054
+ basename2(destination).toLowerCase().replace(/[^a-z0-9-]/g, "-")
3055
+ );
3056
+ const connected = await confirm2(
3057
+ "Enable Connected Profile using your application's sign-in, dedicated D1, and a processing queue? Small processing supports Workers Free with Resend/custom email.",
3058
+ false
3059
+ ) ? {
3060
+ issuer: await text4("Application identity issuer (HTTPS URL)"),
3061
+ loginUrl: await text4(
3062
+ "Application signed-handoff login URL (HTTPS)"
3063
+ ),
3064
+ databaseId: await text4("Dedicated Cloudflare D1 database ID"),
3065
+ databaseName: await text4("Dedicated Cloudflare D1 database name"),
3066
+ queueName: await text4(
3067
+ "Dedicated Cloudflare Queue name (create it with wrangler queues create first)",
3068
+ defaultProcessingQueueName(workerName)
3069
+ ),
3070
+ handoffSecret: await secret(
3071
+ "Shared server-only identity handoff secret (at least 32 characters)"
3072
+ )
3073
+ } : void 0;
3074
+ let email;
3075
+ let imageBucket;
3076
+ if (connected) {
3077
+ const provider = await text4(
3078
+ "Email sender: cloudflare, resend, custom, or none",
3079
+ "none"
3080
+ );
3081
+ if (provider !== "none") {
3082
+ if (provider !== "cloudflare" && provider !== "resend" && provider !== "custom")
3083
+ throw new Error(
3084
+ "Email sender must be cloudflare, resend, custom, or none."
3085
+ );
3086
+ email = {
3087
+ provider,
3088
+ from: await text4("Verified sender email address"),
3089
+ ...provider === "custom" ? { endpoint: await text4("Custom HTTPS delivery endpoint") } : {},
3090
+ ...provider !== "cloudflare" ? { secret: await secret("Server-only email provider secret") } : {}
3091
+ };
3092
+ }
3093
+ if (await confirm2(
3094
+ "Enable Participant image attachments using an existing private R2 bucket?",
3095
+ false
3096
+ ))
3097
+ imageBucket = await text4(
3098
+ "Dedicated private R2 bucket name (create it in Cloudflare first)"
3099
+ );
3100
+ }
3101
+ const themePreset = await text4(
3102
+ "shadcn preset code, or lyra-neutral for the included preset",
3103
+ "lyra-neutral"
3104
+ );
3105
+ const notionToken = process.env.NOTION_TOKEN?.trim() || await secret("Notion internal integration token");
3106
+ const existing = await confirm2(
3107
+ "Use an existing compatible Feedback Data Source?",
3108
+ false
3109
+ );
3110
+ const feedbackSelection = existing ? { kind: "existing", configuration: await existingFeedback() } : {
3111
+ kind: "create",
3112
+ parentPageId: await text4(
3113
+ "Notion parent page ID (share it with the integration)"
3114
+ )
3115
+ };
3116
+ const features = await collectFeatureSelection({
3117
+ confirm: ({ message, initialValue }) => confirm2(message, initialValue)
3118
+ });
3119
+ const commentProbePageId = existing && features.comments ? await text4("Shared Notion page ID for checking Comment permissions") : void 0;
3120
+ const changelogSelection = features.changelog && await confirm2(
3121
+ "Use an existing compatible Changelog Data Source?",
3122
+ false
3123
+ ) ? {
3124
+ kind: "existing",
3125
+ dataSourceId: await text4("Changelog Data Source ID"),
3126
+ propertyIds: await propertyIds([
3127
+ "title",
3128
+ "slug",
3129
+ "date",
3130
+ "summary",
3131
+ "body",
3132
+ "labels",
3133
+ "image",
3134
+ "published",
3135
+ "createdAt",
3136
+ "updatedAt"
3137
+ ])
3138
+ } : void 0;
3139
+ const turnstile = await confirm2(
3140
+ "Enable Cloudflare Turnstile? Recommended for production.",
3141
+ true
3142
+ ) ? {
3143
+ siteKey: await text4("Turnstile site key"),
3144
+ secretKey: process.env.TURNSTILE_SECRET_KEY || await secret("Turnstile secret key")
3145
+ } : {};
3146
+ const result = await provisionGuidedInstallation({
3147
+ destination,
3148
+ product,
3149
+ themePreset,
3150
+ workerName,
3151
+ commentProbePageId,
3152
+ connected: connected ? {
3153
+ ...connected,
3154
+ ...email ? { email } : {},
3155
+ ...imageBucket ? { imageBucket } : {}
3156
+ } : void 0,
3157
+ features,
3158
+ feedbackSelection,
3159
+ changelogSelection,
3160
+ notionToken,
3161
+ turnstile,
3162
+ preview: (message) => confirm2(message, false)
3163
+ });
3164
+ console.log(
3165
+ `Created ${destination}.
3166
+ Trusted API key \u2014 copy it now; plaintext is not stored:
3167
+ ${result.apiKey}`
3168
+ );
3169
+ await runIn(destination, "pnpm", ["install"]);
3170
+ if (themePreset !== "lyra-neutral")
3171
+ await runIn(destination, "pnpm", [
3172
+ "dlx",
3173
+ "shadcn@latest",
3174
+ "init",
3175
+ "--preset",
3176
+ themePreset,
3177
+ "--yes",
3178
+ "--force"
3179
+ ]);
3180
+ await runIn(destination, "pnpm", [
3181
+ "exec",
3182
+ "prettier",
3183
+ "--write",
3184
+ "src/feedbax.ts"
3185
+ ]);
3186
+ if (connected) {
3187
+ if (!await confirm2(
3188
+ `Apply the included Connected schema migration to D1 ${connected.databaseName} (${connected.databaseId}) in your authenticated Cloudflare account?`,
3189
+ false
3190
+ ))
3191
+ throw new Error(
3192
+ "Connected source is preserved. Apply the D1 migration described in CONNECTED.md before running doctor or deploying."
3193
+ );
3194
+ await runIn(destination, "pnpm", [
3195
+ "exec",
3196
+ "wrangler",
3197
+ "d1",
3198
+ "migrations",
3199
+ "apply",
3200
+ "FEEDBAX_DB",
3201
+ "--remote"
3202
+ ]);
3203
+ }
3204
+ await runIn(destination, "pnpm", ["exec", "feedbax", "doctor"]);
3205
+ if (await confirm2(
3206
+ "Authenticate with Cloudflare and deploy this portal?",
3207
+ false
3208
+ )) {
3209
+ await runIn(destination, "pnpm", ["exec", "wrangler", "login"]);
3210
+ await runIn(destination, "pnpm", ["exec", "feedbax", "deploy"]);
3211
+ }
3212
+ prompt.outro(`Your portal source is ready in ${destination}.`);
3213
+ }
3214
+ }
3215
+ } catch (error) {
3216
+ console.error(
3217
+ error instanceof Error ? error.message : "Feedbax setup failed."
3218
+ );
3219
+ process.exitCode = 10;
3220
+ }
3221
+ function checked(value) {
3222
+ if (prompt.isCancel(value)) throw new Error("Setup cancelled.");
3223
+ return value;
3224
+ }
3225
+ async function text4(message, defaultValue) {
3226
+ return checked(
3227
+ await prompt.text({
3228
+ message,
3229
+ defaultValue,
3230
+ placeholder: defaultValue,
3231
+ validate: (value) => value?.trim() || defaultValue ? void 0 : "A value is required."
3232
+ })
3233
+ ).trim();
3234
+ }
3235
+ async function secret(message) {
3236
+ return checked(
3237
+ await prompt.password({
3238
+ message,
3239
+ validate: (value) => value?.trim() ? void 0 : "A value is required."
3240
+ })
3241
+ ).trim();
3242
+ }
3243
+ async function confirm2(message, initialValue) {
3244
+ return checked(await prompt.confirm({ message, initialValue }));
3245
+ }
3246
+ async function propertyIds(keys) {
3247
+ const entries = [];
3248
+ for (const key of keys)
3249
+ entries.push([key, await text4(`Stable property ID: ${key}`)]);
3250
+ return Object.fromEntries(entries);
3251
+ }
3252
+ async function existingFeedback() {
3253
+ return {
3254
+ databaseId: await text4("Feedback Database ID"),
3255
+ dataSourceId: await text4("Feedback Data Source ID"),
3256
+ propertyIds: await propertyIds([
3257
+ "title",
3258
+ "slug",
3259
+ "description",
3260
+ "type",
3261
+ "status",
3262
+ "published",
3263
+ "voteCount",
3264
+ "teamResponse",
3265
+ "releaseNotesUrl",
3266
+ "submitterName",
3267
+ "submitterEmail",
3268
+ "source",
3269
+ "externalId",
3270
+ "editTokenHash",
3271
+ "createdAt",
3272
+ "updatedAt"
3273
+ ])
3274
+ };
23
3275
  }
24
- catch (error) {
25
- process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
26
- process.exitCode = 1;
3276
+ function runIn(cwd, command, args) {
3277
+ return new Promise((resolve3, reject) => {
3278
+ const child = spawn(command, args, { cwd, stdio: "inherit" });
3279
+ child.on("error", reject);
3280
+ child.on(
3281
+ "exit",
3282
+ (code) => code === 0 ? resolve3() : reject(
3283
+ new Error(
3284
+ `${command} failed with exit code ${code}. The generated source has been preserved.`
3285
+ )
3286
+ )
3287
+ );
3288
+ });
27
3289
  }
28
- //# sourceMappingURL=cli.js.map