@model-ts/dynamodb 0.1.2 → 0.2.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.
- package/CHANGELOG.md +6 -0
- package/README.md +169 -1
- package/dist/cjs/__test__/client.test.js +85 -57
- package/dist/cjs/__test__/client.test.js.map +1 -1
- package/dist/cjs/client.js +2 -2
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/dynamodb-model.d.ts +4 -0
- package/dist/cjs/operations.d.ts +4 -0
- package/dist/cjs/operations.js.map +1 -1
- package/dist/cjs/pagination.d.ts +10 -2
- package/dist/cjs/pagination.js +19 -4
- package/dist/cjs/pagination.js.map +1 -1
- package/dist/cjs/provider.d.ts +16 -0
- package/dist/cjs/provider.js +4 -0
- package/dist/cjs/provider.js.map +1 -1
- package/dist/cjs/sandbox.js +24 -0
- package/dist/cjs/sandbox.js.map +1 -1
- package/dist/esm/__test__/client.test.js +86 -58
- package/dist/esm/__test__/client.test.js.map +1 -1
- package/dist/esm/client.js +2 -2
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/dynamodb-model.d.ts +4 -0
- package/dist/esm/operations.d.ts +4 -0
- package/dist/esm/operations.js.map +1 -1
- package/dist/esm/pagination.d.ts +10 -2
- package/dist/esm/pagination.js +19 -4
- package/dist/esm/pagination.js.map +1 -1
- package/dist/esm/provider.d.ts +16 -0
- package/dist/esm/provider.js +4 -0
- package/dist/esm/provider.js.map +1 -1
- package/dist/esm/sandbox.js +24 -0
- package/dist/esm/sandbox.js.map +1 -1
- package/package.json +1 -1
- package/src/__test__/client.test.ts +86 -58
- package/src/client.ts +13 -8
- package/src/dynamodb-model.ts +16 -14
- package/src/operations.ts +4 -0
- package/src/pagination.ts +42 -8
- package/src/provider.ts +5 -1
- package/src/sandbox.ts +24 -0
package/src/operations.ts
CHANGED
|
@@ -62,6 +62,10 @@ export interface UpdateRawOperation<M extends DynamoDBModelConstructor<any>>
|
|
|
62
62
|
GSI2SK?: string | null
|
|
63
63
|
GSI3PK?: string | null
|
|
64
64
|
GSI3SK?: string | null
|
|
65
|
+
GSI4PK?: string | null
|
|
66
|
+
GSI4SK?: string | null
|
|
67
|
+
GSI5PK?: string | null
|
|
68
|
+
GSI5SK?: string | null
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
71
|
|
package/src/pagination.ts
CHANGED
|
@@ -35,9 +35,11 @@ const DEFAULT_OPTIONS = {
|
|
|
35
35
|
default: 20,
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export function decodePagination(
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
export function decodePagination(pagination: PaginationInput): {
|
|
39
|
+
cursor?: string
|
|
40
|
+
limit: number
|
|
41
|
+
direction: PaginationDirection
|
|
42
|
+
} {
|
|
41
43
|
const { after, before, first, last } = pagination
|
|
42
44
|
|
|
43
45
|
if (before && after)
|
|
@@ -77,6 +79,10 @@ export const encodeDDBCursor = (
|
|
|
77
79
|
GSI2SK,
|
|
78
80
|
GSI3PK,
|
|
79
81
|
GSI3SK,
|
|
82
|
+
GSI4PK,
|
|
83
|
+
GSI4SK,
|
|
84
|
+
GSI5PK,
|
|
85
|
+
GSI5SK,
|
|
80
86
|
}: {
|
|
81
87
|
PK: string
|
|
82
88
|
SK: string
|
|
@@ -84,24 +90,52 @@ export const encodeDDBCursor = (
|
|
|
84
90
|
GSI2SK?: string
|
|
85
91
|
GSI3PK?: string
|
|
86
92
|
GSI3SK?: string
|
|
93
|
+
GSI4PK?: string
|
|
94
|
+
GSI4SK?: string
|
|
95
|
+
GSI5PK?: string
|
|
96
|
+
GSI5SK?: string
|
|
87
97
|
},
|
|
88
|
-
index?: "GSI2" | "GSI3"
|
|
98
|
+
index?: "GSI2" | "GSI3" | "GSI4" | "GSI5"
|
|
89
99
|
) =>
|
|
90
100
|
index === "GSI2"
|
|
91
101
|
? Buffer.from(JSON.stringify({ PK, SK, GSI2PK, GSI2SK })).toString("base64")
|
|
92
102
|
: index === "GSI3"
|
|
93
103
|
? Buffer.from(JSON.stringify({ PK, SK, GSI3PK, GSI3SK })).toString("base64")
|
|
104
|
+
: index === "GSI4"
|
|
105
|
+
? Buffer.from(JSON.stringify({ PK, SK, GSI4PK, GSI4SK })).toString("base64")
|
|
106
|
+
: index === "GSI5"
|
|
107
|
+
? Buffer.from(JSON.stringify({ PK, SK, GSI5PK, GSI5SK })).toString("base64")
|
|
94
108
|
: Buffer.from(JSON.stringify({ PK, SK })).toString("base64")
|
|
95
109
|
|
|
96
110
|
export const decodeDDBCursor = (encoded: string) => {
|
|
97
111
|
try {
|
|
98
|
-
const {
|
|
99
|
-
|
|
100
|
-
|
|
112
|
+
const {
|
|
113
|
+
PK,
|
|
114
|
+
SK,
|
|
115
|
+
GSI2PK,
|
|
116
|
+
GSI2SK,
|
|
117
|
+
GSI3PK,
|
|
118
|
+
GSI3SK,
|
|
119
|
+
GSI4PK,
|
|
120
|
+
GSI4SK,
|
|
121
|
+
GSI5PK,
|
|
122
|
+
GSI5SK,
|
|
123
|
+
} = JSON.parse(Buffer.from(encoded, "base64").toString())
|
|
101
124
|
|
|
102
125
|
if (typeof PK !== "string" || typeof SK !== "string") throw new Error()
|
|
103
126
|
|
|
104
|
-
return {
|
|
127
|
+
return {
|
|
128
|
+
PK,
|
|
129
|
+
SK,
|
|
130
|
+
GSI2PK,
|
|
131
|
+
GSI2SK,
|
|
132
|
+
GSI3PK,
|
|
133
|
+
GSI3SK,
|
|
134
|
+
GSI4PK,
|
|
135
|
+
GSI4SK,
|
|
136
|
+
GSI5PK,
|
|
137
|
+
GSI5SK,
|
|
138
|
+
}
|
|
105
139
|
} catch (error) {
|
|
106
140
|
throw new PaginationError("Couldn't decode cursor")
|
|
107
141
|
}
|
package/src/provider.ts
CHANGED
|
@@ -295,7 +295,7 @@ export const getProvider = (client: Client) => {
|
|
|
295
295
|
): DeleteOperation<ModelOf<T>>
|
|
296
296
|
function instanceOperation<T extends DynamoDBModelInstance>(
|
|
297
297
|
this: T,
|
|
298
|
-
operation: "softDelete"
|
|
298
|
+
operation: "softDelete"
|
|
299
299
|
): [
|
|
300
300
|
{
|
|
301
301
|
action: PutOperation<T, ModelOf<T>>
|
|
@@ -518,6 +518,10 @@ export const getProvider = (client: Client) => {
|
|
|
518
518
|
GSI2SK: this.GSI2SK,
|
|
519
519
|
GSI3PK: this.GSI3PK,
|
|
520
520
|
GSI3SK: this.GSI3SK,
|
|
521
|
+
GSI4PK: this.GSI4PK,
|
|
522
|
+
GSI4SK: this.GSI4SK,
|
|
523
|
+
GSI5PK: this.GSI5PK,
|
|
524
|
+
GSI5SK: this.GSI5SK,
|
|
521
525
|
}
|
|
522
526
|
},
|
|
523
527
|
put<T extends DynamoDBModelInstance>(
|
package/src/sandbox.ts
CHANGED
|
@@ -31,6 +31,10 @@ export const createTable = async () => {
|
|
|
31
31
|
{ AttributeName: "GSI2SK", AttributeType: "S" },
|
|
32
32
|
{ AttributeName: "GSI3PK", AttributeType: "S" },
|
|
33
33
|
{ AttributeName: "GSI3SK", AttributeType: "S" },
|
|
34
|
+
{ AttributeName: "GSI4PK", AttributeType: "S" },
|
|
35
|
+
{ AttributeName: "GSI4SK", AttributeType: "S" },
|
|
36
|
+
{ AttributeName: "GSI5PK", AttributeType: "S" },
|
|
37
|
+
{ AttributeName: "GSI5SK", AttributeType: "S" },
|
|
34
38
|
],
|
|
35
39
|
KeySchema: [
|
|
36
40
|
{ AttributeName: "PK", KeyType: "HASH" },
|
|
@@ -67,6 +71,26 @@ export const createTable = async () => {
|
|
|
67
71
|
ProjectionType: "ALL",
|
|
68
72
|
},
|
|
69
73
|
},
|
|
74
|
+
{
|
|
75
|
+
IndexName: "GSI4",
|
|
76
|
+
KeySchema: [
|
|
77
|
+
{ AttributeName: "GSI4PK", KeyType: "HASH" },
|
|
78
|
+
{ AttributeName: "GSI4SK", KeyType: "RANGE" },
|
|
79
|
+
],
|
|
80
|
+
Projection: {
|
|
81
|
+
ProjectionType: "ALL",
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
IndexName: "GSI5",
|
|
86
|
+
KeySchema: [
|
|
87
|
+
{ AttributeName: "GSI5PK", KeyType: "HASH" },
|
|
88
|
+
{ AttributeName: "GSI5SK", KeyType: "RANGE" },
|
|
89
|
+
],
|
|
90
|
+
Projection: {
|
|
91
|
+
ProjectionType: "ALL",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
70
94
|
],
|
|
71
95
|
BillingMode: "PAY_PER_REQUEST",
|
|
72
96
|
})
|