@teambit/cache 0.0.931 → 0.0.933
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/cache.aspect.ts +7 -0
- package/cache.main.runtime.ts +66 -0
- package/cache.spec.ts +32 -0
- package/dist/cache.composition.d.ts +2 -2
- package/dist/cache.main.runtime.d.ts +1 -1
- package/dist/cache.main.runtime.js +2 -2
- package/dist/cache.main.runtime.js.map +1 -1
- package/dist/{preview-1703387662836.js → preview-1703647408454.js} +2 -2
- package/index.ts +2 -0
- package/package.json +13 -20
- package/tsconfig.json +16 -21
- package/types/asset.d.ts +15 -3
package/cache.aspect.ts
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
import { MainRuntime } from '@teambit/cli';
|
2
|
+
import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
|
3
|
+
import { CACHE_ROOT } from '@teambit/legacy/dist/constants';
|
4
|
+
import cacache from 'cacache';
|
5
|
+
|
6
|
+
import { CacheAspect } from './cache.aspect';
|
7
|
+
|
8
|
+
export type CacheConfig = {
|
9
|
+
cacheDirectory: string;
|
10
|
+
};
|
11
|
+
|
12
|
+
export class CacheMain {
|
13
|
+
static runtime = MainRuntime;
|
14
|
+
|
15
|
+
constructor(
|
16
|
+
/**
|
17
|
+
* extension config
|
18
|
+
*/
|
19
|
+
readonly config: CacheConfig,
|
20
|
+
|
21
|
+
/**
|
22
|
+
* logger extension.
|
23
|
+
*/
|
24
|
+
private readonly logger: Logger
|
25
|
+
) {}
|
26
|
+
|
27
|
+
static dependencies = [LoggerAspect];
|
28
|
+
|
29
|
+
static defaultConfig = {
|
30
|
+
cacheDirectory: CACHE_ROOT,
|
31
|
+
};
|
32
|
+
|
33
|
+
async set(key: string, data: any, ttl?: number): Promise<boolean> {
|
34
|
+
this.logger.debug(`put cache to ${key} with data ${data}`);
|
35
|
+
const expire = ttl ? new Date().getTime() + ttl : null;
|
36
|
+
return cacache
|
37
|
+
.put(this.globalCacheFolder, key, JSON.stringify({ data, expire }))
|
38
|
+
.then(() => true)
|
39
|
+
.catch(() => false);
|
40
|
+
}
|
41
|
+
|
42
|
+
async get<T>(key: string): Promise<T | undefined> {
|
43
|
+
this.logger.debug(`get cache for ${key}`);
|
44
|
+
return cacache
|
45
|
+
.get(this.globalCacheFolder, key)
|
46
|
+
.then(async (cacheObject) => {
|
47
|
+
const { data, expire } = JSON.parse(cacheObject.data.toString());
|
48
|
+
if (expire && new Date().getTime() > expire) {
|
49
|
+
return cacache.rm(this.globalCacheFolder, key);
|
50
|
+
}
|
51
|
+
return data;
|
52
|
+
})
|
53
|
+
.catch(() => undefined);
|
54
|
+
}
|
55
|
+
|
56
|
+
private get globalCacheFolder() {
|
57
|
+
return this.config.cacheDirectory;
|
58
|
+
}
|
59
|
+
|
60
|
+
static async provider([loggerFactory]: [LoggerMain], config: CacheConfig) {
|
61
|
+
const logger = loggerFactory.createLogger(CacheAspect.id);
|
62
|
+
return new CacheMain(config, logger);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
CacheAspect.addRuntime(CacheMain);
|
package/cache.spec.ts
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
import { v4 } from 'uuid';
|
2
|
+
import { rmdirSync } from 'fs';
|
3
|
+
import { expect } from 'chai';
|
4
|
+
import { Logger } from '@teambit/logger';
|
5
|
+
import { CacheMain } from './cache.main.runtime';
|
6
|
+
|
7
|
+
describe('Cache Aspect', () => {
|
8
|
+
const cacheDirectory = `/tmp/bit/${v4()}`;
|
9
|
+
const cache = new CacheMain({ cacheDirectory }, new Logger('cache.main.runtime'));
|
10
|
+
it('it should set cache with ttl', async () => {
|
11
|
+
await cache.set('_foo', 'bar', 1000);
|
12
|
+
const data = await cache.get('_foo');
|
13
|
+
expect(data).to.equal('bar');
|
14
|
+
});
|
15
|
+
|
16
|
+
// this test is flaky, it fails often on CircleCI.
|
17
|
+
// it('it should expire cache', async () => {
|
18
|
+
// await cache.set('_foo', 'bar', 1);
|
19
|
+
// const data = await cache.get('_foo');
|
20
|
+
// expect(data).to.equal(null);
|
21
|
+
// });
|
22
|
+
|
23
|
+
it('it should set cache without expire ttl', async () => {
|
24
|
+
await cache.set('_foo', 'bar');
|
25
|
+
const data = await cache.get('_foo');
|
26
|
+
expect(data).to.equal('bar');
|
27
|
+
});
|
28
|
+
|
29
|
+
afterAll(() => {
|
30
|
+
rmdirSync(cacheDirectory, { recursive: true });
|
31
|
+
});
|
32
|
+
});
|
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
export declare const Logo: () =>
|
1
|
+
/// <reference types="react" />
|
2
|
+
export declare const Logo: () => JSX.Element;
|
@@ -41,8 +41,8 @@ function _cache() {
|
|
41
41
|
}
|
42
42
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
43
43
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
44
|
-
function _toPropertyKey(
|
45
|
-
function _toPrimitive(
|
44
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
45
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
46
46
|
class CacheMain {
|
47
47
|
constructor(
|
48
48
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_cli","data","require","_logger","_constants","_cacache","_interopRequireDefault","_cache","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","
|
1
|
+
{"version":3,"names":["_cli","data","require","_logger","_constants","_cacache","_interopRequireDefault","_cache","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","CacheMain","constructor","config","logger","set","ttl","debug","expire","Date","getTime","cacache","put","globalCacheFolder","JSON","stringify","then","catch","get","cacheObject","parse","toString","rm","undefined","cacheDirectory","provider","loggerFactory","createLogger","CacheAspect","id","exports","MainRuntime","LoggerAspect","CACHE_ROOT","addRuntime"],"sources":["cache.main.runtime.ts"],"sourcesContent":["import { MainRuntime } from '@teambit/cli';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { CACHE_ROOT } from '@teambit/legacy/dist/constants';\nimport cacache from 'cacache';\n\nimport { CacheAspect } from './cache.aspect';\n\nexport type CacheConfig = {\n cacheDirectory: string;\n};\n\nexport class CacheMain {\n static runtime = MainRuntime;\n\n constructor(\n /**\n * extension config\n */\n readonly config: CacheConfig,\n\n /**\n * logger extension.\n */\n private readonly logger: Logger\n ) {}\n\n static dependencies = [LoggerAspect];\n\n static defaultConfig = {\n cacheDirectory: CACHE_ROOT,\n };\n\n async set(key: string, data: any, ttl?: number): Promise<boolean> {\n this.logger.debug(`put cache to ${key} with data ${data}`);\n const expire = ttl ? new Date().getTime() + ttl : null;\n return cacache\n .put(this.globalCacheFolder, key, JSON.stringify({ data, expire }))\n .then(() => true)\n .catch(() => false);\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n this.logger.debug(`get cache for ${key}`);\n return cacache\n .get(this.globalCacheFolder, key)\n .then(async (cacheObject) => {\n const { data, expire } = JSON.parse(cacheObject.data.toString());\n if (expire && new Date().getTime() > expire) {\n return cacache.rm(this.globalCacheFolder, key);\n }\n return data;\n })\n .catch(() => undefined);\n }\n\n private get globalCacheFolder() {\n return this.config.cacheDirectory;\n }\n\n static async provider([loggerFactory]: [LoggerMain], config: CacheConfig) {\n const logger = loggerFactory.createLogger(CacheAspect.id);\n return new CacheMain(config, logger);\n }\n}\n\nCacheAspect.addRuntime(CacheMain);\n"],"mappings":";;;;;;AAAA,SAAAA,KAAA;EAAA,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AACD,WAAW,CAAChD,IAAI,CAACkD,QAAQ,CAAC,CAAC,CAAC;MAChE,IAAIb,MAAM,IAAI,IAAIC,IAAI,CAAC,CAAC,CAACC,OAAO,CAAC,CAAC,GAAGF,MAAM,EAAE;QAC3C,OAAOG,kBAAO,CAACW,EAAE,CAAC,IAAI,CAACT,iBAAiB,EAAE/B,GAAG,CAAC;MAChD;MACA,OAAOX,IAAI;IACb,CAAC,CAAC,CACD8C,KAAK,CAAC,MAAMM,SAAS,CAAC;EAC3B;EAEA,IAAYV,iBAAiBA,CAAA,EAAG;IAC9B,OAAO,IAAI,CAACV,MAAM,CAACqB,cAAc;EACnC;EAEA,aAAaC,QAAQA,CAAC,CAACC,aAAa,CAAe,EAAEvB,MAAmB,EAAE;IACxE,MAAMC,MAAM,GAAGsB,aAAa,CAACC,YAAY,CAACC,oBAAW,CAACC,EAAE,CAAC;IACzD,OAAO,IAAI5B,SAAS,CAACE,MAAM,EAAEC,MAAM,CAAC;EACtC;AACF;AAAC0B,OAAA,CAAA7B,SAAA,GAAAA,SAAA;AAAApB,eAAA,CApDYoB,SAAS,aACH8B,kBAAW;AAAAlD,eAAA,CADjBoB,SAAS,kBAeE,CAAC+B,sBAAY,CAAC;AAAAnD,eAAA,CAfzBoB,SAAS,mBAiBG;EACrBuB,cAAc,EAAES;AAClB,CAAC;AAmCHL,oBAAW,CAACM,UAAU,CAACjC,SAAS,CAAC"}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_cache@0.0.
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_cache@0.0.
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_cache@0.0.933/dist/cache.composition.js';
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_cache@0.0.933/dist/cache.docs.mdx';
|
3
3
|
|
4
4
|
export const compositions = [compositions_0];
|
5
5
|
export const overview = [overview_0];
|
package/index.ts
ADDED
package/package.json
CHANGED
@@ -1,38 +1,34 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/cache",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.933",
|
4
4
|
"homepage": "https://bit.cloud/teambit/harmony/cache",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"componentId": {
|
7
7
|
"scope": "teambit.harmony",
|
8
8
|
"name": "cache",
|
9
|
-
"version": "0.0.
|
9
|
+
"version": "0.0.933"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
12
|
"cacache": "15.0.5",
|
13
|
-
"core-js": "^3.0.0",
|
14
|
-
"@babel/runtime": "7.20.0",
|
15
13
|
"@teambit/harmony": "0.4.6",
|
16
|
-
"@teambit/cli": "0.0.
|
17
|
-
"@teambit/logger": "0.0.
|
14
|
+
"@teambit/cli": "0.0.840",
|
15
|
+
"@teambit/logger": "0.0.933"
|
18
16
|
},
|
19
17
|
"devDependencies": {
|
20
|
-
"@types/react": "^17.0.8",
|
21
18
|
"@types/cacache": "12.0.1",
|
22
19
|
"@types/chai": "4.2.15",
|
23
20
|
"@types/uuid": "8.3.4",
|
24
21
|
"chai": "4.3.0",
|
25
22
|
"uuid": "8.3.2",
|
26
23
|
"@types/mocha": "9.1.0",
|
27
|
-
"@types/
|
28
|
-
"@types/
|
29
|
-
"@
|
30
|
-
"@types/testing-library__jest-dom": "5.9.5"
|
24
|
+
"@types/jest": "^29.2.2",
|
25
|
+
"@types/testing-library__jest-dom": "^5.9.5",
|
26
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.13"
|
31
27
|
},
|
32
28
|
"peerDependencies": {
|
33
|
-
"
|
34
|
-
"react": "^
|
35
|
-
"
|
29
|
+
"react": "^17.0.0 || ^18.0.0",
|
30
|
+
"@types/react": "^18.2.12",
|
31
|
+
"@teambit/legacy": "1.0.624"
|
36
32
|
},
|
37
33
|
"license": "Apache-2.0",
|
38
34
|
"optionalDependencies": {},
|
@@ -46,7 +42,7 @@
|
|
46
42
|
},
|
47
43
|
"private": false,
|
48
44
|
"engines": {
|
49
|
-
"node": ">=
|
45
|
+
"node": ">=16.0.0"
|
50
46
|
},
|
51
47
|
"repository": {
|
52
48
|
"type": "git",
|
@@ -55,12 +51,9 @@
|
|
55
51
|
"keywords": [
|
56
52
|
"bit",
|
57
53
|
"bit-aspect",
|
54
|
+
"bit-core-aspect",
|
58
55
|
"components",
|
59
56
|
"collaboration",
|
60
|
-
"web"
|
61
|
-
"react",
|
62
|
-
"react-components",
|
63
|
-
"angular",
|
64
|
-
"angular-components"
|
57
|
+
"web"
|
65
58
|
]
|
66
59
|
}
|
package/tsconfig.json
CHANGED
@@ -1,38 +1,33 @@
|
|
1
1
|
{
|
2
2
|
"compilerOptions": {
|
3
3
|
"lib": [
|
4
|
-
"
|
5
|
-
"
|
6
|
-
"
|
7
|
-
"DOM.Iterable",
|
8
|
-
"ScriptHost"
|
4
|
+
"esnext",
|
5
|
+
"dom",
|
6
|
+
"dom.Iterable"
|
9
7
|
],
|
10
|
-
"target": "
|
11
|
-
"module": "
|
12
|
-
"jsx": "react",
|
13
|
-
"allowJs": true,
|
14
|
-
"composite": true,
|
8
|
+
"target": "es2020",
|
9
|
+
"module": "es2020",
|
10
|
+
"jsx": "react-jsx",
|
15
11
|
"declaration": true,
|
16
12
|
"sourceMap": true,
|
17
|
-
"skipLibCheck": true,
|
18
13
|
"experimentalDecorators": true,
|
19
|
-
"
|
14
|
+
"skipLibCheck": true,
|
20
15
|
"moduleResolution": "node",
|
21
16
|
"esModuleInterop": true,
|
22
|
-
"rootDir": ".",
|
23
17
|
"resolveJsonModule": true,
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"
|
27
|
-
"strictPropertyInitialization": false,
|
28
|
-
"strict": true,
|
29
|
-
"noImplicitAny": false,
|
30
|
-
"preserveConstEnums": true
|
18
|
+
"allowJs": true,
|
19
|
+
"outDir": "dist",
|
20
|
+
"emitDeclarationOnly": true
|
31
21
|
},
|
32
22
|
"exclude": [
|
23
|
+
"artifacts",
|
24
|
+
"public",
|
33
25
|
"dist",
|
26
|
+
"node_modules",
|
27
|
+
"package.json",
|
34
28
|
"esm.mjs",
|
35
|
-
"
|
29
|
+
"**/*.cjs",
|
30
|
+
"./dist"
|
36
31
|
],
|
37
32
|
"include": [
|
38
33
|
"**/*",
|
package/types/asset.d.ts
CHANGED
@@ -5,12 +5,12 @@ declare module '*.png' {
|
|
5
5
|
declare module '*.svg' {
|
6
6
|
import type { FunctionComponent, SVGProps } from 'react';
|
7
7
|
|
8
|
-
export const ReactComponent: FunctionComponent<
|
8
|
+
export const ReactComponent: FunctionComponent<
|
9
|
+
SVGProps<SVGSVGElement> & { title?: string }
|
10
|
+
>;
|
9
11
|
const src: string;
|
10
12
|
export default src;
|
11
13
|
}
|
12
|
-
|
13
|
-
// @TODO Gilad
|
14
14
|
declare module '*.jpg' {
|
15
15
|
const value: any;
|
16
16
|
export = value;
|
@@ -27,3 +27,15 @@ declare module '*.bmp' {
|
|
27
27
|
const value: any;
|
28
28
|
export = value;
|
29
29
|
}
|
30
|
+
declare module '*.otf' {
|
31
|
+
const value: any;
|
32
|
+
export = value;
|
33
|
+
}
|
34
|
+
declare module '*.woff' {
|
35
|
+
const value: any;
|
36
|
+
export = value;
|
37
|
+
}
|
38
|
+
declare module '*.woff2' {
|
39
|
+
const value: any;
|
40
|
+
export = value;
|
41
|
+
}
|