import type { ConnectionTypes, ExpressionTypes, SegmentationTypes, StorageTypes } from "@cargo-ai/types"; import { type EncryptionRef, type Token } from "../core.js"; import { type ConnectorRef, type FolderRef, type ModelRef, type RelationshipRef } from "../refs.js"; import type { ConnectorHandle } from "./connector.js"; import type { FolderHandle } from "./folder.js"; import type { RelationshipHandle } from "./relationship.js"; export type ScheduleSpec = { type: "cron"; cron: string; } | { type: "dbt"; jobId: string; }; export type ModelKind = StorageTypes.ModelKind; export type NativeObjectExtractorSlug = "defineAccount" | "defineContact" | "defineCustom" | "defineDeal" | "defineLead" | "defineScript"; export type NativeUnifyExtractorSlug = "unifyAccounts" | "unifyAccountEvents" | "unifyContacts" | "unifyContactEvents"; /** The unify extractor slugs, for the deploy engine's adopt-only branch. */ export declare const UNIFY_EXTRACTOR_SLUGS: ReadonlySet; export type NativeExtractorSlug = NativeObjectExtractorSlug | NativeUnifyExtractorSlug; type NativeExtractorConfigs = { defineAccount: Record; defineContact: Record; defineCustom: { columns: { slug: string; type: StorageTypes.ColumnType; }[]; }; defineDeal: Record; defineLead: Record; defineScript: { script: string; columns: { slug: string; type: StorageTypes.ColumnType; }[]; env?: Record; }; unifyAccounts: ModelUnificationConfigSpec; unifyContacts: ModelUnificationConfigSpec; unifyAccountEvents: Record; unifyContactEvents: Record; }; type NativeExtractorColumns = { unifyAccounts: "id" | "domain" | "slug" | "linkedin_id" | "linkedin_handle" | "crunchbase_uuid" | "crunchbase_permalink" | "twitter_handle" | "sales_navigator_id" | "ids"; unifyContacts: "id" | "email" | "personal_email" | "work_email" | "linkedin_id" | "linkedin_handle" | "crunchbase_uuid" | "crunchbase_permalink" | "twitter_handle" | "sales_navigator_id" | "account_id" | "ids"; unifyAccountEvents: "id" | "account_id" | "occurred_at" | "event_name" | "properties" | "dataset_slug" | "model_slug"; unifyContactEvents: "id" | "contact_id" | "occurred_at" | "event_name" | "properties" | "dataset_slug" | "model_slug"; defineAccount: "id" | "name" | "type" | "industry" | "website" | "linkedin_url" | "phone" | "description" | "number_of_employees" | "annual_revenue" | "billing_street" | "billing_city" | "billing_state" | "billing_postal_code" | "billing_country" | "owner_id" | "parent_id"; defineContact: "id" | "account_id" | "first_name" | "last_name" | "name" | "title" | "department" | "email" | "phone" | "mobile_phone" | "linkedin_url" | "mailing_street" | "mailing_city" | "mailing_state" | "mailing_postal_code" | "mailing_country" | "lead_source" | "owner_id" | "description"; defineCustom: "id"; defineScript: "id"; defineDeal: "id" | "name" | "account_id" | "amount" | "stage_name" | "close_date" | "probability" | "type" | "lead_source" | "next_step" | "forecast_category" | "is_closed" | "is_won" | "expected_revenue" | "description" | "owner_id" | "campaign_id"; defineLead: "id" | "first_name" | "last_name" | "name" | "company" | "title" | "email" | "phone" | "mobile_phone" | "website" | "linkedin_url" | "status" | "lead_source" | "industry" | "rating" | "annual_revenue" | "number_of_employees" | "street" | "city" | "state" | "postal_code" | "country" | "description" | "owner_id" | "is_converted" | "converted_date" | "converted_account_id" | "converted_contact_id" | "converted_opportunity_id" | "has_opted_out_of_email" | "do_not_call" | "created_date" | "last_modified_date"; }; export type ModelUnificationColumnSpec = { slug: string; reference: string; }; export type ModelUnificationParentSpec = { kind: "model"; columnSlug: string; parent: ModelHandle | ModelRef; } | { kind: "reference"; columnSlug: string; reference: string; }; export type ModelUnificationSpec = { source: "integration"; } | { source: "custom"; type: StorageTypes.ModelUnificationType; uniqueColumns: ModelUnificationColumnSpec[]; /** Columns exposed on the unified model (defaults to all). */ selectedColumnSlugs?: string[]; /** Column carrying the event timestamp (event unification types only). */ timeColumnSlug?: string; parent?: ModelUnificationParentSpec; /** Restrict which rows take part in unification (defaults to all rows). */ filter?: SegmentationTypes.Filter; }; export type AccountUnificationReference = Extract; export type ContactUnificationReference = Extract; /** * How a reference merges records into the unified model: * - `none` — keep the golden column, never merge on it * - `weak` — corroborates a merge, never causes one on its own * - `strong` — merges records on its own (forms the component backbone) */ export type ModelUnificationConfigReferenceSpec = "none" | "weak" | "strong"; export type ModelUnificationConfigSpec = { [K in R]: ModelUnificationConfigReferenceSpec; }; export type ModelAdditionalColumnSpecBase = { slug: string; type: StorageTypes.ColumnType; /** Display name. Defaults to the title-cased slug. */ label?: string; description?: string; properties?: string[]; }; /** A manually-filled column (values written per record, no formula). */ export type ModelCustomColumnSpec = ModelAdditionalColumnSpecBase & { kind: "custom"; }; /** A formula column evaluated per record. */ export type ModelComputedColumnSpec = ModelAdditionalColumnSpecBase & { kind: "computed"; expression: ExpressionTypes.Expression; columnsUsed?: string[]; }; /** An aggregation over the records a relationship joins to. */ export type ModelMetricColumnSpec = ModelAdditionalColumnSpecBase & { kind: "metric"; relationship: RelationshipHandle | RelationshipRef; aggregation: { function: StorageTypes.AggregationFunction; columnSlug: string; }; filter?: SegmentationTypes.Filter; }; /** A value copied from a matching record of another model. */ export type ModelLookupColumnSpec = ModelAdditionalColumnSpecBase & { kind: "lookup"; join: { model: ModelHandle | ModelRef; fromColumnSlug: string; toColumnSlug: string; }; extractColumnSlug: string; filter?: SegmentationTypes.Filter; }; export type ModelAdditionalColumnSpec = ModelCustomColumnSpec | ModelComputedColumnSpec | ModelMetricColumnSpec | ModelLookupColumnSpec; type AdditionalColumnSlugsOf = AC[number] extends infer C ? C extends ModelAdditionalColumnSpec ? `${C["kind"]}__${C["slug"]}` : never : never; export interface ExtractorConfigs { } type ExtractorConfigFor = S extends "native" ? E extends keyof NativeExtractorConfigs ? NativeExtractorConfigs[E] : Record : S extends keyof ExtractorConfigs ? E extends keyof ExtractorConfigs[S] ? ExtractorConfigs[S][E] : Record : Record; export interface ExtractorSlugs { } type ExtractorSlugFor = S extends "native" ? NativeExtractorSlug : S extends keyof ExtractorSlugs ? ExtractorSlugs[S] & string : string; export interface ModelColumns { } export interface ExtractorColumns { } type ExtractorColumnsFor = S extends "native" ? E extends keyof NativeExtractorColumns ? NativeExtractorColumns[E] : never : S extends keyof ExtractorColumns ? E extends keyof ExtractorColumns[S] ? ExtractorColumns[S][E] & string : never : never; type ModelColumnsAccessor = Slug extends keyof ModelColumns ? { readonly [C in (ModelColumns[Slug] & string) | ACSlugs]: C; } & { readonly [columnSlug: string]: string; } : [ExtractorColumnsFor | ACSlugs] extends [never] ? { readonly [columnSlug: string]: string; } : { readonly [C in ExtractorColumnsFor | ACSlugs]: C; } & { readonly [columnSlug: string]: string; }; type LiteralUnion = T | (string & {}); export type ModelSpec> = LiteralUnion>, AC extends readonly ModelAdditionalColumnSpec[] = readonly ModelAdditionalColumnSpec[]> = { /** A connector model — the default kind; `NativeModelSpec` handles "native". */ kind?: "connector"; name?: string; description?: string; /** * The source connector — a handle, or `connectorRef(uuid)` for one that * isn't defined in code (the deploy engine then resolves its dataset live). */ connector: ConnectorHandle | ConnectorRef; /** * An extractor the source's integration exposes, e.g. "fetchRecords". After * `cargo-ai cdk types`, editors autocomplete the connector's known extractors; * an unsynced/newer slug is still accepted. */ extractSlug: E; /** Extractor config — validated against the extractor's schema on apply. */ config?: ExtractorConfigFor; schedule?: ScheduleSpec; folder?: FolderHandle | FolderRef; /** * How this model participates in unification. Omit to keep the source's * default (a connector model defaults to its integration's mapping). Applied * via an update once the model exists. */ unification?: ModelUnificationSpec; /** * Columns added on top of the extracted schema (custom / computed / metric / * lookup). When declared, the list is authoritative: deploy creates missing * columns, updates changed ones, and removes additional columns no longer * listed. Omit to leave the model's live additional columns untouched. */ additionalColumns?: AC; }; export type NativeModelSpec = LiteralUnion, AC extends readonly ModelAdditionalColumnSpec[] = readonly ModelAdditionalColumnSpec[]> = { /** A model in the workspace's built-in native dataset — no connector. */ kind: "native"; name?: string; description?: string; extractSlug: E; /** * Columns added on top of the extracted schema — same authoritative * reconciliation as a connector model's `additionalColumns`. */ additionalColumns?: AC; } & (E extends NativeUnifyExtractorSlug ? { config?: E extends keyof NativeExtractorConfigs ? NativeExtractorConfigs[E] : Record; schedule?: ScheduleSpec; unification?: never; folder?: never; } : { /** Extractor config — validated against the extractor's schema on apply. */ config?: ExtractorConfigFor<"native", E>; schedule?: ScheduleSpec; folder?: FolderHandle | FolderRef; /** How this model participates in unification (see `ModelSpec`). */ unification?: ModelUnificationSpec; }); export type ModelHandle = { readonly slug: string; readonly uuid: Token; readonly resource: "model"; /** This model's columns — `model.columns.` yields the slug * string, for relationships, unification, and segment column lists. */ readonly columns: ModelColumnsAccessor; }; export declare function defineModel, const AC extends readonly ModelAdditionalColumnSpec[] = readonly []>(slug: Slug, spec: NativeModelSpec): ModelHandle>; export declare function defineModel>, const AC extends readonly ModelAdditionalColumnSpec[] = readonly []>(slug: Slug, spec: ModelSpec): ModelHandle>; export {}; //# sourceMappingURL=model.d.ts.map