@webiny/db-dynamodb 6.3.0-beta.4 → 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
package/utils/scan.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["executeWithRetry","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","scanWithCallback","callback","usingRetry","Boolean","retry","retryOptions","executeScan","getInitialResult","length","callbackResult","mustBreak","executeNext","getNextResult"],"sources":["scan.ts"],"sourcesContent":["import type { ScanInput, ScanOutput } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { Entity, ScanOptions, TableDef } from \"~/toolbox.js\";\nimport type { ExecuteWithRetryOptions } from \"@webiny/utils\";\nimport { executeWithRetry } from \"@webiny/utils\";\n\nexport type { ScanOptions, ScanInput, ScanOutput };\n\nexport interface BaseScanParams {\n options?: ScanOptions;\n params?: Partial<ScanInput>;\n}\n\nexport interface ScanWithTable extends BaseScanParams {\n table: TableDef;\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":"AAGA,SAASA,gBAAgB,QAAQ,eAAe;AA6ChD,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,gBAAgB,EAAEZ,MAAM,CAACC,gBAAgB,IAAIE,SAAS;IACtDD,IAAI,EAAEH,UAAU,CAAIC,MAAM,CAAC;IAC3Ba,KAAK,EAAEb,MAAM,CAACa,KAAK;IACnBC,SAAS,EAAEd,MAAM,CAACe,SAAS,EAAED,SAAS,IAAI;EAC9C,CAAC;AACL,CAAC;AAUD,OAAO,MAAME,IAAI,GAAG,MAAUC,MAAkB,I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AAc,KAAK,KAAK;EAC1C,IAAIC,SAAS,EAAE;IACX;EACJ;EAEA,OAAOnC,MAAM,CAACE,IAAI,EAAE;IAChB,MAAMkC,WAAW,GAAGA,CAAA,KAAMpC,MAAM,CAACE,IAAI,CAAE,CAAC;IACxC,MAAMmC,aAAa,GAAGA,CAAA,KAAM;MACxB,IAAIV,UAAU,EAAE;QACZ,OAAO7B,gBAAgB,CAACsC,WAAW,EAAEN,YAAY,CAAC;MACtD;MACA,OAAOM,WAAW,CAAC,CAAC;IACxB,CAAC;IAEDpC,MAAM,GAAG,MAAMqC,aAAa,CAAC,CAAC;;IAE9B;IACA;IACA,MAAMH,cAAc,GAAG,MAAMR,QAAQ,CAAC1B,MAAM,CAAC;IAC7C,MAAMmC,SAAS,GAAGD,cAAc,KAAK,KAAK;IAC1C,IAAIC,SAAS,EAAE;MACX;IACJ;IAEA,IAAI,CAACnC,MAAM,CAACE,IAAI,EAAE;MACd;IACJ;EACJ;AACJ,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"utils/scan.js","sources":["../../src/utils/scan.ts"],"sourcesContent":["import type { ScanInput, ScanOutput } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { Entity, ScanOptions, TableDef } from \"~/toolbox.js\";\nimport type { ExecuteWithRetryOptions } from \"@webiny/utils\";\nimport { executeWithRetry } from \"@webiny/utils\";\n\nexport type { ScanOptions, ScanInput, ScanOutput };\n\nexport interface BaseScanParams {\n options?: ScanOptions;\n params?: Partial<ScanInput>;\n}\n\nexport interface ScanWithTable extends BaseScanParams {\n table: TableDef;\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"],"names":["createNext","result","response","convertResult","undefined","scan","params","options","table","Error","JSON","scanWithCallback","callback","usingRetry","Boolean","retryOptions","executeScan","getInitialResult","executeWithRetry","callbackResult","mustBreak","executeNext","getNextResult"],"mappings":";AAgDA,MAAMA,aAAa,CAAIC;IACnB,IAAI,CAACA,QAAQ,oBAAoB,CAACA,OAAO,IAAI,EACzC;IAEJ,OAAO;QACH,MAAMC,WAAW,MAAMD,OAAQ,IAAI;QACnC,OAAOE,cAAcD;IACzB;AACJ;AAEA,MAAMC,gBAAgB,CAAIF,SACf;QACH,OAAOA,OAAO,KAAK,IAAI,EAAE;QACzB,OAAOA,OAAO,KAAK;QACnB,cAAcA,OAAO,YAAY;QACjC,kBAAkBA,OAAO,gBAAgB,IAAIG;QAC7C,MAAMJ,WAAcC;QACpB,OAAOA,OAAO,KAAK;QACnB,WAAWA,OAAO,SAAS,EAAE,aAAa;IAC9C;AAWG,MAAMI,OAAO,OAAUC;IAC1B,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,MAAME,QAAQF,OAAO,KAAK,GAAGA,OAAO,KAAK,GAAGA,OAAO,MAAM,CAAC,KAAK;IAC/D,IAAI,CAACE,OACD,MAAM,IAAIC,MAAM,CAAC,wBAAwB,EAAEC,KAAK,SAAS,CAACH,UAAU;IAGxE,MAAMN,SAAS,MAAMO,MAAM,IAAI,CAC3B;QACI,GAAGD,OAAO;QACV,SAAS;IACb,GACAD,OAAO,MAAM;IAGjB,OAAOH,cAAcF;AACzB;AAMO,MAAMU,mBAAmB,OAC5BL,QACAM,UACAL;IAGA,MAAMM,aAAaC,QAAQP,SAAS;IACpC,MAAMQ,eAAeR,SAAS,UAAU,OAAO,CAAC,IAAIA,SAAS;IAE7D,MAAMS,cAAc,IAAMX,KAAoBC;IAC9C,MAAMW,mBAAmB;QACrB,IAAIJ,YACA,OAAOK,iBAAiBF,aAAaD;QAEzC,OAAOC;IACX;IAEA,IAAIf,SAAS,MAAMgB;IAEnB,IAAI,CAAChB,OAAO,KAAK,EAAE,UAAU,CAACA,OAAO,gBAAgB,EACjD;IAKJ,MAAMkB,iBAAiB,MAAMP,SAASX;IACtC,MAAMmB,YAAYD,AAAmB,UAAnBA;IAClB,IAAIC,WACA;IAGJ,MAAOnB,OAAO,IAAI,CAAE;QAChB,MAAMoB,cAAc,IAAMpB,OAAO,IAAI;QACrC,MAAMqB,gBAAgB;YAClB,IAAIT,YACA,OAAOK,iBAAiBG,aAAaN;YAEzC,OAAOM;QACX;QAEApB,SAAS,MAAMqB;QAIf,MAAMH,iBAAiB,MAAMP,SAASX;QACtC,MAAMmB,YAAYD,AAAmB,UAAnBA;QAClB,IAAIC,WACA;QAGJ,IAAI,CAACnB,OAAO,IAAI,EACZ;IAER;AACJ"}
package/utils/sort.js CHANGED
@@ -1,69 +1,45 @@
1
- import lodashOrderBy from "lodash/orderBy.js";
2
- import WebinyError from "@webiny/error";
3
- const extractSort = (sortBy, fields) => {
4
- const result = sortBy.split("_");
5
- if (result.length !== 2) {
6
- throw new WebinyError("Problem in determining the sorting for the entry items.", "SORT_ERROR", {
7
- sortBy
1
+ import orderBy from "lodash/orderBy.js";
2
+ import error from "@webiny/error";
3
+ const extractSort = (sortBy, fields)=>{
4
+ const result = sortBy.split("_");
5
+ if (2 !== result.length) throw new error("Problem in determining the sorting for the entry items.", "SORT_ERROR", {
6
+ sortBy
8
7
  });
9
- }
10
- const [field, order] = result;
11
- if (!field) {
12
- throw new WebinyError("Sorting field does not exist.", "SORTING_FIELD_ERROR", {
13
- field,
14
- order,
15
- fields
8
+ const [field, order] = result;
9
+ if (!field) throw new error("Sorting field does not exist.", "SORTING_FIELD_ERROR", {
10
+ field,
11
+ order,
12
+ fields
16
13
  });
17
- }
18
- const fieldPlugin = fields.find(f => f.getField() === field);
19
- const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;
20
- if (isSortable === false) {
21
- throw new WebinyError(`Cannot sort by given field: "${field}".`, "UNSUPPORTED_SORT_ERROR", {
22
- fields,
23
- field
14
+ const fieldPlugin = fields.find((f)=>f.getField() === field);
15
+ const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;
16
+ if (false === isSortable) throw new error(`Cannot sort by given field: "${field}".`, "UNSUPPORTED_SORT_ERROR", {
17
+ fields,
18
+ field
24
19
  });
25
- }
26
- return {
27
- field,
28
- reverse: order.toUpperCase() === "DESC"
29
- };
20
+ return {
21
+ field,
22
+ reverse: "DESC" === order.toUpperCase()
23
+ };
30
24
  };
31
- export function sortItems(params) {
32
- const {
33
- items,
34
- sort: initialSort = [],
35
- fields = []
36
- } = params;
37
- /**
38
- * Skip sorting if nothing was passed to sort by or nothing to sort.
39
- */
40
- if (items.length <= 1 || Array.isArray(initialSort) === false || initialSort.length === 0) {
41
- return items;
42
- }
43
- const info = {
44
- sorters: [],
45
- orders: []
46
- };
47
- for (const sort of initialSort) {
48
- /**
49
- * Possibly empty array item was passed.
50
- */
51
- if (!sort) {
52
- continue;
25
+ function sortItems(params) {
26
+ const { items, sort: initialSort = [], fields = [] } = params;
27
+ if (items.length <= 1 || false === Array.isArray(initialSort) || 0 === initialSort.length) return items;
28
+ const info = {
29
+ sorters: [],
30
+ orders: []
31
+ };
32
+ for (const sort of initialSort){
33
+ if (!sort) continue;
34
+ const { field, reverse } = extractSort(sort, fields);
35
+ const fieldPlugin = fields.find((f)=>f.getField() === field);
36
+ const path = fieldPlugin ? fieldPlugin.getPath() : field;
37
+ info.sorters.push(path);
38
+ info.orders.push(true === reverse ? "desc" : "asc");
53
39
  }
54
- const {
55
- field,
56
- reverse
57
- } = extractSort(sort, fields);
58
- const fieldPlugin = fields.find(f => f.getField() === field);
59
- const path = fieldPlugin ? fieldPlugin.getPath() : field;
60
- info.sorters.push(path);
61
- info.orders.push(reverse === true ? "desc" : "asc");
62
- }
63
- if (info.sorters.length === 0) {
64
- return items;
65
- }
66
- return lodashOrderBy(items, info.sorters, info.orders);
40
+ if (0 === info.sorters.length) return items;
41
+ return orderBy(items, info.sorters, info.orders);
67
42
  }
43
+ export { sortItems };
68
44
 
69
45
  //# sourceMappingURL=sort.js.map
package/utils/sort.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["lodashOrderBy","WebinyError","extractSort","sortBy","fields","result","split","length","field","order","fieldPlugin","find","f","getField","isSortable","reverse","toUpperCase","sortItems","params","items","sort","initialSort","Array","isArray","info","sorters","orders","path","getPath","push"],"sources":["sort.ts"],"sourcesContent":["import lodashOrderBy from \"lodash/orderBy.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { FieldPlugin } from \"~/plugins/definitions/FieldPlugin.js\";\n\ninterface Info {\n sorters: string[];\n orders: (boolean | \"asc\" | \"desc\")[];\n}\n\ninterface Response {\n reverse: boolean;\n field: string;\n}\n\nconst extractSort = (sortBy: string, fields: FieldPlugin[]): Response => {\n const result = sortBy.split(\"_\");\n if (result.length !== 2) {\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_ERROR\",\n {\n sortBy\n }\n );\n }\n const [field, order] = result;\n\n if (!field) {\n throw new WebinyError(\"Sorting field does not exist.\", \"SORTING_FIELD_ERROR\", {\n field,\n order,\n fields\n });\n }\n const fieldPlugin = fields.find(f => f.getField() === field);\n const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;\n if (isSortable === false) {\n throw new WebinyError(`Cannot sort by given field: \"${field}\".`, \"UNSUPPORTED_SORT_ERROR\", {\n fields,\n field\n });\n }\n\n return {\n field,\n reverse: order.toUpperCase() === \"DESC\"\n };\n};\n\ninterface Params<T> {\n /**\n * The items we are sorting.\n */\n items: T[];\n /**\n * Sort options. For example: [\"id_ASC\"]\n */\n sort?: string[];\n /**\n * Fields we can sort by.\n */\n fields?: FieldPlugin[];\n}\n\nexport function sortItems<T = any>(params: Params<T>): T[] {\n const { items, sort: initialSort = [], fields = [] } = params;\n /**\n * Skip sorting if nothing was passed to sort by or nothing to sort.\n */\n if (items.length <= 1 || Array.isArray(initialSort) === false || initialSort.length === 0) {\n return items;\n }\n\n const info: Info = {\n sorters: [],\n orders: []\n };\n\n for (const sort of initialSort) {\n /**\n * Possibly empty array item was passed.\n */\n if (!sort) {\n continue;\n }\n const { field, reverse } = extractSort(sort, fields);\n const fieldPlugin = fields.find(f => f.getField() === field);\n const path = fieldPlugin ? fieldPlugin.getPath() : field;\n\n info.sorters.push(path);\n info.orders.push(reverse === true ? \"desc\" : \"asc\");\n }\n\n if (info.sorters.length === 0) {\n return items;\n }\n\n return lodashOrderBy(items, info.sorters, info.orders);\n}\n"],"mappings":"AAAA,OAAOA,aAAa,MAAM,mBAAmB;AAC7C,OAAOC,WAAW,MAAM,eAAe;AAavC,MAAMC,WAAW,GAAGA,CAACC,MAAc,EAAEC,MAAqB,KAAe;EACrE,MAAMC,MAAM,GAAGF,MAAM,CAACG,KAAK,CAAC,GAAG,CAAC;EAChC,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,MAAM,IAAIN,WAAW,CACjB,yDAAyD,EACzD,YAAY,EACZ;MACIE;IACJ,CACJ,CAAC;EACL;EACA,MAAM,CAACK,KAAK,EAAEC,KAAK,CAAC,GAAGJ,MAAM;EAE7B,IAAI,CAACG,KAAK,EAAE;IACR,MAAM,IAAIP,WAAW,CAAC,+BAA+B,EAAE,qBAAqB,EAAE;MAC1EO,KAAK;MACLC,KAAK;MACLL;IACJ,CAAC,CAAC;EACN;EACA,MAAMM,WAAW,GAAGN,M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AGpB,KAAK;IAExDgB,IAAI,CAACC,OAAO,CAACI,IAAI,CAACF,IAAI,CAAC;IACvBH,IAAI,CAACE,MAAM,CAACG,IAAI,CAACd,OAAO,KAAK,IAAI,GAAG,MAAM,GAAG,KAAK,CAAC;EACvD;EAEA,IAAIS,IAAI,CAACC,OAAO,CAAClB,MAAM,KAAK,CAAC,EAAE;IAC3B,OAAOY,KAAK;EAChB;EAEA,OAAOnB,aAAa,CAACmB,KAAK,EAAEK,IAAI,CAACC,OAAO,EAAED,IAAI,CAACE,MAAM,CAAC;AAC1D","ignoreList":[]}
1
+ {"version":3,"file":"utils/sort.js","sources":["../../src/utils/sort.ts"],"sourcesContent":["import lodashOrderBy from \"lodash/orderBy.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { FieldPlugin } from \"~/plugins/definitions/FieldPlugin.js\";\n\ninterface Info {\n sorters: string[];\n orders: (boolean | \"asc\" | \"desc\")[];\n}\n\ninterface Response {\n reverse: boolean;\n field: string;\n}\n\nconst extractSort = (sortBy: string, fields: FieldPlugin[]): Response => {\n const result = sortBy.split(\"_\");\n if (result.length !== 2) {\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_ERROR\",\n {\n sortBy\n }\n );\n }\n const [field, order] = result;\n\n if (!field) {\n throw new WebinyError(\"Sorting field does not exist.\", \"SORTING_FIELD_ERROR\", {\n field,\n order,\n fields\n });\n }\n const fieldPlugin = fields.find(f => f.getField() === field);\n const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;\n if (isSortable === false) {\n throw new WebinyError(`Cannot sort by given field: \"${field}\".`, \"UNSUPPORTED_SORT_ERROR\", {\n fields,\n field\n });\n }\n\n return {\n field,\n reverse: order.toUpperCase() === \"DESC\"\n };\n};\n\ninterface Params<T> {\n /**\n * The items we are sorting.\n */\n items: T[];\n /**\n * Sort options. For example: [\"id_ASC\"]\n */\n sort?: string[];\n /**\n * Fields we can sort by.\n */\n fields?: FieldPlugin[];\n}\n\nexport function sortItems<T = any>(params: Params<T>): T[] {\n const { items, sort: initialSort = [], fields = [] } = params;\n /**\n * Skip sorting if nothing was passed to sort by or nothing to sort.\n */\n if (items.length <= 1 || Array.isArray(initialSort) === false || initialSort.length === 0) {\n return items;\n }\n\n const info: Info = {\n sorters: [],\n orders: []\n };\n\n for (const sort of initialSort) {\n /**\n * Possibly empty array item was passed.\n */\n if (!sort) {\n continue;\n }\n const { field, reverse } = extractSort(sort, fields);\n const fieldPlugin = fields.find(f => f.getField() === field);\n const path = fieldPlugin ? fieldPlugin.getPath() : field;\n\n info.sorters.push(path);\n info.orders.push(reverse === true ? \"desc\" : \"asc\");\n }\n\n if (info.sorters.length === 0) {\n return items;\n }\n\n return lodashOrderBy(items, info.sorters, info.orders);\n}\n"],"names":["extractSort","sortBy","fields","result","WebinyError","field","order","fieldPlugin","f","isSortable","sortItems","params","items","initialSort","Array","info","sort","reverse","path","lodashOrderBy"],"mappings":";;AAcA,MAAMA,cAAc,CAACC,QAAgBC;IACjC,MAAMC,SAASF,OAAO,KAAK,CAAC;IAC5B,IAAIE,AAAkB,MAAlBA,OAAO,MAAM,EACb,MAAM,IAAIC,MACN,2DACA,cACA;QACIH;IACJ;IAGR,MAAM,CAACI,OAAOC,MAAM,GAAGH;IAEvB,IAAI,CAACE,OACD,MAAM,IAAID,MAAY,iCAAiC,uBAAuB;QAC1EC;QACAC;QACAJ;IACJ;IAEJ,MAAMK,cAAcL,OAAO,IAAI,CAACM,CAAAA,IAAKA,EAAE,QAAQ,OAAOH;IACtD,MAAMI,aAAaF,cAAcA,YAAY,UAAU,KAAK;IAC5D,IAAIE,AAAe,UAAfA,YACA,MAAM,IAAIL,MAAY,CAAC,6BAA6B,EAAEC,MAAM,EAAE,CAAC,EAAE,0BAA0B;QACvFH;QACAG;IACJ;IAGJ,OAAO;QACHA;QACA,SAASC,AAAwB,WAAxBA,MAAM,WAAW;IAC9B;AACJ;AAiBO,SAASI,UAAmBC,MAAiB;IAChD,MAAM,EAAEC,KAAK,EAAE,MAAMC,cAAc,EAAE,EAAEX,SAAS,EAAE,EAAE,GAAGS;IAIvD,IAAIC,MAAM,MAAM,IAAI,KAAKE,AAA+B,UAA/BA,MAAM,OAAO,CAACD,gBAA0BA,AAAuB,MAAvBA,YAAY,MAAM,EAC/E,OAAOD;IAGX,MAAMG,OAAa;QACf,SAAS,EAAE;QACX,QAAQ,EAAE;IACd;IAEA,KAAK,MAAMC,QAAQH,YAAa;QAI5B,IAAI,CAACG,MACD;QAEJ,MAAM,EAAEX,KAAK,EAAEY,OAAO,EAAE,GAAGjB,YAAYgB,MAAMd;QAC7C,MAAMK,cAAcL,OAAO,IAAI,CAACM,CAAAA,IAAKA,EAAE,QAAQ,OAAOH;QACtD,MAAMa,OAAOX,cAAcA,YAAY,OAAO,KAAKF;QAEnDU,KAAK,OAAO,CAAC,IAAI,CAACG;QAClBH,KAAK,MAAM,CAAC,IAAI,CAACE,AAAY,SAAZA,UAAmB,SAAS;IACjD;IAEA,IAAIF,AAAwB,MAAxBA,KAAK,OAAO,CAAC,MAAM,EACnB,OAAOH;IAGX,OAAOO,QAAcP,OAAOG,KAAK,OAAO,EAAEA,KAAK,MAAM;AACzD"}
@@ -1,27 +1,28 @@
1
- import { Table as BaseTable } from "../../toolbox.js";
1
+ import { Table } from "../../toolbox.js";
2
2
  import { createTableWriteBatch } from "./TableWriteBatch.js";
3
3
  import { createTableReadBatch } from "./TableReadBatch.js";
4
4
  import { scan } from "../scan.js";
5
- export class Table {
6
- constructor(params) {
7
- this.table = new BaseTable(params);
8
- }
9
- createWriter() {
10
- return createTableWriteBatch({
11
- table: this.table
12
- });
13
- }
14
- createReader() {
15
- return createTableReadBatch({
16
- table: this.table
17
- });
18
- }
19
- async scan(params) {
20
- return scan({
21
- ...params,
22
- table: this.table
23
- });
24
- }
5
+ class Table_Table {
6
+ constructor(params){
7
+ this.table = new Table(params);
8
+ }
9
+ createWriter() {
10
+ return createTableWriteBatch({
11
+ table: this.table
12
+ });
13
+ }
14
+ createReader() {
15
+ return createTableReadBatch({
16
+ table: this.table
17
+ });
18
+ }
19
+ async scan(params) {
20
+ return scan({
21
+ ...params,
22
+ table: this.table
23
+ });
24
+ }
25
25
  }
26
+ export { Table_Table as Table };
26
27
 
27
28
  //# sourceMappingURL=Table.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Table","BaseTable","createTableWriteBatch","createTableReadBatch","scan","constructor","params","table","createWriter","createReader"],"sources":["Table.ts"],"sourcesContent":["import type { TableConstructor } from \"~/toolbox.js\";\nimport { Table as BaseTable } from \"~/toolbox.js\";\nimport type {\n ITable,\n ITableReadBatch,\n ITableScanParams,\n ITableScanResponse,\n ITableWriteBatch\n} from \"./types.js\";\nimport { createTableWriteBatch } from \"./TableWriteBatch.js\";\nimport { createTableReadBatch } from \"./TableReadBatch.js\";\nimport { scan } from \"../scan.js\";\n\nexport class Table<\n Name extends string = string,\n PartitionKey extends string = string,\n SortKey extends string = string\n> implements ITable<Name, PartitionKey, SortKey> {\n public readonly table: BaseTable<Name, PartitionKey, SortKey>;\n\n public constructor(params: TableConstructor<Name, PartitionKey, SortKey>) {\n this.table = new BaseTable(params);\n }\n\n public createWriter(): ITableWriteBatch {\n return createTableWriteBatch({\n table: this.table\n });\n }\n\n public createReader(): ITableReadBatch {\n return createTableReadBatch({\n table: this.table\n });\n }\n\n public async scan<T>(params: ITableScanParams): Promise<ITableScanResponse<T>> {\n return scan<T>({\n ...params,\n table: this.table\n });\n }\n}\n"],"mappings":"AACA,SAASA,KAAK,IAAIC,SAAS;AAQ3B,SAASC,qBAAqB;AAC9B,SAASC,oBAAoB;AAC7B,SAASC,IAAI;AAEb,OAAO,MAAMJ,KAAK,CAI+B;EAGtCK,WAAWA,CAACC,MAAqD,EAAE;IACtE,IAAI,CAACC,KAAK,GAAG,IAAIN,SAAS,CAACK,MAAM,CAAC;EACtC;EAEOE,YAAYA,CAAA,EAAqB;IACpC,OAAON,qBAAqB,CAAC;MACzBK,KAAK,EAAE,IAAI,CAACA;IAChB,CAAC,CAAC;EACN;EAEOE,YAAYA,CAAA,EAAoB;IACnC,OAAON,oBAAoB,CAAC;MACxBI,KAAK,EAAE,IAAI,CAACA;IAChB,CAAC,CAAC;EACN;EAEA,MAAaH,IAAIA,CAAIE,MAAwB,EAAkC;IAC3E,OAAOF,IAAI,CAAI;MACX,GAAGE,MAAM;MACTC,KAAK,EAAE,IAAI,CAACA;IAChB,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"utils/table/Table.js","sources":["../../../src/utils/table/Table.ts"],"sourcesContent":["import type { TableConstructor } from \"~/toolbox.js\";\nimport { Table as BaseTable } from \"~/toolbox.js\";\nimport type {\n ITable,\n ITableReadBatch,\n ITableScanParams,\n ITableScanResponse,\n ITableWriteBatch\n} from \"./types.js\";\nimport { createTableWriteBatch } from \"./TableWriteBatch.js\";\nimport { createTableReadBatch } from \"./TableReadBatch.js\";\nimport { scan } from \"../scan.js\";\n\nexport class Table<\n Name extends string = string,\n PartitionKey extends string = string,\n SortKey extends string = string\n> implements ITable<Name, PartitionKey, SortKey> {\n public readonly table: BaseTable<Name, PartitionKey, SortKey>;\n\n public constructor(params: TableConstructor<Name, PartitionKey, SortKey>) {\n this.table = new BaseTable(params);\n }\n\n public createWriter(): ITableWriteBatch {\n return createTableWriteBatch({\n table: this.table\n });\n }\n\n public createReader(): ITableReadBatch {\n return createTableReadBatch({\n table: this.table\n });\n }\n\n public async scan<T>(params: ITableScanParams): Promise<ITableScanResponse<T>> {\n return scan<T>({\n ...params,\n table: this.table\n });\n }\n}\n"],"names":["Table","params","BaseTable","createTableWriteBatch","createTableReadBatch","scan"],"mappings":";;;;AAaO,MAAMA;IAOT,YAAmBC,MAAqD,CAAE;QACtE,IAAI,CAAC,KAAK,GAAG,IAAIC,MAAUD;IAC/B;IAEO,eAAiC;QACpC,OAAOE,sBAAsB;YACzB,OAAO,IAAI,CAAC,KAAK;QACrB;IACJ;IAEO,eAAgC;QACnC,OAAOC,qBAAqB;YACxB,OAAO,IAAI,CAAC,KAAK;QACrB;IACJ;IAEA,MAAa,KAAQH,MAAwB,EAAkC;QAC3E,OAAOI,KAAQ;YACX,GAAGJ,MAAM;YACT,OAAO,IAAI,CAAC,KAAK;QACrB;IACJ;AACJ"}
@@ -1,54 +1,46 @@
1
1
  import { batchReadAll } from "../batch/batchRead.js";
2
2
  import { createEntityReadBatchBuilder } from "../entity/EntityReadBatchBuilder.js";
3
3
  import { WebinyError } from "@webiny/error";
4
- export class TableReadBatch {
5
- _items = [];
6
- builders = new Map();
7
- constructor(params) {
8
- this.table = params.table;
9
- }
10
- get total() {
11
- return this._items.length;
12
- }
13
- get items() {
14
- return Array.from(this._items);
15
- }
16
- get(entity, input) {
17
- const builder = this.getBuilder(entity);
18
- const items = Array.isArray(input) ? input : [input];
19
- for (const item of items) {
20
- /**
21
- * We cannot read from two tables at the same time, so check for that.
22
- */
23
- if (this.table.name !== entity.table.name) {
24
- throw new WebinyError(`Cannot read from two different tables at the same time.`);
25
- }
26
- this._items.push(builder.get(item));
4
+ class TableReadBatch {
5
+ constructor(params){
6
+ this._items = [];
7
+ this.builders = new Map();
8
+ this.table = params.table;
27
9
  }
28
- }
29
- async execute() {
30
- if (this._items.length === 0) {
31
- return [];
10
+ get total() {
11
+ return this._items.length;
32
12
  }
33
- const items = Array.from(this._items);
34
- this._items.length = 0;
35
- return await batchReadAll({
36
- items,
37
- table: this.table
38
- });
39
- }
40
- getBuilder(entity) {
41
- const builder = this.builders.get(entity.name);
42
- if (builder) {
43
- return builder;
13
+ get items() {
14
+ return Array.from(this._items);
15
+ }
16
+ get(entity, input) {
17
+ const builder = this.getBuilder(entity);
18
+ const items = Array.isArray(input) ? input : [
19
+ input
20
+ ];
21
+ for (const item of items){
22
+ if (this.table.name !== entity.table.name) throw new WebinyError("Cannot read from two different tables at the same time.");
23
+ this._items.push(builder.get(item));
24
+ }
25
+ }
26
+ async execute() {
27
+ if (0 === this._items.length) return [];
28
+ const items = Array.from(this._items);
29
+ this._items.length = 0;
30
+ return await batchReadAll({
31
+ items,
32
+ table: this.table
33
+ });
34
+ }
35
+ getBuilder(entity) {
36
+ const builder = this.builders.get(entity.name);
37
+ if (builder) return builder;
38
+ const newBuilder = createEntityReadBatchBuilder(entity);
39
+ this.builders.set(entity.name, newBuilder);
40
+ return newBuilder;
44
41
  }
45
- const newBuilder = createEntityReadBatchBuilder(entity);
46
- this.builders.set(entity.name, newBuilder);
47
- return newBuilder;
48
- }
49
42
  }
50
- export const createTableReadBatch = params => {
51
- return new TableReadBatch(params);
52
- };
43
+ const createTableReadBatch = (params)=>new TableReadBatch(params);
44
+ export { TableReadBatch, createTableReadBatch };
53
45
 
54
46
  //# sourceMappingURL=TableReadBatch.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["batchReadAll","createEntityReadBatchBuilder","WebinyError","TableReadBatch","_items","builders","Map","constructor","params","table","total","length","items","Array","from","get","entity","input","builder","getBuilder","isArray","item","name","push","execute","newBuilder","set","createTableReadBatch"],"sources":["TableReadBatch.ts"],"sourcesContent":["import type { Entity, TableDef } from \"~/toolbox.js\";\nimport type {\n IEntityReadBatchBuilder,\n IEntityReadBatchBuilderGetResponse\n} from \"~/utils/entity/types.js\";\nimport { batchReadAll } from \"~/utils/batch/batchRead.js\";\nimport { createEntityReadBatchBuilder } from \"~/utils/entity/EntityReadBatchBuilder.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport type { ITableReadBatch, ITableReadBatchKey } from \"./types.js\";\n\nexport interface ITableReadBatchParams {\n table: TableDef;\n}\n\nexport class TableReadBatch implements ITableReadBatch {\n private readonly table: TableDef;\n\n private readonly _items: IEntityReadBatchBuilderGetResponse[] = [];\n private readonly builders: Map<string, IEntityReadBatchBuilder> = new Map();\n\n public constructor(params: ITableReadBatchParams) {\n this.table = params.table;\n }\n\n public get total(): number {\n return this._items.length;\n }\n\n public get items(): IEntityReadBatchBuilderGetResponse[] {\n return Array.from(this._items);\n }\n\n public get(entity: Entity, input: ITableReadBatchKey): void {\n const builder = this.getBuilder(entity);\n\n const items = Array.isArray(input) ? input : [input];\n for (const item of items) {\n /**\n * We cannot read from two tables at the same time, so check for that.\n */\n if (this.table.name !== entity.table!.name) {\n throw new WebinyError(`Cannot read from two different tables at the same time.`);\n }\n\n this._items.push(builder.get(item));\n }\n }\n\n public async execute<T = GenericRecord>(): Promise<T[]> {\n if (this._items.length === 0) {\n return [];\n }\n const items = Array.from(this._items);\n this._items.length = 0;\n return await batchReadAll<T>({\n items,\n table: this.table\n });\n }\n\n private getBuilder(entity: Entity): IEntityReadBatchBuilder {\n const builder = this.builders.get(entity.name);\n if (builder) {\n return builder;\n }\n const newBuilder = createEntityReadBatchBuilder(entity);\n this.builders.set(entity.name, newBuilder);\n return newBuilder;\n }\n}\n\nexport const createTableReadBatch = (params: ITableReadBatchParams): ITableReadBatch => {\n return new TableReadBatch(params);\n};\n"],"mappings":"AAKA,SAASA,YAAY;AACrB,SAASC,4BAA4B;AAErC,SAASC,WAAW,QAAQ,eAAe;AAO3C,OAAO,MAAMC,cAAc,CAA4B;EAGlCC,MAAM,GAAyC,EAAE;EACjDC,QAAQ,GAAyC,IAAIC,GAAG,CAAC,CAAC;EAEpEC,WAAWA,CAACC,MAA6B,EAAE;IAC9C,IAAI,CAACC,KAAK,GAAGD,MAAM,CAACC,KAAK;EAC7B;EAEA,IAAWC,KAAKA,CAAA,EAAW;IACvB,OAAO,IAAI,CAACN,MAAM,CAACO,MAAM;EAC7B;EAEA,IAAWC,KAAKA,CAAA,EAAyC;IACrD,OAAOC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACV,MAAM,CAAC;EAClC;EAEOW,GAAGA,CAACC,MAAc,EAAEC,KAAyB,EAAQ;IACxD,MAAMC,OAAO,GAAG,IAAI,CAACC,UAAU,CAACH,MAAM,CAAC;IAEvC,MAAMJ,KAAK,GAAGC,KAAK,CAACO,OAAO,CAACH,KAAK,CAAC,GAAGA,KAAK,GAAG,CAACA,KAAK,CAAC;IACpD,KAAK,MAAMI,IAAI,IAAIT,KAAK,EAAE;MACtB;AACZ;AACA;MACY,IAAI,IAAI,CAACH,KAAK,CAACa,IAAI,KAAKN,MAAM,CAACP,KAAK,CAAEa,IAAI,EAAE;QACxC,MAAM,IAAIpB,WAAW,CAAC,yDAAyD,CAAC;MACpF;MAEA,IAAI,CAACE,MAAM,CAACmB,IAAI,CAACL,OAAO,CAACH,GAAG,CAACM,IAAI,CAAC,CAAC;IACvC;EACJ;EAEA,MAAaG,OAAOA,CAAA,EAAoC;IACpD,IAAI,IAAI,CAACpB,MAAM,CAACO,MAAM,KAAK,CAAC,EAAE;MAC1B,OAAO,EAAE;IACb;IACA,MAAMC,KAAK,GAAGC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACV,MAAM,CAAC;IACrC,IAAI,CAACA,MAAM,CAACO,MAAM,GAAG,CAAC;IACtB,OAAO,MAAMX,YAAY,CAAI;MACzBY,KAAK;MACLH,KAAK,EAAE,IAAI,CAACA;IAChB,CAAC,CAAC;EACN;EAEQU,UAAUA,CAACH,MAAc,EAA2B;IACxD,MAAME,OAAO,GAAG,IAAI,CAACb,QAAQ,CAACU,GAAG,CAACC,MAAM,CAACM,IAAI,CAAC;IAC9C,IAAIJ,OAAO,EAAE;MACT,OAAOA,OAAO;IAClB;IACA,MAAMO,UAAU,GAAGxB,4BAA4B,CAACe,MAAM,CAAC;IACvD,IAAI,CAACX,QAAQ,CAACqB,GAAG,CAACV,MAAM,CAACM,IAAI,EAAEG,UAAU,CAAC;IAC1C,OAAOA,UAAU;EACrB;AACJ;AAEA,OAAO,MAAME,oBAAoB,GAAInB,MAA6B,IAAsB;EACpF,OAAO,IAAIL,cAAc,CAACK,MAAM,CAAC;AACrC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"utils/table/TableReadBatch.js","sources":["../../../src/utils/table/TableReadBatch.ts"],"sourcesContent":["import type { Entity, TableDef } from \"~/toolbox.js\";\nimport type {\n IEntityReadBatchBuilder,\n IEntityReadBatchBuilderGetResponse\n} from \"~/utils/entity/types.js\";\nimport { batchReadAll } from \"~/utils/batch/batchRead.js\";\nimport { createEntityReadBatchBuilder } from \"~/utils/entity/EntityReadBatchBuilder.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport type { ITableReadBatch, ITableReadBatchKey } from \"./types.js\";\n\nexport interface ITableReadBatchParams {\n table: TableDef;\n}\n\nexport class TableReadBatch implements ITableReadBatch {\n private readonly table: TableDef;\n\n private readonly _items: IEntityReadBatchBuilderGetResponse[] = [];\n private readonly builders: Map<string, IEntityReadBatchBuilder> = new Map();\n\n public constructor(params: ITableReadBatchParams) {\n this.table = params.table;\n }\n\n public get total(): number {\n return this._items.length;\n }\n\n public get items(): IEntityReadBatchBuilderGetResponse[] {\n return Array.from(this._items);\n }\n\n public get(entity: Entity, input: ITableReadBatchKey): void {\n const builder = this.getBuilder(entity);\n\n const items = Array.isArray(input) ? input : [input];\n for (const item of items) {\n /**\n * We cannot read from two tables at the same time, so check for that.\n */\n if (this.table.name !== entity.table!.name) {\n throw new WebinyError(`Cannot read from two different tables at the same time.`);\n }\n\n this._items.push(builder.get(item));\n }\n }\n\n public async execute<T = GenericRecord>(): Promise<T[]> {\n if (this._items.length === 0) {\n return [];\n }\n const items = Array.from(this._items);\n this._items.length = 0;\n return await batchReadAll<T>({\n items,\n table: this.table\n });\n }\n\n private getBuilder(entity: Entity): IEntityReadBatchBuilder {\n const builder = this.builders.get(entity.name);\n if (builder) {\n return builder;\n }\n const newBuilder = createEntityReadBatchBuilder(entity);\n this.builders.set(entity.name, newBuilder);\n return newBuilder;\n }\n}\n\nexport const createTableReadBatch = (params: ITableReadBatchParams): ITableReadBatch => {\n return new TableReadBatch(params);\n};\n"],"names":["TableReadBatch","params","Map","Array","entity","input","builder","items","item","WebinyError","batchReadAll","newBuilder","createEntityReadBatchBuilder","createTableReadBatch"],"mappings":";;;AAeO,MAAMA;IAM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batchWrite.js";
2
2
  import { createEntityWriteBatchBuilder } from "../entity/EntityWriteBatchBuilder.js";
3
- export class TableWriteBatch {
4
- _items = [];
5
- builders = new Map();
6
- get total() {
7
- return this._items.length;
8
- }
9
- get items() {
10
- return Array.from(this._items);
11
- }
12
- constructor(params) {
13
- this.table = params.table;
14
- if (!params.items?.length) {
15
- return;
16
- }
17
- this._items.push(...params.items);
18
- }
19
- put(entity, item) {
20
- const builder = this.getBuilder(entity);
21
- this._items.push(builder.put(item));
22
- }
23
- delete(entity, item) {
24
- const builder = this.getBuilder(entity);
25
- this._items.push(builder.delete(item));
26
- }
27
- combine(items) {
28
- return createTableWriteBatch({
29
- table: this.table,
30
- items: this._items.concat(items)
31
- });
32
- }
33
- async execute() {
34
- if (this._items.length === 0) {
35
- return [];
36
- }
37
- const items = Array.from(this._items);
38
- this._items.length = 0;
39
- return await batchWriteAll({
40
- items,
41
- table: this.table
42
- });
43
- }
44
- getBuilder(entity) {
45
- if (!entity.name) {
46
- throw new Error("Entity must have a name.");
47
- }
48
- const builder = this.builders.get(entity.name);
49
- if (builder) {
50
- return builder;
51
- }
52
- const newBuilder = createEntityWriteBatchBuilder(entity);
53
- this.builders.set(entity.name, newBuilder);
54
- return newBuilder;
55
- }
3
+ class TableWriteBatch {
4
+ get total() {
5
+ return this._items.length;
6
+ }
7
+ get items() {
8
+ return Array.from(this._items);
9
+ }
10
+ constructor(params){
11
+ this._items = [];
12
+ this.builders = new Map();
13
+ this.table = params.table;
14
+ if (!params.items?.length) return;
15
+ this._items.push(...params.items);
16
+ }
17
+ put(entity, item) {
18
+ const builder = this.getBuilder(entity);
19
+ this._items.push(builder.put(item));
20
+ }
21
+ delete(entity, item) {
22
+ const builder = this.getBuilder(entity);
23
+ this._items.push(builder.delete(item));
24
+ }
25
+ combine(items) {
26
+ return createTableWriteBatch({
27
+ table: this.table,
28
+ items: this._items.concat(items)
29
+ });
30
+ }
31
+ async execute() {
32
+ if (0 === this._items.length) return [];
33
+ const items = Array.from(this._items);
34
+ this._items.length = 0;
35
+ return await batchWriteAll({
36
+ items,
37
+ table: this.table
38
+ });
39
+ }
40
+ getBuilder(entity) {
41
+ if (!entity.name) throw new Error("Entity must have a name.");
42
+ const builder = this.builders.get(entity.name);
43
+ if (builder) return builder;
44
+ const newBuilder = createEntityWriteBatchBuilder(entity);
45
+ this.builders.set(entity.name, newBuilder);
46
+ return newBuilder;
47
+ }
56
48
  }
57
- export const createTableWriteBatch = params => {
58
- return new TableWriteBatch(params);
59
- };
49
+ const createTableWriteBatch = (params)=>new TableWriteBatch(params);
50
+ export { TableWriteBatch, createTableWriteBatch };
60
51
 
61
52
  //# sourceMappingURL=TableWriteBatch.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["batchWriteAll","createEntityWriteBatchBuilder","TableWriteBatch","_items","builders","Map","total","length","items","Array","from","constructor","params","table","push","put","entity","item","builder","getBuilder","delete","combine","createTableWriteBatch","concat","execute","name","Error","get","newBuilder","set"],"sources":["TableWriteBatch.ts"],"sourcesContent":["import type { Entity, TableDef } from \"~/toolbox.js\";\nimport type {\n BatchWriteItem,\n BatchWriteResult,\n IDeleteBatchItem,\n IPutBatchItem\n} from \"~/utils/batch/types.js\";\nimport type { IEntityWriteBatchBuilder } from \"~/utils/entity/types.js\";\nimport { batchWriteAll } from \"~/utils/batch/batchWrite.js\";\nimport { createEntityWriteBatchBuilder } from \"~/utils/entity/EntityWriteBatchBuilder.js\";\nimport type { ITableWriteBatch } from \"./types.js\";\n\nexport interface ITableWriteBatchParams {\n table: TableDef;\n items?: BatchWriteItem[];\n}\n\nexport class TableWriteBatch implements ITableWriteBatch {\n private readonly table: TableDef;\n private readonly _items: BatchWriteItem[] = [];\n private readonly builders: Map<string, IEntityWriteBatchBuilder> = new Map();\n\n public get total(): number {\n return this._items.length;\n }\n\n public get items(): BatchWriteItem[] {\n return Array.from(this._items);\n }\n\n public constructor(params: ITableWriteBatchParams) {\n this.table = params.table;\n if (!params.items?.length) {\n return;\n }\n this._items.push(...params.items);\n }\n\n public put(entity: Entity, item: IPutBatchItem): void {\n const builder = this.getBuilder(entity);\n this._items.push(builder.put(item));\n }\n\n public delete(entity: Entity, item: IDeleteBatchItem): void {\n const builder = this.getBuilder(entity);\n this._items.push(builder.delete(item));\n }\n\n public combine(items: BatchWriteItem[]): ITableWriteBatch {\n return createTableWriteBatch({\n table: this.table,\n items: this._items.concat(items)\n });\n }\n\n public async execute(): Promise<BatchWriteResult> {\n if (this._items.length === 0) {\n return [];\n }\n const items = Array.from(this._items);\n this._items.length = 0;\n return await batchWriteAll({\n items,\n table: this.table\n });\n }\n\n private getBuilder(entity: Entity): IEntityWriteBatchBuilder {\n if (!entity.name) {\n throw new Error(\"Entity must have a name.\");\n }\n const builder = this.builders.get(entity.name);\n if (builder) {\n return builder;\n }\n const newBuilder = createEntityWriteBatchBuilder(entity);\n this.builders.set(entity.name, newBuilder);\n return newBuilder;\n }\n}\n\nexport const createTableWriteBatch = (params: ITableWriteBatchParams): ITableWriteBatch => {\n return new TableWriteBatch(params);\n};\n"],"mappings":"AAQA,SAASA,aAAa;AACtB,SAASC,6BAA6B;AAQtC,OAAO,MAAMC,eAAe,CAA6B;EAEpCC,MAAM,GAAqB,EAAE;EAC7BC,QAAQ,GAA0C,IAAIC,GAAG,CAAC,CAAC;EAE5E,IAAWC,KAAKA,CAAA,EAAW;IACvB,OAAO,IAAI,CAACH,MAAM,CAACI,MAAM;EAC7B;EAEA,IAAWC,KAAKA,CAAA,EAAqB;IACjC,OAAOC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACP,MAAM,CAAC;EAClC;EAEOQ,WAAWA,CAACC,MAA8B,EAAE;IAC/C,IAAI,CAACC,KAAK,GAAGD,MAAM,CAACC,KAAK;IACzB,IAAI,CAACD,MAAM,CAACJ,KAAK,EAAED,MAAM,EAAE;MACvB;IACJ;IACA,IAAI,CAACJ,MAAM,CAACW,IAAI,CAAC,GAAGF,MAAM,CAACJ,KAAK,CAAC;EACrC;EAEOO,GAAGA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IACxD,IAAI,CAACZ,QAAQ,CAACyB,GAAG,CAACb,MAAM,CAACS,IAAI,EAAEG,UAAU,CAAC;IAC1C,OAAOA,UAAU;EACrB;AACJ;AAEA,OAAO,MAAMN,qBAAqB,GAAIV,MAA8B,IAAuB;EACvF,OAAO,IAAIV,eAAe,CAACU,MAAM,CAAC;AACtC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"utils/table/TableWriteBatch.js","sources":["../../../src/utils/table/TableWriteBatch.ts"],"sourcesContent":["import type { Entity, TableDef } from \"~/toolbox.js\";\nimport type {\n BatchWriteItem,\n BatchWriteResult,\n IDeleteBatchItem,\n IPutBatchItem\n} from \"~/utils/batch/types.js\";\nimport type { IEntityWriteBatchBuilder } from \"~/utils/entity/types.js\";\nimport { batchWriteAll } from \"~/utils/batch/batchWrite.js\";\nimport { createEntityWriteBatchBuilder } from \"~/utils/entity/EntityWriteBatchBuilder.js\";\nimport type { ITableWriteBatch } from \"./types.js\";\n\nexport interface ITableWriteBatchParams {\n table: TableDef;\n items?: BatchWriteItem[];\n}\n\nexport class TableWriteBatch implements ITableWriteBatch {\n private readonly table: TableDef;\n private readonly _items: BatchWriteItem[] = [];\n private readonly builders: Map<string, IEntityWriteBatchBuilder> = new Map();\n\n public get total(): number {\n return this._items.length;\n }\n\n public get items(): BatchWriteItem[] {\n return Array.from(this._items);\n }\n\n public constructor(params: ITableWriteBatchParams) {\n this.table = params.table;\n if (!params.items?.length) {\n return;\n }\n this._items.push(...params.items);\n }\n\n public put(entity: Entity, item: IPutBatchItem): void {\n const builder = this.getBuilder(entity);\n this._items.push(builder.put(item));\n }\n\n public delete(entity: Entity, item: IDeleteBatchItem): void {\n const builder = this.getBuilder(entity);\n this._items.push(builder.delete(item));\n }\n\n public combine(items: BatchWriteItem[]): ITableWriteBatch {\n return createTableWriteBatch({\n table: this.table,\n items: this._items.concat(items)\n });\n }\n\n public async execute(): Promise<BatchWriteResult> {\n if (this._items.length === 0) {\n return [];\n }\n const items = Array.from(this._items);\n this._items.length = 0;\n return await batchWriteAll({\n items,\n table: this.table\n });\n }\n\n private getBuilder(entity: Entity): IEntityWriteBatchBuilder {\n if (!entity.name) {\n throw new Error(\"Entity must have a name.\");\n }\n const builder = this.builders.get(entity.name);\n if (builder) {\n return builder;\n }\n const newBuilder = createEntityWriteBatchBuilder(entity);\n this.builders.set(entity.name, newBuilder);\n return newBuilder;\n }\n}\n\nexport const createTableWriteBatch = (params: ITableWriteBatchParams): ITableWriteBatch => {\n return new TableWriteBatch(params);\n};\n"],"names":["TableWriteBatch","Array","params","Map","entity","item","builder","items","createTableWriteBatch","batchWriteAll","Error","newBuilder","createEntityWriteBatchBuilder"],"mappings":";;AAiBO,MAAMA;IAKT,IAAW,QAAgB;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM;IAC7B;IAEA,IAAW,QAA0B;QACjC,OAAOC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;IACjC;IAEA,YAAmBC,MAA8B,CAAE;aAXlC,MAAM,GAAqB,EAAE;aAC7B,QAAQ,GAA0C,IAAIC;QAWnE,IAAI,CAAC,KAAK,GAAGD,OAAO,KAAK;QACzB,IAAI,CAACA,OAAO,KAAK,EAAE,QACf;QAEJ,IAAI,CAAC,MAAM,CAAC,IAAI,IAAIA,OAAO,KAAK;IACpC;IAEO,IAAIE,MAAc,EAAEC,IAAmB,EAAQ;QAClD,MAAMC,UAAU,IAAI,CAAC,UAAU,CAACF;QAChC,IAAI,CAAC,MAAM,CAAC,IAAI,CAACE,QAAQ,GAAG,CAACD;IACjC;IAEO,OAAOD,MAAc,EAAEC,IAAsB,EAAQ;QACxD,MAAMC,UAAU,IAAI,CAAC,UAAU,CAACF;QAChC,IAAI,CAAC,MAAM,CAAC,IAAI,CAACE,QAAQ,MAAM,CAACD;IACpC;IAEO,QAAQE,KAAuB,EAAoB;QACtD,OAAOC,sBAAsB;YACzB,OAAO,IAAI,CAAC,KAAK;YACjB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAACD;QAC9B;IACJ;IAEA,MAAa,UAAqC;QAC9C,IAAI,AAAuB,MAAvB,IAAI,CAAC,MAAM,CAAC,MAAM,EAClB,OAAO,EAAE;QAEb,MAAMA,QAAQN,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;QACpC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG;QACrB,OAAO,MAAMQ,cAAc;YACvBF;YACA,OAAO,IAAI,CAAC,KAAK;QACrB;IACJ;IAEQ,WAAWH,MAAc,EAA4B;QACzD,IAAI,CAACA,OAAO,IAAI,EACZ,MAAM,IAAIM,MAAM;QAEpB,MAAMJ,UAAU,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACF,OAAO,IAAI;QAC7C,IAAIE,SACA,OAAOA;QAEX,MAAMK,aAAaC,8BAA8BR;QACjD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACA,OAAO,IAAI,EAAEO;QAC/B,OAAOA;IACX;AACJ;AAEO,MAAMH,wBAAwB,CAACN,SAC3B,IAAIF,gBAAgBE"}
@@ -2,5 +2,3 @@ export * from "./Table.js";
2
2
  export * from "./TableReadBatch.js";
3
3
  export * from "./TableWriteBatch.js";
4
4
  export * from "./types.js";
5
-
6
- //# sourceMappingURL=index.js.map
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["ValueFilter","ValueFilterRegistry","FilterUtil"],"sources":["db.ts"],"sourcesContent":["export { ValueFilter, ValueFilterRegistry } from \"~/feature/ValueFilter/index.js\";\nexport { FilterUtil } from \"~/feature/FilterUtil/index.js\";\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,mBAAmB;AACzC,SAASC,UAAU","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["FilterUtil","FilterUtilFeature"],"sources":["index.ts"],"sourcesContent":["export { FilterUtil } from \"./abstractions/FilterUtil.js\";\nexport { FilterUtilFeature } from \"./feature.js\";\n"],"mappings":"AAAA,SAASA,UAAU;AACnB,SAASC,iBAAiB","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["ValueFilter","ValueFilterRegistry","ValueFilterFeature"],"sources":["index.ts"],"sourcesContent":["export { ValueFilter } from \"./abstractions/ValueFilter.js\";\nexport { ValueFilterRegistry } from \"./abstractions/ValueFilterRegistry.js\";\nexport { ValueFilterFeature } from \"./feature.js\";\n"],"mappings":"AAAA,SAASA,WAAW;AACpB,SAASC,mBAAmB;AAC5B,SAASC,kBAAkB","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./definitions/assignFields.js\";\nexport * from \"./definitions/DateTimeTransformPlugin.js\";\nexport * from \"./definitions/FieldPlugin.js\";\nexport * from \"./definitions/TimeTransformPlugin.js\";\nexport * from \"./definitions/ValueTransformPlugin.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IEntity, IGlobalEntityAttributes } from \"~/utils/index.js\";\n\nexport interface IStoreEntityValue {\n key: string;\n value: string;\n}\n\nexport type IStoreEntity = IEntity<IGlobalEntityAttributes<IStoreEntityValue>>;\n"],"mappings":"","ignoreList":[]}
package/toolbox.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":["Entity","Table"],"sources":["toolbox.ts"],"sourcesContent":["export { Entity, Table } from \"dynamodb-toolbox\";\n\nimport { Entity, Table } from \"dynamodb-toolbox\";\n\nexport type ScanOptions = NonNullable<Parameters<Entity[\"scan\"]>[0]>;\nexport type DynamoDBTypes =\n | \"string\"\n | \"boolean\"\n | \"number\"\n | \"bigint\"\n | \"list\"\n | \"map\"\n | \"binary\"\n | \"set\";\n\ntype Key = string | number | symbol;\n\nexport type TableDef = Table<string, Key, Key | null>;\nexport type TableConstructor<\n A extends string,\n B extends Key,\n C extends Key\n> = ConstructorParameters<typeof Table<A, B, C>>[0];\n\n// Types previously imported from dynamodb-toolbox internals.\n// Declared locally to avoid deep path imports blocked by moduleResolution: bundler.\nexport type Readonly<T> = T extends ((...args: any[]) => any) | undefined\n ? T\n : T extends object\n ? { readonly [P in keyof T]: Readonly<T[P]> }\n : T;\n\nexport type AttributeDefinition =\n | DynamoDBTypes\n | Partial<{\n type: DynamoDBTypes;\n coerce: boolean;\n default: unknown;\n dependsOn: string | string[];\n required: boolean | \"always\";\n hidden: boolean;\n prefix: string;\n suffix: string;\n delimiter: string;\n map: string;\n alias: string;\n onlyMap: boolean;\n partitionKey: boolean;\n sortKey: boolean;\n [key: string]: unknown;\n }>\n | [string, number]\n | [string, number, string]\n | [string, number, Record<string, unknown>];\n\nexport type AttributeDefinitions = Record<PropertyKey, AttributeDefinition>;\n\nexport interface EntityConstructor<\n T extends Readonly<AttributeDefinitions> = Readonly<AttributeDefinitions>\n> {\n name: string;\n attributes: T;\n table?: TableDef;\n timestamps?: boolean;\n createdAlias?: string;\n modifiedAlias?: string;\n typeAlias?: string;\n typeHidden?: boolean;\n autoExecute?: boolean;\n autoParse?: boolean;\n}\n\nexport interface EntityQueryOptions {\n index?: string;\n limit?: number;\n reverse?: boolean;\n consistent?: boolean;\n capacity?: \"indexes\" | \"total\" | \"none\";\n select?: \"all_attributes\" | \"all_projected_attributes\" | \"count\" | \"specific_attributes\";\n eq?: string | number;\n lt?: string | number;\n lte?: string | number;\n gt?: string | number;\n gte?: string | number;\n between?: [string, string] | [number, number] | [bigint, bigint];\n beginsWith?: string;\n startKey?: Record<string, unknown>;\n filters?: Record<string, unknown>;\n attributes?: string[];\n execute?: boolean;\n parse?: boolean;\n}\n"],"mappings":"AAAA,SAASA,MAAM,EAAEC,KAAK,QAAQ,kBAAkB;;AAwBhD;AACA","ignoreList":[]}
package/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/**\n * We use this definition to search for a value in any given field that was passed.\n * It works as an \"OR\" condition.\n */\nexport interface DynamoDbContainsFilter {\n fields: string[];\n value: string;\n}\n\nexport interface ProcessStatementArgsParam {\n expression: string;\n attributeNames: Record<string, any>;\n attributeValues: Record<string, any>;\n}\nexport interface ProcessStatementQueryParam {\n [key: string]: any;\n}\nexport interface ProcessStatementParams {\n args: ProcessStatementArgsParam;\n query: ProcessStatementQueryParam;\n}\n\nexport interface ProcessStatementCallable {\n (params: ProcessStatementParams): void;\n}\n\nexport interface Query {\n [key: string]: string;\n}\nexport interface QueryKeyField {\n name: string;\n}\nexport interface QueryKey {\n fields: QueryKeyField[];\n primary?: boolean;\n unique?: boolean;\n name: string;\n}\nexport type QueryKeys = QueryKey[];\n\nexport type QuerySort = Record<string, -1 | 1>;\n\nexport type DbItem<TData extends Record<string, any> = Record<string, any>> = {\n PK: string;\n SK: string;\n GSI1_PK: string;\n GSI1_SK: string;\n TYPE: string;\n data: TData;\n};\n"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./batchRead.js\";\nexport * from \"./batchWrite.js\";\nexport * from \"./types.js\";\n"],"mappings":"AAAA;AACA;AACA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { WriteRequest } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface BatchWriteResponse {\n next?: () => Promise<BatchWriteResponse>;\n $metadata: {\n httpStatusCode: number;\n requestId: string;\n attempts: number;\n totalRetryDelay: number;\n };\n UnprocessedItems?: {\n [table: string]: WriteRequest[];\n };\n}\n\nexport type BatchWriteResult = BatchWriteResponse[];\n\nexport interface IDeleteBatchItem {\n PK: string;\n SK: string;\n}\n\nexport type IPutBatchItem<T = GenericRecord> = {\n PK: string;\n SK: string;\n} & T;\n\nexport interface BatchWriteItem {\n [key: string]: WriteRequest;\n}\n\nexport interface IReadBatchItem {\n PK: string;\n SK: string;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Entity.js\";\nexport * from \"./EntityReadBatch.js\";\nexport * from \"./EntityReadBatchBuilder.js\";\nexport * from \"./EntityWriteBatch.js\";\nexport * from \"./EntityWriteBatchBuilder.js\";\nexport * from \"./getEntity.js\";\nexport * from \"./types.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["queryAll","queryAllClean","queryOne","queryOneClean","queryPerPage"],"sources":["types.ts"],"sourcesContent":["import type { Entity as BaseEntity } from \"dynamodb-toolbox\";\nimport type {\n BatchWriteItem,\n BatchWriteResult,\n IDeleteBatchItem,\n IPutBatchItem\n} from \"~/utils/batch/types.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { TableDef } from \"~/toolbox.js\";\nimport type { ITableWriteBatch } from \"~/utils/table/types.js\";\nimport type { IPutParamsItem, put } from \"~/utils/put.js\";\nimport {\n queryAll,\n queryAllClean,\n type QueryAllParams,\n queryOne,\n queryOneClean,\n type QueryOneParams\n} from \"~/utils/query.js\";\nimport type { get, getClean, GetRecordParamsKeys } from \"~/utils/get.js\";\nimport type { deleteItem, IDeleteItemKeys } from \"~/utils/delete.js\";\nimport type { batchReadAll, BatchReadItem } from \"~/utils/batch/batchRead.js\";\nimport type { IEntityWriteBatchParams } from \"./EntityWriteBatch.js\";\nimport type { IEntityReadBatchParams } from \"./EntityReadBatch.js\";\nimport { queryPerPage } from \"~/utils/index.js\";\n\nexport type IEntityQueryOneParams = Omit<QueryOneParams, \"entity\">;\n\nexport type IEntityQueryAllParams = Omit<QueryAllParams, \"entity\">;\nexport type IEntityQueryPerPageParams = Omit<QueryAllParams, \"entity\">;\n\nexport interface IEntityCreateEntityWriterParams<T = GenericRecord> extends Omit<\n IEntityWriteBatchParams<T>,\n \"entity\"\n> {}\nexport interface IEntityCreateEntityReaderParams extends Omit<IEntityReadBatchParams, \"entity\"> {}\n\nexport type IEntityPutResult = ReturnType<typeof put>;\nexport type IEntityGetResult<T> = ReturnType<typeof get<T>>;\nexport type IEntityGetCleanResult<T> = ReturnType<typeof getClean<T>>;\nexport type IEntityDeleteResult = ReturnType<typeof deleteItem>;\nexport type IEntityQueryOneResult<T> = ReturnType<typeof queryOne<T>>;\nexport type IEntityQueryOneCleanResult<T> = ReturnType<typeof queryOneClean<T>>;\nexport type IEntityQueryAllResult<T> = ReturnType<typeof queryAll<T>>;\nexport type IEntityQueryAllCleanResult<T> = ReturnType<typeof queryAllClean<T>>;\nexport type IEntityQueryPerPageResult<T> = ReturnType<typeof queryPerPage<T>>;\n\nexport interface IEntity<T extends GenericRecord = GenericRecord> {\n readonly entity: BaseEntity;\n readonly name: string;\n readonly table: TableDef;\n createEntityReader(params?: IEntityCreateEntityReaderParams): IEntityReadBatch<T>;\n createEntityWriter(params?: IEntityCreateEntityWriterParams<T>): IEntityWriteBatch<T>;\n createTableWriter(): ITableWriteBatch;\n put(item: IPutParamsItem<T>): IEntityPutResult;\n get<R extends T = T>(keys: GetRecordParamsKeys): IEntityGetResult<R>;\n getClean<R extends T = T>(keys: GetRecordParamsKeys): IEntityGetCleanResult<R>;\n delete(keys: IDeleteItemKeys): IEntityDeleteResult;\n queryOne<R extends T = T>(params: IEntityQueryOneParams): IEntityQueryOneResult<R>;\n queryOneClean<R extends T = T>(params: IEntityQueryOneParams): IEntityQueryOneCleanResult<R>;\n queryAll<R extends T = T>(params: IEntityQueryAllParams): IEntityQueryAllResult<R>;\n queryAllClean<R extends T = T>(params: IEntityQueryAllParams): IEntityQueryAllCleanResult<R>;\n queryPerPage<R extends T = T>(params: IEntityQueryPerPageParams): IEntityQueryPerPageResult<R>;\n}\n\nexport interface IEntityWriteBatchBuilder {\n // readonly entity: Entity;\n put<T extends Record<string, any>>(item: IPutBatchItem<T>): BatchWriteItem;\n delete(item: IDeleteBatchItem): BatchWriteItem;\n}\n\nexport interface IEntityWriteBatch<T = GenericRecord> {\n readonly total: number;\n readonly items: BatchWriteItem[];\n\n put(item: IPutBatchItem<T>): void;\n delete(item: IDeleteBatchItem): void;\n execute(): Promise<BatchWriteResult>;\n combine(items: BatchWriteItem[]): ITableWriteBatch;\n}\n\nexport interface IEntityReadBatchKey {\n PK: string;\n SK: string;\n}\n\nexport interface IEntityReadBatch<T = GenericRecord> {\n readonly total: number;\n readonly items: BatchReadItem[];\n get(input: IEntityReadBatchKey | IEntityReadBatchKey[]): void;\n execute(): ReturnType<typeof batchReadAll<T>>;\n}\n\nexport interface IEntityReadBatchBuilderGetResponse {\n Table: TableDef;\n Key: IEntityReadBatchKey;\n}\n\nexport interface IEntityReadBatchBuilder {\n get(item: IEntityReadBatchKey): IEntityReadBatchBuilderGetResponse;\n}\n"],"mappings":"AAWA,SACIA,QAAQ,EACRC,aAAa,EAEbC,QAAQ,EACRC,aAAa;AAQjB,SAASC,YAAY","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["decodeCursor","encodeCursor"],"sources":["index.ts"],"sourcesContent":["export * from \"./cleanup.js\";\nexport * from \"./createEntity.js\";\nexport * from \"./createTable.js\";\nexport { decodeCursor, encodeCursor } from \"./cursor.js\";\nexport * from \"./get.js\";\nexport * from \"./delete.js\";\nexport * from \"./put.js\";\nexport * from \"./query.js\";\nexport * from \"./scan.js\";\nexport * from \"./sort.js\";\nexport * from \"./batch/index.js\";\nexport * from \"./entity/index.js\";\nexport * from \"./table/index.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAY,EAAEC,YAAY;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Table.js\";\nexport * from \"./TableReadBatch.js\";\nexport * from \"./TableWriteBatch.js\";\nexport * from \"./types.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n BatchWriteItem,\n BatchWriteResult,\n IDeleteBatchItem,\n IPutBatchItem\n} from \"~/utils/batch/types.js\";\nimport type { BaseScanParams, ScanResponse } from \"../scan.js\";\nimport type { Entity } from \"~/toolbox.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { Table } from \"~/toolbox.js\";\n\nexport type ITableScanParams = BaseScanParams;\n\nexport type ITableScanResponse<T> = ScanResponse<T>;\n\nexport interface ITable<\n Name extends string = string,\n PK extends string = string,\n SK extends string = string\n> {\n table: Table<Name, PK, SK>;\n createWriter(): ITableWriteBatch;\n createReader(): ITableReadBatch;\n scan<T>(params: ITableScanParams): Promise<ITableScanResponse<T>>;\n}\n\nexport interface ITableWriteBatch {\n readonly total: number;\n readonly items: BatchWriteItem[];\n put(entity: Entity, item: IPutBatchItem): void;\n delete(entity: Entity, item: IDeleteBatchItem): void;\n execute(): Promise<BatchWriteResult>;\n combine(items: BatchWriteItem[]): ITableWriteBatch;\n}\n\nexport interface ITableReadBatchKey {\n PK: string;\n SK: string;\n}\n\nexport interface ITableReadBatchBuilderGetResponse {\n Table: Table<string, string, string>;\n Key: ITableReadBatchKey;\n}\n\nexport interface ITableReadBatchKey {\n PK: string;\n SK: string;\n}\n\nexport interface ITableReadBatch {\n readonly total: number;\n readonly items: ITableReadBatchBuilderGetResponse[];\n get(entity: Entity, input: ITableReadBatchKey | ITableReadBatchKey[]): void;\n execute<T = GenericRecord>(): Promise<T[]>;\n}\n"],"mappings":"","ignoreList":[]}