@payloadcms/db-postgres 0.1.0-beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. package/dist/connect.js +82 -0
  2. package/dist/create.js +32 -0
  3. package/dist/createGlobal.js +32 -0
  4. package/dist/createGlobalVersion.js +48 -0
  5. package/dist/createMigration.js +85 -0
  6. package/dist/createVersion.js +54 -0
  7. package/dist/deleteMany.js +44 -0
  8. package/dist/deleteOne.js +47 -0
  9. package/dist/deleteVersions.js +46 -0
  10. package/dist/destroy.js +16 -0
  11. package/dist/find/buildFindManyArgs.js +61 -0
  12. package/dist/find/chainMethods.js +21 -0
  13. package/dist/find/findMany.js +197 -0
  14. package/dist/find/traverseFields.js +118 -0
  15. package/dist/find.js +35 -0
  16. package/dist/findGlobal.js +38 -0
  17. package/dist/findGlobalVersions.js +39 -0
  18. package/dist/findOne.js +49 -0
  19. package/dist/findVersions.js +39 -0
  20. package/dist/index.js +95 -0
  21. package/dist/init.js +74 -0
  22. package/dist/migrate.js +81 -0
  23. package/dist/migrateStatus.js +54 -0
  24. package/dist/mock.js +13 -0
  25. package/dist/queries/buildAndOrConditions.js +39 -0
  26. package/dist/queries/buildQuery.js +80 -0
  27. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js +24 -0
  28. package/dist/queries/createJSONQuery/formatJSONPathSegment.js +15 -0
  29. package/dist/queries/createJSONQuery/index.js +64 -0
  30. package/dist/queries/getTableColumnFromPath.js +333 -0
  31. package/dist/queries/operatorMap.js +34 -0
  32. package/dist/queries/parseParams.js +146 -0
  33. package/dist/queries/sanitizeQueryValue.js +79 -0
  34. package/dist/queryDrafts.js +56 -0
  35. package/dist/reference.js +76 -0
  36. package/dist/schema/build.js +245 -0
  37. package/dist/schema/createIndex.js +19 -0
  38. package/dist/schema/parentIDColumnMap.js +18 -0
  39. package/dist/schema/traverseFields.js +430 -0
  40. package/dist/schema/validateExistingBlockIsIdentical.js +34 -0
  41. package/dist/transactions/beginTransaction.js +51 -0
  42. package/dist/transactions/commitTransaction.js +24 -0
  43. package/dist/transactions/rollbackTransaction.js +20 -0
  44. package/dist/transform/read/hasManyNumber.js +20 -0
  45. package/dist/transform/read/index.js +42 -0
  46. package/dist/transform/read/relationship.js +74 -0
  47. package/dist/transform/read/traverseFields.js +325 -0
  48. package/dist/transform/write/array.js +55 -0
  49. package/dist/transform/write/blocks.js +56 -0
  50. package/dist/transform/write/index.js +46 -0
  51. package/dist/transform/write/numbers.js +21 -0
  52. package/dist/transform/write/relationships.js +33 -0
  53. package/dist/transform/write/selects.js +29 -0
  54. package/dist/transform/write/traverseFields.js +379 -0
  55. package/dist/transform/write/types.js +6 -0
  56. package/dist/types.js +6 -0
  57. package/dist/update.js +48 -0
  58. package/dist/updateGlobal.js +39 -0
  59. package/dist/updateGlobalVersion.js +50 -0
  60. package/dist/updateVersion.js +50 -0
  61. package/dist/upsertRow/deleteExistingArrayRows.js +20 -0
  62. package/dist/upsertRow/deleteExistingRowsByPath.js +43 -0
  63. package/dist/upsertRow/index.js +243 -0
  64. package/dist/upsertRow/insertArrays.js +64 -0
  65. package/dist/upsertRow/types.js +6 -0
  66. package/dist/utilities/appendPrefixToKeys.js +16 -0
  67. package/dist/utilities/createBlocksMap.js +39 -0
  68. package/dist/utilities/createMigrationTable.js +23 -0
  69. package/dist/utilities/createRelationshipMap.js +29 -0
  70. package/dist/utilities/hasLocalesTable.js +21 -0
  71. package/dist/utilities/isArrayOfRows.js +15 -0
  72. package/dist/utilities/migrationTableExists.js +19 -0
  73. package/dist/webpack.js +30 -0
  74. package/package.json +47 -0
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "sanitizeQueryValue", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return sanitizeQueryValue;
9
+ }
10
+ });
11
+ const _errors = require("payload/errors");
12
+ const _types = require("payload/types");
13
+ const _utilities = require("payload/utilities");
14
+ const sanitizeQueryValue = ({ field, operator: operatorArg, val })=>{
15
+ let operator = operatorArg;
16
+ let formattedValue = val;
17
+ if (!(0, _types.fieldAffectsData)(field)) return {
18
+ operator,
19
+ value: formattedValue
20
+ };
21
+ // Cast incoming values as proper searchable types
22
+ if (field.type === 'checkbox' && typeof val === 'string') {
23
+ if (val.toLowerCase() === 'true') formattedValue = true;
24
+ if (val.toLowerCase() === 'false') formattedValue = false;
25
+ }
26
+ if ([
27
+ 'all',
28
+ 'in',
29
+ 'not_in'
30
+ ].includes(operator) && typeof formattedValue === 'string') {
31
+ formattedValue = (0, _utilities.createArrayFromCommaDelineated)(formattedValue);
32
+ if (field.type === 'number') {
33
+ formattedValue = formattedValue.map((arrayVal)=>parseFloat(arrayVal));
34
+ }
35
+ }
36
+ if (field.type === 'number' && typeof formattedValue === 'string') {
37
+ formattedValue = Number(val);
38
+ }
39
+ if (field.type === 'date') {
40
+ if (typeof val === 'string') {
41
+ formattedValue = new Date(val);
42
+ if (Number.isNaN(Date.parse(formattedValue))) {
43
+ return {
44
+ operator,
45
+ value: undefined
46
+ };
47
+ }
48
+ }
49
+ if (typeof val === 'number') {
50
+ formattedValue = new Date(val);
51
+ }
52
+ }
53
+ if ([
54
+ 'relationship',
55
+ 'upload'
56
+ ].includes(field.type)) {
57
+ if (val === 'null') {
58
+ formattedValue = null;
59
+ }
60
+ }
61
+ if (operator === 'near' || operator === 'within' || operator === 'intersects') {
62
+ throw new _errors.APIError(`Querying with '${operator}' is not supported with the postgres database adapter.`);
63
+ }
64
+ if (operator === 'contains') {
65
+ formattedValue = `%${formattedValue}%`;
66
+ }
67
+ if (operator === 'exists') {
68
+ formattedValue = formattedValue === 'true' || formattedValue === true;
69
+ if (formattedValue === false) {
70
+ operator = 'isNull';
71
+ }
72
+ }
73
+ return {
74
+ operator,
75
+ value: formattedValue
76
+ };
77
+ };
78
+
79
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9xdWVyaWVzL3Nhbml0aX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BQUksT0FBT0osUUFBUSxVQUFVO1lBQzNCQyxpQkFBaUIsSUFBSVcsS0FBS1o7WUFDMUIsSUFBSVcsT0FBT0UsS0FBSyxDQUFDRCxLQUFLRSxLQUFLLENBQUNiLGtCQUFrQjtnQkFDNUMsT0FBTztvQkFBRUg7b0JBQVVLLE9BQU9ZO2dCQUFVO1lBQ3RDO1FBQ0Y7UUFFQSxJQUFJLE9BQU9mLFFBQVEsVUFBVTtZQUMzQkMsaUJBQWlCLElBQUlXLEtBQUtaO1FBQzVCO0lBQ0Y7SUFFQSxJQUFJO1FBQUM7UUFBZ0I7S0FBUyxDQUFDTSxRQUFRLENBQUNULE1BQU1PLElBQUksR0FBRztRQUNuRCxJQUFJSixRQUFRLFFBQVE7WUFDbEJDLGlCQUFpQjtRQUNuQjtJQUNGO0lBRUEsSUFBSUgsYUFBYSxVQUFVQSxhQUFhLFlBQVlBLGFBQWEsY0FBYztRQUM3RSxNQUFNLElBQUlrQixnQkFBUSxDQUNoQixDQUFDLGVBQWUsRUFBRWxCLFNBQVMsc0RBQXNELENBQUM7SUFFdEY7SUFFQSxJQUFJQSxhQUFhLFlBQVk7UUFDM0JHLGlCQUFpQixDQUFDLENBQUMsRUFBRUEsZUFBZSxDQUFDLENBQUM7SUFDeEM7SUFFQSxJQUFJSCxhQUFhLFVBQVU7UUFDekJHLGlCQUFpQkEsbUJBQW1CLFVBQVVBLG1CQUFtQjtRQUNqRSxJQUFJQSxtQkFBbUIsT0FBTztZQUM1QkgsV0FBVztRQUNiO0lBQ0Y7SUFFQSxPQUFPO1FBQUVBO1FBQVVLLE9BQU9GO0lBQWU7QUFDM0MifQ==
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "queryDrafts", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return queryDrafts;
9
+ }
10
+ });
11
+ const _database = require("payload/database");
12
+ const _versions = require("payload/versions");
13
+ const _tosnakecase = /*#__PURE__*/ _interop_require_default(require("to-snake-case"));
14
+ const _findMany = require("./find/findMany");
15
+ function _interop_require_default(obj) {
16
+ return obj && obj.__esModule ? obj : {
17
+ default: obj
18
+ };
19
+ }
20
+ const queryDrafts = async function queryDrafts({ collection, limit, locale, page = 1, pagination, req = {}, sort, where }) {
21
+ const collectionConfig = this.payload.collections[collection].config;
22
+ const tableName = `_${(0, _tosnakecase.default)(collection)}_v`;
23
+ const fields = (0, _versions.buildVersionCollectionFields)(collectionConfig);
24
+ const combinedWhere = (0, _database.combineQueries)({
25
+ latest: {
26
+ equals: true
27
+ }
28
+ }, where);
29
+ const result = await (0, _findMany.findMany)({
30
+ adapter: this,
31
+ fields,
32
+ limit,
33
+ locale,
34
+ page,
35
+ pagination,
36
+ req,
37
+ sort,
38
+ tableName,
39
+ where: combinedWhere
40
+ });
41
+ return {
42
+ ...result,
43
+ docs: result.docs.map((doc)=>{
44
+ // eslint-disable-next-line no-param-reassign
45
+ doc = {
46
+ id: doc.parent,
47
+ ...doc.version,
48
+ createdAt: doc.createdAt,
49
+ updatedAt: doc.updatedAt
50
+ };
51
+ return doc;
52
+ })
53
+ };
54
+ };
55
+
56
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9xdWVyeURyYWZ0cy50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgdHlwZSB7IFBheWxvYWRSZXF1ZXN0LCBTYW5pdGl6ZWRDb2xsZWN0aW9uQ29uZmlnIH0gZnJvbSAncGF5bG9hZC90eXBlcydcblxuaW1wb3J0IHsgdHlwZSBRdWVyeURyYWZ0cywgY29tYmluZVF1ZXJpZXMgfSBmcm9tICdwYXlsb2FkL2RhdGFiYXNlJ1xuaW1wb3J0IHsgYnVpbGRWZXJzaW9uQ29sbGVjdGlvbkZpZWxkcyB9IGZyb20gJ3BheWxvYWQvdmVyc2lvbnMnXG5pbXBvcnQgdG9TbmFrZ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UFDTjtJQUNDLE1BQU1DLG1CQUE4QyxJQUFJLENBQUNDLE9BQU8sQ0FBQ0MsV0FBVyxDQUFDVixXQUFXLENBQUNXLE1BQU07SUFDL0YsTUFBTUMsWUFBWSxDQUFDLENBQUMsRUFBRUMsSUFBQUEsb0JBQVcsRUFBQ2IsWUFBWSxFQUFFLENBQUM7SUFDakQsTUFBTWMsU0FBU0MsSUFBQUEsc0NBQTRCLEVBQUNQO0lBRTVDLE1BQU1RLGdCQUFnQkMsSUFBQUEsd0JBQWMsRUFBQztRQUFFQyxRQUFRO1lBQUVDLFFBQVE7UUFBSztJQUFFLEdBQUdaO0lBRW5FLE1BQU1hLFNBQVMsTUFBTUMsSUFBQUEsa0JBQVEsRUFBQztRQUM1QkMsU0FBUyxJQUFJO1FBQ2JSO1FBQ0FiO1FBQ0FDO1FBQ0FDO1FBQ0FDO1FBQ0FDO1FBQ0FDO1FBQ0FNO1FBQ0FMLE9BQU9TO0lBQ1Q7SUFFQSxPQUFPO1FBQ0wsR0FBR0ksTUFBTTtRQUNURyxNQUFNSCxPQUFPRyxJQUFJLENBQUNDLEdBQUcsQ0FBQyxDQUFDQztZQUNyQiw2Q0FBNkM7WUFDN0NBLE1BQU07Z0JBQ0pDLElBQUlELElBQUlFLE1BQU07Z0JBQ2QsR0FBR0YsSUFBSUcsT0FBTztnQkFDZEMsV0FBV0osSUFBSUksU0FBUztnQkFDeEJDLFdBQVdMLElBQUlLLFNBQVM7WUFDMUI7WUFFQSxPQUFPTDtRQUNUO0lBQ0Y7QUFDRiJ9
@@ -0,0 +1,76 @@
1
+ // type GenerateMigration = (before: DrizzleSnapshotJSON, after: DrizzleSnapshotJSON) => string[]
2
+ // type GenerateDrizzleJSON = (schema: DrizzleSchemaExports) => DrizzleSnapshotJSON
3
+ // type PushDiff = (schema: DrizzleSchemaExports) => Promise<{ warnings: string[], apply: () => Promise<void> }>
4
+ // drizzle-kit@utils
5
+ "use strict";
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ const _utils = require("drizzle-kit/utils");
10
+ const _nodepostgres = require("drizzle-orm/node-postgres");
11
+ const _pg = require("pg");
12
+ function _getRequireWildcardCache(nodeInterop) {
13
+ if (typeof WeakMap !== "function") return null;
14
+ var cacheBabelInterop = new WeakMap();
15
+ var cacheNodeInterop = new WeakMap();
16
+ return (_getRequireWildcardCache = function(nodeInterop) {
17
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
18
+ })(nodeInterop);
19
+ }
20
+ function _interop_require_wildcard(obj, nodeInterop) {
21
+ if (!nodeInterop && obj && obj.__esModule) {
22
+ return obj;
23
+ }
24
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
25
+ return {
26
+ default: obj
27
+ };
28
+ }
29
+ var cache = _getRequireWildcardCache(nodeInterop);
30
+ if (cache && cache.has(obj)) {
31
+ return cache.get(obj);
32
+ }
33
+ var newObj = {};
34
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
35
+ for(var key in obj){
36
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
37
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
38
+ if (desc && (desc.get || desc.set)) {
39
+ Object.defineProperty(newObj, key, desc);
40
+ } else {
41
+ newObj[key] = obj[key];
42
+ }
43
+ }
44
+ }
45
+ newObj.default = obj;
46
+ if (cache) {
47
+ cache.set(obj, newObj);
48
+ }
49
+ return newObj;
50
+ }
51
+ async function generateUsage() {
52
+ // @ts-expect-error Just TypeScript being broken // TODO: Open TypeScript issue
53
+ const schema = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("./data/users")));
54
+ // @ts-expect-error Just TypeScript being broken // TODO: Open TypeScript issue
55
+ const schemaAfter = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("./data/users-after")));
56
+ const drizzleJsonBefore = (0, _utils.generateDrizzleJson)(schema);
57
+ const drizzleJsonAfter = (0, _utils.generateDrizzleJson)(schemaAfter);
58
+ const sqlStatements = await (0, _utils.generateMigration)(drizzleJsonBefore, drizzleJsonAfter);
59
+ console.log(sqlStatements);
60
+ }
61
+ async function pushUsage() {
62
+ // @ts-expect-error Just TypeScript being broken // TODO: Open TypeScript issue
63
+ const schemaAfter = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("./data/users-after")));
64
+ const db = (0, _nodepostgres.drizzle)(new _pg.Pool({
65
+ connectionString: ''
66
+ }));
67
+ const response = await (0, _utils.pushSchema)(schemaAfter, db);
68
+ console.log('\n');
69
+ console.log('hasDataLoss: ', response.hasDataLoss);
70
+ console.log('warnings: ', response.warnings);
71
+ console.log('statements: ', response.statementsToExecute);
72
+ await response.apply();
73
+ process.exit(0);
74
+ }
75
+
76
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9yZWZlcmVuY2UudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLy8gdHlwZSBHZW5lcmF0ZU1pZ3JhdGlvbiA9IChiZWZvcmU6IERyaXp6bGVTbmFwc2hvdEpTT04sIGFmdGVyOiBEcml6emxlU25hcHNob3RKU09OKSA9PiBzdHJpbmdbXVxuXG4vLyB0eXBlIEdlbmVyYXRlRHJpenpsZUpTT04gPSAoc2NoZW1hOiBEcml6emxlU2NoZW1hRXhwb3J0cykgPT4gRHJpenpsZVNuYXBzaG90SlNPTlxuXG4vLyB0eXBlIFB1c2hEaWZmID0gKHNjaGVtYTogRHJpenpsZVNjaGVtYUV4cG9ydHMpID0+IFByb21pc2U8eyB3YXJuaW5nczogc3RyaW5nW10sIGFwcGx5OiAoKSA9PiBQcm9taXNlPHZvaWQ+IH0+XG5cbi8vIGRyaXp6bGUta2l0QHV0aWxzXG5cbmltcG9ydCB7IGdlbmVyYXRlRHJpenpsZUpzb24sIGdlbmVyYXRlTWlncmF0aW9uLCBwdXNoU2NoZW1hIH0gZnJvbSAnZHJp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ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBRXJCLGVBQWVBO0lBQ2IsK0VBQStFO0lBQy9FLE1BQU1DLFNBQVMsTUFBTSxtRUFBQSxRQUFPO0lBQzVCLCtFQUErRTtJQUMvRSxNQUFNQyxjQUFjLE1BQU0sbUVBQUEsUUFBTztJQUVqQyxNQUFNQyxvQkFBb0JDLElBQUFBLDBCQUFtQixFQUFDSDtJQUM5QyxNQUFNSSxtQkFBbUJELElBQUFBLDBCQUFtQixFQUFDRjtJQUU3QyxNQUFNSSxnQkFBZ0IsTUFBTUMsSUFBQUEsd0JBQWlCLEVBQUNKLG1CQUFtQkU7SUFFakVHLFFBQVFDLEdBQUcsQ0FBQ0g7QUFDZDtBQUVBLGVBQWVJO0lBQ2IsK0VBQStFO0lBQy9FLE1BQU1SLGNBQWMsTUFBTSxtRUFBQSxRQUFPO0lBRWpDLE1BQU1TLEtBQUtDLElBQUFBLHFCQUFPLEVBQUMsSUFBSUMsUUFBSSxDQUFDO1FBQUVDLGtCQUFrQjtJQUFHO0lBRW5ELE1BQU1DLFdBQVcsTUFBTUMsSUFBQUEsaUJBQVUsRUFBQ2QsYUFBYVM7SUFFL0NILFFBQVFDLEdBQUcsQ0FBQztJQUNaRCxRQUFRQyxHQUFHLENBQUMsaUJBQWlCTSxTQUFTRSxXQUFXO0lBQ2pEVCxRQUFRQyxHQUFHLENBQUMsY0FBY00sU0FBU0csUUFBUTtJQUMzQ1YsUUFBUUMsR0FBRyxDQUFDLGdCQUFnQk0sU0FBU0ksbUJBQW1CO0lBRXhELE1BQU1KLFNBQVNLLEtBQUs7SUFFcEJDLFFBQVFDLElBQUksQ0FBQztBQUNmIn0=
@@ -0,0 +1,245 @@
1
+ /* eslint-disable no-param-reassign */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "buildTable", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return buildTable;
9
+ }
10
+ });
11
+ const _drizzleorm = require("drizzle-orm");
12
+ const _pgcore = require("drizzle-orm/pg-core");
13
+ const _types = require("payload/types");
14
+ const _tosnakecase = /*#__PURE__*/ _interop_require_default(require("to-snake-case"));
15
+ const _parentIDColumnMap = require("./parentIDColumnMap");
16
+ const _traverseFields = require("./traverseFields");
17
+ function _interop_require_default(obj) {
18
+ return obj && obj.__esModule ? obj : {
19
+ default: obj
20
+ };
21
+ }
22
+ const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, buildRelationships, disableUnique = false, fields, rootRelationsToBuild, rootTableIDColType, rootTableName, tableName, timestamps })=>{
23
+ const columns = baseColumns;
24
+ const indexes = {};
25
+ let hasLocalizedField = false;
26
+ let hasLocalizedRelationshipField = false;
27
+ let hasManyNumberField = false;
28
+ let hasLocalizedManyNumberField = false;
29
+ const localesColumns = {};
30
+ const localesIndexes = {};
31
+ let localesTable;
32
+ let numbersTable;
33
+ const relationships = new Set();
34
+ let relationshipsTable;
35
+ const relationsToBuild = new Map();
36
+ const idField = fields.find((field)=>(0, _types.fieldAffectsData)(field) && field.name === 'id');
37
+ let idColType = 'integer';
38
+ if (idField) {
39
+ if (idField.type === 'number') {
40
+ idColType = 'numeric';
41
+ columns.id = (0, _pgcore.numeric)('id').primaryKey();
42
+ }
43
+ if (idField.type === 'text') {
44
+ idColType = 'varchar';
45
+ columns.id = (0, _pgcore.varchar)('id').primaryKey();
46
+ }
47
+ } else {
48
+ columns.id = (0, _pgcore.serial)('id').primaryKey();
49
+ }
50
+ ({ hasLocalizedField, hasLocalizedManyNumberField, hasLocalizedRelationshipField, hasManyNumberField } = (0, _traverseFields.traverseFields)({
51
+ adapter,
52
+ buildRelationships,
53
+ columns,
54
+ disableUnique,
55
+ fields,
56
+ indexes,
57
+ localesColumns,
58
+ localesIndexes,
59
+ newTableName: tableName,
60
+ parentTableName: tableName,
61
+ relationsToBuild,
62
+ relationships,
63
+ rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,
64
+ rootTableIDColType: rootTableIDColType || idColType,
65
+ rootTableName: rootTableName || tableName
66
+ }));
67
+ if (timestamps) {
68
+ columns.createdAt = (0, _pgcore.timestamp)('created_at', {
69
+ mode: 'string',
70
+ precision: 3,
71
+ withTimezone: true
72
+ }).defaultNow().notNull();
73
+ columns.updatedAt = (0, _pgcore.timestamp)('updated_at', {
74
+ mode: 'string',
75
+ precision: 3,
76
+ withTimezone: true
77
+ }).defaultNow().notNull();
78
+ }
79
+ const table = (0, _pgcore.pgTable)(tableName, columns, (cols)=>{
80
+ const extraConfig = Object.entries(baseExtraConfig).reduce((config, [key, func])=>{
81
+ config[key] = func(cols);
82
+ return config;
83
+ }, {});
84
+ return Object.entries(indexes).reduce((acc, [colName, func])=>{
85
+ acc[colName] = func(cols);
86
+ return acc;
87
+ }, extraConfig);
88
+ });
89
+ adapter.tables[tableName] = table;
90
+ if (hasLocalizedField) {
91
+ const localeTableName = `${tableName}_locales`;
92
+ localesColumns.id = (0, _pgcore.serial)('id').primaryKey();
93
+ localesColumns._locale = adapter.enums.enum__locales('_locale').notNull();
94
+ localesColumns._parentID = _parentIDColumnMap.parentIDColumnMap[idColType]('_parent_id').references(()=>table.id, {
95
+ onDelete: 'cascade'
96
+ }).notNull();
97
+ localesTable = (0, _pgcore.pgTable)(localeTableName, localesColumns, (cols)=>{
98
+ return Object.entries(localesIndexes).reduce((acc, [colName, func])=>{
99
+ acc[colName] = func(cols);
100
+ return acc;
101
+ }, {
102
+ _localeParent: (0, _pgcore.unique)().on(cols._locale, cols._parentID)
103
+ });
104
+ });
105
+ adapter.tables[localeTableName] = localesTable;
106
+ const localesTableRelations = (0, _drizzleorm.relations)(localesTable, ({ one })=>({
107
+ _parentID: one(table, {
108
+ fields: [
109
+ localesTable._parentID
110
+ ],
111
+ references: [
112
+ table.id
113
+ ]
114
+ })
115
+ }));
116
+ adapter.relations[`relations_${localeTableName}`] = localesTableRelations;
117
+ }
118
+ if (hasManyNumberField) {
119
+ const numbersTableName = `${tableName}_numbers`;
120
+ const columns = {
121
+ id: (0, _pgcore.serial)('id').primaryKey(),
122
+ number: (0, _pgcore.numeric)('number'),
123
+ order: (0, _pgcore.integer)('order').notNull(),
124
+ parent: _parentIDColumnMap.parentIDColumnMap[idColType]('parent_id').references(()=>table.id, {
125
+ onDelete: 'cascade'
126
+ }).notNull(),
127
+ path: (0, _pgcore.varchar)('path').notNull()
128
+ };
129
+ if (hasLocalizedManyNumberField) {
130
+ columns.locale = adapter.enums.enum__locales('locale');
131
+ }
132
+ numbersTable = (0, _pgcore.pgTable)(numbersTableName, columns, (cols)=>{
133
+ const indexes = {
134
+ orderParentIdx: (0, _pgcore.index)('order_parent_idx').on(cols.order, cols.parent)
135
+ };
136
+ if (hasManyNumberField === 'index') {
137
+ indexes.numberIdx = (0, _pgcore.index)('number_idx').on(cols.number);
138
+ }
139
+ if (hasLocalizedManyNumberField) {
140
+ indexes.localeParent = (0, _pgcore.index)('locale_parent').on(cols.locale, cols.parent);
141
+ }
142
+ return indexes;
143
+ });
144
+ adapter.tables[numbersTableName] = numbersTable;
145
+ const numbersTableRelations = (0, _drizzleorm.relations)(numbersTable, ({ one })=>({
146
+ parent: one(table, {
147
+ fields: [
148
+ numbersTable.parent
149
+ ],
150
+ references: [
151
+ table.id
152
+ ]
153
+ })
154
+ }));
155
+ adapter.relations[`relations_${numbersTableName}`] = numbersTableRelations;
156
+ }
157
+ if (buildRelationships) {
158
+ if (relationships.size) {
159
+ const relationshipColumns = {
160
+ id: (0, _pgcore.serial)('id').primaryKey(),
161
+ order: (0, _pgcore.integer)('order'),
162
+ parent: _parentIDColumnMap.parentIDColumnMap[idColType]('parent_id').references(()=>table.id, {
163
+ onDelete: 'cascade'
164
+ }).notNull(),
165
+ path: (0, _pgcore.varchar)('path').notNull()
166
+ };
167
+ if (hasLocalizedRelationshipField) {
168
+ relationshipColumns.locale = adapter.enums.enum__locales('locale');
169
+ }
170
+ relationships.forEach((relationTo)=>{
171
+ const formattedRelationTo = (0, _tosnakecase.default)(relationTo);
172
+ let colType = 'integer';
173
+ const relatedCollectionCustomID = adapter.payload.collections[relationTo].config.fields.find((field)=>(0, _types.fieldAffectsData)(field) && field.name === 'id');
174
+ if (relatedCollectionCustomID?.type === 'number') colType = 'numeric';
175
+ if (relatedCollectionCustomID?.type === 'text') colType = 'varchar';
176
+ relationshipColumns[`${relationTo}ID`] = _parentIDColumnMap.parentIDColumnMap[colType](`${formattedRelationTo}_id`).references(()=>adapter.tables[formattedRelationTo].id, {
177
+ onDelete: 'cascade'
178
+ });
179
+ });
180
+ const relationshipsTableName = `${tableName}_relationships`;
181
+ relationshipsTable = (0, _pgcore.pgTable)(relationshipsTableName, relationshipColumns, (cols)=>{
182
+ const result = {};
183
+ if (hasLocalizedRelationshipField) {
184
+ result.localeIdx = (0, _pgcore.index)('locale_idx').on(cols.locale);
185
+ result.parentPathOrderLocale = (0, _pgcore.unique)().on(cols.parent, cols.path, cols.order, cols.locale);
186
+ } else {
187
+ result.parentPathOrder = (0, _pgcore.unique)().on(cols.parent, cols.path, cols.order);
188
+ }
189
+ return result;
190
+ });
191
+ adapter.tables[relationshipsTableName] = relationshipsTable;
192
+ const relationshipsTableRelations = (0, _drizzleorm.relations)(relationshipsTable, ({ one })=>{
193
+ const result = {
194
+ parent: one(table, {
195
+ fields: [
196
+ relationshipsTable.parent
197
+ ],
198
+ references: [
199
+ table.id
200
+ ],
201
+ relationName: '_relationships'
202
+ })
203
+ };
204
+ relationships.forEach((relationTo)=>{
205
+ const relatedTableName = (0, _tosnakecase.default)(relationTo);
206
+ const idColumnName = `${relationTo}ID`;
207
+ result[idColumnName] = one(adapter.tables[relatedTableName], {
208
+ fields: [
209
+ relationshipsTable[idColumnName]
210
+ ],
211
+ references: [
212
+ adapter.tables[relatedTableName].id
213
+ ]
214
+ });
215
+ });
216
+ return result;
217
+ });
218
+ adapter.relations[`relations_${relationshipsTableName}`] = relationshipsTableRelations;
219
+ }
220
+ }
221
+ const tableRelations = (0, _drizzleorm.relations)(table, ({ many })=>{
222
+ const result = {};
223
+ relationsToBuild.forEach((val, key)=>{
224
+ result[key] = many(adapter.tables[val]);
225
+ });
226
+ if (hasLocalizedField) {
227
+ result._locales = many(localesTable);
228
+ }
229
+ if (hasManyNumberField) {
230
+ result._numbers = many(numbersTable);
231
+ }
232
+ if (relationships.size && relationshipsTable) {
233
+ result._relationships = many(relationshipsTable, {
234
+ relationName: '_relationships'
235
+ });
236
+ }
237
+ return result;
238
+ });
239
+ adapter.relations[`relations_${tableName}`] = tableRelations;
240
+ return {
241
+ relationsToBuild
242
+ };
243
+ };
244
+
245
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zY2hlbWEvYnVpbGQudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyogZXNsaW50LWRpc2FibGUgbm8tcGFyYW0tcmVhc3NpZ24gKi9cbmltcG9ydCB0eXBlIHsgUmVsYXRpb24gfSBmcm9tICdkcml6emxlLW9ybSdcbmltcG9ydCB0eXBlIHsgSW5kZXhCdWlsZGVyLCBQZ0NvbHVtbkJ1aWxkZXIsIFVuaXF1ZUNvbnN0cmFpbnRCdWlsZGVyIH0gZnJvbSAnZHJpenpsZS1vcm0vcGctY29yZSdcbmltcG9ydCB0eXBlIHsgRmllbGQgfSBmcm9tICdwYXlsb2FkL3R5cGVzJ1xuXG5pbXBvcnQgeyByZWxhdGlvbnMgfSBmcm9tICdkcml6emxlLW9ybSdcbmltcG9ydCB7XG4gIGluZGV4LFxuICBpbnRlZ2VyLFxuICBudW1lcmljLFxuICBwZ1RhYmxlLFxuICBzZXJpYWwsXG4gIHRpbWVzdGFtcCxcbiAgdW5pcXVlLFxuICB2YXJjaGFyLFxufSBmcm9tICdkcml6emxlLW9ybS9wZy1jb3JlJ1xuaW1wb3J0IHsgZmllbGRBZmZlY3RzRGF0YSB9IGZyb20gJ3BheWxvYWQvdHlwZXMnXG5pbXBvcnQgdG9TbmFrZUNhc2UgZnJvbSAndG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UsT0FBTyxDQUFDLENBQUNtQixLQUFLcEQ7WUFDN0IwQyxNQUFNLENBQUMxQyxJQUFJLEdBQUdtRCxLQUFLNUcsUUFBUTZELE1BQU0sQ0FBQ2dELElBQUk7UUFDeEM7UUFFQSxJQUFJaEcsbUJBQW1CO1lBQ3JCc0YsT0FBT1csUUFBUSxHQUFHRixLQUFLekY7UUFDekI7UUFFQSxJQUFJSixvQkFBb0I7WUFDdEJvRixPQUFPWSxRQUFRLEdBQUdILEtBQUt4RjtRQUN6QjtRQUVBLElBQUlDLGNBQWNtRSxJQUFJLElBQUlqRSxvQkFBb0I7WUFDNUM0RSxPQUFPYSxjQUFjLEdBQUdKLEtBQUtyRixvQkFBb0I7Z0JBQy9DaUYsY0FBYztZQUNoQjtRQUNGO1FBRUEsT0FBT0w7SUFDVDtJQUVBbkcsUUFBUTBFLFNBQVMsQ0FBQyxDQUFDLFVBQVUsRUFBRWpFLFVBQVUsQ0FBQyxDQUFDLEdBQUdrRztJQUU5QyxPQUFPO1FBQUVuRjtJQUFpQjtBQUM1QiJ9
@@ -0,0 +1,19 @@
1
+ /* eslint-disable no-param-reassign */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "createIndex", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return createIndex;
9
+ }
10
+ });
11
+ const _pgcore = require("drizzle-orm/pg-core");
12
+ const createIndex = ({ name, columnName, unique })=>{
13
+ return (table)=>{
14
+ if (unique) return (0, _pgcore.uniqueIndex)(`${columnName}_idx`).on(table[name]);
15
+ return (0, _pgcore.index)(`${columnName}_idx`).on(table[name]);
16
+ };
17
+ };
18
+
19
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zY2hlbWEvY3JlYXRlSW5kZXgudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyogZXNsaW50LWRpc2FibGUgbm8tcGFyYW0tcmV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FLO1FBQ2xFLE9BQU9NLElBQUFBLGFBQUssRUFBQyxDQUFDLEVBQUVMLFdBQVcsSUFBSSxDQUFDLEVBQUVJLEVBQUUsQ0FBQ0YsS0FBSyxDQUFDSCxLQUFLO0lBQ2xEO0FBQ0YifQ==
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "parentIDColumnMap", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return parentIDColumnMap;
9
+ }
10
+ });
11
+ const _pgcore = require("drizzle-orm/pg-core");
12
+ const parentIDColumnMap = {
13
+ integer: _pgcore.integer,
14
+ numeric: _pgcore.numeric,
15
+ varchar: _pgcore.varchar
16
+ };
17
+
18
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zY2hlbWEvcGFyZW50SURDb2x1bW5NYXAudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgaW50ZWdlciwgbnVtZXJpYywgdmFyY2hhciB9IGZyb20gJ2RyaXp6bGUtb3JtL3BnLWNvcmUnXG5cbmV4cG9ydCBjb25zdCBwYXJlbnRJRENvbHVtbk1hcCA9IHtcbiAgaW50ZWdlcixcbiAgbnVtZXJpYyxcbiAgdmFyY2hhcixcbn1cbiJdLCJuYW1lcyI6WyJwYXJlbnRJRENvbHVtbk1hcCIsImludGVnZXIiLCJudW1lcmljIiwidmFyY2hhciJdLCJtYXBwaW5ncyI6Ijs7OzsrQkFFYUE7OztlQUFBQTs7O3dCQUY2QjtBQUVuQyxNQUFNQSxvQkFBb0I7SUFDL0JDLFNBQUFBLGVBQU87SUFDUEMsU0FBQUEsZUFBTztJQUNQQyxTQUFBQSxlQUFPO0FBQ1QifQ==