@webiny/db-dynamodb 5.40.5 → 5.40.6-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/db-dynamodb",
3
- "version": "5.40.5",
3
+ "version": "5.40.6-beta.0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,25 +10,25 @@
10
10
  "author": "Webiny Ltd",
11
11
  "license": "MIT",
12
12
  "dependencies": {
13
- "@webiny/api": "5.40.5",
14
- "@webiny/aws-sdk": "5.40.5",
15
- "@webiny/db": "5.40.5",
16
- "@webiny/error": "5.40.5",
17
- "@webiny/handler-db": "5.40.5",
18
- "@webiny/plugins": "5.40.5",
13
+ "@webiny/api": "5.40.6-beta.0",
14
+ "@webiny/aws-sdk": "5.40.6-beta.0",
15
+ "@webiny/db": "5.40.6-beta.0",
16
+ "@webiny/error": "5.40.6-beta.0",
17
+ "@webiny/handler-db": "5.40.6-beta.0",
18
+ "@webiny/plugins": "5.40.6-beta.0",
19
+ "@webiny/utils": "5.40.6-beta.0",
19
20
  "date-fns": "2.29.3",
20
21
  "dot-prop": "6.0.1",
21
22
  "dynamodb-toolbox": "0.9.2",
22
23
  "fuse.js": "7.0.0",
23
- "is-number": "7.0.0",
24
24
  "lodash": "4.17.21"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@babel/cli": "7.24.1",
28
28
  "@babel/core": "7.24.3",
29
29
  "@types/is-number": "7.0.3",
30
- "@webiny/cli": "5.40.5",
31
- "@webiny/project-utils": "5.40.5",
30
+ "@webiny/cli": "5.40.6-beta.0",
31
+ "@webiny/project-utils": "5.40.6-beta.0",
32
32
  "jest": "29.7.0",
33
33
  "jest-dynalite": "3.6.1",
34
34
  "rimraf": "5.0.5",
@@ -43,5 +43,5 @@
43
43
  "build": "yarn webiny run build",
44
44
  "watch": "yarn webiny run watch"
45
45
  },
46
- "gitHead": "f67778732392ed88f28da869ddacbf08a98cdec6"
46
+ "gitHead": "c0bf7d9bfe72b0689b29c84506f3168515a78517"
47
47
  }
@@ -7,20 +7,21 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.TimeTransformPlugin = void 0;
8
8
  var _ValueTransformPlugin = require("./ValueTransformPlugin");
9
9
  var _error = _interopRequireDefault(require("@webiny/error"));
10
- var _isNumber = _interopRequireDefault(require("is-number"));
11
10
  const transformTime = params => {
12
11
  const {
13
12
  value
14
13
  } = params;
15
14
  if (value === undefined || value === null) {
16
- throw new _error.default(`Time value is null or undefined`, "TIME_PARSE_ERROR", {
15
+ throw new _error.default(`Time value is null or undefined.`, "TIME_PARSE_ERROR", {
16
+ value
17
+ });
18
+ } else if (typeof value === "boolean" || value === "" || Array.isArray(value)) {
19
+ throw new _error.default("Field value must be a string because field is defined as time.", "TIME_PARSE_ERROR", {
17
20
  value
18
21
  });
19
22
  }
20
- /**
21
- * Due to some internal JS stuff, we must check for a number like this.
22
- */
23
- if (typeof value === "number" || (0, _isNumber.default)(value) === true) {
23
+ const converted = Number(`${value}`);
24
+ if (typeof value === "number" || isNaN(converted) === false) {
24
25
  return Number(value);
25
26
  } else if (typeof value !== "string") {
26
27
  throw new _error.default("Field value must be a string because field is defined as time.", "TIME_PARSE_ERROR", {
@@ -1 +1 @@
1
- {"version":3,"names":["_ValueTransformPlugin","require","_error","_interopRequireDefault","_isNumber","transformTime","params","value","undefined","WebinyError","isNumber","Number","time","milliseconds","split","values","map","length","hours","minutes","seconds","TimeTransformPlugin","ValueTransformPlugin","constructor","transform","exports"],"sources":["TimeTransformPlugin.ts"],"sourcesContent":["import {\n ValueTransformPlugin,\n ValueTransformPluginParams,\n ValueTransformPluginParamsTransformParams\n} from \"./ValueTransformPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport isNumber from \"is-number\";\n\nconst transformTime = (params: ValueTransformPluginParamsTransformParams): number => {\n const { value } = params;\n if (value === undefined || value === null) {\n throw new WebinyError(`Time value is null or undefined`, \"TIME_PARSE_ERROR\", {\n value\n });\n }\n /**\n * Due to some internal JS stuff, we must check for a number like this.\n */\n if (typeof value === \"number\" || isNumber(value) === true) {\n return Number(value);\n } else if (typeof value !== \"string\") {\n throw new WebinyError(\n \"Field value must be a string because field is defined as time.\",\n \"TIME_PARSE_ERROR\",\n {\n value\n }\n );\n }\n /**\n * This is for the time format, eg. 12:36:25 or 12:36:25.881\n */\n const [time, milliseconds = 0] = value.split(\".\");\n const values = time.split(\":\").map(Number);\n if (values.length < 2) {\n throw new WebinyError(\"Time must contain at least hours and minutes.\", \"TIME_PARSE_ERROR\", {\n value\n });\n }\n const [hours, minutes, seconds = 0] = values;\n return (hours * 60 * 60 + minutes * 60 + seconds) * 1000 + Number(milliseconds);\n};\n\nexport class TimeTransformPlugin extends ValueTransformPlugin {\n public constructor(params: Omit<ValueTransformPluginParams, \"transform\">) {\n super({\n transform: transformTime,\n ...params\n });\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,qBAAA,GAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,SAAA,GAAAD,sBAAA,CAAAF,OAAA;AAEA,MAAMI,aAAa,GAAIC,MAAiD,IAAa;EACjF,MAAM;IAAEC;EAAM,CAAC,GAAGD,MAAM;EACxB,IAAIC,KAAK,KAAKC,SAAS,IAAID,KAAK,KAAK,IAAI,EAAE;IACvC,MAAM,IAAIE,cAAW,CAAE,iCAAgC,EAAE,kBAAkB,EAAE;MACzEF;IACJ,CAAC,CAAC;EACN;EACA;AACJ;AACA;EACI,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAI,IAAAG,iBAAQ,EAACH,KAAK,CAAC,KAAK,IAAI,EAAE;IACvD,OAAOI,MAAM,CAACJ,KAAK,CAAC;EACxB,CAAC,MAAM,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAClC,MAAM,IAAIE,cAAW,CACjB,gEAAgE,EAChE,kBAAkB,EAClB;MACIF;IACJ,CACJ,CAAC;EACL;EACA;AACJ;AACA;EACI,MAAM,CAACK,IAAI,EAAEC,YAAY,GAAG,CAAC,CAAC,GAAGN,KAAK,CAACO,KAAK,CAAC,GAAG,CAAC;EACjD,MAAMC,MAAM,GAAGH,IAAI,CAACE,KAAK,CAAC,GAAG,CAAC,CAACE,GAAG,CAACL,MAAM,CAAC;EAC1C,IAAII,MAAM,CAACE,MAAM,GAAG,CAAC,EAAE;IACnB,MAAM,IAAIR,cAAW,CAAC,+CAA+C,EAAE,kBAAkB,EAAE;MACvFF;IACJ,CAAC,CAAC;EACN;EACA,MAAM,CAACW,KAAK,EAAEC,OAAO,EAAEC,OAAO,GAAG,CAAC,CAAC,GAAGL,MAAM;EAC5C,OAAO,CAACG,KAAK,GAAG,EAAE,GAAG,EAAE,GAAGC,OAAO,GAAG,EAAE,GAAGC,OAAO,IAAI,IAAI,GAAGT,MAAM,CAACE,YAAY,CAAC;AACnF,CAAC;AAEM,MAAMQ,mBAAmB,SAASC,0CAAoB,CAAC;EACnDC,WAAWA,CAACjB,MAAqD,EAAE;IACtE,KAAK,CAAC;MACFkB,SAAS,EAAEnB,aAAa;MACxB,GAAGC;IACP,CAAC,CAAC;EACN;AACJ;AAACmB,OAAA,CAAAJ,mBAAA,GAAAA,mBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_ValueTransformPlugin","require","_error","_interopRequireDefault","transformTime","params","value","undefined","WebinyError","Array","isArray","converted","Number","isNaN","time","milliseconds","split","values","map","length","hours","minutes","seconds","TimeTransformPlugin","ValueTransformPlugin","constructor","transform","exports"],"sources":["TimeTransformPlugin.ts"],"sourcesContent":["import {\n ValueTransformPlugin,\n ValueTransformPluginParams,\n ValueTransformPluginParamsTransformParams\n} from \"./ValueTransformPlugin\";\nimport WebinyError from \"@webiny/error\";\n\nconst transformTime = (params: ValueTransformPluginParamsTransformParams): number => {\n const { value } = params;\n if (value === undefined || value === null) {\n throw new WebinyError(`Time value is null or undefined.`, \"TIME_PARSE_ERROR\", {\n value\n });\n } else if (typeof value === \"boolean\" || value === \"\" || Array.isArray(value)) {\n throw new WebinyError(\n \"Field value must be a string because field is defined as time.\",\n \"TIME_PARSE_ERROR\",\n {\n value\n }\n );\n }\n const converted = Number(`${value}`);\n if (typeof value === \"number\" || isNaN(converted) === false) {\n return Number(value);\n } else if (typeof value !== \"string\") {\n throw new WebinyError(\n \"Field value must be a string because field is defined as time.\",\n \"TIME_PARSE_ERROR\",\n {\n value\n }\n );\n }\n /**\n * This is for the time format, eg. 12:36:25 or 12:36:25.881\n */\n const [time, milliseconds = 0] = value.split(\".\");\n const values = time.split(\":\").map(Number);\n if (values.length < 2) {\n throw new WebinyError(\"Time must contain at least hours and minutes.\", \"TIME_PARSE_ERROR\", {\n value\n });\n }\n const [hours, minutes, seconds = 0] = values;\n return (hours * 60 * 60 + minutes * 60 + seconds) * 1000 + Number(milliseconds);\n};\n\nexport class TimeTransformPlugin extends ValueTransformPlugin {\n public constructor(params: Omit<ValueTransformPluginParams, \"transform\">) {\n super({\n transform: transformTime,\n ...params\n });\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,qBAAA,GAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,MAAMG,aAAa,GAAIC,MAAiD,IAAa;EACjF,MAAM;IAAEC;EAAM,CAAC,GAAGD,MAAM;EACxB,IAAIC,KAAK,KAAKC,SAAS,IAAID,KAAK,KAAK,IAAI,EAAE;IACvC,MAAM,IAAIE,cAAW,CAAE,kCAAiC,EAAE,kBAAkB,EAAE;MAC1EF;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAI,OAAOA,KAAK,KAAK,SAAS,IAAIA,KAAK,KAAK,EAAE,IAAIG,KAAK,CAACC,OAAO,CAACJ,KAAK,CAAC,EAAE;IAC3E,MAAM,IAAIE,cAAW,CACjB,gEAAgE,EAChE,kBAAkB,EAClB;MACIF;IACJ,CACJ,CAAC;EACL;EACA,MAAMK,SAAS,GAAGC,MAAM,CAAE,GAAEN,KAAM,EAAC,CAAC;EACpC,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIO,KAAK,CAACF,SAAS,CAAC,KAAK,KAAK,EAAE;IACzD,OAAOC,MAAM,CAACN,KAAK,CAAC;EACxB,CAAC,MAAM,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAClC,MAAM,IAAIE,cAAW,CACjB,gEAAgE,EAChE,kBAAkB,EAClB;MACIF;IACJ,CACJ,CAAC;EACL;EACA;AACJ;AACA;EACI,MAAM,CAACQ,IAAI,EAAEC,YAAY,GAAG,CAAC,CAAC,GAAGT,KAAK,CAACU,KAAK,CAAC,GAAG,CAAC;EACjD,MAAMC,MAAM,GAAGH,IAAI,CAACE,KAAK,CAAC,GAAG,CAAC,CAACE,GAAG,CAACN,MAAM,CAAC;EAC1C,IAAIK,MAAM,CAACE,MAAM,GAAG,CAAC,EAAE;IACnB,MAAM,IAAIX,cAAW,CAAC,+CAA+C,EAAE,kBAAkB,EAAE;MACvFF;IACJ,CAAC,CAAC;EACN;EACA,MAAM,CAACc,KAAK,EAAEC,OAAO,EAAEC,OAAO,GAAG,CAAC,CAAC,GAAGL,MAAM;EAC5C,OAAO,CAACG,KAAK,GAAG,EAAE,GAAG,EAAE,GAAGC,OAAO,GAAG,EAAE,GAAGC,OAAO,IAAI,IAAI,GAAGV,MAAM,CAACG,YAAY,CAAC;AACnF,CAAC;AAEM,MAAMQ,mBAAmB,SAASC,0CAAoB,CAAC;EACnDC,WAAWA,CAACpB,MAAqD,EAAE;IACtE,KAAK,CAAC;MACFqB,SAAS,EAAEtB,aAAa;MACxB,GAAGC;IACP,CAAC,CAAC;EACN;AACJ;AAACsB,OAAA,CAAAJ,mBAAA,GAAAA,mBAAA","ignoreList":[]}
@@ -20,10 +20,10 @@ const plugin = new _ValueFilterPlugin.ValueFilterPlugin({
20
20
  });
21
21
  } else if (Array.isArray(compareValue) === true) {
22
22
  return compareValue.every(v => {
23
- return value === v;
23
+ return value == v;
24
24
  });
25
25
  }
26
- return value === compareValue;
26
+ return value == compareValue;
27
27
  }
28
28
  });
29
29
  plugin.name = "dynamodb.value.filter.eq";
@@ -1 +1 @@
1
- {"version":3,"names":["_ValueFilterPlugin","require","plugin","ValueFilterPlugin","operation","matches","value","compareValue","Array","isArray","some","v","includes","every","name","_default","exports","default"],"sources":["eq.ts"],"sourcesContent":["import { ValueFilterPlugin } from \"../definitions/ValueFilterPlugin\";\n\nconst plugin = new ValueFilterPlugin({\n operation: \"eq\",\n matches: ({ value, compareValue }) => {\n /**\n * Possibility that either input value or one from the system is array.\n */\n if (Array.isArray(value) === true) {\n return value.some((v: string) => {\n return Array.isArray(compareValue) ? compareValue.includes(v) : compareValue === v;\n });\n } else if (Array.isArray(compareValue) === true) {\n return compareValue.every((v: string) => {\n return value === v;\n });\n }\n return value === compareValue;\n }\n});\n\nplugin.name = \"dynamodb.value.filter.eq\";\n\nexport default plugin;\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAEA,MAAMC,MAAM,GAAG,IAAIC,oCAAiB,CAAC;EACjCC,SAAS,EAAE,IAAI;EACfC,OAAO,EAAEA,CAAC;IAAEC,KAAK;IAAEC;EAAa,CAAC,KAAK;IAClC;AACR;AACA;IACQ,IAAIC,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,KAAK,IAAI,EAAE;MAC/B,OAAOA,KAAK,CAACI,IAAI,CAAEC,CAAS,IAAK;QAC7B,OAAOH,KAAK,CAACC,OAAO,CAACF,YAAY,CAAC,GAAGA,YAAY,CAACK,QAAQ,CAACD,CAAC,CAAC,GAAGJ,YAAY,KAAKI,CAAC;MACtF,CAAC,CAAC;IACN,CAAC,MAAM,IAAIH,KAAK,CAACC,OAAO,CAACF,YAAY,CAAC,KAAK,IAAI,EAAE;MAC7C,OAAOA,YAAY,CAACM,KAAK,CAAEF,CAAS,IAAK;QACrC,OAAOL,KAAK,KAAKK,CAAC;MACtB,CAAC,CAAC;IACN;IACA,OAAOL,KAAK,KAAKC,YAAY;EACjC;AACJ,CAAC,CAAC;AAEFL,MAAM,CAACY,IAAI,GAAG,0BAA0B;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAE1Bf,MAAM","ignoreList":[]}
1
+ {"version":3,"names":["_ValueFilterPlugin","require","plugin","ValueFilterPlugin","operation","matches","value","compareValue","Array","isArray","some","v","includes","every","name","_default","exports","default"],"sources":["eq.ts"],"sourcesContent":["import { ValueFilterPlugin } from \"../definitions/ValueFilterPlugin\";\n\nconst plugin = new ValueFilterPlugin({\n operation: \"eq\",\n matches: ({ value, compareValue }) => {\n /**\n * Possibility that either input value or one from the system is array.\n */\n if (Array.isArray(value) === true) {\n return value.some((v: string) => {\n return Array.isArray(compareValue) ? compareValue.includes(v) : compareValue === v;\n });\n } else if (Array.isArray(compareValue) === true) {\n return compareValue.every((v: string) => {\n return value == v;\n });\n }\n return value == compareValue;\n }\n});\n\nplugin.name = \"dynamodb.value.filter.eq\";\n\nexport default plugin;\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAEA,MAAMC,MAAM,GAAG,IAAIC,oCAAiB,CAAC;EACjCC,SAAS,EAAE,IAAI;EACfC,OAAO,EAAEA,CAAC;IAAEC,KAAK;IAAEC;EAAa,CAAC,KAAK;IAClC;AACR;AACA;IACQ,IAAIC,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,KAAK,IAAI,EAAE;MAC/B,OAAOA,KAAK,CAACI,IAAI,CAAEC,CAAS,IAAK;QAC7B,OAAOH,KAAK,CAACC,OAAO,CAACF,YAAY,CAAC,GAAGA,YAAY,CAACK,QAAQ,CAACD,CAAC,CAAC,GAAGJ,YAAY,KAAKI,CAAC;MACtF,CAAC,CAAC;IACN,CAAC,MAAM,IAAIH,KAAK,CAACC,OAAO,CAACF,YAAY,CAAC,KAAK,IAAI,EAAE;MAC7C,OAAOA,YAAY,CAACM,KAAK,CAAEF,CAAS,IAAK;QACrC,OAAOL,KAAK,IAAIK,CAAC;MACrB,CAAC,CAAC;IACN;IACA,OAAOL,KAAK,IAAIC,YAAY;EAChC;AACJ,CAAC,CAAC;AAEFL,MAAM,CAACY,IAAI,GAAG,0BAA0B;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAE1Bf,MAAM","ignoreList":[]}
package/utils/scan.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ScanInput, ScanOutput } from "@webiny/aws-sdk/client-dynamodb";
2
2
  import { Entity, ScanOptions, Table } from "../toolbox";
3
+ import { ExecuteWithRetryOptions } from "@webiny/utils";
3
4
  export type { ScanOptions };
4
5
  export interface BaseScanParams {
5
6
  options?: ScanOptions;
@@ -31,4 +32,7 @@ export declare type ScanDbItem<T> = T & {
31
32
  TYPE: string;
32
33
  };
33
34
  export declare const scan: <T>(params: ScanParams) => Promise<ScanResponse<T>>;
34
- export declare const scanWithCallback: <T>(params: ScanParams, callback: (result: ScanResponse<ScanDbItem<T>>) => Promise<void | boolean>) => Promise<void>;
35
+ interface ScanWithCallbackOptions {
36
+ retry?: true | ExecuteWithRetryOptions;
37
+ }
38
+ export declare const scanWithCallback: <T>(params: ScanParams, callback: (result: ScanResponse<ScanDbItem<T>>) => Promise<void | boolean>, options?: ScanWithCallbackOptions) => Promise<void>;
package/utils/scan.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.scanWithCallback = exports.scan = void 0;
7
+ var _utils = require("@webiny/utils");
7
8
  const createNext = result => {
8
9
  if (!result?.LastEvaluatedKey || !result.next) {
9
10
  return undefined;
@@ -39,8 +40,18 @@ const scan = async params => {
39
40
  return convertResult(result);
40
41
  };
41
42
  exports.scan = scan;
42
- const scanWithCallback = async (params, callback) => {
43
- let result = await scan(params);
43
+ const scanWithCallback = async (params, callback, options) => {
44
+ // For backwards compatibility, we still allow for executing the scan without retries.
45
+ const usingRetry = Boolean(options?.retry);
46
+ const retryOptions = options?.retry === true ? {} : options?.retry;
47
+ const executeScan = () => scan(params);
48
+ const getInitialResult = () => {
49
+ if (usingRetry) {
50
+ return (0, _utils.executeWithRetry)(executeScan, retryOptions);
51
+ }
52
+ return executeScan();
53
+ };
54
+ let result = await getInitialResult();
44
55
  if (!result.items?.length && !result.lastEvaluatedKey) {
45
56
  return;
46
57
  }
@@ -53,7 +64,14 @@ const scanWithCallback = async (params, callback) => {
53
64
  return;
54
65
  }
55
66
  while (result.next) {
56
- result = await result.next();
67
+ const executeNext = () => result.next();
68
+ const getNextResult = () => {
69
+ if (usingRetry) {
70
+ return (0, _utils.executeWithRetry)(executeNext, retryOptions);
71
+ }
72
+ return executeNext();
73
+ };
74
+ result = await getNextResult();
57
75
 
58
76
  // If the result of the callback was `false`, that means the
59
77
  // user's intention was to stop further table scanning.
package/utils/scan.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["createNext","result","LastEvaluatedKey","next","undefined","response","convertResult","items","Items","count","Count","scannedCount","ScannedCount","lastEvaluatedKey","error","requestId","$response","scan","params","options","table","entity","Error","JSON","stringify","execute","exports","scanWithCallback","callback","length","callbackResult","mustBreak"],"sources":["scan.ts"],"sourcesContent":["import { ScanInput, ScanOutput } from \"@webiny/aws-sdk/client-dynamodb\";\nimport { Entity, ScanOptions, Table } from \"~/toolbox\";\n\nexport type { ScanOptions };\n\nexport interface BaseScanParams {\n options?: ScanOptions;\n params?: Partial<ScanInput>;\n}\n\nexport interface ScanWithTable extends BaseScanParams {\n table: Table<any, any, any>;\n entity?: never;\n}\n\nexport interface ScanWithEntity extends BaseScanParams {\n entity: Entity;\n table?: never;\n}\n\nexport type ScanParams = ScanWithTable | ScanWithEntity;\n\nexport interface ScanResponse<T = any> {\n items: T[];\n count?: number;\n scannedCount?: number;\n lastEvaluatedKey?: ScanOutput[\"LastEvaluatedKey\"];\n next?: () => Promise<ScanResponse<T>>;\n requestId: string;\n error: any;\n}\n\ninterface DdbScanResult<T> {\n Items?: T[];\n Count?: number;\n ScannedCount?: number;\n LastEvaluatedKey?: ScanOutput[\"LastEvaluatedKey\"];\n next?: () => Promise<DdbScanResult<T>>;\n error?: any;\n $response?: {\n requestId: string;\n };\n}\n\ntype NextCb<T> = () => Promise<ScanResponse<T>>;\n\nconst createNext = <T>(result: DdbScanResult<T>): NextCb<T> | undefined => {\n if (!result?.LastEvaluatedKey || !result.next) {\n return undefined;\n }\n return async () => {\n const response = await result!.next!();\n return convertResult(response);\n };\n};\n\nconst convertResult = <T>(result: DdbScanResult<T>): ScanResponse<T> => {\n return {\n items: result.Items || [],\n count: result.Count,\n scannedCount: result.ScannedCount,\n lastEvaluatedKey: result.LastEvaluatedKey || undefined,\n next: createNext<T>(result),\n error: result.error,\n requestId: result.$response?.requestId || \"\"\n };\n};\n\nexport type ScanDbItem<T> = T & {\n PK: string;\n SK: string;\n GSI1_PK: string;\n GSI1_SK: string;\n TYPE: string;\n};\n\nexport const scan = async <T>(params: ScanParams): Promise<ScanResponse<T>> => {\n const { options } = params;\n\n const table = params.table ? params.table : params.entity.table;\n if (!table) {\n throw new Error(`Missing table for scan: ${JSON.stringify(options)}`);\n }\n\n const result = await table.scan(\n {\n ...options,\n execute: true\n },\n params.params\n );\n\n return convertResult(result) as ScanResponse<T>;\n};\n\nexport const scanWithCallback = async <T>(\n params: ScanParams,\n callback: (result: ScanResponse<ScanDbItem<T>>) => Promise<void | boolean>\n): Promise<void> => {\n let result = await scan<ScanDbItem<T>>(params);\n if (!result.items?.length && !result.lastEvaluatedKey) {\n return;\n }\n\n // If the result of the callback was `false`, that means the\n // user's intention was to stop further table scanning.\n const callbackResult = await callback(result);\n const mustBreak = callbackResult === false;\n if (mustBreak) {\n return;\n }\n\n while (result.next) {\n result = await result.next();\n\n // If the result of the callback was `false`, that means the\n // user's intention was to stop further table scanning.\n const callbackResult = await callback(result);\n const mustBreak = callbackResult === false;\n if (mustBreak) {\n break;\n }\n\n if (!result.next) {\n return;\n }\n }\n};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AAAT,IAAA,GAAAA,IAAA;AAEK,MAAMU,gBAAgB,GAAG,MAAAA,CAC5BT,MAAkB,EAClBU,QAA0E,KAC1D;EAChB,IAAI3B,MAAM,GAAG,MAAMgB,IAAI,CAAgBC,MAAM,CAAC;EAC9C,IAAI,CAACjB,MAAM,CAACM,KAAK,EAAEsB,MAAM,IAAI,CAAC5B,MAAM,CAACY,gBAAgB,EAAE;IACnD;EACJ;;EAEA;EACA;EACA,MAAMiB,cAAc,GAAG,MAAMF,QAAQ,CAAC3B,MAAM,CAAC;EAC7C,MAAM8B,SAAS,GAAGD,cAAc,KAAK,KAAK;EAC1C,IAAIC,SAAS,EAAE;IACX;EACJ;EAEA,OAAO9B,MAAM,CAACE,IAAI,EAAE;IAChBF,MAAM,GAAG,MAAMA,MAAM,CAACE,IAAI,CAAC,CAAC;;IAE5B;IACA;IACA,MAAM2B,cAAc,GAAG,MAAMF,QAAQ,CAAC3B,MAAM,CAAC;IAC7C,MAAM8B,SAAS,GAAGD,cAAc,KAAK,KAAK;IAC1C,IAAIC,SAAS,EAAE;MACX;IACJ;IAEA,IAAI,CAAC9B,MAAM,CAACE,IAAI,EAAE;MACd;IACJ;EACJ;AACJ,CAAC;AAACuB,OAAA,CAAAC,gBAAA,GAAAA,gBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_utils","require","createNext","result","LastEvaluatedKey","next","undefined","response","convertResult","items","Items","count","Count","scannedCount","ScannedCount","lastEvaluatedKey","error","requestId","$response","scan","params","options","table","entity","Error","JSON","stringify","execute","exports","scanWithCallback","callback","usingRetry","Boolean","retry","retryOptions","executeScan","getInitialResult","executeWithRetry","length","callbackResult","mustBreak","executeNext","getNextResult"],"sources":["scan.ts"],"sourcesContent":["import { ScanInput, ScanOutput } from \"@webiny/aws-sdk/client-dynamodb\";\nimport { Entity, ScanOptions, Table } from \"~/toolbox\";\nimport { executeWithRetry, ExecuteWithRetryOptions } from \"@webiny/utils\";\n\nexport type { ScanOptions };\n\nexport interface BaseScanParams {\n options?: ScanOptions;\n params?: Partial<ScanInput>;\n}\n\nexport interface ScanWithTable extends BaseScanParams {\n table: Table<any, any, any>;\n entity?: never;\n}\n\nexport interface ScanWithEntity extends BaseScanParams {\n entity: Entity;\n table?: never;\n}\n\nexport type ScanParams = ScanWithTable | ScanWithEntity;\n\nexport interface ScanResponse<T = any> {\n items: T[];\n count?: number;\n scannedCount?: number;\n lastEvaluatedKey?: ScanOutput[\"LastEvaluatedKey\"];\n next?: () => Promise<ScanResponse<T>>;\n requestId: string;\n error: any;\n}\n\ninterface DdbScanResult<T> {\n Items?: T[];\n Count?: number;\n ScannedCount?: number;\n LastEvaluatedKey?: ScanOutput[\"LastEvaluatedKey\"];\n next?: () => Promise<DdbScanResult<T>>;\n error?: any;\n $response?: {\n requestId: string;\n };\n}\n\ntype NextCb<T> = () => Promise<ScanResponse<T>>;\n\nconst createNext = <T>(result: DdbScanResult<T>): NextCb<T> | undefined => {\n if (!result?.LastEvaluatedKey || !result.next) {\n return undefined;\n }\n return async () => {\n const response = await result!.next!();\n return convertResult(response);\n };\n};\n\nconst convertResult = <T>(result: DdbScanResult<T>): ScanResponse<T> => {\n return {\n items: result.Items || [],\n count: result.Count,\n scannedCount: result.ScannedCount,\n lastEvaluatedKey: result.LastEvaluatedKey || undefined,\n next: createNext<T>(result),\n error: result.error,\n requestId: result.$response?.requestId || \"\"\n };\n};\n\nexport type ScanDbItem<T> = T & {\n PK: string;\n SK: string;\n GSI1_PK: string;\n GSI1_SK: string;\n TYPE: string;\n};\n\nexport const scan = async <T>(params: ScanParams): Promise<ScanResponse<T>> => {\n const { options } = params;\n\n const table = params.table ? params.table : params.entity.table;\n if (!table) {\n throw new Error(`Missing table for scan: ${JSON.stringify(options)}`);\n }\n\n const result = await table.scan(\n {\n ...options,\n execute: true\n },\n params.params\n );\n\n return convertResult(result) as ScanResponse<T>;\n};\n\ninterface ScanWithCallbackOptions {\n retry?: true | ExecuteWithRetryOptions;\n}\n\nexport const scanWithCallback = async <T>(\n params: ScanParams,\n callback: (result: ScanResponse<ScanDbItem<T>>) => Promise<void | boolean>,\n options?: ScanWithCallbackOptions\n): Promise<void> => {\n // For backwards compatibility, we still allow for executing the scan without retries.\n const usingRetry = Boolean(options?.retry);\n const retryOptions = options?.retry === true ? {} : options?.retry;\n\n const executeScan = () => scan<ScanDbItem<T>>(params);\n const getInitialResult = () => {\n if (usingRetry) {\n return executeWithRetry(executeScan, retryOptions);\n }\n return executeScan();\n };\n\n let result = await getInitialResult();\n\n if (!result.items?.length && !result.lastEvaluatedKey) {\n return;\n }\n\n // If the result of the callback was `false`, that means the\n // user's intention was to stop further table scanning.\n const callbackResult = await callback(result);\n const mustBreak = callbackResult === false;\n if (mustBreak) {\n return;\n }\n\n while (result.next) {\n const executeNext = () => result.next!();\n const getNextResult = () => {\n if (usingRetry) {\n return executeWithRetry(executeNext, retryOptions);\n }\n return executeNext();\n };\n\n result = await getNextResult();\n\n // If the result of the callback was `false`, that means the\n // user's intention was to stop further table scanning.\n const callbackResult = await callback(result);\n const mustBreak = callbackResult === false;\n if (mustBreak) {\n break;\n }\n\n if (!result.next) {\n return;\n }\n }\n};\n"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AA6CA,MAAMC,UAAU,GAAOC,MAAwB,IAA4B;EACvE,IAAI,CAACA,MAAM,EAAEC,gBAAgB,IAAI,CAACD,MAAM,CAACE,IAAI,EAAE;IAC3C,OAAOC,SAAS;EACpB;EACA,OAAO,YAAY;IACf,MAAMC,QAAQ,GAAG,MAAMJ,MAAM,CAAEE,IAAI,CAAE,CAAC;IACtC,OAAOG,aAAa,CAACD,QAAQ,CAAC;EAClC,CAAC;AACL,CAAC;AAED,MAAMC,aAAa,GAAOL,MAAwB,IAAsB;EACpE,OAAO;IACHM,KAAK,EAAEN,MAAM,CAACO,KAAK,IAAI,EAAE;IACzBC,KAAK,EAAER,MAAM,CAACS,KAAK;IACnBC,YAAY,EAAEV,MAAM,CAACW,YAAY;IACjCC,gBA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C,WAAW,CAAC,CAAC;EACxB,CAAC;EAED,IAAIhC,MAAM,GAAG,MAAMiC,gBAAgB,CAAC,CAAC;EAErC,IAAI,CAACjC,MAAM,CAACM,KAAK,EAAE6B,MAAM,IAAI,CAACnC,MAAM,CAACY,gBAAgB,EAAE;IACnD;EACJ;;EAEA;EACA;EACA,MAAMwB,cAAc,GAAG,MAAMT,QAAQ,CAAC3B,MAAM,CAAC;EAC7C,MAAMqC,SAAS,GAAGD,cAAc,KAAK,KAAK;EAC1C,IAAIC,SAAS,EAAE;IACX;EACJ;EAEA,OAAOrC,MAAM,CAACE,IAAI,EAAE;IAChB,MAAMoC,WAAW,GAAGA,CAAA,KAAMtC,MAAM,CAACE,IAAI,CAAE,CAAC;IACxC,MAAMqC,aAAa,GAAGA,CAAA,KAAM;MACxB,IAAIX,UAAU,EAAE;QACZ,OAAO,IAAAM,uBAAgB,EAACI,WAAW,EAAEP,YAAY,CAAC;MACtD;MACA,OAAOO,WAAW,CAAC,CAAC;IACxB,CAAC;IAEDtC,MAAM,GAAG,MAAMuC,aAAa,CAAC,CAAC;;IAE9B;IACA;IACA,MAAMH,cAAc,GAAG,MAAMT,QAAQ,CAAC3B,MAAM,CAAC;IAC7C,MAAMqC,SAAS,GAAGD,cAAc,KAAK,KAAK;IAC1C,IAAIC,SAAS,EAAE;MACX;IACJ;IAEA,IAAI,CAACrC,MAAM,CAACE,IAAI,EAAE;MACd;IACJ;EACJ;AACJ,CAAC;AAACuB,OAAA,CAAAC,gBAAA,GAAAA,gBAAA","ignoreList":[]}
@@ -1,4 +0,0 @@
1
- import { ValueTransformPlugin, ValueTransformPluginParams } from "./ValueTransformPlugin";
2
- export declare class NumberTransformPlugin extends ValueTransformPlugin {
3
- constructor(params: Omit<ValueTransformPluginParams, "transform">);
4
- }
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.NumberTransformPlugin = void 0;
8
- var _ValueTransformPlugin = require("./ValueTransformPlugin");
9
- var _error = _interopRequireDefault(require("@webiny/error"));
10
- var _isNumber = _interopRequireDefault(require("is-number"));
11
- const transformNumber = params => {
12
- const {
13
- value
14
- } = params;
15
- const typeOf = typeof value;
16
- /**
17
- * Due to some internal JS stuff, we must check for a number like this.
18
- */
19
- if (typeOf === "number" || (0, _isNumber.default)(value) === true) {
20
- return Number(value);
21
- }
22
- throw new _error.default("Field value must be a number because.", "NUMBER_ERROR", {
23
- value
24
- });
25
- };
26
- class NumberTransformPlugin extends _ValueTransformPlugin.ValueTransformPlugin {
27
- constructor(params) {
28
- super({
29
- transform: transformNumber,
30
- ...params
31
- });
32
- }
33
- }
34
- exports.NumberTransformPlugin = NumberTransformPlugin;
35
-
36
- //# sourceMappingURL=NumberTransformPlugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_ValueTransformPlugin","require","_error","_interopRequireDefault","_isNumber","transformNumber","params","value","typeOf","isNumber","Number","WebinyError","NumberTransformPlugin","ValueTransformPlugin","constructor","transform","exports"],"sources":["NumberTransformPlugin.ts"],"sourcesContent":["import {\n ValueTransformPlugin,\n ValueTransformPluginParams,\n ValueTransformPluginParamsTransformParams\n} from \"./ValueTransformPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport isNumber from \"is-number\";\n\nconst transformNumber = (params: ValueTransformPluginParamsTransformParams): number => {\n const { value } = params;\n const typeOf = typeof value;\n /**\n * Due to some internal JS stuff, we must check for a number like this.\n */\n if (typeOf === \"number\" || isNumber(value) === true) {\n return Number(value);\n }\n throw new WebinyError(\"Field value must be a number because.\", \"NUMBER_ERROR\", {\n value\n });\n};\n\nexport class NumberTransformPlugin extends ValueTransformPlugin {\n public constructor(params: Omit<ValueTransformPluginParams, \"transform\">) {\n super({\n transform: transformNumber,\n ...params\n });\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,qBAAA,GAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,SAAA,GAAAD,sBAAA,CAAAF,OAAA;AAEA,MAAMI,eAAe,GAAIC,MAAiD,IAAa;EACnF,MAAM;IAAEC;EAAM,CAAC,GAAGD,MAAM;EACxB,MAAME,MAAM,GAAG,OAAOD,KAAK;EAC3B;AACJ;AACA;EACI,IAAIC,MAAM,KAAK,QAAQ,IAAI,IAAAC,iBAAQ,EAACF,KAAK,CAAC,KAAK,IAAI,EAAE;IACjD,OAAOG,MAAM,CAACH,KAAK,CAAC;EACxB;EACA,MAAM,IAAII,cAAW,CAAC,uCAAuC,EAAE,cAAc,EAAE;IAC3EJ;EACJ,CAAC,CAAC;AACN,CAAC;AAEM,MAAMK,qBAAqB,SAASC,0CAAoB,CAAC;EACrDC,WAAWA,CAACR,MAAqD,EAAE;IACtE,KAAK,CAAC;MACFS,SAAS,EAAEV,eAAe;MAC1B,GAAGC;IACP,CAAC,CAAC;EACN;AACJ;AAACU,OAAA,CAAAJ,qBAAA,GAAAA,qBAAA","ignoreList":[]}