ag-common 0.0.411 → 0.0.413
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.
|
@@ -2,7 +2,10 @@ import DynamoDB from 'aws-sdk/clients/dynamodb';
|
|
|
2
2
|
import { DYNAMOKEYS, IQueryDynamo, Key } from '../types';
|
|
3
3
|
export declare let dynamoDb: DynamoDB.DocumentClient;
|
|
4
4
|
export declare const setDynamo: (region: string) => void;
|
|
5
|
-
export declare const putDynamo: <T>(item: T, tableName: string
|
|
5
|
+
export declare const putDynamo: <T>(item: T, tableName: string, opt?: {
|
|
6
|
+
/** if provided, will assert this PK value doesnt already exist */
|
|
7
|
+
pkName?: string;
|
|
8
|
+
}) => Promise<{
|
|
6
9
|
error?: string | undefined;
|
|
7
10
|
data?: T | undefined;
|
|
8
11
|
}>;
|
|
@@ -48,12 +48,12 @@ const setDynamo = (region) => {
|
|
|
48
48
|
exports.dynamoDb = new dynamodb_1.DocumentClient({ region });
|
|
49
49
|
};
|
|
50
50
|
exports.setDynamo = setDynamo;
|
|
51
|
-
const putDynamo = (item, tableName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
-
const params = {
|
|
53
|
-
TableName: tableName,
|
|
51
|
+
const putDynamo = (item, tableName, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
const params = Object.assign({ TableName: tableName,
|
|
54
53
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
-
Item: item,
|
|
56
|
-
|
|
54
|
+
Item: item }, ((opt === null || opt === void 0 ? void 0 : opt.pkName) && {
|
|
55
|
+
ConditionExpression: `attribute_not_exists(${opt.pkName})`,
|
|
56
|
+
}));
|
|
57
57
|
(0, log_1.info)(`running dynamo put=${JSON.stringify(params, null, 2)}`);
|
|
58
58
|
// write the todo to the database
|
|
59
59
|
const put = yield exports.dynamoDb.put(params).promise();
|
|
@@ -36,16 +36,14 @@ const useCallOpenApi = (pIn) => {
|
|
|
36
36
|
setData([pIn, defaultState(pIn, true)]);
|
|
37
37
|
}
|
|
38
38
|
}, [data, pIn]);
|
|
39
|
+
const run = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
const resp = yield (0, direct_1.callOpenApi)(data[0]);
|
|
41
|
+
setData((d) => [
|
|
42
|
+
d[0],
|
|
43
|
+
Object.assign(Object.assign({}, resp), { loaded: true, loading: false, loadcount: d[1].loadcount + 1, url: '', datetime: new Date().getTime() }),
|
|
44
|
+
]);
|
|
45
|
+
}), [data]);
|
|
39
46
|
(0, react_1.useEffect)(() => {
|
|
40
|
-
function run() {
|
|
41
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
const resp = yield (0, direct_1.callOpenApi)(data[0]);
|
|
43
|
-
setData((d) => [
|
|
44
|
-
d[0],
|
|
45
|
-
Object.assign(Object.assign({}, resp), { loaded: true, loading: false, loadcount: d[1].loadcount + 1, url: '', datetime: new Date().getTime() }),
|
|
46
|
-
]);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
47
|
const { error, loaded, loading, loadcount } = data[1];
|
|
50
48
|
const ng = data[0].disabled || loaded || loading || (error && loadcount > 2);
|
|
51
49
|
if (ng) {
|
|
@@ -53,8 +51,8 @@ const useCallOpenApi = (pIn) => {
|
|
|
53
51
|
}
|
|
54
52
|
setData((d) => [d[0], Object.assign(Object.assign({}, d[1]), { loading: true })]);
|
|
55
53
|
void run();
|
|
56
|
-
}, [data, setData]);
|
|
57
|
-
const ret = Object.assign(Object.assign({}, data[1]), { reFetch: () => __awaiter(void 0, void 0, void 0, function* () { return
|
|
54
|
+
}, [data, run, setData]);
|
|
55
|
+
const ret = Object.assign(Object.assign({}, data[1]), { reFetch: () => __awaiter(void 0, void 0, void 0, function* () { return run; }), setData: (d) => {
|
|
58
56
|
setData([
|
|
59
57
|
data[0],
|
|
60
58
|
Object.assign(Object.assign({}, data[1]), { data: d(data[1].data), datetime: new Date().getTime() }),
|