convex-helpers
Advanced tools
Comparing version 0.1.34-alpha.0 to 0.1.34-alpha.1
@@ -62,3 +62,3 @@ /** | ||
declare const error: unique symbol; | ||
export type TypeError<Reason extends string> = Reason & { | ||
export type ErrorMessage<Reason extends string> = Reason & { | ||
__error: typeof error; | ||
@@ -65,0 +65,0 @@ }; |
@@ -26,3 +26,3 @@ /** | ||
import { GenericId, ObjectType } from "convex/values"; | ||
import { TypeError } from "../index.js"; | ||
import { ErrorMessage } from "../index.js"; | ||
export declare const DEFAULT_BATCH_SIZE = 100; | ||
@@ -66,3 +66,3 @@ declare const migrationsFields: { | ||
type MigrationTableNames<DataModel extends GenericDataModel> = { | ||
[K in TableNamesInDataModel<DataModel>]: DocumentByInfo<NamedTableInfo<DataModel, K>> extends MigrationMetadata ? K : TypeError<"Add migrationsTable to your schema">; | ||
[K in TableNamesInDataModel<DataModel>]: DocumentByInfo<NamedTableInfo<DataModel, K>> extends MigrationMetadata ? K : ErrorMessage<"Add migrationsTable to your schema">; | ||
}[TableNamesInDataModel<DataModel>]; | ||
@@ -69,0 +69,0 @@ /** |
@@ -27,2 +27,3 @@ /** | ||
import { asyncMap } from "../index.js"; | ||
import { pretendRequired } from "../validators.js"; | ||
export const DEFAULT_BATCH_SIZE = 100; | ||
@@ -45,3 +46,3 @@ // To be imported if you want to declare it in your schema (optional). | ||
const migrationArgs = { | ||
fn: v.string(), | ||
fn: pretendRequired(v.string()), | ||
cursor: v.optional(v.union(v.string(), v.null())), | ||
@@ -112,10 +113,11 @@ batchSize: v.optional(v.number()), | ||
* # Restart a migration from a cursor (null is from the beginning): | ||
* '{fn: "migrations:foo", cursor: null }' | ||
* npx convex run migrations:myMigration '{fn: "migrations:foo", cursor: null }' | ||
* | ||
* # Dry run - runs one batch but doesn't schedule or commit changes. | ||
* # so you can see what it would do without committing the transaction. | ||
* '{fn: "migrations:foo", dryRun: true }' | ||
* npx convex run migrations:myMigration '{ dryRun: true }' | ||
* | ||
* # Run many migrations serially: | ||
* '{fn: "migrations:foo", next: ["migrations:bar", "migrations:baz"] }' | ||
* npx convex run migrations:myMigration '{fn: "migrations:foo", \ | ||
* next: ["migrations:bar", "migrations:baz"] }' | ||
* ``` | ||
@@ -130,6 +132,7 @@ * | ||
* | ||
* await startMigration(ctx, internal.migrations.myMigration, { | ||
* startCursor: null, // optional override | ||
* batchSize: 10, // optional override | ||
* }); | ||
* // in a mutation or action: | ||
* await startMigration(ctx, internal.migrations.myMigration, { | ||
* startCursor: null, // optional override | ||
* batchSize: 10, // optional override | ||
* }); | ||
* ``` | ||
@@ -141,6 +144,7 @@ * | ||
* | ||
* await startMigrationsSerially(ctx, [ | ||
* internal.migrations.myMigration, | ||
* internal.migrations.myOtherMigration, | ||
* ]); | ||
* // in a mutation or action: | ||
* await startMigrationsSerially(ctx, [ | ||
* internal.migrations.myMigration, | ||
* internal.migrations.myOtherMigration, | ||
* ]); | ||
* | ||
@@ -179,4 +183,4 @@ * It runs one batch at a time currently. | ||
} | ||
if (args.fn === "" && !args.dryRun) { | ||
// We allow passing an empty string for dry runs. | ||
if (!args.fn && !args.dryRun) { | ||
// We allow omitting fn for dry runs. | ||
// They don't need to recursively schedule. | ||
@@ -183,0 +187,0 @@ throw new Error("fn must be set if dryRun: false."); |
@@ -102,3 +102,3 @@ /** | ||
const error = Symbol(); | ||
export type TypeError<Reason extends string> = Reason & { | ||
export type ErrorMessage<Reason extends string> = Reason & { | ||
__error: typeof error; | ||
@@ -105,0 +105,0 @@ }; |
{ | ||
"name": "convex-helpers", | ||
"version": "0.1.34-alpha.0", | ||
"version": "0.1.34-alpha.1", | ||
"description": "A collection of useful code to complement the official convex package.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -44,3 +44,4 @@ /** | ||
import { GenericId, ObjectType, v } from "convex/values"; | ||
import { asyncMap, TypeError } from "../index.js"; | ||
import { asyncMap, ErrorMessage } from "../index.js"; | ||
import { pretendRequired } from "../validators.js"; | ||
@@ -71,3 +72,3 @@ export const DEFAULT_BATCH_SIZE = 100; | ||
const migrationArgs = { | ||
fn: v.string(), | ||
fn: pretendRequired(v.string()), | ||
cursor: v.optional(v.union(v.string(), v.null())), | ||
@@ -86,3 +87,3 @@ batchSize: v.optional(v.number()), | ||
? K | ||
: TypeError<"Add migrationsTable to your schema">; | ||
: ErrorMessage<"Add migrationsTable to your schema">; | ||
}[TableNamesInDataModel<DataModel>]; | ||
@@ -159,10 +160,11 @@ | ||
* # Restart a migration from a cursor (null is from the beginning): | ||
* '{fn: "migrations:foo", cursor: null }' | ||
* npx convex run migrations:myMigration '{fn: "migrations:foo", cursor: null }' | ||
* | ||
* # Dry run - runs one batch but doesn't schedule or commit changes. | ||
* # so you can see what it would do without committing the transaction. | ||
* '{fn: "migrations:foo", dryRun: true }' | ||
* npx convex run migrations:myMigration '{ dryRun: true }' | ||
* | ||
* # Run many migrations serially: | ||
* '{fn: "migrations:foo", next: ["migrations:bar", "migrations:baz"] }' | ||
* npx convex run migrations:myMigration '{fn: "migrations:foo", \ | ||
* next: ["migrations:bar", "migrations:baz"] }' | ||
* ``` | ||
@@ -177,6 +179,7 @@ * | ||
* | ||
* await startMigration(ctx, internal.migrations.myMigration, { | ||
* startCursor: null, // optional override | ||
* batchSize: 10, // optional override | ||
* }); | ||
* // in a mutation or action: | ||
* await startMigration(ctx, internal.migrations.myMigration, { | ||
* startCursor: null, // optional override | ||
* batchSize: 10, // optional override | ||
* }); | ||
* ``` | ||
@@ -188,6 +191,7 @@ * | ||
* | ||
* await startMigrationsSerially(ctx, [ | ||
* internal.migrations.myMigration, | ||
* internal.migrations.myOtherMigration, | ||
* ]); | ||
* // in a mutation or action: | ||
* await startMigrationsSerially(ctx, [ | ||
* internal.migrations.myMigration, | ||
* internal.migrations.myOtherMigration, | ||
* ]); | ||
* | ||
@@ -245,4 +249,4 @@ * It runs one batch at a time currently. | ||
} | ||
if (args.fn === "" && !args.dryRun) { | ||
// We allow passing an empty string for dry runs. | ||
if (!args.fn && !args.dryRun) { | ||
// We allow omitting fn for dry runs. | ||
// They don't need to recursively schedule. | ||
@@ -249,0 +253,0 @@ throw new Error("fn must be set if dryRun: false."); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
493132
8974