@wix/motion-edm-autogen-query-wrapper
Advanced tools
Comparing version 1.0.28 to 1.0.29
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
exports.__esModule = true; | ||
exports.CursorBasedIterator = void 0; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _Iterator = require("./Iterator"); | ||
class CursorBasedIterator extends _Iterator.Iterator { | ||
@@ -39,14 +35,10 @@ constructor({ | ||
} | ||
hasNext() { | ||
return !!this._nextCursor; | ||
} | ||
hasPrev() { | ||
return !!this._prevCursor; | ||
} | ||
} | ||
exports.CursorBasedIterator = CursorBasedIterator; | ||
//# sourceMappingURL=CursorBasedIterator.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
var _wrapWithQueryBuilder = require("./wrapWithQueryBuilder"); | ||
exports.wrapWithQueryBuilder = _wrapWithQueryBuilder.wrapWithQueryBuilder; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
exports.__esModule = true; | ||
exports.Iterator = void 0; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
class Iterator { | ||
@@ -29,19 +26,14 @@ constructor({ | ||
} | ||
get items() { | ||
return this._items; | ||
} | ||
get length() { | ||
return this._items.length; | ||
} | ||
get pageSize() { | ||
return this._limit; | ||
} | ||
get query() { | ||
return this._originQuery; | ||
} | ||
async next() { | ||
@@ -51,7 +43,5 @@ if (!this.hasNext()) { | ||
} | ||
const nextPageIterator = await this._fetchNextPage(); | ||
return nextPageIterator; | ||
} | ||
async prev() { | ||
@@ -61,10 +51,7 @@ if (!this.hasPrev()) { | ||
} | ||
const previousPageIterator = await this._fetchPrevPage(); | ||
return previousPageIterator; | ||
} | ||
} | ||
exports.Iterator = Iterator; | ||
//# sourceMappingURL=Iterator.js.map |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
exports.__esModule = true; | ||
exports.OffsetBasedIterator = void 0; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _Iterator = require("./Iterator"); | ||
class OffsetBasedIterator extends _Iterator.Iterator { | ||
@@ -37,27 +33,21 @@ constructor({ | ||
} | ||
get currentPage() { | ||
return this._limit === 0 ? undefined : Math.floor(this._offset / this._limit); | ||
} | ||
get totalPages() { | ||
return this._tooManyToCount || this._limit === 0 ? undefined : Math.ceil(this._totalCount / this._limit); | ||
} | ||
get totalCount() { | ||
return this._tooManyToCount ? undefined : this._totalCount; | ||
} | ||
hasNext() { | ||
return Boolean(this._limit !== 0 && this.currentPage !== undefined && // currentPage 0 is the first page | ||
return Boolean(this._limit !== 0 && this.currentPage !== undefined && | ||
// currentPage 0 is the first page | ||
this.totalPages !== undefined && this.currentPage < this.totalPages - 1); | ||
} | ||
hasPrev() { | ||
return Boolean(this._limit !== 0 && this.currentPage && this.currentPage > 0); | ||
} | ||
} | ||
exports.OffsetBasedIterator = OffsetBasedIterator; | ||
//# sourceMappingURL=OffsetBasedIterator.js.map |
@@ -5,9 +5,5 @@ "use strict"; | ||
exports.PlatformizedQueryBuilder = void 0; | ||
var _filterBuilder = require("@wix/filter-builder"); | ||
var _lodash = require("lodash"); | ||
var _renameFieldByPaths = require("./renameFieldByPaths"); | ||
// import wrapper from './proto-generated'; | ||
@@ -17,21 +13,19 @@ // The use of SortOrder adds @wix/motion-edm-autogen-query-wrapper into the chunk out of auto-fem for certain edms | ||
// const { SortOrder } = wrapper.wix.common; | ||
var SortOrder; | ||
(function (SortOrder) { | ||
var SortOrder = /*#__PURE__*/function (SortOrder) { | ||
SortOrder[SortOrder["ASC"] = 0] = "ASC"; | ||
SortOrder[SortOrder["DESC"] = 1] = "DESC"; | ||
})(SortOrder || (SortOrder = {})); | ||
return SortOrder; | ||
}(SortOrder || {}); | ||
const WIX_DATA_EMPTY_FILTER = { | ||
$and: [] | ||
}; // This can be removed when the platformized-filter-builder | ||
}; | ||
// This can be removed when the platformized-filter-builder | ||
// will stop producing { $and: [] } for an empty filter | ||
const toScalaCompatibleFilter = filter => (0, _lodash.isEqual)(filter, WIX_DATA_EMPTY_FILTER) ? {} : filter; | ||
class PlatformizedQueryBuilder extends (0, _filterBuilder.filterMixin)() { | ||
constructor(obj) { | ||
super(obj); // We must save transformationPaths on this (without `_` prefix), due to how filterMixin works. | ||
super(obj); | ||
// We must save transformationPaths on this (without `_` prefix), due to how filterMixin works. | ||
// See a more details explanation on PlatformizedQueryMethodWrapper | ||
this.transformationPaths = obj.transformationPaths; | ||
@@ -41,58 +35,45 @@ this.sort = obj.sort || []; | ||
} | ||
eq(field, value) { | ||
return super.eq(this._transformQueryFieldName(field), value); | ||
} | ||
ne(field, value) { | ||
return super.ne(this._transformQueryFieldName(field), value); | ||
} | ||
ge(field, value) { | ||
return super.ge(this._transformQueryFieldName(field), value); | ||
} | ||
gt(field, value) { | ||
return super.gt(this._transformQueryFieldName(field), value); | ||
} | ||
le(field, value) { | ||
return super.le(this._transformQueryFieldName(field), value); | ||
} | ||
lt(field, value) { | ||
return super.lt(this._transformQueryFieldName(field), value); | ||
} | ||
isNotEmpty(field) { | ||
return super.isNotEmpty(this._transformQueryFieldName(field)); | ||
} | ||
isEmpty(field) { | ||
return super.isEmpty(this._transformQueryFieldName(field)); | ||
} | ||
startsWith(field, value) { | ||
return super.startsWith(this._transformQueryFieldName(field), value); | ||
} | ||
endsWith(field, value) { | ||
return super.endsWith(this._transformQueryFieldName(field), value); | ||
} | ||
contains(field, value) { | ||
return super.contains(this._transformQueryFieldName(field), value); | ||
} | ||
hasSome(field, ...values) { | ||
return super.hasSome(this._transformQueryFieldName(field), ...values); | ||
} | ||
hasAll(field, ...values) { | ||
return super.hasAll(this._transformQueryFieldName(field), ...values); | ||
} | ||
between(field, rangeStart, rangeEnd) { | ||
return super.between(this._transformQueryFieldName(field), rangeStart, rangeEnd); | ||
} | ||
/* | ||
@@ -103,11 +84,8 @@ TODO: use the custom in() and exists() implementations from super (PlatformizedFilterBuilder) once it is exposed as a class | ||
in(field, values) { | ||
return this._AndSetOperand('$in', '.in', [this._transformQueryFieldName(field), values]); | ||
} | ||
exists(field, value) { | ||
return this._binaryAnd('$exists', '.exists', [this._transformQueryFieldName(field), value]); | ||
} | ||
ascending(...fieldNames) { | ||
@@ -120,3 +98,2 @@ this.sort.push(...fieldNames.map(fieldName => ({ | ||
} | ||
descending(...fieldNames) { | ||
@@ -129,3 +106,2 @@ this.sort.push(...fieldNames.map(fieldName => ({ | ||
} | ||
skip(offset) { | ||
@@ -135,3 +111,2 @@ this.paging.offset = offset; | ||
} | ||
limit(limit) { | ||
@@ -141,3 +116,2 @@ this.paging.limit = limit; | ||
} | ||
build() { | ||
@@ -150,10 +124,7 @@ return { | ||
} | ||
_transformQueryFieldName(field) { | ||
return (0, _renameFieldByPaths.renameFieldByPaths)(this.transformationPaths, field); | ||
} | ||
} | ||
exports.PlatformizedQueryBuilder = PlatformizedQueryBuilder; | ||
//# sourceMappingURL=PlatformizedQueryBuilder.js.map |
const wrapper = require('../index'); | ||
module.exports = { | ||
@@ -4,0 +3,0 @@ services: wrapper, |
const wrapper = require('../index'); | ||
module.exports = { | ||
@@ -4,0 +3,0 @@ services: wrapper, |
@@ -5,9 +5,5 @@ "use strict"; | ||
exports.renameFieldByPaths = void 0; | ||
var _lodash = require("lodash"); | ||
var _motionEdmAutogenTransformationsCore = require("@wix/motion-edm-autogen-transformations-core"); | ||
const fromCorvidName = _motionEdmAutogenTransformationsCore.corvidEntities.fromCorvidName; | ||
const renameFieldByPaths = (transformationPaths, fieldPath) => { | ||
@@ -17,13 +13,9 @@ if (!(0, _lodash.isString)(fieldPath)) { | ||
} | ||
const transformationPath = (0, _lodash.findKey)(transformationPaths, (_, path) => path === fieldPath || fieldPath.startsWith(`${path}.`)); | ||
if (transformationPath) { | ||
return fieldPath.replace(transformationPath, transformationPaths[transformationPath]); | ||
} | ||
return fieldPath.split('.').map(segment => transformationPaths[segment] || fromCorvidName(segment)).join('.'); | ||
}; | ||
exports.renameFieldByPaths = renameFieldByPaths; | ||
//# sourceMappingURL=renameFieldByPaths.js.map |
@@ -5,26 +5,19 @@ "use strict"; | ||
exports.wrapWithQueryBuilder = exports.PlatformizedQueryMethodWrapper = void 0; | ||
var _CursorBasedIterator = require("./CursorBasedIterator"); | ||
var _OffsetBasedIterator = require("./OffsetBasedIterator"); | ||
var _PlatformizedQueryBuilder = require("./PlatformizedQueryBuilder"); | ||
var _motionEdmAutogenCommon = require("@wix/motion-edm-autogen-common"); | ||
var _motionEdmAutogenTransformationsCore = require("@wix/motion-edm-autogen-transformations-core"); | ||
const _preset$query = _motionEdmAutogenTransformationsCore.preset.query, | ||
ITEMS_RESULT_PROPERTY_NAME = _preset$query.ITEMS_RESULT_PROPERTY_NAME, | ||
PAGING_METADATA_RESULT_PROPERTY_NAME = _preset$query.PAGING_METADATA_RESULT_PROPERTY_NAME; | ||
ITEMS_RESULT_PROPERTY_NAME = _preset$query.ITEMS_RESULT_PROPERTY_NAME, | ||
PAGING_METADATA_RESULT_PROPERTY_NAME = _preset$query.PAGING_METADATA_RESULT_PROPERTY_NAME; | ||
const PagingMethods = _motionEdmAutogenCommon.constants.PagingMethods; | ||
const DEFAULT_LIMIT = 50; | ||
class PlatformizedQueryMethodWrapper extends _PlatformizedQueryBuilder.PlatformizedQueryBuilder { | ||
constructor(obj) { | ||
super(obj); // Private variables cannot be prefixed with '_' here. | ||
super(obj); | ||
// Private variables cannot be prefixed with '_' here. | ||
// That's because the filterMixin used by PlatformizedQueryBuilder copies its properties from "this" | ||
// and passes them to the new instance ctor, that expects names without the '_' prefix. | ||
// Changing this breaks the chaining capability. | ||
this.func = obj.func; | ||
@@ -38,18 +31,14 @@ this.requestTransformer = obj.requestTransformer; | ||
} | ||
async find(options = {}) { | ||
try { | ||
var _pagingMetadata$curso5, _pagingMetadata$curso6, _pagingMetadata$curso7, _pagingMetadata$curso8; | ||
const query = this._buildQuery(); | ||
const request = this.requestTransformer(query, options); | ||
const response = await this.func(request, { ...options, | ||
const response = await this.func(request, { | ||
...options, | ||
...this.builderOptions | ||
}); | ||
const _this$responseTransfo = this.responseTransformer(response), | ||
items = _this$responseTransfo[ITEMS_RESULT_PROPERTY_NAME], | ||
pagingMetadata = _this$responseTransfo[PAGING_METADATA_RESULT_PROPERTY_NAME]; | ||
items = _this$responseTransfo[ITEMS_RESULT_PROPERTY_NAME], | ||
pagingMetadata = _this$responseTransfo[PAGING_METADATA_RESULT_PROPERTY_NAME]; | ||
if (this.pagingMethod === PagingMethods.Offset) { | ||
@@ -67,3 +56,2 @@ return new _OffsetBasedIterator.OffsetBasedIterator({ | ||
} | ||
return new _CursorBasedIterator.CursorBasedIterator({ | ||
@@ -75,3 +63,2 @@ items, | ||
var _pagingMetadata$curso, _pagingMetadata$curso2; | ||
return this._copyWithCursor((_pagingMetadata$curso = pagingMetadata == null ? void 0 : (_pagingMetadata$curso2 = pagingMetadata.cursors) == null ? void 0 : _pagingMetadata$curso2.next) != null ? _pagingMetadata$curso : '').find(options); | ||
@@ -81,3 +68,2 @@ }, | ||
var _pagingMetadata$curso3, _pagingMetadata$curso4; | ||
return this._copyWithCursor((_pagingMetadata$curso3 = pagingMetadata == null ? void 0 : (_pagingMetadata$curso4 = pagingMetadata.cursors) == null ? void 0 : _pagingMetadata$curso4.prev) != null ? _pagingMetadata$curso3 : '').find(options); | ||
@@ -92,19 +78,15 @@ }, | ||
} | ||
skipTo(cursor) { | ||
return this._copyWithCursor(cursor); | ||
} | ||
_copyWithCursor(cursor) { | ||
return new PlatformizedQueryMethodWrapper({ ...this, | ||
return new PlatformizedQueryMethodWrapper({ | ||
...this, | ||
cursor | ||
}); | ||
} | ||
_buildQuery() { | ||
const queryObject = this.build(); | ||
if (this.pagingMethod === PagingMethods.Cursor) { | ||
var _this$builderOptions; | ||
if ((_this$builderOptions = this.builderOptions) != null && _this$builderOptions.cursorWithEmptyFilterAndSort && this.cursor) { | ||
@@ -118,3 +100,2 @@ return { | ||
} | ||
return { | ||
@@ -129,3 +110,2 @@ filter: queryObject.filter, | ||
} | ||
return { | ||
@@ -140,11 +120,8 @@ filter: queryObject.filter, | ||
} | ||
get _pagingOffset() { | ||
return this.paging.offset || 0; | ||
} | ||
get _pagingLimit() { | ||
return this.paging.limit === undefined ? DEFAULT_LIMIT : this.paging.limit; | ||
} | ||
_copyWithOffsetChange(amount) { | ||
@@ -155,19 +132,15 @@ const nextPage = { | ||
}; | ||
return new PlatformizedQueryMethodWrapper({ ...this, | ||
return new PlatformizedQueryMethodWrapper({ | ||
...this, | ||
paging: nextPage | ||
}); | ||
} | ||
_copyWithNextPage() { | ||
return this._copyWithOffsetChange(this._pagingLimit); | ||
} | ||
_copyWithPrevPage() { | ||
return this._copyWithOffsetChange(-this._pagingLimit); | ||
} | ||
} | ||
exports.PlatformizedQueryMethodWrapper = PlatformizedQueryMethodWrapper; | ||
const wrapWithQueryBuilder = ({ | ||
@@ -191,4 +164,3 @@ func, | ||
}); | ||
exports.wrapWithQueryBuilder = wrapWithQueryBuilder; | ||
//# sourceMappingURL=wrapWithQueryBuilder.js.map |
{ | ||
"name": "@wix/motion-edm-autogen-query-wrapper", | ||
"version": "1.0.28", | ||
"version": "1.0.29", | ||
"main": "dist/cjs/index.js", | ||
@@ -38,4 +38,4 @@ "module": "dist/esm/index.js", | ||
"@babel/runtime": "^7.0.0", | ||
"@wix/motion-edm-autogen-common": "1.15.0", | ||
"@wix/motion-edm-autogen-transformations-core": "1.17.0", | ||
"@wix/motion-edm-autogen-common": "1.16.0", | ||
"@wix/motion-edm-autogen-transformations-core": "1.18.0", | ||
"@wix/filter-builder": "^1.0.20", | ||
@@ -48,3 +48,3 @@ "lodash": "~4.17.0", | ||
"@types/jest": "^26.0.15", | ||
"@wix/cloud-edm-autogen-test-service": "~1.0.186", | ||
"@wix/cloud-edm-autogen-test-service": "~1.0.187", | ||
"@wix/jest-yoshi-preset": "^5.162.14", | ||
@@ -72,3 +72,3 @@ "@wix/motion-runtime-test-context": "~1.0.0", | ||
}, | ||
"falconPackageHash": "b863c8b9ffc0ce34eb92493c61551f10405f2e7db5cefd93c24b9d85" | ||
"falconPackageHash": "1fd757e9c06980f72b05c63690a29af0021afea481e29f9865573b99" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
4449843
39445
+ Added@wix/motion-edm-autogen-common@1.16.0(transitive)
+ Added@wix/motion-edm-autogen-transformations-core@1.18.0(transitive)
+ Added@wix/motion-edm-autogen-types@1.0.8(transitive)
- Removed@wix/motion-edm-autogen-common@1.15.0(transitive)
- Removed@wix/motion-edm-autogen-transformations-core@1.17.0(transitive)
- Removed@wix/motion-edm-autogen-types@1.0.7(transitive)