apibara 2.1.0-beta.19 → 2.1.0-beta.21

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.
@@ -1,5 +1,7 @@
1
1
  import { addIndexer } from 'apibara/create';
2
2
  import { defineCommand } from 'citty';
3
+ import { a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
4
+ import 'consola';
3
5
 
4
6
  const add = defineCommand({
5
7
  meta: {
@@ -33,7 +35,8 @@ const add = defineCommand({
33
35
  description: "Root directory - apibara project root where apibara.config is located | default: current working directory"
34
36
  }
35
37
  },
36
- async run({ args }) {
38
+ async run({ args, cmd }) {
39
+ await checkForUnknownArgs(args, cmd);
37
40
  const { indexerId, chain, network, storage, dnaUrl, dir } = args;
38
41
  await addIndexer({
39
42
  argIndexerId: indexerId,
@@ -2,7 +2,8 @@ import { createApibara, prepare, writeTypes, build as build$1 } from 'apibara/co
2
2
  import { runtimeDir } from 'apibara/runtime/meta';
3
3
  import { defineCommand } from 'citty';
4
4
  import { resolve, join } from 'pathe';
5
- import { c as commonArgs } from '../shared/apibara.1b515d04.mjs';
5
+ import { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
6
+ import 'consola';
6
7
 
7
8
  const build = defineCommand({
8
9
  meta: {
@@ -12,7 +13,8 @@ const build = defineCommand({
12
13
  args: {
13
14
  ...commonArgs
14
15
  },
15
- async run({ args }) {
16
+ async run({ args, cmd }) {
17
+ await checkForUnknownArgs(args, cmd);
16
18
  const rootDir = resolve(args.dir || args._dir || ".");
17
19
  const apibara = await createApibara({
18
20
  rootDir
@@ -4,7 +4,8 @@ import { runtimeDir } from 'apibara/runtime/meta';
4
4
  import { defineCommand } from 'citty';
5
5
  import { colors } from 'consola/utils';
6
6
  import { resolve, join } from 'pathe';
7
- import { c as commonArgs } from '../shared/apibara.1b515d04.mjs';
7
+ import { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
8
+ import 'consola';
8
9
 
9
10
  const hmrKeyRe = /^runtimeConfig\./;
10
11
  const dev = defineCommand({
@@ -22,15 +23,16 @@ const dev = defineCommand({
22
23
  type: "string",
23
24
  description: "Preset to use"
24
25
  },
25
- alwaysReindex: {
26
+ "always-reindex": {
26
27
  type: "boolean",
27
28
  default: false,
28
- description: "Reindex the indexers from the starting block on every restart (default: false)"
29
+ description: "Reindex the indexers from the starting block on every restart | default: `false`"
29
30
  }
30
31
  },
31
- async run({ args }) {
32
+ async run({ args, data, cmd, rawArgs }) {
33
+ await checkForUnknownArgs(args, cmd);
32
34
  const rootDir = resolve(args.dir || args._dir || ".");
33
- if (args.alwaysReindex) {
35
+ if (args["always-reindex"]) {
34
36
  process.env.APIBARA_ALWAYS_REINDEX = "true";
35
37
  }
36
38
  let apibara;
@@ -100,7 +102,6 @@ const dev = defineCommand({
100
102
  apibara.logger.log(
101
103
  `Indexers process exited${code !== null ? ` with code ${colors.red(code)}` : ""}`
102
104
  );
103
- process.exit(code ?? 0);
104
105
  });
105
106
  });
106
107
  };
@@ -1,5 +1,7 @@
1
1
  import { initializeProject } from 'apibara/create';
2
2
  import { defineCommand } from 'citty';
3
+ import { a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
4
+ import 'consola';
3
5
 
4
6
  const init = defineCommand({
5
7
  meta: {
@@ -14,22 +16,24 @@ const init = defineCommand({
14
16
  },
15
17
  language: {
16
18
  type: "string",
17
- description: "Language to use: typescript, ts or javascript, js",
19
+ description: "Language to use: typescript, ts or javascript, js | default: `ts`",
18
20
  default: "ts",
19
21
  alias: "l"
20
22
  },
21
- noIndexer: {
23
+ "create-indexer": {
22
24
  type: "boolean",
23
- description: "Do not create an indexer after initialization",
24
- default: false
25
+ name: "create-indexer",
26
+ default: true,
27
+ description: "TODO"
25
28
  }
26
29
  },
27
- async run({ args }) {
28
- const { dir: targetDir, noIndexer, language } = args;
30
+ async run({ args, cmd }) {
31
+ await checkForUnknownArgs(args, cmd);
32
+ const { dir: targetDir, "create-indexer": createIndexer, language } = args;
29
33
  await initializeProject({
30
34
  argTargetDir: targetDir,
31
35
  argLanguage: language,
32
- argNoCreateIndexer: noIndexer
36
+ argNoCreateIndexer: !createIndexer
33
37
  });
34
38
  }
35
39
  });
@@ -1,7 +1,8 @@
1
1
  import { createApibara, writeTypes } from 'apibara/core';
2
2
  import { defineCommand } from 'citty';
3
3
  import { resolve } from 'pathe';
4
- import { c as commonArgs } from '../shared/apibara.1b515d04.mjs';
4
+ import { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
5
+ import 'consola';
5
6
 
6
7
  const prepare = defineCommand({
7
8
  meta: {
@@ -11,7 +12,8 @@ const prepare = defineCommand({
11
12
  args: {
12
13
  ...commonArgs
13
14
  },
14
- async run({ args }) {
15
+ async run({ args, cmd }) {
16
+ await checkForUnknownArgs(args, cmd);
15
17
  const rootDir = resolve(args.dir || ".");
16
18
  const apibara = await createApibara({ rootDir });
17
19
  await writeTypes(apibara);
@@ -4,7 +4,8 @@ import { defineCommand } from 'citty';
4
4
  import { colors } from 'consola/utils';
5
5
  import fse from 'fs-extra';
6
6
  import { resolve } from 'pathe';
7
- import { c as commonArgs } from '../shared/apibara.1b515d04.mjs';
7
+ import { c as commonArgs, a as checkForUnknownArgs } from '../shared/apibara.63c9a277.mjs';
8
+ import 'consola';
8
9
 
9
10
  const start = defineCommand({
10
11
  meta: {
@@ -23,9 +24,10 @@ const start = defineCommand({
23
24
  description: "The preset to use"
24
25
  }
25
26
  },
26
- async run({ args }) {
27
+ async run({ args, cmd }) {
27
28
  const { indexer, preset } = args;
28
29
  const rootDir = resolve(args.dir || args._dir || ".");
30
+ await checkForUnknownArgs(args, cmd);
29
31
  const apibara = await createApibara({
30
32
  rootDir,
31
33
  preset
@@ -57,7 +59,6 @@ const start = defineCommand({
57
59
  apibara.logger.log(
58
60
  `Indexers process exited${code !== null ? ` with code ${colors.red(code)}` : ""}`
59
61
  );
60
- process.exit(code ?? 0);
61
62
  });
62
63
  }
63
64
  });
@@ -70,7 +70,7 @@ const packageVersions = {
70
70
  "@apibara/plugin-sqlite": "next",
71
71
  // Postgres Dependencies
72
72
  "@electric-sql/pglite": "^0.2.17",
73
- "drizzle-orm": "^0.37.0",
73
+ "drizzle-orm": "^0.40.1",
74
74
  pg: "^8.13.1",
75
75
  "@types/pg": "^8.11.10",
76
76
  "drizzle-kit": "^0.29.0",
@@ -0,0 +1,29 @@
1
+ import { renderUsage } from 'citty';
2
+ import consola from 'consola';
3
+
4
+ const commonArgs = {
5
+ dir: {
6
+ type: "string",
7
+ description: "project root directory"
8
+ }
9
+ };
10
+ const checkForUnknownArgs = async (args, cmd) => {
11
+ const definedArgs = [];
12
+ if (cmd.args) {
13
+ for (const [argName, argDef] of Object.entries(cmd.args)) {
14
+ definedArgs.push(argName);
15
+ if (argDef.alias) {
16
+ definedArgs.push(argDef.alias);
17
+ }
18
+ }
19
+ }
20
+ const providedArgs = Object.keys(args).filter((arg) => arg !== "_");
21
+ const wrongArgs = providedArgs.filter((arg) => !definedArgs.includes(arg));
22
+ if (wrongArgs.length > 0) {
23
+ consola.error(`Unknown arguments: ${wrongArgs.join(", ")}`);
24
+ consola.info(await renderUsage(cmd));
25
+ process.exit(1);
26
+ }
27
+ };
28
+
29
+ export { checkForUnknownArgs as a, commonArgs as c };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apibara",
3
- "version": "2.1.0-beta.19",
3
+ "version": "2.1.0-beta.21",
4
4
  "type": "module",
5
5
  "main": "./dist/core/index.mjs",
6
6
  "exports": {
@@ -78,7 +78,7 @@
78
78
  "playground:add": "pnpm playground add --dir playground"
79
79
  },
80
80
  "devDependencies": {
81
- "@apibara/starknet": "2.1.0-beta.19",
81
+ "@apibara/starknet": "2.1.0-beta.21",
82
82
  "@types/fs-extra": "^11.0.4",
83
83
  "@types/node": "^20.14.0",
84
84
  "@types/prompts": "^2.4.9",
@@ -89,8 +89,8 @@
89
89
  "vitest": "^1.6.0"
90
90
  },
91
91
  "dependencies": {
92
- "@apibara/indexer": "2.1.0-beta.19",
93
- "@apibara/protocol": "2.1.0-beta.19",
92
+ "@apibara/indexer": "2.1.0-beta.21",
93
+ "@apibara/protocol": "2.1.0-beta.21",
94
94
  "@rollup/plugin-replace": "^6.0.2",
95
95
  "@rollup/plugin-virtual": "^3.0.2",
96
96
  "c12": "^1.11.1",
@@ -1,5 +1,6 @@
1
1
  import { addIndexer } from "apibara/create";
2
2
  import { defineCommand } from "citty";
3
+ import { checkForUnknownArgs } from "../common";
3
4
 
4
5
  export default defineCommand({
5
6
  meta: {
@@ -35,7 +36,9 @@ export default defineCommand({
35
36
  "Root directory - apibara project root where apibara.config is located | default: current working directory",
36
37
  },
37
38
  },
38
- async run({ args }) {
39
+ async run({ args, cmd }) {
40
+ await checkForUnknownArgs(args, cmd);
41
+
39
42
  const { indexerId, chain, network, storage, dnaUrl, dir } = args;
40
43
 
41
44
  await addIndexer({
@@ -2,7 +2,7 @@ import { build, createApibara, prepare, writeTypes } from "apibara/core";
2
2
  import { runtimeDir } from "apibara/runtime/meta";
3
3
  import { defineCommand } from "citty";
4
4
  import { join, resolve } from "pathe";
5
- import { commonArgs } from "../common";
5
+ import { checkForUnknownArgs, commonArgs } from "../common";
6
6
 
7
7
  export default defineCommand({
8
8
  meta: {
@@ -12,8 +12,11 @@ export default defineCommand({
12
12
  args: {
13
13
  ...commonArgs,
14
14
  },
15
- async run({ args }) {
15
+ async run({ args, cmd }) {
16
+ await checkForUnknownArgs(args, cmd);
17
+
16
18
  const rootDir = resolve((args.dir || args._dir || ".") as string);
19
+
17
20
  const apibara = await createApibara({
18
21
  rootDir,
19
22
  });
@@ -5,7 +5,7 @@ import type { Apibara } from "apibara/types";
5
5
  import { defineCommand } from "citty";
6
6
  import { colors } from "consola/utils";
7
7
  import { join, resolve } from "pathe";
8
- import { commonArgs } from "../common";
8
+ import { checkForUnknownArgs, commonArgs } from "../common";
9
9
 
10
10
  // Hot module reloading key regex
11
11
  // for only runtimeConfig.* keys
@@ -26,17 +26,19 @@ export default defineCommand({
26
26
  type: "string",
27
27
  description: "Preset to use",
28
28
  },
29
- alwaysReindex: {
29
+ "always-reindex": {
30
30
  type: "boolean",
31
31
  default: false,
32
32
  description:
33
- "Reindex the indexers from the starting block on every restart (default: false)",
33
+ "Reindex the indexers from the starting block on every restart | default: `false`",
34
34
  },
35
35
  },
36
- async run({ args }) {
36
+ async run({ args, data, cmd, rawArgs }) {
37
+ await checkForUnknownArgs(args, cmd);
38
+
37
39
  const rootDir = resolve((args.dir || args._dir || ".") as string);
38
40
 
39
- if (args.alwaysReindex) {
41
+ if (args["always-reindex"]) {
40
42
  process.env.APIBARA_ALWAYS_REINDEX = "true";
41
43
  }
42
44
 
@@ -125,7 +127,6 @@ export default defineCommand({
125
127
  code !== null ? ` with code ${colors.red(code)}` : ""
126
128
  }`,
127
129
  );
128
- process.exit(code ?? 0);
129
130
  });
130
131
  });
131
132
  };
@@ -1,5 +1,6 @@
1
1
  import { initializeProject } from "apibara/create";
2
2
  import { defineCommand } from "citty";
3
+ import { checkForUnknownArgs } from "../common";
3
4
 
4
5
  export default defineCommand({
5
6
  meta: {
@@ -14,23 +15,27 @@ export default defineCommand({
14
15
  },
15
16
  language: {
16
17
  type: "string",
17
- description: "Language to use: typescript, ts or javascript, js",
18
+ description:
19
+ "Language to use: typescript, ts or javascript, js | default: `ts`",
18
20
  default: "ts",
19
21
  alias: "l",
20
22
  },
21
- noIndexer: {
23
+ "create-indexer": {
22
24
  type: "boolean",
23
- description: "Do not create an indexer after initialization",
24
- default: false,
25
+ name: "create-indexer",
26
+ default: true,
27
+ description: "TODO",
25
28
  },
26
29
  },
27
- async run({ args }) {
28
- const { dir: targetDir, noIndexer, language } = args;
30
+ async run({ args, cmd }) {
31
+ await checkForUnknownArgs(args, cmd);
32
+
33
+ const { dir: targetDir, "create-indexer": createIndexer, language } = args;
29
34
 
30
35
  await initializeProject({
31
36
  argTargetDir: targetDir,
32
37
  argLanguage: language,
33
- argNoCreateIndexer: noIndexer,
38
+ argNoCreateIndexer: !createIndexer,
34
39
  });
35
40
  },
36
41
  });
@@ -2,7 +2,7 @@ import { createApibara, writeTypes } from "apibara/core";
2
2
  import {} from "apibara/types";
3
3
  import { defineCommand } from "citty";
4
4
  import { resolve } from "pathe";
5
- import { commonArgs } from "../common";
5
+ import { checkForUnknownArgs, commonArgs } from "../common";
6
6
 
7
7
  export default defineCommand({
8
8
  meta: {
@@ -12,7 +12,9 @@ export default defineCommand({
12
12
  args: {
13
13
  ...commonArgs,
14
14
  },
15
- async run({ args }) {
15
+ async run({ args, cmd }) {
16
+ await checkForUnknownArgs(args, cmd);
17
+
16
18
  const rootDir = resolve((args.dir || ".") as string);
17
19
  const apibara = await createApibara({ rootDir });
18
20
  await writeTypes(apibara);
@@ -4,7 +4,7 @@ import { defineCommand } from "citty";
4
4
  import { colors } from "consola/utils";
5
5
  import fse from "fs-extra";
6
6
  import { resolve } from "pathe";
7
- import { commonArgs } from "../common";
7
+ import { checkForUnknownArgs, commonArgs } from "../common";
8
8
 
9
9
  export default defineCommand({
10
10
  meta: {
@@ -23,10 +23,12 @@ export default defineCommand({
23
23
  description: "The preset to use",
24
24
  },
25
25
  },
26
- async run({ args }) {
26
+ async run({ args, cmd }) {
27
27
  const { indexer, preset } = args;
28
28
  const rootDir = resolve((args.dir || args._dir || ".") as string);
29
29
 
30
+ await checkForUnknownArgs(args, cmd);
31
+
30
32
  const apibara = await createApibara({
31
33
  rootDir,
32
34
  preset,
@@ -67,7 +69,6 @@ export default defineCommand({
67
69
  code !== null ? ` with code ${colors.red(code)}` : ""
68
70
  }`,
69
71
  );
70
- process.exit(code ?? 0);
71
72
  });
72
73
  },
73
74
  });
package/src/cli/common.ts CHANGED
@@ -1,4 +1,10 @@
1
- import type { ArgsDef } from "citty";
1
+ import {
2
+ type ArgsDef,
3
+ type CommandDef,
4
+ type ParsedArgs,
5
+ renderUsage,
6
+ } from "citty";
7
+ import consola from "consola";
2
8
 
3
9
  export const commonArgs = <ArgsDef>{
4
10
  dir: {
@@ -6,3 +12,29 @@ export const commonArgs = <ArgsDef>{
6
12
  description: "project root directory",
7
13
  },
8
14
  };
15
+
16
+ export const checkForUnknownArgs = async <T extends ArgsDef = ArgsDef>(
17
+ args: ParsedArgs<T>,
18
+ cmd: CommandDef<T>,
19
+ ) => {
20
+ // Create a list of defined args including both the main arg names and their aliases
21
+ const definedArgs: string[] = [];
22
+ if (cmd.args) {
23
+ for (const [argName, argDef] of Object.entries(cmd.args)) {
24
+ definedArgs.push(argName);
25
+ // Add alias to definedArgs if it exists
26
+ if (argDef.alias) {
27
+ definedArgs.push(argDef.alias);
28
+ }
29
+ }
30
+ }
31
+
32
+ const providedArgs = Object.keys(args).filter((arg) => arg !== "_");
33
+ const wrongArgs = providedArgs.filter((arg) => !definedArgs.includes(arg));
34
+
35
+ if (wrongArgs.length > 0) {
36
+ consola.error(`Unknown arguments: ${wrongArgs.join(", ")}`);
37
+ consola.info(await renderUsage(cmd));
38
+ process.exit(1);
39
+ }
40
+ };
@@ -79,7 +79,7 @@ export const packageVersions = {
79
79
  "@apibara/plugin-sqlite": "next",
80
80
  // Postgres Dependencies
81
81
  "@electric-sql/pglite": "^0.2.17",
82
- "drizzle-orm": "^0.37.0",
82
+ "drizzle-orm": "^0.40.1",
83
83
  pg: "^8.13.1",
84
84
  "@types/pg": "^8.11.10",
85
85
  "drizzle-kit": "^0.29.0",
@@ -1,8 +0,0 @@
1
- const commonArgs = {
2
- dir: {
3
- type: "string",
4
- description: "project root directory"
5
- }
6
- };
7
-
8
- export { commonArgs as c };