@teambit/cache 0.0.932 → 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.
@@ -0,0 +1,7 @@
1
+ import { Aspect } from '@teambit/harmony';
2
+
3
+ export const CacheAspect = Aspect.create({
4
+ id: 'teambit.harmony/cache',
5
+ dependencies: [],
6
+ defaultConfig: {},
7
+ });
@@ -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
- import React from 'react';
2
- export declare const Logo: () => React.JSX.Element;
1
+ /// <reference types="react" />
2
+ export declare const Logo: () => JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import { Logger, LoggerMain } from '@teambit/logger';
2
- export declare type CacheConfig = {
2
+ export type CacheConfig = {
3
3
  cacheDirectory: string;
4
4
  };
5
5
  export declare class CacheMain {
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_cache@0.0.932/dist/cache.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_cache@0.0.932/dist/cache.docs.mdx';
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
@@ -0,0 +1,2 @@
1
+ export type { CacheMain } from './cache.main.runtime';
2
+ export { CacheAspect } from './cache.aspect';
package/package.json CHANGED
@@ -1,38 +1,34 @@
1
1
  {
2
2
  "name": "@teambit/cache",
3
- "version": "0.0.932",
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.932"
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.839",
17
- "@teambit/logger": "0.0.932"
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/node": "12.20.4",
28
- "@types/react-dom": "^17.0.5",
29
- "@types/jest": "^26.0.0",
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
- "@teambit/legacy": "1.0.624",
34
- "react": "^16.8.0 || ^17.0.0",
35
- "react-dom": "^16.8.0 || ^17.0.0"
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": ">=12.22.0"
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
- "es2019",
5
- "DOM",
6
- "ES6",
7
- "DOM.Iterable",
8
- "ScriptHost"
4
+ "esnext",
5
+ "dom",
6
+ "dom.Iterable"
9
7
  ],
10
- "target": "es2015",
11
- "module": "CommonJS",
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
- "outDir": "dist",
14
+ "skipLibCheck": true,
20
15
  "moduleResolution": "node",
21
16
  "esModuleInterop": true,
22
- "rootDir": ".",
23
17
  "resolveJsonModule": true,
24
- "emitDeclarationOnly": true,
25
- "emitDecoratorMetadata": true,
26
- "allowSyntheticDefaultImports": true,
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
- "package.json"
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<SVGProps<SVGSVGElement> & { title?: string }>;
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
+ }