@rebasepro/server-postgresql 0.0.1-canary.dbf160a → 0.0.1-canary.e17585f
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.
- package/dist/index.es.js +683 -1362
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +614 -1293
- package/dist/index.umd.js.map +1 -1
- package/dist/server-postgresql/src/PostgresAdapter.d.ts +6 -0
- package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +8 -1
- package/dist/server-postgresql/src/PostgresBootstrapper.d.ts +0 -5
- package/dist/server-postgresql/src/index.d.ts +1 -0
- package/dist/server-postgresql/src/schema/introspect-db-inference.d.ts +5 -0
- package/dist/server-postgresql/src/schema/introspect-db-logic.d.ts +44 -9
- package/dist/server-postgresql/src/services/EntityPersistService.d.ts +9 -0
- package/dist/server-postgresql/src/services/realtimeService.d.ts +12 -0
- package/dist/server-postgresql/src/websocket.d.ts +2 -1
- package/dist/types/src/controllers/auth.d.ts +8 -2
- package/dist/types/src/controllers/client.d.ts +13 -0
- package/dist/types/src/controllers/collection_registry.d.ts +2 -1
- package/dist/types/src/controllers/data_driver.d.ts +36 -1
- package/dist/types/src/controllers/navigation.d.ts +18 -6
- package/dist/types/src/controllers/registry.d.ts +9 -1
- package/dist/types/src/controllers/side_entity_controller.d.ts +7 -0
- package/dist/types/src/rebase_context.d.ts +17 -0
- package/dist/types/src/types/auth_adapter.d.ts +354 -0
- package/dist/types/src/types/backend_hooks.d.ts +187 -0
- package/dist/types/src/types/collections.d.ts +75 -11
- package/dist/types/src/types/component_ref.d.ts +47 -0
- package/dist/types/src/types/cron.d.ts +1 -1
- package/dist/types/src/types/database_adapter.d.ts +90 -0
- package/dist/types/src/types/entity_views.d.ts +6 -7
- package/dist/types/src/types/formex.d.ts +40 -0
- package/dist/types/src/types/index.d.ts +5 -0
- package/dist/types/src/types/plugins.d.ts +6 -3
- package/dist/types/src/types/properties.d.ts +72 -88
- package/dist/types/src/types/slots.d.ts +20 -10
- package/dist/types/src/types/translations.d.ts +12 -0
- package/package.json +5 -5
- package/src/PostgresAdapter.ts +52 -0
- package/src/PostgresBackendDriver.ts +49 -7
- package/src/PostgresBootstrapper.ts +4 -7
- package/src/auth/ensure-tables.ts +3 -121
- package/src/cli.ts +10 -2
- package/src/data-transformer.ts +84 -1
- package/src/index.ts +1 -0
- package/src/schema/doctor.ts +14 -2
- package/src/schema/generate-drizzle-schema-logic.ts +59 -30
- package/src/schema/introspect-db-inference.ts +238 -0
- package/src/schema/introspect-db-logic.ts +365 -61
- package/src/schema/introspect-db.ts +66 -23
- package/src/services/EntityFetchService.ts +16 -0
- package/src/services/EntityPersistService.ts +95 -13
- package/src/services/realtimeService.ts +35 -0
- package/src/utils/drizzle-conditions.ts +6 -0
- package/src/websocket.ts +60 -11
- package/test/generate-drizzle-schema.test.ts +342 -0
- package/test/introspect-db-generation.test.ts +32 -10
- package/test/property-ordering.test.ts +395 -0
- package/test/relations.test.ts +4 -4
- package/jest-all.log +0 -3128
- package/jest.log +0 -49
- package/scratch.ts +0 -41
- package/test-drizzle-bug.ts +0 -18
- package/test-drizzle-out/0000_cultured_freak.sql +0 -7
- package/test-drizzle-out/0001_tiresome_professor_monster.sql +0 -1
- package/test-drizzle-out/meta/0000_snapshot.json +0 -55
- package/test-drizzle-out/meta/0001_snapshot.json +0 -63
- package/test-drizzle-out/meta/_journal.json +0 -20
- package/test-drizzle-prompt.sh +0 -2
- package/test-policy-prompt.sh +0 -3
- package/test-programmatic.ts +0 -30
- package/test-programmatic2.ts +0 -59
- package/test-schema-no-policies.ts +0 -12
- package/test_drizzle_mock.js +0 -3
- package/test_find_changed.mjs +0 -32
- package/test_hash.js +0 -14
- package/test_output.txt +0 -3145
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Pool, Client } from "pg";
|
|
2
2
|
import { drizzle } from "drizzle-orm/node-postgres";
|
|
3
|
-
import { sql, inArray, eq
|
|
3
|
+
import { sql, inArray, eq, and, or, ilike, asc, desc, gt, lt, getTableName as getTableName$1, count, relations, isTable } from "drizzle-orm";
|
|
4
4
|
import { pgSchema, timestamp, varchar, boolean, uuid, jsonb, primaryKey, unique } from "drizzle-orm/pg-core";
|
|
5
5
|
import { createHash, randomUUID } from "crypto";
|
|
6
6
|
import * as fs from "fs";
|
|
@@ -124,16 +124,14 @@ function getDataSourceCapabilities(driver) {
|
|
|
124
124
|
}
|
|
125
125
|
const DEFAULT_ONE_OF_TYPE = "type";
|
|
126
126
|
const DEFAULT_ONE_OF_VALUE = "value";
|
|
127
|
-
const
|
|
127
|
+
const tokenizeRegex = /[A-Z]{2,}(?=[A-Z][a-z]|\b)|[A-Z]?[a-z]+|[0-9]+(?:[a-z](?![a-z]))?|[A-Z]/g;
|
|
128
|
+
const snakeCaseRegex = tokenizeRegex;
|
|
128
129
|
const toSnakeCase = (str) => {
|
|
129
130
|
const regExpMatchArray = str.match(snakeCaseRegex);
|
|
130
131
|
if (!regExpMatchArray) return "";
|
|
131
132
|
return regExpMatchArray.map((x) => x.toLowerCase()).join("_");
|
|
132
133
|
};
|
|
133
134
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
134
|
-
function getDefaultExportFromCjs(x) {
|
|
135
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
136
|
-
}
|
|
137
135
|
function commonjsRequire(path2) {
|
|
138
136
|
throw new Error('Could not dynamically require "' + path2 + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
139
137
|
}
|
|
@@ -920,7 +918,23 @@ var object_hash = { exports: {} };
|
|
|
920
918
|
}, { buffer: 3, lYpoI2: 11 }] }, {}, [1])(1);
|
|
921
919
|
});
|
|
922
920
|
})(object_hash);
|
|
923
|
-
function
|
|
921
|
+
function deepClone(value) {
|
|
922
|
+
if (value === null || value === void 0) return value;
|
|
923
|
+
if (typeof value === "function") return value;
|
|
924
|
+
if (typeof value !== "object") return value;
|
|
925
|
+
if (Array.isArray(value)) {
|
|
926
|
+
return value.map((item) => deepClone(item));
|
|
927
|
+
}
|
|
928
|
+
if (Object.getPrototypeOf(value) !== Object.prototype) {
|
|
929
|
+
return value;
|
|
930
|
+
}
|
|
931
|
+
const result = {};
|
|
932
|
+
for (const key of Object.keys(value)) {
|
|
933
|
+
result[key] = deepClone(value[key]);
|
|
934
|
+
}
|
|
935
|
+
return result;
|
|
936
|
+
}
|
|
937
|
+
function isObject(item) {
|
|
924
938
|
return !!item && typeof item === "object" && !Array.isArray(item);
|
|
925
939
|
}
|
|
926
940
|
function isPlainObject(obj) {
|
|
@@ -931,13 +945,13 @@ function isPlainObject(obj) {
|
|
|
931
945
|
return proto === Object.prototype;
|
|
932
946
|
}
|
|
933
947
|
function mergeDeep(target, source, ignoreUndefined = false) {
|
|
934
|
-
if (!isObject
|
|
948
|
+
if (!isObject(target)) {
|
|
935
949
|
return target;
|
|
936
950
|
}
|
|
937
951
|
const output = {
|
|
938
952
|
...target
|
|
939
953
|
};
|
|
940
|
-
if (!isObject
|
|
954
|
+
if (!isObject(source)) {
|
|
941
955
|
return output;
|
|
942
956
|
}
|
|
943
957
|
for (const key in source) {
|
|
@@ -978,7 +992,7 @@ function mergeDeep(target, source, ignoreUndefined = false) {
|
|
|
978
992
|
} else {
|
|
979
993
|
output[key] = sourceValue;
|
|
980
994
|
}
|
|
981
|
-
} else if (isObject
|
|
995
|
+
} else if (isObject(sourceValue)) {
|
|
982
996
|
output[key] = sourceValue;
|
|
983
997
|
} else {
|
|
984
998
|
output[key] = sourceValue;
|
|
@@ -1021,6 +1035,80 @@ function generateForeignKeyName(name) {
|
|
|
1021
1035
|
const singularName = snakeCaseName.endsWith("s") ? snakeCaseName.slice(0, -1) : snakeCaseName;
|
|
1022
1036
|
return `${singularName}_id`;
|
|
1023
1037
|
}
|
|
1038
|
+
function updateDateAutoValues({
|
|
1039
|
+
inputValues,
|
|
1040
|
+
properties,
|
|
1041
|
+
status,
|
|
1042
|
+
timestampNowValue
|
|
1043
|
+
}) {
|
|
1044
|
+
return traverseValuesProperties(inputValues, properties, (inputValue, property) => {
|
|
1045
|
+
if (property.type === "date") {
|
|
1046
|
+
if (status === "existing" && property.autoValue === "on_update") {
|
|
1047
|
+
return timestampNowValue;
|
|
1048
|
+
} else if ((status === "new" || status === "copy") && (property.autoValue === "on_update" || property.autoValue === "on_create")) {
|
|
1049
|
+
return timestampNowValue;
|
|
1050
|
+
} else {
|
|
1051
|
+
return inputValue;
|
|
1052
|
+
}
|
|
1053
|
+
} else {
|
|
1054
|
+
return inputValue;
|
|
1055
|
+
}
|
|
1056
|
+
}) ?? {};
|
|
1057
|
+
}
|
|
1058
|
+
function traverseValuesProperties(inputValues, properties, operation) {
|
|
1059
|
+
const safeInputValues = inputValues ?? {};
|
|
1060
|
+
const updatedValues = Object.entries(properties).map(([key, property]) => {
|
|
1061
|
+
const inputValue = safeInputValues && safeInputValues[key];
|
|
1062
|
+
const updatedValue = traverseValueProperty(inputValue, property, operation);
|
|
1063
|
+
if (updatedValue === null) return null;
|
|
1064
|
+
if (updatedValue === void 0) return void 0;
|
|
1065
|
+
return {
|
|
1066
|
+
[key]: updatedValue
|
|
1067
|
+
};
|
|
1068
|
+
}).reduce((a, b) => ({
|
|
1069
|
+
...a,
|
|
1070
|
+
...b
|
|
1071
|
+
}), {});
|
|
1072
|
+
const result = mergeDeep(safeInputValues, updatedValues);
|
|
1073
|
+
if (!result || Object.keys(result).length === 0) return void 0;
|
|
1074
|
+
return result;
|
|
1075
|
+
}
|
|
1076
|
+
function traverseValueProperty(inputValue, property, operation) {
|
|
1077
|
+
let value;
|
|
1078
|
+
if (property.type === "map" && property.properties) {
|
|
1079
|
+
value = traverseValuesProperties(inputValue, property.properties, operation);
|
|
1080
|
+
} else if (property.type === "array") {
|
|
1081
|
+
const of = property.of;
|
|
1082
|
+
if (of && Array.isArray(inputValue) && !Array.isArray(of)) {
|
|
1083
|
+
value = inputValue.map((e) => traverseValueProperty(e, of, operation));
|
|
1084
|
+
} else if (of && Array.isArray(inputValue) && Array.isArray(of)) {
|
|
1085
|
+
value = inputValue.map((e, i) => {
|
|
1086
|
+
if (i < of.length) return traverseValueProperty(e, of[i], operation);
|
|
1087
|
+
return null;
|
|
1088
|
+
}).filter(Boolean);
|
|
1089
|
+
} else if (property.oneOf && Array.isArray(inputValue)) {
|
|
1090
|
+
const typeField = property.oneOf?.typeField ?? DEFAULT_ONE_OF_TYPE;
|
|
1091
|
+
const valueField = property.oneOf?.valueField ?? DEFAULT_ONE_OF_VALUE;
|
|
1092
|
+
value = inputValue.map((e) => {
|
|
1093
|
+
if (e === null) return null;
|
|
1094
|
+
if (typeof e !== "object") return e;
|
|
1095
|
+
const rec = e;
|
|
1096
|
+
const type = rec[typeField];
|
|
1097
|
+
const childProperty = property.oneOf?.properties[type];
|
|
1098
|
+
if (!type || !childProperty) return e;
|
|
1099
|
+
return {
|
|
1100
|
+
[typeField]: type,
|
|
1101
|
+
[valueField]: traverseValueProperty(rec[valueField], childProperty, operation)
|
|
1102
|
+
};
|
|
1103
|
+
});
|
|
1104
|
+
} else {
|
|
1105
|
+
value = inputValue;
|
|
1106
|
+
}
|
|
1107
|
+
} else {
|
|
1108
|
+
value = operation(inputValue, property);
|
|
1109
|
+
}
|
|
1110
|
+
return value;
|
|
1111
|
+
}
|
|
1024
1112
|
function createRelationRef(id, path2) {
|
|
1025
1113
|
return {
|
|
1026
1114
|
id,
|
|
@@ -1227,6 +1315,17 @@ function sanitizeRelation(relation, sourceCollection) {
|
|
|
1227
1315
|
break;
|
|
1228
1316
|
}
|
|
1229
1317
|
}
|
|
1318
|
+
if (!isManyToManyInverse && targetCollection.properties) {
|
|
1319
|
+
for (const [propKey, prop] of Object.entries(targetCollection.properties)) {
|
|
1320
|
+
if (prop.type !== "relation") continue;
|
|
1321
|
+
const relProp = prop;
|
|
1322
|
+
const relName = relProp.relationName || propKey;
|
|
1323
|
+
if (relName === newRelation.inverseRelationName && relProp.cardinality === "many" && (relProp.direction === "owning" || !relProp.direction)) {
|
|
1324
|
+
isManyToManyInverse = true;
|
|
1325
|
+
break;
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1230
1329
|
} catch (e) {
|
|
1231
1330
|
}
|
|
1232
1331
|
}
|
|
@@ -1350,7 +1449,7 @@ function findRelation(resolvedRelations, key) {
|
|
|
1350
1449
|
}
|
|
1351
1450
|
var logic = { exports: {} };
|
|
1352
1451
|
(function(module, exports$1) {
|
|
1353
|
-
(function(
|
|
1452
|
+
(function(root, factory) {
|
|
1354
1453
|
{
|
|
1355
1454
|
module.exports = factory();
|
|
1356
1455
|
}
|
|
@@ -1717,8 +1816,8 @@ var logic = { exports: {} };
|
|
|
1717
1816
|
return jsonLogic;
|
|
1718
1817
|
});
|
|
1719
1818
|
})(logic);
|
|
1720
|
-
|
|
1721
|
-
|
|
1819
|
+
const { getOwnPropertyNames, getOwnPropertySymbols } = Object;
|
|
1820
|
+
const { hasOwnProperty } = Object.prototype;
|
|
1722
1821
|
function combineComparators(comparatorA, comparatorB) {
|
|
1723
1822
|
return function isEqual(a, b, state) {
|
|
1724
1823
|
return comparatorA(a, b, state) && comparatorB(a, b, state);
|
|
@@ -1729,38 +1828,45 @@ function createIsCircular(areItemsEqual) {
|
|
|
1729
1828
|
if (!a || !b || typeof a !== "object" || typeof b !== "object") {
|
|
1730
1829
|
return areItemsEqual(a, b, state);
|
|
1731
1830
|
}
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1831
|
+
const { cache } = state;
|
|
1832
|
+
const cachedA = cache.get(a);
|
|
1833
|
+
const cachedB = cache.get(b);
|
|
1735
1834
|
if (cachedA && cachedB) {
|
|
1736
1835
|
return cachedA === b && cachedB === a;
|
|
1737
1836
|
}
|
|
1738
1837
|
cache.set(a, b);
|
|
1739
1838
|
cache.set(b, a);
|
|
1740
|
-
|
|
1839
|
+
const result = areItemsEqual(a, b, state);
|
|
1741
1840
|
cache.delete(a);
|
|
1742
1841
|
cache.delete(b);
|
|
1743
1842
|
return result;
|
|
1744
1843
|
};
|
|
1745
1844
|
}
|
|
1746
|
-
function getShortTag(value) {
|
|
1747
|
-
return value != null ? value[Symbol.toStringTag] : void 0;
|
|
1748
|
-
}
|
|
1749
1845
|
function getStrictProperties(object) {
|
|
1750
1846
|
return getOwnPropertyNames(object).concat(getOwnPropertySymbols(object));
|
|
1751
1847
|
}
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1848
|
+
const hasOwn = (
|
|
1849
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1850
|
+
Object.hasOwn || ((object, property) => hasOwnProperty.call(object, property))
|
|
1851
|
+
);
|
|
1852
|
+
const PREACT_VNODE = "__v";
|
|
1853
|
+
const PREACT_OWNER = "__o";
|
|
1854
|
+
const REACT_OWNER = "_owner";
|
|
1855
|
+
const { getOwnPropertyDescriptor, keys } = Object;
|
|
1856
|
+
const sameValueEqual = (
|
|
1857
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1858
|
+
Object.is || function sameValueEqual2(a, b) {
|
|
1859
|
+
return a === b ? a !== 0 || 1 / a === 1 / b : a !== a && b !== b;
|
|
1860
|
+
}
|
|
1861
|
+
);
|
|
1862
|
+
function strictEqual(a, b) {
|
|
1863
|
+
return a === b;
|
|
1864
|
+
}
|
|
1865
|
+
function areArrayBuffersEqual(a, b) {
|
|
1866
|
+
return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a), new Uint8Array(b));
|
|
1757
1867
|
}
|
|
1758
|
-
var PREACT_VNODE = "__v";
|
|
1759
|
-
var PREACT_OWNER = "__o";
|
|
1760
|
-
var REACT_OWNER = "_owner";
|
|
1761
|
-
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, keys$4 = Object.keys;
|
|
1762
1868
|
function areArraysEqual(a, b, state) {
|
|
1763
|
-
|
|
1869
|
+
let index = a.length;
|
|
1764
1870
|
if (b.length !== index) {
|
|
1765
1871
|
return false;
|
|
1766
1872
|
}
|
|
@@ -1771,35 +1877,35 @@ function areArraysEqual(a, b, state) {
|
|
|
1771
1877
|
}
|
|
1772
1878
|
return true;
|
|
1773
1879
|
}
|
|
1880
|
+
function areDataViewsEqual(a, b) {
|
|
1881
|
+
return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a.buffer, a.byteOffset, a.byteLength), new Uint8Array(b.buffer, b.byteOffset, b.byteLength));
|
|
1882
|
+
}
|
|
1774
1883
|
function areDatesEqual(a, b) {
|
|
1775
|
-
return
|
|
1884
|
+
return sameValueEqual(a.getTime(), b.getTime());
|
|
1776
1885
|
}
|
|
1777
1886
|
function areErrorsEqual(a, b) {
|
|
1778
1887
|
return a.name === b.name && a.message === b.message && a.cause === b.cause && a.stack === b.stack;
|
|
1779
1888
|
}
|
|
1780
|
-
function areFunctionsEqual(a, b) {
|
|
1781
|
-
return a === b;
|
|
1782
|
-
}
|
|
1783
1889
|
function areMapsEqual(a, b, state) {
|
|
1784
|
-
|
|
1890
|
+
const size = a.size;
|
|
1785
1891
|
if (size !== b.size) {
|
|
1786
1892
|
return false;
|
|
1787
1893
|
}
|
|
1788
1894
|
if (!size) {
|
|
1789
1895
|
return true;
|
|
1790
1896
|
}
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1897
|
+
const matchedIndices = new Array(size);
|
|
1898
|
+
const aIterable = a.entries();
|
|
1899
|
+
let aResult;
|
|
1900
|
+
let bResult;
|
|
1901
|
+
let index = 0;
|
|
1796
1902
|
while (aResult = aIterable.next()) {
|
|
1797
1903
|
if (aResult.done) {
|
|
1798
1904
|
break;
|
|
1799
1905
|
}
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1906
|
+
const bIterable = b.entries();
|
|
1907
|
+
let hasMatch = false;
|
|
1908
|
+
let matchIndex = 0;
|
|
1803
1909
|
while (bResult = bIterable.next()) {
|
|
1804
1910
|
if (bResult.done) {
|
|
1805
1911
|
break;
|
|
@@ -1808,8 +1914,8 @@ function areMapsEqual(a, b, state) {
|
|
|
1808
1914
|
matchIndex++;
|
|
1809
1915
|
continue;
|
|
1810
1916
|
}
|
|
1811
|
-
|
|
1812
|
-
|
|
1917
|
+
const aEntry = aResult.value;
|
|
1918
|
+
const bEntry = bResult.value;
|
|
1813
1919
|
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)) {
|
|
1814
1920
|
hasMatch = matchedIndices[matchIndex] = true;
|
|
1815
1921
|
break;
|
|
@@ -1823,11 +1929,10 @@ function areMapsEqual(a, b, state) {
|
|
|
1823
1929
|
}
|
|
1824
1930
|
return true;
|
|
1825
1931
|
}
|
|
1826
|
-
var areNumbersEqual = sameValueZeroEqual;
|
|
1827
1932
|
function areObjectsEqual(a, b, state) {
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
if (keys
|
|
1933
|
+
const properties = keys(a);
|
|
1934
|
+
let index = properties.length;
|
|
1935
|
+
if (keys(b).length !== index) {
|
|
1831
1936
|
return false;
|
|
1832
1937
|
}
|
|
1833
1938
|
while (index-- > 0) {
|
|
@@ -1838,14 +1943,14 @@ function areObjectsEqual(a, b, state) {
|
|
|
1838
1943
|
return true;
|
|
1839
1944
|
}
|
|
1840
1945
|
function areObjectsEqualStrict(a, b, state) {
|
|
1841
|
-
|
|
1842
|
-
|
|
1946
|
+
const properties = getStrictProperties(a);
|
|
1947
|
+
let index = properties.length;
|
|
1843
1948
|
if (getStrictProperties(b).length !== index) {
|
|
1844
1949
|
return false;
|
|
1845
1950
|
}
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1951
|
+
let property;
|
|
1952
|
+
let descriptorA;
|
|
1953
|
+
let descriptorB;
|
|
1849
1954
|
while (index-- > 0) {
|
|
1850
1955
|
property = properties[index];
|
|
1851
1956
|
if (!isPropertyEqual(a, b, state, property)) {
|
|
@@ -1860,30 +1965,30 @@ function areObjectsEqualStrict(a, b, state) {
|
|
|
1860
1965
|
return true;
|
|
1861
1966
|
}
|
|
1862
1967
|
function arePrimitiveWrappersEqual(a, b) {
|
|
1863
|
-
return
|
|
1968
|
+
return sameValueEqual(a.valueOf(), b.valueOf());
|
|
1864
1969
|
}
|
|
1865
1970
|
function areRegExpsEqual(a, b) {
|
|
1866
1971
|
return a.source === b.source && a.flags === b.flags;
|
|
1867
1972
|
}
|
|
1868
1973
|
function areSetsEqual(a, b, state) {
|
|
1869
|
-
|
|
1974
|
+
const size = a.size;
|
|
1870
1975
|
if (size !== b.size) {
|
|
1871
1976
|
return false;
|
|
1872
1977
|
}
|
|
1873
1978
|
if (!size) {
|
|
1874
1979
|
return true;
|
|
1875
1980
|
}
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1981
|
+
const matchedIndices = new Array(size);
|
|
1982
|
+
const aIterable = a.values();
|
|
1983
|
+
let aResult;
|
|
1984
|
+
let bResult;
|
|
1880
1985
|
while (aResult = aIterable.next()) {
|
|
1881
1986
|
if (aResult.done) {
|
|
1882
1987
|
break;
|
|
1883
1988
|
}
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1989
|
+
const bIterable = b.values();
|
|
1990
|
+
let hasMatch = false;
|
|
1991
|
+
let matchIndex = 0;
|
|
1887
1992
|
while (bResult = bIterable.next()) {
|
|
1888
1993
|
if (bResult.done) {
|
|
1889
1994
|
break;
|
|
@@ -1901,8 +2006,8 @@ function areSetsEqual(a, b, state) {
|
|
|
1901
2006
|
return true;
|
|
1902
2007
|
}
|
|
1903
2008
|
function areTypedArraysEqual(a, b) {
|
|
1904
|
-
|
|
1905
|
-
if (b.
|
|
2009
|
+
let index = a.byteLength;
|
|
2010
|
+
if (b.byteLength !== index || a.byteOffset !== b.byteOffset) {
|
|
1906
2011
|
return false;
|
|
1907
2012
|
}
|
|
1908
2013
|
while (index-- > 0) {
|
|
@@ -1921,23 +2026,10 @@ function isPropertyEqual(a, b, state, property) {
|
|
|
1921
2026
|
}
|
|
1922
2027
|
return hasOwn(b, property) && state.equals(a[property], b[property], property, property, a, b, state);
|
|
1923
2028
|
}
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
var MAP_TAG = "[object Map]";
|
|
1929
|
-
var NUMBER_TAG = "[object Number]";
|
|
1930
|
-
var OBJECT_TAG = "[object Object]";
|
|
1931
|
-
var REG_EXP_TAG = "[object RegExp]";
|
|
1932
|
-
var SET_TAG = "[object Set]";
|
|
1933
|
-
var STRING_TAG = "[object String]";
|
|
1934
|
-
var URL_TAG = "[object URL]";
|
|
1935
|
-
var isArray$4 = Array.isArray;
|
|
1936
|
-
var isTypedArray$2 = typeof ArrayBuffer === "function" && ArrayBuffer.isView ? ArrayBuffer.isView : null;
|
|
1937
|
-
var assign = Object.assign;
|
|
1938
|
-
var getTag$4 = Object.prototype.toString.call.bind(Object.prototype.toString);
|
|
1939
|
-
function createEqualityComparator(_a) {
|
|
1940
|
-
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;
|
|
2029
|
+
const toString = Object.prototype.toString;
|
|
2030
|
+
function createEqualityComparator(config) {
|
|
2031
|
+
const supportedComparatorMap = createSupportedComparatorMap(config);
|
|
2032
|
+
const { areArraysEqual: areArraysEqual2, areDatesEqual: areDatesEqual2, areFunctionsEqual, areMapsEqual: areMapsEqual2, areNumbersEqual, areObjectsEqual: areObjectsEqual2, areRegExpsEqual: areRegExpsEqual2, areSetsEqual: areSetsEqual2, getUnsupportedCustomComparator } = config;
|
|
1941
2033
|
return function comparator(a, b, state) {
|
|
1942
2034
|
if (a === b) {
|
|
1943
2035
|
return true;
|
|
@@ -1945,32 +2037,29 @@ function createEqualityComparator(_a) {
|
|
|
1945
2037
|
if (a == null || b == null) {
|
|
1946
2038
|
return false;
|
|
1947
2039
|
}
|
|
1948
|
-
|
|
2040
|
+
const type = typeof a;
|
|
1949
2041
|
if (type !== typeof b) {
|
|
1950
2042
|
return false;
|
|
1951
2043
|
}
|
|
1952
2044
|
if (type !== "object") {
|
|
1953
|
-
if (type === "number") {
|
|
1954
|
-
return
|
|
2045
|
+
if (type === "number" || type === "bigint") {
|
|
2046
|
+
return areNumbersEqual(a, b, state);
|
|
1955
2047
|
}
|
|
1956
2048
|
if (type === "function") {
|
|
1957
|
-
return
|
|
2049
|
+
return areFunctionsEqual(a, b, state);
|
|
1958
2050
|
}
|
|
1959
2051
|
return false;
|
|
1960
2052
|
}
|
|
1961
|
-
|
|
2053
|
+
const constructor = a.constructor;
|
|
1962
2054
|
if (constructor !== b.constructor) {
|
|
1963
2055
|
return false;
|
|
1964
2056
|
}
|
|
1965
2057
|
if (constructor === Object) {
|
|
1966
2058
|
return areObjectsEqual2(a, b, state);
|
|
1967
2059
|
}
|
|
1968
|
-
if (
|
|
2060
|
+
if (constructor === Array) {
|
|
1969
2061
|
return areArraysEqual2(a, b, state);
|
|
1970
2062
|
}
|
|
1971
|
-
if (isTypedArray$2 != null && isTypedArray$2(a)) {
|
|
1972
|
-
return areTypedArraysEqual2(a, b, state);
|
|
1973
|
-
}
|
|
1974
2063
|
if (constructor === Date) {
|
|
1975
2064
|
return areDatesEqual2(a, b, state);
|
|
1976
2065
|
}
|
|
@@ -1983,79 +2072,55 @@ function createEqualityComparator(_a) {
|
|
|
1983
2072
|
if (constructor === Set) {
|
|
1984
2073
|
return areSetsEqual2(a, b, state);
|
|
1985
2074
|
}
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
return areDatesEqual2(a, b, state);
|
|
1989
|
-
}
|
|
1990
|
-
if (tag === REG_EXP_TAG) {
|
|
1991
|
-
return areRegExpsEqual2(a, b, state);
|
|
1992
|
-
}
|
|
1993
|
-
if (tag === MAP_TAG) {
|
|
1994
|
-
return areMapsEqual2(a, b, state);
|
|
1995
|
-
}
|
|
1996
|
-
if (tag === SET_TAG) {
|
|
1997
|
-
return areSetsEqual2(a, b, state);
|
|
1998
|
-
}
|
|
1999
|
-
if (tag === OBJECT_TAG) {
|
|
2000
|
-
return typeof a.then !== "function" && typeof b.then !== "function" && areObjectsEqual2(a, b, state);
|
|
2075
|
+
if (constructor === Promise) {
|
|
2076
|
+
return false;
|
|
2001
2077
|
}
|
|
2002
|
-
if (
|
|
2003
|
-
return
|
|
2078
|
+
if (Array.isArray(a)) {
|
|
2079
|
+
return areArraysEqual2(a, b, state);
|
|
2004
2080
|
}
|
|
2005
|
-
|
|
2006
|
-
|
|
2081
|
+
const tag = toString.call(a);
|
|
2082
|
+
const supportedComparator = supportedComparatorMap[tag];
|
|
2083
|
+
if (supportedComparator) {
|
|
2084
|
+
return supportedComparator(a, b, state);
|
|
2007
2085
|
}
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
if (tag === BOOLEAN_TAG || tag === NUMBER_TAG || tag === STRING_TAG) {
|
|
2012
|
-
return arePrimitiveWrappersEqual2(a, b, state);
|
|
2013
|
-
}
|
|
2014
|
-
if (unknownTagComparators) {
|
|
2015
|
-
var unknownTagComparator = unknownTagComparators[tag];
|
|
2016
|
-
if (!unknownTagComparator) {
|
|
2017
|
-
var shortTag = getShortTag(a);
|
|
2018
|
-
if (shortTag) {
|
|
2019
|
-
unknownTagComparator = unknownTagComparators[shortTag];
|
|
2020
|
-
}
|
|
2021
|
-
}
|
|
2022
|
-
if (unknownTagComparator) {
|
|
2023
|
-
return unknownTagComparator(a, b, state);
|
|
2024
|
-
}
|
|
2086
|
+
const unsupportedCustomComparator = getUnsupportedCustomComparator && getUnsupportedCustomComparator(a, b, state, tag);
|
|
2087
|
+
if (unsupportedCustomComparator) {
|
|
2088
|
+
return unsupportedCustomComparator(a, b, state);
|
|
2025
2089
|
}
|
|
2026
2090
|
return false;
|
|
2027
2091
|
};
|
|
2028
2092
|
}
|
|
2029
|
-
function createEqualityComparatorConfig(
|
|
2030
|
-
|
|
2031
|
-
|
|
2093
|
+
function createEqualityComparatorConfig({ circular, createCustomConfig, strict }) {
|
|
2094
|
+
let config = {
|
|
2095
|
+
areArrayBuffersEqual,
|
|
2032
2096
|
areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
|
|
2097
|
+
areDataViewsEqual,
|
|
2033
2098
|
areDatesEqual,
|
|
2034
2099
|
areErrorsEqual,
|
|
2035
|
-
areFunctionsEqual,
|
|
2100
|
+
areFunctionsEqual: strictEqual,
|
|
2036
2101
|
areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
|
|
2037
|
-
areNumbersEqual,
|
|
2102
|
+
areNumbersEqual: sameValueEqual,
|
|
2038
2103
|
areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
|
|
2039
2104
|
arePrimitiveWrappersEqual,
|
|
2040
2105
|
areRegExpsEqual,
|
|
2041
2106
|
areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
|
|
2042
|
-
areTypedArraysEqual: strict ? areObjectsEqualStrict : areTypedArraysEqual,
|
|
2107
|
+
areTypedArraysEqual: strict ? combineComparators(areTypedArraysEqual, areObjectsEqualStrict) : areTypedArraysEqual,
|
|
2043
2108
|
areUrlsEqual,
|
|
2044
|
-
|
|
2109
|
+
getUnsupportedCustomComparator: void 0
|
|
2045
2110
|
};
|
|
2046
2111
|
if (createCustomConfig) {
|
|
2047
|
-
config = assign({}, config, createCustomConfig(config));
|
|
2112
|
+
config = Object.assign({}, config, createCustomConfig(config));
|
|
2048
2113
|
}
|
|
2049
2114
|
if (circular) {
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
config = assign({}, config, {
|
|
2055
|
-
areArraysEqual:
|
|
2056
|
-
areMapsEqual:
|
|
2057
|
-
areObjectsEqual:
|
|
2058
|
-
areSetsEqual:
|
|
2115
|
+
const areArraysEqual2 = createIsCircular(config.areArraysEqual);
|
|
2116
|
+
const areMapsEqual2 = createIsCircular(config.areMapsEqual);
|
|
2117
|
+
const areObjectsEqual2 = createIsCircular(config.areObjectsEqual);
|
|
2118
|
+
const areSetsEqual2 = createIsCircular(config.areSetsEqual);
|
|
2119
|
+
config = Object.assign({}, config, {
|
|
2120
|
+
areArraysEqual: areArraysEqual2,
|
|
2121
|
+
areMapsEqual: areMapsEqual2,
|
|
2122
|
+
areObjectsEqual: areObjectsEqual2,
|
|
2123
|
+
areSetsEqual: areSetsEqual2
|
|
2059
2124
|
});
|
|
2060
2125
|
}
|
|
2061
2126
|
return config;
|
|
@@ -2065,11 +2130,10 @@ function createInternalEqualityComparator(compare) {
|
|
|
2065
2130
|
return compare(a, b, state);
|
|
2066
2131
|
};
|
|
2067
2132
|
}
|
|
2068
|
-
function createIsEqual(
|
|
2069
|
-
var circular = _a.circular, comparator = _a.comparator, createState = _a.createState, equals = _a.equals, strict = _a.strict;
|
|
2133
|
+
function createIsEqual({ circular, comparator, createState, equals, strict }) {
|
|
2070
2134
|
if (createState) {
|
|
2071
2135
|
return function isEqual(a, b) {
|
|
2072
|
-
|
|
2136
|
+
const { cache = circular ? /* @__PURE__ */ new WeakMap() : void 0, meta } = createState();
|
|
2073
2137
|
return comparator(a, b, {
|
|
2074
2138
|
cache,
|
|
2075
2139
|
equals,
|
|
@@ -2088,7 +2152,7 @@ function createIsEqual(_a) {
|
|
|
2088
2152
|
});
|
|
2089
2153
|
};
|
|
2090
2154
|
}
|
|
2091
|
-
|
|
2155
|
+
const state = {
|
|
2092
2156
|
cache: void 0,
|
|
2093
2157
|
equals,
|
|
2094
2158
|
meta: void 0,
|
|
@@ -2098,7 +2162,50 @@ function createIsEqual(_a) {
|
|
|
2098
2162
|
return comparator(a, b, state);
|
|
2099
2163
|
};
|
|
2100
2164
|
}
|
|
2101
|
-
|
|
2165
|
+
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 }) {
|
|
2166
|
+
return {
|
|
2167
|
+
"[object Arguments]": areObjectsEqual2,
|
|
2168
|
+
"[object Array]": areArraysEqual2,
|
|
2169
|
+
"[object ArrayBuffer]": areArrayBuffersEqual2,
|
|
2170
|
+
"[object AsyncGeneratorFunction]": areFunctionsEqual,
|
|
2171
|
+
"[object BigInt]": areNumbersEqual,
|
|
2172
|
+
"[object BigInt64Array]": areTypedArraysEqual2,
|
|
2173
|
+
"[object BigUint64Array]": areTypedArraysEqual2,
|
|
2174
|
+
"[object Boolean]": arePrimitiveWrappersEqual2,
|
|
2175
|
+
"[object DataView]": areDataViewsEqual2,
|
|
2176
|
+
"[object Date]": areDatesEqual2,
|
|
2177
|
+
// If an error tag, it should be tested explicitly. Like RegExp, the properties are not
|
|
2178
|
+
// enumerable, and therefore will give false positives if tested like a standard object.
|
|
2179
|
+
"[object Error]": areErrorsEqual2,
|
|
2180
|
+
"[object Float16Array]": areTypedArraysEqual2,
|
|
2181
|
+
"[object Float32Array]": areTypedArraysEqual2,
|
|
2182
|
+
"[object Float64Array]": areTypedArraysEqual2,
|
|
2183
|
+
"[object Function]": areFunctionsEqual,
|
|
2184
|
+
"[object GeneratorFunction]": areFunctionsEqual,
|
|
2185
|
+
"[object Int8Array]": areTypedArraysEqual2,
|
|
2186
|
+
"[object Int16Array]": areTypedArraysEqual2,
|
|
2187
|
+
"[object Int32Array]": areTypedArraysEqual2,
|
|
2188
|
+
"[object Map]": areMapsEqual2,
|
|
2189
|
+
"[object Number]": arePrimitiveWrappersEqual2,
|
|
2190
|
+
"[object Object]": (a, b, state) => (
|
|
2191
|
+
// The exception for value comparison is custom `Promise`-like class instances. These should
|
|
2192
|
+
// be treated the same as standard `Promise` objects, which means strict equality, and if
|
|
2193
|
+
// it reaches this point then that strict equality comparison has already failed.
|
|
2194
|
+
typeof a.then !== "function" && typeof b.then !== "function" && areObjectsEqual2(a, b, state)
|
|
2195
|
+
),
|
|
2196
|
+
// For RegExp, the properties are not enumerable, and therefore will give false positives if
|
|
2197
|
+
// tested like a standard object.
|
|
2198
|
+
"[object RegExp]": areRegExpsEqual2,
|
|
2199
|
+
"[object Set]": areSetsEqual2,
|
|
2200
|
+
"[object String]": arePrimitiveWrappersEqual2,
|
|
2201
|
+
"[object URL]": areUrlsEqual2,
|
|
2202
|
+
"[object Uint8Array]": areTypedArraysEqual2,
|
|
2203
|
+
"[object Uint8ClampedArray]": areTypedArraysEqual2,
|
|
2204
|
+
"[object Uint16Array]": areTypedArraysEqual2,
|
|
2205
|
+
"[object Uint32Array]": areTypedArraysEqual2
|
|
2206
|
+
};
|
|
2207
|
+
}
|
|
2208
|
+
const deepEqual = createCustomEqual();
|
|
2102
2209
|
createCustomEqual({ strict: true });
|
|
2103
2210
|
createCustomEqual({ circular: true });
|
|
2104
2211
|
createCustomEqual({
|
|
@@ -2106,1015 +2213,28 @@ createCustomEqual({
|
|
|
2106
2213
|
strict: true
|
|
2107
2214
|
});
|
|
2108
2215
|
createCustomEqual({
|
|
2109
|
-
createInternalComparator:
|
|
2110
|
-
return sameValueZeroEqual;
|
|
2111
|
-
}
|
|
2216
|
+
createInternalComparator: () => sameValueEqual
|
|
2112
2217
|
});
|
|
2113
2218
|
createCustomEqual({
|
|
2114
2219
|
strict: true,
|
|
2115
|
-
createInternalComparator:
|
|
2116
|
-
return sameValueZeroEqual;
|
|
2117
|
-
}
|
|
2220
|
+
createInternalComparator: () => sameValueEqual
|
|
2118
2221
|
});
|
|
2119
2222
|
createCustomEqual({
|
|
2120
2223
|
circular: true,
|
|
2121
|
-
createInternalComparator:
|
|
2122
|
-
return sameValueZeroEqual;
|
|
2123
|
-
}
|
|
2224
|
+
createInternalComparator: () => sameValueEqual
|
|
2124
2225
|
});
|
|
2125
2226
|
createCustomEqual({
|
|
2126
2227
|
circular: true,
|
|
2127
|
-
createInternalComparator:
|
|
2128
|
-
return sameValueZeroEqual;
|
|
2129
|
-
},
|
|
2228
|
+
createInternalComparator: () => sameValueEqual,
|
|
2130
2229
|
strict: true
|
|
2131
2230
|
});
|
|
2132
|
-
function createCustomEqual(options) {
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
var config = createEqualityComparatorConfig(options);
|
|
2138
|
-
var comparator = createEqualityComparator(config);
|
|
2139
|
-
var equals = createCustomInternalComparator ? createCustomInternalComparator(comparator) : createInternalEqualityComparator(comparator);
|
|
2231
|
+
function createCustomEqual(options = {}) {
|
|
2232
|
+
const { circular = false, createInternalComparator: createCustomInternalComparator, createState, strict = false } = options;
|
|
2233
|
+
const config = createEqualityComparatorConfig(options);
|
|
2234
|
+
const comparator = createEqualityComparator(config);
|
|
2235
|
+
const equals = createCustomInternalComparator ? createCustomInternalComparator(comparator) : createInternalEqualityComparator(comparator);
|
|
2140
2236
|
return createIsEqual({ circular, comparator, createState, equals, strict });
|
|
2141
2237
|
}
|
|
2142
|
-
function listCacheClear$1() {
|
|
2143
|
-
this.__data__ = [];
|
|
2144
|
-
this.size = 0;
|
|
2145
|
-
}
|
|
2146
|
-
var _listCacheClear = listCacheClear$1;
|
|
2147
|
-
function eq$2(value, other) {
|
|
2148
|
-
return value === other || value !== value && other !== other;
|
|
2149
|
-
}
|
|
2150
|
-
var eq_1 = eq$2;
|
|
2151
|
-
var eq$1 = eq_1;
|
|
2152
|
-
function assocIndexOf$4(array, key) {
|
|
2153
|
-
var length = array.length;
|
|
2154
|
-
while (length--) {
|
|
2155
|
-
if (eq$1(array[length][0], key)) {
|
|
2156
|
-
return length;
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
return -1;
|
|
2160
|
-
}
|
|
2161
|
-
var _assocIndexOf = assocIndexOf$4;
|
|
2162
|
-
var assocIndexOf$3 = _assocIndexOf;
|
|
2163
|
-
var arrayProto = Array.prototype;
|
|
2164
|
-
var splice = arrayProto.splice;
|
|
2165
|
-
function listCacheDelete$1(key) {
|
|
2166
|
-
var data = this.__data__, index = assocIndexOf$3(data, key);
|
|
2167
|
-
if (index < 0) {
|
|
2168
|
-
return false;
|
|
2169
|
-
}
|
|
2170
|
-
var lastIndex = data.length - 1;
|
|
2171
|
-
if (index == lastIndex) {
|
|
2172
|
-
data.pop();
|
|
2173
|
-
} else {
|
|
2174
|
-
splice.call(data, index, 1);
|
|
2175
|
-
}
|
|
2176
|
-
--this.size;
|
|
2177
|
-
return true;
|
|
2178
|
-
}
|
|
2179
|
-
var _listCacheDelete = listCacheDelete$1;
|
|
2180
|
-
var assocIndexOf$2 = _assocIndexOf;
|
|
2181
|
-
function listCacheGet$1(key) {
|
|
2182
|
-
var data = this.__data__, index = assocIndexOf$2(data, key);
|
|
2183
|
-
return index < 0 ? void 0 : data[index][1];
|
|
2184
|
-
}
|
|
2185
|
-
var _listCacheGet = listCacheGet$1;
|
|
2186
|
-
var assocIndexOf$1 = _assocIndexOf;
|
|
2187
|
-
function listCacheHas$1(key) {
|
|
2188
|
-
return assocIndexOf$1(this.__data__, key) > -1;
|
|
2189
|
-
}
|
|
2190
|
-
var _listCacheHas = listCacheHas$1;
|
|
2191
|
-
var assocIndexOf = _assocIndexOf;
|
|
2192
|
-
function listCacheSet$1(key, value) {
|
|
2193
|
-
var data = this.__data__, index = assocIndexOf(data, key);
|
|
2194
|
-
if (index < 0) {
|
|
2195
|
-
++this.size;
|
|
2196
|
-
data.push([key, value]);
|
|
2197
|
-
} else {
|
|
2198
|
-
data[index][1] = value;
|
|
2199
|
-
}
|
|
2200
|
-
return this;
|
|
2201
|
-
}
|
|
2202
|
-
var _listCacheSet = listCacheSet$1;
|
|
2203
|
-
var listCacheClear = _listCacheClear, listCacheDelete = _listCacheDelete, listCacheGet = _listCacheGet, listCacheHas = _listCacheHas, listCacheSet = _listCacheSet;
|
|
2204
|
-
function ListCache$4(entries) {
|
|
2205
|
-
var index = -1, length = entries == null ? 0 : entries.length;
|
|
2206
|
-
this.clear();
|
|
2207
|
-
while (++index < length) {
|
|
2208
|
-
var entry = entries[index];
|
|
2209
|
-
this.set(entry[0], entry[1]);
|
|
2210
|
-
}
|
|
2211
|
-
}
|
|
2212
|
-
ListCache$4.prototype.clear = listCacheClear;
|
|
2213
|
-
ListCache$4.prototype["delete"] = listCacheDelete;
|
|
2214
|
-
ListCache$4.prototype.get = listCacheGet;
|
|
2215
|
-
ListCache$4.prototype.has = listCacheHas;
|
|
2216
|
-
ListCache$4.prototype.set = listCacheSet;
|
|
2217
|
-
var _ListCache = ListCache$4;
|
|
2218
|
-
var ListCache$3 = _ListCache;
|
|
2219
|
-
function stackClear$1() {
|
|
2220
|
-
this.__data__ = new ListCache$3();
|
|
2221
|
-
this.size = 0;
|
|
2222
|
-
}
|
|
2223
|
-
var _stackClear = stackClear$1;
|
|
2224
|
-
function stackDelete$1(key) {
|
|
2225
|
-
var data = this.__data__, result = data["delete"](key);
|
|
2226
|
-
this.size = data.size;
|
|
2227
|
-
return result;
|
|
2228
|
-
}
|
|
2229
|
-
var _stackDelete = stackDelete$1;
|
|
2230
|
-
function stackGet$1(key) {
|
|
2231
|
-
return this.__data__.get(key);
|
|
2232
|
-
}
|
|
2233
|
-
var _stackGet = stackGet$1;
|
|
2234
|
-
function stackHas$1(key) {
|
|
2235
|
-
return this.__data__.has(key);
|
|
2236
|
-
}
|
|
2237
|
-
var _stackHas = stackHas$1;
|
|
2238
|
-
var freeGlobal$1 = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
|
|
2239
|
-
var _freeGlobal = freeGlobal$1;
|
|
2240
|
-
var freeGlobal = _freeGlobal;
|
|
2241
|
-
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
2242
|
-
var root$8 = freeGlobal || freeSelf || Function("return this")();
|
|
2243
|
-
var _root = root$8;
|
|
2244
|
-
var root$7 = _root;
|
|
2245
|
-
var Symbol$4 = root$7.Symbol;
|
|
2246
|
-
var _Symbol = Symbol$4;
|
|
2247
|
-
var Symbol$3 = _Symbol;
|
|
2248
|
-
var objectProto$c = Object.prototype;
|
|
2249
|
-
var hasOwnProperty$9 = objectProto$c.hasOwnProperty;
|
|
2250
|
-
var nativeObjectToString$1 = objectProto$c.toString;
|
|
2251
|
-
var symToStringTag$1 = Symbol$3 ? Symbol$3.toStringTag : void 0;
|
|
2252
|
-
function getRawTag$1(value) {
|
|
2253
|
-
var isOwn = hasOwnProperty$9.call(value, symToStringTag$1), tag = value[symToStringTag$1];
|
|
2254
|
-
try {
|
|
2255
|
-
value[symToStringTag$1] = void 0;
|
|
2256
|
-
var unmasked = true;
|
|
2257
|
-
} catch (e) {
|
|
2258
|
-
}
|
|
2259
|
-
var result = nativeObjectToString$1.call(value);
|
|
2260
|
-
if (unmasked) {
|
|
2261
|
-
if (isOwn) {
|
|
2262
|
-
value[symToStringTag$1] = tag;
|
|
2263
|
-
} else {
|
|
2264
|
-
delete value[symToStringTag$1];
|
|
2265
|
-
}
|
|
2266
|
-
}
|
|
2267
|
-
return result;
|
|
2268
|
-
}
|
|
2269
|
-
var _getRawTag = getRawTag$1;
|
|
2270
|
-
var objectProto$b = Object.prototype;
|
|
2271
|
-
var nativeObjectToString = objectProto$b.toString;
|
|
2272
|
-
function objectToString$1(value) {
|
|
2273
|
-
return nativeObjectToString.call(value);
|
|
2274
|
-
}
|
|
2275
|
-
var _objectToString = objectToString$1;
|
|
2276
|
-
var Symbol$2 = _Symbol, getRawTag = _getRawTag, objectToString = _objectToString;
|
|
2277
|
-
var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
|
|
2278
|
-
var symToStringTag = Symbol$2 ? Symbol$2.toStringTag : void 0;
|
|
2279
|
-
function baseGetTag$4(value) {
|
|
2280
|
-
if (value == null) {
|
|
2281
|
-
return value === void 0 ? undefinedTag : nullTag;
|
|
2282
|
-
}
|
|
2283
|
-
return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
|
|
2284
|
-
}
|
|
2285
|
-
var _baseGetTag = baseGetTag$4;
|
|
2286
|
-
function isObject$5(value) {
|
|
2287
|
-
var type = typeof value;
|
|
2288
|
-
return value != null && (type == "object" || type == "function");
|
|
2289
|
-
}
|
|
2290
|
-
var isObject_1 = isObject$5;
|
|
2291
|
-
var baseGetTag$3 = _baseGetTag, isObject$4 = isObject_1;
|
|
2292
|
-
var asyncTag = "[object AsyncFunction]", funcTag$2 = "[object Function]", genTag$1 = "[object GeneratorFunction]", proxyTag = "[object Proxy]";
|
|
2293
|
-
function isFunction$2(value) {
|
|
2294
|
-
if (!isObject$4(value)) {
|
|
2295
|
-
return false;
|
|
2296
|
-
}
|
|
2297
|
-
var tag = baseGetTag$3(value);
|
|
2298
|
-
return tag == funcTag$2 || tag == genTag$1 || tag == asyncTag || tag == proxyTag;
|
|
2299
|
-
}
|
|
2300
|
-
var isFunction_1 = isFunction$2;
|
|
2301
|
-
var root$6 = _root;
|
|
2302
|
-
var coreJsData$1 = root$6["__core-js_shared__"];
|
|
2303
|
-
var _coreJsData = coreJsData$1;
|
|
2304
|
-
var coreJsData = _coreJsData;
|
|
2305
|
-
var maskSrcKey = function() {
|
|
2306
|
-
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || "");
|
|
2307
|
-
return uid ? "Symbol(src)_1." + uid : "";
|
|
2308
|
-
}();
|
|
2309
|
-
function isMasked$1(func) {
|
|
2310
|
-
return !!maskSrcKey && maskSrcKey in func;
|
|
2311
|
-
}
|
|
2312
|
-
var _isMasked = isMasked$1;
|
|
2313
|
-
var funcProto$1 = Function.prototype;
|
|
2314
|
-
var funcToString$1 = funcProto$1.toString;
|
|
2315
|
-
function toSource$2(func) {
|
|
2316
|
-
if (func != null) {
|
|
2317
|
-
try {
|
|
2318
|
-
return funcToString$1.call(func);
|
|
2319
|
-
} catch (e) {
|
|
2320
|
-
}
|
|
2321
|
-
try {
|
|
2322
|
-
return func + "";
|
|
2323
|
-
} catch (e) {
|
|
2324
|
-
}
|
|
2325
|
-
}
|
|
2326
|
-
return "";
|
|
2327
|
-
}
|
|
2328
|
-
var _toSource = toSource$2;
|
|
2329
|
-
var isFunction$1 = isFunction_1, isMasked = _isMasked, isObject$3 = isObject_1, toSource$1 = _toSource;
|
|
2330
|
-
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
|
2331
|
-
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
2332
|
-
var funcProto = Function.prototype, objectProto$a = Object.prototype;
|
|
2333
|
-
var funcToString = funcProto.toString;
|
|
2334
|
-
var hasOwnProperty$8 = objectProto$a.hasOwnProperty;
|
|
2335
|
-
var reIsNative = RegExp(
|
|
2336
|
-
"^" + funcToString.call(hasOwnProperty$8).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
|
|
2337
|
-
);
|
|
2338
|
-
function baseIsNative$1(value) {
|
|
2339
|
-
if (!isObject$3(value) || isMasked(value)) {
|
|
2340
|
-
return false;
|
|
2341
|
-
}
|
|
2342
|
-
var pattern = isFunction$1(value) ? reIsNative : reIsHostCtor;
|
|
2343
|
-
return pattern.test(toSource$1(value));
|
|
2344
|
-
}
|
|
2345
|
-
var _baseIsNative = baseIsNative$1;
|
|
2346
|
-
function getValue$1(object, key) {
|
|
2347
|
-
return object == null ? void 0 : object[key];
|
|
2348
|
-
}
|
|
2349
|
-
var _getValue = getValue$1;
|
|
2350
|
-
var baseIsNative = _baseIsNative, getValue = _getValue;
|
|
2351
|
-
function getNative$7(object, key) {
|
|
2352
|
-
var value = getValue(object, key);
|
|
2353
|
-
return baseIsNative(value) ? value : void 0;
|
|
2354
|
-
}
|
|
2355
|
-
var _getNative = getNative$7;
|
|
2356
|
-
var getNative$6 = _getNative, root$5 = _root;
|
|
2357
|
-
var Map$4 = getNative$6(root$5, "Map");
|
|
2358
|
-
var _Map = Map$4;
|
|
2359
|
-
var getNative$5 = _getNative;
|
|
2360
|
-
var nativeCreate$4 = getNative$5(Object, "create");
|
|
2361
|
-
var _nativeCreate = nativeCreate$4;
|
|
2362
|
-
var nativeCreate$3 = _nativeCreate;
|
|
2363
|
-
function hashClear$1() {
|
|
2364
|
-
this.__data__ = nativeCreate$3 ? nativeCreate$3(null) : {};
|
|
2365
|
-
this.size = 0;
|
|
2366
|
-
}
|
|
2367
|
-
var _hashClear = hashClear$1;
|
|
2368
|
-
function hashDelete$1(key) {
|
|
2369
|
-
var result = this.has(key) && delete this.__data__[key];
|
|
2370
|
-
this.size -= result ? 1 : 0;
|
|
2371
|
-
return result;
|
|
2372
|
-
}
|
|
2373
|
-
var _hashDelete = hashDelete$1;
|
|
2374
|
-
var nativeCreate$2 = _nativeCreate;
|
|
2375
|
-
var HASH_UNDEFINED$1 = "__lodash_hash_undefined__";
|
|
2376
|
-
var objectProto$9 = Object.prototype;
|
|
2377
|
-
var hasOwnProperty$7 = objectProto$9.hasOwnProperty;
|
|
2378
|
-
function hashGet$1(key) {
|
|
2379
|
-
var data = this.__data__;
|
|
2380
|
-
if (nativeCreate$2) {
|
|
2381
|
-
var result = data[key];
|
|
2382
|
-
return result === HASH_UNDEFINED$1 ? void 0 : result;
|
|
2383
|
-
}
|
|
2384
|
-
return hasOwnProperty$7.call(data, key) ? data[key] : void 0;
|
|
2385
|
-
}
|
|
2386
|
-
var _hashGet = hashGet$1;
|
|
2387
|
-
var nativeCreate$1 = _nativeCreate;
|
|
2388
|
-
var objectProto$8 = Object.prototype;
|
|
2389
|
-
var hasOwnProperty$6 = objectProto$8.hasOwnProperty;
|
|
2390
|
-
function hashHas$1(key) {
|
|
2391
|
-
var data = this.__data__;
|
|
2392
|
-
return nativeCreate$1 ? data[key] !== void 0 : hasOwnProperty$6.call(data, key);
|
|
2393
|
-
}
|
|
2394
|
-
var _hashHas = hashHas$1;
|
|
2395
|
-
var nativeCreate = _nativeCreate;
|
|
2396
|
-
var HASH_UNDEFINED = "__lodash_hash_undefined__";
|
|
2397
|
-
function hashSet$1(key, value) {
|
|
2398
|
-
var data = this.__data__;
|
|
2399
|
-
this.size += this.has(key) ? 0 : 1;
|
|
2400
|
-
data[key] = nativeCreate && value === void 0 ? HASH_UNDEFINED : value;
|
|
2401
|
-
return this;
|
|
2402
|
-
}
|
|
2403
|
-
var _hashSet = hashSet$1;
|
|
2404
|
-
var hashClear = _hashClear, hashDelete = _hashDelete, hashGet = _hashGet, hashHas = _hashHas, hashSet = _hashSet;
|
|
2405
|
-
function Hash$1(entries) {
|
|
2406
|
-
var index = -1, length = entries == null ? 0 : entries.length;
|
|
2407
|
-
this.clear();
|
|
2408
|
-
while (++index < length) {
|
|
2409
|
-
var entry = entries[index];
|
|
2410
|
-
this.set(entry[0], entry[1]);
|
|
2411
|
-
}
|
|
2412
|
-
}
|
|
2413
|
-
Hash$1.prototype.clear = hashClear;
|
|
2414
|
-
Hash$1.prototype["delete"] = hashDelete;
|
|
2415
|
-
Hash$1.prototype.get = hashGet;
|
|
2416
|
-
Hash$1.prototype.has = hashHas;
|
|
2417
|
-
Hash$1.prototype.set = hashSet;
|
|
2418
|
-
var _Hash = Hash$1;
|
|
2419
|
-
var Hash = _Hash, ListCache$2 = _ListCache, Map$3 = _Map;
|
|
2420
|
-
function mapCacheClear$1() {
|
|
2421
|
-
this.size = 0;
|
|
2422
|
-
this.__data__ = {
|
|
2423
|
-
"hash": new Hash(),
|
|
2424
|
-
"map": new (Map$3 || ListCache$2)(),
|
|
2425
|
-
"string": new Hash()
|
|
2426
|
-
};
|
|
2427
|
-
}
|
|
2428
|
-
var _mapCacheClear = mapCacheClear$1;
|
|
2429
|
-
function isKeyable$1(value) {
|
|
2430
|
-
var type = typeof value;
|
|
2431
|
-
return type == "string" || type == "number" || type == "symbol" || type == "boolean" ? value !== "__proto__" : value === null;
|
|
2432
|
-
}
|
|
2433
|
-
var _isKeyable = isKeyable$1;
|
|
2434
|
-
var isKeyable = _isKeyable;
|
|
2435
|
-
function getMapData$4(map, key) {
|
|
2436
|
-
var data = map.__data__;
|
|
2437
|
-
return isKeyable(key) ? data[typeof key == "string" ? "string" : "hash"] : data.map;
|
|
2438
|
-
}
|
|
2439
|
-
var _getMapData = getMapData$4;
|
|
2440
|
-
var getMapData$3 = _getMapData;
|
|
2441
|
-
function mapCacheDelete$1(key) {
|
|
2442
|
-
var result = getMapData$3(this, key)["delete"](key);
|
|
2443
|
-
this.size -= result ? 1 : 0;
|
|
2444
|
-
return result;
|
|
2445
|
-
}
|
|
2446
|
-
var _mapCacheDelete = mapCacheDelete$1;
|
|
2447
|
-
var getMapData$2 = _getMapData;
|
|
2448
|
-
function mapCacheGet$1(key) {
|
|
2449
|
-
return getMapData$2(this, key).get(key);
|
|
2450
|
-
}
|
|
2451
|
-
var _mapCacheGet = mapCacheGet$1;
|
|
2452
|
-
var getMapData$1 = _getMapData;
|
|
2453
|
-
function mapCacheHas$1(key) {
|
|
2454
|
-
return getMapData$1(this, key).has(key);
|
|
2455
|
-
}
|
|
2456
|
-
var _mapCacheHas = mapCacheHas$1;
|
|
2457
|
-
var getMapData = _getMapData;
|
|
2458
|
-
function mapCacheSet$1(key, value) {
|
|
2459
|
-
var data = getMapData(this, key), size = data.size;
|
|
2460
|
-
data.set(key, value);
|
|
2461
|
-
this.size += data.size == size ? 0 : 1;
|
|
2462
|
-
return this;
|
|
2463
|
-
}
|
|
2464
|
-
var _mapCacheSet = mapCacheSet$1;
|
|
2465
|
-
var mapCacheClear = _mapCacheClear, mapCacheDelete = _mapCacheDelete, mapCacheGet = _mapCacheGet, mapCacheHas = _mapCacheHas, mapCacheSet = _mapCacheSet;
|
|
2466
|
-
function MapCache$1(entries) {
|
|
2467
|
-
var index = -1, length = entries == null ? 0 : entries.length;
|
|
2468
|
-
this.clear();
|
|
2469
|
-
while (++index < length) {
|
|
2470
|
-
var entry = entries[index];
|
|
2471
|
-
this.set(entry[0], entry[1]);
|
|
2472
|
-
}
|
|
2473
|
-
}
|
|
2474
|
-
MapCache$1.prototype.clear = mapCacheClear;
|
|
2475
|
-
MapCache$1.prototype["delete"] = mapCacheDelete;
|
|
2476
|
-
MapCache$1.prototype.get = mapCacheGet;
|
|
2477
|
-
MapCache$1.prototype.has = mapCacheHas;
|
|
2478
|
-
MapCache$1.prototype.set = mapCacheSet;
|
|
2479
|
-
var _MapCache = MapCache$1;
|
|
2480
|
-
var ListCache$1 = _ListCache, Map$2 = _Map, MapCache = _MapCache;
|
|
2481
|
-
var LARGE_ARRAY_SIZE = 200;
|
|
2482
|
-
function stackSet$1(key, value) {
|
|
2483
|
-
var data = this.__data__;
|
|
2484
|
-
if (data instanceof ListCache$1) {
|
|
2485
|
-
var pairs = data.__data__;
|
|
2486
|
-
if (!Map$2 || pairs.length < LARGE_ARRAY_SIZE - 1) {
|
|
2487
|
-
pairs.push([key, value]);
|
|
2488
|
-
this.size = ++data.size;
|
|
2489
|
-
return this;
|
|
2490
|
-
}
|
|
2491
|
-
data = this.__data__ = new MapCache(pairs);
|
|
2492
|
-
}
|
|
2493
|
-
data.set(key, value);
|
|
2494
|
-
this.size = data.size;
|
|
2495
|
-
return this;
|
|
2496
|
-
}
|
|
2497
|
-
var _stackSet = stackSet$1;
|
|
2498
|
-
var ListCache = _ListCache, stackClear = _stackClear, stackDelete = _stackDelete, stackGet = _stackGet, stackHas = _stackHas, stackSet = _stackSet;
|
|
2499
|
-
function Stack$1(entries) {
|
|
2500
|
-
var data = this.__data__ = new ListCache(entries);
|
|
2501
|
-
this.size = data.size;
|
|
2502
|
-
}
|
|
2503
|
-
Stack$1.prototype.clear = stackClear;
|
|
2504
|
-
Stack$1.prototype["delete"] = stackDelete;
|
|
2505
|
-
Stack$1.prototype.get = stackGet;
|
|
2506
|
-
Stack$1.prototype.has = stackHas;
|
|
2507
|
-
Stack$1.prototype.set = stackSet;
|
|
2508
|
-
var _Stack = Stack$1;
|
|
2509
|
-
function arrayEach$1(array, iteratee) {
|
|
2510
|
-
var index = -1, length = array == null ? 0 : array.length;
|
|
2511
|
-
while (++index < length) {
|
|
2512
|
-
if (iteratee(array[index], index, array) === false) {
|
|
2513
|
-
break;
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
return array;
|
|
2517
|
-
}
|
|
2518
|
-
var _arrayEach = arrayEach$1;
|
|
2519
|
-
var getNative$4 = _getNative;
|
|
2520
|
-
var defineProperty$1 = function() {
|
|
2521
|
-
try {
|
|
2522
|
-
var func = getNative$4(Object, "defineProperty");
|
|
2523
|
-
func({}, "", {});
|
|
2524
|
-
return func;
|
|
2525
|
-
} catch (e) {
|
|
2526
|
-
}
|
|
2527
|
-
}();
|
|
2528
|
-
var _defineProperty = defineProperty$1;
|
|
2529
|
-
var defineProperty = _defineProperty;
|
|
2530
|
-
function baseAssignValue$2(object, key, value) {
|
|
2531
|
-
if (key == "__proto__" && defineProperty) {
|
|
2532
|
-
defineProperty(object, key, {
|
|
2533
|
-
"configurable": true,
|
|
2534
|
-
"enumerable": true,
|
|
2535
|
-
"value": value,
|
|
2536
|
-
"writable": true
|
|
2537
|
-
});
|
|
2538
|
-
} else {
|
|
2539
|
-
object[key] = value;
|
|
2540
|
-
}
|
|
2541
|
-
}
|
|
2542
|
-
var _baseAssignValue = baseAssignValue$2;
|
|
2543
|
-
var baseAssignValue$1 = _baseAssignValue, eq = eq_1;
|
|
2544
|
-
var objectProto$7 = Object.prototype;
|
|
2545
|
-
var hasOwnProperty$5 = objectProto$7.hasOwnProperty;
|
|
2546
|
-
function assignValue$2(object, key, value) {
|
|
2547
|
-
var objValue = object[key];
|
|
2548
|
-
if (!(hasOwnProperty$5.call(object, key) && eq(objValue, value)) || value === void 0 && !(key in object)) {
|
|
2549
|
-
baseAssignValue$1(object, key, value);
|
|
2550
|
-
}
|
|
2551
|
-
}
|
|
2552
|
-
var _assignValue = assignValue$2;
|
|
2553
|
-
var assignValue$1 = _assignValue, baseAssignValue = _baseAssignValue;
|
|
2554
|
-
function copyObject$4(source, props, object, customizer) {
|
|
2555
|
-
var isNew = !object;
|
|
2556
|
-
object || (object = {});
|
|
2557
|
-
var index = -1, length = props.length;
|
|
2558
|
-
while (++index < length) {
|
|
2559
|
-
var key = props[index];
|
|
2560
|
-
var newValue = customizer ? customizer(object[key], source[key], key, object, source) : void 0;
|
|
2561
|
-
if (newValue === void 0) {
|
|
2562
|
-
newValue = source[key];
|
|
2563
|
-
}
|
|
2564
|
-
if (isNew) {
|
|
2565
|
-
baseAssignValue(object, key, newValue);
|
|
2566
|
-
} else {
|
|
2567
|
-
assignValue$1(object, key, newValue);
|
|
2568
|
-
}
|
|
2569
|
-
}
|
|
2570
|
-
return object;
|
|
2571
|
-
}
|
|
2572
|
-
var _copyObject = copyObject$4;
|
|
2573
|
-
function baseTimes$1(n, iteratee) {
|
|
2574
|
-
var index = -1, result = Array(n);
|
|
2575
|
-
while (++index < n) {
|
|
2576
|
-
result[index] = iteratee(index);
|
|
2577
|
-
}
|
|
2578
|
-
return result;
|
|
2579
|
-
}
|
|
2580
|
-
var _baseTimes = baseTimes$1;
|
|
2581
|
-
function isObjectLike$5(value) {
|
|
2582
|
-
return value != null && typeof value == "object";
|
|
2583
|
-
}
|
|
2584
|
-
var isObjectLike_1 = isObjectLike$5;
|
|
2585
|
-
var baseGetTag$2 = _baseGetTag, isObjectLike$4 = isObjectLike_1;
|
|
2586
|
-
var argsTag$2 = "[object Arguments]";
|
|
2587
|
-
function baseIsArguments$1(value) {
|
|
2588
|
-
return isObjectLike$4(value) && baseGetTag$2(value) == argsTag$2;
|
|
2589
|
-
}
|
|
2590
|
-
var _baseIsArguments = baseIsArguments$1;
|
|
2591
|
-
var baseIsArguments = _baseIsArguments, isObjectLike$3 = isObjectLike_1;
|
|
2592
|
-
var objectProto$6 = Object.prototype;
|
|
2593
|
-
var hasOwnProperty$4 = objectProto$6.hasOwnProperty;
|
|
2594
|
-
var propertyIsEnumerable$1 = objectProto$6.propertyIsEnumerable;
|
|
2595
|
-
var isArguments$1 = baseIsArguments(/* @__PURE__ */ function() {
|
|
2596
|
-
return arguments;
|
|
2597
|
-
}()) ? baseIsArguments : function(value) {
|
|
2598
|
-
return isObjectLike$3(value) && hasOwnProperty$4.call(value, "callee") && !propertyIsEnumerable$1.call(value, "callee");
|
|
2599
|
-
};
|
|
2600
|
-
var isArguments_1 = isArguments$1;
|
|
2601
|
-
var isArray$3 = Array.isArray;
|
|
2602
|
-
var isArray_1 = isArray$3;
|
|
2603
|
-
var isBuffer$2 = { exports: {} };
|
|
2604
|
-
function stubFalse() {
|
|
2605
|
-
return false;
|
|
2606
|
-
}
|
|
2607
|
-
var stubFalse_1 = stubFalse;
|
|
2608
|
-
isBuffer$2.exports;
|
|
2609
|
-
(function(module, exports$1) {
|
|
2610
|
-
var root2 = _root, stubFalse2 = stubFalse_1;
|
|
2611
|
-
var freeExports = exports$1 && !exports$1.nodeType && exports$1;
|
|
2612
|
-
var freeModule = freeExports && true && module && !module.nodeType && module;
|
|
2613
|
-
var moduleExports = freeModule && freeModule.exports === freeExports;
|
|
2614
|
-
var Buffer = moduleExports ? root2.Buffer : void 0;
|
|
2615
|
-
var nativeIsBuffer = Buffer ? Buffer.isBuffer : void 0;
|
|
2616
|
-
var isBuffer2 = nativeIsBuffer || stubFalse2;
|
|
2617
|
-
module.exports = isBuffer2;
|
|
2618
|
-
})(isBuffer$2, isBuffer$2.exports);
|
|
2619
|
-
var isBufferExports = isBuffer$2.exports;
|
|
2620
|
-
var MAX_SAFE_INTEGER$1 = 9007199254740991;
|
|
2621
|
-
var reIsUint = /^(?:0|[1-9]\d*)$/;
|
|
2622
|
-
function isIndex$1(value, length) {
|
|
2623
|
-
var type = typeof value;
|
|
2624
|
-
length = length == null ? MAX_SAFE_INTEGER$1 : length;
|
|
2625
|
-
return !!length && (type == "number" || type != "symbol" && reIsUint.test(value)) && (value > -1 && value % 1 == 0 && value < length);
|
|
2626
|
-
}
|
|
2627
|
-
var _isIndex = isIndex$1;
|
|
2628
|
-
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
2629
|
-
function isLength$2(value) {
|
|
2630
|
-
return typeof value == "number" && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
2631
|
-
}
|
|
2632
|
-
var isLength_1 = isLength$2;
|
|
2633
|
-
var baseGetTag$1 = _baseGetTag, isLength$1 = isLength_1, isObjectLike$2 = isObjectLike_1;
|
|
2634
|
-
var argsTag$1 = "[object Arguments]", arrayTag$1 = "[object Array]", boolTag$2 = "[object Boolean]", dateTag$2 = "[object Date]", errorTag$1 = "[object Error]", funcTag$1 = "[object Function]", mapTag$4 = "[object Map]", numberTag$2 = "[object Number]", objectTag$2 = "[object Object]", regexpTag$2 = "[object RegExp]", setTag$4 = "[object Set]", stringTag$2 = "[object String]", weakMapTag$2 = "[object WeakMap]";
|
|
2635
|
-
var arrayBufferTag$2 = "[object ArrayBuffer]", dataViewTag$3 = "[object DataView]", float32Tag$2 = "[object Float32Array]", float64Tag$2 = "[object Float64Array]", int8Tag$2 = "[object Int8Array]", int16Tag$2 = "[object Int16Array]", int32Tag$2 = "[object Int32Array]", uint8Tag$2 = "[object Uint8Array]", uint8ClampedTag$2 = "[object Uint8ClampedArray]", uint16Tag$2 = "[object Uint16Array]", uint32Tag$2 = "[object Uint32Array]";
|
|
2636
|
-
var typedArrayTags = {};
|
|
2637
|
-
typedArrayTags[float32Tag$2] = typedArrayTags[float64Tag$2] = typedArrayTags[int8Tag$2] = typedArrayTags[int16Tag$2] = typedArrayTags[int32Tag$2] = typedArrayTags[uint8Tag$2] = typedArrayTags[uint8ClampedTag$2] = typedArrayTags[uint16Tag$2] = typedArrayTags[uint32Tag$2] = true;
|
|
2638
|
-
typedArrayTags[argsTag$1] = typedArrayTags[arrayTag$1] = typedArrayTags[arrayBufferTag$2] = typedArrayTags[boolTag$2] = typedArrayTags[dataViewTag$3] = typedArrayTags[dateTag$2] = typedArrayTags[errorTag$1] = typedArrayTags[funcTag$1] = typedArrayTags[mapTag$4] = typedArrayTags[numberTag$2] = typedArrayTags[objectTag$2] = typedArrayTags[regexpTag$2] = typedArrayTags[setTag$4] = typedArrayTags[stringTag$2] = typedArrayTags[weakMapTag$2] = false;
|
|
2639
|
-
function baseIsTypedArray$1(value) {
|
|
2640
|
-
return isObjectLike$2(value) && isLength$1(value.length) && !!typedArrayTags[baseGetTag$1(value)];
|
|
2641
|
-
}
|
|
2642
|
-
var _baseIsTypedArray = baseIsTypedArray$1;
|
|
2643
|
-
function baseUnary$3(func) {
|
|
2644
|
-
return function(value) {
|
|
2645
|
-
return func(value);
|
|
2646
|
-
};
|
|
2647
|
-
}
|
|
2648
|
-
var _baseUnary = baseUnary$3;
|
|
2649
|
-
var _nodeUtil = { exports: {} };
|
|
2650
|
-
_nodeUtil.exports;
|
|
2651
|
-
(function(module, exports$1) {
|
|
2652
|
-
var freeGlobal2 = _freeGlobal;
|
|
2653
|
-
var freeExports = exports$1 && !exports$1.nodeType && exports$1;
|
|
2654
|
-
var freeModule = freeExports && true && module && !module.nodeType && module;
|
|
2655
|
-
var moduleExports = freeModule && freeModule.exports === freeExports;
|
|
2656
|
-
var freeProcess = moduleExports && freeGlobal2.process;
|
|
2657
|
-
var nodeUtil2 = function() {
|
|
2658
|
-
try {
|
|
2659
|
-
var types = freeModule && freeModule.require && freeModule.require("util").types;
|
|
2660
|
-
if (types) {
|
|
2661
|
-
return types;
|
|
2662
|
-
}
|
|
2663
|
-
return freeProcess && freeProcess.binding && freeProcess.binding("util");
|
|
2664
|
-
} catch (e) {
|
|
2665
|
-
}
|
|
2666
|
-
}();
|
|
2667
|
-
module.exports = nodeUtil2;
|
|
2668
|
-
})(_nodeUtil, _nodeUtil.exports);
|
|
2669
|
-
var _nodeUtilExports = _nodeUtil.exports;
|
|
2670
|
-
var baseIsTypedArray = _baseIsTypedArray, baseUnary$2 = _baseUnary, nodeUtil$2 = _nodeUtilExports;
|
|
2671
|
-
var nodeIsTypedArray = nodeUtil$2 && nodeUtil$2.isTypedArray;
|
|
2672
|
-
var isTypedArray$1 = nodeIsTypedArray ? baseUnary$2(nodeIsTypedArray) : baseIsTypedArray;
|
|
2673
|
-
var isTypedArray_1 = isTypedArray$1;
|
|
2674
|
-
var baseTimes = _baseTimes, isArguments = isArguments_1, isArray$2 = isArray_1, isBuffer$1 = isBufferExports, isIndex = _isIndex, isTypedArray = isTypedArray_1;
|
|
2675
|
-
var objectProto$5 = Object.prototype;
|
|
2676
|
-
var hasOwnProperty$3 = objectProto$5.hasOwnProperty;
|
|
2677
|
-
function arrayLikeKeys$2(value, inherited) {
|
|
2678
|
-
var isArr = isArray$2(value), isArg = !isArr && isArguments(value), isBuff = !isArr && !isArg && isBuffer$1(value), isType = !isArr && !isArg && !isBuff && isTypedArray(value), skipIndexes = isArr || isArg || isBuff || isType, result = skipIndexes ? baseTimes(value.length, String) : [], length = result.length;
|
|
2679
|
-
for (var key in value) {
|
|
2680
|
-
if ((inherited || hasOwnProperty$3.call(value, key)) && !(skipIndexes && // Safari 9 has enumerable `arguments.length` in strict mode.
|
|
2681
|
-
(key == "length" || // Node.js 0.10 has enumerable non-index properties on buffers.
|
|
2682
|
-
isBuff && (key == "offset" || key == "parent") || // PhantomJS 2 has enumerable non-index properties on typed arrays.
|
|
2683
|
-
isType && (key == "buffer" || key == "byteLength" || key == "byteOffset") || // Skip index properties.
|
|
2684
|
-
isIndex(key, length)))) {
|
|
2685
|
-
result.push(key);
|
|
2686
|
-
}
|
|
2687
|
-
}
|
|
2688
|
-
return result;
|
|
2689
|
-
}
|
|
2690
|
-
var _arrayLikeKeys = arrayLikeKeys$2;
|
|
2691
|
-
var objectProto$4 = Object.prototype;
|
|
2692
|
-
function isPrototype$3(value) {
|
|
2693
|
-
var Ctor = value && value.constructor, proto = typeof Ctor == "function" && Ctor.prototype || objectProto$4;
|
|
2694
|
-
return value === proto;
|
|
2695
|
-
}
|
|
2696
|
-
var _isPrototype = isPrototype$3;
|
|
2697
|
-
function overArg$2(func, transform) {
|
|
2698
|
-
return function(arg) {
|
|
2699
|
-
return func(transform(arg));
|
|
2700
|
-
};
|
|
2701
|
-
}
|
|
2702
|
-
var _overArg = overArg$2;
|
|
2703
|
-
var overArg$1 = _overArg;
|
|
2704
|
-
var nativeKeys$1 = overArg$1(Object.keys, Object);
|
|
2705
|
-
var _nativeKeys = nativeKeys$1;
|
|
2706
|
-
var isPrototype$2 = _isPrototype, nativeKeys = _nativeKeys;
|
|
2707
|
-
var objectProto$3 = Object.prototype;
|
|
2708
|
-
var hasOwnProperty$2 = objectProto$3.hasOwnProperty;
|
|
2709
|
-
function baseKeys$1(object) {
|
|
2710
|
-
if (!isPrototype$2(object)) {
|
|
2711
|
-
return nativeKeys(object);
|
|
2712
|
-
}
|
|
2713
|
-
var result = [];
|
|
2714
|
-
for (var key in Object(object)) {
|
|
2715
|
-
if (hasOwnProperty$2.call(object, key) && key != "constructor") {
|
|
2716
|
-
result.push(key);
|
|
2717
|
-
}
|
|
2718
|
-
}
|
|
2719
|
-
return result;
|
|
2720
|
-
}
|
|
2721
|
-
var _baseKeys = baseKeys$1;
|
|
2722
|
-
var isFunction = isFunction_1, isLength = isLength_1;
|
|
2723
|
-
function isArrayLike$2(value) {
|
|
2724
|
-
return value != null && isLength(value.length) && !isFunction(value);
|
|
2725
|
-
}
|
|
2726
|
-
var isArrayLike_1 = isArrayLike$2;
|
|
2727
|
-
var arrayLikeKeys$1 = _arrayLikeKeys, baseKeys = _baseKeys, isArrayLike$1 = isArrayLike_1;
|
|
2728
|
-
function keys$3(object) {
|
|
2729
|
-
return isArrayLike$1(object) ? arrayLikeKeys$1(object) : baseKeys(object);
|
|
2730
|
-
}
|
|
2731
|
-
var keys_1 = keys$3;
|
|
2732
|
-
var copyObject$3 = _copyObject, keys$2 = keys_1;
|
|
2733
|
-
function baseAssign$1(object, source) {
|
|
2734
|
-
return object && copyObject$3(source, keys$2(source), object);
|
|
2735
|
-
}
|
|
2736
|
-
var _baseAssign = baseAssign$1;
|
|
2737
|
-
function nativeKeysIn$1(object) {
|
|
2738
|
-
var result = [];
|
|
2739
|
-
if (object != null) {
|
|
2740
|
-
for (var key in Object(object)) {
|
|
2741
|
-
result.push(key);
|
|
2742
|
-
}
|
|
2743
|
-
}
|
|
2744
|
-
return result;
|
|
2745
|
-
}
|
|
2746
|
-
var _nativeKeysIn = nativeKeysIn$1;
|
|
2747
|
-
var isObject$2 = isObject_1, isPrototype$1 = _isPrototype, nativeKeysIn = _nativeKeysIn;
|
|
2748
|
-
var objectProto$2 = Object.prototype;
|
|
2749
|
-
var hasOwnProperty$1 = objectProto$2.hasOwnProperty;
|
|
2750
|
-
function baseKeysIn$1(object) {
|
|
2751
|
-
if (!isObject$2(object)) {
|
|
2752
|
-
return nativeKeysIn(object);
|
|
2753
|
-
}
|
|
2754
|
-
var isProto = isPrototype$1(object), result = [];
|
|
2755
|
-
for (var key in object) {
|
|
2756
|
-
if (!(key == "constructor" && (isProto || !hasOwnProperty$1.call(object, key)))) {
|
|
2757
|
-
result.push(key);
|
|
2758
|
-
}
|
|
2759
|
-
}
|
|
2760
|
-
return result;
|
|
2761
|
-
}
|
|
2762
|
-
var _baseKeysIn = baseKeysIn$1;
|
|
2763
|
-
var arrayLikeKeys = _arrayLikeKeys, baseKeysIn = _baseKeysIn, isArrayLike = isArrayLike_1;
|
|
2764
|
-
function keysIn$3(object) {
|
|
2765
|
-
return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
|
|
2766
|
-
}
|
|
2767
|
-
var keysIn_1 = keysIn$3;
|
|
2768
|
-
var copyObject$2 = _copyObject, keysIn$2 = keysIn_1;
|
|
2769
|
-
function baseAssignIn$1(object, source) {
|
|
2770
|
-
return object && copyObject$2(source, keysIn$2(source), object);
|
|
2771
|
-
}
|
|
2772
|
-
var _baseAssignIn = baseAssignIn$1;
|
|
2773
|
-
var _cloneBuffer = { exports: {} };
|
|
2774
|
-
_cloneBuffer.exports;
|
|
2775
|
-
(function(module, exports$1) {
|
|
2776
|
-
var root2 = _root;
|
|
2777
|
-
var freeExports = exports$1 && !exports$1.nodeType && exports$1;
|
|
2778
|
-
var freeModule = freeExports && true && module && !module.nodeType && module;
|
|
2779
|
-
var moduleExports = freeModule && freeModule.exports === freeExports;
|
|
2780
|
-
var Buffer = moduleExports ? root2.Buffer : void 0, allocUnsafe = Buffer ? Buffer.allocUnsafe : void 0;
|
|
2781
|
-
function cloneBuffer2(buffer, isDeep) {
|
|
2782
|
-
if (isDeep) {
|
|
2783
|
-
return buffer.slice();
|
|
2784
|
-
}
|
|
2785
|
-
var length = buffer.length, result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
|
|
2786
|
-
buffer.copy(result);
|
|
2787
|
-
return result;
|
|
2788
|
-
}
|
|
2789
|
-
module.exports = cloneBuffer2;
|
|
2790
|
-
})(_cloneBuffer, _cloneBuffer.exports);
|
|
2791
|
-
var _cloneBufferExports = _cloneBuffer.exports;
|
|
2792
|
-
function copyArray$1(source, array) {
|
|
2793
|
-
var index = -1, length = source.length;
|
|
2794
|
-
array || (array = Array(length));
|
|
2795
|
-
while (++index < length) {
|
|
2796
|
-
array[index] = source[index];
|
|
2797
|
-
}
|
|
2798
|
-
return array;
|
|
2799
|
-
}
|
|
2800
|
-
var _copyArray = copyArray$1;
|
|
2801
|
-
function arrayFilter$1(array, predicate) {
|
|
2802
|
-
var index = -1, length = array == null ? 0 : array.length, resIndex = 0, result = [];
|
|
2803
|
-
while (++index < length) {
|
|
2804
|
-
var value = array[index];
|
|
2805
|
-
if (predicate(value, index, array)) {
|
|
2806
|
-
result[resIndex++] = value;
|
|
2807
|
-
}
|
|
2808
|
-
}
|
|
2809
|
-
return result;
|
|
2810
|
-
}
|
|
2811
|
-
var _arrayFilter = arrayFilter$1;
|
|
2812
|
-
function stubArray$2() {
|
|
2813
|
-
return [];
|
|
2814
|
-
}
|
|
2815
|
-
var stubArray_1 = stubArray$2;
|
|
2816
|
-
var arrayFilter = _arrayFilter, stubArray$1 = stubArray_1;
|
|
2817
|
-
var objectProto$1 = Object.prototype;
|
|
2818
|
-
var propertyIsEnumerable = objectProto$1.propertyIsEnumerable;
|
|
2819
|
-
var nativeGetSymbols$1 = Object.getOwnPropertySymbols;
|
|
2820
|
-
var getSymbols$3 = !nativeGetSymbols$1 ? stubArray$1 : function(object) {
|
|
2821
|
-
if (object == null) {
|
|
2822
|
-
return [];
|
|
2823
|
-
}
|
|
2824
|
-
object = Object(object);
|
|
2825
|
-
return arrayFilter(nativeGetSymbols$1(object), function(symbol) {
|
|
2826
|
-
return propertyIsEnumerable.call(object, symbol);
|
|
2827
|
-
});
|
|
2828
|
-
};
|
|
2829
|
-
var _getSymbols = getSymbols$3;
|
|
2830
|
-
var copyObject$1 = _copyObject, getSymbols$2 = _getSymbols;
|
|
2831
|
-
function copySymbols$1(source, object) {
|
|
2832
|
-
return copyObject$1(source, getSymbols$2(source), object);
|
|
2833
|
-
}
|
|
2834
|
-
var _copySymbols = copySymbols$1;
|
|
2835
|
-
function arrayPush$2(array, values) {
|
|
2836
|
-
var index = -1, length = values.length, offset = array.length;
|
|
2837
|
-
while (++index < length) {
|
|
2838
|
-
array[offset + index] = values[index];
|
|
2839
|
-
}
|
|
2840
|
-
return array;
|
|
2841
|
-
}
|
|
2842
|
-
var _arrayPush = arrayPush$2;
|
|
2843
|
-
var overArg = _overArg;
|
|
2844
|
-
var getPrototype$2 = overArg(Object.getPrototypeOf, Object);
|
|
2845
|
-
var _getPrototype = getPrototype$2;
|
|
2846
|
-
var arrayPush$1 = _arrayPush, getPrototype$1 = _getPrototype, getSymbols$1 = _getSymbols, stubArray = stubArray_1;
|
|
2847
|
-
var nativeGetSymbols = Object.getOwnPropertySymbols;
|
|
2848
|
-
var getSymbolsIn$2 = !nativeGetSymbols ? stubArray : function(object) {
|
|
2849
|
-
var result = [];
|
|
2850
|
-
while (object) {
|
|
2851
|
-
arrayPush$1(result, getSymbols$1(object));
|
|
2852
|
-
object = getPrototype$1(object);
|
|
2853
|
-
}
|
|
2854
|
-
return result;
|
|
2855
|
-
};
|
|
2856
|
-
var _getSymbolsIn = getSymbolsIn$2;
|
|
2857
|
-
var copyObject = _copyObject, getSymbolsIn$1 = _getSymbolsIn;
|
|
2858
|
-
function copySymbolsIn$1(source, object) {
|
|
2859
|
-
return copyObject(source, getSymbolsIn$1(source), object);
|
|
2860
|
-
}
|
|
2861
|
-
var _copySymbolsIn = copySymbolsIn$1;
|
|
2862
|
-
var arrayPush = _arrayPush, isArray$1 = isArray_1;
|
|
2863
|
-
function baseGetAllKeys$2(object, keysFunc, symbolsFunc) {
|
|
2864
|
-
var result = keysFunc(object);
|
|
2865
|
-
return isArray$1(object) ? result : arrayPush(result, symbolsFunc(object));
|
|
2866
|
-
}
|
|
2867
|
-
var _baseGetAllKeys = baseGetAllKeys$2;
|
|
2868
|
-
var baseGetAllKeys$1 = _baseGetAllKeys, getSymbols = _getSymbols, keys$1 = keys_1;
|
|
2869
|
-
function getAllKeys$1(object) {
|
|
2870
|
-
return baseGetAllKeys$1(object, keys$1, getSymbols);
|
|
2871
|
-
}
|
|
2872
|
-
var _getAllKeys = getAllKeys$1;
|
|
2873
|
-
var baseGetAllKeys = _baseGetAllKeys, getSymbolsIn = _getSymbolsIn, keysIn$1 = keysIn_1;
|
|
2874
|
-
function getAllKeysIn$1(object) {
|
|
2875
|
-
return baseGetAllKeys(object, keysIn$1, getSymbolsIn);
|
|
2876
|
-
}
|
|
2877
|
-
var _getAllKeysIn = getAllKeysIn$1;
|
|
2878
|
-
var getNative$3 = _getNative, root$4 = _root;
|
|
2879
|
-
var DataView$1 = getNative$3(root$4, "DataView");
|
|
2880
|
-
var _DataView = DataView$1;
|
|
2881
|
-
var getNative$2 = _getNative, root$3 = _root;
|
|
2882
|
-
var Promise$2 = getNative$2(root$3, "Promise");
|
|
2883
|
-
var _Promise = Promise$2;
|
|
2884
|
-
var getNative$1 = _getNative, root$2 = _root;
|
|
2885
|
-
var Set$2 = getNative$1(root$2, "Set");
|
|
2886
|
-
var _Set = Set$2;
|
|
2887
|
-
var getNative = _getNative, root$1 = _root;
|
|
2888
|
-
var WeakMap$2 = getNative(root$1, "WeakMap");
|
|
2889
|
-
var _WeakMap = WeakMap$2;
|
|
2890
|
-
var DataView = _DataView, Map$1 = _Map, Promise$1 = _Promise, Set$1 = _Set, WeakMap$1 = _WeakMap, baseGetTag = _baseGetTag, toSource = _toSource;
|
|
2891
|
-
var mapTag$3 = "[object Map]", objectTag$1 = "[object Object]", promiseTag = "[object Promise]", setTag$3 = "[object Set]", weakMapTag$1 = "[object WeakMap]";
|
|
2892
|
-
var dataViewTag$2 = "[object DataView]";
|
|
2893
|
-
var dataViewCtorString = toSource(DataView), mapCtorString = toSource(Map$1), promiseCtorString = toSource(Promise$1), setCtorString = toSource(Set$1), weakMapCtorString = toSource(WeakMap$1);
|
|
2894
|
-
var getTag$3 = baseGetTag;
|
|
2895
|
-
if (DataView && getTag$3(new DataView(new ArrayBuffer(1))) != dataViewTag$2 || Map$1 && getTag$3(new Map$1()) != mapTag$3 || Promise$1 && getTag$3(Promise$1.resolve()) != promiseTag || Set$1 && getTag$3(new Set$1()) != setTag$3 || WeakMap$1 && getTag$3(new WeakMap$1()) != weakMapTag$1) {
|
|
2896
|
-
getTag$3 = function(value) {
|
|
2897
|
-
var result = baseGetTag(value), Ctor = result == objectTag$1 ? value.constructor : void 0, ctorString = Ctor ? toSource(Ctor) : "";
|
|
2898
|
-
if (ctorString) {
|
|
2899
|
-
switch (ctorString) {
|
|
2900
|
-
case dataViewCtorString:
|
|
2901
|
-
return dataViewTag$2;
|
|
2902
|
-
case mapCtorString:
|
|
2903
|
-
return mapTag$3;
|
|
2904
|
-
case promiseCtorString:
|
|
2905
|
-
return promiseTag;
|
|
2906
|
-
case setCtorString:
|
|
2907
|
-
return setTag$3;
|
|
2908
|
-
case weakMapCtorString:
|
|
2909
|
-
return weakMapTag$1;
|
|
2910
|
-
}
|
|
2911
|
-
}
|
|
2912
|
-
return result;
|
|
2913
|
-
};
|
|
2914
|
-
}
|
|
2915
|
-
var _getTag = getTag$3;
|
|
2916
|
-
var objectProto = Object.prototype;
|
|
2917
|
-
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
2918
|
-
function initCloneArray$1(array) {
|
|
2919
|
-
var length = array.length, result = new array.constructor(length);
|
|
2920
|
-
if (length && typeof array[0] == "string" && hasOwnProperty.call(array, "index")) {
|
|
2921
|
-
result.index = array.index;
|
|
2922
|
-
result.input = array.input;
|
|
2923
|
-
}
|
|
2924
|
-
return result;
|
|
2925
|
-
}
|
|
2926
|
-
var _initCloneArray = initCloneArray$1;
|
|
2927
|
-
var root = _root;
|
|
2928
|
-
var Uint8Array$2 = root.Uint8Array;
|
|
2929
|
-
var _Uint8Array = Uint8Array$2;
|
|
2930
|
-
var Uint8Array$1 = _Uint8Array;
|
|
2931
|
-
function cloneArrayBuffer$3(arrayBuffer) {
|
|
2932
|
-
var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
|
|
2933
|
-
new Uint8Array$1(result).set(new Uint8Array$1(arrayBuffer));
|
|
2934
|
-
return result;
|
|
2935
|
-
}
|
|
2936
|
-
var _cloneArrayBuffer = cloneArrayBuffer$3;
|
|
2937
|
-
var cloneArrayBuffer$2 = _cloneArrayBuffer;
|
|
2938
|
-
function cloneDataView$1(dataView, isDeep) {
|
|
2939
|
-
var buffer = isDeep ? cloneArrayBuffer$2(dataView.buffer) : dataView.buffer;
|
|
2940
|
-
return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
|
|
2941
|
-
}
|
|
2942
|
-
var _cloneDataView = cloneDataView$1;
|
|
2943
|
-
var reFlags = /\w*$/;
|
|
2944
|
-
function cloneRegExp$1(regexp) {
|
|
2945
|
-
var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
|
|
2946
|
-
result.lastIndex = regexp.lastIndex;
|
|
2947
|
-
return result;
|
|
2948
|
-
}
|
|
2949
|
-
var _cloneRegExp = cloneRegExp$1;
|
|
2950
|
-
var Symbol$1 = _Symbol;
|
|
2951
|
-
var symbolProto = Symbol$1 ? Symbol$1.prototype : void 0, symbolValueOf = symbolProto ? symbolProto.valueOf : void 0;
|
|
2952
|
-
function cloneSymbol$1(symbol) {
|
|
2953
|
-
return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
|
|
2954
|
-
}
|
|
2955
|
-
var _cloneSymbol = cloneSymbol$1;
|
|
2956
|
-
var cloneArrayBuffer$1 = _cloneArrayBuffer;
|
|
2957
|
-
function cloneTypedArray$1(typedArray, isDeep) {
|
|
2958
|
-
var buffer = isDeep ? cloneArrayBuffer$1(typedArray.buffer) : typedArray.buffer;
|
|
2959
|
-
return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
|
|
2960
|
-
}
|
|
2961
|
-
var _cloneTypedArray = cloneTypedArray$1;
|
|
2962
|
-
var cloneArrayBuffer = _cloneArrayBuffer, cloneDataView = _cloneDataView, cloneRegExp = _cloneRegExp, cloneSymbol = _cloneSymbol, cloneTypedArray = _cloneTypedArray;
|
|
2963
|
-
var boolTag$1 = "[object Boolean]", dateTag$1 = "[object Date]", mapTag$2 = "[object Map]", numberTag$1 = "[object Number]", regexpTag$1 = "[object RegExp]", setTag$2 = "[object Set]", stringTag$1 = "[object String]", symbolTag$1 = "[object Symbol]";
|
|
2964
|
-
var arrayBufferTag$1 = "[object ArrayBuffer]", dataViewTag$1 = "[object DataView]", float32Tag$1 = "[object Float32Array]", float64Tag$1 = "[object Float64Array]", int8Tag$1 = "[object Int8Array]", int16Tag$1 = "[object Int16Array]", int32Tag$1 = "[object Int32Array]", uint8Tag$1 = "[object Uint8Array]", uint8ClampedTag$1 = "[object Uint8ClampedArray]", uint16Tag$1 = "[object Uint16Array]", uint32Tag$1 = "[object Uint32Array]";
|
|
2965
|
-
function initCloneByTag$1(object, tag, isDeep) {
|
|
2966
|
-
var Ctor = object.constructor;
|
|
2967
|
-
switch (tag) {
|
|
2968
|
-
case arrayBufferTag$1:
|
|
2969
|
-
return cloneArrayBuffer(object);
|
|
2970
|
-
case boolTag$1:
|
|
2971
|
-
case dateTag$1:
|
|
2972
|
-
return new Ctor(+object);
|
|
2973
|
-
case dataViewTag$1:
|
|
2974
|
-
return cloneDataView(object, isDeep);
|
|
2975
|
-
case float32Tag$1:
|
|
2976
|
-
case float64Tag$1:
|
|
2977
|
-
case int8Tag$1:
|
|
2978
|
-
case int16Tag$1:
|
|
2979
|
-
case int32Tag$1:
|
|
2980
|
-
case uint8Tag$1:
|
|
2981
|
-
case uint8ClampedTag$1:
|
|
2982
|
-
case uint16Tag$1:
|
|
2983
|
-
case uint32Tag$1:
|
|
2984
|
-
return cloneTypedArray(object, isDeep);
|
|
2985
|
-
case mapTag$2:
|
|
2986
|
-
return new Ctor();
|
|
2987
|
-
case numberTag$1:
|
|
2988
|
-
case stringTag$1:
|
|
2989
|
-
return new Ctor(object);
|
|
2990
|
-
case regexpTag$1:
|
|
2991
|
-
return cloneRegExp(object);
|
|
2992
|
-
case setTag$2:
|
|
2993
|
-
return new Ctor();
|
|
2994
|
-
case symbolTag$1:
|
|
2995
|
-
return cloneSymbol(object);
|
|
2996
|
-
}
|
|
2997
|
-
}
|
|
2998
|
-
var _initCloneByTag = initCloneByTag$1;
|
|
2999
|
-
var isObject$1 = isObject_1;
|
|
3000
|
-
var objectCreate = Object.create;
|
|
3001
|
-
var baseCreate$1 = /* @__PURE__ */ function() {
|
|
3002
|
-
function object() {
|
|
3003
|
-
}
|
|
3004
|
-
return function(proto) {
|
|
3005
|
-
if (!isObject$1(proto)) {
|
|
3006
|
-
return {};
|
|
3007
|
-
}
|
|
3008
|
-
if (objectCreate) {
|
|
3009
|
-
return objectCreate(proto);
|
|
3010
|
-
}
|
|
3011
|
-
object.prototype = proto;
|
|
3012
|
-
var result = new object();
|
|
3013
|
-
object.prototype = void 0;
|
|
3014
|
-
return result;
|
|
3015
|
-
};
|
|
3016
|
-
}();
|
|
3017
|
-
var _baseCreate = baseCreate$1;
|
|
3018
|
-
var baseCreate = _baseCreate, getPrototype = _getPrototype, isPrototype = _isPrototype;
|
|
3019
|
-
function initCloneObject$1(object) {
|
|
3020
|
-
return typeof object.constructor == "function" && !isPrototype(object) ? baseCreate(getPrototype(object)) : {};
|
|
3021
|
-
}
|
|
3022
|
-
var _initCloneObject = initCloneObject$1;
|
|
3023
|
-
var getTag$2 = _getTag, isObjectLike$1 = isObjectLike_1;
|
|
3024
|
-
var mapTag$1 = "[object Map]";
|
|
3025
|
-
function baseIsMap$1(value) {
|
|
3026
|
-
return isObjectLike$1(value) && getTag$2(value) == mapTag$1;
|
|
3027
|
-
}
|
|
3028
|
-
var _baseIsMap = baseIsMap$1;
|
|
3029
|
-
var baseIsMap = _baseIsMap, baseUnary$1 = _baseUnary, nodeUtil$1 = _nodeUtilExports;
|
|
3030
|
-
var nodeIsMap = nodeUtil$1 && nodeUtil$1.isMap;
|
|
3031
|
-
var isMap$1 = nodeIsMap ? baseUnary$1(nodeIsMap) : baseIsMap;
|
|
3032
|
-
var isMap_1 = isMap$1;
|
|
3033
|
-
var getTag$1 = _getTag, isObjectLike = isObjectLike_1;
|
|
3034
|
-
var setTag$1 = "[object Set]";
|
|
3035
|
-
function baseIsSet$1(value) {
|
|
3036
|
-
return isObjectLike(value) && getTag$1(value) == setTag$1;
|
|
3037
|
-
}
|
|
3038
|
-
var _baseIsSet = baseIsSet$1;
|
|
3039
|
-
var baseIsSet = _baseIsSet, baseUnary = _baseUnary, nodeUtil = _nodeUtilExports;
|
|
3040
|
-
var nodeIsSet = nodeUtil && nodeUtil.isSet;
|
|
3041
|
-
var isSet$1 = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
|
|
3042
|
-
var isSet_1 = isSet$1;
|
|
3043
|
-
var Stack = _Stack, arrayEach = _arrayEach, assignValue = _assignValue, baseAssign = _baseAssign, baseAssignIn = _baseAssignIn, cloneBuffer = _cloneBufferExports, copyArray = _copyArray, copySymbols = _copySymbols, copySymbolsIn = _copySymbolsIn, getAllKeys = _getAllKeys, getAllKeysIn = _getAllKeysIn, getTag = _getTag, initCloneArray = _initCloneArray, initCloneByTag = _initCloneByTag, initCloneObject = _initCloneObject, isArray = isArray_1, isBuffer = isBufferExports, isMap = isMap_1, isObject = isObject_1, isSet = isSet_1, keys = keys_1, keysIn = keysIn_1;
|
|
3044
|
-
var CLONE_DEEP_FLAG$1 = 1, CLONE_FLAT_FLAG = 2, CLONE_SYMBOLS_FLAG$1 = 4;
|
|
3045
|
-
var argsTag = "[object Arguments]", arrayTag = "[object Array]", boolTag = "[object Boolean]", dateTag = "[object Date]", errorTag = "[object Error]", funcTag = "[object Function]", genTag = "[object GeneratorFunction]", mapTag = "[object Map]", numberTag = "[object Number]", objectTag = "[object Object]", regexpTag = "[object RegExp]", setTag = "[object Set]", stringTag = "[object String]", symbolTag = "[object Symbol]", weakMapTag = "[object WeakMap]";
|
|
3046
|
-
var arrayBufferTag = "[object ArrayBuffer]", dataViewTag = "[object DataView]", float32Tag = "[object Float32Array]", float64Tag = "[object Float64Array]", int8Tag = "[object Int8Array]", int16Tag = "[object Int16Array]", int32Tag = "[object Int32Array]", uint8Tag = "[object Uint8Array]", uint8ClampedTag = "[object Uint8ClampedArray]", uint16Tag = "[object Uint16Array]", uint32Tag = "[object Uint32Array]";
|
|
3047
|
-
var cloneableTags = {};
|
|
3048
|
-
cloneableTags[argsTag] = cloneableTags[arrayTag] = cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = cloneableTags[boolTag] = cloneableTags[dateTag] = cloneableTags[float32Tag] = cloneableTags[float64Tag] = cloneableTags[int8Tag] = cloneableTags[int16Tag] = cloneableTags[int32Tag] = cloneableTags[mapTag] = cloneableTags[numberTag] = cloneableTags[objectTag] = cloneableTags[regexpTag] = cloneableTags[setTag] = cloneableTags[stringTag] = cloneableTags[symbolTag] = cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
|
|
3049
|
-
cloneableTags[errorTag] = cloneableTags[funcTag] = cloneableTags[weakMapTag] = false;
|
|
3050
|
-
function baseClone$1(value, bitmask, customizer, key, object, stack) {
|
|
3051
|
-
var result, isDeep = bitmask & CLONE_DEEP_FLAG$1, isFlat = bitmask & CLONE_FLAT_FLAG, isFull = bitmask & CLONE_SYMBOLS_FLAG$1;
|
|
3052
|
-
if (customizer) {
|
|
3053
|
-
result = object ? customizer(value, key, object, stack) : customizer(value);
|
|
3054
|
-
}
|
|
3055
|
-
if (result !== void 0) {
|
|
3056
|
-
return result;
|
|
3057
|
-
}
|
|
3058
|
-
if (!isObject(value)) {
|
|
3059
|
-
return value;
|
|
3060
|
-
}
|
|
3061
|
-
var isArr = isArray(value);
|
|
3062
|
-
if (isArr) {
|
|
3063
|
-
result = initCloneArray(value);
|
|
3064
|
-
if (!isDeep) {
|
|
3065
|
-
return copyArray(value, result);
|
|
3066
|
-
}
|
|
3067
|
-
} else {
|
|
3068
|
-
var tag = getTag(value), isFunc = tag == funcTag || tag == genTag;
|
|
3069
|
-
if (isBuffer(value)) {
|
|
3070
|
-
return cloneBuffer(value, isDeep);
|
|
3071
|
-
}
|
|
3072
|
-
if (tag == objectTag || tag == argsTag || isFunc && !object) {
|
|
3073
|
-
result = isFlat || isFunc ? {} : initCloneObject(value);
|
|
3074
|
-
if (!isDeep) {
|
|
3075
|
-
return isFlat ? copySymbolsIn(value, baseAssignIn(result, value)) : copySymbols(value, baseAssign(result, value));
|
|
3076
|
-
}
|
|
3077
|
-
} else {
|
|
3078
|
-
if (!cloneableTags[tag]) {
|
|
3079
|
-
return object ? value : {};
|
|
3080
|
-
}
|
|
3081
|
-
result = initCloneByTag(value, tag, isDeep);
|
|
3082
|
-
}
|
|
3083
|
-
}
|
|
3084
|
-
stack || (stack = new Stack());
|
|
3085
|
-
var stacked = stack.get(value);
|
|
3086
|
-
if (stacked) {
|
|
3087
|
-
return stacked;
|
|
3088
|
-
}
|
|
3089
|
-
stack.set(value, result);
|
|
3090
|
-
if (isSet(value)) {
|
|
3091
|
-
value.forEach(function(subValue) {
|
|
3092
|
-
result.add(baseClone$1(subValue, bitmask, customizer, subValue, value, stack));
|
|
3093
|
-
});
|
|
3094
|
-
} else if (isMap(value)) {
|
|
3095
|
-
value.forEach(function(subValue, key2) {
|
|
3096
|
-
result.set(key2, baseClone$1(subValue, bitmask, customizer, key2, value, stack));
|
|
3097
|
-
});
|
|
3098
|
-
}
|
|
3099
|
-
var keysFunc = isFull ? isFlat ? getAllKeysIn : getAllKeys : isFlat ? keysIn : keys;
|
|
3100
|
-
var props = isArr ? void 0 : keysFunc(value);
|
|
3101
|
-
arrayEach(props || value, function(subValue, key2) {
|
|
3102
|
-
if (props) {
|
|
3103
|
-
key2 = subValue;
|
|
3104
|
-
subValue = value[key2];
|
|
3105
|
-
}
|
|
3106
|
-
assignValue(result, key2, baseClone$1(subValue, bitmask, customizer, key2, value, stack));
|
|
3107
|
-
});
|
|
3108
|
-
return result;
|
|
3109
|
-
}
|
|
3110
|
-
var _baseClone = baseClone$1;
|
|
3111
|
-
var baseClone = _baseClone;
|
|
3112
|
-
var CLONE_DEEP_FLAG = 1, CLONE_SYMBOLS_FLAG = 4;
|
|
3113
|
-
function cloneDeep(value) {
|
|
3114
|
-
return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
|
|
3115
|
-
}
|
|
3116
|
-
var cloneDeep_1 = cloneDeep;
|
|
3117
|
-
const cloneDeep$1 = /* @__PURE__ */ getDefaultExportFromCjs(cloneDeep_1);
|
|
3118
2238
|
class CollectionRegistry {
|
|
3119
2239
|
// Normalized runtime layer (used by Data Grid / UI)
|
|
3120
2240
|
collectionsByTableName = /* @__PURE__ */ new Map();
|
|
@@ -3162,7 +2282,7 @@ class CollectionRegistry {
|
|
|
3162
2282
|
...c
|
|
3163
2283
|
}));
|
|
3164
2284
|
normalizedCollections.forEach((c, index) => {
|
|
3165
|
-
const raw =
|
|
2285
|
+
const raw = deepClone(collections[index]);
|
|
3166
2286
|
this.rootCollections.push(c);
|
|
3167
2287
|
this.rawRootCollections.push(raw);
|
|
3168
2288
|
const normalized = this.normalizeCollection(c);
|
|
@@ -3182,7 +2302,7 @@ class CollectionRegistry {
|
|
|
3182
2302
|
if (!subCollection) return;
|
|
3183
2303
|
this._registerRecursively(this.normalizeCollection({
|
|
3184
2304
|
...subCollection
|
|
3185
|
-
}),
|
|
2305
|
+
}), deepClone(subCollection));
|
|
3186
2306
|
});
|
|
3187
2307
|
}
|
|
3188
2308
|
});
|
|
@@ -3190,7 +2310,7 @@ class CollectionRegistry {
|
|
|
3190
2310
|
return true;
|
|
3191
2311
|
}
|
|
3192
2312
|
register(collection, rawCollection) {
|
|
3193
|
-
const raw = rawCollection ?
|
|
2313
|
+
const raw = rawCollection ? deepClone(rawCollection) : deepClone(collection);
|
|
3194
2314
|
this.rootCollections.push(collection);
|
|
3195
2315
|
this.rawRootCollections.push(raw);
|
|
3196
2316
|
this._registerRecursively(collection, raw);
|
|
@@ -3214,7 +2334,7 @@ class CollectionRegistry {
|
|
|
3214
2334
|
if (!subCollection) return;
|
|
3215
2335
|
this._registerRecursively(this.normalizeCollection({
|
|
3216
2336
|
...subCollection
|
|
3217
|
-
}),
|
|
2337
|
+
}), deepClone(subCollection));
|
|
3218
2338
|
});
|
|
3219
2339
|
}
|
|
3220
2340
|
}
|
|
@@ -3386,7 +2506,10 @@ class CollectionRegistry {
|
|
|
3386
2506
|
if (!relation) {
|
|
3387
2507
|
throw new Error(`Relation '${relationKey}' not found in collection '${currentCollection.slug}'`);
|
|
3388
2508
|
}
|
|
3389
|
-
|
|
2509
|
+
const target = relation.target();
|
|
2510
|
+
const targetRelationKey = relation.relationName || target.slug;
|
|
2511
|
+
const targetSlug = relation.overrides?.slug ?? targetRelationKey;
|
|
2512
|
+
currentCollection = this.get(targetSlug) || this.normalizeCollection(target);
|
|
3390
2513
|
if (i + 1 < pathSegments.length) ;
|
|
3391
2514
|
}
|
|
3392
2515
|
return currentCollection;
|
|
@@ -3435,7 +2558,7 @@ class CollectionRegistry {
|
|
|
3435
2558
|
if (!subcollection) {
|
|
3436
2559
|
throw new Error(`Subcollection '${subcollectionSlug}' not found in ${currentCollection.slug}`);
|
|
3437
2560
|
}
|
|
3438
|
-
currentCollection = subcollection;
|
|
2561
|
+
currentCollection = this.get(subcollection.slug) || this.normalizeCollection(subcollection);
|
|
3439
2562
|
collections.push(currentCollection);
|
|
3440
2563
|
}
|
|
3441
2564
|
}
|
|
@@ -3672,8 +2795,14 @@ class DrizzleConditionBuilder {
|
|
|
3672
2795
|
static buildSingleFilterCondition(column, op, value) {
|
|
3673
2796
|
switch (op) {
|
|
3674
2797
|
case "==":
|
|
3675
|
-
|
|
2798
|
+
if (value === null || value === void 0) {
|
|
2799
|
+
return sql`${column} IS NULL`;
|
|
2800
|
+
}
|
|
2801
|
+
return eq(column, value);
|
|
3676
2802
|
case "!=":
|
|
2803
|
+
if (value === null || value === void 0) {
|
|
2804
|
+
return sql`${column} IS NOT NULL`;
|
|
2805
|
+
}
|
|
3677
2806
|
return sql`${column} != ${value}`;
|
|
3678
2807
|
case ">":
|
|
3679
2808
|
return sql`${column} > ${value}`;
|
|
@@ -3802,7 +2931,7 @@ class DrizzleConditionBuilder {
|
|
|
3802
2931
|
throw new Error(`Join path did not result in connecting to parent table. Current: ${currentTableName}, Parent: ${parentTableName}`);
|
|
3803
2932
|
}
|
|
3804
2933
|
}
|
|
3805
|
-
const finalCondition = Array.isArray(parentEntityId) ? inArray(parentIdColumn, parentEntityId) : eq
|
|
2934
|
+
const finalCondition = Array.isArray(parentEntityId) ? inArray(parentIdColumn, parentEntityId) : eq(parentIdColumn, parentEntityId);
|
|
3806
2935
|
return {
|
|
3807
2936
|
joins,
|
|
3808
2937
|
finalCondition
|
|
@@ -3828,7 +2957,7 @@ class DrizzleConditionBuilder {
|
|
|
3828
2957
|
throw new Error(`Join columns not found: ${fromTableName}.${fromColName} = ${toTableName}.${toColName}`);
|
|
3829
2958
|
}
|
|
3830
2959
|
joinTable = fromTable;
|
|
3831
|
-
condition = eq
|
|
2960
|
+
condition = eq(left, right);
|
|
3832
2961
|
} else if (currentTable === fromTable) {
|
|
3833
2962
|
const left = toTable[toColName];
|
|
3834
2963
|
const right = currentTable[fromColName];
|
|
@@ -3842,7 +2971,7 @@ class DrizzleConditionBuilder {
|
|
|
3842
2971
|
throw new Error(`Join columns not found: ${toTableName}.${toColName} = ${fromTableName}.${fromColName}`);
|
|
3843
2972
|
}
|
|
3844
2973
|
joinTable = toTable;
|
|
3845
|
-
condition = eq
|
|
2974
|
+
condition = eq(left, right);
|
|
3846
2975
|
} else {
|
|
3847
2976
|
throw new Error(`Join step does not match current table. Current table does not match from: ${fromTableName} or to: ${toTableName}`);
|
|
3848
2977
|
}
|
|
@@ -3873,19 +3002,19 @@ class DrizzleConditionBuilder {
|
|
|
3873
3002
|
if (currentTable === targetTable) {
|
|
3874
3003
|
return {
|
|
3875
3004
|
joinTable: targetTable,
|
|
3876
|
-
condition: eq
|
|
3005
|
+
condition: eq(targetTableIdCol, junctionTargetCol),
|
|
3877
3006
|
additionalJoins: [{
|
|
3878
3007
|
table: junctionTable,
|
|
3879
|
-
condition: eq
|
|
3008
|
+
condition: eq(currentTableIdCol, junctionSourceCol)
|
|
3880
3009
|
}]
|
|
3881
3010
|
};
|
|
3882
3011
|
} else {
|
|
3883
3012
|
return {
|
|
3884
3013
|
joinTable: junctionTable,
|
|
3885
|
-
condition: eq
|
|
3014
|
+
condition: eq(currentTableIdCol, junctionSourceCol),
|
|
3886
3015
|
additionalJoins: [{
|
|
3887
3016
|
table: targetTable,
|
|
3888
|
-
condition: eq
|
|
3017
|
+
condition: eq(targetTableIdCol, junctionTargetCol)
|
|
3889
3018
|
}]
|
|
3890
3019
|
};
|
|
3891
3020
|
}
|
|
@@ -3910,11 +3039,11 @@ class DrizzleConditionBuilder {
|
|
|
3910
3039
|
if (!junctionTargetCol) {
|
|
3911
3040
|
throw new Error(`Target column '${through.targetColumn}' not found in junction table '${through.table}'`);
|
|
3912
3041
|
}
|
|
3913
|
-
const condition = Array.isArray(parentEntityId) ? inArray(junctionSourceCol, parentEntityId) : eq
|
|
3042
|
+
const condition = Array.isArray(parentEntityId) ? inArray(junctionSourceCol, parentEntityId) : eq(junctionSourceCol, parentEntityId);
|
|
3914
3043
|
return {
|
|
3915
3044
|
join: {
|
|
3916
3045
|
table: junctionTable,
|
|
3917
|
-
condition: eq
|
|
3046
|
+
condition: eq(targetIdColumn, junctionTargetCol)
|
|
3918
3047
|
},
|
|
3919
3048
|
condition
|
|
3920
3049
|
};
|
|
@@ -3935,11 +3064,11 @@ class DrizzleConditionBuilder {
|
|
|
3935
3064
|
if (!junctionTargetCol) {
|
|
3936
3065
|
throw new Error(`Target column '${through.targetColumn}' not found in junction table '${through.table}'`);
|
|
3937
3066
|
}
|
|
3938
|
-
const condition = Array.isArray(parentEntityId) ? inArray(junctionSourceCol, parentEntityId) : eq
|
|
3067
|
+
const condition = Array.isArray(parentEntityId) ? inArray(junctionSourceCol, parentEntityId) : eq(junctionSourceCol, parentEntityId);
|
|
3939
3068
|
return {
|
|
3940
3069
|
join: {
|
|
3941
3070
|
table: junctionTable,
|
|
3942
|
-
condition: eq
|
|
3071
|
+
condition: eq(targetIdColumn, junctionTargetCol)
|
|
3943
3072
|
},
|
|
3944
3073
|
condition
|
|
3945
3074
|
};
|
|
@@ -3955,15 +3084,15 @@ class DrizzleConditionBuilder {
|
|
|
3955
3084
|
if (!idCol) {
|
|
3956
3085
|
throw new Error('No primary key or "id" column found in target table');
|
|
3957
3086
|
}
|
|
3958
|
-
return Array.isArray(parentEntityId) ? inArray(idCol, parentEntityId) : eq
|
|
3087
|
+
return Array.isArray(parentEntityId) ? inArray(idCol, parentEntityId) : eq(idCol, parentEntityId);
|
|
3959
3088
|
}
|
|
3960
|
-
return Array.isArray(parentEntityId) ? inArray(targetIdCol, parentEntityId) : eq
|
|
3089
|
+
return Array.isArray(parentEntityId) ? inArray(targetIdCol, parentEntityId) : eq(targetIdCol, parentEntityId);
|
|
3961
3090
|
} else if (relation.direction === "inverse" && relation.foreignKeyOnTarget) {
|
|
3962
3091
|
const foreignKeyCol = targetTable[relation.foreignKeyOnTarget];
|
|
3963
3092
|
if (!foreignKeyCol) {
|
|
3964
3093
|
throw new Error(`Foreign key column '${relation.foreignKeyOnTarget}' not found in target table. This might be a many-to-many relationship that requires a junction table. Consider using 'through' property or ensure the corresponding owning relation exists with junction table configuration.`);
|
|
3965
3094
|
}
|
|
3966
|
-
return Array.isArray(parentEntityId) ? inArray(foreignKeyCol, parentEntityId) : eq
|
|
3095
|
+
return Array.isArray(parentEntityId) ? inArray(foreignKeyCol, parentEntityId) : eq(foreignKeyCol, parentEntityId);
|
|
3967
3096
|
} else if (relation.direction === "inverse" && relation.cardinality === "many" && relation.inverseRelationName) {
|
|
3968
3097
|
throw new Error(`Inverse many-to-many relation '${relation.relationName}' requires a junction table. Either specify 'through' property or ensure the corresponding owning relation exists with junction table configuration.`);
|
|
3969
3098
|
} else if (relation.direction === "inverse" && relation.cardinality === "one" && relation.inverseRelationName) {
|
|
@@ -3973,7 +3102,7 @@ class DrizzleConditionBuilder {
|
|
|
3973
3102
|
throw new Error(`Auto-inferred foreign key column '${inferredForeignKeyName}' not found in target table for inverse relation '${relation.relationName}'. Please specify 'foreignKeyOnTarget' explicitly.`);
|
|
3974
3103
|
}
|
|
3975
3104
|
console.debug(`🔍 [DrizzleConditionBuilder] Auto-inferred foreign key '${inferredForeignKeyName}' for inverse relation '${relation.relationName}'`);
|
|
3976
|
-
return Array.isArray(parentEntityId) ? inArray(foreignKeyCol, parentEntityId) : eq
|
|
3105
|
+
return Array.isArray(parentEntityId) ? inArray(foreignKeyCol, parentEntityId) : eq(foreignKeyCol, parentEntityId);
|
|
3977
3106
|
} else {
|
|
3978
3107
|
throw new Error(`Relation '${relation.relationName}' lacks proper configuration. For many-to-many relations, use 'through' property. For simple relations, use 'localKey' or 'foreignKeyOnTarget'.`);
|
|
3979
3108
|
}
|
|
@@ -4014,7 +3143,7 @@ class DrizzleConditionBuilder {
|
|
|
4014
3143
|
* Build a unique field check condition
|
|
4015
3144
|
*/
|
|
4016
3145
|
static buildUniqueFieldCondition(fieldColumn, value, idColumn, excludeId) {
|
|
4017
|
-
const conditions = [eq
|
|
3146
|
+
const conditions = [eq(fieldColumn, value)];
|
|
4018
3147
|
if (excludeId && idColumn) {
|
|
4019
3148
|
conditions.push(sql`${idColumn} != ${excludeId}`);
|
|
4020
3149
|
}
|
|
@@ -4089,7 +3218,7 @@ class DrizzleConditionBuilder {
|
|
|
4089
3218
|
if (currentTable !== parentTable) {
|
|
4090
3219
|
throw new Error("Join path did not result in connecting to parent table");
|
|
4091
3220
|
}
|
|
4092
|
-
const allConditions = [eq
|
|
3221
|
+
const allConditions = [eq(parentIdColumn, parentEntityId)];
|
|
4093
3222
|
if (additionalFilters) {
|
|
4094
3223
|
allConditions.push(...additionalFilters);
|
|
4095
3224
|
}
|
|
@@ -4111,11 +3240,11 @@ class DrizzleConditionBuilder {
|
|
|
4111
3240
|
if (!junctionTargetCol) {
|
|
4112
3241
|
throw new Error(`Target column '${through.targetColumn}' not found in junction table '${through.table}'`);
|
|
4113
3242
|
}
|
|
4114
|
-
const baseConditions = [eq
|
|
3243
|
+
const baseConditions = [eq(junctionSourceCol, parentEntityId)];
|
|
4115
3244
|
if (additionalFilters && additionalFilters.length > 0) {
|
|
4116
3245
|
baseConditions.push(...additionalFilters);
|
|
4117
3246
|
}
|
|
4118
|
-
return baseCountQuery.innerJoin(junctionTable, eq
|
|
3247
|
+
return baseCountQuery.innerJoin(junctionTable, eq(targetIdColumn, junctionTargetCol)).where(and(...baseConditions));
|
|
4119
3248
|
}
|
|
4120
3249
|
/**
|
|
4121
3250
|
* Build inverse junction table conditions for count queries
|
|
@@ -4133,11 +3262,11 @@ class DrizzleConditionBuilder {
|
|
|
4133
3262
|
if (!junctionTargetCol) {
|
|
4134
3263
|
throw new Error(`Target column '${through.targetColumn}' not found in junction table '${through.table}'`);
|
|
4135
3264
|
}
|
|
4136
|
-
const baseConditions = [eq
|
|
3265
|
+
const baseConditions = [eq(junctionSourceCol, parentEntityId)];
|
|
4137
3266
|
if (additionalFilters && additionalFilters.length > 0) {
|
|
4138
3267
|
baseConditions.push(...additionalFilters);
|
|
4139
3268
|
}
|
|
4140
|
-
return baseCountQuery.innerJoin(junctionTable, eq
|
|
3269
|
+
return baseCountQuery.innerJoin(junctionTable, eq(targetIdColumn, junctionTargetCol)).where(and(...baseConditions));
|
|
4141
3270
|
}
|
|
4142
3271
|
/**
|
|
4143
3272
|
* Helper method to extract table names from columns
|
|
@@ -4477,7 +3606,25 @@ function serializePropertyToServer(value, property) {
|
|
|
4477
3606
|
return result;
|
|
4478
3607
|
}
|
|
4479
3608
|
return value;
|
|
3609
|
+
case "string":
|
|
3610
|
+
if (typeof value === "string") {
|
|
3611
|
+
if (value.startsWith("data:application/octet-stream;base64,")) {
|
|
3612
|
+
const base64Data = value.split(",")[1];
|
|
3613
|
+
if (base64Data) {
|
|
3614
|
+
return Buffer.from(base64Data, "base64");
|
|
3615
|
+
}
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3618
|
+
return value;
|
|
4480
3619
|
default:
|
|
3620
|
+
if (typeof value === "string") {
|
|
3621
|
+
if (value.startsWith("data:application/octet-stream;base64,")) {
|
|
3622
|
+
const base64Data = value.split(",")[1];
|
|
3623
|
+
if (base64Data) {
|
|
3624
|
+
return Buffer.from(base64Data, "base64");
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
4481
3628
|
return value;
|
|
4482
3629
|
}
|
|
4483
3630
|
}
|
|
@@ -4511,7 +3658,7 @@ async function parseDataFromServer(data, collection, db, registry) {
|
|
|
4511
3658
|
if (targetTable && currentEntityId) {
|
|
4512
3659
|
const foreignKeyColumn = targetTable[relation.foreignKeyOnTarget];
|
|
4513
3660
|
if (foreignKeyColumn) {
|
|
4514
|
-
const relatedEntities = await db.select().from(targetTable).where(eq
|
|
3661
|
+
const relatedEntities = await db.select().from(targetTable).where(eq(foreignKeyColumn, currentEntityId)).limit(relation.cardinality === "one" ? 1 : 100);
|
|
4515
3662
|
if (relatedEntities.length > 0) {
|
|
4516
3663
|
if (relation.cardinality === "one") {
|
|
4517
3664
|
const targetPks = getPrimaryKeys(targetCollection, registry);
|
|
@@ -4558,12 +3705,12 @@ async function parseDataFromServer(data, collection, db, registry) {
|
|
|
4558
3705
|
console.warn(`Join columns not found: ${fromColumn} -> ${toColumn}`);
|
|
4559
3706
|
break;
|
|
4560
3707
|
}
|
|
4561
|
-
query = query.innerJoin(joinTable, eq
|
|
3708
|
+
query = query.innerJoin(joinTable, eq(fromCol, toCol));
|
|
4562
3709
|
currentTable = joinTable;
|
|
4563
3710
|
}
|
|
4564
3711
|
if (pks.length === 1) {
|
|
4565
3712
|
const sourceIdField = sourceTable[pks[0].fieldName];
|
|
4566
|
-
query = query.where(eq
|
|
3713
|
+
query = query.where(eq(sourceIdField, currentEntityId));
|
|
4567
3714
|
} else {
|
|
4568
3715
|
console.warn(`Join path resolution for composite primary keys is not yet fully supported: ${collection.slug}`);
|
|
4569
3716
|
}
|
|
@@ -4571,7 +3718,7 @@ async function parseDataFromServer(data, collection, db, registry) {
|
|
|
4571
3718
|
let combinedWhere;
|
|
4572
3719
|
if (pks.length === 1) {
|
|
4573
3720
|
const sourceIdField = sourceTable[pks[0].fieldName];
|
|
4574
|
-
combinedWhere = DrizzleConditionBuilder.combineConditionsWithAnd([eq
|
|
3721
|
+
combinedWhere = DrizzleConditionBuilder.combineConditionsWithAnd([eq(sourceIdField, currentEntityId), ...additionalFilters].filter(Boolean));
|
|
4575
3722
|
}
|
|
4576
3723
|
const joinResults = await query.where(combinedWhere).limit(relation.cardinality === "one" ? 1 : 100);
|
|
4577
3724
|
if (joinResults.length > 0) {
|
|
@@ -4603,6 +3750,37 @@ function parsePropertyFromServer(value, property, collection, propertyKey) {
|
|
|
4603
3750
|
return value;
|
|
4604
3751
|
}
|
|
4605
3752
|
switch (property.type) {
|
|
3753
|
+
case "string": {
|
|
3754
|
+
if (typeof value === "string") return value;
|
|
3755
|
+
let isBuffer = false;
|
|
3756
|
+
let buf = null;
|
|
3757
|
+
if (Buffer.isBuffer(value)) {
|
|
3758
|
+
isBuffer = true;
|
|
3759
|
+
buf = value;
|
|
3760
|
+
} else if (typeof value === "object" && value !== null && value.type === "Buffer" && Array.isArray(value.data)) {
|
|
3761
|
+
isBuffer = true;
|
|
3762
|
+
buf = Buffer.from(value.data);
|
|
3763
|
+
}
|
|
3764
|
+
if (isBuffer && buf) {
|
|
3765
|
+
let isPrintable = true;
|
|
3766
|
+
for (let i = 0; i < buf.length; i++) {
|
|
3767
|
+
const b = buf[i];
|
|
3768
|
+
if ((b < 32 || b > 126) && b !== 9 && b !== 10 && b !== 13) {
|
|
3769
|
+
isPrintable = false;
|
|
3770
|
+
break;
|
|
3771
|
+
}
|
|
3772
|
+
}
|
|
3773
|
+
return isPrintable ? buf.toString("utf8") : `data:application/octet-stream;base64,${buf.toString("base64")}`;
|
|
3774
|
+
}
|
|
3775
|
+
if (typeof value === "object" && value !== null) {
|
|
3776
|
+
try {
|
|
3777
|
+
return JSON.stringify(value);
|
|
3778
|
+
} catch {
|
|
3779
|
+
return String(value);
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3782
|
+
return String(value);
|
|
3783
|
+
}
|
|
4606
3784
|
case "relation":
|
|
4607
3785
|
if (typeof value === "string" || typeof value === "number") {
|
|
4608
3786
|
let relationDef = property.relation;
|
|
@@ -4686,8 +3864,29 @@ function parsePropertyFromServer(value, property, collection, propertyKey) {
|
|
|
4686
3864
|
}
|
|
4687
3865
|
return null;
|
|
4688
3866
|
}
|
|
4689
|
-
default:
|
|
3867
|
+
default: {
|
|
3868
|
+
let isBuffer = false;
|
|
3869
|
+
let buf = null;
|
|
3870
|
+
if (Buffer.isBuffer(value)) {
|
|
3871
|
+
isBuffer = true;
|
|
3872
|
+
buf = value;
|
|
3873
|
+
} else if (typeof value === "object" && value !== null && value.type === "Buffer" && Array.isArray(value.data)) {
|
|
3874
|
+
isBuffer = true;
|
|
3875
|
+
buf = Buffer.from(value.data);
|
|
3876
|
+
}
|
|
3877
|
+
if (isBuffer && buf) {
|
|
3878
|
+
let isPrintable = true;
|
|
3879
|
+
for (let i = 0; i < buf.length; i++) {
|
|
3880
|
+
const b = buf[i];
|
|
3881
|
+
if ((b < 32 || b > 126) && b !== 9 && b !== 10 && b !== 13) {
|
|
3882
|
+
isPrintable = false;
|
|
3883
|
+
break;
|
|
3884
|
+
}
|
|
3885
|
+
}
|
|
3886
|
+
return isPrintable ? buf.toString("utf8") : `data:application/octet-stream;base64,${buf.toString("base64")}`;
|
|
3887
|
+
}
|
|
4690
3888
|
return value;
|
|
3889
|
+
}
|
|
4691
3890
|
}
|
|
4692
3891
|
}
|
|
4693
3892
|
function normalizeScalarValues(data, properties, collection, resolvedRelations, options) {
|
|
@@ -4770,11 +3969,11 @@ class RelationService {
|
|
|
4770
3969
|
if (!fromCol || !toCol) {
|
|
4771
3970
|
throw new Error(`Join columns not found: ${fromColumn} -> ${toColumn}`);
|
|
4772
3971
|
}
|
|
4773
|
-
query2 = query2.innerJoin(joinTable, eq
|
|
3972
|
+
query2 = query2.innerJoin(joinTable, eq(fromCol, toCol));
|
|
4774
3973
|
currentTable = joinTable;
|
|
4775
3974
|
}
|
|
4776
3975
|
const parentIdField = parentTable[getPrimaryKeys(parentCollection, this.registry)[0].fieldName];
|
|
4777
|
-
query2 = query2.where(eq
|
|
3976
|
+
query2 = query2.where(eq(parentIdField, parsedParentId));
|
|
4778
3977
|
if (options.limit) {
|
|
4779
3978
|
query2 = query2.limit(options.limit);
|
|
4780
3979
|
}
|
|
@@ -4893,7 +4092,7 @@ class RelationService {
|
|
|
4893
4092
|
if (!fromCol || !toCol) {
|
|
4894
4093
|
throw new Error(`Join columns not found: ${fromColumn} -> ${toColumn}`);
|
|
4895
4094
|
}
|
|
4896
|
-
query2 = query2.innerJoin(joinTable, eq
|
|
4095
|
+
query2 = query2.innerJoin(joinTable, eq(fromCol, toCol));
|
|
4897
4096
|
currentTable = joinTable;
|
|
4898
4097
|
}
|
|
4899
4098
|
const parentIdField = parentTable[getPrimaryKeys(parentCollection, this.registry)[0].fieldName];
|
|
@@ -5024,7 +4223,7 @@ class RelationService {
|
|
|
5024
4223
|
const fromCol = currentTable[fromColName];
|
|
5025
4224
|
const toCol = joinTable[toColName];
|
|
5026
4225
|
if (!fromCol || !toCol) throw new Error(`Join columns not found: ${fromColumn} -> ${toColumn}`);
|
|
5027
|
-
query2 = query2.innerJoin(joinTable, eq
|
|
4226
|
+
query2 = query2.innerJoin(joinTable, eq(fromCol, toCol));
|
|
5028
4227
|
currentTable = joinTable;
|
|
5029
4228
|
}
|
|
5030
4229
|
const parentIdField = parentTable[getPrimaryKeys(parentCollection, this.registry)[0].fieldName];
|
|
@@ -5059,7 +4258,7 @@ class RelationService {
|
|
|
5059
4258
|
console.warn(`[batchFetchRelatedEntitiesMany] Junction columns not found in '${relation.through.table}'`);
|
|
5060
4259
|
return /* @__PURE__ */ new Map();
|
|
5061
4260
|
}
|
|
5062
|
-
const query2 = this.db.select().from(junctionTable).innerJoin(targetTable, eq
|
|
4261
|
+
const query2 = this.db.select().from(junctionTable).innerJoin(targetTable, eq(targetJunctionCol, targetIdField)).where(inArray(sourceJunctionCol, parsedParentIds));
|
|
5063
4262
|
const results2 = await query2;
|
|
5064
4263
|
const resultMap2 = /* @__PURE__ */ new Map();
|
|
5065
4264
|
const targetTableName = getTableName(targetCollection);
|
|
@@ -5157,7 +4356,7 @@ class RelationService {
|
|
|
5157
4356
|
const parentIdInfo = parentPks[0];
|
|
5158
4357
|
const parsedParentIdObj = parseIdValues(entityId, parentPks);
|
|
5159
4358
|
const parsedParentId = parsedParentIdObj[parentIdInfo.fieldName];
|
|
5160
|
-
await tx.delete(junctionTable).where(eq
|
|
4359
|
+
await tx.delete(junctionTable).where(eq(sourceJunctionColumn, parsedParentId));
|
|
5161
4360
|
if (targetEntityIds.length > 0) {
|
|
5162
4361
|
const targetPks = getPrimaryKeys(targetCollection, this.registry);
|
|
5163
4362
|
const targetIdInfo = targetPks[0];
|
|
@@ -5186,7 +4385,7 @@ class RelationService {
|
|
|
5186
4385
|
const parentIdInfo = parentPks[0];
|
|
5187
4386
|
const parsedParentIdObj = parseIdValues(entityId, parentPks);
|
|
5188
4387
|
const parsedParentId = parsedParentIdObj[parentIdInfo.fieldName];
|
|
5189
|
-
await tx.delete(junctionTable).where(eq
|
|
4388
|
+
await tx.delete(junctionTable).where(eq(sourceJunctionColumn, parsedParentId));
|
|
5190
4389
|
if (targetEntityIds.length > 0) {
|
|
5191
4390
|
const targetPks = getPrimaryKeys(targetCollection, this.registry);
|
|
5192
4391
|
const targetIdInfo = targetPks[0];
|
|
@@ -5219,14 +4418,14 @@ class RelationService {
|
|
|
5219
4418
|
const parsedTargetIds = targetEntityIds.map((id) => parseIdValues(id, targetPks)[targetIdInfo.fieldName]);
|
|
5220
4419
|
await tx.update(targetTable).set({
|
|
5221
4420
|
[relation.foreignKeyOnTarget]: null
|
|
5222
|
-
}).where(and(eq
|
|
4421
|
+
}).where(and(eq(fkCol, parsedParentId), sql`${targetIdCol} NOT IN (${sql.join(parsedTargetIds)})`));
|
|
5223
4422
|
await tx.update(targetTable).set({
|
|
5224
4423
|
[relation.foreignKeyOnTarget]: parsedParentId
|
|
5225
4424
|
}).where(inArray(targetIdCol, parsedTargetIds));
|
|
5226
4425
|
} else {
|
|
5227
4426
|
await tx.update(targetTable).set({
|
|
5228
4427
|
[relation.foreignKeyOnTarget]: null
|
|
5229
|
-
}).where(eq
|
|
4428
|
+
}).where(eq(fkCol, parsedParentId));
|
|
5230
4429
|
}
|
|
5231
4430
|
} else {
|
|
5232
4431
|
console.warn(`Many relation '${key}' in collection '${collection.slug}' lacks write configuration and will be skipped during save.`);
|
|
@@ -5285,17 +4484,17 @@ class RelationService {
|
|
|
5285
4484
|
if (newValue === null || newValue === void 0) {
|
|
5286
4485
|
await tx.update(targetTable).set({
|
|
5287
4486
|
[relation.foreignKeyOnTarget]: null
|
|
5288
|
-
}).where(eq
|
|
4487
|
+
}).where(eq(foreignKeyColumn, parsedSourceId));
|
|
5289
4488
|
} else {
|
|
5290
4489
|
const parsedNewTargetIdObj = parseIdValues(newValue, targetPks);
|
|
5291
4490
|
const parsedNewTargetId = parsedNewTargetIdObj[targetIdInfo.fieldName];
|
|
5292
4491
|
const targetIdField = targetTable[targetIdInfo.fieldName];
|
|
5293
4492
|
await tx.update(targetTable).set({
|
|
5294
4493
|
[relation.foreignKeyOnTarget]: null
|
|
5295
|
-
}).where(eq
|
|
4494
|
+
}).where(eq(foreignKeyColumn, parsedSourceId));
|
|
5296
4495
|
await tx.update(targetTable).set({
|
|
5297
4496
|
[relation.foreignKeyOnTarget]: parsedSourceId
|
|
5298
|
-
}).where(eq
|
|
4497
|
+
}).where(eq(targetIdField, parsedNewTargetId));
|
|
5299
4498
|
}
|
|
5300
4499
|
} catch (e) {
|
|
5301
4500
|
console.warn(`Failed to update inverse relation '${relation.relationName}':`, e);
|
|
@@ -5350,7 +4549,7 @@ class RelationService {
|
|
|
5350
4549
|
const sourceIdInfo = sourcePks[0];
|
|
5351
4550
|
const parsedSourceIdObj = parseIdValues(sourceEntityId, sourcePks);
|
|
5352
4551
|
const parsedSourceId = parsedSourceIdObj[sourceIdInfo.fieldName];
|
|
5353
|
-
await tx.delete(junctionTable).where(eq
|
|
4552
|
+
await tx.delete(junctionTable).where(eq(sourceJunctionColumn, parsedSourceId));
|
|
5354
4553
|
if (newValue && Array.isArray(newValue) && newValue.length > 0) {
|
|
5355
4554
|
const targetPks = getPrimaryKeys(targetCollection, this.registry);
|
|
5356
4555
|
const targetIdInfo = targetPks[0];
|
|
@@ -5401,7 +4600,7 @@ class RelationService {
|
|
|
5401
4600
|
const sourceIdInfo = sourcePks[0];
|
|
5402
4601
|
const parsedSourceIdObj = parseIdValues(sourceEntityId, sourcePks);
|
|
5403
4602
|
const parsedSourceId = parsedSourceIdObj[sourceIdInfo.fieldName];
|
|
5404
|
-
await tx.delete(junctionTable).where(eq
|
|
4603
|
+
await tx.delete(junctionTable).where(eq(sourceJunctionColumn, parsedSourceId));
|
|
5405
4604
|
if (newValue && Array.isArray(newValue) && newValue.length > 0) {
|
|
5406
4605
|
const targetPks = getPrimaryKeys(targetCollection, this.registry);
|
|
5407
4606
|
const targetIdInfo = targetPks[0];
|
|
@@ -5456,14 +4655,14 @@ class RelationService {
|
|
|
5456
4655
|
}
|
|
5457
4656
|
const parentRows = await tx.select({
|
|
5458
4657
|
val: parentSourceCol
|
|
5459
|
-
}).from(parentTable).where(eq
|
|
4658
|
+
}).from(parentTable).where(eq(parentIdCol, parsedParentId)).limit(1);
|
|
5460
4659
|
if (parentRows.length === 0) continue;
|
|
5461
4660
|
const parentFKValue = parentRows[0].val;
|
|
5462
4661
|
if (newTargetId === null || newTargetId === void 0) {
|
|
5463
4662
|
if (parentFKValue !== null && parentFKValue !== void 0) {
|
|
5464
4663
|
await tx.update(targetTable).set({
|
|
5465
4664
|
[targetFKColName]: null
|
|
5466
|
-
}).where(eq
|
|
4665
|
+
}).where(eq(targetFKCol, parentFKValue));
|
|
5467
4666
|
}
|
|
5468
4667
|
continue;
|
|
5469
4668
|
}
|
|
@@ -5472,14 +4671,14 @@ class RelationService {
|
|
|
5472
4671
|
if (parentFKValue !== null && parentFKValue !== void 0) {
|
|
5473
4672
|
await tx.update(targetTable).set({
|
|
5474
4673
|
[targetFKColName]: null
|
|
5475
|
-
}).where(eq
|
|
4674
|
+
}).where(eq(targetFKCol, parentFKValue));
|
|
5476
4675
|
} else {
|
|
5477
4676
|
console.warn(`Cannot set joinPath relation '${relation.relationName}' because parent FK value is null/undefined`);
|
|
5478
4677
|
continue;
|
|
5479
4678
|
}
|
|
5480
4679
|
await tx.update(targetTable).set({
|
|
5481
4680
|
[targetFKColName]: parentFKValue
|
|
5482
|
-
}).where(eq
|
|
4681
|
+
}).where(eq(targetIdCol, parsedTargetId));
|
|
5483
4682
|
}
|
|
5484
4683
|
}
|
|
5485
4684
|
/**
|
|
@@ -5864,7 +5063,7 @@ class EntityFetchService {
|
|
|
5864
5063
|
const collection = getCollectionByPath(collectionPath, this.registry);
|
|
5865
5064
|
const searchConditions = DrizzleConditionBuilder.buildSearchConditions(options.searchString, collection.properties, table);
|
|
5866
5065
|
if (searchConditions.length === 0) {
|
|
5867
|
-
queryOpts.where = and(eq
|
|
5066
|
+
queryOpts.where = and(eq(idField, -99999999));
|
|
5868
5067
|
return queryOpts;
|
|
5869
5068
|
}
|
|
5870
5069
|
allConditions.push(DrizzleConditionBuilder.combineConditionsWithOr(searchConditions));
|
|
@@ -5911,9 +5110,9 @@ class EntityFetchService {
|
|
|
5911
5110
|
const startAfterId = cursor.id ?? cursor[idInfo.fieldName];
|
|
5912
5111
|
if (startAfterOrderValue !== void 0 && startAfterId !== void 0) {
|
|
5913
5112
|
if (options.order === "asc") {
|
|
5914
|
-
return [or(gt(orderByField, startAfterOrderValue), and(eq
|
|
5113
|
+
return [or(gt(orderByField, startAfterOrderValue), and(eq(orderByField, startAfterOrderValue), gt(idField, startAfterId)))];
|
|
5915
5114
|
} else {
|
|
5916
|
-
return [or(lt(orderByField, startAfterOrderValue), and(eq
|
|
5115
|
+
return [or(lt(orderByField, startAfterOrderValue), and(eq(orderByField, startAfterOrderValue), lt(idField, startAfterId)))];
|
|
5917
5116
|
}
|
|
5918
5117
|
}
|
|
5919
5118
|
}
|
|
@@ -5947,7 +5146,7 @@ class EntityFetchService {
|
|
|
5947
5146
|
try {
|
|
5948
5147
|
const withConfig = this.buildWithConfig(collection);
|
|
5949
5148
|
const row = await qb.findFirst({
|
|
5950
|
-
where: eq
|
|
5149
|
+
where: eq(idField, parsedId),
|
|
5951
5150
|
with: withConfig
|
|
5952
5151
|
});
|
|
5953
5152
|
if (!row) return void 0;
|
|
@@ -5955,10 +5154,14 @@ class EntityFetchService {
|
|
|
5955
5154
|
await this.resolveJoinPathRelations(entity, collection, collectionPath, parsedId, databaseId);
|
|
5956
5155
|
return entity;
|
|
5957
5156
|
} catch (e) {
|
|
5157
|
+
if (e instanceof Error && e.message.includes("not enough information to infer relation")) {
|
|
5158
|
+
console.error(`[EntityFetchService] Relation inference error for collection '${collectionPath}': ${e.message}`);
|
|
5159
|
+
console.error(`Hint: This usually means a relation in your drizzle schema is missing a reciprocal 'one()' or 'many()' definition. Run 'rebase schema generate' to fix this.`);
|
|
5160
|
+
}
|
|
5958
5161
|
console.warn(`[EntityFetchService] db.query.findFirst failed for ${collectionPath}, falling back to db.select:`, e);
|
|
5959
5162
|
}
|
|
5960
5163
|
}
|
|
5961
|
-
const result = await this.db.select().from(table).where(eq
|
|
5164
|
+
const result = await this.db.select().from(table).where(eq(idField, parsedId)).limit(1);
|
|
5962
5165
|
if (result.length === 0) return void 0;
|
|
5963
5166
|
const raw = result[0];
|
|
5964
5167
|
const values = await parseDataFromServer(raw, collection, this.db, this.registry);
|
|
@@ -6015,6 +5218,10 @@ class EntityFetchService {
|
|
|
6015
5218
|
const entities = results2.map((row) => this.drizzleResultToEntity(row, collection, collectionPath, idInfo, options.databaseId, idInfoArray));
|
|
6016
5219
|
return entities;
|
|
6017
5220
|
} catch (e) {
|
|
5221
|
+
if (e instanceof Error && e.message.includes("not enough information to infer relation")) {
|
|
5222
|
+
console.error(`[EntityFetchService] Relation inference error for collection '${collectionPath}': ${e.message}`);
|
|
5223
|
+
console.error(`Hint: This usually means a relation in your drizzle schema is missing a reciprocal 'one()' or 'many()' definition. Run 'rebase schema generate' to fix this.`);
|
|
5224
|
+
}
|
|
6018
5225
|
console.warn(`[EntityFetchService] db.query.findMany failed for ${collectionPath}, falling back to db.select:`, e);
|
|
6019
5226
|
}
|
|
6020
5227
|
}
|
|
@@ -6284,6 +5491,10 @@ class EntityFetchService {
|
|
|
6284
5491
|
await this.resolveJoinPathRelationsBatchRest(restRows, collection, collectionPath, idInfoArray, include);
|
|
6285
5492
|
return restRows;
|
|
6286
5493
|
} catch (e) {
|
|
5494
|
+
if (e instanceof Error && e.message.includes("not enough information to infer relation")) {
|
|
5495
|
+
console.error(`[EntityFetchService] Relation inference error for collection '${collectionPath}': ${e.message}`);
|
|
5496
|
+
console.error(`Hint: This usually means a relation in your drizzle schema is missing a reciprocal 'one()' or 'many()' definition. Run 'rebase schema generate' to fix this.`);
|
|
5497
|
+
}
|
|
6287
5498
|
console.warn(`[fetchCollectionForRest] db.query.findMany failed for ${collectionPath}, falling back:`, e);
|
|
6288
5499
|
}
|
|
6289
5500
|
}
|
|
@@ -6354,7 +5565,7 @@ class EntityFetchService {
|
|
|
6354
5565
|
try {
|
|
6355
5566
|
const withConfig = include && include.length > 0 ? this.buildWithConfig(collection, include) : void 0;
|
|
6356
5567
|
const row = await qb.findFirst({
|
|
6357
|
-
where: eq
|
|
5568
|
+
where: eq(idField, parsedId),
|
|
6358
5569
|
...withConfig ? {
|
|
6359
5570
|
with: withConfig
|
|
6360
5571
|
} : {}
|
|
@@ -6364,10 +5575,14 @@ class EntityFetchService {
|
|
|
6364
5575
|
await this.resolveJoinPathRelationsBatchRest([restRow], collection, collectionPath, idInfoArray, include);
|
|
6365
5576
|
return restRow;
|
|
6366
5577
|
} catch (e) {
|
|
5578
|
+
if (e instanceof Error && e.message.includes("not enough information to infer relation")) {
|
|
5579
|
+
console.error(`[EntityFetchService] Relation inference error for collection '${collectionPath}': ${e.message}`);
|
|
5580
|
+
console.error(`Hint: This usually means a relation in your drizzle schema is missing a reciprocal 'one()' or 'many()' definition. Run 'rebase schema generate' to fix this.`);
|
|
5581
|
+
}
|
|
6367
5582
|
console.warn(`[fetchEntityForRest] db.query.findFirst failed for ${collectionPath}, falling back:`, e);
|
|
6368
5583
|
}
|
|
6369
5584
|
}
|
|
6370
|
-
const result = await this.db.select().from(table).where(eq
|
|
5585
|
+
const result = await this.db.select().from(table).where(eq(idField, parsedId)).limit(1);
|
|
6371
5586
|
if (result.length === 0) return null;
|
|
6372
5587
|
const raw = result[0];
|
|
6373
5588
|
const flatEntity = {
|
|
@@ -6576,7 +5791,7 @@ class EntityPersistService {
|
|
|
6576
5791
|
}
|
|
6577
5792
|
const parsedIdObj = parseIdValues(entityId, idInfoArray);
|
|
6578
5793
|
const parsedId = parsedIdObj[idInfo.fieldName];
|
|
6579
|
-
await this.db.delete(table).where(eq
|
|
5794
|
+
await this.db.delete(table).where(eq(idField, parsedId));
|
|
6580
5795
|
}
|
|
6581
5796
|
/**
|
|
6582
5797
|
* Save an entity (create or update)
|
|
@@ -6622,7 +5837,7 @@ class EntityPersistService {
|
|
|
6622
5837
|
targetColumnName = relation.localKey;
|
|
6623
5838
|
} else if (relation.foreignKeyOnTarget) {
|
|
6624
5839
|
targetColumnName = relation.foreignKeyOnTarget;
|
|
6625
|
-
} else if (relation.joinPath && relation.joinPath.length
|
|
5840
|
+
} else if (relation.joinPath && relation.joinPath.length === 1) {
|
|
6626
5841
|
const targetTableName = getTableName(targetCollection);
|
|
6627
5842
|
const relevantJoinStep = relation.joinPath.find((joinStep) => joinStep.table === targetTableName);
|
|
6628
5843
|
if (relevantJoinStep) {
|
|
@@ -6633,6 +5848,8 @@ class EntityPersistService {
|
|
|
6633
5848
|
const targetColumnNames = DrizzleConditionBuilder.getColumnNamesFromColumns(relation.joinPath[0].on.to);
|
|
6634
5849
|
targetColumnName = targetColumnNames[0];
|
|
6635
5850
|
}
|
|
5851
|
+
} else if (relation.joinPath && relation.joinPath.length > 1) {
|
|
5852
|
+
break;
|
|
6636
5853
|
} else {
|
|
6637
5854
|
throw new Error(`Relation '${relationKey}' lacks configuration for path-based saving.`);
|
|
6638
5855
|
}
|
|
@@ -6698,7 +5915,7 @@ class EntityPersistService {
|
|
|
6698
5915
|
const conditions = [];
|
|
6699
5916
|
for (const info of idInfoArray) {
|
|
6700
5917
|
const field = table[info.fieldName];
|
|
6701
|
-
conditions.push(eq
|
|
5918
|
+
conditions.push(eq(field, idValues[info.fieldName]));
|
|
6702
5919
|
}
|
|
6703
5920
|
await updateQuery.where(and(...conditions));
|
|
6704
5921
|
}
|
|
@@ -6755,22 +5972,78 @@ class EntityPersistService {
|
|
|
6755
5972
|
const pgError = this.extractPgError(error);
|
|
6756
5973
|
if (pgError) {
|
|
6757
5974
|
const detail = pgError.detail;
|
|
5975
|
+
const hint = pgError.hint;
|
|
6758
5976
|
const constraint = pgError.constraint;
|
|
6759
5977
|
const column = pgError.column;
|
|
6760
5978
|
const table = pgError.table;
|
|
5979
|
+
const dataType = pgError.dataType;
|
|
5980
|
+
const pgMessage = pgError.message || "Unknown database error";
|
|
5981
|
+
const suffix = hint ? ` Hint: ${hint}` : "";
|
|
5982
|
+
const tableRef = table ?? collectionSlug;
|
|
6761
5983
|
switch (pgError.code) {
|
|
6762
5984
|
case "23503":
|
|
6763
|
-
return new Error(detail ? `Foreign key constraint violated: ${detail}` : `Cannot save: a foreign key constraint${constraint ? ` (${constraint})` : ""} was violated in "${collectionSlug}"
|
|
5985
|
+
return new Error(detail ? `Foreign key constraint violated: ${detail}${suffix}` : `Cannot save: a foreign key constraint${constraint ? ` (${constraint})` : ""} was violated in "${collectionSlug}".${suffix}`);
|
|
6764
5986
|
case "23505":
|
|
6765
|
-
return new Error(detail ? `Duplicate value: ${detail}` : `Cannot save: a unique constraint${constraint ? ` (${constraint})` : ""} was violated in "${collectionSlug}"
|
|
5987
|
+
return new Error(detail ? `Duplicate value: ${detail}${suffix}` : `Cannot save: a unique constraint${constraint ? ` (${constraint})` : ""} was violated in "${collectionSlug}".${suffix}`);
|
|
6766
5988
|
case "23502":
|
|
6767
|
-
return new Error(`Missing required field: "${column ?? "unknown"}" in "${
|
|
5989
|
+
return new Error(`Missing required field: "${column ?? "unknown"}" in "${tableRef}" cannot be empty.${suffix}`);
|
|
6768
5990
|
case "23514":
|
|
6769
|
-
return new Error(`Validation failed: a check constraint${constraint ? ` (${constraint})` : ""} was violated in "${collectionSlug}"
|
|
5991
|
+
return new Error(`Validation failed: a check constraint${constraint ? ` (${constraint})` : ""} was violated in "${collectionSlug}".${suffix}`);
|
|
5992
|
+
case "22P02":
|
|
5993
|
+
return new Error(`Invalid data format in "${collectionSlug}": ${pgMessage}${suffix}`);
|
|
5994
|
+
case "22001":
|
|
5995
|
+
return new Error(`Value too long for column "${column ?? "unknown"}" in "${tableRef}": ${pgMessage}${suffix}`);
|
|
5996
|
+
case "22003":
|
|
5997
|
+
return new Error(`Numeric value out of range for column "${column ?? "unknown"}" in "${tableRef}": ${pgMessage}${suffix}`);
|
|
5998
|
+
case "42703":
|
|
5999
|
+
return new Error(`Unknown column in "${tableRef}": ${pgMessage}. Check if your schema is up to date (run migrations).${suffix}`);
|
|
6000
|
+
case "42P01":
|
|
6001
|
+
return new Error(`Table not found for "${collectionSlug}": ${pgMessage}. Check if your schema is up to date (run migrations).${suffix}`);
|
|
6002
|
+
default: {
|
|
6003
|
+
const parts = [`Database error in "${collectionSlug}" [${pgError.code}]: ${pgMessage}`];
|
|
6004
|
+
if (detail) parts.push(`Detail: ${detail}`);
|
|
6005
|
+
if (column) parts.push(`Column: ${column}`);
|
|
6006
|
+
if (dataType) parts.push(`Data type: ${dataType}`);
|
|
6007
|
+
if (constraint) parts.push(`Constraint: ${constraint}`);
|
|
6008
|
+
if (hint) parts.push(`Hint: ${hint}`);
|
|
6009
|
+
return new Error(parts.join(". "));
|
|
6010
|
+
}
|
|
6011
|
+
}
|
|
6012
|
+
}
|
|
6013
|
+
const causeMessage = this.extractCauseMessage(error);
|
|
6014
|
+
if (causeMessage) {
|
|
6015
|
+
return new Error(`Database error in "${collectionSlug}": ${causeMessage}`);
|
|
6016
|
+
}
|
|
6017
|
+
if (error instanceof Error) {
|
|
6018
|
+
const cleaned = this.stripSqlFromMessage(error.message, collectionSlug);
|
|
6019
|
+
return new Error(cleaned);
|
|
6020
|
+
}
|
|
6021
|
+
return new Error(`Database error in "${collectionSlug}": ${String(error)}`);
|
|
6022
|
+
}
|
|
6023
|
+
/**
|
|
6024
|
+
* Walk the error cause chain and return the deepest meaningful message.
|
|
6025
|
+
*/
|
|
6026
|
+
extractCauseMessage(error) {
|
|
6027
|
+
if (!error || typeof error !== "object") return null;
|
|
6028
|
+
const err = error;
|
|
6029
|
+
if (err.cause && typeof err.cause === "object") {
|
|
6030
|
+
const deeper = this.extractCauseMessage(err.cause);
|
|
6031
|
+
if (deeper) return deeper;
|
|
6032
|
+
if (err.cause instanceof Error && err.cause.message) {
|
|
6033
|
+
return err.cause.message;
|
|
6770
6034
|
}
|
|
6771
6035
|
}
|
|
6772
|
-
|
|
6773
|
-
|
|
6036
|
+
return null;
|
|
6037
|
+
}
|
|
6038
|
+
/**
|
|
6039
|
+
* Strip the raw SQL query from a Drizzle "Failed query: ..." message,
|
|
6040
|
+
* keeping only the error description.
|
|
6041
|
+
*/
|
|
6042
|
+
stripSqlFromMessage(message, collectionSlug) {
|
|
6043
|
+
if (message.startsWith("Failed query:")) {
|
|
6044
|
+
return `Failed to save entity in "${collectionSlug}". Check server logs for details.`;
|
|
6045
|
+
}
|
|
6046
|
+
return message;
|
|
6774
6047
|
}
|
|
6775
6048
|
/**
|
|
6776
6049
|
* Extract the underlying PostgreSQL error from a Drizzle wrapper.
|
|
@@ -6779,7 +6052,7 @@ class EntityPersistService {
|
|
|
6779
6052
|
extractPgError(error) {
|
|
6780
6053
|
if (!error || typeof error !== "object") return null;
|
|
6781
6054
|
const err = error;
|
|
6782
|
-
if (err.code && /^[0-
|
|
6055
|
+
if (err.code && /^[0-9A-Z]{5}$/.test(err.code)) {
|
|
6783
6056
|
return err;
|
|
6784
6057
|
}
|
|
6785
6058
|
if (err.cause && typeof err.cause === "object") {
|
|
@@ -7067,6 +6340,7 @@ class PostgresBackendDriver {
|
|
|
7067
6340
|
branchService;
|
|
7068
6341
|
user;
|
|
7069
6342
|
data;
|
|
6343
|
+
client;
|
|
7070
6344
|
/**
|
|
7071
6345
|
* When true, realtime notifications are deferred until after the
|
|
7072
6346
|
* wrapping transaction commits. Set by `withAuth` → `withTransaction`.
|
|
@@ -7095,6 +6369,14 @@ class PostgresBackendDriver {
|
|
|
7095
6369
|
} : {}
|
|
7096
6370
|
};
|
|
7097
6371
|
}
|
|
6372
|
+
/**
|
|
6373
|
+
* REST-optimised fetch service (include-aware eager-loading).
|
|
6374
|
+
* Delegates to the underlying EntityFetchService which already
|
|
6375
|
+
* implements the matching method signatures.
|
|
6376
|
+
*/
|
|
6377
|
+
get restFetchService() {
|
|
6378
|
+
return this.entityService.getFetchService();
|
|
6379
|
+
}
|
|
7098
6380
|
resolveCollectionCallbacks(collection, path2) {
|
|
7099
6381
|
if (!collection && !path2) return {
|
|
7100
6382
|
collection: void 0,
|
|
@@ -7148,7 +6430,8 @@ class PostgresBackendDriver {
|
|
|
7148
6430
|
const contextForCallback = {
|
|
7149
6431
|
user: this.user,
|
|
7150
6432
|
driver: this,
|
|
7151
|
-
data: this.data
|
|
6433
|
+
data: this.data,
|
|
6434
|
+
client: this.client
|
|
7152
6435
|
};
|
|
7153
6436
|
return Promise.all(entities.map(async (entity) => {
|
|
7154
6437
|
let fetched = entity;
|
|
@@ -7242,7 +6525,8 @@ class PostgresBackendDriver {
|
|
|
7242
6525
|
const contextForCallback = {
|
|
7243
6526
|
user: this.user,
|
|
7244
6527
|
driver: this,
|
|
7245
|
-
data: this.data
|
|
6528
|
+
data: this.data,
|
|
6529
|
+
client: this.client
|
|
7246
6530
|
};
|
|
7247
6531
|
if (callbacks?.afterRead) {
|
|
7248
6532
|
entity = await callbacks.afterRead({
|
|
@@ -7311,7 +6595,8 @@ class PostgresBackendDriver {
|
|
|
7311
6595
|
const contextForCallback = {
|
|
7312
6596
|
user: this.user,
|
|
7313
6597
|
driver: this,
|
|
7314
|
-
data: this.data
|
|
6598
|
+
data: this.data,
|
|
6599
|
+
client: this.client
|
|
7315
6600
|
};
|
|
7316
6601
|
let previousValuesForHistory;
|
|
7317
6602
|
if (status === "existing" && entityId) {
|
|
@@ -7346,6 +6631,14 @@ class PostgresBackendDriver {
|
|
|
7346
6631
|
if (result) updatedValues = mergeDeep(updatedValues, result);
|
|
7347
6632
|
}
|
|
7348
6633
|
}
|
|
6634
|
+
if (resolvedCollection?.properties) {
|
|
6635
|
+
updatedValues = updateDateAutoValues({
|
|
6636
|
+
inputValues: updatedValues,
|
|
6637
|
+
properties: resolvedCollection.properties,
|
|
6638
|
+
status: status ?? "new",
|
|
6639
|
+
timestampNowValue: /* @__PURE__ */ new Date()
|
|
6640
|
+
});
|
|
6641
|
+
}
|
|
7349
6642
|
try {
|
|
7350
6643
|
let savedEntity = await this.entityService.saveEntity(path2, updatedValues, entityId, resolvedCollection?.databaseId);
|
|
7351
6644
|
if (savedEntity && (callbacks?.afterRead || propertyCallbacks?.afterRead)) {
|
|
@@ -7451,7 +6744,8 @@ class PostgresBackendDriver {
|
|
|
7451
6744
|
const contextForCallback = {
|
|
7452
6745
|
user: this.user,
|
|
7453
6746
|
driver: this,
|
|
7454
|
-
data: this.data
|
|
6747
|
+
data: this.data,
|
|
6748
|
+
client: this.client
|
|
7455
6749
|
};
|
|
7456
6750
|
if (callbacks?.beforeDelete || propertyCallbacks?.beforeDelete) {
|
|
7457
6751
|
if (callbacks?.beforeDelete) {
|
|
@@ -7543,7 +6837,17 @@ class PostgresBackendDriver {
|
|
|
7543
6837
|
}
|
|
7544
6838
|
const targetDb = this.getTargetDb(options?.database);
|
|
7545
6839
|
try {
|
|
7546
|
-
|
|
6840
|
+
let needsRoleSwitch = false;
|
|
6841
|
+
if (options?.role && process.env.DISABLE_DB_ROLE_SWITCHING !== "true") {
|
|
6842
|
+
try {
|
|
6843
|
+
const currentRoleResult = await targetDb.execute(sql.raw("SELECT current_user AS role"));
|
|
6844
|
+
const currentRole = currentRoleResult.rows?.[0]?.role;
|
|
6845
|
+
needsRoleSwitch = !!currentRole && currentRole !== options.role;
|
|
6846
|
+
} catch {
|
|
6847
|
+
needsRoleSwitch = true;
|
|
6848
|
+
}
|
|
6849
|
+
}
|
|
6850
|
+
if (needsRoleSwitch && options?.role) {
|
|
7547
6851
|
const safeRole = options.role.replace(/"/g, '""');
|
|
7548
6852
|
return await targetDb.transaction(async (tx) => {
|
|
7549
6853
|
await tx.execute(sql.raw(`SET LOCAL ROLE "${safeRole}"`));
|
|
@@ -7778,6 +7082,7 @@ class AuthenticatedPostgresBackendDriver {
|
|
|
7778
7082
|
txDelegate.entityService = txEntityService;
|
|
7779
7083
|
txDelegate._deferNotifications = true;
|
|
7780
7084
|
txDelegate._pendingNotifications = pendingNotifications;
|
|
7085
|
+
txDelegate.client = this.delegate.client;
|
|
7781
7086
|
return await operation(txDelegate);
|
|
7782
7087
|
});
|
|
7783
7088
|
for (const notification of pendingNotifications) {
|
|
@@ -8059,6 +7364,12 @@ const userIdentitiesRelations = relations(userIdentities, ({
|
|
|
8059
7364
|
references: [users.id]
|
|
8060
7365
|
})
|
|
8061
7366
|
}));
|
|
7367
|
+
const resolveColumnName = (propName, prop) => {
|
|
7368
|
+
if (prop && "columnName" in prop && typeof prop.columnName === "string") {
|
|
7369
|
+
return prop.columnName;
|
|
7370
|
+
}
|
|
7371
|
+
return toSnakeCase(propName);
|
|
7372
|
+
};
|
|
8062
7373
|
const getPrimaryKeyProp = (collection) => {
|
|
8063
7374
|
if (collection.properties) {
|
|
8064
7375
|
const idPropEntry = Object.entries(collection.properties).find(([_, prop]) => "isId" in prop && Boolean(prop.isId));
|
|
@@ -8099,7 +7410,7 @@ const isIdProperty = (propName, prop, collection) => {
|
|
|
8099
7410
|
return !hasExplicitId && propName === "id";
|
|
8100
7411
|
};
|
|
8101
7412
|
const getDrizzleColumn = (propName, prop, collection, collections) => {
|
|
8102
|
-
const colName =
|
|
7413
|
+
const colName = resolveColumnName(propName, prop);
|
|
8103
7414
|
let columnDefinition;
|
|
8104
7415
|
switch (prop.type) {
|
|
8105
7416
|
case "string": {
|
|
@@ -8171,6 +7482,9 @@ const getDrizzleColumn = (propName, prop, collection, collections) => {
|
|
|
8171
7482
|
} else {
|
|
8172
7483
|
columnDefinition = `timestamp("${colName}", { withTimezone: true, mode: 'string' })`;
|
|
8173
7484
|
}
|
|
7485
|
+
if (dateProp.autoValue === "on_create" || dateProp.autoValue === "on_update") {
|
|
7486
|
+
columnDefinition += `.default(sql\`now()\`)`;
|
|
7487
|
+
}
|
|
8174
7488
|
break;
|
|
8175
7489
|
}
|
|
8176
7490
|
case "map":
|
|
@@ -8203,7 +7517,7 @@ const getDrizzleColumn = (propName, prop, collection, collections) => {
|
|
|
8203
7517
|
} catch {
|
|
8204
7518
|
return null;
|
|
8205
7519
|
}
|
|
8206
|
-
const fkColumnName =
|
|
7520
|
+
const fkColumnName = relation.localKey;
|
|
8207
7521
|
const targetTableVar = getTableVarName(getTableName(targetCollection));
|
|
8208
7522
|
const pkProp = getPrimaryKeyProp(targetCollection);
|
|
8209
7523
|
const targetIdField = pkProp.name;
|
|
@@ -8391,7 +7705,7 @@ const generateSchema = async (collections, stripPolicies = false) => {
|
|
|
8391
7705
|
Object.entries(collection.properties ?? {}).forEach(([propName, prop]) => {
|
|
8392
7706
|
if ("enum" in prop && (prop.type === "string" || prop.type === "number") && prop.enum) {
|
|
8393
7707
|
const enumVarName = getEnumVarName(collectionPath, propName);
|
|
8394
|
-
const enumDbName = `${collectionPath}_${
|
|
7708
|
+
const enumDbName = `${collectionPath}_${resolveColumnName(propName, prop)}`;
|
|
8395
7709
|
const values = Array.isArray(prop.enum) ? prop.enum.map((v) => String(v.id ?? v)) : Object.keys(prop.enum);
|
|
8396
7710
|
if (values.length > 0) {
|
|
8397
7711
|
schemaContent += `export const ${enumVarName} = pgEnum("${enumDbName}", [${values.map((v) => `'${v}'`).join(", ")}]);
|
|
@@ -8448,9 +7762,9 @@ const generateSchema = async (collections, stripPolicies = false) => {
|
|
|
8448
7762
|
const targetId = getPrimaryKeyName(targetCollection);
|
|
8449
7763
|
schemaContent += `export const ${tableVarName} = pgTable("${tableName}", {
|
|
8450
7764
|
`;
|
|
8451
|
-
schemaContent += ` ${sourceColumn}: ${sourceColType}("${
|
|
7765
|
+
schemaContent += ` ${sourceColumn}: ${sourceColType}("${sourceColumn}").notNull().references(() => ${getTableVarName(getTableName(sourceCollection))}.${sourceId}, ${refOptions}),
|
|
8452
7766
|
`;
|
|
8453
|
-
schemaContent += ` ${targetColumn}: ${targetColType}("${
|
|
7767
|
+
schemaContent += ` ${targetColumn}: ${targetColType}("${targetColumn}").notNull().references(() => ${getTableVarName(getTableName(targetCollection))}.${targetId}, ${refOptions}),
|
|
8454
7768
|
`;
|
|
8455
7769
|
schemaContent += "}, (table) => ({\n";
|
|
8456
7770
|
schemaContent += ` pk: primaryKey({ columns: [table.${sourceColumn}, table.${targetColumn}] })
|
|
@@ -8543,29 +7857,10 @@ const generateSchema = async (collections, stripPolicies = false) => {
|
|
|
8543
7857
|
references: [${targetTableVar}.${getPrimaryKeyName(target)}],
|
|
8544
7858
|
relationName: "${drizzleRelationName}"
|
|
8545
7859
|
})`);
|
|
8546
|
-
} else if (rel.direction === "inverse"
|
|
8547
|
-
const sourceIdField = getPrimaryKeyName(collection);
|
|
7860
|
+
} else if (rel.direction === "inverse") {
|
|
8548
7861
|
tableRelations.push(` "${relationKey}": one(${targetTableVar}, {
|
|
8549
|
-
fields: [${tableVarName}.${sourceIdField}],
|
|
8550
|
-
references: [${targetTableVar}.${rel.foreignKeyOnTarget}],
|
|
8551
7862
|
relationName: "${drizzleRelationName}"
|
|
8552
7863
|
})`);
|
|
8553
|
-
} else if (rel.direction === "inverse" && !rel.foreignKeyOnTarget) {
|
|
8554
|
-
try {
|
|
8555
|
-
const targetCollection = rel.target();
|
|
8556
|
-
const targetResolvedRelations = resolveCollectionRelations(targetCollection);
|
|
8557
|
-
const correspondingRelation = Object.values(targetResolvedRelations).find((targetRel) => targetRel.direction === "owning" && targetRel.cardinality === "one" && targetRel.target().slug === collection.slug);
|
|
8558
|
-
if (correspondingRelation && correspondingRelation.localKey) {
|
|
8559
|
-
const sourceIdField = getPrimaryKeyName(collection);
|
|
8560
|
-
tableRelations.push(` "${relationKey}": one(${targetTableVar}, {
|
|
8561
|
-
fields: [${tableVarName}.${sourceIdField}],
|
|
8562
|
-
references: [${targetTableVar}.${correspondingRelation.localKey}],
|
|
8563
|
-
relationName: "${drizzleRelationName}"
|
|
8564
|
-
})`);
|
|
8565
|
-
}
|
|
8566
|
-
} catch (e) {
|
|
8567
|
-
console.warn(`Could not resolve inverse one-to-one relation '${relationKey}':`, e);
|
|
8568
|
-
}
|
|
8569
7864
|
}
|
|
8570
7865
|
} else if (rel.cardinality === "many") {
|
|
8571
7866
|
if (rel.direction === "inverse" && rel.foreignKeyOnTarget) {
|
|
@@ -8593,6 +7888,32 @@ const generateSchema = async (collections, stripPolicies = false) => {
|
|
|
8593
7888
|
console.warn(`Could not generate relation ${relationKey} for ${collection.name}:`, e);
|
|
8594
7889
|
}
|
|
8595
7890
|
}
|
|
7891
|
+
for (const otherCollection of collections) {
|
|
7892
|
+
if (otherCollection.slug === collection.slug) continue;
|
|
7893
|
+
const otherRelations = resolveCollectionRelations(otherCollection);
|
|
7894
|
+
for (const [otherKey, otherRel] of Object.entries(otherRelations)) {
|
|
7895
|
+
if (otherRel.direction === "inverse" && otherRel.foreignKeyOnTarget) {
|
|
7896
|
+
try {
|
|
7897
|
+
const otherTarget = otherRel.target();
|
|
7898
|
+
if (otherTarget.slug === collection.slug) {
|
|
7899
|
+
const drizzleRelationName = computeSharedRelationName(otherRel, otherCollection, collections);
|
|
7900
|
+
const deduplicationKey = `${drizzleRelationName}::owning`;
|
|
7901
|
+
if (!emittedRelationNames.has(deduplicationKey)) {
|
|
7902
|
+
const otherTableVar = getTableVarName(getTableName(otherCollection));
|
|
7903
|
+
const synthKey = `_synth_${otherTableVar}_${otherRel.foreignKeyOnTarget}`;
|
|
7904
|
+
tableRelations.push(` "${synthKey}": one(${otherTableVar}, {
|
|
7905
|
+
fields: [${tableVarName}.${otherRel.foreignKeyOnTarget}],
|
|
7906
|
+
references: [${otherTableVar}.${getPrimaryKeyName(otherCollection)}],
|
|
7907
|
+
relationName: "${drizzleRelationName}"
|
|
7908
|
+
})`);
|
|
7909
|
+
emittedRelationNames.add(deduplicationKey);
|
|
7910
|
+
}
|
|
7911
|
+
}
|
|
7912
|
+
} catch (e) {
|
|
7913
|
+
}
|
|
7914
|
+
}
|
|
7915
|
+
}
|
|
7916
|
+
}
|
|
8596
7917
|
}
|
|
8597
7918
|
if (tableRelations.length > 0) {
|
|
8598
7919
|
const relVarName = `${tableVarName}Relations`;
|
|
@@ -9372,6 +8693,31 @@ class RealtimeService extends EventEmitter {
|
|
|
9372
8693
|
return parentPaths;
|
|
9373
8694
|
}
|
|
9374
8695
|
// =============================================================================
|
|
8696
|
+
// Lifecycle / Cleanup
|
|
8697
|
+
// =============================================================================
|
|
8698
|
+
/**
|
|
8699
|
+
* Gracefully tear down all realtime resources.
|
|
8700
|
+
*
|
|
8701
|
+
* This MUST be called during process shutdown, **before** `pool.end()`.
|
|
8702
|
+
* It ensures:
|
|
8703
|
+
* 1. All debounced refetch timers are cancelled (prevents queries after pool closes).
|
|
8704
|
+
* 2. All subscription state and callbacks are cleared.
|
|
8705
|
+
* 3. The dedicated LISTEN client (outside the pool) is disconnected.
|
|
8706
|
+
* 4. All WebSocket clients are removed (but not forcefully closed — the
|
|
8707
|
+
* HTTP server close will handle that).
|
|
8708
|
+
*/
|
|
8709
|
+
async destroy() {
|
|
8710
|
+
for (const [key, timer] of this.refetchTimers) {
|
|
8711
|
+
clearTimeout(timer);
|
|
8712
|
+
this.refetchTimers.delete(key);
|
|
8713
|
+
}
|
|
8714
|
+
this._subscriptions.clear();
|
|
8715
|
+
this.subscriptionCallbacks.clear();
|
|
8716
|
+
await this.stopListening();
|
|
8717
|
+
this.clients.clear();
|
|
8718
|
+
this.debugLog("🧹 [RealtimeService] destroy() complete — all resources released.");
|
|
8719
|
+
}
|
|
8720
|
+
// =============================================================================
|
|
9375
8721
|
// Cross-Instance LISTEN/NOTIFY
|
|
9376
8722
|
// =============================================================================
|
|
9377
8723
|
/**
|
|
@@ -9513,7 +8859,9 @@ const WS_RATE_LIMIT = 2e3;
|
|
|
9513
8859
|
const WS_RATE_WINDOW_MS = 6e4;
|
|
9514
8860
|
const ADMIN_ONLY_TYPES = /* @__PURE__ */ new Set(["EXECUTE_SQL", "FETCH_DATABASES", "FETCH_ROLES", "FETCH_UNMAPPED_TABLES", "FETCH_TABLE_METADATA", "FETCH_CURRENT_DATABASE", "CREATE_BRANCH", "DELETE_BRANCH", "LIST_BRANCHES"]);
|
|
9515
8861
|
function isAdminSession(session) {
|
|
9516
|
-
if (!session?.user
|
|
8862
|
+
if (!session?.user) return false;
|
|
8863
|
+
if (session.user.isAdmin) return true;
|
|
8864
|
+
if (!session.user.roles) return false;
|
|
9517
8865
|
return session.user.roles.some((r) => {
|
|
9518
8866
|
if (typeof r === "string") return r === "admin";
|
|
9519
8867
|
if (r && typeof r === "object" && "isAdmin" in r) return r.isAdmin;
|
|
@@ -9521,7 +8869,7 @@ function isAdminSession(session) {
|
|
|
9521
8869
|
return false;
|
|
9522
8870
|
});
|
|
9523
8871
|
}
|
|
9524
|
-
function createPostgresWebSocket(server, realtimeService, driver, authConfig) {
|
|
8872
|
+
function createPostgresWebSocket(server, realtimeService, driver, authConfig, authAdapter) {
|
|
9525
8873
|
const isProduction = process.env.NODE_ENV === "production";
|
|
9526
8874
|
const wsDebug = (...args) => {
|
|
9527
8875
|
if (!isProduction) console.debug(...args);
|
|
@@ -9535,7 +8883,7 @@ function createPostgresWebSocket(server, realtimeService, driver, authConfig) {
|
|
|
9535
8883
|
}
|
|
9536
8884
|
console.error("❌ [WebSocket Server] Error:", err);
|
|
9537
8885
|
});
|
|
9538
|
-
const requireAuth = authConfig?.requireAuth !== false && authConfig?.jwtSecret;
|
|
8886
|
+
const requireAuth = authAdapter ? true : authConfig?.requireAuth !== false && !!authConfig?.jwtSecret;
|
|
9539
8887
|
wss.on("connection", (ws) => {
|
|
9540
8888
|
const clientId = `client_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
9541
8889
|
wsDebug(`WebSocket client connected: ${clientId}`);
|
|
@@ -9580,11 +8928,37 @@ function createPostgresWebSocket(server, realtimeService, driver, authConfig) {
|
|
|
9580
8928
|
sendError("AUTH_ERROR", "INVALID_INPUT", "Token is required");
|
|
9581
8929
|
return;
|
|
9582
8930
|
}
|
|
9583
|
-
|
|
9584
|
-
if (
|
|
8931
|
+
let verifiedUser = null;
|
|
8932
|
+
if (authAdapter) {
|
|
8933
|
+
try {
|
|
8934
|
+
const adapterUser = authAdapter.verifyToken ? await authAdapter.verifyToken(token) : await authAdapter.verifyRequest(new Request("http://localhost/_ws_auth", {
|
|
8935
|
+
headers: {
|
|
8936
|
+
Authorization: `Bearer ${token}`
|
|
8937
|
+
}
|
|
8938
|
+
}));
|
|
8939
|
+
if (adapterUser) {
|
|
8940
|
+
verifiedUser = {
|
|
8941
|
+
userId: adapterUser.uid,
|
|
8942
|
+
roles: adapterUser.roles,
|
|
8943
|
+
isAdmin: adapterUser.isAdmin
|
|
8944
|
+
};
|
|
8945
|
+
}
|
|
8946
|
+
} catch {
|
|
8947
|
+
}
|
|
8948
|
+
} else {
|
|
8949
|
+
const jwtPayload = extractUserFromToken(token);
|
|
8950
|
+
if (jwtPayload) {
|
|
8951
|
+
verifiedUser = {
|
|
8952
|
+
userId: jwtPayload.userId,
|
|
8953
|
+
roles: jwtPayload.roles ?? [],
|
|
8954
|
+
isAdmin: (jwtPayload.roles ?? []).some((r) => r === "admin")
|
|
8955
|
+
};
|
|
8956
|
+
}
|
|
8957
|
+
}
|
|
8958
|
+
if (verifiedUser) {
|
|
9585
8959
|
const session = clientSessions.get(clientId);
|
|
9586
8960
|
if (session) {
|
|
9587
|
-
session.user =
|
|
8961
|
+
session.user = verifiedUser;
|
|
9588
8962
|
session.authenticated = true;
|
|
9589
8963
|
}
|
|
9590
8964
|
wsDebug(`[WS] replying AUTH_SUCCESS for requestId ${requestId}`);
|
|
@@ -9592,11 +8966,11 @@ function createPostgresWebSocket(server, realtimeService, driver, authConfig) {
|
|
|
9592
8966
|
type: "AUTH_SUCCESS",
|
|
9593
8967
|
requestId,
|
|
9594
8968
|
payload: {
|
|
9595
|
-
userId:
|
|
9596
|
-
roles:
|
|
8969
|
+
userId: verifiedUser.userId,
|
|
8970
|
+
roles: verifiedUser.roles
|
|
9597
8971
|
}
|
|
9598
8972
|
}));
|
|
9599
|
-
wsDebug(`🔐 [WebSocket Server] Client ${clientId} authenticated as ${
|
|
8973
|
+
wsDebug(`🔐 [WebSocket Server] Client ${clientId} authenticated as ${verifiedUser.userId}`);
|
|
9600
8974
|
} else {
|
|
9601
8975
|
wsDebug(`[WS] replying AUTH_ERROR for requestId ${requestId} (invalid token)`);
|
|
9602
8976
|
sendError("AUTH_ERROR", "INVALID_TOKEN", "Invalid or expired token");
|
|
@@ -10125,6 +9499,9 @@ async function ensureAuthTablesExist(db) {
|
|
|
10125
9499
|
password_hash TEXT,
|
|
10126
9500
|
display_name TEXT,
|
|
10127
9501
|
photo_url TEXT,
|
|
9502
|
+
email_verified BOOLEAN DEFAULT FALSE,
|
|
9503
|
+
email_verification_token TEXT,
|
|
9504
|
+
email_verification_sent_at TIMESTAMP WITH TIME ZONE,
|
|
10128
9505
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
10129
9506
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
10130
9507
|
)
|
|
@@ -10216,7 +9593,6 @@ async function ensureAuthTablesExist(db) {
|
|
|
10216
9593
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
10217
9594
|
)
|
|
10218
9595
|
`);
|
|
10219
|
-
await applyInternalMigrations(db);
|
|
10220
9596
|
await db.execute(sql`CREATE SCHEMA IF NOT EXISTS auth`);
|
|
10221
9597
|
await db.transaction(async (tx) => {
|
|
10222
9598
|
await tx.execute(sql`SELECT pg_advisory_xact_lock(hashtext('rebase_auth_functions_init'))`);
|
|
@@ -10269,99 +9645,6 @@ async function seedDefaultRoles(db) {
|
|
|
10269
9645
|
}
|
|
10270
9646
|
console.log("✅ Default roles created: admin, editor, viewer");
|
|
10271
9647
|
}
|
|
10272
|
-
async function applyInternalMigrations(db) {
|
|
10273
|
-
try {
|
|
10274
|
-
await db.execute(sql`
|
|
10275
|
-
ALTER TABLE rebase.users
|
|
10276
|
-
ADD COLUMN IF NOT EXISTS email_verified BOOLEAN DEFAULT FALSE,
|
|
10277
|
-
ADD COLUMN IF NOT EXISTS email_verification_token TEXT,
|
|
10278
|
-
ADD COLUMN IF NOT EXISTS email_verification_sent_at TIMESTAMP WITH TIME ZONE
|
|
10279
|
-
`);
|
|
10280
|
-
const columnsCheck = await db.execute(sql`
|
|
10281
|
-
SELECT column_name
|
|
10282
|
-
FROM information_schema.columns
|
|
10283
|
-
WHERE table_schema='rebase' AND table_name='users' AND column_name IN ('google_id', 'linkedin_id', 'provider')
|
|
10284
|
-
`);
|
|
10285
|
-
const existingColumns = columnsCheck.rows.map((r) => r.column_name);
|
|
10286
|
-
if (existingColumns.includes("google_id")) {
|
|
10287
|
-
await db.execute(sql`
|
|
10288
|
-
INSERT INTO rebase.user_identities (user_id, provider, provider_id)
|
|
10289
|
-
SELECT id, 'google', google_id
|
|
10290
|
-
FROM rebase.users
|
|
10291
|
-
WHERE google_id IS NOT NULL
|
|
10292
|
-
ON CONFLICT (provider, provider_id) DO NOTHING
|
|
10293
|
-
`);
|
|
10294
|
-
}
|
|
10295
|
-
if (existingColumns.includes("linkedin_id")) {
|
|
10296
|
-
await db.execute(sql`
|
|
10297
|
-
INSERT INTO rebase.user_identities (user_id, provider, provider_id)
|
|
10298
|
-
SELECT id, 'linkedin', linkedin_id
|
|
10299
|
-
FROM rebase.users
|
|
10300
|
-
WHERE linkedin_id IS NOT NULL
|
|
10301
|
-
ON CONFLICT (provider, provider_id) DO NOTHING
|
|
10302
|
-
`);
|
|
10303
|
-
}
|
|
10304
|
-
if (existingColumns.length > 0) {
|
|
10305
|
-
await db.execute(sql`
|
|
10306
|
-
ALTER TABLE rebase.users
|
|
10307
|
-
DROP COLUMN IF EXISTS provider,
|
|
10308
|
-
DROP COLUMN IF EXISTS google_id,
|
|
10309
|
-
DROP COLUMN IF EXISTS linkedin_id
|
|
10310
|
-
`);
|
|
10311
|
-
await db.execute(sql`DROP INDEX IF EXISTS rebase.idx_users_google_id`);
|
|
10312
|
-
await db.execute(sql`DROP INDEX IF EXISTS rebase.idx_users_linkedin_id`);
|
|
10313
|
-
console.log("✅ Migrated to user_identities and dropped legacy columns.");
|
|
10314
|
-
}
|
|
10315
|
-
await db.execute(sql`
|
|
10316
|
-
ALTER TABLE rebase.roles
|
|
10317
|
-
ADD COLUMN IF NOT EXISTS collection_permissions JSONB
|
|
10318
|
-
`);
|
|
10319
|
-
await db.execute(sql`
|
|
10320
|
-
ALTER TABLE rebase.refresh_tokens
|
|
10321
|
-
ADD COLUMN IF NOT EXISTS user_agent TEXT,
|
|
10322
|
-
ADD COLUMN IF NOT EXISTS ip_address TEXT
|
|
10323
|
-
`);
|
|
10324
|
-
const constraintCheck = await db.execute(sql`
|
|
10325
|
-
SELECT 1 FROM information_schema.table_constraints
|
|
10326
|
-
WHERE constraint_name = 'unique_device_session'
|
|
10327
|
-
AND table_schema = 'rebase'
|
|
10328
|
-
AND table_name = 'refresh_tokens'
|
|
10329
|
-
`);
|
|
10330
|
-
if (constraintCheck.rows.length === 0) {
|
|
10331
|
-
try {
|
|
10332
|
-
await db.execute(sql`
|
|
10333
|
-
ALTER TABLE rebase.refresh_tokens
|
|
10334
|
-
ADD CONSTRAINT unique_device_session UNIQUE (user_id, user_agent, ip_address)
|
|
10335
|
-
`);
|
|
10336
|
-
console.log("✅ Added unique_device_session constraint");
|
|
10337
|
-
} catch (e) {
|
|
10338
|
-
const errorMessage = e instanceof Error ? e.message : String(e);
|
|
10339
|
-
if (errorMessage.includes("could not create unique index")) {
|
|
10340
|
-
console.warn("⚠️ Duplicate sessions found, cleaning up before adding constraint...");
|
|
10341
|
-
await db.execute(sql`
|
|
10342
|
-
DELETE FROM rebase.refresh_tokens a
|
|
10343
|
-
USING rebase.refresh_tokens b
|
|
10344
|
-
WHERE a.user_id = b.user_id
|
|
10345
|
-
AND COALESCE(a.user_agent, '') = COALESCE(b.user_agent, '')
|
|
10346
|
-
AND COALESCE(a.ip_address, '') = COALESCE(b.ip_address, '')
|
|
10347
|
-
AND a.created_at < b.created_at
|
|
10348
|
-
`);
|
|
10349
|
-
await db.execute(sql`
|
|
10350
|
-
ALTER TABLE rebase.refresh_tokens
|
|
10351
|
-
ADD CONSTRAINT unique_device_session UNIQUE (user_id, user_agent, ip_address)
|
|
10352
|
-
`).catch((retryErr) => {
|
|
10353
|
-
const retryMessage = retryErr instanceof Error ? retryErr.message : String(retryErr);
|
|
10354
|
-
console.error("Failed to add unique_device_session constraint after cleanup:", retryMessage);
|
|
10355
|
-
});
|
|
10356
|
-
} else {
|
|
10357
|
-
console.error("Constraint migration issue:", errorMessage);
|
|
10358
|
-
}
|
|
10359
|
-
}
|
|
10360
|
-
}
|
|
10361
|
-
} catch (error) {
|
|
10362
|
-
console.error("❌ Failed to run internal migrations:", error);
|
|
10363
|
-
}
|
|
10364
|
-
}
|
|
10365
9648
|
class UserService {
|
|
10366
9649
|
constructor(db) {
|
|
10367
9650
|
this.db = db;
|
|
@@ -10371,11 +9654,11 @@ class UserService {
|
|
|
10371
9654
|
return user;
|
|
10372
9655
|
}
|
|
10373
9656
|
async getUserById(id) {
|
|
10374
|
-
const [user] = await this.db.select().from(users).where(eq
|
|
9657
|
+
const [user] = await this.db.select().from(users).where(eq(users.id, id));
|
|
10375
9658
|
return user || null;
|
|
10376
9659
|
}
|
|
10377
9660
|
async getUserByEmail(email) {
|
|
10378
|
-
const [user] = await this.db.select().from(users).where(eq
|
|
9661
|
+
const [user] = await this.db.select().from(users).where(eq(users.email, email.toLowerCase()));
|
|
10379
9662
|
return user || null;
|
|
10380
9663
|
}
|
|
10381
9664
|
async getUserByIdentity(provider, providerId) {
|
|
@@ -10431,11 +9714,11 @@ class UserService {
|
|
|
10431
9714
|
const [user] = await this.db.update(users).set({
|
|
10432
9715
|
...data,
|
|
10433
9716
|
updatedAt: /* @__PURE__ */ new Date()
|
|
10434
|
-
}).where(eq
|
|
9717
|
+
}).where(eq(users.id, id)).returning();
|
|
10435
9718
|
return user || null;
|
|
10436
9719
|
}
|
|
10437
9720
|
async deleteUser(id) {
|
|
10438
|
-
await this.db.delete(users).where(eq
|
|
9721
|
+
await this.db.delete(users).where(eq(users.id, id));
|
|
10439
9722
|
}
|
|
10440
9723
|
async listUsers() {
|
|
10441
9724
|
return this.db.select().from(users);
|
|
@@ -10504,7 +9787,7 @@ class UserService {
|
|
|
10504
9787
|
await this.db.update(users).set({
|
|
10505
9788
|
passwordHash,
|
|
10506
9789
|
updatedAt: /* @__PURE__ */ new Date()
|
|
10507
|
-
}).where(eq
|
|
9790
|
+
}).where(eq(users.id, id));
|
|
10508
9791
|
}
|
|
10509
9792
|
/**
|
|
10510
9793
|
* Set email verification status
|
|
@@ -10514,7 +9797,7 @@ class UserService {
|
|
|
10514
9797
|
emailVerified: verified,
|
|
10515
9798
|
emailVerificationToken: null,
|
|
10516
9799
|
updatedAt: /* @__PURE__ */ new Date()
|
|
10517
|
-
}).where(eq
|
|
9800
|
+
}).where(eq(users.id, id));
|
|
10518
9801
|
}
|
|
10519
9802
|
/**
|
|
10520
9803
|
* Set email verification token
|
|
@@ -10524,13 +9807,13 @@ class UserService {
|
|
|
10524
9807
|
emailVerificationToken: token,
|
|
10525
9808
|
emailVerificationSentAt: token ? /* @__PURE__ */ new Date() : null,
|
|
10526
9809
|
updatedAt: /* @__PURE__ */ new Date()
|
|
10527
|
-
}).where(eq
|
|
9810
|
+
}).where(eq(users.id, id));
|
|
10528
9811
|
}
|
|
10529
9812
|
/**
|
|
10530
9813
|
* Find user by email verification token
|
|
10531
9814
|
*/
|
|
10532
9815
|
async getUserByVerificationToken(token) {
|
|
10533
|
-
const [user] = await this.db.select().from(users).where(eq
|
|
9816
|
+
const [user] = await this.db.select().from(users).where(eq(users.emailVerificationToken, token));
|
|
10534
9817
|
return user || null;
|
|
10535
9818
|
}
|
|
10536
9819
|
/**
|
|
@@ -10703,14 +9986,14 @@ class RefreshTokenService {
|
|
|
10703
9986
|
createdAt: refreshTokens.createdAt,
|
|
10704
9987
|
userAgent: refreshTokens.userAgent,
|
|
10705
9988
|
ipAddress: refreshTokens.ipAddress
|
|
10706
|
-
}).from(refreshTokens).where(eq
|
|
9989
|
+
}).from(refreshTokens).where(eq(refreshTokens.tokenHash, tokenHash));
|
|
10707
9990
|
return token || null;
|
|
10708
9991
|
}
|
|
10709
9992
|
async deleteByHash(tokenHash) {
|
|
10710
|
-
await this.db.delete(refreshTokens).where(eq
|
|
9993
|
+
await this.db.delete(refreshTokens).where(eq(refreshTokens.tokenHash, tokenHash));
|
|
10711
9994
|
}
|
|
10712
9995
|
async deleteAllForUser(userId) {
|
|
10713
|
-
await this.db.delete(refreshTokens).where(eq
|
|
9996
|
+
await this.db.delete(refreshTokens).where(eq(refreshTokens.userId, userId));
|
|
10714
9997
|
}
|
|
10715
9998
|
async listForUser(userId) {
|
|
10716
9999
|
const tokens = await this.db.select({
|
|
@@ -10721,7 +10004,7 @@ class RefreshTokenService {
|
|
|
10721
10004
|
createdAt: refreshTokens.createdAt,
|
|
10722
10005
|
userAgent: refreshTokens.userAgent,
|
|
10723
10006
|
ipAddress: refreshTokens.ipAddress
|
|
10724
|
-
}).from(refreshTokens).where(eq
|
|
10007
|
+
}).from(refreshTokens).where(eq(refreshTokens.userId, userId)).orderBy(refreshTokens.createdAt);
|
|
10725
10008
|
return tokens;
|
|
10726
10009
|
}
|
|
10727
10010
|
async deleteById(id, userId) {
|
|
@@ -10753,7 +10036,7 @@ class PasswordResetTokenService {
|
|
|
10753
10036
|
const [token] = await this.db.select({
|
|
10754
10037
|
userId: passwordResetTokens.userId,
|
|
10755
10038
|
expiresAt: passwordResetTokens.expiresAt
|
|
10756
|
-
}).from(passwordResetTokens).where(eq
|
|
10039
|
+
}).from(passwordResetTokens).where(eq(passwordResetTokens.tokenHash, tokenHash));
|
|
10757
10040
|
if (!token) return null;
|
|
10758
10041
|
const result = await this.db.execute(sql`
|
|
10759
10042
|
SELECT user_id, expires_at
|
|
@@ -10775,13 +10058,13 @@ class PasswordResetTokenService {
|
|
|
10775
10058
|
async markAsUsed(tokenHash) {
|
|
10776
10059
|
await this.db.update(passwordResetTokens).set({
|
|
10777
10060
|
usedAt: /* @__PURE__ */ new Date()
|
|
10778
|
-
}).where(eq
|
|
10061
|
+
}).where(eq(passwordResetTokens.tokenHash, tokenHash));
|
|
10779
10062
|
}
|
|
10780
10063
|
/**
|
|
10781
10064
|
* Delete all tokens for a user
|
|
10782
10065
|
*/
|
|
10783
10066
|
async deleteAllForUser(userId) {
|
|
10784
|
-
await this.db.delete(passwordResetTokens).where(eq
|
|
10067
|
+
await this.db.delete(passwordResetTokens).where(eq(passwordResetTokens.userId, userId));
|
|
10785
10068
|
}
|
|
10786
10069
|
/**
|
|
10787
10070
|
* Clean up expired tokens
|
|
@@ -11258,11 +10541,48 @@ function createPostgresBootstrapper(pgConfig) {
|
|
|
11258
10541
|
},
|
|
11259
10542
|
mountRoutes(app, basePath, driverResult) {
|
|
11260
10543
|
},
|
|
11261
|
-
async initializeWebsockets(server, realtimeService, driver, config) {
|
|
10544
|
+
async initializeWebsockets(server, realtimeService, driver, config, adapter) {
|
|
11262
10545
|
const {
|
|
11263
10546
|
createPostgresWebSocket: createPostgresWebSocket2
|
|
11264
10547
|
} = await Promise.resolve().then(() => websocket);
|
|
11265
|
-
createPostgresWebSocket2(server, realtimeService, driver, config);
|
|
10548
|
+
createPostgresWebSocket2(server, realtimeService, driver, config, adapter);
|
|
10549
|
+
}
|
|
10550
|
+
};
|
|
10551
|
+
}
|
|
10552
|
+
function createPostgresAdapter(pgConfig) {
|
|
10553
|
+
const bootstrapper = createPostgresBootstrapper(pgConfig);
|
|
10554
|
+
return {
|
|
10555
|
+
type: bootstrapper.type,
|
|
10556
|
+
async initializeDriver(config) {
|
|
10557
|
+
return bootstrapper.initializeDriver(config);
|
|
10558
|
+
},
|
|
10559
|
+
async initializeRealtime(driverResult) {
|
|
10560
|
+
if (bootstrapper.initializeRealtime) {
|
|
10561
|
+
return bootstrapper.initializeRealtime({}, driverResult);
|
|
10562
|
+
}
|
|
10563
|
+
return void 0;
|
|
10564
|
+
},
|
|
10565
|
+
async initializeHistory(config, driverResult) {
|
|
10566
|
+
if (bootstrapper.initializeHistory) {
|
|
10567
|
+
return bootstrapper.initializeHistory(config, driverResult);
|
|
10568
|
+
}
|
|
10569
|
+
return void 0;
|
|
10570
|
+
},
|
|
10571
|
+
initializeWebsockets(server, realtimeService, driver, config) {
|
|
10572
|
+
if (bootstrapper.initializeWebsockets) {
|
|
10573
|
+
return bootstrapper.initializeWebsockets(server, realtimeService, driver, config);
|
|
10574
|
+
}
|
|
10575
|
+
},
|
|
10576
|
+
getAdmin(driverResult) {
|
|
10577
|
+
if (bootstrapper.getAdmin) {
|
|
10578
|
+
return bootstrapper.getAdmin(driverResult);
|
|
10579
|
+
}
|
|
10580
|
+
return void 0;
|
|
10581
|
+
},
|
|
10582
|
+
mountRoutes(app, basePath, driverResult) {
|
|
10583
|
+
if (bootstrapper.mountRoutes) {
|
|
10584
|
+
bootstrapper.mountRoutes(app, basePath, driverResult);
|
|
10585
|
+
}
|
|
11266
10586
|
}
|
|
11267
10587
|
};
|
|
11268
10588
|
}
|
|
@@ -11277,6 +10597,7 @@ export {
|
|
|
11277
10597
|
PostgresRealtimeProvider,
|
|
11278
10598
|
RealtimeService,
|
|
11279
10599
|
appConfig,
|
|
10600
|
+
createPostgresAdapter,
|
|
11280
10601
|
createPostgresBootstrapper,
|
|
11281
10602
|
createPostgresDatabaseConnection,
|
|
11282
10603
|
createPostgresWebSocket,
|