CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
selection-proxy.cjs100 linesDownload Raw Back to drizzle-orm
1"use strict";2var __defProp = Object.defineProperty;3var __getOwnPropDesc = Object.getOwnPropertyDescriptor;4var __getOwnPropNames = Object.getOwnPropertyNames;5var __hasOwnProp = Object.prototype.hasOwnProperty;6var __export = (target, all) => {7  for (var name in all)8    __defProp(target, name, { get: all[name], enumerable: true });9};10var __copyProps = (to, from, except, desc) => {11  if (from && typeof from === "object" || typeof from === "function") {12    for (let key of __getOwnPropNames(from))13      if (!__hasOwnProp.call(to, key) && key !== except)14        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });15  }16  return to;17};18var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);19var selection_proxy_exports = {};20__export(selection_proxy_exports, {21  SelectionProxyHandler: () => SelectionProxyHandler22});23module.exports = __toCommonJS(selection_proxy_exports);24var import_alias = require("./alias.cjs");25var import_column = require("./column.cjs");26var import_entity = require("./entity.cjs");27var import_sql = require("./sql/sql.cjs");28var import_subquery = require("./subquery.cjs");29var import_view_common = require("./view-common.cjs");30class SelectionProxyHandler {31  static [import_entity.entityKind] = "SelectionProxyHandler";32  config;33  constructor(config) {34    this.config = { ...config };35  }36  get(subquery, prop) {37    if (prop === "_") {38      return {39        ...subquery["_"],40        selectedFields: new Proxy(41          subquery._.selectedFields,42          this43        )44      };45    }46    if (prop === import_view_common.ViewBaseConfig) {47      return {48        ...subquery[import_view_common.ViewBaseConfig],49        selectedFields: new Proxy(50          subquery[import_view_common.ViewBaseConfig].selectedFields,51          this52        )53      };54    }55    if (typeof prop === "symbol") {56      return subquery[prop];57    }58    const columns = (0, import_entity.is)(subquery, import_subquery.Subquery) ? subquery._.selectedFields : (0, import_entity.is)(subquery, import_sql.View) ? subquery[import_view_common.ViewBaseConfig].selectedFields : subquery;59    const value = columns[prop];60    if ((0, import_entity.is)(value, import_sql.SQL.Aliased)) {61      if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) {62        return value.sql;63      }64      const newValue = value.clone();65      newValue.isSelectionField = true;66      return newValue;67    }68    if ((0, import_entity.is)(value, import_sql.SQL)) {69      if (this.config.sqlBehavior === "sql") {70        return value;71      }72      throw new Error(73        `You tried to reference "${prop}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`74      );75    }76    if ((0, import_entity.is)(value, import_column.Column)) {77      if (this.config.alias) {78        return new Proxy(79          value,80          new import_alias.ColumnAliasProxyHandler(81            new Proxy(82              value.table,83              new import_alias.TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false)84            )85          )86        );87      }88      return value;89    }90    if (typeof value !== "object" || value === null) {91      return value;92    }93    return new Proxy(value, new SelectionProxyHandler(this.config));94  }95}96// Annotate the CommonJS export names for ESM import in node:970 && (module.exports = {98  SelectionProxyHandler99});100//# sourceMappingURL=selection-proxy.cjs.map