kitcn 0.15.1 → 0.15.4

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.
@@ -7063,7 +7063,69 @@ const BASE_ENV_FIELDS = [{
7063
7063
  schema: "z.string().default('http://localhost:3000')"
7064
7064
  }];
7065
7065
  const ENV_SCHEMA_RE = /(const\s+\w+\s*=\s*z\.object\(\{\n)([\s\S]*?)(\n\}\);)/m;
7066
+ const CREATE_ENV_OPTIONS_START_RE = /createEnv\s*\(\s*\{/m;
7067
+ const READ_OPTIONAL_RUNTIME_ENV_PROPERTY_RE = /\breadOptionalRuntimeEnv\s*:/m;
7068
+ const READ_OPTIONAL_RUNTIME_ENV_RE = /(\s*readOptionalRuntimeEnv\s*:\s*\[)([\s\S]*?)(\]\s*,?)/m;
7069
+ const LEADING_WHITESPACE_RE = /^\s*/;
7070
+ const STRING_LITERAL_ARRAY_ENTRY_RE = /^(['"])([^'"]+)\1$/;
7066
7071
  const WHITESPACE_RE$1 = /\s/;
7072
+ const findMatchingObjectBraceIndex = (source, openIndex) => {
7073
+ let depth = 0;
7074
+ let quote;
7075
+ let escaped = false;
7076
+ let lineComment = false;
7077
+ let blockComment = false;
7078
+ for (let index = openIndex; index < source.length; index++) {
7079
+ const char = source[index];
7080
+ const nextChar = source[index + 1];
7081
+ if (lineComment) {
7082
+ if (char === "\n" || char === "\r") lineComment = false;
7083
+ continue;
7084
+ }
7085
+ if (blockComment) {
7086
+ if (char === "*" && nextChar === "/") {
7087
+ blockComment = false;
7088
+ index++;
7089
+ }
7090
+ continue;
7091
+ }
7092
+ if (quote) {
7093
+ if (escaped) {
7094
+ escaped = false;
7095
+ continue;
7096
+ }
7097
+ if (char === "\\") {
7098
+ escaped = true;
7099
+ continue;
7100
+ }
7101
+ if (char === quote) quote = void 0;
7102
+ continue;
7103
+ }
7104
+ if (char === "/" && nextChar === "/") {
7105
+ lineComment = true;
7106
+ index++;
7107
+ continue;
7108
+ }
7109
+ if (char === "/" && nextChar === "*") {
7110
+ blockComment = true;
7111
+ index++;
7112
+ continue;
7113
+ }
7114
+ if (char === "\"" || char === "'" || char === "`") {
7115
+ quote = char;
7116
+ continue;
7117
+ }
7118
+ if (char === "{") {
7119
+ depth++;
7120
+ continue;
7121
+ }
7122
+ if (char === "}") {
7123
+ depth--;
7124
+ if (depth === 0) return index;
7125
+ }
7126
+ }
7127
+ return -1;
7128
+ };
7067
7129
  const resolveEnvBootstrapPlanFileDetails = (templateId) => {
7068
7130
  if (templateId === KITCN_CONFIG_TEMPLATE_ID) return {
7069
7131
  createReason: "Create kitcn config.",
@@ -7099,18 +7161,64 @@ const resolveBootstrapEnvFields = (envFields) => {
7099
7161
  for (const field of envFields) if (!fields.some((existing) => existing.key === field.key)) fields.push(field);
7100
7162
  return fields;
7101
7163
  };
7164
+ const resolveReadOptionalRuntimeEnvKeys = (fields) => fields.filter((field) => field.readOptionalRuntimeEnv).map((field) => field.key);
7165
+ const renderReadOptionalRuntimeEnvOption = (keys) => {
7166
+ if (keys.length === 0) return "";
7167
+ return ` readOptionalRuntimeEnv: [\n${keys.map((key) => ` '${key}',`).join("\n")}\n ],\n`;
7168
+ };
7169
+ const parseReadOptionalRuntimeEnvKeys = (existingOptionsBody, existingMatch) => {
7170
+ if (existingMatch.index === void 0) return [];
7171
+ const matchEnd = existingMatch.index + existingMatch[0].length;
7172
+ if (!existingMatch[3].includes(",") && existingOptionsBody.slice(matchEnd).trim()) throw new Error("Expected env helper `readOptionalRuntimeEnv` to be an inline array of string literals before adding keys.");
7173
+ const rawEntries = existingMatch[2].trim();
7174
+ if (!rawEntries) return [];
7175
+ const keys = [];
7176
+ const entries = rawEntries.split(",");
7177
+ for (let index = 0; index < entries.length; index++) {
7178
+ const entry = entries[index].trim();
7179
+ if (!entry && index === entries.length - 1) continue;
7180
+ const stringLiteralMatch = entry.match(STRING_LITERAL_ARRAY_ENTRY_RE);
7181
+ if (!stringLiteralMatch) throw new Error("Expected env helper `readOptionalRuntimeEnv` to be an inline array of string literals before adding keys.");
7182
+ keys.push(stringLiteralMatch[2]);
7183
+ }
7184
+ return keys;
7185
+ };
7186
+ const upsertReadOptionalRuntimeEnvOption = (source, keys) => {
7187
+ if (keys.length === 0) return source;
7188
+ const createEnvMatch = source.match(CREATE_ENV_OPTIONS_START_RE);
7189
+ if (!createEnvMatch || createEnvMatch.index === void 0) throw new Error("Expected env helper to call `createEnv({ ... })` before adding `readOptionalRuntimeEnv`.");
7190
+ const insertIndex = createEnvMatch.index + createEnvMatch[0].lastIndexOf("{") + 1;
7191
+ const closingBraceIndex = findMatchingObjectBraceIndex(source, insertIndex - 1);
7192
+ if (closingBraceIndex === -1) throw new Error("Expected env helper `createEnv` options object to close before adding `readOptionalRuntimeEnv`.");
7193
+ const existingOptionsBody = source.slice(insertIndex, closingBraceIndex);
7194
+ const existingMatch = existingOptionsBody.match(READ_OPTIONAL_RUNTIME_ENV_RE);
7195
+ if (!existingMatch && READ_OPTIONAL_RUNTIME_ENV_PROPERTY_RE.test(existingOptionsBody)) throw new Error("Expected env helper `readOptionalRuntimeEnv` to be an inline array before adding keys.");
7196
+ const existingKeys = existingMatch ? parseReadOptionalRuntimeEnvKeys(existingOptionsBody, existingMatch) : [];
7197
+ const option = renderReadOptionalRuntimeEnvOption([...new Set([...existingKeys, ...keys])]);
7198
+ if (existingMatch && existingMatch.index !== void 0) {
7199
+ const replacement = `${existingMatch[1].match(LEADING_WHITESPACE_RE)?.[0] ?? ""}${option.trimStart().trimEnd()}`;
7200
+ const existingOptionStart = insertIndex + existingMatch.index;
7201
+ return `${source.slice(0, existingOptionStart)}${replacement}${source.slice(existingOptionStart + existingMatch[0].length)}`;
7202
+ }
7203
+ const before = source.slice(0, insertIndex);
7204
+ const after = source.slice(insertIndex);
7205
+ if (after.startsWith("\n")) return `${before}\n${option}${after.slice(1)}`;
7206
+ const body = source.slice(insertIndex, closingBraceIndex).trim();
7207
+ return `${before}\n${option}${body.length === 0 ? "" : ` ${body}${body.endsWith(",") ? "" : ","}\n`}${source.slice(closingBraceIndex)}`;
7208
+ };
7102
7209
  const renderEnvHelperContent = (envFields, existingContent) => {
7103
7210
  const fields = resolveBootstrapEnvFields(envFields);
7104
- if (!existingContent) return `import { createEnv } from 'kitcn/server';\nimport { z } from 'zod';\n\nconst envSchema = z.object({\n${fields.map((field) => ` ${field.key}: ${field.schema},`).join("\n")}\n});\n\nexport const getEnv = createEnv({\n schema: envSchema,\n});\n`;
7211
+ const readOptionalRuntimeEnvKeys = resolveReadOptionalRuntimeEnvKeys(fields);
7212
+ if (!existingContent) return `import { createEnv } from 'kitcn/server';\nimport { z } from 'zod';\n\nconst envSchema = z.object({\n${fields.map((field) => ` ${field.key}: ${field.schema},`).join("\n")}\n});\n\nexport const getEnv = createEnv({\n${renderReadOptionalRuntimeEnvOption(readOptionalRuntimeEnvKeys)} schema: envSchema,\n});\n`;
7105
7213
  const match = existingContent.match(ENV_SCHEMA_RE);
7106
7214
  if (!match) throw new Error("Expected env helper to define `const envSchema = z.object({ ... });`.");
7107
7215
  const existingBody = match[2];
7108
7216
  const missingFieldLines = fields.filter((field) => {
7109
7217
  return !new RegExp(`(^|\\n)\\s*${field.key}\\s*:`, "m").test(existingBody);
7110
7218
  }).map((field) => ` ${field.key}: ${field.schema},`);
7111
- if (missingFieldLines.length === 0) return existingContent;
7219
+ if (missingFieldLines.length === 0) return upsertReadOptionalRuntimeEnvOption(existingContent, readOptionalRuntimeEnvKeys);
7112
7220
  const nextBody = `${existingBody}${existingBody.endsWith("\n") ? "" : "\n"}${missingFieldLines.join("\n")}`;
7113
- return existingContent.replace(ENV_SCHEMA_RE, `${match[1]}${nextBody}${match[3]}`);
7221
+ return upsertReadOptionalRuntimeEnvOption(existingContent.replace(ENV_SCHEMA_RE, `${match[1]}${nextBody}${match[3]}`), readOptionalRuntimeEnvKeys);
7114
7222
  };
7115
7223
  const renderLocalConvexEnvContent = (envFields, existingContent) => {
7116
7224
  const fields = resolveBootstrapEnvFields(envFields).filter((field) => field.bootstrap !== void 0);
@@ -8345,7 +8453,6 @@ import {
8345
8453
  ConvexReactClient,
8346
8454
  getConvexQueryClientSingleton,
8347
8455
  getQueryClientSingleton,
8348
- useAuthStore,
8349
8456
  } from 'kitcn/react';
8350
8457
  import { useRouter } from 'next/navigation';
8351
8458
  import type { ReactNode } from 'react';
@@ -8362,11 +8469,17 @@ export function AppConvexProvider({
8362
8469
  children: ReactNode;
8363
8470
  }) {
8364
8471
  const router = useRouter();
8472
+ const queryClient = getQueryClientSingleton(createQueryClient);
8473
+ const convexQueryClient = getConvexQueryClientSingleton({
8474
+ convex,
8475
+ queryClient,
8476
+ });
8365
8477
 
8366
8478
  return (
8367
8479
  <ConvexAuthProvider
8368
8480
  authClient={authClient}
8369
8481
  client={convex}
8482
+ convexQueryClient={convexQueryClient}
8370
8483
  onMutationUnauthorized={() => {
8371
8484
  router.push('/auth');
8372
8485
  }}
@@ -8374,28 +8487,14 @@ export function AppConvexProvider({
8374
8487
  router.push('/auth');
8375
8488
  }}
8376
8489
  >
8377
- <QueryProvider>{children}</QueryProvider>
8490
+ <TanstackQueryClientProvider client={queryClient}>
8491
+ <CRPCProvider convexClient={convex} convexQueryClient={convexQueryClient}>
8492
+ {children}
8493
+ </CRPCProvider>
8494
+ </TanstackQueryClientProvider>
8378
8495
  </ConvexAuthProvider>
8379
8496
  );
8380
8497
  }
8381
-
8382
- function QueryProvider({ children }: { children: ReactNode }) {
8383
- const authStore = useAuthStore();
8384
- const queryClient = getQueryClientSingleton(createQueryClient);
8385
- const convexQueryClient = getConvexQueryClientSingleton({
8386
- authStore,
8387
- convex,
8388
- queryClient,
8389
- });
8390
-
8391
- return (
8392
- <TanstackQueryClientProvider client={queryClient}>
8393
- <CRPCProvider convexClient={convex} convexQueryClient={convexQueryClient}>
8394
- {children}
8395
- </CRPCProvider>
8396
- </TanstackQueryClientProvider>
8397
- );
8398
- }
8399
8498
  `;
8400
8499
 
8401
8500
  //#endregion
@@ -8554,7 +8653,6 @@ import {
8554
8653
  ConvexReactClient,
8555
8654
  getConvexQueryClientSingleton,
8556
8655
  getQueryClientSingleton,
8557
- useAuthStore,
8558
8656
  } from 'kitcn/react';
8559
8657
  import type { ReactNode } from 'react';
8560
8658
 
@@ -8570,11 +8668,17 @@ export function AppConvexProvider({
8570
8668
  children: ReactNode;
8571
8669
  }) {
8572
8670
  const router = useRouter();
8671
+ const queryClient = getQueryClientSingleton(createQueryClient);
8672
+ const convexQueryClient = getConvexQueryClientSingleton({
8673
+ convex,
8674
+ queryClient,
8675
+ });
8573
8676
 
8574
8677
  return (
8575
8678
  <ConvexAuthProvider
8576
8679
  authClient={authClient}
8577
8680
  client={convex}
8681
+ convexQueryClient={convexQueryClient}
8578
8682
  onMutationUnauthorized={() => {
8579
8683
  router.push('/auth');
8580
8684
  }}
@@ -8582,28 +8686,14 @@ export function AppConvexProvider({
8582
8686
  router.push('/auth');
8583
8687
  }}
8584
8688
  >
8585
- <QueryProvider>{children}</QueryProvider>
8689
+ <TanstackQueryClientProvider client={queryClient}>
8690
+ <CRPCProvider convexClient={convex} convexQueryClient={convexQueryClient}>
8691
+ {children}
8692
+ </CRPCProvider>
8693
+ </TanstackQueryClientProvider>
8586
8694
  </ConvexAuthProvider>
8587
8695
  );
8588
8696
  }
8589
-
8590
- function QueryProvider({ children }: { children: ReactNode }) {
8591
- const authStore = useAuthStore();
8592
- const queryClient = getQueryClientSingleton(createQueryClient);
8593
- const convexQueryClient = getConvexQueryClientSingleton({
8594
- authStore,
8595
- convex,
8596
- queryClient,
8597
- });
8598
-
8599
- return (
8600
- <TanstackQueryClientProvider client={queryClient}>
8601
- <CRPCProvider convexClient={convex} convexQueryClient={convexQueryClient}>
8602
- {children}
8603
- </CRPCProvider>
8604
- </TanstackQueryClientProvider>
8605
- );
8606
- }
8607
8697
  `;
8608
8698
 
8609
8699
  //#endregion
@@ -9021,7 +9111,6 @@ import {
9021
9111
  ConvexReactClient,
9022
9112
  getConvexQueryClientSingleton,
9023
9113
  getQueryClientSingleton,
9024
- useAuthStore,
9025
9114
  } from 'kitcn/react';
9026
9115
  import type { ReactNode } from 'react';
9027
9116
 
@@ -9038,32 +9127,25 @@ export function AppConvexProvider({
9038
9127
  children: ReactNode;
9039
9128
  token?: string;
9040
9129
  }) {
9041
- return (
9042
- <ConvexAuthProvider
9043
- authClient={authClient}
9044
- client={convex}
9045
- initialToken={token}
9046
- >
9047
- <QueryProvider>{children}</QueryProvider>
9048
- </ConvexAuthProvider>
9049
- );
9050
- }
9051
-
9052
- function QueryProvider({ children }: { children: ReactNode }) {
9053
- const authStore = useAuthStore();
9054
9130
  const queryClient = getQueryClientSingleton(createQueryClient);
9055
9131
  const convexQueryClient = getConvexQueryClientSingleton({
9056
- authStore,
9057
9132
  convex,
9058
9133
  queryClient,
9059
9134
  });
9060
9135
 
9061
9136
  return (
9062
- <TanstackQueryClientProvider client={queryClient}>
9063
- <CRPCProvider convexClient={convex} convexQueryClient={convexQueryClient}>
9064
- {children}
9065
- </CRPCProvider>
9066
- </TanstackQueryClientProvider>
9137
+ <ConvexAuthProvider
9138
+ authClient={authClient}
9139
+ client={convex}
9140
+ convexQueryClient={convexQueryClient}
9141
+ initialToken={token}
9142
+ >
9143
+ <TanstackQueryClientProvider client={queryClient}>
9144
+ <CRPCProvider convexClient={convex} convexQueryClient={convexQueryClient}>
9145
+ {children}
9146
+ </CRPCProvider>
9147
+ </TanstackQueryClientProvider>
9148
+ </ConvexAuthProvider>
9067
9149
  );
9068
9150
  }
9069
9151
  `;
@@ -9264,7 +9346,6 @@ import {
9264
9346
  ConvexReactClient,
9265
9347
  getConvexQueryClientSingleton,
9266
9348
  getQueryClientSingleton,
9267
- useAuthStore,
9268
9349
  } from 'kitcn/react';
9269
9350
  import type { ReactNode } from 'react';
9270
9351
 
@@ -9279,28 +9360,24 @@ export function AppConvexProvider({
9279
9360
  }: {
9280
9361
  children: ReactNode;
9281
9362
  }) {
9282
- return (
9283
- <ConvexAuthProvider authClient={authClient} client={convex}>
9284
- <QueryProvider>{children}</QueryProvider>
9285
- </ConvexAuthProvider>
9286
- );
9287
- }
9288
-
9289
- function QueryProvider({ children }: { children: ReactNode }) {
9290
- const authStore = useAuthStore();
9291
9363
  const queryClient = getQueryClientSingleton(createQueryClient);
9292
9364
  const convexQueryClient = getConvexQueryClientSingleton({
9293
- authStore,
9294
9365
  convex,
9295
9366
  queryClient,
9296
9367
  });
9297
9368
 
9298
9369
  return (
9299
- <TanstackQueryClientProvider client={queryClient}>
9300
- <CRPCProvider convexClient={convex} convexQueryClient={convexQueryClient}>
9301
- {children}
9302
- </CRPCProvider>
9303
- </TanstackQueryClientProvider>
9370
+ <ConvexAuthProvider
9371
+ authClient={authClient}
9372
+ client={convex}
9373
+ convexQueryClient={convexQueryClient}
9374
+ >
9375
+ <TanstackQueryClientProvider client={queryClient}>
9376
+ <CRPCProvider convexClient={convex} convexQueryClient={convexQueryClient}>
9377
+ {children}
9378
+ </CRPCProvider>
9379
+ </TanstackQueryClientProvider>
9380
+ </ConvexAuthProvider>
9304
9381
  );
9305
9382
  }
9306
9383
  `;
@@ -11970,19 +12047,19 @@ const RESEND_SCHEMA_TEMPLATE = `import {
11970
12047
  unionOf,
11971
12048
  } from "kitcn/orm";
11972
12049
 
11973
- export const resendContentTable = convexTable("resend_content", {
12050
+ export const resendContentTable = convexTable("resendContent", {
11974
12051
  content: bytes().notNull(),
11975
12052
  mimeType: text().notNull(),
11976
12053
  filename: text(),
11977
12054
  path: text(),
11978
12055
  });
11979
12056
 
11980
- export const resendNextBatchRunTable = convexTable("resend_next_batch_run", {
12057
+ export const resendNextBatchRunTable = convexTable("resendNextBatchRun", {
11981
12058
  runId: text().notNull(),
11982
12059
  });
11983
12060
 
11984
12061
  export const resendDeliveryEventsTable = convexTable(
11985
- "resend_delivery_events",
12062
+ "resendDeliveryEvents",
11986
12063
  {
11987
12064
  emailId: text().notNull(),
11988
12065
  resendId: text().notNull(),
@@ -11997,7 +12074,7 @@ export const resendDeliveryEventsTable = convexTable(
11997
12074
  );
11998
12075
 
11999
12076
  export const resendEmailsTable = convexTable(
12000
- "resend_emails",
12077
+ "resendEmails",
12001
12078
  {
12002
12079
  from: text().notNull(),
12003
12080
  to: arrayOf(text().notNull()).notNull(),
@@ -12200,15 +12277,18 @@ const resendRegistryItem = defineInternalRegistryItem({
12200
12277
  envFields: [
12201
12278
  {
12202
12279
  key: "RESEND_API_KEY",
12280
+ readOptionalRuntimeEnv: true,
12203
12281
  schema: "z.string().optional()",
12204
12282
  reminder: { message: "Set before sending email through Resend." }
12205
12283
  },
12206
12284
  {
12207
12285
  key: "RESEND_WEBHOOK_SECRET",
12286
+ readOptionalRuntimeEnv: true,
12208
12287
  schema: "z.string().optional()"
12209
12288
  },
12210
12289
  {
12211
12290
  key: "RESEND_FROM_EMAIL",
12291
+ readOptionalRuntimeEnv: true,
12212
12292
  schema: "z.string().optional()"
12213
12293
  }
12214
12294
  ],
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { $ as promptForScaffoldTemplateSelection, A as resolveCodegenTrimSegments, At as highlighter, B as runConfiguredCodegen, C as isEntryPoint, Ct as formatDependencyInstallCommand, D as parseInitCommandArgs, E as parseBackendRunJson, Et as stripConvexCommandNoise, F as resolveRunDeps, G as runMigrationFlow, H as runDevSchemaBackfillIfNeeded, I as runAfterScaffoldScript, J as withWorkingDirectory, K as trackProcess, L as runAggregateBackfillFlow, M as resolveDocTopic, N as resolveInitProjectDir, O as readPackageVersions, P as resolveMigrationConfig, Q as promptForPluginSelection, R as runAggregatePruneFlow, S as isConvexDevPreRunConflictFlag, St as detectPackageManager, T as parseArgs, Tt as serializeEnvValue, U as runInitCommandFlow, V as runConvexInitIfNeeded, W as runMigrationCreate, X as collectPluginScaffoldTemplates, Y as createSpinner, Z as filterScaffoldTemplatePathMap, _ as formatInfoOutput, _t as applyPlanningDependencyInstall, a as cleanup, at as getPluginCatalogEntry, b as getDevAggregateBackfillStatePath, bt as resolveSupportedDependencyWarnings, c as createCommandEnv, ct as buildPluginInstallPlan, d as extractBackfillCliOptions, dt as collectInstalledPluginKeys, et as resolveAddTemplateDefaults, f as extractConcaveRunTargetArgs, ft as getPluginLockfilePath, g as formatDocsOutput, gt as applyDependencyHintsInstall, h as extractResetCliOptions, ht as resolveSchemaInstalledPlugins, i as buildInitializationPlan, it as resolveTemplatesByIdOrThrow, j as resolveConfiguredBackend, k as resolveBackfillConfig, kt as logger, l as ensureConvexGitignoreEntry, lt as resolvePluginScaffoldRoots, m as extractMigrationDownOptions, mt as readPluginLockfile, n as applyPluginInstallPlanFiles, nt as resolvePresetScaffoldTemplates, o as createBackendAdapter, ot as getSupportedPluginKeys, p as extractMigrationCliOptions, pt as getSchemaFilePath, q as withLocalCodegenEnv, r as assertNoRemovedDevPreRunFlag, rt as resolveTemplateSelectionSource, s as createBackendCommandEnv, st as isSupportedPluginKey, t as applyDependencyInstallPlan, tt as resolvePluginPreset, u as extractBackendRunTargetArgs, ut as assertSchemaFileExists, v as getAggregateBackfillDeploymentKey, vt as applyPluginDependencyInstall, w as isInitialized, wt as resolveAuthEnvState, x as hasRemoteConvexDeploymentEnv, xt as resolveProjectScaffoldContext, y as getConvexDeploymentCommandEnv, yt as inspectPluginDependencyInstall, z as runBackendFunction } from "./backend-core-B091CyHN.mjs";
2
+ import { $ as promptForScaffoldTemplateSelection, A as resolveCodegenTrimSegments, At as highlighter, B as runConfiguredCodegen, C as isEntryPoint, Ct as formatDependencyInstallCommand, D as parseInitCommandArgs, E as parseBackendRunJson, Et as stripConvexCommandNoise, F as resolveRunDeps, G as runMigrationFlow, H as runDevSchemaBackfillIfNeeded, I as runAfterScaffoldScript, J as withWorkingDirectory, K as trackProcess, L as runAggregateBackfillFlow, M as resolveDocTopic, N as resolveInitProjectDir, O as readPackageVersions, P as resolveMigrationConfig, Q as promptForPluginSelection, R as runAggregatePruneFlow, S as isConvexDevPreRunConflictFlag, St as detectPackageManager, T as parseArgs, Tt as serializeEnvValue, U as runInitCommandFlow, V as runConvexInitIfNeeded, W as runMigrationCreate, X as collectPluginScaffoldTemplates, Y as createSpinner, Z as filterScaffoldTemplatePathMap, _ as formatInfoOutput, _t as applyPlanningDependencyInstall, a as cleanup, at as getPluginCatalogEntry, b as getDevAggregateBackfillStatePath, bt as resolveSupportedDependencyWarnings, c as createCommandEnv, ct as buildPluginInstallPlan, d as extractBackfillCliOptions, dt as collectInstalledPluginKeys, et as resolveAddTemplateDefaults, f as extractConcaveRunTargetArgs, ft as getPluginLockfilePath, g as formatDocsOutput, gt as applyDependencyHintsInstall, h as extractResetCliOptions, ht as resolveSchemaInstalledPlugins, i as buildInitializationPlan, it as resolveTemplatesByIdOrThrow, j as resolveConfiguredBackend, k as resolveBackfillConfig, kt as logger, l as ensureConvexGitignoreEntry, lt as resolvePluginScaffoldRoots, m as extractMigrationDownOptions, mt as readPluginLockfile, n as applyPluginInstallPlanFiles, nt as resolvePresetScaffoldTemplates, o as createBackendAdapter, ot as getSupportedPluginKeys, p as extractMigrationCliOptions, pt as getSchemaFilePath, q as withLocalCodegenEnv, r as assertNoRemovedDevPreRunFlag, rt as resolveTemplateSelectionSource, s as createBackendCommandEnv, st as isSupportedPluginKey, t as applyDependencyInstallPlan, tt as resolvePluginPreset, u as extractBackendRunTargetArgs, ut as assertSchemaFileExists, v as getAggregateBackfillDeploymentKey, vt as applyPluginDependencyInstall, w as isInitialized, wt as resolveAuthEnvState, x as hasRemoteConvexDeploymentEnv, xt as resolveProjectScaffoldContext, y as getConvexDeploymentCommandEnv, yt as inspectPluginDependencyInstall, z as runBackendFunction } from "./backend-core-BA0CgHrL.mjs";
3
3
  import fs, { existsSync, readFileSync } from "node:fs";
4
4
  import path, { delimiter, dirname, join, relative, resolve } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
@@ -173,10 +173,18 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
173
173
  };
174
174
  }, Promise<any>>;
175
175
  deleteMany: convex_server0.RegisteredMutation<"internal", {
176
+ paginationOpts: {
177
+ id?: number;
178
+ endCursor?: string | null;
179
+ maximumRowsRead?: number;
180
+ maximumBytesRead?: number;
181
+ numItems: number;
182
+ cursor: string | null;
183
+ };
176
184
  input: {
177
185
  where?: {
186
+ operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
178
187
  connector?: "AND" | "OR" | undefined;
179
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
180
188
  value: string | number | boolean | string[] | number[] | null;
181
189
  field: string;
182
190
  }[] | undefined;
@@ -185,14 +193,6 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
185
193
  where?: any[] | undefined;
186
194
  model: string;
187
195
  };
188
- paginationOpts: {
189
- id?: number;
190
- endCursor?: string | null;
191
- maximumRowsRead?: number;
192
- maximumBytesRead?: number;
193
- numItems: number;
194
- cursor: string | null;
195
- };
196
196
  }, Promise<{
197
197
  count: number;
198
198
  ids: any[];
@@ -204,8 +204,8 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
204
204
  deleteOne: convex_server0.RegisteredMutation<"internal", {
205
205
  input: {
206
206
  where?: {
207
+ operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
207
208
  connector?: "AND" | "OR" | undefined;
208
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
209
209
  value: string | number | boolean | string[] | number[] | null;
210
210
  field: string;
211
211
  }[] | undefined;
@@ -216,21 +216,20 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
216
216
  };
217
217
  }, Promise<Record<string, unknown> | undefined>>;
218
218
  findMany: convex_server0.RegisteredQuery<"internal", {
219
+ limit?: number | undefined;
219
220
  join?: any;
220
221
  where?: {
221
222
  mode?: "sensitive" | "insensitive" | undefined;
223
+ operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
222
224
  connector?: "AND" | "OR" | undefined;
223
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
224
225
  value: string | number | boolean | string[] | number[] | null;
225
226
  field: string;
226
227
  }[] | undefined;
227
- limit?: number | undefined;
228
228
  offset?: number | undefined;
229
229
  sortBy?: {
230
230
  field: string;
231
231
  direction: "asc" | "desc";
232
232
  } | undefined;
233
- model: string;
234
233
  paginationOpts: {
235
234
  id?: number;
236
235
  endCursor?: string | null;
@@ -239,47 +238,48 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
239
238
  numItems: number;
240
239
  cursor: string | null;
241
240
  };
241
+ model: string;
242
242
  }, Promise<convex_server0.PaginationResult<convex_server0.GenericDocument>>>;
243
243
  findOne: convex_server0.RegisteredQuery<"internal", {
244
244
  join?: any;
245
- select?: string[] | undefined;
246
245
  where?: {
247
246
  mode?: "sensitive" | "insensitive" | undefined;
247
+ operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
248
248
  connector?: "AND" | "OR" | undefined;
249
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
250
249
  value: string | number | boolean | string[] | number[] | null;
251
250
  field: string;
252
251
  }[] | undefined;
252
+ select?: string[] | undefined;
253
253
  model: string;
254
254
  }, Promise<convex_server0.GenericDocument | null>>;
255
255
  getLatestJwks: convex_server0.RegisteredAction<"internal", {}, Promise<unknown>>;
256
256
  rotateKeys: convex_server0.RegisteredAction<"internal", {}, Promise<unknown>>;
257
257
  updateMany: convex_server0.RegisteredMutation<"internal", {
258
+ paginationOpts: {
259
+ id?: number;
260
+ endCursor?: string | null;
261
+ maximumRowsRead?: number;
262
+ maximumBytesRead?: number;
263
+ numItems: number;
264
+ cursor: string | null;
265
+ };
258
266
  input: {
259
267
  where?: {
268
+ operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
260
269
  connector?: "AND" | "OR" | undefined;
261
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
262
270
  value: string | number | boolean | string[] | number[] | null;
263
271
  field: string;
264
272
  }[] | undefined;
265
- model: string;
266
273
  update: {
267
274
  [x: string]: unknown;
268
275
  [x: number]: unknown;
269
276
  [x: symbol]: unknown;
270
277
  };
278
+ model: string;
271
279
  } | {
272
280
  where?: any[] | undefined;
273
- model: string;
274
281
  update: any;
275
- };
276
- paginationOpts: {
277
- id?: number;
278
- endCursor?: string | null;
279
- maximumRowsRead?: number;
280
- maximumBytesRead?: number;
281
- numItems: number;
282
- cursor: string | null;
282
+ model: string;
283
283
  };
284
284
  }, Promise<{
285
285
  count: number;
@@ -292,21 +292,21 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
292
292
  updateOne: convex_server0.RegisteredMutation<"internal", {
293
293
  input: {
294
294
  where?: {
295
+ operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
295
296
  connector?: "AND" | "OR" | undefined;
296
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
297
297
  value: string | number | boolean | string[] | number[] | null;
298
298
  field: string;
299
299
  }[] | undefined;
300
- model: string;
301
300
  update: {
302
301
  [x: string]: unknown;
303
302
  [x: number]: unknown;
304
303
  [x: symbol]: unknown;
305
304
  };
305
+ model: string;
306
306
  } | {
307
307
  where?: any[] | undefined;
308
- model: string;
309
308
  update: any;
309
+ model: string;
310
310
  };
311
311
  }, Promise<any>>;
312
312
  };
@@ -1,4 +1,4 @@
1
- import { $ as GenericOrmCtx$1, $n as unique, $r as endsWith, $t as ManyConfig, A as ConvexDateMode, An as ConvexRankIndexBuilder, Ar as ReturningResult, At as MigrationManifestEntry, B as ConvexBytesBuilderInitial, Bn as rankIndex, Br as OrmSchemaRelations, Bt as defineMigration, C as ConvexNumberBuilderInitial, Ci as ColumnBuilderWithTableName, Cn as RlsRole, Cr as MutationReturning, Ct as MigrationStatusArgs, D as id, Di as IsPrimaryKey, Dn as ConvexAggregateIndexBuilderOn, Dr as PaginatedResult, Dt as MigrationDoc, E as ConvexIdBuilderInitial, Ei as HasDefault, En as ConvexAggregateIndexBuilder, Er as OrderDirection, Et as MigrationDirection, F as custom, Fn as ConvexVectorIndexBuilder, Fr as unsetToken, Ft as MigrationStateMap, G as ConvexBigIntBuilder, Gn as ConvexCheckConfig, Gr as ExpressionVisitor, Gt as OrmReader$1, H as ConvexBooleanBuilder, Hn as uniqueIndex, Hr as TableName, Ht as detectMigrationDrift, I as json, In as ConvexVectorIndexBuilderOn, Ir as Brand, It as MigrationStep, J as CountBackfillChunkArgs, Jn as ConvexUniqueConstraintBuilder, Jr as LogicalExpression, Jt as RlsMode, K as ConvexBigIntBuilderInitial, Kn as ConvexForeignKeyBuilder, Kr as FieldReference, Kt as OrmWriter$1, L as objectOf, Ln as ConvexVectorIndexConfig, Lr as Columns, Lt as MigrationTableName, M as ConvexCustomBuilder, Mn as ConvexSearchIndexBuilder, Mr as UpdateSet, Mt as MigrationPlan, N as ConvexCustomBuilderInitial, Nn as ConvexSearchIndexBuilderOn, Nr as VectorQueryConfig, Nt as MigrationRunStatus, O as ConvexDateBuilder, Oi as IsUnique, On as ConvexIndexBuilder, Or as PredicateWhereIndexConfig, Ot as MigrationDocContext, P as arrayOf, Pn as ConvexSearchIndexConfig, Pr as VectorSearchProvider, Pt as MigrationSet, Q as GenericOrm$1, Qn as foreignKey, Qr as contains, Qt as ExtractTablesWithRelations, R as unionOf, Rn as aggregateIndex, Rr as OrmSchemaExtensionTables, Rt as MigrationWriteMode, S as ConvexNumberBuilder, Si as ColumnBuilderTypeConfig, Sn as rlsPolicy, Sr as MutationResult, St as MigrationRunChunkArgs, T as ConvexIdBuilder, Ti as DrizzleEntity, Tn as rlsRole, Tr as OrderByClause, Tt as MigrationDefinition, U as ConvexBooleanBuilderInitial, Un as vectorIndex, Ur as SystemFields, Ut as DatabaseWithMutations, V as bytes, Vn as searchIndex, Vr as OrmSchemaTriggers, Vt as defineMigrationSet, W as boolean, Wn as ConvexCheckBuilder, Wr as BinaryExpression, Wt as DatabaseWithQuery, X as CountBackfillStatusArgs, Xn as ConvexUniqueConstraintConfig, Xr as and, Xt as extractRelationsConfig, Y as CountBackfillKickoffArgs, Yn as ConvexUniqueConstraintBuilderOn, Yr as UnaryExpression, Yt as EdgeMetadata, Z as CreateOrmOptions, Zn as check, Zr as between, Zt as ExtractTablesFromSchema, _ as ConvexTimestampMode, _i as startsWith, _n as deletion, _r as MutationExecuteConfig, _t as OrmTriggerContext, a as requireSchemaRelations, ai as inArray, an as TablesRelationalConfig, ar as AggregateResult, at as OrmWriterCtx, b as ConvexTextEnumBuilderInitial, bi as ColumnBuilderBaseConfig, bn as RlsPolicyConfig, br as MutationPaginateConfig, bt as MigrationCancelArgs, c as TableConfigResult, ci as isNull, cn as ConvexDeletionBuilder, cr as CountConfig, ct as ScheduledMutationBatchArgs, d as OrmNotFoundError, di as lte, dn as ConvexTableWithColumns, dr as FilterOperators, dt as scheduledDeleteFactory, ei as eq, en as OneConfig, er as ConvexTextBuilder, et as OrmApiResult, f as ConvexVectorBuilder, fi as ne, fn as DiscriminatorBuilderConfig, fr as GetColumnData, ft as SchemaExtension, g as ConvexTimestampBuilderInitial, gi as or, gn as convexTable, gr as InsertValue, gt as OrmTriggerChange, h as ConvexTimestampBuilder, hi as notInArray, hn as TableConfig, hr as InferSelectModel, ht as OrmTableTriggers, i as getSchemaTriggers, ii as ilike, in as TableRelationalConfig, ir as AggregateFieldValue, it as OrmReaderCtx, j as date, jn as ConvexRankIndexBuilderOn, jr as ReturningSelection, jt as MigrationMigrateOne, k as ConvexDateBuilderInitial, ki as NotNull, kn as ConvexIndexBuilderOn, kr as ReturningAll, kt as MigrationDriftIssue, l as getTableColumns, li as like, ln as ConvexDeletionConfig, lr as CountResult, lt as scheduledMutationBatchFactory, m as vector, mi as notBetween, mn as OrmLifecycleOperation, mr as InferModelFromColumns, mt as OrmBeforeResult, n as defineSchema, ni as gt, nn as RelationsBuilderColumnBase, nr as text, nt as OrmClientWithApi$1, o as asc, oi as isFieldReference, on as defineRelations, or as BuildQueryResult, ot as ResolveOrmSchema, p as ConvexVectorBuilderInitial, pi as not, pn as OrmLifecycleChange, pr as InferInsertModel, pt as defineSchemaExtension, q as bigint, qn as ConvexForeignKeyConfig, qr as FilterExpression, qt as RlsContext, r as getSchemaRelations, ri as gte, rn as RelationsBuilderColumnConfig, rr as AggregateConfig, rt as OrmFunctions, s as desc, si as isNotNull, sn as defineRelationsPart, sr as BuildRelationResult, st as createOrm, t as WhereClauseResult, ti as fieldRef, tn as RelationsBuilder, tr as ConvexTextBuilderInitial, tt as OrmClientBase$1, u as getTableConfig, ui as lt, un as ConvexTable, ur as DBQueryConfig, ut as ScheduledDeleteArgs, v as timestamp, vi as AnyColumn, vn as discriminator, vr as MutationExecuteResult, vt as OrmTriggers, w as integer, wi as ColumnDataType, wn as RlsRoleConfig, wr as MutationRunMode, wt as MigrationAppliedState, x as textEnum, xi as ColumnBuilderRuntimeConfig, xn as RlsPolicyToOption, xr as MutationPaginatedResult, xt as MigrationRunArgs, y as ConvexTextEnumBuilder, yi as ColumnBuilder, yn as RlsPolicy, yr as MutationExecutionMode, yt as defineTriggers, z as ConvexBytesBuilder, zn as index, zr as OrmSchemaExtensions, zt as buildMigrationPlan } from "../where-clause-compiler-DcEhkJ12.js";
1
+ import { $ as GenericOrmCtx$1, $n as unique, $r as endsWith, $t as ManyConfig, A as ConvexDateMode, An as ConvexRankIndexBuilder, Ar as ReturningResult, At as MigrationManifestEntry, B as ConvexBytesBuilderInitial, Bn as rankIndex, Br as OrmSchemaRelations, Bt as defineMigration, C as ConvexNumberBuilderInitial, Ci as ColumnBuilderWithTableName, Cn as RlsRole, Cr as MutationReturning, Ct as MigrationStatusArgs, D as id, Di as IsPrimaryKey, Dn as ConvexAggregateIndexBuilderOn, Dr as PaginatedResult, Dt as MigrationDoc, E as ConvexIdBuilderInitial, Ei as HasDefault, En as ConvexAggregateIndexBuilder, Er as OrderDirection, Et as MigrationDirection, F as custom, Fn as ConvexVectorIndexBuilder, Fr as unsetToken, Ft as MigrationStateMap, G as ConvexBigIntBuilder, Gn as ConvexCheckConfig, Gr as ExpressionVisitor, Gt as OrmReader$1, H as ConvexBooleanBuilder, Hn as uniqueIndex, Hr as TableName, Ht as detectMigrationDrift, I as json, In as ConvexVectorIndexBuilderOn, Ir as Brand, It as MigrationStep, J as CountBackfillChunkArgs, Jn as ConvexUniqueConstraintBuilder, Jr as LogicalExpression, Jt as RlsMode, K as ConvexBigIntBuilderInitial, Kn as ConvexForeignKeyBuilder, Kr as FieldReference, Kt as OrmWriter$1, L as objectOf, Ln as ConvexVectorIndexConfig, Lr as Columns, Lt as MigrationTableName, M as ConvexCustomBuilder, Mn as ConvexSearchIndexBuilder, Mr as UpdateSet, Mt as MigrationPlan, N as ConvexCustomBuilderInitial, Nn as ConvexSearchIndexBuilderOn, Nr as VectorQueryConfig, Nt as MigrationRunStatus, O as ConvexDateBuilder, Oi as IsUnique, On as ConvexIndexBuilder, Or as PredicateWhereIndexConfig, Ot as MigrationDocContext, P as arrayOf, Pn as ConvexSearchIndexConfig, Pr as VectorSearchProvider, Pt as MigrationSet, Q as GenericOrm$1, Qn as foreignKey, Qr as contains, Qt as ExtractTablesWithRelations, R as unionOf, Rn as aggregateIndex, Rr as OrmSchemaExtensionTables, Rt as MigrationWriteMode, S as ConvexNumberBuilder, Si as ColumnBuilderTypeConfig, Sn as rlsPolicy, Sr as MutationResult, St as MigrationRunChunkArgs, T as ConvexIdBuilder, Ti as DrizzleEntity, Tn as rlsRole, Tr as OrderByClause, Tt as MigrationDefinition, U as ConvexBooleanBuilderInitial, Un as vectorIndex, Ur as SystemFields, Ut as DatabaseWithMutations, V as bytes, Vn as searchIndex, Vr as OrmSchemaTriggers, Vt as defineMigrationSet, W as boolean, Wn as ConvexCheckBuilder, Wr as BinaryExpression, Wt as DatabaseWithQuery, X as CountBackfillStatusArgs, Xn as ConvexUniqueConstraintConfig, Xr as and, Xt as extractRelationsConfig, Y as CountBackfillKickoffArgs, Yn as ConvexUniqueConstraintBuilderOn, Yr as UnaryExpression, Yt as EdgeMetadata, Z as CreateOrmOptions, Zn as check, Zr as between, Zt as ExtractTablesFromSchema, _ as ConvexTimestampMode, _i as startsWith, _n as deletion, _r as MutationExecuteConfig, _t as OrmTriggerContext, a as requireSchemaRelations, ai as inArray, an as TablesRelationalConfig, ar as AggregateResult, at as OrmWriterCtx, b as ConvexTextEnumBuilderInitial, bi as ColumnBuilderBaseConfig, bn as RlsPolicyConfig, br as MutationPaginateConfig, bt as MigrationCancelArgs, c as TableConfigResult, ci as isNull, cn as ConvexDeletionBuilder, cr as CountConfig, ct as ScheduledMutationBatchArgs, d as OrmNotFoundError, di as lte, dn as ConvexTableWithColumns, dr as FilterOperators, dt as scheduledDeleteFactory, ei as eq, en as OneConfig, er as ConvexTextBuilder, et as OrmApiResult, f as ConvexVectorBuilder, fi as ne, fn as DiscriminatorBuilderConfig, fr as GetColumnData, ft as SchemaExtension, g as ConvexTimestampBuilderInitial, gi as or, gn as convexTable, gr as InsertValue, gt as OrmTriggerChange, h as ConvexTimestampBuilder, hi as notInArray, hn as TableConfig, hr as InferSelectModel, ht as OrmTableTriggers, i as getSchemaTriggers, ii as ilike, in as TableRelationalConfig, ir as AggregateFieldValue, it as OrmReaderCtx, j as date, jn as ConvexRankIndexBuilderOn, jr as ReturningSelection, jt as MigrationMigrateOne, k as ConvexDateBuilderInitial, ki as NotNull, kn as ConvexIndexBuilderOn, kr as ReturningAll, kt as MigrationDriftIssue, l as getTableColumns, li as like, ln as ConvexDeletionConfig, lr as CountResult, lt as scheduledMutationBatchFactory, m as vector, mi as notBetween, mn as OrmLifecycleOperation, mr as InferModelFromColumns, mt as OrmBeforeResult, n as defineSchema, ni as gt, nn as RelationsBuilderColumnBase, nr as text, nt as OrmClientWithApi$1, o as asc, oi as isFieldReference, on as defineRelations, or as BuildQueryResult, ot as ResolveOrmSchema, p as ConvexVectorBuilderInitial, pi as not, pn as OrmLifecycleChange, pr as InferInsertModel, pt as defineSchemaExtension, q as bigint, qn as ConvexForeignKeyConfig, qr as FilterExpression, qt as RlsContext, r as getSchemaRelations, ri as gte, rn as RelationsBuilderColumnConfig, rr as AggregateConfig, rt as OrmFunctions, s as desc, si as isNotNull, sn as defineRelationsPart, sr as BuildRelationResult, st as createOrm, t as WhereClauseResult, ti as fieldRef, tn as RelationsBuilder, tr as ConvexTextBuilderInitial, tt as OrmClientBase$1, u as getTableConfig, ui as lt, un as ConvexTable, ur as DBQueryConfig, ut as ScheduledDeleteArgs, v as timestamp, vi as AnyColumn, vn as discriminator, vr as MutationExecuteResult, vt as OrmTriggers, w as integer, wi as ColumnDataType, wn as RlsRoleConfig, wr as MutationRunMode, wt as MigrationAppliedState, x as textEnum, xi as ColumnBuilderRuntimeConfig, xn as RlsPolicyToOption, xr as MutationPaginatedResult, xt as MigrationRunArgs, y as ConvexTextEnumBuilder, yi as ColumnBuilder, yn as RlsPolicy, yr as MutationExecutionMode, yt as defineTriggers, z as ConvexBytesBuilder, zn as index, zr as OrmSchemaExtensions, zt as buildMigrationPlan } from "../where-clause-compiler-Dv-3mnJF.js";
2
2
  import { i as pretendRequired, n as deprecated, r as pretend } from "../validators-BhsByJeg.js";
3
3
  import { a as QueryCtxWithPreferredOrmQueryTable, i as QueryCtxWithOrmQueryTable, n as LookupByIdResultByCtx, o as getByIdWithOrmQueryFallback, r as QueryCtxWithOptionalOrmQueryTable, t as DocByCtx } from "../query-context-CNo9ffvI.js";
4
4
  import { DefineSchemaOptions, GenericDatabaseReader, GenericDatabaseWriter, GenericSchema, SchemaDefinition } from "convex/server";
@@ -4,8 +4,13 @@ import { z } from "zod";
4
4
 
5
5
  //#region src/server/env.ts
6
6
  function createEnv(options) {
7
- const { schema, runtimeEnv, cache = true, codegenFallback = false } = options;
7
+ const { schema, runtimeEnv, cache = true, codegenFallback = false, readOptionalRuntimeEnv = [] } = options;
8
+ const directOptionalKeys = new Set(readOptionalRuntimeEnv);
8
9
  let cached;
10
+ const createInvalidEnvError = () => new CRPCError({
11
+ code: "INTERNAL_SERVER_ERROR",
12
+ message: "Invalid environment variables"
13
+ });
9
14
  return () => {
10
15
  if (cache && cached) return cached;
11
16
  const isCodegenParse = globalThis.__KITCN_CODEGEN__ === true || codegenFallback;
@@ -14,6 +19,11 @@ function createEnv(options) {
14
19
  for (const [key, zodType] of Object.entries(schema.shape)) {
15
20
  const undefinedParse = zodType.safeParse(void 0);
16
21
  if (undefinedParse.success) {
22
+ if (directOptionalKeys.has(key)) {
23
+ if (Object.hasOwn(runtimeEnvSource, key) || Object.getOwnPropertyDescriptor(runtimeEnvSource, key) !== void 0 || key in runtimeEnvSource) runtimeEnvSnapshot[key] = runtimeEnvSource[key];
24
+ else if (!isCodegenParse && undefinedParse.data !== void 0) runtimeEnvSnapshot[key] = runtimeEnvSource[key];
25
+ continue;
26
+ }
17
27
  if (Object.hasOwn(runtimeEnvSource, key) || Object.getOwnPropertyDescriptor(runtimeEnvSource, key) !== void 0 || key in runtimeEnvSource) runtimeEnvSnapshot[key] = runtimeEnvSource[key];
18
28
  else if (!isCodegenParse && undefinedParse.data !== void 0) runtimeEnvSnapshot[key] = runtimeEnvSource[key];
19
29
  continue;
@@ -32,10 +42,22 @@ function createEnv(options) {
32
42
  ...Object.fromEntries(Object.entries(runtimeEnvSnapshot).filter(([, value]) => value !== void 0))
33
43
  } : runtimeEnvSnapshot;
34
44
  const parsed = schema.safeParse(envForParse);
35
- if (!parsed.success) throw new CRPCError({
36
- code: "INTERNAL_SERVER_ERROR",
37
- message: "Invalid environment variables"
38
- });
45
+ if (!parsed.success) throw createInvalidEnvError();
46
+ const parsedData = parsed.data;
47
+ for (const key of directOptionalKeys) {
48
+ if (!(key in schema.shape) || parsedData[key] !== void 0) continue;
49
+ Object.defineProperty(parsedData, key, {
50
+ configurable: true,
51
+ enumerable: true,
52
+ get: () => {
53
+ const value = runtimeEnvSource[key];
54
+ if (value === void 0) return;
55
+ const result = schema.shape[key].safeParse(value);
56
+ if (!result.success) throw createInvalidEnvError();
57
+ return result.data;
58
+ }
59
+ });
60
+ }
39
61
  if (cache) cached = parsed.data;
40
62
  return parsed.data;
41
63
  };