@toa.io/extensions.stash 0.20.0-dev.34 → 0.20.0-dev.35

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/extensions.stash",
3
- "version": "0.20.0-dev.34",
3
+ "version": "0.20.0-dev.35",
4
4
  "description": "Toa Stash",
5
5
  "author": "temich <tema.gurtovoy@gmail.com>",
6
6
  "homepage": "https://github.com/toa-io/toa#readme",
@@ -17,7 +17,7 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "@toa.io/pointer": "0.20.0-dev.34",
20
+ "@toa.io/pointer": "0.20.0-dev.35",
21
21
  "ioredis": "5.3.2",
22
22
  "msgpackr": "1.9.5",
23
23
  "redlock-temp-fix": "5.0.0-beta.2"
@@ -30,5 +30,5 @@
30
30
  "preset": "ts-jest",
31
31
  "testEnvironment": "node"
32
32
  },
33
- "gitHead": "7035b1985fe9bb844069308a272d061bfbd38bf0"
33
+ "gitHead": "04d3317272256b98003a414ee1eb2555b65163a5"
34
34
  }
@@ -1,20 +0,0 @@
1
- import { Connector, type extensions } from '@toa.io/core';
2
- import type { Connection } from './Connection';
3
- export declare class Aspect extends Connector implements extensions.Aspect {
4
- readonly name = "stash";
5
- private readonly connection;
6
- private redis;
7
- private redlock;
8
- constructor(connection: Connection);
9
- invoke(method: 'store', key: string, value: object): Promise<void>;
10
- invoke(method: 'fetch', key: string): Promise<object>;
11
- invoke<T>(method: 'lock', key: Resources, routine: Routine<T>): Promise<T>;
12
- invoke(method: string, ...args: unknown[]): Promise<any>;
13
- protected open(): Promise<void>;
14
- private store;
15
- private fetch;
16
- private lock;
17
- }
18
- type Routine<T> = () => Promise<T>;
19
- type Resources = string | string[];
20
- export {};
@@ -1,57 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Aspect = void 0;
7
- const redlock_temp_fix_1 = __importDefault(require("redlock-temp-fix"));
8
- const msgpackr_1 = require("msgpackr");
9
- const core_1 = require("@toa.io/core");
10
- class Aspect extends core_1.Connector {
11
- name = 'stash';
12
- connection;
13
- redis = null;
14
- redlock = null;
15
- constructor(connection) {
16
- super();
17
- this.connection = connection;
18
- this.depends(connection);
19
- }
20
- async invoke(method, ...args) {
21
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
22
- // @ts-expect-error
23
- if (typeof this.redis[method] === 'function')
24
- return this.redis[method](...args);
25
- if (method === 'store')
26
- await this.store(args[0], args[1], ...args.slice(2));
27
- if (method === 'fetch')
28
- return await this.fetch(args[0]);
29
- if (method === 'lock')
30
- return await this.lock(args[0], args[1]);
31
- }
32
- async open() {
33
- this.redis = this.connection.redises[0];
34
- this.redlock = new redlock_temp_fix_1.default(this.connection.redises, { retryCount: -1 });
35
- }
36
- async store(key, value, ...args) {
37
- const buffer = (0, msgpackr_1.encode)(value);
38
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
39
- // @ts-expect-error
40
- await this.redis.set(key, buffer, ...args);
41
- }
42
- async fetch(key) {
43
- if (this.redis === null)
44
- return null;
45
- const buffer = await this.redis.getBuffer(key);
46
- return buffer === null ? null : (0, msgpackr_1.decode)(buffer);
47
- }
48
- async lock(key, routine) {
49
- if (this.redlock === null)
50
- return null;
51
- if (typeof key === 'string')
52
- key = [key];
53
- return await this.redlock.using(key, 5000, routine);
54
- }
55
- }
56
- exports.Aspect = Aspect;
57
- //# sourceMappingURL=Aspect.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Aspect.js","sourceRoot":"","sources":["../source/Aspect.ts"],"names":[],"mappings":";;;;;;AAAA,wEAAsC;AACtC,uCAAyC;AACzC,uCAAyD;AAIzD,MAAa,MAAO,SAAQ,gBAAS;IACnB,IAAI,GAAG,OAAO,CAAA;IACb,UAAU,CAA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AG,IAAA,iBAAM,EAAC,KAAK,CAAC,CAAA;QAE5B,6DAA6D;QAC7D,mBAAmB;QACnB,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,CAAA;IAC5C,CAAC;IAEO,KAAK,CAAC,KAAK,CAAE,GAAW;QAC9B,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI;YAAE,OAAO,IAAI,CAAA;QAEpC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QAE9C,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,iBAAM,EAAC,MAAM,CAAC,CAAA;IAChD,CAAC;IAEO,KAAK,CAAC,IAAI,CAAK,GAAc,EAAE,OAAmB;QACxD,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI;YAAE,OAAO,IAAI,CAAA;QAEtC,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;QAExC,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAI,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IACxD,CAAC;CACF;AA5DD,wBA4DC"}
@@ -1,11 +0,0 @@
1
- import { Redis } from 'ioredis';
2
- import { Connector, type Locator } from '@toa.io/core';
3
- export declare class Connection extends Connector {
4
- readonly redises: Redis[];
5
- private readonly locator;
6
- constructor(locator: Locator);
7
- protected open(): Promise<void>;
8
- protected close(): Promise<void>;
9
- private connectNode;
10
- private resolveURLs;
11
- }
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Connection = void 0;
4
- const ioredis_1 = require("ioredis");
5
- const core_1 = require("@toa.io/core");
6
- const pointer_1 = require("@toa.io/pointer");
7
- const extension_1 = require("./extension");
8
- class Connection extends core_1.Connector {
9
- redises = [];
10
- locator;
11
- constructor(locator) {
12
- super();
13
- this.locator = locator;
14
- }
15
- async open() {
16
- const keyPrefix = `${this.locator.namespace}:${this.locator.name}:`;
17
- const options = { keyPrefix, enableReadyCheck: true, lazyConnect: true };
18
- const urls = await this.resolveURLs();
19
- for (const url of urls)
20
- this.redises.push(new ioredis_1.Redis(url, options));
21
- const connecting = this.redises.map(this.connectNode.bind(this));
22
- await Promise.all(connecting);
23
- }
24
- async close() {
25
- for (const redis of this.redises)
26
- redis.disconnect();
27
- console.log('Stash disconnected');
28
- }
29
- async connectNode(redis) {
30
- await redis.connect();
31
- console.log(`Stash connected to ${redis.options.host}:${String(redis.options.port)}`);
32
- }
33
- async resolveURLs() {
34
- if (process.env.TOA_DEV === '1')
35
- return ['redis://localhost'];
36
- else
37
- return await (0, pointer_1.resolve)(extension_1.ID, this.locator.id);
38
- }
39
- }
40
- exports.Connection = Connection;
41
- //# sourceMappingURL=Connection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Connection.js","sourceRoot":"","sources":["../source/Connection.ts"],"names":[],"mappings":";;;AAAA,qCAAoD;AACpD,uCAAsD;AACtD,6CAAyC;AACzC,2CAAgC;AAEhC,MAAa,UAAW,SAAQ,gBAAS;IACvB,OAAO,GAAY,EAAE,CAAA;IACpB,OAAO,CAAS;IAEjC,YAAoB,OAAgB;QAClC,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAEkB,KAAK,CAAC,IAAI;QAC3B,MAAM,SAAS,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,CAAA;QACnE,MAAM,OAAO,GAAmB,EAAE,SAAS,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAA;QACxF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE,CAAA;QAErC,KAAK,MAAM,GAAG,IAAI,IAAI;YACpB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,eAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAA;QAE5C,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QAEhE,MAAM,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IAC/B,CAAC;IAEkB,KAAK,CAAC,KAAK;QAC5B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO;YAC9B,KAAK,CAAC,UAAU,EAAE,CAAA;QAEpB,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;IACnC,CAAC;IAEO,KAAK,CAAC,WAAW,CAAE,KAAY;QACrC,MAAM,KAAK,CAAC,OAAO,EAAE,CAAA;QAErB,OAAO,CAAC,GAAG,CAAC,sBAAsB,KAAK,CAAC,OAAO,CAAC,IAAc,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACjG,CAAC;IAEO,KAAK,CAAC,WAAW;QACvB,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,GAAG;YAAE,OAAO,CAAC,mBAAmB,CAAC,CAAA;;YACxD,OAAO,MAAM,IAAA,iBAAO,EAAC,cAAE,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAChD,CAAC;CACF;AAxCD,gCAwCC"}
@@ -1,9 +0,0 @@
1
- import { type URIMap } from '@toa.io/pointer';
2
- import type { Locator, extensions } from '@toa.io/core';
3
- import type { context } from '@toa.io/norm';
4
- import type { Dependency } from '@toa.io/operations';
5
- export declare class Factory implements extensions.Factory {
6
- aspect(locator: Locator): extensions.Aspect;
7
- }
8
- export declare function deployment(instances: context.Dependency[], annotation: URIMap): Dependency;
9
- export declare const ID = "stash";
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ID = exports.deployment = exports.Factory = void 0;
4
- const pointer_1 = require("@toa.io/pointer");
5
- const Aspect_1 = require("./Aspect");
6
- const Connection_1 = require("./Connection");
7
- class Factory {
8
- aspect(locator) {
9
- const connection = new Connection_1.Connection(locator);
10
- return new Aspect_1.Aspect(connection);
11
- }
12
- }
13
- exports.Factory = Factory;
14
- function deployment(instances, annotation) {
15
- const requests = instances.map((instance) => createRequest(instance));
16
- const variables = (0, pointer_1.createVariables)(exports.ID, annotation, requests);
17
- return { variables };
18
- }
19
- exports.deployment = deployment;
20
- function createRequest(instance) {
21
- return {
22
- group: instance.locator.label,
23
- selectors: [instance.locator.id]
24
- };
25
- }
26
- exports.ID = 'stash';
27
- //# sourceMappingURL=extension.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../source/extension.ts"],"names":[],"mappings":";;;AAAA,6CAA4E;AAC5E,qCAAiC;AACjC,6CAAyC;AAKzC,MAAa,OAAO;IACX,MAAM,CAAE,OAAgB;QAC7B,MAAM,UAAU,GAAG,IAAI,uBAAU,CAAC,OAAO,CAAC,CAAA;QAE1C,OAAO,IAAI,eAAM,CAAC,UAAU,CAAC,CAAA;IAC/B,CAAC;CACF;AAND,0BAMC;AAED,SAAgB,UAAU,CAAE,SAA+B,EAAE,UAAkB;IAC7E,MAAM,QAAQ,GAAc,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAA;IAChF,MAAM,SAAS,GAAG,IAAA,yBAAe,EAAC,UAAE,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAA;IAE3D,OAAO,EAAE,SAAS,EAAE,CAAA;AACtB,CAAC;AALD,gCAKC;AAED,SAAS,aAAa,CAAE,QAA4B;IAClD,OAAO;QACL,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,KAAK;QAC7B,SAAS,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;KACjC,CAAA;AACH,CAAC;AAEY,QAAA,EAAE,GAAG,OAAO,CAAA"}
@@ -1 +0,0 @@
1
- export * from './extension';
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./extension"), exports);
18
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B"}