@baadal-sdk/dapi 0.28.4 → 0.31.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/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/types/aws/client.d.ts +13 -0
- package/dist/types/aws/client.d.ts.map +1 -0
- package/dist/types/aws/db.d.ts +261 -9
- package/dist/types/aws/db.d.ts.map +1 -1
- package/dist/types/aws/index.d.ts +10 -11
- package/dist/types/aws/index.d.ts.map +1 -1
- package/dist/types/aws/s3.d.ts +90 -0
- package/dist/types/aws/s3.d.ts.map +1 -0
- package/dist/types/common/const.d.ts +3 -0
- package/dist/types/common/const.d.ts.map +1 -0
- package/dist/types/fs/index.d.ts +29 -25
- package/dist/types/fs/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +6 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/package.json +5 -1
- package/src/aws/client.ts +18 -0
- package/src/aws/db.ts +534 -105
- package/src/aws/index.ts +22 -8
- package/src/aws/s3.ts +476 -0
- package/src/common/const.ts +2 -0
- package/src/fs/index.ts +60 -54
- package/src/index.ts +3 -2
- package/src/utils/index.ts +39 -0
- package/dist/types/aws/db-client.d.ts +0 -7
- package/dist/types/aws/db-client.d.ts.map +0 -1
- package/src/aws/db-client.ts +0 -6
package/dist/types/aws/db.d.ts
CHANGED
|
@@ -1,15 +1,267 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Examples:
|
|
3
|
+
* Ref: https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/dynamodb-examples.html
|
|
4
|
+
*
|
|
2
5
|
* Partition key vs Composite primary key:
|
|
3
6
|
* Ref: https://aws.amazon.com/premiumsupport/knowledge-center/primary-key-dynamodb-table/
|
|
4
7
|
*/
|
|
5
8
|
import { StringIndexable } from '../common/common.model';
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
export interface WriteItemForceInput<T = any> {
|
|
10
|
+
table: string;
|
|
11
|
+
item: T;
|
|
12
|
+
key?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Write an item to a DynamoDB table, retry in case of key conflict
|
|
16
|
+
* @param input input command object
|
|
17
|
+
* @returns the created item, null in case of error
|
|
18
|
+
*
|
|
19
|
+
* ```js
|
|
20
|
+
* writeItemForce({
|
|
21
|
+
* table: 'lesson_list',
|
|
22
|
+
* item: { title: 'My Lesson' },
|
|
23
|
+
* key: 'id',
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* interface WriteItemForceInput<T = any> {
|
|
27
|
+
* table: string;
|
|
28
|
+
* item: T;
|
|
29
|
+
* key?: string; // default: `id`
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare const writeItemForce: <T = any>(input: WriteItemForceInput<T>) => Promise<T | null>;
|
|
34
|
+
export interface WriteItemInput {
|
|
35
|
+
table: string;
|
|
36
|
+
item: StringIndexable;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Write an item to a DynamoDB table
|
|
40
|
+
* @param input input command object
|
|
41
|
+
* @returns true if successful, null in case of error
|
|
42
|
+
*
|
|
43
|
+
* ```js
|
|
44
|
+
* writeItem({
|
|
45
|
+
* table: 'lesson_list',
|
|
46
|
+
* item: { id: 'id_001', title: 'My Lesson' },
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* interface WriteItemInput {
|
|
50
|
+
* table: string;
|
|
51
|
+
* item: StringIndexable;
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const writeItem: (input: WriteItemInput) => Promise<true | null>;
|
|
56
|
+
export interface WriteItemsAllInput {
|
|
57
|
+
table: string;
|
|
58
|
+
items: StringIndexable[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Write an list of items to a DynamoDB table
|
|
62
|
+
* @param input input command object
|
|
63
|
+
* @returns true if successful, null in case of error
|
|
64
|
+
*
|
|
65
|
+
* ```js
|
|
66
|
+
* writeItemsAll({
|
|
67
|
+
* table: 'lesson_list',
|
|
68
|
+
* items: [{ id: 'id_001', title: 'My Lesson' }, { id: 'id_002', title: 'My Lesson 2' }],
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* interface WriteItemInput {
|
|
72
|
+
* table: string;
|
|
73
|
+
* items: StringIndexable[];
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare const writeItemsAll: (input: WriteItemsAllInput) => Promise<boolean | null>;
|
|
78
|
+
export interface UpdateItemInput {
|
|
79
|
+
table: string;
|
|
80
|
+
key: StringIndexable;
|
|
81
|
+
update: string;
|
|
82
|
+
attr: StringIndexable;
|
|
83
|
+
attrNames?: StringIndexable;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Update an item in DynamoDB table
|
|
87
|
+
* @param input input command object
|
|
88
|
+
* @returns true if successful, null in case of error
|
|
89
|
+
*
|
|
90
|
+
* ```js
|
|
91
|
+
* updateItem({
|
|
92
|
+
* table: 'lesson_list',
|
|
93
|
+
* key: { id: 'id_001' },
|
|
94
|
+
* update: 'SET status = :status, #rev = 10',
|
|
95
|
+
* attr: { ':status': 'completed' },
|
|
96
|
+
* attrNames: { '#rev': 'revision' },
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* interface UpdateItemInput {
|
|
100
|
+
* table: string;
|
|
101
|
+
* key: StringIndexable;
|
|
102
|
+
* update: string;
|
|
103
|
+
* attr: StringIndexable;
|
|
104
|
+
* attrNames?: StringIndexable;
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare const updateItem: (input: UpdateItemInput) => Promise<true | null>;
|
|
109
|
+
export interface ReadItemInput {
|
|
110
|
+
table: string;
|
|
111
|
+
key: StringIndexable;
|
|
112
|
+
projection?: string;
|
|
113
|
+
attrNames?: StringIndexable;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Read an item from DynamoDB table
|
|
117
|
+
* @param input input command object
|
|
118
|
+
* @returns item contents, null in case of error
|
|
119
|
+
*
|
|
120
|
+
* ```js
|
|
121
|
+
* readItem({
|
|
122
|
+
* table: 'lesson_list',
|
|
123
|
+
* key: { id: 'id_001' },
|
|
124
|
+
* projection: 'id, lesson, status',
|
|
125
|
+
* });
|
|
126
|
+
*
|
|
127
|
+
* interface ReadItemInput {
|
|
128
|
+
* table: string;
|
|
129
|
+
* key: StringIndexable;
|
|
130
|
+
* projection?: string;
|
|
131
|
+
* attrNames?: StringIndexable;
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare const readItem: <T = any>(input: ReadItemInput) => Promise<T | null>;
|
|
136
|
+
export interface ReadItemsAllInput {
|
|
137
|
+
table: string;
|
|
138
|
+
keys: StringIndexable[];
|
|
139
|
+
projection?: string;
|
|
140
|
+
attrNames?: StringIndexable;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Read a list of items from DynamoDB table
|
|
144
|
+
* Note: ordering of items in result may not be same as that in `keys`
|
|
145
|
+
* @param input input command object
|
|
146
|
+
* @returns list of contents for items, null in case of error
|
|
147
|
+
*
|
|
148
|
+
* ```js
|
|
149
|
+
* readItemsAll({
|
|
150
|
+
* table: 'lesson_list',
|
|
151
|
+
* keys: [{ id: 'id_001' }, { id: 'id_002' }],
|
|
152
|
+
* projection: 'id, lesson, status',
|
|
153
|
+
* });
|
|
154
|
+
*
|
|
155
|
+
* interface ReadItemsAllInput {
|
|
156
|
+
* table: string;
|
|
157
|
+
* keys: StringIndexable[];
|
|
158
|
+
* projection?: string;
|
|
159
|
+
* attrNames?: StringIndexable;
|
|
160
|
+
* }
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export declare const readItemsAll: <T = any>(input: ReadItemsAllInput) => Promise<StringIndexable<T>[] | null>;
|
|
164
|
+
export interface QueryItemsInput {
|
|
165
|
+
table: string;
|
|
166
|
+
indexName?: string;
|
|
167
|
+
cond: string;
|
|
168
|
+
attr: StringIndexable;
|
|
169
|
+
attrNames?: StringIndexable;
|
|
170
|
+
projection?: string;
|
|
171
|
+
desc?: boolean;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Query items from a DynamoDB table based on some condition
|
|
175
|
+
* @param input input command object
|
|
176
|
+
* @returns query results array, null in case of error
|
|
177
|
+
*
|
|
178
|
+
* ```js
|
|
179
|
+
* dbQueryItems({
|
|
180
|
+
* table: 'lesson_list',
|
|
181
|
+
* indexName: 'status-revision-index',
|
|
182
|
+
* cond: 'status = :comp AND #rev >= :rev',
|
|
183
|
+
* attr: { ':comp': 'completed', ':rev': 9 },
|
|
184
|
+
* attrNames: { '#rev': 'revision' },
|
|
185
|
+
* projection: 'id, lesson, status, revision',
|
|
186
|
+
* });
|
|
187
|
+
*
|
|
188
|
+
* interface QueryItemsInput {
|
|
189
|
+
* table: string;
|
|
190
|
+
* indexName?: string;
|
|
191
|
+
* cond: string;
|
|
192
|
+
* attr: StringIndexable;
|
|
193
|
+
* attrNames?: StringIndexable;
|
|
194
|
+
* projection?: string;
|
|
195
|
+
* desc?: boolean;
|
|
196
|
+
* }
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
export declare const queryItems: (input: QueryItemsInput) => Promise<StringIndexable<any>[] | null>;
|
|
200
|
+
export interface ScanItemsInput {
|
|
201
|
+
table: string;
|
|
202
|
+
projection?: string;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Scan all items in a DynamoDB table
|
|
206
|
+
* Note: avoid using this method in favour of `queryItems` method due to performance reasons
|
|
207
|
+
* @param input input command object
|
|
208
|
+
* @returns results of the scan query, null in case of error
|
|
209
|
+
*
|
|
210
|
+
* ```js
|
|
211
|
+
* scanItems({
|
|
212
|
+
* table: 'lesson_list',
|
|
213
|
+
* projection: 'id, status',
|
|
214
|
+
* });
|
|
215
|
+
*
|
|
216
|
+
* interface ScanItemsInput {
|
|
217
|
+
* table: string;
|
|
218
|
+
* projection?: string;
|
|
219
|
+
* }
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
export declare const scanItems: (input: ScanItemsInput) => Promise<StringIndexable<any>[] | null>;
|
|
223
|
+
export interface DeleteItemInput {
|
|
224
|
+
table: string;
|
|
225
|
+
key: StringIndexable;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Delete an item in a DynamoDB table
|
|
229
|
+
* @param input input command object
|
|
230
|
+
* @returns true if successful, null in case of error
|
|
231
|
+
*
|
|
232
|
+
* ```js
|
|
233
|
+
* deleteItem({
|
|
234
|
+
* table: 'lesson_list',
|
|
235
|
+
* key: { id: 'id_001' },
|
|
236
|
+
* });
|
|
237
|
+
*
|
|
238
|
+
* interface DeleteItemInput {
|
|
239
|
+
* table: string;
|
|
240
|
+
* key: StringIndexable;
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
export declare const deleteItem: (input: DeleteItemInput) => Promise<true | null>;
|
|
245
|
+
export interface DeleteItemsAllInput {
|
|
246
|
+
table: string;
|
|
247
|
+
keys: StringIndexable[];
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Delete a list of items in a DynamoDB table
|
|
251
|
+
* @param input input command object
|
|
252
|
+
* @returns true if successful, null in case of error
|
|
253
|
+
*
|
|
254
|
+
* ```js
|
|
255
|
+
* deleteItemsAll({
|
|
256
|
+
* table: 'lesson_list',
|
|
257
|
+
* keys: [{ id: 'id_001' }, { id: 'id_002' }],
|
|
258
|
+
* });
|
|
259
|
+
*
|
|
260
|
+
* interface DeleteItemsAllInput {
|
|
261
|
+
* table: string;
|
|
262
|
+
* keys: StringIndexable[];
|
|
263
|
+
* }
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
export declare const deleteItemsAll: (input: DeleteItemsAllInput) => Promise<boolean | null>;
|
|
15
267
|
//# sourceMappingURL=db.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../../src/aws/db.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../../src/aws/db.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA0BH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAsEzD,MAAM,WAAW,mBAAmB,CAAC,CAAC,GAAG,GAAG;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,CAAC,CAAC;IACR,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,cAAc,+DAG1B,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,eAAe,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,SAAS,UAAiB,cAAc,yBAkBpD,CAAC;AA8BF,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,eAAe,EAAE,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,aAAa,UAAiB,kBAAkB,4BAsB5D,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,eAAe,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,eAAe,CAAC;IACtB,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,UAAU,UAAiB,eAAe,yBAwBtD,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,eAAe,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,QAAQ,mBAA0B,aAAa,sBA6B3D,CAAC;AA6CF,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,eAAe,EAAE,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,YAAY,mBAA0B,iBAAiB,yCA8BnE,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,eAAe,CAAC;IACtB,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,UAAU,UAAiB,eAAe,2CAyCtD,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,SAAS,UAAiB,cAAc,2CAoCpD,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,eAAe,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,UAAU,UAAiB,eAAe,yBAkBtD,CAAC;AA+BF,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,eAAe,EAAE,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,cAAc,UAAiB,mBAAmB,4BAsB9D,CAAC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import * as db from './db';
|
|
2
|
+
import * as s3 from './s3';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated explicit init deprecated!
|
|
5
|
+
*/
|
|
6
|
+
export declare const init: (region: string) => boolean;
|
|
7
|
+
export declare const status: () => {
|
|
8
|
+
db: string | null;
|
|
9
|
+
s3: string | null;
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
declare const status: () => string | null;
|
|
12
|
-
export { db, init, status };
|
|
11
|
+
export { db, s3 };
|
|
13
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/aws/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/aws/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;AAC3B,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;AAS3B;;GAEG;AACH,eAAO,MAAM,IAAI,WAAY,MAAM,YAUlC,CAAC;AAEF,eAAO,MAAM,MAAM;;;CAKlB,CAAC;AAEF,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Examples:
|
|
3
|
+
* Ref: https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/s3-examples.html
|
|
4
|
+
*/
|
|
5
|
+
import { StringIndexable } from 'src/common/common.model';
|
|
6
|
+
/**
|
|
7
|
+
* Create a new file in S3 bucket
|
|
8
|
+
* @param bucket S3 bucket name
|
|
9
|
+
* @param s3path S3 path to be created
|
|
10
|
+
* @param contents contents of the file to be created
|
|
11
|
+
* @returns true if the write is successful, null in case of error
|
|
12
|
+
*/
|
|
13
|
+
export declare const putObject: (bucket: string, s3path: string, contents: string) => Promise<true | null>;
|
|
14
|
+
/**
|
|
15
|
+
* Upload a file to S3 bucket
|
|
16
|
+
* @param bucket S3 bucket name
|
|
17
|
+
* @param file (local) path of the file to upload
|
|
18
|
+
* @param s3path [optional] S3 path to be created, if not provided then derived from `file` path
|
|
19
|
+
* @returns true if the write is successful, null in case of error
|
|
20
|
+
*/
|
|
21
|
+
export declare const uploadFile: (bucket: string, file: string, s3path?: string | undefined) => Promise<true | null>;
|
|
22
|
+
/**
|
|
23
|
+
* Upload a list of files to S3 bucket
|
|
24
|
+
* @param bucket S3 bucket name
|
|
25
|
+
* @param files (local) list of file paths to upload
|
|
26
|
+
* @param s3paths [optional] S3 path to be created, if not provided then derived from `file` path
|
|
27
|
+
* @returns true if the write is successful, null in case of error
|
|
28
|
+
*/
|
|
29
|
+
export declare const uploadFilesAll: (bucket: string, files: string[], s3paths?: string[] | undefined) => Promise<boolean | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Get the contents of a file in S3 bucket
|
|
32
|
+
* @param bucket S3 bucket name
|
|
33
|
+
* @param s3path S3 path of the file to be read
|
|
34
|
+
* @returns contents of the file, null in case of error
|
|
35
|
+
*/
|
|
36
|
+
export declare const getObject: (bucket: string, s3path: string) => Promise<string | null>;
|
|
37
|
+
/**
|
|
38
|
+
* Download a file from S3 bucket
|
|
39
|
+
* @param bucket S3 bucket name
|
|
40
|
+
* @param s3path S3 path of the file to be downloaded
|
|
41
|
+
* @param outPath [optional] path where the downloaded file is written, if not provided then derived from `s3path`
|
|
42
|
+
* @returns true if download is successful, null in case of error
|
|
43
|
+
*/
|
|
44
|
+
export declare const downloadFile: (bucket: string, s3path: string, outPath?: string | undefined) => Promise<true | null>;
|
|
45
|
+
/**
|
|
46
|
+
* List objects in a S3 bucket
|
|
47
|
+
* @param bucket S3 bucket name
|
|
48
|
+
* @param prefix [optional] prefix for object names in the bucket
|
|
49
|
+
* @returns list of objects in the S3 bucket (optionally starting with the given prefix), null in case of error
|
|
50
|
+
*/
|
|
51
|
+
export declare const listObjects: (bucket: string, prefix?: string | undefined) => Promise<string[] | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Get head content for a file in S3 bucket
|
|
54
|
+
* @param bucket S3 bucket name
|
|
55
|
+
* @param s3path S3 path of the file
|
|
56
|
+
* @returns head content for the given file, null in case of error
|
|
57
|
+
*/
|
|
58
|
+
export declare const getObjectHead: (bucket: string, s3path: string) => Promise<HeadObject | null>;
|
|
59
|
+
/**
|
|
60
|
+
* Get head contents for a list of files in S3 bucket
|
|
61
|
+
* @param bucket S3 bucket name
|
|
62
|
+
* @param s3paths list of S3 paths of the files
|
|
63
|
+
* @returns head contents for the given files, null in case of error
|
|
64
|
+
*/
|
|
65
|
+
export declare const getObjectHeadsAll: (bucket: string, s3paths: string[]) => Promise<(HeadObject | null)[] | null>;
|
|
66
|
+
/**
|
|
67
|
+
* Delete a file in S3 bucket
|
|
68
|
+
* @param bucket S3 bucket name
|
|
69
|
+
* @param s3path S3 file path to be deleted
|
|
70
|
+
* @returns true if delete is successful, null in case of error
|
|
71
|
+
*/
|
|
72
|
+
export declare const deleteObject: (bucket: string, s3path: string) => Promise<true | null>;
|
|
73
|
+
/**
|
|
74
|
+
* Delete a list of files in S3 bucket
|
|
75
|
+
* @param bucket S3 bucket name
|
|
76
|
+
* @param s3paths list of S3 file paths to be deleted
|
|
77
|
+
* @returns true if all deletes are successful, null in case of error
|
|
78
|
+
*/
|
|
79
|
+
export declare const deleteObjectsAll: (bucket: string, s3paths: string[]) => Promise<boolean | null>;
|
|
80
|
+
export interface HeadObject {
|
|
81
|
+
Key: string;
|
|
82
|
+
ContentLength?: number;
|
|
83
|
+
ContentType?: string;
|
|
84
|
+
ETag?: string;
|
|
85
|
+
CacheControl?: string;
|
|
86
|
+
Expires?: Date;
|
|
87
|
+
LastModified?: Date;
|
|
88
|
+
Metadata?: StringIndexable;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=s3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../src/aws/s3.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAwBH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AA6C1D;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,WAAkB,MAAM,UAAU,MAAM,YAAY,MAAM,yBA4B/E,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,WAAkB,MAAM,QAAQ,MAAM,sDAiD5D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,WAAkB,MAAM,SAAS,MAAM,EAAE,4DAuBnE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,SAAS,WAAkB,MAAM,UAAU,MAAM,2BAkC7D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,WAAkB,MAAM,UAAU,MAAM,uDAkChE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,WAAkB,MAAM,0DA+B/C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,WAAkB,MAAM,UAAU,MAAM,+BA0BjE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,WAAkB,MAAM,WAAW,MAAM,EAAE,0CAuBxE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,WAAkB,MAAM,UAAU,MAAM,yBAkBhE,CAAC;AAwBF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,WAAkB,MAAM,WAAW,MAAM,EAAE,4BAsBvE,CAAC;AAEF,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,YAAY,CAAC,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../../src/common/const.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,UAAU,KAAK,CAAC"}
|
package/dist/types/fs/index.d.ts
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
* Check whether a file exists
|
|
3
3
|
* @param file file path
|
|
4
4
|
* @param loud whether to throw errors [default: false]
|
|
5
|
-
* @returns true if it exists, false
|
|
5
|
+
* @returns true if it exists, false if it doesn't, null in case of error
|
|
6
6
|
*/
|
|
7
|
-
export declare const existsFileSync: (file: string, loud?: boolean) => boolean;
|
|
7
|
+
export declare const existsFileSync: (file: string, loud?: boolean) => boolean | null;
|
|
8
8
|
/**
|
|
9
9
|
* Check whether a directory exists
|
|
10
10
|
* @param dir directory path
|
|
11
11
|
* @param loud whether to throw errors [default: false]
|
|
12
|
-
* @returns true if it exists, false
|
|
12
|
+
* @returns true if it exists, false if it doesn't, null in case of error
|
|
13
13
|
*/
|
|
14
|
-
export declare const existsDirSync: (dir: string, loud?: boolean) => boolean;
|
|
14
|
+
export declare const existsDirSync: (dir: string, loud?: boolean) => boolean | null;
|
|
15
15
|
/**
|
|
16
16
|
* Read contents of a file
|
|
17
17
|
* @param file file path
|
|
@@ -30,69 +30,73 @@ export declare const readFileSync: (file: string, warn?: boolean) => string | nu
|
|
|
30
30
|
* Get the list of files/directories in a directory
|
|
31
31
|
* @param dir directory path
|
|
32
32
|
* @param warn whether to show warnings [default: false]
|
|
33
|
-
* @
|
|
33
|
+
* @param hiddenItems whether to include items starting with dot(.) [default: false]
|
|
34
|
+
* @returns an object {dirs,files} containing list of directories & files, null in case or error
|
|
34
35
|
*/
|
|
35
|
-
export declare const readDir: (dir: string, warn?: boolean) => Promise<{
|
|
36
|
-
dirs: string[]
|
|
37
|
-
files: string[]
|
|
38
|
-
}>;
|
|
36
|
+
export declare const readDir: (dir: string, warn?: boolean, hiddenItems?: boolean) => Promise<{
|
|
37
|
+
dirs: string[];
|
|
38
|
+
files: string[];
|
|
39
|
+
} | null>;
|
|
39
40
|
/**
|
|
40
41
|
* Get the list of files in a directory
|
|
41
42
|
* @param dir directory path
|
|
42
43
|
* @param warn whether to show warnings [default: false]
|
|
44
|
+
* @param hiddenItems whether to include items starting with dot(.) [default: false]
|
|
43
45
|
* @returns list of files, null in case of error or no items
|
|
44
46
|
*/
|
|
45
|
-
export declare const readDirFiles: (dir: string, warn?: boolean) => Promise<string[] | null>;
|
|
47
|
+
export declare const readDirFiles: (dir: string, warn?: boolean, hiddenItems?: boolean) => Promise<string[] | null | undefined>;
|
|
46
48
|
/**
|
|
47
49
|
* Get the list of directories in a directory
|
|
48
50
|
* @param dir directory path
|
|
49
51
|
* @param warn whether to show warnings [default: false]
|
|
52
|
+
* @param hiddenItems whether to include items starting with dot(.) [default: false]
|
|
50
53
|
* @returns list of directories, null in case of error or no items
|
|
51
54
|
*/
|
|
52
|
-
export declare const readDirDirs: (dir: string, warn?: boolean) => Promise<string[] | null>;
|
|
55
|
+
export declare const readDirDirs: (dir: string, warn?: boolean, hiddenItems?: boolean) => Promise<string[] | null | undefined>;
|
|
53
56
|
/**
|
|
54
57
|
* Get the (recursive) list of files in a directory
|
|
55
58
|
* @param dir directory path
|
|
56
|
-
* @
|
|
59
|
+
* @param hiddenItems whether to include items starting with dot(.) [default: false]
|
|
60
|
+
* @returns complete (recursive) list of files, null in case of error
|
|
57
61
|
*/
|
|
58
|
-
export declare const readDirFilesRec: (dir: string) => Promise<string[] | null>;
|
|
62
|
+
export declare const readDirFilesRec: (dir: string, hiddenItems?: boolean) => Promise<string[] | null>;
|
|
59
63
|
/**
|
|
60
64
|
* Write contents to a file (creates the file path if it doesn't exist)
|
|
61
65
|
* @param file file path
|
|
62
66
|
* @param contents contents to write
|
|
63
|
-
* @returns true if successful,
|
|
67
|
+
* @returns true if successful, null in case of error
|
|
64
68
|
*/
|
|
65
|
-
export declare const writeFile: (file: string, contents: string) => Promise<
|
|
69
|
+
export declare const writeFile: (file: string, contents: string) => Promise<true | null>;
|
|
66
70
|
/**
|
|
67
71
|
* Append contents to a file
|
|
68
72
|
* @param file file path
|
|
69
73
|
* @param contents contents to append
|
|
70
|
-
* @returns true if successful,
|
|
74
|
+
* @returns true if successful, null in case of error
|
|
71
75
|
*/
|
|
72
|
-
export declare const appendToFile: (file: string, contents: string) => Promise<
|
|
76
|
+
export declare const appendToFile: (file: string, contents: string) => Promise<true | null>;
|
|
73
77
|
/**
|
|
74
78
|
* Rename a file
|
|
75
79
|
* @param oldpath old file path
|
|
76
80
|
* @param newpath new file path
|
|
77
|
-
* @returns true if successful,
|
|
81
|
+
* @returns true if successful, null in case of error
|
|
78
82
|
*/
|
|
79
|
-
export declare const renameFile: (oldpath: string, newpath: string) => Promise<
|
|
83
|
+
export declare const renameFile: (oldpath: string, newpath: string) => Promise<true | null>;
|
|
80
84
|
/**
|
|
81
85
|
* Create a directory, if it doesn't exist
|
|
82
86
|
* @param dir directory path
|
|
83
|
-
* @returns true if successful,
|
|
87
|
+
* @returns true if successful, null in case of failure/error
|
|
84
88
|
*/
|
|
85
|
-
export declare const createDir: (dir: string) => Promise<
|
|
89
|
+
export declare const createDir: (dir: string) => Promise<true | null>;
|
|
86
90
|
/**
|
|
87
91
|
* Delete a file
|
|
88
92
|
* @param file file path
|
|
89
|
-
* @returns true if successful,
|
|
93
|
+
* @returns true if successful, null in case of error
|
|
90
94
|
*/
|
|
91
|
-
export declare const deleteFile: (file: string) => Promise<
|
|
95
|
+
export declare const deleteFile: (file: string) => Promise<true | null>;
|
|
92
96
|
/**
|
|
93
97
|
* Delete a directory
|
|
94
98
|
* @param dir directory path
|
|
95
|
-
* @returns true if successful,
|
|
99
|
+
* @returns true if successful, null in case of error
|
|
96
100
|
*/
|
|
97
|
-
export declare const deleteDir: (dir: string) => Promise<
|
|
101
|
+
export declare const deleteDir: (dir: string) => Promise<true | null>;
|
|
98
102
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fs/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fs/index.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,eAAO,MAAM,cAAc,SAAU,MAAM,mCAiB1C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,QAAS,MAAM,mCAiBxC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,SAAgB,MAAM,2CAU1C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,SAAU,MAAM,kCAUxC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,QAAe,MAAM;;;SA2BxC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,QAAe,MAAM,gFAI7C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,QAAe,MAAM,gFAI5C,CAAC;AA0BF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,QAAe,MAAM,oDAMhD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,SAAS,SAAgB,MAAM,YAAY,MAAM,yBAY7D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,SAAgB,MAAM,YAAY,MAAM,yBAkBhE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,YAAmB,MAAM,WAAW,MAAM,yBAWhE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,SAAS,QAAe,MAAM,yBAY1C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,SAAgB,MAAM,yBAU5C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,SAAS,QAAe,MAAM,yBAe1C,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import * as fs from './fs';
|
|
2
2
|
import * as aws from './aws';
|
|
3
3
|
import * as gh from './gh';
|
|
4
|
-
|
|
4
|
+
import * as utils from './utils';
|
|
5
|
+
export { fs, aws, gh, utils };
|
|
5
6
|
declare const _default: {
|
|
6
7
|
fs: typeof fs;
|
|
7
8
|
aws: typeof aws;
|
|
8
9
|
gh: typeof gh;
|
|
10
|
+
utils: typeof utils;
|
|
9
11
|
};
|
|
10
12
|
export default _default;
|
|
11
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;AAC3B,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;AAC3B,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAGjC,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;;;;;;;AAC9B,wBAAsC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare const assertPath: (p: string) => string;
|
|
3
|
+
export declare const sha1Hash: (data: string) => string | null;
|
|
4
|
+
export declare const sha256Hash: (data: string | Buffer) => string | null;
|
|
5
|
+
export declare const fileHash: (file: string) => Promise<string | null>;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";AAMA,eAAO,MAAM,UAAU,MAAO,MAAM,WAGnC,CAAC;AAEF,eAAO,MAAM,QAAQ,SAAU,MAAM,kBAKpC,CAAC;AAEF,eAAO,MAAM,UAAU,SAAU,MAAM,GAAG,MAAM,kBAK/C,CAAC;AAEF,eAAO,MAAM,QAAQ,SAAgB,MAAM,2BAa1C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baadal-sdk/dapi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Dead-simple API wrappers",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"@babel/preset-env": "7.15.6",
|
|
45
45
|
"@babel/preset-react": "^7.14.5",
|
|
46
46
|
"@babel/preset-typescript": "7.15.0",
|
|
47
|
+
"@types/mime-types": "^2.1.1",
|
|
47
48
|
"@types/node": "16.9.6",
|
|
48
49
|
"@types/react": "^16.0.0",
|
|
49
50
|
"@types/react-dom": "^16.0.0",
|
|
@@ -74,10 +75,13 @@
|
|
|
74
75
|
},
|
|
75
76
|
"dependencies": {
|
|
76
77
|
"@aws-sdk/client-dynamodb": "^3.34.0",
|
|
78
|
+
"@aws-sdk/client-s3": "^3.36.0",
|
|
77
79
|
"@aws-sdk/lib-dynamodb": "^3.34.0",
|
|
80
|
+
"@baadal-sdk/utils": "0.12.0",
|
|
78
81
|
"@octokit/core": "^3.5.1",
|
|
79
82
|
"chalk": "^2.4.2",
|
|
80
83
|
"core-js": "^3.18.0",
|
|
84
|
+
"mime-types": "^2.1.33",
|
|
81
85
|
"rimraf": "^3.0.2",
|
|
82
86
|
"short-uuid": "^4.2.0"
|
|
83
87
|
},
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
|
|
2
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
3
|
+
|
|
4
|
+
const dbDocClient: DynamoDBDocumentClient | null = null;
|
|
5
|
+
const awsS3Client: S3Client | null = null;
|
|
6
|
+
|
|
7
|
+
export const dbClient = { client: dbDocClient, id: null } as DBClientType;
|
|
8
|
+
export const s3Client = { client: awsS3Client, id: null } as S3ClientType;
|
|
9
|
+
|
|
10
|
+
export interface DBClientType {
|
|
11
|
+
client: DynamoDBDocumentClient | null;
|
|
12
|
+
id: string | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface S3ClientType {
|
|
16
|
+
client: S3Client | null;
|
|
17
|
+
id: string | null;
|
|
18
|
+
}
|