open-index/open-npm huggingface dataset:
npm package: @fastcampus/stylelint-config
Description: stylelint config for fastcampus
Author: Jaewon Noh
Latest version: 0.0.3

# stylelint-config

## Getting Started

```
.stylelintrc inside your repo..
{
  "extends": ["@fastcampus/stylelint-config"],
}
```

## Contributing

### test

```console
$ npm run test
```
npm package: @fastcar/cache
Description: 应用内缓存
Author: william_zhong
Latest version: 0.1.0

# 内存缓存

## 使用场景

* 提供基础的缓存功能(比如 增删改查和设置缓存失效)

* 用于频繁存储数据 减缓对数据库写操作的压力

* 允许自定义不同的客户端，拓展其数据持久化能力

## 快速安装

npm install @fastcar/cache

## 使用案例

* 开启缓存功能

```ts
@EnableCache
class APP {
 app!: FastCarApplication;
}
```

* 无客户端持久化缓存示例

```ts
import {CacheMapping} from "@fastcar/cache";
//配置操作
@CacheMapping
class NoclientMapping implements CacheConfig {
 store: string = "noclientStore";
 initSync: boolean = false;
}

export default NoclientMapping;
```

```ts
//调用操作
cacheApplication.set("noclientStore", "hello", "world");
let world = cacheApplication.get("noclientStore", "hello");
assert(world == "world");

//设置缓存过期时间
cacheApplication.set("noclientStore", "hellottl", "worldttl", { ttl: 2 }); //2秒后消失
  //两秒判断是否存在key
setTimeout(() => {
    assert(!cacheApplication.has("noclientStore", "hellottl")); //可能会有100ms左右延迟
}, 2200);
```

* 文件客户端缓存示例

```ts
//配置操作
@CacheMapping
export default class FileClientMapping implements CacheConfig {
 store: string = "fileStore";
 initSync: boolean = true;
 syncTimer: number = 5; //5秒钟同步一次
 dbClient: DBClientService<String>;

 constructor() {
  this.dbClient = new FSClient(path.join(__dirname, "../", "filedb", "filedb.json"));
 }
}
```

```ts
 cacheApplication.set("fileStore", "hello", "world", { flush: true }); //立即存储
 cacheApplication.set("fileStore", "hello", "worldss"); //同步后存储
```

* mysql数据库操作示例

```ts
//配置操作
@CacheMapping
export default class MySqlClientMapping implements CacheConfig {
 store: string = "mysqlStore";
 initSync: boolean = true;
 syncTimer: number = 10;
 ttl: number = 20; //60秒后过期
 dbClient: DBClientService<String>;
 dbSync: boolean = false;

 @CallDependency
 private cacheMapper!: CacheMapper;

 constructor() {
  //自定义构造一个存储器
  this.dbClient = {
   mset: async (list: Item<String>[]) => {
    await this.cacheMapper.saveORUpdate(
     list.map((item) => {
      return new CacheModel(Object.assign(item, { updateTime: DateUtil.toDateTime() }));
     })
    );
    return true;
   },
   mget: async (): Promise<Item<String>[]> => {
    let list = await this.cacheMapper.select({});
    return list.map((item) => {
     return {
      key: item.key,
      value: item.value,
      ttl: Math.floor((item.updateTime.getTime() - Date.now()) / 1000),
     };
    });
   },
   mdelete: async (keys: string[]) => {
    await this.cacheMapper.delete({
     where: {
      key: keys,
     },
    });
    return true;
   },
  };
 }
}
```

```ts
  cacheApplication.set("mysqlStore", "hello", "world"); //10s秒存储 60秒后进行删除
```

## 缺陷

* 在项目中限定了每100ms扫描计划操作一次，所以当设置立即存储时 仍然有100ms左右的延迟

* 设置ttl后，数据库客户端的数据，如果程序重启了，则需要重新计算一次ttl时效性

* 不支持分布式缓存，如果需要实现分布式，请确保路由到每个服务时需满足一致性hash规则

## 更多用法

参考项目git地址 @fastcar/cache/test 下的simple内

## 项目开源地址

* 项目下载 git clone <https://github.com/williamDazhangyu/fast-car.git>

* 在线查看 <https://github.com/williamDazhangyu/fast-car>
npm package: @fastcar/cossdk
Description: npm install @fastcar/cossdk
Author: william_zhong
Latest version: 0.1.4

# fastcar-cos的SDK封装

## 快速安装

npm install @fastcar/cossdk

## 项目开源地址

* 项目下载 git clone <https://github.com/williamDazhangyu/fast-car.git>

* 在线查看 <https://github.com/williamDazhangyu/fast-car>
npm package: @fastcar/redis
Description: npm install @fastcar/redis
Author: william_zhong
Latest version: 0.1.5

# @fastcar/core框架下的redis使用

## 快速安装

npm install @fastcar/redis

## 使用过程

* 在应用(application)配置下使用 可配置多个 source为自定义数据源名称
* settings:
        redis:
            - { source: "default", host: "localhost", port: 6379, password: "123456" }

* 应用入口开启

```ts
import { EnableRedis } from "@fastcar/redis/annotation";

@Application
@EnableRedis  //开启redis
class APP {
 app!: FastCarApplication;
}

export default = new APP();
```

* 声明redis模板

```ts
import { Repository, DS } from "@fastcar/core/annotation";
import { RedisTemplate } from "@fastcar/redis";

//声明为redis操作模板
@Repository //标注为数据依赖
@DS("default") //这边指定数据源名称和配置内一致
export default class TestRedisTemplate extends RedisTemplate {}
```

* 调用方法

```ts
import { Service } from "@fastcar/core/annotation";
import { Autowired } from "@fastcar/core/annotation";
import TestRedisTemplate from "./TestRedisTemplate";

@Service
export default class SimpleService {

 @Autowired
 private redisTemplate!: TestRedisTemplate;

 async setHello() {
  await this.redisTemplate.set("hello", "world");
 }

 async getHello() {
  return await this.redisTemplate.get("hello");
 }
}
```

## 注解说明

EnableRedis 作用于应用上 用于开启redis组件

## 更多用法

参考项目git地址 @fastcar/redis/test 下的example内

## 项目开源地址

* 项目下载 git clone <https://github.com/williamDazhangyu/fast-car.git>

* 在线查看 <https://github.com/williamDazhangyu/fast-car>
npm package: @fastcar/server
Description: 服务统一管理框架
Latest version: 0.0.5

# @fastcar/core框架下创建网络服务器

## 快速安装

npm install @fastcar/server

## 使用说明

* 由应用手动创建服务，并放置ServerApplication下统一进行管理
* 应用入口开启 @EnableServer
* 新版本的@fastcar/koa 和 @fastcar/rpc均依赖于server创建服务
* 生命周期，它的周期均为最后 每次启动或者停止均为最后
* 支持创建 net http https http2 ssl服务

## 服务基础配置说明

* port?: number; //可选 默认80 https默认443
* protocol?: Protocol; //可选 http  http2 或者 https 默认http
* ssl?: SSLConfig; //可选 ssl 对象中为cert和key 用于支持ssl请求
* hostname?: string; //可选 当填写0.0.0.0时则不开启ipv6了

```ts
import "reflect-metadata";
import { FastCarApplication } from "@fastcar/core";
import { Application, BaseFilePath, BasePath } from "@fastcar/core/annotation";
import { EnableServer } from "@fastcar/server";

@Application
@BasePath(__dirname)
@BaseFilePath(__filename)
@EnableServer
class APP {
 app!: FastCarApplication;
}
new APP();

```

* 手动调用server示例

```ts
@ApplicationStart(BootPriority.Lowest)
export default class ServerService {
 @Autowired
 protected serverApplication!: ServerApplication;

 @Autowired
 protected app!: FastCarApplication;

 run() {
  let list: ServerConfig[] = this.app.getSetting("server"); //此处为服务器配置列表

  //进行创建
  list.forEach((item) => {
   this.serverApplication.createServer(item, (req: any, res: any) => {
    try {
     if (item.protocol == Protocol.http || item.protocol == Protocol.https || item.protocol == Protocol.http2) {
      res.writeHead(200);
      res.end("hello world\n");
     } else {
      req.end("hello world\n");
     }
    } catch (e) {
     console.error(e);
    }
   });
  });
 }
}
```

* 应用配置示例

```yml
application:
  name: "simple"
settings:
  server:
    - { port: 1234 } ##默认http请求
    - {
        port: 1235,
        protocol: https,
        ssl:
          { key: "./ssl/localhost-key.pem", cert: "./ssl/localhost-cert.crt" },
      }
    - { port: 1236, protocol: net } #创建一个tcp请求
```

## 注解说明

EnableServer 作用于应用上 用于开启server组件

## 更多用法

参考项目git地址 @fastcar/server/test 下的example内

## 项目开源地址

* 项目下载 git clone <https://github.com/williamDazhangyu/fast-car.git>

* 在线查看 <https://github.com/williamDazhangyu/fast-car>