Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "plugin-drizzle: add idColumn map support with validation and fix cleanup errors",
"packageName": "@apibara/plugin-drizzle",
"email": "jadejajaipal5@gmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "plugin-mongo: move cleanup part after initialization",
"packageName": "@apibara/plugin-mongo",
"email": "jadejajaipal5@gmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "add cleanup logic and add indexerId relation to KV Store",
"packageName": "@apibara/plugin-sqlite",
"email": "jadejajaipal5@gmail.com",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions change/apibara-34f7f808-dcf6-45ec-bbe4-5e74b0193361.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "cli: fix dev reload, change flag names, args validation, bump drizzle-orm version in template",
"packageName": "apibara",
"email": "jadejajaipal5@gmail.com",
"dependentChangeType": "patch"
}
4 changes: 3 additions & 1 deletion examples/cli-drizzle/indexers/2-starknet.indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export default function (runtimeConfig: ApibaraRuntimeConfig) {
plugins: [
drizzleStorage({
db: database,
idColumn: "_id",
idColumn: {
"*": "_id",
},
persistState: true,
indexerName: "starknet-usdc-transfers",
migrate: {
Expand Down
2 changes: 1 addition & 1 deletion examples/cli-drizzle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@apibara/starknet": "workspace:*",
"@electric-sql/pglite": "^0.2.17",
"apibara": "workspace:*",
"drizzle-orm": "^0.37.0",
"drizzle-orm": "^0.40.1",
"pg": "^8.13.1",
"starknet": "^6.11.0",
"viem": "^2.21.53"
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/cli/commands/add.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { addIndexer } from "apibara/create";
import { defineCommand } from "citty";
import { checkForUnknownArgs } from "../common";

export default defineCommand({
meta: {
Expand Down Expand Up @@ -35,7 +36,9 @@ export default defineCommand({
"Root directory - apibara project root where apibara.config is located | default: current working directory",
},
},
async run({ args }) {
async run({ args, cmd }) {
await checkForUnknownArgs(args, cmd);

const { indexerId, chain, network, storage, dnaUrl, dir } = args;

await addIndexer({
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { build, createApibara, prepare, writeTypes } from "apibara/core";
import { runtimeDir } from "apibara/runtime/meta";
import { defineCommand } from "citty";
import { join, resolve } from "pathe";
import { commonArgs } from "../common";
import { checkForUnknownArgs, commonArgs } from "../common";

export default defineCommand({
meta: {
Expand All @@ -12,8 +12,11 @@ export default defineCommand({
args: {
...commonArgs,
},
async run({ args }) {
async run({ args, cmd }) {
await checkForUnknownArgs(args, cmd);

const rootDir = resolve((args.dir || args._dir || ".") as string);

const apibara = await createApibara({
rootDir,
});
Expand Down
13 changes: 7 additions & 6 deletions packages/cli/src/cli/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Apibara } from "apibara/types";
import { defineCommand } from "citty";
import { colors } from "consola/utils";
import { join, resolve } from "pathe";
import { commonArgs } from "../common";
import { checkForUnknownArgs, commonArgs } from "../common";

// Hot module reloading key regex
// for only runtimeConfig.* keys
Expand All @@ -26,17 +26,19 @@ export default defineCommand({
type: "string",
description: "Preset to use",
},
alwaysReindex: {
"always-reindex": {
type: "boolean",
default: false,
description:
"Reindex the indexers from the starting block on every restart (default: false)",
"Reindex the indexers from the starting block on every restart | default: `false`",
},
},
async run({ args }) {
async run({ args, data, cmd, rawArgs }) {
await checkForUnknownArgs(args, cmd);

const rootDir = resolve((args.dir || args._dir || ".") as string);

if (args.alwaysReindex) {
if (args["always-reindex"]) {
process.env.APIBARA_ALWAYS_REINDEX = "true";
}

Expand Down Expand Up @@ -125,7 +127,6 @@ export default defineCommand({
code !== null ? ` with code ${colors.red(code)}` : ""
}`,
);
process.exit(code ?? 0);
});
});
};
Expand Down
19 changes: 12 additions & 7 deletions packages/cli/src/cli/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { initializeProject } from "apibara/create";
import { defineCommand } from "citty";
import { checkForUnknownArgs } from "../common";

export default defineCommand({
meta: {
Expand All @@ -14,23 +15,27 @@ export default defineCommand({
},
language: {
type: "string",
description: "Language to use: typescript, ts or javascript, js",
description:
"Language to use: typescript, ts or javascript, js | default: `ts`",
default: "ts",
alias: "l",
},
noIndexer: {
"create-indexer": {
type: "boolean",
description: "Do not create an indexer after initialization",
default: false,
name: "create-indexer",
default: true,
description: "TODO",
},
},
async run({ args }) {
const { dir: targetDir, noIndexer, language } = args;
async run({ args, cmd }) {
await checkForUnknownArgs(args, cmd);

const { dir: targetDir, "create-indexer": createIndexer, language } = args;

await initializeProject({
argTargetDir: targetDir,
argLanguage: language,
argNoCreateIndexer: noIndexer,
argNoCreateIndexer: !createIndexer,
});
},
});
6 changes: 4 additions & 2 deletions packages/cli/src/cli/commands/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createApibara, writeTypes } from "apibara/core";
import {} from "apibara/types";
import { defineCommand } from "citty";
import { resolve } from "pathe";
import { commonArgs } from "../common";
import { checkForUnknownArgs, commonArgs } from "../common";

export default defineCommand({
meta: {
Expand All @@ -12,7 +12,9 @@ export default defineCommand({
args: {
...commonArgs,
},
async run({ args }) {
async run({ args, cmd }) {
await checkForUnknownArgs(args, cmd);

const rootDir = resolve((args.dir || ".") as string);
const apibara = await createApibara({ rootDir });
await writeTypes(apibara);
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/cli/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineCommand } from "citty";
import { colors } from "consola/utils";
import fse from "fs-extra";
import { resolve } from "pathe";
import { commonArgs } from "../common";
import { checkForUnknownArgs, commonArgs } from "../common";

export default defineCommand({
meta: {
Expand All @@ -23,10 +23,12 @@ export default defineCommand({
description: "The preset to use",
},
},
async run({ args }) {
async run({ args, cmd }) {
const { indexer, preset } = args;
const rootDir = resolve((args.dir || args._dir || ".") as string);

await checkForUnknownArgs(args, cmd);

const apibara = await createApibara({
rootDir,
preset,
Expand Down Expand Up @@ -67,7 +69,6 @@ export default defineCommand({
code !== null ? ` with code ${colors.red(code)}` : ""
}`,
);
process.exit(code ?? 0);
});
},
});
34 changes: 33 additions & 1 deletion packages/cli/src/cli/common.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
import type { ArgsDef } from "citty";
import {
type ArgsDef,
type CommandDef,
type ParsedArgs,
renderUsage,
} from "citty";
import consola from "consola";

export const commonArgs = <ArgsDef>{
dir: {
type: "string",
description: "project root directory",
},
};

export const checkForUnknownArgs = async <T extends ArgsDef = ArgsDef>(
args: ParsedArgs<T>,
cmd: CommandDef<T>,
) => {
// Create a list of defined args including both the main arg names and their aliases
const definedArgs: string[] = [];
if (cmd.args) {
for (const [argName, argDef] of Object.entries(cmd.args)) {
definedArgs.push(argName);
// Add alias to definedArgs if it exists
if (argDef.alias) {
definedArgs.push(argDef.alias);
}
}
}

const providedArgs = Object.keys(args).filter((arg) => arg !== "_");
const wrongArgs = providedArgs.filter((arg) => !definedArgs.includes(arg));

if (wrongArgs.length > 0) {
consola.error(`Unknown arguments: ${wrongArgs.join(", ")}`);
consola.info(await renderUsage(cmd));
process.exit(1);
}
};
2 changes: 1 addition & 1 deletion packages/cli/src/create/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const packageVersions = {
"@apibara/plugin-sqlite": "next",
// Postgres Dependencies
"@electric-sql/pglite": "^0.2.17",
"drizzle-orm": "^0.37.0",
"drizzle-orm": "^0.40.1",
pg: "^8.13.1",
"@types/pg": "^8.11.10",
"drizzle-kit": "^0.29.0",
Expand Down
Loading