kitcn 0.13.6 → 0.13.8
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.
package/dist/auth/index.js
CHANGED
|
@@ -319,6 +319,34 @@ const resolveSchemaTableName = (schema, betterAuthSchema, model) => {
|
|
|
319
319
|
if (schema.tables[value.modelName]) return value.modelName;
|
|
320
320
|
}
|
|
321
321
|
};
|
|
322
|
+
const AUTH_TIMESTAMP_FIELDS = ["createdAt", "updatedAt"];
|
|
323
|
+
const resolveBetterAuthModel = (betterAuthSchema, model) => {
|
|
324
|
+
if (betterAuthSchema?.[model]) return betterAuthSchema[model];
|
|
325
|
+
return Object.values(betterAuthSchema ?? {}).find((value) => value?.modelName === model);
|
|
326
|
+
};
|
|
327
|
+
const resolveWriteFields = (schema, betterAuthSchema, model) => {
|
|
328
|
+
const tableName = resolveSchemaTableName(schema, betterAuthSchema, model);
|
|
329
|
+
const validatorFields = tableName ? schema.tables[tableName]?.validator?.fields : void 0;
|
|
330
|
+
if (validatorFields) return new Set(Object.keys(validatorFields));
|
|
331
|
+
const modelFields = resolveBetterAuthModel(betterAuthSchema, model)?.fields;
|
|
332
|
+
if (!modelFields) return;
|
|
333
|
+
const fields = /* @__PURE__ */ new Set();
|
|
334
|
+
for (const [field, config] of Object.entries(modelFields)) {
|
|
335
|
+
fields.add(field);
|
|
336
|
+
if (typeof config?.fieldName === "string") fields.add(config.fieldName);
|
|
337
|
+
}
|
|
338
|
+
return fields;
|
|
339
|
+
};
|
|
340
|
+
const stripUnsupportedAuthTimestamps = (data, schema, betterAuthSchema, model) => {
|
|
341
|
+
const writeFields = resolveWriteFields(schema, betterAuthSchema, model);
|
|
342
|
+
if (!writeFields) return data;
|
|
343
|
+
let result;
|
|
344
|
+
for (const field of AUTH_TIMESTAMP_FIELDS) if (field in data && !writeFields.has(field)) {
|
|
345
|
+
result ??= { ...data };
|
|
346
|
+
delete result[field];
|
|
347
|
+
}
|
|
348
|
+
return result ?? data;
|
|
349
|
+
};
|
|
322
350
|
const resolveOrmTable = (ctx, schema, betterAuthSchema, model) => {
|
|
323
351
|
if (!ctx?.orm || typeof ctx.orm.insert !== "function" || typeof ctx.orm.update !== "function" || typeof ctx.orm.delete !== "function") return;
|
|
324
352
|
const tableName = resolveSchemaTableName(schema, betterAuthSchema, model);
|
|
@@ -418,19 +446,23 @@ const serializeDatesForConvex = (value) => {
|
|
|
418
446
|
return serialized ?? value;
|
|
419
447
|
};
|
|
420
448
|
const toConvexSafe = (value) => serializeDatesForConvex(value);
|
|
421
|
-
const withAuthTimestamps = (data) => {
|
|
422
|
-
|
|
449
|
+
const withAuthTimestamps = (data, schema, betterAuthSchema, model) => {
|
|
450
|
+
const writeFields = resolveWriteFields(schema, betterAuthSchema, model);
|
|
451
|
+
if (data.createdAt !== void 0) return stripUnsupportedAuthTimestamps(data, schema, betterAuthSchema, model);
|
|
452
|
+
const supportsCreatedAt = !writeFields || writeFields.has("createdAt");
|
|
453
|
+
const supportsUpdatedAt = !writeFields || writeFields.has("updatedAt");
|
|
454
|
+
if (!(supportsCreatedAt || supportsUpdatedAt)) return data;
|
|
423
455
|
const now = Date.now();
|
|
424
|
-
return {
|
|
456
|
+
return stripUnsupportedAuthTimestamps({
|
|
425
457
|
...data,
|
|
426
|
-
createdAt: now,
|
|
427
|
-
...data.updatedAt === void 0 ? { updatedAt: now } : {}
|
|
428
|
-
};
|
|
458
|
+
...supportsCreatedAt ? { createdAt: now } : {},
|
|
459
|
+
...supportsUpdatedAt && data.updatedAt === void 0 ? { updatedAt: now } : {}
|
|
460
|
+
}, schema, betterAuthSchema, model);
|
|
429
461
|
};
|
|
430
462
|
const createHandler = async (ctx, args, schema, betterAuthSchema) => {
|
|
431
463
|
const triggerCtx = args.triggerCtx ?? ctx;
|
|
432
464
|
const tableTriggers = args.tableTriggers;
|
|
433
|
-
const data = serializeDatesForConvex(withAuthTimestamps(await applyBeforeHook(args.input.model, "create", args.input.data, tableTriggers?.create?.before, triggerCtx)));
|
|
465
|
+
const data = serializeDatesForConvex(withAuthTimestamps(await applyBeforeHook(args.input.model, "create", args.input.data, tableTriggers?.create?.before, triggerCtx), schema, betterAuthSchema, args.input.model));
|
|
434
466
|
await checkUniqueFields(ctx, schema, betterAuthSchema, args.input.model, data);
|
|
435
467
|
const ormTable = resolveOrmTable(ctx, schema, betterAuthSchema, args.input.model);
|
|
436
468
|
const doc = ormTable ? await ormInsert(ctx, ormTable.table, data) : await (async () => {
|
|
@@ -459,7 +491,7 @@ const updateOneHandler = async (ctx, args, schema, betterAuthSchema) => {
|
|
|
459
491
|
const doc = await listOne(ctx, schema, betterAuthSchema, args.input);
|
|
460
492
|
if (!doc) throw new Error(`Failed to update ${args.input.model}`);
|
|
461
493
|
const normalizedDoc = withBothIdFields(doc);
|
|
462
|
-
const update = serializeDatesForConvex(await applyBeforeHook(args.input.model, "update", args.input.update, tableTriggers?.update?.before, triggerCtx));
|
|
494
|
+
const update = stripUnsupportedAuthTimestamps(serializeDatesForConvex(await applyBeforeHook(args.input.model, "update", args.input.update, tableTriggers?.update?.before, triggerCtx)), schema, betterAuthSchema, args.input.model);
|
|
463
495
|
await checkUniqueFields(ctx, schema, betterAuthSchema, args.input.model, update, normalizedDoc);
|
|
464
496
|
const ormTable = resolveOrmTable(ctx, schema, betterAuthSchema, args.input.model);
|
|
465
497
|
const updatedDoc = ormTable ? await ormUpdate(ctx, ormTable.table, normalizedDoc._id, update) : await (async () => {
|
|
@@ -492,7 +524,7 @@ const updateManyHandler = async (ctx, args, schema, betterAuthSchema) => {
|
|
|
492
524
|
if (hasUniqueFields(betterAuthSchema, args.input.model, args.input.update ?? {}) && page.length > 1) throw new Error(`Attempted to set unique fields in multiple documents in ${args.input.model} with the same value. Fields: ${Object.keys(args.input.update ?? {}).join(", ")}`);
|
|
493
525
|
await asyncMap(page, async (doc) => {
|
|
494
526
|
const normalizedDoc = withBothIdFields(doc);
|
|
495
|
-
const update = serializeDatesForConvex(await applyBeforeHook(args.input.model, "update", args.input.update ?? {}, tableTriggers?.update?.before, triggerCtx));
|
|
527
|
+
const update = stripUnsupportedAuthTimestamps(serializeDatesForConvex(await applyBeforeHook(args.input.model, "update", args.input.update ?? {}, tableTriggers?.update?.before, triggerCtx)), schema, betterAuthSchema, args.input.model);
|
|
496
528
|
await checkUniqueFields(ctx, schema, betterAuthSchema, args.input.model, update ?? {}, normalizedDoc);
|
|
497
529
|
const hookNewDoc = serializeDatesForConvex(withBothIdFields(ormTable ? await ormUpdate(ctx, ormTable.table, normalizedDoc._id, update ?? {}) : await (async () => {
|
|
498
530
|
await ctx.db.patch(normalizedDoc._id, update);
|
|
@@ -10089,6 +10089,7 @@ const AUTH_CONVEX_HTTP_ROUTER_RE = /const\s+http\s*=\s*httpRouter\(\);?/;
|
|
|
10089
10089
|
const AUTH_CONVEX_HTTP_IMPORT_RE = /from\s+['"]kitcn\/auth\/http['"]/;
|
|
10090
10090
|
const AUTH_CONVEX_HTTP_GET_AUTH_IMPORT_RE = /from\s+['"]\.\/generated\/auth['"]/;
|
|
10091
10091
|
const AUTH_CONVEX_SCHEMA_CALL_RE = /defineSchema\(\s*\{/;
|
|
10092
|
+
const AUTH_CONVEX_SCHEMA_AUTH_SCHEMA_IMPORT_RE = /import\s+\{\s*authSchema\s*\}\s+from\s+['"]\.\/authSchema['"];?/;
|
|
10092
10093
|
const AUTH_CONVEX_APP_IMPORT_RE = /import App from ['"][^'"]+['"];?/;
|
|
10093
10094
|
const AUTH_CONVEX_PROVIDER_IMPORT_RE = /import\s+\{\s*ConvexProvider,\s*ConvexReactClient\s*\}\s+from\s+['"]convex\/react['"];?/;
|
|
10094
10095
|
const AUTH_PROVIDER_REACT_NODE_IMPORT_RE = /import\s+type\s+\{\s*ReactNode\s*\}\s+from\s+['"]react['"];?/;
|
|
@@ -10428,7 +10429,7 @@ export default http;
|
|
|
10428
10429
|
function buildAuthConvexSchemaPlanFile(params) {
|
|
10429
10430
|
const schemaPath = getSchemaFilePath(params.functionsDir);
|
|
10430
10431
|
let source = fs.readFileSync(schemaPath, "utf8");
|
|
10431
|
-
if (!
|
|
10432
|
+
if (!AUTH_CONVEX_SCHEMA_AUTH_SCHEMA_IMPORT_RE.test(source)) source = `import { authSchema } from './authSchema';\n${source}`;
|
|
10432
10433
|
if (!source.includes("...authSchema")) source = source.replace(AUTH_CONVEX_SCHEMA_CALL_RE, (match) => `${match}\n ...authSchema,`);
|
|
10433
10434
|
return createPlanFile({
|
|
10434
10435
|
kind: "schema",
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { $ as promptForScaffoldTemplateSelection, A as resolveCodegenTrimSegments, B as runConfiguredCodegen, C as isEntryPoint, Ct as serializeEnvValue, D as parseInitCommandArgs, Dt as logger, E as parseBackendRunJson, 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, Ot as highlighter, P as resolveMigrationConfig, Q as promptForPluginSelection, R as runAggregatePruneFlow, S as isConvexDevPreRunConflictFlag, St as resolveAuthEnvState, T as parseArgs, 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, 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 stripConvexCommandNoise, x as hasRemoteConvexDeploymentEnv, xt as resolveProjectScaffoldContext, y as getConvexDeploymentCommandEnv, yt as inspectPluginDependencyInstall, z as runBackendFunction } from "./backend-core-
|
|
2
|
+
import { $ as promptForScaffoldTemplateSelection, A as resolveCodegenTrimSegments, B as runConfiguredCodegen, C as isEntryPoint, Ct as serializeEnvValue, D as parseInitCommandArgs, Dt as logger, E as parseBackendRunJson, 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, Ot as highlighter, P as resolveMigrationConfig, Q as promptForPluginSelection, R as runAggregatePruneFlow, S as isConvexDevPreRunConflictFlag, St as resolveAuthEnvState, T as parseArgs, 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, 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 stripConvexCommandNoise, x as hasRemoteConvexDeploymentEnv, xt as resolveProjectScaffoldContext, y as getConvexDeploymentCommandEnv, yt as inspectPluginDependencyInstall, z as runBackendFunction } from "./backend-core-s2N3CTN-.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";
|
package/dist/watcher.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Dt as logger, Et as getConvexConfig, F as resolveRunDeps, Tt as generateMeta, j as resolveConfiguredBackend, q as withLocalCodegenEnv } from "./backend-core-
|
|
2
|
+
import { Dt as logger, Et as getConvexConfig, F as resolveRunDeps, Tt as generateMeta, j as resolveConfiguredBackend, q as withLocalCodegenEnv } from "./backend-core-s2N3CTN-.mjs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
|