@ekhein/lamda-node-sdk 2.1.6 → 2.1.8

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/main.d.ts CHANGED
@@ -34,14 +34,14 @@ export declare class Device {
34
34
  }): Promise<any>;
35
35
  }
36
36
  export declare class Storage {
37
- private readonly container;
38
37
  private readonly $;
39
- constructor(container: string, $: Device);
38
+ private readonly container;
39
+ constructor($: Device, container: string);
40
40
  set(key: string, data: any): Promise<boolean>;
41
41
  setex(key: string, data: any, ttl: number): Promise<boolean>;
42
42
  setnx(key: string, data: any): Promise<boolean>;
43
43
  expire(key: string, ttl: number): Promise<boolean>;
44
- get<T = any>(key: string): Promise<T>;
44
+ get<T = any>(key: string, defaultValue?: T): Promise<T>;
45
45
  ttl(key: string): Promise<number>;
46
46
  exists(key: string): Promise<boolean>;
47
47
  delete(key: string): Promise<boolean>;
package/dist/main.js CHANGED
@@ -155,59 +155,70 @@ __decorate([
155
155
  __metadata("design:type", Object)
156
156
  ], Device.prototype, "Settings", void 0);
157
157
  class Storage {
158
- container;
159
158
  $;
160
- constructor(container, $) {
161
- this.container = container;
159
+ container;
160
+ constructor($, container) {
162
161
  this.$ = $;
162
+ this.container = container;
163
+ for (const method in $.Storage) {
164
+ if (method != "clearAll") {
165
+ const origin = $.Storage[method];
166
+ $.Storage[method] = function (params) {
167
+ Object.assign(params, { container });
168
+ return origin.call(this, params);
169
+ };
170
+ }
171
+ }
163
172
  }
164
173
  async set(key, data) {
165
174
  const value = (0, msgpackr_1.pack)(data);
166
- return this.$.Storage
167
- .set({ container: this.container, key, value })
168
- .then(async (r) => r.value);
175
+ const result = await this.$.Storage
176
+ .set({ key, value });
177
+ return result.value;
169
178
  }
170
179
  async setex(key, data, ttl) {
171
180
  const value = (0, msgpackr_1.pack)(data);
172
- return this.$.Storage
173
- .setex({ container: this.container, key, value, ttl })
174
- .then(async (r) => r.value);
181
+ const result = await this.$.Storage
182
+ .setex({ key, value, ttl });
183
+ return result.value;
175
184
  }
176
185
  async setnx(key, data) {
177
186
  const value = (0, msgpackr_1.pack)(data);
178
- return this.$.Storage
179
- .setnx({ container: this.container, key, value })
180
- .then(async (r) => r.value);
187
+ const result = await this.$.Storage
188
+ .setnx({ key, value });
189
+ return result.value;
181
190
  }
182
191
  async expire(key, ttl) {
183
- return this.$.Storage
184
- .expire({ container: this.container, key, ttl })
185
- .then(async (r) => r.value);
192
+ const result = await this.$.Storage
193
+ .expire({ key, ttl });
194
+ return result.value;
186
195
  }
187
- async get(key) {
188
- return this.$.Storage
189
- .get({ container: this.container, key })
190
- .then(async (r) => (0, msgpackr_1.unpack)(r.value));
196
+ async get(key, defaultValue) {
197
+ const result = await this.$.Storage
198
+ .get({ key });
199
+ if (result.value.length == 0)
200
+ return defaultValue;
201
+ return (0, msgpackr_1.unpack)(result.value);
191
202
  }
192
203
  async ttl(key) {
193
- return this.$.Storage
194
- .ttl({ container: this.container, key })
195
- .then(r => r.value);
204
+ const result = await this.$.Storage
205
+ .ttl({ key });
206
+ return result.value;
196
207
  }
197
208
  async exists(key) {
198
- return this.$.Storage
199
- .exists({ container: this.container, key })
200
- .then(async (r) => r.value);
209
+ const result = await this.$.Storage
210
+ .exists({ key });
211
+ return result.value;
201
212
  }
202
213
  async delete(key) {
203
- return this.$.Storage
204
- .delete({ container: this.container, key })
205
- .then(async (r) => r.value);
214
+ const result = await this.$.Storage
215
+ .delete({ key });
216
+ return result.value;
206
217
  }
207
218
  async clear() {
208
- return this.$.Storage
209
- .clearContainer({ container: this.container })
210
- .then(async (r) => r.value);
219
+ const result = await this.$.Storage
220
+ .clearContainer({ container: this.container });
221
+ return result.value;
211
222
  }
212
223
  }
213
224
  exports.Storage = Storage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekhein/lamda-node-sdk",
3
- "version": "2.1.6",
3
+ "version": "2.1.8",
4
4
  "author": "ekhein",
5
5
  "license": "MIT",
6
6
  "main": "./dist/main.js",