@creator.co/wapi 1.2.0-alpha8 → 1.2.0-alpha9

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/.eslintrc.cjs CHANGED
@@ -18,7 +18,7 @@ module.exports = {
18
18
  },
19
19
  ],
20
20
  "@typescript-eslint/ban-ts-comment": 0,
21
- "@typescript-eslint/no-explicit-any": "warn",
21
+ "@typescript-eslint/no-explicit-any": 0,
22
22
  // turn on errors for missing imports
23
23
  "import/no-unresolved": "error",
24
24
  // 'import/no-named-as-default-member': 'off',
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator.co/wapi",
3
- "version": "1.2.0-alpha7",
3
+ "version": "1.2.0-alpha8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,19 +11,19 @@ export type TransactionConfig = {
11
11
  publisher?: PublisherConfig;
12
12
  };
13
13
  export default class Transaction<T = object, B = null> {
14
- private _event;
15
- private _context;
16
- private _response;
17
- private _syncReturn;
18
- private _retrowErrors;
14
+ private event;
15
+ private context;
16
+ private response;
17
+ private syncReturn;
18
+ private retrowErrors;
19
19
  readonly logger: Logger;
20
20
  readonly request: Request<T>;
21
21
  readonly publisher: Publisher;
22
22
  responseProxy: (response: Response) => Promise<void>;
23
23
  constructor(event: APIGatewayEvent | SQSEvent, context: Context, config?: TransactionConfig);
24
24
  execute(executionFunc: TransactionExecution<Transaction<T, B>>): Promise<Response | null | SQSBatchResponse>;
25
- _execute(executionFunc: TransactionExecution<Transaction<T>>): Promise<boolean>;
26
- _executeDBTransactions(safeExecution: any): Promise<void>;
27
- _executeLoggerFlush(safeExecution: any): Promise<void>;
28
- _getErrorResponse(error: string, code: string): Response;
25
+ private iexecute;
26
+ private executeDBTransactions;
27
+ private executeLoggerFlush;
28
+ private getErrorResponse;
29
29
  }
@@ -50,17 +50,17 @@ var Transaction = /** @class */ (function () {
50
50
  ? event.requestContext.requestId
51
51
  : "unknown";
52
52
  // transaction ctx
53
- this._event = event;
54
- this._context = context;
55
- this._response = null;
53
+ this.event = event;
54
+ this.context = context;
55
+ this.response = null;
56
56
  // when set, this will be called with the response context right before calling the context suceed/fail - useful for writing the resp for example.
57
57
  this.responseProxy = null;
58
58
  // transaction flags
59
- this._syncReturn = !!(config === null || config === void 0 ? void 0 : config.syncReturn);
60
- this._retrowErrors = !!(config === null || config === void 0 ? void 0 : config.throwOnErrors); /* retrow internal errors */
59
+ this.syncReturn = !!(config === null || config === void 0 ? void 0 : config.syncReturn);
60
+ this.retrowErrors = !!(config === null || config === void 0 ? void 0 : config.throwOnErrors); /* retrow internal errors */
61
61
  // components
62
62
  this.logger = new Logger_1.default(config === null || config === void 0 ? void 0 : config.logger, transactionId);
63
- this.request = new Request_1.default(this._event, this._context, this.logger);
63
+ this.request = new Request_1.default(this.event, this.context, this.logger);
64
64
  this.publisher = new Publisher_1.default(config === null || config === void 0 ? void 0 : config.publisher);
65
65
  }
66
66
  //Main interface
@@ -69,14 +69,14 @@ var Transaction = /** @class */ (function () {
69
69
  var _this = this;
70
70
  return __generator(this, function (_a) {
71
71
  switch (_a.label) {
72
- case 0: return [4 /*yield*/, this._executeLoggerFlush(function () { return __awaiter(_this, void 0, void 0, function () {
72
+ case 0: return [4 /*yield*/, this.executeLoggerFlush(function () { return __awaiter(_this, void 0, void 0, function () {
73
73
  var _this = this;
74
74
  return __generator(this, function (_a) {
75
75
  switch (_a.label) {
76
- case 0: return [4 /*yield*/, this._executeDBTransactions(function () { return __awaiter(_this, void 0, void 0, function () {
76
+ case 0: return [4 /*yield*/, this.executeDBTransactions(function () { return __awaiter(_this, void 0, void 0, function () {
77
77
  return __generator(this, function (_a) {
78
78
  switch (_a.label) {
79
- case 0: return [4 /*yield*/, this._execute(executionFunc)];
79
+ case 0: return [4 /*yield*/, this.iexecute(executionFunc)];
80
80
  case 1: return [2 /*return*/, _a.sent()];
81
81
  }
82
82
  });
@@ -92,8 +92,8 @@ var Transaction = /** @class */ (function () {
92
92
  case 1:
93
93
  _a.sent();
94
94
  // return raw response if sync return is requested
95
- if (this._syncReturn)
96
- return [2 /*return*/, this._response
95
+ if (this.syncReturn)
96
+ return [2 /*return*/, this.response
97
97
  // allow request to async succeed through lambda context
98
98
  ];
99
99
  // allow request to async succeed through lambda context
@@ -103,7 +103,7 @@ var Transaction = /** @class */ (function () {
103
103
  });
104
104
  };
105
105
  //Executions
106
- Transaction.prototype._execute = function (executionFunc) {
106
+ Transaction.prototype.iexecute = function (executionFunc) {
107
107
  return __awaiter(this, void 0, void 0, function () {
108
108
  var executionFailed, _a, e_1;
109
109
  return __generator(this, function (_b) {
@@ -121,22 +121,22 @@ var Transaction = /** @class */ (function () {
121
121
  //Answer client
122
122
  ];
123
123
  case 2:
124
- _a._response = _b.sent();
125
- if (!(this._response && this._response instanceof Response_1.default)) return [3 /*break*/, 4];
126
- return [4 /*yield*/, this._response.build(this._context, this, this._syncReturn)];
124
+ _a.response = _b.sent();
125
+ if (!(this.response && this.response instanceof Response_1.default)) return [3 /*break*/, 4];
126
+ return [4 /*yield*/, this.response.build(this.context, this, this.syncReturn)];
127
127
  case 3:
128
128
  _b.sent();
129
- executionFailed = !!(this._response.getBody() && this._response.getBody().rollback);
129
+ executionFailed = !!(this.response.getBody() && this.response.getBody().rollback);
130
130
  return [3 /*break*/, 7];
131
131
  case 4:
132
- if (!(this._syncReturn && this._response)) return [3 /*break*/, 5];
132
+ if (!(this.syncReturn && this.response)) return [3 /*break*/, 5];
133
133
  this.logger.log("Sync return with different response object");
134
- this.logger.debug(this._response);
134
+ this.logger.debug(this.response);
135
135
  executionFailed = false;
136
136
  return [3 /*break*/, 7];
137
137
  case 5:
138
- this._response = this._getErrorResponse(Globals_1.default.ErrorResponseInvalidServerResponse, Globals_1.default.ErrorCode_APIError);
139
- return [4 /*yield*/, this._response.build(this._context, this, this._syncReturn)];
138
+ this.response = this.getErrorResponse(Globals_1.default.ErrorResponseInvalidServerResponse, Globals_1.default.ErrorCode_APIError);
139
+ return [4 /*yield*/, this.response.build(this.context, this, this.syncReturn)];
140
140
  case 6:
141
141
  _b.sent();
142
142
  this.logger.error("Invalid response object from main request code.");
@@ -148,11 +148,11 @@ var Transaction = /** @class */ (function () {
148
148
  this.logger.error("Exception when executing main request code.");
149
149
  this.logger.exception(e_1);
150
150
  //retrow?
151
- if (this._retrowErrors)
151
+ if (this.retrowErrors)
152
152
  throw e_1;
153
153
  if (!executionFailed) return [3 /*break*/, 10];
154
- this._response = this._getErrorResponse(Globals_1.default.ErrorResponseUnhandledError, Globals_1.default.ErrorCode_APIError);
155
- return [4 /*yield*/, this._response.build(this._context, this, this._syncReturn)];
154
+ this.response = this.getErrorResponse(Globals_1.default.ErrorResponseUnhandledError, Globals_1.default.ErrorCode_APIError);
155
+ return [4 /*yield*/, this.response.build(this.context, this, this.syncReturn)];
156
156
  case 9:
157
157
  _b.sent();
158
158
  _b.label = 10;
@@ -162,7 +162,7 @@ var Transaction = /** @class */ (function () {
162
162
  });
163
163
  });
164
164
  };
165
- Transaction.prototype._executeDBTransactions = function (safeExecution) {
165
+ Transaction.prototype.executeDBTransactions = function (safeExecution) {
166
166
  return __awaiter(this, void 0, void 0, function () {
167
167
  var e_2;
168
168
  return __generator(this, function (_a) {
@@ -200,7 +200,7 @@ var Transaction = /** @class */ (function () {
200
200
  this.logger.error("Exception when executing DB transactions.");
201
201
  this.logger.log(e_2.stack);
202
202
  //retrow?
203
- if (this._retrowErrors)
203
+ if (this.retrowErrors)
204
204
  throw e_2;
205
205
  return [3 /*break*/, 3];
206
206
  case 3: return [2 /*return*/];
@@ -208,7 +208,7 @@ var Transaction = /** @class */ (function () {
208
208
  });
209
209
  });
210
210
  };
211
- Transaction.prototype._executeLoggerFlush = function (safeExecution) {
211
+ Transaction.prototype.executeLoggerFlush = function (safeExecution) {
212
212
  return __awaiter(this, void 0, void 0, function () {
213
213
  var e_3;
214
214
  return __generator(this, function (_a) {
@@ -227,7 +227,7 @@ var Transaction = /** @class */ (function () {
227
227
  this.logger.error("Exception when flushing logs.");
228
228
  this.logger.exception(e_3);
229
229
  //retrow?
230
- if (this._retrowErrors)
230
+ if (this.retrowErrors)
231
231
  throw e_3;
232
232
  return [3 /*break*/, 5];
233
233
  case 4:
@@ -239,7 +239,7 @@ var Transaction = /** @class */ (function () {
239
239
  });
240
240
  };
241
241
  /* Response support */
242
- Transaction.prototype._getErrorResponse = function (error, code) {
242
+ Transaction.prototype.getErrorResponse = function (error, code) {
243
243
  return Response_1.default.BadRequestResponseWithRollback(error, code);
244
244
  };
245
245
  return Transaction;
@@ -1 +1 @@
1
- {"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../../src/BaseEvent/Transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,0CAAoC;AACpC,4CAAsC;AACtC,sCAAgC;AAChC,2CAAuD;AACvD,oDAAmE;AAenE;IAWE,EAAE;IACF,qBACE,KAAiC,EACjC,OAAgB,EAChB,MAA0B;QAE1B,IAAM,aAAa,GAAG,OAAO,CAAC,YAAY;YACxC,CAAC,CAAC,OAAO,CAAC,YAAY;YACtB,CAAC,CAAmB,KAAM,CAAC,cAAc;gBACzC,CAAC,CAAmB,KAAM,CAAC,cAAc,CAAC,SAAS;gBACnD,CAAC,CAAC,SAAS,CAAA;QACb,kBAAkB;QAClB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;QACrB,kJAAkJ;QAClJ,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA;QACzB,oBAAoB;QACpB,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,CAAA,CAAA;QACvC,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,CAAA,MAAM,aAAN,MAAM,u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AA;;;;;;KAEzC;IACD,sBAAsB;IACd,sCAAgB,GAAxB,UAAyB,KAAa,EAAE,IAAY;QAClD,OAAO,kBAAQ,CAAC,8BAA8B,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IAC7D,CAAC;IACH,kBAAC;AAAD,CAAC,AA1ID,IA0IC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator.co/wapi",
3
- "version": "1.2.0-alpha8",
3
+ "version": "1.2.0-alpha9",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,11 +25,11 @@ export type TransactionConfig = {
25
25
  }
26
26
 
27
27
  export default class Transaction<T = object, B = null> {
28
- private _event: any
29
- private _context: Context
30
- private _response: Response | null | SQSBatchResponse
31
- private _syncReturn: boolean
32
- private _retrowErrors: boolean
28
+ private event: any
29
+ private context: Context
30
+ private response: Response | null | SQSBatchResponse
31
+ private syncReturn: boolean
32
+ private retrowErrors: boolean
33
33
  //
34
34
  public readonly logger: Logger
35
35
  public readonly request: Request<T>
@@ -47,36 +47,36 @@ export default class Transaction<T = object, B = null> {
47
47
  ? (<APIGatewayEvent>event).requestContext.requestId
48
48
  : "unknown"
49
49
  // transaction ctx
50
- this._event = event
51
- this._context = context
52
- this._response = null
50
+ this.event = event
51
+ this.context = context
52
+ this.response = null
53
53
  // when set, this will be called with the response context right before calling the context suceed/fail - useful for writing the resp for example.
54
54
  this.responseProxy = null
55
55
  // transaction flags
56
- this._syncReturn = !!config?.syncReturn
57
- this._retrowErrors = !!config?.throwOnErrors /* retrow internal errors */
56
+ this.syncReturn = !!config?.syncReturn
57
+ this.retrowErrors = !!config?.throwOnErrors /* retrow internal errors */
58
58
  // components
59
59
  this.logger = new Logger(config?.logger, transactionId)
60
- this.request = new Request<T>(this._event, this._context, this.logger)
60
+ this.request = new Request<T>(this.event, this.context, this.logger)
61
61
  this.publisher = new Publisher(config?.publisher)
62
62
  }
63
63
 
64
64
  //Main interface
65
- async execute(
65
+ public async execute(
66
66
  executionFunc: TransactionExecution<Transaction<T, B>>,
67
67
  ): Promise<Response | null | SQSBatchResponse> {
68
- await this._executeLoggerFlush(async () => {
69
- await this._executeDBTransactions(async () => {
70
- return await this._execute(executionFunc)
68
+ await this.executeLoggerFlush(async () => {
69
+ await this.executeDBTransactions(async () => {
70
+ return await this.iexecute(executionFunc)
71
71
  })
72
72
  })
73
73
  // return raw response if sync return is requested
74
- if (this._syncReturn) return this._response
74
+ if (this.syncReturn) return this.response
75
75
  // allow request to async succeed through lambda context
76
76
  return null
77
77
  }
78
78
  //Executions
79
- async _execute(
79
+ private async iexecute(
80
80
  executionFunc: TransactionExecution<Transaction<T>>,
81
81
  ): Promise<boolean> {
82
82
  let executionFailed = true //failed til we say no!
@@ -84,23 +84,23 @@ export default class Transaction<T = object, B = null> {
84
84
  try {
85
85
  //Execute
86
86
  this.logger.debug("Starting main request code")
87
- this._response = await executionFunc(this)
87
+ this.response = await executionFunc(this)
88
88
  //Answer client
89
- if (this._response && this._response instanceof Response) {
90
- await this._response.build(this._context, this, this._syncReturn)
89
+ if (this.response && this.response instanceof Response) {
90
+ await this.response.build(this.context, this, this.syncReturn)
91
91
  executionFailed = !!(
92
- this._response.getBody() && this._response.getBody().rollback
92
+ this.response.getBody() && this.response.getBody().rollback
93
93
  )
94
- } else if (this._syncReturn && this._response) {
94
+ } else if (this.syncReturn && this.response) {
95
95
  this.logger.log("Sync return with different response object")
96
- this.logger.debug(this._response)
96
+ this.logger.debug(this.response)
97
97
  executionFailed = false
98
98
  } else {
99
- this._response = this._getErrorResponse(
99
+ this.response = this.getErrorResponse(
100
100
  Globals.ErrorResponseInvalidServerResponse,
101
101
  Globals.ErrorCode_APIError,
102
102
  )
103
- await this._response.build(this._context, this, this._syncReturn)
103
+ await this.response.build(this.context, this, this.syncReturn)
104
104
  this.logger.error("Invalid response object from main request code.")
105
105
  }
106
106
  } catch (e) {
@@ -108,19 +108,19 @@ export default class Transaction<T = object, B = null> {
108
108
  this.logger.error("Exception when executing main request code.")
109
109
  this.logger.exception(e)
110
110
  //retrow?
111
- if (this._retrowErrors) throw e
111
+ if (this.retrowErrors) throw e
112
112
  //envelope exception?
113
113
  if (executionFailed) {
114
- this._response = this._getErrorResponse(
114
+ this.response = this.getErrorResponse(
115
115
  Globals.ErrorResponseUnhandledError,
116
116
  Globals.ErrorCode_APIError,
117
117
  )
118
- await this._response.build(this._context, this, this._syncReturn)
118
+ await this.response.build(this.context, this, this.syncReturn)
119
119
  }
120
120
  }
121
121
  return executionFailed
122
122
  }
123
- async _executeDBTransactions(safeExecution) {
123
+ private async executeDBTransactions(safeExecution) {
124
124
  try {
125
125
  // //start DB
126
126
  // if (this.db) await this.db.connect();
@@ -142,10 +142,10 @@ export default class Transaction<T = object, B = null> {
142
142
  this.logger.error("Exception when executing DB transactions.")
143
143
  this.logger.log(e.stack)
144
144
  //retrow?
145
- if (this._retrowErrors) throw e
145
+ if (this.retrowErrors) throw e
146
146
  }
147
147
  }
148
- async _executeLoggerFlush(safeExecution) {
148
+ private async executeLoggerFlush(safeExecution) {
149
149
  try {
150
150
  await safeExecution()
151
151
  await this.logger.flushLogs()
@@ -153,13 +153,13 @@ export default class Transaction<T = object, B = null> {
153
153
  this.logger.error("Exception when flushing logs.")
154
154
  this.logger.exception(e)
155
155
  //retrow?
156
- if (this._retrowErrors) throw e
156
+ if (this.retrowErrors) throw e
157
157
  } finally {
158
158
  this.logger.debug("Transaction ended")
159
159
  }
160
160
  }
161
161
  /* Response support */
162
- _getErrorResponse(error: string, code: string): Response {
162
+ private getErrorResponse(error: string, code: string): Response {
163
163
  return Response.BadRequestResponseWithRollback(error, code)
164
164
  }
165
165
  }