@wix/wix-data-items-common 1.0.52

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 (228) hide show
  1. package/README.md +8 -0
  2. package/dist/cjs/api/ApiClient.js +186 -0
  3. package/dist/cjs/api/ApiClient.js.map +1 -0
  4. package/dist/cjs/api/QueryBase.js +200 -0
  5. package/dist/cjs/api/QueryBase.js.map +1 -0
  6. package/dist/cjs/api/QueryValidator.js +36 -0
  7. package/dist/cjs/api/QueryValidator.js.map +1 -0
  8. package/dist/cjs/api/WixDataAggregate.js +4 -0
  9. package/dist/cjs/api/WixDataAggregate.js.map +1 -0
  10. package/dist/cjs/api/WixDataApi.js +800 -0
  11. package/dist/cjs/api/WixDataApi.js.map +1 -0
  12. package/dist/cjs/api/WixDataFilter.js +2 -0
  13. package/dist/cjs/api/WixDataFilter.js.map +1 -0
  14. package/dist/cjs/api/WixDataPatch.js +139 -0
  15. package/dist/cjs/api/WixDataPatch.js.map +1 -0
  16. package/dist/cjs/api/WixDataQuery.js +4 -0
  17. package/dist/cjs/api/WixDataQuery.js.map +1 -0
  18. package/dist/cjs/api/WixDataResult.js +4 -0
  19. package/dist/cjs/api/WixDataResult.js.map +1 -0
  20. package/dist/cjs/api/common.js +14 -0
  21. package/dist/cjs/api/common.js.map +1 -0
  22. package/dist/cjs/api/errors.js +67 -0
  23. package/dist/cjs/api/errors.js.map +1 -0
  24. package/dist/cjs/api/impl/WixDataAggregateImpl.js +193 -0
  25. package/dist/cjs/api/impl/WixDataAggregateImpl.js.map +1 -0
  26. package/dist/cjs/api/impl/WixDataQueryImpl.js +116 -0
  27. package/dist/cjs/api/impl/WixDataQueryImpl.js.map +1 -0
  28. package/dist/cjs/api/impl/WixDataResultImpl.js +111 -0
  29. package/dist/cjs/api/impl/WixDataResultImpl.js.map +1 -0
  30. package/dist/cjs/api/index.js +32 -0
  31. package/dist/cjs/api/index.js.map +1 -0
  32. package/dist/cjs/api/types.js +2 -0
  33. package/dist/cjs/api/types.js.map +1 -0
  34. package/dist/cjs/errors/base-validator.js +92 -0
  35. package/dist/cjs/errors/base-validator.js.map +1 -0
  36. package/dist/cjs/errors/errors.js +155 -0
  37. package/dist/cjs/errors/errors.js.map +1 -0
  38. package/dist/cjs/errors/index.js +15 -0
  39. package/dist/cjs/errors/index.js.map +1 -0
  40. package/dist/cjs/errors/validations.js +91 -0
  41. package/dist/cjs/errors/validations.js.map +1 -0
  42. package/dist/cjs/external-types.d.js +2 -0
  43. package/dist/cjs/external-types.d.js.map +1 -0
  44. package/dist/cjs/filter/FilterTree.js +154 -0
  45. package/dist/cjs/filter/FilterTree.js.map +1 -0
  46. package/dist/cjs/filter/WithFilter.js +2 -0
  47. package/dist/cjs/filter/WithFilter.js.map +1 -0
  48. package/dist/cjs/filter/filterBuilder.js +53 -0
  49. package/dist/cjs/filter/filterBuilder.js.map +1 -0
  50. package/dist/cjs/filter/filterMixin.js +144 -0
  51. package/dist/cjs/filter/filterMixin.js.map +1 -0
  52. package/dist/cjs/filter/index.js +16 -0
  53. package/dist/cjs/filter/index.js.map +1 -0
  54. package/dist/cjs/index.js +120 -0
  55. package/dist/cjs/index.js.map +1 -0
  56. package/dist/cjs/sort/sortMixin.js +79 -0
  57. package/dist/cjs/sort/sortMixin.js.map +1 -0
  58. package/dist/cjs/test-types.d.js +2 -0
  59. package/dist/cjs/test-types.d.js.map +1 -0
  60. package/dist/cjs/types/api.js +4 -0
  61. package/dist/cjs/types/api.js.map +1 -0
  62. package/dist/cjs/types/data-item-types.js +46 -0
  63. package/dist/cjs/types/data-item-types.js.map +1 -0
  64. package/dist/cjs/types/error.js +2 -0
  65. package/dist/cjs/types/error.js.map +1 -0
  66. package/dist/cjs/types/index.js +16 -0
  67. package/dist/cjs/types/index.js.map +1 -0
  68. package/dist/cjs/utils/base64url.js +51 -0
  69. package/dist/cjs/utils/base64url.js.map +1 -0
  70. package/dist/cjs/utils/clone.js +21 -0
  71. package/dist/cjs/utils/clone.js.map +1 -0
  72. package/dist/cjs/utils/codec.js +64 -0
  73. package/dist/cjs/utils/codec.js.map +1 -0
  74. package/dist/cjs/utils/field-key-utils.js +18 -0
  75. package/dist/cjs/utils/field-key-utils.js.map +1 -0
  76. package/dist/cjs/utils/index.js +25 -0
  77. package/dist/cjs/utils/index.js.map +1 -0
  78. package/dist/cjs/utils/type-utils.js +54 -0
  79. package/dist/cjs/utils/type-utils.js.map +1 -0
  80. package/dist/esm/api/ApiClient.js +174 -0
  81. package/dist/esm/api/ApiClient.js.map +1 -0
  82. package/dist/esm/api/QueryBase.js +117 -0
  83. package/dist/esm/api/QueryBase.js.map +1 -0
  84. package/dist/esm/api/QueryValidator.js +32 -0
  85. package/dist/esm/api/QueryValidator.js.map +1 -0
  86. package/dist/esm/api/WixDataAggregate.js +2 -0
  87. package/dist/esm/api/WixDataAggregate.js.map +1 -0
  88. package/dist/esm/api/WixDataApi.js +829 -0
  89. package/dist/esm/api/WixDataApi.js.map +1 -0
  90. package/dist/esm/api/WixDataFilter.js +2 -0
  91. package/dist/esm/api/WixDataFilter.js.map +1 -0
  92. package/dist/esm/api/WixDataPatch.js +134 -0
  93. package/dist/esm/api/WixDataPatch.js.map +1 -0
  94. package/dist/esm/api/WixDataQuery.js +2 -0
  95. package/dist/esm/api/WixDataQuery.js.map +1 -0
  96. package/dist/esm/api/WixDataResult.js +2 -0
  97. package/dist/esm/api/WixDataResult.js.map +1 -0
  98. package/dist/esm/api/common.js +10 -0
  99. package/dist/esm/api/common.js.map +1 -0
  100. package/dist/esm/api/errors.js +52 -0
  101. package/dist/esm/api/errors.js.map +1 -0
  102. package/dist/esm/api/impl/WixDataAggregateImpl.js +214 -0
  103. package/dist/esm/api/impl/WixDataAggregateImpl.js.map +1 -0
  104. package/dist/esm/api/impl/WixDataQueryImpl.js +119 -0
  105. package/dist/esm/api/impl/WixDataQueryImpl.js.map +1 -0
  106. package/dist/esm/api/impl/WixDataResultImpl.js +100 -0
  107. package/dist/esm/api/impl/WixDataResultImpl.js.map +1 -0
  108. package/dist/esm/api/index.js +5 -0
  109. package/dist/esm/api/index.js.map +1 -0
  110. package/dist/esm/api/types.js +2 -0
  111. package/dist/esm/api/types.js.map +1 -0
  112. package/dist/esm/errors/base-validator.js +71 -0
  113. package/dist/esm/errors/base-validator.js.map +1 -0
  114. package/dist/esm/errors/errors.js +147 -0
  115. package/dist/esm/errors/errors.js.map +1 -0
  116. package/dist/esm/errors/index.js +5 -0
  117. package/dist/esm/errors/index.js.map +1 -0
  118. package/dist/esm/errors/validations.js +114 -0
  119. package/dist/esm/errors/validations.js.map +1 -0
  120. package/dist/esm/filter/FilterTree.js +148 -0
  121. package/dist/esm/filter/FilterTree.js.map +1 -0
  122. package/dist/esm/filter/WithFilter.js +2 -0
  123. package/dist/esm/filter/WithFilter.js.map +1 -0
  124. package/dist/esm/filter/filterBuilder.js +43 -0
  125. package/dist/esm/filter/filterBuilder.js.map +1 -0
  126. package/dist/esm/filter/filterMixin.js +137 -0
  127. package/dist/esm/filter/filterMixin.js.map +1 -0
  128. package/dist/esm/filter/index.js +5 -0
  129. package/dist/esm/filter/index.js.map +1 -0
  130. package/dist/esm/index.js +9 -0
  131. package/dist/esm/index.js.map +1 -0
  132. package/dist/esm/sort/sortMixin.js +74 -0
  133. package/dist/esm/sort/sortMixin.js.map +1 -0
  134. package/dist/esm/types/api.js +2 -0
  135. package/dist/esm/types/api.js.map +1 -0
  136. package/dist/esm/types/data-item-types.js +35 -0
  137. package/dist/esm/types/data-item-types.js.map +1 -0
  138. package/dist/esm/types/error.js +2 -0
  139. package/dist/esm/types/error.js.map +1 -0
  140. package/dist/esm/types/index.js +3 -0
  141. package/dist/esm/types/index.js.map +1 -0
  142. package/dist/esm/utils/base64url.js +57 -0
  143. package/dist/esm/utils/base64url.js.map +1 -0
  144. package/dist/esm/utils/clone.js +18 -0
  145. package/dist/esm/utils/clone.js.map +1 -0
  146. package/dist/esm/utils/codec.js +60 -0
  147. package/dist/esm/utils/codec.js.map +1 -0
  148. package/dist/esm/utils/field-key-utils.js +14 -0
  149. package/dist/esm/utils/field-key-utils.js.map +1 -0
  150. package/dist/esm/utils/index.js +7 -0
  151. package/dist/esm/utils/index.js.map +1 -0
  152. package/dist/esm/utils/type-utils.js +40 -0
  153. package/dist/esm/utils/type-utils.js.map +1 -0
  154. package/dist/types/api/ApiClient.d.ts +30 -0
  155. package/dist/types/api/ApiClient.d.ts.map +1 -0
  156. package/dist/types/api/QueryBase.d.ts +111 -0
  157. package/dist/types/api/QueryBase.d.ts.map +1 -0
  158. package/dist/types/api/QueryValidator.d.ts +12 -0
  159. package/dist/types/api/QueryValidator.d.ts.map +1 -0
  160. package/dist/types/api/WixDataAggregate.d.ts +320 -0
  161. package/dist/types/api/WixDataAggregate.d.ts.map +1 -0
  162. package/dist/types/api/WixDataApi.d.ts +52 -0
  163. package/dist/types/api/WixDataApi.d.ts.map +1 -0
  164. package/dist/types/api/WixDataFilter.d.ts +424 -0
  165. package/dist/types/api/WixDataFilter.d.ts.map +1 -0
  166. package/dist/types/api/WixDataPatch.d.ts +80 -0
  167. package/dist/types/api/WixDataPatch.d.ts.map +1 -0
  168. package/dist/types/api/WixDataQuery.d.ts +702 -0
  169. package/dist/types/api/WixDataQuery.d.ts.map +1 -0
  170. package/dist/types/api/WixDataResult.d.ts +144 -0
  171. package/dist/types/api/WixDataResult.d.ts.map +1 -0
  172. package/dist/types/api/common.d.ts +3 -0
  173. package/dist/types/api/common.d.ts.map +1 -0
  174. package/dist/types/api/errors.d.ts +12 -0
  175. package/dist/types/api/errors.d.ts.map +1 -0
  176. package/dist/types/api/impl/WixDataAggregateImpl.d.ts +76 -0
  177. package/dist/types/api/impl/WixDataAggregateImpl.d.ts.map +1 -0
  178. package/dist/types/api/impl/WixDataQueryImpl.d.ts +72 -0
  179. package/dist/types/api/impl/WixDataQueryImpl.d.ts.map +1 -0
  180. package/dist/types/api/impl/WixDataResultImpl.d.ts +34 -0
  181. package/dist/types/api/impl/WixDataResultImpl.d.ts.map +1 -0
  182. package/dist/types/api/index.d.ts +11 -0
  183. package/dist/types/api/index.d.ts.map +1 -0
  184. package/dist/types/api/types.d.ts +163 -0
  185. package/dist/types/api/types.d.ts.map +1 -0
  186. package/dist/types/errors/base-validator.d.ts +28 -0
  187. package/dist/types/errors/base-validator.d.ts.map +1 -0
  188. package/dist/types/errors/errors.d.ts +108 -0
  189. package/dist/types/errors/errors.d.ts.map +1 -0
  190. package/dist/types/errors/index.d.ts +5 -0
  191. package/dist/types/errors/index.d.ts.map +1 -0
  192. package/dist/types/errors/validations.d.ts +25 -0
  193. package/dist/types/errors/validations.d.ts.map +1 -0
  194. package/dist/types/filter/FilterTree.d.ts +56 -0
  195. package/dist/types/filter/FilterTree.d.ts.map +1 -0
  196. package/dist/types/filter/WithFilter.d.ts +470 -0
  197. package/dist/types/filter/WithFilter.d.ts.map +1 -0
  198. package/dist/types/filter/filterBuilder.d.ts +105 -0
  199. package/dist/types/filter/filterBuilder.d.ts.map +1 -0
  200. package/dist/types/filter/filterMixin.d.ts +61 -0
  201. package/dist/types/filter/filterMixin.d.ts.map +1 -0
  202. package/dist/types/filter/index.d.ts +8 -0
  203. package/dist/types/filter/index.d.ts.map +1 -0
  204. package/dist/types/index.d.ts +13 -0
  205. package/dist/types/index.d.ts.map +1 -0
  206. package/dist/types/sort/sortMixin.d.ts +46 -0
  207. package/dist/types/sort/sortMixin.d.ts.map +1 -0
  208. package/dist/types/types/api.d.ts +36 -0
  209. package/dist/types/types/api.d.ts.map +1 -0
  210. package/dist/types/types/data-item-types.d.ts +1448 -0
  211. package/dist/types/types/data-item-types.d.ts.map +1 -0
  212. package/dist/types/types/error.d.ts +23 -0
  213. package/dist/types/types/error.d.ts.map +1 -0
  214. package/dist/types/types/index.d.ts +4 -0
  215. package/dist/types/types/index.d.ts.map +1 -0
  216. package/dist/types/utils/base64url.d.ts +2 -0
  217. package/dist/types/utils/base64url.d.ts.map +1 -0
  218. package/dist/types/utils/clone.d.ts +2 -0
  219. package/dist/types/utils/clone.d.ts.map +1 -0
  220. package/dist/types/utils/codec.d.ts +3 -0
  221. package/dist/types/utils/codec.d.ts.map +1 -0
  222. package/dist/types/utils/field-key-utils.d.ts +2 -0
  223. package/dist/types/utils/field-key-utils.d.ts.map +1 -0
  224. package/dist/types/utils/index.d.ts +7 -0
  225. package/dist/types/utils/index.d.ts.map +1 -0
  226. package/dist/types/utils/type-utils.d.ts +11 -0
  227. package/dist/types/utils/type-utils.d.ts.map +1 -0
  228. package/package.json +89 -0
@@ -0,0 +1,800 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ exports.__esModule = true;
5
+ exports.WixDataApi = void 0;
6
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
7
+ var _errors = require("../errors");
8
+ var apiTypes = _interopRequireWildcard(require("../types/data-item-types"));
9
+ var _utils = require("../utils");
10
+ var _common = require("./common");
11
+ var _WixDataQueryImpl = require("./impl/WixDataQueryImpl");
12
+ var _WixDataResultImpl = require("./impl/WixDataResultImpl");
13
+ var _WixDataAggregateImpl = require("./impl/WixDataAggregateImpl");
14
+ var _ApiClient = require("./ApiClient");
15
+ var _errors2 = require("./errors");
16
+ var _WixDataPatch = require("./WixDataPatch");
17
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
18
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
+ class WixDataApi {
20
+ constructor(clientFactory, allowGet, environment, gridAppId, tracer) {
21
+ this.environment = environment;
22
+ this.gridAppId = gridAppId;
23
+ this.tracer = tracer;
24
+ (0, _defineProperty2.default)(this, "client", void 0);
25
+ // NOTE sort method for builder is not implemented
26
+ (0, _defineProperty2.default)(this, "truncate", withArgs(async (args, collectionName, options) => {
27
+ await (0, _errors.apiValidator)().arity('truncate', args, 1, 2).collectionName(collectionName).options(options).validateAndReject();
28
+ return this.trace('truncate', {
29
+ collectionName
30
+ })(async env => {
31
+ await this.client.truncateDataItems({
32
+ ...env,
33
+ dataCollectionId: collectionName,
34
+ ...toOptions(options)
35
+ });
36
+ });
37
+ }));
38
+ // --- single-item methods ---
39
+ (0, _defineProperty2.default)(this, "get", withArgs(async (args, collectionName, itemId, options) => {
40
+ await (0, _errors.apiValidator)().arity('get', args, 2, 3).collectionName(collectionName).itemId(itemId).options(options).validateAndReject();
41
+ return this.trace('get', {
42
+ collectionName,
43
+ itemId
44
+ })(async env => {
45
+ const {
46
+ dataItem
47
+ } = await this.client.getDataItem({
48
+ ...env,
49
+ dataCollectionId: collectionName,
50
+ dataItemId: itemId,
51
+ ...toReadOptions(options),
52
+ fields: options == null ? void 0 : options.fields
53
+ }).catch(recover(_errors.codes.ItemDoesNotExist, {}));
54
+ return dataItem ? toDataItem(dataItem) : null;
55
+ });
56
+ }));
57
+ (0, _defineProperty2.default)(this, "insert", withArgs(async (args, collectionName, item, options) => {
58
+ await (0, _errors.apiValidator)().arity('insert', args, 2, 3).collectionName(collectionName).item(item, collectionName, false).options(options).validateAndReject();
59
+ warnAboutBrokenFields(item);
60
+ return this.trace('insert', {
61
+ collectionName
62
+ })(async env => {
63
+ const {
64
+ dataItem
65
+ } = await this.client.insertDataItem({
66
+ ...env,
67
+ dataCollectionId: collectionName,
68
+ dataItem: {
69
+ id: item._id,
70
+ data: item
71
+ },
72
+ includeReferencedItems: options == null ? void 0 : options.includeReferences,
73
+ ...toOptions(options)
74
+ });
75
+ return toDataItem(dataItem);
76
+ });
77
+ }));
78
+ (0, _defineProperty2.default)(this, "save", withArgs(async (args, collectionName, item, options) => {
79
+ await (0, _errors.apiValidator)().arity('save', args, 2, 3).collectionName(collectionName).item(item, collectionName, false).options(options).validateAndReject();
80
+ return this.trace('save', {
81
+ collectionName
82
+ })(async env => {
83
+ const {
84
+ dataItem
85
+ } = await this.client.saveDataItem({
86
+ ...env,
87
+ dataCollectionId: collectionName,
88
+ dataItem: {
89
+ id: item._id,
90
+ data: item
91
+ },
92
+ ...toOptions(options),
93
+ includeReferencedItems: options == null ? void 0 : options.includeReferences
94
+ });
95
+ return toDataItem(dataItem);
96
+ });
97
+ }));
98
+ (0, _defineProperty2.default)(this, "update", withArgs(async (args, collectionName, item, options) => {
99
+ await (0, _errors.apiValidator)().arity('update', args, 2, 3).collectionName(collectionName).item(item, collectionName, false).options(options).validateAndReject();
100
+ return this.trace('update', {
101
+ collectionName
102
+ })(async env => {
103
+ const {
104
+ dataItem
105
+ } = await this.client.updateDataItem({
106
+ ...env,
107
+ dataCollectionId: collectionName,
108
+ dataItem: {
109
+ id: item._id,
110
+ data: item
111
+ },
112
+ ...toOptions(options),
113
+ includeReferencedItems: options == null ? void 0 : options.includeReferences
114
+ });
115
+ return toDataItem(dataItem);
116
+ });
117
+ }));
118
+ (0, _defineProperty2.default)(this, "remove", withArgs(async (args, collectionName, itemId, options) => {
119
+ await (0, _errors.apiValidator)().arity('remove', args, 2, 3).collectionName(collectionName).itemId(itemId).options(options).validateAndReject();
120
+ return this.trace('remove', {
121
+ collectionName,
122
+ itemId
123
+ })(async env => {
124
+ const {
125
+ dataItem
126
+ } = await this.client.removeDataItem({
127
+ ...env,
128
+ dataCollectionId: collectionName,
129
+ dataItemId: itemId,
130
+ ...toOptions(options)
131
+ }).catch(recover(_errors.codes.ItemDoesNotExist, {}));
132
+ return dataItem ? toDataItem(dataItem) : null;
133
+ });
134
+ }));
135
+ (0, _defineProperty2.default)(this, "toFieldUpdateApi", fieldUpdate => {
136
+ switch (fieldUpdate.action) {
137
+ case 'SET_FIELD':
138
+ return {
139
+ action: apiTypes.ACTION.SET_FIELD,
140
+ fieldPath: fieldUpdate.fieldPath,
141
+ setField: {
142
+ value: fieldUpdate.actionOptions
143
+ }
144
+ };
145
+ case 'REMOVE_FIELD':
146
+ return {
147
+ action: apiTypes.ACTION.REMOVE_FIELD,
148
+ fieldPath: fieldUpdate.fieldPath
149
+ };
150
+ case 'INCREMENT_FIELD':
151
+ return {
152
+ action: apiTypes.ACTION.INCREMENT_FIELD,
153
+ fieldPath: fieldUpdate.fieldPath,
154
+ incrementField: {
155
+ value: fieldUpdate.actionOptions
156
+ }
157
+ };
158
+ case 'APPEND_TO_ARRAY':
159
+ return {
160
+ action: apiTypes.ACTION.APPEND_TO_ARRAY,
161
+ fieldPath: fieldUpdate.fieldPath,
162
+ appendToArray: {
163
+ value: fieldUpdate.actionOptions
164
+ }
165
+ };
166
+ case 'REMOVE_FROM_ARRAY':
167
+ return {
168
+ action: apiTypes.ACTION.REMOVE_FROM_ARRAY,
169
+ fieldPath: fieldUpdate.fieldPath,
170
+ removeFromArray: {
171
+ value: fieldUpdate.actionOptions
172
+ }
173
+ };
174
+ default:
175
+ throw new Error('Invalid patch action');
176
+ }
177
+ });
178
+ (0, _defineProperty2.default)(this, "patch", (collectionName, itemId) => {
179
+ return new _WixDataPatch.WixDataPatch({
180
+ collectionName,
181
+ itemId,
182
+ onRun: async (_args, patchParams, options) => {
183
+ const fieldUpdates = patchParams.fieldUpdates.map(this.toFieldUpdateApi);
184
+ return this.trace('patch', {
185
+ collectionName
186
+ })(async env => {
187
+ const result = await this.client.patchDataItem({
188
+ ...env,
189
+ dataCollectionId: patchParams.collectionName,
190
+ patchSet: {
191
+ dataItemId: patchParams.itemId,
192
+ fieldUpdates
193
+ },
194
+ ...toOptions(options)
195
+ });
196
+ return result.dataItem ? toDataItem(result.dataItem) : null;
197
+ });
198
+ }
199
+ });
200
+ });
201
+ (0, _defineProperty2.default)(this, "bulkPatch", (collectionName, itemIds) => {
202
+ return new _WixDataPatch.WixDataBulkPatch({
203
+ collectionName,
204
+ itemIds,
205
+ onRun: async (_args, patchParams, options) => {
206
+ const fieldUpdates = patchParams.fieldUpdates.map(this.toFieldUpdateApi);
207
+ return this.trace('bulkPatch', {
208
+ collectionName
209
+ })(async env => {
210
+ const {
211
+ results
212
+ } = await this.client.bulkPatchDataItems({
213
+ ...env,
214
+ dataCollectionId: patchParams.collectionName,
215
+ patchSets: patchParams.itemIds.map(itemId => ({
216
+ dataItemId: itemId,
217
+ fieldUpdates
218
+ })),
219
+ ...toOptions(options)
220
+ });
221
+ return toBulkResult(itemIds, results, ['WDE0073']);
222
+ });
223
+ }
224
+ });
225
+ });
226
+ // --- query, count, distinct ---
227
+ (0, _defineProperty2.default)(this, "query", collectionName => {
228
+ const ensureValidQuery = invalidArgs => {
229
+ if (invalidArgs.length > 0) {
230
+ throw (0, _errors.validationError)(_errors.messages.queryValidations.queryInvalid(collectionName, invalidArgs));
231
+ }
232
+ };
233
+ return new _WixDataQueryImpl.WixDataQueryImpl({
234
+ collectionName,
235
+ onCount: async (args, params, options) => {
236
+ ensureValidQuery([...params.invalidArguments, ...(0, _errors.apiValidator)().collectionName(collectionName).arity('count', args, 0, 1).options(options).validateAndReturn()]);
237
+ return this.trace('count', {
238
+ collectionName
239
+ })(async env => {
240
+ const {
241
+ totalCount
242
+ } = await this.client.countDataItems({
243
+ ...env,
244
+ dataCollectionId: collectionName,
245
+ filter: params.filterTree,
246
+ ...toReadOptions(options)
247
+ });
248
+ return totalCount;
249
+ });
250
+ },
251
+ onDistinct: async (args, params, field, options) => {
252
+ var _toSort$find;
253
+ ensureValidQuery([...params.invalidArguments, ...(0, _errors.apiValidator)().collectionName(collectionName).arity('distinct', args, 1, 2).fieldName(field).options(options).validateAndReturn()]);
254
+ const order = (_toSort$find = toSort(params.orderBy).find(o => o.fieldName === field)) == null ? void 0 : _toSort$find.order;
255
+ const fetch = (cursorOrOffset, returnTotalCount) => this.trace('distinct', {
256
+ collectionName,
257
+ field
258
+ })(async env => {
259
+ const {
260
+ distinctValues,
261
+ pagingMetadata
262
+ } = await this.client.queryDistinctValues({
263
+ ...env,
264
+ dataCollectionId: collectionName,
265
+ ...toReadOptions(options),
266
+ ...toPaging(params.limitNumber, cursorOrOffset),
267
+ ...(isOffset(cursorOrOffset) ? {
268
+ fieldName: field,
269
+ filter: params.filterTree,
270
+ order,
271
+ returnTotalCount
272
+ } : {})
273
+ });
274
+ return [distinctValues, pagingMetadata];
275
+ });
276
+ const [items, paging] = await fetch(params.skipNumber, options == null ? void 0 : options.returnTotalCount);
277
+ return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, params);
278
+ },
279
+ onFind: async (args, params, options) => {
280
+ ensureValidQuery([...params.invalidArguments, ...(0, _errors.apiValidator)().collectionName(collectionName).arity('find', args, 0, 1).options(options).validateAndReturn()]);
281
+ const fetch = (cursorOrOffset, returnTotalCount) => this.trace('query', {
282
+ collectionName
283
+ })(async env => {
284
+ const {
285
+ dataItems,
286
+ pagingMetadata
287
+ } = await this.client.queryDataItems({
288
+ ...env,
289
+ dataCollectionId: collectionName,
290
+ query: {
291
+ fields: params.projectedFields,
292
+ ...toPaging(params.limitNumber, cursorOrOffset),
293
+ ...(isOffset(cursorOrOffset) ? {
294
+ filter: params.filterTree,
295
+ sort: toSort(params.orderBy)
296
+ } : {})
297
+ },
298
+ referencedItemOptions: params.included,
299
+ ...toReadOptions(options),
300
+ ...(isOffset(cursorOrOffset) ? {
301
+ returnTotalCount
302
+ } : {})
303
+ });
304
+ return [dataItems.map(toDataItem), pagingMetadata];
305
+ });
306
+ const [items, paging] = await fetch(params.skipNumber, options == null ? void 0 : options.returnTotalCount);
307
+ return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, params);
308
+ }
309
+ });
310
+ });
311
+ // NOTE find method is not implemented
312
+ (0, _defineProperty2.default)(this, "fetch", withArgs(async (args, collectionName, cursor, limit, options) => {
313
+ await (0, _errors.apiValidator)().arity('fetch', args, 2, 4).collectionName(collectionName).isNonEmptyString(cursor, 'cursor').validateAndReject();
314
+ const fetch = cursorOrOffset => this.trace('query', {
315
+ collectionName
316
+ })(async env => {
317
+ const {
318
+ dataItems,
319
+ pagingMetadata
320
+ } = await this.client.queryDataItems({
321
+ ...env,
322
+ dataCollectionId: collectionName,
323
+ query: {
324
+ ...toPaging(limit, cursorOrOffset)
325
+ },
326
+ ...toReadOptions(options)
327
+ });
328
+ return [dataItems.map(toDataItem), pagingMetadata];
329
+ });
330
+ const [items, paging] = await fetch(cursor);
331
+ return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, {
332
+ limitNumber: limit,
333
+ collectionName,
334
+ skipNumber: 0
335
+ });
336
+ }));
337
+ // --- aggregate ---
338
+ (0, _defineProperty2.default)(this, "aggregate", collectionName => {
339
+ return new _WixDataAggregateImpl.WixDataAggregateImpl({
340
+ collectionName,
341
+ onRun: async (args, params, options) => {
342
+ const validationErrors = [...params.invalidArguments, ...(0, _errors.apiValidator)().arity('run', args, 0, 1).collectionName(collectionName).options(options).validateAndReturn()];
343
+ if (validationErrors.length > 0) {
344
+ throw (0, _errors.validationError)(_errors.messages.aggregateValidations.aggregateInvalid(collectionName, validationErrors));
345
+ }
346
+ const fetch = (cursorOrOffset, returnTotalCount) => this.trace('aggregate', {
347
+ collectionName
348
+ })(async env => {
349
+ const toOperation = field => field ? {
350
+ itemFieldName: field
351
+ } : undefined;
352
+ const {
353
+ results,
354
+ pagingMetadata
355
+ } = await this.client.aggregateDataItems({
356
+ ...env,
357
+ dataCollectionId: collectionName,
358
+ ...toPaging(params.limitNumber, cursorOrOffset),
359
+ ...toReadOptions(options),
360
+ ...(isOffset(cursorOrOffset) ? {
361
+ initialFilter: params.filterTree,
362
+ aggregation: {
363
+ groupingFields: params.groupBy,
364
+ operations: params.aggregates.map(a => ({
365
+ resultFieldName: a.name,
366
+ average: toOperation(a.avg),
367
+ min: toOperation(a.min),
368
+ max: toOperation(a.max),
369
+ sum: toOperation(a.sum),
370
+ itemCount: a.count ? {} : undefined
371
+ }))
372
+ },
373
+ finalFilter: params.havingTree,
374
+ sort: toSort(params.orderBy),
375
+ returnTotalCount
376
+ } : {})
377
+ });
378
+ return [unwrapAggregationId(results), pagingMetadata];
379
+ });
380
+ const [items, paging] = await fetch(params.skipNumber, true);
381
+ return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, params);
382
+ }
383
+ });
384
+ });
385
+ (0, _defineProperty2.default)(this, "fetchAggregate", withArgs(async (args, collectionName, cursor, limit, options) => {
386
+ await (0, _errors.apiValidator)().arity('fetchAggregate', args, 2, 4).collectionName(collectionName).isNonEmptyString(cursor, 'cursor').validateAndReject();
387
+ const fetch = cursorOrOffset => this.trace('aggregate', {
388
+ collectionName
389
+ })(async env => {
390
+ const {
391
+ results,
392
+ pagingMetadata
393
+ } = await this.client.aggregateDataItems({
394
+ ...env,
395
+ dataCollectionId: collectionName,
396
+ ...toPaging(limit, cursorOrOffset),
397
+ ...toReadOptions(options)
398
+ });
399
+ return [unwrapAggregationId(results), pagingMetadata];
400
+ });
401
+ const [items, paging] = await fetch(cursor, true);
402
+ return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, {
403
+ limitNumber: limit,
404
+ skipNumber: 0,
405
+ collectionName
406
+ });
407
+ }));
408
+ // --- bulk methods ---
409
+ (0, _defineProperty2.default)(this, "bulkRemove", withArgs(async (args, collectionName, itemIds, options) => {
410
+ await (0, _errors.apiValidator)().arity('bulkRemove', args, 2, 3).collectionName(collectionName).itemIds(itemIds, collectionName).bulkRemoveOptions(options).validateAndReject();
411
+ return this.trace('bulkRemove', {
412
+ collectionName
413
+ })(async env => {
414
+ const {
415
+ results
416
+ } = await this.client.bulkRemoveDataItems({
417
+ ...env,
418
+ dataCollectionId: collectionName,
419
+ dataItemIds: itemIds,
420
+ ...toOptions(options)
421
+ });
422
+ // Non-existing items are skipped and not reported as errors.
423
+ return toBulkResult(itemIds, results, ['WDE0073']);
424
+ });
425
+ }));
426
+ (0, _defineProperty2.default)(this, "bulkInsert", withArgs(async (args, collectionName, items, options) => {
427
+ await (0, _errors.apiValidator)().arity('bulkInsert', args, 2, 3).items(items, collectionName).bulkInsertOptions(options).collectionName(collectionName).validateAndReject();
428
+ return this.trace('bulkInsert', {
429
+ collectionName,
430
+ options
431
+ })(async appId => this.runBulkSave(appId, collectionName, items, options, (options == null ? void 0 : options.overrideExisting) ?? false));
432
+ }));
433
+ (0, _defineProperty2.default)(this, "bulkSave", withArgs(async (args, collectionName, items, options) => {
434
+ await (0, _errors.apiValidator)().arity('bulkSave', args, 2, 3).bulkInsertOptions(options).collectionName(collectionName).items(items, collectionName).validateAndReject();
435
+ return this.trace('bulkSave', {
436
+ collectionName
437
+ })(async env => this.runBulkSave(env, collectionName, items, options));
438
+ }));
439
+ (0, _defineProperty2.default)(this, "bulkUpdate", withArgs(async (args, collectionName, items, options) => {
440
+ await (0, _errors.apiValidator)().arity('bulkUpdate', args, 2, 3).bulkUpdateOptions(options).collectionName(collectionName).items(items, collectionName).validateAndReject();
441
+ return this.trace('bulkUpdate', {
442
+ collectionName
443
+ })(async env => {
444
+ const {
445
+ results
446
+ } = await this.client.bulkUpdateDataItems({
447
+ ...env,
448
+ dataCollectionId: collectionName,
449
+ dataItems: items.map(data => ({
450
+ id: data._id,
451
+ data
452
+ })),
453
+ ...toOptions(options)
454
+ });
455
+ // Non-existing items are skipped and not reported as errors.
456
+ return toBulkResult(items, results, ['WDE0073']);
457
+ });
458
+ }));
459
+ // --- references ---
460
+ (0, _defineProperty2.default)(this, "fetchReferenced", withArgs(async (args, collectionName, cursor, limit, options) => {
461
+ await (0, _errors.apiValidator)().arity('fetchReferenced', args, 2, 4).isNonEmptyString(cursor, 'cursor').collectionName(collectionName).validateAndReject();
462
+ const fetch = current => this.trace('fetchReferenced', {
463
+ collectionName
464
+ })(async env => {
465
+ const {
466
+ results,
467
+ pagingMetadata
468
+ } = await this.client.queryReferencedDataItems({
469
+ ...env,
470
+ ...toPaging(limit, current),
471
+ ...toReadOptions(options),
472
+ dataCollectionId: collectionName,
473
+ fields: options == null ? void 0 : options.fields
474
+ });
475
+ return [onlyReferencedItems(results), pagingMetadata];
476
+ });
477
+ const [items, paging] = await fetch(cursor);
478
+ return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, {
479
+ collectionName,
480
+ limitNumber: limit,
481
+ skipNumber: 0
482
+ });
483
+ }));
484
+ (0, _defineProperty2.default)(this, "queryReferenced", withArgs(async (args, collectionName, holdingItem, relationshipAttribute, options) => {
485
+ await (0, _errors.apiValidator)().arity('queryReferenced', args, 3, 4).collectionName(collectionName).referenceParameter(holdingItem).isNonEmptyString(relationshipAttribute, 'relationshipAttribute').options(options).validateAndReject();
486
+ const id = itemId(holdingItem);
487
+ const fetch = (cursorOrOffset, returnTotalCount) => this.trace('queryReferenced', {
488
+ collectionName,
489
+ itemId: id,
490
+ options,
491
+ relationshipAttribute
492
+ })(async env => {
493
+ const {
494
+ results,
495
+ pagingMetadata
496
+ } = await this.client.queryReferencedDataItems({
497
+ ...env,
498
+ ...toPaging((options == null ? void 0 : options.limit) ?? 50, cursorOrOffset),
499
+ ...toReadOptions(options),
500
+ dataCollectionId: collectionName,
501
+ fields: options == null ? void 0 : options.fields,
502
+ ...(isOffset(cursorOrOffset) ? {
503
+ referringItemId: id,
504
+ referringItemFieldName: relationshipAttribute,
505
+ order: (options == null ? void 0 : options.order) === 'asc' ? apiTypes.SortOrder.ASC : (options == null ? void 0 : options.order) === 'desc' ? apiTypes.SortOrder.DESC : undefined,
506
+ returnTotalCount
507
+ } : {})
508
+ });
509
+ return [onlyReferencedItems(results), pagingMetadata];
510
+ });
511
+ const [items, paging] = await fetch((options == null ? void 0 : options.skip) ?? 0, options == null ? void 0 : options.returnTotalCount);
512
+ return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, {
513
+ collectionName,
514
+ limitNumber: (options == null ? void 0 : options.limit) ?? 50,
515
+ skipNumber: (options == null ? void 0 : options.skip) ?? 0
516
+ });
517
+ }));
518
+ (0, _defineProperty2.default)(this, "insertReference", withArgs(async (args, collectionName, refsOrAttr, leftOrOpts, right, options) => {
519
+ let refs;
520
+ let opts;
521
+ let argc;
522
+ if (typeof refsOrAttr === 'string') {
523
+ const rights = asArray(right);
524
+ refs = rights.map(r => ({
525
+ relationshipName: refsOrAttr,
526
+ left: leftOrOpts,
527
+ right: r
528
+ }));
529
+ opts = options;
530
+ argc = [4, 5];
531
+ } else {
532
+ refs = refsOrAttr;
533
+ opts = leftOrOpts;
534
+ argc = [2, 3];
535
+ }
536
+ await (0, _errors.apiValidator)().arity('insertReference', args, ...argc).collectionName(collectionName).references(refs).options(opts).validateAndReject();
537
+ await this.trace('insertReference', {
538
+ collectionName
539
+ })(async env => this.client.bulkInsertDataItemReferences({
540
+ ...env,
541
+ dataCollectionId: collectionName,
542
+ dataItemReferences: refs.map(r => ({
543
+ referringItemFieldName: r.relationshipName,
544
+ referringItemId: itemId(r.left),
545
+ referencedItemId: itemId(r.right)
546
+ })),
547
+ ...toOptions(opts)
548
+ }));
549
+ }));
550
+ (0, _defineProperty2.default)(this, "replaceReferences", withArgs(async (args, collectionName, relationshipAttribute, left, right, options) => {
551
+ const rights = asArray(right);
552
+ await (0, _errors.apiValidator)().arity('replaceReferences', args, 4, 5).collectionName(collectionName).isNonEmptyString(relationshipAttribute, 'relationshipAttribute').referenceParameter(left).referenceParameters(rights).options(options).validateAndReject();
553
+ await this.trace('replaceReferences', {
554
+ collectionName,
555
+ relationshipAttribute
556
+ })(async env => this.client.replaceDataItemReferences({
557
+ ...env,
558
+ dataCollectionId: collectionName,
559
+ referringItemFieldName: relationshipAttribute,
560
+ referringItemId: itemId(left),
561
+ newReferencedItemIds: rights.map(itemId),
562
+ ...toOptions(options)
563
+ }));
564
+ }));
565
+ (0, _defineProperty2.default)(this, "removeReference", withArgs(async (args, collectionName, relationshipAttribute, left, right, options) => {
566
+ const rights = asArray(right);
567
+ await (0, _errors.apiValidator)().arity('removeReference', args, 4, 5).collectionName(collectionName).referenceParameter(left).referenceRemoveParameters(rights).isNonEmptyString(relationshipAttribute, 'relationshipAttribute').options(options).validateAndReject();
568
+ await this.trace('removeReference', {
569
+ collectionName,
570
+ relationshipAttribute
571
+ })(async env => this.client.bulkRemoveDataItemReferences({
572
+ ...env,
573
+ dataCollectionId: collectionName,
574
+ dataItemReferences: rights.map(r => ({
575
+ referringItemFieldName: relationshipAttribute,
576
+ referringItemId: itemId(left),
577
+ referencedItemId: itemId(r)
578
+ })),
579
+ ...toOptions(options)
580
+ }));
581
+ }));
582
+ (0, _defineProperty2.default)(this, "isReferenced", withArgs(async (args, collectionName, relationshipAttribute, left, right, options) => {
583
+ await (0, _errors.apiValidator)().arity('isReferenced', args, 4, 5).collectionName(collectionName).referenceParameter(left).referenceParameter(right).options(options).validateAndReject();
584
+ return this.trace('isReferenced', {
585
+ collectionName,
586
+ relationshipAttribute
587
+ })(async env => {
588
+ const {
589
+ isReferenced
590
+ } = await this.client.isReferencedDataItem({
591
+ ...env,
592
+ dataCollectionId: collectionName,
593
+ referringItemFieldName: relationshipAttribute,
594
+ referringItemId: itemId(left),
595
+ referencedItemId: itemId(right),
596
+ ...toOptions(options),
597
+ consistentRead: options == null ? void 0 : options.consistentRead
598
+ });
599
+ return isReferenced;
600
+ });
601
+ }));
602
+ this.client = new _ApiClient.ApiClient(clientFactory, allowGet);
603
+ }
604
+ get wixData() {
605
+ return this;
606
+ }
607
+ get filter() {
608
+ return (0, _common.filterBuilder)();
609
+ }
610
+ async runBulkSave(env, collectionName, items, options, overrideExisting = true) {
611
+ const request = {
612
+ ...env,
613
+ dataCollectionId: collectionName,
614
+ dataItems: items.map(data => ({
615
+ id: data._id,
616
+ data
617
+ })),
618
+ ...toOptions(options)
619
+ };
620
+ const {
621
+ results
622
+ } = await (overrideExisting ? this.client.bulkSaveDataItems(request) : this.client.bulkInsertDataItems(request));
623
+ const ignoreCodes = overrideExisting ? [] : ['WDE0074'];
624
+ return toBulkResult(items, results, ignoreCodes);
625
+ }
626
+ trace(action, opts) {
627
+ return async fn => {
628
+ const gridAppId = await get(this.gridAppId);
629
+ const env = {
630
+ appId: gridAppId,
631
+ environment: this.environment
632
+ };
633
+ if (this.tracer) {
634
+ return this.tracer(`WixDataApi.${action}`, {
635
+ ...opts,
636
+ gridAppId,
637
+ environment: this.environment
638
+ })(() => fn(env));
639
+ }
640
+ return fn(env);
641
+ };
642
+ }
643
+ }
644
+ exports.WixDataApi = WixDataApi;
645
+ function withArgs(fn) {
646
+ return function (...args) {
647
+ return fn(arguments, ...args);
648
+ };
649
+ }
650
+ function toOptions(opts) {
651
+ if (!opts) {
652
+ return undefined;
653
+ }
654
+ const res = {
655
+ suppressHooks: opts.suppressHooks,
656
+ appOptions: opts.appOptions,
657
+ ...(opts.showDrafts !== undefined ? {
658
+ publishPluginOptions: {
659
+ includeDraftItems: opts.showDrafts
660
+ }
661
+ } : {})
662
+ };
663
+ if (Object.entries(res).every(kv => kv[1] === undefined)) {
664
+ return undefined;
665
+ }
666
+ return res;
667
+ }
668
+ function toReadOptions(options) {
669
+ return {
670
+ suppressHooks: options == null ? void 0 : options.suppressHooks,
671
+ appOptions: options == null ? void 0 : options.appOptions,
672
+ ...((options == null ? void 0 : options.showDrafts) !== undefined ? {
673
+ publishPluginOptions: {
674
+ includeDraftItems: options == null ? void 0 : options.showDrafts
675
+ }
676
+ } : {}),
677
+ consistentRead: options == null ? void 0 : options.consistentRead,
678
+ language: options == null ? void 0 : options.language
679
+ };
680
+ }
681
+ function toDataItem(item) {
682
+ return item.data;
683
+ }
684
+ function toPaging(limit, cursorOrOffset) {
685
+ return typeof cursorOrOffset === 'string' ? {
686
+ cursorPaging: {
687
+ limit,
688
+ cursor: cursorOrOffset
689
+ }
690
+ } : limit !== undefined || cursorOrOffset > 0 ? {
691
+ paging: {
692
+ limit,
693
+ offset: cursorOrOffset
694
+ }
695
+ } : {};
696
+ }
697
+ function toSort(orderBy) {
698
+ return orderBy.map(fieldOrder => {
699
+ const [[fieldName, sort]] = Object.entries(fieldOrder);
700
+ const order = sort === 'asc' ? apiTypes.SortOrder.ASC : sort === 'desc' ? apiTypes.SortOrder.DESC : undefined;
701
+ return {
702
+ fieldName,
703
+ order
704
+ };
705
+ });
706
+ }
707
+ async function get(providerOrValue) {
708
+ if (typeof (providerOrValue == null ? void 0 : providerOrValue.get) === 'function') {
709
+ return providerOrValue.get();
710
+ }
711
+ return providerOrValue;
712
+ }
713
+ function recover(code, value) {
714
+ return error => {
715
+ if (error instanceof Error && error.code === code) {
716
+ return Promise.resolve(value);
717
+ }
718
+ return Promise.reject(error);
719
+ };
720
+ }
721
+ function warnAboutBrokenFields(item) {
722
+ const hasFieldWithDollar = (0, _utils.hasField)(item, key => key.startsWith('$'));
723
+ const hasFieldWithDot = (0, _utils.hasField)(item, key => key.includes('.'));
724
+ if (hasFieldWithDollar) {
725
+ console.error("Data inserted contains field name prefixed with symbol '$'. It is not recommended to use such field names as it will not work with some data operations.");
726
+ }
727
+ if (hasFieldWithDot) {
728
+ console.warn("Data inserted contains field name containing symbol '.'. It is not recommended to use such field names as it will not work with some data operations.");
729
+ }
730
+ }
731
+ function toBulkResult(request, results, ignoreCodes = []) {
732
+ const errors = results.flatMap(r => {
733
+ var _r$itemMetadata, _r$itemMetadata2;
734
+ if ((_r$itemMetadata = r.itemMetadata) != null && _r$itemMetadata.success || !((_r$itemMetadata2 = r.itemMetadata) != null && _r$itemMetadata2.error)) {
735
+ return [];
736
+ }
737
+ if (ignoreCodes.includes(r.itemMetadata.error.code ?? '')) {
738
+ return [];
739
+ }
740
+ return [new _errors.BulkError(r.itemMetadata.error.description, (0, _errors2.toKnownCode)(r.itemMetadata.error.code), request[r.itemMetadata.originalIndex], 'BulkError', r.itemMetadata.originalIndex)];
741
+ });
742
+ const success = results.filter(r => {
743
+ var _r$itemMetadata3;
744
+ return (_r$itemMetadata3 = r.itemMetadata) == null ? void 0 : _r$itemMetadata3.success;
745
+ });
746
+ const inserted = success.filter(r => r.action === apiTypes.BulkActionType.INSERT);
747
+ const updated = success.filter(r => r.action === apiTypes.BulkActionType.UPDATE || r.action === apiTypes.BulkActionType.PATCH);
748
+ const removed = success.filter(r => r.action === apiTypes.BulkActionType.DELETE);
749
+ return {
750
+ inserted: inserted.length,
751
+ updated: updated.length,
752
+ removed: removed.length,
753
+ skipped: request.length - errors.length - success.length,
754
+ errors,
755
+ insertedItemIds: inserted.map(r => {
756
+ var _r$itemMetadata4;
757
+ return (_r$itemMetadata4 = r.itemMetadata) == null ? void 0 : _r$itemMetadata4.id;
758
+ }),
759
+ updatedItemIds: updated.map(r => {
760
+ var _r$itemMetadata5;
761
+ return (_r$itemMetadata5 = r.itemMetadata) == null ? void 0 : _r$itemMetadata5.id;
762
+ }),
763
+ removedItemIds: removed.map(r => {
764
+ var _r$itemMetadata6;
765
+ return (_r$itemMetadata6 = r.itemMetadata) == null ? void 0 : _r$itemMetadata6.id;
766
+ })
767
+ };
768
+ }
769
+ function unwrapAggregationId(items) {
770
+ // When grouping by one field WixDataService returns value on _id field directly, DataItemService wraps it in an object, i.e.
771
+ // grouping by surname returns {_id: 'Simpson'} in WixDataService vs {_id: {surname: 'Simpson'}} in DataItemService
772
+ // When grouping by more fields, values are kept wrapped.
773
+ return items.map(item => {
774
+ const id = item._id;
775
+ if ((0, _utils.isObject)(id)) {
776
+ const [key, ...rest] = Object.keys(id);
777
+ if (rest.length === 0) {
778
+ item._id = id[key];
779
+ return item;
780
+ }
781
+ }
782
+ return item;
783
+ });
784
+ }
785
+ function onlyReferencedItems(results) {
786
+ return results.map(result => result.dataItem).filter(notEmpty).map(toDataItem);
787
+ }
788
+ function notEmpty(value) {
789
+ return value != null;
790
+ }
791
+ function itemId(item) {
792
+ return typeof item === 'string' ? item : item._id;
793
+ }
794
+ function asArray(xOrXs) {
795
+ return (0, _utils.isArray)(xOrXs) ? xOrXs : [xOrXs];
796
+ }
797
+ function isOffset(cursorOrOffset) {
798
+ return typeof cursorOrOffset === 'number';
799
+ }
800
+ //# sourceMappingURL=WixDataApi.js.map