Skip to content

Commit 69140f2

Browse files
Update Symbiosis To 0.0.31 (#140)
1 parent 29e1ac1 commit 69140f2

File tree

20 files changed

+141
-48
lines changed

20 files changed

+141
-48
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Removed
1717

18+
## [0.0.18] - 2022-02-14
19+
20+
### Added
21+
22+
### Changed
23+
24+
- Update `@techmmunity/symbiosis` to [0.0.31](https://github.com/techmmunity-symbiosis/symbiosis/blob/master/CHANGELOG.md#0031---2022-02-12)
25+
26+
### Fixed
27+
28+
### Removed
29+
1830
## [0.0.17] - 2021-12-05
1931

2032
### Added

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@techmmunity/symbiosis-dynamodb",
3-
"version": "0.0.17",
3+
"version": "0.0.18",
44
"main": "index.js",
55
"types": "index.d.ts",
66
"license": "Apache-2.0",
@@ -38,7 +38,7 @@
3838
},
3939
"devDependencies": {
4040
"@techmmunity/eslint-config": "^5.2.2",
41-
"@techmmunity/symbiosis": "^0.0.30",
41+
"@techmmunity/symbiosis": "^0.0.31",
4242
"@types/jest": "^27.0.1",
4343
"@vercel/ncc": "^0.33.2",
4444
"eslint": "^8.9.0",

src/lib/repository/delete/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ export const del = async <Entity>(
3434

3535
await context.connectionInstance.send(deleteItemCommand);
3636

37-
return context.afterDelete({
38-
dataToReturn: 1,
39-
where: rawWhere,
40-
options: rawOptions,
41-
});
37+
return {
38+
data: await context.afterDelete({
39+
dataToReturn: 1,
40+
where: rawWhere,
41+
options: rawOptions,
42+
}),
43+
};
4244
};

src/lib/repository/find-one/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ export const findOne = async <Entity>(
5858

5959
const result = item ? unmarshall(item) : undefined;
6060

61-
return context.afterFindOne({
62-
dataToReturn: result as DatabaseEntity,
63-
conditions: rawConditions,
64-
options: rawOptions,
65-
});
61+
return {
62+
data: context.afterFindOne({
63+
dataToReturn: result as DatabaseEntity,
64+
conditions: rawConditions,
65+
options: rawOptions,
66+
}),
67+
};
6668
};

src/lib/repository/find/index.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable @typescript-eslint/naming-convention */
22

33
import { unmarshall } from "@aws-sdk/util-dynamodb";
4+
import type { ClassType } from "@techmmunity/symbiosis";
45
import type { BeforeFindInput } from "@techmmunity/symbiosis/lib/repository/methods/find/before";
56
import { isNotEmptyObject } from "@techmmunity/utils";
67

@@ -60,13 +61,22 @@ export const find = async <Entity>(
6061
...whereProps,
6162
});
6263

63-
const { Items } = await context.connectionInstance.send(findCommand);
64+
const { Items, LastEvaluatedKey } = await context.connectionInstance.send(
65+
findCommand,
66+
);
6467

6568
const result = Items?.map(item => unmarshall(item)) || [];
6669

67-
return context.afterFind({
68-
dataToReturn: result as Array<Entity>,
69-
conditions: rawConditions,
70-
options: rawOptions,
71-
});
70+
return {
71+
data: context.afterFind({
72+
dataToReturn: result as Array<Entity>,
73+
conditions: rawConditions,
74+
options: rawOptions,
75+
}),
76+
...(LastEvaluatedKey
77+
? {
78+
cursor: unmarshall(LastEvaluatedKey) as ClassType<Entity>,
79+
}
80+
: {}),
81+
};
7282
};

src/lib/repository/index.ts

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
FindOptions,
1515
SaveData,
1616
SingleSaveData,
17+
ArraySaveData,
1718
Logger,
1819
} from "@techmmunity/symbiosis";
1920
import { BaseRepository, SymbiosisError } from "@techmmunity/symbiosis";
@@ -27,6 +28,17 @@ import { upsert } from "./upsert";
2728
import { handleDatabaseError } from "../utils/handle-database-error";
2829

2930
import type { ExtraMetadata } from "../types/extra-metadata";
31+
import type { CountOutput } from "../types/methods-outputs/count";
32+
import type { DeleteOutput } from "../types/methods-outputs/delete";
33+
import type { FindOutput } from "../types/methods-outputs/find";
34+
import type { FindOneOutput } from "../types/methods-outputs/find-one";
35+
import type { InsertOutput } from "../types/methods-outputs/insert";
36+
import type { PerformativeCountOutput } from "../types/methods-outputs/performative-count";
37+
import type { RecoverOutput } from "../types/methods-outputs/recover";
38+
import type { SaveOutput } from "../types/methods-outputs/save";
39+
import type { SoftDeleteOutput } from "../types/methods-outputs/soft-delete";
40+
import type { UpdateOutput } from "../types/methods-outputs/update";
41+
import type { UpsertOutput } from "../types/methods-outputs/upsert";
3042

3143
export class Repository<Entity> extends BaseRepository<Entity, ExtraMetadata> {
3244
public constructor(
@@ -54,10 +66,18 @@ export class Repository<Entity> extends BaseRepository<Entity, ExtraMetadata> {
5466
* @param options Options for this operation
5567
* @returns The entity as it's saved on the database
5668
*/
57-
public save<Result = Array<Entity> | Entity>(
69+
public save(
70+
data: SingleSaveData<Entity>,
71+
options?: BaseQueryOptions,
72+
): Promise<SaveOutput<Entity>>;
73+
public save(
74+
data: ArraySaveData<Entity>,
75+
options?: BaseQueryOptions,
76+
): Promise<SaveOutput<Array<Entity>>>;
77+
public save(
5878
data: SaveData<Entity>,
5979
options?: BaseQueryOptions,
60-
): Promise<Result> {
80+
): Promise<SaveOutput<Array<Entity> | Entity>> {
6181
return save(this as any, {
6282
data,
6383
options,
@@ -69,10 +89,18 @@ export class Repository<Entity> extends BaseRepository<Entity, ExtraMetadata> {
6989
/**
7090
* ## NOT IMPLEMENTED!
7191
*/
72-
public insert<Result = Array<Entity> | Entity>(
92+
public insert(
93+
data: SingleSaveData<Entity>,
94+
options?: BaseQueryOptions,
95+
): Promise<InsertOutput<Entity>>;
96+
public insert(
97+
data: ArraySaveData<Entity>,
98+
options?: BaseQueryOptions,
99+
): Promise<InsertOutput<Array<Entity>>>;
100+
public insert(
73101
_data: SaveData<Entity>,
74102
_options?: BaseQueryOptions,
75-
): Promise<Result> {
103+
): Promise<InsertOutput<Array<Entity> | Entity>> {
76104
// Delete this after the method is implemented
77105
throw new SymbiosisError({
78106
code: "NOT_IMPLEMENTED",
@@ -109,11 +137,11 @@ export class Repository<Entity> extends BaseRepository<Entity, ExtraMetadata> {
109137
/**
110138
* ## NOT IMPLEMENTED!
111139
*/
112-
public update<Result = Array<Entity> | Entity>(
140+
public update(
113141
_conditions: FindConditions<Entity>,
114142
_data: SingleSaveData<Entity>,
115143
_options?: BaseQueryOptions,
116-
): Promise<Result> {
144+
): Promise<UpdateOutput<Entity>> {
117145
// Delete this after the method is implemented
118146
throw new SymbiosisError({
119147
code: "NOT_IMPLEMENTED",
@@ -157,11 +185,11 @@ export class Repository<Entity> extends BaseRepository<Entity, ExtraMetadata> {
157185
* @param options Options for this operation
158186
* @returns The updated record
159187
*/
160-
public upsert<Result = Array<Entity> | Entity>(
188+
public upsert(
161189
conditions: FindConditions<Entity>,
162190
data: SingleSaveData<Entity>,
163191
options?: BaseQueryOptions,
164-
): Promise<Result> {
192+
): Promise<UpsertOutput<Entity>> {
165193
return upsert(this as any, {
166194
conditions,
167195
data,
@@ -174,7 +202,7 @@ export class Repository<Entity> extends BaseRepository<Entity, ExtraMetadata> {
174202
public find(
175203
conditions: FindOptions<Entity>,
176204
options?: BaseQueryOptions,
177-
): Promise<Array<Entity>> {
205+
): Promise<FindOutput<Entity>> {
178206
return find(this as any, {
179207
conditions,
180208
options,
@@ -186,7 +214,7 @@ export class Repository<Entity> extends BaseRepository<Entity, ExtraMetadata> {
186214
public findOne(
187215
conditions: FindOneOptions<Entity>,
188216
options?: BaseQueryOptions,
189-
): Promise<Entity> {
217+
): Promise<FindOneOutput<Entity>> {
190218
return findOne(this as any, {
191219
conditions,
192220
options,
@@ -207,7 +235,7 @@ export class Repository<Entity> extends BaseRepository<Entity, ExtraMetadata> {
207235
public delete(
208236
where: FindConditions<Entity>,
209237
options?: BaseQueryOptions,
210-
): Promise<number> {
238+
): Promise<DeleteOutput> {
211239
return del(this as any, {
212240
where,
213241
options,
@@ -222,7 +250,7 @@ export class Repository<Entity> extends BaseRepository<Entity, ExtraMetadata> {
222250
public softDelete(
223251
_where: FindConditions<Entity>,
224252
_options?: BaseQueryOptions,
225-
): Promise<number> {
253+
): Promise<SoftDeleteOutput> {
226254
// Delete this after the method is implemented
227255
throw new SymbiosisError({
228256
code: "NOT_IMPLEMENTED",
@@ -263,7 +291,7 @@ export class Repository<Entity> extends BaseRepository<Entity, ExtraMetadata> {
263291
public recover(
264292
_where: FindConditions<Entity>,
265293
_options?: BaseQueryOptions,
266-
): Promise<number> {
294+
): Promise<RecoverOutput> {
267295
// Delete this after the method is implemented
268296
throw new SymbiosisError({
269297
code: "NOT_IMPLEMENTED",
@@ -304,7 +332,7 @@ export class Repository<Entity> extends BaseRepository<Entity, ExtraMetadata> {
304332
public count(
305333
_where: FindConditions<Entity>,
306334
_options?: BaseQueryOptions,
307-
): Promise<number> {
335+
): Promise<CountOutput> {
308336
// Delete this after the method is implemented
309337
throw new SymbiosisError({
310338
code: "NOT_IMPLEMENTED",
@@ -345,7 +373,7 @@ export class Repository<Entity> extends BaseRepository<Entity, ExtraMetadata> {
345373
public performativeCount(
346374
_where: FindConditions<Entity>,
347375
_options?: BaseQueryOptions,
348-
): Promise<number> {
376+
): Promise<PerformativeCountOutput> {
349377
// Delete this after the method is implemented
350378
throw new SymbiosisError({
351379
code: "NOT_IMPLEMENTED",

src/lib/repository/save/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ export const save = async <Entity>(
5454
});
5555
}
5656

57-
return context.afterSave({
58-
// Dynamo doesn't return the new values, so we have to return the same data that we receive
59-
data: [data as DatabaseEntity],
60-
returnArray,
61-
options: rawOptions,
62-
});
57+
return {
58+
data: context.afterSave({
59+
// Dynamo doesn't return the new values, so we have to return the same data that we receive
60+
data: [data as DatabaseEntity],
61+
returnArray,
62+
options: rawOptions,
63+
}),
64+
};
6365
};

src/lib/repository/upsert/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ export const upsert = async <Entity>(
7979
});
8080
}
8181

82-
return context.afterUpsert({
83-
conditions: rawConditions,
84-
data: unmarshall(Attributes),
85-
options: rawOptions,
86-
});
82+
return {
83+
data: context.afterUpsert({
84+
conditions: rawConditions,
85+
data: unmarshall(Attributes),
86+
options: rawOptions,
87+
}),
88+
};
8789
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { BaseCountOutput } from "@techmmunity/symbiosis";
2+
3+
export type CountOutput = BaseCountOutput;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { BaseDeleteOutput } from "@techmmunity/symbiosis";
2+
3+
export type DeleteOutput = BaseDeleteOutput;

0 commit comments

Comments
 (0)