ponder 0.9.2 → 0.9.3
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/bin/ponder.js +1933 -1606
- package/dist/bin/ponder.js.map +1 -1
- package/dist/{chunk-IFTUFVCL.js → chunk-LHCA5XFV.js} +2 -5
- package/dist/chunk-LHCA5XFV.js.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/bin/commands/codegen.ts +8 -10
- package/src/bin/commands/dev.ts +30 -42
- package/src/bin/commands/list.ts +9 -14
- package/src/bin/commands/serve.ts +26 -39
- package/src/bin/commands/start.ts +29 -42
- package/src/bin/utils/{shutdown.ts → exit.ts} +23 -37
- package/src/bin/utils/run.ts +275 -175
- package/src/bin/utils/runServer.ts +1 -5
- package/src/build/index.ts +3 -8
- package/src/build/pre.ts +3 -0
- package/src/config/index.ts +5 -2
- package/src/database/index.ts +72 -72
- package/src/drizzle/kit/index.ts +3 -3
- package/src/indexing/index.ts +0 -4
- package/src/indexing/service.ts +31 -93
- package/src/indexing-store/historical.ts +2 -4
- package/src/internal/common.ts +2 -0
- package/src/internal/errors.ts +9 -9
- package/src/internal/logger.ts +1 -1
- package/src/internal/metrics.ts +75 -103
- package/src/internal/shutdown.ts +25 -0
- package/src/internal/telemetry.ts +16 -18
- package/src/internal/types.ts +9 -1
- package/src/server/index.ts +3 -5
- package/src/sync/events.ts +4 -4
- package/src/sync/filter.ts +1 -0
- package/src/sync/index.ts +1046 -805
- package/src/sync-historical/index.ts +0 -37
- package/src/sync-realtime/index.ts +48 -48
- package/src/sync-store/encoding.ts +5 -5
- package/src/sync-store/index.ts +5 -23
- package/src/ui/index.ts +2 -11
- package/src/utils/checkpoint.ts +17 -3
- package/src/utils/chunk.ts +7 -0
- package/src/utils/generators.ts +66 -0
- package/src/utils/mutex.ts +34 -0
- package/src/utils/partition.ts +41 -0
- package/src/utils/requestQueue.ts +19 -10
- package/src/utils/zipper.ts +80 -0
- package/dist/chunk-IFTUFVCL.js.map +0 -1
package/package.json
CHANGED
|
@@ -2,9 +2,10 @@ import { runCodegen } from "@/bin/utils/codegen.js";
|
|
|
2
2
|
import { createLogger } from "@/internal/logger.js";
|
|
3
3
|
import { MetricsService } from "@/internal/metrics.js";
|
|
4
4
|
import { buildOptions } from "@/internal/options.js";
|
|
5
|
+
import { createShutdown } from "@/internal/shutdown.js";
|
|
5
6
|
import { createTelemetry } from "@/internal/telemetry.js";
|
|
6
7
|
import type { CliOptions } from "../ponder.js";
|
|
7
|
-
import {
|
|
8
|
+
import { createExit } from "../utils/exit.js";
|
|
8
9
|
|
|
9
10
|
export async function codegen({ cliOptions }: { cliOptions: CliOptions }) {
|
|
10
11
|
const options = buildOptions({ cliOptions });
|
|
@@ -22,19 +23,16 @@ export async function codegen({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
22
23
|
service: "process",
|
|
23
24
|
msg: `Invalid Node.js version. Expected >=18.14, detected ${major}.${minor}.`,
|
|
24
25
|
});
|
|
25
|
-
|
|
26
|
+
|
|
26
27
|
process.exit(1);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
const metrics = new MetricsService();
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const cleanup = async () => {
|
|
34
|
-
await telemetry.kill();
|
|
35
|
-
};
|
|
31
|
+
const shutdown = createShutdown();
|
|
32
|
+
const telemetry = createTelemetry({ options, logger, shutdown });
|
|
33
|
+
const common = { options, logger, metrics, telemetry, shutdown };
|
|
36
34
|
|
|
37
|
-
const
|
|
35
|
+
const exit = createExit({ common });
|
|
38
36
|
|
|
39
37
|
telemetry.record({
|
|
40
38
|
name: "lifecycle:session_start",
|
|
@@ -45,5 +43,5 @@ export async function codegen({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
45
43
|
|
|
46
44
|
logger.info({ service: "codegen", msg: "Wrote ponder-env.d.ts" });
|
|
47
45
|
|
|
48
|
-
await
|
|
46
|
+
await exit({ reason: "Success", code: 0 });
|
|
49
47
|
}
|
package/src/bin/commands/dev.ts
CHANGED
|
@@ -5,15 +5,16 @@ import { type Database, createDatabase } from "@/database/index.js";
|
|
|
5
5
|
import { createLogger } from "@/internal/logger.js";
|
|
6
6
|
import { MetricsService } from "@/internal/metrics.js";
|
|
7
7
|
import { buildOptions } from "@/internal/options.js";
|
|
8
|
+
import { createShutdown } from "@/internal/shutdown.js";
|
|
8
9
|
import { buildPayload, createTelemetry } from "@/internal/telemetry.js";
|
|
9
10
|
import type { IndexingBuild } from "@/internal/types.js";
|
|
10
11
|
import { createUi } from "@/ui/index.js";
|
|
11
12
|
import { type Result, mergeResults } from "@/utils/result.js";
|
|
12
13
|
import { createQueue } from "@ponder/common";
|
|
13
14
|
import type { CliOptions } from "../ponder.js";
|
|
15
|
+
import { createExit } from "../utils/exit.js";
|
|
14
16
|
import { run } from "../utils/run.js";
|
|
15
17
|
import { runServer } from "../utils/runServer.js";
|
|
16
|
-
import { setupShutdown } from "../utils/shutdown.js";
|
|
17
18
|
|
|
18
19
|
export async function dev({ cliOptions }: { cliOptions: CliOptions }) {
|
|
19
20
|
const options = buildOptions({ cliOptions });
|
|
@@ -31,7 +32,6 @@ export async function dev({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
31
32
|
service: "process",
|
|
32
33
|
msg: `Invalid Node.js version. Expected >=18.14, detected ${major}.${minor}.`,
|
|
33
34
|
});
|
|
34
|
-
await logger.kill();
|
|
35
35
|
process.exit(1);
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -49,29 +49,25 @@ export async function dev({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
const metrics = new MetricsService();
|
|
52
|
-
|
|
52
|
+
let indexingShutdown = createShutdown();
|
|
53
|
+
let apiShutdown = createShutdown();
|
|
54
|
+
const shutdown = createShutdown();
|
|
55
|
+
const telemetry = createTelemetry({ options, logger, shutdown });
|
|
53
56
|
const common = { options, logger, metrics, telemetry };
|
|
54
57
|
|
|
55
|
-
const build = await createBuild({
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
let indexingCleanupReloadable = () => Promise.resolve();
|
|
60
|
-
let apiCleanupReloadable = () => Promise.resolve();
|
|
58
|
+
const build = await createBuild({
|
|
59
|
+
common: { ...common, shutdown },
|
|
60
|
+
cliOptions,
|
|
61
|
+
});
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
await
|
|
64
|
-
await
|
|
63
|
+
shutdown.add(async () => {
|
|
64
|
+
await indexingShutdown.kill();
|
|
65
|
+
await apiShutdown.kill();
|
|
66
|
+
});
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
await database.kill();
|
|
68
|
-
}
|
|
69
|
-
await build.kill();
|
|
70
|
-
await telemetry.kill();
|
|
71
|
-
ui.kill();
|
|
72
|
-
};
|
|
68
|
+
createUi({ common: { ...common, shutdown } });
|
|
73
69
|
|
|
74
|
-
const
|
|
70
|
+
const exit = createExit({ common: { ...common, shutdown } });
|
|
75
71
|
|
|
76
72
|
let isInitialBuild = true;
|
|
77
73
|
|
|
@@ -80,27 +76,21 @@ export async function dev({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
80
76
|
concurrency: 1,
|
|
81
77
|
worker: async (result: Result<never> & { kind: "indexing" | "api" }) => {
|
|
82
78
|
if (result.kind === "indexing") {
|
|
83
|
-
await
|
|
79
|
+
await indexingShutdown.kill();
|
|
80
|
+
indexingShutdown = createShutdown();
|
|
84
81
|
}
|
|
85
|
-
await
|
|
82
|
+
await apiShutdown.kill();
|
|
83
|
+
apiShutdown = createShutdown();
|
|
86
84
|
|
|
87
85
|
if (result.status === "error") {
|
|
88
86
|
// This handles indexing function build failures on hot reload.
|
|
89
87
|
metrics.ponder_indexing_has_error.set(1);
|
|
90
|
-
if (result.kind === "indexing") {
|
|
91
|
-
indexingCleanupReloadable = () => Promise.resolve();
|
|
92
|
-
}
|
|
93
|
-
apiCleanupReloadable = () => Promise.resolve();
|
|
94
88
|
return;
|
|
95
89
|
}
|
|
96
90
|
|
|
97
91
|
if (result.kind === "indexing") {
|
|
98
92
|
metrics.resetIndexingMetrics();
|
|
99
93
|
|
|
100
|
-
if (database) {
|
|
101
|
-
await database.kill();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
94
|
const configResult = await build.executeConfig();
|
|
105
95
|
if (configResult.status === "error") {
|
|
106
96
|
buildQueue.add({
|
|
@@ -164,7 +154,7 @@ export async function dev({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
164
154
|
indexingBuild = indexingBuildResult.result;
|
|
165
155
|
|
|
166
156
|
database = await createDatabase({
|
|
167
|
-
common,
|
|
157
|
+
common: { ...common, shutdown: indexingShutdown },
|
|
168
158
|
namespace,
|
|
169
159
|
preBuild,
|
|
170
160
|
schemaBuild,
|
|
@@ -215,19 +205,20 @@ export async function dev({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
215
205
|
|
|
216
206
|
metrics.resetApiMetrics();
|
|
217
207
|
|
|
218
|
-
|
|
219
|
-
common,
|
|
208
|
+
runServer({
|
|
209
|
+
common: { ...common, shutdown: apiShutdown },
|
|
220
210
|
database,
|
|
221
211
|
apiBuild: apiBuildResult.result,
|
|
222
212
|
});
|
|
223
213
|
|
|
224
|
-
|
|
225
|
-
common,
|
|
214
|
+
run({
|
|
215
|
+
common: { ...common, shutdown: indexingShutdown },
|
|
226
216
|
database,
|
|
217
|
+
preBuild,
|
|
227
218
|
schemaBuild,
|
|
228
219
|
indexingBuild: indexingBuildResult.result,
|
|
229
220
|
onFatalError: () => {
|
|
230
|
-
|
|
221
|
+
exit({ reason: "Received fatal error", code: 1 });
|
|
231
222
|
},
|
|
232
223
|
onReloadableError: (error) => {
|
|
233
224
|
buildQueue.clear();
|
|
@@ -264,8 +255,8 @@ export async function dev({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
264
255
|
|
|
265
256
|
const apiBuild = buildResult.result;
|
|
266
257
|
|
|
267
|
-
|
|
268
|
-
common,
|
|
258
|
+
runServer({
|
|
259
|
+
common: { ...common, shutdown: apiShutdown },
|
|
269
260
|
database: database!,
|
|
270
261
|
apiBuild,
|
|
271
262
|
});
|
|
@@ -288,8 +279,5 @@ export async function dev({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
288
279
|
|
|
289
280
|
buildQueue.add({ status: "success", kind: "indexing" });
|
|
290
281
|
|
|
291
|
-
return
|
|
292
|
-
buildQueue.pause();
|
|
293
|
-
await cleanup();
|
|
294
|
-
};
|
|
282
|
+
return shutdown.kill;
|
|
295
283
|
}
|
package/src/bin/commands/list.ts
CHANGED
|
@@ -7,12 +7,13 @@ import {
|
|
|
7
7
|
import { createLogger } from "@/internal/logger.js";
|
|
8
8
|
import { MetricsService } from "@/internal/metrics.js";
|
|
9
9
|
import { buildOptions } from "@/internal/options.js";
|
|
10
|
+
import { createShutdown } from "@/internal/shutdown.js";
|
|
10
11
|
import { createTelemetry } from "@/internal/telemetry.js";
|
|
11
12
|
import { printTable } from "@/ui/Table.js";
|
|
12
13
|
import { formatEta } from "@/utils/format.js";
|
|
13
14
|
import { type SelectQueryBuilder, sql } from "kysely";
|
|
14
15
|
import type { CliOptions } from "../ponder.js";
|
|
15
|
-
import {
|
|
16
|
+
import { createExit } from "../utils/exit.js";
|
|
16
17
|
|
|
17
18
|
const emptySchemaBuild = {
|
|
18
19
|
schema: {},
|
|
@@ -32,28 +33,24 @@ export async function list({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
32
33
|
});
|
|
33
34
|
|
|
34
35
|
const metrics = new MetricsService();
|
|
35
|
-
const
|
|
36
|
-
const
|
|
36
|
+
const shutdown = createShutdown();
|
|
37
|
+
const telemetry = createTelemetry({ options, logger, shutdown });
|
|
38
|
+
const common = { options, logger, metrics, telemetry, shutdown };
|
|
37
39
|
|
|
38
40
|
const build = await createBuild({ common, cliOptions });
|
|
39
41
|
|
|
40
|
-
const
|
|
41
|
-
await build.kill();
|
|
42
|
-
await telemetry.kill();
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const shutdown = setupShutdown({ common, cleanup });
|
|
42
|
+
const exit = createExit({ common });
|
|
46
43
|
|
|
47
44
|
const configResult = await build.executeConfig();
|
|
48
45
|
if (configResult.status === "error") {
|
|
49
|
-
await
|
|
46
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
50
47
|
return;
|
|
51
48
|
}
|
|
52
49
|
|
|
53
50
|
const buildResult = build.preCompile(configResult.result);
|
|
54
51
|
|
|
55
52
|
if (buildResult.status === "error") {
|
|
56
|
-
await
|
|
53
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
57
54
|
return;
|
|
58
55
|
}
|
|
59
56
|
|
|
@@ -136,7 +133,5 @@ export async function list({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
136
133
|
})),
|
|
137
134
|
});
|
|
138
135
|
|
|
139
|
-
await
|
|
140
|
-
|
|
141
|
-
await shutdown({ reason: "Success", code: 0 });
|
|
136
|
+
await exit({ reason: "Success", code: 0 });
|
|
142
137
|
}
|
|
@@ -4,11 +4,12 @@ import { createDatabase } from "@/database/index.js";
|
|
|
4
4
|
import { createLogger } from "@/internal/logger.js";
|
|
5
5
|
import { MetricsService } from "@/internal/metrics.js";
|
|
6
6
|
import { buildOptions } from "@/internal/options.js";
|
|
7
|
+
import { createShutdown } from "@/internal/shutdown.js";
|
|
7
8
|
import { buildPayload, createTelemetry } from "@/internal/telemetry.js";
|
|
8
9
|
import { createServer } from "@/server/index.js";
|
|
9
10
|
import { mergeResults } from "@/utils/result.js";
|
|
10
11
|
import type { CliOptions } from "../ponder.js";
|
|
11
|
-
import {
|
|
12
|
+
import { createExit } from "../utils/exit.js";
|
|
12
13
|
|
|
13
14
|
export async function serve({ cliOptions }: { cliOptions: CliOptions }) {
|
|
14
15
|
const options = buildOptions({ cliOptions });
|
|
@@ -26,7 +27,6 @@ export async function serve({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
26
27
|
service: "process",
|
|
27
28
|
msg: `Invalid Node.js version. Expected >=18.14, detected ${major}.${minor}.`,
|
|
28
29
|
});
|
|
29
|
-
await logger.kill();
|
|
30
30
|
process.exit(1);
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -37,38 +37,32 @@ export async function serve({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
const metrics = new MetricsService();
|
|
40
|
-
const
|
|
41
|
-
const
|
|
40
|
+
const shutdown = createShutdown();
|
|
41
|
+
const telemetry = createTelemetry({ options, logger, shutdown });
|
|
42
|
+
const common = { options, logger, metrics, telemetry, shutdown };
|
|
42
43
|
|
|
43
44
|
const build = await createBuild({ common, cliOptions });
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const cleanup = async () => {
|
|
48
|
-
await cleanupReloadable();
|
|
49
|
-
await telemetry.kill();
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const shutdown = setupShutdown({ common, cleanup });
|
|
46
|
+
const exit = createExit({ common });
|
|
53
47
|
const namespaceResult = build.namespaceCompile();
|
|
54
48
|
|
|
55
49
|
if (namespaceResult.status === "error") {
|
|
56
|
-
await
|
|
57
|
-
return
|
|
50
|
+
await exit({ reason: "Failed to initialize namespace", code: 1 });
|
|
51
|
+
return;
|
|
58
52
|
}
|
|
59
53
|
|
|
60
54
|
const configResult = await build.executeConfig();
|
|
61
55
|
if (configResult.status === "error") {
|
|
62
|
-
await
|
|
63
|
-
return
|
|
56
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
57
|
+
return;
|
|
64
58
|
}
|
|
65
59
|
|
|
66
60
|
const schemaResult = await build.executeSchema({
|
|
67
61
|
namespace: namespaceResult.result,
|
|
68
62
|
});
|
|
69
63
|
if (schemaResult.status === "error") {
|
|
70
|
-
await
|
|
71
|
-
return
|
|
64
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
65
|
+
return;
|
|
72
66
|
}
|
|
73
67
|
|
|
74
68
|
const buildResult1 = mergeResults([
|
|
@@ -77,24 +71,24 @@ export async function serve({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
77
71
|
]);
|
|
78
72
|
|
|
79
73
|
if (buildResult1.status === "error") {
|
|
80
|
-
await
|
|
81
|
-
return
|
|
74
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
75
|
+
return;
|
|
82
76
|
}
|
|
83
77
|
|
|
84
78
|
const [preBuild, schemaBuild] = buildResult1.result;
|
|
85
79
|
|
|
86
80
|
if (preBuild.databaseConfig.kind === "pglite") {
|
|
87
|
-
await
|
|
81
|
+
await exit({
|
|
88
82
|
reason: "The 'ponder serve' command does not support PGlite",
|
|
89
83
|
code: 1,
|
|
90
84
|
});
|
|
91
|
-
return
|
|
85
|
+
return;
|
|
92
86
|
}
|
|
93
87
|
|
|
94
88
|
const indexingResult = await build.executeIndexingFunctions();
|
|
95
89
|
if (indexingResult.status === "error") {
|
|
96
|
-
await
|
|
97
|
-
return
|
|
90
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
91
|
+
return;
|
|
98
92
|
}
|
|
99
93
|
|
|
100
94
|
const indexingBuildResult = await build.compileIndexing({
|
|
@@ -104,8 +98,8 @@ export async function serve({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
104
98
|
});
|
|
105
99
|
|
|
106
100
|
if (indexingBuildResult.status === "error") {
|
|
107
|
-
await
|
|
108
|
-
return
|
|
101
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
102
|
+
return;
|
|
109
103
|
}
|
|
110
104
|
|
|
111
105
|
const database = await createDatabase({
|
|
@@ -120,17 +114,15 @@ export async function serve({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
120
114
|
database,
|
|
121
115
|
});
|
|
122
116
|
if (apiResult.status === "error") {
|
|
123
|
-
await
|
|
124
|
-
return
|
|
117
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
118
|
+
return;
|
|
125
119
|
}
|
|
126
120
|
|
|
127
|
-
await build.kill();
|
|
128
|
-
|
|
129
121
|
const buildResult2 = await build.compileApi({ apiResult: apiResult.result });
|
|
130
122
|
|
|
131
123
|
if (buildResult2.status === "error") {
|
|
132
|
-
await
|
|
133
|
-
return
|
|
124
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
125
|
+
return;
|
|
134
126
|
}
|
|
135
127
|
|
|
136
128
|
const apiBuild = buildResult2.result;
|
|
@@ -146,16 +138,11 @@ export async function serve({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
146
138
|
},
|
|
147
139
|
});
|
|
148
140
|
|
|
149
|
-
|
|
141
|
+
createServer({
|
|
150
142
|
common,
|
|
151
143
|
database,
|
|
152
144
|
apiBuild,
|
|
153
145
|
});
|
|
154
146
|
|
|
155
|
-
|
|
156
|
-
await server.kill();
|
|
157
|
-
await database.kill();
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
return cleanup;
|
|
147
|
+
return shutdown.kill;
|
|
161
148
|
}
|
|
@@ -4,12 +4,13 @@ import { type Database, createDatabase } from "@/database/index.js";
|
|
|
4
4
|
import { createLogger } from "@/internal/logger.js";
|
|
5
5
|
import { MetricsService } from "@/internal/metrics.js";
|
|
6
6
|
import { buildOptions } from "@/internal/options.js";
|
|
7
|
+
import { createShutdown } from "@/internal/shutdown.js";
|
|
7
8
|
import { buildPayload, createTelemetry } from "@/internal/telemetry.js";
|
|
8
9
|
import { mergeResults } from "@/utils/result.js";
|
|
9
10
|
import type { CliOptions } from "../ponder.js";
|
|
11
|
+
import { createExit } from "../utils/exit.js";
|
|
10
12
|
import { run } from "../utils/run.js";
|
|
11
13
|
import { runServer } from "../utils/runServer.js";
|
|
12
|
-
import { setupShutdown } from "../utils/shutdown.js";
|
|
13
14
|
|
|
14
15
|
export async function start({ cliOptions }: { cliOptions: CliOptions }) {
|
|
15
16
|
const options = buildOptions({ cliOptions });
|
|
@@ -27,7 +28,6 @@ export async function start({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
27
28
|
service: "process",
|
|
28
29
|
msg: `Invalid Node.js version. Expected >=18.14, detected ${major}.${minor}.`,
|
|
29
30
|
});
|
|
30
|
-
await logger.kill();
|
|
31
31
|
process.exit(1);
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -38,48 +38,36 @@ export async function start({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
const metrics = new MetricsService();
|
|
41
|
-
const
|
|
42
|
-
const
|
|
41
|
+
const shutdown = createShutdown();
|
|
42
|
+
const telemetry = createTelemetry({ options, logger, shutdown });
|
|
43
|
+
const common = { options, logger, metrics, telemetry, shutdown };
|
|
44
|
+
const exit = createExit({ common });
|
|
43
45
|
|
|
44
46
|
const build = await createBuild({ common, cliOptions });
|
|
45
47
|
|
|
46
|
-
let cleanupReloadable = () => Promise.resolve();
|
|
47
|
-
let cleanupReloadableServer = () => Promise.resolve();
|
|
48
|
-
|
|
49
48
|
// biome-ignore lint/style/useConst: <explanation>
|
|
50
49
|
let database: Database | undefined;
|
|
51
50
|
|
|
52
|
-
const
|
|
53
|
-
await cleanupReloadable();
|
|
54
|
-
await cleanupReloadableServer();
|
|
55
|
-
|
|
56
|
-
if (database) {
|
|
57
|
-
await database.kill();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
await telemetry.kill();
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const shutdown = setupShutdown({ common, cleanup });
|
|
51
|
+
// const shutdown = setupShutdown({ common, cleanup });
|
|
64
52
|
|
|
65
53
|
const namespaceResult = build.namespaceCompile();
|
|
66
54
|
if (namespaceResult.status === "error") {
|
|
67
|
-
await
|
|
68
|
-
return
|
|
55
|
+
await exit({ reason: "Failed to initialize namespace", code: 1 });
|
|
56
|
+
return;
|
|
69
57
|
}
|
|
70
58
|
|
|
71
59
|
const configResult = await build.executeConfig();
|
|
72
60
|
if (configResult.status === "error") {
|
|
73
|
-
await
|
|
74
|
-
return
|
|
61
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
62
|
+
return;
|
|
75
63
|
}
|
|
76
64
|
|
|
77
65
|
const schemaResult = await build.executeSchema({
|
|
78
66
|
namespace: namespaceResult.result,
|
|
79
67
|
});
|
|
80
68
|
if (schemaResult.status === "error") {
|
|
81
|
-
await
|
|
82
|
-
return
|
|
69
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
70
|
+
return;
|
|
83
71
|
}
|
|
84
72
|
|
|
85
73
|
const buildResult1 = mergeResults([
|
|
@@ -88,16 +76,16 @@ export async function start({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
88
76
|
]);
|
|
89
77
|
|
|
90
78
|
if (buildResult1.status === "error") {
|
|
91
|
-
await
|
|
92
|
-
return
|
|
79
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
80
|
+
return;
|
|
93
81
|
}
|
|
94
82
|
|
|
95
83
|
const [preBuild, schemaBuild] = buildResult1.result;
|
|
96
84
|
|
|
97
85
|
const indexingResult = await build.executeIndexingFunctions();
|
|
98
86
|
if (indexingResult.status === "error") {
|
|
99
|
-
await
|
|
100
|
-
return
|
|
87
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
88
|
+
return;
|
|
101
89
|
}
|
|
102
90
|
|
|
103
91
|
const indexingBuildResult = await build.compileIndexing({
|
|
@@ -107,8 +95,8 @@ export async function start({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
107
95
|
});
|
|
108
96
|
|
|
109
97
|
if (indexingBuildResult.status === "error") {
|
|
110
|
-
await
|
|
111
|
-
return
|
|
98
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
99
|
+
return;
|
|
112
100
|
}
|
|
113
101
|
|
|
114
102
|
database = await createDatabase({
|
|
@@ -124,8 +112,8 @@ export async function start({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
124
112
|
database,
|
|
125
113
|
});
|
|
126
114
|
if (apiResult.status === "error") {
|
|
127
|
-
await
|
|
128
|
-
return
|
|
115
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
116
|
+
return;
|
|
129
117
|
}
|
|
130
118
|
|
|
131
119
|
const apiBuildResult = await build.compileApi({
|
|
@@ -133,12 +121,10 @@ export async function start({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
133
121
|
});
|
|
134
122
|
|
|
135
123
|
if (apiBuildResult.status === "error") {
|
|
136
|
-
await
|
|
137
|
-
return
|
|
124
|
+
await exit({ reason: "Failed intial build", code: 1 });
|
|
125
|
+
return;
|
|
138
126
|
}
|
|
139
127
|
|
|
140
|
-
await build.kill();
|
|
141
|
-
|
|
142
128
|
telemetry.record({
|
|
143
129
|
name: "lifecycle:session_start",
|
|
144
130
|
properties: {
|
|
@@ -151,24 +137,25 @@ export async function start({ cliOptions }: { cliOptions: CliOptions }) {
|
|
|
151
137
|
},
|
|
152
138
|
});
|
|
153
139
|
|
|
154
|
-
|
|
140
|
+
run({
|
|
155
141
|
common,
|
|
156
142
|
database,
|
|
143
|
+
preBuild,
|
|
157
144
|
schemaBuild,
|
|
158
145
|
indexingBuild: indexingBuildResult.result,
|
|
159
146
|
onFatalError: () => {
|
|
160
|
-
|
|
147
|
+
exit({ reason: "Received fatal error", code: 1 });
|
|
161
148
|
},
|
|
162
149
|
onReloadableError: () => {
|
|
163
|
-
|
|
150
|
+
exit({ reason: "Encountered indexing error", code: 1 });
|
|
164
151
|
},
|
|
165
152
|
});
|
|
166
153
|
|
|
167
|
-
|
|
154
|
+
runServer({
|
|
168
155
|
common,
|
|
169
156
|
database,
|
|
170
157
|
apiBuild: apiBuildResult.result,
|
|
171
158
|
});
|
|
172
159
|
|
|
173
|
-
return
|
|
160
|
+
return shutdown.kill;
|
|
174
161
|
}
|