feat(foundation): Wave 3 integrity/persistence/build fixes
CI (SIAX Cloud) / security (push) Failing after 28s
CI (SIAX Cloud) / quality (push) Failing after 38s

This commit is contained in:
SIAX Foundation Bot
2026-07-25 13:54:36 +02:00
parent bd5e309851
commit 844220d9f5
18 changed files with 2616 additions and 38 deletions
+6 -1
View File
@@ -24,4 +24,9 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
next-env.d.ts
# pnpm local store (created when store-dir defaults into the project)
.pnpm-store/
# interim LocalBlobStore output (src/adapters/local-blob-store.ts)
.data/
+2
View File
@@ -1 +1,3 @@
verify-deps-before-run=false
include-workspace-root=true
confirmModulesPurge=false
+29
View File
@@ -0,0 +1,29 @@
// Flat ESLint config (ESLint 9) for 0pt's capability code.
//
// Scope: src/ + tests/ — the backend capability layer this repo's Wave 2/3
// hardening actually owns. The v0-generated Next.js UI (app/, components/,
// hooks/, lib/) is intentionally NOT linted here; wiring the full Next lint
// preset over that generated surface is a separate concern. `pnpm run lint`
// runs this over src + tests.
import js from "@eslint/js";
import tseslint from "typescript-eslint";
export default tseslint.config(
{
ignores: ["node_modules/**", ".next/**", "**/*.d.ts"],
},
js.configs.recommended,
...tseslint.configs.recommended,
{
files: ["src/**/*.ts", "tests/**/*.ts"],
languageOptions: {
ecmaVersion: 2022,
sourceType: "module",
},
rules: {
// Underscore-prefixed args are deliberate no-op/interface-shaped params
// (e.g. the local/no-op client method params in src/clients/*).
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_", varsIgnorePattern: "^_" }],
},
},
);
+14 -5
View File
@@ -2,11 +2,15 @@
"name": "my-v0-project",
"version": "0.1.0",
"private": true,
"packageManager": "pnpm@9.15.9",
"scripts": {
"build": "next build",
"dev": "next dev",
"lint": "eslint .",
"start": "next start"
"lint": "eslint src tests",
"start": "next start",
"typecheck": "tsc -p tsconfig.check.json",
"test": "vitest run",
"test:watch": "vitest"
},
"dependencies": {
"@hookform/resolvers": "^3.10.0",
@@ -63,18 +67,23 @@
"zod": "3.25.76"
},
"devDependencies": {
"@eslint/js": "^9.15.0",
"@tailwindcss/postcss": "^4.1.9",
"@types/node": "^22",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9.15.0",
"postcss": "^8.5",
"tailwindcss": "^4.1.9",
"tw-animate-css": "1.3.3",
"typescript": "^5"
"typescript": "^5",
"typescript-eslint": "^8.15.0",
"vitest": "^3.2.0"
},
"pnpm": {
"onlyBuiltDependencies": [
"sharp"
"sharp",
"esbuild"
]
}
}
}
@@ -0,0 +1,36 @@
{
"$id": "0pt.iceberg_table.schema.v1",
"type": "object",
"required": [
"table_id",
"tenant_id",
"project_id",
"table_name",
"namespace",
"storage_uri",
"table_format",
"status",
"created_at"
],
"properties": {
"table_id": { "type": "string", "description": "Reference into ST0RE's table registry (IcebergTable.tableId, st0re_iceberg_tables)." },
"tenant_id": { "type": "string" },
"project_id": { "type": "string" },
"table_name": { "type": "string" },
"namespace": { "type": "string", "description": "ST0RE lakehouse namespace name." },
"storage_uri": { "type": "string", "description": "Object-store URI for the table's data/metadata, e.g. s3://siax-tenants/.../table." },
"catalog_ref": { "type": "string", "description": "Opaque reference into the external Iceberg catalog — ST0RE does not resolve it." },
"table_format": { "type": "string", "enum": ["iceberg", "delta", "hudi"] },
"current_snapshot_id": { "type": "string" },
"schema_version": { "type": "string" },
"partition_spec": { "type": "array", "items": { "type": "string" } },
"retention_policy": { "type": "string" },
"data_residency": { "type": "string" },
"pii_level": { "type": "string", "enum": ["none", "low", "medium", "high"] },
"owner_product": { "type": "string" },
"status": { "type": "string", "enum": ["active", "deprecated", "archived"] },
"correlation_id": { "type": "string" },
"created_at": { "type": "string" },
"created_by": { "type": "string" }
}
}
@@ -0,0 +1,53 @@
{
"$id": "0pt.lineage_event.schema.v1",
"type": "object",
"required": [
"lineage_event_id",
"tenant_id",
"project_id",
"producer",
"input_assets",
"output_assets",
"created_at"
],
"properties": {
"lineage_event_id": { "type": "string" },
"tenant_id": { "type": "string" },
"project_id": { "type": "string" },
"producer": {
"type": "object",
"description": "The capability/app that produced this lineage edge.",
"required": ["app_id", "capability_id"],
"properties": {
"app_id": { "type": "string" },
"capability_id": { "type": "string" }
}
},
"input_assets": {
"type": "array",
"items": {
"type": "object",
"required": ["asset_type", "asset_id"],
"properties": {
"asset_type": { "type": "string", "enum": ["dataset", "iceberg_table", "artifact", "source", "document", "signal"] },
"asset_id": { "type": "string" }
}
}
},
"output_assets": {
"type": "array",
"items": {
"type": "object",
"required": ["asset_type", "asset_id"],
"properties": {
"asset_type": { "type": "string", "enum": ["dataset", "iceberg_table", "artifact", "source", "document", "signal"] },
"asset_id": { "type": "string" }
}
}
},
"st0re_artifacts": { "type": "array", "items": { "type": "string" } },
"quality_report_id": { "type": "string" },
"correlation_id": { "type": "string" },
"created_at": { "type": "string" }
}
}
+31
View File
@@ -0,0 +1,31 @@
{
"$id": "0pt.signal.schema.v1",
"type": "object",
"required": [
"signal_id",
"tenant_id",
"project_id",
"signal_type",
"signal_strength",
"entity_type",
"entity_id",
"observed_at",
"created_at"
],
"properties": {
"signal_id": { "type": "string" },
"tenant_id": { "type": "string" },
"project_id": { "type": "string" },
"signal_type": { "type": "string", "description": "e.g. hiring_growth, funding_round, tech_adoption, leadership_change." },
"signal_strength": { "type": "number", "description": "Normalized 0..1 confidence/intensity of the signal.", "minimum": 0, "maximum": 1 },
"entity_type": { "type": "string", "enum": ["company", "person", "domain", "vehicle"] },
"entity_id": { "type": "string" },
"value": { "description": "Signal payload value (type depends on signal_type)." },
"unit": { "type": "string" },
"source_id": { "type": "string", "description": "References 0pt.source.schema.v1's source_id." },
"confidence_level": { "type": "string", "enum": ["low", "medium", "high"] },
"observed_at": { "type": "string" },
"correlation_id": { "type": "string" },
"created_at": { "type": "string" }
}
}
+1798 -30
View File
File diff suppressed because it is too large Load Diff
+18 -2
View File
@@ -1,2 +1,18 @@
allowBuilds:
sharp: set this to true or false
# SIAX Cloud 0pt workspace.
#
# The deployable Next.js app AND the 0pt capability code (src/, tests/) live at
# the repo ROOT — there are no separate member packages yet (packages/ holds
# JSON schemas only, no package.json). Previously this file carried only a
# placeholder `allowBuilds:` block and NO `packages:` field, which made pnpm
# abort with "packages field missing or empty" on any non-`--ignore-workspace`
# invocation. A present (non-empty) `packages:` field fixes that; the root
# package is included in `pnpm -r` runs via `include-workspace-root=true`
# (.npmrc), which is what lets `pnpm -r run typecheck` / `pnpm -r run test`
# execute the root package's scripts.
packages:
- "packages/*"
# Build scripts that are allowed to run during install (pnpm >= 9 approval gate).
onlyBuiltDependencies:
- sharp
- esbuild
+98
View File
@@ -0,0 +1,98 @@
/**
* src/clients/aud0-client.ts
* ===========================
* 0pt's thin client for emitting append-only events + lineage edges to AUD0
* (the SIAX Cloud system of record). Two methods:
* - ingestEvent -> POST {baseUrl}/v1/aud0/events
* - ingestLineageEvent -> POST {baseUrl}/v1/aud0/lineage/events
*
* Convention (identical to cl0ud-client.ts / n0d-client.ts / st0re-client.ts
* / st0re-lakehouse-client.ts): when no base URL is configured the client is
* a NO-OP — it does not attempt any network call. AUD0 is a best-effort,
* out-of-band audit sink for 0pt; a missing AUD0_URL (unit tests, local dev)
* must not turn every capability call into a failed fetch to `undefined`.
* When a base URL IS configured, events are POSTed as-is (the event object is
* the wire body) with `Content-Type: application/json`.
*/
export interface Aud0Event {
event_id: string;
event_type: string;
tenant_id: string;
project_id: string;
actor_id: string;
app_id: string;
capability_id: string;
resource_type: string;
resource_id: string;
/** Risk level L0–L5 per the SIAX Cloud risk taxonomy. */
risk_level: string;
payload: Record<string, unknown>;
created_at: string;
correlation_id?: string;
}
export interface Aud0LineageEvent {
lineage_event_id: string;
tenant_id: string;
project_id: string;
app_id: string;
capability_id: string;
source_type: string;
source_id: string;
target_type: string;
target_id: string;
/** e.g. "produced" | "derived_from" | "stored_as". */
lineage_type: string;
metadata: Record<string, unknown>;
created_at: string;
correlation_id?: string;
}
export interface Aud0Client {
ingestEvent(event: Aud0Event): Promise<void>;
ingestLineageEvent(event: Aud0LineageEvent): Promise<void>;
}
export function createAud0Client(baseUrl?: string): Aud0Client {
if (!baseUrl) return new NoopAud0Client();
return new HttpAud0Client(baseUrl);
}
/** No AUD0_URL configured: audit emission is a no-op (see module doc comment). */
class NoopAud0Client implements Aud0Client {
async ingestEvent(_event: Aud0Event): Promise<void> {
/* intentional no-op */
}
async ingestLineageEvent(_event: Aud0LineageEvent): Promise<void> {
/* intentional no-op */
}
}
class HttpAud0Client implements Aud0Client {
private readonly baseUrl: string;
constructor(baseUrl: string) {
// Normalize so `${baseUrl}/v1/...` never produces a double slash.
this.baseUrl = baseUrl.replace(/\/+$/, "");
}
async ingestEvent(event: Aud0Event): Promise<void> {
await this.post("/v1/aud0/events", event);
}
async ingestLineageEvent(event: Aud0LineageEvent): Promise<void> {
await this.post("/v1/aud0/lineage/events", event);
}
private async post(path: string, body: unknown): Promise<void> {
const res = await fetch(`${this.baseUrl}${path}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
if (!res.ok) {
throw new Error(`AUD0 ${path} error: ${res.status} ${await res.text().catch(() => "")}`);
}
}
}
+79
View File
@@ -0,0 +1,79 @@
/**
* src/clients/cl0ud-client.ts
* ============================
* 0pt's client for the CL0UD control-plane policy decision point:
* evaluatePolicy -> POST {baseUrl}/v1/cl0ud/policies/evaluate
*
* Every side-effecting 0pt capability re-consults CL0UD before acting (per
* docs/PRODUCT_PLAN.md §4.1), so this is the single choke point for that.
*
* Convention (identical to aud0-client.ts / n0d-client.ts / st0re-client.ts):
* when no base URL is configured the client runs in LOCAL PASS-THROUGH mode —
* it returns a deterministic `allow` decision WITHOUT any network call, so
* unit tests and local dev are hermetic. This is a dev-mode default only; any
* real deployment MUST set CL0UD_URL so decisions come from the real policy
* engine. The pass-through never invents a `deny`/`approval_required` — it
* only ever allows, and it stamps a clearly local-looking decision id.
*/
import crypto from "crypto";
export type PolicyDecision = "allow" | "deny" | "approval_required";
export interface EvaluatePolicyInput {
tenant_id: string;
project_id: string;
actor_id: string;
capability_id: string;
resource_type: string;
resource_id: string;
/** Risk level L0–L5 per the SIAX Cloud risk taxonomy. */
risk_level: string;
correlation_id?: string;
}
export interface PolicyResult {
decision: PolicyDecision;
decision_id: string;
reason?: string;
}
export interface Cl0udClient {
evaluatePolicy(input: EvaluatePolicyInput): Promise<PolicyResult>;
}
export function createCl0udClient(baseUrl?: string): Cl0udClient {
if (!baseUrl) return new LocalAllowCl0udClient();
return new HttpCl0udClient(baseUrl);
}
/** No CL0UD_URL configured: allow-only local pass-through (see module doc comment). */
class LocalAllowCl0udClient implements Cl0udClient {
async evaluatePolicy(_input: EvaluatePolicyInput): Promise<PolicyResult> {
return { decision: "allow", decision_id: `pdec_local_${crypto.randomUUID()}` };
}
}
class HttpCl0udClient implements Cl0udClient {
private readonly baseUrl: string;
constructor(baseUrl: string) {
this.baseUrl = baseUrl.replace(/\/+$/, "");
}
async evaluatePolicy(input: EvaluatePolicyInput): Promise<PolicyResult> {
const res = await fetch(`${this.baseUrl}/v1/cl0ud/policies/evaluate`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(input),
});
if (!res.ok) {
throw new Error(`CL0UD policy evaluate error: ${res.status} ${await res.text().catch(() => "")}`);
}
const body = (await res.json()) as Partial<PolicyResult>;
return {
decision: (body.decision ?? "deny") as PolicyDecision,
decision_id: body.decision_id ?? `pdec_${crypto.randomUUID()}`,
reason: body.reason,
};
}
}
+84
View File
@@ -0,0 +1,84 @@
/**
* src/clients/n0d-client.ts
* ==========================
* 0pt's client for REQUESTING heavy compute jobs from N0D (the Compute OS).
* 0pt never executes heavy work in-process — it submits an N0D job and holds
* only the returned `job_id` (docs/11-lakehouse-write-plan.md item 7,
* docs/P0_QUERY_SOURCE_FLOW.md):
* createJob -> POST {baseUrl}/v1/n0d/jobs
*
* Convention (identical to aud0-client.ts / cl0ud-client.ts / st0re-client.ts
* / st0re-lakehouse-client.ts): when no base URL is configured the client
* returns a deterministic in-memory MOCK job (id prefixed "mock_job_") with
* NO network call, so unit tests stay hermetic. A real deployment sets
* N0D_URL to submit against the live scheduler.
*/
import crypto from "crypto";
export interface CreateJobInput {
tenant_id: string;
project_id: string;
job_type: string;
capability_id: string;
requested_by_app_id: string;
requested_by_actor_id: string;
input_artifact_ids?: string[];
input_dataset_ids?: string[];
output_artifact_type: string;
requires_backbone: boolean;
requires_gpu: boolean;
required_node_roles: string[];
resource_profile: string;
/** Risk level L0–L5 per the SIAX Cloud risk taxonomy. */
risk_level: string;
correlation_id?: string;
}
export type N0dJobState = "queued" | "running" | "succeeded" | "failed" | "cancelled";
export interface N0dJob extends CreateJobInput {
job_id: string;
state: N0dJobState;
created_at: string;
}
export interface N0dClient {
createJob(input: CreateJobInput): Promise<N0dJob>;
}
export function createN0dClient(baseUrl?: string): N0dClient {
if (!baseUrl) return new MockN0dClient();
return new HttpN0dClient(baseUrl);
}
/** No N0D_URL configured: returns a deterministic mock job (see module doc comment). */
class MockN0dClient implements N0dClient {
async createJob(input: CreateJobInput): Promise<N0dJob> {
return {
...input,
job_id: `mock_job_${crypto.randomUUID()}`,
state: "queued",
created_at: new Date().toISOString(),
};
}
}
class HttpN0dClient implements N0dClient {
private readonly baseUrl: string;
constructor(baseUrl: string) {
this.baseUrl = baseUrl.replace(/\/+$/, "");
}
async createJob(input: CreateJobInput): Promise<N0dJob> {
const res = await fetch(`${this.baseUrl}/v1/n0d/jobs`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(input),
});
if (!res.ok) {
throw new Error(`N0D create-job error: ${res.status} ${await res.text().catch(() => "")}`);
}
return (await res.json()) as N0dJob;
}
}
+93
View File
@@ -0,0 +1,93 @@
/**
* src/clients/st0re-client.ts
* ============================
* 0pt's client for the generic ST0RE Artifact registry (snake_case wire
* shape), distinct from `./st0re-lakehouse-client.ts` (the camelCase
* /v1/st0re/lakehouse/* table registry). This one registers an artifact's
* METADATA — a pointer to where the bytes live (provider/bucket/key/region)
* plus content-type/size/checksum/retention/PII/residency:
* createArtifact -> POST {baseUrl}/v1/st0re/artifacts
*
* KNOWN GAP (documented in src/adapters/local-blob-store.ts): ST0RE does not
* yet expose a raw-bytes upload endpoint for 0pt to call, so the actual bytes
* are persisted by LocalBlobStore (interim) and only the resulting location
* is registered here as metadata.
*
* Convention (identical to aud0-client.ts / cl0ud-client.ts / n0d-client.ts /
* st0re-lakehouse-client.ts): when no base URL is configured the client
* returns a deterministic in-memory MOCK artifact (id prefixed
* "mock_artifact_") with NO network call, so unit tests stay hermetic. A real
* deployment sets ST0RE_URL to register against the live artifact registry.
*/
import crypto from "crypto";
export interface St0reObjectLocation {
provider: string;
bucket: string;
key: string;
region?: string;
}
export interface CreateArtifactInput {
tenant_id: string;
project_id: string;
artifact_type: string;
app_id: string;
produced_by: string;
object_location: St0reObjectLocation;
content_type: string;
size_bytes: number;
checksum_sha256: string;
/** "none" | "low" | "medium" | "high" — kept as string to stay tolerant of ST0RE's own vocabulary. */
pii_level: string;
retention_policy: string;
data_residency: string;
/** Risk level L0–L5 per the SIAX Cloud risk taxonomy. */
risk_level: string;
correlation_id?: string;
}
export interface St0reArtifact extends CreateArtifactInput {
artifact_id: string;
created_at: string;
}
export interface St0reClient {
createArtifact(input: CreateArtifactInput): Promise<St0reArtifact>;
}
export function createSt0reClient(baseUrl?: string): St0reClient {
if (!baseUrl) return new MockSt0reClient();
return new HttpSt0reClient(baseUrl);
}
/** No ST0RE_URL configured: returns a deterministic mock artifact (see module doc comment). */
class MockSt0reClient implements St0reClient {
async createArtifact(input: CreateArtifactInput): Promise<St0reArtifact> {
return {
...input,
artifact_id: `mock_artifact_${crypto.randomUUID()}`,
created_at: new Date().toISOString(),
};
}
}
class HttpSt0reClient implements St0reClient {
private readonly baseUrl: string;
constructor(baseUrl: string) {
this.baseUrl = baseUrl.replace(/\/+$/, "");
}
async createArtifact(input: CreateArtifactInput): Promise<St0reArtifact> {
const res = await fetch(`${this.baseUrl}/v1/st0re/artifacts`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(input),
});
if (!res.ok) {
throw new Error(`ST0RE create-artifact error: ${res.status} ${await res.text().catch(() => "")}`);
}
return (await res.json()) as St0reArtifact;
}
}
+112
View File
@@ -0,0 +1,112 @@
/**
* src/services/dataset-service.ts
* ================================
* Owns 0pt.dataset.schema.v1 — the registry of 0pt datasets (raw / enriched /
* curated / feature outputs). In-memory reference implementation (same
* convention as the other 0pt services in this repo; a real deployment backs
* this with `opt_datasets`).
*
* Consumed by:
* - dataset-iceberg-mapping-service.ts (getDataset -> does the dataset exist
* before we map it to an Iceberg table?)
* - iceberg-write-service.ts (getDataset -> guard the write path)
*
* Registering a dataset emits a best-effort AUD0 `0pt.dataset_registered`
* event; with no AUD0_URL configured that emission is a no-op (see
* aud0-client.ts), so this stays hermetic in tests and local dev.
*/
import { createAud0Client, type Aud0Client } from "../clients/aud0-client";
export type DatasetType = "raw" | "enriched" | "curated" | "feature" | "derived";
export type DatasetStatus = "active" | "deprecated" | "archived";
export interface Dataset {
dataset_id: string;
tenant_id: string;
project_id: string;
name: string;
dataset_type: DatasetType;
description?: string;
status: DatasetStatus;
correlation_id?: string;
created_at: string;
updated_at?: string;
created_by?: string;
}
export interface RegisterDatasetInput {
dataset_id: string;
tenant_id: string;
project_id: string;
name: string;
dataset_type: DatasetType;
description?: string;
status?: DatasetStatus;
correlation_id?: string;
created_by?: string;
}
export class DatasetService {
private datasets: Map<string, Dataset> = new Map();
private aud0: Aud0Client;
constructor(aud0BaseUrl?: string) {
this.aud0 = createAud0Client(aud0BaseUrl);
}
async registerDataset(input: RegisterDatasetInput): Promise<Dataset> {
if (this.datasets.has(input.dataset_id)) {
throw new Error(`Dataset ${input.dataset_id} already exists`);
}
if (!input.name) {
throw new Error("name is required");
}
const now = new Date().toISOString();
const dataset: Dataset = {
dataset_id: input.dataset_id,
tenant_id: input.tenant_id,
project_id: input.project_id,
name: input.name,
dataset_type: input.dataset_type,
description: input.description,
status: input.status ?? "active",
correlation_id: input.correlation_id,
created_at: now,
created_by: input.created_by,
};
this.datasets.set(dataset.dataset_id, dataset);
await this.aud0.ingestEvent({
event_id: `evt_0pt_dataset_registered_${dataset.dataset_id}`,
event_type: "0pt.dataset_registered",
tenant_id: dataset.tenant_id,
project_id: dataset.project_id,
actor_id: dataset.created_by ?? "system",
app_id: "0pt",
capability_id: "0pt.register_dataset",
resource_type: "dataset",
resource_id: dataset.dataset_id,
risk_level: "L2",
payload: { dataset_type: dataset.dataset_type, name: dataset.name },
created_at: now,
correlation_id: dataset.correlation_id,
});
return dataset;
}
async getDataset(datasetId: string): Promise<Dataset> {
const dataset = this.datasets.get(datasetId);
if (!dataset) throw new Error(`Dataset ${datasetId} not found`);
return dataset;
}
async listDatasets(filter?: { tenant_id?: string; project_id?: string; dataset_type?: DatasetType }): Promise<Dataset[]> {
let results = Array.from(this.datasets.values());
if (filter?.tenant_id) results = results.filter((d) => d.tenant_id === filter.tenant_id);
if (filter?.project_id) results = results.filter((d) => d.project_id === filter.project_id);
if (filter?.dataset_type) results = results.filter((d) => d.dataset_type === filter.dataset_type);
return results;
}
}
+85
View File
@@ -0,0 +1,85 @@
/**
* src/services/source-service.ts
* ===============================
* Owns 0pt.source.schema.v1 — the registry of upstream data sources
* (databases, crawl domains, APIs, file drops). In-memory reference
* implementation (same convention as the other 0pt services in this repo:
* each API route file constructs its own instance; a real deployment backs
* this with `opt_sources` — sql/002_p0_dataset_quality.sql).
*
* Consumed by:
* - source-query-service.ts (getSource -> is this source queryable?)
* - source-rate-policy-service.ts (getSource -> does the source exist?)
*
* Registering a source emits a best-effort AUD0 `0pt.source_registered`
* event; with no AUD0_URL configured that emission is a no-op (see
* aud0-client.ts), so this stays hermetic in tests and local dev.
*/
import { createAud0Client, type Aud0Client } from "../clients/aud0-client";
import type { CreateSourceInput, Source } from "../types/source";
export class SourceService {
private sources: Map<string, Source> = new Map();
private aud0: Aud0Client;
constructor(aud0BaseUrl?: string) {
this.aud0 = createAud0Client(aud0BaseUrl);
}
async createSource(input: CreateSourceInput): Promise<Source> {
if (this.sources.has(input.source_id)) {
throw new Error(`Source ${input.source_id} already exists`);
}
if (!input.name) {
throw new Error("name is required");
}
const now = new Date().toISOString();
const source: Source = {
source_id: input.source_id,
tenant_id: input.tenant_id,
project_id: input.project_id,
source_type: input.source_type,
name: input.name,
adapter_id: input.adapter_id,
description: input.description,
status: input.status ?? "active",
correlation_id: input.correlation_id,
created_at: now,
created_by: input.created_by,
};
this.sources.set(source.source_id, source);
await this.aud0.ingestEvent({
event_id: `evt_0pt_source_registered_${source.source_id}`,
event_type: "0pt.source_registered",
tenant_id: source.tenant_id,
project_id: source.project_id,
actor_id: source.created_by ?? "system",
app_id: "0pt",
capability_id: "0pt.register_source",
resource_type: "source",
resource_id: source.source_id,
risk_level: "L2",
payload: { source_type: source.source_type, adapter_id: source.adapter_id ?? null, name: source.name },
created_at: now,
correlation_id: source.correlation_id,
});
return source;
}
async getSource(sourceId: string): Promise<Source> {
const source = this.sources.get(sourceId);
if (!source) throw new Error(`Source ${sourceId} not found`);
return source;
}
async listSources(filter?: { tenant_id?: string; project_id?: string; source_type?: Source["source_type"] }): Promise<Source[]> {
let results = Array.from(this.sources.values());
if (filter?.tenant_id) results = results.filter((s) => s.tenant_id === filter.tenant_id);
if (filter?.project_id) results = results.filter((s) => s.project_id === filter.project_id);
if (filter?.source_type) results = results.filter((s) => s.source_type === filter.source_type);
return results;
}
}
+45
View File
@@ -0,0 +1,45 @@
/**
* src/types/source.ts
* =====================
* 0pt.source.schema.v1 — a registered upstream data source (a database, a
* crawlable web domain, an API, a file drop, …). Owned by SourceService
* (src/services/source-service.ts); referenced by SourceRatePolicy
* (src/types/source-rate-policy.ts) and by the synchronous query path
* (src/services/source-query-service.ts), which reads `source_type` +
* `adapter_id` to decide whether a Source is queryable.
*
* `adapter_id` is the seam that lets a "database" source name the concrete
* driver 0pt should use for it (today only "fabric_onelake_sql" is wired on
* the synchronous path — see source-query-service.ts).
*/
export type SourceType = "database" | "file" | "web" | "api" | "stream" | "manual";
export type SourceStatus = "active" | "paused" | "archived";
export interface Source {
source_id: string;
tenant_id: string;
project_id: string;
source_type: SourceType;
name: string;
/** Concrete driver id for this source, e.g. "fabric_onelake_sql". Optional: not every source is directly queryable. */
adapter_id?: string;
description?: string;
status: SourceStatus;
correlation_id?: string;
created_at: string;
updated_at?: string;
created_by?: string;
}
export interface CreateSourceInput {
source_id: string;
tenant_id: string;
project_id: string;
source_type: SourceType;
name: string;
adapter_id?: string;
description?: string;
status?: SourceStatus;
correlation_id?: string;
created_by?: string;
}
+10
View File
@@ -0,0 +1,10 @@
{
"//": "Scoped, blocking type-check for 0pt's capability code (src/ + tests/). The root tsconfig.json intentionally also covers the v0-generated Next.js UI (app/, components/, hooks/), whose known TS issues next.config.mjs suppresses via `typescript.ignoreBuildErrors: true`. This config type-checks the backend capability layer — the actual deliverable — under the SAME strict settings as the root tsconfig, without inheriting the UI's suppressed surface. Invoked by `pnpm run typecheck`.",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"types": ["node"]
},
"include": ["src/**/*.ts", "tests/**/*.ts"],
"exclude": ["node_modules", ".next"]
}
+23
View File
@@ -0,0 +1,23 @@
import { defineConfig } from "vitest/config";
import { fileURLToPath } from "node:url";
import path from "node:path";
// `@/…` maps to the repo root, matching tsconfig.json's `paths` (`@/*` -> `./*`),
// so tests can `import { X } from "@/src/services/…"` exactly as the app code does.
const rootDir = path.dirname(fileURLToPath(import.meta.url));
export default defineConfig({
resolve: {
alias: {
"@": rootDir,
},
},
test: {
// P0 capability tests. Node environment (these are backend service/adapter
// tests, no DOM). The `.realinfra.` test self-skips when its live backend
// is unreachable — see tests/p0/iceberg-write-service.realinfra.test.ts.
include: ["tests/**/*.test.ts"],
environment: "node",
globals: false,
},
});