Merge pull request #2 from sax3l/fix/0pt-missing-client-service-modules

fix: restore 0pt build — add missing platform clients + registry services
This commit is contained in:
2026-07-14 01:23:57 +02:00
committed by GitHub
14 changed files with 1711 additions and 3 deletions
+6 -3
View File
@@ -6,7 +6,9 @@
"build": "next build",
"dev": "next dev",
"lint": "eslint .",
"start": "next start"
"start": "next start",
"typecheck": "tsc --noEmit -p tsconfig.json",
"test": "vitest run"
},
"dependencies": {
"@hookform/resolvers": "^3.10.0",
@@ -70,11 +72,12 @@
"postcss": "^8.5",
"tailwindcss": "^4.1.9",
"tw-animate-css": "1.3.3",
"typescript": "^5"
"typescript": "^5",
"vitest": "^3.2.7"
},
"pnpm": {
"onlyBuiltDependencies": [
"sharp"
]
}
}
}
@@ -0,0 +1,20 @@
{
"$id": "0pt.iceberg_table.schema.v1",
"description": "NON-AUTHORITATIVE READ CACHE ONLY. ST0RE owns Iceberg table/catalog/snapshot state (docs/ICEBERG_WRITE_BOUNDARY.md, src/clients/st0re-lakehouse-client.ts's St0reIcebergTable). This schema mirrors that shape for tests/p0/enterprise-data-os-expansion.test.ts's contract assertions from an earlier pass; 0pt must never write to it as a second copy of ST0RE's table registry -- see docs/ICEBERG_WRITE_BOUNDARY.md's 'A pre-existing artifact this pass did not touch' section.",
"type": "object",
"required": ["table_id", "table_name", "storage_uri", "namespace", "table_format", "catalog_ref"],
"properties": {
"table_id": { "type": "string" },
"namespace": { "type": "string" },
"table_name": { "type": "string" },
"table_format": { "type": "string", "enum": ["iceberg", "delta", "hudi"] },
"storage_uri": { "type": "string" },
"catalog_ref": { "type": "string", "description": "Opaque reference into the external Iceberg catalog -- ST0RE does not resolve it." },
"dataset_id": { "type": "string" },
"owner_product": { "type": "string" },
"current_snapshot_id": { "type": "string" },
"status": { "type": "string", "enum": ["active", "deprecated", "archived"] },
"created_at": { "type": "string" },
"created_by": { "type": "string" }
}
}
@@ -0,0 +1,30 @@
{
"$id": "0pt.lineage_event.schema.v1",
"description": "CONTRACT-ONLY -- 0pt's real lineage emissions today go through Aud0Client.ingestLineageEvent (src/clients/aud0-client.ts), whose Aud0LineageEventInput shape is source_type/source_id -> target_type/target_id, not input_assets/output_assets. This wider multi-asset shape exists so tests/p0/enterprise-data-os-expansion.test.ts's contract assertions (from an earlier 'PROMPT 2' pass) have a real file to check; it documents an intended future generalization (multi-input/multi-output lineage), not a built/wired capability.",
"type": "object",
"required": ["input_assets", "output_assets", "producer"],
"properties": {
"lineage_event_id": { "type": "string" },
"event_type": { "type": "string" },
"app_id": { "type": "string" },
"capability_id": { "type": "string" },
"producer": { "type": "string", "description": "app_id/capability_id that produced this lineage edge." },
"input_assets": {
"type": "array",
"items": {
"type": "object",
"properties": { "asset_type": { "type": "string" }, "asset_id": { "type": "string" } }
}
},
"output_assets": {
"type": "array",
"items": {
"type": "object",
"properties": { "asset_type": { "type": "string" }, "asset_id": { "type": "string" } }
}
},
"st0re_artifacts": { "type": "array", "items": { "type": "string" } },
"quality_report_id": { "type": "string" },
"created_at": { "type": "string" }
}
}
+17
View File
@@ -0,0 +1,17 @@
{
"$id": "0pt.signal.schema.v1",
"description": "CONTRACT-ONLY -- no service in this repo produces or reads 0pt.signal rows yet (as of this pass). This schema exists so tests/p0/enterprise-data-os-expansion.test.ts's contract assertions (from an earlier 'PROMPT 2' pass) have a real file to check; it is documentation of an intended shape for future ICP/signal-intelligence work, not a built capability. Do not treat it as evidence that signal detection is implemented.",
"type": "object",
"required": ["signal_id", "signal_type", "signal_strength", "entity_type"],
"properties": {
"signal_id": { "type": "string" },
"signal_type": { "type": "string", "description": "e.g. hiring_growth, funding_event, leadership_change." },
"signal_strength": { "type": "number", "minimum": 0, "maximum": 1 },
"entity_type": { "type": "string", "enum": ["company", "contact", "vehicle"] },
"entity_key": { "type": "string" },
"source_id": { "type": "string" },
"confidence": { "type": "number", "minimum": 0, "maximum": 1 },
"detected_at": { "type": "string" },
"metadata": { "type": "object" }
}
}
+947
View File
File diff suppressed because it is too large Load Diff
+97
View File
@@ -0,0 +1,97 @@
// AUD0 audit/evidence client -- 0pt's ONLY path for recording "what
// happened" to the append-only system of record. Every mutating capability
// in this repo emits both a plain event (`ingestEvent`) and, where the
// mutation produced or transformed something, a lineage edge
// (`ingestLineageEvent`) -- see docs/ICEBERG_WRITE_BOUNDARY.md's "Event
// names" table for the full list this client backs.
//
// Same fetch-based, dependency-light shape every sibling client in this
// repo uses (src/clients/st0re-lakehouse-client.ts and this file's own
// siblings cl0ud-client.ts/n0d-client.ts/st0re-client.ts): a thin
// interface, an HTTP implementation, and a deterministic in-memory MOCK used
// whenever no base URL is configured.
//
// HONESTY NOTE: no AUD0_URL was available to probe in this pass. The mock
// below is a true no-op (per docs/ICEBERG_WRITE_BOUNDARY.md: "no-op by
// default, same as every other AUD0 emission already in this repo -- AUD0
// has no live ingestion endpoint yet") -- it never throws and never blocks a
// caller, matching AUD0's own documented stance that an audit emission is a
// record of what already happened, not a gate the action waits on. A real
// deployment must be pointed at via `aud0BaseUrl`/`AUD0_URL` before events
// emitted through this client are actually durable anywhere.
export interface Aud0EventInput {
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: string;
payload?: unknown;
created_at: string;
correlation_id: string;
}
export interface Aud0LineageEventInput {
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;
lineage_type: string;
metadata?: unknown;
created_at: string;
correlation_id: string;
}
export interface Aud0Client {
ingestEvent(input: Aud0EventInput): Promise<Aud0EventInput>;
ingestLineageEvent(input: Aud0LineageEventInput): Promise<Aud0LineageEventInput>;
}
export function createAud0Client(baseUrl?: string): Aud0Client {
if (!baseUrl) return new MockAud0Client();
return new HttpAud0Client(baseUrl);
}
class MockAud0Client implements Aud0Client {
async ingestEvent(input: Aud0EventInput): Promise<Aud0EventInput> {
return input;
}
async ingestLineageEvent(input: Aud0LineageEventInput): Promise<Aud0LineageEventInput> {
return input;
}
}
class HttpAud0Client implements Aud0Client {
constructor(private baseUrl: string) {}
async ingestEvent(input: Aud0EventInput): Promise<Aud0EventInput> {
const res = await fetch(`${this.baseUrl}/v1/aud0/events`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(input),
});
if (!res.ok) throw new Error(`AUD0 event ingestion error: ${res.status}`);
return res.json();
}
async ingestLineageEvent(input: Aud0LineageEventInput): Promise<Aud0LineageEventInput> {
const res = await fetch(`${this.baseUrl}/v1/aud0/lineage/events`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(input),
});
if (!res.ok) throw new Error(`AUD0 lineage event ingestion error: ${res.status}`);
return res.json();
}
}
+82
View File
@@ -0,0 +1,82 @@
// CL0UD policy client -- 0pt's ONLY path for the "is this actor/capability/
// resource allowed right now" check every mutating capability in this repo
// re-runs before it acts (document-extraction-service.ts, iceberg-write-service.ts,
// external-writeback-service.ts). Never bypassed: a `deny` or
// `approval_required` decision always aborts the caller, even when an
// upstream gate (e.g. ACT0's own Approval Engine) already ran -- see
// external-writeback-service.ts's own module doc comment for why that
// specific re-check matters.
//
// Same fetch-based, dependency-light shape every sibling client in this
// repo uses (src/clients/st0re-lakehouse-client.ts, and this file's own
// siblings n0d-client.ts/aud0-client.ts/st0re-client.ts): a thin interface,
// an HTTP implementation, and a deterministic in-memory MOCK used whenever
// no base URL is configured, so this repo's tests (and any caller before
// CL0UD_URL is wired) exercise the real request/response shape and control
// flow without requiring a live CL0UD deployment.
//
// HONESTY NOTE (matches the convention docs/ICEBERG_WRITE_BOUNDARY.md
// documents for st0re-lakehouse-client.ts): no CL0UD_URL was available to
// probe in this pass. The mock below always returns "allow" -- the same
// "graceful degradation when unconfigured" doctrine used throughout this
// repo family, not a security control. A real deployment must be pointed at
// via `cl0udBaseUrl`/`CL0UD_URL` before this client's decision means
// anything in production.
export type PolicyDecisionValue = "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: string;
correlation_id: string;
}
export interface PolicyDecision {
decision_id: string;
decision: PolicyDecisionValue;
reason?: string;
}
export interface Cl0udClient {
evaluatePolicy(input: EvaluatePolicyInput): Promise<PolicyDecision>;
}
export function createCl0udClient(baseUrl?: string): Cl0udClient {
if (!baseUrl) return new MockCl0udClient();
return new HttpCl0udClient(baseUrl);
}
/**
* Deterministic mock -- always "allow". Every 0pt service that calls
* evaluatePolicy() treats a missing decision as fail-closed (it throws on
* anything other than "allow"), so a mock that instead defaulted to "deny"
* would make every unconfigured-CL0UD test path unusable. "allow" is the
* documented, deliberate choice for local/test/unconfigured use --
* tests/p0/external-writeback-service.test.ts exercises "deny" and
* "approval_required" explicitly via its own fetch stub against an HTTP
* client instance, not this mock.
*/
class MockCl0udClient implements Cl0udClient {
async evaluatePolicy(_input: EvaluatePolicyInput): Promise<PolicyDecision> {
return { decision_id: `mock_decision_${Date.now()}`, decision: "allow" };
}
}
class HttpCl0udClient implements Cl0udClient {
constructor(private baseUrl: string) {}
async evaluatePolicy(input: EvaluatePolicyInput): Promise<PolicyDecision> {
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 evaluation error: ${res.status}`);
return res.json();
}
}
+85
View File
@@ -0,0 +1,85 @@
// N0D compute client -- 0pt's ONLY path for requesting a job on N0D
// (Compute OS). 0pt REQUESTS jobs; it never executes them in-process and
// never owns N0D's scheduling/node/GPU decisions (see
// docs/ICEBERG_WRITE_BOUNDARY.md's "N0D executes" boundary note and
// iceberg-write-service.ts's `requestIcebergWrite({ heavy: true })` for the
// concrete example this client backs).
//
// Same fetch-based, dependency-light shape every sibling client in this
// repo uses (src/clients/st0re-lakehouse-client.ts and this file's own
// siblings cl0ud-client.ts/aud0-client.ts/st0re-client.ts): a thin
// interface, an HTTP implementation, and a deterministic in-memory MOCK used
// whenever no base URL is configured -- see st0re-lakehouse-client.ts's
// module doc comment for the full rationale, which applies here unchanged.
//
// HONESTY NOTE: no N0D_URL was available to probe in this pass. The mock
// below returns a queued job id (`mock_job_*`, matching the prefix this
// repo's own tests already assert on -- tests/p0/iceberg-write-service.test.ts,
// tests/p0/document-capture-mailbox.test.ts) but never actually runs
// anything. A real deployment must be pointed at via `n0dBaseUrl`/`N0D_URL`
// before a "job" requested through this client does real work.
export interface N0dCreateJobInput {
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: string;
correlation_id: string;
}
export type N0dJobStatus = "queued" | "running" | "completed" | "failed";
export interface N0dJob {
job_id: string;
status: N0dJobStatus;
job_type: string;
tenant_id: string;
project_id: string;
created_at: string;
}
export interface N0dClient {
createJob(input: N0dCreateJobInput): Promise<N0dJob>;
}
export function createN0dClient(baseUrl?: string): N0dClient {
if (!baseUrl) return new MockN0dClient();
return new HttpN0dClient(baseUrl);
}
class MockN0dClient implements N0dClient {
async createJob(input: N0dCreateJobInput): Promise<N0dJob> {
return {
job_id: `mock_job_${Date.now()}`,
status: "queued",
job_type: input.job_type,
tenant_id: input.tenant_id,
project_id: input.project_id,
created_at: new Date().toISOString(),
};
}
}
class HttpN0dClient implements N0dClient {
constructor(private baseUrl: string) {}
async createJob(input: N0dCreateJobInput): 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 job creation error: ${res.status}`);
return res.json();
}
}
+89
View File
@@ -0,0 +1,89 @@
// ST0RE generic artifact-registry client -- 0pt's path for registering
// artifact METADATA (a pointer to provider/bucket/key + content/PII/
// retention metadata), used by document-capture-service.ts and
// document-extraction-service.ts to record what they produced.
//
// Distinct from `./st0re-lakehouse-client.ts` (which targets ST0RE's newer,
// camelCase `/v1/st0re/lakehouse/*` route family for Iceberg table/snapshot
// state -- see that file's own module doc comment for why the two are kept
// separate). This client's request/response shape is 0pt's own snake_case
// domain convention, matching every other 0pt-owned client in this repo.
//
// KNOWN GAP (see src/adapters/local-blob-store.ts and
// src/services/document-capture-service.ts's own file header "KNOWN GAP"
// note): this client registers artifact metadata only -- it has no real
// bytes-upload endpoint yet. Callers persist bytes via LocalBlobStore first,
// then register the resulting location here.
//
// Same fetch-based, dependency-light shape every sibling client in this
// repo uses (src/clients/st0re-lakehouse-client.ts and this file's own
// siblings cl0ud-client.ts/n0d-client.ts/aud0-client.ts): a thin interface,
// an HTTP implementation, and a deterministic in-memory MOCK used whenever
// no base URL is configured.
//
// HONESTY NOTE: no ST0RE_URL was available to probe in this pass. The mock
// below returns a registered artifact id (`mock_artifact_*`, matching the
// prefix this repo's own tests already assert on --
// tests/p0/document-capture-mailbox.test.ts,
// tests/p0/document-extraction-never-fabricates.test.ts) but does not
// persist anything beyond the current process. A real deployment must be
// pointed at via `st0reBaseUrl`/`ST0RE_URL` before an artifact registered
// through this client is durable anywhere.
export interface St0reObjectLocation {
provider: string;
bucket: string;
key: string;
region?: string;
}
export interface St0reArtifactInput {
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;
pii_level?: "none" | "low" | "medium" | "high";
retention_policy?: string;
data_residency?: string;
risk_level: string;
correlation_id: string;
}
export interface St0reArtifact extends St0reArtifactInput {
artifact_id: string;
created_at: string;
}
export interface St0reClient {
createArtifact(input: St0reArtifactInput): Promise<St0reArtifact>;
}
export function createSt0reClient(baseUrl?: string): St0reClient {
if (!baseUrl) return new MockSt0reClient();
return new HttpSt0reClient(baseUrl);
}
class MockSt0reClient implements St0reClient {
async createArtifact(input: St0reArtifactInput): Promise<St0reArtifact> {
return { ...input, artifact_id: `mock_artifact_${Date.now()}`, created_at: new Date().toISOString() };
}
}
class HttpSt0reClient implements St0reClient {
constructor(private baseUrl: string) {}
async createArtifact(input: St0reArtifactInput): Promise<St0reArtifact> {
const res = await fetch(`${this.baseUrl}/v1/st0re/artifacts/register`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(input),
});
if (!res.ok) throw new Error(`ST0RE artifact registration error: ${res.status}`);
return res.json();
}
}
+114
View File
@@ -0,0 +1,114 @@
/**
* src/services/dataset-service.ts
* ==================================
* Owns the 0pt.dataset registry -- the thing `DatasetIcebergMappingService`
* (src/services/dataset-iceberg-mapping-service.ts) and `IcebergWriteService`
* (src/services/iceberg-write-service.ts) look a `dataset_id` up against
* before pointing an Iceberg table mapping or a write at it. Deliberately
* small and in-memory, same "pure core, thin registry" shape every other
* P0 service in this repo already uses (SourceService, SourceRatePolicyService,
* DatasetIcebergMappingService) -- this is NOT dataset content, schema, or
* quality state; see docs/ICEBERG_WRITE_BOUNDARY.md for that boundary.
*
* In-memory scope: each `new DatasetService()` owns its own registry, same
* pre-existing limitation source-service.ts and every other P0 registry
* service in this repo documents (see docs/P0_QUERY_SOURCE_FLOW.md's "Known
* gaps" section) -- callers that need a shared view across API routes pass
* an existing instance in via the `datasetService` constructor option,
* exactly like IcebergWriteService and DatasetIcebergMappingService already
* do for each other.
*/
import { createAud0Client, type Aud0Client } from "../clients/aud0-client";
import type { Dataset, DatasetStatus, DatasetType, CreateDatasetInput } from "../types/dataset";
interface DatasetRecord {
dataset_id: string;
tenant_id: string;
project_id: string;
name: string;
dataset_type: string;
status: string;
description: string | null;
correlation_id: string | null;
created_at: string;
updated_at: string | null;
}
export class DatasetService {
private datasets: Map<string, DatasetRecord> = new Map();
private aud0: Aud0Client;
constructor(aud0BaseUrl?: string) {
this.aud0 = createAud0Client(aud0BaseUrl);
}
async registerDataset(input: CreateDatasetInput): Promise<Dataset> {
if (this.datasets.has(input.dataset_id)) {
throw new Error(`Dataset ${input.dataset_id} already exists`);
}
const now = new Date().toISOString();
const record: DatasetRecord = {
dataset_id: input.dataset_id,
tenant_id: input.tenant_id,
project_id: input.project_id,
name: input.name,
dataset_type: input.dataset_type,
status: input.status ?? "active",
description: input.description ?? null,
correlation_id: input.correlation_id ?? null,
created_at: now,
updated_at: null,
};
this.datasets.set(input.dataset_id, record);
// 0pt.dataset_registered -- same "no mutation without an evented trail"
// doctrine every other P0 registry service in this repo follows
// (SourceService.createSource, SourceRatePolicyService.createSourceRatePolicy).
await this.aud0.ingestEvent({
event_id: `evt_0pt_dataset_registered_${input.dataset_id}`,
event_type: "0pt.dataset_registered",
tenant_id: input.tenant_id,
project_id: input.project_id,
actor_id: "system",
app_id: "0pt",
capability_id: "0pt.register_dataset",
resource_type: "dataset",
resource_id: input.dataset_id,
risk_level: "L2",
payload: { name: input.name, dataset_type: input.dataset_type },
created_at: now,
correlation_id: input.correlation_id ?? "",
});
return this.toDataset(record);
}
async getDataset(datasetId: string): Promise<Dataset> {
const record = this.datasets.get(datasetId);
if (!record) throw new Error(`Dataset ${datasetId} not found`);
return this.toDataset(record);
}
async listDatasets(filter?: { tenant_id?: string; project_id?: string; status?: DatasetStatus }): Promise<Dataset[]> {
let results = Array.from(this.datasets.values());
if (filter?.tenant_id) results = results.filter((r) => r.tenant_id === filter.tenant_id);
if (filter?.project_id) results = results.filter((r) => r.project_id === filter.project_id);
if (filter?.status) results = results.filter((r) => r.status === filter.status);
return results.map((r) => this.toDataset(r));
}
private toDataset(r: DatasetRecord): Dataset {
return {
dataset_id: r.dataset_id,
tenant_id: r.tenant_id,
project_id: r.project_id,
name: r.name,
dataset_type: r.dataset_type as DatasetType,
status: r.status as DatasetStatus,
description: r.description ?? undefined,
correlation_id: r.correlation_id ?? undefined,
created_at: r.created_at,
updated_at: r.updated_at ?? undefined,
};
}
}
+116
View File
@@ -0,0 +1,116 @@
/**
* src/services/source-service.ts
* =================================
* Owns the 0pt.source registry -- a per-tenant registration of something
* 0pt can query or crawl against (source_type "database" | "web" | "api" |
* "file", carrying an `adapter_id` for the database case). This is the
* registry `SourceQueryService.querySource()` (src/services/source-query-service.ts)
* and `SourceRatePolicyService` (src/services/source-rate-policy-service.ts)
* both look a `source_id` up against -- see docs/P0_QUERY_SOURCE_FLOW.md.
*
* Deliberately small and in-memory, same "pure core, thin registry" shape
* every other P0 service in this repo already uses. In-memory scope: each
* `new SourceService()` owns its own registry -- the same pre-existing
* limitation docs/P0_QUERY_SOURCE_FLOW.md's "Known gaps" section documents
* (a Source registered via one API route module is not yet visible to
* another route module in the same running process). Callers that need a
* shared view pass an existing instance in via the `sourceService`
* constructor option, exactly like SourceQueryService/SourceRatePolicyService
* already do.
*/
import { createAud0Client, type Aud0Client } from "../clients/aud0-client";
import type { Source, SourceStatus, SourceType, CreateSourceInput } from "../types/source";
interface SourceRecord {
source_id: string;
tenant_id: string;
project_id: string;
source_type: string;
name: string;
adapter_id: string | null;
access: string | null;
status: string;
correlation_id: string | null;
created_at: string;
updated_at: string | null;
}
export class SourceService {
private sources: Map<string, SourceRecord> = 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`);
}
const now = new Date().toISOString();
const record: SourceRecord = {
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 ?? null,
access: input.access ?? null,
status: input.status ?? "active",
correlation_id: input.correlation_id ?? null,
created_at: now,
updated_at: null,
};
this.sources.set(input.source_id, record);
// 0pt.source_created -- same "no mutation without an evented trail"
// doctrine every other P0 registry service in this repo follows.
await this.aud0.ingestEvent({
event_id: `evt_0pt_source_created_${input.source_id}`,
event_type: "0pt.source_created",
tenant_id: input.tenant_id,
project_id: input.project_id,
actor_id: "system",
app_id: "0pt",
capability_id: "0pt.create_source",
resource_type: "source",
resource_id: input.source_id,
risk_level: "L2",
payload: { source_type: input.source_type, name: input.name, adapter_id: input.adapter_id },
created_at: now,
correlation_id: input.correlation_id ?? "",
});
return this.toSource(record);
}
async getSource(sourceId: string): Promise<Source> {
const record = this.sources.get(sourceId);
if (!record) throw new Error(`Source ${sourceId} not found`);
return this.toSource(record);
}
async listSources(filter?: { tenant_id?: string; project_id?: string; status?: SourceStatus }): Promise<Source[]> {
let results = Array.from(this.sources.values());
if (filter?.tenant_id) results = results.filter((r) => r.tenant_id === filter.tenant_id);
if (filter?.project_id) results = results.filter((r) => r.project_id === filter.project_id);
if (filter?.status) results = results.filter((r) => r.status === filter.status);
return results.map((r) => this.toSource(r));
}
private toSource(r: SourceRecord): Source {
return {
source_id: r.source_id,
tenant_id: r.tenant_id,
project_id: r.project_id,
source_type: r.source_type as SourceType,
name: r.name,
adapter_id: r.adapter_id ?? undefined,
access: (r.access as Source["access"]) ?? undefined,
status: r.status as SourceStatus,
correlation_id: r.correlation_id ?? undefined,
created_at: r.created_at,
updated_at: r.updated_at ?? undefined,
};
}
}
+39
View File
@@ -0,0 +1,39 @@
// 0pt.dataset.schema.v1
//
// A dataset 0pt produces or manages -- the thing `dataset_iceberg_mapping`
// (src/types/dataset-iceberg-mapping.ts) points at, and the thing
// IcebergWriteService (src/services/iceberg-write-service.ts) writes through
// ST0RE's table registry on behalf of. This type intentionally stays small:
// it is a reference/registry entry, not a copy of dataset content, schema,
// or quality state (that boundary is documented in
// docs/ICEBERG_WRITE_BOUNDARY.md -- 0pt owns dataset production, but this
// specific type is only what DatasetIcebergMappingService/IcebergWriteService
// need to confirm a dataset_id is real before pointing a table at it).
export type DatasetType = "raw" | "structured" | "enriched" | "curated";
export type DatasetStatus = "active" | "archived" | "deprecated";
export interface Dataset {
dataset_id: string;
tenant_id: string;
project_id: string;
name: string;
dataset_type: DatasetType;
status: DatasetStatus;
description?: string;
correlation_id?: string;
created_at: string;
updated_at?: string;
}
export interface CreateDatasetInput {
dataset_id: string;
tenant_id: string;
project_id: string;
name: string;
dataset_type: DatasetType;
description?: string;
status?: DatasetStatus;
correlation_id?: string;
}
+53
View File
@@ -0,0 +1,53 @@
// 0pt.source.schema.v1
//
// A registered data Source that a capability (0pt.query_source today;
// 0pt.create_source / crawl-time source registration in the future) can act
// against. This is a DIFFERENT, newer entity than the static provenance
// catalog in docs/03-data-model.md's `dim_source` table (the ~9-row list of
// national registries served today by GET /api/sources) -- this Source is a
// per-tenant registration of something 0pt can actually connect to (a
// database, a web target, a file drop, an API), carrying an `adapter_id`
// that tells a service layer (e.g. SourceQueryService) which concrete
// adapter implementation to use. See docs/P0_QUERY_SOURCE_FLOW.md and
// src/services/source-query-service.ts, the first real consumer.
//
// `access` mirrors dim_source.access (docs/03-data-model.md) so a Source
// registered here can still be reported against the same legal-sourcing
// vocabulary CLAUDE.md §1 requires everywhere in this repo.
export type SourceType = "web" | "api" | "database" | "file";
export type SourceStatus = "active" | "paused" | "deprecated";
export interface Source {
source_id: string;
tenant_id: string;
project_id: string;
source_type: SourceType;
name: string;
/**
* Identifies which concrete adapter implementation this source is queried
* through (e.g. "fabric_onelake_sql" -- src/adapters/fabric-onelake-adapter.ts).
* Required for source_type "database"; optional/unused for other types
* until they grow a synchronous query path of their own.
*/
adapter_id?: string;
/** Mirrors dim_source.access (docs/03-data-model.md): api | bulk | authorized_web | licensed. */
access?: "api" | "bulk" | "authorized_web" | "licensed";
status: SourceStatus;
correlation_id?: string;
created_at: string;
updated_at?: string;
}
export interface CreateSourceInput {
source_id: string;
tenant_id: string;
project_id: string;
source_type: SourceType;
name: string;
adapter_id?: string;
access?: "api" | "bulk" | "authorized_web" | "licensed";
status?: SourceStatus;
correlation_id?: string;
}
+16
View File
@@ -0,0 +1,16 @@
import { defineConfig } from "vitest/config";
import path from "path";
// Mirrors tsconfig.json's "@/*" -> "./*" path alias so tests/p0/*.test.ts's
// "@/src/..." imports resolve the same way they do for `next build`/tsc.
export default defineConfig({
test: {
include: ["tests/**/*.test.ts"],
environment: "node",
},
resolve: {
alias: {
"@": path.resolve(__dirname, "."),
},
},
});