@webiny/db-dynamodb 6.3.0 → 6.4.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.
Files changed (132) hide show
  1. package/DynamoDbDriver.js +204 -209
  2. package/DynamoDbDriver.js.map +1 -1
  3. package/exports/api/db.js +0 -2
  4. package/feature/FilterUtil/FilterUtil.js +18 -20
  5. package/feature/FilterUtil/FilterUtil.js.map +1 -1
  6. package/feature/FilterUtil/abstractions/FilterUtil.js +2 -1
  7. package/feature/FilterUtil/abstractions/FilterUtil.js.map +1 -1
  8. package/feature/FilterUtil/createFilters.js +82 -120
  9. package/feature/FilterUtil/createFilters.js.map +1 -1
  10. package/feature/FilterUtil/extractWhereArgs.js +15 -19
  11. package/feature/FilterUtil/extractWhereArgs.js.map +1 -1
  12. package/feature/FilterUtil/feature.js +6 -5
  13. package/feature/FilterUtil/feature.js.map +1 -1
  14. package/feature/FilterUtil/index.js +0 -2
  15. package/feature/ValueFilter/ValueFilterRegistry.js +21 -17
  16. package/feature/ValueFilter/ValueFilterRegistry.js.map +1 -1
  17. package/feature/ValueFilter/abstractions/ValueFilter.js +2 -1
  18. package/feature/ValueFilter/abstractions/ValueFilter.js.map +1 -1
  19. package/feature/ValueFilter/abstractions/ValueFilterRegistry.js +2 -1
  20. package/feature/ValueFilter/abstractions/ValueFilterRegistry.js.map +1 -1
  21. package/feature/ValueFilter/feature.js +17 -16
  22. package/feature/ValueFilter/feature.js.map +1 -1
  23. package/feature/ValueFilter/filters/AndInFilter.js +19 -23
  24. package/feature/ValueFilter/filters/AndInFilter.js.map +1 -1
  25. package/feature/ValueFilter/filters/BetweenFilter.js +23 -25
  26. package/feature/ValueFilter/filters/BetweenFilter.js.map +1 -1
  27. package/feature/ValueFilter/filters/ContainsFilter.js +34 -53
  28. package/feature/ValueFilter/filters/ContainsFilter.js.map +1 -1
  29. package/feature/ValueFilter/filters/EqFilter.js +17 -27
  30. package/feature/ValueFilter/filters/EqFilter.js.map +1 -1
  31. package/feature/ValueFilter/filters/FuzzyFilter.js +30 -30
  32. package/feature/ValueFilter/filters/FuzzyFilter.js.map +1 -1
  33. package/feature/ValueFilter/filters/GtFilter.js +16 -16
  34. package/feature/ValueFilter/filters/GtFilter.js.map +1 -1
  35. package/feature/ValueFilter/filters/GteFilter.js +16 -16
  36. package/feature/ValueFilter/filters/GteFilter.js.map +1 -1
  37. package/feature/ValueFilter/filters/InFilter.js +19 -23
  38. package/feature/ValueFilter/filters/InFilter.js.map +1 -1
  39. package/feature/ValueFilter/filters/LtFilter.js +16 -16
  40. package/feature/ValueFilter/filters/LtFilter.js.map +1 -1
  41. package/feature/ValueFilter/filters/LteFilter.js +16 -16
  42. package/feature/ValueFilter/filters/LteFilter.js.map +1 -1
  43. package/feature/ValueFilter/filters/StartsWithFilter.js +20 -36
  44. package/feature/ValueFilter/filters/StartsWithFilter.js.map +1 -1
  45. package/feature/ValueFilter/index.js +0 -2
  46. package/index.js +7 -9
  47. package/index.js.map +1 -1
  48. package/package.json +13 -13
  49. package/plugins/definitions/DateTimeTransformPlugin.js +18 -30
  50. package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -1
  51. package/plugins/definitions/FieldPlugin.js +34 -37
  52. package/plugins/definitions/FieldPlugin.js.map +1 -1
  53. package/plugins/definitions/TimeTransformPlugin.js +25 -37
  54. package/plugins/definitions/TimeTransformPlugin.js.map +1 -1
  55. package/plugins/definitions/ValueTransformPlugin.js +18 -17
  56. package/plugins/definitions/ValueTransformPlugin.js.map +1 -1
  57. package/plugins/definitions/assignFields.js +14 -18
  58. package/plugins/definitions/assignFields.js.map +1 -1
  59. package/plugins/index.js +0 -2
  60. package/store/entity.js +6 -9
  61. package/store/entity.js.map +1 -1
  62. package/store/keys.js +6 -13
  63. package/store/keys.js.map +1 -1
  64. package/store/types.js +0 -3
  65. package/toolbox.js +0 -5
  66. package/types.js +0 -3
  67. package/utils/batch/batchRead.js +37 -56
  68. package/utils/batch/batchRead.js.map +1 -1
  69. package/utils/batch/batchWrite.js +33 -51
  70. package/utils/batch/batchWrite.js.map +1 -1
  71. package/utils/batch/index.js +0 -2
  72. package/utils/batch/types.js +0 -3
  73. package/utils/cleanup.js +35 -25
  74. package/utils/cleanup.js.map +1 -1
  75. package/utils/count.js +8 -14
  76. package/utils/count.js.map +1 -1
  77. package/utils/createEntity.d.ts +1 -1
  78. package/utils/createEntity.js +75 -78
  79. package/utils/createEntity.js.map +1 -1
  80. package/utils/createTable.js +25 -35
  81. package/utils/createTable.js.map +1 -1
  82. package/utils/cursor.js +7 -10
  83. package/utils/cursor.js.map +1 -1
  84. package/utils/delete.js +6 -8
  85. package/utils/delete.js.map +1 -1
  86. package/utils/entity/Entity.js +85 -90
  87. package/utils/entity/Entity.js.map +1 -1
  88. package/utils/entity/EntityReadBatch.js +23 -31
  89. package/utils/entity/EntityReadBatch.js.map +1 -1
  90. package/utils/entity/EntityReadBatchBuilder.js +12 -15
  91. package/utils/entity/EntityReadBatchBuilder.js.map +1 -1
  92. package/utils/entity/EntityWriteBatch.js +34 -41
  93. package/utils/entity/EntityWriteBatch.js.map +1 -1
  94. package/utils/entity/EntityWriteBatchBuilder.js +15 -16
  95. package/utils/entity/EntityWriteBatchBuilder.js.map +1 -1
  96. package/utils/entity/getEntity.js +8 -9
  97. package/utils/entity/getEntity.js.map +1 -1
  98. package/utils/entity/index.js +0 -2
  99. package/utils/entity/types.js +0 -4
  100. package/utils/get.js +12 -26
  101. package/utils/get.js.map +1 -1
  102. package/utils/index.js +1 -3
  103. package/utils/put.js +7 -9
  104. package/utils/put.js.map +1 -1
  105. package/utils/query.js +77 -129
  106. package/utils/query.js.map +1 -1
  107. package/utils/scan.js +47 -73
  108. package/utils/scan.js.map +1 -1
  109. package/utils/sort.js +37 -61
  110. package/utils/sort.js.map +1 -1
  111. package/utils/table/Table.js +22 -21
  112. package/utils/table/Table.js.map +1 -1
  113. package/utils/table/TableReadBatch.js +37 -45
  114. package/utils/table/TableReadBatch.js.map +1 -1
  115. package/utils/table/TableWriteBatch.js +47 -56
  116. package/utils/table/TableWriteBatch.js.map +1 -1
  117. package/utils/table/index.js +0 -2
  118. package/utils/table/types.js +0 -3
  119. package/exports/api/db.js.map +0 -1
  120. package/feature/FilterUtil/index.js.map +0 -1
  121. package/feature/ValueFilter/index.js.map +0 -1
  122. package/plugins/index.js.map +0 -1
  123. package/store/types.js.map +0 -1
  124. package/toolbox.js.map +0 -1
  125. package/types.js.map +0 -1
  126. package/utils/batch/index.js.map +0 -1
  127. package/utils/batch/types.js.map +0 -1
  128. package/utils/entity/index.js.map +0 -1
  129. package/utils/entity/types.js.map +0 -1
  130. package/utils/index.js.map +0 -1
  131. package/utils/table/index.js.map +0 -1
  132. package/utils/table/types.js.map +0 -1
@@ -1,20 +1,19 @@
1
1
  import { getEntity } from "./getEntity.js";
2
- export class EntityWriteBatchBuilder {
3
- constructor(entity) {
4
- this.entity = getEntity(entity);
5
- }
6
- put(item) {
7
- return this.entity.putBatch(item, {
8
- execute: true,
9
- strictSchemaCheck: false
10
- });
11
- }
12
- delete(item) {
13
- return this.entity.deleteBatch(item);
14
- }
2
+ class EntityWriteBatchBuilder {
3
+ constructor(entity){
4
+ this.entity = getEntity(entity);
5
+ }
6
+ put(item) {
7
+ return this.entity.putBatch(item, {
8
+ execute: true,
9
+ strictSchemaCheck: false
10
+ });
11
+ }
12
+ delete(item) {
13
+ return this.entity.deleteBatch(item);
14
+ }
15
15
  }
16
- export const createEntityWriteBatchBuilder = entity => {
17
- return new EntityWriteBatchBuilder(entity);
18
- };
16
+ const createEntityWriteBatchBuilder = (entity)=>new EntityWriteBatchBuilder(entity);
17
+ export { EntityWriteBatchBuilder, createEntityWriteBatchBuilder };
19
18
 
20
19
  //# sourceMappingURL=EntityWriteBatchBuilder.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getEntity","EntityWriteBatchBuilder","constructor","entity","put","item","putBatch","execute","strictSchemaCheck","delete","deleteBatch","createEntityWriteBatchBuilder"],"sources":["EntityWriteBatchBuilder.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox.js\";\nimport type { BatchWriteItem, IDeleteBatchItem, IPutBatchItem } from \"~/utils/batch/types.js\";\nimport type { IEntityWriteBatchBuilder } from \"./types.js\";\nimport type { EntityOption } from \"./getEntity.js\";\nimport { getEntity } from \"./getEntity.js\";\n\nexport class EntityWriteBatchBuilder implements IEntityWriteBatchBuilder {\n private readonly entity: Entity;\n\n public constructor(entity: EntityOption) {\n this.entity = getEntity(entity);\n }\n\n public put<T extends Record<string, any>>(item: IPutBatchItem<T>): BatchWriteItem {\n return this.entity.putBatch(item, {\n execute: true,\n strictSchemaCheck: false\n });\n }\n\n public delete(item: IDeleteBatchItem): BatchWriteItem {\n return this.entity.deleteBatch(item);\n }\n}\n\nexport const createEntityWriteBatchBuilder = (entity: Entity): IEntityWriteBatchBuilder => {\n return new EntityWriteBatchBuilder(entity);\n};\n"],"mappings":"AAIA,SAASA,SAAS;AAElB,OAAO,MAAMC,uBAAuB,CAAqC;EAG9DC,WAAWA,CAACC,MAAoB,EAAE;IACrC,IAAI,CAACA,MAAM,GAAGH,SAAS,CAACG,MAAM,CAAC;EACnC;EAEOC,GAAGA,CAAgCC,IAAsB,EAAkB;IAC9E,OAAO,IAAI,CAACF,MAAM,CAACG,QAAQ,CAACD,IAAI,EAAE;MAC9BE,OAAO,EAAE,IAAI;MACbC,iBAAiB,EAAE;IACvB,CAAC,CAAC;EACN;EAEOC,MAAMA,CAACJ,IAAsB,EAAkB;IAClD,OAAO,IAAI,CAACF,MAAM,CAACO,WAAW,CAACL,IAAI,CAAC;EACxC;AACJ;AAEA,OAAO,MAAMM,6BAA6B,GAAIR,MAAc,IAA+B;EACvF,OAAO,IAAIF,uBAAuB,CAACE,MAAM,CAAC;AAC9C,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"utils/entity/EntityWriteBatchBuilder.js","sources":["../../../src/utils/entity/EntityWriteBatchBuilder.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox.js\";\nimport type { BatchWriteItem, IDeleteBatchItem, IPutBatchItem } from \"~/utils/batch/types.js\";\nimport type { IEntityWriteBatchBuilder } from \"./types.js\";\nimport type { EntityOption } from \"./getEntity.js\";\nimport { getEntity } from \"./getEntity.js\";\n\nexport class EntityWriteBatchBuilder implements IEntityWriteBatchBuilder {\n private readonly entity: Entity;\n\n public constructor(entity: EntityOption) {\n this.entity = getEntity(entity);\n }\n\n public put<T extends Record<string, any>>(item: IPutBatchItem<T>): BatchWriteItem {\n return this.entity.putBatch(item, {\n execute: true,\n strictSchemaCheck: false\n });\n }\n\n public delete(item: IDeleteBatchItem): BatchWriteItem {\n return this.entity.deleteBatch(item);\n }\n}\n\nexport const createEntityWriteBatchBuilder = (entity: Entity): IEntityWriteBatchBuilder => {\n return new EntityWriteBatchBuilder(entity);\n};\n"],"names":["EntityWriteBatchBuilder","entity","getEntity","item","createEntityWriteBatchBuilder"],"mappings":";AAMO,MAAMA;IAGT,YAAmBC,MAAoB,CAAE;QACrC,IAAI,CAAC,MAAM,GAAGC,UAAUD;IAC5B;IAEO,IAAmCE,IAAsB,EAAkB;QAC9E,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAACA,MAAM;YAC9B,SAAS;YACT,mBAAmB;QACvB;IACJ;IAEO,OAAOA,IAAsB,EAAkB;QAClD,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAACA;IACnC;AACJ;AAEO,MAAMC,gCAAgC,CAACH,SACnC,IAAID,wBAAwBC"}
@@ -1,12 +1,11 @@
1
- import { Entity as ToolboxEntity } from "../../toolbox.js";
2
- export const getEntity = entity => {
3
- const result = entity instanceof ToolboxEntity ? entity : entity.entity;
4
- if (!result.name) {
5
- throw new Error(`No name provided for entity.`);
6
- } else if (!result.table) {
7
- throw new Error(`No table provided for entity ${result.name}.`);
8
- }
9
- return result;
1
+ import { Entity } from "../../toolbox.js";
2
+ const getEntity = (entity)=>{
3
+ const result = entity instanceof Entity ? entity : entity.entity;
4
+ if (result.name) {
5
+ if (!result.table) throw new Error(`No table provided for entity ${result.name}.`);
6
+ } else throw new Error("No name provided for entity.");
7
+ return result;
10
8
  };
9
+ export { getEntity };
11
10
 
12
11
  //# sourceMappingURL=getEntity.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Entity","ToolboxEntity","getEntity","entity","result","name","Error","table"],"sources":["getEntity.ts"],"sourcesContent":["import { Entity as ToolboxEntity } from \"~/toolbox.js\";\nimport type { Entity } from \"./Entity.js\";\n\nexport type EntityOption = ToolboxEntity | Entity;\n\nexport const getEntity = (entity: EntityOption): ToolboxEntity => {\n const result = entity instanceof ToolboxEntity ? entity : entity.entity;\n if (!result.name) {\n throw new Error(`No name provided for entity.`);\n } else if (!result.table) {\n throw new Error(`No table provided for entity ${result.name}.`);\n }\n return result;\n};\n"],"mappings":"AAAA,SAASA,MAAM,IAAIC,aAAa;AAKhC,OAAO,MAAMC,SAAS,GAAIC,MAAoB,IAAoB;EAC9D,MAAMC,MAAM,GAAGD,MAAM,YAAYF,aAAa,GAAGE,MAAM,GAAGA,MAAM,CAACA,MAAM;EACvE,IAAI,CAACC,MAAM,CAACC,IAAI,EAAE;IACd,MAAM,IAAIC,KAAK,CAAC,8BAA8B,CAAC;EACnD,CAAC,MAAM,IAAI,CAACF,MAAM,CAACG,KAAK,EAAE;IACtB,MAAM,IAAID,KAAK,CAAC,gCAAgCF,MAAM,CAACC,IAAI,GAAG,CAAC;EACnE;EACA,OAAOD,MAAM;AACjB,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"utils/entity/getEntity.js","sources":["../../../src/utils/entity/getEntity.ts"],"sourcesContent":["import { Entity as ToolboxEntity } from \"~/toolbox.js\";\nimport type { Entity } from \"./Entity.js\";\n\nexport type EntityOption = ToolboxEntity | Entity;\n\nexport const getEntity = (entity: EntityOption): ToolboxEntity => {\n const result = entity instanceof ToolboxEntity ? entity : entity.entity;\n if (!result.name) {\n throw new Error(`No name provided for entity.`);\n } else if (!result.table) {\n throw new Error(`No table provided for entity ${result.name}.`);\n }\n return result;\n};\n"],"names":["getEntity","entity","result","ToolboxEntity","Error"],"mappings":";AAKO,MAAMA,YAAY,CAACC;IACtB,MAAMC,SAASD,kBAAkBE,SAAgBF,SAASA,OAAO,MAAM;IACvE,IAAKC,OAAO,IAAI,EAET;QAAA,IAAI,CAACA,OAAO,KAAK,EACpB,MAAM,IAAIE,MAAM,CAAC,6BAA6B,EAAEF,OAAO,IAAI,CAAC,CAAC,CAAC;IAClE,OAHI,MAAM,IAAIE,MAAM;IAIpB,OAAOF;AACX"}
@@ -5,5 +5,3 @@ export * from "./EntityWriteBatch.js";
5
5
  export * from "./EntityWriteBatchBuilder.js";
6
6
  export * from "./getEntity.js";
7
7
  export * from "./types.js";
8
-
9
- //# sourceMappingURL=index.js.map
@@ -1,4 +0,0 @@
1
- import { queryAll, queryAllClean, queryOne, queryOneClean } from "../query.js";
2
- import { queryPerPage } from "../index.js";
3
-
4
- //# sourceMappingURL=types.js.map
package/utils/get.js CHANGED
@@ -1,31 +1,17 @@
1
1
  import { cleanupItem } from "./cleanup.js";
2
- /**
3
- * Gets a single record from the DynamoDB table.
4
- * Returns either record or null.
5
- *
6
- * Be aware to wrap in try/catch to avoid the error killing your app.
7
- *
8
- * @throws
9
- */
10
- export const get = async params => {
11
- const {
12
- entity,
13
- keys
14
- } = params;
15
- const result = await entity.get(keys, {
16
- execute: true
17
- });
18
- if (!result?.Item) {
19
- return null;
20
- }
21
- return result.Item;
2
+ const get = async (params)=>{
3
+ const { entity, keys } = params;
4
+ const result = await entity.get(keys, {
5
+ execute: true
6
+ });
7
+ if (!result?.Item) return null;
8
+ return result.Item;
22
9
  };
23
- export const getClean = async params => {
24
- const result = await get(params);
25
- if (!result) {
26
- return null;
27
- }
28
- return cleanupItem(params.entity, result);
10
+ const getClean = async (params)=>{
11
+ const result = await get(params);
12
+ if (!result) return null;
13
+ return cleanupItem(params.entity, result);
29
14
  };
15
+ export { get, getClean };
30
16
 
31
17
  //# sourceMappingURL=get.js.map
package/utils/get.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["cleanupItem","get","params","entity","keys","result","execute","Item","getClean"],"sources":["get.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox.js\";\nimport { cleanupItem } from \"~/utils/cleanup.js\";\n\nexport interface GetRecordParamsKeys {\n PK: string;\n SK: string;\n}\n\nexport interface GetRecordParams {\n entity: Entity;\n keys: GetRecordParamsKeys;\n}\n\n/**\n * Gets a single record from the DynamoDB table.\n * Returns either record or null.\n *\n * Be aware to wrap in try/catch to avoid the error killing your app.\n *\n * @throws\n */\nexport const get = async <T>(params: GetRecordParams): Promise<T | null> => {\n const { entity, keys } = params;\n\n const result = await entity.get(keys, {\n execute: true\n });\n\n if (!result?.Item) {\n return null;\n }\n return result.Item as T;\n};\n\nexport const getClean = async <T>(params: GetRecordParams): Promise<T | null> => {\n const result = await get<T>(params);\n if (!result) {\n return null;\n }\n return cleanupItem<T>(params.entity, result);\n};\n"],"mappings":"AACA,SAASA,WAAW;AAYpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,GAAG,GAAG,MAAUC,MAAuB,IAAwB;EACxE,MAAM;IAAEC,MAAM;IAAEC;EAAK,CAAC,GAAGF,MAAM;EAE/B,MAAMG,MAAM,GAAG,MAAMF,MAAM,CAACF,GAAG,CAACG,IAAI,EAAE;IAClCE,OAAO,EAAE;EACb,CAAC,CAAC;EAEF,IAAI,CAACD,MAAM,EAAEE,IAAI,EAAE;IACf,OAAO,IAAI;EACf;EACA,OAAOF,MAAM,CAACE,IAAI;AACtB,CAAC;AAED,OAAO,MAAMC,QAAQ,GAAG,MAAUN,MAAuB,IAAwB;EAC7E,MAAMG,MAAM,GAAG,MAAMJ,GAAG,CAAIC,MAAM,CAAC;EACnC,IAAI,CAACG,MAAM,EAAE;IACT,OAAO,IAAI;EACf;EACA,OAAOL,WAAW,CAAIE,MAAM,CAACC,MAAM,EAAEE,MAAM,CAAC;AAChD,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"utils/get.js","sources":["../../src/utils/get.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox.js\";\nimport { cleanupItem } from \"~/utils/cleanup.js\";\n\nexport interface GetRecordParamsKeys {\n PK: string;\n SK: string;\n}\n\nexport interface GetRecordParams {\n entity: Entity;\n keys: GetRecordParamsKeys;\n}\n\n/**\n * Gets a single record from the DynamoDB table.\n * Returns either record or null.\n *\n * Be aware to wrap in try/catch to avoid the error killing your app.\n *\n * @throws\n */\nexport const get = async <T>(params: GetRecordParams): Promise<T | null> => {\n const { entity, keys } = params;\n\n const result = await entity.get(keys, {\n execute: true\n });\n\n if (!result?.Item) {\n return null;\n }\n return result.Item as T;\n};\n\nexport const getClean = async <T>(params: GetRecordParams): Promise<T | null> => {\n const result = await get<T>(params);\n if (!result) {\n return null;\n }\n return cleanupItem<T>(params.entity, result);\n};\n"],"names":["get","params","entity","keys","result","getClean","cleanupItem"],"mappings":";AAqBO,MAAMA,MAAM,OAAUC;IACzB,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAE,GAAGF;IAEzB,MAAMG,SAAS,MAAMF,OAAO,GAAG,CAACC,MAAM;QAClC,SAAS;IACb;IAEA,IAAI,CAACC,QAAQ,MACT,OAAO;IAEX,OAAOA,OAAO,IAAI;AACtB;AAEO,MAAMC,WAAW,OAAUJ;IAC9B,MAAMG,SAAS,MAAMJ,IAAOC;IAC5B,IAAI,CAACG,QACD,OAAO;IAEX,OAAOE,YAAeL,OAAO,MAAM,EAAEG;AACzC"}
package/utils/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  export * from "./cleanup.js";
2
2
  export * from "./createEntity.js";
3
3
  export * from "./createTable.js";
4
- export { decodeCursor, encodeCursor } from "./cursor.js";
5
4
  export * from "./get.js";
6
5
  export * from "./delete.js";
7
6
  export * from "./put.js";
@@ -11,5 +10,4 @@ export * from "./sort.js";
11
10
  export * from "./batch/index.js";
12
11
  export * from "./entity/index.js";
13
12
  export * from "./table/index.js";
14
-
15
- //# sourceMappingURL=index.js.map
13
+ export { decodeCursor, encodeCursor } from "./cursor.js";
package/utils/put.js CHANGED
@@ -1,12 +1,10 @@
1
- export const put = async params => {
2
- const {
3
- entity,
4
- item
5
- } = params;
6
- return await entity.put(item, {
7
- execute: true,
8
- strictSchemaCheck: false
9
- });
1
+ const put = async (params)=>{
2
+ const { entity, item } = params;
3
+ return await entity.put(item, {
4
+ execute: true,
5
+ strictSchemaCheck: false
6
+ });
10
7
  };
8
+ export { put };
11
9
 
12
10
  //# sourceMappingURL=put.js.map
package/utils/put.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["put","params","entity","item","execute","strictSchemaCheck"],"sources":["put.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport type IPutParamsItem<T extends GenericRecord = GenericRecord> = {\n PK: string;\n SK: string;\n [key: string]: any;\n} & T;\n\nexport interface IPutParams<T extends GenericRecord = GenericRecord> {\n entity: Entity;\n item: IPutParamsItem<T>;\n}\n\nexport const put = async <T extends GenericRecord = GenericRecord>(params: IPutParams<T>) => {\n const { entity, item } = params;\n\n return await entity.put(item, {\n execute: true,\n strictSchemaCheck: false\n });\n};\n"],"mappings":"AAcA,OAAO,MAAMA,GAAG,GAAG,MAAgDC,MAAqB,IAAK;EACzF,MAAM;IAAEC,MAAM;IAAEC;EAAK,CAAC,GAAGF,MAAM;EAE/B,OAAO,MAAMC,MAAM,CAACF,GAAG,CAACG,IAAI,EAAE;IAC1BC,OAAO,EAAE,IAAI;IACbC,iBAAiB,EAAE;EACvB,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"utils/put.js","sources":["../../src/utils/put.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport type IPutParamsItem<T extends GenericRecord = GenericRecord> = {\n PK: string;\n SK: string;\n [key: string]: any;\n} & T;\n\nexport interface IPutParams<T extends GenericRecord = GenericRecord> {\n entity: Entity;\n item: IPutParamsItem<T>;\n}\n\nexport const put = async <T extends GenericRecord = GenericRecord>(params: IPutParams<T>) => {\n const { entity, item } = params;\n\n return await entity.put(item, {\n execute: true,\n strictSchemaCheck: false\n });\n};\n"],"names":["put","params","entity","item"],"mappings":"AAcO,MAAMA,MAAM,OAAgDC;IAC/D,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAE,GAAGF;IAEzB,OAAO,MAAMC,OAAO,GAAG,CAACC,MAAM;QAC1B,SAAS;QACT,mBAAmB;IACvB;AACJ"}
package/utils/query.js CHANGED
@@ -1,147 +1,95 @@
1
- import WebinyError from "@webiny/error";
1
+ import error from "@webiny/error";
2
2
  import { cleanupItem, cleanupItems } from "./cleanup.js";
3
- /**
4
- * Will run query only once. Pass the previous to run the query again to fetch new data.
5
- * It returns the result and the items it found.
6
- * Result is required to fetch the items that were not fetched in the previous run.
7
- */
8
- const query = async params => {
9
- const {
10
- entity,
11
- previous,
12
- partitionKey,
13
- options
14
- } = params;
15
- let result;
16
- /**
17
- * In case there is no previous result we must make a new query.
18
- * This is the first query on the given partition key.
19
- */
20
- if (!previous) {
21
- // @ts-expect-error
22
- result = await entity.query(partitionKey, options);
23
- } else if (typeof previous.next === "function") {
24
- /**
25
- * In case we have a previous result and it has a next method, we run it.
26
- * In case result of the next method is false, it means it has nothing else to read
27
- * and we return a null to keep the query from repeating.
28
- */
29
- result = await previous.next();
30
- if (result === false) {
31
- return {
3
+ const query = async (params)=>{
4
+ const { entity, previous, partitionKey, options } = params;
5
+ let result;
6
+ if (previous) if ("function" != typeof previous.next) return {
32
7
  result: null,
33
8
  items: []
34
- };
9
+ };
10
+ else {
11
+ result = await previous.next();
12
+ if (false === result) return {
13
+ result: null,
14
+ items: []
15
+ };
35
16
  }
36
- } else {
37
- /**
38
- * This could probably never happen but keep it here just in case to break the query loop.
39
- * Basically, either previous does not exist or it exists and it does not have the next method
40
- * and at that point a result returned will be null and loop should not start again.
41
- */
17
+ else result = await entity.query(partitionKey, options);
18
+ if (!result || !result.Items || !Array.isArray(result.Items)) throw new error("Error when querying for content entries - no result.", "QUERY_ERROR", {
19
+ partitionKey,
20
+ options
21
+ });
42
22
  return {
43
- result: null,
44
- items: []
23
+ result,
24
+ items: result.Items
45
25
  };
46
- }
47
- /**
48
- * We expect the result to contain an Items array and if not, something went wrong, very wrong.
49
- */
50
- if (!result || !result.Items || !Array.isArray(result.Items)) {
51
- throw new WebinyError("Error when querying for content entries - no result.", "QUERY_ERROR", {
52
- partitionKey,
53
- options
54
- });
55
- }
56
- return {
57
- result,
58
- items: result.Items
59
- };
60
26
  };
61
- /**
62
- * Will run the query to fetch the first possible item from the database.
63
- */
64
- export const queryOne = async params => {
65
- const {
66
- items
67
- } = await query({
68
- ...params,
69
- options: {
70
- ...(params.options || {}),
71
- limit: 1
72
- }
73
- });
74
- const item = items.shift();
75
- return item ? item : null;
27
+ const queryOne = async (params)=>{
28
+ const { items } = await query({
29
+ ...params,
30
+ options: {
31
+ ...params.options || {},
32
+ limit: 1
33
+ }
34
+ });
35
+ const item = items.shift();
36
+ return item ? item : null;
76
37
  };
77
- export const queryOneClean = async params => {
78
- const result = await queryOne(params);
79
- if (!result) {
80
- return null;
81
- }
82
- return cleanupItem(params.entity, result);
38
+ const queryOneClean = async (params)=>{
39
+ const result = await queryOne(params);
40
+ if (!result) return null;
41
+ return cleanupItem(params.entity, result);
83
42
  };
84
- /**
85
- * Will run the query to fetch the results no matter how many iterations it needs to go through.
86
- */
87
- export const queryAll = async params => {
88
- const items = [];
89
- let results;
90
- let previousResult = undefined;
91
- while (results = await query({
92
- ...params,
93
- previous: previousResult
94
- })) {
95
- items.push(...results.items);
96
- if (!results.result) {
97
- return items;
43
+ const queryAll = async (params)=>{
44
+ const items = [];
45
+ let results;
46
+ let previousResult;
47
+ while(results = await query({
48
+ ...params,
49
+ previous: previousResult
50
+ })){
51
+ items.push(...results.items);
52
+ if (!results.result) break;
53
+ previousResult = results.result;
98
54
  }
99
- previousResult = results.result;
100
- }
101
- return items;
55
+ return items;
102
56
  };
103
- export const queryAllClean = async params => {
104
- const results = await queryAll(params);
105
- return cleanupItems(params.entity, results);
57
+ const queryAllClean = async (params)=>{
58
+ const results = await queryAll(params);
59
+ return cleanupItems(params.entity, results);
106
60
  };
107
- export const queryPerPage = async params => {
108
- const result = await query({
109
- ...params,
110
- options: {
111
- ...params.options,
112
- limit: params.options?.limit || 50
113
- }
114
- });
115
- return {
116
- items: result.items,
117
- lastEvaluatedKey: result.result?.LastEvaluatedKey
118
- };
61
+ const queryPerPage = async (params)=>{
62
+ const result = await query({
63
+ ...params,
64
+ options: {
65
+ ...params.options,
66
+ limit: params.options?.limit || 50
67
+ }
68
+ });
69
+ return {
70
+ items: result.items,
71
+ lastEvaluatedKey: result.result?.LastEvaluatedKey
72
+ };
119
73
  };
120
- export const queryPerPageClean = async params => {
121
- const result = await queryPerPage(params);
122
- return {
123
- items: cleanupItems(params.entity, result.items),
124
- lastEvaluatedKey: result.lastEvaluatedKey
125
- };
74
+ const queryPerPageClean = async (params)=>{
75
+ const result = await queryPerPage(params);
76
+ return {
77
+ items: cleanupItems(params.entity, result.items),
78
+ lastEvaluatedKey: result.lastEvaluatedKey
79
+ };
126
80
  };
127
-
128
- /**
129
- * Will run the query to fetch the results no matter how many iterations it needs to go through.
130
- * Results of each iteration will be passed to the provided callback
131
- */
132
- export const queryAllWithCallback = async (params, callback) => {
133
- let results;
134
- let previousResult = undefined;
135
- while (results = await query({
136
- ...params,
137
- previous: previousResult
138
- })) {
139
- if (!results.result) {
140
- break;
81
+ const queryAllWithCallback = async (params, callback)=>{
82
+ let results;
83
+ let previousResult;
84
+ while(results = await query({
85
+ ...params,
86
+ previous: previousResult
87
+ })){
88
+ if (!results.result) break;
89
+ await callback(results.items);
90
+ previousResult = results.result;
141
91
  }
142
- await callback(results.items);
143
- previousResult = results.result;
144
- }
145
92
  };
93
+ export { queryAll, queryAllClean, queryAllWithCallback, queryOne, queryOneClean, queryPerPage, queryPerPageClean };
146
94
 
147
95
  //# sourceMappingURL=query.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["WebinyError","cleanupItem","cleanupItems","query","params","entity","previous","partitionKey","options","result","next","items","Items","Array","isArray","queryOne","limit","item","shift","queryOneClean","queryAll","results","previousResult","undefined","push","queryAllClean","queryPerPage","lastEvaluatedKey","LastEvaluatedKey","queryPerPageClean","queryAllWithCallback","callback"],"sources":["query.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { Entity, EntityQueryOptions } from \"~/toolbox.js\";\nimport { cleanupItem, cleanupItems } from \"~/utils/cleanup.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface QueryAllParams {\n entity: Entity<any>;\n partitionKey: string;\n options?: EntityQueryOptions;\n}\n\nexport interface QueryOneParams extends QueryAllParams {\n options?: Omit<EntityQueryOptions, \"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\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 // @ts-expect-error\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<T | null> => {\n const { items } = await query<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\nexport const queryOneClean = async <T>(params: QueryOneParams): Promise<T | null> => {\n const result = await queryOne<T>(params);\n if (!result) {\n return null;\n }\n return cleanupItem(params.entity, result);\n};\n/**\n * Will run the query to fetch the results no matter how many iterations it needs to go through.\n */\nexport const queryAll = async <T>(params: QueryAllParams): Promise<T[]> => {\n const items: T[] = [];\n let results: QueryResult<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\nexport const queryAllClean = async <T>(params: QueryAllParams): Promise<T[]> => {\n const results = await queryAll<T>(params);\n return cleanupItems(params.entity, results);\n};\n\nexport interface IQueryPageResponse<T> {\n items: T[];\n lastEvaluatedKey: GenericRecord;\n}\n\nexport const queryPerPage = async <T>(params: QueryAllParams): Promise<IQueryPageResponse<T>> => {\n const result = await query<T>({\n ...params,\n options: {\n ...params.options,\n limit: params.options?.limit || 50\n }\n });\n\n return {\n items: result.items,\n lastEvaluatedKey: result.result?.LastEvaluatedKey\n };\n};\n\nexport const queryPerPageClean = async <T>(\n params: QueryAllParams\n): Promise<IQueryPageResponse<T>> => {\n const result = await queryPerPage<T>(params);\n return {\n items: cleanupItems<T>(params.entity, result.items),\n lastEvaluatedKey: result.lastEvaluatedKey\n };\n};\n\n/**\n * Will run the query to fetch the results no matter how many iterations it needs to go through.\n * Results of each iteration will be passed to the provided callback\n */\nexport const queryAllWithCallback = async <T>(\n params: QueryAllParams,\n callback: (items: T[]) => Promise<void>\n): Promise<void> => {\n let results: QueryResult<T>;\n let previousResult: any = undefined;\n while ((results = await query({ ...params, previous: previousResult }))) {\n if (!results.result) {\n break;\n }\n await callback(results.items);\n previousResult = results.result;\n }\n};\n"],"mappings":"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","ignoreList":[]}
1
+ {"version":3,"file":"utils/query.js","sources":["../../src/utils/query.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { Entity, EntityQueryOptions } from \"~/toolbox.js\";\nimport { cleanupItem, cleanupItems } from \"~/utils/cleanup.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface QueryAllParams {\n entity: Entity<any>;\n partitionKey: string;\n options?: EntityQueryOptions;\n}\n\nexport interface QueryOneParams extends QueryAllParams {\n options?: Omit<EntityQueryOptions, \"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\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 // @ts-expect-error\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<T | null> => {\n const { items } = await query<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\nexport const queryOneClean = async <T>(params: QueryOneParams): Promise<T | null> => {\n const result = await queryOne<T>(params);\n if (!result) {\n return null;\n }\n return cleanupItem(params.entity, result);\n};\n/**\n * Will run the query to fetch the results no matter how many iterations it needs to go through.\n */\nexport const queryAll = async <T>(params: QueryAllParams): Promise<T[]> => {\n const items: T[] = [];\n let results: QueryResult<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\nexport const queryAllClean = async <T>(params: QueryAllParams): Promise<T[]> => {\n const results = await queryAll<T>(params);\n return cleanupItems(params.entity, results);\n};\n\nexport interface IQueryPageResponse<T> {\n items: T[];\n lastEvaluatedKey: GenericRecord;\n}\n\nexport const queryPerPage = async <T>(params: QueryAllParams): Promise<IQueryPageResponse<T>> => {\n const result = await query<T>({\n ...params,\n options: {\n ...params.options,\n limit: params.options?.limit || 50\n }\n });\n\n return {\n items: result.items,\n lastEvaluatedKey: result.result?.LastEvaluatedKey\n };\n};\n\nexport const queryPerPageClean = async <T>(\n params: QueryAllParams\n): Promise<IQueryPageResponse<T>> => {\n const result = await queryPerPage<T>(params);\n return {\n items: cleanupItems<T>(params.entity, result.items),\n lastEvaluatedKey: result.lastEvaluatedKey\n };\n};\n\n/**\n * Will run the query to fetch the results no matter how many iterations it needs to go through.\n * Results of each iteration will be passed to the provided callback\n */\nexport const queryAllWithCallback = async <T>(\n params: QueryAllParams,\n callback: (items: T[]) => Promise<void>\n): Promise<void> => {\n let results: QueryResult<T>;\n let previousResult: any = undefined;\n while ((results = await query({ ...params, previous: previousResult }))) {\n if (!results.result) {\n break;\n }\n await callback(results.items);\n previousResult = results.result;\n }\n};\n"],"names":["query","params","entity","previous","partitionKey","options","result","Array","WebinyError","queryOne","items","item","queryOneClean","cleanupItem","queryAll","results","previousResult","queryAllClean","cleanupItems","queryPerPage","queryPerPageClean","queryAllWithCallback","callback"],"mappings":";;AA6BA,MAAMA,QAAQ,OAAUC;IACpB,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,OAAO,EAAE,GAAGJ;IACpD,IAAIK;IAKJ,IAAKH,UAGE,IAAI,AAAyB,cAAzB,OAAOA,SAAS,IAAI,EAmB3B,OAAO;QACH,QAAQ;QACR,OAAO,EAAE;IACb;SAtB4C;QAM5CG,SAAS,MAAMH,SAAS,IAAI;QAC5B,IAAIG,AAAW,UAAXA,QACA,OAAO;YACH,QAAQ;YACR,OAAO,EAAE;QACb;IAER;SAdIA,SAAS,MAAMJ,OAAO,KAAK,CAACE,cAAcC;IA4B9C,IAAI,CAACC,UAAU,CAACA,OAAO,KAAK,IAAI,CAACC,MAAM,OAAO,CAACD,OAAO,KAAK,GACvD,MAAM,IAAIE,MACN,wDACA,eACA;QACIJ;QACAC;IACJ;IAGR,OAAO;QACHC;QACA,OAAOA,OAAO,KAAK;IACvB;AACJ;AAIO,MAAMG,WAAW,OAAUR;IAC9B,MAAM,EAAES,KAAK,EAAE,GAAG,MAAMV,MAAS;QAC7B,GAAGC,MAAM;QACT,SAAS;YACL,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YACxB,OAAO;QACX;IACJ;IACA,MAAMU,OAAOD,MAAM,KAAK;IACxB,OAAOC,OAAOA,OAAO;AACzB;AAEO,MAAMC,gBAAgB,OAAUX;IACnC,MAAMK,SAAS,MAAMG,SAAYR;IACjC,IAAI,CAACK,QACD,OAAO;IAEX,OAAOO,YAAYZ,OAAO,MAAM,EAAEK;AACtC;AAIO,MAAMQ,WAAW,OAAUb;IAC9B,MAAMS,QAAa,EAAE;IACrB,IAAIK;IACJ,IAAIC;IACJ,MAAQD,UAAU,MAAMf,MAAM;QAAE,GAAGC,MAAM;QAAE,UAAUe;IAAe,GAAK;QACrEN,MAAM,IAAI,IAAIK,QAAQ,KAAK;QAC3B,IAAI,CAACA,QAAQ,MAAM,EACf;QAEJC,iBAAiBD,QAAQ,MAAM;IACnC;IACA,OAAOL;AACX;AAEO,MAAMO,gBAAgB,OAAUhB;IACnC,MAAMc,UAAU,MAAMD,SAAYb;IAClC,OAAOiB,aAAajB,OAAO,MAAM,EAAEc;AACvC;AAOO,MAAMI,eAAe,OAAUlB;IAClC,MAAMK,SAAS,MAAMN,MAAS;QAC1B,GAAGC,MAAM;QACT,SAAS;YACL,GAAGA,OAAO,OAAO;YACjB,OAAOA,OAAO,OAAO,EAAE,SAAS;QACpC;IACJ;IAEA,OAAO;QACH,OAAOK,OAAO,KAAK;QACnB,kBAAkBA,OAAO,MAAM,EAAE;IACrC;AACJ;AAEO,MAAMc,oBAAoB,OAC7BnB;IAEA,MAAMK,SAAS,MAAMa,aAAgBlB;IACrC,OAAO;QACH,OAAOiB,aAAgBjB,OAAO,MAAM,EAAEK,OAAO,KAAK;QAClD,kBAAkBA,OAAO,gBAAgB;IAC7C;AACJ;AAMO,MAAMe,uBAAuB,OAChCpB,QACAqB;IAEA,IAAIP;IACJ,IAAIC;IACJ,MAAQD,UAAU,MAAMf,MAAM;QAAE,GAAGC,MAAM;QAAE,UAAUe;IAAe,GAAK;QACrE,IAAI,CAACD,QAAQ,MAAM,EACf;QAEJ,MAAMO,SAASP,QAAQ,KAAK;QAC5BC,iBAAiBD,QAAQ,MAAM;IACnC;AACJ"}
package/utils/scan.js CHANGED
@@ -1,82 +1,56 @@
1
1
  import { executeWithRetry } from "@webiny/utils";
2
- const createNext = result => {
3
- if (!result?.LastEvaluatedKey || !result.next) {
4
- return undefined;
5
- }
6
- return async () => {
7
- const response = await result.next();
8
- return convertResult(response);
9
- };
10
- };
11
- const convertResult = result => {
12
- return {
13
- items: result.Items || [],
14
- count: result.Count,
15
- scannedCount: result.ScannedCount,
16
- lastEvaluatedKey: result.LastEvaluatedKey || undefined,
17
- next: createNext(result),
18
- error: result.error,
19
- requestId: result.$response?.requestId || ""
20
- };
2
+ const createNext = (result)=>{
3
+ if (!result?.LastEvaluatedKey || !result.next) return;
4
+ return async ()=>{
5
+ const response = await result.next();
6
+ return convertResult(response);
7
+ };
21
8
  };
22
- export const scan = async params => {
23
- const {
24
- options
25
- } = params;
26
- const table = params.table ? params.table : params.entity.table;
27
- if (!table) {
28
- throw new Error(`Missing table for scan: ${JSON.stringify(options)}`);
29
- }
30
- const result = await table.scan({
31
- ...options,
32
- execute: true
33
- }, params.params);
34
- return convertResult(result);
9
+ const convertResult = (result)=>({
10
+ items: result.Items || [],
11
+ count: result.Count,
12
+ scannedCount: result.ScannedCount,
13
+ lastEvaluatedKey: result.LastEvaluatedKey || void 0,
14
+ next: createNext(result),
15
+ error: result.error,
16
+ requestId: result.$response?.requestId || ""
17
+ });
18
+ const scan = async (params)=>{
19
+ const { options } = params;
20
+ const table = params.table ? params.table : params.entity.table;
21
+ if (!table) throw new Error(`Missing table for scan: ${JSON.stringify(options)}`);
22
+ const result = await table.scan({
23
+ ...options,
24
+ execute: true
25
+ }, params.params);
26
+ return convertResult(result);
35
27
  };
36
- export const scanWithCallback = async (params, callback, options) => {
37
- // For backwards compatibility, we still allow for executing the scan without retries.
38
- const usingRetry = Boolean(options?.retry);
39
- const retryOptions = options?.retry === true ? {} : options?.retry;
40
- const executeScan = () => scan(params);
41
- const getInitialResult = () => {
42
- if (usingRetry) {
43
- return executeWithRetry(executeScan, retryOptions);
44
- }
45
- return executeScan();
46
- };
47
- let result = await getInitialResult();
48
- if (!result.items?.length && !result.lastEvaluatedKey) {
49
- return;
50
- }
51
-
52
- // If the result of the callback was `false`, that means the
53
- // user's intention was to stop further table scanning.
54
- const callbackResult = await callback(result);
55
- const mustBreak = callbackResult === false;
56
- if (mustBreak) {
57
- return;
58
- }
59
- while (result.next) {
60
- const executeNext = () => result.next();
61
- const getNextResult = () => {
62
- if (usingRetry) {
63
- return executeWithRetry(executeNext, retryOptions);
64
- }
65
- return executeNext();
28
+ const scanWithCallback = async (params, callback, options)=>{
29
+ const usingRetry = Boolean(options?.retry);
30
+ const retryOptions = options?.retry === true ? {} : options?.retry;
31
+ const executeScan = ()=>scan(params);
32
+ const getInitialResult = ()=>{
33
+ if (usingRetry) return executeWithRetry(executeScan, retryOptions);
34
+ return executeScan();
66
35
  };
67
- result = await getNextResult();
68
-
69
- // If the result of the callback was `false`, that means the
70
- // user's intention was to stop further table scanning.
36
+ let result = await getInitialResult();
37
+ if (!result.items?.length && !result.lastEvaluatedKey) return;
71
38
  const callbackResult = await callback(result);
72
- const mustBreak = callbackResult === false;
73
- if (mustBreak) {
74
- break;
75
- }
76
- if (!result.next) {
77
- return;
39
+ const mustBreak = false === callbackResult;
40
+ if (mustBreak) return;
41
+ while(result.next){
42
+ const executeNext = ()=>result.next();
43
+ const getNextResult = ()=>{
44
+ if (usingRetry) return executeWithRetry(executeNext, retryOptions);
45
+ return executeNext();
46
+ };
47
+ result = await getNextResult();
48
+ const callbackResult = await callback(result);
49
+ const mustBreak = false === callbackResult;
50
+ if (mustBreak) break;
51
+ if (!result.next) return;
78
52
  }
79
- }
80
53
  };
54
+ export { scan, scanWithCallback };
81
55
 
82
56
  //# sourceMappingURL=scan.js.map