apibara 2.1.0-beta.3 → 2.1.0-beta.31
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/chunks/add.mjs +17 -8
- package/dist/chunks/add.mjs.map +1 -0
- package/dist/chunks/build.mjs +5 -2
- package/dist/chunks/build.mjs.map +1 -0
- package/dist/chunks/dev.mjs +56 -21
- package/dist/chunks/dev.mjs.map +1 -0
- package/dist/chunks/init.mjs +12 -7
- package/dist/chunks/init.mjs.map +1 -0
- package/dist/chunks/prepare.mjs +5 -2
- package/dist/chunks/prepare.mjs.map +1 -0
- package/dist/chunks/start.mjs +16 -11
- package/dist/chunks/start.mjs.map +1 -0
- package/dist/chunks/write-project-info.mjs +51 -0
- package/dist/chunks/write-project-info.mjs.map +1 -0
- package/dist/cli/index.mjs +3 -1
- package/dist/cli/index.mjs.map +1 -0
- package/dist/common/index.d.mts +28 -0
- package/dist/common/index.d.ts +28 -0
- package/dist/common/index.mjs +64 -0
- package/dist/common/index.mjs.map +1 -0
- package/dist/config/index.mjs +1 -0
- package/dist/config/index.mjs.map +1 -0
- package/dist/core/index.mjs +133 -68
- package/dist/core/index.mjs.map +1 -0
- package/dist/create/index.d.mts +2 -1
- package/dist/create/index.d.ts +2 -1
- package/dist/create/index.mjs +144 -115
- package/dist/create/index.mjs.map +1 -0
- package/dist/hooks/index.mjs +6 -1
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/indexer/index.d.ts +1 -0
- package/dist/indexer/index.mjs +1 -0
- package/dist/indexer/plugins.d.ts +1 -0
- package/dist/indexer/plugins.mjs +1 -0
- package/dist/indexer/testing.d.ts +1 -0
- package/dist/indexer/testing.mjs +1 -0
- package/dist/indexer/vcr.d.ts +1 -0
- package/dist/indexer/vcr.mjs +1 -0
- package/dist/rolldown/index.d.mts +7 -0
- package/dist/rolldown/index.d.ts +7 -0
- package/dist/rolldown/index.mjs +122 -0
- package/dist/rolldown/index.mjs.map +1 -0
- package/dist/runtime/dev.mjs +23 -10
- package/dist/runtime/internal/app.d.ts +16 -1
- package/dist/runtime/internal/app.mjs +51 -21
- package/dist/runtime/project-info.d.ts +3 -0
- package/dist/runtime/project-info.mjs +67 -0
- package/dist/runtime/start.mjs +27 -10
- package/dist/shared/apibara.63c9a277.mjs +30 -0
- package/dist/shared/apibara.63c9a277.mjs.map +1 -0
- package/dist/shared/apibara.730bb1e4.mjs +18 -0
- package/dist/shared/apibara.730bb1e4.mjs.map +1 -0
- package/dist/types/index.d.mts +24 -20
- package/dist/types/index.d.ts +24 -20
- package/dist/types/index.mjs +1 -0
- package/dist/types/index.mjs.map +1 -0
- package/package.json +33 -16
- package/src/cli/commands/add.ts +16 -7
- package/src/cli/commands/build.ts +5 -2
- package/src/cli/commands/dev.ts +64 -20
- package/src/cli/commands/init.ts +12 -7
- package/src/cli/commands/prepare.ts +4 -2
- package/src/cli/commands/start.ts +17 -10
- package/src/cli/commands/write-project-info.ts +56 -0
- package/src/cli/common.ts +33 -1
- package/src/cli/index.ts +2 -0
- package/src/common/constants.ts +6 -0
- package/src/common/helper.ts +86 -0
- package/src/common/index.ts +2 -0
- package/src/core/apibara.ts +7 -2
- package/src/core/build/build.ts +13 -5
- package/src/core/build/dev.ts +46 -23
- package/src/core/build/error.ts +9 -14
- package/src/core/build/prepare.ts +5 -3
- package/src/core/build/prod.ts +25 -16
- package/src/core/build/types.ts +11 -1
- package/src/core/config/defaults.ts +3 -0
- package/src/core/config/loader.ts +15 -7
- package/src/core/config/resolvers/runtime.resolver.ts +44 -0
- package/src/core/config/update.ts +6 -2
- package/src/create/add.ts +10 -9
- package/src/create/constants.ts +9 -11
- package/src/create/init.ts +8 -5
- package/src/create/templates.ts +132 -105
- package/src/hooks/useRuntimeConfig.ts +4 -1
- package/src/indexer/index.ts +1 -0
- package/src/indexer/plugins.ts +1 -0
- package/src/indexer/testing.ts +1 -0
- package/src/indexer/vcr.ts +1 -0
- package/src/rolldown/config.ts +84 -0
- package/src/rolldown/index.ts +2 -0
- package/src/{rollup → rolldown}/plugins/indexers.ts +3 -3
- package/src/rolldown/plugins/instrumentation.ts +68 -0
- package/src/runtime/dev.ts +25 -9
- package/src/runtime/internal/app.ts +75 -29
- package/src/runtime/project-info.ts +90 -0
- package/src/runtime/start.ts +30 -9
- package/src/types/config.ts +27 -13
- package/src/types/hooks.ts +8 -5
- package/src/types/index.ts +1 -1
- package/src/types/rolldown.ts +5 -0
- package/src/types/virtual/indexers.d.ts +4 -1
- package/src/types/virtual/instrumentation.d.ts +4 -0
- package/dist/rollup/index.d.mts +0 -6
- package/dist/rollup/index.d.ts +0 -6
- package/dist/rollup/index.mjs +0 -150
- package/dist/shared/apibara.1b515d04.mjs +0 -8
- package/src/core/config/resolvers/preset.resolver.ts +0 -9
- package/src/core/config/resolvers/runtime-config.resolver.ts +0 -6
- package/src/rollup/config.ts +0 -87
- package/src/rollup/index.ts +0 -2
- package/src/rollup/plugins/config.ts +0 -12
- package/src/rollup/plugins/esm-shim.ts +0 -69
- package/src/types/rollup.ts +0 -8
- package/src/types/virtual/config.d.ts +0 -3
|
@@ -8,32 +8,34 @@ import {
|
|
|
8
8
|
inMemoryPersistence,
|
|
9
9
|
logger,
|
|
10
10
|
} from "@apibara/indexer/plugins";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
type CreateClientOptions,
|
|
13
|
+
Metadata,
|
|
14
|
+
type StreamConfig,
|
|
15
|
+
createClient,
|
|
16
|
+
} from "@apibara/protocol";
|
|
17
|
+
import consola from "consola";
|
|
12
18
|
import { indexers } from "#apibara-internal-virtual/indexers";
|
|
19
|
+
import { logger as instrumentationLogger } from "#apibara-internal-virtual/instrumentation";
|
|
13
20
|
import { createLogger } from "./logger";
|
|
14
21
|
|
|
15
22
|
export const availableIndexers = indexers.map((i) => i.name);
|
|
16
23
|
|
|
17
|
-
export function createIndexer(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
runtimeConfig: Record<string, unknown>;
|
|
33
|
-
};
|
|
34
|
-
runtimeConfig = { ...runtimeConfig, ...presetValue.runtimeConfig };
|
|
35
|
-
}
|
|
36
|
-
|
|
24
|
+
export function createIndexer({
|
|
25
|
+
indexerName,
|
|
26
|
+
processedRuntimeConfig,
|
|
27
|
+
preset,
|
|
28
|
+
}: {
|
|
29
|
+
indexerName: string;
|
|
30
|
+
/**
|
|
31
|
+
* Final processed runtime config to be used by the indexer
|
|
32
|
+
*/
|
|
33
|
+
processedRuntimeConfig: Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Preset name which was used to generate the runtime config
|
|
36
|
+
*/
|
|
37
|
+
preset?: string;
|
|
38
|
+
}) {
|
|
37
39
|
const indexerDefinition = indexers.find((i) => i.name === indexerName);
|
|
38
40
|
|
|
39
41
|
if (indexerDefinition === undefined) {
|
|
@@ -42,10 +44,18 @@ export function createIndexer(indexerName: string, preset?: string) {
|
|
|
42
44
|
);
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
const indexerModule = indexerDefinition.indexer?.default;
|
|
48
|
+
if (indexerModule === undefined) {
|
|
49
|
+
consola.warn(
|
|
50
|
+
`Specified indexer "${indexerName}" but it does not export a default. Ignoring.`,
|
|
51
|
+
);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
45
55
|
const definition =
|
|
46
|
-
typeof
|
|
47
|
-
?
|
|
48
|
-
:
|
|
56
|
+
typeof indexerModule === "function"
|
|
57
|
+
? indexerModule(processedRuntimeConfig)
|
|
58
|
+
: indexerModule;
|
|
49
59
|
|
|
50
60
|
let reporter: ConsolaReporter = createLogger({
|
|
51
61
|
indexer: indexerName,
|
|
@@ -53,26 +63,62 @@ export function createIndexer(indexerName: string, preset?: string) {
|
|
|
53
63
|
indexers: availableIndexers,
|
|
54
64
|
});
|
|
55
65
|
|
|
56
|
-
if
|
|
57
|
-
|
|
66
|
+
// Check if a custom logger is provided through instrumentation
|
|
67
|
+
if (instrumentationLogger) {
|
|
68
|
+
// Create a reporter using the custom logger function
|
|
69
|
+
const _reporter = instrumentationLogger({
|
|
58
70
|
indexer: indexerName,
|
|
59
71
|
preset,
|
|
60
72
|
indexers: availableIndexers,
|
|
61
73
|
});
|
|
74
|
+
|
|
75
|
+
// If the reporter is valid (has a log method), use it instead of the default
|
|
76
|
+
if (_reporter && "log" in _reporter) {
|
|
77
|
+
reporter = _reporter;
|
|
78
|
+
}
|
|
62
79
|
}
|
|
63
80
|
|
|
64
81
|
// Put the in-memory persistence plugin first so that it can be overridden by any user-defined
|
|
65
82
|
// persistence plugin.
|
|
66
|
-
// Put the logger last since we want to override any user-defined logger.
|
|
67
83
|
definition.plugins = [
|
|
68
84
|
internalContext({
|
|
69
85
|
indexerName,
|
|
70
86
|
availableIndexers,
|
|
71
87
|
} as InternalContext),
|
|
88
|
+
logger({ logger: reporter }),
|
|
72
89
|
inMemoryPersistence(),
|
|
73
90
|
...(definition.plugins ?? []),
|
|
74
|
-
logger({ logger: reporter }),
|
|
75
91
|
];
|
|
76
92
|
|
|
77
|
-
return
|
|
93
|
+
return {
|
|
94
|
+
indexer: _createIndexer(definition),
|
|
95
|
+
logger: consola.create({ reporters: [reporter] }),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function createAuthenticatedClient(
|
|
100
|
+
config: StreamConfig<unknown, unknown>,
|
|
101
|
+
streamUrl: string,
|
|
102
|
+
options?: CreateClientOptions,
|
|
103
|
+
) {
|
|
104
|
+
const dnaToken = process.env.DNA_TOKEN;
|
|
105
|
+
if (!dnaToken) {
|
|
106
|
+
consola.warn(
|
|
107
|
+
"DNA_TOKEN environment variable is not set. Trying to connect without authentication.",
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return createClient(config, streamUrl, {
|
|
112
|
+
...options,
|
|
113
|
+
defaultCallOptions: {
|
|
114
|
+
...(options?.defaultCallOptions ?? {}),
|
|
115
|
+
"*": {
|
|
116
|
+
metadata: Metadata({
|
|
117
|
+
Authorization: `Bearer ${dnaToken}`,
|
|
118
|
+
}),
|
|
119
|
+
// metadata cant be overrided with spread as its a class so we override it fully if user provided it.
|
|
120
|
+
...(options?.defaultCallOptions?.["*"] ?? {}),
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
});
|
|
78
124
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
getProcessedRuntimeConfig,
|
|
5
|
+
getRuntimeDataFromEnv,
|
|
6
|
+
} from "apibara/common";
|
|
7
|
+
import { defineCommand, runMain } from "citty";
|
|
8
|
+
import { availableIndexers, createIndexer } from "./internal/app";
|
|
9
|
+
|
|
10
|
+
type ProjectInfo = {
|
|
11
|
+
indexers: {
|
|
12
|
+
[indexerName: string]: {
|
|
13
|
+
[presetName: string]: {
|
|
14
|
+
type: string;
|
|
15
|
+
isFactory: boolean;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const startCommand = defineCommand({
|
|
22
|
+
meta: {
|
|
23
|
+
name: "write-project-info",
|
|
24
|
+
description: "Write json-encoded information about the project.",
|
|
25
|
+
},
|
|
26
|
+
args: {
|
|
27
|
+
"build-dir": {
|
|
28
|
+
type: "string",
|
|
29
|
+
description: "project build directory",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
async run({ args }) {
|
|
33
|
+
const projectInfo: ProjectInfo = {
|
|
34
|
+
indexers: {},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// get all original runtime data from env
|
|
38
|
+
const { presets, runtimeConfig, userEnvRuntimeConfig } =
|
|
39
|
+
getRuntimeDataFromEnv();
|
|
40
|
+
|
|
41
|
+
for (const preset of Object.keys(presets ?? {})) {
|
|
42
|
+
// process runtime config for each preset
|
|
43
|
+
const processedRuntimeConfig = getProcessedRuntimeConfig({
|
|
44
|
+
preset,
|
|
45
|
+
presets,
|
|
46
|
+
runtimeConfig,
|
|
47
|
+
userEnvRuntimeConfig,
|
|
48
|
+
});
|
|
49
|
+
for (const indexer of availableIndexers) {
|
|
50
|
+
const { indexer: indexerInstance } =
|
|
51
|
+
createIndexer({
|
|
52
|
+
indexerName: indexer,
|
|
53
|
+
processedRuntimeConfig,
|
|
54
|
+
preset,
|
|
55
|
+
}) ?? {};
|
|
56
|
+
if (!indexerInstance) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
projectInfo.indexers[indexer] = {
|
|
60
|
+
...(projectInfo.indexers[indexer] ?? {}),
|
|
61
|
+
[preset]: {
|
|
62
|
+
type: indexerInstance.streamConfig.name,
|
|
63
|
+
isFactory: indexerInstance.options.factory !== undefined,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const projectInfoPath = resolve(
|
|
70
|
+
args["build-dir"] ?? ".apibara",
|
|
71
|
+
"project-info.json",
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
writeFileSync(projectInfoPath, JSON.stringify(projectInfo, null, 2));
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export const mainCli = defineCommand({
|
|
79
|
+
meta: {
|
|
80
|
+
name: "write-project-info-runner",
|
|
81
|
+
description: "Write json-encoded information about the project.",
|
|
82
|
+
},
|
|
83
|
+
subCommands: {
|
|
84
|
+
start: () => startCommand,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
runMain(mainCli);
|
|
89
|
+
|
|
90
|
+
export default {};
|
package/src/runtime/start.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { runWithReconnect } from "@apibara/indexer";
|
|
2
|
-
import {
|
|
2
|
+
import { getRuntimeDataFromEnv } from "apibara/common";
|
|
3
3
|
import { defineCommand, runMain } from "citty";
|
|
4
|
-
import
|
|
4
|
+
import consola from "consola";
|
|
5
|
+
import { blueBright } from "picocolors";
|
|
6
|
+
import { register } from "#apibara-internal-virtual/instrumentation";
|
|
7
|
+
import { createAuthenticatedClient, createIndexer } from "./internal/app";
|
|
5
8
|
|
|
6
9
|
const startCommand = defineCommand({
|
|
7
10
|
meta: {
|
|
@@ -14,21 +17,39 @@ const startCommand = defineCommand({
|
|
|
14
17
|
description: "Indexer name",
|
|
15
18
|
required: true,
|
|
16
19
|
},
|
|
17
|
-
preset: {
|
|
18
|
-
type: "string",
|
|
19
|
-
description: "Preset to use",
|
|
20
|
-
},
|
|
21
20
|
},
|
|
22
21
|
async run({ args }) {
|
|
23
|
-
const { indexer
|
|
22
|
+
const { indexer } = args;
|
|
23
|
+
|
|
24
|
+
const { processedRuntimeConfig, preset } = getRuntimeDataFromEnv();
|
|
24
25
|
|
|
25
|
-
const
|
|
26
|
+
const { indexer: indexerInstance, logger } =
|
|
27
|
+
createIndexer({
|
|
28
|
+
indexerName: indexer,
|
|
29
|
+
processedRuntimeConfig,
|
|
30
|
+
preset,
|
|
31
|
+
}) ?? {};
|
|
32
|
+
if (!indexerInstance) {
|
|
33
|
+
consola.error(`Specified indexer "${indexer}" but it was not defined`);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
26
36
|
|
|
27
|
-
const client =
|
|
37
|
+
const client = createAuthenticatedClient(
|
|
28
38
|
indexerInstance.streamConfig,
|
|
29
39
|
indexerInstance.options.streamUrl,
|
|
40
|
+
indexerInstance.options.clientOptions,
|
|
30
41
|
);
|
|
31
42
|
|
|
43
|
+
if (register) {
|
|
44
|
+
consola.start("Registering from instrumentation");
|
|
45
|
+
await register();
|
|
46
|
+
consola.success("Registered from instrumentation");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (logger) {
|
|
50
|
+
logger.info(`Indexer ${blueBright(indexer)} started`);
|
|
51
|
+
}
|
|
52
|
+
|
|
32
53
|
await runWithReconnect(client, indexerInstance);
|
|
33
54
|
},
|
|
34
55
|
});
|
package/src/types/config.ts
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
import type { ConsolaReporter } from "@apibara/indexer/plugins";
|
|
2
|
-
import type { RollupCommonJSOptions } from "@rollup/plugin-commonjs";
|
|
3
2
|
import type {
|
|
4
3
|
C12InputConfig,
|
|
5
4
|
ConfigWatcher,
|
|
6
5
|
ResolvedConfig,
|
|
7
6
|
WatchConfigOptions,
|
|
8
7
|
} from "c12";
|
|
9
|
-
import type { WatchOptions } from "chokidar";
|
|
10
8
|
import type { NestedHooks } from "hookable";
|
|
9
|
+
import type { WatchOptions } from "rolldown";
|
|
10
|
+
import type { RolldownOptions } from "rolldown";
|
|
11
11
|
import type { DeepPartial } from "./_utils";
|
|
12
12
|
import type { ApibaraHooks } from "./hooks";
|
|
13
|
-
import type { RollupConfig } from "./rollup";
|
|
14
13
|
|
|
15
|
-
export type
|
|
14
|
+
export type RegisterFn = () => Promise<void>;
|
|
15
|
+
|
|
16
|
+
export type LoggerFactoryFn = ({
|
|
16
17
|
indexer,
|
|
18
|
+
indexers,
|
|
17
19
|
preset,
|
|
18
|
-
}:
|
|
20
|
+
}: LoggerFactoryArgs) => ConsolaReporter;
|
|
21
|
+
|
|
22
|
+
export type LoggerFactoryArgs = {
|
|
23
|
+
indexer: string;
|
|
24
|
+
indexers: string[];
|
|
25
|
+
preset?: string;
|
|
26
|
+
};
|
|
19
27
|
|
|
20
28
|
/**
|
|
21
29
|
* Apibara Config type (apibara.config)
|
|
@@ -31,10 +39,12 @@ export interface ApibaraConfig<
|
|
|
31
39
|
runtimeConfig?: R;
|
|
32
40
|
presets?: T;
|
|
33
41
|
preset?: keyof T;
|
|
34
|
-
logger?: LoggerFactory;
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
export type ApibaraDynamicConfig = Pick<
|
|
44
|
+
export type ApibaraDynamicConfig = Pick<
|
|
45
|
+
ApibaraConfig,
|
|
46
|
+
"runtimeConfig" | "preset" | "presets"
|
|
47
|
+
>;
|
|
38
48
|
|
|
39
49
|
/**
|
|
40
50
|
* Config loader options
|
|
@@ -68,22 +78,26 @@ export interface ApibaraOptions<
|
|
|
68
78
|
buildDir: string;
|
|
69
79
|
outputDir: string;
|
|
70
80
|
indexersDir: string;
|
|
81
|
+
disableLogs?: boolean;
|
|
71
82
|
|
|
72
83
|
// Dev
|
|
73
84
|
dev: boolean;
|
|
74
|
-
watchOptions: WatchOptions;
|
|
85
|
+
watchOptions: WatchOptions["watch"];
|
|
75
86
|
|
|
76
87
|
// Hooks
|
|
77
88
|
hooks: NestedHooks<ApibaraHooks>;
|
|
78
89
|
|
|
79
|
-
//
|
|
80
|
-
|
|
90
|
+
// Rolldown
|
|
91
|
+
rolldownConfig?: Partial<RolldownOptions>;
|
|
81
92
|
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
/**
|
|
94
|
+
* @deprecated Use rolldownConfig instead. This option will be removed in future releases.
|
|
95
|
+
*/
|
|
96
|
+
rollupConfig?: unknown;
|
|
84
97
|
sourceMap?: boolean;
|
|
85
98
|
entry: string;
|
|
86
|
-
|
|
99
|
+
node: boolean;
|
|
100
|
+
exportConditions?: string[];
|
|
87
101
|
|
|
88
102
|
// Advanced
|
|
89
103
|
typescript: {
|
package/src/types/hooks.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import type { RolldownOptions } from "rolldown";
|
|
1
2
|
import type { Apibara } from "./apibara";
|
|
2
|
-
import type { RollupConfig } from "./rollup";
|
|
3
3
|
|
|
4
4
|
export interface ApibaraHooks {
|
|
5
|
-
"
|
|
5
|
+
"rolldown:before": (
|
|
6
|
+
apibara: Apibara,
|
|
7
|
+
rolldownConfig: RolldownOptions,
|
|
8
|
+
) => void;
|
|
6
9
|
compiled: (apibara: Apibara) => void;
|
|
7
|
-
"dev:restart": () => void
|
|
8
|
-
"dev:reload": () => void
|
|
9
|
-
"
|
|
10
|
+
"dev:restart": () => Promise<void>;
|
|
11
|
+
"dev:reload": () => Promise<void>;
|
|
12
|
+
"rolldown:reload": () => Promise<void>;
|
|
10
13
|
restart: () => void;
|
|
11
14
|
close: () => void;
|
|
12
15
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -7,4 +7,7 @@ export type IndexerConstructor =
|
|
|
7
7
|
) => IndexerWithStreamConfig<unknown, unknown, unknown>)
|
|
8
8
|
| IndexerWithStreamConfig<unknown, unknown, unknown>;
|
|
9
9
|
|
|
10
|
-
export const indexers: {
|
|
10
|
+
export const indexers: {
|
|
11
|
+
name: string;
|
|
12
|
+
indexer: { default?: IndexerConstructor | undefined };
|
|
13
|
+
}[] = [];
|
package/dist/rollup/index.d.mts
DELETED
package/dist/rollup/index.d.ts
DELETED
package/dist/rollup/index.mjs
DELETED
|
@@ -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,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
|
-
}
|