@malloy-publisher/server 0.0.382-dev → 0.2.0
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/README.docker.md +145 -20
- package/README.md +65 -12
- package/dist/app/api-doc.html +5 -0
- package/dist/app/api-doc.yaml +3903 -583
- package/dist/app/assets/EnvironmentPage-DiUgLuCH.js +1 -0
- package/dist/app/assets/HomePage-MhhjhnFj.js +1 -0
- package/dist/app/assets/LightMode-BEyvNUzT.js +1 -0
- package/dist/app/assets/MainPage-D4Cfee9o.js +2 -0
- package/dist/app/assets/MaterializationsPage-nGgGqwSN.js +1 -0
- package/dist/app/assets/ModelPage-DLAcEw-F.js +1 -0
- package/dist/app/assets/PackagePage-Df0ikH7w.js +1 -0
- package/dist/app/assets/RouteError-BFQwtroH.js +1 -0
- package/dist/app/assets/ThemeEditorPage-OoskoQYN.js +1 -0
- package/dist/app/assets/WorkbookPage-CpFgvUDC.js +1 -0
- package/dist/app/assets/{core-CjeTkq8O.es-BqRc6yhC.js → core-lb28vQkR.es-BoVSOc75.js} +1 -1
- package/dist/app/assets/github-dark-DenFmJkN.es-DHJKELXO.js +1 -0
- package/dist/app/assets/index-5eLCcNmP.css +1 -0
- package/dist/app/assets/index-6ypuFH6g.js +1774 -0
- package/dist/app/assets/index-B8pnU_V_.js +615 -0
- package/dist/app/assets/index-BImcHmVP.js +1 -0
- package/dist/app/assets/index-DSoCUF-f.js +2725 -0
- package/dist/app/assets/index-DfqzSItA.js +2 -0
- package/dist/app/assets/index-w_0OQJgZ.js +23 -0
- package/dist/app/index.html +8 -4
- package/dist/cpufeatures-1yrn0vtw.node +0 -0
- package/dist/default-publisher.config.json +23 -0
- package/dist/{instrumentation.js → instrumentation.mjs} +10631 -10573
- package/dist/package_load_worker.mjs +15219 -0
- package/dist/runtime/publisher.js +331 -0
- package/dist/{server.js → server.mjs} +115548 -49590
- package/dist/sshcrypto-vd2k5hq9.node +0 -0
- package/package.json +41 -28
- package/publisher.config.example.bigquery.json +33 -0
- package/publisher.config.example.duckdb.json +23 -0
- package/.eslintrc.json +0 -44
- package/.prettierignore +0 -1
- package/.prettierrc +0 -4
- package/build.ts +0 -38
- package/dist/app/assets/HomePage-Dn3E4CuB.js +0 -1
- package/dist/app/assets/MainPage-BzB3yoqi.js +0 -2
- package/dist/app/assets/ModelPage-C9O_sAXT.js +0 -1
- package/dist/app/assets/PackagePage-DcxKEjBX.js +0 -1
- package/dist/app/assets/ProjectPage-BDj307rF.js +0 -1
- package/dist/app/assets/RouteError-DAShbVCG.js +0 -1
- package/dist/app/assets/WorkbookPage-Cs_XYEaB.js +0 -1
- package/dist/app/assets/index-15BOvhp0.js +0 -456
- package/dist/app/assets/index-Bb2jqquW.js +0 -676
- package/dist/app/assets/index-CMlGQMcl.css +0 -1
- package/dist/app/assets/index-D68X76-7.js +0 -1276
- package/dist/app/assets/index.umd-DGBekgSu.js +0 -1145
- package/dxt/malloy_bridge.py +0 -354
- package/dxt/manifest.json +0 -22
- package/eslint.config.mjs +0 -76
- package/k6-tests/README.md +0 -144
- package/k6-tests/bun.lock +0 -797
- package/k6-tests/load-test/load-test-crud-connections.ts +0 -263
- package/k6-tests/load-test/load-test-crud-packages.ts +0 -461
- package/k6-tests/load-test/load-test-crud-projects.ts +0 -160
- package/k6-tests/load-test/load-test-crud.ts +0 -142
- package/k6-tests/load-test/load-test.ts +0 -784
- package/k6-tests/package.json +0 -27
- package/k6-tests/scripts/run-with-otel.sh +0 -50
- package/k6-tests/smoke-test/smoke-test.ts +0 -158
- package/k6-tests/tsconfig.json +0 -29
- package/k6-tests/utils/client_factory.ts +0 -128
- package/k6-tests/utils/common.ts +0 -489
- package/k6-tests/utils/logger.ts +0 -62
- package/k6-tests/utils/types.d.ts +0 -35
- package/malloy_mcp.dxt +0 -0
- package/publisher.config.json +0 -33
- package/src/config.spec.ts +0 -850
- package/src/config.ts +0 -305
- package/src/constants.ts +0 -10
- package/src/controller/compile.controller.ts +0 -35
- package/src/controller/connection.controller.ts +0 -515
- package/src/controller/database.controller.ts +0 -21
- package/src/controller/manifest.controller.ts +0 -29
- package/src/controller/materialization.controller.ts +0 -125
- package/src/controller/model.controller.ts +0 -107
- package/src/controller/package.controller.ts +0 -182
- package/src/controller/query.controller.ts +0 -60
- package/src/controller/watch-mode.controller.ts +0 -98
- package/src/data_styles.ts +0 -71
- package/src/dto/connection.dto.spec.ts +0 -131
- package/src/dto/connection.dto.ts +0 -174
- package/src/dto/index.ts +0 -2
- package/src/dto/package.dto.spec.ts +0 -42
- package/src/dto/package.dto.ts +0 -12
- package/src/dto/validate.spec.ts +0 -76
- package/src/dto/validate.ts +0 -31
- package/src/errors.ts +0 -116
- package/src/health.ts +0 -189
- package/src/instrumentation.ts +0 -148
- package/src/logger.ts +0 -154
- package/src/mcp/error_messages.ts +0 -199
- package/src/mcp/handler_utils.ts +0 -239
- package/src/mcp/mcp_constants.ts +0 -22
- package/src/mcp/prompts/handlers.ts +0 -84
- package/src/mcp/prompts/index.ts +0 -11
- package/src/mcp/prompts/prompt_definitions.ts +0 -160
- package/src/mcp/prompts/prompt_service.ts +0 -67
- package/src/mcp/prompts/utils.ts +0 -62
- package/src/mcp/resource_metadata.ts +0 -47
- package/src/mcp/resources/model_resource.ts +0 -153
- package/src/mcp/resources/notebook_resource.ts +0 -137
- package/src/mcp/resources/package_resource.ts +0 -370
- package/src/mcp/resources/project_resource.ts +0 -184
- package/src/mcp/resources/query_resource.ts +0 -117
- package/src/mcp/resources/source_resource.ts +0 -141
- package/src/mcp/resources/view_resource.ts +0 -136
- package/src/mcp/server.ts +0 -62
- package/src/mcp/tools/discovery_tools.ts +0 -258
- package/src/mcp/tools/execute_query_tool.ts +0 -265
- package/src/server.ts +0 -1195
- package/src/service/connection.spec.ts +0 -1331
- package/src/service/connection.ts +0 -1511
- package/src/service/connection_service.spec.ts +0 -641
- package/src/service/connection_service.ts +0 -181
- package/src/service/db_utils.spec.ts +0 -714
- package/src/service/db_utils.ts +0 -1227
- package/src/service/filter.spec.ts +0 -447
- package/src/service/filter.ts +0 -337
- package/src/service/filter_integration.spec.ts +0 -825
- package/src/service/gcs_s3_utils.ts +0 -427
- package/src/service/manifest_service.spec.ts +0 -201
- package/src/service/manifest_service.ts +0 -106
- package/src/service/materialization_service.spec.ts +0 -648
- package/src/service/materialization_service.ts +0 -929
- package/src/service/materialized_table_gc.spec.ts +0 -383
- package/src/service/materialized_table_gc.ts +0 -279
- package/src/service/model.spec.ts +0 -257
- package/src/service/model.ts +0 -1069
- package/src/service/package.spec.ts +0 -236
- package/src/service/package.ts +0 -463
- package/src/service/project.ts +0 -681
- package/src/service/project_compile.spec.ts +0 -197
- package/src/service/project_store.spec.ts +0 -859
- package/src/service/project_store.ts +0 -1531
- package/src/service/quoting.ts +0 -41
- package/src/service/resolve_project.ts +0 -13
- package/src/storage/BaseRepository.ts +0 -31
- package/src/storage/DatabaseInterface.ts +0 -180
- package/src/storage/StorageManager.mock.ts +0 -59
- package/src/storage/StorageManager.ts +0 -210
- package/src/storage/duckdb/ConnectionRepository.ts +0 -141
- package/src/storage/duckdb/DuckDBConnection.ts +0 -177
- package/src/storage/duckdb/DuckDBManifestStore.ts +0 -70
- package/src/storage/duckdb/DuckDBRepository.ts +0 -224
- package/src/storage/duckdb/ManifestRepository.ts +0 -119
- package/src/storage/duckdb/MaterializationRepository.ts +0 -249
- package/src/storage/duckdb/PackageRepository.ts +0 -135
- package/src/storage/duckdb/ProjectRepository.ts +0 -148
- package/src/storage/duckdb/manifest_store.spec.ts +0 -133
- package/src/storage/duckdb/schema.ts +0 -147
- package/src/storage/ducklake/DuckLakeManifestStore.ts +0 -146
- package/src/utils.ts +0 -13
- package/tests/fixtures/persist-test/data/orders.csv +0 -5
- package/tests/fixtures/persist-test/persist_test.malloy +0 -11
- package/tests/fixtures/persist-test/publisher.json +0 -5
- package/tests/fixtures/publisher.config.json +0 -15
- package/tests/harness/e2e.ts +0 -96
- package/tests/harness/mcp_test_setup.ts +0 -344
- package/tests/harness/mocks.ts +0 -37
- package/tests/harness/rest_e2e.ts +0 -68
- package/tests/harness/uris.ts +0 -31
- package/tests/integration/materialization/materialization_lifecycle.integration.spec.ts +0 -470
- package/tests/integration/mcp/mcp_execute_query_tool.integration.spec.ts +0 -434
- package/tests/integration/mcp/mcp_resource.integration.spec.ts +0 -663
- package/tests/integration/mcp/mcp_transport.integration.spec.ts +0 -122
- package/tests/integration/mcp/setup.spec.ts +0 -5
- package/tests/unit/duckdb/attached_databases.test.ts +0 -1132
- package/tests/unit/ducklake/ducklake.test.ts +0 -950
- package/tests/unit/mcp/prompt_definitions.test.ts +0 -102
- package/tests/unit/mcp/prompt_happy.test.ts +0 -51
- package/tsconfig.json +0 -32
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { Type } from "class-transformer";
|
|
2
|
-
import {
|
|
3
|
-
IsEnum,
|
|
4
|
-
IsNumber,
|
|
5
|
-
IsOptional,
|
|
6
|
-
IsString,
|
|
7
|
-
ValidateNested,
|
|
8
|
-
} from "class-validator";
|
|
9
|
-
import "reflect-metadata";
|
|
10
|
-
import { ApiConnection } from "../service/model";
|
|
11
|
-
|
|
12
|
-
export class PostgresConnectionDto {
|
|
13
|
-
@IsOptional()
|
|
14
|
-
@IsString()
|
|
15
|
-
host?: string;
|
|
16
|
-
|
|
17
|
-
@IsOptional()
|
|
18
|
-
@IsNumber()
|
|
19
|
-
port?: number;
|
|
20
|
-
|
|
21
|
-
@IsOptional()
|
|
22
|
-
@IsString()
|
|
23
|
-
databaseName?: string;
|
|
24
|
-
|
|
25
|
-
@IsOptional()
|
|
26
|
-
@IsString()
|
|
27
|
-
userName?: string;
|
|
28
|
-
|
|
29
|
-
@IsOptional()
|
|
30
|
-
@IsString()
|
|
31
|
-
password?: string;
|
|
32
|
-
|
|
33
|
-
@IsOptional()
|
|
34
|
-
@IsString()
|
|
35
|
-
connectionString?: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export class MysqlConnectionDto {
|
|
39
|
-
@IsOptional()
|
|
40
|
-
@IsString()
|
|
41
|
-
host?: string;
|
|
42
|
-
|
|
43
|
-
@IsOptional()
|
|
44
|
-
@IsNumber()
|
|
45
|
-
port?: number;
|
|
46
|
-
|
|
47
|
-
@IsOptional()
|
|
48
|
-
@IsString()
|
|
49
|
-
database?: string;
|
|
50
|
-
|
|
51
|
-
@IsOptional()
|
|
52
|
-
@IsString()
|
|
53
|
-
user?: string;
|
|
54
|
-
|
|
55
|
-
@IsOptional()
|
|
56
|
-
@IsString()
|
|
57
|
-
password?: string;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export class BigqueryConnectionDto {
|
|
61
|
-
@IsOptional()
|
|
62
|
-
@IsString()
|
|
63
|
-
defaultProjectId?: string;
|
|
64
|
-
|
|
65
|
-
@IsOptional()
|
|
66
|
-
@IsString()
|
|
67
|
-
billingProjectId?: string;
|
|
68
|
-
|
|
69
|
-
@IsOptional()
|
|
70
|
-
@IsString()
|
|
71
|
-
location?: string;
|
|
72
|
-
|
|
73
|
-
@IsOptional()
|
|
74
|
-
@IsString()
|
|
75
|
-
serviceAccountKeyJson?: string;
|
|
76
|
-
|
|
77
|
-
@IsOptional()
|
|
78
|
-
@IsString()
|
|
79
|
-
maximumBytesBilled?: string;
|
|
80
|
-
|
|
81
|
-
@IsOptional()
|
|
82
|
-
@IsString()
|
|
83
|
-
queryTimeoutMilliseconds?: string;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export class SnowflakeConnectionDto {
|
|
87
|
-
@IsOptional()
|
|
88
|
-
@IsString()
|
|
89
|
-
account?: string;
|
|
90
|
-
|
|
91
|
-
@IsOptional()
|
|
92
|
-
@IsString()
|
|
93
|
-
username?: string;
|
|
94
|
-
|
|
95
|
-
@IsOptional()
|
|
96
|
-
@IsString()
|
|
97
|
-
password?: string;
|
|
98
|
-
|
|
99
|
-
@IsOptional()
|
|
100
|
-
@IsString()
|
|
101
|
-
warehouse?: string;
|
|
102
|
-
|
|
103
|
-
@IsOptional()
|
|
104
|
-
@IsString()
|
|
105
|
-
database?: string;
|
|
106
|
-
|
|
107
|
-
@IsOptional()
|
|
108
|
-
@IsString()
|
|
109
|
-
schema?: string;
|
|
110
|
-
|
|
111
|
-
@IsOptional()
|
|
112
|
-
@IsNumber()
|
|
113
|
-
responseTimeoutMilliseconds?: number;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export class TrinoConnectionDto {
|
|
117
|
-
@IsOptional()
|
|
118
|
-
@IsString()
|
|
119
|
-
server?: string;
|
|
120
|
-
|
|
121
|
-
@IsOptional()
|
|
122
|
-
@IsString()
|
|
123
|
-
port?: number;
|
|
124
|
-
|
|
125
|
-
@IsOptional()
|
|
126
|
-
@IsString()
|
|
127
|
-
catalog?: string;
|
|
128
|
-
|
|
129
|
-
@IsOptional()
|
|
130
|
-
@IsString()
|
|
131
|
-
schema?: string;
|
|
132
|
-
|
|
133
|
-
@IsOptional()
|
|
134
|
-
@IsString()
|
|
135
|
-
user?: string;
|
|
136
|
-
|
|
137
|
-
@IsOptional()
|
|
138
|
-
@IsString()
|
|
139
|
-
password?: string;
|
|
140
|
-
|
|
141
|
-
@IsOptional()
|
|
142
|
-
@IsString()
|
|
143
|
-
peakaKey?: string;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export class ConnectionDto implements ApiConnection {
|
|
147
|
-
@IsOptional()
|
|
148
|
-
@IsString()
|
|
149
|
-
name?: string;
|
|
150
|
-
|
|
151
|
-
@IsOptional()
|
|
152
|
-
@IsEnum(["postgres", "bigquery", "snowflake", "trino"])
|
|
153
|
-
type?: "postgres" | "bigquery" | "snowflake" | "trino";
|
|
154
|
-
|
|
155
|
-
@IsOptional()
|
|
156
|
-
@ValidateNested()
|
|
157
|
-
@Type(() => PostgresConnectionDto)
|
|
158
|
-
postgresConnection?: PostgresConnectionDto;
|
|
159
|
-
|
|
160
|
-
@IsOptional()
|
|
161
|
-
@ValidateNested()
|
|
162
|
-
@Type(() => BigqueryConnectionDto)
|
|
163
|
-
bigqueryConnection?: BigqueryConnectionDto;
|
|
164
|
-
|
|
165
|
-
@IsOptional()
|
|
166
|
-
@ValidateNested()
|
|
167
|
-
@Type(() => SnowflakeConnectionDto)
|
|
168
|
-
snowflakeConnection?: SnowflakeConnectionDto;
|
|
169
|
-
|
|
170
|
-
@IsOptional()
|
|
171
|
-
@ValidateNested()
|
|
172
|
-
@Type(() => TrinoConnectionDto)
|
|
173
|
-
TrinoConnection?: TrinoConnectionDto;
|
|
174
|
-
}
|
package/src/dto/index.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { expect, it, describe } from "bun:test";
|
|
2
|
-
|
|
3
|
-
import { plainToInstance } from "class-transformer";
|
|
4
|
-
import { validate } from "class-validator";
|
|
5
|
-
import { PackageDto } from "./package.dto";
|
|
6
|
-
import { faker } from "@faker-js/faker";
|
|
7
|
-
|
|
8
|
-
describe("dto/package", () => {
|
|
9
|
-
it("should not throw when valid object is provided", async () => {
|
|
10
|
-
const errors = await validate(
|
|
11
|
-
plainToInstance(PackageDto, {
|
|
12
|
-
name: faker.person.firstName(),
|
|
13
|
-
description: faker.person.lastName(),
|
|
14
|
-
}),
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
expect(errors).toHaveLength(0);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("should throw when no name is specified", async () => {
|
|
21
|
-
const errors = await validate(
|
|
22
|
-
plainToInstance(PackageDto, {
|
|
23
|
-
name: "",
|
|
24
|
-
description: faker.person.lastName(),
|
|
25
|
-
}),
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
expect(errors.length).toBeGreaterThan(0);
|
|
29
|
-
expect(errors).toHaveLength(1);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("should throw when no description is specified", async () => {
|
|
33
|
-
const errors = await validate(
|
|
34
|
-
plainToInstance(PackageDto, {
|
|
35
|
-
name: faker.person.firstName(),
|
|
36
|
-
}),
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
expect(errors.length).toBeGreaterThan(0);
|
|
40
|
-
expect(errors).toHaveLength(1);
|
|
41
|
-
});
|
|
42
|
-
});
|
package/src/dto/package.dto.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { IsString, IsNotEmpty } from "class-validator";
|
|
2
|
-
import { ApiPackage } from "../service/package";
|
|
3
|
-
|
|
4
|
-
export class PackageDto implements ApiPackage {
|
|
5
|
-
@IsString()
|
|
6
|
-
@IsNotEmpty()
|
|
7
|
-
name: string;
|
|
8
|
-
|
|
9
|
-
@IsString()
|
|
10
|
-
@IsNotEmpty()
|
|
11
|
-
description: string;
|
|
12
|
-
}
|
package/src/dto/validate.spec.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { expect, it, describe } from "bun:test";
|
|
2
|
-
import request from "supertest";
|
|
3
|
-
import express from "express";
|
|
4
|
-
import { validateSchema } from "./validate";
|
|
5
|
-
import { PackageDto } from "./package.dto";
|
|
6
|
-
import { faker } from "@faker-js/faker";
|
|
7
|
-
|
|
8
|
-
const app = express();
|
|
9
|
-
app.use(express.json());
|
|
10
|
-
|
|
11
|
-
app.post("/packages", validateSchema(PackageDto), (req, res) => {
|
|
12
|
-
res.status(201).json({ message: "Package created", data: req.body });
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe("dto/validate", () => {
|
|
16
|
-
describe("validateSchema", () => {
|
|
17
|
-
it("should pass validation for a valid request", async () => {
|
|
18
|
-
const dummyPayload = {
|
|
19
|
-
name: faker.person.firstName(),
|
|
20
|
-
description: faker.person.lastName(),
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const response = await request(app)
|
|
24
|
-
.post("/packages")
|
|
25
|
-
.send(dummyPayload);
|
|
26
|
-
|
|
27
|
-
expect(response.status).toBe(201);
|
|
28
|
-
expect(response.body.message).toBe("Package created");
|
|
29
|
-
expect(response.body.data).toEqual(dummyPayload);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("should return 400 for missing required fields", async () => {
|
|
33
|
-
const response = await request(app).post("/packages").send({
|
|
34
|
-
name: "",
|
|
35
|
-
description: "",
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
expect(response.status).toBe(400);
|
|
39
|
-
expect(Array.isArray(response.body.errors)).toBe(true);
|
|
40
|
-
|
|
41
|
-
const expectedErrors = [
|
|
42
|
-
{
|
|
43
|
-
property: "name",
|
|
44
|
-
constraints: { isNotEmpty: "name should not be empty" },
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
property: "description",
|
|
48
|
-
constraints: {
|
|
49
|
-
isNotEmpty: "description should not be empty",
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
];
|
|
53
|
-
expect(response.body.errors).toEqual(
|
|
54
|
-
expect.arrayContaining(expectedErrors),
|
|
55
|
-
);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("should return 400 for invalid description format", async () => {
|
|
59
|
-
const response = await request(app).post("/packages").send({
|
|
60
|
-
name: faker.person.firstName(),
|
|
61
|
-
description: false,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
expect(response.status).toBe(400);
|
|
65
|
-
const expectedErrors = [
|
|
66
|
-
{
|
|
67
|
-
property: "description",
|
|
68
|
-
constraints: { isString: "description must be a string" },
|
|
69
|
-
},
|
|
70
|
-
];
|
|
71
|
-
expect(response.body.errors).toEqual(
|
|
72
|
-
expect.arrayContaining(expectedErrors),
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
package/src/dto/validate.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from "express";
|
|
2
|
-
import { plainToInstance, ClassConstructor } from "class-transformer";
|
|
3
|
-
import { validate } from "class-validator";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @description validates incoming requests based on the provided dto schema
|
|
7
|
-
* @param dtoClass to validate against
|
|
8
|
-
* @example
|
|
9
|
-
* app.post('/users', validateSchema(UserDto), (req, res) => {
|
|
10
|
-
* res.status(201).json({ message: 'User created', data: req.body });
|
|
11
|
-
* });
|
|
12
|
-
*/
|
|
13
|
-
export function validateSchema<T extends object>(
|
|
14
|
-
dtoClass: ClassConstructor<T>,
|
|
15
|
-
) {
|
|
16
|
-
return async (req: Request, res: Response, next: NextFunction) => {
|
|
17
|
-
const dtoInstance = plainToInstance(dtoClass, req.body);
|
|
18
|
-
const errors = await validate(dtoInstance);
|
|
19
|
-
|
|
20
|
-
if (errors.length > 0) {
|
|
21
|
-
const formattedErrors = errors.map((err) => ({
|
|
22
|
-
property: err.property,
|
|
23
|
-
constraints: err.constraints,
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
return res.status(400).json({ errors: formattedErrors });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
next();
|
|
30
|
-
};
|
|
31
|
-
}
|
package/src/errors.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { MalloyError } from "@malloydata/malloy";
|
|
2
|
-
import { PUBLISHER_CONFIG_NAME } from "./constants";
|
|
3
|
-
|
|
4
|
-
export function internalErrorToHttpError(error: Error) {
|
|
5
|
-
if (error instanceof BadRequestError) {
|
|
6
|
-
return httpError(400, error.message);
|
|
7
|
-
} else if (error instanceof FrozenConfigError) {
|
|
8
|
-
return httpError(403, error.message);
|
|
9
|
-
} else if (error instanceof ProjectNotFoundError) {
|
|
10
|
-
return httpError(404, error.message);
|
|
11
|
-
} else if (error instanceof PackageNotFoundError) {
|
|
12
|
-
return httpError(404, error.message);
|
|
13
|
-
} else if (error instanceof ModelNotFoundError) {
|
|
14
|
-
return httpError(404, error.message);
|
|
15
|
-
} else if (error instanceof MalloyError) {
|
|
16
|
-
return httpError(400, error.message);
|
|
17
|
-
} else if (error instanceof ConnectionNotFoundError) {
|
|
18
|
-
return httpError(404, error.message);
|
|
19
|
-
} else if (error instanceof ModelCompilationError) {
|
|
20
|
-
return httpError(424, error.message);
|
|
21
|
-
} else if (error instanceof ConnectionError) {
|
|
22
|
-
return httpError(502, error.message);
|
|
23
|
-
} else if (error instanceof MaterializationNotFoundError) {
|
|
24
|
-
return httpError(404, error.message);
|
|
25
|
-
} else if (error instanceof MaterializationConflictError) {
|
|
26
|
-
return httpError(409, error.message);
|
|
27
|
-
} else if (error instanceof InvalidStateTransitionError) {
|
|
28
|
-
return httpError(409, error.message);
|
|
29
|
-
} else {
|
|
30
|
-
return httpError(500, error.message);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function httpError(code: number, message: string) {
|
|
35
|
-
return {
|
|
36
|
-
status: code,
|
|
37
|
-
json: {
|
|
38
|
-
code,
|
|
39
|
-
message: message,
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export class NotImplementedError extends Error {
|
|
45
|
-
constructor(message: string) {
|
|
46
|
-
super(message);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export class BadRequestError extends Error {
|
|
51
|
-
constructor(message: string) {
|
|
52
|
-
super(message);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export class ProjectNotFoundError extends Error {
|
|
57
|
-
constructor(message: string) {
|
|
58
|
-
super(message);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export class PackageNotFoundError extends Error {
|
|
63
|
-
constructor(message: string) {
|
|
64
|
-
super(message);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export class ModelNotFoundError extends Error {
|
|
69
|
-
constructor(message: string) {
|
|
70
|
-
super(message);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export class ConnectionNotFoundError extends Error {
|
|
75
|
-
constructor(message: string) {
|
|
76
|
-
super(message);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export class ConnectionError extends Error {
|
|
81
|
-
constructor(message: string) {
|
|
82
|
-
super(message);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export class ModelCompilationError extends Error {
|
|
87
|
-
constructor(error: MalloyError) {
|
|
88
|
-
super(error.message);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export class FrozenConfigError extends Error {
|
|
93
|
-
constructor(
|
|
94
|
-
message = `Publisher config can't be updated when ${PUBLISHER_CONFIG_NAME} has { "frozenConfig": true }`,
|
|
95
|
-
) {
|
|
96
|
-
super(message);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export class MaterializationNotFoundError extends Error {
|
|
101
|
-
constructor(message: string) {
|
|
102
|
-
super(message);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export class MaterializationConflictError extends Error {
|
|
107
|
-
constructor(message: string) {
|
|
108
|
-
super(message);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export class InvalidStateTransitionError extends Error {
|
|
113
|
-
constructor(message: string) {
|
|
114
|
-
super(message);
|
|
115
|
-
}
|
|
116
|
-
}
|
package/src/health.ts
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Health check endpoints and graceful shutdown handling.
|
|
3
|
-
*
|
|
4
|
-
* Provides Kubernetes-compatible health probes:
|
|
5
|
-
* - /health - Overall health status
|
|
6
|
-
* - /health/liveness - Always returns 200 (process is alive)
|
|
7
|
-
* - /health/readiness - Returns 200 when ready, 503 when not ready
|
|
8
|
-
*
|
|
9
|
-
* On SIGTERM, the service enters draining state to allow in-flight requests
|
|
10
|
-
* to complete before shutdown.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { Express, NextFunction, Request, Response } from "express";
|
|
14
|
-
import { Server } from "http";
|
|
15
|
-
import { components } from "./api";
|
|
16
|
-
import { shutdownSDK } from "./instrumentation";
|
|
17
|
-
import { logger } from "./logger";
|
|
18
|
-
export type OperationalState =
|
|
19
|
-
components["schemas"]["ServerStatus"]["operationalState"];
|
|
20
|
-
|
|
21
|
-
let operationalState: OperationalState = "initializing" as OperationalState;
|
|
22
|
-
let ready: boolean = false;
|
|
23
|
-
let preGracefulShutdownCompleted: boolean = false;
|
|
24
|
-
/**
|
|
25
|
-
* Returns the current operational state of the service.
|
|
26
|
-
*/
|
|
27
|
-
export function getOperationalState(): OperationalState {
|
|
28
|
-
return operationalState;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Marks the service as ready to serve traffic.
|
|
33
|
-
*/
|
|
34
|
-
export function markReady(): void {
|
|
35
|
-
if (operationalState !== "draining") {
|
|
36
|
-
operationalState = "serving";
|
|
37
|
-
ready = true;
|
|
38
|
-
logger.info("Service marked as ready");
|
|
39
|
-
} else {
|
|
40
|
-
logger.error("Service is already draining - cannot mark as ready");
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Marks the service as not ready (readiness probe will return 503).
|
|
46
|
-
*/
|
|
47
|
-
export function markNotReady(): void {
|
|
48
|
-
ready = false;
|
|
49
|
-
logger.info("Service marked as not ready - readiness probe will fail");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Registers SIGTERM handler for graceful shutdown.
|
|
54
|
-
*
|
|
55
|
-
* Shutdown sequence:
|
|
56
|
-
* 1. Marks service as not ready (readiness probe returns 503) and enters draining state
|
|
57
|
-
* 2. Waits shutdownDrainDurationSeconds to allow in-flight requests to complete
|
|
58
|
-
* 3. Sets preGracefulShutdownCompleted flag (enables drainingGuard middleware to reject new requests)
|
|
59
|
-
* 4. Closes main server and MCP server (stops accepting new connections)
|
|
60
|
-
* 5. Closes logger
|
|
61
|
-
* 6. Waits shutdownGracefulCloseTimeoutSeconds (if > 0) for final cleanup
|
|
62
|
-
* 7. Exits process
|
|
63
|
-
*
|
|
64
|
-
* Note: drainingGuard only rejects requests after step 3 completes. During step 2,
|
|
65
|
-
* the service is draining but still accepts requests (readiness probe returns 503).
|
|
66
|
-
*
|
|
67
|
-
* @param server - Main HTTP server instance
|
|
68
|
-
* @param mcpServer - MCP server instance
|
|
69
|
-
* @param shutdownDrainDurationSeconds - Duration in seconds to wait before closing servers
|
|
70
|
-
* @param shutdownGracefulCloseTimeoutSeconds - Duration in seconds to wait after closing servers before exit
|
|
71
|
-
*/
|
|
72
|
-
export function registerSignalHandlers(
|
|
73
|
-
server: Server,
|
|
74
|
-
mcpServer: Server,
|
|
75
|
-
shutdownDrainDurationSeconds: number = 0,
|
|
76
|
-
shutdownGracefulCloseTimeoutSeconds: number = 0,
|
|
77
|
-
): void {
|
|
78
|
-
// Keep the process alive on SIGTERM — do not close the server.
|
|
79
|
-
// K8s will SIGKILL after terminationGracePeriodSeconds (which cannot be caught).
|
|
80
|
-
process.once("SIGTERM", async () => {
|
|
81
|
-
logger.info("========== SIGTERM RECEIVED ==========");
|
|
82
|
-
markNotReady();
|
|
83
|
-
operationalState = "draining" as OperationalState;
|
|
84
|
-
logger.info(
|
|
85
|
-
`Service entering draining state for ${shutdownDrainDurationSeconds} seconds before closing servers...`,
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
await new Promise((resolve) =>
|
|
89
|
-
setTimeout(() => {
|
|
90
|
-
preGracefulShutdownCompleted = true;
|
|
91
|
-
resolve(true);
|
|
92
|
-
}, shutdownDrainDurationSeconds * 1000),
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const closeServer = (server: Server, name: string) =>
|
|
96
|
-
new Promise<void>((resolve) => {
|
|
97
|
-
if (server && server.listening) {
|
|
98
|
-
server.close((err) => {
|
|
99
|
-
if (err) {
|
|
100
|
-
logger.error(`${name} close error:`, err);
|
|
101
|
-
} else {
|
|
102
|
-
logger.info(`${name} closed`);
|
|
103
|
-
}
|
|
104
|
-
resolve();
|
|
105
|
-
});
|
|
106
|
-
} else {
|
|
107
|
-
resolve();
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
await Promise.all([
|
|
112
|
-
closeServer(server, "Main server"),
|
|
113
|
-
closeServer(mcpServer, "MCP server"),
|
|
114
|
-
]);
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
await shutdownSDK();
|
|
118
|
-
logger.info("OpenTelemetry SDK shut down");
|
|
119
|
-
} catch (_error) {
|
|
120
|
-
/* do nothing */
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
try {
|
|
124
|
-
logger.close();
|
|
125
|
-
} catch (_error) {
|
|
126
|
-
/* do nothing */
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (shutdownGracefulCloseTimeoutSeconds > 0) {
|
|
130
|
-
logger.info(
|
|
131
|
-
`Waiting ${shutdownGracefulCloseTimeoutSeconds} seconds after server close before exit...`,
|
|
132
|
-
);
|
|
133
|
-
await new Promise((resolve) =>
|
|
134
|
-
setTimeout(resolve, shutdownGracefulCloseTimeoutSeconds * 1000),
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
process.exit(0);
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Middleware that returns 503 for non-health and metrics requests when service is draining.
|
|
142
|
-
* Must be registered before application routes.
|
|
143
|
-
*/
|
|
144
|
-
export function drainingGuard(
|
|
145
|
-
req: Request,
|
|
146
|
-
res: Response,
|
|
147
|
-
next: NextFunction,
|
|
148
|
-
): void {
|
|
149
|
-
if (
|
|
150
|
-
operationalState === "draining" &&
|
|
151
|
-
preGracefulShutdownCompleted &&
|
|
152
|
-
!req.path.startsWith("/health") &&
|
|
153
|
-
!req.path.startsWith("/metrics")
|
|
154
|
-
) {
|
|
155
|
-
res.status(503).json({
|
|
156
|
-
message: "Service is draining",
|
|
157
|
-
details: "The service is shutting down and hence is not available.",
|
|
158
|
-
});
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
next();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Registers health check endpoints
|
|
166
|
-
*/
|
|
167
|
-
export function registerHealthEndpoints(app: Express): void {
|
|
168
|
-
app.get("/health", (_req: Request, res: Response) => {
|
|
169
|
-
res.status(200).json({
|
|
170
|
-
status: "UP",
|
|
171
|
-
components: {
|
|
172
|
-
livenessState: { status: "UP" },
|
|
173
|
-
readinessState: { status: ready ? "UP" : "DOWN" },
|
|
174
|
-
},
|
|
175
|
-
groups: ["livenessState", "readinessState"],
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
app.get("/health/liveness", (_req: Request, res: Response) => {
|
|
180
|
-
res.status(200).json({ status: "UP" });
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
app.get("/health/readiness", (_req: Request, res: Response) => {
|
|
184
|
-
const isReady = ready;
|
|
185
|
-
res.status(isReady ? 200 : 503).json({
|
|
186
|
-
status: isReady ? "UP" : "DOWN",
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
}
|