Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@segment/analytics-core

Package Overview
Dependencies
Maintainers
242
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@segment/analytics-core - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

dist/cjs/analytics/dispatch-emit.js

14

CHANGELOG.md
# @segment/analytics-core
## 1.1.0
### Minor Changes
- [#587](https://github.com/segmentio/analytics-next/pull/587) [`598fc31`](https://github.com/segmentio/analytics-next/commit/598fc318a457ac6e5b04d04406f8d836d83763a4) Thanks [@silesky](https://github.com/silesky)! - Migrate shared code into core.
### Patch Changes
- [#602](https://github.com/segmentio/analytics-next/pull/602) [`4644afc`](https://github.com/segmentio/analytics-next/commit/4644afc5be2dac90465e16a485ef5c34ff694da3) Thanks [@silesky](https://github.com/silesky)! - Fix bug where delay and pTimeout are coupled
* [#603](https://github.com/segmentio/analytics-next/pull/603) [`ce90543`](https://github.com/segmentio/analytics-next/commit/ce905439355c1cbd306535600bf356710be147de) Thanks [@silesky](https://github.com/silesky)! - Remove extraneous code from EQ
- [#593](https://github.com/segmentio/analytics-next/pull/593) [`7b5d3df`](https://github.com/segmentio/analytics-next/commit/7b5d3df8d7d8e479d1dda4557297baedb3cdcf6f) Thanks [@silesky](https://github.com/silesky)! - Revise NodeJS public API. Fix core so Node SDK waits for plugins to be registered before dispatching any events.
## 1.0.1

@@ -4,0 +18,0 @@

26

dist/cjs/emitter/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Emitter = void 0;
var tslib_1 = require("tslib");
/**
* Event Emitter that takes the expected contract as a generic
* @example
* ```ts
* type Contract = {
* delivery_success: [DeliverySuccessResponse, Metrics],
* delivery_failure: [DeliveryError]
* }
* new Emitter<Contract>()
* .on('delivery_success', (res, metrics) => ...)
* .on('delivery_failure', (err) => ...)
* ```
*/
var Emitter = /** @class */ (function () {

@@ -10,7 +22,11 @@ function Emitter() {

Emitter.prototype.on = function (event, callback) {
var _a;
this.callbacks[event] = tslib_1.__spreadArray(tslib_1.__spreadArray([], ((_a = this.callbacks[event]) !== null && _a !== void 0 ? _a : []), true), [callback], false);
if (!this.callbacks[event]) {
this.callbacks[event] = [callback];
}
else {
this.callbacks[event].push(callback);
}
return this;
};
Emitter.prototype.once = function (event, fn) {
Emitter.prototype.once = function (event, callback) {
var _this = this;

@@ -23,3 +39,3 @@ var on = function () {

_this.off(event, on);
fn.apply(_this, args);
callback.apply(_this, args);
};

@@ -26,0 +42,0 @@ this.on(event, on);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Emitter = void 0;
var emitter_1 = require("./emitter");
Object.defineProperty(exports, "Emitter", { enumerable: true, get: function () { return emitter_1.Emitter; } });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./emitter"), exports);
tslib_1.__exportStar(require("./emitter/interface"), exports);
tslib_1.__exportStar(require("./plugins"), exports);
tslib_1.__exportStar(require("./plugins/middleware"), exports);
tslib_1.__exportStar(require("./events/interfaces"), exports);
tslib_1.__exportStar(require("./events"), exports);
tslib_1.__exportStar(require("./callback"), exports);
tslib_1.__exportStar(require("./priority-queue"), exports);
tslib_1.__exportStar(require("./context"), exports);
tslib_1.__exportStar(require("./queue/event-queue"), exports);
tslib_1.__exportStar(require("./analytics"), exports);
tslib_1.__exportStar(require("./analytics/dispatch"), exports);
tslib_1.__exportStar(require("./analytics/dispatch-emit"), exports);
tslib_1.__exportStar(require("./arguments-resolver"), exports);
tslib_1.__exportStar(require("./validation/helpers"), exports);
tslib_1.__exportStar(require("./validation/assertions"), exports);
tslib_1.__exportStar(require("./utils/to-facade"), exports);
tslib_1.__exportStar(require("./utils/bind-all"), exports);
tslib_1.__exportStar(require("./stats"), exports);
//# sourceMappingURL=index.js.map

@@ -1,2 +0,14 @@

import { __spreadArray } from "tslib";
/**
* Event Emitter that takes the expected contract as a generic
* @example
* ```ts
* type Contract = {
* delivery_success: [DeliverySuccessResponse, Metrics],
* delivery_failure: [DeliveryError]
* }
* new Emitter<Contract>()
* .on('delivery_success', (res, metrics) => ...)
* .on('delivery_failure', (err) => ...)
* ```
*/
var Emitter = /** @class */ (function () {

@@ -7,7 +19,11 @@ function Emitter() {

Emitter.prototype.on = function (event, callback) {
var _a;
this.callbacks[event] = __spreadArray(__spreadArray([], ((_a = this.callbacks[event]) !== null && _a !== void 0 ? _a : []), true), [callback], false);
if (!this.callbacks[event]) {
this.callbacks[event] = [callback];
}
else {
this.callbacks[event].push(callback);
}
return this;
};
Emitter.prototype.once = function (event, fn) {
Emitter.prototype.once = function (event, callback) {
var _this = this;

@@ -20,3 +36,3 @@ var on = function () {

_this.off(event, on);
fn.apply(_this, args);
callback.apply(_this, args);
};

@@ -23,0 +39,0 @@ this.on(event, on);

@@ -1,2 +0,20 @@

export { Emitter } from './emitter';
export * from './emitter';
export * from './emitter/interface';
export * from './plugins';
export * from './plugins/middleware';
export * from './events/interfaces';
export * from './events';
export * from './callback';
export * from './priority-queue';
export * from './context';
export * from './queue/event-queue';
export * from './analytics';
export * from './analytics/dispatch';
export * from './analytics/dispatch-emit';
export * from './arguments-resolver';
export * from './validation/helpers';
export * from './validation/assertions';
export * from './utils/to-facade';
export * from './utils/bind-all';
export * from './stats';
//# sourceMappingURL=index.js.map

@@ -1,8 +0,25 @@

export declare class Emitter {
declare type EventName = string;
declare type EventFnArgs = any[];
declare type EmitterContract = Record<EventName, EventFnArgs>;
/**
* Event Emitter that takes the expected contract as a generic
* @example
* ```ts
* type Contract = {
* delivery_success: [DeliverySuccessResponse, Metrics],
* delivery_failure: [DeliveryError]
* }
* new Emitter<Contract>()
* .on('delivery_success', (res, metrics) => ...)
* .on('delivery_failure', (err) => ...)
* ```
*/
export declare class Emitter<Contract extends EmitterContract = EmitterContract> {
private callbacks;
on(event: string, callback: Function): this;
once(event: string, fn: Function): this;
off(event: string, callback: Function): this;
emit(event: string, ...args: unknown[]): this;
on<EventName extends keyof Contract>(event: EventName, callback: (...args: Contract[EventName]) => void): this;
once<EventName extends keyof Contract>(event: EventName, callback: (...args: Contract[EventName]) => void): this;
off<EventName extends keyof Contract>(event: EventName, callback: (...args: Contract[EventName]) => void): this;
emit<EventName extends keyof Contract>(event: EventName, ...args: Contract[EventName]): this;
}
export {};
//# sourceMappingURL=index.d.ts.map

@@ -1,2 +0,20 @@

export { Emitter } from './emitter';
export * from './emitter';
export * from './emitter/interface';
export * from './plugins';
export * from './plugins/middleware';
export * from './events/interfaces';
export * from './events';
export * from './callback';
export * from './priority-queue';
export * from './context';
export * from './queue/event-queue';
export * from './analytics';
export * from './analytics/dispatch';
export * from './analytics/dispatch-emit';
export * from './arguments-resolver';
export * from './validation/helpers';
export * from './validation/assertions';
export * from './utils/to-facade';
export * from './utils/bind-all';
export * from './stats';
//# sourceMappingURL=index.d.ts.map

11

package.json
{
"name": "@segment/analytics-core",
"version": "1.0.1",
"version": "1.1.0",
"repository": {

@@ -16,3 +16,4 @@ "type": "git",

"src/",
"!**/__tests__/**"
"!**/__tests__/**",
"!*.tsbuildinfo"
],

@@ -23,6 +24,6 @@ "sideEffects": false,

"lint": "yarn concurrently 'yarn:eslint .' 'yarn:tsc --noEmit'",
"build": "rm -rf dist && yarn concurrently 'yarn:build:*'",
"build": "yarn concurrently 'yarn:build:*'",
"build:esm": "yarn tsc -p tsconfig.build.json",
"build:cjs": "yarn tsc -p tsconfig.build.json --outDir ./dist/cjs --module commonjs",
"watch": "yarn concurrently 'yarn:build:cjs --watch' 'yarn:build:esm --watch'",
"watch": "yarn build:esm --watch --incremental",
"watch:test": "yarn test --watch",

@@ -36,4 +37,6 @@ "tsc": "yarn run -T tsc",

"dependencies": {
"@lukeed/uuid": "^2.0.0",
"dset": "^3.1.2",
"tslib": "^2.4.0"
}
}

@@ -1,13 +0,39 @@

export class Emitter {
private callbacks: Record<string, Function[]> = {}
type EventName = string
type EventFnArgs = any[]
type EmitterContract = Record<EventName, EventFnArgs>
on(event: string, callback: Function): this {
this.callbacks[event] = [...(this.callbacks[event] ?? []), callback]
/**
* Event Emitter that takes the expected contract as a generic
* @example
* ```ts
* type Contract = {
* delivery_success: [DeliverySuccessResponse, Metrics],
* delivery_failure: [DeliveryError]
* }
* new Emitter<Contract>()
* .on('delivery_success', (res, metrics) => ...)
* .on('delivery_failure', (err) => ...)
* ```
*/
export class Emitter<Contract extends EmitterContract = EmitterContract> {
private callbacks: Partial<Contract> = {}
on<EventName extends keyof Contract>(
event: EventName,
callback: (...args: Contract[EventName]) => void
): this {
if (!this.callbacks[event]) {
this.callbacks[event] = [callback] as Contract[EventName]
} else {
this.callbacks[event]!.push(callback)
}
return this
}
once(event: string, fn: Function): this {
const on = (...args: unknown[]): void => {
once<EventName extends keyof Contract>(
event: EventName,
callback: (...args: Contract[EventName]) => void
): this {
const on = (...args: Contract[EventName]): void => {
this.off(event, on)
fn.apply(this, args)
callback.apply(this, args)
}

@@ -19,5 +45,8 @@

off(event: string, callback: Function): this {
off<EventName extends keyof Contract>(
event: EventName,
callback: (...args: Contract[EventName]) => void
): this {
const fns = this.callbacks[event] ?? []
const without = fns.filter((fn) => fn !== callback)
const without = fns.filter((fn) => fn !== callback) as Contract[EventName]
this.callbacks[event] = without

@@ -27,3 +56,6 @@ return this

emit(event: string, ...args: unknown[]): this {
emit<EventName extends keyof Contract>(
event: EventName,
...args: Contract[EventName]
): this {
const callbacks = this.callbacks[event] ?? []

@@ -30,0 +62,0 @@ callbacks.forEach((callback) => {

@@ -1,1 +0,19 @@

export { Emitter } from './emitter'
export * from './emitter'
export * from './emitter/interface'
export * from './plugins'
export * from './plugins/middleware'
export * from './events/interfaces'
export * from './events'
export * from './callback'
export * from './priority-queue'
export * from './context'
export * from './queue/event-queue'
export * from './analytics'
export * from './analytics/dispatch'
export * from './analytics/dispatch-emit'
export * from './arguments-resolver'
export * from './validation/helpers'
export * from './validation/assertions'
export * from './utils/to-facade'
export * from './utils/bind-all'
export * from './stats'

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc