@rebasepro/server-postgresql 0.0.1-canary.6e26b67 → 0.0.1-canary.892f711

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/index.es.js +184 -186
  2. package/dist/index.es.js.map +1 -1
  3. package/dist/index.umd.js +184 -186
  4. package/dist/index.umd.js.map +1 -1
  5. package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +6 -0
  6. package/dist/types/src/controllers/auth.d.ts +2 -2
  7. package/dist/types/src/controllers/collection_registry.d.ts +2 -1
  8. package/dist/types/src/controllers/data_driver.d.ts +36 -1
  9. package/dist/types/src/types/backend_hooks.d.ts +187 -0
  10. package/dist/types/src/types/collections.d.ts +11 -10
  11. package/dist/types/src/types/cron.d.ts +1 -1
  12. package/dist/types/src/types/entity_views.d.ts +4 -6
  13. package/dist/types/src/types/formex.d.ts +40 -0
  14. package/dist/types/src/types/index.d.ts +2 -0
  15. package/dist/types/src/types/plugins.d.ts +6 -3
  16. package/dist/types/src/types/properties.d.ts +71 -87
  17. package/dist/types/src/types/slots.d.ts +20 -10
  18. package/dist/types/src/types/translations.d.ts +4 -0
  19. package/package.json +5 -5
  20. package/src/PostgresBackendDriver.ts +9 -0
  21. package/src/cli.ts +2 -2
  22. package/src/schema/doctor.ts +14 -2
  23. package/src/schema/generate-drizzle-schema-logic.ts +24 -30
  24. package/src/schema/introspect-db-logic.ts +33 -30
  25. package/src/services/EntityPersistService.ts +7 -1
  26. package/test/generate-drizzle-schema.test.ts +214 -0
  27. package/test/introspect-db-generation.test.ts +27 -5
  28. package/test/relations.test.ts +4 -4
  29. package/jest-all.log +0 -3128
  30. package/jest.log +0 -49
  31. package/scratch.ts +0 -41
  32. package/test-drizzle-bug.ts +0 -18
  33. package/test-drizzle-out/0000_cultured_freak.sql +0 -7
  34. package/test-drizzle-out/0001_tiresome_professor_monster.sql +0 -1
  35. package/test-drizzle-out/meta/0000_snapshot.json +0 -55
  36. package/test-drizzle-out/meta/0001_snapshot.json +0 -63
  37. package/test-drizzle-out/meta/_journal.json +0 -20
  38. package/test-drizzle-prompt.sh +0 -2
  39. package/test-policy-prompt.sh +0 -3
  40. package/test-programmatic.ts +0 -30
  41. package/test-programmatic2.ts +0 -59
  42. package/test-schema-no-policies.ts +0 -12
  43. package/test_drizzle_mock.js +0 -3
  44. package/test_find_changed.mjs +0 -32
  45. package/test_hash.js +0 -14
  46. package/test_output.txt +0 -3145
package/dist/index.umd.js CHANGED
@@ -132,7 +132,8 @@
132
132
  }
133
133
  const DEFAULT_ONE_OF_TYPE = "type";
134
134
  const DEFAULT_ONE_OF_VALUE = "value";
135
- const snakeCaseRegex = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g;
135
+ const tokenizeRegex = /[A-Z]{2,}(?=[A-Z][a-z]|\b)|[A-Z]?[a-z]+|[0-9]+(?:[a-z](?![a-z]))?|[A-Z]/g;
136
+ const snakeCaseRegex = tokenizeRegex;
136
137
  const toSnakeCase = (str) => {
137
138
  const regExpMatchArray = str.match(snakeCaseRegex);
138
139
  if (!regExpMatchArray) return "";
@@ -1725,8 +1726,8 @@
1725
1726
  return jsonLogic;
1726
1727
  });
1727
1728
  })(logic);
1728
- var getOwnPropertyNames = Object.getOwnPropertyNames, getOwnPropertySymbols = Object.getOwnPropertySymbols;
1729
- var hasOwnProperty$a = Object.prototype.hasOwnProperty;
1729
+ const { getOwnPropertyNames, getOwnPropertySymbols } = Object;
1730
+ const { hasOwnProperty: hasOwnProperty$a } = Object.prototype;
1730
1731
  function combineComparators(comparatorA, comparatorB) {
1731
1732
  return function isEqual(a, b, state) {
1732
1733
  return comparatorA(a, b, state) && comparatorB(a, b, state);
@@ -1737,38 +1738,45 @@
1737
1738
  if (!a || !b || typeof a !== "object" || typeof b !== "object") {
1738
1739
  return areItemsEqual(a, b, state);
1739
1740
  }
1740
- var cache = state.cache;
1741
- var cachedA = cache.get(a);
1742
- var cachedB = cache.get(b);
1741
+ const { cache } = state;
1742
+ const cachedA = cache.get(a);
1743
+ const cachedB = cache.get(b);
1743
1744
  if (cachedA && cachedB) {
1744
1745
  return cachedA === b && cachedB === a;
1745
1746
  }
1746
1747
  cache.set(a, b);
1747
1748
  cache.set(b, a);
1748
- var result = areItemsEqual(a, b, state);
1749
+ const result = areItemsEqual(a, b, state);
1749
1750
  cache.delete(a);
1750
1751
  cache.delete(b);
1751
1752
  return result;
1752
1753
  };
1753
1754
  }
1754
- function getShortTag(value) {
1755
- return value != null ? value[Symbol.toStringTag] : void 0;
1756
- }
1757
1755
  function getStrictProperties(object) {
1758
1756
  return getOwnPropertyNames(object).concat(getOwnPropertySymbols(object));
1759
1757
  }
1760
- var hasOwn = Object.hasOwn || function(object, property) {
1761
- return hasOwnProperty$a.call(object, property);
1762
- };
1763
- function sameValueZeroEqual(a, b) {
1764
- return a === b || !a && !b && a !== a && b !== b;
1758
+ const hasOwn = (
1759
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1760
+ Object.hasOwn || ((object, property) => hasOwnProperty$a.call(object, property))
1761
+ );
1762
+ const PREACT_VNODE = "__v";
1763
+ const PREACT_OWNER = "__o";
1764
+ const REACT_OWNER = "_owner";
1765
+ const { getOwnPropertyDescriptor, keys: keys$4 } = Object;
1766
+ const sameValueEqual = (
1767
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1768
+ Object.is || function sameValueEqual2(a, b) {
1769
+ return a === b ? a !== 0 || 1 / a === 1 / b : a !== a && b !== b;
1770
+ }
1771
+ );
1772
+ function strictEqual(a, b) {
1773
+ return a === b;
1774
+ }
1775
+ function areArrayBuffersEqual(a, b) {
1776
+ return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a), new Uint8Array(b));
1765
1777
  }
1766
- var PREACT_VNODE = "__v";
1767
- var PREACT_OWNER = "__o";
1768
- var REACT_OWNER = "_owner";
1769
- var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, keys$4 = Object.keys;
1770
1778
  function areArraysEqual(a, b, state) {
1771
- var index = a.length;
1779
+ let index = a.length;
1772
1780
  if (b.length !== index) {
1773
1781
  return false;
1774
1782
  }
@@ -1779,35 +1787,35 @@
1779
1787
  }
1780
1788
  return true;
1781
1789
  }
1790
+ function areDataViewsEqual(a, b) {
1791
+ return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a.buffer, a.byteOffset, a.byteLength), new Uint8Array(b.buffer, b.byteOffset, b.byteLength));
1792
+ }
1782
1793
  function areDatesEqual(a, b) {
1783
- return sameValueZeroEqual(a.getTime(), b.getTime());
1794
+ return sameValueEqual(a.getTime(), b.getTime());
1784
1795
  }
1785
1796
  function areErrorsEqual(a, b) {
1786
1797
  return a.name === b.name && a.message === b.message && a.cause === b.cause && a.stack === b.stack;
1787
1798
  }
1788
- function areFunctionsEqual(a, b) {
1789
- return a === b;
1790
- }
1791
1799
  function areMapsEqual(a, b, state) {
1792
- var size = a.size;
1800
+ const size = a.size;
1793
1801
  if (size !== b.size) {
1794
1802
  return false;
1795
1803
  }
1796
1804
  if (!size) {
1797
1805
  return true;
1798
1806
  }
1799
- var matchedIndices = new Array(size);
1800
- var aIterable = a.entries();
1801
- var aResult;
1802
- var bResult;
1803
- var index = 0;
1807
+ const matchedIndices = new Array(size);
1808
+ const aIterable = a.entries();
1809
+ let aResult;
1810
+ let bResult;
1811
+ let index = 0;
1804
1812
  while (aResult = aIterable.next()) {
1805
1813
  if (aResult.done) {
1806
1814
  break;
1807
1815
  }
1808
- var bIterable = b.entries();
1809
- var hasMatch = false;
1810
- var matchIndex = 0;
1816
+ const bIterable = b.entries();
1817
+ let hasMatch = false;
1818
+ let matchIndex = 0;
1811
1819
  while (bResult = bIterable.next()) {
1812
1820
  if (bResult.done) {
1813
1821
  break;
@@ -1816,8 +1824,8 @@
1816
1824
  matchIndex++;
1817
1825
  continue;
1818
1826
  }
1819
- var aEntry = aResult.value;
1820
- var bEntry = bResult.value;
1827
+ const aEntry = aResult.value;
1828
+ const bEntry = bResult.value;
1821
1829
  if (state.equals(aEntry[0], bEntry[0], index, matchIndex, a, b, state) && state.equals(aEntry[1], bEntry[1], aEntry[0], bEntry[0], a, b, state)) {
1822
1830
  hasMatch = matchedIndices[matchIndex] = true;
1823
1831
  break;
@@ -1831,10 +1839,9 @@
1831
1839
  }
1832
1840
  return true;
1833
1841
  }
1834
- var areNumbersEqual = sameValueZeroEqual;
1835
1842
  function areObjectsEqual(a, b, state) {
1836
- var properties = keys$4(a);
1837
- var index = properties.length;
1843
+ const properties = keys$4(a);
1844
+ let index = properties.length;
1838
1845
  if (keys$4(b).length !== index) {
1839
1846
  return false;
1840
1847
  }
@@ -1846,14 +1853,14 @@
1846
1853
  return true;
1847
1854
  }
1848
1855
  function areObjectsEqualStrict(a, b, state) {
1849
- var properties = getStrictProperties(a);
1850
- var index = properties.length;
1856
+ const properties = getStrictProperties(a);
1857
+ let index = properties.length;
1851
1858
  if (getStrictProperties(b).length !== index) {
1852
1859
  return false;
1853
1860
  }
1854
- var property;
1855
- var descriptorA;
1856
- var descriptorB;
1861
+ let property;
1862
+ let descriptorA;
1863
+ let descriptorB;
1857
1864
  while (index-- > 0) {
1858
1865
  property = properties[index];
1859
1866
  if (!isPropertyEqual(a, b, state, property)) {
@@ -1868,30 +1875,30 @@
1868
1875
  return true;
1869
1876
  }
1870
1877
  function arePrimitiveWrappersEqual(a, b) {
1871
- return sameValueZeroEqual(a.valueOf(), b.valueOf());
1878
+ return sameValueEqual(a.valueOf(), b.valueOf());
1872
1879
  }
1873
1880
  function areRegExpsEqual(a, b) {
1874
1881
  return a.source === b.source && a.flags === b.flags;
1875
1882
  }
1876
1883
  function areSetsEqual(a, b, state) {
1877
- var size = a.size;
1884
+ const size = a.size;
1878
1885
  if (size !== b.size) {
1879
1886
  return false;
1880
1887
  }
1881
1888
  if (!size) {
1882
1889
  return true;
1883
1890
  }
1884
- var matchedIndices = new Array(size);
1885
- var aIterable = a.values();
1886
- var aResult;
1887
- var bResult;
1891
+ const matchedIndices = new Array(size);
1892
+ const aIterable = a.values();
1893
+ let aResult;
1894
+ let bResult;
1888
1895
  while (aResult = aIterable.next()) {
1889
1896
  if (aResult.done) {
1890
1897
  break;
1891
1898
  }
1892
- var bIterable = b.values();
1893
- var hasMatch = false;
1894
- var matchIndex = 0;
1899
+ const bIterable = b.values();
1900
+ let hasMatch = false;
1901
+ let matchIndex = 0;
1895
1902
  while (bResult = bIterable.next()) {
1896
1903
  if (bResult.done) {
1897
1904
  break;
@@ -1909,8 +1916,8 @@
1909
1916
  return true;
1910
1917
  }
1911
1918
  function areTypedArraysEqual(a, b) {
1912
- var index = a.length;
1913
- if (b.length !== index) {
1919
+ let index = a.byteLength;
1920
+ if (b.byteLength !== index || a.byteOffset !== b.byteOffset) {
1914
1921
  return false;
1915
1922
  }
1916
1923
  while (index-- > 0) {
@@ -1929,23 +1936,10 @@
1929
1936
  }
1930
1937
  return hasOwn(b, property) && state.equals(a[property], b[property], property, property, a, b, state);
1931
1938
  }
1932
- var ARGUMENTS_TAG = "[object Arguments]";
1933
- var BOOLEAN_TAG = "[object Boolean]";
1934
- var DATE_TAG = "[object Date]";
1935
- var ERROR_TAG = "[object Error]";
1936
- var MAP_TAG = "[object Map]";
1937
- var NUMBER_TAG = "[object Number]";
1938
- var OBJECT_TAG = "[object Object]";
1939
- var REG_EXP_TAG = "[object RegExp]";
1940
- var SET_TAG = "[object Set]";
1941
- var STRING_TAG = "[object String]";
1942
- var URL_TAG = "[object URL]";
1943
- var isArray$4 = Array.isArray;
1944
- var isTypedArray$2 = typeof ArrayBuffer === "function" && ArrayBuffer.isView ? ArrayBuffer.isView : null;
1945
- var assign = Object.assign;
1946
- var getTag$4 = Object.prototype.toString.call.bind(Object.prototype.toString);
1947
- function createEqualityComparator(_a) {
1948
- var areArraysEqual2 = _a.areArraysEqual, areDatesEqual2 = _a.areDatesEqual, areErrorsEqual2 = _a.areErrorsEqual, areFunctionsEqual2 = _a.areFunctionsEqual, areMapsEqual2 = _a.areMapsEqual, areNumbersEqual2 = _a.areNumbersEqual, areObjectsEqual2 = _a.areObjectsEqual, arePrimitiveWrappersEqual2 = _a.arePrimitiveWrappersEqual, areRegExpsEqual2 = _a.areRegExpsEqual, areSetsEqual2 = _a.areSetsEqual, areTypedArraysEqual2 = _a.areTypedArraysEqual, areUrlsEqual2 = _a.areUrlsEqual, unknownTagComparators = _a.unknownTagComparators;
1939
+ const toString = Object.prototype.toString;
1940
+ function createEqualityComparator(config) {
1941
+ const supportedComparatorMap = createSupportedComparatorMap(config);
1942
+ const { areArraysEqual: areArraysEqual2, areDatesEqual: areDatesEqual2, areFunctionsEqual, areMapsEqual: areMapsEqual2, areNumbersEqual, areObjectsEqual: areObjectsEqual2, areRegExpsEqual: areRegExpsEqual2, areSetsEqual: areSetsEqual2, getUnsupportedCustomComparator } = config;
1949
1943
  return function comparator(a, b, state) {
1950
1944
  if (a === b) {
1951
1945
  return true;
@@ -1953,32 +1947,29 @@
1953
1947
  if (a == null || b == null) {
1954
1948
  return false;
1955
1949
  }
1956
- var type = typeof a;
1950
+ const type = typeof a;
1957
1951
  if (type !== typeof b) {
1958
1952
  return false;
1959
1953
  }
1960
1954
  if (type !== "object") {
1961
- if (type === "number") {
1962
- return areNumbersEqual2(a, b, state);
1955
+ if (type === "number" || type === "bigint") {
1956
+ return areNumbersEqual(a, b, state);
1963
1957
  }
1964
1958
  if (type === "function") {
1965
- return areFunctionsEqual2(a, b, state);
1959
+ return areFunctionsEqual(a, b, state);
1966
1960
  }
1967
1961
  return false;
1968
1962
  }
1969
- var constructor = a.constructor;
1963
+ const constructor = a.constructor;
1970
1964
  if (constructor !== b.constructor) {
1971
1965
  return false;
1972
1966
  }
1973
1967
  if (constructor === Object) {
1974
1968
  return areObjectsEqual2(a, b, state);
1975
1969
  }
1976
- if (isArray$4(a)) {
1970
+ if (constructor === Array) {
1977
1971
  return areArraysEqual2(a, b, state);
1978
1972
  }
1979
- if (isTypedArray$2 != null && isTypedArray$2(a)) {
1980
- return areTypedArraysEqual2(a, b, state);
1981
- }
1982
1973
  if (constructor === Date) {
1983
1974
  return areDatesEqual2(a, b, state);
1984
1975
  }
@@ -1991,79 +1982,55 @@
1991
1982
  if (constructor === Set) {
1992
1983
  return areSetsEqual2(a, b, state);
1993
1984
  }
1994
- var tag = getTag$4(a);
1995
- if (tag === DATE_TAG) {
1996
- return areDatesEqual2(a, b, state);
1997
- }
1998
- if (tag === REG_EXP_TAG) {
1999
- return areRegExpsEqual2(a, b, state);
2000
- }
2001
- if (tag === MAP_TAG) {
2002
- return areMapsEqual2(a, b, state);
2003
- }
2004
- if (tag === SET_TAG) {
2005
- return areSetsEqual2(a, b, state);
2006
- }
2007
- if (tag === OBJECT_TAG) {
2008
- return typeof a.then !== "function" && typeof b.then !== "function" && areObjectsEqual2(a, b, state);
2009
- }
2010
- if (tag === URL_TAG) {
2011
- return areUrlsEqual2(a, b, state);
1985
+ if (constructor === Promise) {
1986
+ return false;
2012
1987
  }
2013
- if (tag === ERROR_TAG) {
2014
- return areErrorsEqual2(a, b, state);
1988
+ if (Array.isArray(a)) {
1989
+ return areArraysEqual2(a, b, state);
2015
1990
  }
2016
- if (tag === ARGUMENTS_TAG) {
2017
- return areObjectsEqual2(a, b, state);
1991
+ const tag = toString.call(a);
1992
+ const supportedComparator = supportedComparatorMap[tag];
1993
+ if (supportedComparator) {
1994
+ return supportedComparator(a, b, state);
2018
1995
  }
2019
- if (tag === BOOLEAN_TAG || tag === NUMBER_TAG || tag === STRING_TAG) {
2020
- return arePrimitiveWrappersEqual2(a, b, state);
2021
- }
2022
- if (unknownTagComparators) {
2023
- var unknownTagComparator = unknownTagComparators[tag];
2024
- if (!unknownTagComparator) {
2025
- var shortTag = getShortTag(a);
2026
- if (shortTag) {
2027
- unknownTagComparator = unknownTagComparators[shortTag];
2028
- }
2029
- }
2030
- if (unknownTagComparator) {
2031
- return unknownTagComparator(a, b, state);
2032
- }
1996
+ const unsupportedCustomComparator = getUnsupportedCustomComparator && getUnsupportedCustomComparator(a, b, state, tag);
1997
+ if (unsupportedCustomComparator) {
1998
+ return unsupportedCustomComparator(a, b, state);
2033
1999
  }
2034
2000
  return false;
2035
2001
  };
2036
2002
  }
2037
- function createEqualityComparatorConfig(_a) {
2038
- var circular = _a.circular, createCustomConfig = _a.createCustomConfig, strict = _a.strict;
2039
- var config = {
2003
+ function createEqualityComparatorConfig({ circular, createCustomConfig, strict }) {
2004
+ let config = {
2005
+ areArrayBuffersEqual,
2040
2006
  areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
2007
+ areDataViewsEqual,
2041
2008
  areDatesEqual,
2042
2009
  areErrorsEqual,
2043
- areFunctionsEqual,
2010
+ areFunctionsEqual: strictEqual,
2044
2011
  areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
2045
- areNumbersEqual,
2012
+ areNumbersEqual: sameValueEqual,
2046
2013
  areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
2047
2014
  arePrimitiveWrappersEqual,
2048
2015
  areRegExpsEqual,
2049
2016
  areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
2050
- areTypedArraysEqual: strict ? areObjectsEqualStrict : areTypedArraysEqual,
2017
+ areTypedArraysEqual: strict ? combineComparators(areTypedArraysEqual, areObjectsEqualStrict) : areTypedArraysEqual,
2051
2018
  areUrlsEqual,
2052
- unknownTagComparators: void 0
2019
+ getUnsupportedCustomComparator: void 0
2053
2020
  };
2054
2021
  if (createCustomConfig) {
2055
- config = assign({}, config, createCustomConfig(config));
2022
+ config = Object.assign({}, config, createCustomConfig(config));
2056
2023
  }
2057
2024
  if (circular) {
2058
- var areArraysEqual$1 = createIsCircular(config.areArraysEqual);
2059
- var areMapsEqual$1 = createIsCircular(config.areMapsEqual);
2060
- var areObjectsEqual$1 = createIsCircular(config.areObjectsEqual);
2061
- var areSetsEqual$1 = createIsCircular(config.areSetsEqual);
2062
- config = assign({}, config, {
2063
- areArraysEqual: areArraysEqual$1,
2064
- areMapsEqual: areMapsEqual$1,
2065
- areObjectsEqual: areObjectsEqual$1,
2066
- areSetsEqual: areSetsEqual$1
2025
+ const areArraysEqual2 = createIsCircular(config.areArraysEqual);
2026
+ const areMapsEqual2 = createIsCircular(config.areMapsEqual);
2027
+ const areObjectsEqual2 = createIsCircular(config.areObjectsEqual);
2028
+ const areSetsEqual2 = createIsCircular(config.areSetsEqual);
2029
+ config = Object.assign({}, config, {
2030
+ areArraysEqual: areArraysEqual2,
2031
+ areMapsEqual: areMapsEqual2,
2032
+ areObjectsEqual: areObjectsEqual2,
2033
+ areSetsEqual: areSetsEqual2
2067
2034
  });
2068
2035
  }
2069
2036
  return config;
@@ -2073,11 +2040,10 @@
2073
2040
  return compare(a, b, state);
2074
2041
  };
2075
2042
  }
2076
- function createIsEqual(_a) {
2077
- var circular = _a.circular, comparator = _a.comparator, createState = _a.createState, equals = _a.equals, strict = _a.strict;
2043
+ function createIsEqual({ circular, comparator, createState, equals, strict }) {
2078
2044
  if (createState) {
2079
2045
  return function isEqual(a, b) {
2080
- var _a2 = createState(), _b = _a2.cache, cache = _b === void 0 ? circular ? /* @__PURE__ */ new WeakMap() : void 0 : _b, meta = _a2.meta;
2046
+ const { cache = circular ? /* @__PURE__ */ new WeakMap() : void 0, meta } = createState();
2081
2047
  return comparator(a, b, {
2082
2048
  cache,
2083
2049
  equals,
@@ -2096,7 +2062,7 @@
2096
2062
  });
2097
2063
  };
2098
2064
  }
2099
- var state = {
2065
+ const state = {
2100
2066
  cache: void 0,
2101
2067
  equals,
2102
2068
  meta: void 0,
@@ -2106,7 +2072,50 @@
2106
2072
  return comparator(a, b, state);
2107
2073
  };
2108
2074
  }
2109
- var deepEqual = createCustomEqual();
2075
+ function createSupportedComparatorMap({ areArrayBuffersEqual: areArrayBuffersEqual2, areArraysEqual: areArraysEqual2, areDataViewsEqual: areDataViewsEqual2, areDatesEqual: areDatesEqual2, areErrorsEqual: areErrorsEqual2, areFunctionsEqual, areMapsEqual: areMapsEqual2, areNumbersEqual, areObjectsEqual: areObjectsEqual2, arePrimitiveWrappersEqual: arePrimitiveWrappersEqual2, areRegExpsEqual: areRegExpsEqual2, areSetsEqual: areSetsEqual2, areTypedArraysEqual: areTypedArraysEqual2, areUrlsEqual: areUrlsEqual2 }) {
2076
+ return {
2077
+ "[object Arguments]": areObjectsEqual2,
2078
+ "[object Array]": areArraysEqual2,
2079
+ "[object ArrayBuffer]": areArrayBuffersEqual2,
2080
+ "[object AsyncGeneratorFunction]": areFunctionsEqual,
2081
+ "[object BigInt]": areNumbersEqual,
2082
+ "[object BigInt64Array]": areTypedArraysEqual2,
2083
+ "[object BigUint64Array]": areTypedArraysEqual2,
2084
+ "[object Boolean]": arePrimitiveWrappersEqual2,
2085
+ "[object DataView]": areDataViewsEqual2,
2086
+ "[object Date]": areDatesEqual2,
2087
+ // If an error tag, it should be tested explicitly. Like RegExp, the properties are not
2088
+ // enumerable, and therefore will give false positives if tested like a standard object.
2089
+ "[object Error]": areErrorsEqual2,
2090
+ "[object Float16Array]": areTypedArraysEqual2,
2091
+ "[object Float32Array]": areTypedArraysEqual2,
2092
+ "[object Float64Array]": areTypedArraysEqual2,
2093
+ "[object Function]": areFunctionsEqual,
2094
+ "[object GeneratorFunction]": areFunctionsEqual,
2095
+ "[object Int8Array]": areTypedArraysEqual2,
2096
+ "[object Int16Array]": areTypedArraysEqual2,
2097
+ "[object Int32Array]": areTypedArraysEqual2,
2098
+ "[object Map]": areMapsEqual2,
2099
+ "[object Number]": arePrimitiveWrappersEqual2,
2100
+ "[object Object]": (a, b, state) => (
2101
+ // The exception for value comparison is custom `Promise`-like class instances. These should
2102
+ // be treated the same as standard `Promise` objects, which means strict equality, and if
2103
+ // it reaches this point then that strict equality comparison has already failed.
2104
+ typeof a.then !== "function" && typeof b.then !== "function" && areObjectsEqual2(a, b, state)
2105
+ ),
2106
+ // For RegExp, the properties are not enumerable, and therefore will give false positives if
2107
+ // tested like a standard object.
2108
+ "[object RegExp]": areRegExpsEqual2,
2109
+ "[object Set]": areSetsEqual2,
2110
+ "[object String]": arePrimitiveWrappersEqual2,
2111
+ "[object URL]": areUrlsEqual2,
2112
+ "[object Uint8Array]": areTypedArraysEqual2,
2113
+ "[object Uint8ClampedArray]": areTypedArraysEqual2,
2114
+ "[object Uint16Array]": areTypedArraysEqual2,
2115
+ "[object Uint32Array]": areTypedArraysEqual2
2116
+ };
2117
+ }
2118
+ const deepEqual = createCustomEqual();
2110
2119
  createCustomEqual({ strict: true });
2111
2120
  createCustomEqual({ circular: true });
2112
2121
  createCustomEqual({
@@ -2114,37 +2123,26 @@
2114
2123
  strict: true
2115
2124
  });
2116
2125
  createCustomEqual({
2117
- createInternalComparator: function() {
2118
- return sameValueZeroEqual;
2119
- }
2126
+ createInternalComparator: () => sameValueEqual
2120
2127
  });
2121
2128
  createCustomEqual({
2122
2129
  strict: true,
2123
- createInternalComparator: function() {
2124
- return sameValueZeroEqual;
2125
- }
2130
+ createInternalComparator: () => sameValueEqual
2126
2131
  });
2127
2132
  createCustomEqual({
2128
2133
  circular: true,
2129
- createInternalComparator: function() {
2130
- return sameValueZeroEqual;
2131
- }
2134
+ createInternalComparator: () => sameValueEqual
2132
2135
  });
2133
2136
  createCustomEqual({
2134
2137
  circular: true,
2135
- createInternalComparator: function() {
2136
- return sameValueZeroEqual;
2137
- },
2138
+ createInternalComparator: () => sameValueEqual,
2138
2139
  strict: true
2139
2140
  });
2140
- function createCustomEqual(options) {
2141
- if (options === void 0) {
2142
- options = {};
2143
- }
2144
- var _a = options.circular, circular = _a === void 0 ? false : _a, createCustomInternalComparator = options.createInternalComparator, createState = options.createState, _b = options.strict, strict = _b === void 0 ? false : _b;
2145
- var config = createEqualityComparatorConfig(options);
2146
- var comparator = createEqualityComparator(config);
2147
- var equals = createCustomInternalComparator ? createCustomInternalComparator(comparator) : createInternalEqualityComparator(comparator);
2141
+ function createCustomEqual(options = {}) {
2142
+ const { circular = false, createInternalComparator: createCustomInternalComparator, createState, strict = false } = options;
2143
+ const config = createEqualityComparatorConfig(options);
2144
+ const comparator = createEqualityComparator(config);
2145
+ const equals = createCustomInternalComparator ? createCustomInternalComparator(comparator) : createInternalEqualityComparator(comparator);
2148
2146
  return createIsEqual({ circular, comparator, createState, equals, strict });
2149
2147
  }
2150
2148
  function listCacheClear$1() {
@@ -3394,7 +3392,10 @@
3394
3392
  if (!relation) {
3395
3393
  throw new Error(`Relation '${relationKey}' not found in collection '${currentCollection.slug}'`);
3396
3394
  }
3397
- currentCollection = relation.target();
3395
+ const target = relation.target();
3396
+ const targetRelationKey = relation.relationName || target.slug;
3397
+ const targetSlug = relation.overrides?.slug ?? targetRelationKey;
3398
+ currentCollection = this.get(targetSlug) || this.normalizeCollection(target);
3398
3399
  if (i + 1 < pathSegments.length) ;
3399
3400
  }
3400
3401
  return currentCollection;
@@ -3443,7 +3444,7 @@
3443
3444
  if (!subcollection) {
3444
3445
  throw new Error(`Subcollection '${subcollectionSlug}' not found in ${currentCollection.slug}`);
3445
3446
  }
3446
- currentCollection = subcollection;
3447
+ currentCollection = this.get(subcollection.slug) || this.normalizeCollection(subcollection);
3447
3448
  collections.push(currentCollection);
3448
3449
  }
3449
3450
  }
@@ -6630,7 +6631,7 @@
6630
6631
  targetColumnName = relation.localKey;
6631
6632
  } else if (relation.foreignKeyOnTarget) {
6632
6633
  targetColumnName = relation.foreignKeyOnTarget;
6633
- } else if (relation.joinPath && relation.joinPath.length > 0) {
6634
+ } else if (relation.joinPath && relation.joinPath.length === 1) {
6634
6635
  const targetTableName = getTableName(targetCollection);
6635
6636
  const relevantJoinStep = relation.joinPath.find((joinStep) => joinStep.table === targetTableName);
6636
6637
  if (relevantJoinStep) {
@@ -6641,6 +6642,8 @@
6641
6642
  const targetColumnNames = DrizzleConditionBuilder.getColumnNamesFromColumns(relation.joinPath[0].on.to);
6642
6643
  targetColumnName = targetColumnNames[0];
6643
6644
  }
6645
+ } else if (relation.joinPath && relation.joinPath.length > 1) {
6646
+ break;
6644
6647
  } else {
6645
6648
  throw new Error(`Relation '${relationKey}' lacks configuration for path-based saving.`);
6646
6649
  }
@@ -7103,6 +7106,14 @@
7103
7106
  } : {}
7104
7107
  };
7105
7108
  }
7109
+ /**
7110
+ * REST-optimised fetch service (include-aware eager-loading).
7111
+ * Delegates to the underlying EntityFetchService which already
7112
+ * implements the matching method signatures.
7113
+ */
7114
+ get restFetchService() {
7115
+ return this.entityService.getFetchService();
7116
+ }
7106
7117
  resolveCollectionCallbacks(collection, path2) {
7107
7118
  if (!collection && !path2) return {
7108
7119
  collection: void 0,
@@ -8067,6 +8078,12 @@
8067
8078
  references: [users.id]
8068
8079
  })
8069
8080
  }));
8081
+ const resolveColumnName = (propName, prop) => {
8082
+ if (prop && "columnName" in prop && typeof prop.columnName === "string") {
8083
+ return prop.columnName;
8084
+ }
8085
+ return toSnakeCase(propName);
8086
+ };
8070
8087
  const getPrimaryKeyProp = (collection) => {
8071
8088
  if (collection.properties) {
8072
8089
  const idPropEntry = Object.entries(collection.properties).find(([_, prop]) => "isId" in prop && Boolean(prop.isId));
@@ -8107,7 +8124,7 @@
8107
8124
  return !hasExplicitId && propName === "id";
8108
8125
  };
8109
8126
  const getDrizzleColumn = (propName, prop, collection, collections) => {
8110
- const colName = toSnakeCase(propName);
8127
+ const colName = resolveColumnName(propName, prop);
8111
8128
  let columnDefinition;
8112
8129
  switch (prop.type) {
8113
8130
  case "string": {
@@ -8211,7 +8228,7 @@
8211
8228
  } catch {
8212
8229
  return null;
8213
8230
  }
8214
- const fkColumnName = toSnakeCase(relation.localKey);
8231
+ const fkColumnName = relation.localKey;
8215
8232
  const targetTableVar = getTableVarName(getTableName(targetCollection));
8216
8233
  const pkProp = getPrimaryKeyProp(targetCollection);
8217
8234
  const targetIdField = pkProp.name;
@@ -8399,7 +8416,7 @@
8399
8416
  Object.entries(collection.properties ?? {}).forEach(([propName, prop]) => {
8400
8417
  if ("enum" in prop && (prop.type === "string" || prop.type === "number") && prop.enum) {
8401
8418
  const enumVarName = getEnumVarName(collectionPath, propName);
8402
- const enumDbName = `${collectionPath}_${toSnakeCase(propName)}`;
8419
+ const enumDbName = `${collectionPath}_${resolveColumnName(propName, prop)}`;
8403
8420
  const values = Array.isArray(prop.enum) ? prop.enum.map((v) => String(v.id ?? v)) : Object.keys(prop.enum);
8404
8421
  if (values.length > 0) {
8405
8422
  schemaContent += `export const ${enumVarName} = pgEnum("${enumDbName}", [${values.map((v) => `'${v}'`).join(", ")}]);
@@ -8456,9 +8473,9 @@
8456
8473
  const targetId = getPrimaryKeyName(targetCollection);
8457
8474
  schemaContent += `export const ${tableVarName} = pgTable("${tableName}", {
8458
8475
  `;
8459
- schemaContent += ` ${sourceColumn}: ${sourceColType}("${toSnakeCase(sourceColumn)}").notNull().references(() => ${getTableVarName(getTableName(sourceCollection))}.${sourceId}, ${refOptions}),
8476
+ schemaContent += ` ${sourceColumn}: ${sourceColType}("${sourceColumn}").notNull().references(() => ${getTableVarName(getTableName(sourceCollection))}.${sourceId}, ${refOptions}),
8460
8477
  `;
8461
- schemaContent += ` ${targetColumn}: ${targetColType}("${toSnakeCase(targetColumn)}").notNull().references(() => ${getTableVarName(getTableName(targetCollection))}.${targetId}, ${refOptions}),
8478
+ schemaContent += ` ${targetColumn}: ${targetColType}("${targetColumn}").notNull().references(() => ${getTableVarName(getTableName(targetCollection))}.${targetId}, ${refOptions}),
8462
8479
  `;
8463
8480
  schemaContent += "}, (table) => ({\n";
8464
8481
  schemaContent += ` pk: primaryKey({ columns: [table.${sourceColumn}, table.${targetColumn}] })
@@ -8551,29 +8568,10 @@
8551
8568
  references: [${targetTableVar}.${getPrimaryKeyName(target)}],
8552
8569
  relationName: "${drizzleRelationName}"
8553
8570
  })`);
8554
- } else if (rel.direction === "inverse" && rel.foreignKeyOnTarget) {
8555
- const sourceIdField = getPrimaryKeyName(collection);
8571
+ } else if (rel.direction === "inverse") {
8556
8572
  tableRelations.push(` "${relationKey}": one(${targetTableVar}, {
8557
- fields: [${tableVarName}.${sourceIdField}],
8558
- references: [${targetTableVar}.${rel.foreignKeyOnTarget}],
8559
- relationName: "${drizzleRelationName}"
8560
- })`);
8561
- } else if (rel.direction === "inverse" && !rel.foreignKeyOnTarget) {
8562
- try {
8563
- const targetCollection = rel.target();
8564
- const targetResolvedRelations = resolveCollectionRelations(targetCollection);
8565
- const correspondingRelation = Object.values(targetResolvedRelations).find((targetRel) => targetRel.direction === "owning" && targetRel.cardinality === "one" && targetRel.target().slug === collection.slug);
8566
- if (correspondingRelation && correspondingRelation.localKey) {
8567
- const sourceIdField = getPrimaryKeyName(collection);
8568
- tableRelations.push(` "${relationKey}": one(${targetTableVar}, {
8569
- fields: [${tableVarName}.${sourceIdField}],
8570
- references: [${targetTableVar}.${correspondingRelation.localKey}],
8571
8573
  relationName: "${drizzleRelationName}"
8572
8574
  })`);
8573
- }
8574
- } catch (e) {
8575
- console.warn(`Could not resolve inverse one-to-one relation '${relationKey}':`, e);
8576
- }
8577
8575
  }
8578
8576
  } else if (rel.cardinality === "many") {
8579
8577
  if (rel.direction === "inverse" && rel.foreignKeyOnTarget) {