@webiny/db-dynamodb 5.33.5-beta.0 → 5.34.0-beta.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.
- package/BatchProcess.js +4 -6
- package/BatchProcess.js.map +1 -1
- package/DynamoDbDriver.js +10 -8
- package/DynamoDbDriver.js.map +1 -1
- package/QueryGenerator.js +3 -7
- package/QueryGenerator.js.map +1 -1
- package/index.js +1 -1
- package/operators/index.js +1 -1
- package/package.json +13 -13
- package/plugins/definitions/AttributePlugin.js +1 -1
- package/plugins/definitions/DateTimeTransformPlugin.js +3 -7
- package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/FieldPathPlugin.js +4 -6
- package/plugins/definitions/FieldPathPlugin.js.map +1 -1
- package/plugins/definitions/FieldPlugin.js +1 -1
- package/plugins/definitions/NumberTransformPlugin.js +3 -7
- package/plugins/definitions/NumberTransformPlugin.js.map +1 -1
- package/plugins/definitions/TimeTransformPlugin.js +3 -7
- package/plugins/definitions/TimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/ValueFilterPlugin.js +1 -1
- package/plugins/definitions/ValueTransformPlugin.js +4 -6
- package/plugins/definitions/ValueTransformPlugin.js.map +1 -1
- package/plugins/definitions/assignFields.js +1 -1
- package/plugins/filters/andIn.d.ts +2 -2
- package/plugins/filters/andIn.js +4 -3
- package/plugins/filters/andIn.js.map +1 -1
- package/plugins/filters/between.d.ts +2 -2
- package/plugins/filters/between.js +4 -3
- package/plugins/filters/between.js.map +1 -1
- package/plugins/filters/contains.d.ts +2 -2
- package/plugins/filters/contains.js +3 -2
- package/plugins/filters/contains.js.map +1 -1
- package/plugins/filters/eq.d.ts +2 -2
- package/plugins/filters/eq.js +3 -2
- package/plugins/filters/eq.js.map +1 -1
- package/plugins/filters/fuzzy.d.ts +2 -2
- package/plugins/filters/fuzzy.js +4 -3
- package/plugins/filters/fuzzy.js.map +1 -1
- package/plugins/filters/gt.d.ts +2 -2
- package/plugins/filters/gt.js +3 -2
- package/plugins/filters/gt.js.map +1 -1
- package/plugins/filters/gte.d.ts +2 -2
- package/plugins/filters/gte.js +3 -2
- package/plugins/filters/gte.js.map +1 -1
- package/plugins/filters/in.d.ts +2 -2
- package/plugins/filters/in.js +4 -3
- package/plugins/filters/in.js.map +1 -1
- package/plugins/filters/index.js +1 -1
- package/plugins/filters/lt.d.ts +2 -2
- package/plugins/filters/lt.js +3 -2
- package/plugins/filters/lt.js.map +1 -1
- package/plugins/filters/lte.d.ts +2 -2
- package/plugins/filters/lte.js +3 -2
- package/plugins/filters/lte.js.map +1 -1
- package/plugins/filters/startsWith.d.ts +2 -2
- package/plugins/filters/startsWith.js +3 -2
- package/plugins/filters/startsWith.js.map +1 -1
- package/plugins/index.js +1 -1
- package/statements/createKeyConditionExpressionArgs.js +1 -1
- package/statements/processStatement.js +1 -1
- package/utils/attributes.js +3 -7
- package/utils/attributes.js.map +1 -1
- package/utils/batchRead.js +1 -1
- package/utils/batchWrite.js +1 -1
- package/utils/cleanup.js +3 -8
- package/utils/cleanup.js.map +1 -1
- package/utils/filter.js +1 -1
- package/utils/query.js +5 -9
- package/utils/query.js.map +1 -1
- package/utils/sort.js +1 -1
- package/utils/table.js +1 -1
package/utils/query.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.queryOne = exports.queryAll = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
13
|
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
-
|
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
-
|
|
18
14
|
/**
|
|
19
15
|
* Will run query only once. Pass the previous to run the query again to fetch new data.
|
|
20
16
|
* It returns the result and the items it found.
|
|
@@ -85,8 +81,8 @@ const query = async params => {
|
|
|
85
81
|
const queryOne = async params => {
|
|
86
82
|
const {
|
|
87
83
|
items
|
|
88
|
-
} = await query(
|
|
89
|
-
options:
|
|
84
|
+
} = await query((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
85
|
+
options: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params.options || {}), {}, {
|
|
90
86
|
limit: 1
|
|
91
87
|
})
|
|
92
88
|
}));
|
|
@@ -105,7 +101,7 @@ const queryAll = async params => {
|
|
|
105
101
|
let results;
|
|
106
102
|
let previousResult = undefined;
|
|
107
103
|
|
|
108
|
-
while (results = await query(
|
|
104
|
+
while (results = await query((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
109
105
|
previous: previousResult
|
|
110
106
|
}))) {
|
|
111
107
|
items.push(...results.items);
|
package/utils/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["query","params","entity","previous","partitionKey","options","result","next","items","Items","Array","isArray","WebinyError","queryOne","limit","item","shift","queryAll","results","previousResult","undefined","push"],"sources":["query.ts"],"sourcesContent":["import { queryOptions as DynamoDBToolboxQueryOptions } from \"dynamodb-toolbox/dist/classes/Table\";\nimport WebinyError from \"@webiny/error\";\nimport { Entity } from \"dynamodb-toolbox\";\n\nexport interface QueryAllParams {\n entity: Entity<any>;\n partitionKey: string;\n options?: DynamoDBToolboxQueryOptions;\n}\n\nexport interface QueryOneParams extends QueryAllParams {\n options?: Omit<DynamoDBToolboxQueryOptions, \"limit\">;\n}\n\nexport interface QueryParams extends QueryAllParams {\n previous?: any;\n}\n\nexport interface QueryResult<T> {\n result: any | null;\n items: T[];\n}\n\nexport type DbItem<T> = T & {\n PK: string;\n SK: string;\n TYPE: string;\n GSI1_PK?: string;\n GSI1_SK?: string;\n};\n\n/**\n * Will run query only once. Pass the previous to run the query again to fetch new data.\n * It returns the result and the items it found.\n * Result is required to fetch the items that were not fetched in the previous run.\n */\nconst query = async <T>(params: QueryParams): Promise<QueryResult<T>> => {\n const { entity, previous, partitionKey, options } = params;\n let result;\n /**\n * In case there is no previous result we must make a new query.\n * This is the first query on the given partition key.\n */\n if (!previous) {\n result = await entity.query(partitionKey, options);\n } else if (typeof previous.next === \"function\") {\n /**\n * In case we have a previous result and it has a next method, we run it.\n * In case result of the next method is false, it means it has nothing else to read\n * and we return a null to keep the query from repeating.\n */\n result = await previous.next();\n if (result === false) {\n return {\n result: null,\n items: []\n };\n }\n } else {\n /**\n * This could probably never happen but keep it here just in case to break the query loop.\n * Basically, either previous does not exist or it exists and it does not have the next method\n * and at that point a result returned will be null and loop should not start again.\n */\n return {\n result: null,\n items: []\n };\n }\n /**\n * We expect the result to contain an Items array and if not, something went wrong, very wrong.\n */\n if (!result || !result.Items || !Array.isArray(result.Items)) {\n throw new WebinyError(\n \"Error when querying for content entries - no result.\",\n \"QUERY_ERROR\",\n {\n partitionKey,\n options\n }\n );\n }\n return {\n result,\n items: result.Items\n };\n};\n/**\n * Will run the query to fetch the first possible item from the database.\n */\nexport const queryOne = async <T>(params: QueryOneParams): Promise<DbItem<T> | null> => {\n const { items } = await query<DbItem<T>>({\n ...params,\n options: {\n ...(params.options || {}),\n limit: 1\n }\n });\n const item = items.shift();\n return item ? item : null;\n};\n/**\n * Will run the query to fetch the results no matter how much iterations it needs to go through.\n */\nexport const queryAll = async <T>(params: QueryAllParams): Promise<DbItem<T>[]> => {\n const items: DbItem<T>[] = [];\n let results: QueryResult<DbItem<T>>;\n let previousResult: any = undefined;\n while ((results = await query({ ...params, previous: previousResult }))) {\n items.push(...results.items);\n if (!results.result) {\n return items;\n }\n previousResult = results.result;\n }\n return items;\n};\n"],"mappings":";;;;;;;;;;;AACA
|
|
1
|
+
{"version":3,"names":["query","params","entity","previous","partitionKey","options","result","next","items","Items","Array","isArray","WebinyError","queryOne","limit","item","shift","queryAll","results","previousResult","undefined","push"],"sources":["query.ts"],"sourcesContent":["import { queryOptions as DynamoDBToolboxQueryOptions } from \"dynamodb-toolbox/dist/classes/Table\";\nimport WebinyError from \"@webiny/error\";\nimport { Entity } from \"dynamodb-toolbox\";\n\nexport interface QueryAllParams {\n entity: Entity<any>;\n partitionKey: string;\n options?: DynamoDBToolboxQueryOptions;\n}\n\nexport interface QueryOneParams extends QueryAllParams {\n options?: Omit<DynamoDBToolboxQueryOptions, \"limit\">;\n}\n\nexport interface QueryParams extends QueryAllParams {\n previous?: any;\n}\n\nexport interface QueryResult<T> {\n result: any | null;\n items: T[];\n}\n\nexport type DbItem<T> = T & {\n PK: string;\n SK: string;\n TYPE: string;\n GSI1_PK?: string;\n GSI1_SK?: string;\n};\n\n/**\n * Will run query only once. Pass the previous to run the query again to fetch new data.\n * It returns the result and the items it found.\n * Result is required to fetch the items that were not fetched in the previous run.\n */\nconst query = async <T>(params: QueryParams): Promise<QueryResult<T>> => {\n const { entity, previous, partitionKey, options } = params;\n let result;\n /**\n * In case there is no previous result we must make a new query.\n * This is the first query on the given partition key.\n */\n if (!previous) {\n result = await entity.query(partitionKey, options);\n } else if (typeof previous.next === \"function\") {\n /**\n * In case we have a previous result and it has a next method, we run it.\n * In case result of the next method is false, it means it has nothing else to read\n * and we return a null to keep the query from repeating.\n */\n result = await previous.next();\n if (result === false) {\n return {\n result: null,\n items: []\n };\n }\n } else {\n /**\n * This could probably never happen but keep it here just in case to break the query loop.\n * Basically, either previous does not exist or it exists and it does not have the next method\n * and at that point a result returned will be null and loop should not start again.\n */\n return {\n result: null,\n items: []\n };\n }\n /**\n * We expect the result to contain an Items array and if not, something went wrong, very wrong.\n */\n if (!result || !result.Items || !Array.isArray(result.Items)) {\n throw new WebinyError(\n \"Error when querying for content entries - no result.\",\n \"QUERY_ERROR\",\n {\n partitionKey,\n options\n }\n );\n }\n return {\n result,\n items: result.Items\n };\n};\n/**\n * Will run the query to fetch the first possible item from the database.\n */\nexport const queryOne = async <T>(params: QueryOneParams): Promise<DbItem<T> | null> => {\n const { items } = await query<DbItem<T>>({\n ...params,\n options: {\n ...(params.options || {}),\n limit: 1\n }\n });\n const item = items.shift();\n return item ? item : null;\n};\n/**\n * Will run the query to fetch the results no matter how much iterations it needs to go through.\n */\nexport const queryAll = async <T>(params: QueryAllParams): Promise<DbItem<T>[]> => {\n const items: DbItem<T>[] = [];\n let results: QueryResult<DbItem<T>>;\n let previousResult: any = undefined;\n while ((results = await query({ ...params, previous: previousResult }))) {\n items.push(...results.items);\n if (!results.result) {\n return items;\n }\n previousResult = results.result;\n }\n return items;\n};\n"],"mappings":";;;;;;;;;;;AACA;;AA8BA;AACA;AACA;AACA;AACA;AACA,MAAMA,KAAK,GAAG,MAAUC,MAAV,IAA2D;EACrE,MAAM;IAAEC,MAAF;IAAUC,QAAV;IAAoBC,YAApB;IAAkCC;EAAlC,IAA8CJ,MAApD;EACA,IAAIK,MAAJ;EACA;AACJ;AACA;AACA;;EACI,IAAI,CAACH,QAAL,EAAe;IACXG,MAAM,GAAG,MAAMJ,MAAM,CAACF,KAAP,CAAaI,YAAb,EAA2BC,OAA3B,CAAf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