@tramvai/module-common 3.7.0 → 3.9.0
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/__migrations__/1-als-rename-module.js +32 -0
- package/lib/CommonModule.browser.js +2 -0
- package/lib/CommonModule.es.js +2 -0
- package/lib/CommonModule.js +2 -0
- package/lib/async-local-storage/browser.browser.js +12 -0
- package/lib/async-local-storage/browser.d.ts +3 -0
- package/lib/async-local-storage/server.d.ts +3 -0
- package/lib/async-local-storage/server.es.js +38 -0
- package/lib/async-local-storage/server.js +40 -0
- package/lib/cache/cacheFactory.es.js +13 -0
- package/lib/cache/cacheFactory.js +13 -0
- package/lib/index.browser.js +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.es.js +1 -0
- package/lib/index.js +5 -0
- package/lib/providers/clientProviders.browser.js +30 -1
- package/package.json +20 -19
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
var dependency = require('@tramvai/tools-migrate/lib/dependency');
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line import/no-default-export
|
|
7
|
+
var _1AlsRenameModule = (function (api) { return tslib.__awaiter(void 0, void 0, void 0, function () {
|
|
8
|
+
var packageJSON;
|
|
9
|
+
return tslib.__generator(this, function (_a) {
|
|
10
|
+
switch (_a.label) {
|
|
11
|
+
case 0: return [4 /*yield*/, api.transform(function (_a, _b, _c) {
|
|
12
|
+
var source = _a.source;
|
|
13
|
+
var j = _b.j;
|
|
14
|
+
var printOptions = _c.printOptions;
|
|
15
|
+
var parsed = j(source);
|
|
16
|
+
if (parsed.renameImportSource('@tramvai-tinkoff/module-async-local-storage', '@tramvai/module-common')) {
|
|
17
|
+
return parsed.toSource(printOptions);
|
|
18
|
+
}
|
|
19
|
+
})];
|
|
20
|
+
case 1:
|
|
21
|
+
_a.sent();
|
|
22
|
+
packageJSON = api.packageJSON.source;
|
|
23
|
+
dependency.replaceDependency({
|
|
24
|
+
packageJSON: packageJSON,
|
|
25
|
+
from: '@tramvai-tinkoff/module-async-local-storage',
|
|
26
|
+
});
|
|
27
|
+
return [2 /*return*/];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}); });
|
|
31
|
+
|
|
32
|
+
module.exports = _1AlsRenameModule;
|
|
@@ -13,6 +13,7 @@ import { ResponseManagerModule } from './responseManager/ResponseManagerModule.b
|
|
|
13
13
|
import { createConsumerContext } from './createConsumerContext/createConsumerContext.browser.js';
|
|
14
14
|
import { CommandModule } from './command/CommandModule.browser.js';
|
|
15
15
|
import { PubSubModule } from './pubsub/PubSubModule.browser.js';
|
|
16
|
+
import { AsyncLocalStorageModule } from './async-local-storage/browser.browser.js';
|
|
16
17
|
import { providers } from './providers/clientProviders.browser.js';
|
|
17
18
|
import { ActionModule } from './actions/ActionModule.browser.js';
|
|
18
19
|
import { StateModule } from './state/StateModule.browser.js';
|
|
@@ -34,6 +35,7 @@ CommonModule = __decorate([
|
|
|
34
35
|
RequestManagerModule,
|
|
35
36
|
ResponseManagerModule,
|
|
36
37
|
CacheModule,
|
|
38
|
+
AsyncLocalStorageModule,
|
|
37
39
|
],
|
|
38
40
|
providers: [
|
|
39
41
|
provide({
|
package/lib/CommonModule.es.js
CHANGED
|
@@ -13,6 +13,7 @@ import { ResponseManagerModule } from './responseManager/ResponseManagerModule.e
|
|
|
13
13
|
import { createConsumerContext } from './createConsumerContext/createConsumerContext.es.js';
|
|
14
14
|
import { CommandModule } from './command/CommandModule.es.js';
|
|
15
15
|
import { PubSubModule } from './pubsub/PubSubModule.es.js';
|
|
16
|
+
import { AsyncLocalStorageModule } from './async-local-storage/server.es.js';
|
|
16
17
|
import { providers } from './providers/serverProviders.es.js';
|
|
17
18
|
import { ActionModule } from './actions/ActionModule.es.js';
|
|
18
19
|
import { StateModule } from './state/StateModule.es.js';
|
|
@@ -34,6 +35,7 @@ CommonModule = __decorate([
|
|
|
34
35
|
RequestManagerModule,
|
|
35
36
|
ResponseManagerModule,
|
|
36
37
|
CacheModule,
|
|
38
|
+
AsyncLocalStorageModule,
|
|
37
39
|
],
|
|
38
40
|
providers: [
|
|
39
41
|
provide({
|
package/lib/CommonModule.js
CHANGED
|
@@ -17,6 +17,7 @@ var ResponseManagerModule = require('./responseManager/ResponseManagerModule.js'
|
|
|
17
17
|
var createConsumerContext = require('./createConsumerContext/createConsumerContext.js');
|
|
18
18
|
var CommandModule = require('./command/CommandModule.js');
|
|
19
19
|
var PubSubModule = require('./pubsub/PubSubModule.js');
|
|
20
|
+
var server = require('./async-local-storage/server.js');
|
|
20
21
|
var serverProviders = require('./providers/serverProviders.js');
|
|
21
22
|
var ActionModule = require('./actions/ActionModule.js');
|
|
22
23
|
var StateModule = require('./state/StateModule.js');
|
|
@@ -42,6 +43,7 @@ exports.CommonModule = tslib.__decorate([
|
|
|
42
43
|
RequestManagerModule.RequestManagerModule,
|
|
43
44
|
ResponseManagerModule.ResponseManagerModule,
|
|
44
45
|
CacheModule.CacheModule,
|
|
46
|
+
server.AsyncLocalStorageModule,
|
|
45
47
|
],
|
|
46
48
|
providers: [
|
|
47
49
|
core.provide({
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { Module } from '@tramvai/core';
|
|
3
|
+
|
|
4
|
+
let AsyncLocalStorageModule = class AsyncLocalStorageModule {
|
|
5
|
+
};
|
|
6
|
+
AsyncLocalStorageModule = __decorate([
|
|
7
|
+
Module({
|
|
8
|
+
providers: [],
|
|
9
|
+
})
|
|
10
|
+
], AsyncLocalStorageModule);
|
|
11
|
+
|
|
12
|
+
export { AsyncLocalStorageModule };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
|
+
import { Module, provide, Scope } from '@tramvai/core';
|
|
4
|
+
import { WEB_FASTIFY_APP_INIT_TOKEN, WEB_FASTIFY_APP_TOKEN } from '@tramvai/tokens-server-private';
|
|
5
|
+
import { ASYNC_LOCAL_STORAGE_TOKEN } from '@tramvai/tokens-common';
|
|
6
|
+
|
|
7
|
+
let AsyncLocalStorageModule = class AsyncLocalStorageModule {
|
|
8
|
+
};
|
|
9
|
+
AsyncLocalStorageModule = __decorate([
|
|
10
|
+
Module({
|
|
11
|
+
imports: [],
|
|
12
|
+
providers: [
|
|
13
|
+
provide({
|
|
14
|
+
provide: ASYNC_LOCAL_STORAGE_TOKEN,
|
|
15
|
+
scope: Scope.SINGLETON,
|
|
16
|
+
useFactory: () => new AsyncLocalStorage(),
|
|
17
|
+
}),
|
|
18
|
+
provide({
|
|
19
|
+
provide: WEB_FASTIFY_APP_INIT_TOKEN,
|
|
20
|
+
multi: true,
|
|
21
|
+
scope: Scope.REQUEST,
|
|
22
|
+
useFactory: ({ app, storage }) => {
|
|
23
|
+
return () => {
|
|
24
|
+
app.addHook('onRequest', (req, reply, done) => {
|
|
25
|
+
storage.run({}, done);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
deps: {
|
|
30
|
+
app: WEB_FASTIFY_APP_TOKEN,
|
|
31
|
+
storage: ASYNC_LOCAL_STORAGE_TOKEN,
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
],
|
|
35
|
+
})
|
|
36
|
+
], AsyncLocalStorageModule);
|
|
37
|
+
|
|
38
|
+
export { AsyncLocalStorageModule };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var async_hooks = require('async_hooks');
|
|
7
|
+
var core = require('@tramvai/core');
|
|
8
|
+
var tokensServerPrivate = require('@tramvai/tokens-server-private');
|
|
9
|
+
var tokensCommon = require('@tramvai/tokens-common');
|
|
10
|
+
|
|
11
|
+
exports.AsyncLocalStorageModule = class AsyncLocalStorageModule {
|
|
12
|
+
};
|
|
13
|
+
exports.AsyncLocalStorageModule = tslib.__decorate([
|
|
14
|
+
core.Module({
|
|
15
|
+
imports: [],
|
|
16
|
+
providers: [
|
|
17
|
+
core.provide({
|
|
18
|
+
provide: tokensCommon.ASYNC_LOCAL_STORAGE_TOKEN,
|
|
19
|
+
scope: core.Scope.SINGLETON,
|
|
20
|
+
useFactory: () => new async_hooks.AsyncLocalStorage(),
|
|
21
|
+
}),
|
|
22
|
+
core.provide({
|
|
23
|
+
provide: tokensServerPrivate.WEB_FASTIFY_APP_INIT_TOKEN,
|
|
24
|
+
multi: true,
|
|
25
|
+
scope: core.Scope.REQUEST,
|
|
26
|
+
useFactory: ({ app, storage }) => {
|
|
27
|
+
return () => {
|
|
28
|
+
app.addHook('onRequest', (req, reply, done) => {
|
|
29
|
+
storage.run({}, done);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
deps: {
|
|
34
|
+
app: tokensServerPrivate.WEB_FASTIFY_APP_TOKEN,
|
|
35
|
+
storage: tokensCommon.ASYNC_LOCAL_STORAGE_TOKEN,
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
39
|
+
})
|
|
40
|
+
], exports.AsyncLocalStorageModule);
|
|
@@ -2,9 +2,22 @@ import LRU from '@tinkoff/lru-cache-nano';
|
|
|
2
2
|
import LFU from '@akashbabu/lfu-cache';
|
|
3
3
|
|
|
4
4
|
class LFUToCacheAdapter extends LFU {
|
|
5
|
+
set(key, value, options) {
|
|
6
|
+
return this.set(key, value);
|
|
7
|
+
}
|
|
5
8
|
has(key) {
|
|
6
9
|
return typeof this.get(key) !== 'undefined';
|
|
7
10
|
}
|
|
11
|
+
dump() {
|
|
12
|
+
const arr = [];
|
|
13
|
+
this.forEach(([key, value]) => arr.push([key, { value }]));
|
|
14
|
+
return arr;
|
|
15
|
+
}
|
|
16
|
+
load(arr) {
|
|
17
|
+
arr.forEach(([key, { value }]) => {
|
|
18
|
+
this.set(key, value);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
8
21
|
}
|
|
9
22
|
const cacheFactory = (type, options = { max: 100 }) => {
|
|
10
23
|
if (type === 'memory-lfu') {
|
|
@@ -11,9 +11,22 @@ var LRU__default = /*#__PURE__*/_interopDefaultLegacy(LRU);
|
|
|
11
11
|
var LFU__default = /*#__PURE__*/_interopDefaultLegacy(LFU);
|
|
12
12
|
|
|
13
13
|
class LFUToCacheAdapter extends LFU__default["default"] {
|
|
14
|
+
set(key, value, options) {
|
|
15
|
+
return this.set(key, value);
|
|
16
|
+
}
|
|
14
17
|
has(key) {
|
|
15
18
|
return typeof this.get(key) !== 'undefined';
|
|
16
19
|
}
|
|
20
|
+
dump() {
|
|
21
|
+
const arr = [];
|
|
22
|
+
this.forEach(([key, value]) => arr.push([key, { value }]));
|
|
23
|
+
return arr;
|
|
24
|
+
}
|
|
25
|
+
load(arr) {
|
|
26
|
+
arr.forEach(([key, { value }]) => {
|
|
27
|
+
this.set(key, value);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
17
30
|
}
|
|
18
31
|
const cacheFactory = (type, options = { max: 100 }) => {
|
|
19
32
|
if (type === 'memory-lfu') {
|
package/lib/index.browser.js
CHANGED
|
@@ -7,6 +7,7 @@ export { ExecutionContextManager } from './executionContext/executionContextMana
|
|
|
7
7
|
import './actions/ActionModule.browser.js';
|
|
8
8
|
export { createConsumerContext } from './createConsumerContext/createConsumerContext.browser.js';
|
|
9
9
|
export { CommonChildAppModule } from './child-app/ChildAppModule.browser.js';
|
|
10
|
+
export { AsyncLocalStorageModule } from './async-local-storage/browser.browser.js';
|
|
10
11
|
export * from '@tramvai/tokens-common';
|
|
11
12
|
export { COOKIE_MANAGER_TOKEN } from '@tramvai/module-cookie';
|
|
12
13
|
export { alwaysCondition } from './actions/conditions/always.browser.js';
|
package/lib/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { ExecutionContextManager } from './executionContext/executionContextMana
|
|
|
7
7
|
export { alwaysCondition, onlyServer, onlyBrowser, pageServer, pageBrowser, } from './actions/ActionModule';
|
|
8
8
|
export { createConsumerContext } from './createConsumerContext/createConsumerContext';
|
|
9
9
|
export { CommonChildAppModule } from './child-app/ChildAppModule';
|
|
10
|
+
export { AsyncLocalStorageModule } from './async-local-storage/server';
|
|
10
11
|
export * from '@tramvai/tokens-common';
|
|
11
12
|
export { COOKIE_MANAGER_TOKEN } from '@tramvai/module-cookie';
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.es.js
CHANGED
|
@@ -7,6 +7,7 @@ export { ExecutionContextManager } from './executionContext/executionContextMana
|
|
|
7
7
|
import './actions/ActionModule.es.js';
|
|
8
8
|
export { createConsumerContext } from './createConsumerContext/createConsumerContext.es.js';
|
|
9
9
|
export { CommonChildAppModule } from './child-app/ChildAppModule.es.js';
|
|
10
|
+
export { AsyncLocalStorageModule } from './async-local-storage/server.es.js';
|
|
10
11
|
export * from '@tramvai/tokens-common';
|
|
11
12
|
export { COOKIE_MANAGER_TOKEN } from '@tramvai/module-cookie';
|
|
12
13
|
export { alwaysCondition } from './actions/conditions/always.es.js';
|
package/lib/index.js
CHANGED
|
@@ -11,6 +11,7 @@ var executionContextManager = require('./executionContext/executionContextManage
|
|
|
11
11
|
require('./actions/ActionModule.js');
|
|
12
12
|
var createConsumerContext = require('./createConsumerContext/createConsumerContext.js');
|
|
13
13
|
var ChildAppModule = require('./child-app/ChildAppModule.js');
|
|
14
|
+
var server = require('./async-local-storage/server.js');
|
|
14
15
|
var tokensCommon = require('@tramvai/tokens-common');
|
|
15
16
|
var moduleCookie = require('@tramvai/module-cookie');
|
|
16
17
|
var always = require('./actions/conditions/always.js');
|
|
@@ -38,6 +39,10 @@ Object.defineProperty(exports, 'CommonChildAppModule', {
|
|
|
38
39
|
enumerable: true,
|
|
39
40
|
get: function () { return ChildAppModule.CommonChildAppModule; }
|
|
40
41
|
});
|
|
42
|
+
Object.defineProperty(exports, 'AsyncLocalStorageModule', {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () { return server.AsyncLocalStorageModule; }
|
|
45
|
+
});
|
|
41
46
|
Object.defineProperty(exports, 'COOKIE_MANAGER_TOKEN', {
|
|
42
47
|
enumerable: true,
|
|
43
48
|
get: function () { return moduleCookie.COOKIE_MANAGER_TOKEN; }
|
|
@@ -4,8 +4,37 @@ import { INITIAL_APP_STATE_TOKEN } from '@tramvai/tokens-common';
|
|
|
4
4
|
const providers = [
|
|
5
5
|
provide({
|
|
6
6
|
provide: INITIAL_APP_STATE_TOKEN,
|
|
7
|
-
useFactory: () => { var _a, _b; return JSON.parse((_b = (_a = document.getElementById('__TRAMVAI_STATE__')) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : '{}'); },
|
|
8
7
|
scope: Scope.REQUEST,
|
|
8
|
+
useFactory: () => {
|
|
9
|
+
var _a;
|
|
10
|
+
let initialState;
|
|
11
|
+
try {
|
|
12
|
+
initialState = (_a = document.getElementById('__TRAMVAI_STATE__')) === null || _a === void 0 ? void 0 : _a.textContent;
|
|
13
|
+
if (!initialState) {
|
|
14
|
+
throw Error('__TRAMVAI_STATE__ element is empty or missing');
|
|
15
|
+
}
|
|
16
|
+
return JSON.parse(initialState);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
if (window.logger) {
|
|
20
|
+
const log = window.logger('tramvai-state');
|
|
21
|
+
log.error({
|
|
22
|
+
event: 'initial-state-parse-error',
|
|
23
|
+
error: e,
|
|
24
|
+
initialState,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
// if logger is not ready, we still can log this error in inline scripts with error interceptors.
|
|
29
|
+
// force unhandled promise reject, because we don't need to break application here with sync error.
|
|
30
|
+
// eslint-disable-next-line promise/catch-or-return
|
|
31
|
+
Promise.resolve().then(() => {
|
|
32
|
+
throw Object.assign(e, { initialState, event: 'initial-state-parse-error' });
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
},
|
|
9
38
|
}),
|
|
10
39
|
provide({
|
|
11
40
|
provide: commandLineListTokens.listen,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-common",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"./lib/providers/serverProviders.js": "./lib/providers/clientProviders.js",
|
|
18
18
|
"./lib/child-app/serverProviders.js": "./lib/child-app/clientProviders.js",
|
|
19
19
|
"./lib/requestManager/RequestManagerModule.js": "./lib/requestManager/RequestManagerModule.browser.js",
|
|
20
|
-
"./lib/responseManager/ResponseManagerModule.js": "./lib/responseManager/ResponseManagerModule.browser.js"
|
|
20
|
+
"./lib/responseManager/ResponseManagerModule.js": "./lib/responseManager/ResponseManagerModule.browser.js",
|
|
21
|
+
"./lib/async-local-storage/server.js": "./lib/async-local-storage/browser.js"
|
|
21
22
|
},
|
|
22
23
|
"sideEffects": false,
|
|
23
24
|
"repository": {
|
|
@@ -31,33 +32,33 @@
|
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"@tinkoff/errors": "0.4.1",
|
|
33
34
|
"@tinkoff/hook-runner": "0.5.1",
|
|
34
|
-
"@tinkoff/lru-cache-nano": "^7.
|
|
35
|
+
"@tinkoff/lru-cache-nano": "^7.9.0",
|
|
35
36
|
"@akashbabu/lfu-cache": "1.0.2",
|
|
36
37
|
"@tinkoff/pubsub": "0.6.1",
|
|
37
38
|
"@tinkoff/url": "0.9.1",
|
|
38
39
|
"@tramvai/safe-strings": "0.6.1",
|
|
39
|
-
"@tramvai/experiments": "3.
|
|
40
|
-
"@tramvai/module-cookie": "3.
|
|
41
|
-
"@tramvai/module-environment": "3.
|
|
42
|
-
"@tramvai/module-log": "3.
|
|
43
|
-
"@tramvai/tokens-child-app": "3.
|
|
44
|
-
"@tramvai/tokens-core-private": "3.
|
|
45
|
-
"@tramvai/tokens-common": "3.
|
|
46
|
-
"@tramvai/tokens-render": "3.
|
|
47
|
-
"@tramvai/tokens-server-private": "3.
|
|
48
|
-
"@tramvai/types-actions-state-context": "3.
|
|
40
|
+
"@tramvai/experiments": "3.9.0",
|
|
41
|
+
"@tramvai/module-cookie": "3.9.0",
|
|
42
|
+
"@tramvai/module-environment": "3.9.0",
|
|
43
|
+
"@tramvai/module-log": "3.9.0",
|
|
44
|
+
"@tramvai/tokens-child-app": "3.9.0",
|
|
45
|
+
"@tramvai/tokens-core-private": "3.9.0",
|
|
46
|
+
"@tramvai/tokens-common": "3.9.0",
|
|
47
|
+
"@tramvai/tokens-render": "3.9.0",
|
|
48
|
+
"@tramvai/tokens-server-private": "3.9.0",
|
|
49
|
+
"@tramvai/types-actions-state-context": "3.9.0",
|
|
49
50
|
"hoist-non-react-statics": "^3.3.1",
|
|
50
51
|
"node-abort-controller": "^3.0.1"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
53
54
|
"@tinkoff/dippy": "0.9.1",
|
|
54
55
|
"@tinkoff/utils": "^2.1.2",
|
|
55
|
-
"@tramvai/cli": "3.
|
|
56
|
-
"@tramvai/core": "3.
|
|
57
|
-
"@tramvai/papi": "3.
|
|
58
|
-
"@tramvai/react": "3.
|
|
59
|
-
"@tramvai/state": "3.
|
|
60
|
-
"@tramvai/tokens-server": "3.
|
|
56
|
+
"@tramvai/cli": "3.9.0",
|
|
57
|
+
"@tramvai/core": "3.9.0",
|
|
58
|
+
"@tramvai/papi": "3.9.0",
|
|
59
|
+
"@tramvai/react": "3.9.0",
|
|
60
|
+
"@tramvai/state": "3.9.0",
|
|
61
|
+
"@tramvai/tokens-server": "3.9.0",
|
|
61
62
|
"react": ">=16.14.0",
|
|
62
63
|
"tslib": "^2.4.0"
|
|
63
64
|
},
|