@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
package/dist/update.js ADDED
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "updateOne", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return updateOne;
9
+ }
10
+ });
11
+ const _tosnakecase = /*#__PURE__*/ _interop_require_default(require("to-snake-case"));
12
+ const _buildQuery = /*#__PURE__*/ _interop_require_default(require("./queries/buildQuery"));
13
+ const _upsertRow = require("./upsertRow");
14
+ function _interop_require_default(obj) {
15
+ return obj && obj.__esModule ? obj : {
16
+ default: obj
17
+ };
18
+ }
19
+ const updateOne = async function updateOne({ id, collection: collectionSlug, data, draft, locale, req, where: whereArg }) {
20
+ const db = this.sessions[req.transactionID]?.db || this.db;
21
+ const collection = this.payload.collections[collectionSlug].config;
22
+ const tableName = (0, _tosnakecase.default)(collectionSlug);
23
+ const whereToUse = whereArg || {
24
+ id: {
25
+ equals: id
26
+ }
27
+ };
28
+ const { where } = await (0, _buildQuery.default)({
29
+ adapter: this,
30
+ fields: collection.fields,
31
+ locale,
32
+ tableName,
33
+ where: whereToUse
34
+ });
35
+ const result = await (0, _upsertRow.upsertRow)({
36
+ id,
37
+ adapter: this,
38
+ data,
39
+ db,
40
+ fields: collection.fields,
41
+ operation: 'update',
42
+ tableName: (0, _tosnakecase.default)(collectionSlug),
43
+ where
44
+ });
45
+ return result;
46
+ };
47
+
48
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy91cGRhdGUudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHR5cGUgeyBVcGRhdGVPbmUgfSBmcm9tICdwYXlsb2FkL2RhdGFiYXNlJ1xuXG5pbXBvcnQgdG9TbmFrZUNhc2UgZnJvbSAndG8tc25ha2UtY2FzZSdcblxuaW1wb3J0IHR5cGUgeyBQb3N0Z3Jlc0FkYXB0ZXIgfSBmcm9tICcuL3R5cGVzJ1xuXG5pbXBvcnQgYnVpbGRRdWVyeSBmcm9tICcuL3F1ZXJpZXMvYnVpbGRRdWVyeSdcbmltcG9ydCB7IHVwc2VydFJvdyB9IGZyb20gJy4vdXBzZXJ0Um93J1xuXG5leHBvcnQgY29uc3QgdXBkYXRlT25lOiBVcGRhdGVPbmUgPSBhc3luYyBmdW5jdGlvbiB1cGRhdGVPbmUgKFxuICB0aGlzOiBQb3N0Z3Jlc0FkYXB0ZX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sRUFBQztRQUM3QnZCO1FBQ0FvQixTQUFTLElBQUk7UUFDYmpCO1FBQ0FNO1FBQ0FZLFFBQVFwQixXQUFXb0IsTUFBTTtRQUN6QkcsV0FBVztRQUNYVCxXQUFXQyxJQUFBQSxvQkFBVyxFQUFDZDtRQUN2Qks7SUFDRjtJQUVBLE9BQU9lO0FBQ1QifQ==
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "updateGlobal", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return updateGlobal;
9
+ }
10
+ });
11
+ const _tosnakecase = /*#__PURE__*/ _interop_require_default(require("to-snake-case"));
12
+ const _upsertRow = require("./upsertRow");
13
+ function _interop_require_default(obj) {
14
+ return obj && obj.__esModule ? obj : {
15
+ default: obj
16
+ };
17
+ }
18
+ async function updateGlobal({ data, req = {}, slug }) {
19
+ const db = this.sessions[req.transactionID]?.db || this.db;
20
+ const globalConfig = this.payload.globals.config.find((config)=>config.slug === slug);
21
+ const tableName = (0, _tosnakecase.default)(slug);
22
+ const existingGlobal = await db.query[tableName].findFirst({});
23
+ const result = await (0, _upsertRow.upsertRow)({
24
+ ...existingGlobal ? {
25
+ id: existingGlobal.id,
26
+ operation: 'update'
27
+ } : {
28
+ operation: 'create'
29
+ },
30
+ adapter: this,
31
+ data,
32
+ db,
33
+ fields: globalConfig.fields,
34
+ tableName
35
+ });
36
+ return result;
37
+ }
38
+
39
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy91cGRhdGVHbG9iYWwudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHR5cGUgeyBVcGRhdGVHbG9iYWxBcmdzIH0gZnJvbSAncGF5bG9hZC9kYXRhYmFzZSdcbmltcG9ydCB0eXBlIHsgUGF5bG9hZFJlcXVlc3QsIFR5cGVXaXRoSUQgfSBmcm9tICdwYXl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LEVBQUU7WUFBRUMsV0FBVztRQUFTLElBQUk7WUFBRUEsV0FBVztRQUFTLENBQUM7UUFDN0ZDLFNBQVMsSUFBSTtRQUNicEI7UUFDQUc7UUFDQWtCLFFBQVFmLGFBQWFlLE1BQU07UUFDM0JWO0lBQ0Y7SUFFQSxPQUFPSztBQUNUIn0=
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "updateGlobalVersion", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return updateGlobalVersion;
9
+ }
10
+ });
11
+ const _versions = require("payload/versions");
12
+ const _tosnakecase = /*#__PURE__*/ _interop_require_default(require("to-snake-case"));
13
+ const _buildQuery = /*#__PURE__*/ _interop_require_default(require("./queries/buildQuery"));
14
+ const _upsertRow = require("./upsertRow");
15
+ function _interop_require_default(obj) {
16
+ return obj && obj.__esModule ? obj : {
17
+ default: obj
18
+ };
19
+ }
20
+ async function updateGlobalVersion({ id, global, locale, req = {}, versionData, where: whereArg }) {
21
+ const db = this.sessions[req.transactionID]?.db || this.db;
22
+ const globalConfig = this.payload.globals.config.find(({ slug })=>slug === global);
23
+ const whereToUse = whereArg || {
24
+ id: {
25
+ equals: id
26
+ }
27
+ };
28
+ const tableName = `_${(0, _tosnakecase.default)(global)}_v`;
29
+ const fields = (0, _versions.buildVersionGlobalFields)(globalConfig);
30
+ const { where } = await (0, _buildQuery.default)({
31
+ adapter: this,
32
+ fields,
33
+ locale,
34
+ tableName,
35
+ where: whereToUse
36
+ });
37
+ const result = await (0, _upsertRow.upsertRow)({
38
+ id,
39
+ adapter: this,
40
+ data: versionData,
41
+ db,
42
+ fields,
43
+ operation: 'update',
44
+ tableName,
45
+ where
46
+ });
47
+ return result;
48
+ }
49
+
50
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy91cGRhdGVHbG9iYWxWZXJzaW9uLnRz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c7SUFDVDtJQUVBLE1BQU1RLFNBQVMsTUFBTUMsSUFBQUEsb0JBQVMsRUFBcUI7UUFDakR6QjtRQUNBdUIsU0FBUyxJQUFJO1FBQ2JHLE1BQU10QjtRQUNORztRQUNBYTtRQUNBTyxXQUFXO1FBQ1hUO1FBQ0FiO0lBQ0Y7SUFFQSxPQUFPbUI7QUFDVCJ9
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "updateVersion", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return updateVersion;
9
+ }
10
+ });
11
+ const _versions = require("payload/versions");
12
+ const _tosnakecase = /*#__PURE__*/ _interop_require_default(require("to-snake-case"));
13
+ const _buildQuery = /*#__PURE__*/ _interop_require_default(require("./queries/buildQuery"));
14
+ const _upsertRow = require("./upsertRow");
15
+ function _interop_require_default(obj) {
16
+ return obj && obj.__esModule ? obj : {
17
+ default: obj
18
+ };
19
+ }
20
+ async function updateVersion({ id, collection, locale, req = {}, versionData, where: whereArg }) {
21
+ const db = this.sessions[req.transactionID]?.db || this.db;
22
+ const collectionConfig = this.payload.collections[collection].config;
23
+ const whereToUse = whereArg || {
24
+ id: {
25
+ equals: id
26
+ }
27
+ };
28
+ const tableName = `_${(0, _tosnakecase.default)(collection)}_v`;
29
+ const fields = (0, _versions.buildVersionCollectionFields)(collectionConfig);
30
+ const { where } = await (0, _buildQuery.default)({
31
+ adapter: this,
32
+ fields,
33
+ locale,
34
+ tableName,
35
+ where: whereToUse
36
+ });
37
+ const result = await (0, _upsertRow.upsertRow)({
38
+ id,
39
+ adapter: this,
40
+ data: versionData,
41
+ db,
42
+ fields,
43
+ operation: 'update',
44
+ tableName,
45
+ where
46
+ });
47
+ return result;
48
+ }
49
+
50
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy91cGRhdGVWZXJzaW9uLnRzIl0sInNv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FDQVc7UUFDQU8sV0FBVztRQUNYVDtRQUNBWDtJQUNGO0lBRUEsT0FBT2lCO0FBQ1QifQ==
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "deleteExistingArrayRows", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return deleteExistingArrayRows;
9
+ }
10
+ });
11
+ const _drizzleorm = require("drizzle-orm");
12
+ const deleteExistingArrayRows = async ({ adapter, db, parentID, tableName })=>{
13
+ const table = adapter.tables[tableName];
14
+ const whereConstraints = [
15
+ (0, _drizzleorm.eq)(table._parentID, parentID)
16
+ ];
17
+ await db.delete(table).where((0, _drizzleorm.and)(...whereConstraints));
18
+ };
19
+
20
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91cHNlcnRSb3cvZGVsZXRlRXhpc3RpbmdBcnJheVJvd3MudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgYW5kLCBlcSB9IGZyb20gJ2RyaXp6bGUtb3JtJ1xuXG5pbXBvcnQgdHlwZSB7IERyaXp6bGVEQiwgUG9zdGdyZXNBZGFwdGVyIH0gZnJvbSAnLi4vdHlwZXMnXG5cbnR5cGUgQXJncyA9IHtcbiAgYWRhcHRlcjogUG9zdGdyZXNBZGFwdGVyXG4gIGRiOiBEcml6emxlREJcbiAgcGFyZW50SUQ6IHVua25vd25cbiAgdGFibGVOYW1lOiBzdHJpbmdcbn1cblxuZXhwb3J0IGNvbnN0IGRlbGV0ZUV4aXN0aW5nQXJyYXlSb3dzID0gYXN5bmMgKHtcbiAgYWRhcHRlcixcbiAgZGIsXG4gIHBhcmVudElELFxuICB0YWJsZU5hbWUsXG59OiBBcmdzKTogUHJvbWlzZTx2b2lkPiA9PiB7XG4gIGNvbnN0IHRhYmxlID0gYWRhcHRlci50YWJsZXNbdGFibGVOYW1lXVxuXG4gIGNvbnN0IHdoZXJlQ29uc3RyYWludHMgPSBbZXEodGFibGUuX3BhcmVudElELCBwYXJlbnRJRCldXG5cbiAgYXdhaXQgZGIuZGVsZXRlKHRhYmxlKS53aGVyZShhbmQoLi4ud2hlcmVDb25zdHJhaW50cykpXG59XG4iXSwibmFtZXMiOlsiZGVsZXRlRXhpc3RpbmdBcnJheVJvd3MiLCJhZGFwdGVyIiwiZGIiLCJwYXJlbnRJRCIsInRhYmxlTmFtZSIsInRhYmxlIiwidGFibGVzIiwid2hlcmVDb25zdHJhaW50cyIsImVxIiwiX3BhcmVudElEIiwiZGVsZXRlIiwid2hlcmUiLCJhbmQiXSwibWFwcGluZ3MiOiI7Ozs7K0JBV2FBOzs7ZUFBQUE7Ozs0QkFYVztBQVdqQixNQUFNQSwwQkFBMEIsT0FBTyxFQUM1Q0MsT0FBTyxFQUNQQyxFQUFFLEVBQ0ZDLFFBQVEsRUFDUkMsU0FBUyxFQUNKO0lBQ0wsTUFBTUMsUUFBUUosUUFBUUssTUFBTSxDQUFDRixVQUFVO0lBRXZDLE1BQU1HLG1CQUFtQjtRQUFDQyxJQUFBQSxjQUFFLEVBQUNILE1BQU1JLFNBQVMsRUFBRU47S0FBVTtJQUV4RCxNQUFNRCxHQUFHUSxNQUFNLENBQUNMLE9BQU9NLEtBQUssQ0FBQ0MsSUFBQUEsZUFBRyxLQUFJTDtBQUN0QyJ9
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "deleteExistingRowsByPath", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return deleteExistingRowsByPath;
9
+ }
10
+ });
11
+ const _drizzleorm = require("drizzle-orm");
12
+ const deleteExistingRowsByPath = async ({ adapter, db, localeColumnName = '_locale', parentColumnName = '_parentID', parentID, pathColumnName = '_path', rows, tableName })=>{
13
+ const localizedPathsToDelete = new Set();
14
+ const pathsToDelete = new Set();
15
+ const table = adapter.tables[tableName];
16
+ rows.forEach((row)=>{
17
+ const path = row[pathColumnName];
18
+ const localeData = row[localeColumnName];
19
+ if (typeof path === 'string') {
20
+ if (typeof localeData === 'string') {
21
+ localizedPathsToDelete.add(path);
22
+ } else {
23
+ pathsToDelete.add(path);
24
+ }
25
+ }
26
+ });
27
+ if (localizedPathsToDelete.size > 0) {
28
+ const whereConstraints = [
29
+ (0, _drizzleorm.eq)(table[parentColumnName], parentID)
30
+ ];
31
+ if (pathColumnName) whereConstraints.push((0, _drizzleorm.inArray)(table[pathColumnName], Array.from(localizedPathsToDelete)));
32
+ await db.delete(table).where((0, _drizzleorm.and)(...whereConstraints));
33
+ }
34
+ if (pathsToDelete.size > 0) {
35
+ const whereConstraints = [
36
+ (0, _drizzleorm.eq)(table[parentColumnName], parentID)
37
+ ];
38
+ if (pathColumnName) whereConstraints.push((0, _drizzleorm.inArray)(table[pathColumnName], Array.from(pathsToDelete)));
39
+ await db.delete(table).where((0, _drizzleorm.and)(...whereConstraints));
40
+ }
41
+ };
42
+
43
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91cHNlcnRSb3cvZGVsZXRlRXhpc3RpbmdSb3dzQnlQYXRoLnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGFuZCwgZXEsIGluQXJyYXkgfSBmcm9tICdkcml6emxlLW9ybSdcblxuaW1wb3J0IHR5cGUgeyBEcml6emxlREIsIFBvc3RncmVzQWRhcHRlciB9IGZyb20gJy4uL3R5cGVzJ1xuXG50eXBlIEFyZ3MgPSB7XG4gIGFkYXB0ZXI6IFBvc3RncmVzQWRhcHRlclxuICBkYjogRHJpenpsZURCXG4gIGxvY2FsZUNvbHVtbk5hbWU/OiBzdHJpbmdcbiAgcGFyZW50Q29sdW1uTmFtZT86IHN0cmluZ1xuICBwYXJlbnRJRDogdW5rbm93blxuICBwYXRoQ29sdW1uTmFtZT86IHN0cmluZ1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LElBQUFBLGVBQUcsS0FBSVI7SUFDdEM7SUFFQSxJQUFJVCxjQUFjUSxJQUFJLEdBQUcsR0FBRztRQUMxQixNQUFNQyxtQkFBbUI7WUFBQ0MsSUFBQUEsY0FBRSxFQUFDVCxLQUFLLENBQUNSLGlCQUFpQixFQUFFQztTQUFVO1FBRWhFLElBQUlDLGdCQUNGYyxpQkFBaUJFLElBQUksQ0FBQ0MsSUFBQUEsbUJBQU8sRUFBQ1gsS0FBSyxDQUFDTixlQUFlLEVBQUVrQixNQUFNQyxJQUFJLENBQUNkO1FBRWxFLE1BQU1ULEdBQUd3QixNQUFNLENBQUNkLE9BQU9lLEtBQUssQ0FBQ0MsSUFBQUEsZUFBRyxLQUFJUjtJQUN0QztBQUNGIn0=
@@ -0,0 +1,243 @@
1
+ /* eslint-disable no-param-reassign */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "upsertRow", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return upsertRow;
9
+ }
10
+ });
11
+ const _drizzleorm = require("drizzle-orm");
12
+ const _buildFindManyArgs = require("../find/buildFindManyArgs");
13
+ const _read = require("../transform/read");
14
+ const _write = require("../transform/write");
15
+ const _deleteExistingArrayRows = require("./deleteExistingArrayRows");
16
+ const _deleteExistingRowsByPath = require("./deleteExistingRowsByPath");
17
+ const _insertArrays = require("./insertArrays");
18
+ const upsertRow = async ({ id, adapter, data, db, fields, operation, path = '', tableName, upsertTarget, where })=>{
19
+ // Split out the incoming data into the corresponding:
20
+ // base row, locales, relationships, blocks, and arrays
21
+ const rowToInsert = (0, _write.transformForWrite)({
22
+ data,
23
+ fields,
24
+ path,
25
+ tableName
26
+ });
27
+ // First, we insert the main row
28
+ let insertedRow;
29
+ if (operation === 'update') {
30
+ const target = upsertTarget || adapter.tables[tableName].id;
31
+ if (id) {
32
+ rowToInsert.row.id = id;
33
+ [insertedRow] = await db.insert(adapter.tables[tableName]).values(rowToInsert.row).onConflictDoUpdate({
34
+ set: rowToInsert.row,
35
+ target
36
+ }).returning();
37
+ } else {
38
+ [insertedRow] = await db.insert(adapter.tables[tableName]).values(rowToInsert.row).onConflictDoUpdate({
39
+ set: rowToInsert.row,
40
+ target,
41
+ where
42
+ }).returning();
43
+ }
44
+ } else {
45
+ [insertedRow] = await db.insert(adapter.tables[tableName]).values(rowToInsert.row).returning();
46
+ }
47
+ const localesToInsert = [];
48
+ const relationsToInsert = [];
49
+ const numbersToInsert = [];
50
+ const blocksToInsert = {};
51
+ const selectsToInsert = {};
52
+ // If there are locale rows with data, add the parent and locale to each
53
+ if (Object.keys(rowToInsert.locales).length > 0) {
54
+ Object.entries(rowToInsert.locales).forEach(([locale, localeRow])=>{
55
+ localeRow._parentID = insertedRow.id;
56
+ localeRow._locale = locale;
57
+ localesToInsert.push(localeRow);
58
+ });
59
+ }
60
+ // If there are relationships, add parent to each
61
+ if (rowToInsert.relationships.length > 0) {
62
+ rowToInsert.relationships.forEach((relation)=>{
63
+ relation.parent = insertedRow.id;
64
+ relationsToInsert.push(relation);
65
+ });
66
+ }
67
+ // If there are numbers, add parent to each
68
+ if (rowToInsert.numbers.length > 0) {
69
+ rowToInsert.numbers.forEach((numberRow)=>{
70
+ numberRow.parent = insertedRow.id;
71
+ numbersToInsert.push(numberRow);
72
+ });
73
+ }
74
+ // If there are selects, add parent to each, and then
75
+ // store by table name and rows
76
+ if (Object.keys(rowToInsert.selects).length > 0) {
77
+ Object.entries(rowToInsert.selects).forEach(([selectTableName, selectRows])=>{
78
+ selectRows.forEach((row)=>{
79
+ row.parent = insertedRow.id;
80
+ if (!selectsToInsert[selectTableName]) selectsToInsert[selectTableName] = [];
81
+ selectsToInsert[selectTableName].push(row);
82
+ });
83
+ });
84
+ }
85
+ // If there are blocks, add parent to each, and then
86
+ // store by table name and rows
87
+ Object.keys(rowToInsert.blocks).forEach((blockName)=>{
88
+ rowToInsert.blocks[blockName].forEach((blockRow)=>{
89
+ blockRow.row._parentID = insertedRow.id;
90
+ if (!blocksToInsert[blockName]) blocksToInsert[blockName] = [];
91
+ blocksToInsert[blockName].push(blockRow);
92
+ });
93
+ });
94
+ // //////////////////////////////////
95
+ // INSERT LOCALES
96
+ // //////////////////////////////////
97
+ if (localesToInsert.length > 0) {
98
+ const localeTable = adapter.tables[`${tableName}_locales`];
99
+ if (operation === 'update') {
100
+ await db.delete(localeTable).where((0, _drizzleorm.eq)(localeTable._parentID, insertedRow.id));
101
+ }
102
+ await db.insert(localeTable).values(localesToInsert);
103
+ }
104
+ // //////////////////////////////////
105
+ // INSERT RELATIONSHIPS
106
+ // //////////////////////////////////
107
+ const relationshipsTableName = `${tableName}_relationships`;
108
+ if (operation === 'update') {
109
+ await (0, _deleteExistingRowsByPath.deleteExistingRowsByPath)({
110
+ adapter,
111
+ db,
112
+ localeColumnName: 'locale',
113
+ parentColumnName: 'parent',
114
+ parentID: insertedRow.id,
115
+ pathColumnName: 'path',
116
+ rows: [
117
+ ...relationsToInsert,
118
+ ...rowToInsert.relationshipsToDelete
119
+ ],
120
+ tableName: relationshipsTableName
121
+ });
122
+ }
123
+ if (relationsToInsert.length > 0) {
124
+ await db.insert(adapter.tables[relationshipsTableName]).values(relationsToInsert);
125
+ }
126
+ // //////////////////////////////////
127
+ // INSERT hasMany NUMBERS
128
+ // //////////////////////////////////
129
+ const numbersTableName = `${tableName}_numbers`;
130
+ if (operation === 'update') {
131
+ await (0, _deleteExistingRowsByPath.deleteExistingRowsByPath)({
132
+ adapter,
133
+ db,
134
+ localeColumnName: 'locale',
135
+ parentColumnName: 'parent',
136
+ parentID: insertedRow.id,
137
+ pathColumnName: 'path',
138
+ rows: numbersToInsert,
139
+ tableName: numbersTableName
140
+ });
141
+ }
142
+ if (numbersToInsert.length > 0) {
143
+ await db.insert(adapter.tables[numbersTableName]).values(numbersToInsert).returning();
144
+ }
145
+ // //////////////////////////////////
146
+ // INSERT BLOCKS
147
+ // //////////////////////////////////
148
+ const insertedBlockRows = {};
149
+ for (const [blockName, blockRows] of Object.entries(blocksToInsert)){
150
+ if (operation === 'update') {
151
+ await (0, _deleteExistingRowsByPath.deleteExistingRowsByPath)({
152
+ adapter,
153
+ db,
154
+ parentID: insertedRow.id,
155
+ pathColumnName: '_path',
156
+ rows: blockRows.map(({ row })=>row),
157
+ tableName: `${tableName}_blocks_${blockName}`
158
+ });
159
+ }
160
+ insertedBlockRows[blockName] = await db.insert(adapter.tables[`${tableName}_blocks_${blockName}`]).values(blockRows.map(({ row })=>row)).returning();
161
+ insertedBlockRows[blockName].forEach((row, i)=>{
162
+ blockRows[i].row = row;
163
+ });
164
+ const blockLocaleIndexMap = [];
165
+ const blockLocaleRowsToInsert = blockRows.reduce((acc, blockRow, i)=>{
166
+ if (Object.entries(blockRow.locales).length > 0) {
167
+ Object.entries(blockRow.locales).forEach(([blockLocale, blockLocaleData])=>{
168
+ if (Object.keys(blockLocaleData).length > 0) {
169
+ blockLocaleData._parentID = blockRow.row.id;
170
+ blockLocaleData._locale = blockLocale;
171
+ acc.push(blockLocaleData);
172
+ blockLocaleIndexMap.push(i);
173
+ }
174
+ });
175
+ }
176
+ return acc;
177
+ }, []);
178
+ if (blockLocaleRowsToInsert.length > 0) {
179
+ await db.insert(adapter.tables[`${tableName}_blocks_${blockName}_locales`]).values(blockLocaleRowsToInsert).returning();
180
+ }
181
+ await (0, _insertArrays.insertArrays)({
182
+ adapter,
183
+ arrays: blockRows.map(({ arrays })=>arrays),
184
+ db,
185
+ parentRows: insertedBlockRows[blockName]
186
+ });
187
+ }
188
+ // //////////////////////////////////
189
+ // INSERT ARRAYS RECURSIVELY
190
+ // //////////////////////////////////
191
+ if (operation === 'update') {
192
+ for (const arrayTableName of Object.keys(rowToInsert.arrays)){
193
+ await (0, _deleteExistingArrayRows.deleteExistingArrayRows)({
194
+ adapter,
195
+ db,
196
+ parentID: insertedRow.id,
197
+ tableName: arrayTableName
198
+ });
199
+ }
200
+ }
201
+ await (0, _insertArrays.insertArrays)({
202
+ adapter,
203
+ arrays: [
204
+ rowToInsert.arrays
205
+ ],
206
+ db,
207
+ parentRows: [
208
+ insertedRow
209
+ ]
210
+ });
211
+ // //////////////////////////////////
212
+ // INSERT hasMany SELECTS
213
+ // //////////////////////////////////
214
+ for (const [selectTableName, tableRows] of Object.entries(selectsToInsert)){
215
+ const selectTable = adapter.tables[selectTableName];
216
+ if (operation === 'update') {
217
+ await db.delete(selectTable).where((0, _drizzleorm.eq)(selectTable.parent, insertedRow.id));
218
+ }
219
+ await db.insert(selectTable).values(tableRows).returning();
220
+ }
221
+ // //////////////////////////////////
222
+ // RETRIEVE NEWLY UPDATED ROW
223
+ // //////////////////////////////////
224
+ const findManyArgs = (0, _buildFindManyArgs.buildFindManyArgs)({
225
+ adapter,
226
+ depth: 0,
227
+ fields,
228
+ tableName
229
+ });
230
+ findManyArgs.where = (0, _drizzleorm.eq)(adapter.tables[tableName].id, insertedRow.id);
231
+ const doc = await db.query[tableName].findFirst(findManyArgs);
232
+ // //////////////////////////////////
233
+ // TRANSFORM DATA
234
+ // //////////////////////////////////
235
+ const result = (0, _read.transform)({
236
+ config: adapter.payload.config,
237
+ data: doc,
238
+ fields
239
+ });
240
+ return result;
241
+ };
242
+
243
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91cHNlcnRSb3cvaW5kZXgudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyogZXNsaW50LWRpc2FibGUgbm8tcGFyYW0tcmVhc3NpZ24gKi9cbmltcG9ydCB0eXBlIHsgVHlwZVdpdGhJRCB9IGZyb20gJ3BheWxvYWQvdHlwZXMnXG5cbmltcG9ydCB7IGVxIH0gZnJvbSAnZHJpenpsZS1vcm0nXG5cbmltcG9ydCB0eXBlIHsgQmxvY2tSb3dUb0luc2VydCB9IGZyb20gJy4uL3RyYW5zZm9ybS93cml0ZS90eXBlcydcbmltcG9ydCB0eXBlIHsgQXJncyB9IGZyb20gJy4vdHlwZXMnXG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TtRQUNBLE1BQU1HLEdBQUdhLE1BQU0sQ0FBQzRELGFBQWEzRCxNQUFNLENBQUMwRCxXQUFXdkQsU0FBUztJQUMxRDtJQUVBLHFDQUFxQztJQUNyQyw2QkFBNkI7SUFDN0IscUNBQXFDO0lBRXJDLE1BQU15RCxlQUFlQyxJQUFBQSxvQ0FBaUIsRUFBQztRQUNyQzdFO1FBQ0E4RSxPQUFPO1FBQ1AzRTtRQUNBRztJQUNGO0lBRUFzRSxhQUFhcEUsS0FBSyxHQUFHeUMsSUFBQUEsY0FBRSxFQUFDakQsUUFBUWEsTUFBTSxDQUFDUCxVQUFVLENBQUNQLEVBQUUsRUFBRVksWUFBWVosRUFBRTtJQUVwRSxNQUFNZ0YsTUFBTSxNQUFNN0UsR0FBRzhFLEtBQUssQ0FBQzFFLFVBQVUsQ0FBQzJFLFNBQVMsQ0FBQ0w7SUFFaEQscUNBQXFDO0lBQ3JDLGlCQUFpQjtJQUNqQixxQ0FBcUM7SUFFckMsTUFBTU0sU0FBU0MsSUFBQUEsZUFBUyxFQUFJO1FBQzFCQyxRQUFRcEYsUUFBUXFGLE9BQU8sQ0FBQ0QsTUFBTTtRQUM5Qm5GLE1BQU04RTtRQUNONUU7SUFDRjtJQUVBLE9BQU8rRTtBQUNUIn0=
@@ -0,0 +1,64 @@
1
+ /* eslint-disable no-param-reassign */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "insertArrays", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return insertArrays;
9
+ }
10
+ });
11
+ const insertArrays = async ({ adapter, arrays, db, parentRows })=>{
12
+ // Maintain a map of flattened rows by table
13
+ const rowsByTable = {};
14
+ arrays.forEach((arraysByTable, parentRowIndex)=>{
15
+ Object.entries(arraysByTable).forEach(([tableName, arrayRows])=>{
16
+ // If the table doesn't exist in map, initialize it
17
+ if (!rowsByTable[tableName]) {
18
+ rowsByTable[tableName] = {
19
+ arrays: [],
20
+ locales: [],
21
+ rows: []
22
+ };
23
+ }
24
+ const parentID = parentRows[parentRowIndex].id;
25
+ // Add any sub arrays that need to be created
26
+ // We will call this recursively below
27
+ arrayRows.forEach((arrayRow)=>{
28
+ if (Object.keys(arrayRow.arrays).length > 0) {
29
+ rowsByTable[tableName].arrays.push(arrayRow.arrays);
30
+ }
31
+ // Set up parent IDs for both row and locale row
32
+ arrayRow.row._parentID = parentID;
33
+ rowsByTable[tableName].rows.push(arrayRow.row);
34
+ Object.entries(arrayRow.locales).forEach(([arrayRowLocale, arrayRowLocaleData])=>{
35
+ arrayRowLocaleData._parentID = arrayRow.row.id;
36
+ arrayRowLocaleData._locale = arrayRowLocale;
37
+ rowsByTable[tableName].locales.push(arrayRowLocaleData);
38
+ });
39
+ });
40
+ });
41
+ });
42
+ // Insert all corresponding arrays
43
+ // (one insert per array table)
44
+ for (const [tableName, row] of Object.entries(rowsByTable)){
45
+ if (row.rows.length > 0) {
46
+ await db.insert(adapter.tables[tableName]).values(row.rows).returning();
47
+ }
48
+ // Insert locale rows
49
+ if (adapter.tables[`${tableName}_locales`] && row.locales.length > 0) {
50
+ await db.insert(adapter.tables[`${tableName}_locales`]).values(row.locales).returning();
51
+ }
52
+ // If there are sub arrays, call this function recursively
53
+ if (row.arrays.length > 0) {
54
+ await insertArrays({
55
+ adapter,
56
+ arrays: row.arrays,
57
+ db,
58
+ parentRows: row.rows
59
+ });
60
+ }
61
+ }
62
+ };
63
+
64
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91cHNlcnRSb3cvaW5zZXJ0QXJyYXlzLnRzIl0sInNvdXJjZXNDb250ZW50IjpbIi8qIGVzbGludC1kaXNhYmxlIG5vLXBhcmFtLXJlYXNzaWduICovXG5pbXBvcnQgdHlwZSB7IEFycmF5Um93VG9JbnNlcnQgfSBmcm9tICcuLi90cmFuc2Zvcm0vd3JpdGUvdHlwZXMnXG5pbXBvcnQgdH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