Update from Vibe Studio

This commit is contained in:
Vibe Studio
2026-01-09 14:52:46 +00:00
parent 42a0efe70b
commit 47fa6d98b2
28661 changed files with 2421771 additions and 0 deletions

21
node_modules/@segment/analytics-generic-utils/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright © 2023 Segment
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,3 @@
# @segment/analytics-generic-utils
This monorepo's version of "lodash". This package contains shared generic utilities that can be used within the ecosystem. This package should not have dependencies, and should not contain any references to the Analytics domain.

View File

@@ -0,0 +1,39 @@
{
"name": "@segment/analytics-generic-utils",
"version": "1.2.0",
"repository": {
"type": "git",
"url": "https://github.com/segmentio/analytics-next",
"directory": "packages/generic-utils"
},
"license": "MIT",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"files": [
"dist/",
"src/",
"!**/__tests__/**",
"!*.tsbuildinfo",
"LICENSE"
],
"sideEffects": false,
"scripts": {
".": "yarn run -T turbo run --filter=@segment/analytics-generic-utils",
"test": "yarn jest",
"lint": "yarn concurrently 'yarn:eslint .' 'yarn:tsc --noEmit'",
"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 build:esm --watch",
"watch:test": "yarn test --watch",
"tsc": "yarn run -T tsc",
"eslint": "yarn run -T eslint",
"concurrently": "yarn run -T concurrently",
"jest": "yarn run -T jest"
},
"packageManager": "yarn@3.4.1",
"dependencies": {
"tslib": "^2.4.1"
}
}

View File

@@ -0,0 +1,25 @@
/**
* Return a promise that can be externally resolved
*/
export const createDeferred = <T>() => {
let resolve!: (value: T | PromiseLike<T>) => void
let reject!: (reason: any) => void
let settled = false
const promise = new Promise<T>((_resolve, _reject) => {
resolve = (...args) => {
settled = true
_resolve(...args)
}
reject = (...args) => {
settled = true
_reject(...args)
}
})
return {
resolve,
reject,
promise,
isSettled: () => settled,
}
}

View File

@@ -0,0 +1 @@
export * from './create-deferred'

View File

@@ -0,0 +1,98 @@
type EventName = string
type EventFnArgs = any[]
type EmitterContract = Record<EventName, EventFnArgs>
export interface EmitterOptions {
/** How many event listeners for a particular event before emitting a warning (0 = disabled)
* @default 10
**/
maxListeners?: number
}
/**
* 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> {
maxListeners: number
constructor(options?: EmitterOptions) {
this.maxListeners = options?.maxListeners ?? 10
}
private callbacks: Partial<Contract> = {}
private warned = false
private warnIfPossibleMemoryLeak<EventName extends keyof Contract>(
event: EventName
) {
if (this.warned) {
return
}
if (
this.maxListeners &&
this.callbacks[event]!.length > this.maxListeners
) {
console.warn(
`Event Emitter: Possible memory leak detected; ${String(
event
)} has exceeded ${this.maxListeners} listeners.`
)
this.warned = true
}
}
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)
this.warnIfPossibleMemoryLeak(event)
}
return this
}
once<EventName extends keyof Contract>(
event: EventName,
callback: (...args: Contract[EventName]) => void
): this {
const on = (...args: Contract[EventName]): void => {
this.off(event, on)
callback.apply(this, args)
}
this.on(event, on)
return 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) as Contract[EventName]
this.callbacks[event] = without
return this
}
emit<EventName extends keyof Contract>(
event: EventName,
...args: Contract[EventName]
): this {
const callbacks = this.callbacks[event] ?? []
callbacks.forEach((callback) => {
callback.apply(this, args)
})
return this
}
}

View File

@@ -0,0 +1 @@
export * from './emitter'

View File

@@ -0,0 +1,2 @@
export * from './create-deferred'
export * from './emitter'