@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.
Files changed (47) hide show
  1. package/ApiCoreDdbFeature.d.ts +12 -0
  2. package/ApiCoreDdbFeature.js +16 -0
  3. package/ApiCoreDdbFeature.js.map +1 -0
  4. package/adminUsers/definitions/entities.js +5 -6
  5. package/adminUsers/definitions/entities.js.map +1 -1
  6. package/adminUsers/definitions/types.js +0 -3
  7. package/adminUsers/index.js +187 -156
  8. package/adminUsers/index.js.map +1 -1
  9. package/adminUsers/types.js +5 -4
  10. package/adminUsers/types.js.map +1 -1
  11. package/createApiCoreDdb.js +23 -21
  12. package/createApiCoreDdb.js.map +1 -1
  13. package/index.d.ts +3 -0
  14. package/index.js +2 -2
  15. package/keyValueStore/KeyValueStoreDynamoTable.d.ts +24 -0
  16. package/keyValueStore/KeyValueStoreDynamoTable.js +39 -25
  17. package/keyValueStore/KeyValueStoreDynamoTable.js.map +1 -1
  18. package/keyValueStore/KeyValueStoreStorageOperations.d.ts +14 -2
  19. package/keyValueStore/KeyValueStoreStorageOperations.js +222 -71
  20. package/keyValueStore/KeyValueStoreStorageOperations.js.map +1 -1
  21. package/keyValueStore/index.js +2 -3
  22. package/keyValueStore/index.js.map +1 -1
  23. package/package.json +20 -15
  24. package/security/definitions/entities.js +19 -24
  25. package/security/definitions/entities.js.map +1 -1
  26. package/security/definitions/types.d.ts +3 -3
  27. package/security/definitions/types.js +0 -3
  28. package/security/index.js +389 -464
  29. package/security/index.js.map +1 -1
  30. package/security/types.js +6 -5
  31. package/security/types.js.map +1 -1
  32. package/serviceDiscovery/DdbServiceManifestLoader.d.ts +7 -0
  33. package/serviceDiscovery/DdbServiceManifestLoader.js +27 -0
  34. package/serviceDiscovery/DdbServiceManifestLoader.js.map +1 -0
  35. package/serviceDiscovery/index.d.ts +1 -0
  36. package/serviceDiscovery/index.js +1 -0
  37. package/tenancy/definitions/tenantEntity.js +5 -9
  38. package/tenancy/definitions/tenantEntity.js.map +1 -1
  39. package/tenancy/definitions/types.js +0 -3
  40. package/tenancy/index.js +107 -127
  41. package/tenancy/index.js.map +1 -1
  42. package/tenancy/types.js +4 -3
  43. package/tenancy/types.js.map +1 -1
  44. package/adminUsers/definitions/types.js.map +0 -1
  45. package/index.js.map +0 -1
  46. package/security/definitions/types.js.map +0 -1
  47. package/tenancy/definitions/types.js.map +0 -1
@@ -1,29 +1,43 @@
1
1
  import { createGlobalEntity, createTable, globalEntityAttributes } from "@webiny/db-dynamodb";
2
- export class KeyValueStoreDynamoTable {
3
- constructor(documentClient) {
4
- const table = createTable({
5
- name: process.env.DB_TABLE,
6
- documentClient
7
- });
8
- this.entity = createGlobalEntity({
9
- name: "KeyValueStore",
10
- table: table.table,
11
- attributes: {
12
- ...globalEntityAttributes
13
- }
14
- });
15
- }
16
- createKeys({
17
- scopedKey
18
- }) {
19
- return {
20
- PK: `KV#${scopedKey}`,
21
- SK: `A`
22
- };
23
- }
24
- getEntity() {
25
- return this.entity;
26
- }
2
+ class KeyValueStoreDynamoTable {
3
+ constructor(documentClient){
4
+ const table = createTable({
5
+ name: process.env.DB_TABLE,
6
+ documentClient
7
+ });
8
+ this.entity = createGlobalEntity({
9
+ name: "KeyValueStore",
10
+ table: table.table,
11
+ attributes: {
12
+ ...globalEntityAttributes
13
+ }
14
+ });
15
+ }
16
+ createKeys({ scopedKey }) {
17
+ return {
18
+ PK: `KV#${scopedKey}`,
19
+ SK: "A"
20
+ };
21
+ }
22
+ createListKeys({ key, scope, collection }) {
23
+ return {
24
+ GSI1_PK: this.createListPartitionKey(scope, collection),
25
+ GSI1_SK: this.createListSortKey(key)
26
+ };
27
+ }
28
+ createListPartitionKey(scope, collection) {
29
+ return `KV#COL#${scope.length}#${scope}#${collection}`;
30
+ }
31
+ createListSortKey(key) {
32
+ return `K#${key}`;
33
+ }
34
+ parseListSortKey(sortKey) {
35
+ return sortKey.slice(2);
36
+ }
37
+ getEntity() {
38
+ return this.entity;
39
+ }
27
40
  }
41
+ export { KeyValueStoreDynamoTable };
28
42
 
29
43
  //# sourceMappingURL=KeyValueStoreDynamoTable.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createGlobalEntity","createTable","globalEntityAttributes","KeyValueStoreDynamoTable","constructor","documentClient","table","name","process","env","DB_TABLE","entity","attributes","createKeys","scopedKey","PK","SK","getEntity"],"sources":["KeyValueStoreDynamoTable.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { createGlobalEntity, createTable, globalEntityAttributes } from \"@webiny/db-dynamodb\";\n\ninterface CreateKeysParams {\n scopedKey: string;\n}\n\nexport class KeyValueStoreDynamoTable<T extends GenericRecord> {\n private readonly entity;\n\n constructor(documentClient: DynamoDBDocument) {\n const table = createTable({\n name: process.env.DB_TABLE as string,\n documentClient\n });\n this.entity = createGlobalEntity<T>({\n name: \"KeyValueStore\",\n table: table.table,\n attributes: {\n ...globalEntityAttributes\n }\n });\n }\n\n createKeys({ scopedKey }: CreateKeysParams) {\n return {\n PK: `KV#${scopedKey}`,\n SK: `A`\n };\n }\n\n getEntity() {\n return this.entity;\n }\n}\n"],"mappings":"AAEA,SAASA,kBAAkB,EAAEC,WAAW,EAAEC,sBAAsB,QAAQ,qBAAqB;AAM7F,OAAO,MAAMC,wBAAwB,CAA0B;EAG3DC,WAAWA,CAACC,cAAgC,EAAE;IAC1C,MAAMC,KAAK,GAAGL,WAAW,CAAC;MACtBM,IAAI,EAAEC,OAAO,CAACC,GAAG,CAACC,QAAkB;MACpCL;IACJ,CAAC,CAAC;IACF,IAAI,CAACM,MAAM,GAAGX,kBAAkB,CAAI;MAChCO,IAAI,EAAE,eAAe;MACrBD,KAAK,EAAEA,KAAK,CAACA,KAAK;MAClBM,UAAU,EAAE;QACR,GAAGV;MACP;IACJ,CAAC,CAAC;EACN;EAEAW,UAAUA,CAAC;IAAEC;EAA4B,CAAC,EAAE;IACxC,OAAO;MACHC,EAAE,EAAE,MAAMD,SAAS,EAAE;MACrBE,EAAE,EAAE;IACR,CAAC;EACL;EAEAC,SAASA,CAAA,EAAG;IACR,OAAO,IAAI,CAACN,MAAM;EACtB;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"keyValueStore/KeyValueStoreDynamoTable.js","sources":["../../src/keyValueStore/KeyValueStoreDynamoTable.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { createGlobalEntity, createTable, globalEntityAttributes } from \"@webiny/db-dynamodb\";\n\ninterface CreateKeysParams {\n scopedKey: string;\n}\n\ninterface CreateListKeysParams {\n key: string;\n scope: string;\n collection: string;\n}\n\nexport class KeyValueStoreDynamoTable<T extends GenericRecord> {\n private readonly entity;\n\n constructor(documentClient: DynamoDBDocument) {\n const table = createTable({\n name: process.env.DB_TABLE as string,\n documentClient\n });\n this.entity = createGlobalEntity<T>({\n name: \"KeyValueStore\",\n table: table.table,\n attributes: {\n ...globalEntityAttributes\n }\n });\n }\n\n createKeys({ scopedKey }: CreateKeysParams) {\n return {\n PK: `KV#${scopedKey}`,\n SK: `A`\n };\n }\n\n /**\n * GSI1 keys for a member of a collection. Each collection is its own GSI1 partition, sorted by\n * key, so `list` is one Query on it. A record outside every collection gets no GSI1 keys at all\n * and costs the index nothing. The primary key gives each record its own partition, which a\n * Query cannot list.\n */\n createListKeys({ key, scope, collection }: CreateListKeysParams) {\n return {\n GSI1_PK: this.createListPartitionKey(scope, collection),\n GSI1_SK: this.createListSortKey(key)\n };\n }\n\n /**\n * The scope's length goes in front so the key reads back one way only: without it, scope `a#b`\n * with collection `c` and scope `a` with collection `b#c` would share a partition, and a list\n * in one scope would return another scope's records.\n */\n createListPartitionKey(scope: string, collection: string) {\n return `KV#COL#${scope.length}#${scope}#${collection}`;\n }\n\n /** Prefixed because DynamoDB rejects an empty string as an index key, and `\"\"` is a valid key. */\n createListSortKey(key: string) {\n return `K#${key}`;\n }\n\n parseListSortKey(sortKey: string) {\n return sortKey.slice(\"K#\".length);\n }\n\n getEntity() {\n return this.entity;\n }\n}\n"],"names":["KeyValueStoreDynamoTable","documentClient","table","createTable","process","createGlobalEntity","globalEntityAttributes","scopedKey","key","scope","collection","sortKey"],"mappings":";AAcO,MAAMA;IAGT,YAAYC,cAAgC,CAAE;QAC1C,MAAMC,QAAQC,YAAY;YACtB,MAAMC,QAAQ,GAAG,CAAC,QAAQ;YAC1BH;QACJ;QACA,IAAI,CAAC,MAAM,GAAGI,mBAAsB;YAChC,MAAM;YACN,OAAOH,MAAM,KAAK;YAClB,YAAY;gBACR,GAAGI,sBAAsB;YAC7B;QACJ;IACJ;IAEA,WAAW,EAAEC,SAAS,EAAoB,EAAE;QACxC,OAAO;YACH,IAAI,CAAC,GAAG,EAAEA,WAAW;YACrB,IAAI;QACR;IACJ;IAQA,eAAe,EAAEC,GAAG,EAAEC,KAAK,EAAEC,UAAU,EAAwB,EAAE;QAC7D,OAAO;YACH,SAAS,IAAI,CAAC,sBAAsB,CAACD,OAAOC;YAC5C,SAAS,IAAI,CAAC,iBAAiB,CAACF;QACpC;IACJ;IAOA,uBAAuBC,KAAa,EAAEC,UAAkB,EAAE;QACtD,OAAO,CAAC,OAAO,EAAED,MAAM,MAAM,CAAC,CAAC,EAAEA,MAAM,CAAC,EAAEC,YAAY;IAC1D;IAGA,kBAAkBF,GAAW,EAAE;QAC3B,OAAO,CAAC,EAAE,EAAEA,KAAK;IACrB;IAEA,iBAAiBG,OAAe,EAAE;QAC9B,OAAOA,QAAQ,KAAK,CAAC;IACzB;IAEA,YAAY;QACR,OAAO,IAAI,CAAC,MAAM;IACtB;AACJ"}
@@ -1,4 +1,8 @@
1
1
  import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
2
+ import type { IKeyValueStorageListParams } from "@webiny/api-core/features/keyValueStore/abstractions.js";
3
+ import type { IKeyValueStorageListResult } from "@webiny/api-core/features/keyValueStore/abstractions.js";
4
+ import type { IKeyValueStoreSetOptions } from "@webiny/api-core/features/keyValueStore/abstractions.js";
5
+ import type { IKeyValueDeleteOptions } from "@webiny/api-core/features/keyValueStore/abstractions.js";
2
6
  interface KeyValueRecord {
3
7
  key: string;
4
8
  value: any;
@@ -7,10 +11,18 @@ interface KeyValueRecord {
7
11
  export declare class KeyValueStoreStorageOperations {
8
12
  private readonly table;
9
13
  private readonly entity;
14
+ private readonly client;
10
15
  constructor(dynamoDbClient: DynamoDBDocument);
11
16
  private createScopedKey;
12
17
  get(key: string, scope: string): Promise<KeyValueRecord | null>;
13
- set(key: string, value: any, scope: string): Promise<void>;
14
- delete(key: string, scope: string): Promise<void>;
18
+ set(key: string, value: any, scope: string, options?: IKeyValueStoreSetOptions): Promise<boolean>;
19
+ delete(key: string, scope: string, options?: IKeyValueDeleteOptions): Promise<boolean>;
20
+ list(params: IKeyValueStorageListParams): Promise<IKeyValueStorageListResult>;
21
+ /**
22
+ * A GSI query resumes from the full key of an item: the table's own PK and SK as well as the
23
+ * index's. All four follow from the scope, collection and key, so the item does not have to
24
+ * exist any more.
25
+ */
26
+ private createStartKey;
15
27
  }
16
28
  export {};
@@ -1,83 +1,234 @@
1
1
  import { WebinyError } from "@webiny/error";
2
2
  import { KeyValueStoreDynamoTable } from "./KeyValueStoreDynamoTable.js";
3
- export class KeyValueStoreStorageOperations {
4
- constructor(dynamoDbClient) {
5
- this.table = new KeyValueStoreDynamoTable(dynamoDbClient);
6
- this.entity = this.table.getEntity();
7
- }
8
- createScopedKey(key, scope) {
9
- return `${scope}:${key}`;
10
- }
11
- async get(key, scope) {
12
- try {
13
- const scopedKey = this.createScopedKey(key, scope);
14
- const entry = await this.entity.get(this.table.createKeys({
15
- scopedKey
16
- }));
17
- if (!entry) {
18
- return null;
19
- }
20
-
21
- // Return the user-facing key without scope prefix
22
- return {
23
- key,
24
- value: entry.data.value,
25
- scope: entry.data.scope
26
- };
27
- } catch (err) {
28
- throw WebinyError.from(err, {
29
- message: "Could not get key-value record.",
30
- code: "GET_KEY_VALUE_ERROR",
31
- data: {
32
- key,
33
- scope
3
+ const nowInSeconds = ()=>Math.floor(Date.now() / 1000);
4
+ const toEpochSeconds = (date)=>Math.ceil(date.getTime() / 1000);
5
+ const isExpired = (expiresAt)=>{
6
+ const ttl = Number(expiresAt);
7
+ return Boolean(ttl) && ttl <= nowInSeconds();
8
+ };
9
+ const isConditionFailed = (error)=>error?.name === "ConditionalCheckFailedException";
10
+ const notExistsCondition = ()=>({
11
+ expression: "attribute_not_exists(#pk) OR #expiresAt <= :now",
12
+ names: {
13
+ "#pk": "PK",
14
+ "#expiresAt": "expiresAt"
15
+ },
16
+ values: {
17
+ ":now": nowInSeconds()
18
+ }
19
+ });
20
+ const liveCondition = ()=>({
21
+ expression: "attribute_exists(#pk) AND (attribute_not_exists(#expiresAt) OR #expiresAt > :now)",
22
+ names: {
23
+ "#pk": "PK",
24
+ "#expiresAt": "expiresAt"
25
+ },
26
+ values: {
27
+ ":now": nowInSeconds()
28
+ }
29
+ });
30
+ const liveValueCondition = (equals)=>({
31
+ expression: "#data.#value = :equals AND (attribute_not_exists(#expiresAt) OR #expiresAt > :now)",
32
+ names: {
33
+ "#data": "data",
34
+ "#value": "value",
35
+ "#expiresAt": "expiresAt"
36
+ },
37
+ values: {
38
+ ":equals": equals,
39
+ ":now": nowInSeconds()
40
+ }
41
+ });
42
+ const toCondition = (condition)=>{
43
+ if (!condition) return;
44
+ if (void 0 !== condition.equals) return liveValueCondition(condition.equals);
45
+ if (condition.exists) return liveCondition();
46
+ return notExistsCondition();
47
+ };
48
+ class KeyValueStoreStorageOperations {
49
+ constructor(dynamoDbClient){
50
+ this.table = new KeyValueStoreDynamoTable(dynamoDbClient);
51
+ this.entity = this.table.getEntity();
52
+ this.client = dynamoDbClient;
53
+ }
54
+ createScopedKey(key, scope) {
55
+ return `${scope}:${key}`;
56
+ }
57
+ async get(key, scope) {
58
+ try {
59
+ const scopedKey = this.createScopedKey(key, scope);
60
+ const entry = await this.entity.get(this.table.createKeys({
61
+ scopedKey
62
+ }));
63
+ if (!entry) return null;
64
+ if (isExpired(entry.expiresAt)) return null;
65
+ return {
66
+ key,
67
+ value: entry.data.value,
68
+ scope: entry.data.scope
69
+ };
70
+ } catch (err) {
71
+ throw WebinyError.from(err, {
72
+ message: "Could not get key-value record.",
73
+ code: "GET_KEY_VALUE_ERROR",
74
+ data: {
75
+ key,
76
+ scope
77
+ }
78
+ });
34
79
  }
35
- });
36
80
  }
37
- }
38
- async set(key, value, scope) {
39
- try {
40
- const scopedKey = this.createScopedKey(key, scope);
41
- const keys = this.table.createKeys({
42
- scopedKey
43
- });
44
- await this.entity.put({
45
- ...keys,
46
- TYPE: "KeyValueStore",
47
- data: {
48
- key,
49
- value,
50
- scope
81
+ async set(key, value, scope, options) {
82
+ try {
83
+ const scopedKey = this.createScopedKey(key, scope);
84
+ const keys = this.table.createKeys({
85
+ scopedKey
86
+ });
87
+ const item = {
88
+ ...keys,
89
+ TYPE: "KeyValueStore",
90
+ expiresAt: options?.expiresAt ? toEpochSeconds(options.expiresAt) : void 0,
91
+ data: {
92
+ key,
93
+ value,
94
+ scope
95
+ }
96
+ };
97
+ const collection = options?.collection;
98
+ if (collection) {
99
+ const listKeys = this.table.createListKeys({
100
+ key,
101
+ scope,
102
+ collection
103
+ });
104
+ Object.assign(item, listKeys);
105
+ }
106
+ const condition = toCondition(options?.condition);
107
+ if (!condition) {
108
+ await this.entity.put(item);
109
+ return true;
110
+ }
111
+ const params = this.entity.entity.putParams(item, {
112
+ strictSchemaCheck: false
113
+ });
114
+ await this.client.put({
115
+ ...params,
116
+ ConditionExpression: condition.expression,
117
+ ExpressionAttributeNames: {
118
+ ...params.ExpressionAttributeNames,
119
+ ...condition.names
120
+ },
121
+ ExpressionAttributeValues: {
122
+ ...params.ExpressionAttributeValues,
123
+ ...condition.values
124
+ }
125
+ });
126
+ return true;
127
+ } catch (err) {
128
+ if (isConditionFailed(err)) return false;
129
+ throw WebinyError.from(err, {
130
+ message: "Could not set key-value record.",
131
+ code: "SET_KEY_VALUE_ERROR",
132
+ data: {
133
+ key,
134
+ scope
135
+ }
136
+ });
51
137
  }
52
- });
53
- } catch (err) {
54
- throw WebinyError.from(err, {
55
- message: "Could not set key-value record.",
56
- code: "SET_KEY_VALUE_ERROR",
57
- data: {
58
- key,
59
- scope
138
+ }
139
+ async delete(key, scope, options) {
140
+ try {
141
+ const scopedKey = this.createScopedKey(key, scope);
142
+ const keys = this.table.createKeys({
143
+ scopedKey
144
+ });
145
+ const condition = toCondition(options?.condition);
146
+ if (!condition) {
147
+ await this.entity.delete(keys);
148
+ return true;
149
+ }
150
+ const params = this.entity.entity.deleteParams(keys);
151
+ await this.client.delete({
152
+ ...params,
153
+ ConditionExpression: condition.expression,
154
+ ExpressionAttributeNames: {
155
+ ...params.ExpressionAttributeNames,
156
+ ...condition.names
157
+ },
158
+ ExpressionAttributeValues: {
159
+ ...params.ExpressionAttributeValues,
160
+ ...condition.values
161
+ }
162
+ });
163
+ return true;
164
+ } catch (err) {
165
+ if (isConditionFailed(err)) return false;
166
+ throw WebinyError.from(err, {
167
+ message: "Could not delete key-value record.",
168
+ code: "DELETE_KEY_VALUE_ERROR",
169
+ data: {
170
+ key,
171
+ scope
172
+ }
173
+ });
60
174
  }
61
- });
62
175
  }
63
- }
64
- async delete(key, scope) {
65
- try {
66
- const scopedKey = this.createScopedKey(key, scope);
67
- await this.entity.delete(this.table.createKeys({
68
- scopedKey
69
- }));
70
- } catch (err) {
71
- throw WebinyError.from(err, {
72
- message: "Could not delete key-value record.",
73
- code: "DELETE_KEY_VALUE_ERROR",
74
- data: {
75
- key,
76
- scope
176
+ async list(params) {
177
+ const { collection, scope, limit, reverse, after } = params;
178
+ try {
179
+ const partitionKey = this.table.createListPartitionKey(scope, collection);
180
+ let startKey;
181
+ if (void 0 !== after) startKey = this.createStartKey({
182
+ key: after,
183
+ scope,
184
+ collection
185
+ });
186
+ const { items, lastEvaluatedKey } = await this.entity.queryPerPage({
187
+ partitionKey,
188
+ options: {
189
+ index: "GSI1",
190
+ limit: limit + 1,
191
+ reverse,
192
+ startKey
193
+ }
194
+ });
195
+ const page = items.slice(0, limit);
196
+ const keyOf = (item)=>item.data.key ?? "";
197
+ let lastKey = null;
198
+ if (items.length > limit) lastKey = keyOf(page[page.length - 1]);
199
+ else if (lastEvaluatedKey) lastKey = this.table.parseListSortKey(lastEvaluatedKey.GSI1_SK);
200
+ return {
201
+ items: page.filter((item)=>!isExpired(item.expiresAt)).map((item)=>({
202
+ key: keyOf(item),
203
+ value: item.data.value
204
+ })),
205
+ lastKey
206
+ };
207
+ } catch (err) {
208
+ throw WebinyError.from(err, {
209
+ message: "Could not list key-value records.",
210
+ code: "LIST_KEY_VALUE_ERROR",
211
+ data: {
212
+ collection,
213
+ scope,
214
+ after
215
+ }
216
+ });
77
217
  }
78
- });
79
218
  }
80
- }
219
+ createStartKey(params) {
220
+ const { key, scope } = params;
221
+ const scopedKey = this.createScopedKey(key, scope);
222
+ const tableKeys = this.table.createKeys({
223
+ scopedKey
224
+ });
225
+ const listKeys = this.table.createListKeys(params);
226
+ return {
227
+ ...tableKeys,
228
+ ...listKeys
229
+ };
230
+ }
81
231
  }
232
+ export { KeyValueStoreStorageOperations };
82
233
 
83
234
  //# sourceMappingURL=KeyValueStoreStorageOperations.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["WebinyError","KeyValueStoreDynamoTable","KeyValueStoreStorageOperations","constructor","dynamoDbClient","table","entity","getEntity","createScopedKey","key","scope","get","scopedKey","entry","createKeys","value","data","err","from","message","code","set","keys","put","TYPE","delete"],"sources":["KeyValueStoreStorageOperations.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport { KeyValueStoreDynamoTable } from \"./KeyValueStoreDynamoTable.js\";\n\ninterface KeyValueRecord {\n key: string;\n value: any;\n scope: string;\n}\n\nexport class KeyValueStoreStorageOperations {\n private readonly table;\n private readonly entity;\n\n constructor(dynamoDbClient: DynamoDBDocument) {\n this.table = new KeyValueStoreDynamoTable<KeyValueRecord>(dynamoDbClient);\n this.entity = this.table.getEntity();\n }\n\n private createScopedKey(key: string, scope: string): string {\n return `${scope}:${key}`;\n }\n\n async get(key: string, scope: string): Promise<KeyValueRecord | null> {\n try {\n const scopedKey = this.createScopedKey(key, scope);\n const entry = await this.entity.get(this.table.createKeys({ scopedKey }));\n\n if (!entry) {\n return null;\n }\n\n // Return the user-facing key without scope prefix\n return {\n key,\n value: entry.data.value,\n scope: entry.data.scope\n };\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not get key-value record.\",\n code: \"GET_KEY_VALUE_ERROR\",\n data: { key, scope }\n });\n }\n }\n\n async set(key: string, value: any, scope: string): Promise<void> {\n try {\n const scopedKey = this.createScopedKey(key, scope);\n const keys = this.table.createKeys({ scopedKey });\n\n await this.entity.put({\n ...keys,\n TYPE: \"KeyValueStore\",\n data: {\n key,\n value,\n scope\n }\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not set key-value record.\",\n code: \"SET_KEY_VALUE_ERROR\",\n data: { key, scope }\n });\n }\n }\n\n async delete(key: string, scope: string): Promise<void> {\n try {\n const scopedKey = this.createScopedKey(key, scope);\n await this.entity.delete(this.table.createKeys({ scopedKey }));\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete key-value record.\",\n code: \"DELETE_KEY_VALUE_ERROR\",\n data: { key, scope }\n });\n }\n }\n}\n"],"mappings":"AACA,SAASA,WAAW,QAAQ,eAAe;AAC3C,SAASC,wBAAwB;AAQjC,OAAO,MAAMC,8BAA8B,CAAC;EAIxCC,WAAWA,CAACC,cAAgC,EAAE;IAC1C,IAAI,CAACC,KAAK,GAAG,IAAIJ,wBAAwB,CAAiBG,cAAc,CAAC;IACzE,IA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;QACJ;MACJ,CAAC,CAAC;IACN,CAAC,CAAC,OAAOO,GAAG,EAAE;MACV,MAAMjB,WAAW,CAACkB,IAAI,CAACD,GAAG,EAAE;QACxBE,OAAO,EAAE,iCAAiC;QAC1CC,IAAI,EAAE,qBAAqB;QAC3BJ,IAAI,EAAE;UAAEP,GAAG;UAAEC;QAAM;MACvB,CAAC,CAAC;IACN;EACJ;EAEA,MAAMe,MAAMA,CAAChB,GAAW,EAAEC,KAAa,EAAiB;IACpD,IAAI;MACA,MAAME,SAAS,GAAG,IAAI,CAACJ,eAAe,CAACC,GAAG,EAAEC,KAAK,CAAC;MAClD,MAAM,IAAI,CAACJ,MAAM,CAACmB,MAAM,CAAC,IAAI,CAACpB,KAAK,CAACS,UAAU,CAAC;QAAEF;MAAU,CAAC,CAAC,CAAC;IAClE,CAAC,CAAC,OAAOK,GAAG,EAAE;MACV,MAAMjB,WAAW,CAACkB,IAAI,CAACD,GAAG,EAAE;QACxBE,OAAO,EAAE,oCAAoC;QAC7CC,IAAI,EAAE,wBAAwB;QAC9BJ,IAAI,EAAE;UAAEP,GAAG;UAAEC;QAAM;MACvB,CAAC,CAAC;IACN;EACJ;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"keyValueStore/KeyValueStoreStorageOperations.js","sources":["../../src/keyValueStore/KeyValueStoreStorageOperations.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport type { IKeyValueStorageListParams } from \"@webiny/api-core/features/keyValueStore/abstractions.js\";\nimport type { IKeyValueStorageListResult } from \"@webiny/api-core/features/keyValueStore/abstractions.js\";\nimport type { IKeyValueStoreSetOptions } from \"@webiny/api-core/features/keyValueStore/abstractions.js\";\nimport type { IKeyValueDeleteOptions } from \"@webiny/api-core/features/keyValueStore/abstractions.js\";\nimport type { IKeyValueWriteCondition } from \"@webiny/api-core/features/keyValueStore/abstractions.js\";\nimport type { KeyValueComparable } from \"@webiny/api-core/features/keyValueStore/abstractions.js\";\nimport type { IGlobalEntityAttributes } from \"@webiny/db-dynamodb\";\nimport { KeyValueStoreDynamoTable } from \"./KeyValueStoreDynamoTable.js\";\n\ninterface KeyValueRecord {\n key: string;\n value: any;\n scope: string;\n}\n\nconst nowInSeconds = (): number => {\n return Math.floor(Date.now() / 1000);\n};\n\n/*\n * DynamoDB keeps `expiresAt` in whole seconds. Rounded up, a record never counts as expired before\n * the time it was given; rounded down, an `exists: false` write could take it over up to a\n * second early.\n */\nconst toEpochSeconds = (date: Date): number => {\n return Math.ceil(date.getTime() / 1000);\n};\n\nconst isExpired = (expiresAt: unknown): boolean => {\n const ttl = Number(expiresAt);\n return Boolean(ttl) && ttl <= nowInSeconds();\n};\n\nconst isConditionFailed = (error: unknown): boolean => {\n return (error as { name?: unknown })?.name === \"ConditionalCheckFailedException\";\n};\n\ninterface ICondition {\n expression: string;\n names: Record<string, string>;\n values: Record<string, unknown>;\n}\n\n/*\n * DynamoDB's TTL deletes expired items late, so each condition checks the time itself. DynamoDB\n * rejects a name or value the expression does not use, so each condition carries exactly its own.\n */\nconst notExistsCondition = (): ICondition => {\n return {\n expression: \"attribute_not_exists(#pk) OR #expiresAt <= :now\",\n names: { \"#pk\": \"PK\", \"#expiresAt\": \"expiresAt\" },\n values: { \":now\": nowInSeconds() }\n };\n};\n\nconst liveCondition = (): ICondition => {\n return {\n expression:\n \"attribute_exists(#pk) AND (attribute_not_exists(#expiresAt) OR #expiresAt > :now)\",\n names: { \"#pk\": \"PK\", \"#expiresAt\": \"expiresAt\" },\n values: { \":now\": nowInSeconds() }\n };\n};\n\nconst liveValueCondition = (equals: KeyValueComparable): ICondition => {\n return {\n expression:\n \"#data.#value = :equals AND (attribute_not_exists(#expiresAt) OR #expiresAt > :now)\",\n names: { \"#data\": \"data\", \"#value\": \"value\", \"#expiresAt\": \"expiresAt\" },\n values: { \":equals\": equals, \":now\": nowInSeconds() }\n };\n};\n\nconst toCondition = (condition: IKeyValueWriteCondition | undefined): ICondition | undefined => {\n if (!condition) {\n return undefined;\n }\n if (condition.equals !== undefined) {\n return liveValueCondition(condition.equals);\n }\n if (condition.exists) {\n return liveCondition();\n }\n return notExistsCondition();\n};\n\nexport class KeyValueStoreStorageOperations {\n private readonly table;\n private readonly entity;\n private readonly client;\n\n constructor(dynamoDbClient: DynamoDBDocument) {\n this.table = new KeyValueStoreDynamoTable<KeyValueRecord>(dynamoDbClient);\n this.entity = this.table.getEntity();\n this.client = dynamoDbClient;\n }\n\n private createScopedKey(key: string, scope: string): string {\n return `${scope}:${key}`;\n }\n\n async get(key: string, scope: string): Promise<KeyValueRecord | null> {\n try {\n const scopedKey = this.createScopedKey(key, scope);\n const entry = await this.entity.get(this.table.createKeys({ scopedKey }));\n\n if (!entry) {\n return null;\n }\n\n if (isExpired(entry.expiresAt)) {\n return null;\n }\n\n return {\n key,\n value: entry.data.value,\n scope: entry.data.scope\n };\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not get key-value record.\",\n code: \"GET_KEY_VALUE_ERROR\",\n data: { key, scope }\n });\n }\n }\n\n async set(\n key: string,\n value: any,\n scope: string,\n options?: IKeyValueStoreSetOptions\n ): Promise<boolean> {\n try {\n const scopedKey = this.createScopedKey(key, scope);\n const keys = this.table.createKeys({ scopedKey });\n\n const item: IGlobalEntityAttributes<KeyValueRecord> = {\n ...keys,\n TYPE: \"KeyValueStore\",\n expiresAt: options?.expiresAt ? toEpochSeconds(options.expiresAt) : undefined,\n data: {\n key,\n value,\n scope\n }\n };\n\n /*\n * A put replaces the whole item, so a write without a collection also drops GSI1 keys\n * an earlier write gave it, which takes the record out of that collection.\n */\n const collection = options?.collection;\n if (collection) {\n const listKeys = this.table.createListKeys({ key, scope, collection });\n Object.assign(item, listKeys);\n }\n\n const condition = toCondition(options?.condition);\n if (!condition) {\n await this.entity.put(item);\n return true;\n }\n\n // The entity builds the put it would send itself, so the stored item is the same.\n const params = this.entity.entity.putParams(item, { strictSchemaCheck: false });\n await this.client.put({\n ...params,\n ConditionExpression: condition.expression,\n ExpressionAttributeNames: {\n ...params.ExpressionAttributeNames,\n ...condition.names\n },\n ExpressionAttributeValues: {\n ...params.ExpressionAttributeValues,\n ...condition.values\n }\n });\n return true;\n } catch (err) {\n if (isConditionFailed(err)) {\n return false;\n }\n throw WebinyError.from(err, {\n message: \"Could not set key-value record.\",\n code: \"SET_KEY_VALUE_ERROR\",\n data: { key, scope }\n });\n }\n }\n\n async delete(key: string, scope: string, options?: IKeyValueDeleteOptions): Promise<boolean> {\n try {\n const scopedKey = this.createScopedKey(key, scope);\n const keys = this.table.createKeys({ scopedKey });\n const condition = toCondition(options?.condition);\n if (!condition) {\n await this.entity.delete(keys);\n return true;\n }\n\n const params = this.entity.entity.deleteParams(keys);\n await this.client.delete({\n ...params,\n ConditionExpression: condition.expression,\n ExpressionAttributeNames: {\n ...params.ExpressionAttributeNames,\n ...condition.names\n },\n ExpressionAttributeValues: {\n ...params.ExpressionAttributeValues,\n ...condition.values\n }\n });\n return true;\n } catch (err) {\n if (isConditionFailed(err)) {\n return false;\n }\n throw WebinyError.from(err, {\n message: \"Could not delete key-value record.\",\n code: \"DELETE_KEY_VALUE_ERROR\",\n data: { key, scope }\n });\n }\n }\n\n async list(params: IKeyValueStorageListParams): Promise<IKeyValueStorageListResult> {\n const { collection, scope, limit, reverse, after } = params;\n try {\n const partitionKey = this.table.createListPartitionKey(scope, collection);\n\n let startKey: Record<string, string> | undefined;\n if (after !== undefined) {\n startKey = this.createStartKey({ key: after, scope, collection });\n }\n\n // One extra record tells whether another page exists without a second, empty read.\n const { items, lastEvaluatedKey } = await this.entity.queryPerPage<\n IGlobalEntityAttributes<KeyValueRecord>\n >({\n partitionKey,\n options: {\n index: \"GSI1\",\n limit: limit + 1,\n reverse,\n startKey\n }\n });\n\n const page = items.slice(0, limit);\n // A key DynamoDB holds as \"\" comes back as null from the entity.\n const keyOf = (item: (typeof items)[number]) => item.data.key ?? \"\";\n\n let lastKey: string | null = null;\n if (items.length > limit) {\n lastKey = keyOf(page[page.length - 1]);\n } else if (lastEvaluatedKey) {\n // The 1 MB read limit cut the page short of `limit`.\n lastKey = this.table.parseListSortKey(lastEvaluatedKey.GSI1_SK as string);\n }\n\n return {\n items: page\n .filter(item => !isExpired(item.expiresAt))\n .map(item => ({ key: keyOf(item), value: item.data.value })),\n lastKey\n };\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list key-value records.\",\n code: \"LIST_KEY_VALUE_ERROR\",\n data: { collection, scope, after }\n });\n }\n }\n\n /**\n * A GSI query resumes from the full key of an item: the table's own PK and SK as well as the\n * index's. All four follow from the scope, collection and key, so the item does not have to\n * exist any more.\n */\n private createStartKey(params: { key: string; scope: string; collection: string }) {\n const { key, scope } = params;\n const scopedKey = this.createScopedKey(key, scope);\n const tableKeys = this.table.createKeys({ scopedKey });\n const listKeys = this.table.createListKeys(params);\n\n return { ...tableKeys, ...listKeys };\n }\n}\n"],"names":["nowInSeconds","Math","Date","toEpochSeconds","date","isExpired","expiresAt","ttl","Number","Boolean","isConditionFailed","error","notExistsCondition","liveCondition","liveValueCondition","equals","toCondition","condition","undefined","KeyValueStoreStorageOperations","dynamoDbClient","KeyValueStoreDynamoTable","key","scope","scopedKey","entry","err","WebinyError","value","options","keys","item","collection","listKeys","Object","params","limit","reverse","after","partitionKey","startKey","items","lastEvaluatedKey","page","keyOf","lastKey","tableKeys"],"mappings":";;AAiBA,MAAMA,eAAe,IACVC,KAAK,KAAK,CAACC,KAAK,GAAG,KAAK;AAQnC,MAAMC,iBAAiB,CAACC,OACbH,KAAK,IAAI,CAACG,KAAK,OAAO,KAAK;AAGtC,MAAMC,YAAY,CAACC;IACf,MAAMC,MAAMC,OAAOF;IACnB,OAAOG,QAAQF,QAAQA,OAAOP;AAClC;AAEA,MAAMU,oBAAoB,CAACC,QACfA,OAA8B,SAAS;AAanD,MAAMC,qBAAqB,IAChB;QACH,YAAY;QACZ,OAAO;YAAE,OAAO;YAAM,cAAc;QAAY;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const createStorageOperations = params => {
3
- return new KeyValueStoreStorageOperations(params.documentClient);
4
- };
2
+ const createStorageOperations = (params)=>new KeyValueStoreStorageOperations(params.documentClient);
3
+ export { createStorageOperations };
5
4
 
6
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["KeyValueStoreStorageOperations","createStorageOperations","params","documentClient"],"sources":["index.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { KeyValueStoreStorageOperations } from \"./KeyValueStoreStorageOperations.js\";\n\nexport interface CreateKeyValueStoreStorageOperations {\n (params: { documentClient: DynamoDBDocument }): KeyValueStoreStorageOperations;\n}\n\nexport const createStorageOperations: CreateKeyValueStoreStorageOperations = params => {\n return new KeyValueStoreStorageOperations(params.documentClient);\n};\n"],"mappings":"AACA,SAASA,8BAA8B;AAMvC,OAAO,MAAMC,uBAA6D,GAAGC,MAAM,IAAI;EACnF,OAAO,IAAIF,8BAA8B,CAACE,MAAM,CAACC,cAAc,CAAC;AACpE,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"keyValueStore/index.js","sources":["../../src/keyValueStore/index.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { KeyValueStoreStorageOperations } from \"./KeyValueStoreStorageOperations.js\";\n\nexport interface CreateKeyValueStoreStorageOperations {\n (params: { documentClient: DynamoDBDocument }): KeyValueStoreStorageOperations;\n}\n\nexport const createStorageOperations: CreateKeyValueStoreStorageOperations = params => {\n return new KeyValueStoreStorageOperations(params.documentClient);\n};\n"],"names":["createStorageOperations","params","KeyValueStoreStorageOperations"],"mappings":";AAOO,MAAMA,0BAAgEC,CAAAA,SAClE,IAAIC,+BAA+BD,OAAO,cAAc"}
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@webiny/api-core-ddb",
3
- "version": "0.0.0-unstable.df7a8bb475",
3
+ "version": "0.0.0-unstable.e1999482d0",
4
4
  "type": "module",
5
- "main": "index.js",
5
+ "exports": {
6
+ ".": "./index.js",
7
+ "./*": "./*"
8
+ },
6
9
  "repository": {
7
10
  "type": "git",
8
11
  "url": "https://github.com/webiny/webiny-js.git"
@@ -18,23 +21,25 @@
18
21
  "author": "Webiny Ltd.",
19
22
  "license": "MIT",
20
23
  "dependencies": {
21
- "@webiny/api": "0.0.0-unstable.df7a8bb475",
22
- "@webiny/api-core": "0.0.0-unstable.df7a8bb475",
23
- "@webiny/aws-sdk": "0.0.0-unstable.df7a8bb475",
24
- "@webiny/db-dynamodb": "0.0.0-unstable.df7a8bb475",
25
- "@webiny/error": "0.0.0-unstable.df7a8bb475"
24
+ "@webiny/api": "0.0.0-unstable.e1999482d0",
25
+ "@webiny/api-core": "0.0.0-unstable.e1999482d0",
26
+ "@webiny/aws-sdk": "0.0.0-unstable.e1999482d0",
27
+ "@webiny/db-dynamodb": "0.0.0-unstable.e1999482d0",
28
+ "@webiny/error": "0.0.0-unstable.e1999482d0",
29
+ "@webiny/feature": "0.0.0-unstable.e1999482d0"
26
30
  },
27
31
  "devDependencies": {
28
- "@webiny/api": "0.0.0",
29
- "@webiny/build-tools": "0.0.0-unstable.df7a8bb475",
30
- "@webiny/project-utils": "0.0.0-unstable.df7a8bb475",
32
+ "@webiny/api": "0.0.0-unstable.e1999482d0",
33
+ "@webiny/build-tools": "0.0.0-unstable.e1999482d0",
31
34
  "jest-dynalite": "3.6.1",
32
- "rimraf": "6.1.3",
33
- "typescript": "5.9.3"
35
+ "rimraf": "6.1.4",
36
+ "typescript": "7.0.2",
37
+ "vitest": "5.1.1"
34
38
  },
35
39
  "publishConfig": {
36
- "access": "public",
37
- "directory": "dist"
40
+ "access": "public"
38
41
  },
39
- "gitHead": "df7a8bb4755a1da047f0af8c56bdb649cc81bf7d"
42
+ "webiny": {
43
+ "publishFrom": "dist"
44
+ }
40
45
  }
@@ -1,28 +1,23 @@
1
1
  import { createStandardEntity, standardEntityAttributes } from "@webiny/db-dynamodb";
2
2
  import { ENTITIES } from "../types.js";
3
- export const createRoleEntity = table => {
4
- return createStandardEntity({
5
- name: ENTITIES.ROLE,
6
- table
7
- });
8
- };
9
- export const createTeamEntity = table => {
10
- return createStandardEntity({
11
- name: ENTITIES.TEAM,
12
- table,
13
- attributes: {
14
- ...standardEntityAttributes
15
- }
16
- });
17
- };
18
- export const createApiKeyEntity = table => {
19
- return createStandardEntity({
20
- name: ENTITIES.API_KEY,
21
- table,
22
- attributes: {
23
- ...standardEntityAttributes
24
- }
25
- });
26
- };
3
+ const createRoleEntity = (table)=>createStandardEntity({
4
+ name: ENTITIES.ROLE,
5
+ table
6
+ });
7
+ const createTeamEntity = (table)=>createStandardEntity({
8
+ name: ENTITIES.TEAM,
9
+ table,
10
+ attributes: {
11
+ ...standardEntityAttributes
12
+ }
13
+ });
14
+ const createApiKeyEntity = (table)=>createStandardEntity({
15
+ name: ENTITIES.API_KEY,
16
+ table,
17
+ attributes: {
18
+ ...standardEntityAttributes
19
+ }
20
+ });
21
+ export { createApiKeyEntity, createRoleEntity, createTeamEntity };
27
22
 
28
23
  //# sourceMappingURL=entities.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createStandardEntity","standardEntityAttributes","ENTITIES","createRoleEntity","table","name","ROLE","createTeamEntity","TEAM","attributes","createApiKeyEntity","API_KEY"],"sources":["entities.ts"],"sourcesContent":["import { createStandardEntity, standardEntityAttributes } from \"@webiny/db-dynamodb\";\nimport type { Table } from \"@webiny/db-dynamodb/toolbox.js\";\nimport { ENTITIES } from \"../types.js\";\nimport type { IApiKeyEntity, IRoleEntity, ITeamEntity } from \"~/security/definitions/types.js\";\nimport type { Role, StorageApiKey, Team } from \"@webiny/api-core/types/security.js\";\n\nexport const createRoleEntity = (table: Table<string, string, string>): IRoleEntity => {\n return createStandardEntity<Role>({\n name: ENTITIES.ROLE,\n table\n });\n};\n\nexport const createTeamEntity = (table: Table<string, string, string>): ITeamEntity => {\n return createStandardEntity<Team>({\n name: ENTITIES.TEAM,\n table,\n attributes: {\n ...standardEntityAttributes\n }\n });\n};\n\nexport const createApiKeyEntity = (table: Table<string, string, string>): IApiKeyEntity => {\n return createStandardEntity<StorageApiKey>({\n name: ENTITIES.API_KEY,\n table,\n attributes: {\n ...standardEntityAttributes\n }\n });\n};\n"],"mappings":"AAAA,SAASA,oBAAoB,EAAEC,wBAAwB,QAAQ,qBAAqB;AAEpF,SAASC,QAAQ;AAIjB,OAAO,MAAMC,gBAAgB,GAAIC,KAAoC,IAAkB;EACnF,OAAOJ,oBAAoB,CAAO;IAC9BK,IAAI,EAAEH,QAAQ,CAACI,IAAI;IACnBF;EACJ,CAAC,CAAC;AACN,CAAC;AAED,OAAO,MAAMG,gBAAgB,GAAIH,KAAoC,IAAkB;EACnF,OAAOJ,oBAAoB,CAAO;IAC9BK,IAAI,EAAEH,QAAQ,CAACM,IAAI;IACnBJ,KAAK;IACLK,UAAU,EAAE;MACR,GAAGR;IACP;EACJ,CAAC,CAAC;AACN,CAAC;AAED,OAAO,MAAMS,kBAAkB,GAAIN,KAAoC,IAAoB;EACvF,OAAOJ,oBAAoB,CAAgB;IACvCK,IAAI,EAAEH,QAAQ,CAACS,OAAO;IACtBP,KAAK;IACLK,UAAU,EAAE;MACR,GAAGR;IACP;EACJ,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"security/definitions/entities.js","sources":["../../../src/security/definitions/entities.ts"],"sourcesContent":["import { createStandardEntity, standardEntityAttributes } from \"@webiny/db-dynamodb\";\nimport type { StorageApiKey, StorageRole, StorageTeam } from \"@webiny/api-core/types/security.js\";\nimport type { Table } from \"@webiny/db-dynamodb/toolbox.js\";\nimport { ENTITIES } from \"../types.js\";\nimport type { IApiKeyEntity, IRoleEntity, ITeamEntity } from \"~/security/definitions/types.js\";\n\nexport const createRoleEntity = (table: Table<string, string, string>): IRoleEntity => {\n return createStandardEntity<StorageRole>({\n name: ENTITIES.ROLE,\n table\n });\n};\n\nexport const createTeamEntity = (table: Table<string, string, string>): ITeamEntity => {\n return createStandardEntity<StorageTeam>({\n name: ENTITIES.TEAM,\n table,\n attributes: {\n ...standardEntityAttributes\n }\n });\n};\n\nexport const createApiKeyEntity = (table: Table<string, string, string>): IApiKeyEntity => {\n return createStandardEntity<StorageApiKey>({\n name: ENTITIES.API_KEY,\n table,\n attributes: {\n ...standardEntityAttributes\n }\n });\n};\n"],"names":["createRoleEntity","table","createStandardEntity","ENTITIES","createTeamEntity","standardEntityAttributes","createApiKeyEntity"],"mappings":";;AAMO,MAAMA,mBAAmB,CAACC,QACtBC,qBAAkC;QACrC,MAAMC,SAAS,IAAI;QACnBF;IACJ;AAGG,MAAMG,mBAAmB,CAACH,QACtBC,qBAAkC;QACrC,MAAMC,SAAS,IAAI;QACnBF;QACA,YAAY;YACR,GAAGI,wBAAwB;QAC/B;IACJ;AAGG,MAAMC,qBAAqB,CAACL,QACxBC,qBAAoC;QACvC,MAAMC,SAAS,OAAO;QACtBF;QACA,YAAY;YACR,GAAGI,wBAAwB;QAC/B;IACJ"}
@@ -1,10 +1,10 @@
1
1
  import type { IEntity, IStandardEntityAttributes } from "@webiny/db-dynamodb";
2
- import type { Role, StorageApiKey, Team } from "@webiny/api-core/types/security.js";
3
- export interface IRoleEntityAttributes extends IStandardEntityAttributes<Role> {
2
+ import type { StorageApiKey, StorageRole, StorageTeam } from "@webiny/api-core/types/security.js";
3
+ export interface IRoleEntityAttributes extends IStandardEntityAttributes<StorageRole> {
4
4
  TYPE: string;
5
5
  }
6
6
  export type IRoleEntity = IEntity<IRoleEntityAttributes>;
7
- export interface ITeamEntityAttributes extends IStandardEntityAttributes<Team> {
7
+ export interface ITeamEntityAttributes extends IStandardEntityAttributes<StorageTeam> {
8
8
  TYPE: string;
9
9
  }
10
10
  export type ITeamEntity = IEntity<ITeamEntityAttributes>;
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=types.js.map