@corpdk/create-ds 2026.10.0-alpha.3 → 2026.10.0-alpha.4
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/canonical/.env.example +5 -0
- package/canonical/Dockerfile +1 -1
- package/canonical/docker/otel-collector-config.yaml +15 -0
- package/canonical/docker-compose.yml +12 -0
- package/canonical/docker-entrypoint.sh +1 -1
- package/canonical/package.json +16 -5
- package/canonical/src/db/index.ts +17 -1
- package/canonical/src/health.ts +78 -0
- package/canonical/src/index.ts +14 -1
- package/canonical/src/observability/otel-config.ts +11 -0
- package/canonical/src/observability/otel-smoke-extensions.ts +20 -0
- package/canonical/src/observability/preload-otel.ts +37 -0
- package/canonical/src/observability/yoga-tracing-plugin.ts +179 -0
- package/canonical/src/schema.ts +17 -2
- package/canonical/src/validation/parse-input.ts +13 -0
- package/dist/index.js +36 -14
- package/package.json +5 -2
package/canonical/.env.example
CHANGED
|
@@ -7,3 +7,8 @@ DATABASE_URL=postgresql://user:pass@localhost:5433/corpdk_ds
|
|
|
7
7
|
# Optional HMAC-SHA256 signing for pagination cursors (§13). When unset, cursors are unsigned (local dev).
|
|
8
8
|
# DAL_CURSOR_SECRET=
|
|
9
9
|
# REDIS_URL=redis://localhost:6379 # uncomment to switch pubsub to Redis/Valkey
|
|
10
|
+
# OpenTelemetry (optional — omit for local dev without tracing)
|
|
11
|
+
# OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 # OTLP HTTP base URL; exporter appends /v1/traces
|
|
12
|
+
# DS_OTEL_ENABLED=true
|
|
13
|
+
# DS_OTEL_ENABLED=false # force tracing off even if OTEL_EXPORTER_OTLP_ENDPOINT is set
|
|
14
|
+
# OTEL_SERVICE_NAME=@corpdk/ds
|
package/canonical/Dockerfile
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# Build from the monorepo root: docker build -f templates/ds/Dockerfile .
|
|
3
3
|
|
|
4
4
|
# ── Base ──────────────────────────────────────────────────────────────────────
|
|
5
|
-
FROM node:
|
|
5
|
+
FROM node:24-alpine AS base
|
|
6
6
|
ENV PNPM_HOME="/pnpm"
|
|
7
7
|
ENV PATH="$PNPM_HOME:$PATH"
|
|
8
8
|
RUN corepack enable
|
|
@@ -32,6 +32,18 @@ services:
|
|
|
32
32
|
environment:
|
|
33
33
|
DS_PORT: "4000"
|
|
34
34
|
DATABASE_URL: postgresql://user:pass@postgres:5432/corpdk_ds
|
|
35
|
+
DS_OTEL_ENABLED: ${DS_OTEL_ENABLED:-}
|
|
36
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-}
|
|
37
|
+
DS_OTEL_SMOKE_TEST: ${DS_OTEL_SMOKE_TEST:-}
|
|
38
|
+
OTEL_SERVICE_NAME: ${OTEL_SERVICE_NAME:-corpdk-ds-docker}
|
|
39
|
+
|
|
40
|
+
otel-collector:
|
|
41
|
+
profiles: ["otel"]
|
|
42
|
+
image: otel/opentelemetry-collector-contrib:0.120.0
|
|
43
|
+
container_name: corpdk-ds-otel-collector
|
|
44
|
+
command: ["--config=/etc/otelcol/config.yaml"]
|
|
45
|
+
volumes:
|
|
46
|
+
- ./docker/otel-collector-config.yaml:/etc/otelcol/config.yaml:ro
|
|
35
47
|
|
|
36
48
|
volumes:
|
|
37
49
|
corpdk_ds_pgdata:
|
package/canonical/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"registry": "https://artifactory.corp.example.com/api/npm/npm-private/"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"dev": "node --env-file .env --import tsx/esm --watch src/index.ts",
|
|
10
|
+
"dev": "node --env-file .env --import tsx/esm --import ./src/observability/preload-otel.ts --watch src/index.ts",
|
|
11
11
|
"build": "tsc",
|
|
12
12
|
"codegen": "graphql-codegen",
|
|
13
13
|
"dal:codegen:schema": "node ./node_modules/@corpdk/dal-codegen/dist/cli.js --mode=schema",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dal:codegen:bootstrap": "node ./node_modules/@corpdk/dal-codegen/dist/cli.js --mode=bootstrap",
|
|
16
16
|
"dal:codegen": "pnpm run dal:codegen:schema && pnpm run codegen && pnpm run dal:codegen:impl",
|
|
17
17
|
"entity:lint": "node ./node_modules/@corpdk/dal-codegen/dist/lint-cli.js",
|
|
18
|
-
"start": "node dist/src/index.js",
|
|
18
|
+
"start": "node --import ./dist/src/observability/preload-otel.js dist/src/index.js",
|
|
19
19
|
"lint": "eslint src/",
|
|
20
20
|
"typecheck": "tsc --noEmit",
|
|
21
21
|
"db:up": "docker compose up postgres -d",
|
|
@@ -36,7 +36,15 @@
|
|
|
36
36
|
"graphql": "^16.13.2",
|
|
37
37
|
"graphql-yoga": "^5.18.1",
|
|
38
38
|
"ioredis": "^5.10.1",
|
|
39
|
-
"pg": "^8.20.0"
|
|
39
|
+
"pg": "^8.20.0",
|
|
40
|
+
"zod": "^4.3.6",
|
|
41
|
+
"@opentelemetry/api": "^1.9.0",
|
|
42
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.211.0",
|
|
43
|
+
"@opentelemetry/instrumentation-http": "^0.211.0",
|
|
44
|
+
"@opentelemetry/instrumentation-pg": "^0.61.0",
|
|
45
|
+
"@opentelemetry/resources": "^2.5.0",
|
|
46
|
+
"@opentelemetry/sdk-node": "^0.211.0",
|
|
47
|
+
"@opentelemetry/semantic-conventions": "^1.39.0"
|
|
40
48
|
},
|
|
41
49
|
"devDependencies": {
|
|
42
50
|
"@corpdk/codegen-cli": "workspace:*",
|
|
@@ -45,11 +53,14 @@
|
|
|
45
53
|
"@graphql-codegen/client-preset": "^5.2.4",
|
|
46
54
|
"@graphql-codegen/typescript": "^5.0.9",
|
|
47
55
|
"@graphql-codegen/typescript-resolvers": "^5.1.7",
|
|
48
|
-
"@types/node": "^
|
|
56
|
+
"@types/node": "^24.0.0",
|
|
49
57
|
"@types/pg": "^8.11.14",
|
|
50
58
|
"drizzle-kit": "^0.31.10",
|
|
51
59
|
"tsx": "^4.21.0",
|
|
52
60
|
"typescript": "^6.0.2"
|
|
53
61
|
},
|
|
54
|
-
"license": "MIT"
|
|
62
|
+
"license": "MIT",
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=24.0.0"
|
|
65
|
+
}
|
|
55
66
|
}
|
|
@@ -10,6 +10,22 @@ import * as schema from "./schema/index.js";
|
|
|
10
10
|
* CockroachDB), it updates drizzle.config.ts, src/db/schema/, and
|
|
11
11
|
* swaps the driver package in package.json — update this file accordingly.
|
|
12
12
|
*/
|
|
13
|
-
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
13
|
+
export const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
14
14
|
|
|
15
15
|
export const db = drizzle(pool, { schema });
|
|
16
|
+
|
|
17
|
+
export interface DbPingResult {
|
|
18
|
+
connected: boolean;
|
|
19
|
+
latencyMs: number | null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Lightweight connectivity check for /health and orchestrator probes. */
|
|
23
|
+
export async function pingDatabase(): Promise<DbPingResult> {
|
|
24
|
+
const start = performance.now();
|
|
25
|
+
try {
|
|
26
|
+
await pool.query("SELECT 1");
|
|
27
|
+
return { connected: true, latencyMs: Math.round(performance.now() - start) };
|
|
28
|
+
} catch {
|
|
29
|
+
return { connected: false, latencyMs: null };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
5
|
+
import { trace, SpanStatusCode } from "@opentelemetry/api";
|
|
6
|
+
import { pingDatabase } from "./db/index.js";
|
|
7
|
+
|
|
8
|
+
function readPackageVersion(): string {
|
|
9
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
for (const rel of ["../package.json", "../../package.json"]) {
|
|
11
|
+
try {
|
|
12
|
+
const path = join(here, rel);
|
|
13
|
+
return (JSON.parse(readFileSync(path, "utf-8")) as { version: string }).version;
|
|
14
|
+
} catch {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return "unknown";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const packageVersion = readPackageVersion();
|
|
22
|
+
|
|
23
|
+
export interface HealthPayload {
|
|
24
|
+
status: "ok" | "degraded";
|
|
25
|
+
uptime: number;
|
|
26
|
+
version: string;
|
|
27
|
+
db: {
|
|
28
|
+
connected: boolean;
|
|
29
|
+
latencyMs: number | null;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function collectHealth(uptimeSeconds: number): Promise<HealthPayload> {
|
|
34
|
+
const tracer = trace.getTracer("@corpdk/ds/health");
|
|
35
|
+
const db = await tracer.startActiveSpan("db.health_ping", async (span) => {
|
|
36
|
+
try {
|
|
37
|
+
const result = await pingDatabase();
|
|
38
|
+
span.setAttribute("db.connected", result.connected);
|
|
39
|
+
if (result.latencyMs != null) {
|
|
40
|
+
span.setAttribute("db.latency_ms", result.latencyMs);
|
|
41
|
+
}
|
|
42
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
43
|
+
return result;
|
|
44
|
+
} catch (err) {
|
|
45
|
+
span.recordException(err instanceof Error ? err : new Error(String(err)));
|
|
46
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
47
|
+
return { connected: false, latencyMs: null };
|
|
48
|
+
} finally {
|
|
49
|
+
span.end();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const connected = db.connected;
|
|
54
|
+
return {
|
|
55
|
+
status: connected ? "ok" : "degraded",
|
|
56
|
+
uptime: uptimeSeconds,
|
|
57
|
+
version: packageVersion,
|
|
58
|
+
db,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function handleHealthRequest(
|
|
63
|
+
req: IncomingMessage,
|
|
64
|
+
res: ServerResponse,
|
|
65
|
+
serverStartedAt: number,
|
|
66
|
+
): Promise<void> {
|
|
67
|
+
if (req.method !== "GET") {
|
|
68
|
+
res.writeHead(405, { "Content-Type": "application/json" });
|
|
69
|
+
res.end(JSON.stringify({ error: "Method Not Allowed" }));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const uptimeSeconds = Math.floor((Date.now() - serverStartedAt) / 1000);
|
|
74
|
+
const body = await collectHealth(uptimeSeconds);
|
|
75
|
+
const statusCode = body.status === "ok" ? 200 : 503;
|
|
76
|
+
res.writeHead(statusCode, { "Content-Type": "application/json" });
|
|
77
|
+
res.end(JSON.stringify(body));
|
|
78
|
+
}
|
package/canonical/src/index.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { createServer } from "node:http";
|
|
2
2
|
import { createYoga } from "graphql-yoga";
|
|
3
3
|
import { schema, createRequestContext } from "./schema.js";
|
|
4
|
+
import { handleHealthRequest } from "./health.js";
|
|
5
|
+
import { yogaTracingPlugin } from "./observability/yoga-tracing-plugin.js";
|
|
4
6
|
|
|
5
7
|
const PORT = Number(process.env.DS_PORT);
|
|
6
8
|
if (!PORT) throw new Error("DS_PORT env var is required");
|
|
7
9
|
|
|
10
|
+
const serverStartedAt = Date.now();
|
|
11
|
+
|
|
8
12
|
const yoga = createYoga({
|
|
9
13
|
schema,
|
|
10
14
|
context: () => {
|
|
@@ -14,13 +18,22 @@ const yoga = createYoga({
|
|
|
14
18
|
},
|
|
15
19
|
graphiql: process.env.NODE_ENV !== "production",
|
|
16
20
|
logging: true,
|
|
21
|
+
plugins: [yogaTracingPlugin()],
|
|
17
22
|
});
|
|
18
23
|
|
|
19
|
-
const server = createServer(
|
|
24
|
+
const server = createServer((req, res) => {
|
|
25
|
+
const url = req.url?.split("?")[0];
|
|
26
|
+
if (url === "/health") {
|
|
27
|
+
void handleHealthRequest(req, res, serverStartedAt);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
yoga(req, res);
|
|
31
|
+
});
|
|
20
32
|
|
|
21
33
|
server.listen(PORT, () => {
|
|
22
34
|
const base = `http://localhost:${PORT}/graphql`;
|
|
23
35
|
console.log(`@corpdk/ds HTTP ${base}`);
|
|
36
|
+
console.log(`@corpdk/ds health http://localhost:${PORT}/health`);
|
|
24
37
|
console.log(
|
|
25
38
|
`@corpdk/ds SSE ${base} (subscriptions: Accept: text/event-stream)`,
|
|
26
39
|
);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** True when OTLP export or explicit DS flag enables tracing. */
|
|
2
|
+
export function isOtelEnabled(): boolean {
|
|
3
|
+
const flag = process.env.DS_OTEL_ENABLED;
|
|
4
|
+
if (flag === "true") return true;
|
|
5
|
+
if (flag === "false") return false;
|
|
6
|
+
return Boolean(process.env.OTEL_EXPORTER_OTLP_ENDPOINT?.trim());
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function otelServiceName(): string {
|
|
10
|
+
return process.env.OTEL_SERVICE_NAME?.trim() || "@corpdk/ds";
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Dev-only GraphQL fields for OTel integration smoke tests (literal redaction, execute rejection). */
|
|
2
|
+
export const otelSmokeTestEnabled =
|
|
3
|
+
process.env.DS_OTEL_SMOKE_TEST === "true";
|
|
4
|
+
|
|
5
|
+
export const otelSmokeTypeDefs = /* GraphQL */ `
|
|
6
|
+
extend type Query {
|
|
7
|
+
"""Returns ok when OTel smoke test mode is enabled; password arg exercises literal redaction."""
|
|
8
|
+
otelSmoke(password: String!): String!
|
|
9
|
+
"""Resolver returns a rejected Promise to verify graphql span ERROR status."""
|
|
10
|
+
otelSmokeFault: String!
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
export const otelSmokeResolvers = {
|
|
15
|
+
Query: {
|
|
16
|
+
otelSmoke: () => "ok",
|
|
17
|
+
otelSmokeFault: () =>
|
|
18
|
+
Promise.reject(new Error("DS OTel smoke fault injection")),
|
|
19
|
+
},
|
|
20
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { isOtelEnabled, otelServiceName } from "./otel-config.js";
|
|
2
|
+
|
|
3
|
+
if (isOtelEnabled()) {
|
|
4
|
+
const { NodeSDK } = await import("@opentelemetry/sdk-node");
|
|
5
|
+
const { OTLPTraceExporter } = await import(
|
|
6
|
+
"@opentelemetry/exporter-trace-otlp-http"
|
|
7
|
+
);
|
|
8
|
+
const { resourceFromAttributes } = await import("@opentelemetry/resources");
|
|
9
|
+
const { ATTR_SERVICE_NAME } = await import(
|
|
10
|
+
"@opentelemetry/semantic-conventions"
|
|
11
|
+
);
|
|
12
|
+
const { HttpInstrumentation } = await import(
|
|
13
|
+
"@opentelemetry/instrumentation-http"
|
|
14
|
+
);
|
|
15
|
+
const { PgInstrumentation } = await import(
|
|
16
|
+
"@opentelemetry/instrumentation-pg"
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const sdk = new NodeSDK({
|
|
20
|
+
resource: resourceFromAttributes({
|
|
21
|
+
[ATTR_SERVICE_NAME]: otelServiceName(),
|
|
22
|
+
}),
|
|
23
|
+
traceExporter: new OTLPTraceExporter(),
|
|
24
|
+
instrumentations: [
|
|
25
|
+
new HttpInstrumentation(),
|
|
26
|
+
new PgInstrumentation({ enhancedDatabaseReporting: true }),
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
sdk.start();
|
|
31
|
+
|
|
32
|
+
const shutdown = () => {
|
|
33
|
+
void sdk.shutdown();
|
|
34
|
+
};
|
|
35
|
+
process.once("SIGTERM", shutdown);
|
|
36
|
+
process.once("SIGINT", shutdown);
|
|
37
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { trace, SpanStatusCode, type Span } from "@opentelemetry/api";
|
|
2
|
+
import type { Plugin } from "graphql-yoga";
|
|
3
|
+
import {
|
|
4
|
+
Kind,
|
|
5
|
+
visit,
|
|
6
|
+
type DocumentNode,
|
|
7
|
+
type OperationDefinitionNode,
|
|
8
|
+
type GraphQLError,
|
|
9
|
+
} from "graphql";
|
|
10
|
+
import { isOtelEnabled } from "./otel-config.js";
|
|
11
|
+
|
|
12
|
+
const tracer = trace.getTracer("@corpdk/ds/graphql");
|
|
13
|
+
|
|
14
|
+
function operationDefinition(
|
|
15
|
+
document: DocumentNode,
|
|
16
|
+
operationName?: string | null,
|
|
17
|
+
): OperationDefinitionNode | undefined {
|
|
18
|
+
const ops: OperationDefinitionNode[] = [];
|
|
19
|
+
for (const def of document.definitions) {
|
|
20
|
+
if (def.kind === Kind.OPERATION_DEFINITION) ops.push(def);
|
|
21
|
+
}
|
|
22
|
+
if (ops.length === 0) return undefined;
|
|
23
|
+
if (ops.length === 1) return ops[0];
|
|
24
|
+
if (!operationName) return undefined;
|
|
25
|
+
return ops.find((op) => op.name?.value === operationName);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const SENSITIVE_VARIABLE_KEY =
|
|
29
|
+
/password|secret|token|authorization|api[_-]?key|credential|cookie|session/i;
|
|
30
|
+
|
|
31
|
+
function redactVariableValue(key: string, value: unknown): unknown {
|
|
32
|
+
if (SENSITIVE_VARIABLE_KEY.test(key)) return "[REDACTED]";
|
|
33
|
+
if (Array.isArray(value)) {
|
|
34
|
+
return value.map((entry) =>
|
|
35
|
+
entry !== null && typeof entry === "object"
|
|
36
|
+
? redactVariables(entry as Record<string, unknown>)
|
|
37
|
+
: entry,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
if (value !== null && typeof value === "object") {
|
|
41
|
+
return redactVariables(value as Record<string, unknown>);
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function redactVariables(
|
|
47
|
+
variables: Record<string, unknown>,
|
|
48
|
+
): Record<string, unknown> {
|
|
49
|
+
const out: Record<string, unknown> = {};
|
|
50
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
51
|
+
out[key] = redactVariableValue(key, value);
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function sanitizedVariables(
|
|
57
|
+
variables: Record<string, unknown> | null | undefined,
|
|
58
|
+
): string {
|
|
59
|
+
if (!variables || Object.keys(variables).length === 0) return "{}";
|
|
60
|
+
try {
|
|
61
|
+
return JSON.stringify(redactVariables(variables));
|
|
62
|
+
} catch {
|
|
63
|
+
return "[unserializable]";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function redactSensitiveLiteralRanges(document: DocumentNode): { start: number; end: number }[] {
|
|
68
|
+
const ranges: { start: number; end: number }[] = [];
|
|
69
|
+
const pushValueLoc = (fieldName: string, loc: { start: number; end: number } | undefined) => {
|
|
70
|
+
if (SENSITIVE_VARIABLE_KEY.test(fieldName) && loc) {
|
|
71
|
+
ranges.push({ start: loc.start, end: loc.end });
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
visit(document, {
|
|
76
|
+
Argument(node) {
|
|
77
|
+
pushValueLoc(node.name.value, node.value.loc);
|
|
78
|
+
},
|
|
79
|
+
ObjectField(node) {
|
|
80
|
+
pushValueLoc(node.name.value, node.value.loc);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return ranges;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function sanitizedDocument(document: DocumentNode): string {
|
|
88
|
+
const source = document.loc?.source.body;
|
|
89
|
+
if (!source) return "";
|
|
90
|
+
|
|
91
|
+
const ranges = redactSensitiveLiteralRanges(document);
|
|
92
|
+
if (ranges.length === 0) return source;
|
|
93
|
+
|
|
94
|
+
ranges.sort((a, b) => b.start - a.start);
|
|
95
|
+
let out = source;
|
|
96
|
+
for (const { start, end } of ranges) {
|
|
97
|
+
out = `${out.slice(0, start)}[REDACTED]${out.slice(end)}`;
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function endSpan(
|
|
103
|
+
span: Span,
|
|
104
|
+
errors?: readonly GraphQLError[],
|
|
105
|
+
unhandled?: Error,
|
|
106
|
+
): void {
|
|
107
|
+
if (unhandled) {
|
|
108
|
+
span.setStatus({
|
|
109
|
+
code: SpanStatusCode.ERROR,
|
|
110
|
+
message: unhandled.message,
|
|
111
|
+
});
|
|
112
|
+
} else if (errors?.length) {
|
|
113
|
+
span.setStatus({
|
|
114
|
+
code: SpanStatusCode.ERROR,
|
|
115
|
+
message: errors.map((e) => e.message).join("; "),
|
|
116
|
+
});
|
|
117
|
+
} else {
|
|
118
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
119
|
+
}
|
|
120
|
+
span.end();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function finishFromResult(
|
|
124
|
+
span: Span,
|
|
125
|
+
result: { errors?: readonly GraphQLError[] } | AsyncIterable<unknown>,
|
|
126
|
+
): void {
|
|
127
|
+
if (typeof (result as AsyncIterable<unknown>)[Symbol.asyncIterator] === "function") {
|
|
128
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
129
|
+
span.end();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
endSpan(span, (result as { errors?: readonly GraphQLError[] }).errors);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** GraphQL execute spans (when OpenTelemetry is enabled). */
|
|
136
|
+
export function yogaTracingPlugin(): Plugin {
|
|
137
|
+
if (!isOtelEnabled()) {
|
|
138
|
+
return {};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
onExecute({ args }) {
|
|
143
|
+
const op = operationDefinition(args.document, args.operationName);
|
|
144
|
+
const operationType = op?.operation ?? "unknown";
|
|
145
|
+
const operationName =
|
|
146
|
+
args.operationName ?? op?.name?.value ?? "anonymous";
|
|
147
|
+
|
|
148
|
+
const span = tracer.startSpan(`graphql ${operationType}`, {
|
|
149
|
+
attributes: {
|
|
150
|
+
"graphql.operation.name": operationName,
|
|
151
|
+
"graphql.operation.type": operationType,
|
|
152
|
+
"graphql.document": sanitizedDocument(args.document),
|
|
153
|
+
"graphql.variables": sanitizedVariables(
|
|
154
|
+
args.variableValues as Record<string, unknown> | null | undefined,
|
|
155
|
+
),
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
onExecuteDone(payload) {
|
|
161
|
+
const { result } = payload;
|
|
162
|
+
if (result instanceof Promise) {
|
|
163
|
+
void result.then(
|
|
164
|
+
(resolved) => finishFromResult(span, resolved),
|
|
165
|
+
(err: unknown) => {
|
|
166
|
+
const error =
|
|
167
|
+
err instanceof Error ? err : new Error(String(err));
|
|
168
|
+
span.recordException(error);
|
|
169
|
+
endSpan(span, undefined, error);
|
|
170
|
+
},
|
|
171
|
+
);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
finishFromResult(span, result);
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
package/canonical/src/schema.ts
CHANGED
|
@@ -5,10 +5,25 @@ import {
|
|
|
5
5
|
createDalContext,
|
|
6
6
|
pubsub,
|
|
7
7
|
} from "./generated/dal/index.js";
|
|
8
|
+
import {
|
|
9
|
+
otelSmokeResolvers,
|
|
10
|
+
otelSmokeTestEnabled,
|
|
11
|
+
otelSmokeTypeDefs,
|
|
12
|
+
} from "./observability/otel-smoke-extensions.js";
|
|
13
|
+
|
|
14
|
+
const resolvers = otelSmokeTestEnabled
|
|
15
|
+
? {
|
|
16
|
+
...generatedResolvers,
|
|
17
|
+
Query: {
|
|
18
|
+
...generatedResolvers.Query,
|
|
19
|
+
...otelSmokeResolvers.Query,
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
: generatedResolvers;
|
|
8
23
|
|
|
9
24
|
export const schema = createSchema({
|
|
10
|
-
typeDefs,
|
|
11
|
-
resolvers
|
|
25
|
+
typeDefs: otelSmokeTestEnabled ? [typeDefs, otelSmokeTypeDefs] : typeDefs,
|
|
26
|
+
resolvers,
|
|
12
27
|
});
|
|
13
28
|
|
|
14
29
|
export interface RequestContextOptions {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export {
|
|
2
|
+
inputZodSchemas,
|
|
3
|
+
parseGraphqlInput,
|
|
4
|
+
parseGraphqlInputList,
|
|
5
|
+
parseOptionalGraphqlInput,
|
|
6
|
+
safeParseGraphqlInput,
|
|
7
|
+
safeParseGraphqlInputList,
|
|
8
|
+
safeParseOptionalGraphqlInput,
|
|
9
|
+
safeParseOptionalGraphqlInputList,
|
|
10
|
+
unwrapGraphqlInputParseResult,
|
|
11
|
+
type GraphqlInputParseResult,
|
|
12
|
+
type InputZodSchemaName,
|
|
13
|
+
} from "../generated/dal/input-zod.js";
|
package/dist/index.js
CHANGED
|
@@ -76,11 +76,12 @@ function parseArgs(argv) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// src/init.ts
|
|
79
|
-
import
|
|
79
|
+
import fs2 from "fs/promises";
|
|
80
80
|
import path2 from "path";
|
|
81
81
|
import { spinner } from "@clack/prompts";
|
|
82
82
|
|
|
83
83
|
// src/template.ts
|
|
84
|
+
import fs from "fs/promises";
|
|
84
85
|
import path from "path";
|
|
85
86
|
import { fileURLToPath } from "url";
|
|
86
87
|
var __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -123,6 +124,24 @@ function initialScaffoldCalVer(asOf = /* @__PURE__ */ new Date()) {
|
|
|
123
124
|
const month = asOf.getUTCMonth() + 1;
|
|
124
125
|
return `${year}.${month}.0`;
|
|
125
126
|
}
|
|
127
|
+
var BOOTSTRAP_STATIC_SRC_RELATIVE = [
|
|
128
|
+
"src/health.ts",
|
|
129
|
+
"src/validation/parse-input.ts",
|
|
130
|
+
"src/observability/otel-config.ts",
|
|
131
|
+
"src/observability/otel-smoke-extensions.ts",
|
|
132
|
+
"src/observability/preload-otel.ts",
|
|
133
|
+
"src/observability/yoga-tracing-plugin.ts"
|
|
134
|
+
];
|
|
135
|
+
async function copyBootstrapStaticSrc(templateDir, packageDir) {
|
|
136
|
+
const { pathExists: pathExists2 } = await import("./utils-RZJNRUXW.js");
|
|
137
|
+
for (const rel of BOOTSTRAP_STATIC_SRC_RELATIVE) {
|
|
138
|
+
const templatePath = path.join(templateDir, rel);
|
|
139
|
+
if (!await pathExists2(templatePath)) continue;
|
|
140
|
+
const destPath = path.join(packageDir, rel);
|
|
141
|
+
await fs.mkdir(path.dirname(destPath), { recursive: true });
|
|
142
|
+
await fs.copyFile(templatePath, destPath);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
126
145
|
var UPGRADE_RELATIVE_FILES = [
|
|
127
146
|
"LICENSE",
|
|
128
147
|
"package.json",
|
|
@@ -132,12 +151,14 @@ var UPGRADE_RELATIVE_FILES = [
|
|
|
132
151
|
"tsconfig.json",
|
|
133
152
|
"Dockerfile",
|
|
134
153
|
"docker-compose.yml",
|
|
154
|
+
"docker/otel-collector-config.yaml",
|
|
135
155
|
"docker-entrypoint.sh",
|
|
136
156
|
".gitignore",
|
|
137
157
|
".env.example",
|
|
138
158
|
"src/schema.ts",
|
|
139
159
|
"src/index.ts",
|
|
140
|
-
"src/db/index.ts"
|
|
160
|
+
"src/db/index.ts",
|
|
161
|
+
...BOOTSTRAP_STATIC_SRC_RELATIVE
|
|
141
162
|
];
|
|
142
163
|
|
|
143
164
|
// src/package-merge.ts
|
|
@@ -239,13 +260,13 @@ async function runInit(options) {
|
|
|
239
260
|
throw new Error(`Canonical DS template not found: ${templateDir}`);
|
|
240
261
|
}
|
|
241
262
|
if (await pathExists(targetDir)) {
|
|
242
|
-
const entries = await
|
|
263
|
+
const entries = await fs2.readdir(targetDir);
|
|
243
264
|
if (entries.length > 0) {
|
|
244
265
|
throw new Error(`Target directory is not empty: ${targetDir}`);
|
|
245
266
|
}
|
|
246
267
|
}
|
|
247
268
|
s.start("Scaffolding DS package layout");
|
|
248
|
-
await
|
|
269
|
+
await fs2.mkdir(targetDir, { recursive: true });
|
|
249
270
|
await copyDir(templateDir, targetDir, {
|
|
250
271
|
extraExclude: ["src", "drizzle"]
|
|
251
272
|
});
|
|
@@ -254,12 +275,12 @@ async function runInit(options) {
|
|
|
254
275
|
if (options.withDemoSchema) {
|
|
255
276
|
const seedSrc = path2.join(templateDir, "src", "db", "seed.ts");
|
|
256
277
|
if (await pathExists(seedSrc)) {
|
|
257
|
-
await
|
|
278
|
+
await fs2.copyFile(seedSrc, path2.join(targetDir, "src", "db", "seed.ts"));
|
|
258
279
|
}
|
|
259
280
|
}
|
|
260
281
|
const starterDal = path2.join(engineStarterDir(), "dal", "dal.config.yaml");
|
|
261
282
|
if (!options.withDemoSchema && await pathExists(starterDal)) {
|
|
262
|
-
await
|
|
283
|
+
await fs2.copyFile(
|
|
263
284
|
starterDal,
|
|
264
285
|
path2.join(targetDir, "dal", "dal.config.yaml")
|
|
265
286
|
);
|
|
@@ -284,14 +305,15 @@ async function runInit(options) {
|
|
|
284
305
|
});
|
|
285
306
|
} else {
|
|
286
307
|
for (const rel of ["src/schema.ts", "src/index.ts", "src/db/index.ts"]) {
|
|
287
|
-
await
|
|
308
|
+
await fs2.copyFile(path2.join(templateDir, rel), path2.join(targetDir, rel));
|
|
288
309
|
}
|
|
289
310
|
}
|
|
311
|
+
await copyBootstrapStaticSrc(templateDir, targetDir);
|
|
290
312
|
s.stop("DS package scaffolded");
|
|
291
313
|
}
|
|
292
314
|
|
|
293
315
|
// src/upgrade.ts
|
|
294
|
-
import
|
|
316
|
+
import fs3 from "fs/promises";
|
|
295
317
|
import path3 from "path";
|
|
296
318
|
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
|
|
297
319
|
import { spinner as spinner2 } from "@clack/prompts";
|
|
@@ -306,10 +328,10 @@ async function mergeUpgradePackageJson(templatePath, destPath, mergeOptions) {
|
|
|
306
328
|
await writeJson(destPath, mergePackageJson(consumer, template, mergeOptions));
|
|
307
329
|
}
|
|
308
330
|
async function mergeUpgradeDalConfig(templatePath, destPath) {
|
|
309
|
-
const templateRaw = await
|
|
310
|
-
const consumerRaw = await pathExists(destPath) ? await
|
|
311
|
-
await
|
|
312
|
-
await
|
|
331
|
+
const templateRaw = await fs3.readFile(templatePath, "utf8");
|
|
332
|
+
const consumerRaw = await pathExists(destPath) ? await fs3.readFile(destPath, "utf8") : null;
|
|
333
|
+
await fs3.mkdir(path3.dirname(destPath), { recursive: true });
|
|
334
|
+
await fs3.writeFile(
|
|
313
335
|
destPath,
|
|
314
336
|
mergeDalConfig(templateRaw, consumerRaw),
|
|
315
337
|
"utf8"
|
|
@@ -327,8 +349,8 @@ async function copyUpgradeRelativeFile(rel, templateDir, packageDir, mergeOption
|
|
|
327
349
|
await mergeUpgradeDalConfig(templatePath, destPath);
|
|
328
350
|
return;
|
|
329
351
|
}
|
|
330
|
-
await
|
|
331
|
-
await
|
|
352
|
+
await fs3.mkdir(path3.dirname(destPath), { recursive: true });
|
|
353
|
+
await fs3.copyFile(templatePath, destPath);
|
|
332
354
|
}
|
|
333
355
|
async function runEntityLintIfAvailable(repoRoot, packageDir) {
|
|
334
356
|
const dalCodegenLint = path3.join(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@corpdk/create-ds",
|
|
3
|
-
"version": "2026.10.0-alpha.
|
|
3
|
+
"version": "2026.10.0-alpha.4",
|
|
4
4
|
"description": "Scaffold and upgrade DAL-automated GraphQL data services",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -26,11 +26,14 @@
|
|
|
26
26
|
"yaml": "^2.8.3"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/node": "^
|
|
29
|
+
"@types/node": "^24.0.0",
|
|
30
30
|
"tsup": "^8.5.1",
|
|
31
31
|
"typescript": "^6.0.2"
|
|
32
32
|
},
|
|
33
33
|
"license": "MIT",
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=24.0.0"
|
|
36
|
+
},
|
|
34
37
|
"scripts": {
|
|
35
38
|
"build": "tsup",
|
|
36
39
|
"dev": "tsup --watch",
|