@brainstack/core
Advanced tools
+0
-0
@@ -0,0 +0,0 @@ { |
+0
-0
@@ -0,0 +0,0 @@ { |
+0
-0
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ trigger: |
+7
-2
@@ -1,2 +0,7 @@ | ||
| export * from './abstraction'; | ||
| export * from './implementation'; | ||
| export * from '@brainstack/inject'; | ||
| export * from '@brainstack/log'; | ||
| export * from '@brainstack/hub'; | ||
| export * from '@brainstack/state'; | ||
| export * from '@brainstack/config'; | ||
| export * from '@brainstack/agent'; | ||
| export * from '@brainstack/crud'; |
+7
-2
@@ -17,3 +17,8 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| __exportStar(require("./abstraction"), exports); | ||
| __exportStar(require("./implementation"), exports); | ||
| __exportStar(require("@brainstack/inject"), exports); | ||
| __exportStar(require("@brainstack/log"), exports); | ||
| __exportStar(require("@brainstack/hub"), exports); | ||
| __exportStar(require("@brainstack/state"), exports); | ||
| __exportStar(require("@brainstack/config"), exports); | ||
| __exportStar(require("@brainstack/agent"), exports); | ||
| __exportStar(require("@brainstack/crud"), exports); |
+0
-0
@@ -0,0 +0,0 @@ module.exports = { |
+9
-7
| { | ||
| "name": "@brainstack/core", | ||
| "version": "1.0.13", | ||
| "description": "Your package description", | ||
| "version": "1.1.0", | ||
| "description": "Brainstack Core Packages", | ||
| "main": "dist/index.js", | ||
@@ -31,8 +31,10 @@ "types": "dist/index.d.ts", | ||
| "dependencies": { | ||
| "@brainstack/bridge-client": "^1.0.6", | ||
| "@brainstack/bridge-server": "^1.0.0", | ||
| "@brainstack/hub": "^1.1.3", | ||
| "@brainstack/log": "^1.1.4", | ||
| "@brainstack/state": "^1.1.2" | ||
| "@brainstack/agent": "^1.0.6", | ||
| "@brainstack/config": "^1.0.4", | ||
| "@brainstack/crud": "^1.0.0", | ||
| "@brainstack/hub": "^1.1.5", | ||
| "@brainstack/inject": "^1.2.1", | ||
| "@brainstack/log": "^1.1.9", | ||
| "@brainstack/state": "^1.1.5" | ||
| } | ||
| } |
+73
-23
@@ -0,38 +1,88 @@ | ||
| # @brainstack/core | ||
| # Brainstack Core | ||
| The @brainstack/core package provides a function createCore that creates a core object with a state, a bridge client/server, and a logger. | ||
| A collection of micro packages designed to streamline and enhance the development of modular applications. | ||
| ## Installation | ||
| To install @brainstack/core, run the following command: | ||
| ```sh | ||
| You can install the package using npm: | ||
| ```bash | ||
| npm install @brainstack/core | ||
| ``` | ||
| ## Packages Included | ||
| The `@brainstack/core` package is a bundle that includes the following micro packages, each tailored to address specific aspects of application development: | ||
| - **[@brainstack/inject](https://www.npmjs.com/package/@brainstack/inject)**: A lightweight dependency injection library for JavaScript and TypeScript. Simplify the management of object dependencies and promote code reusability. | ||
| - **[@brainstack/log](https://www.npmjs.com/package/@brainstack/log)**: A micro logger package that offers a simple and efficient way to manage logs and improve debugging processes. | ||
| - **[@brainstack/hub](https://www.npmjs.com/package/@brainstack/hub)**: A micro pub/sub package that facilitates seamless communication between different parts of your application, enabling efficient event-based architectures. | ||
| - **[@brainstack/state](https://www.npmjs.com/package/@brainstack/state)**: A micro state management library that empowers you to handle application state effortlessly, making it ideal for managing complex UI components or global application data. | ||
| - **[@brainstack/config](https://www.npmjs.com/package/@brainstack/config)**: A micro config manager package that lets you manage configuration settings efficiently and flexibly, ensuring smooth application setup and behavior. | ||
| - **[@brainstack/agent](https://www.npmjs.com/package/@brainstack/agent)**: A package tailored for building model agents that help you encapsulate complex logic and behavior into reusable components. | ||
| - **[@brainstack/crud](https://www.npmjs.com/package/@brainstack/crud)**: A micro CRUD package that provides a convenient way to perform Create, Read, Update, and Delete operations on data sources, making data manipulation straightforward. | ||
| ## Usage | ||
| To use createCore, import it along with the necessary dependencies: | ||
| ```js | ||
| import { createCore } from '@brainstack/core'; | ||
| The `@brainstack/core` package serves as a convenient entry point to access and utilize the included micro packages in your application. | ||
| const core = createCore(); | ||
| ### Importing | ||
| To use the various micro packages, simply import them from `@brainstack/core`. For example: | ||
| ```javascript | ||
| import { inject, Dependency } from '@brainstack/core'; | ||
| import { createLogger } from '@brainstack/core'; | ||
| import { createHub } from '@brainstack/core'; | ||
| // Import other packages as needed | ||
| ``` | ||
| The core object returned by createCore includes the following properties: | ||
| state: a state object created with createState | ||
| bridge: a bridge client or server object created with BridgeServer or BridgeClient | ||
| logger: a logger object created with createLogger | ||
| ### Example Use Case | ||
| ## API | ||
| ### createCore(options: CoreOptions): object | ||
| Creates a core object with a state, a bridge client/server, and a logger. | ||
| Imagine you're building a sophisticated web application that requires efficient communication between components, detailed logging, and centralized state management. Instead of manually integrating separate libraries for these tasks, you can leverage the power of `@brainstack/core`. | ||
| **Arguments** | ||
| options (object): An object with the following properties: | ||
| stateOptions (any): Options for createState. | ||
| ```javascript | ||
| import { createLogger, createHub, createStateManager } from '@brainstack/core'; | ||
| **Returns** | ||
| The core object with the following properties: | ||
| // Create a logger instance | ||
| const logger = createLogger(); | ||
| state (object): The state object created with createState. | ||
| bridge (object): The bridge client or server object created with BridgeServer or BridgeClient. | ||
| logger (object): The logger object created with createLogger. | ||
| // Create a hub for event communication | ||
| const hub = createHub(); | ||
| // Create a state manager for managing application state | ||
| const stateManager = createStateManager(); | ||
| // Now you can use these instances throughout your application | ||
| // ... other code ... | ||
| ``` | ||
| ## Use Cases | ||
| The `@brainstack/core` package is ideal for: | ||
| - Building modular applications that follow best practices for dependency management, logging, and communication. | ||
| - Streamlining development by providing simple and focused solutions for common challenges. | ||
| - Simplifying the setup and management of application-wide configuration and state. | ||
| - Promoting code reusability and maintainability through encapsulated logic and agents. | ||
| - Ensuring consistent and efficient data manipulation with the CRUD package. | ||
| # Contributing | ||
| Contributions are welcome! If you would like to contribute to this module, please follow these guidelines: | ||
| Fork the repository | ||
| Create a new branch for your changes | ||
| Make your changes and commit them with descriptive commit messages | ||
| Push your changes to your fork | ||
| Submit a pull request | ||
| # License | ||
| This module is released under the MIT License. |
+7
-2
@@ -1,2 +0,7 @@ | ||
| export * from './abstraction' | ||
| export * from './implementation' | ||
| export * from '@brainstack/inject'; | ||
| export * from '@brainstack/log'; | ||
| export * from '@brainstack/hub'; | ||
| export * from '@brainstack/state'; | ||
| export * from '@brainstack/config'; | ||
| export * from '@brainstack/agent'; | ||
| export * from '@brainstack/crud'; |
+0
-0
@@ -0,0 +0,0 @@ { |
| export {}; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
| import { LogLevel, LoggerIntegration } from "@brainstack/log"; | ||
| export type CoreOptions = { | ||
| stateOptions?: any; | ||
| hubOptions?: any; | ||
| logLevel?: LogLevel; | ||
| logIntegration?: LoggerIntegration[]; | ||
| }; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
| /// <reference types="ws" /> | ||
| /// <reference types="node" /> | ||
| import { State } from '@brainstack/state'; | ||
| import { BridgeClientOption } from '@brainstack/bridge-client'; | ||
| import { EventHub } from '@brainstack/hub'; | ||
| import { Logger } from '@brainstack/log'; | ||
| import { CoreOptions } from './abstraction'; | ||
| export declare const createCore: (options?: CoreOptions) => { | ||
| state: { | ||
| getState: (selector?: ((state: any) => any) | undefined) => any; | ||
| mutate: (arg: any) => any; | ||
| }; | ||
| hub: EventHub; | ||
| logger: Logger; | ||
| }; | ||
| export type CoreClientOptions = { | ||
| stateOptions?: any; | ||
| coreClientOptions?: BridgeClientOption; | ||
| hubOptions?: any; | ||
| loggerOptions?: any; | ||
| }; | ||
| export declare const createCoreClient: (options?: CoreClientOptions) => { | ||
| state: State<any>; | ||
| hub: EventHub; | ||
| logger: Logger; | ||
| connect: (destination: import("@brainstack/bridge-client").ConnectionConfig) => WebSocket; | ||
| close: () => void; | ||
| }; | ||
| export type CoreServerOptions = { | ||
| stateOptions?: any; | ||
| coreServerOptions?: any; | ||
| hubOptions?: any; | ||
| loggerOptions?: any; | ||
| }; | ||
| export declare const createCoreServer: (options?: CoreServerOptions) => { | ||
| state: State<any>; | ||
| hub: EventHub; | ||
| logger: Logger; | ||
| listen: (options: { | ||
| host: string; | ||
| port: number; | ||
| }) => import("ws").Server<typeof import("ws"), typeof import("http").IncomingMessage>; | ||
| close: () => void; | ||
| }; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.createCoreServer = exports.createCoreClient = exports.createCore = void 0; | ||
| const state_1 = require("@brainstack/state"); | ||
| const bridge_client_1 = require("@brainstack/bridge-client"); | ||
| const bridge_server_1 = require("@brainstack/bridge-server"); | ||
| const hub_1 = require("@brainstack/hub"); | ||
| const log_1 = require("@brainstack/log"); | ||
| const createCore = (options) => { | ||
| const { stateOptions, hubOptions, logLevel, logIntegration } = options !== null && options !== void 0 ? options : {}; | ||
| const { mutate, getState } = (0, state_1.createState)(stateOptions); | ||
| const hub = (0, hub_1.createEventHub)(hubOptions); | ||
| const logger = (0, log_1.createLogger)(logLevel, logIntegration); | ||
| const eventMutate = (arg) => { | ||
| const newState = mutate(arg); | ||
| hub.emit("state.changed", { data: newState }); | ||
| return newState; | ||
| }; | ||
| return { state: { getState, mutate: eventMutate }, hub, logger, }; | ||
| }; | ||
| exports.createCore = createCore; | ||
| const createCoreClient = (options) => { | ||
| const { stateOptions, coreClientOptions } = options !== null && options !== void 0 ? options : {}; | ||
| const state = (0, state_1.createState)(stateOptions); | ||
| const bridgeClient = (0, bridge_client_1.createBridgeClient)(coreClientOptions); | ||
| const { hub, logger, close, connect } = bridgeClient; | ||
| return { state, hub, logger, connect, close }; | ||
| }; | ||
| exports.createCoreClient = createCoreClient; | ||
| const createCoreServer = (options) => { | ||
| const { stateOptions, coreServerOptions } = options !== null && options !== void 0 ? options : {}; | ||
| const state = (0, state_1.createState)(stateOptions); | ||
| const bridgeServer = (0, bridge_server_1.createBridgeServer)(coreServerOptions); | ||
| const { hub, logger, close, listen } = bridgeServer; | ||
| return { state, hub, logger, listen, close }; | ||
| }; | ||
| exports.createCoreServer = createCoreServer; |
| export {} |
| import { LogLevel, Logger, LoggerIntegration } from "@brainstack/log" | ||
| export type CoreOptions = { | ||
| stateOptions?: any | ||
| hubOptions?: any | ||
| logLevel?: LogLevel | ||
| logIntegration?: LoggerIntegration[] | ||
| } |
| import { createState, State } from '@brainstack/state'; | ||
| import { BridgeClient, BridgeClientOption, createBridgeClient } from '@brainstack/bridge-client'; | ||
| import { BridgeServer, createBridgeServer } from '@brainstack/bridge-server'; | ||
| import { createEventHub, EventHub } from '@brainstack/hub'; | ||
| import { createLogger, Logger } from '@brainstack/log'; | ||
| import { CoreOptions } from './abstraction'; | ||
| export const createCore = (options?: CoreOptions) => { | ||
| const { stateOptions, hubOptions, logLevel, logIntegration } = options ?? {} | ||
| const { mutate, getState }: State<any> = createState(stateOptions); | ||
| const hub: EventHub = createEventHub(hubOptions); | ||
| const logger: Logger = createLogger(logLevel, logIntegration) | ||
| const eventMutate = (arg: any) => { | ||
| const newState = mutate(arg) | ||
| hub.emit("state.changed", { data: newState }) | ||
| return newState | ||
| } | ||
| return { state: { getState, mutate: eventMutate }, hub, logger, }; | ||
| } | ||
| export type CoreClientOptions = { | ||
| stateOptions?: any | ||
| coreClientOptions?: BridgeClientOption | ||
| hubOptions?: any | ||
| loggerOptions?: any | ||
| } | ||
| export const createCoreClient = (options?: CoreClientOptions) => { | ||
| const { stateOptions, coreClientOptions } = options ?? {} | ||
| const state: State<any> = createState(stateOptions); | ||
| const bridgeClient: BridgeClient = createBridgeClient(coreClientOptions) | ||
| const { hub, logger, close, connect } = bridgeClient | ||
| return { state, hub, logger, connect, close }; | ||
| } | ||
| export type CoreServerOptions = { | ||
| stateOptions?: any | ||
| coreServerOptions?: any | ||
| hubOptions?: any | ||
| loggerOptions?: any | ||
| } | ||
| export const createCoreServer = (options?: CoreServerOptions) => { | ||
| const { stateOptions, coreServerOptions } = options ?? {} | ||
| const state: State<any> = createState(stateOptions); | ||
| const bridgeServer: BridgeServer = createBridgeServer(coreServerOptions) | ||
| const { hub, logger, close, listen } = bridgeServer | ||
| return { state, hub, logger, listen, close }; | ||
| } |
89
134.21%9365
-21.67%7
40%12
-42.86%118
-51.84%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated