create-feedbax 0.2.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 (99) hide show
  1. package/dist/cli.js +2042 -16
  2. package/dist/index.js +1997 -5
  3. package/package.json +1 -1
  4. package/template/.feedbax-template.sha256 +1 -1
  5. package/template/AGENTS.md +13 -0
  6. package/template/CONNECTED.md +404 -0
  7. package/template/README.md +58 -0
  8. package/template/components.json +1 -1
  9. package/template/eslint.config.mjs +23 -0
  10. package/template/migrations/0001_connected.sql +6 -0
  11. package/template/migrations/0002_participation.sql +8 -0
  12. package/template/migrations/0003_images.sql +3 -0
  13. package/template/migrations/0004_followed_status.sql +9 -0
  14. package/template/package.json +9 -5
  15. package/template/src/authorized-draft-post.tsx +1 -0
  16. package/template/src/changelog-page.tsx +63 -54
  17. package/template/src/cloudflare-workers.d.ts +6 -0
  18. package/template/src/comment-creation.test.tsx +42 -1
  19. package/template/src/comment-thread-page.ts +11 -1
  20. package/template/src/components/command-palette.tsx +59 -30
  21. package/template/src/components/connected-identity-provider.tsx +108 -0
  22. package/template/src/components/device-profile-provider.tsx +41 -26
  23. package/template/src/components/follow-post-button.tsx +89 -0
  24. package/template/src/components/header.tsx +2 -0
  25. package/template/src/components/image-attachments.tsx +187 -0
  26. package/template/src/components/loader.tsx +48 -5
  27. package/template/src/components/notification-inbox.tsx +232 -0
  28. package/template/src/components/portal-footer.tsx +14 -0
  29. package/template/src/components/profile-menu.tsx +30 -0
  30. package/template/src/components/ui/components/command.tsx +30 -29
  31. package/template/src/components/ui/components/message-scroller.tsx +2 -2
  32. package/template/src/components/ui/components/scroll-area.tsx +0 -1
  33. package/template/src/components/ui/components/switch.tsx +29 -0
  34. package/template/src/components/ui/styles/globals.css +1 -1
  35. package/template/src/connected-identity.test.ts +144 -0
  36. package/template/src/connected-identity.ts +122 -0
  37. package/template/src/connected-participation.test.tsx +67 -0
  38. package/template/src/connected-runtime.test.ts +241 -0
  39. package/template/src/connected-runtime.ts +176 -0
  40. package/template/src/connected-social.test.tsx +158 -0
  41. package/template/src/feedback-cache-invalidation.ts +1 -0
  42. package/template/src/feedback-runtime.ts +79 -12
  43. package/template/src/feedbax/config/index.test.ts +28 -0
  44. package/template/src/feedbax/config/index.ts +93 -0
  45. package/template/src/feedbax/feedback/connected-feedback.ts +206 -0
  46. package/template/src/feedbax/feedback/connected.test.ts +272 -0
  47. package/template/src/feedbax/feedback/connected.ts +215 -0
  48. package/template/src/feedbax/feedback/email-delivery.test.ts +65 -0
  49. package/template/src/feedbax/feedback/email-delivery.ts +66 -0
  50. package/template/src/feedbax/feedback/identity-handoff.test.ts +81 -0
  51. package/template/src/feedbax/feedback/identity-handoff.ts +119 -0
  52. package/template/src/feedbax/feedback/image-feedback.ts +101 -0
  53. package/template/src/feedbax/feedback/images.test.ts +223 -0
  54. package/template/src/feedbax/feedback/images.ts +324 -0
  55. package/template/src/feedbax/feedback/index.ts +55 -1
  56. package/template/src/feedbax/feedback/notion-image-review.ts +55 -0
  57. package/template/src/feedbax/feedback/participation.test.ts +653 -0
  58. package/template/src/feedbax/feedback/participation.ts +502 -0
  59. package/template/src/images-runtime.test.ts +133 -0
  60. package/template/src/images-runtime.ts +125 -0
  61. package/template/src/index.css +97 -440
  62. package/template/src/lazy-post-detail-overlay.tsx +13 -2
  63. package/template/src/overlay-post-detail.test.tsx +59 -8
  64. package/template/src/overlay-post-detail.tsx +20 -69
  65. package/template/src/participation-client.ts +63 -0
  66. package/template/src/participation-runtime.test.ts +35 -0
  67. package/template/src/participation-runtime.ts +255 -0
  68. package/template/src/portal-comments.ts +24 -5
  69. package/template/src/portal-feedback-form.tsx +18 -3
  70. package/template/src/portal-feedback-runtime.ts +3 -0
  71. package/template/src/portal-feedback-server-function.ts +6 -3
  72. package/template/src/portal-feedback-submission.ts +10 -0
  73. package/template/src/portal-server-entry.ts +4 -0
  74. package/template/src/post-creation-flow.tsx +2 -2
  75. package/template/src/post-detail-content.test.tsx +233 -0
  76. package/template/src/post-detail-content.tsx +162 -0
  77. package/template/src/post-detail-query.ts +34 -0
  78. package/template/src/post-results.tsx +1 -1
  79. package/template/src/public-cache-policy.test.ts +11 -4
  80. package/template/src/public-cache-policy.ts +1 -1
  81. package/template/src/public-feedback-index.tsx +9 -39
  82. package/template/src/public-feedback-page.test.tsx +65 -0
  83. package/template/src/public-feedback-page.ts +12 -1
  84. package/template/src/public-post-detail-skeleton.tsx +54 -0
  85. package/template/src/public-post-detail.tsx +298 -208
  86. package/template/src/public-post-route.test.tsx +39 -3
  87. package/template/src/public-post-route.tsx +15 -28
  88. package/template/src/public-roadmap-route.test.tsx +38 -2
  89. package/template/src/public-roadmap-view.tsx +56 -23
  90. package/template/src/public-shell.test.tsx +26 -0
  91. package/template/src/routeTree.gen.ts +49 -3
  92. package/template/src/router.tsx +2 -0
  93. package/template/src/routes/__root.tsx +3 -5
  94. package/template/src/routes/email-preferences.tsx +77 -0
  95. package/template/src/routes/submit.tsx +1 -1
  96. package/template/src/safe-public-failure.ts +3 -1
  97. package/template/src/server.ts +41 -1
  98. package/template/src/trusted-feedback-handler.test.ts +1 -1
  99. package/template/src/vote-toggle.tsx +42 -9
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import { readFile as readFile2, readdir as readdir2, writeFile as writeFile2 } f
4
4
 
5
5
  // ../config/src/index.ts
6
6
  var rootKeys = [
7
+ "connected",
7
8
  "product",
8
9
  "theme",
9
10
  "notion",
@@ -60,6 +61,66 @@ function defineFeedbax(config) {
60
61
  ...optionalPublicUrl(product, "supportUrl"),
61
62
  ...optionalPublicUrl(product, "privacyUrl")
62
63
  };
64
+ let connected;
65
+ if (value.connected !== void 0) {
66
+ const input = object(value.connected, "connected");
67
+ rejectUnknown(
68
+ input,
69
+ ["issuer", "loginUrl", "email", "images", "processing"],
70
+ "connected"
71
+ );
72
+ const issuer = publicUrl(input.issuer, "connected.issuer", false);
73
+ const loginUrl = publicUrl(input.loginUrl, "connected.loginUrl", false);
74
+ if (!validatedProduct.siteUrl)
75
+ throw new Error("Connected Profile requires product.siteUrl.");
76
+ if (new URL(loginUrl).username || new URL(loginUrl).password || new URL(loginUrl).hash)
77
+ throw new Error(
78
+ "connected.loginUrl must not contain credentials or a fragment."
79
+ );
80
+ let email;
81
+ if (input.email !== void 0) {
82
+ const sender = object(input.email, "connected.email");
83
+ rejectUnknown(
84
+ sender,
85
+ ["provider", "from", "endpoint"],
86
+ "connected.email"
87
+ );
88
+ if (!["cloudflare", "resend", "custom"].includes(String(sender.provider)))
89
+ throw new Error(
90
+ "connected.email.provider must be cloudflare, resend, or custom."
91
+ );
92
+ const from = text(sender.from, "connected.email.from");
93
+ if (from.length > 254 || !/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(from))
94
+ throw new Error(
95
+ "connected.email.from must be a plain sender email address."
96
+ );
97
+ const endpoint = sender.endpoint === void 0 ? void 0 : publicUrl(sender.endpoint, "connected.email.endpoint", false);
98
+ if (sender.provider === "custom" && !endpoint)
99
+ throw new Error("Custom email requires connected.email.endpoint.");
100
+ if (sender.provider !== "custom" && endpoint)
101
+ throw new Error("Only custom email uses connected.email.endpoint.");
102
+ if (endpoint && (new URL(endpoint).username || new URL(endpoint).password || new URL(endpoint).hash))
103
+ throw new Error(
104
+ "Custom email endpoint must not contain credentials or a fragment."
105
+ );
106
+ email = {
107
+ provider: sender.provider,
108
+ from,
109
+ ...endpoint ? { endpoint } : {}
110
+ };
111
+ }
112
+ if (input.images !== void 0 && typeof input.images !== "boolean")
113
+ throw new Error("connected.images must be true or false.");
114
+ if (input.processing !== void 0 && input.processing !== "small" && input.processing !== "standard")
115
+ throw new Error("connected.processing must be small or standard.");
116
+ connected = {
117
+ issuer,
118
+ loginUrl,
119
+ ...input.processing !== void 0 ? { processing: input.processing } : {},
120
+ ...email ? { email } : {},
121
+ ...input.images !== void 0 ? { images: input.images } : {}
122
+ };
123
+ }
63
124
  const theme = object(value.theme, "theme");
64
125
  rejectUnknown(theme, ["preset"], "theme");
65
126
  const notion = storage(
@@ -102,6 +163,7 @@ function defineFeedbax(config) {
102
163
  throw new Error("Turnstile is enabled but turnstile.siteKey is missing.");
103
164
  return {
104
165
  product: validatedProduct,
166
+ ...connected ? { connected } : {},
105
167
  theme: { preset: text(theme.preset, "theme.preset") },
106
168
  notion,
107
169
  ...changelog ? { changelog } : {},
@@ -197,6 +259,22 @@ async function assembleFlatTemplate(coreRoot, destination) {
197
259
  await mkdir(join(target, "src/feedbax"), { recursive: true });
198
260
  await copy(join(coreRoot, "apps/portal/src"), join(target, "src"));
199
261
  await copy(join(coreRoot, "apps/portal/public"), join(target, "public"));
262
+ await copy(
263
+ join(coreRoot, "apps/portal/migrations"),
264
+ join(target, "migrations")
265
+ );
266
+ await copy(
267
+ join(coreRoot, "docs/connected-profile.md"),
268
+ join(target, "CONNECTED.md")
269
+ );
270
+ await copy(
271
+ join(coreRoot, "packages/create-feedbax/docs/installation-readme.md"),
272
+ join(target, "README.md")
273
+ );
274
+ await copy(
275
+ join(coreRoot, "packages/create-feedbax/docs/installation-agents.md"),
276
+ join(target, "AGENTS.md")
277
+ );
200
278
  await copy(
201
279
  join(coreRoot, "packages/feedback/src"),
202
280
  join(target, "src/feedbax/feedback")
@@ -213,12 +291,28 @@ async function assembleFlatTemplate(coreRoot, destination) {
213
291
  join(coreRoot, "packages/ui/src"),
214
292
  join(target, "src/components/ui")
215
293
  );
294
+ const stylesheet = join(target, "src/index.css");
295
+ await writeFile(
296
+ stylesheet,
297
+ (await readFile(stylesheet, "utf8")).replace(
298
+ '@import "@feedbax/ui/globals.css";',
299
+ '@import "./components/ui/styles/globals.css";'
300
+ )
301
+ );
302
+ const globals = join(target, "src/components/ui/styles/globals.css");
303
+ await writeFile(
304
+ globals,
305
+ (await readFile(globals, "utf8")).replace(
306
+ '@source "../../../../apps/**/*.{ts,tsx}";',
307
+ '@source "../../../**/*.{ts,tsx}";'
308
+ )
309
+ );
216
310
  for (const name of ["vite.config.ts"])
217
311
  await copy(join(coreRoot, "apps/portal", name), join(target, name));
218
312
  const components = parse(
219
313
  await readFile(join(coreRoot, "apps/portal/components.json"), "utf8")
220
314
  );
221
- components.tailwind.css = "src/components/ui/styles/globals.css";
315
+ components.tailwind.css = "src/index.css";
222
316
  await writeFile(
223
317
  join(target, "components.json"),
224
318
  JSON.stringify(components, null, 2) + "\n"
@@ -408,9 +502,9 @@ async function flatManifest(coreRoot) {
408
502
  ])
409
503
  );
410
504
  const collect = (section) => Object.fromEntries(
411
- manifests.flatMap((manifest) => Object.entries(manifest[section] ?? {})).filter(([name]) => !name.startsWith("@feedbax/")).map(([name, version]) => [
505
+ manifests.flatMap((manifest) => Object.entries(manifest[section] ?? {})).filter(([name]) => !name.startsWith("@feedbax/")).map(([name, version2]) => [
412
506
  name,
413
- version === "catalog:" ? catalog[name] : version
507
+ version2 === "catalog:" ? catalog[name] : version2
414
508
  ])
415
509
  );
416
510
  return {
@@ -434,6 +528,7 @@ async function flatManifest(coreRoot) {
434
528
  devDependencies: {
435
529
  ...collect("devDependencies"),
436
530
  "@eslint/js": "10.0.1",
531
+ "@shadcn/lint": "0.2.1",
437
532
  "@types/node": "22.20.1",
438
533
  feedbax: JSON.parse(
439
534
  await readFile(join(coreRoot, "packages/feedbax/package.json"), "utf8")
@@ -905,6 +1000,1795 @@ function isPropertyMap(value) {
905
1000
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
906
1001
  }
907
1002
 
1003
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/entity.js
1004
+ var entityKind = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
1005
+ function is(value, type) {
1006
+ if (!value || typeof value !== "object") {
1007
+ return false;
1008
+ }
1009
+ if (value instanceof type) {
1010
+ return true;
1011
+ }
1012
+ if (!Object.prototype.hasOwnProperty.call(type, entityKind)) {
1013
+ throw new Error(
1014
+ `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.`
1015
+ );
1016
+ }
1017
+ let cls = Object.getPrototypeOf(value).constructor;
1018
+ if (cls) {
1019
+ while (cls) {
1020
+ if (entityKind in cls && cls[entityKind] === type[entityKind]) {
1021
+ return true;
1022
+ }
1023
+ cls = Object.getPrototypeOf(cls);
1024
+ }
1025
+ }
1026
+ return false;
1027
+ }
1028
+
1029
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/column.js
1030
+ var Column = class {
1031
+ constructor(table, config) {
1032
+ this.table = table;
1033
+ this.config = config;
1034
+ this.name = config.name;
1035
+ this.keyAsName = config.keyAsName;
1036
+ this.notNull = config.notNull;
1037
+ this.default = config.default;
1038
+ this.defaultFn = config.defaultFn;
1039
+ this.onUpdateFn = config.onUpdateFn;
1040
+ this.hasDefault = config.hasDefault;
1041
+ this.primary = config.primaryKey;
1042
+ this.isUnique = config.isUnique;
1043
+ this.uniqueName = config.uniqueName;
1044
+ this.uniqueType = config.uniqueType;
1045
+ this.dataType = config.dataType;
1046
+ this.columnType = config.columnType;
1047
+ this.generated = config.generated;
1048
+ this.generatedIdentity = config.generatedIdentity;
1049
+ }
1050
+ static [entityKind] = "Column";
1051
+ name;
1052
+ keyAsName;
1053
+ primary;
1054
+ notNull;
1055
+ default;
1056
+ defaultFn;
1057
+ onUpdateFn;
1058
+ hasDefault;
1059
+ isUnique;
1060
+ uniqueName;
1061
+ uniqueType;
1062
+ dataType;
1063
+ columnType;
1064
+ enumValues = void 0;
1065
+ generated = void 0;
1066
+ generatedIdentity = void 0;
1067
+ config;
1068
+ mapFromDriverValue(value) {
1069
+ return value;
1070
+ }
1071
+ mapToDriverValue(value) {
1072
+ return value;
1073
+ }
1074
+ // ** @internal */
1075
+ shouldDisableInsert() {
1076
+ return this.config.generated !== void 0 && this.config.generated.type !== "byDefault";
1077
+ }
1078
+ };
1079
+
1080
+ // ../../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
1081
+ var ColumnBuilder = class {
1082
+ static [entityKind] = "ColumnBuilder";
1083
+ config;
1084
+ constructor(name, dataType, columnType) {
1085
+ this.config = {
1086
+ name,
1087
+ keyAsName: name === "",
1088
+ notNull: false,
1089
+ default: void 0,
1090
+ hasDefault: false,
1091
+ primaryKey: false,
1092
+ isUnique: false,
1093
+ uniqueName: void 0,
1094
+ uniqueType: void 0,
1095
+ dataType,
1096
+ columnType,
1097
+ generated: void 0
1098
+ };
1099
+ }
1100
+ /**
1101
+ * Changes the data type of the column. Commonly used with `json` columns. Also, useful for branded types.
1102
+ *
1103
+ * @example
1104
+ * ```ts
1105
+ * const users = pgTable('users', {
1106
+ * id: integer('id').$type<UserId>().primaryKey(),
1107
+ * details: json('details').$type<UserDetails>().notNull(),
1108
+ * });
1109
+ * ```
1110
+ */
1111
+ $type() {
1112
+ return this;
1113
+ }
1114
+ /**
1115
+ * Adds a `not null` clause to the column definition.
1116
+ *
1117
+ * Affects the `select` model of the table - columns *without* `not null` will be nullable on select.
1118
+ */
1119
+ notNull() {
1120
+ this.config.notNull = true;
1121
+ return this;
1122
+ }
1123
+ /**
1124
+ * Adds a `default <value>` clause to the column definition.
1125
+ *
1126
+ * Affects the `insert` model of the table - columns *with* `default` are optional on insert.
1127
+ *
1128
+ * If you need to set a dynamic default value, use {@link $defaultFn} instead.
1129
+ */
1130
+ default(value) {
1131
+ this.config.default = value;
1132
+ this.config.hasDefault = true;
1133
+ return this;
1134
+ }
1135
+ /**
1136
+ * Adds a dynamic default value to the column.
1137
+ * The function will be called when the row is inserted, and the returned value will be used as the column value.
1138
+ *
1139
+ * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
1140
+ */
1141
+ $defaultFn(fn) {
1142
+ this.config.defaultFn = fn;
1143
+ this.config.hasDefault = true;
1144
+ return this;
1145
+ }
1146
+ /**
1147
+ * Alias for {@link $defaultFn}.
1148
+ */
1149
+ $default = this.$defaultFn;
1150
+ /**
1151
+ * Adds a dynamic update value to the column.
1152
+ * 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.
1153
+ * 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.
1154
+ *
1155
+ * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
1156
+ */
1157
+ $onUpdateFn(fn) {
1158
+ this.config.onUpdateFn = fn;
1159
+ this.config.hasDefault = true;
1160
+ return this;
1161
+ }
1162
+ /**
1163
+ * Alias for {@link $onUpdateFn}.
1164
+ */
1165
+ $onUpdate = this.$onUpdateFn;
1166
+ /**
1167
+ * Adds a `primary key` clause to the column definition. This implicitly makes the column `not null`.
1168
+ *
1169
+ * In SQLite, `integer primary key` implicitly makes the column auto-incrementing.
1170
+ */
1171
+ primaryKey() {
1172
+ this.config.primaryKey = true;
1173
+ this.config.notNull = true;
1174
+ return this;
1175
+ }
1176
+ /** @internal Sets the name of the column to the key within the table definition if a name was not given. */
1177
+ setName(name) {
1178
+ if (this.config.name !== "") return;
1179
+ this.config.name = name;
1180
+ }
1181
+ };
1182
+
1183
+ // ../../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
1184
+ var TableName = /* @__PURE__ */ Symbol.for("drizzle:Name");
1185
+
1186
+ // ../../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
1187
+ var ForeignKeyBuilder = class {
1188
+ static [entityKind] = "PgForeignKeyBuilder";
1189
+ /** @internal */
1190
+ reference;
1191
+ /** @internal */
1192
+ _onUpdate = "no action";
1193
+ /** @internal */
1194
+ _onDelete = "no action";
1195
+ constructor(config, actions) {
1196
+ this.reference = () => {
1197
+ const { name, columns, foreignColumns } = config();
1198
+ return { name, columns, foreignTable: foreignColumns[0].table, foreignColumns };
1199
+ };
1200
+ if (actions) {
1201
+ this._onUpdate = actions.onUpdate;
1202
+ this._onDelete = actions.onDelete;
1203
+ }
1204
+ }
1205
+ onUpdate(action) {
1206
+ this._onUpdate = action === void 0 ? "no action" : action;
1207
+ return this;
1208
+ }
1209
+ onDelete(action) {
1210
+ this._onDelete = action === void 0 ? "no action" : action;
1211
+ return this;
1212
+ }
1213
+ /** @internal */
1214
+ build(table) {
1215
+ return new ForeignKey(table, this);
1216
+ }
1217
+ };
1218
+ var ForeignKey = class {
1219
+ constructor(table, builder) {
1220
+ this.table = table;
1221
+ this.reference = builder.reference;
1222
+ this.onUpdate = builder._onUpdate;
1223
+ this.onDelete = builder._onDelete;
1224
+ }
1225
+ static [entityKind] = "PgForeignKey";
1226
+ reference;
1227
+ onUpdate;
1228
+ onDelete;
1229
+ getName() {
1230
+ const { name, columns, foreignColumns } = this.reference();
1231
+ const columnNames = columns.map((column) => column.name);
1232
+ const foreignColumnNames = foreignColumns.map((column) => column.name);
1233
+ const chunks = [
1234
+ this.table[TableName],
1235
+ ...columnNames,
1236
+ foreignColumns[0].table[TableName],
1237
+ ...foreignColumnNames
1238
+ ];
1239
+ return name ?? `${chunks.join("_")}_fk`;
1240
+ }
1241
+ };
1242
+
1243
+ // ../../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
1244
+ function iife(fn, ...args) {
1245
+ return fn(...args);
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/unique-constraint.js
1249
+ function uniqueKeyName(table, columns) {
1250
+ return `${table[TableName]}_${columns.join("_")}_unique`;
1251
+ }
1252
+ var UniqueConstraintBuilder = class {
1253
+ constructor(columns, name) {
1254
+ this.name = name;
1255
+ this.columns = columns;
1256
+ }
1257
+ static [entityKind] = "PgUniqueConstraintBuilder";
1258
+ /** @internal */
1259
+ columns;
1260
+ /** @internal */
1261
+ nullsNotDistinctConfig = false;
1262
+ nullsNotDistinct() {
1263
+ this.nullsNotDistinctConfig = true;
1264
+ return this;
1265
+ }
1266
+ /** @internal */
1267
+ build(table) {
1268
+ return new UniqueConstraint(table, this.columns, this.nullsNotDistinctConfig, this.name);
1269
+ }
1270
+ };
1271
+ var UniqueOnConstraintBuilder = class {
1272
+ static [entityKind] = "PgUniqueOnConstraintBuilder";
1273
+ /** @internal */
1274
+ name;
1275
+ constructor(name) {
1276
+ this.name = name;
1277
+ }
1278
+ on(...columns) {
1279
+ return new UniqueConstraintBuilder(columns, this.name);
1280
+ }
1281
+ };
1282
+ var UniqueConstraint = class {
1283
+ constructor(table, columns, nullsNotDistinct, name) {
1284
+ this.table = table;
1285
+ this.columns = columns;
1286
+ this.name = name ?? uniqueKeyName(this.table, this.columns.map((column) => column.name));
1287
+ this.nullsNotDistinct = nullsNotDistinct;
1288
+ }
1289
+ static [entityKind] = "PgUniqueConstraint";
1290
+ columns;
1291
+ name;
1292
+ nullsNotDistinct = false;
1293
+ getName() {
1294
+ return this.name;
1295
+ }
1296
+ };
1297
+
1298
+ // ../../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
1299
+ function parsePgArrayValue(arrayString, startFrom, inQuotes) {
1300
+ for (let i = startFrom; i < arrayString.length; i++) {
1301
+ const char = arrayString[i];
1302
+ if (char === "\\") {
1303
+ i++;
1304
+ continue;
1305
+ }
1306
+ if (char === '"') {
1307
+ return [arrayString.slice(startFrom, i).replace(/\\/g, ""), i + 1];
1308
+ }
1309
+ if (inQuotes) {
1310
+ continue;
1311
+ }
1312
+ if (char === "," || char === "}") {
1313
+ return [arrayString.slice(startFrom, i).replace(/\\/g, ""), i];
1314
+ }
1315
+ }
1316
+ return [arrayString.slice(startFrom).replace(/\\/g, ""), arrayString.length];
1317
+ }
1318
+ function parsePgNestedArray(arrayString, startFrom = 0) {
1319
+ const result = [];
1320
+ let i = startFrom;
1321
+ let lastCharIsComma = false;
1322
+ while (i < arrayString.length) {
1323
+ const char = arrayString[i];
1324
+ if (char === ",") {
1325
+ if (lastCharIsComma || i === startFrom) {
1326
+ result.push("");
1327
+ }
1328
+ lastCharIsComma = true;
1329
+ i++;
1330
+ continue;
1331
+ }
1332
+ lastCharIsComma = false;
1333
+ if (char === "\\") {
1334
+ i += 2;
1335
+ continue;
1336
+ }
1337
+ if (char === '"') {
1338
+ const [value2, startFrom2] = parsePgArrayValue(arrayString, i + 1, true);
1339
+ result.push(value2);
1340
+ i = startFrom2;
1341
+ continue;
1342
+ }
1343
+ if (char === "}") {
1344
+ return [result, i + 1];
1345
+ }
1346
+ if (char === "{") {
1347
+ const [value2, startFrom2] = parsePgNestedArray(arrayString, i + 1);
1348
+ result.push(value2);
1349
+ i = startFrom2;
1350
+ continue;
1351
+ }
1352
+ const [value, newStartFrom] = parsePgArrayValue(arrayString, i, false);
1353
+ result.push(value);
1354
+ i = newStartFrom;
1355
+ }
1356
+ return [result, i];
1357
+ }
1358
+ function parsePgArray(arrayString) {
1359
+ const [result] = parsePgNestedArray(arrayString, 1);
1360
+ return result;
1361
+ }
1362
+ function makePgArray(array) {
1363
+ return `{${array.map((item) => {
1364
+ if (Array.isArray(item)) {
1365
+ return makePgArray(item);
1366
+ }
1367
+ if (typeof item === "string") {
1368
+ return `"${item.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
1369
+ }
1370
+ return `${item}`;
1371
+ }).join(",")}}`;
1372
+ }
1373
+
1374
+ // ../../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
1375
+ var PgColumnBuilder = class extends ColumnBuilder {
1376
+ foreignKeyConfigs = [];
1377
+ static [entityKind] = "PgColumnBuilder";
1378
+ array(size) {
1379
+ return new PgArrayBuilder(this.config.name, this, size);
1380
+ }
1381
+ references(ref, actions = {}) {
1382
+ this.foreignKeyConfigs.push({ ref, actions });
1383
+ return this;
1384
+ }
1385
+ unique(name, config) {
1386
+ this.config.isUnique = true;
1387
+ this.config.uniqueName = name;
1388
+ this.config.uniqueType = config?.nulls;
1389
+ return this;
1390
+ }
1391
+ generatedAlwaysAs(as) {
1392
+ this.config.generated = {
1393
+ as,
1394
+ type: "always",
1395
+ mode: "stored"
1396
+ };
1397
+ return this;
1398
+ }
1399
+ /** @internal */
1400
+ buildForeignKeys(column, table) {
1401
+ return this.foreignKeyConfigs.map(({ ref, actions }) => {
1402
+ return iife(
1403
+ (ref2, actions2) => {
1404
+ const builder = new ForeignKeyBuilder(() => {
1405
+ const foreignColumn = ref2();
1406
+ return { columns: [column], foreignColumns: [foreignColumn] };
1407
+ });
1408
+ if (actions2.onUpdate) {
1409
+ builder.onUpdate(actions2.onUpdate);
1410
+ }
1411
+ if (actions2.onDelete) {
1412
+ builder.onDelete(actions2.onDelete);
1413
+ }
1414
+ return builder.build(table);
1415
+ },
1416
+ ref,
1417
+ actions
1418
+ );
1419
+ });
1420
+ }
1421
+ /** @internal */
1422
+ buildExtraConfigColumn(table) {
1423
+ return new ExtraConfigColumn(table, this.config);
1424
+ }
1425
+ };
1426
+ var PgColumn = class extends Column {
1427
+ constructor(table, config) {
1428
+ if (!config.uniqueName) {
1429
+ config.uniqueName = uniqueKeyName(table, [config.name]);
1430
+ }
1431
+ super(table, config);
1432
+ this.table = table;
1433
+ }
1434
+ static [entityKind] = "PgColumn";
1435
+ };
1436
+ var ExtraConfigColumn = class extends PgColumn {
1437
+ static [entityKind] = "ExtraConfigColumn";
1438
+ getSQLType() {
1439
+ return this.getSQLType();
1440
+ }
1441
+ indexConfig = {
1442
+ order: this.config.order ?? "asc",
1443
+ nulls: this.config.nulls ?? "last",
1444
+ opClass: this.config.opClass
1445
+ };
1446
+ defaultConfig = {
1447
+ order: "asc",
1448
+ nulls: "last",
1449
+ opClass: void 0
1450
+ };
1451
+ asc() {
1452
+ this.indexConfig.order = "asc";
1453
+ return this;
1454
+ }
1455
+ desc() {
1456
+ this.indexConfig.order = "desc";
1457
+ return this;
1458
+ }
1459
+ nullsFirst() {
1460
+ this.indexConfig.nulls = "first";
1461
+ return this;
1462
+ }
1463
+ nullsLast() {
1464
+ this.indexConfig.nulls = "last";
1465
+ return this;
1466
+ }
1467
+ /**
1468
+ * ### PostgreSQL documentation quote
1469
+ *
1470
+ * > An operator class with optional parameters can be specified for each column of an index.
1471
+ * The operator class identifies the operators to be used by the index for that column.
1472
+ * For example, a B-tree index on four-byte integers would use the int4_ops class;
1473
+ * this operator class includes comparison functions for four-byte integers.
1474
+ * In practice the default operator class for the column's data type is usually sufficient.
1475
+ * The main point of having operator classes is that for some data types, there could be more than one meaningful ordering.
1476
+ * For example, we might want to sort a complex-number data type either by absolute value or by real part.
1477
+ * We could do this by defining two operator classes for the data type and then selecting the proper class when creating an index.
1478
+ * More information about operator classes check:
1479
+ *
1480
+ * ### Useful links
1481
+ * https://www.postgresql.org/docs/current/sql-createindex.html
1482
+ *
1483
+ * https://www.postgresql.org/docs/current/indexes-opclass.html
1484
+ *
1485
+ * https://www.postgresql.org/docs/current/xindex.html
1486
+ *
1487
+ * ### Additional types
1488
+ * If you have the `pg_vector` extension installed in your database, you can use the
1489
+ * `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.
1490
+ *
1491
+ * **You can always specify any string you want in the operator class, in case Drizzle doesn't have it natively in its types**
1492
+ *
1493
+ * @param opClass
1494
+ * @returns
1495
+ */
1496
+ op(opClass) {
1497
+ this.indexConfig.opClass = opClass;
1498
+ return this;
1499
+ }
1500
+ };
1501
+ var IndexedColumn = class {
1502
+ static [entityKind] = "IndexedColumn";
1503
+ constructor(name, keyAsName, type, indexConfig) {
1504
+ this.name = name;
1505
+ this.keyAsName = keyAsName;
1506
+ this.type = type;
1507
+ this.indexConfig = indexConfig;
1508
+ }
1509
+ name;
1510
+ keyAsName;
1511
+ type;
1512
+ indexConfig;
1513
+ };
1514
+ var PgArrayBuilder = class extends PgColumnBuilder {
1515
+ static [entityKind] = "PgArrayBuilder";
1516
+ constructor(name, baseBuilder, size) {
1517
+ super(name, "array", "PgArray");
1518
+ this.config.baseBuilder = baseBuilder;
1519
+ this.config.size = size;
1520
+ }
1521
+ /** @internal */
1522
+ build(table) {
1523
+ const baseColumn = this.config.baseBuilder.build(table);
1524
+ return new PgArray(
1525
+ table,
1526
+ this.config,
1527
+ baseColumn
1528
+ );
1529
+ }
1530
+ };
1531
+ var PgArray = class _PgArray extends PgColumn {
1532
+ constructor(table, config, baseColumn, range) {
1533
+ super(table, config);
1534
+ this.baseColumn = baseColumn;
1535
+ this.range = range;
1536
+ this.size = config.size;
1537
+ }
1538
+ size;
1539
+ static [entityKind] = "PgArray";
1540
+ getSQLType() {
1541
+ return `${this.baseColumn.getSQLType()}[${typeof this.size === "number" ? this.size : ""}]`;
1542
+ }
1543
+ mapFromDriverValue(value) {
1544
+ if (typeof value === "string") {
1545
+ value = parsePgArray(value);
1546
+ }
1547
+ return value.map((v) => this.baseColumn.mapFromDriverValue(v));
1548
+ }
1549
+ mapToDriverValue(value, isNestedArray = false) {
1550
+ const a = value.map(
1551
+ (v) => v === null ? null : is(this.baseColumn, _PgArray) ? this.baseColumn.mapToDriverValue(v, true) : this.baseColumn.mapToDriverValue(v)
1552
+ );
1553
+ if (isNestedArray) return a;
1554
+ return makePgArray(a);
1555
+ }
1556
+ };
1557
+
1558
+ // ../../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
1559
+ var PgEnumObjectColumnBuilder = class extends PgColumnBuilder {
1560
+ static [entityKind] = "PgEnumObjectColumnBuilder";
1561
+ constructor(name, enumInstance) {
1562
+ super(name, "string", "PgEnumObjectColumn");
1563
+ this.config.enum = enumInstance;
1564
+ }
1565
+ /** @internal */
1566
+ build(table) {
1567
+ return new PgEnumObjectColumn(
1568
+ table,
1569
+ this.config
1570
+ );
1571
+ }
1572
+ };
1573
+ var PgEnumObjectColumn = class extends PgColumn {
1574
+ static [entityKind] = "PgEnumObjectColumn";
1575
+ enum;
1576
+ enumValues = this.config.enum.enumValues;
1577
+ constructor(table, config) {
1578
+ super(table, config);
1579
+ this.enum = config.enum;
1580
+ }
1581
+ getSQLType() {
1582
+ return this.enum.enumName;
1583
+ }
1584
+ };
1585
+ var isPgEnumSym = /* @__PURE__ */ Symbol.for("drizzle:isPgEnum");
1586
+ function isPgEnum(obj) {
1587
+ return !!obj && typeof obj === "function" && isPgEnumSym in obj && obj[isPgEnumSym] === true;
1588
+ }
1589
+ var PgEnumColumnBuilder = class extends PgColumnBuilder {
1590
+ static [entityKind] = "PgEnumColumnBuilder";
1591
+ constructor(name, enumInstance) {
1592
+ super(name, "string", "PgEnumColumn");
1593
+ this.config.enum = enumInstance;
1594
+ }
1595
+ /** @internal */
1596
+ build(table) {
1597
+ return new PgEnumColumn(
1598
+ table,
1599
+ this.config
1600
+ );
1601
+ }
1602
+ };
1603
+ var PgEnumColumn = class extends PgColumn {
1604
+ static [entityKind] = "PgEnumColumn";
1605
+ enum = this.config.enum;
1606
+ enumValues = this.config.enum.enumValues;
1607
+ constructor(table, config) {
1608
+ super(table, config);
1609
+ this.enum = config.enum;
1610
+ }
1611
+ getSQLType() {
1612
+ return this.enum.enumName;
1613
+ }
1614
+ };
1615
+
1616
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/subquery.js
1617
+ var Subquery = class {
1618
+ static [entityKind] = "Subquery";
1619
+ constructor(sql2, fields, alias, isWith = false, usedTables = []) {
1620
+ this._ = {
1621
+ brand: "Subquery",
1622
+ sql: sql2,
1623
+ selectedFields: fields,
1624
+ alias,
1625
+ isWith,
1626
+ usedTables
1627
+ };
1628
+ }
1629
+ // getSQL(): SQL<unknown> {
1630
+ // return new SQL([this]);
1631
+ // }
1632
+ };
1633
+ var WithSubquery = class extends Subquery {
1634
+ static [entityKind] = "WithSubquery";
1635
+ };
1636
+
1637
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/version.js
1638
+ var version = "0.45.2";
1639
+
1640
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/tracing.js
1641
+ var otel;
1642
+ var rawTracer;
1643
+ var tracer = {
1644
+ startActiveSpan(name, fn) {
1645
+ if (!otel) {
1646
+ return fn();
1647
+ }
1648
+ if (!rawTracer) {
1649
+ rawTracer = otel.trace.getTracer("drizzle-orm", version);
1650
+ }
1651
+ return iife(
1652
+ (otel2, rawTracer2) => rawTracer2.startActiveSpan(
1653
+ name,
1654
+ (span) => {
1655
+ try {
1656
+ return fn(span);
1657
+ } catch (e) {
1658
+ span.setStatus({
1659
+ code: otel2.SpanStatusCode.ERROR,
1660
+ message: e instanceof Error ? e.message : "Unknown error"
1661
+ // eslint-disable-line no-instanceof/no-instanceof
1662
+ });
1663
+ throw e;
1664
+ } finally {
1665
+ span.end();
1666
+ }
1667
+ }
1668
+ ),
1669
+ otel,
1670
+ rawTracer
1671
+ );
1672
+ }
1673
+ };
1674
+
1675
+ // ../../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
1676
+ var ViewBaseConfig = /* @__PURE__ */ Symbol.for("drizzle:ViewBaseConfig");
1677
+
1678
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/table.js
1679
+ var Schema = /* @__PURE__ */ Symbol.for("drizzle:Schema");
1680
+ var Columns = /* @__PURE__ */ Symbol.for("drizzle:Columns");
1681
+ var ExtraConfigColumns = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigColumns");
1682
+ var OriginalName = /* @__PURE__ */ Symbol.for("drizzle:OriginalName");
1683
+ var BaseName = /* @__PURE__ */ Symbol.for("drizzle:BaseName");
1684
+ var IsAlias = /* @__PURE__ */ Symbol.for("drizzle:IsAlias");
1685
+ var ExtraConfigBuilder = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigBuilder");
1686
+ var IsDrizzleTable = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleTable");
1687
+ var Table = class {
1688
+ static [entityKind] = "Table";
1689
+ /** @internal */
1690
+ static Symbol = {
1691
+ Name: TableName,
1692
+ Schema,
1693
+ OriginalName,
1694
+ Columns,
1695
+ ExtraConfigColumns,
1696
+ BaseName,
1697
+ IsAlias,
1698
+ ExtraConfigBuilder
1699
+ };
1700
+ /**
1701
+ * @internal
1702
+ * Can be changed if the table is aliased.
1703
+ */
1704
+ [TableName];
1705
+ /**
1706
+ * @internal
1707
+ * Used to store the original name of the table, before any aliasing.
1708
+ */
1709
+ [OriginalName];
1710
+ /** @internal */
1711
+ [Schema];
1712
+ /** @internal */
1713
+ [Columns];
1714
+ /** @internal */
1715
+ [ExtraConfigColumns];
1716
+ /**
1717
+ * @internal
1718
+ * Used to store the table name before the transformation via the `tableCreator` functions.
1719
+ */
1720
+ [BaseName];
1721
+ /** @internal */
1722
+ [IsAlias] = false;
1723
+ /** @internal */
1724
+ [IsDrizzleTable] = true;
1725
+ /** @internal */
1726
+ [ExtraConfigBuilder] = void 0;
1727
+ constructor(name, schema, baseName) {
1728
+ this[TableName] = this[OriginalName] = name;
1729
+ this[Schema] = schema;
1730
+ this[BaseName] = baseName;
1731
+ }
1732
+ };
1733
+
1734
+ // ../../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
1735
+ var FakePrimitiveParam = class {
1736
+ static [entityKind] = "FakePrimitiveParam";
1737
+ };
1738
+ function isSQLWrapper(value) {
1739
+ return value !== null && value !== void 0 && typeof value.getSQL === "function";
1740
+ }
1741
+ function mergeQueries(queries) {
1742
+ const result = { sql: "", params: [] };
1743
+ for (const query of queries) {
1744
+ result.sql += query.sql;
1745
+ result.params.push(...query.params);
1746
+ if (query.typings?.length) {
1747
+ if (!result.typings) {
1748
+ result.typings = [];
1749
+ }
1750
+ result.typings.push(...query.typings);
1751
+ }
1752
+ }
1753
+ return result;
1754
+ }
1755
+ var StringChunk = class {
1756
+ static [entityKind] = "StringChunk";
1757
+ value;
1758
+ constructor(value) {
1759
+ this.value = Array.isArray(value) ? value : [value];
1760
+ }
1761
+ getSQL() {
1762
+ return new SQL([this]);
1763
+ }
1764
+ };
1765
+ var SQL = class _SQL {
1766
+ constructor(queryChunks) {
1767
+ this.queryChunks = queryChunks;
1768
+ for (const chunk of queryChunks) {
1769
+ if (is(chunk, Table)) {
1770
+ const schemaName = chunk[Table.Symbol.Schema];
1771
+ this.usedTables.push(
1772
+ schemaName === void 0 ? chunk[Table.Symbol.Name] : schemaName + "." + chunk[Table.Symbol.Name]
1773
+ );
1774
+ }
1775
+ }
1776
+ }
1777
+ static [entityKind] = "SQL";
1778
+ /** @internal */
1779
+ decoder = noopDecoder;
1780
+ shouldInlineParams = false;
1781
+ /** @internal */
1782
+ usedTables = [];
1783
+ append(query) {
1784
+ this.queryChunks.push(...query.queryChunks);
1785
+ return this;
1786
+ }
1787
+ toQuery(config) {
1788
+ return tracer.startActiveSpan("drizzle.buildSQL", (span) => {
1789
+ const query = this.buildQueryFromSourceParams(this.queryChunks, config);
1790
+ span?.setAttributes({
1791
+ "drizzle.query.text": query.sql,
1792
+ "drizzle.query.params": JSON.stringify(query.params)
1793
+ });
1794
+ return query;
1795
+ });
1796
+ }
1797
+ buildQueryFromSourceParams(chunks, _config) {
1798
+ const config = Object.assign({}, _config, {
1799
+ inlineParams: _config.inlineParams || this.shouldInlineParams,
1800
+ paramStartIndex: _config.paramStartIndex || { value: 0 }
1801
+ });
1802
+ const {
1803
+ casing,
1804
+ escapeName,
1805
+ escapeParam,
1806
+ prepareTyping,
1807
+ inlineParams,
1808
+ paramStartIndex
1809
+ } = config;
1810
+ return mergeQueries(chunks.map((chunk) => {
1811
+ if (is(chunk, StringChunk)) {
1812
+ return { sql: chunk.value.join(""), params: [] };
1813
+ }
1814
+ if (is(chunk, Name)) {
1815
+ return { sql: escapeName(chunk.value), params: [] };
1816
+ }
1817
+ if (chunk === void 0) {
1818
+ return { sql: "", params: [] };
1819
+ }
1820
+ if (Array.isArray(chunk)) {
1821
+ const result = [new StringChunk("(")];
1822
+ for (const [i, p] of chunk.entries()) {
1823
+ result.push(p);
1824
+ if (i < chunk.length - 1) {
1825
+ result.push(new StringChunk(", "));
1826
+ }
1827
+ }
1828
+ result.push(new StringChunk(")"));
1829
+ return this.buildQueryFromSourceParams(result, config);
1830
+ }
1831
+ if (is(chunk, _SQL)) {
1832
+ return this.buildQueryFromSourceParams(chunk.queryChunks, {
1833
+ ...config,
1834
+ inlineParams: inlineParams || chunk.shouldInlineParams
1835
+ });
1836
+ }
1837
+ if (is(chunk, Table)) {
1838
+ const schemaName = chunk[Table.Symbol.Schema];
1839
+ const tableName = chunk[Table.Symbol.Name];
1840
+ return {
1841
+ sql: schemaName === void 0 || chunk[IsAlias] ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
1842
+ params: []
1843
+ };
1844
+ }
1845
+ if (is(chunk, Column)) {
1846
+ const columnName = casing.getColumnCasing(chunk);
1847
+ if (_config.invokeSource === "indexes") {
1848
+ return { sql: escapeName(columnName), params: [] };
1849
+ }
1850
+ const schemaName = chunk.table[Table.Symbol.Schema];
1851
+ return {
1852
+ 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),
1853
+ params: []
1854
+ };
1855
+ }
1856
+ if (is(chunk, View)) {
1857
+ const schemaName = chunk[ViewBaseConfig].schema;
1858
+ const viewName = chunk[ViewBaseConfig].name;
1859
+ return {
1860
+ sql: schemaName === void 0 || chunk[ViewBaseConfig].isAlias ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
1861
+ params: []
1862
+ };
1863
+ }
1864
+ if (is(chunk, Param)) {
1865
+ if (is(chunk.value, Placeholder)) {
1866
+ return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
1867
+ }
1868
+ const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
1869
+ if (is(mappedValue, _SQL)) {
1870
+ return this.buildQueryFromSourceParams([mappedValue], config);
1871
+ }
1872
+ if (inlineParams) {
1873
+ return { sql: this.mapInlineParam(mappedValue, config), params: [] };
1874
+ }
1875
+ let typings = ["none"];
1876
+ if (prepareTyping) {
1877
+ typings = [prepareTyping(chunk.encoder)];
1878
+ }
1879
+ return { sql: escapeParam(paramStartIndex.value++, mappedValue), params: [mappedValue], typings };
1880
+ }
1881
+ if (is(chunk, Placeholder)) {
1882
+ return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
1883
+ }
1884
+ if (is(chunk, _SQL.Aliased) && chunk.fieldAlias !== void 0) {
1885
+ return { sql: escapeName(chunk.fieldAlias), params: [] };
1886
+ }
1887
+ if (is(chunk, Subquery)) {
1888
+ if (chunk._.isWith) {
1889
+ return { sql: escapeName(chunk._.alias), params: [] };
1890
+ }
1891
+ return this.buildQueryFromSourceParams([
1892
+ new StringChunk("("),
1893
+ chunk._.sql,
1894
+ new StringChunk(") "),
1895
+ new Name(chunk._.alias)
1896
+ ], config);
1897
+ }
1898
+ if (isPgEnum(chunk)) {
1899
+ if (chunk.schema) {
1900
+ return { sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName), params: [] };
1901
+ }
1902
+ return { sql: escapeName(chunk.enumName), params: [] };
1903
+ }
1904
+ if (isSQLWrapper(chunk)) {
1905
+ if (chunk.shouldOmitSQLParens?.()) {
1906
+ return this.buildQueryFromSourceParams([chunk.getSQL()], config);
1907
+ }
1908
+ return this.buildQueryFromSourceParams([
1909
+ new StringChunk("("),
1910
+ chunk.getSQL(),
1911
+ new StringChunk(")")
1912
+ ], config);
1913
+ }
1914
+ if (inlineParams) {
1915
+ return { sql: this.mapInlineParam(chunk, config), params: [] };
1916
+ }
1917
+ return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
1918
+ }));
1919
+ }
1920
+ mapInlineParam(chunk, { escapeString }) {
1921
+ if (chunk === null) {
1922
+ return "null";
1923
+ }
1924
+ if (typeof chunk === "number" || typeof chunk === "boolean") {
1925
+ return chunk.toString();
1926
+ }
1927
+ if (typeof chunk === "string") {
1928
+ return escapeString(chunk);
1929
+ }
1930
+ if (typeof chunk === "object") {
1931
+ const mappedValueAsString = chunk.toString();
1932
+ if (mappedValueAsString === "[object Object]") {
1933
+ return escapeString(JSON.stringify(chunk));
1934
+ }
1935
+ return escapeString(mappedValueAsString);
1936
+ }
1937
+ throw new Error("Unexpected param value: " + chunk);
1938
+ }
1939
+ getSQL() {
1940
+ return this;
1941
+ }
1942
+ as(alias) {
1943
+ if (alias === void 0) {
1944
+ return this;
1945
+ }
1946
+ return new _SQL.Aliased(this, alias);
1947
+ }
1948
+ mapWith(decoder) {
1949
+ this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
1950
+ return this;
1951
+ }
1952
+ inlineParams() {
1953
+ this.shouldInlineParams = true;
1954
+ return this;
1955
+ }
1956
+ /**
1957
+ * This method is used to conditionally include a part of the query.
1958
+ *
1959
+ * @param condition - Condition to check
1960
+ * @returns itself if the condition is `true`, otherwise `undefined`
1961
+ */
1962
+ if(condition) {
1963
+ return condition ? this : void 0;
1964
+ }
1965
+ };
1966
+ var Name = class {
1967
+ constructor(value) {
1968
+ this.value = value;
1969
+ }
1970
+ static [entityKind] = "Name";
1971
+ brand;
1972
+ getSQL() {
1973
+ return new SQL([this]);
1974
+ }
1975
+ };
1976
+ var noopDecoder = {
1977
+ mapFromDriverValue: (value) => value
1978
+ };
1979
+ var noopEncoder = {
1980
+ mapToDriverValue: (value) => value
1981
+ };
1982
+ var noopMapper = {
1983
+ ...noopDecoder,
1984
+ ...noopEncoder
1985
+ };
1986
+ var Param = class {
1987
+ /**
1988
+ * @param value - Parameter value
1989
+ * @param encoder - Encoder to convert the value to a driver parameter
1990
+ */
1991
+ constructor(value, encoder = noopEncoder) {
1992
+ this.value = value;
1993
+ this.encoder = encoder;
1994
+ }
1995
+ static [entityKind] = "Param";
1996
+ brand;
1997
+ getSQL() {
1998
+ return new SQL([this]);
1999
+ }
2000
+ };
2001
+ function sql(strings, ...params) {
2002
+ const queryChunks = [];
2003
+ if (params.length > 0 || strings.length > 0 && strings[0] !== "") {
2004
+ queryChunks.push(new StringChunk(strings[0]));
2005
+ }
2006
+ for (const [paramIndex, param2] of params.entries()) {
2007
+ queryChunks.push(param2, new StringChunk(strings[paramIndex + 1]));
2008
+ }
2009
+ return new SQL(queryChunks);
2010
+ }
2011
+ ((sql2) => {
2012
+ function empty() {
2013
+ return new SQL([]);
2014
+ }
2015
+ sql2.empty = empty;
2016
+ function fromList(list) {
2017
+ return new SQL(list);
2018
+ }
2019
+ sql2.fromList = fromList;
2020
+ function raw(str) {
2021
+ return new SQL([new StringChunk(str)]);
2022
+ }
2023
+ sql2.raw = raw;
2024
+ function join3(chunks, separator) {
2025
+ const result = [];
2026
+ for (const [i, chunk] of chunks.entries()) {
2027
+ if (i > 0 && separator !== void 0) {
2028
+ result.push(separator);
2029
+ }
2030
+ result.push(chunk);
2031
+ }
2032
+ return new SQL(result);
2033
+ }
2034
+ sql2.join = join3;
2035
+ function identifier(value) {
2036
+ return new Name(value);
2037
+ }
2038
+ sql2.identifier = identifier;
2039
+ function placeholder2(name2) {
2040
+ return new Placeholder(name2);
2041
+ }
2042
+ sql2.placeholder = placeholder2;
2043
+ function param2(value, encoder) {
2044
+ return new Param(value, encoder);
2045
+ }
2046
+ sql2.param = param2;
2047
+ })(sql || (sql = {}));
2048
+ ((SQL2) => {
2049
+ class Aliased {
2050
+ constructor(sql2, fieldAlias) {
2051
+ this.sql = sql2;
2052
+ this.fieldAlias = fieldAlias;
2053
+ }
2054
+ static [entityKind] = "SQL.Aliased";
2055
+ /** @internal */
2056
+ isSelectionField = false;
2057
+ getSQL() {
2058
+ return this.sql;
2059
+ }
2060
+ /** @internal */
2061
+ clone() {
2062
+ return new Aliased(this.sql, this.fieldAlias);
2063
+ }
2064
+ }
2065
+ SQL2.Aliased = Aliased;
2066
+ })(SQL || (SQL = {}));
2067
+ var Placeholder = class {
2068
+ constructor(name2) {
2069
+ this.name = name2;
2070
+ }
2071
+ static [entityKind] = "Placeholder";
2072
+ getSQL() {
2073
+ return new SQL([this]);
2074
+ }
2075
+ };
2076
+ var IsDrizzleView = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleView");
2077
+ var View = class {
2078
+ static [entityKind] = "View";
2079
+ /** @internal */
2080
+ [ViewBaseConfig];
2081
+ /** @internal */
2082
+ [IsDrizzleView] = true;
2083
+ constructor({ name: name2, schema, selectedFields, query }) {
2084
+ this[ViewBaseConfig] = {
2085
+ name: name2,
2086
+ originalName: name2,
2087
+ schema,
2088
+ selectedFields,
2089
+ query,
2090
+ isExisting: !query,
2091
+ isAlias: false
2092
+ };
2093
+ }
2094
+ getSQL() {
2095
+ return new SQL([this]);
2096
+ }
2097
+ };
2098
+ Column.prototype.getSQL = function() {
2099
+ return new SQL([this]);
2100
+ };
2101
+ Table.prototype.getSQL = function() {
2102
+ return new SQL([this]);
2103
+ };
2104
+ Subquery.prototype.getSQL = function() {
2105
+ return new SQL([this]);
2106
+ };
2107
+
2108
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20261014.1_kysely@0.29.6/node_modules/drizzle-orm/utils.js
2109
+ function getColumnNameAndConfig(a, b) {
2110
+ return {
2111
+ name: typeof a === "string" && a.length > 0 ? a : "",
2112
+ config: typeof a === "object" ? a : b
2113
+ };
2114
+ }
2115
+ var textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder();
2116
+
2117
+ // ../../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
2118
+ var ForeignKeyBuilder2 = class {
2119
+ static [entityKind] = "SQLiteForeignKeyBuilder";
2120
+ /** @internal */
2121
+ reference;
2122
+ /** @internal */
2123
+ _onUpdate;
2124
+ /** @internal */
2125
+ _onDelete;
2126
+ constructor(config, actions) {
2127
+ this.reference = () => {
2128
+ const { name, columns, foreignColumns } = config();
2129
+ return { name, columns, foreignTable: foreignColumns[0].table, foreignColumns };
2130
+ };
2131
+ if (actions) {
2132
+ this._onUpdate = actions.onUpdate;
2133
+ this._onDelete = actions.onDelete;
2134
+ }
2135
+ }
2136
+ onUpdate(action) {
2137
+ this._onUpdate = action;
2138
+ return this;
2139
+ }
2140
+ onDelete(action) {
2141
+ this._onDelete = action;
2142
+ return this;
2143
+ }
2144
+ /** @internal */
2145
+ build(table) {
2146
+ return new ForeignKey2(table, this);
2147
+ }
2148
+ };
2149
+ var ForeignKey2 = class {
2150
+ constructor(table, builder) {
2151
+ this.table = table;
2152
+ this.reference = builder.reference;
2153
+ this.onUpdate = builder._onUpdate;
2154
+ this.onDelete = builder._onDelete;
2155
+ }
2156
+ static [entityKind] = "SQLiteForeignKey";
2157
+ reference;
2158
+ onUpdate;
2159
+ onDelete;
2160
+ getName() {
2161
+ const { name, columns, foreignColumns } = this.reference();
2162
+ const columnNames = columns.map((column) => column.name);
2163
+ const foreignColumnNames = foreignColumns.map((column) => column.name);
2164
+ const chunks = [
2165
+ this.table[TableName],
2166
+ ...columnNames,
2167
+ foreignColumns[0].table[TableName],
2168
+ ...foreignColumnNames
2169
+ ];
2170
+ return name ?? `${chunks.join("_")}_fk`;
2171
+ }
2172
+ };
2173
+
2174
+ // ../../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
2175
+ function uniqueKeyName2(table, columns) {
2176
+ return `${table[TableName]}_${columns.join("_")}_unique`;
2177
+ }
2178
+ var UniqueConstraintBuilder2 = class {
2179
+ constructor(columns, name) {
2180
+ this.name = name;
2181
+ this.columns = columns;
2182
+ }
2183
+ static [entityKind] = "SQLiteUniqueConstraintBuilder";
2184
+ /** @internal */
2185
+ columns;
2186
+ /** @internal */
2187
+ build(table) {
2188
+ return new UniqueConstraint2(table, this.columns, this.name);
2189
+ }
2190
+ };
2191
+ var UniqueOnConstraintBuilder2 = class {
2192
+ static [entityKind] = "SQLiteUniqueOnConstraintBuilder";
2193
+ /** @internal */
2194
+ name;
2195
+ constructor(name) {
2196
+ this.name = name;
2197
+ }
2198
+ on(...columns) {
2199
+ return new UniqueConstraintBuilder2(columns, this.name);
2200
+ }
2201
+ };
2202
+ var UniqueConstraint2 = class {
2203
+ constructor(table, columns, name) {
2204
+ this.table = table;
2205
+ this.columns = columns;
2206
+ this.name = name ?? uniqueKeyName2(this.table, this.columns.map((column) => column.name));
2207
+ }
2208
+ static [entityKind] = "SQLiteUniqueConstraint";
2209
+ columns;
2210
+ name;
2211
+ getName() {
2212
+ return this.name;
2213
+ }
2214
+ };
2215
+
2216
+ // ../../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
2217
+ var SQLiteColumnBuilder = class extends ColumnBuilder {
2218
+ static [entityKind] = "SQLiteColumnBuilder";
2219
+ foreignKeyConfigs = [];
2220
+ references(ref, actions = {}) {
2221
+ this.foreignKeyConfigs.push({ ref, actions });
2222
+ return this;
2223
+ }
2224
+ unique(name) {
2225
+ this.config.isUnique = true;
2226
+ this.config.uniqueName = name;
2227
+ return this;
2228
+ }
2229
+ generatedAlwaysAs(as, config) {
2230
+ this.config.generated = {
2231
+ as,
2232
+ type: "always",
2233
+ mode: config?.mode ?? "virtual"
2234
+ };
2235
+ return this;
2236
+ }
2237
+ /** @internal */
2238
+ buildForeignKeys(column, table) {
2239
+ return this.foreignKeyConfigs.map(({ ref, actions }) => {
2240
+ return ((ref2, actions2) => {
2241
+ const builder = new ForeignKeyBuilder2(() => {
2242
+ const foreignColumn = ref2();
2243
+ return { columns: [column], foreignColumns: [foreignColumn] };
2244
+ });
2245
+ if (actions2.onUpdate) {
2246
+ builder.onUpdate(actions2.onUpdate);
2247
+ }
2248
+ if (actions2.onDelete) {
2249
+ builder.onDelete(actions2.onDelete);
2250
+ }
2251
+ return builder.build(table);
2252
+ })(ref, actions);
2253
+ });
2254
+ }
2255
+ };
2256
+ var SQLiteColumn = class extends Column {
2257
+ constructor(table, config) {
2258
+ if (!config.uniqueName) {
2259
+ config.uniqueName = uniqueKeyName2(table, [config.name]);
2260
+ }
2261
+ super(table, config);
2262
+ this.table = table;
2263
+ }
2264
+ static [entityKind] = "SQLiteColumn";
2265
+ };
2266
+
2267
+ // ../../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
2268
+ var SQLiteBigIntBuilder = class extends SQLiteColumnBuilder {
2269
+ static [entityKind] = "SQLiteBigIntBuilder";
2270
+ constructor(name) {
2271
+ super(name, "bigint", "SQLiteBigInt");
2272
+ }
2273
+ /** @internal */
2274
+ build(table) {
2275
+ return new SQLiteBigInt(table, this.config);
2276
+ }
2277
+ };
2278
+ var SQLiteBigInt = class extends SQLiteColumn {
2279
+ static [entityKind] = "SQLiteBigInt";
2280
+ getSQLType() {
2281
+ return "blob";
2282
+ }
2283
+ mapFromDriverValue(value) {
2284
+ if (typeof Buffer !== "undefined" && Buffer.from) {
2285
+ 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);
2286
+ return BigInt(buf.toString("utf8"));
2287
+ }
2288
+ return BigInt(textDecoder.decode(value));
2289
+ }
2290
+ mapToDriverValue(value) {
2291
+ return Buffer.from(value.toString());
2292
+ }
2293
+ };
2294
+ var SQLiteBlobJsonBuilder = class extends SQLiteColumnBuilder {
2295
+ static [entityKind] = "SQLiteBlobJsonBuilder";
2296
+ constructor(name) {
2297
+ super(name, "json", "SQLiteBlobJson");
2298
+ }
2299
+ /** @internal */
2300
+ build(table) {
2301
+ return new SQLiteBlobJson(
2302
+ table,
2303
+ this.config
2304
+ );
2305
+ }
2306
+ };
2307
+ var SQLiteBlobJson = class extends SQLiteColumn {
2308
+ static [entityKind] = "SQLiteBlobJson";
2309
+ getSQLType() {
2310
+ return "blob";
2311
+ }
2312
+ mapFromDriverValue(value) {
2313
+ if (typeof Buffer !== "undefined" && Buffer.from) {
2314
+ 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);
2315
+ return JSON.parse(buf.toString("utf8"));
2316
+ }
2317
+ return JSON.parse(textDecoder.decode(value));
2318
+ }
2319
+ mapToDriverValue(value) {
2320
+ return Buffer.from(JSON.stringify(value));
2321
+ }
2322
+ };
2323
+ var SQLiteBlobBufferBuilder = class extends SQLiteColumnBuilder {
2324
+ static [entityKind] = "SQLiteBlobBufferBuilder";
2325
+ constructor(name) {
2326
+ super(name, "buffer", "SQLiteBlobBuffer");
2327
+ }
2328
+ /** @internal */
2329
+ build(table) {
2330
+ return new SQLiteBlobBuffer(table, this.config);
2331
+ }
2332
+ };
2333
+ var SQLiteBlobBuffer = class extends SQLiteColumn {
2334
+ static [entityKind] = "SQLiteBlobBuffer";
2335
+ mapFromDriverValue(value) {
2336
+ if (Buffer.isBuffer(value)) {
2337
+ return value;
2338
+ }
2339
+ return Buffer.from(value);
2340
+ }
2341
+ getSQLType() {
2342
+ return "blob";
2343
+ }
2344
+ };
2345
+ function blob(a, b) {
2346
+ const { name, config } = getColumnNameAndConfig(a, b);
2347
+ if (config?.mode === "json") {
2348
+ return new SQLiteBlobJsonBuilder(name);
2349
+ }
2350
+ if (config?.mode === "bigint") {
2351
+ return new SQLiteBigIntBuilder(name);
2352
+ }
2353
+ return new SQLiteBlobBufferBuilder(name);
2354
+ }
2355
+
2356
+ // ../../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
2357
+ var SQLiteCustomColumnBuilder = class extends SQLiteColumnBuilder {
2358
+ static [entityKind] = "SQLiteCustomColumnBuilder";
2359
+ constructor(name, fieldConfig, customTypeParams) {
2360
+ super(name, "custom", "SQLiteCustomColumn");
2361
+ this.config.fieldConfig = fieldConfig;
2362
+ this.config.customTypeParams = customTypeParams;
2363
+ }
2364
+ /** @internal */
2365
+ build(table) {
2366
+ return new SQLiteCustomColumn(
2367
+ table,
2368
+ this.config
2369
+ );
2370
+ }
2371
+ };
2372
+ var SQLiteCustomColumn = class extends SQLiteColumn {
2373
+ static [entityKind] = "SQLiteCustomColumn";
2374
+ sqlName;
2375
+ mapTo;
2376
+ mapFrom;
2377
+ constructor(table, config) {
2378
+ super(table, config);
2379
+ this.sqlName = config.customTypeParams.dataType(config.fieldConfig);
2380
+ this.mapTo = config.customTypeParams.toDriver;
2381
+ this.mapFrom = config.customTypeParams.fromDriver;
2382
+ }
2383
+ getSQLType() {
2384
+ return this.sqlName;
2385
+ }
2386
+ mapFromDriverValue(value) {
2387
+ return typeof this.mapFrom === "function" ? this.mapFrom(value) : value;
2388
+ }
2389
+ mapToDriverValue(value) {
2390
+ return typeof this.mapTo === "function" ? this.mapTo(value) : value;
2391
+ }
2392
+ };
2393
+ function customType(customTypeParams) {
2394
+ return (a, b) => {
2395
+ const { name, config } = getColumnNameAndConfig(a, b);
2396
+ return new SQLiteCustomColumnBuilder(
2397
+ name,
2398
+ config,
2399
+ customTypeParams
2400
+ );
2401
+ };
2402
+ }
2403
+
2404
+ // ../../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
2405
+ var SQLiteBaseIntegerBuilder = class extends SQLiteColumnBuilder {
2406
+ static [entityKind] = "SQLiteBaseIntegerBuilder";
2407
+ constructor(name, dataType, columnType) {
2408
+ super(name, dataType, columnType);
2409
+ this.config.autoIncrement = false;
2410
+ }
2411
+ primaryKey(config) {
2412
+ if (config?.autoIncrement) {
2413
+ this.config.autoIncrement = true;
2414
+ }
2415
+ this.config.hasDefault = true;
2416
+ return super.primaryKey();
2417
+ }
2418
+ };
2419
+ var SQLiteBaseInteger = class extends SQLiteColumn {
2420
+ static [entityKind] = "SQLiteBaseInteger";
2421
+ autoIncrement = this.config.autoIncrement;
2422
+ getSQLType() {
2423
+ return "integer";
2424
+ }
2425
+ };
2426
+ var SQLiteIntegerBuilder = class extends SQLiteBaseIntegerBuilder {
2427
+ static [entityKind] = "SQLiteIntegerBuilder";
2428
+ constructor(name) {
2429
+ super(name, "number", "SQLiteInteger");
2430
+ }
2431
+ build(table) {
2432
+ return new SQLiteInteger(
2433
+ table,
2434
+ this.config
2435
+ );
2436
+ }
2437
+ };
2438
+ var SQLiteInteger = class extends SQLiteBaseInteger {
2439
+ static [entityKind] = "SQLiteInteger";
2440
+ };
2441
+ var SQLiteTimestampBuilder = class extends SQLiteBaseIntegerBuilder {
2442
+ static [entityKind] = "SQLiteTimestampBuilder";
2443
+ constructor(name, mode) {
2444
+ super(name, "date", "SQLiteTimestamp");
2445
+ this.config.mode = mode;
2446
+ }
2447
+ /**
2448
+ * @deprecated Use `default()` with your own expression instead.
2449
+ *
2450
+ * Adds `DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer))` to the column, which is the current epoch timestamp in milliseconds.
2451
+ */
2452
+ defaultNow() {
2453
+ return this.default(sql`(cast((julianday('now') - 2440587.5)*86400000 as integer))`);
2454
+ }
2455
+ build(table) {
2456
+ return new SQLiteTimestamp(
2457
+ table,
2458
+ this.config
2459
+ );
2460
+ }
2461
+ };
2462
+ var SQLiteTimestamp = class extends SQLiteBaseInteger {
2463
+ static [entityKind] = "SQLiteTimestamp";
2464
+ mode = this.config.mode;
2465
+ mapFromDriverValue(value) {
2466
+ if (this.config.mode === "timestamp") {
2467
+ return new Date(value * 1e3);
2468
+ }
2469
+ return new Date(value);
2470
+ }
2471
+ mapToDriverValue(value) {
2472
+ const unix = value.getTime();
2473
+ if (this.config.mode === "timestamp") {
2474
+ return Math.floor(unix / 1e3);
2475
+ }
2476
+ return unix;
2477
+ }
2478
+ };
2479
+ var SQLiteBooleanBuilder = class extends SQLiteBaseIntegerBuilder {
2480
+ static [entityKind] = "SQLiteBooleanBuilder";
2481
+ constructor(name, mode) {
2482
+ super(name, "boolean", "SQLiteBoolean");
2483
+ this.config.mode = mode;
2484
+ }
2485
+ build(table) {
2486
+ return new SQLiteBoolean(
2487
+ table,
2488
+ this.config
2489
+ );
2490
+ }
2491
+ };
2492
+ var SQLiteBoolean = class extends SQLiteBaseInteger {
2493
+ static [entityKind] = "SQLiteBoolean";
2494
+ mode = this.config.mode;
2495
+ mapFromDriverValue(value) {
2496
+ return Number(value) === 1;
2497
+ }
2498
+ mapToDriverValue(value) {
2499
+ return value ? 1 : 0;
2500
+ }
2501
+ };
2502
+ function integer(a, b) {
2503
+ const { name, config } = getColumnNameAndConfig(a, b);
2504
+ if (config?.mode === "timestamp" || config?.mode === "timestamp_ms") {
2505
+ return new SQLiteTimestampBuilder(name, config.mode);
2506
+ }
2507
+ if (config?.mode === "boolean") {
2508
+ return new SQLiteBooleanBuilder(name, config.mode);
2509
+ }
2510
+ return new SQLiteIntegerBuilder(name);
2511
+ }
2512
+
2513
+ // ../../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
2514
+ var SQLiteNumericBuilder = class extends SQLiteColumnBuilder {
2515
+ static [entityKind] = "SQLiteNumericBuilder";
2516
+ constructor(name) {
2517
+ super(name, "string", "SQLiteNumeric");
2518
+ }
2519
+ /** @internal */
2520
+ build(table) {
2521
+ return new SQLiteNumeric(
2522
+ table,
2523
+ this.config
2524
+ );
2525
+ }
2526
+ };
2527
+ var SQLiteNumeric = class extends SQLiteColumn {
2528
+ static [entityKind] = "SQLiteNumeric";
2529
+ mapFromDriverValue(value) {
2530
+ if (typeof value === "string") return value;
2531
+ return String(value);
2532
+ }
2533
+ getSQLType() {
2534
+ return "numeric";
2535
+ }
2536
+ };
2537
+ var SQLiteNumericNumberBuilder = class extends SQLiteColumnBuilder {
2538
+ static [entityKind] = "SQLiteNumericNumberBuilder";
2539
+ constructor(name) {
2540
+ super(name, "number", "SQLiteNumericNumber");
2541
+ }
2542
+ /** @internal */
2543
+ build(table) {
2544
+ return new SQLiteNumericNumber(
2545
+ table,
2546
+ this.config
2547
+ );
2548
+ }
2549
+ };
2550
+ var SQLiteNumericNumber = class extends SQLiteColumn {
2551
+ static [entityKind] = "SQLiteNumericNumber";
2552
+ mapFromDriverValue(value) {
2553
+ if (typeof value === "number") return value;
2554
+ return Number(value);
2555
+ }
2556
+ mapToDriverValue = String;
2557
+ getSQLType() {
2558
+ return "numeric";
2559
+ }
2560
+ };
2561
+ var SQLiteNumericBigIntBuilder = class extends SQLiteColumnBuilder {
2562
+ static [entityKind] = "SQLiteNumericBigIntBuilder";
2563
+ constructor(name) {
2564
+ super(name, "bigint", "SQLiteNumericBigInt");
2565
+ }
2566
+ /** @internal */
2567
+ build(table) {
2568
+ return new SQLiteNumericBigInt(
2569
+ table,
2570
+ this.config
2571
+ );
2572
+ }
2573
+ };
2574
+ var SQLiteNumericBigInt = class extends SQLiteColumn {
2575
+ static [entityKind] = "SQLiteNumericBigInt";
2576
+ mapFromDriverValue = BigInt;
2577
+ mapToDriverValue = String;
2578
+ getSQLType() {
2579
+ return "numeric";
2580
+ }
2581
+ };
2582
+ function numeric(a, b) {
2583
+ const { name, config } = getColumnNameAndConfig(a, b);
2584
+ const mode = config?.mode;
2585
+ return mode === "number" ? new SQLiteNumericNumberBuilder(name) : mode === "bigint" ? new SQLiteNumericBigIntBuilder(name) : new SQLiteNumericBuilder(name);
2586
+ }
2587
+
2588
+ // ../../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
2589
+ var SQLiteRealBuilder = class extends SQLiteColumnBuilder {
2590
+ static [entityKind] = "SQLiteRealBuilder";
2591
+ constructor(name) {
2592
+ super(name, "number", "SQLiteReal");
2593
+ }
2594
+ /** @internal */
2595
+ build(table) {
2596
+ return new SQLiteReal(table, this.config);
2597
+ }
2598
+ };
2599
+ var SQLiteReal = class extends SQLiteColumn {
2600
+ static [entityKind] = "SQLiteReal";
2601
+ getSQLType() {
2602
+ return "real";
2603
+ }
2604
+ };
2605
+ function real(name) {
2606
+ return new SQLiteRealBuilder(name ?? "");
2607
+ }
2608
+
2609
+ // ../../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
2610
+ var SQLiteTextBuilder = class extends SQLiteColumnBuilder {
2611
+ static [entityKind] = "SQLiteTextBuilder";
2612
+ constructor(name, config) {
2613
+ super(name, "string", "SQLiteText");
2614
+ this.config.enumValues = config.enum;
2615
+ this.config.length = config.length;
2616
+ }
2617
+ /** @internal */
2618
+ build(table) {
2619
+ return new SQLiteText(
2620
+ table,
2621
+ this.config
2622
+ );
2623
+ }
2624
+ };
2625
+ var SQLiteText = class extends SQLiteColumn {
2626
+ static [entityKind] = "SQLiteText";
2627
+ enumValues = this.config.enumValues;
2628
+ length = this.config.length;
2629
+ constructor(table, config) {
2630
+ super(table, config);
2631
+ }
2632
+ getSQLType() {
2633
+ return `text${this.config.length ? `(${this.config.length})` : ""}`;
2634
+ }
2635
+ };
2636
+ var SQLiteTextJsonBuilder = class extends SQLiteColumnBuilder {
2637
+ static [entityKind] = "SQLiteTextJsonBuilder";
2638
+ constructor(name) {
2639
+ super(name, "json", "SQLiteTextJson");
2640
+ }
2641
+ /** @internal */
2642
+ build(table) {
2643
+ return new SQLiteTextJson(
2644
+ table,
2645
+ this.config
2646
+ );
2647
+ }
2648
+ };
2649
+ var SQLiteTextJson = class extends SQLiteColumn {
2650
+ static [entityKind] = "SQLiteTextJson";
2651
+ getSQLType() {
2652
+ return "text";
2653
+ }
2654
+ mapFromDriverValue(value) {
2655
+ return JSON.parse(value);
2656
+ }
2657
+ mapToDriverValue(value) {
2658
+ return JSON.stringify(value);
2659
+ }
2660
+ };
2661
+ function text2(a, b = {}) {
2662
+ const { name, config } = getColumnNameAndConfig(a, b);
2663
+ if (config.mode === "json") {
2664
+ return new SQLiteTextJsonBuilder(name);
2665
+ }
2666
+ return new SQLiteTextBuilder(name, config);
2667
+ }
2668
+
2669
+ // ../../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
2670
+ function getSQLiteColumnBuilders() {
2671
+ return {
2672
+ blob,
2673
+ customType,
2674
+ integer,
2675
+ numeric,
2676
+ real,
2677
+ text: text2
2678
+ };
2679
+ }
2680
+
2681
+ // ../../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
2682
+ var InlineForeignKeys = /* @__PURE__ */ Symbol.for("drizzle:SQLiteInlineForeignKeys");
2683
+ var SQLiteTable = class extends Table {
2684
+ static [entityKind] = "SQLiteTable";
2685
+ /** @internal */
2686
+ static Symbol = Object.assign({}, Table.Symbol, {
2687
+ InlineForeignKeys
2688
+ });
2689
+ /** @internal */
2690
+ [Table.Symbol.Columns];
2691
+ /** @internal */
2692
+ [InlineForeignKeys] = [];
2693
+ /** @internal */
2694
+ [Table.Symbol.ExtraConfigBuilder] = void 0;
2695
+ };
2696
+ function sqliteTableBase(name, columns, extraConfig, schema, baseName = name) {
2697
+ const rawTable = new SQLiteTable(name, schema, baseName);
2698
+ const parsedColumns = typeof columns === "function" ? columns(getSQLiteColumnBuilders()) : columns;
2699
+ const builtColumns = Object.fromEntries(
2700
+ Object.entries(parsedColumns).map(([name2, colBuilderBase]) => {
2701
+ const colBuilder = colBuilderBase;
2702
+ colBuilder.setName(name2);
2703
+ const column = colBuilder.build(rawTable);
2704
+ rawTable[InlineForeignKeys].push(...colBuilder.buildForeignKeys(column, rawTable));
2705
+ return [name2, column];
2706
+ })
2707
+ );
2708
+ const table = Object.assign(rawTable, builtColumns);
2709
+ table[Table.Symbol.Columns] = builtColumns;
2710
+ table[Table.Symbol.ExtraConfigColumns] = builtColumns;
2711
+ if (extraConfig) {
2712
+ table[SQLiteTable.Symbol.ExtraConfigBuilder] = extraConfig;
2713
+ }
2714
+ return table;
2715
+ }
2716
+ var sqliteTable = (name, columns, extraConfig) => {
2717
+ return sqliteTableBase(name, columns, extraConfig);
2718
+ };
2719
+
2720
+ // ../../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
2721
+ function primaryKey(...config) {
2722
+ if (config[0].columns) {
2723
+ return new PrimaryKeyBuilder(config[0].columns, config[0].name);
2724
+ }
2725
+ return new PrimaryKeyBuilder(config);
2726
+ }
2727
+ var PrimaryKeyBuilder = class {
2728
+ static [entityKind] = "SQLitePrimaryKeyBuilder";
2729
+ /** @internal */
2730
+ columns;
2731
+ /** @internal */
2732
+ name;
2733
+ constructor(columns, name) {
2734
+ this.columns = columns;
2735
+ this.name = name;
2736
+ }
2737
+ /** @internal */
2738
+ build(table) {
2739
+ return new PrimaryKey(table, this.columns, this.name);
2740
+ }
2741
+ };
2742
+ var PrimaryKey = class {
2743
+ constructor(table, columns, name) {
2744
+ this.table = table;
2745
+ this.columns = columns;
2746
+ this.name = name;
2747
+ }
2748
+ static [entityKind] = "SQLitePrimaryKey";
2749
+ columns;
2750
+ name;
2751
+ getName() {
2752
+ return this.name ?? `${this.table[SQLiteTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
2753
+ }
2754
+ };
2755
+
2756
+ // ../feedback/src/connected.ts
2757
+ var participants = sqliteTable("participants", {
2758
+ subject: text2("subject").primaryKey(),
2759
+ displayName: text2("display_name").notNull()
2760
+ });
2761
+ var contacts = sqliteTable("participant_contacts", {
2762
+ subject: text2("subject").primaryKey(),
2763
+ email: text2("email"),
2764
+ emailEnabled: integer("email_enabled").notNull().default(0)
2765
+ });
2766
+ var nonces = sqliteTable("identity_nonces", {
2767
+ nonce: text2("nonce").primaryKey(),
2768
+ expiresAt: integer("expires_at").notNull()
2769
+ });
2770
+ var sessions = sqliteTable("participant_sessions", {
2771
+ tokenHash: text2("token_hash").primaryKey(),
2772
+ subject: text2("subject").notNull().references(() => participants.subject),
2773
+ expiresAt: integer("expires_at").notNull()
2774
+ });
2775
+ var votes = sqliteTable(
2776
+ "participant_votes",
2777
+ {
2778
+ postSlug: text2("post_slug").notNull(),
2779
+ subject: text2("subject").notNull().references(() => participants.subject)
2780
+ },
2781
+ (t) => [primaryKey({ columns: [t.postSlug, t.subject] })]
2782
+ );
2783
+ var attribution = sqliteTable("comment_attribution", {
2784
+ commentId: text2("comment_id").primaryKey(),
2785
+ subject: text2("subject").notNull().references(() => participants.subject),
2786
+ displayName: text2("display_name").notNull()
2787
+ });
2788
+
2789
+ // ../feedback/src/images.ts
2790
+ var limit = 5 * 1024 * 1024;
2791
+
908
2792
  // ../feedback/src/index.ts
909
2793
  var postCreationQueue = Promise.resolve();
910
2794
 
@@ -1058,12 +2942,16 @@ function isRecord(value) {
1058
2942
  }
1059
2943
 
1060
2944
  // src/index.ts
2945
+ function defaultProcessingQueueName(workerName) {
2946
+ return workerName.length <= 55 ? `${workerName}-updates` : `${workerName.slice(0, 46)}-${createHash2("sha256").update(workerName).digest("hex").slice(0, 8)}-updates`;
2947
+ }
1061
2948
  async function provisionGuidedInstallation({
1062
2949
  destination,
1063
2950
  product,
1064
2951
  themePreset,
1065
2952
  workerName,
1066
2953
  commentProbePageId,
2954
+ connected,
1067
2955
  features,
1068
2956
  feedbackSelection,
1069
2957
  changelogSelection,
@@ -1082,11 +2970,46 @@ async function provisionGuidedInstallation({
1082
2970
  }
1083
2971
  if (product.siteUrl && new URL(product.siteUrl).protocol !== "https:")
1084
2972
  throw new Error("product.siteUrl must be an HTTPS URL.");
2973
+ if (connected) {
2974
+ if (!product.siteUrl || connected.handoffSecret.length < 32 || !/^[0-9a-f-]{36}$/i.test(connected.databaseId) || !connected.databaseName.trim())
2975
+ throw new Error(
2976
+ "Connected setup requires a public site URL, dedicated D1 identifiers, and a handoff secret of at least 32 characters."
2977
+ );
2978
+ for (const url of [connected.issuer, connected.loginUrl])
2979
+ if (new URL(url).protocol !== "https:" || new URL(url).username || new URL(url).password)
2980
+ throw new Error(
2981
+ "Connected identity URLs must use HTTPS without credentials."
2982
+ );
2983
+ }
2984
+ if (connected?.email) {
2985
+ const sender = connected.email;
2986
+ if (!["cloudflare", "resend", "custom"].includes(sender.provider) || !/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(sender.from))
2987
+ throw new Error(
2988
+ "Choose cloudflare, resend, or custom and a plain sender email address."
2989
+ );
2990
+ if (sender.provider !== "cloudflare" && !sender.secret?.trim())
2991
+ throw new Error(
2992
+ "Resend and custom delivery require a server-only email secret."
2993
+ );
2994
+ 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))
2995
+ throw new Error(
2996
+ "Custom delivery requires an HTTPS endpoint without credentials or fragments."
2997
+ );
2998
+ }
2999
+ if (connected?.imageBucket && !/^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$/.test(connected.imageBucket))
3000
+ throw new Error(
3001
+ "Use a dedicated private R2 bucket name of 3\u201363 lowercase letters, digits, or hyphens."
3002
+ );
1085
3003
  const targetName = workerName ?? basename(destination).toLowerCase().replace(/[^a-z0-9-]/g, "-");
1086
3004
  if (!/^[a-z0-9][a-z0-9-]{0,62}$/.test(targetName))
1087
3005
  throw new Error(
1088
3006
  "Worker name must contain 1\u201363 lowercase letters, numbers, or hyphens."
1089
3007
  );
3008
+ const processingQueue = connected && connected.processing !== "standard" ? connected.queueName ?? defaultProcessingQueueName(targetName) : void 0;
3009
+ if (processingQueue && !/^[a-z0-9][a-z0-9-]{0,62}$/.test(processingQueue))
3010
+ throw new Error(
3011
+ "Processing queue name must contain 1\u201363 lowercase letters, numbers, or hyphens."
3012
+ );
1090
3013
  const approved = await preview(
1091
3014
  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.`
1092
3015
  );
@@ -1132,7 +3055,58 @@ async function provisionGuidedInstallation({
1132
3055
  const wrangler = JSON.parse(await readFile2(wranglerPath, "utf8"));
1133
3056
  await writeFile2(
1134
3057
  wranglerPath,
1135
- JSON.stringify({ ...wrangler, name: targetName }, null, 2) + "\n"
3058
+ JSON.stringify(
3059
+ {
3060
+ ...wrangler,
3061
+ name: targetName,
3062
+ ...connected ? {
3063
+ triggers: { crons: ["*/5 * * * *"] },
3064
+ ...processingQueue ? {
3065
+ queues: {
3066
+ producers: [
3067
+ { binding: "FEEDBAX_UPDATES", queue: processingQueue }
3068
+ ],
3069
+ consumers: [
3070
+ {
3071
+ queue: processingQueue,
3072
+ max_batch_size: 1,
3073
+ max_batch_timeout: 1,
3074
+ max_retries: 3,
3075
+ max_concurrency: 1,
3076
+ retry_delay: 60
3077
+ }
3078
+ ]
3079
+ }
3080
+ } : {},
3081
+ ...connected.email?.provider === "cloudflare" ? {
3082
+ send_email: [
3083
+ {
3084
+ name: "FEEDBAX_EMAIL",
3085
+ allowed_sender_addresses: [connected.email.from]
3086
+ }
3087
+ ]
3088
+ } : {},
3089
+ ...connected.imageBucket ? {
3090
+ r2_buckets: [
3091
+ {
3092
+ binding: "FEEDBAX_IMAGES",
3093
+ bucket_name: connected.imageBucket
3094
+ }
3095
+ ]
3096
+ } : {},
3097
+ d1_databases: [
3098
+ {
3099
+ binding: "FEEDBAX_DB",
3100
+ database_id: connected.databaseId,
3101
+ database_name: connected.databaseName,
3102
+ migrations_dir: "migrations"
3103
+ }
3104
+ ]
3105
+ } : {}
3106
+ },
3107
+ null,
3108
+ 2
3109
+ ) + "\n"
1136
3110
  );
1137
3111
  const apiKey = randomBytes(32).toString("base64url");
1138
3112
  const signingSecret = randomBytes(32).toString("base64url");
@@ -1143,6 +3117,8 @@ async function provisionGuidedInstallation({
1143
3117
  ...prefixProperties("NOTION_FEEDBACK", feedback.propertyIds),
1144
3118
  FEEDBAX_API_KEY_HASH: createHash2("sha256").update(apiKey).digest("base64url"),
1145
3119
  PARTICIPATION_SIGNING_SECRET: signingSecret,
3120
+ ...connected ? { IDENTITY_HANDOFF_SECRET: connected.handoffSecret } : {},
3121
+ ...connected?.email?.secret ? { EMAIL_PROVIDER_SECRET: connected.email.secret } : {},
1146
3122
  FEEDBAX_VOTING_ENABLED: String(features.voting),
1147
3123
  FEEDBAX_COMMENTS_ENABLED: String(features.comments),
1148
3124
  FEEDBAX_CHANGELOG_ENABLED: String(features.changelog),
@@ -1162,6 +3138,21 @@ async function provisionGuidedInstallation({
1162
3138
  const configuration = defineFeedbax({
1163
3139
  product: { ...product, logo: "/feedbax-mark.svg" },
1164
3140
  theme: { preset: themePreset },
3141
+ ...connected ? {
3142
+ connected: {
3143
+ processing: connected.processing ?? "small",
3144
+ issuer: connected.issuer,
3145
+ loginUrl: connected.loginUrl,
3146
+ ...connected.email ? {
3147
+ email: {
3148
+ provider: connected.email.provider,
3149
+ from: connected.email.from,
3150
+ ...connected.email.endpoint ? { endpoint: connected.email.endpoint } : {}
3151
+ }
3152
+ } : {},
3153
+ ...connected.imageBucket ? { images: true } : {}
3154
+ }
3155
+ } : {},
1165
3156
  notion: {
1166
3157
  databaseId: feedback.databaseId,
1167
3158
  dataSourceId: feedback.dataSourceId,
@@ -1199,7 +3190,7 @@ export default defineFeedbax(${JSON.stringify(configuration, null, 2)});
1199
3190
  `,
1200
3191
  { flag: "a", mode: 384 }
1201
3192
  );
1202
- return { apiKey, feedback, changelog };
3193
+ return { apiKey, feedback, changelog, processingQueue };
1203
3194
  }
1204
3195
  function prefixProperties(prefix, properties) {
1205
3196
  return Object.fromEntries(
@@ -1403,6 +3394,7 @@ export {
1403
3394
  collectFeatureSelection,
1404
3395
  configureChangelogStorage,
1405
3396
  copyPackagedTemplate,
3397
+ defaultProcessingQueueName,
1406
3398
  doctorChangelogStorage,
1407
3399
  doctorInstallation,
1408
3400
  featureChoices,