dyna-record 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [API Documentation](https://dyna-record.com/)
4
4
 
5
- Dyna-Record is a strongly typed ORM (Object-Relational Mapping) tool designed for modeling and interacting with data stored in DynamoDB in a structured and type-safe manner. It simplifies the process of defining data models (entities), performing CRUD operations, and handling complex queries. To support relational data, dyna-record implements a flavor of the [single-table design pattern](https://aws.amazon.com/blogs/compute/creating-a-single-table-design-with-amazon-dynamodb/) and the [adjacency list design pattern](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html). All operations are [ACID compliant transactions\*](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/transaction-apis.html)\. To enforce data integrity beyond the type system, schema validation is performed at runtime.
5
+ Dyna-Record is a strongly typed Data Modeler and ORM (Object-Relational Mapping) tool designed for modeling and interacting with data stored in DynamoDB in a structured and type-safe manner. It simplifies the process of defining data models (entities), performing CRUD operations, and handling complex queries. To support relational data, dyna-record implements a flavor of the [single-table design pattern](https://aws.amazon.com/blogs/compute/creating-a-single-table-design-with-amazon-dynamodb/) and the [adjacency list design pattern](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html). All operations are [ACID compliant transactions\*](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/transaction-apis.html)\. To enforce data integrity beyond the type system, schema validation is performed at runtime.
6
6
 
7
7
  Note: ACID compliant according to DynamoDB [limitations](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/transaction-apis.html)
8
8
 
@@ -1,5 +1,4 @@
1
- import { type QueryOptions as QueryBuilderOptions } from "./query-utils";
2
- import { type FindByIdOptions, type FindByIdIncludesRes, type QueryOptions, type EntityKeyConditions, type QueryResults, Create, type CreateOptions, type UpdateOptions, type EntityAttributesInstance } from "./operations";
1
+ import { type FindByIdOptions, type FindByIdIncludesRes, type EntityKeyConditions, type QueryResults, Create, type CreateOptions, type UpdateOptions, type EntityAttributesInstance, type IncludedAssociations, type IndexKeyConditions, type OptionsWithoutIndex, type OptionsWithIndex } from "./operations";
3
2
  import type { EntityClass, Optional } from "./types";
4
3
  interface DynaRecordBase {
5
4
  id: string;
@@ -71,9 +70,47 @@ declare abstract class DynaRecord implements DynaRecordBase {
71
70
  * ```
72
71
  */
73
72
  static findById<T extends DynaRecord>(this: EntityClass<T>, id: string, options?: undefined): Promise<Optional<EntityAttributesInstance<T>>>;
74
- static findById<T extends DynaRecord, Opts extends FindByIdOptions<T>>(this: EntityClass<T>, id: string, options?: Opts): Promise<Optional<FindByIdIncludesRes<T, Opts>>>;
73
+ static findById<T extends DynaRecord, Inc extends IncludedAssociations<T> = []>(this: EntityClass<T>, id: string, options: FindByIdOptions<T, Inc>): Promise<Optional<FindByIdIncludesRes<T, Inc>>>;
75
74
  /**
76
- * Query by PartitionKey and optional SortKey/Filter/Index conditions
75
+ * Query an EntityPartition by EntityId and optional SortKey/Filter conditions.
76
+ * QueryByIndex not supported. Use Query with keys if indexName is needed
77
+ * @param {string} id - Entity Id
78
+ * @param {Object=} options - QueryOptions. Supports filter, consistentRead and skCondition. indexName is not supported
79
+ *
80
+ * @example By partition key only
81
+ * ```typescript
82
+ * const user = await User.query("123");
83
+ * ```
84
+ *
85
+ * @example By partition key and sort key exact match
86
+ * ```typescript
87
+ * const user = await User.query("123", { skCondition: "Profile#111" });
88
+ * ```
89
+ *
90
+ * @example By partition key and sort key begins with
91
+ * ```typescript
92
+ * const user = await User.query("123", { skCondition: { $beginsWith: "Profile" } })
93
+ * ```
94
+ *
95
+ * @example With filter (arbitrary example)
96
+ * ```typescript
97
+ * const user = await User.query("123", {
98
+ * filter: {
99
+ * type: "Profile",
100
+ * createdAt: "2023-11-21T12:31:21.148Z"
101
+ * }
102
+ * });
103
+ *
104
+ * @example Query as consistent read
105
+ * ```typescript
106
+ * const user = await User.query("123", { consistentRead: true })
107
+ * ```
108
+ * ```
109
+ */
110
+ static query<T extends DynaRecord>(this: EntityClass<T>, key: string, options?: OptionsWithoutIndex): Promise<QueryResults<T>>;
111
+ /**
112
+ * Query by PartitionKey and optional SortKey/Filter/Index conditions without and index
113
+ * When querying without an index the key conditions must be the PartitionKey and SortKey defined on the entity
77
114
  * @param {Object} key - PartitionKey value and optional SortKey condition. Keys must be attributes defined on the model
78
115
  * @param {Object=} options - QueryBuilderOptions
79
116
  *
@@ -120,50 +157,29 @@ declare abstract class DynaRecord implements DynaRecordBase {
120
157
  *);
121
158
  * ```
122
159
  *
160
+ * @example With a consistent read
161
+ * ```typescript
162
+ * const user = await User.query({ pk: "User#123", consistentRead: true });
163
+ * ```
164
+ */
165
+ static query<T extends DynaRecord>(this: EntityClass<T>, key: EntityKeyConditions<T>, options?: OptionsWithoutIndex): Promise<QueryResults<T>>;
166
+ /**
167
+ * Query by PartitionKey and optional SortKey/Filter/Index conditions with an index
168
+ * When querying on an index, any of the entities attributes can be part of the key condition
169
+ * @param {Object} key - Any attribute defined on the entity that is part of an index's keys
170
+ * @param {Object=} options - QueryBuilderOptions
171
+ *
123
172
  * @example On index
124
173
  * ```typescript
125
174
  * const result = await User.query(
126
175
  * {
127
- * pk: "User#123",
128
- * sk: { $beginsWith: "Profile" }
176
+ * name: "SomeName" // An attribute that is part of the key condition on an iondex
129
177
  * },
130
178
  * { indexName: "myIndex" }
131
179
  * );
132
180
  * ```
133
181
  */
134
- static query<T extends DynaRecord>(this: EntityClass<T>, key: EntityKeyConditions<T>, options?: QueryBuilderOptions): Promise<QueryResults<T>>;
135
- /**
136
- * Query an EntityPartition by EntityId and optional SortKey/Filter conditions.
137
- * QueryByIndex not supported. Use Query with keys if indexName is needed
138
- * @param {string} id - Entity Id
139
- * @param {Object=} options - QueryOptions. Supports filter and skCondition. indexName is not supported
140
- *
141
- * @example By partition key only
142
- * ```typescript
143
- * const user = await User.query("123");
144
- * ```
145
- *
146
- * @example By partition key and sort key exact match
147
- * ```typescript
148
- * const user = await User.query("123", { skCondition: "Profile#111" });
149
- * ```
150
- *
151
- * @example By partition key and sort key begins with
152
- * ```typescript
153
- * const user = await User.query("123", { skCondition: { $beginsWith: "Profile" } })
154
- * ```
155
- *
156
- * @example With filter (arbitrary example)
157
- * ```typescript
158
- * const user = await User.query("123", {
159
- * filter: {
160
- * type: "Profile",
161
- * createdAt: "2023-11-21T12:31:21.148Z"
162
- * }
163
- * });
164
- * ```
165
- */
166
- static query<T extends DynaRecord>(this: EntityClass<T>, id: string, options?: Omit<QueryOptions, "indexName">): Promise<QueryResults<T>>;
182
+ static query<T extends DynaRecord>(this: EntityClass<T>, key: IndexKeyConditions<T>, options: OptionsWithIndex): Promise<QueryResults<T>>;
167
183
  /**
168
184
  * Create an entity. If foreign keys are included in the attributes then links will be demoralized accordingly
169
185
  * @param attributes - Attributes of the model to create
@@ -1 +1 @@
1
- {"version":3,"file":"DynaRecord.d.ts","sourceRoot":"","sources":["../../src/DynaRecord.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,IAAI,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzE,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EAExB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,MAAM,EACN,KAAK,aAAa,EAElB,KAAK,aAAa,EAGlB,KAAK,wBAAwB,EAC9B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGrD,UAAU,cAAc;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,uBAAe,UAAW,YAAW,cAAc;IACjD;;OAEG;IACH,SACgB,EAAE,EAAE,MAAM,CAAC;I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OASG;WACW,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;IAK5C,iBAAiB,IAAI,MAAM;CAGnC;AAED,eAAe,UAAU,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Delete.d.ts","sourceRoot":"","sources":["../../../../src/operations/Delete/Delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAY/C,OAAO,KAAK,EAEV,WAAW,EAEZ,MAAM,aAAa,CAAC;AAErB,OAAO,aAAa,MAAM,kBAAkB,CAAC;AA2B7C;;;;;;;;;GASG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAS7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAiBlC;;;;;;;OAOG;IACU,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgC3C;;;;OAIG;YACW,QAAQ;IA+BtB;;;;OAIG;IACH,OAAO,CAAC,iCAAiC;IASzC;;;OAGG;IACH,OAAO,CAAC,2BAA2B;IAOnC;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAalC;;;OAGG;IACH,OAAO,CAAC,4BAA4B;IAkBpC;;;;OAIG;YACW,iCAAiC;IA2B/C;;;;OAIG;IACH,OAAO,CAAC,uCAAuC;IA2B/C;;;OAGG;IACH,OAAO,CAAC,mCAAmC;IAiB3C;;;OAGG;IACH,OAAO,CAAC,+BAA+B;IAqBvC;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,cAAc;CAcvB;AAED,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"Delete.d.ts","sourceRoot":"","sources":["../../../../src/operations/Delete/Delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAY/C,OAAO,KAAK,EAEV,WAAW,EAEZ,MAAM,aAAa,CAAC;AAErB,OAAO,aAAa,MAAM,kBAAkB,CAAC;AA2B7C;;;;;;;;;GASG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAS7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAiBlC;;;;;;;OAOG;IACU,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgC3C;;;;OAIG;YACW,QAAQ;IAiCtB;;;;OAIG;IACH,OAAO,CAAC,iCAAiC;IASzC;;;OAGG;IACH,OAAO,CAAC,2BAA2B;IAOnC;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAalC;;;OAGG;IACH,OAAO,CAAC,4BAA4B;IAkBpC;;;;OAIG;YACW,iCAAiC;IA2B/C;;;;OAIG;IACH,OAAO,CAAC,uCAAuC;IA2B/C;;;OAGG;IACH,OAAO,CAAC,mCAAmC;IAiB3C;;;OAGG;IACH,OAAO,CAAC,+BAA+B;IAqBvC;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,cAAc;CAcvB;AAED,eAAe,MAAM,CAAC"}
@@ -74,7 +74,9 @@ class Delete extends OperationBase_1.default {
74
74
  * @returns - The item and its associated links denormalized
75
75
  */
76
76
  async preFetch(id) {
77
- const items = await this.EntityClass.query(id);
77
+ const items = await this.EntityClass.query(id, {
78
+ consistentRead: true
79
+ });
78
80
  const prefetchResult = items.reduce((acc, item) => {
79
81
  const isItemSelf = item.id === id && item instanceof this.EntityClass;
80
82
  if (isItemSelf) {
@@ -1,7 +1,7 @@
1
1
  import type DynaRecord from "../../DynaRecord";
2
- import type { EntityClass, Optional } from "../../types";
2
+ import type { Optional } from "../../types";
3
3
  import OperationBase from "../OperationBase";
4
- import type { FindByIdOptions, FindByIdIncludesRes } from "./types";
4
+ import type { FindByIdOptions, FindByIdIncludesRes, IncludedAssociations } from "./types";
5
5
  /**
6
6
  * Facilitates the retrieval of an entity by its identifier (ID) from the database, potentially including its associated entities based on specified relationships.
7
7
  *
@@ -10,8 +10,6 @@ import type { FindByIdOptions, FindByIdIncludesRes } from "./types";
10
10
  * @template T - The type of the entity being retrieved, extending `DynaRecord`.
11
11
  */
12
12
  declare class FindById<T extends DynaRecord> extends OperationBase<T> {
13
- #private;
14
- constructor(Entity: EntityClass<T>);
15
13
  /**
16
14
  * Find an entity by Id and optionally include associations
17
15
  * @param {string} id - Entity Id
@@ -20,7 +18,7 @@ declare class FindById<T extends DynaRecord> extends OperationBase<T> {
20
18
  * @param {string} options.include[].association - The name of the association to include. Must be defined on the model
21
19
  * @returns An entity with optional included associations serialized
22
20
  */
23
- run(id: string, options?: FindByIdOptions<T>): Promise<Optional<T | FindByIdIncludesRes<T, FindByIdOptions<T>>>>;
21
+ run<Inc extends IncludedAssociations<T> = []>(id: string, options?: FindByIdOptions<T, Inc>): Promise<Optional<T | FindByIdIncludesRes<T, Inc>>>;
24
22
  /**
25
23
  * Find an Entity by id without associations
26
24
  * @param {string} id - Entity Id
@@ -1 +1 @@
1
- {"version":3,"file":"FindById.d.ts","sourceRoot":"","sources":["../../../../src/operations/FindById/FindById.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAI/C,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAsB,MAAM,aAAa,CAAC;AAE7E,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EAGpB,MAAM,SAAS,CAAC;AAQjB;;;;;;GAMG;AACH,cAAM,QAAQ,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAG/C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAKlC;;;;;;;OAOG;IACU,GAAG,CACd,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,QAAQ,CAAC,CAAC,GAA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AO,CAAC,+BAA+B;CAaxC;AAED,eAAe,QAAQ,CAAC"}
@@ -17,11 +17,6 @@ const utils_3 = require("../../metadata/utils");
17
17
  * @template T - The type of the entity being retrieved, extending `DynaRecord`.
18
18
  */
19
19
  class FindById extends OperationBase_1.default {
20
- #transactionBuilder;
21
- constructor(Entity) {
22
- super(Entity);
23
- this.#transactionBuilder = new dynamo_utils_1.TransactGetBuilder();
24
- }
25
20
  /**
26
21
  * Find an entity by Id and optionally include associations
27
22
  * @param {string} id - Entity Id
@@ -32,10 +27,15 @@ class FindById extends OperationBase_1.default {
32
27
  */
33
28
  async run(id, options) {
34
29
  if (options?.include === undefined) {
35
- return await this.findByIdOnly(id);
30
+ return await this.findByIdOnly(id, {
31
+ consistentRead: options?.consistentRead
32
+ });
36
33
  }
37
34
  else {
38
- return await this.findByIdWithIncludes(id, options.include);
35
+ return await this.findByIdWithIncludes(id, {
36
+ includedAssociations: options.include,
37
+ consistentRead: options?.consistentRead
38
+ });
39
39
  }
40
40
  }
41
41
  /**
@@ -43,7 +43,7 @@ class FindById extends OperationBase_1.default {
43
43
  * @param {string} id - Entity Id
44
44
  * @returns An entity object or undefined
45
45
  */
46
- async findByIdOnly(id) {
46
+ async findByIdOnly(id, options) {
47
47
  const { name: tableName } = this.tableMetadata;
48
48
  const res = await dynamo_utils_1.DynamoClient.getItem({
49
49
  TableName: tableName,
@@ -51,7 +51,7 @@ class FindById extends OperationBase_1.default {
51
51
  [this.partitionKeyAlias]: this.EntityClass.partitionKeyValue(id),
52
52
  [this.sortKeyAlias]: this.EntityClass.name
53
53
  },
54
- ConsistentRead: true
54
+ ConsistentRead: (0, utils_2.consistentReadVal)(options.consistentRead)
55
55
  });
56
56
  if (res === undefined) {
57
57
  return undefined;
@@ -67,11 +67,12 @@ class FindById extends OperationBase_1.default {
67
67
  * @param {string} includedAssociations[].association - The name of the association to include. Must be defined on the model
68
68
  * @returns An entity with included associations serialized
69
69
  */
70
- async findByIdWithIncludes(id, includedAssociations) {
71
- const includedRelMeta = this.getIncludedRelationships(includedAssociations);
70
+ async findByIdWithIncludes(id, options) {
71
+ const includedRelMeta = this.getIncludedRelationships(options.includedAssociations);
72
72
  const includedTypesFilter = (0, Filters_1.includedRelationshipsFilter)(this.EntityClass.name, includedRelMeta);
73
73
  const queryResults = await this.EntityClass.query(id, {
74
- filter: includedTypesFilter
74
+ filter: includedTypesFilter,
75
+ consistentRead: (0, utils_2.consistentReadVal)(options.consistentRead)
75
76
  });
76
77
  if (queryResults.length === 0)
77
78
  return undefined;
@@ -2,23 +2,25 @@ import type DynaRecord from "../../DynaRecord";
2
2
  import type { EntityAttributesOnly, FunctionFields, RelationshipAttributeNames } from "../types";
3
3
  import { type QueryResult, type QueryResults } from "../Query";
4
4
  /**
5
- * Defines options for the `FindById` operation, allowing specification of additional associations to include in the query result.
6
- *
7
- * @template T - The type of the entity being queried, extending `DynaRecord`.
8
- *
9
- * @property {Array<{ association: RelationshipAttributeNames<T> }>} [include] - An array of association names to be included in the result of the query. Each association name must be a valid relationship attribute name for the entity `T`.
5
+ * An array of objects each describing an entity relationship association to include.
10
6
  */
11
- export interface FindByIdOptions<T extends DynaRecord> {
12
- include?: Array<{
13
- association: RelationshipAttributeNames<T>;
14
- }>;
15
- }
7
+ export type IncludedAssociations<T extends DynaRecord> = Array<{
8
+ association: RelationshipAttributeNames<T>;
9
+ }>;
16
10
  /**
17
- * Represents a list of associations to be included in the query result, derived from the `FindByIdOptions`.
11
+ * Options for the FindById operation.
18
12
  *
19
- * @template T - The type of the entity being queried, extending `DynaRecord`.
13
+ * @template T - The type of the entity.
14
+ * @template Inc - The entity relationships to include in the results
20
15
  */
21
- export type IncludedAssociations<T extends DynaRecord> = NonNullable<FindByIdOptions<T>["include"]>;
16
+ export interface FindByIdOptions<T extends DynaRecord, Inc extends IncludedAssociations<T> = []> {
17
+ include?: Inc;
18
+ /**
19
+ * Whether to use consistent reads for the operation. Defaults to false.
20
+ * @default false
21
+ */
22
+ consistentRead?: boolean;
23
+ }
22
24
  /**
23
25
  * Describes the structure of query results, sorting them into the main entity item and any associated items. Used during processing
24
26
  *
@@ -30,27 +32,22 @@ export interface SortedQueryResults {
30
32
  relatedEntities: QueryResults<DynaRecord>;
31
33
  }
32
34
  /**
33
- * Derives the keys of included associations from `FindByIdOptions`, representing the names of relationships specified to be included in the query result.
34
- *
35
- * @template T - The type of the entity being queried, extending `DynaRecord`.
36
- * @template Opts - The options for the `FindById` operation.
35
+ * Extract the association keys from the include array.
37
36
  */
38
- type IncludedKeys<T extends DynaRecord, Opts extends FindByIdOptions<T>> = Opts extends Required<FindByIdOptions<T>> ? [...NonNullable<Opts>["include"]][number]["association"] : never;
37
+ type IncludedKeys<T extends DynaRecord, Inc extends IncludedAssociations<T> = []> = Inc[number]["association"];
39
38
  /**
40
- * Describes the entity attributes, extending them with any specified included associations for comprehensive query results.
41
- *
42
- * @template T - The type of the entity being queried, extending `DynaRecord`.
43
- * @template P - The properties of the entity `T`.
39
+ * Given an entity type T and a set of keys, produce the output type that augments the
40
+ * entity attributes with included associations.
44
41
  */
45
42
  type EntityKeysWithIncludedAssociations<T extends DynaRecord, P extends keyof T> = {
46
43
  [K in P]: T[K] extends DynaRecord ? EntityAttributesOnly<T> : T[K] extends DynaRecord[] ? Array<EntityAttributesOnly<T[K][number]>> : T[K];
47
44
  };
48
45
  /**
49
- * Represents the result of a `FindById` operation, including the main entity and any specified associated entities.
46
+ * The result type for a FindById operation that includes associations.
50
47
  *
51
- * @template T - The type of the main entity, extending `DynaRecord`.
52
- * @template Opts - The options for the `FindById` operation, specifying included associations.
48
+ * @template T - The type of the entity.
49
+ * @template Inc - The entities relationships of the include array.
53
50
  */
54
- export type FindByIdIncludesRes<T extends DynaRecord, Opts extends FindByIdOptions<T>> = EntityKeysWithIncludedAssociations<T, keyof EntityAttributesOnly<T> | IncludedKeys<T, Opts> | FunctionFields<T>>;
51
+ export type FindByIdIncludesRes<T extends DynaRecord, Inc extends IncludedAssociations<T> = []> = EntityKeysWithIncludedAssociations<T, keyof EntityAttributesOnly<T> | IncludedKeys<T, Inc> | FunctionFields<T>>;
55
52
  export {};
56
53
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/FindById/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EACV,oBAAoB,EACpB,cAAc,EACd,0BAA0B,EAC3B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAE/D;;;;;;GAMG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,UAAU;IACnD,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,WAAW,EAAE,0BAA0B,CAAC,CAAC,CAAC,CAAA;KAAE,CAAC,CAAC;CACjE;AAED;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,UAAU,IAAI,WAAW,CAClE,eAAe,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAC9B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IACjC,eAAe,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC;CAC3C;AAED;;;;;GAKG;AACH,KAAK,YAAY,CAAC,CAAC,SAAS,UAAU,EAAE,IAAI,SAAS,eAAe,CAAC,CAAC,CAAC,IACrE,IAAI,SAAS,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,GACrC,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,GACxD,KAAK,CAAC;AAEZ;;;;;GAKG;AACH,KAAK,kCAAkC,CACrC,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,MAAM,CAAC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MAAM,CAAC,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IACjC,eAAe,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC;CAC3C;AAED;;GAEG;AACH,KAAK,YAAY,CACf,CAAC,SAAS,UAAU,EACpB,GAAG,SAAS,oBAAoB,CAAC,CAAC,CAAC,GAAG,EAAE,IACtC,GAAG,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC;AAE/B;;;GAGG;AACH,KAAK,kCAAkC,CACrC,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,MAAM,CAAC,IACf;KACD,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,GAC7B,oBAAoB,CAAC,CAAC,CAAC,GACvB,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,EAAE,GACvB,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GACzC,CAAC,CAAC,CAAC,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,CAC7B,CAAC,SAAS,UAAU,EACpB,GAAG,SAAS,oBAAoB,CAAC,CAAC,CAAC,GAAG,EAAE,IACtC,kCAAkC,CACpC,CAAC,EACD,MAAM,oBAAoB,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CACzE,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import type DynaRecord from "../../DynaRecord";
2
2
  import { type QueryOptions as QueryBuilderOptions } from "../../query-utils";
3
3
  import OperationBase from "../OperationBase";
4
- import type { EntityKeyConditions, QueryOptions, QueryResults } from "./types";
4
+ import type { EntityQueryKeyConditions, QueryOptions, QueryResults } from "./types";
5
5
  /**
6
6
  * Provides functionality to query entities from the database based on partition key, sort key, and optional filter conditions.
7
7
  *
@@ -16,7 +16,7 @@ declare class Query<T extends DynaRecord> extends OperationBase<T> {
16
16
  * @param options Filter conditions, indexName, or SortKey conditions if querying by keys
17
17
  * @returns Array of Entity or denormalized records
18
18
  */
19
- run(key: string | EntityKeyConditions<T>, options?: QueryBuilderOptions | Omit<QueryOptions, "indexName">): Promise<QueryResults<T>>;
19
+ run(key: string | EntityQueryKeyConditions<T>, options?: QueryBuilderOptions | Omit<QueryOptions, "indexName">): Promise<QueryResults<T>>;
20
20
  /**
21
21
  * Query by PartitionKey and optional SortKey/Filter/Index conditions
22
22
  * @param {Object} key - PartitionKey value and optional SortKey condition. Keys must be attributes defined on the model
@@ -1 +1 @@
1
- {"version":3,"file":"Query.d.ts","sourceRoot":"","sources":["../../../../src/operations/Query/Query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAEL,KAAK,YAAY,IAAI,mBAAmB,EACzC,MAAM,mBAAmB,CAAC;AAI3B,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EAEZ,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB;;;;;;GAMG;AACH,cAAM,KAAK,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;IACxD;;;;;OAKG;IACU,GAAG,CACd,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAAC,CAAC,CAAC,EACpC,OAAO,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,GAC9D,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAQ3B;;;;;;OAMG;YACW,UAAU;IAexB;;;;;;;OAOG;YACW,WAAW;IAyBzB;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,uBAAuB;CAchC;AAED,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"Query.d.ts","sourceRoot":"","sources":["../../../../src/operations/Query/Query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAEL,KAAK,YAAY,IAAI,mBAAmB,EACzC,MAAM,mBAAmB,CAAC;AAI3B,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EACV,wBAAwB,EACxB,YAAY,EAEZ,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB;;;;;;GAMG;AACH,cAAM,KAAK,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;IACxD;;;;;OAKG;IACU,GAAG,CACd,GAAG,EAAE,MAAM,GAAG,wBAAwB,CAAC,CAAC,CAAC,EACzC,OAAO,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,GAC9D,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAQ3B;;;;;;OAMG;YACW,UAAU;IAexB;;;;;;;OAOG;YACW,WAAW;IAyBzB;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,uBAAuB;CAchC;AAED,eAAe,KAAK,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import type DynaRecord from "../../DynaRecord";
2
- import type { KeyConditions, QueryOptions as QueryBuilderOptions, SortKeyCondition } from "../../query-utils";
2
+ import type { KeyConditions as QueryKeyConditions, QueryOptions as QueryBuilderOptions, SortKeyCondition, BeginsWithFilter } from "../../query-utils";
3
+ import type { PartitionKey, SortKey } from "../../types";
3
4
  import type { EntityAttributesInstance } from "../types";
4
5
  /**
5
6
  * Extends the basic query builder options by adding an optional sort key condition for more precise querying capabilities.
@@ -7,20 +8,41 @@ import type { EntityAttributesInstance } from "../types";
7
8
  * @extends QueryBuilderOptions - Base query options provided by the query utilities.
8
9
  * @property {SortKeyCondition?} skCondition - An optional condition for the sort key to further refine the query. This can be an exact match condition or a condition specifying a range or beginning match for the sort key.
9
10
  */
10
- export interface QueryOptions extends QueryBuilderOptions {
11
+ export type QueryOptions = QueryBuilderOptions & {
11
12
  /**
12
13
  * Condition to query sort key by
13
14
  */
14
15
  skCondition?: SortKeyCondition;
15
- }
16
+ };
17
+ /**
18
+ * Options for querying without an index
19
+ */
20
+ export type OptionsWithoutIndex = Omit<QueryOptions, "indexName">;
21
+ /**
22
+ * Options for querying on an index. Consistent reads are not allowed
23
+ */
24
+ export type OptionsWithIndex = QueryBuilderOptions & {
25
+ indexName: string;
26
+ consistentRead?: false;
27
+ };
16
28
  /**
17
- * Defines partition key conditions for querying entities based on their keys. This type is used to specify the conditions under which an entity or a set of entities can be queried from the database.
29
+ * Defines key conditions for querying entities based on their keys.
30
+ *
31
+ * PartitionKey is required, SortKey is optional.
18
32
  *
19
33
  * @template T - The type of the entity being queried, extending `DynaRecord`.
20
34
  * @property {KeyConditions} - Conditions applied to entity keys. Each key in the entity can have conditions such as equality, range conditions, or begins with conditions.
21
35
  */
22
36
  export type EntityKeyConditions<T> = {
23
- [K in keyof T]?: KeyConditions;
37
+ [K in keyof T as T[K] extends PartitionKey ? K : never]-?: string;
38
+ } & {
39
+ [K in keyof T as T[K] extends SortKey ? K : never]?: string | BeginsWithFilter;
40
+ };
41
+ /**
42
+ * Key conditions when querying on an index. Can be any attribute on the entity but must be the keys of the given index
43
+ */
44
+ export type IndexKeyConditions<T> = {
45
+ [K in keyof T]?: QueryKeyConditions;
24
46
  };
25
47
  /**
26
48
  * Asserts that a given type `E` extends `DynaRecord`. If `E` does not extend `DynaRecord`, it resolves to `never`.
@@ -69,4 +91,10 @@ export type QueryResults<T extends DynaRecord> = Array<EntityAttributesInstance<
69
91
  * @template T - The type of the entity being queried, extending `DynaRecord`.
70
92
  */
71
93
  export type QueryResult<T extends DynaRecord> = QueryResults<T>[number];
94
+ /**
95
+ * Key conditions when querying an entity.
96
+ * When querying the main table this will enforce that the keys are the PartitionKey and SortKey from the table
97
+ * When querying an index, this can be any key on the table, but must be the keys for that index
98
+ */
99
+ export type EntityQueryKeyConditions<T> = EntityKeyConditions<T> | IndexKeyConditions<T>;
72
100
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/Query/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EACV,aAAa,EACb,YAAY,IAAI,mBAAmB,EACnC,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,WAAW,YAAa,SAAQ,mBAAmB;IACvD;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;CAChC;AAED;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI;KAClC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,aAAa;CAC/B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,UAAU,GAAG,CAAC,GAAG,KAAK,CAAC;AAEnE;;;;;;;GAOG;AACH,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,UAAU,IAAI,OAAO,CAChE;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,GAC/D,CAAC,GACD,KAAK;CACV,CAAC,MAAM,CAAC,CAAC,EACV,MAAM,CACP,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,UAAU,IAAI;KACtD,CAAC,IAAI,sBAAsB,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GACtE,gBAAgB,CAAC,CAAC,CAAC,GACnB,gBAAgB,CAAC,WAAW,CAAC,CAAC,CA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Promise.all([
124
124
  transactionBuilder.executeTransaction(),
125
125
  this.EntityClass.query(id, {
126
+ consistentRead: true,
126
127
  filter: {
127
128
  type: [
128
129
  this.EntityClass.name,
@@ -26,4 +26,9 @@ export declare const extractForeignKeyFromEntity: <T extends Partial<EntityAttri
26
26
  * @returns
27
27
  */
28
28
  export declare const buildBelongsToLinkKey: (entityClass: EntityClass<DynaRecord>, entityId: string, relMeta: BelongsToOrOwnedByRelationship, foreignKey: string) => DynamoTableItem;
29
+ /**
30
+ * Consistent read value.
31
+ * @default false
32
+ */
33
+ export declare const consistentReadVal: (val?: boolean) => boolean;
29
34
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/operations/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EACV,8BAA8B,EAC9B,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AAQxB,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,UAAU,EACV,QAAQ,EACR,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B,kBAC1B,oBAAoB,EAAE,KACpC,mBAaF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GACtC,CAAC,SAAS,OAAO,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,WAE1C,oBAAoB,UACrB,CAAC,KACR,QAAQ,CAAC,UAAU,CAKrB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,gBACnB,WAAW,CAAC,UAAU,CAAC,YAC1B,MAAM,WACP,8BAA8B,cAC3B,MAAM,KACjB,eAqBF,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/operations/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EACV,8BAA8B,EAC9B,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AAQxB,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,UAAU,EACV,QAAQ,EACR,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B,kBAC1B,oBAAoB,EAAE,KACpC,mBAaF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GACtC,CAAC,SAAS,OAAO,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,WAE1C,oBAAoB,UACrB,CAAC,KACR,QAAQ,CAAC,UAAU,CAKrB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,gBACnB,WAAW,CAAC,UAAU,CAAC,YAC1B,MAAM,WACP,8BAA8B,cAC3B,MAAM,KACjB,eAqBF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,SAAU,OAAO,KAAG,OAEjD,CAAC"}
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.buildBelongsToLinkKey = exports.extractForeignKeyFromEntity = exports.buildEntityRelationshipMetaObj = void 0;
6
+ exports.consistentReadVal = exports.buildBelongsToLinkKey = exports.extractForeignKeyFromEntity = exports.buildEntityRelationshipMetaObj = void 0;
7
7
  const metadata_1 = __importDefault(require("../../metadata"));
8
8
  const utils_1 = require("../../metadata/utils");
9
9
  const utils_2 = require("../../utils");
@@ -64,3 +64,11 @@ const buildBelongsToLinkKey = (entityClass, entityId, relMeta, foreignKey) => {
64
64
  throw new Error("Failed to build BelongsTo key for linked record");
65
65
  };
66
66
  exports.buildBelongsToLinkKey = buildBelongsToLinkKey;
67
+ /**
68
+ * Consistent read value.
69
+ * @default false
70
+ */
71
+ const consistentReadVal = (val) => {
72
+ return val ?? false;
73
+ };
74
+ exports.consistentReadVal = consistentReadVal;
@@ -1 +1 @@
1
- {"version":3,"file":"QueryBuilder.d.ts","sourceRoot":"","sources":["../../../src/query-utils/QueryBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAO/D,OAAO,KAAK,EASV,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,cAAM,YAAY;;gBASJ,KAAK,EAAE,iBAAiB;IAmBpC;;;OAGG;IACI,KAAK,IAAI,iBAAiB;IAuBjC;;;;;OAKG;IACH,OAAO,CAAC,8BAA8B;IAetC;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAgChC;;;;;;;;;OASG;IACH,OAAO,CAAC,YAAY;IAWpB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IASnB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAejB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAyBpB;;;;OAIG;IACH,OAAO,CAAC,QAAQ;IAehB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAanB;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAI1B;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAIrB;;;;OAIG;IACH,OAAO,CAAC,UAAU;CAGnB;AAED,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"QueryBuilder.d.ts","sourceRoot":"","sources":["../../../src/query-utils/QueryBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAO/D,OAAO,KAAK,EASV,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAGjB;;;;GAIG;AACH,cAAM,YAAY;;gBASJ,KAAK,EAAE,iBAAiB;IAmBpC;;;OAGG;IACI,KAAK,IAAI,iBAAiB;IAwBjC;;;;;OAKG;IACH,OAAO,CAAC,8BAA8B;IAetC;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAgChC;;;;;;;;;OASG;IACH,OAAO,CAAC,YAAY;IAWpB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IASnB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAejB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAyBpB;;;;OAIG;IACH,OAAO,CAAC,QAAQ;IAehB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAanB;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAI1B;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAIrB;;;;OAIG;IACH,OAAO,CAAC,UAAU;CAGnB;AAED,eAAe,YAAY,CAAC"}
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const metadata_1 = __importDefault(require("../metadata"));
7
+ const utils_1 = require("../operations/utils");
7
8
  /**
8
9
  * Constructs and formats a DynamoDB query command based on provided key conditions and query options. This class simplifies the creation of complex DynamoDB queries by abstracting the underlying AWS SDK query command structure, particularly handling the construction of key condition expressions, filter expressions, and expression attribute names and values.
9
10
  *
@@ -45,7 +46,8 @@ class QueryBuilder {
45
46
  ...(hasFilter && { FilterExpression: filterParams.expression }),
46
47
  KeyConditionExpression: keyFilter.expression,
47
48
  ExpressionAttributeNames: this.expressionAttributeNames(),
48
- ExpressionAttributeValues: this.expressionAttributeValueParams(keyFilter, filterParams)
49
+ ExpressionAttributeValues: this.expressionAttributeValueParams(keyFilter, filterParams),
50
+ ConsistentRead: (0, utils_1.consistentReadVal)(this.#props.options?.consistentRead)
49
51
  };
50
52
  }
51
53
  /**
@@ -65,15 +65,22 @@ export type AndOrFilter = FilterParams & OrFilter;
65
65
  */
66
66
  export type SortKeyCondition = BeginsWithFilter | NativeScalarAttributeValue;
67
67
  /**
68
- * Specifies additional options for querying items, including optional index name and filter conditions.
68
+ * Specifies additional options for querying items, including optional consistent read, index name and filter conditions.
69
+ *
69
70
  *
70
71
  * @property {string?} indexName - Optional name of the secondary index to use in the query.
71
72
  * @property {FilterParams?} filter - Optional filter conditions to apply to the query.
73
+ * @property {boolean?} consistentRead - Whether to use consistent reads for the operation. Defaults to false. Cannot be used when indexName is provided ([Docs](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html#HowItWorks.ReadConsistency.Strongly))
72
74
  */
73
- export interface QueryOptions {
74
- indexName?: string;
75
+ export type QueryOptions = {
76
+ indexName: string;
75
77
  filter?: FilterParams;
76
- }
78
+ consistentRead?: never;
79
+ } | {
80
+ indexName?: undefined;
81
+ filter?: FilterParams;
82
+ consistentRead?: boolean;
83
+ };
77
84
  /**
78
85
  * Combines key conditions and query options to define the properties for a query command.
79
86
  *
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/query-utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAEzE;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,CAC9B,iBAAiB,CAAC,eAAe,CAAC,EAClC,WAAW,CACZ,CAAC;AAEF;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;IACnD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CACnC,aAAa,EACb,0BAA0B,CAC3B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,WAAW,GACnB,gBAAgB,GAChB,0BAA0B,GAC1B,0BAA0B,EAAE,CAAC;AAE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xB"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dyna-record",
3
- "version": "0.2.4",
4
- "description": "Typescript Object Relational Mapper (ORM) for Dynamo",
3
+ "version": "0.2.5",
4
+ "description": "Typescript Data Modeler and ORM for Dynamo",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {