@effect-aws/dynamodb 1.0.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 (53) hide show
  1. package/DynamoDBDocumentClientInstance/package.json +6 -0
  2. package/DynamoDBDocumentService/package.json +6 -0
  3. package/DynamoDBDocumentServiceConfig/package.json +6 -0
  4. package/DynamoDBStore/package.json +6 -0
  5. package/LICENSE +19 -0
  6. package/README.md +65 -0
  7. package/dist/cjs/DynamoDBDocumentClientInstance.d.ts +25 -0
  8. package/dist/cjs/DynamoDBDocumentClientInstance.d.ts.map +1 -0
  9. package/dist/cjs/DynamoDBDocumentClientInstance.js +54 -0
  10. package/dist/cjs/DynamoDBDocumentClientInstance.js.map +1 -0
  11. package/dist/cjs/DynamoDBDocumentService.d.ts +97 -0
  12. package/dist/cjs/DynamoDBDocumentService.d.ts.map +1 -0
  13. package/dist/cjs/DynamoDBDocumentService.js +68 -0
  14. package/dist/cjs/DynamoDBDocumentService.js.map +1 -0
  15. package/dist/cjs/DynamoDBDocumentServiceConfig.d.ts +25 -0
  16. package/dist/cjs/DynamoDBDocumentServiceConfig.d.ts.map +1 -0
  17. package/dist/cjs/DynamoDBDocumentServiceConfig.js +28 -0
  18. package/dist/cjs/DynamoDBDocumentServiceConfig.js.map +1 -0
  19. package/dist/cjs/DynamoDBStore.d.ts +82 -0
  20. package/dist/cjs/DynamoDBStore.d.ts.map +1 -0
  21. package/dist/cjs/DynamoDBStore.js +57 -0
  22. package/dist/cjs/DynamoDBStore.js.map +1 -0
  23. package/dist/cjs/index.d.ts +44 -0
  24. package/dist/cjs/index.d.ts.map +1 -0
  25. package/dist/cjs/index.js +56 -0
  26. package/dist/cjs/index.js.map +1 -0
  27. package/dist/dts/DynamoDBDocumentClientInstance.d.ts +25 -0
  28. package/dist/dts/DynamoDBDocumentClientInstance.d.ts.map +1 -0
  29. package/dist/dts/DynamoDBDocumentService.d.ts +97 -0
  30. package/dist/dts/DynamoDBDocumentService.d.ts.map +1 -0
  31. package/dist/dts/DynamoDBDocumentServiceConfig.d.ts +25 -0
  32. package/dist/dts/DynamoDBDocumentServiceConfig.d.ts.map +1 -0
  33. package/dist/dts/DynamoDBStore.d.ts +82 -0
  34. package/dist/dts/DynamoDBStore.d.ts.map +1 -0
  35. package/dist/dts/index.d.ts +44 -0
  36. package/dist/dts/index.d.ts.map +1 -0
  37. package/dist/esm/DynamoDBDocumentClientInstance.js +27 -0
  38. package/dist/esm/DynamoDBDocumentClientInstance.js.map +1 -0
  39. package/dist/esm/DynamoDBDocumentService.js +41 -0
  40. package/dist/esm/DynamoDBDocumentService.js.map +1 -0
  41. package/dist/esm/DynamoDBDocumentServiceConfig.js +24 -0
  42. package/dist/esm/DynamoDBDocumentServiceConfig.js.map +1 -0
  43. package/dist/esm/DynamoDBStore.js +53 -0
  44. package/dist/esm/DynamoDBStore.js.map +1 -0
  45. package/dist/esm/index.js +27 -0
  46. package/dist/esm/index.js.map +1 -0
  47. package/dist/esm/package.json +4 -0
  48. package/package.json +73 -0
  49. package/src/DynamoDBDocumentClientInstance.ts +34 -0
  50. package/src/DynamoDBDocumentService.ts +377 -0
  51. package/src/DynamoDBDocumentServiceConfig.ts +43 -0
  52. package/src/DynamoDBStore.ts +131 -0
  53. package/src/index.ts +50 -0
@@ -0,0 +1,4 @@
1
+ {
2
+ "type": "module",
3
+ "sideEffects": []
4
+ }
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@effect-aws/dynamodb",
3
+ "version": "1.0.0",
4
+ "description": "Effectful AWS DynamoDB library & functions",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "github:floydspace/effect-aws",
9
+ "directory": "packages/dynamodb"
10
+ },
11
+ "sideEffects": [],
12
+ "author": {
13
+ "name": "Victor Korzunin",
14
+ "email": "ifloydrose@gmail.com"
15
+ },
16
+ "homepage": "https://floydspace.github.io/effect-aws/docs/dynamodb",
17
+ "dependencies": {
18
+ "@aws-sdk/client-dynamodb": "^3",
19
+ "@aws-sdk/lib-dynamodb": "^3",
20
+ "@effect-aws/commons": "^0.3.0"
21
+ },
22
+ "peerDependencies": {
23
+ "effect": ">=3.0.4 <4.0.0",
24
+ "@effect-aws/client-dynamodb": "^1.10.3"
25
+ },
26
+ "main": "./dist/cjs/index.js",
27
+ "module": "./dist/esm/index.js",
28
+ "types": "./dist/dts/index.d.ts",
29
+ "exports": {
30
+ "./package.json": "./package.json",
31
+ ".": {
32
+ "types": "./dist/dts/index.d.ts",
33
+ "import": "./dist/esm/index.js",
34
+ "default": "./dist/cjs/index.js"
35
+ },
36
+ "./DynamoDBDocumentClientInstance": {
37
+ "types": "./dist/dts/DynamoDBDocumentClientInstance.d.ts",
38
+ "import": "./dist/esm/DynamoDBDocumentClientInstance.js",
39
+ "default": "./dist/cjs/DynamoDBDocumentClientInstance.js"
40
+ },
41
+ "./DynamoDBDocumentService": {
42
+ "types": "./dist/dts/DynamoDBDocumentService.d.ts",
43
+ "import": "./dist/esm/DynamoDBDocumentService.js",
44
+ "default": "./dist/cjs/DynamoDBDocumentService.js"
45
+ },
46
+ "./DynamoDBDocumentServiceConfig": {
47
+ "types": "./dist/dts/DynamoDBDocumentServiceConfig.d.ts",
48
+ "import": "./dist/esm/DynamoDBDocumentServiceConfig.js",
49
+ "default": "./dist/cjs/DynamoDBDocumentServiceConfig.js"
50
+ },
51
+ "./DynamoDBStore": {
52
+ "types": "./dist/dts/DynamoDBStore.d.ts",
53
+ "import": "./dist/esm/DynamoDBStore.js",
54
+ "default": "./dist/cjs/DynamoDBStore.js"
55
+ }
56
+ },
57
+ "typesVersions": {
58
+ "*": {
59
+ "DynamoDBDocumentClientInstance": [
60
+ "./dist/dts/DynamoDBDocumentClientInstance.d.ts"
61
+ ],
62
+ "DynamoDBDocumentService": [
63
+ "./dist/dts/DynamoDBDocumentService.d.ts"
64
+ ],
65
+ "DynamoDBDocumentServiceConfig": [
66
+ "./dist/dts/DynamoDBDocumentServiceConfig.d.ts"
67
+ ],
68
+ "DynamoDBStore": [
69
+ "./dist/dts/DynamoDBStore.d.ts"
70
+ ]
71
+ }
72
+ }
73
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
5
+ import { DynamoDBClientInstance } from "@effect-aws/client-dynamodb";
6
+ import { Context, Effect, Layer } from "effect";
7
+ import * as DynamoDBDocumentServiceConfig from "./DynamoDBDocumentServiceConfig.js";
8
+
9
+ /**
10
+ * @since 1.0.0
11
+ * @category tags
12
+ */
13
+ export class DynamoDBDocumentClientInstance extends Context.Tag(
14
+ "@effect-aws/lib-dynamodb/DynamoDBDocumentClientInstance",
15
+ )<DynamoDBDocumentClientInstance, DynamoDBDocumentClient>() {}
16
+
17
+ /**
18
+ * @since 1.0.0
19
+ * @category constructors
20
+ */
21
+ export const make = Effect.all([
22
+ DynamoDBClientInstance.DynamoDBClientInstance,
23
+ DynamoDBDocumentServiceConfig.toTranslateConfig,
24
+ ]).pipe(
25
+ Effect.map(([client, config]) => DynamoDBDocumentClient.from(client, config)),
26
+ );
27
+
28
+ /**
29
+ * @since 1.0.0
30
+ * @category layers
31
+ */
32
+ export const layer = Layer.scoped(DynamoDBDocumentClientInstance, make).pipe(
33
+ Layer.provide(DynamoDBClientInstance.layer),
34
+ );
@@ -0,0 +1,377 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import type { DynamoDBClientConfig } from "@aws-sdk/client-dynamodb";
5
+ import type {
6
+ BatchExecuteStatementCommandInput,
7
+ BatchExecuteStatementCommandOutput,
8
+ BatchGetCommandInput,
9
+ BatchGetCommandOutput,
10
+ BatchWriteCommandInput,
11
+ BatchWriteCommandOutput,
12
+ DeleteCommandInput,
13
+ DeleteCommandOutput,
14
+ DynamoDBDocumentClient,
15
+ ExecuteStatementCommandInput,
16
+ ExecuteStatementCommandOutput,
17
+ ExecuteTransactionCommandInput,
18
+ ExecuteTransactionCommandOutput,
19
+ GetCommandInput,
20
+ GetCommandOutput,
21
+ PutCommandInput,
22
+ PutCommandOutput,
23
+ QueryCommandInput,
24
+ QueryCommandOutput,
25
+ ScanCommandInput,
26
+ ScanCommandOutput,
27
+ TransactGetCommandInput,
28
+ TransactGetCommandOutput,
29
+ TransactWriteCommandInput,
30
+ TransactWriteCommandOutput,
31
+ TranslateConfig,
32
+ UpdateCommandInput,
33
+ UpdateCommandOutput,
34
+ } from "@aws-sdk/lib-dynamodb";
35
+ import {
36
+ BatchExecuteStatementCommand,
37
+ BatchGetCommand,
38
+ BatchWriteCommand,
39
+ DeleteCommand,
40
+ ExecuteStatementCommand,
41
+ ExecuteTransactionCommand,
42
+ GetCommand,
43
+ PutCommand,
44
+ QueryCommand,
45
+ ScanCommand,
46
+ TransactGetCommand,
47
+ TransactWriteCommand,
48
+ UpdateCommand,
49
+ } from "@aws-sdk/lib-dynamodb";
50
+ import type {
51
+ ConditionalCheckFailedError,
52
+ DuplicateItemError,
53
+ IdempotentParameterMismatchError,
54
+ InternalServerError,
55
+ InvalidEndpointError,
56
+ ItemCollectionSizeLimitExceededError,
57
+ ProvisionedThroughputExceededError,
58
+ RequestLimitExceededError,
59
+ ResourceNotFoundError,
60
+ SdkError,
61
+ TransactionCanceledError,
62
+ TransactionConflictError,
63
+ TransactionInProgressError,
64
+ } from "@effect-aws/client-dynamodb";
65
+ import { DynamoDBServiceConfig } from "@effect-aws/client-dynamodb";
66
+ import { type HttpHandlerOptions, Service } from "@effect-aws/commons";
67
+ import type { Cause } from "effect";
68
+ import { Effect, Layer } from "effect";
69
+ import * as Instance from "./DynamoDBDocumentClientInstance.js";
70
+ import * as DynamoDBDocumentServiceConfig from "./DynamoDBDocumentServiceConfig.js";
71
+
72
+ const commands = {
73
+ BatchExecuteStatementCommand,
74
+ BatchGetCommand,
75
+ BatchWriteCommand,
76
+ DeleteCommand,
77
+ ExecuteStatementCommand,
78
+ ExecuteTransactionCommand,
79
+ GetCommand,
80
+ PutCommand,
81
+ QueryCommand,
82
+ ScanCommand,
83
+ TransactGetCommand,
84
+ TransactWriteCommand,
85
+ UpdateCommand,
86
+ };
87
+
88
+ interface DynamoDBDocumentService$ {
89
+ readonly _: unique symbol;
90
+
91
+ /**
92
+ * @see {@link BatchExecuteStatementCommand}
93
+ */
94
+ batchExecuteStatement(
95
+ args: BatchExecuteStatementCommandInput,
96
+ options?: HttpHandlerOptions,
97
+ ): Effect.Effect<
98
+ BatchExecuteStatementCommandOutput,
99
+ Cause.TimeoutException | SdkError | InternalServerError | RequestLimitExceededError
100
+ >;
101
+
102
+ /**
103
+ * @see {@link BatchGetCommand}
104
+ */
105
+ batchGet(
106
+ args: BatchGetCommandInput,
107
+ options?: HttpHandlerOptions,
108
+ ): Effect.Effect<
109
+ BatchGetCommandOutput,
110
+ | Cause.TimeoutException
111
+ | SdkError
112
+ | InternalServerError
113
+ | InvalidEndpointError
114
+ | ProvisionedThroughputExceededError
115
+ | RequestLimitExceededError
116
+ | ResourceNotFoundError
117
+ >;
118
+
119
+ /**
120
+ * @see {@link BatchWriteCommand}
121
+ */
122
+ batchWrite(
123
+ args: BatchWriteCommandInput,
124
+ options?: HttpHandlerOptions,
125
+ ): Effect.Effect<
126
+ BatchWriteCommandOutput,
127
+ | Cause.TimeoutException
128
+ | SdkError
129
+ | InternalServerError
130
+ | InvalidEndpointError
131
+ | ItemCollectionSizeLimitExceededError
132
+ | ProvisionedThroughputExceededError
133
+ | RequestLimitExceededError
134
+ | ResourceNotFoundError
135
+ >;
136
+
137
+ /**
138
+ * @see {@link DeleteCommand}
139
+ */
140
+ delete(
141
+ args: DeleteCommandInput,
142
+ options?: HttpHandlerOptions,
143
+ ): Effect.Effect<
144
+ DeleteCommandOutput,
145
+ | Cause.TimeoutException
146
+ | SdkError
147
+ | ConditionalCheckFailedError
148
+ | InternalServerError
149
+ | InvalidEndpointError
150
+ | ItemCollectionSizeLimitExceededError
151
+ | ProvisionedThroughputExceededError
152
+ | RequestLimitExceededError
153
+ | ResourceNotFoundError
154
+ | TransactionConflictError
155
+ >;
156
+
157
+ /**
158
+ * @see {@link ExecuteStatementCommand}
159
+ */
160
+ executeStatement(
161
+ args: ExecuteStatementCommandInput,
162
+ options?: HttpHandlerOptions,
163
+ ): Effect.Effect<
164
+ ExecuteStatementCommandOutput,
165
+ | Cause.TimeoutException
166
+ | SdkError
167
+ | ConditionalCheckFailedError
168
+ | DuplicateItemError
169
+ | InternalServerError
170
+ | ItemCollectionSizeLimitExceededError
171
+ | ProvisionedThroughputExceededError
172
+ | RequestLimitExceededError
173
+ | ResourceNotFoundError
174
+ | TransactionConflictError
175
+ >;
176
+
177
+ /**
178
+ * @see {@link ExecuteTransactionCommand}
179
+ */
180
+ executeTransaction(
181
+ args: ExecuteTransactionCommandInput,
182
+ options?: HttpHandlerOptions,
183
+ ): Effect.Effect<
184
+ ExecuteTransactionCommandOutput,
185
+ | Cause.TimeoutException
186
+ | SdkError
187
+ | IdempotentParameterMismatchError
188
+ | InternalServerError
189
+ | ProvisionedThroughputExceededError
190
+ | RequestLimitExceededError
191
+ | ResourceNotFoundError
192
+ | TransactionCanceledError
193
+ | TransactionInProgressError
194
+ >;
195
+
196
+ /**
197
+ * @see {@link GetCommand}
198
+ */
199
+ get(
200
+ args: GetCommandInput,
201
+ options?: HttpHandlerOptions,
202
+ ): Effect.Effect<
203
+ GetCommandOutput,
204
+ | Cause.TimeoutException
205
+ | SdkError
206
+ | InternalServerError
207
+ | InvalidEndpointError
208
+ | ProvisionedThroughputExceededError
209
+ | RequestLimitExceededError
210
+ | ResourceNotFoundError
211
+ >;
212
+
213
+ /**
214
+ * @see {@link PutCommand}
215
+ */
216
+ put(
217
+ args: PutCommandInput,
218
+ options?: HttpHandlerOptions,
219
+ ): Effect.Effect<
220
+ PutCommandOutput,
221
+ | Cause.TimeoutException
222
+ | SdkError
223
+ | ConditionalCheckFailedError
224
+ | InternalServerError
225
+ | InvalidEndpointError
226
+ | ItemCollectionSizeLimitExceededError
227
+ | ProvisionedThroughputExceededError
228
+ | RequestLimitExceededError
229
+ | ResourceNotFoundError
230
+ | TransactionConflictError
231
+ >;
232
+
233
+ /**
234
+ * @see {@link QueryCommand}
235
+ */
236
+ query(
237
+ args: QueryCommandInput,
238
+ options?: HttpHandlerOptions,
239
+ ): Effect.Effect<
240
+ QueryCommandOutput,
241
+ | Cause.TimeoutException
242
+ | SdkError
243
+ | InternalServerError
244
+ | InvalidEndpointError
245
+ | ProvisionedThroughputExceededError
246
+ | RequestLimitExceededError
247
+ | ResourceNotFoundError
248
+ >;
249
+
250
+ /**
251
+ * @see {@link ScanCommand}
252
+ */
253
+ scan(
254
+ args: ScanCommandInput,
255
+ options?: HttpHandlerOptions,
256
+ ): Effect.Effect<
257
+ ScanCommandOutput,
258
+ | Cause.TimeoutException
259
+ | SdkError
260
+ | InternalServerError
261
+ | InvalidEndpointError
262
+ | ProvisionedThroughputExceededError
263
+ | RequestLimitExceededError
264
+ | ResourceNotFoundError
265
+ >;
266
+
267
+ /**
268
+ * @see {@link TransactGetCommand}
269
+ */
270
+ transactGet(
271
+ args: TransactGetCommandInput,
272
+ options?: HttpHandlerOptions,
273
+ ): Effect.Effect<
274
+ TransactGetCommandOutput,
275
+ | Cause.TimeoutException
276
+ | SdkError
277
+ | InternalServerError
278
+ | InvalidEndpointError
279
+ | ProvisionedThroughputExceededError
280
+ | RequestLimitExceededError
281
+ | ResourceNotFoundError
282
+ | TransactionCanceledError
283
+ >;
284
+
285
+ /**
286
+ * @see {@link TransactWriteCommand}
287
+ */
288
+ transactWrite(
289
+ args: TransactWriteCommandInput,
290
+ options?: HttpHandlerOptions,
291
+ ): Effect.Effect<
292
+ TransactWriteCommandOutput,
293
+ | Cause.TimeoutException
294
+ | SdkError
295
+ | IdempotentParameterMismatchError
296
+ | InternalServerError
297
+ | InvalidEndpointError
298
+ | ProvisionedThroughputExceededError
299
+ | RequestLimitExceededError
300
+ | ResourceNotFoundError
301
+ | TransactionCanceledError
302
+ | TransactionInProgressError
303
+ >;
304
+
305
+ /**
306
+ * @see {@link UpdateCommand}
307
+ */
308
+ update(
309
+ args: UpdateCommandInput,
310
+ options?: HttpHandlerOptions,
311
+ ): Effect.Effect<
312
+ UpdateCommandOutput,
313
+ | Cause.TimeoutException
314
+ | SdkError
315
+ | ConditionalCheckFailedError
316
+ | InternalServerError
317
+ | InvalidEndpointError
318
+ | ItemCollectionSizeLimitExceededError
319
+ | ProvisionedThroughputExceededError
320
+ | RequestLimitExceededError
321
+ | ResourceNotFoundError
322
+ | TransactionConflictError
323
+ >;
324
+ }
325
+
326
+ /**
327
+ * @since 1.0.0
328
+ * @category constructors
329
+ */
330
+ export const makeDynamoDBDocumentService = Effect.gen(function*() {
331
+ const client = yield* Instance.DynamoDBDocumentClientInstance;
332
+
333
+ return yield* Service.fromClientAndCommands<DynamoDBDocumentService$>(client, commands, {
334
+ resolveClientConfig: DynamoDBServiceConfig.toDynamoDBClientConfig,
335
+ });
336
+ });
337
+
338
+ /**
339
+ * @since 1.0.0
340
+ * @category models
341
+ */
342
+ export class DynamoDBDocumentService extends Effect.Tag(
343
+ "@effect-aws/lib-dynamodb/DynamoDBDocumentService",
344
+ )<DynamoDBDocumentService, DynamoDBDocumentService$>() {
345
+ static readonly defaultLayer = Layer.effect(this, makeDynamoDBDocumentService).pipe(Layer.provide(Instance.layer));
346
+ static readonly layer = (config: DynamoDBDocumentService.Config) =>
347
+ Layer.effect(this, makeDynamoDBDocumentService).pipe(
348
+ Layer.provide(Instance.layer),
349
+ Layer.provide(DynamoDBDocumentServiceConfig.setDynamoDBDocumentServiceConfig(config)),
350
+ );
351
+ static readonly baseLayer = (
352
+ evaluate: (defaultConfig: DynamoDBClientConfig) => DynamoDBDocumentClient,
353
+ ) =>
354
+ Layer.effect(this, makeDynamoDBDocumentService).pipe(
355
+ Layer.provide(
356
+ Layer.effect(
357
+ Instance.DynamoDBDocumentClientInstance,
358
+ Effect.map(DynamoDBServiceConfig.toDynamoDBClientConfig, evaluate),
359
+ ),
360
+ ),
361
+ );
362
+ }
363
+
364
+ /**
365
+ * @since 1.0.0
366
+ */
367
+ export declare namespace DynamoDBDocumentService {
368
+ /**
369
+ * @since 1.0.0
370
+ */
371
+ export type Config = TranslateConfig;
372
+
373
+ /**
374
+ * @since 1.0.0
375
+ */
376
+ export type Type = DynamoDBDocumentService$;
377
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import type { TranslateConfig } from "@aws-sdk/lib-dynamodb";
5
+ import { Effect, FiberRef, Layer } from "effect";
6
+ import { dual } from "effect/Function";
7
+ import { globalValue } from "effect/GlobalValue";
8
+ import type { DynamoDBDocumentService } from "./DynamoDBDocumentService.js";
9
+
10
+ /**
11
+ * @since 1.0.0
12
+ * @category dynamodb service config
13
+ */
14
+ const currentDynamoDBDocumentServiceConfig = globalValue(
15
+ "@effect-aws/lib-dynamodb/currentDynamoDBDocumentServiceConfig",
16
+ () => FiberRef.unsafeMake<DynamoDBDocumentService.Config>({}),
17
+ );
18
+
19
+ /**
20
+ * @since 1.0.0
21
+ * @category dynamodb service config
22
+ */
23
+ export const withDynamoDBDocumentServiceConfig: {
24
+ (config: DynamoDBDocumentService.Config): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
25
+ <A, E, R>(effect: Effect.Effect<A, E, R>, config: DynamoDBDocumentService.Config): Effect.Effect<A, E, R>;
26
+ } = dual(
27
+ 2,
28
+ <A, E, R>(effect: Effect.Effect<A, E, R>, config: DynamoDBDocumentService.Config): Effect.Effect<A, E, R> =>
29
+ Effect.locally(effect, currentDynamoDBDocumentServiceConfig, config),
30
+ );
31
+
32
+ /**
33
+ * @since 1.0.0
34
+ * @category dynamodb service config
35
+ */
36
+ export const setDynamoDBDocumentServiceConfig = (config: DynamoDBDocumentService.Config) =>
37
+ Layer.locallyScoped(currentDynamoDBDocumentServiceConfig, config);
38
+
39
+ /**
40
+ * @since 1.0.0
41
+ * @category adapters
42
+ */
43
+ export const toTranslateConfig: Effect.Effect<TranslateConfig> = FiberRef.get(currentDynamoDBDocumentServiceConfig);
@@ -0,0 +1,131 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import { Config, Effect, Layer } from "effect";
5
+ import { DynamoDBDocumentService } from "./DynamoDBDocumentService.js";
6
+
7
+ type WithoutTableNameInArgs = {
8
+ [K in keyof Omit<DynamoDBDocumentService.Type, "_">]: Parameters<
9
+ DynamoDBDocumentService.Type[K]
10
+ >[0] extends { TableName?: string } ? (
11
+ args: Omit<Parameters<DynamoDBDocumentService.Type[K]>[0], "TableName">,
12
+ options?: Parameters<DynamoDBDocumentService.Type[K]>[1],
13
+ ) => Effect.Effect<
14
+ Effect.Effect.Success<
15
+ ReturnType<DynamoDBDocumentService.Type[K]>
16
+ > extends { Item?: infer Item } ? Item | undefined
17
+ : Effect.Effect.Success<
18
+ ReturnType<DynamoDBDocumentService.Type[K]>
19
+ > extends { Items?: infer Items } ? Items
20
+ : Effect.Effect.Success<
21
+ ReturnType<DynamoDBDocumentService.Type[K]>
22
+ > extends { Attributes?: infer Attributes } ? Attributes | undefined
23
+ : never,
24
+ Effect.Effect.Error<ReturnType<DynamoDBDocumentService.Type[K]>>,
25
+ Effect.Effect.Context<ReturnType<DynamoDBDocumentService.Type[K]>>
26
+ >
27
+ : never;
28
+ };
29
+
30
+ type WithoutTableNameInBatchRequest = {
31
+ [K in keyof Omit<DynamoDBDocumentService.Type, "_">]: Parameters<
32
+ DynamoDBDocumentService.Type[K]
33
+ >[0] extends { RequestItems?: { [key: string]: infer RequestItems } } ? (
34
+ args: RequestItems,
35
+ options?: Parameters<DynamoDBDocumentService.Type[K]>[1],
36
+ ) => ReturnType<DynamoDBDocumentService.Type[K]>
37
+ : never;
38
+ };
39
+
40
+ type OmitNeverProps<T> = {
41
+ [K in keyof T as T[K] extends never ? never : K]: T[K];
42
+ };
43
+
44
+ /**
45
+ * @since 1.0.0
46
+ * @category constructors
47
+ */
48
+ export const makeDynamoDBStore = Effect.fn(function*(props: DynamoDBStore.Config) {
49
+ const ddb = yield* DynamoDBDocumentService;
50
+
51
+ return {
52
+ scan: (args) =>
53
+ ddb
54
+ .scan({ TableName: props.tableName, ...args })
55
+ .pipe(Effect.map(({ Items }) => Items ?? [])),
56
+ query: (args) =>
57
+ ddb
58
+ .query({ TableName: props.tableName, ...args })
59
+ .pipe(Effect.map(({ Items }) => Items ?? [])),
60
+ get: (args) =>
61
+ ddb
62
+ .get({ TableName: props.tableName, Key: args?.Key })
63
+ .pipe(Effect.map(({ Item }) => Item)),
64
+ put: (args) =>
65
+ ddb
66
+ .put({ TableName: props.tableName, ...args })
67
+ .pipe(Effect.map(({ Attributes }) => Attributes)),
68
+ batchWrite: (items) => ddb.batchWrite({ RequestItems: { [props.tableName]: items } }),
69
+ batchPut: (items) =>
70
+ ddb.batchWrite({
71
+ RequestItems: {
72
+ [props.tableName]: items.map((Item) => ({ PutRequest: { Item } })),
73
+ },
74
+ }),
75
+ batchDelete: (keys) =>
76
+ ddb.batchWrite({
77
+ RequestItems: {
78
+ [props.tableName]: keys.map((Key) => ({ DeleteRequest: { Key } })),
79
+ },
80
+ }),
81
+ batchGet: (items) => ddb.batchGet({ RequestItems: { [props.tableName]: items } }),
82
+ update: (args) =>
83
+ ddb
84
+ .update({ TableName: props.tableName, ...args })
85
+ .pipe(Effect.map(({ Attributes }) => Attributes)),
86
+ delete: (args) =>
87
+ ddb
88
+ .delete({ TableName: props.tableName, ...args })
89
+ .pipe(Effect.map(({ Attributes }) => Attributes)),
90
+ } satisfies DynamoDBStore.Type;
91
+ });
92
+
93
+ /**
94
+ * @since 1.0.0
95
+ * @category models
96
+ */
97
+ export class DynamoDBStore extends Effect.Tag("@pms/common/DynamoDBStore")<
98
+ DynamoDBStore,
99
+ DynamoDBStore.Type
100
+ >() {
101
+ static layer = (props: DynamoDBStore.Config) => Layer.effect(this, makeDynamoDBStore(props));
102
+ static layerConfig = (config: Config.Config.Wrap<DynamoDBStore.Config>) =>
103
+ Layer.effect(this, Config.unwrap(config).pipe(Effect.flatMap(makeDynamoDBStore)));
104
+ }
105
+
106
+ /**
107
+ * @since 1.0.0
108
+ */
109
+ export declare namespace DynamoDBStore {
110
+ /**
111
+ * @since 1.0.0
112
+ */
113
+ export type Config = {
114
+ readonly tableName: string;
115
+ };
116
+
117
+ /**
118
+ * @since 1.0.0
119
+ */
120
+ export type Type =
121
+ & OmitNeverProps<WithoutTableNameInArgs>
122
+ & OmitNeverProps<WithoutTableNameInBatchRequest>
123
+ & {
124
+ batchPut: (
125
+ items: Array<Record<string, any>>,
126
+ ) => ReturnType<DynamoDBDocumentService.Type["batchWrite"]>;
127
+ batchDelete: (
128
+ keys: Array<Record<string, any>>,
129
+ ) => ReturnType<DynamoDBDocumentService.Type["batchWrite"]>;
130
+ };
131
+ }