@strapi/data-transfer 4.14.4 → 4.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/dist/commands/commander.d.ts +1 -0
  2. package/dist/commands/commander.d.ts.map +1 -0
  3. package/dist/commands/data-transfer.d.ts +2 -1
  4. package/dist/commands/data-transfer.d.ts.map +1 -0
  5. package/dist/commands/export/action.d.ts +1 -0
  6. package/dist/commands/export/action.d.ts.map +1 -0
  7. package/dist/commands/export/command.d.ts +1 -0
  8. package/dist/commands/export/command.d.ts.map +1 -0
  9. package/dist/commands/helpers.d.ts +1 -0
  10. package/dist/commands/helpers.d.ts.map +1 -0
  11. package/dist/commands/import/action.d.ts +1 -0
  12. package/dist/commands/import/action.d.ts.map +1 -0
  13. package/dist/commands/import/command.d.ts +1 -0
  14. package/dist/commands/import/command.d.ts.map +1 -0
  15. package/dist/commands/index.d.ts +1 -0
  16. package/dist/commands/index.d.ts.map +1 -0
  17. package/dist/commands/transfer/action.d.ts +1 -0
  18. package/dist/commands/transfer/action.d.ts.map +1 -0
  19. package/dist/commands/transfer/command.d.ts +1 -0
  20. package/dist/commands/transfer/command.d.ts.map +1 -0
  21. package/dist/engine/diagnostic.d.ts +1 -0
  22. package/dist/engine/diagnostic.d.ts.map +1 -0
  23. package/dist/engine/errors.d.ts +1 -0
  24. package/dist/engine/errors.d.ts.map +1 -0
  25. package/dist/engine/index.d.ts +1 -0
  26. package/dist/engine/index.d.ts.map +1 -0
  27. package/dist/engine/validation/index.d.ts +1 -0
  28. package/dist/engine/validation/index.d.ts.map +1 -0
  29. package/dist/engine/validation/provider.d.ts +1 -0
  30. package/dist/engine/validation/provider.d.ts.map +1 -0
  31. package/dist/engine/validation/schemas/index.d.ts +1 -0
  32. package/dist/engine/validation/schemas/index.d.ts.map +1 -0
  33. package/dist/errors/base.d.ts +1 -0
  34. package/dist/errors/base.d.ts.map +1 -0
  35. package/dist/errors/constants.d.ts +1 -0
  36. package/dist/errors/constants.d.ts.map +1 -0
  37. package/dist/errors/index.d.ts +1 -0
  38. package/dist/errors/index.d.ts.map +1 -0
  39. package/dist/errors/providers.d.ts +1 -0
  40. package/dist/errors/providers.d.ts.map +1 -0
  41. package/dist/file/index.d.ts +1 -0
  42. package/dist/file/index.d.ts.map +1 -0
  43. package/dist/file/providers/destination/index.d.ts +1 -0
  44. package/dist/file/providers/destination/index.d.ts.map +1 -0
  45. package/dist/file/providers/destination/utils.d.ts +1 -0
  46. package/dist/file/providers/destination/utils.d.ts.map +1 -0
  47. package/dist/file/providers/index.d.ts +1 -0
  48. package/dist/file/providers/index.d.ts.map +1 -0
  49. package/dist/file/providers/source/index.d.ts +1 -0
  50. package/dist/file/providers/source/index.d.ts.map +1 -0
  51. package/dist/file/providers/source/utils.d.ts +1 -0
  52. package/dist/file/providers/source/utils.d.ts.map +1 -0
  53. package/dist/index.d.ts +1 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +5242 -30
  56. package/dist/index.js.map +1 -1
  57. package/dist/index.mjs +5213 -0
  58. package/dist/index.mjs.map +1 -0
  59. package/dist/strapi/index.d.ts +1 -0
  60. package/dist/strapi/index.d.ts.map +1 -0
  61. package/dist/strapi/providers/index.d.ts +1 -0
  62. package/dist/strapi/providers/index.d.ts.map +1 -0
  63. package/dist/strapi/providers/local-destination/index.d.ts +1 -0
  64. package/dist/strapi/providers/local-destination/index.d.ts.map +1 -0
  65. package/dist/strapi/providers/local-destination/strategies/index.d.ts +1 -0
  66. package/dist/strapi/providers/local-destination/strategies/index.d.ts.map +1 -0
  67. package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts +1 -0
  68. package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts.map +1 -0
  69. package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts +1 -0
  70. package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts.map +1 -0
  71. package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts +1 -0
  72. package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts.map +1 -0
  73. package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts +1 -0
  74. package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts.map +1 -0
  75. package/dist/strapi/providers/local-source/assets.d.ts +1 -0
  76. package/dist/strapi/providers/local-source/assets.d.ts.map +1 -0
  77. package/dist/strapi/providers/local-source/configuration.d.ts +1 -0
  78. package/dist/strapi/providers/local-source/configuration.d.ts.map +1 -0
  79. package/dist/strapi/providers/local-source/entities.d.ts +1 -0
  80. package/dist/strapi/providers/local-source/entities.d.ts.map +1 -0
  81. package/dist/strapi/providers/local-source/index.d.ts +1 -0
  82. package/dist/strapi/providers/local-source/index.d.ts.map +1 -0
  83. package/dist/strapi/providers/local-source/links.d.ts +1 -0
  84. package/dist/strapi/providers/local-source/links.d.ts.map +1 -0
  85. package/dist/strapi/providers/remote-destination/index.d.ts +1 -0
  86. package/dist/strapi/providers/remote-destination/index.d.ts.map +1 -0
  87. package/dist/strapi/providers/remote-source/index.d.ts +1 -0
  88. package/dist/strapi/providers/remote-source/index.d.ts.map +1 -0
  89. package/dist/strapi/providers/utils.d.ts +1 -0
  90. package/dist/strapi/providers/utils.d.ts.map +1 -0
  91. package/dist/strapi/queries/entity.d.ts +1 -0
  92. package/dist/strapi/queries/entity.d.ts.map +1 -0
  93. package/dist/strapi/queries/index.d.ts +1 -0
  94. package/dist/strapi/queries/index.d.ts.map +1 -0
  95. package/dist/strapi/queries/link.d.ts +1 -0
  96. package/dist/strapi/queries/link.d.ts.map +1 -0
  97. package/dist/strapi/remote/constants.d.ts +1 -0
  98. package/dist/strapi/remote/constants.d.ts.map +1 -0
  99. package/dist/strapi/remote/flows/default.d.ts +1 -0
  100. package/dist/strapi/remote/flows/default.d.ts.map +1 -0
  101. package/dist/strapi/remote/flows/index.d.ts +1 -0
  102. package/dist/strapi/remote/flows/index.d.ts.map +1 -0
  103. package/dist/strapi/remote/handlers/abstract.d.ts +1 -0
  104. package/dist/strapi/remote/handlers/abstract.d.ts.map +1 -0
  105. package/dist/strapi/remote/handlers/constants.d.ts +1 -0
  106. package/dist/strapi/remote/handlers/constants.d.ts.map +1 -0
  107. package/dist/strapi/remote/handlers/index.d.ts +4 -3
  108. package/dist/strapi/remote/handlers/index.d.ts.map +1 -0
  109. package/dist/strapi/remote/handlers/pull.d.ts +1 -0
  110. package/dist/strapi/remote/handlers/pull.d.ts.map +1 -0
  111. package/dist/strapi/remote/handlers/push.d.ts +1 -0
  112. package/dist/strapi/remote/handlers/push.d.ts.map +1 -0
  113. package/dist/strapi/remote/handlers/utils.d.ts +1 -0
  114. package/dist/strapi/remote/handlers/utils.d.ts.map +1 -0
  115. package/dist/strapi/remote/index.d.ts +1 -0
  116. package/dist/strapi/remote/index.d.ts.map +1 -0
  117. package/dist/utils/components.d.ts +1 -0
  118. package/dist/utils/components.d.ts.map +1 -0
  119. package/dist/utils/encryption/decrypt.d.ts +1 -0
  120. package/dist/utils/encryption/decrypt.d.ts.map +1 -0
  121. package/dist/utils/encryption/encrypt.d.ts +1 -0
  122. package/dist/utils/encryption/encrypt.d.ts.map +1 -0
  123. package/dist/utils/encryption/index.d.ts +1 -0
  124. package/dist/utils/encryption/index.d.ts.map +1 -0
  125. package/dist/utils/index.d.ts +1 -0
  126. package/dist/utils/index.d.ts.map +1 -0
  127. package/dist/utils/json.d.ts +1 -0
  128. package/dist/utils/json.d.ts.map +1 -0
  129. package/dist/utils/middleware.d.ts +1 -0
  130. package/dist/utils/middleware.d.ts.map +1 -0
  131. package/dist/utils/providers.d.ts +1 -0
  132. package/dist/utils/providers.d.ts.map +1 -0
  133. package/dist/utils/schema.d.ts +1 -0
  134. package/dist/utils/schema.d.ts.map +1 -0
  135. package/dist/utils/stream.d.ts +1 -0
  136. package/dist/utils/stream.d.ts.map +1 -0
  137. package/dist/utils/transaction.d.ts +1 -0
  138. package/dist/utils/transaction.d.ts.map +1 -0
  139. package/package.json +19 -17
  140. package/dist/commands/commander.js +0 -138
  141. package/dist/commands/commander.js.map +0 -1
  142. package/dist/commands/data-transfer.js +0 -359
  143. package/dist/commands/data-transfer.js.map +0 -1
  144. package/dist/commands/export/action.js +0 -156
  145. package/dist/commands/export/action.js.map +0 -1
  146. package/dist/commands/export/command.js +0 -30
  147. package/dist/commands/export/command.js.map +0 -1
  148. package/dist/commands/helpers.js +0 -87
  149. package/dist/commands/helpers.js.map +0 -1
  150. package/dist/commands/import/action.js +0 -139
  151. package/dist/commands/import/action.js.map +0 -1
  152. package/dist/commands/import/command.js +0 -75
  153. package/dist/commands/import/command.js.map +0 -1
  154. package/dist/commands/index.js +0 -13
  155. package/dist/commands/index.js.map +0 -1
  156. package/dist/commands/transfer/action.js +0 -161
  157. package/dist/commands/transfer/action.js.map +0 -1
  158. package/dist/commands/transfer/command.js +0 -69
  159. package/dist/commands/transfer/command.js.map +0 -1
  160. package/dist/engine/diagnostic.js +0 -50
  161. package/dist/engine/diagnostic.js.map +0 -1
  162. package/dist/engine/errors.js +0 -29
  163. package/dist/engine/errors.js.map +0 -1
  164. package/dist/engine/index.js +0 -708
  165. package/dist/engine/index.js.map +0 -1
  166. package/dist/engine/validation/index.js +0 -19
  167. package/dist/engine/validation/index.js.map +0 -1
  168. package/dist/engine/validation/provider.js +0 -18
  169. package/dist/engine/validation/provider.js.map +0 -1
  170. package/dist/engine/validation/schemas/index.js +0 -70
  171. package/dist/engine/validation/schemas/index.js.map +0 -1
  172. package/dist/errors/base.js +0 -16
  173. package/dist/errors/base.js.map +0 -1
  174. package/dist/errors/constants.js +0 -9
  175. package/dist/errors/constants.js.map +0 -1
  176. package/dist/errors/index.js +0 -19
  177. package/dist/errors/index.js.map +0 -1
  178. package/dist/errors/providers.js +0 -32
  179. package/dist/errors/providers.js.map +0 -1
  180. package/dist/file/index.js +0 -28
  181. package/dist/file/index.js.map +0 -1
  182. package/dist/file/providers/destination/index.js +0 -177
  183. package/dist/file/providers/destination/index.js.map +0 -1
  184. package/dist/file/providers/destination/utils.js +0 -62
  185. package/dist/file/providers/destination/utils.js.map +0 -1
  186. package/dist/file/providers/index.js +0 -19
  187. package/dist/file/providers/index.js.map +0 -1
  188. package/dist/file/providers/source/index.js +0 -234
  189. package/dist/file/providers/source/index.js.map +0 -1
  190. package/dist/file/providers/source/utils.js +0 -62
  191. package/dist/file/providers/source/utils.js.map +0 -1
  192. package/dist/strapi/index.js +0 -30
  193. package/dist/strapi/index.js.map +0 -1
  194. package/dist/strapi/providers/index.js +0 -23
  195. package/dist/strapi/providers/index.js.map +0 -1
  196. package/dist/strapi/providers/local-destination/index.js +0 -360
  197. package/dist/strapi/providers/local-destination/index.js.map +0 -1
  198. package/dist/strapi/providers/local-destination/strategies/index.js +0 -28
  199. package/dist/strapi/providers/local-destination/strategies/index.js.map +0 -1
  200. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js +0 -51
  201. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +0 -1
  202. package/dist/strapi/providers/local-destination/strategies/restore/entities.js +0 -106
  203. package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +0 -1
  204. package/dist/strapi/providers/local-destination/strategies/restore/index.js +0 -109
  205. package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +0 -1
  206. package/dist/strapi/providers/local-destination/strategies/restore/links.js +0 -32
  207. package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +0 -1
  208. package/dist/strapi/providers/local-source/assets.js +0 -102
  209. package/dist/strapi/providers/local-source/assets.js.map +0 -1
  210. package/dist/strapi/providers/local-source/configuration.js +0 -36
  211. package/dist/strapi/providers/local-source/configuration.js.map +0 -1
  212. package/dist/strapi/providers/local-source/entities.js +0 -85
  213. package/dist/strapi/providers/local-source/entities.js.map +0 -1
  214. package/dist/strapi/providers/local-source/index.js +0 -100
  215. package/dist/strapi/providers/local-source/index.js.map +0 -1
  216. package/dist/strapi/providers/local-source/links.js +0 -23
  217. package/dist/strapi/providers/local-source/links.js.map +0 -1
  218. package/dist/strapi/providers/remote-destination/index.js +0 -270
  219. package/dist/strapi/providers/remote-destination/index.js.map +0 -1
  220. package/dist/strapi/providers/remote-source/index.js +0 -239
  221. package/dist/strapi/providers/remote-source/index.js.map +0 -1
  222. package/dist/strapi/providers/utils.js +0 -138
  223. package/dist/strapi/providers/utils.js.map +0 -1
  224. package/dist/strapi/queries/entity.js +0 -130
  225. package/dist/strapi/queries/entity.js.map +0 -1
  226. package/dist/strapi/queries/index.js +0 -29
  227. package/dist/strapi/queries/index.js.map +0 -1
  228. package/dist/strapi/queries/link.js +0 -224
  229. package/dist/strapi/queries/link.js.map +0 -1
  230. package/dist/strapi/remote/constants.js +0 -6
  231. package/dist/strapi/remote/constants.js.map +0 -1
  232. package/dist/strapi/remote/flows/default.js +0 -41
  233. package/dist/strapi/remote/flows/default.js.map +0 -1
  234. package/dist/strapi/remote/flows/index.js +0 -59
  235. package/dist/strapi/remote/flows/index.js.map +0 -1
  236. package/dist/strapi/remote/handlers/abstract.js +0 -3
  237. package/dist/strapi/remote/handlers/abstract.js.map +0 -1
  238. package/dist/strapi/remote/handlers/constants.js +0 -5
  239. package/dist/strapi/remote/handlers/constants.js.map +0 -1
  240. package/dist/strapi/remote/handlers/index.js +0 -10
  241. package/dist/strapi/remote/handlers/index.js.map +0 -1
  242. package/dist/strapi/remote/handlers/pull.js +0 -243
  243. package/dist/strapi/remote/handlers/pull.js.map +0 -1
  244. package/dist/strapi/remote/handlers/push.js +0 -311
  245. package/dist/strapi/remote/handlers/push.js.map +0 -1
  246. package/dist/strapi/remote/handlers/utils.js +0 -298
  247. package/dist/strapi/remote/handlers/utils.js.map +0 -1
  248. package/dist/strapi/remote/index.js +0 -29
  249. package/dist/strapi/remote/index.js.map +0 -1
  250. package/dist/utils/components.js +0 -381
  251. package/dist/utils/components.js.map +0 -1
  252. package/dist/utils/encryption/decrypt.js +0 -47
  253. package/dist/utils/encryption/decrypt.js.map +0 -1
  254. package/dist/utils/encryption/encrypt.js +0 -47
  255. package/dist/utils/encryption/encrypt.js.map +0 -1
  256. package/dist/utils/encryption/index.js +0 -19
  257. package/dist/utils/encryption/index.js.map +0 -1
  258. package/dist/utils/index.js +0 -33
  259. package/dist/utils/index.js.map +0 -1
  260. package/dist/utils/json.js +0 -68
  261. package/dist/utils/json.js.map +0 -1
  262. package/dist/utils/middleware.js +0 -14
  263. package/dist/utils/middleware.js.map +0 -1
  264. package/dist/utils/providers.js +0 -11
  265. package/dist/utils/providers.js.map +0 -1
  266. package/dist/utils/schema.js +0 -29
  267. package/dist/utils/schema.js.map +0 -1
  268. package/dist/utils/stream.js +0 -59
  269. package/dist/utils/stream.js.map +0 -1
  270. package/dist/utils/transaction.js +0 -88
  271. package/dist/utils/transaction.js.map +0 -1
@@ -1,381 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.cloneComponents = exports.deleteComponent = exports.deleteComponents = exports.updateComponents = exports.createComponents = exports.getComponents = exports.omitComponentData = void 0;
7
- const lodash_1 = __importDefault(require("lodash"));
8
- const fp_1 = require("lodash/fp");
9
- const utils_1 = require("@strapi/utils");
10
- const isDialectMySQL = () => strapi.db?.dialect.client === 'mysql';
11
- function omitComponentData(contentType, data) {
12
- const { attributes } = contentType;
13
- const componentAttributes = Object.keys(attributes).filter((attributeName) => utils_1.contentTypes.isComponentAttribute(attributes[attributeName]));
14
- return (0, fp_1.omit)(componentAttributes, data);
15
- }
16
- exports.omitComponentData = omitComponentData;
17
- // NOTE: we could generalize the logic to allow CRUD of relation directly in the DB layer
18
- const createComponents = async (uid, data) => {
19
- const { attributes = {} } = strapi.getModel(uid);
20
- const componentBody = {};
21
- const attributeNames = Object.keys(attributes);
22
- for (const attributeName of attributeNames) {
23
- const attribute = attributes[attributeName];
24
- if (!(0, fp_1.has)(attributeName, data) || !utils_1.contentTypes.isComponentAttribute(attribute)) {
25
- continue;
26
- }
27
- if (attribute.type === 'component') {
28
- const { component: componentUID, repeatable = false } = attribute;
29
- const componentValue = data[attributeName];
30
- if (componentValue === null) {
31
- continue;
32
- }
33
- if (repeatable === true) {
34
- if (!Array.isArray(componentValue)) {
35
- throw new Error('Expected an array to create repeatable component');
36
- }
37
- // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
38
- const components = (await (0, utils_1.mapAsync)(componentValue, (value) => createComponent(componentUID, value), { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }));
39
- componentBody[attributeName] = components.map(({ id }) => {
40
- return {
41
- id,
42
- __pivot: {
43
- field: attributeName,
44
- component_type: componentUID,
45
- },
46
- };
47
- });
48
- }
49
- else {
50
- const component = await createComponent(componentUID, componentValue);
51
- componentBody[attributeName] = {
52
- id: component.id,
53
- __pivot: {
54
- field: attributeName,
55
- component_type: componentUID,
56
- },
57
- };
58
- }
59
- continue;
60
- }
61
- if (attribute.type === 'dynamiczone') {
62
- const dynamiczoneValues = data[attributeName];
63
- if (!Array.isArray(dynamiczoneValues)) {
64
- throw new Error('Expected an array to create repeatable component');
65
- }
66
- const createDynamicZoneComponents = async (value) => {
67
- const { id } = await createComponent(value.__component, value);
68
- return {
69
- id,
70
- __component: value.__component,
71
- __pivot: {
72
- field: attributeName,
73
- },
74
- };
75
- };
76
- // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
77
- componentBody[attributeName] = await (0, utils_1.mapAsync)(dynamiczoneValues, createDynamicZoneComponents, { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity });
78
- continue;
79
- }
80
- }
81
- return componentBody;
82
- };
83
- exports.createComponents = createComponents;
84
- const getComponents = async (uid, entity) => {
85
- const componentAttributes = utils_1.contentTypes.getComponentAttributes(strapi.getModel(uid));
86
- if (lodash_1.default.isEmpty(componentAttributes)) {
87
- return {};
88
- }
89
- return strapi.query(uid).load(entity, componentAttributes);
90
- };
91
- exports.getComponents = getComponents;
92
- /*
93
- delete old components
94
- create or update
95
- */
96
- const updateComponents = async (uid, entityToUpdate, data) => {
97
- const { attributes = {} } = strapi.getModel(uid);
98
- const componentBody = {};
99
- for (const attributeName of Object.keys(attributes)) {
100
- const attribute = attributes[attributeName];
101
- if (!(0, fp_1.has)(attributeName, data)) {
102
- continue;
103
- }
104
- if (attribute.type === 'component') {
105
- const { component: componentUID, repeatable = false } = attribute;
106
- const componentValue = data[attributeName];
107
- await deleteOldComponents(uid, componentUID, entityToUpdate, attributeName, componentValue);
108
- if (repeatable === true) {
109
- if (!Array.isArray(componentValue)) {
110
- throw new Error('Expected an array to create repeatable component');
111
- }
112
- // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
113
- const components = (await (0, utils_1.mapAsync)(componentValue, (value) => updateOrCreateComponent(componentUID, value), { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }));
114
- componentBody[attributeName] = components.filter(lodash_1.default.negate(lodash_1.default.isNil)).map(({ id }) => {
115
- return {
116
- id,
117
- __pivot: {
118
- field: attributeName,
119
- component_type: componentUID,
120
- },
121
- };
122
- });
123
- }
124
- else {
125
- const component = await updateOrCreateComponent(componentUID, componentValue);
126
- componentBody[attributeName] = component && {
127
- id: component.id,
128
- __pivot: {
129
- field: attributeName,
130
- component_type: componentUID,
131
- },
132
- };
133
- }
134
- continue;
135
- }
136
- if (attribute.type === 'dynamiczone') {
137
- const dynamiczoneValues = data[attributeName];
138
- await deleteOldDZComponents(uid, entityToUpdate, attributeName, dynamiczoneValues);
139
- if (!Array.isArray(dynamiczoneValues)) {
140
- throw new Error('Expected an array to create repeatable component');
141
- }
142
- // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
143
- componentBody[attributeName] = await (0, utils_1.mapAsync)(dynamiczoneValues, async (value) => {
144
- const { id } = await updateOrCreateComponent(value.__component, value);
145
- return {
146
- id,
147
- __component: value.__component,
148
- __pivot: {
149
- field: attributeName,
150
- },
151
- };
152
- }, { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity });
153
- continue;
154
- }
155
- }
156
- return componentBody;
157
- };
158
- exports.updateComponents = updateComponents;
159
- const pickStringifiedId = ({ id, }) => {
160
- if (typeof id === 'string') {
161
- return id;
162
- }
163
- return `${id}`;
164
- };
165
- const deleteOldComponents = async (uid, componentUID, entityToUpdate, attributeName, componentValue) => {
166
- const previousValue = (await strapi
167
- .query(uid)
168
- .load(entityToUpdate, attributeName));
169
- const idsToKeep = lodash_1.default.castArray(componentValue).filter((0, fp_1.has)('id')).map(pickStringifiedId);
170
- const allIds = lodash_1.default.castArray(previousValue).filter((0, fp_1.has)('id')).map(pickStringifiedId);
171
- idsToKeep.forEach((id) => {
172
- if (!allIds.includes(id)) {
173
- throw new utils_1.errors.ApplicationError(`Some of the provided components in ${attributeName} are not related to the entity`);
174
- }
175
- });
176
- const idsToDelete = lodash_1.default.difference(allIds, idsToKeep);
177
- if (idsToDelete.length > 0) {
178
- for (const idToDelete of idsToDelete) {
179
- await deleteComponent(componentUID, { id: idToDelete });
180
- }
181
- }
182
- };
183
- const deleteOldDZComponents = async (uid, entityToUpdate, attributeName, dynamiczoneValues) => {
184
- const previousValue = (await strapi
185
- .query(uid)
186
- .load(entityToUpdate, attributeName));
187
- const idsToKeep = lodash_1.default.castArray(dynamiczoneValues)
188
- .filter((0, fp_1.has)('id'))
189
- .map((v) => ({
190
- id: pickStringifiedId(v),
191
- __component: v.__component,
192
- }));
193
- const allIds = lodash_1.default.castArray(previousValue)
194
- .filter((0, fp_1.has)('id'))
195
- .map((v) => ({
196
- id: pickStringifiedId(v),
197
- __component: v.__component,
198
- }));
199
- idsToKeep.forEach(({ id, __component }) => {
200
- if (!allIds.find((el) => el.id === id && el.__component === __component)) {
201
- const err = new Error(`Some of the provided components in ${attributeName} are not related to the entity`);
202
- Object.assign(err, { status: 400 });
203
- throw err;
204
- }
205
- });
206
- const idsToDelete = allIds.reduce((acc, { id, __component }) => {
207
- if (!idsToKeep.find((el) => el.id === id && el.__component === __component)) {
208
- acc.push({ id, __component });
209
- }
210
- return acc;
211
- }, []);
212
- if (idsToDelete.length > 0) {
213
- for (const idToDelete of idsToDelete) {
214
- const { id, __component } = idToDelete;
215
- await deleteComponent(__component, { id });
216
- }
217
- }
218
- };
219
- const deleteComponents = async (uid, entityToDelete, { loadComponents = true } = {}) => {
220
- const { attributes = {} } = strapi.getModel(uid);
221
- const attributeNames = Object.keys(attributes);
222
- for (const attributeName of attributeNames) {
223
- const attribute = attributes[attributeName];
224
- if (attribute.type === 'component' || attribute.type === 'dynamiczone') {
225
- let value;
226
- if (loadComponents) {
227
- value = await strapi.query(uid).load(entityToDelete, attributeName);
228
- }
229
- else {
230
- value = entityToDelete[attributeName];
231
- }
232
- if (!value) {
233
- continue;
234
- }
235
- if (attribute.type === 'component') {
236
- const { component: componentUID } = attribute;
237
- // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
238
- await (0, utils_1.mapAsync)(lodash_1.default.castArray(value), (subValue) => deleteComponent(componentUID, subValue), {
239
- concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity,
240
- });
241
- }
242
- else {
243
- // delete dynamic zone components
244
- // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
245
- await (0, utils_1.mapAsync)(lodash_1.default.castArray(value), (subValue) => deleteComponent(subValue.__component, subValue), { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity });
246
- }
247
- continue;
248
- }
249
- }
250
- };
251
- exports.deleteComponents = deleteComponents;
252
- const cloneComponents = async (uid, entityToClone, data) => {
253
- const { attributes = {} } = strapi.getModel(uid);
254
- const componentBody = {};
255
- const componentData = await getComponents(uid, entityToClone);
256
- for (const attributeName of Object.keys(attributes)) {
257
- const attribute = attributes[attributeName];
258
- // If the attribute is not set or on the component to clone, skip it
259
- if (!(0, fp_1.has)(attributeName, data) && !(0, fp_1.has)(attributeName, componentData)) {
260
- continue;
261
- }
262
- if (attribute.type === 'component') {
263
- const { component: componentUID, repeatable = false } = attribute;
264
- const componentValue = (attributeName in data
265
- ? data[attributeName]
266
- : componentData[attributeName]);
267
- if (componentValue === null) {
268
- continue;
269
- }
270
- if (repeatable === true) {
271
- if (!Array.isArray(componentValue)) {
272
- throw new Error('Expected an array to create repeatable component');
273
- }
274
- // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
275
- const components = (await (0, utils_1.mapAsync)(componentValue, (value) => cloneComponent(componentUID, value), { concurrency: isDialectMySQL() ? 1 : Infinity }));
276
- componentBody[attributeName] = components.filter(lodash_1.default.negate(lodash_1.default.isNil)).map(({ id }) => {
277
- return {
278
- id,
279
- __pivot: {
280
- field: attributeName,
281
- component_type: componentUID,
282
- },
283
- };
284
- });
285
- }
286
- else {
287
- const component = await cloneComponent(componentUID, componentValue);
288
- componentBody[attributeName] = component && {
289
- id: component.id,
290
- __pivot: {
291
- field: attributeName,
292
- component_type: componentUID,
293
- },
294
- };
295
- }
296
- continue;
297
- }
298
- if (attribute.type === 'dynamiczone') {
299
- const dynamiczoneValues = (0, fp_1.has)(attributeName, data)
300
- ? data[attributeName]
301
- : componentData[attributeName];
302
- if (!Array.isArray(dynamiczoneValues)) {
303
- throw new Error('Expected an array to create repeatable component');
304
- }
305
- // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
306
- componentBody[attributeName] = await (0, utils_1.mapAsync)(dynamiczoneValues, async (value) => {
307
- const { id } = await cloneComponent(value.__component, value);
308
- return {
309
- id,
310
- __component: value.__component,
311
- __pivot: {
312
- field: attributeName,
313
- },
314
- };
315
- }, { concurrency: isDialectMySQL() ? 1 : Infinity });
316
- continue;
317
- }
318
- }
319
- return componentBody;
320
- };
321
- exports.cloneComponents = cloneComponents;
322
- /** *************************
323
- Component queries
324
- ************************** */
325
- // components can have nested compos so this must be recursive
326
- const createComponent = async (uid, data) => {
327
- const model = strapi.getModel(uid);
328
- const componentData = await createComponents(uid, data);
329
- const transform = (0, fp_1.pipe)(
330
- // Make sure we don't save the component with a pre-defined ID
331
- (0, fp_1.omit)('id'),
332
- // Remove the component data from the original data object ...
333
- (payload) => omitComponentData(model, payload),
334
- // ... and assign the newly created component instead
335
- (0, fp_1.assign)(componentData));
336
- return strapi.query(uid).create({ data: transform(data) });
337
- };
338
- // components can have nested compos so this must be recursive
339
- const updateComponent = async (uid, componentToUpdate, data) => {
340
- const model = strapi.getModel(uid);
341
- const componentData = await updateComponents(uid, componentToUpdate, data);
342
- return strapi.query(uid).update({
343
- where: {
344
- id: componentToUpdate.id,
345
- },
346
- data: Object.assign(omitComponentData(model, data), componentData),
347
- });
348
- };
349
- const updateOrCreateComponent = (componentUID, value) => {
350
- if (value === null) {
351
- return null;
352
- }
353
- // update
354
- if ('id' in value && typeof value.id !== 'undefined') {
355
- // TODO: verify the compo is associated with the entity
356
- return updateComponent(componentUID, { id: value.id }, value);
357
- }
358
- // create
359
- return createComponent(componentUID, value);
360
- };
361
- const deleteComponent = async (uid, componentToDelete) => {
362
- await deleteComponents(uid, componentToDelete);
363
- await strapi.query(uid).delete({ where: { id: componentToDelete.id } });
364
- };
365
- exports.deleteComponent = deleteComponent;
366
- const cloneComponent = async (uid, data) => {
367
- const model = strapi.getModel(uid);
368
- if (!('id' in data) || typeof data.id === 'undefined') {
369
- return createComponent(uid, data);
370
- }
371
- const componentData = await cloneComponents(uid, { id: data.id }, data);
372
- const transform = (0, fp_1.pipe)(
373
- // Make sure we don't save the component with a pre-defined ID
374
- (0, fp_1.omit)('id'),
375
- // Remove the component data from the original data object ...
376
- (payload) => omitComponentData(model, payload),
377
- // ... and assign the newly created component instead
378
- (0, fp_1.assign)(componentData));
379
- return strapi.query(uid).clone(data.id, { data: transform(data) });
380
- };
381
- //# sourceMappingURL=components.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/utils/components.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,kCAAoD;AAEpD,yCAAoF;AAoBpF,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,MAAM,C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C,qDAAqD;IACrD,IAAA,WAAM,EAAC,aAAa,CAAC,CACtB,CAAC;IAEF,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACrE,CAAC,CAAC"}
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDecryptionCipher = void 0;
4
- const crypto_1 = require("crypto");
5
- // different key values depending on algorithm chosen
6
- const getDecryptionStrategy = (algorithm) => {
7
- const strategies = {
8
- 'aes-128-ecb'(key) {
9
- const hashedKey = (0, crypto_1.scryptSync)(key, '', 16);
10
- const initVector = null;
11
- const securityKey = hashedKey;
12
- return (0, crypto_1.createDecipheriv)(algorithm, securityKey, initVector);
13
- },
14
- aes128(key) {
15
- const hashedKey = (0, crypto_1.scryptSync)(key, '', 32);
16
- const initVector = hashedKey.slice(16);
17
- const securityKey = hashedKey.slice(0, 16);
18
- return (0, crypto_1.createDecipheriv)(algorithm, securityKey, initVector);
19
- },
20
- aes192(key) {
21
- const hashedKey = (0, crypto_1.scryptSync)(key, '', 40);
22
- const initVector = hashedKey.slice(24);
23
- const securityKey = hashedKey.slice(0, 24);
24
- return (0, crypto_1.createDecipheriv)(algorithm, securityKey, initVector);
25
- },
26
- aes256(key) {
27
- const hashedKey = (0, crypto_1.scryptSync)(key, '', 48);
28
- const initVector = hashedKey.slice(32);
29
- const securityKey = hashedKey.slice(0, 32);
30
- return (0, crypto_1.createDecipheriv)(algorithm, securityKey, initVector);
31
- },
32
- };
33
- return strategies[algorithm];
34
- };
35
- /**
36
- * It creates a cipher instance used for decryption
37
- *
38
- * @param key - The decryption key
39
- * @param algorithm - The algorithm to use to create the Cipher
40
- *
41
- * @returns A {@link Cipher} instance created with the given key & algorithm
42
- */
43
- const createDecryptionCipher = (key, algorithm = 'aes-128-ecb') => {
44
- return getDecryptionStrategy(algorithm)(key);
45
- };
46
- exports.createDecryptionCipher = createDecryptionCipher;
47
- //# sourceMappingURL=decrypt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decrypt.js","sourceRoot":"","sources":["../../../src/utils/encryption/decrypt.ts"],"names":[],"mappings":";;;AAAA,mCAAqF;AAGrF,qDAAqD;AACrD,MAAM,qBAAqB,GAAG,CAAC,SAAoB,EAAsB,EAAE;IACzE,MAAM,UAAU,GAAe;QAC7B,aAAa,CAAC,GAAW;YACvB,MAAM,SAAS,GAAG,IAAA,mBAAU,EAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YAC1C,MAAM,UAAU,GAAsB,IAAI,CAAC;YAC3C,MAAM,WAAW,GAAc,SAAS,CAAC;YACzC,OAAO,IAAA,yBAAgB,EAAC,SAAS,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAC9D,CAAC;QACD,MAAM,CAAC,GAAW;YAChB,MAAM,SAAS,GAAG,IAAA,mBAAU,EAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YAC1C,MAAM,UAAU,GAAsB,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC1D,MAAM,WAAW,GAAc,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACtD,OAAO,IAAA,yBAAgB,EAAC,SAAS,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAC9D,CAAC;QACD,MAAM,CAAC,GAAW;YAChB,MAAM,SAAS,GAAG,IAAA,mBAAU,EAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YAC1C,MAAM,UAAU,GAAsB,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC1D,MAAM,WAAW,GAAc,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACtD,OAAO,IAAA,yBAAgB,EAAC,SAAS,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAC9D,CAAC;QACD,MAAM,CAAC,GAAW;YAChB,MAAM,SAAS,GAAG,IAAA,mBAAU,EAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YAC1C,MAAM,UAAU,GAAsB,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC1D,MAAM,WAAW,GAAc,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACtD,OAAO,IAAA,yBAAgB,EAAC,SAAS,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAC9D,CAAC;KACF,CAAC;IAEF,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF;;;;;;;GAOG;AACI,MAAM,sBAAsB,GAAG,CACpC,GAAW,EACX,YAAuB,aAAa,EAC5B,EAAE;IACV,OAAO,qBAAqB,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC;AAC/C,CAAC,CAAC;AALW,QAAA,sBAAsB,0BAKjC"}
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createEncryptionCipher = void 0;
4
- const crypto_1 = require("crypto");
5
- // different key values depending on algorithm chosen
6
- const getEncryptionStrategy = (algorithm) => {
7
- const strategies = {
8
- 'aes-128-ecb'(key) {
9
- const hashedKey = (0, crypto_1.scryptSync)(key, '', 16);
10
- const initVector = null;
11
- const securityKey = hashedKey;
12
- return (0, crypto_1.createCipheriv)(algorithm, securityKey, initVector);
13
- },
14
- aes128(key) {
15
- const hashedKey = (0, crypto_1.scryptSync)(key, '', 32);
16
- const initVector = hashedKey.slice(16);
17
- const securityKey = hashedKey.slice(0, 16);
18
- return (0, crypto_1.createCipheriv)(algorithm, securityKey, initVector);
19
- },
20
- aes192(key) {
21
- const hashedKey = (0, crypto_1.scryptSync)(key, '', 40);
22
- const initVector = hashedKey.slice(24);
23
- const securityKey = hashedKey.slice(0, 24);
24
- return (0, crypto_1.createCipheriv)(algorithm, securityKey, initVector);
25
- },
26
- aes256(key) {
27
- const hashedKey = (0, crypto_1.scryptSync)(key, '', 48);
28
- const initVector = hashedKey.slice(32);
29
- const securityKey = hashedKey.slice(0, 32);
30
- return (0, crypto_1.createCipheriv)(algorithm, securityKey, initVector);
31
- },
32
- };
33
- return strategies[algorithm];
34
- };
35
- /**
36
- * It creates a cipher instance used for encryption
37
- *
38
- * @param key - The encryption key
39
- * @param algorithm - The algorithm to use to create the Cipher
40
- *
41
- * @returns A {@link Cipher} instance created with the given key & algorithm
42
- */
43
- const createEncryptionCipher = (key, algorithm = 'aes-128-ecb') => {
44
- return getEncryptionStrategy(algorithm)(key);
45
- };
46
- exports.createEncryptionCipher = createEncryptionCipher;
47
- //# sourceMappingURL=encrypt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encrypt.js","sourceRoot":"","sources":["../../../src/utils/encryption/encrypt.ts"],"names":[],"mappings":";;;AAAA,mCAAmF;AAGnF,qDAAqD;AACrD,MAAM,qBAAqB,GAAG,CAAC,SAAoB,EAAsB,EAAE;IACzE,MAAM,UAAU,GAAe;QAC7B,aAAa,CAAC,GAAW;YACvB,MAAM,SAAS,GAAG,IAAA,mBAAU,EAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YAC1C,MAAM,UAAU,GAAsB,IAAI,CAAC;YAC3C,MAAM,WAAW,GAAc,SAAS,CAAC;YACzC,OAAO,IAAA,uBAAc,EAAC,SAAS,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAC5D,CAAC;QACD,MAAM,CAAC,GAAW;YAChB,MAAM,SAAS,GAAG,IAAA,mBAAU,EAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YAC1C,MAAM,UAAU,GAAsB,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC1D,MAAM,WAAW,GAAc,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACtD,OAAO,IAAA,uBAAc,EAAC,SAAS,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAC5D,CAAC;QACD,MAAM,CAAC,GAAW;YAChB,MAAM,SAAS,GAAG,IAAA,mBAAU,EAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YAC1C,MAAM,UAAU,GAAsB,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC1D,MAAM,WAAW,GAAc,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACtD,OAAO,IAAA,uBAAc,EAAC,SAAS,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAC5D,CAAC;QACD,MAAM,CAAC,GAAW;YAChB,MAAM,SAAS,GAAG,IAAA,mBAAU,EAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YAC1C,MAAM,UAAU,GAAsB,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC1D,MAAM,WAAW,GAAc,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACtD,OAAO,IAAA,uBAAc,EAAC,SAAS,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAC5D,CAAC;KACF,CAAC;IAEF,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF;;;;;;;GAOG;AACI,MAAM,sBAAsB,GAAG,CACpC,GAAW,EACX,YAAuB,aAAa,EAC5B,EAAE;IACV,OAAO,qBAAqB,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC;AAC/C,CAAC,CAAC;AALW,QAAA,sBAAsB,0BAKjC"}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./encrypt"), exports);
18
- __exportStar(require("./decrypt"), exports);
19
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/encryption/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B"}
@@ -1,33 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.middleware = exports.transaction = exports.schema = exports.json = exports.stream = exports.encryption = void 0;
27
- exports.encryption = __importStar(require("./encryption"));
28
- exports.stream = __importStar(require("./stream"));
29
- exports.json = __importStar(require("./json"));
30
- exports.schema = __importStar(require("./schema"));
31
- exports.transaction = __importStar(require("./transaction"));
32
- exports.middleware = __importStar(require("./middleware"));
33
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAA2C;AAC3C,mDAAmC;AACnC,+CAA+B;AAC/B,mDAAmC;AACnC,6DAA6C;AAC7C,2DAA2C"}
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.diff = void 0;
4
- const fp_1 = require("lodash/fp");
5
- const createContext = () => ({ path: [] });
6
- /**
7
- * Compute differences between two JSON objects and returns them
8
- *
9
- * @param a - First object
10
- * @param b - Second object
11
- * @param ctx - Context used to keep track of the current path during recursion
12
- */
13
- const diff = (a, b, ctx = createContext()) => {
14
- const diffs = [];
15
- const { path } = ctx;
16
- const aType = typeof a;
17
- const bType = typeof b;
18
- // Define helpers
19
- const added = () => {
20
- diffs.push({ kind: 'added', path, type: bType, value: b });
21
- return diffs;
22
- };
23
- const deleted = () => {
24
- diffs.push({ kind: 'deleted', path, type: aType, value: a });
25
- return diffs;
26
- };
27
- const modified = () => {
28
- diffs.push({
29
- kind: 'modified',
30
- path,
31
- types: [aType, bType],
32
- values: [a, b],
33
- });
34
- return diffs;
35
- };
36
- if ((0, fp_1.isArray)(a) && (0, fp_1.isArray)(b)) {
37
- let k = 0;
38
- for (const [aItem, bItem] of (0, fp_1.zip)(a, b)) {
39
- const kCtx = { path: [...path, k.toString()] };
40
- const kDiffs = (0, exports.diff)(aItem, bItem, kCtx);
41
- diffs.push(...kDiffs);
42
- k += 1;
43
- }
44
- return diffs;
45
- }
46
- if ((0, fp_1.isObject)(a) && (0, fp_1.isObject)(b)) {
47
- const keys = (0, fp_1.uniq)(Object.keys(a).concat(Object.keys(b)));
48
- for (const key of keys) {
49
- const aValue = a[key];
50
- const bValue = b[key];
51
- const nestedDiffs = (0, exports.diff)(aValue, bValue, { path: [...path, key] });
52
- diffs.push(...nestedDiffs);
53
- }
54
- return diffs;
55
- }
56
- if (!(0, fp_1.isEqual)(a, b)) {
57
- if (aType === 'undefined') {
58
- return added();
59
- }
60
- if (bType === 'undefined') {
61
- return deleted();
62
- }
63
- return modified();
64
- }
65
- return diffs;
66
- };
67
- exports.diff = diff;
68
- //# sourceMappingURL=json.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/utils/json.ts"],"names":[],"mappings":";;;AAAA,kCAAkE;AAElE,MAAM,aAAa,GAAG,GAAY,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;AAEpD;;;;;;GAMG;AACI,MAAM,IAAI,GAAG,CAAC,CAAU,EAAE,CAAU,EAAE,MAAe,aAAa,EAAE,EAAU,EAAE;IACrF,MAAM,KAAK,GAAW,EAAE,CAAC;IACzB,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;IAErB,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC;IACvB,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC;IAEvB,iBAAiB;IAEjB,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;QAC3D,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;QAC7D,OAAO,KAAK,CAAC;IACf,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