@eresearchqut/ddb-repository 1.5.8 → 1.13.4
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 +190 -105
- package/dist/index.cjs +478 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +116 -0
- package/dist/index.d.mts +116 -0
- package/dist/index.mjs +474 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +30 -20
- package/dist/DynamoDbRepository.d.ts +0 -50
- package/dist/DynamoDbRepository.js +0 -244
- package/dist/consumed-capacity-middleware.d.ts +0 -10
- package/dist/consumed-capacity-middleware.js +0 -25
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -8
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { ConsumedCapacity, DynamoDBClient, ReturnConsumedCapacity, ServiceInputTypes, ServiceOutputTypes } from "@aws-sdk/client-dynamodb";
|
|
2
|
+
import { InitializeHandler, InitializeHandlerArguments, InitializeHandlerOutput } from "@smithy/types";
|
|
3
|
+
|
|
4
|
+
//#region src/DynamoDbRepository.d.ts
|
|
5
|
+
declare enum FilterOperator {
|
|
6
|
+
EQUALS = "=",
|
|
7
|
+
NOT_EQUALS = "<>",
|
|
8
|
+
GREATER_THAN_OR_EQUALS = ">=",
|
|
9
|
+
GREATER_THAN = ">",
|
|
10
|
+
LESS_THAN = "<",
|
|
11
|
+
LESS_THAN_OR_EQUALS = "<=",
|
|
12
|
+
IN = "IN",
|
|
13
|
+
BETWEEN = "BETWEEN",
|
|
14
|
+
BEGINS_WITH = "BEGINS_WITH",
|
|
15
|
+
CONTAINS = "CONTAINS"
|
|
16
|
+
}
|
|
17
|
+
interface FilterExpression {
|
|
18
|
+
attribute: string;
|
|
19
|
+
value: string | number | boolean | Array<string | number> | [string, string] | [number, number];
|
|
20
|
+
operator: FilterOperator;
|
|
21
|
+
negate?: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface FilterableQuery {
|
|
24
|
+
filterExpressions: Array<FilterExpression>;
|
|
25
|
+
}
|
|
26
|
+
interface ProjectedQuery {
|
|
27
|
+
projectedAttributes: string[];
|
|
28
|
+
}
|
|
29
|
+
interface IndexedQuery {
|
|
30
|
+
index: string;
|
|
31
|
+
}
|
|
32
|
+
interface Query extends Partial<FilterableQuery>, Partial<ProjectedQuery>, Partial<IndexedQuery> {
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
filterExpressions?: Array<FilterExpression>;
|
|
35
|
+
projectedAttributes?: string[];
|
|
36
|
+
index?: string;
|
|
37
|
+
sortOrder?: "ASC" | "DESC";
|
|
38
|
+
limit?: number;
|
|
39
|
+
}
|
|
40
|
+
interface DynamoDbRepositoryOptions {
|
|
41
|
+
client: DynamoDBClient;
|
|
42
|
+
tableName: string;
|
|
43
|
+
hashKey: string;
|
|
44
|
+
rangeKey?: string;
|
|
45
|
+
returnConsumedCapacity?: ReturnConsumedCapacity;
|
|
46
|
+
}
|
|
47
|
+
interface PageResult<T> {
|
|
48
|
+
items: Array<T>;
|
|
49
|
+
cursor?: string;
|
|
50
|
+
}
|
|
51
|
+
declare class DynamoDbRepository<K, T> {
|
|
52
|
+
private readonly dynamoDBClient;
|
|
53
|
+
private readonly tableName;
|
|
54
|
+
private readonly hashKey;
|
|
55
|
+
private readonly rangKey?;
|
|
56
|
+
private readonly returnConsumedCapacity;
|
|
57
|
+
constructor(options: DynamoDbRepositoryOptions);
|
|
58
|
+
getItem: (key: K) => Promise<T | undefined>;
|
|
59
|
+
putItem: (key: K, record: T) => Promise<T>;
|
|
60
|
+
deleteItem: (key: K) => Promise<T | undefined>;
|
|
61
|
+
updateItem: (key: K, updates: Partial<T>, remove?: string[]) => Promise<T | undefined>;
|
|
62
|
+
getItems: (query: Query) => Promise<Array<T> | undefined>;
|
|
63
|
+
getItemsPage: (query: Query & {
|
|
64
|
+
cursor?: string;
|
|
65
|
+
}) => Promise<PageResult<T>>;
|
|
66
|
+
batchGetItems: (keys: K[], projectedQuery?: ProjectedQuery) => Promise<Array<T | undefined>>;
|
|
67
|
+
batchWriteItems: (puts: {
|
|
68
|
+
key: K;
|
|
69
|
+
item: T;
|
|
70
|
+
}[], deletes: K[]) => Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/consumed-capacity-middleware.d.ts
|
|
74
|
+
interface ConsumedCapacityDetail {
|
|
75
|
+
ReturnConsumedCapacity: ReturnConsumedCapacity | undefined;
|
|
76
|
+
ConsumedCapacity: ConsumedCapacity | ConsumedCapacity[] | undefined;
|
|
77
|
+
}
|
|
78
|
+
interface ConsumedCapacityMiddlewareConfig {
|
|
79
|
+
onConsumedCapacity: (consumedCapacity: ConsumedCapacityDetail) => Promise<unknown>;
|
|
80
|
+
}
|
|
81
|
+
declare const consumedCapacityMiddleware: (consumedCapacityMiddlewareConfig: ConsumedCapacityMiddlewareConfig) => (next: InitializeHandler<ServiceInputTypes, ServiceOutputTypes>) => (args: InitializeHandlerArguments<ServiceInputTypes>) => Promise<InitializeHandlerOutput<ServiceOutputTypes>>;
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/JsonPointerRepository.d.ts
|
|
84
|
+
type JsonPointerValue = string | number | boolean | null;
|
|
85
|
+
interface JsonPointerRepositoryOptions {
|
|
86
|
+
client: DynamoDBClient;
|
|
87
|
+
tableName: string;
|
|
88
|
+
idKey?: string;
|
|
89
|
+
pointerKey?: string;
|
|
90
|
+
valueKey?: string;
|
|
91
|
+
returnConsumedCapacity?: ReturnConsumedCapacity;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Stores JSON documents as individual per-pointer DynamoDB items addressed by JSON Pointer (RFC 6901).
|
|
95
|
+
*
|
|
96
|
+
* Only JSON objects are supported as the root document (`T extends Record<string, unknown>`).
|
|
97
|
+
* Root arrays and primitives are not supported. Documents must contain at least one leaf value;
|
|
98
|
+
* empty objects and empty arrays are not supported.
|
|
99
|
+
*/
|
|
100
|
+
declare class JsonPointerRepository<T extends Record<string, unknown>> {
|
|
101
|
+
private readonly repository;
|
|
102
|
+
private readonly idKey;
|
|
103
|
+
private readonly pointerKey;
|
|
104
|
+
private readonly valueKey;
|
|
105
|
+
constructor(options: JsonPointerRepositoryOptions);
|
|
106
|
+
putDocument: (id: string, document: T) => Promise<void>;
|
|
107
|
+
getDocument: (id: string) => Promise<T | undefined>;
|
|
108
|
+
getAttribute: <V = JsonPointerValue>(id: string, pointer: string) => Promise<V | undefined>;
|
|
109
|
+
putAttribute: (id: string, pointer: string, value: JsonPointerValue) => Promise<void>;
|
|
110
|
+
deleteAttribute: (id: string, pointer: string) => Promise<void>;
|
|
111
|
+
deleteDocument: (id: string) => Promise<void>;
|
|
112
|
+
patchDocument: (id: string, updates: Record<string, JsonPointerValue | undefined>) => Promise<void>;
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
115
|
+
export { type ConsumedCapacityDetail, type ConsumedCapacityMiddlewareConfig, DynamoDbRepository, type DynamoDbRepositoryOptions, type FilterExpression, FilterOperator, type FilterableQuery, type IndexedQuery, JsonPointerRepository, type JsonPointerRepositoryOptions, type JsonPointerValue, type PageResult, type ProjectedQuery, type Query, consumedCapacityMiddleware };
|
|
116
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { ConsumedCapacity, DynamoDBClient, ReturnConsumedCapacity, ServiceInputTypes, ServiceOutputTypes } from "@aws-sdk/client-dynamodb";
|
|
2
|
+
import { InitializeHandler, InitializeHandlerArguments, InitializeHandlerOutput } from "@smithy/types";
|
|
3
|
+
|
|
4
|
+
//#region src/DynamoDbRepository.d.ts
|
|
5
|
+
declare enum FilterOperator {
|
|
6
|
+
EQUALS = "=",
|
|
7
|
+
NOT_EQUALS = "<>",
|
|
8
|
+
GREATER_THAN_OR_EQUALS = ">=",
|
|
9
|
+
GREATER_THAN = ">",
|
|
10
|
+
LESS_THAN = "<",
|
|
11
|
+
LESS_THAN_OR_EQUALS = "<=",
|
|
12
|
+
IN = "IN",
|
|
13
|
+
BETWEEN = "BETWEEN",
|
|
14
|
+
BEGINS_WITH = "BEGINS_WITH",
|
|
15
|
+
CONTAINS = "CONTAINS"
|
|
16
|
+
}
|
|
17
|
+
interface FilterExpression {
|
|
18
|
+
attribute: string;
|
|
19
|
+
value: string | number | boolean | Array<string | number> | [string, string] | [number, number];
|
|
20
|
+
operator: FilterOperator;
|
|
21
|
+
negate?: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface FilterableQuery {
|
|
24
|
+
filterExpressions: Array<FilterExpression>;
|
|
25
|
+
}
|
|
26
|
+
interface ProjectedQuery {
|
|
27
|
+
projectedAttributes: string[];
|
|
28
|
+
}
|
|
29
|
+
interface IndexedQuery {
|
|
30
|
+
index: string;
|
|
31
|
+
}
|
|
32
|
+
interface Query extends Partial<FilterableQuery>, Partial<ProjectedQuery>, Partial<IndexedQuery> {
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
filterExpressions?: Array<FilterExpression>;
|
|
35
|
+
projectedAttributes?: string[];
|
|
36
|
+
index?: string;
|
|
37
|
+
sortOrder?: "ASC" | "DESC";
|
|
38
|
+
limit?: number;
|
|
39
|
+
}
|
|
40
|
+
interface DynamoDbRepositoryOptions {
|
|
41
|
+
client: DynamoDBClient;
|
|
42
|
+
tableName: string;
|
|
43
|
+
hashKey: string;
|
|
44
|
+
rangeKey?: string;
|
|
45
|
+
returnConsumedCapacity?: ReturnConsumedCapacity;
|
|
46
|
+
}
|
|
47
|
+
interface PageResult<T> {
|
|
48
|
+
items: Array<T>;
|
|
49
|
+
cursor?: string;
|
|
50
|
+
}
|
|
51
|
+
declare class DynamoDbRepository<K, T> {
|
|
52
|
+
private readonly dynamoDBClient;
|
|
53
|
+
private readonly tableName;
|
|
54
|
+
private readonly hashKey;
|
|
55
|
+
private readonly rangKey?;
|
|
56
|
+
private readonly returnConsumedCapacity;
|
|
57
|
+
constructor(options: DynamoDbRepositoryOptions);
|
|
58
|
+
getItem: (key: K) => Promise<T | undefined>;
|
|
59
|
+
putItem: (key: K, record: T) => Promise<T>;
|
|
60
|
+
deleteItem: (key: K) => Promise<T | undefined>;
|
|
61
|
+
updateItem: (key: K, updates: Partial<T>, remove?: string[]) => Promise<T | undefined>;
|
|
62
|
+
getItems: (query: Query) => Promise<Array<T> | undefined>;
|
|
63
|
+
getItemsPage: (query: Query & {
|
|
64
|
+
cursor?: string;
|
|
65
|
+
}) => Promise<PageResult<T>>;
|
|
66
|
+
batchGetItems: (keys: K[], projectedQuery?: ProjectedQuery) => Promise<Array<T | undefined>>;
|
|
67
|
+
batchWriteItems: (puts: {
|
|
68
|
+
key: K;
|
|
69
|
+
item: T;
|
|
70
|
+
}[], deletes: K[]) => Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/consumed-capacity-middleware.d.ts
|
|
74
|
+
interface ConsumedCapacityDetail {
|
|
75
|
+
ReturnConsumedCapacity: ReturnConsumedCapacity | undefined;
|
|
76
|
+
ConsumedCapacity: ConsumedCapacity | ConsumedCapacity[] | undefined;
|
|
77
|
+
}
|
|
78
|
+
interface ConsumedCapacityMiddlewareConfig {
|
|
79
|
+
onConsumedCapacity: (consumedCapacity: ConsumedCapacityDetail) => Promise<unknown>;
|
|
80
|
+
}
|
|
81
|
+
declare const consumedCapacityMiddleware: (consumedCapacityMiddlewareConfig: ConsumedCapacityMiddlewareConfig) => (next: InitializeHandler<ServiceInputTypes, ServiceOutputTypes>) => (args: InitializeHandlerArguments<ServiceInputTypes>) => Promise<InitializeHandlerOutput<ServiceOutputTypes>>;
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/JsonPointerRepository.d.ts
|
|
84
|
+
type JsonPointerValue = string | number | boolean | null;
|
|
85
|
+
interface JsonPointerRepositoryOptions {
|
|
86
|
+
client: DynamoDBClient;
|
|
87
|
+
tableName: string;
|
|
88
|
+
idKey?: string;
|
|
89
|
+
pointerKey?: string;
|
|
90
|
+
valueKey?: string;
|
|
91
|
+
returnConsumedCapacity?: ReturnConsumedCapacity;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Stores JSON documents as individual per-pointer DynamoDB items addressed by JSON Pointer (RFC 6901).
|
|
95
|
+
*
|
|
96
|
+
* Only JSON objects are supported as the root document (`T extends Record<string, unknown>`).
|
|
97
|
+
* Root arrays and primitives are not supported. Documents must contain at least one leaf value;
|
|
98
|
+
* empty objects and empty arrays are not supported.
|
|
99
|
+
*/
|
|
100
|
+
declare class JsonPointerRepository<T extends Record<string, unknown>> {
|
|
101
|
+
private readonly repository;
|
|
102
|
+
private readonly idKey;
|
|
103
|
+
private readonly pointerKey;
|
|
104
|
+
private readonly valueKey;
|
|
105
|
+
constructor(options: JsonPointerRepositoryOptions);
|
|
106
|
+
putDocument: (id: string, document: T) => Promise<void>;
|
|
107
|
+
getDocument: (id: string) => Promise<T | undefined>;
|
|
108
|
+
getAttribute: <V = JsonPointerValue>(id: string, pointer: string) => Promise<V | undefined>;
|
|
109
|
+
putAttribute: (id: string, pointer: string, value: JsonPointerValue) => Promise<void>;
|
|
110
|
+
deleteAttribute: (id: string, pointer: string) => Promise<void>;
|
|
111
|
+
deleteDocument: (id: string) => Promise<void>;
|
|
112
|
+
patchDocument: (id: string, updates: Record<string, JsonPointerValue | undefined>) => Promise<void>;
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
115
|
+
export { type ConsumedCapacityDetail, type ConsumedCapacityMiddlewareConfig, DynamoDbRepository, type DynamoDbRepositoryOptions, type FilterExpression, FilterOperator, type FilterableQuery, type IndexedQuery, JsonPointerRepository, type JsonPointerRepositoryOptions, type JsonPointerValue, type PageResult, type ProjectedQuery, type Query, consumedCapacityMiddleware };
|
|
116
|
+
//# sourceMappingURL=index.d.mts.map
|