AK-21/Graphite-Industrial-Intelligence
0
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 casing_exports = {};20__export(casing_exports, {21 CasingCache: () => CasingCache,22 toCamelCase: () => toCamelCase,23 toSnakeCase: () => toSnakeCase24});25module.exports = __toCommonJS(casing_exports);26var import_entity = require("./entity.cjs");27var import_table = require("./table.cjs");28function toSnakeCase(input) {29 const words = input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? [];30 return words.map((word) => word.toLowerCase()).join("_");31}32function toCamelCase(input) {33 const words = input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? [];34 return words.reduce((acc, word, i) => {35 const formattedWord = i === 0 ? word.toLowerCase() : `${word[0].toUpperCase()}${word.slice(1)}`;36 return acc + formattedWord;37 }, "");38}39function noopCase(input) {40 return input;41}42class CasingCache {43 static [import_entity.entityKind] = "CasingCache";44 /** @internal */45 cache = {};46 cachedTables = {};47 convert;48 constructor(casing) {49 this.convert = casing === "snake_case" ? toSnakeCase : casing === "camelCase" ? toCamelCase : noopCase;50 }51 getColumnCasing(column) {52 if (!column.keyAsName) return column.name;53 const schema = column.table[import_table.Table.Symbol.Schema] ?? "public";54 const tableName = column.table[import_table.Table.Symbol.OriginalName];55 const key = `${schema}.${tableName}.${column.name}`;56 if (!this.cache[key]) {57 this.cacheTable(column.table);58 }59 return this.cache[key];60 }61 cacheTable(table) {62 const schema = table[import_table.Table.Symbol.Schema] ?? "public";63 const tableName = table[import_table.Table.Symbol.OriginalName];64 const tableKey = `${schema}.${tableName}`;65 if (!this.cachedTables[tableKey]) {66 for (const column of Object.values(table[import_table.Table.Symbol.Columns])) {67 const columnKey = `${tableKey}.${column.name}`;68 this.cache[columnKey] = this.convert(column.name);69 }70 this.cachedTables[tableKey] = true;71 }72 }73 clearCache() {74 this.cache = {};75 this.cachedTables = {};76 }77}78// Annotate the CommonJS export names for ESM import in node:790 && (module.exports = {80 CasingCache,81 toCamelCase,82 toSnakeCase83});84//# sourceMappingURL=casing.cjs.map