// packages/core/src/store/nexus-schema.ts
import { sql as sql2 } from "drizzle-orm";

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/column-common.js
var OriginalColumn = /* @__PURE__ */ Symbol.for("drizzle:OriginalColumn");

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/entity.js
var entityKind = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
function is(value, type) {
  if (!value || typeof value !== "object") return false;
  if (value instanceof type) return true;
  if (!Object.prototype.hasOwnProperty.call(type, entityKind)) throw new Error(`Class "${type.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`);
  let cls = Object.getPrototypeOf(value)?.constructor;
  if (cls) while (cls) {
    if (entityKind in cls && cls[entityKind] === type[entityKind]) return true;
    cls = Object.getPrototypeOf(cls);
  }
  return false;
}

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/column.js
var Column = class {
  static [entityKind] = "Column";
  name;
  keyAsName;
  primary;
  notNull;
  default;
  defaultFn;
  onUpdateFn;
  hasDefault;
  isUnique;
  uniqueName;
  uniqueType;
  dataType;
  columnType;
  enumValues = void 0;
  generated = void 0;
  generatedIdentity = void 0;
  length;
  isLengthExact;
  isAlias;
  /** @internal */
  config;
  /** @internal */
  table;
  /** @internal */
  onInit() {
  }
  constructor(table, config) {
    this.config = config;
    this.onInit();
    this.table = table;
    this.name = config.name;
    this.isAlias = false;
    this.keyAsName = config.keyAsName;
    this.notNull = config.notNull;
    this.default = config.default;
    this.defaultFn = config.defaultFn;
    this.onUpdateFn = config.onUpdateFn;
    this.hasDefault = config.hasDefault;
    this.primary = config.primaryKey;
    this.isUnique = config.isUnique;
    this.uniqueName = config.uniqueName;
    this.uniqueType = config.uniqueType;
    this.dataType = config.dataType;
    this.columnType = config.columnType;
    this.generated = config.generated;
    this.generatedIdentity = config.generatedIdentity;
    this.length = config["length"];
    this.isLengthExact = config["isLengthExact"];
  }
  mapFromDriverValue(value) {
    return value;
  }
  mapToDriverValue(value) {
    return value;
  }
  shouldDisableInsert() {
    return this.config.generated !== void 0 && this.config.generated.type !== "byDefault";
  }
  /** @internal */
  [OriginalColumn]() {
    return this;
  }
};

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/table.utils.js
var TableName = /* @__PURE__ */ Symbol.for("drizzle:Name");

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/table.js
var TableSchema = /* @__PURE__ */ Symbol.for("drizzle:Schema");
var TableColumns = /* @__PURE__ */ Symbol.for("drizzle:Columns");
var ExtraConfigColumns = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigColumns");
var OriginalName = /* @__PURE__ */ Symbol.for("drizzle:OriginalName");
var BaseName = /* @__PURE__ */ Symbol.for("drizzle:BaseName");
var IsAlias = /* @__PURE__ */ Symbol.for("drizzle:IsAlias");
var ExtraConfigBuilder = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigBuilder");
var IsDrizzleTable = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleTable");
var Table = class {
  static [entityKind] = "Table";
  /** @internal */
  static Symbol = {
    Name: TableName,
    Schema: TableSchema,
    OriginalName,
    Columns: TableColumns,
    ExtraConfigColumns,
    BaseName,
    IsAlias,
    ExtraConfigBuilder
  };
  /**
  * @internal
  * Can be changed if the table is aliased.
  */
  [TableName];
  /**
  * @internal
  * Used to store the original name of the table, before any aliasing.
  */
  [OriginalName];
  /** @internal */
  [TableSchema];
  /** @internal */
  [TableColumns];
  /** @internal */
  [ExtraConfigColumns];
  /**
  *  @internal
  * Used to store the table name before the transformation via the `tableCreator` functions.
  */
  [BaseName];
  /** @internal */
  [IsAlias] = false;
  /** @internal */
  [IsDrizzleTable] = true;
  /** @internal */
  [ExtraConfigBuilder] = void 0;
  constructor(name, schema, baseName) {
    this[TableName] = this[OriginalName] = name;
    this[TableSchema] = schema;
    this[BaseName] = baseName;
  }
};

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/subquery.js
var Subquery = class {
  static [entityKind] = "Subquery";
  constructor(sql3, fields, alias, isWith = false, usedTables = []) {
    this._ = {
      brand: "Subquery",
      sql: sql3,
      selectedFields: fields,
      alias,
      isWith,
      usedTables
    };
  }
};
var WithSubquery = class extends Subquery {
  static [entityKind] = "WithSubquery";
};

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/tracing.js
var tracer = { startActiveSpan(name, fn) {
  return fn();
} };

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/view-common.js
var ViewBaseConfig = /* @__PURE__ */ Symbol.for("drizzle:ViewBaseConfig");

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/sql/sql.js
var FakePrimitiveParam = class {
  static [entityKind] = "FakePrimitiveParam";
};
function isSQLWrapper(value) {
  return value !== null && value !== void 0 && typeof value.getSQL === "function";
}
function mergeQueries(queries) {
  const result = {
    sql: "",
    params: []
  };
  for (const query of queries) {
    result.sql += query.sql;
    result.params.push(...query.params);
    if (query.typings?.length) {
      if (!result.typings) result.typings = [];
      result.typings.push(...query.typings);
    }
  }
  return result;
}
var StringChunk = class {
  static [entityKind] = "StringChunk";
  value;
  constructor(value) {
    this.value = Array.isArray(value) ? value : [value];
  }
  getSQL() {
    return new SQL([this]);
  }
};
var SQL = class SQL2 {
  static [entityKind] = "SQL";
  /** @internal */
  decoder = noopDecoder;
  /** @internal */
  shouldInlineParams = false;
  /** @internal */
  usedTables = [];
  constructor(queryChunks) {
    this.queryChunks = queryChunks;
    for (const chunk of queryChunks) if (is(chunk, Table)) {
      const schemaName = chunk[Table.Symbol.Schema];
      this.usedTables.push(schemaName === void 0 ? chunk[Table.Symbol.Name] : schemaName + "." + chunk[Table.Symbol.Name]);
    }
  }
  append(query) {
    this.queryChunks.push(...query.queryChunks);
    return this;
  }
  toQuery(config) {
    return tracer.startActiveSpan("drizzle.buildSQL", (span) => {
      const query = this.buildQueryFromSourceParams(this.queryChunks, config);
      span?.setAttributes({
        "drizzle.query.text": query.sql,
        "drizzle.query.params": JSON.stringify(query.params)
      });
      return query;
    });
  }
  buildQueryFromSourceParams(chunks, _config) {
    const config = Object.assign({}, _config, {
      inlineParams: _config.inlineParams || this.shouldInlineParams,
      paramStartIndex: _config.paramStartIndex || { value: 0 }
    });
    const { casing, escapeName, escapeParam, prepareTyping, inlineParams, paramStartIndex, invokeSource } = config;
    return mergeQueries(chunks.map((chunk) => {
      if (is(chunk, StringChunk)) return {
        sql: chunk.value.join(""),
        params: []
      };
      if (is(chunk, Name)) return {
        sql: escapeName(chunk.value),
        params: []
      };
      if (chunk === void 0) return {
        sql: "",
        params: []
      };
      if (Array.isArray(chunk)) {
        const result = [new StringChunk("(")];
        for (const [i, p] of chunk.entries()) {
          result.push(p);
          if (i < chunk.length - 1) result.push(new StringChunk(", "));
        }
        result.push(new StringChunk(")"));
        return this.buildQueryFromSourceParams(result, config);
      }
      if (is(chunk, SQL2)) return this.buildQueryFromSourceParams(chunk.queryChunks, {
        ...config,
        inlineParams: inlineParams || chunk.shouldInlineParams
      });
      if (is(chunk, Table)) {
        const schemaName = chunk[Table.Symbol.Schema];
        const tableName = chunk[Table.Symbol.Name];
        if (invokeSource === "mssql-view-with-schemabinding") return {
          sql: (schemaName === void 0 ? escapeName("dbo") : escapeName(schemaName)) + "." + escapeName(tableName),
          params: []
        };
        return {
          sql: schemaName === void 0 || chunk[IsAlias] ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
          params: []
        };
      }
      if (is(chunk, Column)) {
        const columnName = casing.getColumnCasing(chunk);
        if (_config.invokeSource === "indexes") return {
          sql: escapeName(columnName),
          params: []
        };
        const schemaName = invokeSource === "mssql-check" ? void 0 : chunk.table[Table.Symbol.Schema];
        return {
          sql: chunk.isAlias ? escapeName(chunk.name) : chunk.table[IsAlias] || schemaName === void 0 ? escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName) : escapeName(schemaName) + "." + escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName),
          params: []
        };
      }
      if (is(chunk, View)) {
        const schemaName = chunk[ViewBaseConfig].schema;
        const viewName = chunk[ViewBaseConfig].name;
        return {
          sql: schemaName === void 0 || chunk[ViewBaseConfig].isAlias ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
          params: []
        };
      }
      if (is(chunk, Param)) {
        if (is(chunk.value, Placeholder)) return {
          sql: escapeParam(paramStartIndex.value++, chunk),
          params: [chunk],
          typings: ["none"]
        };
        const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
        if (is(mappedValue, SQL2)) return this.buildQueryFromSourceParams([mappedValue], config);
        if (inlineParams) return {
          sql: this.mapInlineParam(mappedValue, config),
          params: []
        };
        let typings = ["none"];
        if (prepareTyping) typings = [prepareTyping(chunk.encoder)];
        return {
          sql: escapeParam(paramStartIndex.value++, mappedValue),
          params: [mappedValue],
          typings
        };
      }
      if (is(chunk, Placeholder)) return {
        sql: escapeParam(paramStartIndex.value++, chunk),
        params: [chunk],
        typings: ["none"]
      };
      if (is(chunk, SQL2.Aliased) && chunk.fieldAlias !== void 0) return {
        sql: (chunk.origin !== void 0 ? escapeName(chunk.origin) + "." : "") + escapeName(chunk.fieldAlias),
        params: []
      };
      if (is(chunk, Subquery)) {
        if (chunk._.isWith) return {
          sql: escapeName(chunk._.alias),
          params: []
        };
        return this.buildQueryFromSourceParams([
          new StringChunk("("),
          chunk._.sql,
          new StringChunk(") "),
          new Name(chunk._.alias)
        ], config);
      }
      if (typeof chunk === "function" && "enumName" in chunk) {
        if ("schema" in chunk && chunk.schema) return {
          sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName),
          params: []
        };
        return {
          sql: escapeName(chunk.enumName),
          params: []
        };
      }
      if (isSQLWrapper(chunk)) {
        if (chunk.shouldOmitSQLParens?.()) return this.buildQueryFromSourceParams([chunk.getSQL()], config);
        return this.buildQueryFromSourceParams([
          new StringChunk("("),
          chunk.getSQL(),
          new StringChunk(")")
        ], config);
      }
      if (inlineParams) return {
        sql: this.mapInlineParam(chunk, config),
        params: []
      };
      return {
        sql: escapeParam(paramStartIndex.value++, chunk),
        params: [chunk],
        typings: ["none"]
      };
    }));
  }
  mapInlineParam(chunk, { escapeString }) {
    if (chunk === null) return "null";
    if (typeof chunk === "number" || typeof chunk === "boolean" || typeof chunk === "bigint") return chunk.toString();
    if (typeof chunk === "string") return escapeString(chunk);
    if (typeof chunk === "object") {
      const mappedValueAsString = chunk.toString();
      if (mappedValueAsString === "[object Object]") return escapeString(JSON.stringify(chunk));
      return escapeString(mappedValueAsString);
    }
    throw new Error("Unexpected param value: " + chunk);
  }
  getSQL() {
    return this;
  }
  as(alias) {
    if (alias === void 0) return this;
    return new SQL2.Aliased(this, alias);
  }
  mapWith(decoder) {
    this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
    return this;
  }
  inlineParams() {
    this.shouldInlineParams = true;
    return this;
  }
  /**
  * This method is used to conditionally include a part of the query.
  *
  * @param condition - Condition to check
  * @returns itself if the condition is `true`, otherwise `undefined`
  */
  if(condition) {
    return condition ? this : void 0;
  }
};
var Name = class {
  static [entityKind] = "Name";
  brand;
  constructor(value) {
    this.value = value;
  }
  getSQL() {
    return new SQL([this]);
  }
};
var noopDecoder = { mapFromDriverValue: (value) => value };
var noopEncoder = { mapToDriverValue: (value) => value };
var noopMapper = {
  ...noopDecoder,
  ...noopEncoder
};
var Param = class {
  static [entityKind] = "Param";
  brand;
  /**
  * @param value - Parameter value
  * @param encoder - Encoder to convert the value to a driver parameter
  */
  constructor(value, encoder = noopEncoder) {
    this.value = value;
    this.encoder = encoder;
  }
  getSQL() {
    return new SQL([this]);
  }
};
function sql(strings, ...params) {
  const queryChunks = [];
  if (params.length > 0 || strings.length > 0 && strings[0] !== "") queryChunks.push(new StringChunk(strings[0]));
  for (const [paramIndex, param] of params.entries()) queryChunks.push(param, new StringChunk(strings[paramIndex + 1]));
  return new SQL(queryChunks);
}
(function(_sql) {
  function empty() {
    return new SQL([]);
  }
  _sql.empty = empty;
  function fromList(list) {
    return new SQL(list);
  }
  _sql.fromList = fromList;
  function raw(str) {
    return new SQL([new StringChunk(str)]);
  }
  _sql.raw = raw;
  function join(chunks, separator) {
    const result = [];
    for (const [i, chunk] of chunks.entries()) {
      if (i > 0 && separator !== void 0) result.push(separator);
      result.push(chunk);
    }
    return new SQL(result);
  }
  _sql.join = join;
  function identifier(value) {
    return new Name(value);
  }
  _sql.identifier = identifier;
  function placeholder(name) {
    return new Placeholder(name);
  }
  _sql.placeholder = placeholder;
  function param(value, encoder) {
    return new Param(value, encoder);
  }
  _sql.param = param;
})(sql || (sql = {}));
(function(_SQL) {
  class Aliased {
    static [entityKind] = "SQL.Aliased";
    /** @internal */
    isSelectionField = false;
    /** @internal */
    origin;
    constructor(sql3, fieldAlias) {
      this.sql = sql3;
      this.fieldAlias = fieldAlias;
    }
    getSQL() {
      return this.sql;
    }
    /** @internal */
    clone() {
      return new Aliased(this.sql, this.fieldAlias);
    }
  }
  _SQL.Aliased = Aliased;
})(SQL || (SQL = {}));
var Placeholder = class {
  static [entityKind] = "Placeholder";
  constructor(name) {
    this.name = name;
  }
  getSQL() {
    return new SQL([this]);
  }
};
var IsDrizzleView = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleView");
var View = class {
  static [entityKind] = "View";
  /** @internal */
  [ViewBaseConfig];
  /** @internal */
  [IsDrizzleView] = true;
  /** @internal */
  get [TableName]() {
    return this[ViewBaseConfig].name;
  }
  /** @internal */
  get [TableSchema]() {
    return this[ViewBaseConfig].schema;
  }
  /** @internal */
  get [IsAlias]() {
    return this[ViewBaseConfig].isAlias;
  }
  /** @internal */
  get [OriginalName]() {
    return this[ViewBaseConfig].originalName;
  }
  /** @internal */
  get [TableColumns]() {
    return this[ViewBaseConfig].selectedFields;
  }
  constructor({ name, schema, selectedFields, query }) {
    this[ViewBaseConfig] = {
      name,
      originalName: name,
      schema,
      selectedFields,
      query,
      isExisting: !query,
      isAlias: false
    };
  }
};
Column.prototype.getSQL = function() {
  return new SQL([this]);
};
Subquery.prototype.getSQL = function() {
  return new SQL([this]);
};

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/column-builder.js
var ColumnBuilder = class {
  static [entityKind] = "ColumnBuilder";
  /** @internal */
  config;
  constructor(name, dataType, columnType) {
    this.config = {
      name,
      keyAsName: name === "",
      notNull: false,
      default: void 0,
      hasDefault: false,
      primaryKey: false,
      isUnique: false,
      uniqueName: void 0,
      uniqueType: void 0,
      dataType,
      columnType,
      generated: void 0
    };
  }
  /**
  * Changes the data type of the column. Commonly used with `json` columns. Also, useful for branded types.
  *
  * @example
  * ```ts
  * const users = pgTable('users', {
  * 	id: integer('id').$type<UserId>().primaryKey(),
  * 	details: json('details').$type<UserDetails>().notNull(),
  * });
  * ```
  */
  $type() {
    return this;
  }
  /**
  * Adds a `not null` clause to the column definition.
  *
  * Affects the `select` model of the table - columns *without* `not null` will be nullable on select.
  */
  notNull() {
    this.config.notNull = true;
    return this;
  }
  /**
  * Adds a `default <value>` clause to the column definition.
  *
  * Affects the `insert` model of the table - columns *with* `default` are optional on insert.
  *
  * If you need to set a dynamic default value, use {@link $defaultFn} instead.
  */
  default(value) {
    this.config.default = value;
    this.config.hasDefault = true;
    return this;
  }
  /**
  * Adds a dynamic default value to the column.
  * The function will be called when the row is inserted, and the returned value will be used as the column value.
  *
  * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
  */
  $defaultFn(fn) {
    this.config.defaultFn = fn;
    this.config.hasDefault = true;
    return this;
  }
  /**
  * Alias for {@link $defaultFn}.
  */
  $default = this.$defaultFn;
  /**
  * Adds a dynamic update value to the column.
  * The function will be called when the row is updated, and the returned value will be used as the column value if none is provided.
  * If no `default` (or `$defaultFn`) value is provided, the function will be called when the row is inserted as well, and the returned value will be used as the column value.
  *
  * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
  */
  $onUpdateFn(fn) {
    this.config.onUpdateFn = fn;
    this.config.hasDefault = true;
    return this;
  }
  /**
  * Alias for {@link $onUpdateFn}.
  */
  $onUpdate = this.$onUpdateFn;
  /**
  * Adds a `primary key` clause to the column definition. This implicitly makes the column `not null`.
  *
  * In SQLite, `integer primary key` implicitly makes the column auto-incrementing.
  */
  primaryKey() {
    this.config.primaryKey = true;
    this.config.notNull = true;
    return this;
  }
  /** @internal Sets the name of the column to the key within the table definition if a name was not given. */
  setName(name) {
    if (this.config.name !== "") return;
    this.config.name = name;
  }
};

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/sqlite-core/foreign-keys.js
var ForeignKeyBuilder = class {
  static [entityKind] = "SQLiteForeignKeyBuilder";
  /** @internal */
  reference;
  /** @internal */
  _onUpdate;
  /** @internal */
  _onDelete;
  constructor(config, actions) {
    this.reference = () => {
      const { name, columns, foreignColumns } = config();
      return {
        name,
        columns,
        foreignTable: foreignColumns[0].table,
        foreignColumns
      };
    };
    if (actions) {
      this._onUpdate = actions.onUpdate;
      this._onDelete = actions.onDelete;
    }
  }
  onUpdate(action) {
    this._onUpdate = action;
    return this;
  }
  onDelete(action) {
    this._onDelete = action;
    return this;
  }
  /** @internal */
  build(table) {
    return new ForeignKey(table, this);
  }
};
var ForeignKey = class {
  static [entityKind] = "SQLiteForeignKey";
  reference;
  onUpdate;
  onDelete;
  constructor(table, builder) {
    this.table = table;
    this.reference = builder.reference;
    this.onUpdate = builder._onUpdate;
    this.onDelete = builder._onDelete;
  }
  getName() {
    const { name, columns, foreignColumns } = this.reference();
    const columnNames = columns.map((column) => column.name);
    const foreignColumnNames = foreignColumns.map((column) => column.name);
    const chunks = [
      this.table[TableName],
      ...columnNames,
      foreignColumns[0].table[TableName],
      ...foreignColumnNames
    ];
    return name ?? `${chunks.join("_")}_fk`;
  }
  isNameExplicit() {
    return !!this.reference().name;
  }
};

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/sqlite-core/columns/common.js
var SQLiteColumnBuilder = class extends ColumnBuilder {
  static [entityKind] = "SQLiteColumnBuilder";
  foreignKeyConfigs = [];
  references(ref, actions = {}) {
    this.foreignKeyConfigs.push({
      ref,
      actions
    });
    return this;
  }
  unique(name) {
    this.config.isUnique = true;
    this.config.uniqueName = name;
    return this;
  }
  generatedAlwaysAs(as, config) {
    this.config.generated = {
      as,
      type: "always",
      mode: config?.mode ?? "virtual"
    };
    return this;
  }
  /** @internal */
  buildForeignKeys(column, table) {
    return this.foreignKeyConfigs.map(({ ref, actions }) => {
      return ((ref2, actions2) => {
        const builder = new ForeignKeyBuilder(() => {
          const foreignColumn = ref2();
          return {
            columns: [column],
            foreignColumns: [foreignColumn]
          };
        });
        if (actions2.onUpdate) builder.onUpdate(actions2.onUpdate);
        if (actions2.onDelete) builder.onDelete(actions2.onDelete);
        return builder.build(table);
      })(ref, actions);
    });
  }
};
var SQLiteColumn = class extends Column {
  static [entityKind] = "SQLiteColumn";
  /** @internal */
  table;
  constructor(table, config) {
    super(table, config);
    this.table = table;
  }
};

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/utils.js
function getColumnNameAndConfig(a, b) {
  return {
    name: typeof a === "string" && a.length > 0 ? a : "",
    config: typeof a === "object" ? a : b
  };
}
var textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder();

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/sqlite-core/columns/blob.js
function hexToText(hexString) {
  let result = "";
  for (let i = 0; i < hexString.length; i += 2) {
    const hexPair = hexString.slice(i, i + 2);
    const decimalValue = Number.parseInt(hexPair, 16);
    result += String.fromCodePoint(decimalValue);
  }
  return result;
}
var SQLiteBigIntBuilder = class extends SQLiteColumnBuilder {
  static [entityKind] = "SQLiteBigIntBuilder";
  constructor(name) {
    super(name, "bigint int64", "SQLiteBigInt");
  }
  /** @internal */
  build(table) {
    return new SQLiteBigInt(table, this.config);
  }
};
var SQLiteBigInt = class extends SQLiteColumn {
  static [entityKind] = "SQLiteBigInt";
  getSQLType() {
    return "blob";
  }
  mapFromDriverValue(value) {
    if (typeof value === "string") return BigInt(hexToText(value));
    if (typeof Buffer !== "undefined" && Buffer.from) {
      const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
      return BigInt(buf.toString("utf8"));
    }
    return BigInt(textDecoder.decode(value));
  }
  mapToDriverValue(value) {
    return Buffer.from(value.toString());
  }
};
var SQLiteBlobJsonBuilder = class extends SQLiteColumnBuilder {
  static [entityKind] = "SQLiteBlobJsonBuilder";
  constructor(name) {
    super(name, "object json", "SQLiteBlobJson");
  }
  /** @internal */
  build(table) {
    return new SQLiteBlobJson(table, this.config);
  }
};
var SQLiteBlobJson = class extends SQLiteColumn {
  static [entityKind] = "SQLiteBlobJson";
  getSQLType() {
    return "blob";
  }
  mapFromDriverValue(value) {
    if (typeof value === "string") return JSON.parse(hexToText(value));
    if (typeof Buffer !== "undefined" && Buffer.from) {
      const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
      return JSON.parse(buf.toString("utf8"));
    }
    return JSON.parse(textDecoder.decode(value));
  }
  mapToDriverValue(value) {
    return Buffer.from(JSON.stringify(value));
  }
};
var SQLiteBlobBufferBuilder = class extends SQLiteColumnBuilder {
  static [entityKind] = "SQLiteBlobBufferBuilder";
  constructor(name) {
    super(name, "object buffer", "SQLiteBlobBuffer");
  }
  /** @internal */
  build(table) {
    return new SQLiteBlobBuffer(table, this.config);
  }
};
var SQLiteBlobBuffer = class extends SQLiteColumn {
  static [entityKind] = "SQLiteBlobBuffer";
  mapFromDriverValue(value) {
    if (Buffer.isBuffer(value)) return value;
    if (typeof value === "string") return Buffer.from(value, "hex");
    return Buffer.from(value);
  }
  getSQLType() {
    return "blob";
  }
};
function blob(a, b) {
  const { name, config } = getColumnNameAndConfig(a, b);
  if (config?.mode === "json") return new SQLiteBlobJsonBuilder(name);
  if (config?.mode === "bigint") return new SQLiteBigIntBuilder(name);
  return new SQLiteBlobBufferBuilder(name);
}

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/sqlite-core/columns/custom.js
var SQLiteCustomColumnBuilder = class extends SQLiteColumnBuilder {
  static [entityKind] = "SQLiteCustomColumnBuilder";
  constructor(name, fieldConfig, customTypeParams) {
    super(name, "custom", "SQLiteCustomColumn");
    this.config.fieldConfig = fieldConfig;
    this.config.customTypeParams = customTypeParams;
  }
  /** @internal */
  build(table) {
    return new SQLiteCustomColumn(table, this.config);
  }
};
var SQLiteCustomColumn = class extends SQLiteColumn {
  static [entityKind] = "SQLiteCustomColumn";
  sqlName;
  mapTo;
  mapFrom;
  mapJson;
  forJsonSelect;
  constructor(table, config) {
    super(table, config);
    this.sqlName = config.customTypeParams.dataType(config.fieldConfig);
    this.mapTo = config.customTypeParams.toDriver;
    this.mapFrom = config.customTypeParams.fromDriver;
    this.mapJson = config.customTypeParams.fromJson;
    this.forJsonSelect = config.customTypeParams.forJsonSelect;
  }
  getSQLType() {
    return this.sqlName;
  }
  mapFromDriverValue(value) {
    return typeof this.mapFrom === "function" ? this.mapFrom(value) : value;
  }
  mapFromJsonValue(value) {
    return typeof this.mapJson === "function" ? this.mapJson(value) : this.mapFromDriverValue(value);
  }
  jsonSelectIdentifier(identifier, sql3) {
    if (typeof this.forJsonSelect === "function") return this.forJsonSelect(identifier, sql3);
    const rawType = this.getSQLType().toLowerCase();
    const parenPos = rawType.indexOf("(");
    switch (parenPos + 1 ? rawType.slice(0, parenPos) : rawType) {
      case "numeric":
      case "decimal":
      case "bigint":
        return sql3`cast(${identifier} as text)`;
      case "blob":
        return sql3`hex(${identifier})`;
      default:
        return identifier;
    }
  }
  mapToDriverValue(value) {
    return typeof this.mapTo === "function" ? this.mapTo(value) : value;
  }
};
function customType(customTypeParams) {
  return (a, b) => {
    const { name, config } = getColumnNameAndConfig(a, b);
    return new SQLiteCustomColumnBuilder(name, config, customTypeParams);
  };
}

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/sqlite-core/columns/integer.js
var SQLiteBaseIntegerBuilder = class extends SQLiteColumnBuilder {
  static [entityKind] = "SQLiteBaseIntegerBuilder";
  constructor(name, dataType, columnType) {
    super(name, dataType, columnType);
    this.config.autoIncrement = false;
  }
  primaryKey(config) {
    if (config?.autoIncrement) this.config.autoIncrement = true;
    this.config.hasDefault = true;
    return super.primaryKey();
  }
};
var SQLiteBaseInteger = class extends SQLiteColumn {
  static [entityKind] = "SQLiteBaseInteger";
  autoIncrement = this.config.autoIncrement;
  getSQLType() {
    return "integer";
  }
};
var SQLiteIntegerBuilder = class extends SQLiteBaseIntegerBuilder {
  static [entityKind] = "SQLiteIntegerBuilder";
  constructor(name) {
    super(name, "number int53", "SQLiteInteger");
  }
  build(table) {
    return new SQLiteInteger(table, this.config);
  }
};
var SQLiteInteger = class extends SQLiteBaseInteger {
  static [entityKind] = "SQLiteInteger";
};
var SQLiteTimestampBuilder = class extends SQLiteBaseIntegerBuilder {
  static [entityKind] = "SQLiteTimestampBuilder";
  constructor(name, mode) {
    super(name, "object date", "SQLiteTimestamp");
    this.config.mode = mode;
  }
  /**
  * @deprecated Use `default()` with your own expression instead.
  *
  * Adds `DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer))` to the column, which is the current epoch timestamp in milliseconds.
  */
  defaultNow() {
    return this.default(sql`(cast((julianday('now') - 2440587.5)*86400000 as integer))`);
  }
  build(table) {
    return new SQLiteTimestamp(table, this.config);
  }
};
var SQLiteTimestamp = class extends SQLiteBaseInteger {
  static [entityKind] = "SQLiteTimestamp";
  mode = this.config.mode;
  mapFromDriverValue(value) {
    if (typeof value === "string") return new Date(value.replaceAll('"', ""));
    if (this.config.mode === "timestamp") return /* @__PURE__ */ new Date(value * 1e3);
    return new Date(value);
  }
  mapToDriverValue(value) {
    if (typeof value === "number") return value;
    const unix = value.getTime();
    if (this.config.mode === "timestamp") return Math.floor(unix / 1e3);
    return unix;
  }
};
var SQLiteBooleanBuilder = class extends SQLiteBaseIntegerBuilder {
  static [entityKind] = "SQLiteBooleanBuilder";
  constructor(name, mode) {
    super(name, "boolean", "SQLiteBoolean");
    this.config.mode = mode;
  }
  build(table) {
    return new SQLiteBoolean(table, this.config);
  }
};
var SQLiteBoolean = class extends SQLiteBaseInteger {
  static [entityKind] = "SQLiteBoolean";
  mode = this.config.mode;
  mapFromDriverValue(value) {
    return Number(value) === 1;
  }
  mapToDriverValue(value) {
    return value ? 1 : 0;
  }
};
function integer(a, b) {
  const { name, config } = getColumnNameAndConfig(a, b);
  if (config?.mode === "timestamp" || config?.mode === "timestamp_ms") return new SQLiteTimestampBuilder(name, config.mode);
  if (config?.mode === "boolean") return new SQLiteBooleanBuilder(name, config.mode);
  return new SQLiteIntegerBuilder(name);
}

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/sqlite-core/columns/numeric.js
var SQLiteNumericBuilder = class extends SQLiteColumnBuilder {
  static [entityKind] = "SQLiteNumericBuilder";
  constructor(name) {
    super(name, "string numeric", "SQLiteNumeric");
  }
  /** @internal */
  build(table) {
    return new SQLiteNumeric(table, this.config);
  }
};
var SQLiteNumeric = class extends SQLiteColumn {
  static [entityKind] = "SQLiteNumeric";
  mapFromDriverValue(value) {
    if (typeof value === "string") return value;
    return String(value);
  }
  getSQLType() {
    return "numeric";
  }
};
var SQLiteNumericNumberBuilder = class extends SQLiteColumnBuilder {
  static [entityKind] = "SQLiteNumericNumberBuilder";
  constructor(name) {
    super(name, "number", "SQLiteNumericNumber");
  }
  /** @internal */
  build(table) {
    return new SQLiteNumericNumber(table, this.config);
  }
};
var SQLiteNumericNumber = class extends SQLiteColumn {
  static [entityKind] = "SQLiteNumericNumber";
  mapFromDriverValue(value) {
    if (typeof value === "number") return value;
    return Number(value);
  }
  mapToDriverValue = String;
  getSQLType() {
    return "numeric";
  }
};
var SQLiteNumericBigIntBuilder = class extends SQLiteColumnBuilder {
  static [entityKind] = "SQLiteNumericBigIntBuilder";
  constructor(name) {
    super(name, "bigint int64", "SQLiteNumericBigInt");
  }
  /** @internal */
  build(table) {
    return new SQLiteNumericBigInt(table, this.config);
  }
};
var SQLiteNumericBigInt = class extends SQLiteColumn {
  static [entityKind] = "SQLiteNumericBigInt";
  mapFromDriverValue = BigInt;
  mapToDriverValue = String;
  getSQLType() {
    return "numeric";
  }
};
function numeric(a, b) {
  const { name, config } = getColumnNameAndConfig(a, b);
  const mode = config?.mode;
  return mode === "number" ? new SQLiteNumericNumberBuilder(name) : mode === "bigint" ? new SQLiteNumericBigIntBuilder(name) : new SQLiteNumericBuilder(name);
}

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/sqlite-core/columns/real.js
var SQLiteRealBuilder = class extends SQLiteColumnBuilder {
  static [entityKind] = "SQLiteRealBuilder";
  constructor(name) {
    super(name, "number double", "SQLiteReal");
  }
  /** @internal */
  build(table) {
    return new SQLiteReal(table, this.config);
  }
};
var SQLiteReal = class extends SQLiteColumn {
  static [entityKind] = "SQLiteReal";
  getSQLType() {
    return "real";
  }
};
function real(name) {
  return new SQLiteRealBuilder(name ?? "");
}

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/sqlite-core/columns/text.js
var SQLiteTextBuilder = class extends SQLiteColumnBuilder {
  static [entityKind] = "SQLiteTextBuilder";
  constructor(name, config) {
    super(name, config.enum?.length ? "string enum" : "string", "SQLiteText");
    this.config.enumValues = config.enum;
    this.config.length = config.length;
  }
  /** @internal */
  build(table) {
    return new SQLiteText(table, this.config);
  }
};
var SQLiteText = class extends SQLiteColumn {
  static [entityKind] = "SQLiteText";
  enumValues = this.config.enumValues;
  constructor(table, config) {
    super(table, config);
  }
  getSQLType() {
    return `text${this.config.length ? `(${this.config.length})` : ""}`;
  }
};
var SQLiteTextJsonBuilder = class extends SQLiteColumnBuilder {
  static [entityKind] = "SQLiteTextJsonBuilder";
  constructor(name) {
    super(name, "object json", "SQLiteTextJson");
  }
  /** @internal */
  build(table) {
    return new SQLiteTextJson(table, this.config);
  }
};
var SQLiteTextJson = class extends SQLiteColumn {
  static [entityKind] = "SQLiteTextJson";
  getSQLType() {
    return "text";
  }
  mapFromDriverValue(value) {
    return JSON.parse(value);
  }
  mapToDriverValue(value) {
    return JSON.stringify(value);
  }
};
function text(a, b = {}) {
  const { name, config } = getColumnNameAndConfig(a, b);
  if (config.mode === "json") return new SQLiteTextJsonBuilder(name);
  return new SQLiteTextBuilder(name, config);
}

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/sqlite-core/indexes.js
var IndexBuilderOn = class {
  static [entityKind] = "SQLiteIndexBuilderOn";
  constructor(name, unique) {
    this.name = name;
    this.unique = unique;
  }
  on(...columns) {
    return new IndexBuilder(this.name, columns, this.unique);
  }
};
var IndexBuilder = class {
  static [entityKind] = "SQLiteIndexBuilder";
  /** @internal */
  config;
  constructor(name, columns, unique) {
    this.config = {
      name,
      columns,
      unique,
      where: void 0
    };
  }
  /**
  * Condition for partial index.
  */
  where(condition) {
    this.config.where = condition;
    return this;
  }
  /** @internal */
  build(table) {
    return new Index(this.config, table);
  }
};
var Index = class {
  static [entityKind] = "SQLiteIndex";
  config;
  isNameExplicit;
  constructor(config, table) {
    this.config = {
      ...config,
      table
    };
    this.isNameExplicit = !!config.name;
  }
};
function index(name) {
  return new IndexBuilderOn(name, false);
}

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/sqlite-core/columns/all.js
function getSQLiteColumnBuilders() {
  return {
    blob,
    customType,
    integer,
    numeric,
    real,
    text
  };
}

// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@opentelemetry+api@1.9.0_@sinclair+typebox@0.34.49_@t_75c43c98b1753f6d01776e7d65b99902/node_modules/drizzle-orm/sqlite-core/table.js
var InlineForeignKeys = /* @__PURE__ */ Symbol.for("drizzle:SQLiteInlineForeignKeys");
var SQLiteTable = class extends Table {
  static [entityKind] = "SQLiteTable";
  /** @internal */
  static Symbol = Object.assign({}, Table.Symbol, { InlineForeignKeys });
  /** @internal */
  [Table.Symbol.Columns];
  /** @internal */
  [InlineForeignKeys] = [];
  /** @internal */
  [Table.Symbol.ExtraConfigBuilder] = void 0;
};
function sqliteTableBase(name, columns, extraConfig, schema, baseName = name) {
  const rawTable = new SQLiteTable(name, schema, baseName);
  const parsedColumns = typeof columns === "function" ? columns(getSQLiteColumnBuilders()) : columns;
  const builtColumns = Object.fromEntries(Object.entries(parsedColumns).map(([name2, colBuilderBase]) => {
    const colBuilder = colBuilderBase;
    colBuilder.setName(name2);
    const column = colBuilder.build(rawTable);
    rawTable[InlineForeignKeys].push(...colBuilder.buildForeignKeys(column, rawTable));
    return [name2, column];
  }));
  const table = Object.assign(rawTable, builtColumns);
  table[Table.Symbol.Columns] = builtColumns;
  table[Table.Symbol.ExtraConfigColumns] = builtColumns;
  if (extraConfig) table[SQLiteTable.Symbol.ExtraConfigBuilder] = extraConfig;
  return table;
}
var sqliteTable = (name, columns, extraConfig) => {
  return sqliteTableBase(name, columns, extraConfig);
};

// packages/core/src/store/nexus-schema.ts
var projectRegistry = sqliteTable(
  "project_registry",
  {
    projectId: text("project_id").primaryKey(),
    projectHash: text("project_hash").notNull().unique(),
    projectPath: text("project_path").notNull().unique(),
    name: text("name").notNull(),
    registeredAt: text("registered_at").notNull().default(sql2`(datetime('now'))`),
    lastSeen: text("last_seen").notNull().default(sql2`(datetime('now'))`),
    healthStatus: text("health_status").notNull().default("unknown"),
    healthLastCheck: text("health_last_check"),
    permissions: text("permissions").notNull().default("read"),
    lastSync: text("last_sync").notNull().default(sql2`(datetime('now'))`),
    taskCount: integer("task_count").notNull().default(0),
    labelsJson: text("labels_json").notNull().default("[]"),
    /** Absolute path to the project's brain.db file. */
    brainDbPath: text("brain_db_path"),
    /** Absolute path to the project's tasks.db file. */
    tasksDbPath: text("tasks_db_path"),
    /** ISO 8601 timestamp of the last successful code intelligence index run. */
    lastIndexed: text("last_indexed"),
    /** JSON object with per-project code intelligence stats (node_count, relation_count, file_count). */
    statsJson: text("stats_json").notNull().default("{}")
  },
  (table) => [
    index("idx_project_registry_hash").on(table.projectHash),
    index("idx_project_registry_health").on(table.healthStatus),
    index("idx_project_registry_name").on(table.name),
    index("idx_project_registry_last_indexed").on(table.lastIndexed)
  ]
);
var nexusAuditLog = sqliteTable(
  "nexus_audit_log",
  {
    id: text("id").primaryKey(),
    timestamp: text("timestamp").notNull().default(sql2`(datetime('now'))`),
    action: text("action").notNull(),
    projectHash: text("project_hash"),
    projectId: text("project_id"),
    domain: text("domain"),
    operation: text("operation"),
    sessionId: text("session_id"),
    requestId: text("request_id"),
    source: text("source"),
    gateway: text("gateway"),
    success: integer("success"),
    durationMs: integer("duration_ms"),
    detailsJson: text("details_json").default("{}"),
    errorMessage: text("error_message")
  },
  (table) => [
    index("idx_nexus_audit_timestamp").on(table.timestamp),
    index("idx_nexus_audit_action").on(table.action),
    index("idx_nexus_audit_project_hash").on(table.projectHash),
    index("idx_nexus_audit_project_id").on(table.projectId),
    index("idx_nexus_audit_session").on(table.sessionId)
  ]
);
var nexusSchemaMeta = sqliteTable("nexus_schema_meta", {
  key: text("key").primaryKey(),
  value: text("value").notNull()
});
var NEXUS_NODE_KINDS = [
  // Structural
  "file",
  "folder",
  // Module-level
  "module",
  "namespace",
  // Callable
  "function",
  "method",
  "constructor",
  // Type hierarchy
  "class",
  "interface",
  "struct",
  "trait",
  "impl",
  "type_alias",
  "enum",
  // Value-level
  "property",
  "constant",
  "variable",
  "static",
  "record",
  "delegate",
  // Language-specific constructs
  "macro",
  "union",
  "typedef",
  "annotation",
  "template",
  // Graph-level (synthetic nodes from analysis phases)
  "community",
  "process",
  "route",
  // External references
  "tool",
  "section",
  // Legacy (kept for T506 compatibility)
  "import",
  "export",
  "type"
];
var nexusNodes = sqliteTable(
  "nexus_nodes",
  {
    /** Stable node ID. Format: `<filePath>::<name>` for symbols,
     *  `<filePath>` for file nodes, `community:<n>` for community nodes,
     *  `process:<slug>` for execution flow nodes. */
    id: text("id").primaryKey(),
    /** Foreign key to project_registry.project_id. Scopes the node. */
    projectId: text("project_id").notNull(),
    /** Node kind from GraphNodeKind union. */
    kind: text("kind", { enum: NEXUS_NODE_KINDS }).notNull(),
    /** Human-readable label for display. For symbols, same as name.
     *  For communities, the inferred folder label. For processes, the
     *  entry point function name. */
    label: text("label").notNull(),
    /** Symbol name as it appears in source code. Null for file/folder nodes. */
    name: text("name"),
    /** File path relative to project root. Null for community/process nodes. */
    filePath: text("file_path"),
    /** Start line in source file (1-based). Null for structural nodes. */
    startLine: integer("start_line"),
    /** End line in source file (1-based). Null for structural nodes. */
    endLine: integer("end_line"),
    /** Source language (typescript, python, go, rust, etc.). */
    language: text("language"),
    /** Whether the symbol is publicly exported from its module. */
    isExported: integer("is_exported", { mode: "boolean" }).notNull().default(false),
    /** Parent node ID for nested symbols (e.g., method inside class).
     *  References nexus_nodes.id in the same project. Soft FK. */
    parentId: text("parent_id"),
    /** JSON array of parameter name strings for functions/methods.
     *  Stored as `["param1","param2"]`. Null if not applicable. */
    parametersJson: text("parameters_json"),
    /** Return type annotation text (e.g., "Promise<void>"). */
    returnType: text("return_type"),
    /** First line of the TSDoc/JSDoc comment for this symbol. */
    docSummary: text("doc_summary"),
    /** Community membership ID — references the community node's id.
     *  Set during Phase 4.5 community detection. Null until then. */
    communityId: text("community_id"),
    /** JSON blob for kind-specific metadata.
     *  For `process` nodes: `{"stepCount": 7, "entryScore": 0.92}`.
     *  For `community` nodes: `{"memberCount": 14, "topFolders": ["src/core"]}`.
     *  For `route` nodes: `{"method": "GET", "path": "/api/v1/tasks"}`.
     *  For all others: null. */
    metaJson: text("meta_json"),
    /** ISO 8601 timestamp when this node was last indexed. */
    indexedAt: text("indexed_at").notNull().default(sql2`(datetime('now'))`)
  },
  (table) => [
    index("idx_nexus_nodes_project").on(table.projectId),
    index("idx_nexus_nodes_kind").on(table.kind),
    index("idx_nexus_nodes_file").on(table.filePath),
    index("idx_nexus_nodes_name").on(table.name),
    index("idx_nexus_nodes_project_kind").on(table.projectId, table.kind),
    index("idx_nexus_nodes_project_file").on(table.projectId, table.filePath),
    index("idx_nexus_nodes_community").on(table.communityId),
    index("idx_nexus_nodes_parent").on(table.parentId),
    index("idx_nexus_nodes_exported").on(table.isExported)
  ]
);
var NEXUS_RELATION_TYPES = [
  // Structural
  "contains",
  // Definition / usage
  "defines",
  "imports",
  "accesses",
  // Callable
  "calls",
  // Type hierarchy
  "extends",
  "implements",
  "method_overrides",
  "method_implements",
  // Class structure
  "has_method",
  "has_property",
  // Graph-level (synthetic, from analysis phases)
  "member_of",
  // symbol → community
  "step_in_process",
  // symbol → process
  // Web / API
  "handles_route",
  // function → route node
  "fetches",
  // function → external API
  // Tool / agent
  "handles_tool",
  "entry_point_of",
  // function → process
  // Wrapping / delegation
  "wraps",
  // Data access
  "queries",
  // Cross-graph (brain link)
  "documents",
  // brain_page_node → nexus_nodes
  "applies_to"
  // brain_page_node → nexus_nodes
];
var nexusRelations = sqliteTable(
  "nexus_relations",
  {
    /** UUID v4 row identifier. */
    id: text("id").primaryKey(),
    /** Foreign key to project_registry.project_id. */
    projectId: text("project_id").notNull(),
    /** Source node ID (nexus_nodes.id). */
    sourceId: text("source_id").notNull(),
    /** Target node ID (nexus_nodes.id) or raw module specifier for
     *  unresolved imports. Example: `@cleocode/contracts` or
     *  `src/core/parser.ts::parseFile`. */
    targetId: text("target_id").notNull(),
    /** Semantic relation type. */
    type: text("type", { enum: NEXUS_RELATION_TYPES }).notNull(),
    /** Extractor confidence (0.0 to 1.0). */
    confidence: real("confidence").notNull(),
    /** Human-readable note explaining why this relation was emitted. */
    reason: text("reason"),
    /** Step index within an execution flow (for step_in_process relations). */
    step: integer("step"),
    /** ISO 8601 timestamp when this relation was last indexed. */
    indexedAt: text("indexed_at").notNull().default(sql2`(datetime('now'))`)
  },
  (table) => [
    index("idx_nexus_relations_project").on(table.projectId),
    index("idx_nexus_relations_source").on(table.sourceId),
    index("idx_nexus_relations_target").on(table.targetId),
    index("idx_nexus_relations_type").on(table.type),
    index("idx_nexus_relations_project_type").on(table.projectId, table.type),
    index("idx_nexus_relations_source_type").on(table.sourceId, table.type),
    index("idx_nexus_relations_target_type").on(table.targetId, table.type),
    index("idx_nexus_relations_confidence").on(table.confidence)
  ]
);
export {
  NEXUS_NODE_KINDS,
  NEXUS_RELATION_TYPES,
  nexusAuditLog,
  nexusNodes,
  nexusRelations,
  nexusSchemaMeta,
  projectRegistry
};
//# sourceMappingURL=nexus-schema.js.map
