open-index/open-npm huggingface dataset:
npm package: @lucahealthcare/luca-core-ts
Description: Luca Core for TypeScript
Latest version: 1.0.1518

# luca-core-ts

用于 Luca 相关核心功能的 TypeScript 库。

## 包含功能

### DBM 相关实现

- 网络实现
  - 加密
  - 加签
  - 解密
- 对接 Luca OpenAPI 实现模块相关功能
- 模块数据上传到 MinIO 的实现

## 包内使用相关域名

- minio-helper.lucahealthcare.cn
- dbm.lucahealthcare.cn (多环境)
- open.lucahealthcare.cn (多环境)

## 使用方法

### 安装依赖：

```shell
npm install luca-core-ts --save --registry=https://npm.lucahealthcare.cn/
```

### 导入模块以及初始化：

```typescript
import { LucaCore } from "luca-core-ts";
LucaCore.instance.initialize({
  env: "dev", // 环境变量，如 dev, test, uat, prod
  dbmKeys: {
    privateKey: "<your private key>", // 开发方提供的私钥，用于数据加签
    publicKey: "<your public key>", // Luca提供的公钥，用于数据加密
  },
  request: config => {
    /**
     * 这里要根据开发使用的网路框架进行配置，返回一个Promise<Data>对象, Data为response.data
     */
    const { url, method, headers, data, params, cache } = config;

    // 如果使用Taro
    return Taro.request({...})

    // 如果使用axios
    return axios.request({...})
  },
  uploadFile: (config, callbacks) => {
    // 这里要根据开发使用的网路框架进行配置
    const { url, filePath, name, formData, headers } = config;

    // 当上传文件时，执行回调函数，如：onSuccess, onFail, onProgress
    const {onSuccess, onFail, onProgress} = callbacks;

    // 如果使用Taro
    return Taro.uploadFile({...})

    // 如果使用axios
    return axios.post({...})
  },
});
```

### DBMEvent 使用

```typeScript
import { LucaCore, DBMEvent } from "luca-core-ts";

// 创建一个DBMEvent实例，传入一个DBMT对象作为参数。这意味着开始测试
const dbmEvent = DBMEvent.create(dbmt);

// 设置个人信息，比如身高、年龄等
dbmEvent.putProfileJson({...})

// 产生了一些文件数据，如音视频文件
dbmEvent.uploadFromFilePath([...])

// 产生数据后，设置输入数据
dbmEvent.putInputJson({...});

// 结束测试并且完成文件上传以后调用notifyFinish方法。这会触发DBMEvent的结束事件，然后关闭所有相关的资源。
dbmEvent.notifyFinish();

// 轮询等待结果, 当有结果的时候意味着事件结束了
const {isCancel} = await dbmEvent.waitForResult(()=>{
  return false; // 外部可以决定是否手动退出等待
}, {
  network: {
    delayThresholdMs: 1000, // 网络延迟阈值，超过这个时间则认为网络不稳定
    delayCallback: () => void // 网络不稳定时的回调函数
  }
}); // isCancel true 表示取消了，false表示正常结束。

```
npm package: @lucaismyname/l1-utils
Description: Reusable, unopinionated utilities for the L1 Stack ecosystem.
Latest version: 0.1.10

# @lucaismyname/l1-utils

Reusable, unopinionated utilities for the L1 Stack ecosystem.

- Node 18+
- ESM

## Install

```bash
npm install @lucaismyname/l1-utils
```

## CMS / Data connectors

### Strapi

```ts
import { createStrapiClient } from '@lucaismyname/l1-utils'

const strapi = createStrapiClient({
  baseUrl: process.env.STRAPI_URL!,
  apiToken: process.env.STRAPI_TOKEN,
})

const res = await strapi.get('/api/articles')
```

### Sanity (GROQ)

```ts
import { createSanityClient } from '@lucaismyname/l1-utils'

const sanity = createSanityClient({
  projectId: process.env.SANITY_PROJECT_ID!,
  dataset: process.env.SANITY_DATASET!,
  apiVersion: '2024-01-01',
  token: process.env.SANITY_TOKEN,
  useCdn: true,
})

const data = await sanity.fetch('*[_type == "post"][0..9]')
```

### Contentful

```ts
import { createContentfulClient } from '@lucaismyname/l1-utils'

const contentful = createContentfulClient({
  spaceId: process.env.CONTENTFUL_SPACE_ID!,
  environment: 'master',
  accessToken: process.env.CONTENTFUL_ACCESS_TOKEN!,
})

const entries = await contentful.getEntries({ content_type: 'post', limit: 10 })
```

### Notion

```ts
import { createNotionClient } from '@lucaismyname/l1-utils'

const notion = await createNotionClient({ token: process.env.NOTION_TOKEN! })

const rows = await notion.queryDatabase(process.env.NOTION_DATABASE_ID!)
```

### Generic REST

```ts
import { createRestClient } from '@lucaismyname/l1-utils'

const api = createRestClient({ baseUrl: 'https://api.example.com' })

const me = await api.get('/me')
```

### MySQL (backend-only)

```ts
import { createMySqlPool } from '@lucaismyname/l1-utils'

const pool = await createMySqlPool({
  host: process.env.MYSQL_HOST!,
  user: process.env.MYSQL_USER!,
  password: process.env.MYSQL_PASSWORD!,
  database: process.env.MYSQL_DATABASE!,
})

const rows = await pool.query('SELECT 1 as ok')
await pool.end()
```

## String utilities

```ts
import { toCamelCase, toKebabCase, toPascalCase, toSnakeCase, truncate } from '@lucaismyname/l1-utils'

toCamelCase('hello world')
toKebabCase('HelloWorld')
truncate('hello world', 5)
```

## Validators / type guards

```ts
import {
  isEmail,
  isIban,
  isBic,
  isCreditCardNumber,
  isUuid,
  isUrl,
  isSlug,
  isHexColor,
  isPhoneNumberE164,
  isPostalCode,
  isIsoDateString,
  isIsoDateTimeString,
} from '@lucaismyname/l1-utils'

isEmail('a@b.com')
isUuid('550e8400-e29b-41d4-a716-446655440000')
isPostalCode('10115', 'DE')
```

## Object / JSON utilities

```ts
import { safeJsonParse, deepMerge, pick, omit, compactObject } from '@lucaismyname/l1-utils'

const parsed = safeJsonParse('{"a":1}')
if (parsed.ok) {
  parsed.value
}

const merged = deepMerge({ a: { b: 1 } }, { a: { c: 2 } })
const only = pick({ a: 1, b: 2 }, ['a'])
const without = omit({ a: 1, b: 2 }, ['b'])

compactObject({ a: 1, b: undefined, c: { d: undefined, e: 2 } })
compactObject({ a: null, b: 1 }, { removeNull: true })
```