apibara 2.1.0-beta.5 → 2.1.0-beta.51

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.
Files changed (119) hide show
  1. package/dist/chunks/add.mjs +16 -8
  2. package/dist/chunks/add.mjs.map +1 -0
  3. package/dist/chunks/build.mjs +4 -2
  4. package/dist/chunks/build.mjs.map +1 -0
  5. package/dist/chunks/dev.mjs +55 -21
  6. package/dist/chunks/dev.mjs.map +1 -0
  7. package/dist/chunks/init.mjs +11 -7
  8. package/dist/chunks/init.mjs.map +1 -0
  9. package/dist/chunks/prepare.mjs +4 -2
  10. package/dist/chunks/prepare.mjs.map +1 -0
  11. package/dist/chunks/start.mjs +16 -4
  12. package/dist/chunks/start.mjs.map +1 -0
  13. package/dist/chunks/write-project-info.mjs +51 -0
  14. package/dist/chunks/write-project-info.mjs.map +1 -0
  15. package/dist/cli/index.mjs +3 -1
  16. package/dist/cli/index.mjs.map +1 -0
  17. package/dist/common/index.d.mts +33 -0
  18. package/dist/common/index.d.ts +33 -0
  19. package/dist/common/index.mjs +91 -0
  20. package/dist/common/index.mjs.map +1 -0
  21. package/dist/config/index.mjs +1 -0
  22. package/dist/config/index.mjs.map +1 -0
  23. package/dist/core/index.mjs +134 -69
  24. package/dist/core/index.mjs.map +1 -0
  25. package/dist/create/index.d.mts +2 -1
  26. package/dist/create/index.d.ts +2 -1
  27. package/dist/create/index.mjs +80 -136
  28. package/dist/create/index.mjs.map +1 -0
  29. package/dist/hooks/index.mjs +6 -1
  30. package/dist/hooks/index.mjs.map +1 -0
  31. package/dist/indexer/index.d.ts +1 -0
  32. package/dist/indexer/index.mjs +1 -0
  33. package/dist/indexer/plugins.d.ts +1 -0
  34. package/dist/indexer/plugins.mjs +1 -0
  35. package/dist/indexer/testing.d.ts +1 -0
  36. package/dist/indexer/testing.mjs +1 -0
  37. package/dist/indexer/vcr.d.ts +1 -0
  38. package/dist/indexer/vcr.mjs +1 -0
  39. package/dist/rolldown/index.d.mts +7 -0
  40. package/dist/rolldown/index.d.ts +7 -0
  41. package/dist/rolldown/index.mjs +141 -0
  42. package/dist/rolldown/index.mjs.map +1 -0
  43. package/dist/runtime/dev.mjs +39 -17
  44. package/dist/runtime/internal/app.d.ts +14 -1
  45. package/dist/runtime/internal/app.mjs +26 -21
  46. package/dist/runtime/project-info.d.ts +3 -0
  47. package/dist/runtime/project-info.mjs +67 -0
  48. package/dist/runtime/start.mjs +78 -11
  49. package/dist/shared/apibara.730bb1e4.mjs +18 -0
  50. package/dist/shared/apibara.730bb1e4.mjs.map +1 -0
  51. package/dist/types/index.d.mts +24 -20
  52. package/dist/types/index.d.ts +24 -20
  53. package/dist/types/index.mjs +1 -0
  54. package/dist/types/index.mjs.map +1 -0
  55. package/package.json +34 -17
  56. package/src/cli/commands/add.ts +16 -7
  57. package/src/cli/commands/build.ts +5 -2
  58. package/src/cli/commands/dev.ts +64 -20
  59. package/src/cli/commands/init.ts +12 -7
  60. package/src/cli/commands/prepare.ts +4 -3
  61. package/src/cli/commands/start.ts +18 -3
  62. package/src/cli/commands/write-project-info.ts +56 -0
  63. package/src/cli/index.ts +2 -0
  64. package/src/common/cli.ts +40 -0
  65. package/src/common/constants.ts +6 -0
  66. package/src/common/helper.ts +86 -0
  67. package/src/common/index.ts +3 -0
  68. package/src/core/apibara.ts +7 -2
  69. package/src/core/build/build.ts +13 -5
  70. package/src/core/build/dev.ts +46 -23
  71. package/src/core/build/error.ts +9 -14
  72. package/src/core/build/prepare.ts +5 -3
  73. package/src/core/build/prod.ts +25 -16
  74. package/src/core/build/types.ts +11 -1
  75. package/src/core/config/defaults.ts +3 -0
  76. package/src/core/config/loader.ts +15 -7
  77. package/src/core/config/resolvers/runtime.resolver.ts +44 -0
  78. package/src/core/config/update.ts +6 -2
  79. package/src/core/scan.ts +1 -1
  80. package/src/create/add.ts +14 -20
  81. package/src/create/constants.ts +5 -7
  82. package/src/create/init.ts +2 -2
  83. package/src/create/templates.ts +43 -116
  84. package/src/create/types.ts +3 -0
  85. package/src/create/utils.ts +20 -7
  86. package/src/hooks/useRuntimeConfig.ts +4 -1
  87. package/src/indexer/index.ts +1 -0
  88. package/src/indexer/plugins.ts +1 -0
  89. package/src/indexer/testing.ts +1 -0
  90. package/src/indexer/vcr.ts +1 -0
  91. package/src/rolldown/config.ts +86 -0
  92. package/src/rolldown/index.ts +2 -0
  93. package/src/{rollup → rolldown}/plugins/indexers.ts +3 -3
  94. package/src/rolldown/plugins/instrumentation.ts +68 -0
  95. package/src/rolldown/plugins/static-config.ts +21 -0
  96. package/src/runtime/dev.ts +49 -19
  97. package/src/runtime/internal/app.ts +42 -29
  98. package/src/runtime/project-info.ts +90 -0
  99. package/src/runtime/start.ts +91 -11
  100. package/src/types/config.ts +27 -13
  101. package/src/types/hooks.ts +8 -5
  102. package/src/types/index.ts +1 -1
  103. package/src/types/rolldown.ts +5 -0
  104. package/src/types/virtual/indexers.d.ts +4 -1
  105. package/src/types/virtual/instrumentation.d.ts +4 -0
  106. package/src/types/virtual/static-config.d.ts +4 -0
  107. package/dist/rollup/index.d.mts +0 -6
  108. package/dist/rollup/index.d.ts +0 -6
  109. package/dist/rollup/index.mjs +0 -150
  110. package/dist/shared/apibara.1b515d04.mjs +0 -8
  111. package/src/cli/common.ts +0 -8
  112. package/src/core/config/resolvers/preset.resolver.ts +0 -9
  113. package/src/core/config/resolvers/runtime-config.resolver.ts +0 -6
  114. package/src/rollup/config.ts +0 -87
  115. package/src/rollup/index.ts +0 -2
  116. package/src/rollup/plugins/config.ts +0 -12
  117. package/src/rollup/plugins/esm-shim.ts +0 -69
  118. package/src/types/rollup.ts +0 -8
  119. package/src/types/virtual/config.d.ts +0 -3
@@ -1,150 +0,0 @@
1
- import { builtinModules } from 'node:module';
2
- import commonjs from '@rollup/plugin-commonjs';
3
- import json from '@rollup/plugin-json';
4
- import { nodeResolve } from '@rollup/plugin-node-resolve';
5
- import { join } from 'pathe';
6
- import defu from 'defu';
7
- import virtual from '@rollup/plugin-virtual';
8
- import MagicString from 'magic-string';
9
- import { hash } from 'ohash';
10
-
11
- function appConfig(apibara) {
12
- return virtual({
13
- "#apibara-internal-virtual/config": `
14
- import * as projectConfig from '${apibara.options._c12.configFile}';
15
-
16
- export const config = projectConfig.default;
17
- `
18
- });
19
- }
20
-
21
- function esmShim() {
22
- const ESMShim = `
23
- // -- Shims --
24
- import cjsUrl from 'node:url';
25
- import cjsPath from 'node:path';
26
- const __filename = cjsUrl.fileURLToPath(import.meta.url);
27
- const __dirname = cjsPath.dirname(__filename);
28
- // -- End Shims --
29
- `;
30
- const CJSyntaxRegex = /__filename|__dirname/;
31
- return {
32
- name: "esm-shim",
33
- renderChunk(code, _chunk, opts) {
34
- if (opts.format === "es") {
35
- if (code.includes(ESMShim) || !CJSyntaxRegex.test(code)) {
36
- return null;
37
- }
38
- let endIndexOfLastImport = -1;
39
- for (const match of code.matchAll(/^import\s.*';$/gm)) {
40
- if (match.length === 0 || typeof match.index !== "number") {
41
- continue;
42
- }
43
- endIndexOfLastImport = match.index + match[0].length;
44
- }
45
- const s = new MagicString(code);
46
- s.appendRight(endIndexOfLastImport, ESMShim);
47
- const sourceMap = s.generateMap({
48
- includeContent: true
49
- });
50
- let sourcesContent;
51
- if (Array.isArray(sourceMap.sourcesContent)) {
52
- sourcesContent = [];
53
- for (let i = 0; i < sourceMap.sourcesContent.length; i++) {
54
- const content = sourceMap.sourcesContent[i];
55
- if (typeof content === "string") {
56
- sourcesContent.push(content);
57
- }
58
- }
59
- }
60
- return {
61
- code: s.toString(),
62
- map: {
63
- ...sourceMap,
64
- sourcesContent
65
- }
66
- };
67
- }
68
- return null;
69
- }
70
- };
71
- }
72
-
73
- function indexers(apibara) {
74
- const indexers2 = [...new Set(apibara.indexers)];
75
- return virtual({
76
- "#apibara-internal-virtual/indexers": `
77
- ${indexers2.map((i) => `import _${hash(i)} from '${i.indexer}';`).join("\n")}
78
-
79
- export const indexers = [
80
- ${indexers2.map((i) => `{ name: "${i.name}", indexer: _${hash(i)} }`).join(",\n")}
81
- ];
82
- `
83
- });
84
- }
85
-
86
- const runtimeDependencies = ["better-sqlite3", "@electric-sql/pglite"];
87
- function getRollupConfig(apibara) {
88
- const extensions = [
89
- ".ts",
90
- ".mjs",
91
- ".js",
92
- ".json",
93
- ".node",
94
- ".tsx",
95
- ".jsx"
96
- ];
97
- const rollupConfig = defu(
98
- // biome-ignore lint/suspicious/noExplicitAny: apibara.options.rollupConfig is typed
99
- apibara.options.rollupConfig,
100
- {
101
- input: apibara.options.entry,
102
- output: {
103
- dir: join(apibara.options.outputDir || "./.apibara/build"),
104
- format: "esm",
105
- exports: "auto",
106
- entryFileNames: "[name].mjs",
107
- chunkFileNames: "chunks/[name]-[hash].mjs",
108
- generatedCode: {
109
- constBindings: true
110
- },
111
- sourcemap: true,
112
- sourcemapExcludeSources: true,
113
- sourcemapIgnoreList(relativePath, sourcemapPath) {
114
- return relativePath.includes("node_modules");
115
- }
116
- },
117
- plugins: [],
118
- onwarn(warning, rollupWarn) {
119
- if (!["CIRCULAR_DEPENDENCY", "EVAL", "THIS_IS_UNDEFINED"].includes(
120
- warning.code || ""
121
- ) && !warning.message.includes("Unsupported source map comment") && !warning.message.includes("@__PURE__") && !warning.message.includes("/*#__PURE__*/")) {
122
- rollupWarn(warning);
123
- }
124
- },
125
- treeshake: true,
126
- external: [...builtinModules, ...runtimeDependencies]
127
- }
128
- );
129
- rollupConfig.plugins.push(esmShim());
130
- rollupConfig.plugins.push(json());
131
- rollupConfig.plugins.push(
132
- commonjs({
133
- strictRequires: true,
134
- requireReturnsDefault: "auto",
135
- ...apibara.options.commonJS
136
- })
137
- );
138
- rollupConfig.plugins.push(
139
- nodeResolve({
140
- extensions,
141
- preferBuiltins: true,
142
- mainFields: ["main"]
143
- })
144
- );
145
- rollupConfig.plugins.push(indexers(apibara));
146
- rollupConfig.plugins.push(appConfig(apibara));
147
- return rollupConfig;
148
- }
149
-
150
- export { getRollupConfig };
@@ -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 };
package/src/cli/common.ts DELETED
@@ -1,8 +0,0 @@
1
- import type { ArgsDef } from "citty";
2
-
3
- export const commonArgs = <ArgsDef>{
4
- dir: {
5
- type: "string",
6
- description: "project root directory",
7
- },
8
- };
@@ -1,9 +0,0 @@
1
- import type { ApibaraOptions } from "apibara/types";
2
- import defu from "defu";
3
-
4
- export async function presetResolver(options: ApibaraOptions) {
5
- if (options.preset && options.presets?.[options.preset]) {
6
- const new_options = defu(options.presets[options.preset], options);
7
- Object.assign(options, new_options);
8
- }
9
- }
@@ -1,6 +0,0 @@
1
- import type { ApibaraOptions } from "apibara/types";
2
-
3
- export async function resolveRuntimeConfigOptions(options: ApibaraOptions) {
4
- options.runtimeConfig = { ...options.runtimeConfig };
5
- process.env.APIBARA_RUNTIME_CONFIG = JSON.stringify(options.runtimeConfig);
6
- }
@@ -1,87 +0,0 @@
1
- import { builtinModules } from "node:module";
2
- import commonjs from "@rollup/plugin-commonjs";
3
- import json from "@rollup/plugin-json";
4
- import { nodeResolve } from "@rollup/plugin-node-resolve";
5
- import type { Apibara, RollupConfig } from "apibara/types";
6
- import { join } from "pathe";
7
- import type { OutputPluginOption } from "rollup";
8
-
9
- import defu from "defu";
10
- import { appConfig } from "./plugins/config";
11
- import { esmShim } from "./plugins/esm-shim";
12
- import { indexers } from "./plugins/indexers";
13
-
14
- const runtimeDependencies = ["better-sqlite3", "@electric-sql/pglite"];
15
-
16
- export function getRollupConfig(apibara: Apibara): RollupConfig {
17
- const extensions: string[] = [
18
- ".ts",
19
- ".mjs",
20
- ".js",
21
- ".json",
22
- ".node",
23
- ".tsx",
24
- ".jsx",
25
- ];
26
-
27
- const rollupConfig: RollupConfig & { plugins: OutputPluginOption[] } = defu(
28
- // biome-ignore lint/suspicious/noExplicitAny: apibara.options.rollupConfig is typed
29
- apibara.options.rollupConfig as any,
30
- <RollupConfig>{
31
- input: apibara.options.entry,
32
- output: {
33
- dir: join(apibara.options.outputDir || "./.apibara/build"),
34
- format: "esm",
35
- exports: "auto",
36
- entryFileNames: "[name].mjs",
37
- chunkFileNames: "chunks/[name]-[hash].mjs",
38
- generatedCode: {
39
- constBindings: true,
40
- },
41
- sourcemap: true,
42
- sourcemapExcludeSources: true,
43
- sourcemapIgnoreList(relativePath, sourcemapPath) {
44
- return relativePath.includes("node_modules");
45
- },
46
- },
47
- plugins: [],
48
- onwarn(warning, rollupWarn) {
49
- if (
50
- !["CIRCULAR_DEPENDENCY", "EVAL", "THIS_IS_UNDEFINED"].includes(
51
- warning.code || "",
52
- ) &&
53
- !warning.message.includes("Unsupported source map comment") &&
54
- !warning.message.includes("@__PURE__") &&
55
- !warning.message.includes("/*#__PURE__*/")
56
- ) {
57
- rollupWarn(warning);
58
- }
59
- },
60
- treeshake: true,
61
- external: [...builtinModules, ...runtimeDependencies],
62
- },
63
- );
64
-
65
- rollupConfig.plugins.push(esmShim());
66
- rollupConfig.plugins.push(json());
67
-
68
- rollupConfig.plugins.push(
69
- commonjs({
70
- strictRequires: true,
71
- requireReturnsDefault: "auto",
72
- ...apibara.options.commonJS,
73
- }),
74
- );
75
-
76
- rollupConfig.plugins.push(
77
- nodeResolve({
78
- extensions,
79
- preferBuiltins: true,
80
- mainFields: ["main"],
81
- }),
82
- );
83
- rollupConfig.plugins.push(indexers(apibara));
84
- rollupConfig.plugins.push(appConfig(apibara));
85
-
86
- return rollupConfig;
87
- }
@@ -1,2 +0,0 @@
1
- export * from "./config";
2
- export type { Plugin } from "rollup";
@@ -1,12 +0,0 @@
1
- import virtual from "@rollup/plugin-virtual";
2
- import type { Apibara } from "apibara/types";
3
-
4
- export function appConfig(apibara: Apibara) {
5
- return virtual({
6
- "#apibara-internal-virtual/config": `
7
- import * as projectConfig from '${apibara.options._c12.configFile}';
8
-
9
- export const config = projectConfig.default;
10
- `,
11
- });
12
- }
@@ -1,69 +0,0 @@
1
- import MagicString from "magic-string";
2
- import type { Plugin } from "rollup";
3
-
4
- /**
5
- * An alternative to @rollup/plugin-esm-shim
6
- */
7
- export function esmShim(): Plugin {
8
- const ESMShim = `
9
- // -- Shims --
10
- import cjsUrl from 'node:url';
11
- import cjsPath from 'node:path';
12
- const __filename = cjsUrl.fileURLToPath(import.meta.url);
13
- const __dirname = cjsPath.dirname(__filename);
14
- // -- End Shims --
15
- `;
16
-
17
- const CJSyntaxRegex = /__filename|__dirname/;
18
-
19
- return {
20
- name: "esm-shim",
21
-
22
- renderChunk(code, _chunk, opts) {
23
- if (opts.format === "es") {
24
- if (code.includes(ESMShim) || !CJSyntaxRegex.test(code)) {
25
- return null;
26
- }
27
-
28
- let endIndexOfLastImport = -1;
29
-
30
- // Find the last import statement and its ending index
31
- for (const match of code.matchAll(/^import\s.*';$/gm)) {
32
- if (match.length === 0 || typeof match.index !== "number") {
33
- continue;
34
- }
35
-
36
- endIndexOfLastImport = match.index + match[0].length;
37
- }
38
-
39
- const s = new MagicString(code);
40
- s.appendRight(endIndexOfLastImport, ESMShim);
41
-
42
- const sourceMap = s.generateMap({
43
- includeContent: true,
44
- });
45
-
46
- let sourcesContent: string[] | undefined;
47
- if (Array.isArray(sourceMap.sourcesContent)) {
48
- sourcesContent = [];
49
- for (let i = 0; i < sourceMap.sourcesContent.length; i++) {
50
- const content = sourceMap.sourcesContent[i];
51
- if (typeof content === "string") {
52
- sourcesContent.push(content);
53
- }
54
- }
55
- }
56
-
57
- return {
58
- code: s.toString(),
59
- map: {
60
- ...sourceMap,
61
- sourcesContent,
62
- },
63
- };
64
- }
65
-
66
- return null;
67
- },
68
- };
69
- }
@@ -1,8 +0,0 @@
1
- import type {
2
- InputOptions as RollupInputOptions,
3
- OutputOptions as RollupOutputOptions,
4
- } from "rollup";
5
-
6
- export type RollupConfig = RollupInputOptions & {
7
- output: RollupOutputOptions;
8
- };
@@ -1,3 +0,0 @@
1
- import type { ApibaraConfig } from "apibara/types";
2
-
3
- export const config: ApibaraConfig = {};