@teambit/cache 0.0.467 → 0.0.472

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.
@@ -3,10 +3,24 @@ export declare type CacheConfig = {
3
3
  cacheDirectory: string;
4
4
  };
5
5
  export declare class CacheMain {
6
+ /**
7
+ * extension config
8
+ */
6
9
  readonly config: CacheConfig;
10
+ /**
11
+ * logger extension.
12
+ */
7
13
  private readonly logger;
8
14
  static runtime: import("@teambit/harmony").RuntimeDefinition;
9
- constructor(config: CacheConfig, logger: Logger);
15
+ constructor(
16
+ /**
17
+ * extension config
18
+ */
19
+ config: CacheConfig,
20
+ /**
21
+ * logger extension.
22
+ */
23
+ logger: Logger);
10
24
  static dependencies: import("@teambit/harmony").Aspect[];
11
25
  static defaultConfig: {
12
26
  cacheDirectory: string;
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@teambit/cache",
3
- "version": "0.0.467",
3
+ "version": "0.0.472",
4
4
  "homepage": "https://bit.dev/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.467"
9
+ "version": "0.0.472"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/harmony": "0.2.11",
13
13
  "cacache": "15.0.5",
14
14
  "@babel/runtime": "7.12.18",
15
15
  "core-js": "^3.0.0",
16
- "@teambit/cli": "0.0.382",
17
- "@teambit/logger": "0.0.467"
16
+ "@teambit/cli": "0.0.387",
17
+ "@teambit/logger": "0.0.472"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/cacache": "12.0.1",
@@ -30,7 +30,7 @@
30
30
  "@types/node": "12.20.4"
31
31
  },
32
32
  "peerDependencies": {
33
- "@teambit/legacy": "1.0.169",
33
+ "@teambit/legacy": "1.0.173",
34
34
  "react-dom": "^16.8.0 || ^17.0.0",
35
35
  "react": "^16.8.0 || ^17.0.0"
36
36
  },
@@ -58,12 +58,18 @@
58
58
  "react": "-"
59
59
  },
60
60
  "peerDependencies": {
61
- "@teambit/legacy": "1.0.169",
61
+ "@teambit/legacy": "1.0.173",
62
62
  "react-dom": "^16.8.0 || ^17.0.0",
63
63
  "react": "^16.8.0 || ^17.0.0"
64
64
  }
65
65
  }
66
66
  },
67
+ "files": [
68
+ "dist",
69
+ "!dist/tsconfig.tsbuildinfo",
70
+ "README.md",
71
+ "README.mdx"
72
+ ],
67
73
  "private": false,
68
74
  "engines": {
69
75
  "node": ">=12.22.0"
package/cache.aspect.ts DELETED
@@ -1,7 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const CacheAspect = Aspect.create({
4
- id: 'teambit.harmony/cache',
5
- dependencies: [],
6
- defaultConfig: {},
7
- });
@@ -1,66 +0,0 @@
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 DELETED
@@ -1,33 +0,0 @@
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
-
8
-
9
- describe('Cache Aspect', () => {
10
- const cacheDirectory = `/tmp/bit/${v4()}`;
11
- const cache = new CacheMain({ cacheDirectory }, new Logger('cache.main.runtime'));
12
- it('it should set cache with ttl', async () => {
13
- await cache.set('_foo', 'bar', 1000);
14
- const data = await cache.get('_foo');
15
- expect(data).to.equal('bar');
16
- });
17
-
18
- it('it should expire cache', async () => {
19
- await cache.set('_foo', 'bar', 1);
20
- const data = await cache.get('_foo');
21
- expect(data).to.equal(null);
22
- });
23
-
24
- it('it should set cache without expire ttl', async () => {
25
- await cache.set('_foo', 'bar');
26
- const data = await cache.get('_foo');
27
- expect(data).to.equal('bar');
28
- });
29
-
30
- afterAll(() => {
31
- rmdirSync(cacheDirectory, { recursive: true });
32
- });
33
- });
package/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export type { CacheMain } from './cache.main.runtime';
2
- export { CacheAspect } from './cache.aspect';
package/tsconfig.json DELETED
@@ -1,35 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "lib": [
4
- "es2019",
5
- "DOM",
6
- "ES6",
7
- "DOM.Iterable",
8
- "ScriptHost"
9
- ],
10
- "target": "es2015",
11
- "module": "commonjs",
12
- "jsx": "react",
13
- "declaration": true,
14
- "sourceMap": true,
15
- "skipLibCheck": true,
16
- "moduleResolution": "node",
17
- "esModuleInterop": true,
18
- "outDir": "dist",
19
- "composite": true,
20
- "emitDeclarationOnly": true,
21
- "experimentalDecorators": true,
22
- "emitDecoratorMetadata": true,
23
- "allowSyntheticDefaultImports": true,
24
- "strictPropertyInitialization": false,
25
- "strict": true,
26
- "noImplicitAny": false,
27
- "rootDir": ".",
28
- "removeComments": true,
29
- "preserveConstEnums": true,
30
- "resolveJsonModule": true
31
- },
32
- "exclude": [
33
- "dist"
34
- ]
35
- }
package/types/asset.d.ts DELETED
@@ -1,29 +0,0 @@
1
- declare module '*.png' {
2
- const value: any;
3
- export = value;
4
- }
5
- declare module '*.svg' {
6
- import type { FunctionComponent, SVGProps } from 'react';
7
-
8
- export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
9
- const src: string;
10
- export default src;
11
- }
12
-
13
- // @TODO Gilad
14
- declare module '*.jpg' {
15
- const value: any;
16
- export = value;
17
- }
18
- declare module '*.jpeg' {
19
- const value: any;
20
- export = value;
21
- }
22
- declare module '*.gif' {
23
- const value: any;
24
- export = value;
25
- }
26
- declare module '*.bmp' {
27
- const value: any;
28
- export = value;
29
- }
package/types/style.d.ts DELETED
@@ -1,42 +0,0 @@
1
- declare module '*.module.css' {
2
- const classes: { readonly [key: string]: string };
3
- export default classes;
4
- }
5
- declare module '*.module.scss' {
6
- const classes: { readonly [key: string]: string };
7
- export default classes;
8
- }
9
- declare module '*.module.sass' {
10
- const classes: { readonly [key: string]: string };
11
- export default classes;
12
- }
13
-
14
- declare module '*.module.less' {
15
- const classes: { readonly [key: string]: string };
16
- export default classes;
17
- }
18
-
19
- declare module '*.less' {
20
- const classes: { readonly [key: string]: string };
21
- export default classes;
22
- }
23
-
24
- declare module '*.css' {
25
- const classes: { readonly [key: string]: string };
26
- export default classes;
27
- }
28
-
29
- declare module '*.sass' {
30
- const classes: { readonly [key: string]: string };
31
- export default classes;
32
- }
33
-
34
- declare module '*.scss' {
35
- const classes: { readonly [key: string]: string };
36
- export default classes;
37
- }
38
-
39
- declare module '*.mdx' {
40
- const component: any;
41
- export default component;
42
- }