table.cjs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __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. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var table_exports = {};
  20. __export(table_exports, {
  21. EnableRLS: () => EnableRLS,
  22. GelTable: () => GelTable,
  23. InlineForeignKeys: () => InlineForeignKeys,
  24. gelTable: () => gelTable,
  25. gelTableCreator: () => gelTableCreator,
  26. gelTableWithSchema: () => gelTableWithSchema
  27. });
  28. module.exports = __toCommonJS(table_exports);
  29. var import_entity = require("../entity.cjs");
  30. var import_table = require("../table.cjs");
  31. var import_all = require("./columns/all.cjs");
  32. const InlineForeignKeys = Symbol.for("drizzle:GelInlineForeignKeys");
  33. const EnableRLS = Symbol.for("drizzle:EnableRLS");
  34. class GelTable extends import_table.Table {
  35. static [import_entity.entityKind] = "GelTable";
  36. /** @internal */
  37. static Symbol = Object.assign({}, import_table.Table.Symbol, {
  38. InlineForeignKeys,
  39. EnableRLS
  40. });
  41. /**@internal */
  42. [InlineForeignKeys] = [];
  43. /** @internal */
  44. [EnableRLS] = false;
  45. /** @internal */
  46. [import_table.Table.Symbol.ExtraConfigBuilder] = void 0;
  47. /** @internal */
  48. [import_table.Table.Symbol.ExtraConfigColumns] = {};
  49. }
  50. function gelTableWithSchema(name, columns, extraConfig, schema, baseName = name) {
  51. const rawTable = new GelTable(name, schema, baseName);
  52. const parsedColumns = typeof columns === "function" ? columns((0, import_all.getGelColumnBuilders)()) : columns;
  53. const builtColumns = Object.fromEntries(
  54. Object.entries(parsedColumns).map(([name2, colBuilderBase]) => {
  55. const colBuilder = colBuilderBase;
  56. colBuilder.setName(name2);
  57. const column = colBuilder.build(rawTable);
  58. rawTable[InlineForeignKeys].push(...colBuilder.buildForeignKeys(column, rawTable));
  59. return [name2, column];
  60. })
  61. );
  62. const builtColumnsForExtraConfig = Object.fromEntries(
  63. Object.entries(parsedColumns).map(([name2, colBuilderBase]) => {
  64. const colBuilder = colBuilderBase;
  65. colBuilder.setName(name2);
  66. const column = colBuilder.buildExtraConfigColumn(rawTable);
  67. return [name2, column];
  68. })
  69. );
  70. const table = Object.assign(rawTable, builtColumns);
  71. table[import_table.Table.Symbol.Columns] = builtColumns;
  72. table[import_table.Table.Symbol.ExtraConfigColumns] = builtColumnsForExtraConfig;
  73. if (extraConfig) {
  74. table[GelTable.Symbol.ExtraConfigBuilder] = extraConfig;
  75. }
  76. return Object.assign(table, {
  77. enableRLS: () => {
  78. table[GelTable.Symbol.EnableRLS] = true;
  79. return table;
  80. }
  81. });
  82. }
  83. const gelTable = (name, columns, extraConfig) => {
  84. return gelTableWithSchema(name, columns, extraConfig, void 0);
  85. };
  86. function gelTableCreator(customizeTableName) {
  87. return (name, columns, extraConfig) => {
  88. return gelTableWithSchema(customizeTableName(name), columns, extraConfig, void 0, name);
  89. };
  90. }
  91. // Annotate the CommonJS export names for ESM import in node:
  92. 0 && (module.exports = {
  93. EnableRLS,
  94. GelTable,
  95. InlineForeignKeys,
  96. gelTable,
  97. gelTableCreator,
  98. gelTableWithSchema
  99. });
  100. //# sourceMappingURL=table.cjs.map