@toa.io/extensions.stash 0.20.0-dev.28 → 0.20.0-dev.29

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.28",
3
+ "version": "0.20.0-dev.29",
4
4
  "description": "Toa Stash",
5
5
  "author": "temich <tema.gurtovoy@gmail.com>",
6
6
  "homepage": "https://github.com/toa-io/toa#readme",
@@ -29,5 +29,5 @@
29
29
  "preset": "ts-jest",
30
30
  "testEnvironment": "node"
31
31
  },
32
- "gitHead": "a88812012a431cef248b11ee9ce7e718004075c1"
32
+ "gitHead": "dfc890657c2bfca1aa837e481dd959db5d20c724"
33
33
  }
@@ -1,18 +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 redis;
6
- private readonly redlock;
7
- constructor(connection: Connection);
8
- invoke(method: 'store', key: string, value: object): Promise<void>;
9
- invoke(method: 'fetch', key: string): Promise<object>;
10
- invoke<T>(method: 'lock', key: Resources, routine: Routine<T>): Promise<T>;
11
- invoke(method: string, ...args: unknown[]): Promise<any>;
12
- private store;
13
- private fetch;
14
- private lock;
15
- }
16
- type Routine<T> = () => Promise<T>;
17
- type Resources = string | string[];
18
- export {};
@@ -1,4 +0,0 @@
1
- /// <reference types="jest" />
2
- export declare const Redlock: jest.Mock<{
3
- using: jest.Mock<Promise<undefined>, []>;
4
- }, []>;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Redlock = void 0;
4
- exports.Redlock = jest.fn(() => ({
5
- using: jest.fn(async () => undefined)
6
- }));
7
- //# sourceMappingURL=Aspect.fixtures.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Aspect.fixtures.js","sourceRoot":"","sources":["../source/Aspect.fixtures.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IACpC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,SAAS,CAAC;CACtC,CAAC,CAAC,CAAA"}
@@ -1,49 +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
- redis;
13
- redlock;
14
- constructor(connection) {
15
- super();
16
- this.redis = connection.redis;
17
- this.redlock = new redlock_temp_fix_1.default([this.redis], { retryCount: -1 });
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 store(key, value, ...args) {
33
- const buffer = (0, msgpackr_1.encode)(value);
34
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
35
- // @ts-expect-error
36
- await this.redis.set(key, buffer, ...args);
37
- }
38
- async fetch(key) {
39
- const buffer = await this.redis.getBuffer(key);
40
- return buffer === null ? null : (0, msgpackr_1.decode)(buffer);
41
- }
42
- async lock(key, routine) {
43
- if (typeof key === 'string')
44
- key = [key];
45
- return await this.redlock.using(key, 5000, routine);
46
- }
47
- }
48
- exports.Aspect = Aspect;
49
- //# sourceMappingURL=Asp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CAAE,GAAW,EAAE,KAAa,EAAE,GAAG,IAAe;QACjE,MAAM,MAAM,GAAG,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,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,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;AApDD,wBAoDC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,109 +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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const redlock_temp_fix_1 = __importDefault(require("redlock-temp-fix"));
30
- const msgpackr_1 = require("msgpackr");
31
- const randomstring_1 = require("randomstring");
32
- const Aspect_1 = require("./Aspect");
33
- const mock = __importStar(require("./Connection.fixtures"));
34
- jest.mock('redlock-temp-fix');
35
- let aspect;
36
- let connection;
37
- let redis;
38
- let redlock;
39
- const key = (0, randomstring_1.generate)();
40
- beforeEach(() => {
41
- jest.clearAllMocks();
42
- connection = new mock.Connection();
43
- redis = connection.redis;
44
- aspect = new Aspect_1.Aspect(connection);
45
- const m = redlock_temp_fix_1.default.mock;
46
- redlock = redlock_temp_fix_1.default.mock.instances[0];
47
- });
48
- it('should depend on Connection', async () => {
49
- expect(connection.link).toHaveBeenCalledWith(aspect);
50
- });
51
- it('should set', async () => {
52
- const value = (0, randomstring_1.generate)();
53
- await aspect.invoke('set', key, value);
54
- expect(redis.set).toHaveBeenCalledWith(key, value);
55
- });
56
- it('should get', async () => {
57
- const value = await aspect.invoke('get', key);
58
- expect(redis.get).toHaveBeenCalledWith(key);
59
- expect(value).toStrictEqual(await redis.get.mock.results[0].value);
60
- });
61
- describe('buffers', () => {
62
- it.each([
63
- ['object', { [(0, randomstring_1.generate)()]: (0, randomstring_1.generate)() }],
64
- ['array', [(0, randomstring_1.generate)(), (0, randomstring_1.generate)()]]
65
- ])('should encode %s', async (_, value) => {
66
- await aspect.invoke('store', key, value);
67
- const buffer = (0, msgpackr_1.encode)(value);
68
- expect(redis.set).toHaveBeenCalledWith(key, buffer);
69
- });
70
- it('should pass arguments', async () => {
71
- const value = [1, 2];
72
- const buffer = (0, msgpackr_1.encode)(value);
73
- await aspect.invoke('store', key, value, 'EX', 1000);
74
- expect(redis.set).toHaveBeenCalledWith(key, buffer, 'EX', 1000);
75
- });
76
- it.each([
77
- ['object', { [(0, randomstring_1.generate)()]: (0, randomstring_1.generate)() }],
78
- ['array', [(0, randomstring_1.generate)(), (0, randomstring_1.generate)()]]
79
- ])('should decode %s', async (_, value) => {
80
- const buffer = (0, msgpackr_1.encode)(value);
81
- redis.getBuffer.mockImplementationOnce(async () => buffer);
82
- const output = await aspect.invoke('fetch', key);
83
- expect(redis.getBuffer).toHaveBeenCalledWith(key);
84
- expect(output).toStrictEqual(value);
85
- });
86
- });
87
- it('should create DLM', async () => {
88
- expect(redlock_temp_fix_1.default).toHaveBeenCalledWith([redis], { retryCount: -1 });
89
- });
90
- it('should acquire lock', async () => {
91
- const keys = [(0, randomstring_1.generate)(), (0, randomstring_1.generate)()];
92
- const callback = jest.fn();
93
- await aspect.invoke('lock', keys, callback);
94
- expect(redlock.using).toHaveBeenCalledWith(keys, 5000, callback);
95
- });
96
- it('should return result', async () => {
97
- const keys = [(0, randomstring_1.generate)(), (0, randomstring_1.generate)()];
98
- const callback = jest.fn();
99
- redlock.using.mockImplementationOnce(async () => (0, randomstring_1.generate)());
100
- const result = await aspect.invoke('lock', keys, callback);
101
- expect(result).toStrictEqual(await redlock.using.mock.results[0].value);
102
- });
103
- it('should handle non-array key', async () => {
104
- const key = (0, randomstring_1.generate)();
105
- const callback = jest.fn();
106
- await aspect.invoke('lock', key, callback);
107
- expect(redlock.using).toHaveBeenCalledWith([key], 5000, callback);
108
- });
109
- //# sourceMappingURL=Aspect.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Aspect.test.js","sourceRoot":"","sources":["../source/Aspect.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wEAAsC;AACtC,uCAAiC;AACjC,+CAAuC;AACvC,q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AAoB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;AAClE,CAAC,CAAC,CAAA;AAEF,EAAE,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;IACpC,MAAM,IAAI,GAAG,CAAC,IAAA,uBAAQ,GAAE,EAAE,IAAA,uBAAQ,GAAE,CAAC,CAAA;IACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,EAAE,CAAA;IAE1B,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,KAAK,IAAI,EAAE,CAAC,IAAA,uBAAQ,GAAE,CAAC,CAAA;IAE5D,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;IAE1D,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;AACzE,CAAC,CAAC,CAAA;AAEF,EAAE,CAAC,6BAA6B,EAAE,KAAK,IAAI,EAAE;IAC3C,MAAM,GAAG,GAAG,IAAA,uBAAQ,GAAE,CAAA;IACtB,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,EAAE,CAAA;IAE1B,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAA;IAE1C,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;AACnE,CAAC,CAAC,CAAA"}
@@ -1,9 +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 redis: Redis;
5
- private readonly url;
6
- constructor(url: string, locator: Locator);
7
- protected open(): Promise<void>;
8
- protected close(): Promise<void>;
9
- }
@@ -1,10 +0,0 @@
1
- /// <reference types="jest" />
2
- import type * as redis from 'ioredis';
3
- export declare const Redis: jest.Mock<typeof redis.Cluster, any>;
4
- export declare const Connection: jest.Mock<{
5
- redis: typeof redis.Cluster;
6
- link: jest.Mock<any, any>;
7
- }, []>;
8
- export declare const ioredis: {
9
- Redis: jest.Mock<typeof redis.Cluster, any>;
10
- };
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ioredis = exports.Connection = exports.Redis = void 0;
4
- const randomstring_1 = require("randomstring");
5
- exports.Redis = jest.fn(() => ({
6
- connect: jest.fn(async () => undefined),
7
- disconnect: jest.fn(),
8
- get: jest.fn(async () => (0, randomstring_1.generate)()),
9
- getBuffer: jest.fn(async () => Buffer.from((0, randomstring_1.generate)())),
10
- set: jest.fn(async () => undefined),
11
- on: jest.fn()
12
- }));
13
- exports.Connection = jest.fn(() => ({
14
- redis: new exports.Redis(),
15
- link: jest.fn()
16
- }));
17
- exports.ioredis = { Redis: exports.Redis };
18
- //# sourceMappingURL=Connection.fixtures.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Connection.fixtures.js","sourceRoot":"","sources":["../source/Connection.fixtures.ts"],"names":[],"mappings":";;;AAAA,+CAAuC;AAG1B,QAAA,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IAClC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,SAAS,CAAC;IACvC,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;IACrB,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,IAAA,uBAAQ,GAAE,CAAC;IACpC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAA,uBAAQ,GAAE,CAAC,CAAC;IACvD,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,SAAS,CAAC;IACnC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE;CACd,CAAC,CAA+C,CAAA;AAEpC,QAAA,UAAU,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IACvC,KAAK,EAAE,IAAI,aAAK,EAAE;IAClB,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;CAChB,CAAC,CAAC,CAAA;AAEU,QAAA,OAAO,GAAG,EAAE,KAAK,EAAL,aAAK,EAAE,CAAA"}
@@ -1,26 +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
- class Connection extends core_1.Connector {
7
- redis;
8
- url;
9
- constructor(url, locator) {
10
- super();
11
- const keyPrefix = `${locator.namespace}:${locator.name}:`;
12
- const options = { keyPrefix, enableReadyCheck: true, lazyConnect: true };
13
- this.redis = new ioredis_1.Redis(url, options);
14
- this.url = url;
15
- }
16
- async open() {
17
- await this.redis.connect();
18
- console.log('Stash connected to ' + this.url);
19
- }
20
- async close() {
21
- this.redis.disconnect();
22
- console.log('Stash disconnected from ' + this.url);
23
- }
24
- }
25
- exports.Connection = Connection;
26
- //# sourceMappingURL=Connection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Connection.js","sourceRoot":"","sources":["../source/Connection.ts"],"names":[],"mappings":";;;AAAA,qCAAoD;AACpD,uCAAsD;AAEtD,MAAa,UAAW,SAAQ,gBAAS;IACvB,KAAK,CAAO;IACX,GAAG,CAAQ;IAE5B,YAAoB,GAAW,EAAE,OAAgB;QAC/C,KAAK,EAAE,CAAA;QAEP,MAAM,SAAS,GAAG,GAAG,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,IAAI,GAAG,CAAA;QACzD,MAAM,OAAO,GAAmB,EAAE,SAAS,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAA;QAExF,IAAI,CAAC,KAAK,GAAG,IAAI,eAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QACpC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAEkB,KAAK,CAAC,IAAI;QAC3B,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAA;QAE1B,OAAO,CAAC,GAAG,CAAC,qBAAqB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAA;IAC/C,CAAC;IAEkB,KAAK,CAAC,KAAK;QAC5B,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAA;QAEvB,OAAO,CAAC,GAAG,CAAC,0BAA0B,GAAG,IAAI,CAAC,GAAG,CAAC,CAAA;IACpD,CAAC;CACF;AAzBD,gCAyBC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const randomstring_1 = require("randomstring");
4
- const Connection_1 = require("./Connection");
5
- const core_1 = require("@toa.io/core");
6
- const Connection_fixtures_1 = require("./Connection.fixtures");
7
- jest.mock('ioredis', () => ({
8
- Redis: jest.fn((nodes, options) => new Connection_fixtures_1.Redis(nodes, options))
9
- }));
10
- let connection;
11
- let cluster;
12
- const url = (0, randomstring_1.generate)();
13
- const locator = {
14
- namespace: (0, randomstring_1.generate)(),
15
- name: (0, randomstring_1.generate)()
16
- };
17
- beforeEach(() => {
18
- jest.clearAllMocks();
19
- connection = new Connection_1.Connection(url, locator);
20
- cluster = Connection_fixtures_1.Redis.mock.results[0].value;
21
- });
22
- it('should be instance of Connector', async () => {
23
- expect(connection).toBeInstanceOf(core_1.Connector);
24
- });
25
- it('should connect', async () => {
26
- const keyPrefix = `${locator.namespace}:${locator.name}:`;
27
- const options = { keyPrefix, enableReadyCheck: true, lazyConnect: true };
28
- expect(Connection_fixtures_1.Redis).toHaveBeenCalledWith(url, options);
29
- await connection.connect();
30
- expect(cluster.connect).toHaveBeenCalled();
31
- });
32
- it('should disconnect', async () => {
33
- await connection.disconnect();
34
- expect(cluster.disconnect).toHaveBeenCalled();
35
- });
36
- it('should expose cluster', async () => {
37
- expect(connection.redis).toStrictEqual(cluster);
38
- });
39
- //# sourceMappingURL=Connection.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Connection.test.js","sourceRoot":"","sources":["../source/Connection.test.ts"],"names":[],"mappings":";;AAAA,+CAAuC;AACvC,6CAAyC;AACzC,uCAAsD;AACtD,+DAA6C;AAG7C,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1B,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,KAAe,EAAE,OAA6B,EAAE,EAAE,CAAC,IAAI,2BAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;CAC9F,CAAC,CAAC,CAAA;AAEH,IAAI,UAAsB,CAAA;AAC1B,IAAI,OAAyC,CAAA;AAE7C,MAAM,GAAG,GAAG,IAAA,uBAAQ,GAAE,CAAA;AAEtB,MAAM,OAAO,GAAG;IACd,SAAS,EAAE,IAAA,uBAAQ,GAAE;IACrB,IAAI,EAAE,IAAA,uBAAQ,GAAE;CACK,CAAA;AAEvB,UAAU,CAAC,GAAG,EAAE;IACd,IAAI,CAAC,aAAa,EAAE,CAAA;IAEpB,UAAU,GAAG,IAAI,uBAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACzC,OAAO,GAAG,2BAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;AACvC,CAAC,CAAC,CAAA;AAEF,EAAE,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;IAC/C,MAAM,CAAC,UAAU,CAAC,CAAC,cAAc,CAAC,gBAAS,CAAC,CAAA;AAC9C,CAAC,CAAC,CAAA;AAEF,EAAE,CAAC,gBAAgB,EAAE,KAAK,IAAI,EAAE;IAC9B,MAAM,SAAS,GAAG,GAAG,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,IAAI,GAAG,CAAA;IACzD,MAAM,OAAO,GAAyB,EAAE,SAAS,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAA;IAE9F,MAAM,CAAC,2BAAK,CAAC,CAAC,oBAAoB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAEhD,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;IAE1B,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,gBAAgB,EAAE,CAAA;AAC5C,CAAC,CAAC,CAAA;AAEF,EAAE,CAAC,mBAAmB,EAAE,KAAK,IAAI,EAAE;IACjC,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;IAE7B,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,gBAAgB,EAAE,CAAA;AAC/C,CAAC,CAAC,CAAA;AAEF,EAAE,CAAC,uBAAuB,EAAE,KAAK,IAAI,EAAE;IACrC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;AACjD,CAAC,CAAC,CAAA"}
@@ -1,12 +0,0 @@
1
- import { uris } from '@toa.io/pointer';
2
- import type { Locator, extensions } from '@toa.io/core';
3
- import type { context } from '@toa.io/norm';
4
- import type * as operations from '@toa.io/operations';
5
- export declare class Factory implements extensions.Factory {
6
- aspect(locator: Locator): extensions.Aspect;
7
- private url;
8
- }
9
- export declare function deployment(instances: context.Dependency[], annotation: Annotation): Dependency;
10
- type Dependency = operations.deployment.Dependency;
11
- type Annotation = uris.URIs | string;
12
- export {};
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- 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 url = this.url();
10
- const connection = new Connection_1.Connection(url, locator);
11
- return new Aspect_1.Aspect(connection);
12
- }
13
- url() {
14
- if (process.env.TOA_DEV === '1')
15
- return 'redis://localhost';
16
- const url = process.env[URL_VARIABLE];
17
- if (url === undefined)
18
- throw new Error(`${URL_VARIABLE} is not set`);
19
- return url;
20
- }
21
- }
22
- exports.Factory = Factory;
23
- function deployment(instances, annotation) {
24
- const pointer = pointer_1.uris.construct(annotation);
25
- const variables = {};
26
- for (const instance of instances) {
27
- const resolution = pointer_1.uris.resolve(instance.locator, pointer);
28
- const variable = { name: URL_VARIABLE, value: resolution.url.href };
29
- variables[instance.locator.label] = [variable];
30
- }
31
- return { variables };
32
- }
33
- exports.deployment = deployment;
34
- const URL_VARIABLE = 'TOA_STASH';
35
- //# sourceMappingURL=extension.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../source/extension.ts"],"names":[],"mappings":";;;AAAA,6CAAsC;AACtC,qCAAiC;AACjC,6CAAyC;AAKzC,MAAa,OAAO;IACX,MAAM,CAAE,OAAgB;QAC7B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,MAAM,UAAU,GAAG,IAAI,uBAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAE/C,OAAO,IAAI,eAAM,CAAC,UAAU,CAAC,CAAA;IAC/B,CAAC;IAEO,GAAG;QACT,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,GAAG;YAAE,OAAO,mBAAmB,CAAA;QAE3D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QAErC,IAAI,GAAG,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,GAAG,YAAY,aAAa,CAAC,CAAA;QAEpE,OAAO,GAAG,CAAA;IACZ,CAAC;CACF;AAjBD,0BAiBC;AAED,SAAgB,UAAU,CAAE,SAA+B,EAAE,UAAsB;IACjF,MAAM,OAAO,GAAG,cAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;IAC1C,MAAM,SAAS,GAAc,EAAE,CAAA;IAE/B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;QAChC,MAAM,UAAU,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAC1D,MAAM,QAAQ,GAAa,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;QAE7E,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;KAC/C;IAED,OAAO,EAAE,SAAS,EAAE,CAAA;AACtB,CAAC;AAZD,gCAYC;AAED,MAAM,YAAY,GAAG,WAAW,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"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ioredis_1 = require("ioredis");
4
- const url = 'redis://localhost';
5
- const options = { keyPrefix: 'test', enableReadyCheck: true, lazyConnect: true };
6
- const redis = new ioredis_1.Redis(url, options);
7
- it('should get/set', async () => {
8
- await redis.set('foo', 'bar');
9
- const bar = await redis.get('foo');
10
- expect(bar).toStrictEqual('bar');
11
- });
12
- //# sourceMappingURL=redis.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"redis.test.js","sourceRoot":"","sources":["../source/redis.test.ts"],"names":[],"mappings":";;AAAA,qCAA+C;AAE/C,MAAM,GAAG,GAAG,mBAAmB,CAAA;AAC/B,MAAM,OAAO,GAAmB,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAA;AAChG,MAAM,KAAK,GAAG,IAAI,eAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AAErC,EAAE,CAAC,gBAAgB,EAAE,KAAK,IAAI,EAAE;IAC9B,MAAM,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IAC7B,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAElC,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;AAClC,CAAC,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":"4.9.5"}