@teambit/cache 0.0.933 → 0.0.934

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
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuites>
3
+ <testsuite name="teambit.harmony/cache@0.0.934" timestamp="2023-12-27T17:56:28.158Z" tests="2" failures="0" errors="0" skipped="0">
4
+ <testcase classname="cache.spec.js" name="it should set cache with ttl" time="0.5"/>
5
+ <testcase classname="cache.spec.js" name="it should set cache without expire ttl" time="0.004"/>
6
+ </testsuite>
7
+ </testsuites>
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["teambit.harmony/cache-preview"]=t():e["teambit.harmony/cache-preview"]=t()}(self,(()=>(()=>{"use strict";var e={87416:(e,t,o)=>{var r={id:"teambit.harmony/cache@0.0.934",homepage:"https://bit.cloud/teambit/harmony/cache",exported:!0};function n(){const e=i(o(87363));return n=function(){return e},e}function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.Logo=void 0,n.__bit_component=r,i.__bit_component=r;const c=()=>n().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},n().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/extensions-icons/cache.svg"}));c.__bit_component=r,t.Logo=c},87363:e=>{e.exports=React}},t={};function o(r){var n=t[r];if(void 0!==n)return n.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,o),i.exports}o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{o.r(r),o.d(r,{compositions:()=>u,compositions_metadata:()=>l,overview:()=>f});var e={};o.r(e),o.d(e,{default:()=>d});var t=o(87416);o(87363);const n=MdxJsReact,i=TeambitMdxUiMdxScopeContext;var c=["components"];function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},a.apply(this,arguments)}var p={},s="wrapper";function d(e){var t=e.components,o=function(e,t){if(null==e)return{};var o,r,n=function(e,t){if(null==e)return{};var o,r,n={},i=Object.keys(e);for(r=0;r<i.length;r++)o=i[r],t.indexOf(o)>=0||(n[o]=e[o]);return n}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)o=i[r],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(n[o]=e[o])}return n}(e,c);return(0,n.mdx)(s,a({},p,o,{components:t,mdxType:"MDXLayout"}),(0,n.mdx)(i.MDXScopeProvider,{components:{},mdxType:"MDXScopeProvider"}))}d.isMDXComponent=!0;const u=[t],f=[e],l={compositions:[{displayName:"Logo",identifier:"Logo"}]}})(),r})()));
@@ -1,5 +1,5 @@
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';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_cache@0.0.934/dist/cache.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_cache@0.0.934/dist/cache.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@teambit/cache",
3
- "version": "0.0.933",
3
+ "version": "0.0.934",
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.933"
9
+ "version": "0.0.934"
10
10
  },
11
11
  "dependencies": {
12
12
  "cacache": "15.0.5",
13
13
  "@teambit/harmony": "0.4.6",
14
- "@teambit/cli": "0.0.840",
15
- "@teambit/logger": "0.0.933"
14
+ "@teambit/cli": "0.0.841",
15
+ "@teambit/logger": "0.0.934"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/cacache": "12.0.1",
@@ -23,7 +23,7 @@
23
23
  "@types/mocha": "9.1.0",
24
24
  "@types/jest": "^29.2.2",
25
25
  "@types/testing-library__jest-dom": "^5.9.5",
26
- "@teambit/harmony.envs.core-aspect-env": "0.0.13"
26
+ "@teambit/harmony.envs.core-aspect-env": "0.0.14"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "react": "^17.0.0 || ^18.0.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,32 +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
- 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
- });
package/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export type { CacheMain } from './cache.main.runtime';
2
- export { CacheAspect } from './cache.aspect';