@webiny/api-core-ddb 0.0.0-unstable.df7a8bb475 → 0.0.0-unstable.e1999482d0
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/ApiCoreDdbFeature.d.ts +12 -0
- package/ApiCoreDdbFeature.js +16 -0
- package/ApiCoreDdbFeature.js.map +1 -0
- package/adminUsers/definitions/entities.js +5 -6
- package/adminUsers/definitions/entities.js.map +1 -1
- package/adminUsers/definitions/types.js +0 -3
- package/adminUsers/index.js +187 -156
- package/adminUsers/index.js.map +1 -1
- package/adminUsers/types.js +5 -4
- package/adminUsers/types.js.map +1 -1
- package/createApiCoreDdb.js +23 -21
- package/createApiCoreDdb.js.map +1 -1
- package/index.d.ts +3 -0
- package/index.js +2 -2
- package/keyValueStore/KeyValueStoreDynamoTable.d.ts +24 -0
- package/keyValueStore/KeyValueStoreDynamoTable.js +39 -25
- package/keyValueStore/KeyValueStoreDynamoTable.js.map +1 -1
- package/keyValueStore/KeyValueStoreStorageOperations.d.ts +14 -2
- package/keyValueStore/KeyValueStoreStorageOperations.js +222 -71
- package/keyValueStore/KeyValueStoreStorageOperations.js.map +1 -1
- package/keyValueStore/index.js +2 -3
- package/keyValueStore/index.js.map +1 -1
- package/package.json +20 -15
- package/security/definitions/entities.js +19 -24
- package/security/definitions/entities.js.map +1 -1
- package/security/definitions/types.d.ts +3 -3
- package/security/definitions/types.js +0 -3
- package/security/index.js +389 -464
- package/security/index.js.map +1 -1
- package/security/types.js +6 -5
- package/security/types.js.map +1 -1
- package/serviceDiscovery/DdbServiceManifestLoader.d.ts +7 -0
- package/serviceDiscovery/DdbServiceManifestLoader.js +27 -0
- package/serviceDiscovery/DdbServiceManifestLoader.js.map +1 -0
- package/serviceDiscovery/index.d.ts +1 -0
- package/serviceDiscovery/index.js +1 -0
- package/tenancy/definitions/tenantEntity.js +5 -9
- package/tenancy/definitions/tenantEntity.js.map +1 -1
- package/tenancy/definitions/types.js +0 -3
- package/tenancy/index.js +107 -127
- package/tenancy/index.js.map +1 -1
- package/tenancy/types.js +4 -3
- package/tenancy/types.js.map +1 -1
- package/adminUsers/definitions/types.js.map +0 -1
- package/index.js.map +0 -1
- package/security/definitions/types.js.map +0 -1
- package/tenancy/definitions/types.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
export interface ApiCoreDdbConfig {
|
|
3
|
+
documentClient: DynamoDBDocument;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Registers the DynamoDB implementation of ApiCoreStorageOperationsFactory. ApiCoreFeature.register
|
|
7
|
+
* resolves + builds it. Mirrors HeadlessCmsDdbFeature.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ApiCoreDdbFeature: {
|
|
10
|
+
name: string;
|
|
11
|
+
register(container: import("@webiny/di").Container, context: ApiCoreDdbConfig): void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { ApiCoreStorageOperationsFactory } from "@webiny/api-core";
|
|
3
|
+
import { createApiCoreDdb } from "./createApiCoreDdb.js";
|
|
4
|
+
const ApiCoreDdbFeature = createFeature({
|
|
5
|
+
name: "ApiCoreDdb",
|
|
6
|
+
register (container, { documentClient }) {
|
|
7
|
+
container.registerInstance(ApiCoreStorageOperationsFactory, {
|
|
8
|
+
create: ()=>createApiCoreDdb({
|
|
9
|
+
documentClient
|
|
10
|
+
})
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
export { ApiCoreDdbFeature };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=ApiCoreDdbFeature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiCoreDdbFeature.js","sources":["../src/ApiCoreDdbFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { ApiCoreStorageOperationsFactory } from \"@webiny/api-core\";\nimport { createApiCoreDdb } from \"./createApiCoreDdb.js\";\n\nexport interface ApiCoreDdbConfig {\n documentClient: DynamoDBDocument;\n}\n\n/**\n * Registers the DynamoDB implementation of ApiCoreStorageOperationsFactory. ApiCoreFeature.register\n * resolves + builds it. Mirrors HeadlessCmsDdbFeature.\n */\nexport const ApiCoreDdbFeature = createFeature<ApiCoreDdbConfig>({\n name: \"ApiCoreDdb\",\n register(container, { documentClient }) {\n container.registerInstance(ApiCoreStorageOperationsFactory, {\n create: () => createApiCoreDdb({ documentClient })\n });\n }\n});\n"],"names":["ApiCoreDdbFeature","createFeature","container","documentClient","ApiCoreStorageOperationsFactory","createApiCoreDdb"],"mappings":";;;AAaO,MAAMA,oBAAoBC,cAAgC;IAC7D,MAAM;IACN,UAASC,SAAS,EAAE,EAAEC,cAAc,EAAE;QAClCD,UAAU,gBAAgB,CAACE,iCAAiC;YACxD,QAAQ,IAAMC,iBAAiB;oBAAEF;gBAAe;QACpD;IACJ;AACJ"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createStandardEntity } from "@webiny/db-dynamodb";
|
|
2
2
|
import { ENTITIES } from "../types.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
3
|
+
const createUserEntity = (table)=>createStandardEntity({
|
|
4
|
+
name: ENTITIES.USERS,
|
|
5
|
+
table
|
|
6
|
+
});
|
|
7
|
+
export { createUserEntity };
|
|
9
8
|
|
|
10
9
|
//# sourceMappingURL=entities.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"adminUsers/definitions/entities.js","sources":["../../../src/adminUsers/definitions/entities.ts"],"sourcesContent":["import { createStandardEntity } from \"@webiny/db-dynamodb\";\nimport type { Table } from \"@webiny/db-dynamodb/toolbox.js\";\nimport { ENTITIES } from \"../types.js\";\nimport type { IAdminUserEntity } from \"~/adminUsers/definitions/types.js\";\nimport type { AdminUser } from \"@webiny/api-core/types/users.js\";\n\nexport const createUserEntity = (table: Table<string, string, string>): IAdminUserEntity => {\n return createStandardEntity<AdminUser>({\n name: ENTITIES.USERS,\n table\n });\n};\n"],"names":["createUserEntity","table","createStandardEntity","ENTITIES"],"mappings":";;AAMO,MAAMA,mBAAmB,CAACC,QACtBC,qBAAgC;QACnC,MAAMC,SAAS,KAAK;QACpBF;IACJ"}
|
package/adminUsers/index.js
CHANGED
|
@@ -1,165 +1,196 @@
|
|
|
1
|
-
import
|
|
1
|
+
import error from "@webiny/error";
|
|
2
2
|
import { createTable, sortItems } from "@webiny/db-dynamodb";
|
|
3
3
|
import { createUserEntity } from "./definitions/entities.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
table
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
13
|
-
const entities = {
|
|
14
|
-
users: createUserEntity(table.table)
|
|
15
|
-
};
|
|
16
|
-
const createUserKeys = user => ({
|
|
17
|
-
PK: `T#${user.tenant}#ADMIN_USER#${user.id}`,
|
|
18
|
-
SK: `A`
|
|
19
|
-
});
|
|
20
|
-
const createUserGSIKeys = user => {
|
|
21
|
-
return {
|
|
22
|
-
GSI1_PK: `T#${user.tenant}#ADMIN_USERS`,
|
|
23
|
-
GSI1_SK: user.email,
|
|
24
|
-
GSI_TENANT: user.tenant
|
|
4
|
+
const createStorageOperations = (params)=>{
|
|
5
|
+
const { table: tableName, documentClient } = params;
|
|
6
|
+
const table = createTable({
|
|
7
|
+
name: tableName || process.env.DB_TABLE,
|
|
8
|
+
documentClient
|
|
9
|
+
});
|
|
10
|
+
const entities = {
|
|
11
|
+
users: createUserEntity(table.table)
|
|
25
12
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return table;
|
|
30
|
-
},
|
|
31
|
-
getEntities() {
|
|
32
|
-
return entities;
|
|
33
|
-
},
|
|
34
|
-
async createUser({
|
|
35
|
-
user
|
|
36
|
-
}) {
|
|
37
|
-
const keys = {
|
|
38
|
-
...createUserKeys(user),
|
|
39
|
-
...createUserGSIKeys(user)
|
|
40
|
-
};
|
|
41
|
-
try {
|
|
42
|
-
await entities.users.put({
|
|
43
|
-
...keys,
|
|
44
|
-
TYPE: "adminUsers.user",
|
|
45
|
-
data: user
|
|
13
|
+
const createUserKeys = (user)=>({
|
|
14
|
+
PK: `T#${user.tenant}#ADMIN_USER#${user.id}`,
|
|
15
|
+
SK: "A"
|
|
46
16
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
17
|
+
const createUserIndexPartitionKey = (id)=>`ADMIN_USER#${id}`;
|
|
18
|
+
const createUserGSIKeys = (user)=>({
|
|
19
|
+
GSI1_PK: `T#${user.tenant}#ADMIN_USERS`,
|
|
20
|
+
GSI1_SK: user.email,
|
|
21
|
+
GSI2_PK: createUserIndexPartitionKey(user.id),
|
|
22
|
+
GSI2_SK: `T#${user.tenant}`,
|
|
23
|
+
GSI_TENANT: user.tenant
|
|
55
24
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
25
|
+
const storageOperations = {
|
|
26
|
+
getTable () {
|
|
27
|
+
return table;
|
|
28
|
+
},
|
|
29
|
+
getEntities () {
|
|
30
|
+
return entities;
|
|
31
|
+
},
|
|
32
|
+
async createUser ({ user }) {
|
|
33
|
+
const keys = {
|
|
34
|
+
...createUserKeys(user),
|
|
35
|
+
...createUserGSIKeys(user)
|
|
36
|
+
};
|
|
37
|
+
try {
|
|
38
|
+
await entities.users.put({
|
|
39
|
+
...keys,
|
|
40
|
+
TYPE: "adminUsers.user",
|
|
41
|
+
data: user
|
|
42
|
+
});
|
|
43
|
+
return user;
|
|
44
|
+
} catch (err) {
|
|
45
|
+
throw error.from(err, {
|
|
46
|
+
message: "Could not create admin user.",
|
|
47
|
+
code: "CREATE_ADMIN_USER_ERROR",
|
|
48
|
+
data: {
|
|
49
|
+
keys
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
async deleteUser ({ user }) {
|
|
55
|
+
const keys = createUserKeys(user);
|
|
56
|
+
try {
|
|
57
|
+
await entities.users.delete(keys);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
throw error.from(err, {
|
|
60
|
+
message: "Could not delete group.",
|
|
61
|
+
code: "CREATE_DELETE_ERROR",
|
|
62
|
+
data: {
|
|
63
|
+
keys,
|
|
64
|
+
user
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
async getUser (params) {
|
|
70
|
+
const { where: { tenant, id, email } } = params;
|
|
71
|
+
try {
|
|
72
|
+
if (id) {
|
|
73
|
+
const response = await entities.users.get(createUserKeys({
|
|
74
|
+
tenant,
|
|
75
|
+
id
|
|
76
|
+
}));
|
|
77
|
+
return response?.data || null;
|
|
78
|
+
}
|
|
79
|
+
const response = await entities.users.queryOne({
|
|
80
|
+
partitionKey: `T#${tenant}#ADMIN_USERS`,
|
|
81
|
+
options: {
|
|
82
|
+
index: "GSI1",
|
|
83
|
+
eq: email
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return response?.data || null;
|
|
87
|
+
} catch (err) {
|
|
88
|
+
throw error.from(err, {
|
|
89
|
+
message: "Could not load user.",
|
|
90
|
+
code: "GET_ADMIN_USERS_ERROR",
|
|
91
|
+
data: {
|
|
92
|
+
id,
|
|
93
|
+
email
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
async getUserAcrossTenants (params) {
|
|
99
|
+
const { id, tenants } = params;
|
|
100
|
+
if (0 === tenants.length) return [];
|
|
101
|
+
try {
|
|
102
|
+
const reader = entities.users.createEntityReader({
|
|
103
|
+
read: tenants.map((tenant)=>createUserKeys({
|
|
104
|
+
tenant,
|
|
105
|
+
id
|
|
106
|
+
}))
|
|
107
|
+
});
|
|
108
|
+
const items = await reader.execute();
|
|
109
|
+
return items.filter((item)=>!!item?.data).map((item)=>item.data);
|
|
110
|
+
} catch (err) {
|
|
111
|
+
throw error.from(err, {
|
|
112
|
+
message: "Could not load user across tenants.",
|
|
113
|
+
code: "GET_ADMIN_USER_ACROSS_TENANTS_ERROR",
|
|
114
|
+
data: {
|
|
115
|
+
id,
|
|
116
|
+
tenants
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
async listUserRecords (params) {
|
|
122
|
+
const { id } = params;
|
|
123
|
+
try {
|
|
124
|
+
const items = await entities.users.queryAll({
|
|
125
|
+
partitionKey: createUserIndexPartitionKey(id),
|
|
126
|
+
options: {
|
|
127
|
+
index: "GSI2"
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return items.map((item)=>item.data);
|
|
131
|
+
} catch (err) {
|
|
132
|
+
throw error.from(err, {
|
|
133
|
+
message: "Could not list user records.",
|
|
134
|
+
code: "LIST_ADMIN_USER_RECORDS_ERROR",
|
|
135
|
+
data: {
|
|
136
|
+
id
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
async listUsers ({ where, sort }) {
|
|
142
|
+
let items;
|
|
143
|
+
try {
|
|
144
|
+
const ddbItems = await entities.users.queryAll({
|
|
145
|
+
partitionKey: `T#${where.tenant}#ADMIN_USERS`,
|
|
146
|
+
options: {
|
|
147
|
+
index: "GSI1"
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
items = ddbItems.map((item)=>item.data);
|
|
151
|
+
} catch (err) {
|
|
152
|
+
throw error.from(err, {
|
|
153
|
+
message: "Could not list users.",
|
|
154
|
+
code: "LIST_ADMIN_USERS_ERROR"
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
const { id_in, teams_in } = where;
|
|
158
|
+
const filtered = items.filter((item)=>{
|
|
159
|
+
if (Array.isArray(id_in) && !id_in.includes(item.id)) return false;
|
|
160
|
+
if (Array.isArray(teams_in)) return (item.teams || []).some((team)=>teams_in.includes(team));
|
|
161
|
+
return true;
|
|
162
|
+
});
|
|
163
|
+
return sortItems({
|
|
164
|
+
items: filtered,
|
|
165
|
+
sort
|
|
166
|
+
});
|
|
167
|
+
},
|
|
168
|
+
async updateUser ({ user }) {
|
|
169
|
+
const keys = {
|
|
170
|
+
...createUserKeys(user),
|
|
171
|
+
...createUserGSIKeys(user)
|
|
172
|
+
};
|
|
173
|
+
try {
|
|
174
|
+
await entities.users.put({
|
|
175
|
+
...keys,
|
|
176
|
+
TYPE: "adminUsers.user",
|
|
177
|
+
data: user
|
|
178
|
+
});
|
|
179
|
+
return user;
|
|
180
|
+
} catch (err) {
|
|
181
|
+
throw error.from(err, {
|
|
182
|
+
message: "Could not update user.",
|
|
183
|
+
code: "UPDATE_ADMIN_USER_ERROR",
|
|
184
|
+
data: {
|
|
185
|
+
keys,
|
|
186
|
+
user
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
90
190
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
options: {
|
|
94
|
-
index: "GSI1",
|
|
95
|
-
eq: email
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
return response?.data || null;
|
|
99
|
-
} catch (err) {
|
|
100
|
-
throw WebinyError.from(err, {
|
|
101
|
-
message: "Could not load user.",
|
|
102
|
-
code: "GET_ADMIN_USERS_ERROR",
|
|
103
|
-
data: {
|
|
104
|
-
id,
|
|
105
|
-
email
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
async listUsers({
|
|
111
|
-
where,
|
|
112
|
-
sort
|
|
113
|
-
}) {
|
|
114
|
-
let items;
|
|
115
|
-
try {
|
|
116
|
-
const ddbItems = await entities.users.queryAll({
|
|
117
|
-
partitionKey: `T#${where.tenant}#ADMIN_USERS`,
|
|
118
|
-
options: {
|
|
119
|
-
index: "GSI1"
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
items = ddbItems.map(item => {
|
|
123
|
-
return item.data;
|
|
124
|
-
});
|
|
125
|
-
} catch (err) {
|
|
126
|
-
throw WebinyError.from(err, {
|
|
127
|
-
message: "Could not list users.",
|
|
128
|
-
code: "LIST_ADMIN_USERS_ERROR"
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
return sortItems({
|
|
132
|
-
items,
|
|
133
|
-
sort
|
|
134
|
-
});
|
|
135
|
-
},
|
|
136
|
-
async updateUser({
|
|
137
|
-
user
|
|
138
|
-
}) {
|
|
139
|
-
const keys = {
|
|
140
|
-
...createUserKeys(user),
|
|
141
|
-
...createUserGSIKeys(user)
|
|
142
|
-
};
|
|
143
|
-
try {
|
|
144
|
-
await entities.users.put({
|
|
145
|
-
...keys,
|
|
146
|
-
TYPE: "adminUsers.user",
|
|
147
|
-
data: user
|
|
148
|
-
});
|
|
149
|
-
return user;
|
|
150
|
-
} catch (err) {
|
|
151
|
-
throw WebinyError.from(err, {
|
|
152
|
-
message: "Could not update user.",
|
|
153
|
-
code: "UPDATE_ADMIN_USER_ERROR",
|
|
154
|
-
data: {
|
|
155
|
-
keys,
|
|
156
|
-
user
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
return storageOperations;
|
|
191
|
+
};
|
|
192
|
+
return storageOperations;
|
|
163
193
|
};
|
|
194
|
+
export { createStorageOperations };
|
|
164
195
|
|
|
165
196
|
//# sourceMappingURL=index.js.map
|
package/adminUsers/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["WebinyError","createTable","sortItems","createUserEntity","createStorageOperations","params","table","tableName","documentClient","name","process","env","DB_TABLE","entities","users","createUserKeys","user","PK","tenant","id","SK","createUserGSIKeys","GSI1_PK","GSI1_SK","email","GSI_TENANT","storageOperations","getTable","getEntities","createUser","keys","put","TYPE","data","err","from","message","code","deleteUser","delete","getUser","where","response","get","queryOne","partitionKey","options","index","eq","listUsers","sort","items","ddbItems","queryAll","map","item","updateUser"],"sources":["index.ts"],"sourcesContent":["import type { AdminUsersStorageOperations, CreateAdminUsersStorageOperations } from \"./types.js\";\nimport WebinyError from \"@webiny/error\";\nimport { createTable, type IStandardEntityAttributes, sortItems } from \"@webiny/db-dynamodb\";\nimport { createUserEntity } from \"./definitions/entities.js\";\nimport type {\n AdminUser,\n StorageOperationsGetUserParams,\n StorageOperationsListUsersParams\n} from \"@webiny/api-core/types/users.js\";\n\nexport const createStorageOperations: CreateAdminUsersStorageOperations = params => {\n const { table: tableName, documentClient } = params;\n\n const table = createTable({\n name: tableName || (process.env.DB_TABLE as string),\n documentClient\n });\n\n const entities = {\n users: createUserEntity(table.table)\n };\n\n const createUserKeys = (user: Pick<AdminUser, \"tenant\" | \"id\">) => ({\n PK: `T#${user.tenant}#ADMIN_USER#${user.id}`,\n SK: `A`\n });\n\n const createUserGSIKeys = (user: AdminUser) => {\n return {\n GSI1_PK: `T#${user.tenant}#ADMIN_USERS`,\n GSI1_SK: user.email,\n GSI_TENANT: user.tenant\n };\n };\n\n const storageOperations: AdminUsersStorageOperations = {\n getTable() {\n return table;\n },\n getEntities() {\n return entities;\n },\n async createUser({ user }) {\n const keys = {\n ...createUserKeys(user),\n ...createUserGSIKeys(user)\n };\n\n try {\n await entities.users.put({\n ...keys,\n TYPE: \"adminUsers.user\",\n data: user\n });\n\n return user;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create admin user.\",\n code: \"CREATE_ADMIN_USER_ERROR\",\n data: { keys }\n });\n }\n },\n async deleteUser({ user }) {\n const keys = createUserKeys(user);\n\n try {\n await entities.users.delete(keys);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete group.\",\n code: \"CREATE_DELETE_ERROR\",\n data: { keys, user }\n });\n }\n },\n async getUser<TUser extends AdminUser = AdminUser>(\n params: StorageOperationsGetUserParams\n ): Promise<TUser | null> {\n const {\n where: { tenant, id, email }\n } = params;\n try {\n if (id) {\n const response = await entities.users.get<IStandardEntityAttributes<TUser>>(\n createUserKeys({ tenant, id })\n );\n return (response?.data as TUser) || null;\n }\n\n const response = await entities.users.queryOne<IStandardEntityAttributes<TUser>>({\n partitionKey: `T#${tenant}#ADMIN_USERS`,\n options: {\n index: \"GSI1\",\n eq: email\n }\n });\n\n return (response?.data as TUser) || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load user.\",\n code: \"GET_ADMIN_USERS_ERROR\",\n data: { id, email }\n });\n }\n },\n async listUsers<TUser extends AdminUser = AdminUser>({\n where,\n sort\n }: StorageOperationsListUsersParams) {\n let items: TUser[];\n try {\n const ddbItems = await entities.users.queryAll<IStandardEntityAttributes<TUser>>({\n partitionKey: `T#${where.tenant}#ADMIN_USERS`,\n options: {\n index: \"GSI1\"\n }\n });\n items = ddbItems.map(item => {\n return item.data as TUser;\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list users.\",\n code: \"LIST_ADMIN_USERS_ERROR\"\n });\n }\n\n return sortItems({ items, sort });\n },\n async updateUser({ user }) {\n const keys = {\n ...createUserKeys(user),\n ...createUserGSIKeys(user)\n };\n\n try {\n await entities.users.put({\n ...keys,\n TYPE: \"adminUsers.user\",\n data: user\n });\n return user;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update user.\",\n code: \"UPDATE_ADMIN_USER_ERROR\",\n data: { keys, user }\n });\n }\n }\n };\n\n return storageOperations;\n};\n"],"mappings":"AACA,OAAOA,WAAW,MAAM,eAAe;AACvC,SAASC,WAAW,EAAkCC,SAAS,QAAQ,qBAAqB;AAC5F,SAASC,gBAAgB;AAOzB,OAAO,MAAMC,uBAA0D,GAAGC,MAAM,IAAI;EAChF,MAAM;IAAEC,KAAK,EAAEC,SAAS;IAAEC;EAAe,CAAC,GAAGH,MAAM;EAEnD,MAAMC,KAAK,GAAGL,WAAW,CAAC;IACtBQ,IAAI,EAAEF,SAAS,IAAKG,OAAO,CAACC,GAAG,CAACC,QAAmB;IACnDJ;EACJ,CAAC,CAAC;EAEF,MAAMK,QAAQ,GAAG;IACbC,KAAK,EAAEX,gBAAgB,CAACG,KAAK,CAACA,KAAK;EACvC,CAAC;EAED,MAAMS,cAAc,GAAIC,IAAsC,KAAM;IAChEC,EAAE,EAAE,KAAKD,IAAI,CAACE,MAAM,eAAeF,IAAI,CAACG,EAAE,EAAE;IAC5CC,EAAE,EAAE;EACR,CAAC,CAAC;EAEF,MAAMC,iBAAiB,GAAIL,IAAe,IAAK;IAC3C,OAAO;MACHM,OAAO,EAAE,KAAKN,IAAI,CAACE,MAAM,cAAc;MACvCK,OAAO,EAAEP,IAAI,CAACQ,KAAK;MACnBC,UAAU,EAAET,IAAI,CAACE;IACrB,CAAC;EACL,CAAC;EAED,MAAMQ,iBAA8C,GAAG;IACnDC,QAAQA,CAAA,EAAG;MACP,OAAOrB,KAAK;IAChB,CAAC;IACDsB,WAAWA,CAAA,EAAG;MACV,OAAOf,QAAQ;IACnB,CAAC;IACD,MAAMgB,UAAUA,CAAC;MAAEb;IAAK,CAAC,EAAE;MACvB,MAAMc,IAAI,GAAG;QACT,GAAG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IAAI;MAC7B,CAAC;MAED,IAAI;QACA,MAAMH,QAAQ,CAACC,KAAK,CAACiB,GAAG,CAAC;UACrB,GAAGD,IAAI;UACPE,IAAI,EAAE,iBAAiB;UACvBC,IAAI,EAAEjB;QACV,CAAC,CAAC;QACF,OAAOA,IAAI;MACf,CAAC,CAAC,OAAOkB,GAAG,EAAE;QACV,MAAMlC,WAAW,CAACmC,IAAI,CAACD,GAAG,EAAE;UACxBE,OAAO,EAAE,wBAAwB;UACjCC,IAAI,EAAE,yBAAyB;UAC/BJ,IAAI,EAAE;YAAEH,IAAI;YAAEd;UAAK;QACvB,CAAC,CAAC;MACN;IACJ;EACJ,CAAC;EAED,OAAOU,iBAAiB;AAC5B,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"adminUsers/index.js","sources":["../../src/adminUsers/index.ts"],"sourcesContent":["import type { AdminUsersStorageOperations, CreateAdminUsersStorageOperations } from \"./types.js\";\nimport WebinyError from \"@webiny/error\";\nimport { createTable, type IStandardEntityAttributes, sortItems } from \"@webiny/db-dynamodb\";\nimport { createUserEntity } from \"./definitions/entities.js\";\nimport type {\n AdminUser,\n StorageOperationsGetUserAcrossTenantsParams,\n StorageOperationsGetUserParams,\n StorageOperationsListUserRecordsParams,\n StorageOperationsListUsersParams\n} from \"@webiny/api-core/types/users.js\";\n\nexport const createStorageOperations: CreateAdminUsersStorageOperations = params => {\n const { table: tableName, documentClient } = params;\n\n const table = createTable({\n name: tableName || (process.env.DB_TABLE as string),\n documentClient\n });\n\n const entities = {\n users: createUserEntity(table.table)\n };\n\n const createUserKeys = (user: Pick<AdminUser, \"tenant\" | \"id\">) => ({\n PK: `T#${user.tenant}#ADMIN_USER#${user.id}`,\n SK: `A`\n });\n\n const createUserIndexPartitionKey = (id: string) => `ADMIN_USER#${id}`;\n\n const createUserGSIKeys = (user: AdminUser) => {\n return {\n GSI1_PK: `T#${user.tenant}#ADMIN_USERS`,\n GSI1_SK: user.email,\n // The user→tenant index: every tenant's record of one user, in one partition.\n GSI2_PK: createUserIndexPartitionKey(user.id),\n GSI2_SK: `T#${user.tenant}`,\n GSI_TENANT: user.tenant\n };\n };\n\n const storageOperations: AdminUsersStorageOperations = {\n getTable() {\n return table;\n },\n getEntities() {\n return entities;\n },\n async createUser({ user }) {\n const keys = {\n ...createUserKeys(user),\n ...createUserGSIKeys(user)\n };\n\n try {\n await entities.users.put({\n ...keys,\n TYPE: \"adminUsers.user\",\n data: user\n });\n\n return user;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create admin user.\",\n code: \"CREATE_ADMIN_USER_ERROR\",\n data: { keys }\n });\n }\n },\n async deleteUser({ user }) {\n const keys = createUserKeys(user);\n\n try {\n await entities.users.delete(keys);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete group.\",\n code: \"CREATE_DELETE_ERROR\",\n data: { keys, user }\n });\n }\n },\n async getUser<TUser extends AdminUser = AdminUser>(\n params: StorageOperationsGetUserParams\n ): Promise<TUser | null> {\n const {\n where: { tenant, id, email }\n } = params;\n try {\n if (id) {\n const response = await entities.users.get<IStandardEntityAttributes<TUser>>(\n createUserKeys({ tenant, id })\n );\n return (response?.data as TUser) || null;\n }\n\n const response = await entities.users.queryOne<IStandardEntityAttributes<TUser>>({\n partitionKey: `T#${tenant}#ADMIN_USERS`,\n options: {\n index: \"GSI1\",\n eq: email\n }\n });\n\n return (response?.data as TUser) || null;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load user.\",\n code: \"GET_ADMIN_USERS_ERROR\",\n data: { id, email }\n });\n }\n },\n async getUserAcrossTenants<TUser extends AdminUser = AdminUser>(\n params: StorageOperationsGetUserAcrossTenantsParams\n ): Promise<TUser[]> {\n const { id, tenants } = params;\n if (tenants.length === 0) {\n return [];\n }\n\n try {\n // The batch reader splits the keys into chunks of 100 (the BatchGetItem limit).\n const reader = entities.users.createEntityReader({\n read: tenants.map(tenant => createUserKeys({ tenant, id }))\n });\n const items = await reader.execute();\n\n return items\n .filter(item => !!item?.data)\n .map(item => {\n return item.data as unknown as TUser;\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load user across tenants.\",\n code: \"GET_ADMIN_USER_ACROSS_TENANTS_ERROR\",\n data: { id, tenants }\n });\n }\n },\n async listUserRecords<TUser extends AdminUser = AdminUser>(\n params: StorageOperationsListUserRecordsParams\n ): Promise<TUser[]> {\n const { id } = params;\n\n try {\n const items = await entities.users.queryAll<IStandardEntityAttributes<TUser>>({\n partitionKey: createUserIndexPartitionKey(id),\n options: {\n index: \"GSI2\"\n }\n });\n\n return items.map(item => item.data as TUser);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list user records.\",\n code: \"LIST_ADMIN_USER_RECORDS_ERROR\",\n data: { id }\n });\n }\n },\n async listUsers<TUser extends AdminUser = AdminUser>({\n where,\n sort\n }: StorageOperationsListUsersParams) {\n let items: TUser[];\n try {\n const ddbItems = await entities.users.queryAll<IStandardEntityAttributes<TUser>>({\n partitionKey: `T#${where.tenant}#ADMIN_USERS`,\n options: {\n index: \"GSI1\"\n }\n });\n items = ddbItems.map(item => {\n return item.data as TUser;\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list users.\",\n code: \"LIST_ADMIN_USERS_ERROR\"\n });\n }\n\n const { id_in, teams_in } = where;\n\n const filtered = items.filter(item => {\n if (Array.isArray(id_in) && !id_in.includes(item.id)) {\n return false;\n }\n if (Array.isArray(teams_in)) {\n return (item.teams || []).some(team => teams_in.includes(team));\n }\n return true;\n });\n\n return sortItems({ items: filtered, sort });\n },\n async updateUser({ user }) {\n const keys = {\n ...createUserKeys(user),\n ...createUserGSIKeys(user)\n };\n\n try {\n await entities.users.put({\n ...keys,\n TYPE: \"adminUsers.user\",\n data: user\n });\n return user;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update user.\",\n code: \"UPDATE_ADMIN_USER_ERROR\",\n data: { keys, user }\n });\n }\n }\n };\n\n return storageOperations;\n};\n"],"names":["createStorageOperations","params","tableName","documentClient","table","createTable","process","entities","createUserEntity","createUserKeys","user","createUserIndexPartitionKey","id","createUserGSIKeys","storageOperations","keys","err","WebinyError","tenant","email","response","tenants","reader","items","item","where","sort","ddbItems","id_in","teams_in","filtered","Array","team","sortItems"],"mappings":";;;AAYO,MAAMA,0BAA6DC,CAAAA;IACtE,MAAM,EAAE,OAAOC,SAAS,EAAEC,cAAc,EAAE,GAAGF;IAE7C,MAAMG,QAAQC,YAAY;QACtB,MAAMH,aAAcI,QAAQ,GAAG,CAAC,QAAQ;QACxCH;IACJ;IAEA,MAAMI,WAAW;QACb,OAAOC,iBAAiBJ,MAAM,KAAK;IACvC;IAEA,MAAMK,iBAAiB,CAACC,OAA4C;YAChE,IAAI,CAAC,EAAE,EAAEA,KAAK,MAAM,CAAC,YAAY,EAAEA,KAAK,EAAE,EAAE;YAC5C,IAAI;QACR;IAEA,MAAMC,8BAA8B,CAACC,KAAe,CAAC,WAAW,EAAEA,IAAI;IAEtE,MAAMC,oBAAoB,CAACH,OAChB;YACH,SAAS,CAAC,EAAE,EAAEA,KAAK,MAAM,CAAC,YAAY,CAAC;YACvC,SAASA,KAAK,KAAK;YAEnB,SAASC,4BAA4BD,KAAK,EAAE;YAC5C,SAAS,CAAC,EAAE,EAAEA,KAAK,MAAM,EAAE;YAC3B,YAAYA,KAAK,MAAM;QAC3B;IAGJ,MAAMI,oBAAiD;QACnD;YACI,OAAOV;QACX;QACA;YACI,OAAOG;QACX;QACA,MAAM,YAAW,EAAEG,IAAI,EAAE;YACrB,MAAMK,OAAO;gBACT,GAAGN,eAAeC,KAAK;gBACvB,GAAGG,kBAAkBH,KAAK;YAC9B;YAEA,IAAI;gBACA,MAAMH,SAAS,KAAK,CAAC,GAAG,CAAC;oBACrB,GAAGQ,IAAI;oBACP,MAAM;oBACN,MAAML;gBACV;gBAEA,OAAOA;YACX,EAAE,OAAOM,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT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AM,QAAQ,CAACJ,KAAK,EAAE,GAC/C,OAAO;gBAEX,IAAIO,MAAM,OAAO,CAACF,WACd,OAAQL,AAAAA,CAAAA,KAAK,KAAK,IAAI,EAAC,EAAG,IAAI,CAACQ,CAAAA,OAAQH,SAAS,QAAQ,CAACG;gBAE7D,OAAO;YACX;YAEA,OAAOC,UAAU;gBAAE,OAAOH;gBAAUJ;YAAK;QAC7C;QACA,MAAM,YAAW,EAAEhB,IAAI,EAAE;YACrB,MAAMK,OAAO;gBACT,GAAGN,eAAeC,KAAK;gBACvB,GAAGG,kBAAkBH,KAAK;YAC9B;YAEA,IAAI;gBACA,MAAMH,SAAS,KAAK,CAAC,GAAG,CAAC;oBACrB,GAAGQ,IAAI;oBACP,MAAM;oBACN,MAAML;gBACV;gBACA,OAAOA;YACX,EAAE,OAAOM,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAED;wBAAML;oBAAK;gBACvB;YACJ;QACJ;IACJ;IAEA,OAAOI;AACX"}
|
package/adminUsers/types.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var types_ENTITIES = /*#__PURE__*/ function(ENTITIES) {
|
|
2
|
+
ENTITIES["SYSTEM"] = "AdminUsers.System";
|
|
3
|
+
ENTITIES["USERS"] = "AdminUsers.User";
|
|
4
|
+
return ENTITIES;
|
|
5
5
|
}({});
|
|
6
|
+
export { types_ENTITIES as ENTITIES };
|
|
6
7
|
|
|
7
8
|
//# sourceMappingURL=types.js.map
|
package/adminUsers/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"adminUsers/types.js","sources":["../../src/adminUsers/types.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { AdminUsersStorageOperations as BaseAdminUsersStorageOperations } from \"@webiny/api-core/types/users.js\";\nimport type { IAdminUserEntity } from \"~/adminUsers/definitions/types.js\";\nimport { ITable } from \"@webiny/db-dynamodb\";\n\nexport enum ENTITIES {\n SYSTEM = \"AdminUsers.System\",\n USERS = \"AdminUsers.User\"\n}\n\nexport interface ICreateAdminUsersStorageOperationsParams {\n documentClient: DynamoDBDocument;\n table?: string;\n}\n\nexport interface CreateAdminUsersStorageOperations {\n (params: ICreateAdminUsersStorageOperationsParams): AdminUsersStorageOperations;\n}\n\nexport interface IAdminUsersGetEntitiesResponse {\n users: IAdminUserEntity;\n}\n\nexport interface AdminUsersStorageOperations extends BaseAdminUsersStorageOperations {\n getTable(): ITable;\n getEntities(): IAdminUsersGetEntitiesResponse;\n}\n"],"names":["ENTITIES"],"mappings":"AAKO,IAAKA,iBAAQA,WAAAA,GAAAA,SAAAA,QAAAA"}
|
package/createApiCoreDdb.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createStorageOperations
|
|
3
|
-
import { createStorageOperations as
|
|
4
|
-
import { createStorageOperations as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import { ServiceDiscovery } from "@webiny/api-core/features/serviceDiscovery/index.js";
|
|
2
|
+
import { createStorageOperations } from "./adminUsers/index.js";
|
|
3
|
+
import { createStorageOperations as index_js_createStorageOperations } from "./tenancy/index.js";
|
|
4
|
+
import { createStorageOperations as external_security_index_js_createStorageOperations } from "./security/index.js";
|
|
5
|
+
import { createStorageOperations as external_keyValueStore_index_js_createStorageOperations } from "./keyValueStore/index.js";
|
|
6
|
+
import { DdbServiceManifestLoader } from "./serviceDiscovery/index.js";
|
|
7
|
+
const createApiCoreDdb = ({ documentClient })=>{
|
|
8
|
+
ServiceDiscovery.setLoader(new DdbServiceManifestLoader(documentClient));
|
|
9
|
+
return {
|
|
10
|
+
usersStorageOperations: createStorageOperations({
|
|
11
|
+
documentClient
|
|
12
|
+
}),
|
|
13
|
+
tenancyStorageOperations: index_js_createStorageOperations({
|
|
14
|
+
documentClient
|
|
15
|
+
}),
|
|
16
|
+
securityStorageOperations: external_security_index_js_createStorageOperations({
|
|
17
|
+
documentClient
|
|
18
|
+
}),
|
|
19
|
+
keyValueStorageOperations: external_keyValueStore_index_js_createStorageOperations({
|
|
20
|
+
documentClient
|
|
21
|
+
})
|
|
22
|
+
};
|
|
22
23
|
};
|
|
24
|
+
export { createApiCoreDdb };
|
|
23
25
|
|
|
24
26
|
//# sourceMappingURL=createApiCoreDdb.js.map
|
package/createApiCoreDdb.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"createApiCoreDdb.js","sources":["../src/createApiCoreDdb.ts"],"sourcesContent":["import type { ApiCoreStorageOperations } from \"@webiny/api-core/types/core.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { ServiceDiscovery } from \"@webiny/api-core/features/serviceDiscovery/index.js\";\nimport { createStorageOperations as createUsersStorageOperations } from \"./adminUsers/index.js\";\nimport { createStorageOperations as createTenancyStorageOperations } from \"./tenancy/index.js\";\nimport { createStorageOperations as createSecurityStorageOperations } from \"./security/index.js\";\nimport { createStorageOperations as createKeyValueStorageOperations } from \"./keyValueStore/index.js\";\nimport { DdbServiceManifestLoader } from \"./serviceDiscovery/index.js\";\n\ninterface CreateApiCoreDdbParams {\n documentClient: DynamoDBDocument;\n}\n\nexport const createApiCoreDdb = ({\n documentClient\n}: CreateApiCoreDdbParams): ApiCoreStorageOperations => {\n ServiceDiscovery.setLoader(new DdbServiceManifestLoader(documentClient));\n\n return {\n usersStorageOperations: createUsersStorageOperations({\n documentClient\n }),\n tenancyStorageOperations: createTenancyStorageOperations({\n documentClient\n }),\n securityStorageOperations: createSecurityStorageOperations({\n documentClient\n }),\n keyValueStorageOperations: createKeyValueStorageOperations({\n documentClient\n })\n };\n};\n"],"names":["createApiCoreDdb","documentClient","ServiceDiscovery","DdbServiceManifestLoader","createUsersStorageOperations","createTenancyStorageOperations","createSecurityStorageOperations","createKeyValueStorageOperations"],"mappings":";;;;;;AAaO,MAAMA,mBAAmB,CAAC,EAC7BC,cAAc,EACO;IACrBC,iBAAiB,SAAS,CAAC,IAAIC,yBAAyBF;IAExD,OAAO;QACH,wBAAwBG,wBAA6B;YACjDH;QACJ;QACA,0BAA0BI,iCAA+B;YACrDJ;QACJ;QACA,2BAA2BK,mDAAgC;YACvDL;QACJ;QACA,2BAA2BM,wDAAgC;YACvDN;QACJ;IACJ;AACJ"}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from "./createApiCoreDdb.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export { ApiCoreDdbFeature } from "./ApiCoreDdbFeature.js";
|
|
3
|
+
export { DdbServiceManifestLoader } from "./serviceDiscovery/index.js";
|
|
@@ -3,6 +3,11 @@ import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js"
|
|
|
3
3
|
interface CreateKeysParams {
|
|
4
4
|
scopedKey: string;
|
|
5
5
|
}
|
|
6
|
+
interface CreateListKeysParams {
|
|
7
|
+
key: string;
|
|
8
|
+
scope: string;
|
|
9
|
+
collection: string;
|
|
10
|
+
}
|
|
6
11
|
export declare class KeyValueStoreDynamoTable<T extends GenericRecord> {
|
|
7
12
|
private readonly entity;
|
|
8
13
|
constructor(documentClient: DynamoDBDocument);
|
|
@@ -10,6 +15,25 @@ export declare class KeyValueStoreDynamoTable<T extends GenericRecord> {
|
|
|
10
15
|
PK: string;
|
|
11
16
|
SK: string;
|
|
12
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* GSI1 keys for a member of a collection. Each collection is its own GSI1 partition, sorted by
|
|
20
|
+
* key, so `list` is one Query on it. A record outside every collection gets no GSI1 keys at all
|
|
21
|
+
* and costs the index nothing. The primary key gives each record its own partition, which a
|
|
22
|
+
* Query cannot list.
|
|
23
|
+
*/
|
|
24
|
+
createListKeys({ key, scope, collection }: CreateListKeysParams): {
|
|
25
|
+
GSI1_PK: string;
|
|
26
|
+
GSI1_SK: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The scope's length goes in front so the key reads back one way only: without it, scope `a#b`
|
|
30
|
+
* with collection `c` and scope `a` with collection `b#c` would share a partition, and a list
|
|
31
|
+
* in one scope would return another scope's records.
|
|
32
|
+
*/
|
|
33
|
+
createListPartitionKey(scope: string, collection: string): string;
|
|
34
|
+
/** Prefixed because DynamoDB rejects an empty string as an index key, and `""` is a valid key. */
|
|
35
|
+
createListSortKey(key: string): string;
|
|
36
|
+
parseListSortKey(sortKey: string): string;
|
|
13
37
|
getEntity(): import("@webiny/db-dynamodb").IEntity<import("@webiny/db-dynamodb").IGlobalEntityAttributes<T>>;
|
|
14
38
|
}
|
|
15
39
|
export {};
|