@infra-blocks/aws-dynamodb 0.63.0 → 0.64.0-alpha.1

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.
@@ -1,4 +1,5 @@
1
1
  export * from "./condition/index.js";
2
2
  export * from "./key-condition.js";
3
3
  export * from "./operands/index.js";
4
+ export * from "./projection.js";
4
5
  export * from "./update/index.js";
@@ -17,5 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./condition/index.js"), exports);
18
18
  __exportStar(require("./key-condition.js"), exports);
19
19
  __exportStar(require("./operands/index.js"), exports);
20
+ __exportStar(require("./projection.js"), exports);
20
21
  __exportStar(require("./update/index.js"), exports);
21
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/commands/expressions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,qDAAmC;AACnC,sDAAoC;AACpC,oDAAkC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/commands/expressions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,qDAAmC;AACnC,sDAAoC;AACpC,kDAAgC;AAChC,oDAAkC"}
@@ -0,0 +1,21 @@
1
+ import type { AttributeNames } from "../attributes/names.js";
2
+ import { type RawPath } from "./operands/index.js";
3
+ export type ProjectionExpressionParams = ReadonlyArray<RawPath>;
4
+ export type ProjectionExpression = {
5
+ stringify(params: {
6
+ names: AttributeNames;
7
+ }): string;
8
+ };
9
+ export declare const ProjectionExpression: {
10
+ /**
11
+ * Constructs a {@link ProjectionExpression} from the provided {@link ProjectionExpressionParams}.
12
+ *
13
+ * Note that an empty expression is an invalid value for the DynamoDB API. To catch this
14
+ * mistake earlier, this function will throw if the provided list of paths is empty.
15
+ *
16
+ * @param expressionParams - The list of paths to include in the projection expression.
17
+ *
18
+ * @returns The {@link ProjectionExpression} corresponding to the provided {@link ProjectionExpressionParams}.
19
+ */
20
+ from(expressionParams: ProjectionExpressionParams): ProjectionExpression;
21
+ };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ProjectionExpression = void 0;
7
+ const node_assert_1 = __importDefault(require("node:assert"));
8
+ const index_js_1 = require("./operands/index.js");
9
+ exports.ProjectionExpression = {
10
+ /**
11
+ * Constructs a {@link ProjectionExpression} from the provided {@link ProjectionExpressionParams}.
12
+ *
13
+ * Note that an empty expression is an invalid value for the DynamoDB API. To catch this
14
+ * mistake earlier, this function will throw if the provided list of paths is empty.
15
+ *
16
+ * @param expressionParams - The list of paths to include in the projection expression.
17
+ *
18
+ * @returns The {@link ProjectionExpression} corresponding to the provided {@link ProjectionExpressionParams}.
19
+ */
20
+ from(expressionParams) {
21
+ (0, node_assert_1.default)(expressionParams.length > 0, "expression params cannot be empty");
22
+ return {
23
+ stringify(stringifyParams) {
24
+ const { names } = stringifyParams;
25
+ const substitutions = [];
26
+ for (const path of expressionParams) {
27
+ substitutions.push(index_js_1.Path.normalize(path).substitute({ names }));
28
+ }
29
+ return substitutions.join(",");
30
+ },
31
+ };
32
+ },
33
+ };
34
+ //# sourceMappingURL=projection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection.js","sourceRoot":"","sources":["../../../../src/commands/expressions/projection.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAiC;AAEjC,kDAAyD;AAQ5C,QAAA,oBAAoB,GAAG;IAClC;;;;;;;;;OASG;IACH,IAAI,CAAC,gBAA4C;QAC/C,IAAA,qBAAM,EAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,mCAAmC,CAAC,CAAC;QAEzE,OAAO;YACL,SAAS,CAAC,eAAe;gBACvB,MAAM,EAAE,KAAK,EAAE,GAAG,eAAe,CAAC;gBAClC,MAAM,aAAa,GAAG,EAAE,CAAC;gBACzB,KAAK,MAAM,IAAI,IAAI,gBAAgB,EAAE,CAAC;oBACpC,aAAa,CAAC,IAAI,CAAC,eAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;gBACjE,CAAC;gBACD,OAAO,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACjC,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import type { GetCommandInput } from "@aws-sdk/lib-dynamodb";
2
2
  import type { KeyAttributes } from "../../types.js";
3
+ import { type ProjectionExpressionParams } from "../expressions/projection.js";
3
4
  /**
4
5
  * The input required to call the GetItem API.
5
6
  */
@@ -15,6 +16,10 @@ export interface GetItemInput<K extends KeyAttributes = KeyAttributes> {
15
16
  * is part of the table's primary key. No more than 2 fields are expected here.
16
17
  */
17
18
  key: K;
19
+ /**
20
+ * The projection applied to the return item, if any.
21
+ */
22
+ projection?: ProjectionExpressionParams;
18
23
  }
19
24
  export declare const GetItemInput: {
20
25
  encode: typeof encode;
@@ -1,14 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GetItemInput = void 0;
4
+ const names_js_1 = require("../attributes/names.js");
5
+ const projection_js_1 = require("../expressions/projection.js");
4
6
  exports.GetItemInput = {
5
7
  encode,
6
8
  };
7
9
  function encode(input) {
8
- const key = input.key;
9
- return {
10
+ const result = {
10
11
  TableName: input.table,
11
- Key: key,
12
+ Key: input.key,
12
13
  };
14
+ if (input.projection != null) {
15
+ // There should be no values.
16
+ const names = names_js_1.AttributeNames.create();
17
+ const expression = projection_js_1.ProjectionExpression.from(input.projection).stringify({
18
+ names,
19
+ });
20
+ result.ProjectionExpression = expression;
21
+ result.ExpressionAttributeNames = names.getSubstitutions();
22
+ }
23
+ return result;
13
24
  }
14
25
  //# sourceMappingURL=get-item.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-item.js","sourceRoot":"","sources":["../../../../src/commands/inputs/get-item.ts"],"names":[],"mappings":";;;AAoBa,QAAA,YAAY,GAAG;IAC1B,MAAM;CACP,CAAC;AAEF,SAAS,MAAM,CACb,KAAsB;IAEtB,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;IACtB,OAAO;QACL,SAAS,EAAE,KAAK,CAAC,KAAK;QACtB,GAAG,EAAE,GAAG;KACT,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"get-item.js","sourceRoot":"","sources":["../../../../src/commands/inputs/get-item.ts"],"names":[],"mappings":";;;AAEA,qDAAwD;AACxD,gEAGsC;AAuBzB,QAAA,YAAY,GAAG;IAC1B,MAAM;CACP,CAAC;AAEF,SAAS,MAAM,CACb,KAAsB;IAEtB,MAAM,MAAM,GAAoB;QAC9B,SAAS,EAAE,KAAK,CAAC,KAAK;QACtB,GAAG,EAAE,KAAK,CAAC,GAAG;KACf,CAAC;IAEF,IAAI,KAAK,CAAC,UAAU,IAAI,IAAI,EAAE,CAAC;QAC7B,6BAA6B;QAC7B,MAAM,KAAK,GAAG,yBAAc,CAAC,MAAM,EAAE,CAAC;QACtC,MAAM,UAAU,GAAG,oCAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC;YACvE,KAAK;SACN,CAAC,CAAC;QACH,MAAM,CAAC,oBAAoB,GAAG,UAAU,CAAC;QACzC,MAAM,CAAC,wBAAwB,GAAG,KAAK,CAAC,gBAAgB,EAAE,CAAC;IAC7D,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export * from "./condition/index.js";
2
2
  export * from "./key-condition.js";
3
3
  export * from "./operands/index.js";
4
+ export * from "./projection.js";
4
5
  export * from "./update/index.js";
@@ -1,5 +1,6 @@
1
1
  export * from "./condition/index.js";
2
2
  export * from "./key-condition.js";
3
3
  export * from "./operands/index.js";
4
+ export * from "./projection.js";
4
5
  export * from "./update/index.js";
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/commands/expressions/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/commands/expressions/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { AttributeNames } from "../attributes/names.js";
2
+ import { type RawPath } from "./operands/index.js";
3
+ export type ProjectionExpressionParams = ReadonlyArray<RawPath>;
4
+ export type ProjectionExpression = {
5
+ stringify(params: {
6
+ names: AttributeNames;
7
+ }): string;
8
+ };
9
+ export declare const ProjectionExpression: {
10
+ /**
11
+ * Constructs a {@link ProjectionExpression} from the provided {@link ProjectionExpressionParams}.
12
+ *
13
+ * Note that an empty expression is an invalid value for the DynamoDB API. To catch this
14
+ * mistake earlier, this function will throw if the provided list of paths is empty.
15
+ *
16
+ * @param expressionParams - The list of paths to include in the projection expression.
17
+ *
18
+ * @returns The {@link ProjectionExpression} corresponding to the provided {@link ProjectionExpressionParams}.
19
+ */
20
+ from(expressionParams: ProjectionExpressionParams): ProjectionExpression;
21
+ };
@@ -0,0 +1,28 @@
1
+ import assert from "node:assert";
2
+ import { Path } from "./operands/index.js";
3
+ export const ProjectionExpression = {
4
+ /**
5
+ * Constructs a {@link ProjectionExpression} from the provided {@link ProjectionExpressionParams}.
6
+ *
7
+ * Note that an empty expression is an invalid value for the DynamoDB API. To catch this
8
+ * mistake earlier, this function will throw if the provided list of paths is empty.
9
+ *
10
+ * @param expressionParams - The list of paths to include in the projection expression.
11
+ *
12
+ * @returns The {@link ProjectionExpression} corresponding to the provided {@link ProjectionExpressionParams}.
13
+ */
14
+ from(expressionParams) {
15
+ assert(expressionParams.length > 0, "expression params cannot be empty");
16
+ return {
17
+ stringify(stringifyParams) {
18
+ const { names } = stringifyParams;
19
+ const substitutions = [];
20
+ for (const path of expressionParams) {
21
+ substitutions.push(Path.normalize(path).substitute({ names }));
22
+ }
23
+ return substitutions.join(",");
24
+ },
25
+ };
26
+ },
27
+ };
28
+ //# sourceMappingURL=projection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection.js","sourceRoot":"","sources":["../../../../src/commands/expressions/projection.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAE,IAAI,EAAgB,MAAM,qBAAqB,CAAC;AAQzD,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC;;;;;;;;;OASG;IACH,IAAI,CAAC,gBAA4C;QAC/C,MAAM,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,mCAAmC,CAAC,CAAC;QAEzE,OAAO;YACL,SAAS,CAAC,eAAe;gBACvB,MAAM,EAAE,KAAK,EAAE,GAAG,eAAe,CAAC;gBAClC,MAAM,aAAa,GAAG,EAAE,CAAC;gBACzB,KAAK,MAAM,IAAI,IAAI,gBAAgB,EAAE,CAAC;oBACpC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;gBACjE,CAAC;gBACD,OAAO,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACjC,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import type { GetCommandInput } from "@aws-sdk/lib-dynamodb";
2
2
  import type { KeyAttributes } from "../../types.js";
3
+ import { type ProjectionExpressionParams } from "../expressions/projection.js";
3
4
  /**
4
5
  * The input required to call the GetItem API.
5
6
  */
@@ -15,6 +16,10 @@ export interface GetItemInput<K extends KeyAttributes = KeyAttributes> {
15
16
  * is part of the table's primary key. No more than 2 fields are expected here.
16
17
  */
17
18
  key: K;
19
+ /**
20
+ * The projection applied to the return item, if any.
21
+ */
22
+ projection?: ProjectionExpressionParams;
18
23
  }
19
24
  export declare const GetItemInput: {
20
25
  encode: typeof encode;
@@ -1,11 +1,22 @@
1
+ import { AttributeNames } from "../attributes/names.js";
2
+ import { ProjectionExpression, } from "../expressions/projection.js";
1
3
  export const GetItemInput = {
2
4
  encode,
3
5
  };
4
6
  function encode(input) {
5
- const key = input.key;
6
- return {
7
+ const result = {
7
8
  TableName: input.table,
8
- Key: key,
9
+ Key: input.key,
9
10
  };
11
+ if (input.projection != null) {
12
+ // There should be no values.
13
+ const names = AttributeNames.create();
14
+ const expression = ProjectionExpression.from(input.projection).stringify({
15
+ names,
16
+ });
17
+ result.ProjectionExpression = expression;
18
+ result.ExpressionAttributeNames = names.getSubstitutions();
19
+ }
20
+ return result;
10
21
  }
11
22
  //# sourceMappingURL=get-item.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-item.js","sourceRoot":"","sources":["../../../../src/commands/inputs/get-item.ts"],"names":[],"mappings":"AAoBA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,MAAM;CACP,CAAC;AAEF,SAAS,MAAM,CACb,KAAsB;IAEtB,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;IACtB,OAAO;QACL,SAAS,EAAE,KAAK,CAAC,KAAK;QACtB,GAAG,EAAE,GAAG;KACT,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"get-item.js","sourceRoot":"","sources":["../../../../src/commands/inputs/get-item.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EACL,oBAAoB,GAErB,MAAM,8BAA8B,CAAC;AAuBtC,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,MAAM;CACP,CAAC;AAEF,SAAS,MAAM,CACb,KAAsB;IAEtB,MAAM,MAAM,GAAoB;QAC9B,SAAS,EAAE,KAAK,CAAC,KAAK;QACtB,GAAG,EAAE,KAAK,CAAC,GAAG;KACf,CAAC;IAEF,IAAI,KAAK,CAAC,UAAU,IAAI,IAAI,EAAE,CAAC;QAC7B,6BAA6B;QAC7B,MAAM,KAAK,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC;QACtC,MAAM,UAAU,GAAG,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC;YACvE,KAAK;SACN,CAAC,CAAC;QACH,MAAM,CAAC,oBAAoB,GAAG,UAAU,CAAC;QACzC,MAAM,CAAC,wBAAwB,GAAG,KAAK,CAAC,gBAAgB,EAAE,CAAC;IAC7D,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infra-blocks/aws-dynamodb",
3
- "version": "0.63.0",
3
+ "version": "0.64.0-alpha.1",
4
4
  "description": "A convenience wrapper over @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb.",
5
5
  "keywords": [
6
6
  "aws",
@@ -41,6 +41,7 @@
41
41
  "test:unit": "mocha --config test/unit/.mocharc.cjs 'test/unit/**/*.spec.ts'"
42
42
  },
43
43
  "devDependencies": {
44
+ "@aws-sdk/util-dynamodb": "^3.995.0",
44
45
  "@biomejs/biome": "^2.1.2",
45
46
  "@infra-blocks/iter": "^0.2.7",
46
47
  "@infra-blocks/node-console-logger": "^0.3.1",