@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,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "connect", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return connect;
9
+ }
10
+ });
11
+ const _utils = require("drizzle-kit/utils");
12
+ const _drizzleorm = require("drizzle-orm");
13
+ const _nodepostgres = require("drizzle-orm/node-postgres");
14
+ const _pg = require("pg");
15
+ const _prompts = /*#__PURE__*/ _interop_require_default(require("prompts"));
16
+ function _interop_require_default(obj) {
17
+ return obj && obj.__esModule ? obj : {
18
+ default: obj
19
+ };
20
+ }
21
+ const connect = async function connect(payload) {
22
+ this.schema = {
23
+ ...this.tables,
24
+ ...this.relations,
25
+ ...this.enums
26
+ };
27
+ try {
28
+ this.pool = new _pg.Pool(this.client);
29
+ await this.pool.connect();
30
+ this.db = (0, _nodepostgres.drizzle)(this.pool, {
31
+ schema: this.schema
32
+ });
33
+ if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
34
+ this.payload.logger.info('---- DROPPING TABLES ----');
35
+ await this.db.execute((0, _drizzleorm.sql)`drop schema public cascade;\ncreate schema public;`);
36
+ this.payload.logger.info('---- DROPPED TABLES ----');
37
+ }
38
+ } catch (err) {
39
+ payload.logger.error(`Error: cannot connect to Postgres. Details: ${err.message}`, err);
40
+ process.exit(1);
41
+ }
42
+ this.payload.logger.info('Connected to Postgres successfully');
43
+ // Only push schema if not in production
44
+ if (process.env.NODE_ENV === 'production' || process.env.PAYLOAD_MIGRATING === 'true') return;
45
+ // This will prompt if clarifications are needed for Drizzle to push new schema
46
+ const { apply, hasDataLoss, statementsToExecute, warnings } = await (0, _utils.pushSchema)(this.schema, this.db);
47
+ this.payload.logger.debug({
48
+ hasDataLoss,
49
+ msg: 'Schema push results',
50
+ statementsToExecute,
51
+ warnings
52
+ });
53
+ if (warnings.length) {
54
+ this.payload.logger.warn({
55
+ msg: `Warnings detected during schema push: ${warnings.join('\n')}`,
56
+ warnings
57
+ });
58
+ if (hasDataLoss) {
59
+ this.payload.logger.warn({
60
+ msg: 'DATA LOSS WARNING: Possible data loss detected if schema is pushed.'
61
+ });
62
+ }
63
+ const { confirm: acceptWarnings } = await (0, _prompts.default)({
64
+ name: 'confirm',
65
+ initial: false,
66
+ message: 'Accept warnings and push schema to database?',
67
+ type: 'confirm'
68
+ }, {
69
+ onCancel: ()=>{
70
+ process.exit(0);
71
+ }
72
+ });
73
+ // Exit if user does not accept warnings.
74
+ // Q: Is this the right type of exit for this interaction?
75
+ if (!acceptWarnings) {
76
+ process.exit(0);
77
+ }
78
+ }
79
+ await apply();
80
+ };
81
+
82
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9jb25uZWN0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB0eXBlIHsgQ29ubmVjdCB9IGZyb20gJ3BheWxvYWQvZGF0YWJhc2UnXG5cbmltcG9ydCB7IHB1c2hTY2hlbWEgfSBmcm9tICdkcml6emxlLWtpdC91dGlscydcbmltcG9ydCB7IHNxbCB9IGZyb20gJ2RyaXp6bGUtb3JtJ1xuaW1wb3J0IHsgZHJpenpsZSB9IGZyb20gJ2RyaXp6bGUtb3JtL25vZGUtcG9zdGdyZXMnXG5pbXBvcnQgeyBQb29sIH0gZnJvbSAncGcnXG5pbXBvcnQgcHJvbXB0cyBmcm9tICdwcm9tcHRzJ1xuXG5pbXBvcnQgdHlwZSB7IFBvc3RncmVzQWRhcHRlciB9IGZyb20gJy4vdHlwZXMnXG5cbmV4cG9ydCBjb25zdCBjb25uZWN0OiBDb25uZWN0ID0gYXN5bmMgZnVuY3Rpb24gY29ubmVjdCh0aGlzOiBQb3N0Z3Jlc0FkYXB0ZXIsIHBheWxvYWQpIHtcbiAgdGhpcy5zY2hlbWEgPSB7XG4gICAgLi4udGhpcy50YWJsZXMsXG4gICAgLi4udGhpcy5yZWxhdGlvbnMsXG4gICAgLi4udGhpcy5lbnVtcyxcbiAgfVxuXG4gIHRyeSB7XG4gICAgdGhpcy5wb29sID0gbmV3IFBvb2wodGhpcy5jbGllbnQpXG4gICAgYXdhaXQgdGhpcy5wb29sLmNvbm5lY3QoKVxuXG4gICAgdGhpcy5kYiA9IGRyaXp6bGUodGhpcy5wb29sLCB7IHNjaGVtYTogdGhpcy5zY2hlbWEgfSlcbiAgICBpZiAocHJvY2Vzcy5lbnYuUEFZTE9BRF9EU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BSSxDQUFDTyxFQUFFO0lBR1QsSUFBSSxDQUFDUixPQUFPLENBQUNhLE1BQU0sQ0FBQ2UsS0FBSyxDQUFDO1FBQ3hCSjtRQUNBSyxLQUFLO1FBQ0xKO1FBQ0FDO0lBQ0Y7SUFFQSxJQUFJQSxTQUFTSSxNQUFNLEVBQUU7UUFDbkIsSUFBSSxDQUFDOUIsT0FBTyxDQUFDYSxNQUFNLENBQUNrQixJQUFJLENBQUM7WUFDdkJGLEtBQUssQ0FBQyxzQ0FBc0MsRUFBRUgsU0FBU00sSUFBSSxDQUFDLE1BQU0sQ0FBQztZQUNuRU47UUFDRjtRQUVBLElBQUlGLGFBQWE7WUFDZixJQUFJLENBQUN4QixPQUFPLENBQUNhLE1BQU0sQ0FBQ2tCLElBQUksQ0FBQztnQkFDdkJGLEtBQUs7WUFDUDtRQUNGO1FBRUEsTUFBTSxFQUFFSSxTQUFTQyxjQUFjLEVBQUUsR0FBRyxNQUFNQyxJQUFBQSxnQkFBTyxFQUMvQztZQUNFQyxNQUFNO1lBQ05DLFNBQVM7WUFDVGxCLFNBQVM7WUFDVG1CLE1BQU07UUFDUixHQUNBO1lBQ0VDLFVBQVU7Z0JBQ1I3QixRQUFRVSxJQUFJLENBQUM7WUFDZjtRQUNGO1FBR0YseUNBQXlDO1FBQ3pDLDBEQUEwRDtRQUMxRCxJQUFJLENBQUNjLGdCQUFnQjtZQUNuQnhCLFFBQVFVLElBQUksQ0FBQztRQUNmO0lBQ0Y7SUFFQSxNQUFNRztBQUNSIn0=
package/dist/create.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "create", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return create;
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
+ const create = async function create({ collection: collectionSlug, data, req }) {
19
+ const db = this.sessions[req.transactionID]?.db || this.db;
20
+ const collection = this.payload.collections[collectionSlug].config;
21
+ const result = await (0, _upsertRow.upsertRow)({
22
+ adapter: this,
23
+ data,
24
+ db,
25
+ fields: collection.fields,
26
+ operation: 'create',
27
+ tableName: (0, _tosnakecase.default)(collectionSlug)
28
+ });
29
+ return result;
30
+ };
31
+
32
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9jcmVhdGUudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHR5cGUgeyBDcmVhdGUgfSBmcm9tICdwYXlsb2FkL2RhdGFiYXNlJ1xuXG5pbXBvcnQgdG9TbmFrZUNhc2UgZnJvbSAndG8tc25ha2UtY2FzZSdcblxuaW1wb3J0IHsgdXBzZXJ0Um93IH0gZnJvbSAnLi91cHNlcnRSb3cnXG5cbmV4cG9ydCBjb25zdCBjcmVhdGU6IENyZWF0ZSA9IGFzeW5jIGZ1bmN0aW9uIGNyZWF0ZSAoeyBjb2xsZWN0aW9uOiBjb2xsZWN0aW9uU2x1ZywgZGF0YSwgcmVxIH0pIHtcbiAgY29uc3QgZGIgPSB0aGlzLnNlc3Npb25zW3JlcS50cmFuc2FjdGlvbklEXT8uZGIgfHwgdGhpcy5kYlxuICBjb25zdCBjb2xsZWN0aW9uID0gdGhpcy5wYXlsb2FkLmNvbGxlY3Rpb25zW2NvbGxlY3Rpb25TbHVnXS5jb25maWdcblxuICBjb25zdCByZXN1bHQgPSBhd2FpdCB1cHNlcnRSb3coe1xuICAgIGFkYXB0ZXI6IHRoaXMsXG4gICAgZGF0YSxcbiAgICBkYixcbiAgICBmaWVsZHM6IGNvbGxlY3Rpb24uZmllbGRzLFxuICAgIG9wZXJhdGlvbjogJ2NyZWF0ZScsXG4gICAgdGFibGVOYW1lOiB0b1NuYWtlQ2FzZShjb2xsZWN0aW9uU2x1ZyksXG4gIH0pXG5cbiAgcmV0dXJuIHJlc3VsdFxufVxuIl0sIm5hbWVzIjpbImNyZWF0ZSIsImNvbGxlY3Rpb24iLCJjb2xsZWN0aW9uU2x1ZyIsImRhdGEiLCJyZXEiLCJkYiIsInNlc3Npb25zIiwidHJhbnNhY3Rpb25JRCIsInBheWxvYWQiLCJjb2xsZWN0aW9ucyIsImNvbmZpZyIsInJlc3VsdCIsInVwc2VydFJvdyIsImFkYXB0ZXIiLCJmaWVsZHMiLCJvcGVyYXRpb24iLCJ0YWJsZU5hbWUiLCJ0b1NuYWtlQ2FzZSJdLCJtYXBwaW5ncyI6Ijs7OzsrQkFNYUE7OztlQUFBQTs7O29FQUpXOzJCQUVFOzs7Ozs7QUFFbkIsTUFBTUEsU0FBaUIsZUFBZUEsT0FBUSxFQUFFQyxZQUFZQyxjQUFjLEVBQUVDLElBQUksRUFBRUMsR0FBRyxFQUFFO0lBQzVGLE1BQU1DLEtBQUssSUFBSSxDQUFDQyxRQUFRLENBQUNGLElBQUlHLGFBQWEsQ0FBQyxFQUFFRixNQUFNLElBQUksQ0FBQ0EsRUFBRTtJQUMxRCxNQUFNSixhQUFhLElBQUksQ0FBQ08sT0FBTyxDQUFDQyxXQUFXLENBQUNQLGVBQWUsQ0FBQ1EsTUFBTTtJQUVsRSxNQUFNQyxTQUFTLE1BQU1DLElBQUFBLG9CQUFTLEVBQUM7UUFDN0JDLFNBQVMsSUFBSTtRQUNiVjtRQUNBRTtRQUNBUyxRQUFRYixXQUFXYSxNQUFNO1FBQ3pCQyxXQUFXO1FBQ1hDLFdBQVdDLElBQUFBLG9CQUFXLEVBQUNmO0lBQ3pCO0lBRUEsT0FBT1M7QUFDVCJ9
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "createGlobal", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return createGlobal;
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 createGlobal({ 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 result = await (0, _upsertRow.upsertRow)({
22
+ adapter: this,
23
+ data,
24
+ db,
25
+ fields: globalConfig.fields,
26
+ operation: 'create',
27
+ tableName: (0, _tosnakecase.default)(slug)
28
+ });
29
+ return result;
30
+ }
31
+
32
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9jcmVhdGVHbG9iYWwudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHR5cGUgeyBDcmVhdGVHbG9iYWxBcmdzIH0gZnJvbSAncGF5bG9hZC9kYXRhYmFzZSdcbmltcG9ydCB0eXBlIHsgUGF5bG9hZFJlcXVlc3QsIFR5cGVXaXRoSUQgfSBmcm9tICdwYXlsb2FkL3R5cGVzJ1xuXG5pbXBvcnQgdG9TbmFrZUNhc2UgZnJvbSAndG8tc25ha2UtY2FzZSdcblxuaW1wb3J0IHR5cGUgeyBQb3N0Z3Jlc0FkYXB0ZXIgfSBmcm9tICcuL3R5cGVzJ1xuXG5pbXBvcnQgeyB1cHNlcnRSb3cgfSBmcm9tICcuL3Vwc2VydFJvdydcblxuZXhwb3J0IGFzeW5jIGZ1bmN0aW9uIGNyZWF0ZUdsb2JhbDxUIGV4dGVuZHMgVHlwZVdpdGhJRD4oXG4gIHRoaXM6IFBvc3RncmVzQWRhcHRlcixcbiAgeyBkYXRhLCByZXEgPSB7fSBhcyBQYXlsb2FkUmVxdWVzdCwgc2x1ZyB9OiBDcmVhdGVHbG9iYWxBcmdzLFxuKTogUHJvb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xDQUFDQyxPQUFPLENBQUNDLE9BQU8sQ0FBQ0MsTUFBTSxDQUFDQyxJQUFJLENBQUMsQ0FBQ0QsU0FBV0EsT0FBT1AsSUFBSSxLQUFLQTtJQUVsRixNQUFNUyxTQUFTLE1BQU1DLElBQUFBLG9CQUFTLEVBQUk7UUFDaENDLFNBQVMsSUFBSTtRQUNiYjtRQUNBRztRQUNBVyxRQUFRUixhQUFhUSxNQUFNO1FBQzNCQyxXQUFXO1FBQ1hDLFdBQVdDLElBQUFBLG9CQUFXLEVBQUNmO0lBQ3pCO0lBRUEsT0FBT1M7QUFDVCJ9
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "createGlobalVersion", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return createGlobalVersion;
9
+ }
10
+ });
11
+ const _drizzleorm = require("drizzle-orm");
12
+ const _versions = require("payload/versions");
13
+ const _tosnakecase = /*#__PURE__*/ _interop_require_default(require("to-snake-case"));
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 createGlobalVersion({ autosave, globalSlug, req = {}, versionData }) {
21
+ const db = this.sessions[req.transactionID]?.db || this.db;
22
+ const global = this.payload.globals.config.find(({ slug })=>slug === globalSlug);
23
+ const globalTableName = (0, _tosnakecase.default)(globalSlug);
24
+ const tableName = `_${globalTableName}_v`;
25
+ const result = await (0, _upsertRow.upsertRow)({
26
+ adapter: this,
27
+ data: {
28
+ autosave,
29
+ latest: true,
30
+ version: versionData
31
+ },
32
+ db,
33
+ fields: (0, _versions.buildVersionGlobalFields)(global),
34
+ operation: 'create',
35
+ tableName
36
+ });
37
+ const table = this.tables[tableName];
38
+ if (global.versions.drafts) {
39
+ await db.execute((0, _drizzleorm.sql)`
40
+ UPDATE ${table}
41
+ SET latest = false
42
+ WHERE ${table.id} != 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sQjtRQUNYO1FBQ0FDO1FBQ0FrQixRQUFRQyxJQUFBQSxrQ0FBd0IsRUFBQ2hCO1FBQ2pDaUIsV0FBVztRQUNYVDtJQUNGO0lBRUEsTUFBTVUsUUFBUSxJQUFJLENBQUNDLE1BQU0sQ0FBQ1gsVUFBVTtJQUVwQyxJQUFJUixPQUFPb0IsUUFBUSxDQUFDQyxNQUFNLEVBQUU7UUFDMUIsTUFBTXhCLEdBQUd5QixPQUFPLENBQUNDLElBQUFBLGVBQUcsQ0FBQSxDQUFDO2FBQ1osRUFBRUwsTUFBTTs7WUFFVCxFQUFFQSxNQUFNTSxFQUFFLENBQUMsSUFBSSxFQUFFZixPQUFPZSxFQUFFLENBQUM7SUFDbkMsQ0FBQztJQUNIO0lBRUEsT0FBT2Y7QUFDVCJ9
@@ -0,0 +1,85 @@
1
+ /* eslint-disable no-restricted-syntax, no-await-in-loop */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "createMigration", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return createMigration;
9
+ }
10
+ });
11
+ const _utils = require("drizzle-kit/utils");
12
+ const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
13
+ const _migrationTableExists = require("./utilities/migrationTableExists");
14
+ function _interop_require_default(obj) {
15
+ return obj && obj.__esModule ? obj : {
16
+ default: obj
17
+ };
18
+ }
19
+ const migrationTemplate = (upSQL, downSQL)=>`import { MigrateUpArgs, MigrateDownArgs } from '@payloadcms/db-postgres/types'
20
+ import { sql } from 'drizzle-orm'
21
+
22
+ export async function up({ payload }: MigrateUpArgs): Promise<void> {
23
+ ${upSQL ? `await payload.db.db.execute(sql\`
24
+
25
+ ${upSQL}\`);
26
+ ` : '// Migration code'}
27
+ };
28
+
29
+ export async function down({ payload }: MigrateUpArgs): Promise<void> {
30
+ ${downSQL ? `await payload.db.db.execute(sql\`
31
+
32
+ ${downSQL}\`);
33
+ ` : '// Migration code'}
34
+ };
35
+ `;
36
+ const getDefaultDrizzleSnapshot = ()=>({
37
+ id: '00000000-0000-0000-0000-000000000000',
38
+ _meta: {
39
+ columns: {},
40
+ schemas: {},
41
+ tables: {}
42
+ },
43
+ dialect: 'pg',
44
+ enums: {},
45
+ prevId: '00000000-0000-0000-0000-00000000000',
46
+ schemas: {},
47
+ tables: {},
48
+ version: '5'
49
+ });
50
+ const createMigration = async function createMigration(payload, migrationName) {
51
+ payload.logger.info({
52
+ msg: 'Creating new migration...'
53
+ });
54
+ const dir = payload.db.migrationDir;
55
+ if (!_fs.default.existsSync(dir)) {
56
+ _fs.default.mkdirSync(dir);
57
+ }
58
+ const [yyymmdd, hhmmss] = new Date().toISOString().split('T');
59
+ const formattedDate = yyymmdd.replace(/\D/g, '');
60
+ const formattedTime = hhmmss.split('.')[0].replace(/\D/g, '');
61
+ const timestamp = `${formattedDate}_${formattedTime}`;
62
+ const fileName = migrationName ? `${timestamp}_${migrationName.replace(/\W/g, '_')}.ts` : `${timestamp}.ts`;
63
+ const filePath = `${dir}/${fileName}`;
64
+ let drizzleJsonBefore = getDefaultDrizzleSnapshot();
65
+ const hasMigrationTable = await (0, _migrationTableExists.migrationTableExists)(this.db);
66
+ if (hasMigrationTable) {
67
+ const migrationQuery = await payload.find({
68
+ collection: 'payload-migrations',
69
+ limit: 1,
70
+ sort: '-name'
71
+ });
72
+ if (migrationQuery.docs?.[0]?.schema) {
73
+ drizzleJsonBefore = migrationQuery.docs[0]?.schema;
74
+ }
75
+ }
76
+ const drizzleJsonAfter = (0, _utils.generateDrizzleJson)(this.schema);
77
+ const sqlStatementsUp = await (0, _utils.generateMigration)(drizzleJsonBefore, drizzleJsonAfter);
78
+ const sqlStatementsDown = await (0, _utils.generateMigration)(drizzleJsonAfter, drizzleJsonBefore);
79
+ _fs.default.writeFileSync(filePath, migrationTemplate(sqlStatementsUp.length ? sqlStatementsUp?.join('\n') : undefined, sqlStatementsDown.length ? sqlStatementsDown?.join('\n') : undefined));
80
+ payload.logger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BQU1FLFdBQVcsQ0FBQyxFQUFFaEIsSUFBSSxDQUFDLEVBQUVlLFNBQVMsQ0FBQztJQUVyQyxJQUFJRSxvQkFBb0JoQztJQUV4QixNQUFNaUMsb0JBQW9CLE1BQU1DLElBQUFBLDBDQUFvQixFQUFDLElBQUksQ0FBQ2xCLEVBQUU7SUFFNUQsSUFBSWlCLG1CQUFtQjtRQUNyQixNQUFNRSxpQkFBaUIsTUFBTXpCLFFBQVEwQixJQUFJLENBQUM7WUFDeENDLFlBQVk7WUFDWkMsT0FBTztZQUNQQyxNQUFNO1FBQ1I7UUFFQSxJQUFJSixlQUFlSyxJQUFJLEVBQUUsQ0FBQyxFQUFFLEVBQUVDLFFBQVE7WUFDcENULG9CQUFvQkcsZUFBZUssSUFBSSxDQUFDLEVBQUUsRUFBRUM7UUFDOUM7SUFDRjtJQUVBLE1BQU1DLG1CQUFtQkMsSUFBQUEsMEJBQW1CLEVBQUMsSUFBSSxDQUFDRixNQUFNO0lBQ3hELE1BQU1HLGtCQUFrQixNQUFNQyxJQUFBQSx3QkFBaUIsRUFBQ2IsbUJBQW1CVTtJQUNuRSxNQUFNSSxvQkFBb0IsTUFBTUQsSUFBQUEsd0JBQWlCLEVBQUNILGtCQUFrQlY7SUFFcEVkLFdBQUUsQ0FBQzZCLGFBQWEsQ0FDZGhCLFVBQ0FsQyxrQkFDRStDLGdCQUFnQkksTUFBTSxHQUFHSixpQkFBaUJLLEtBQUssUUFBUUMsV0FDdkRKLGtCQUFrQkUsTUFBTSxHQUFHRixtQkFBbUJHLEtBQUssUUFBUUM7SUFHL0R4QyxRQUFRRSxNQUFNLENBQUNDLElBQUksQ0FBQztRQUFFQyxLQUFLLENBQUMscUJBQXFCLEVBQUVpQixTQUFTLENBQUM7SUFBQztBQUNoRSJ9
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "createVersion", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return createVersion;
9
+ }
10
+ });
11
+ const _drizzleorm = require("drizzle-orm");
12
+ const _versions = require("payload/versions");
13
+ const _tosnakecase = /*#__PURE__*/ _interop_require_default(require("to-snake-case"));
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 createVersion({ autosave, collectionSlug, parent, req = {}, versionData }) {
21
+ const db = this.sessions[req.transactionID]?.db || this.db;
22
+ const collection = this.payload.collections[collectionSlug].config;
23
+ const collectionTableName = (0, _tosnakecase.default)(collectionSlug);
24
+ const tableName = `_${collectionTableName}_v`;
25
+ const result = await (0, _upsertRow.upsertRow)({
26
+ adapter: this,
27
+ data: {
28
+ autosave,
29
+ latest: true,
30
+ parent,
31
+ version: versionData
32
+ },
33
+ db,
34
+ fields: (0, _versions.buildVersionCollectionFields)(collection),
35
+ operation: 'create',
36
+ tableName
37
+ });
38
+ const table = this.tables[tableName];
39
+ const relationshipsTable = this.tables[`${tableName}_relationships`];
40
+ if (collection.versions.drafts) {
41
+ await db.execute((0, _drizzleorm.sql)`
42
+ UPDATE ${table}
43
+ SET latest = false
44
+ FROM ${relationshipsTable}
45
+ WHERE ${table.id} = ${relationshipsTable.parent}
46
+ AND ${relationshipsTable.path} = ${'parent'}
47
+ AND ${relationshipsTable[`${collectionSlug}ID`]} = ${parent}
48
+ AND ${table.id} != ${result.id};
49
+ `);
50
+ }
51
+ return result;
52
+ }
53
+
54
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9jcmVhdGVWZXJzaW9uLnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB0eXBlIHsgQ3JlYXRlVmVyc2lvbkFyZ3MsIFR5cGVXaXRoVmVyc2lvbiB9IGZyb20gJ3BheWxvYWQvZGF0YWJhc2UnXG5pbXBvcnQgdHlwZSB7IFBheWxvYWRSZX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EQyxTQUFTLElBQUk7UUFDYkMsTUFBTTtZQUNKbEI7WUFDQW1CLFFBQVE7WUFDUmpCO1lBQ0FrQixTQUFTaEI7UUFDWDtRQUNBQztRQUNBZ0IsUUFBUUMsSUFBQUEsc0NBQTRCLEVBQUNkO1FBQ3JDZSxXQUFXO1FBQ1hUO0lBQ0Y7SUFFQSxNQUFNVSxRQUFRLElBQUksQ0FBQ0MsTUFBTSxDQUFDWCxVQUFVO0lBQ3BDLE1BQU1ZLHFCQUFxQixJQUFJLENBQUNELE1BQU0sQ0FBQyxDQUFDLEVBQUVYLFVBQVUsY0FBYyxDQUFDLENBQUM7SUFFcEUsSUFBSU4sV0FBV21CLFFBQVEsQ0FBQ0MsTUFBTSxFQUFFO1FBQzlCLE1BQU12QixHQUFHd0IsT0FBTyxDQUFDQyxJQUFBQSxlQUFHLENBQUEsQ0FBQzthQUNaLEVBQUVOLE1BQU07O1dBRVYsRUFBRUUsbUJBQW1CO1lBQ3BCLEVBQUVGLE1BQU1PLEVBQUUsQ0FBQyxHQUFHLEVBQUVMLG1CQUFtQnhCLE1BQU0sQ0FBQztZQUMxQyxFQUFFd0IsbUJBQW1CTSxJQUFJLENBQUMsR0FBRyxFQUFFLFNBQVM7WUFDeEMsRUFBRU4sa0JBQWtCLENBQUMsQ0FBQyxFQUFFekIsZUFBZSxFQUFFLENBQUMsQ0FBQyxDQUFDLEdBQUcsRUFBRUMsT0FBTztZQUN4RCxFQUFFc0IsTUFBTU8sRUFBRSxDQUFDLElBQUksRUFBRWhCLE9BQU9nQixFQUFFLENBQUM7RUFDckMsQ0FBQztJQUNEO0lBRUEsT0FBT2hCO0FBQ1QifQ==
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "deleteMany", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return deleteMany;
9
+ }
10
+ });
11
+ const _drizzleorm = require("drizzle-orm");
12
+ const _tosnakecase = /*#__PURE__*/ _interop_require_default(require("to-snake-case"));
13
+ const _findMany = require("./find/findMany");
14
+ function _interop_require_default(obj) {
15
+ return obj && obj.__esModule ? obj : {
16
+ default: obj
17
+ };
18
+ }
19
+ const deleteMany = async function deleteMany({ collection, req = {}, where }) {
20
+ const db = this.sessions[req.transactionID]?.db || this.db;
21
+ const collectionConfig = this.payload.collections[collection].config;
22
+ const tableName = (0, _tosnakecase.default)(collection);
23
+ const result = await (0, _findMany.findMany)({
24
+ adapter: this,
25
+ fields: collectionConfig.fields,
26
+ limit: 0,
27
+ locale: req.locale,
28
+ page: 1,
29
+ pagination: false,
30
+ req,
31
+ tableName,
32
+ where
33
+ });
34
+ const ids = [];
35
+ result.docs.forEach((data)=>{
36
+ ids.push(data.id);
37
+ });
38
+ if (ids.length > 0) {
39
+ await db.delete(this.tables[tableName]).where((0, _drizzleorm.inArray)(this.tables[tableName].id, ids));
40
+ }
41
+ return result;
42
+ };
43
+
44
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9kZWxldGVNYW55LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB0eXBlIHsgRGVsZXRlTWFueSB9IGZyb20gJ3BheWxvYWQvZGF0YWJhc2UnXG5pbXBvcnQgdHlwZSB7IFBheWxvYWRSZXF1ZXN0IH0gZnJvbSAncGF5bG9hZC90eXBlcydcblxuaW1wb3J0IHsgaW5BcnJheSB9IGZyb20gJ2RyaXp6bGUtb3JtJ1xuaW1wb3J0IHRvU25ha2VDYXNlIGZyb20gJ3RvLXNuYWtlLWNhc2UnXG5cbmltcG9ydCB0eXBlIHsgUG9zdGdyZXNBZGFwdGVyIH0gZnJvbSAnLi90eXBlcydcblxuaW1wb3J0IHsgZmluZE1hbnkgfSBmcm9tICcuL2ZpbmQvZmluZE1hbnknXG5cbmV4cG9ydCBjb25zdCBkZWxldGVNYW55OiBEZWxldGVNYW55ID0gYXN5bmMgZn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gsSUFBSUksSUFBSSxDQUFDRCxLQUFLRSxFQUFFO0lBQ2xCO0lBRUEsSUFBSUwsSUFBSU0sTUFBTSxHQUFHLEdBQUc7UUFDbEIsTUFBTXZCLEdBQUd3QixNQUFNLENBQUMsSUFBSSxDQUFDQyxNQUFNLENBQUNsQixVQUFVLEVBQUVSLEtBQUssQ0FBQzJCLElBQUFBLG1CQUFPLEVBQUMsSUFBSSxDQUFDRCxNQUFNLENBQUNsQixVQUFVLENBQUNlLEVBQUUsRUFBRUw7SUFDbkY7SUFFQSxPQUFPUjtBQUNUIn0=
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "deleteOne", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return deleteOne;
9
+ }
10
+ });
11
+ const _tosnakecase = /*#__PURE__*/ _interop_require_default(require("to-snake-case"));
12
+ const _buildFindManyArgs = require("./find/buildFindManyArgs");
13
+ const _buildQuery = /*#__PURE__*/ _interop_require_default(require("./queries/buildQuery"));
14
+ const _read = require("./transform/read");
15
+ function _interop_require_default(obj) {
16
+ return obj && obj.__esModule ? obj : {
17
+ default: obj
18
+ };
19
+ }
20
+ const deleteOne = async function deleteOne({ collection, req = {}, where: incomingWhere }) {
21
+ const db = this.sessions[req.transactionID]?.db || this.db;
22
+ const collectionConfig = this.payload.collections[collection].config;
23
+ const tableName = (0, _tosnakecase.default)(collection);
24
+ const { where } = await (0, _buildQuery.default)({
25
+ adapter: this,
26
+ fields: collectionConfig.fields,
27
+ tableName,
28
+ where: incomingWhere
29
+ });
30
+ const findManyArgs = (0, _buildFindManyArgs.buildFindManyArgs)({
31
+ adapter: this,
32
+ depth: 0,
33
+ fields: collectionConfig.fields,
34
+ tableName
35
+ });
36
+ findManyArgs.where = where;
37
+ const docToDelete = await db.query[tableName].findFirst(findManyArgs);
38
+ const result = (0, _read.transform)({
39
+ config: this.payload.config,
40
+ data: docToDelete,
41
+ fields: collectionConfig.fields
42
+ });
43
+ await db.delete(this.tables[tableName]).where(where);
44
+ return result;
45
+ };
46
+
47
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9kZWxldGVPbmUudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHR5cGUgeyBEZWxldGVPbmUgfSBmcm9tICdwYXlsb2FkL2RhdGFiYXNlJ1xuaW1wb3J0IHR5cGUgeyBQYXlsb2FkUmVxdWVzdCB9IGZyb20gJ3BheWxvYWQvdHlwZXMnXG5cbmltcG9ydCB0b1NuYWtlQ2FzZSBmcm9tICd0by1zbmFrZS1jYXNlJ1xuXG5pbXBvcnQgdHlwZSB7IFBvc3RncmVzQWRhcHRlciB9IGZyb20gJy4vdHlwZXMnXG5cbmltcG9ydCB7IGJ1aWxkRmluZE1hbnlBcmdzIH0gZnJvbSAnLi9maW5kL2J1aWxkRmluZE1hbnlBcmdzJ1xuaW1wb3J0IGJ1aWxkUXVlcnkgZnJvbSAnLi9xdWVyaWVzL2J1aWxkUXVlcnknXG5pbXBvcnQgeyB0cmFuc2Zvcm0gfSBmcm9tICcuL3RyYW5zZm9ybS9yZWFkJ1xuXG5leHBvcnQgY29uc3QgZGVsZXRlT25lOiBEZWxldGVPbmUgPSBhc3luYyBmdW5jdGlvbiBkZWxldGVPbmUoXG4gIHRoaXM6IFBvc3RncmVzQWRhcHRlcixcbiAgeyBjb2xsZWN0aW9uLCByZXEgPSB7fSBhcyBQYXlsb2FkUmVxdWVzdCwgd2hlcmU6IGluY29taW5nV2hlcmUgfSxcbikge1xuICBjb25zdCBkYiA9IHRoaXMuc2Vzc2lvbnNbcmVxLnRyYW5zYWN0aW9uSURdPy5kYiB8fCB0aGlzLmRiXG4gIGNvbnN0IGNvbGxlY3Rpb25Db25maWcgPSB0aGlzLnBheWxvYWQuY29sbGVjdGlvbnNbY29sbGVjdGlvbl0uY29uZmlnXG4gIGNvbnN0IH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UFDVCxVQUFVLENBQUNVLFNBQVMsQ0FBQ0w7SUFFeEQsTUFBTU0sU0FBU0MsSUFBQUEsZUFBUyxFQUFDO1FBQ3ZCYixRQUFRLElBQUksQ0FBQ0YsT0FBTyxDQUFDRSxNQUFNO1FBQzNCYyxNQUFNTDtRQUNOSixRQUFRUixpQkFBaUJRLE1BQU07SUFDakM7SUFFQSxNQUFNWCxHQUFHcUIsTUFBTSxDQUFDLElBQUksQ0FBQ0MsTUFBTSxDQUFDZixVQUFVLEVBQUVULEtBQUssQ0FBQ0E7SUFFOUMsT0FBT29CO0FBQ1QifQ==
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "deleteVersions", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return deleteVersions;
9
+ }
10
+ });
11
+ const _drizzleorm = require("drizzle-orm");
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 deleteVersions = async function deleteVersion({ collection, locale, req = {}, where: where }) {
21
+ const db = this.sessions[req.transactionID]?.db || this.db;
22
+ const collectionConfig = this.payload.collections[collection].config;
23
+ const tableName = `_${(0, _tosnakecase.default)(collection)}_v`;
24
+ const fields = (0, _versions.buildVersionCollectionFields)(collectionConfig);
25
+ const { docs } = await (0, _findMany.findMany)({
26
+ adapter: this,
27
+ fields,
28
+ limit: 0,
29
+ locale,
30
+ page: 1,
31
+ pagination: false,
32
+ req,
33
+ tableName,
34
+ where
35
+ });
36
+ const ids = [];
37
+ docs.forEach((doc)=>{
38
+ ids.push(doc.id);
39
+ });
40
+ if (ids.length > 0) {
41
+ await db.delete(this.tables[tableName]).where((0, _drizzleorm.inArray)(this.tables[tableName].id, ids));
42
+ }
43
+ return docs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LE1BQU0sQ0FBQyxJQUFJLENBQUNDLE1BQU0sQ0FBQ2pCLFVBQVUsRUFBRVIsS0FBSyxDQUFDMEIsSUFBQUEsbUJBQU8sRUFBQyxJQUFJLENBQUNELE1BQU0sQ0FBQ2pCLFVBQVUsQ0FBQ2MsRUFBRSxFQUFFSjtJQUNuRjtJQUVBLE9BQU9OO0FBQ1QifQ==
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "destroy", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return destroy;
9
+ }
10
+ });
11
+ const destroy = async function destroy() {
12
+ // TODO: this hangs test suite for some reason
13
+ // await this.pool.end()
14
+ };
15
+
16
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9kZXN0cm95LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB0eXBlIHsgRGVzdHJveSB9IGZyb20gJ3BheWxvYWQvZGF0YWJhc2UnXG5cbmltcG9ydCB0eXBlIHsgUG9zdGdyZXNBZGFwdGVyIH0gZnJvbSAnLi90eXBlcydcblxuZXhwb3J0IGNvbnN0IGRlc3Ryb3k6IERlc3Ryb3kgPSBhc3luYyBmdW5jdGlvbiBkZXN0cm95KHRoaXM6IFBvc3RncmVzQWRhcHRlcikge1xuICAvLyBUT0RPOiB0aGlzIGhhbmdzIHRlc3Qgc3VpdGUgZm9yIHNvbWUgcmVhc29uXG4gIC8vIGF3YWl0IHRoaXMucG9vbC5lbmQoKVxufVxuIl0sIm5hbWVzIjpbImRlc3Ryb3kiXSwibWFwcGluZ3MiOiI7Ozs7K0JBSWFBOzs7ZUFBQUE7OztBQUFOLE1BQU1BLFVBQW1CLGVBQWVBO0FBQzdDLDhDQUE4QztBQUM5Qyx3QkFBd0I7QUFDMUIifQ==
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "buildFindManyArgs", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return buildFindManyArgs;
9
+ }
10
+ });
11
+ const _traverseFields = require("./traverseFields");
12
+ const buildFindManyArgs = ({ adapter, depth, fields, tableName })=>{
13
+ const result = {
14
+ with: {}
15
+ };
16
+ const _locales = {
17
+ columns: {
18
+ id: false,
19
+ _parentID: false
20
+ }
21
+ };
22
+ if (adapter.tables[`${tableName}_numbers`]) {
23
+ result.with._numbers = {
24
+ columns: {
25
+ id: false,
26
+ parent: false
27
+ },
28
+ orderBy: ({ order }, { asc: ASC })=>[
29
+ ASC(order)
30
+ ]
31
+ };
32
+ }
33
+ if (adapter.tables[`${tableName}_relationships`]) {
34
+ result.with._relationships = {
35
+ columns: {
36
+ id: false,
37
+ parent: false
38
+ },
39
+ orderBy: ({ order }, { asc: ASC })=>[
40
+ ASC(order)
41
+ ]
42
+ };
43
+ }
44
+ if (adapter.tables[`${tableName}_locales`]) {
45
+ result.with._locales = _locales;
46
+ }
47
+ (0, _traverseFields.traverseFields)({
48
+ _locales,
49
+ adapter,
50
+ currentArgs: result,
51
+ currentTableName: tableName,
52
+ depth,
53
+ fields,
54
+ path: '',
55
+ topLevelArgs: result,
56
+ topLevelTableName: tableName
57
+ });
58
+ return result;
59
+ };
60
+
61
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9maW5kL2J1aWxkRmluZE1hbnlBcmdzLnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB0eXBlIHsgREJRdWVyeUNvbmZpZyB9IGZyb20gJ2RyaXp6bGUtb3JtJ1xuaW1wb3J0IHR5cGUgeyBGaWVsZCB9IGZyb20gJ3BheWxvYWQvdHlwZXMnXG5cbmltcG9ydCB0eXBlIHsgUG9zdGdyZXNBZGFwdGVyIH0gZnJvbSAnLi4vdHlwZXMnXG5cbmltcG9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SxNQUFNLENBQUMsQ0FBQyxFQUFFUCxVQUFVLFFBQVEsQ0FBQyxDQUFDLEVBQUU7UUFDMUNDLE9BQU9DLElBQUksQ0FBQ0MsUUFBUSxHQUFHQTtJQUN6QjtJQUVBWSxJQUFBQSw4QkFBYyxFQUFDO1FBQ2JaO1FBQ0FOO1FBQ0FtQixhQUFhZjtRQUNiZ0Isa0JBQWtCakI7UUFDbEJGO1FBQ0FDO1FBQ0FtQixNQUFNO1FBQ05DLGNBQWNsQjtRQUNkbUIsbUJBQW1CcEI7SUFDckI7SUFFQSxPQUFPQztBQUNUIn0=
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "chainMethods", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return chainMethods;
9
+ }
10
+ });
11
+ /**
12
+ * Call and returning methods that would normally be chained together but cannot be because of control logic
13
+ * @param methods
14
+ * @param query
15
+ */ const chainMethods = ({ methods, query })=>{
16
+ return methods.reduce((query, { args, method })=>{
17
+ return query[method](...args);
18
+ }, query);
19
+ };
20
+
21
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9maW5kL2NoYWluTWV0aG9kcy50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgdHlwZSBDaGFpbmVkTWV0aG9kcyA9IHtcbiAgYXJnczogdW5rbm93bltdXG4gIG1ldGhvZDogc3RyaW5nXG59W11cblxuLyoqXG4gKiBDYWxsIGFuZCByZXR1cm5pbmcgbWV0aG9kcyB0aGF0IHdvdWxkIG5vcm1hbGx5IGJlIGNoYWluZWQgdG9nZXRoZXIgYnV0IGNhbm5vdCBiZSBiZWNhdXNlIG9mIGNvbnRyb2wgbG9naWNcbiAqIEBwYXJhbSBtZXRob2RzXG4gKiBAcGFyYW0gcXVlcnlcbiAqL1xuY29uc3QgY2hhaW5NZXRob2RzID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