@benzinga/session

中文文档
2.0.5发布于 2025/04/15MITTypeScriptES Module零依赖近 30 天下载 2881

This Project is Made Possible thanks to

原始使用文档
文档目录4 节
  1. Usage
  2. Adding a New Manager
  3. Session
  4. Methods

Session Package

This Project is Made Possible thanks to

Benzinga Logo

ZSoft Logo

The Session package is a tool that keeps track of all the mangers that you have. Allowing you request, store and fetch data with a ability to configure the Managers before there use.

Usage

To get started you mast first create a session using the createSession function

import { Session } from '@benzinga/session'

you can then simply call get the instance by simply calling the function

const session = new Session();

once you have a session you cant really do much. this is because of the modular design. we call these modules managers. Each manager is responsible for managing a specific resource. to get started lets start with the LoggingManager. to access it simply call the getManager function with the LoggingManager class as a an argument. this will return a logging manager instance. the instance will be held by the session and you can ask for it any time by simply calling getManager

import { Session } from '@benzinga/session';

const session = new Session({
  'benzinga-logging': {
    verbosity: 'warn'
  }
})
const loggingManager = session.getManager(LoggingManager);
loggingManager.log('debug', 'this is a test');

Adding a New Manager

to add a new manager you need to use the following command.

a manager name must end with the word manager. and it must be in the manager directory in the data directory.

in the following command simply replace something with the name of your manager.

yarn nx generate @nrwl/web:lib something --directory=libs/managers --buildable --importPath=@benzinga/something-manager --publishable

A manager must extend the following interface

export interface Manager<T extends Subscribable<any>> {
  getName: () => string;
  new (name: Session): T;
}

what this means in human words is. a manager must take a session as a constructor argument. and it must the a static public function called getName. other then that there are no requirements.

Classes

Session

Core class of Benzinga SDK

To access any of SDK managers, you must create a session first

Methods

getEnvironment <M extends Environment, R extends ReturnType<M["getEnvironment"]>>(managerEnv: M): R

Get environment for given manager

getManager <T extends Subscribable<any>>(managerName: Manager<T>): T

Get instance of a manager

This is the main way and preferred of getting Manager instances

版本与发布记录

@benzinga/session 共发布 15 个版本,首次发布于 2023/01/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.5latest2025/04/151.6 年前
2.0.42025/04/111.6 年前
2.0.32025/04/111.6 年前
2.0.22025/04/111.6 年前
2.0.12025/04/111.6 年前
2.0.02024/10/052 年前

关于 @benzinga/session 的常见问题

@benzinga/session 是什么?

This Project is Made Possible thanks to

如何安装 @benzinga/session?

在项目目录运行 npm install @benzinga/session,或使用 pnpm add / yarn add / bun add。

@benzinga/session 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@benzinga/session 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@benzinga/session 可以商用吗?

@benzinga/session 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@benzinga/session 的下载量有多少?

根据 npm 官方下载统计,@benzinga/session 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,881 次,日均约 96 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@benzinga/session 还在维护吗?

最新版本 2.0.5 发布于 2025/04/15(1.6 年前);至今共发布 15 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/01/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。