Initial commit: Brainy - Multi-Dimensional AI Database
Open source vector database with HNSW indexing, graph relationships, and metadata facets. Features CLI with professional augmentation registry integration for discovering extensions and capabilities.
This commit is contained in:
commit
f8c45f2d8d
448 changed files with 103294 additions and 0 deletions
64
dist/universal/crypto.d.ts
vendored
Normal file
64
dist/universal/crypto.d.ts
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* Universal Crypto implementation
|
||||
* Works in all environments: Browser, Node.js, Serverless
|
||||
*/
|
||||
/**
|
||||
* Generate random bytes
|
||||
*/
|
||||
export declare function randomBytes(size: number): Uint8Array;
|
||||
/**
|
||||
* Generate random UUID
|
||||
*/
|
||||
export declare function randomUUID(): string;
|
||||
/**
|
||||
* Create hash (simplified interface)
|
||||
*/
|
||||
export declare function createHash(algorithm: string): {
|
||||
update: (data: string | Uint8Array) => any;
|
||||
digest: (encoding: string) => string;
|
||||
};
|
||||
/**
|
||||
* Create HMAC
|
||||
*/
|
||||
export declare function createHmac(algorithm: string, key: string | Uint8Array): {
|
||||
update: (data: string | Uint8Array) => any;
|
||||
digest: (encoding: string) => string;
|
||||
};
|
||||
/**
|
||||
* PBKDF2 synchronous
|
||||
*/
|
||||
export declare function pbkdf2Sync(password: string | Uint8Array, salt: string | Uint8Array, iterations: number, keylen: number, digest: string): Uint8Array;
|
||||
/**
|
||||
* Scrypt synchronous
|
||||
*/
|
||||
export declare function scryptSync(password: string | Uint8Array, salt: string | Uint8Array, keylen: number, options?: any): Uint8Array;
|
||||
/**
|
||||
* Create cipher
|
||||
*/
|
||||
export declare function createCipheriv(algorithm: string, key: Uint8Array, iv: Uint8Array): {
|
||||
update: (data: string, inputEncoding?: string, outputEncoding?: string) => string;
|
||||
final: (outputEncoding?: string) => string;
|
||||
};
|
||||
/**
|
||||
* Create decipher
|
||||
*/
|
||||
export declare function createDecipheriv(algorithm: string, key: Uint8Array, iv: Uint8Array): {
|
||||
update: (data: string, inputEncoding?: string, outputEncoding?: string) => string;
|
||||
final: (outputEncoding?: string) => string;
|
||||
};
|
||||
/**
|
||||
* Timing safe equal
|
||||
*/
|
||||
export declare function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
|
||||
declare const _default: {
|
||||
randomBytes: typeof randomBytes;
|
||||
randomUUID: typeof randomUUID;
|
||||
createHash: typeof createHash;
|
||||
createHmac: typeof createHmac;
|
||||
pbkdf2Sync: typeof pbkdf2Sync;
|
||||
scryptSync: typeof scryptSync;
|
||||
createCipheriv: typeof createCipheriv;
|
||||
createDecipheriv: typeof createDecipheriv;
|
||||
timingSafeEqual: typeof timingSafeEqual;
|
||||
};
|
||||
export default _default;
|
||||
215
dist/universal/crypto.js
vendored
Normal file
215
dist/universal/crypto.js
vendored
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
/**
|
||||
* Universal Crypto implementation
|
||||
* Works in all environments: Browser, Node.js, Serverless
|
||||
*/
|
||||
import { isBrowser, isNode } from '../utils/environment.js';
|
||||
let nodeCrypto = null;
|
||||
// Dynamic import for Node.js crypto (only in Node.js environment)
|
||||
if (isNode()) {
|
||||
try {
|
||||
nodeCrypto = await import('crypto');
|
||||
}
|
||||
catch {
|
||||
// Ignore import errors in non-Node environments
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Generate random bytes
|
||||
*/
|
||||
export function randomBytes(size) {
|
||||
if (isBrowser() || typeof crypto !== 'undefined') {
|
||||
// Use Web Crypto API (available in browsers and modern Node.js)
|
||||
const array = new Uint8Array(size);
|
||||
crypto.getRandomValues(array);
|
||||
return array;
|
||||
}
|
||||
else if (nodeCrypto) {
|
||||
// Use Node.js crypto as fallback
|
||||
return new Uint8Array(nodeCrypto.randomBytes(size));
|
||||
}
|
||||
else {
|
||||
// Fallback for environments without crypto
|
||||
const array = new Uint8Array(size);
|
||||
for (let i = 0; i < size; i++) {
|
||||
array[i] = Math.floor(Math.random() * 256);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Generate random UUID
|
||||
*/
|
||||
export function randomUUID() {
|
||||
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
else if (nodeCrypto && nodeCrypto.randomUUID) {
|
||||
return nodeCrypto.randomUUID();
|
||||
}
|
||||
else {
|
||||
// Fallback UUID generation
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
||||
const r = Math.random() * 16 | 0;
|
||||
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create hash (simplified interface)
|
||||
*/
|
||||
export function createHash(algorithm) {
|
||||
if (nodeCrypto && nodeCrypto.createHash) {
|
||||
return nodeCrypto.createHash(algorithm);
|
||||
}
|
||||
else {
|
||||
// Simple fallback hash for browsers (not cryptographically secure)
|
||||
let hash = 0;
|
||||
const hashObj = {
|
||||
update: (data) => {
|
||||
const text = typeof data === 'string' ? data : new TextDecoder().decode(data);
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
const char = text.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + char;
|
||||
hash = hash & hash; // Convert to 32-bit integer
|
||||
}
|
||||
return hashObj;
|
||||
},
|
||||
digest: (encoding) => {
|
||||
return Math.abs(hash).toString(16);
|
||||
}
|
||||
};
|
||||
return hashObj;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create HMAC
|
||||
*/
|
||||
export function createHmac(algorithm, key) {
|
||||
if (nodeCrypto && nodeCrypto.createHmac) {
|
||||
return nodeCrypto.createHmac(algorithm, key);
|
||||
}
|
||||
else {
|
||||
// Fallback HMAC implementation (simplified)
|
||||
return createHash(algorithm);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* PBKDF2 synchronous
|
||||
*/
|
||||
export function pbkdf2Sync(password, salt, iterations, keylen, digest) {
|
||||
if (nodeCrypto && nodeCrypto.pbkdf2Sync) {
|
||||
return new Uint8Array(nodeCrypto.pbkdf2Sync(password, salt, iterations, keylen, digest));
|
||||
}
|
||||
else {
|
||||
// Simplified fallback (not cryptographically secure)
|
||||
const result = new Uint8Array(keylen);
|
||||
const passwordStr = typeof password === 'string' ? password : new TextDecoder().decode(password);
|
||||
const saltStr = typeof salt === 'string' ? salt : new TextDecoder().decode(salt);
|
||||
let hash = 0;
|
||||
const combined = passwordStr + saltStr;
|
||||
for (let i = 0; i < combined.length; i++) {
|
||||
hash = ((hash << 5) - hash) + combined.charCodeAt(i);
|
||||
hash = hash & hash;
|
||||
}
|
||||
for (let i = 0; i < keylen; i++) {
|
||||
result[i] = (Math.abs(hash + i) % 256);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Scrypt synchronous
|
||||
*/
|
||||
export function scryptSync(password, salt, keylen, options) {
|
||||
if (nodeCrypto && nodeCrypto.scryptSync) {
|
||||
return new Uint8Array(nodeCrypto.scryptSync(password, salt, keylen, options));
|
||||
}
|
||||
else {
|
||||
// Fallback to pbkdf2Sync
|
||||
return pbkdf2Sync(password, salt, 10000, keylen, 'sha256');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create cipher
|
||||
*/
|
||||
export function createCipheriv(algorithm, key, iv) {
|
||||
if (nodeCrypto && nodeCrypto.createCipheriv) {
|
||||
return nodeCrypto.createCipheriv(algorithm, key, iv);
|
||||
}
|
||||
else {
|
||||
// Fallback encryption (XOR-based, not secure)
|
||||
let encrypted = '';
|
||||
return {
|
||||
update: (data, inputEncoding, outputEncoding) => {
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const char = data.charCodeAt(i);
|
||||
const keyByte = key[i % key.length];
|
||||
const ivByte = iv[i % iv.length];
|
||||
encrypted += String.fromCharCode(char ^ keyByte ^ ivByte);
|
||||
}
|
||||
return outputEncoding === 'hex' ? Buffer.from(encrypted, 'binary').toString('hex') : encrypted;
|
||||
},
|
||||
final: (outputEncoding) => {
|
||||
return outputEncoding === 'hex' ? '' : '';
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create decipher
|
||||
*/
|
||||
export function createDecipheriv(algorithm, key, iv) {
|
||||
if (nodeCrypto && nodeCrypto.createDecipheriv) {
|
||||
return nodeCrypto.createDecipheriv(algorithm, key, iv);
|
||||
}
|
||||
else {
|
||||
// Fallback decryption (XOR-based, matches createCipheriv)
|
||||
let decrypted = '';
|
||||
return {
|
||||
update: (data, inputEncoding, outputEncoding) => {
|
||||
const input = inputEncoding === 'hex' ? Buffer.from(data, 'hex').toString('binary') : data;
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
const char = input.charCodeAt(i);
|
||||
const keyByte = key[i % key.length];
|
||||
const ivByte = iv[i % iv.length];
|
||||
decrypted += String.fromCharCode(char ^ keyByte ^ ivByte);
|
||||
}
|
||||
return decrypted;
|
||||
},
|
||||
final: (outputEncoding) => {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Timing safe equal
|
||||
*/
|
||||
export function timingSafeEqual(a, b) {
|
||||
if (nodeCrypto && nodeCrypto.timingSafeEqual) {
|
||||
return nodeCrypto.timingSafeEqual(a, b);
|
||||
}
|
||||
else {
|
||||
// Fallback implementation
|
||||
if (a.length !== b.length)
|
||||
return false;
|
||||
let result = 0;
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
result |= a[i] ^ b[i];
|
||||
}
|
||||
return result === 0;
|
||||
}
|
||||
}
|
||||
export default {
|
||||
randomBytes,
|
||||
randomUUID,
|
||||
createHash,
|
||||
createHmac,
|
||||
pbkdf2Sync,
|
||||
scryptSync,
|
||||
createCipheriv,
|
||||
createDecipheriv,
|
||||
timingSafeEqual
|
||||
};
|
||||
//# sourceMappingURL=crypto.js.map
|
||||
1
dist/universal/crypto.js.map
vendored
Normal file
1
dist/universal/crypto.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
31
dist/universal/events.d.ts
vendored
Normal file
31
dist/universal/events.d.ts
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* Universal Events implementation
|
||||
* Browser: Uses EventTarget API
|
||||
* Node.js: Uses built-in events module
|
||||
*/
|
||||
/**
|
||||
* Universal EventEmitter interface
|
||||
*/
|
||||
export interface UniversalEventEmitter {
|
||||
on(event: string, listener: (...args: any[]) => void): this;
|
||||
off(event: string, listener: (...args: any[]) => void): this;
|
||||
emit(event: string, ...args: any[]): boolean;
|
||||
once(event: string, listener: (...args: any[]) => void): this;
|
||||
removeAllListeners(event?: string): this;
|
||||
listenerCount(event: string): number;
|
||||
}
|
||||
/**
|
||||
* Universal EventEmitter class
|
||||
*/
|
||||
export declare class EventEmitter implements UniversalEventEmitter {
|
||||
private emitter;
|
||||
constructor();
|
||||
on(event: string, listener: (...args: any[]) => void): this;
|
||||
off(event: string, listener: (...args: any[]) => void): this;
|
||||
emit(event: string, ...args: any[]): boolean;
|
||||
once(event: string, listener: (...args: any[]) => void): this;
|
||||
removeAllListeners(event?: string): this;
|
||||
listenerCount(event: string): number;
|
||||
}
|
||||
export { EventEmitter as default };
|
||||
export declare const NodeEventEmitterClass: any;
|
||||
156
dist/universal/events.js
vendored
Normal file
156
dist/universal/events.js
vendored
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
/**
|
||||
* Universal Events implementation
|
||||
* Browser: Uses EventTarget API
|
||||
* Node.js: Uses built-in events module
|
||||
*/
|
||||
import { isBrowser, isNode } from '../utils/environment.js';
|
||||
let nodeEvents = null;
|
||||
// Dynamic import for Node.js events (only in Node.js environment)
|
||||
if (isNode()) {
|
||||
try {
|
||||
nodeEvents = await import('events');
|
||||
}
|
||||
catch {
|
||||
// Ignore import errors in non-Node environments
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Browser implementation using EventTarget
|
||||
*/
|
||||
class BrowserEventEmitter extends EventTarget {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.listeners = new Map();
|
||||
}
|
||||
on(event, listener) {
|
||||
if (!this.listeners.has(event)) {
|
||||
this.listeners.set(event, new Set());
|
||||
}
|
||||
this.listeners.get(event).add(listener);
|
||||
const handler = (e) => {
|
||||
const customEvent = e;
|
||||
listener(...(customEvent.detail || []));
|
||||
};
|
||||
listener.__handler = handler;
|
||||
this.addEventListener(event, handler);
|
||||
return this;
|
||||
}
|
||||
off(event, listener) {
|
||||
const eventListeners = this.listeners.get(event);
|
||||
if (eventListeners) {
|
||||
eventListeners.delete(listener);
|
||||
const handler = listener.__handler;
|
||||
if (handler) {
|
||||
this.removeEventListener(event, handler);
|
||||
delete listener.__handler;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
emit(event, ...args) {
|
||||
const customEvent = new CustomEvent(event, { detail: args });
|
||||
this.dispatchEvent(customEvent);
|
||||
const eventListeners = this.listeners.get(event);
|
||||
return eventListeners ? eventListeners.size > 0 : false;
|
||||
}
|
||||
once(event, listener) {
|
||||
const onceListener = (...args) => {
|
||||
this.off(event, onceListener);
|
||||
listener(...args);
|
||||
};
|
||||
return this.on(event, onceListener);
|
||||
}
|
||||
removeAllListeners(event) {
|
||||
if (event) {
|
||||
const eventListeners = this.listeners.get(event);
|
||||
if (eventListeners) {
|
||||
for (const listener of eventListeners) {
|
||||
this.off(event, listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (const [eventName] of this.listeners) {
|
||||
this.removeAllListeners(eventName);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
listenerCount(event) {
|
||||
const eventListeners = this.listeners.get(event);
|
||||
return eventListeners ? eventListeners.size : 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Node.js implementation using events.EventEmitter
|
||||
*/
|
||||
class NodeEventEmitter {
|
||||
constructor() {
|
||||
this.emitter = new nodeEvents.EventEmitter();
|
||||
}
|
||||
on(event, listener) {
|
||||
this.emitter.on(event, listener);
|
||||
return this;
|
||||
}
|
||||
off(event, listener) {
|
||||
this.emitter.off(event, listener);
|
||||
return this;
|
||||
}
|
||||
emit(event, ...args) {
|
||||
return this.emitter.emit(event, ...args);
|
||||
}
|
||||
once(event, listener) {
|
||||
this.emitter.once(event, listener);
|
||||
return this;
|
||||
}
|
||||
removeAllListeners(event) {
|
||||
this.emitter.removeAllListeners(event);
|
||||
return this;
|
||||
}
|
||||
listenerCount(event) {
|
||||
return this.emitter.listenerCount(event);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Universal EventEmitter class
|
||||
*/
|
||||
export class EventEmitter {
|
||||
constructor() {
|
||||
if (isBrowser()) {
|
||||
this.emitter = new BrowserEventEmitter();
|
||||
}
|
||||
else if (isNode() && nodeEvents) {
|
||||
this.emitter = new NodeEventEmitter();
|
||||
}
|
||||
else {
|
||||
this.emitter = new BrowserEventEmitter();
|
||||
}
|
||||
}
|
||||
on(event, listener) {
|
||||
this.emitter.on(event, listener);
|
||||
return this;
|
||||
}
|
||||
off(event, listener) {
|
||||
this.emitter.off(event, listener);
|
||||
return this;
|
||||
}
|
||||
emit(event, ...args) {
|
||||
return this.emitter.emit(event, ...args);
|
||||
}
|
||||
once(event, listener) {
|
||||
this.emitter.once(event, listener);
|
||||
return this;
|
||||
}
|
||||
removeAllListeners(event) {
|
||||
this.emitter.removeAllListeners(event);
|
||||
return this;
|
||||
}
|
||||
listenerCount(event) {
|
||||
return this.emitter.listenerCount(event);
|
||||
}
|
||||
}
|
||||
// Named export for compatibility
|
||||
export { EventEmitter as default };
|
||||
// Re-export Node.js EventEmitter class if available
|
||||
export const NodeEventEmitterClass = nodeEvents?.EventEmitter || null;
|
||||
//# sourceMappingURL=events.js.map
|
||||
1
dist/universal/events.js.map
vendored
Normal file
1
dist/universal/events.js.map
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/universal/events.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAE3D,IAAI,UAAU,GAAQ,IAAI,CAAA;AAE1B,kEAA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AAY,IAAI,IAAI,CAAA"}
|
||||
102
dist/universal/fs.d.ts
vendored
Normal file
102
dist/universal/fs.d.ts
vendored
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
* Universal File System implementation
|
||||
* Browser: Uses OPFS (Origin Private File System)
|
||||
* Node.js: Uses built-in fs/promises
|
||||
* Serverless: Uses memory-based fallback
|
||||
*/
|
||||
/**
|
||||
* Universal file operations interface
|
||||
*/
|
||||
export interface UniversalFS {
|
||||
readFile(path: string, encoding?: string): Promise<string>;
|
||||
writeFile(path: string, data: string, encoding?: string): Promise<void>;
|
||||
mkdir(path: string, options?: {
|
||||
recursive?: boolean;
|
||||
}): Promise<void>;
|
||||
exists(path: string): Promise<boolean>;
|
||||
readdir(path: string): Promise<string[]>;
|
||||
readdir(path: string, options: {
|
||||
withFileTypes: true;
|
||||
}): Promise<{
|
||||
name: string;
|
||||
isDirectory(): boolean;
|
||||
isFile(): boolean;
|
||||
}[]>;
|
||||
unlink(path: string): Promise<void>;
|
||||
stat(path: string): Promise<{
|
||||
isFile(): boolean;
|
||||
isDirectory(): boolean;
|
||||
}>;
|
||||
access(path: string, mode?: number): Promise<void>;
|
||||
}
|
||||
export declare const readFile: (path: string, encoding?: string) => Promise<string>;
|
||||
export declare const writeFile: (path: string, data: string, encoding?: string) => Promise<void>;
|
||||
export declare const mkdir: (path: string, options?: {
|
||||
recursive?: boolean;
|
||||
}) => Promise<void>;
|
||||
export declare const exists: (path: string) => Promise<boolean>;
|
||||
export declare const readdir: {
|
||||
(path: string): Promise<string[]>;
|
||||
(path: string, options: {
|
||||
withFileTypes: true;
|
||||
}): Promise<{
|
||||
name: string;
|
||||
isDirectory(): boolean;
|
||||
isFile(): boolean;
|
||||
}[]>;
|
||||
};
|
||||
export declare const unlink: (path: string) => Promise<void>;
|
||||
export declare const stat: (path: string) => Promise<{
|
||||
isFile(): boolean;
|
||||
isDirectory(): boolean;
|
||||
}>;
|
||||
export declare const access: (path: string, mode?: number) => Promise<void>;
|
||||
declare const _default: {
|
||||
readFile: (path: string, encoding?: string) => Promise<string>;
|
||||
writeFile: (path: string, data: string, encoding?: string) => Promise<void>;
|
||||
mkdir: (path: string, options?: {
|
||||
recursive?: boolean;
|
||||
}) => Promise<void>;
|
||||
exists: (path: string) => Promise<boolean>;
|
||||
readdir: {
|
||||
(path: string): Promise<string[]>;
|
||||
(path: string, options: {
|
||||
withFileTypes: true;
|
||||
}): Promise<{
|
||||
name: string;
|
||||
isDirectory(): boolean;
|
||||
isFile(): boolean;
|
||||
}[]>;
|
||||
};
|
||||
unlink: (path: string) => Promise<void>;
|
||||
stat: (path: string) => Promise<{
|
||||
isFile(): boolean;
|
||||
isDirectory(): boolean;
|
||||
}>;
|
||||
access: (path: string, mode?: number) => Promise<void>;
|
||||
};
|
||||
export default _default;
|
||||
export declare const promises: {
|
||||
readFile: (path: string, encoding?: string) => Promise<string>;
|
||||
writeFile: (path: string, data: string, encoding?: string) => Promise<void>;
|
||||
mkdir: (path: string, options?: {
|
||||
recursive?: boolean;
|
||||
}) => Promise<void>;
|
||||
exists: (path: string) => Promise<boolean>;
|
||||
readdir: {
|
||||
(path: string): Promise<string[]>;
|
||||
(path: string, options: {
|
||||
withFileTypes: true;
|
||||
}): Promise<{
|
||||
name: string;
|
||||
isDirectory(): boolean;
|
||||
isFile(): boolean;
|
||||
}[]>;
|
||||
};
|
||||
unlink: (path: string) => Promise<void>;
|
||||
stat: (path: string) => Promise<{
|
||||
isFile(): boolean;
|
||||
isDirectory(): boolean;
|
||||
}>;
|
||||
access: (path: string, mode?: number) => Promise<void>;
|
||||
};
|
||||
304
dist/universal/fs.js
vendored
Normal file
304
dist/universal/fs.js
vendored
Normal file
|
|
@ -0,0 +1,304 @@
|
|||
/**
|
||||
* Universal File System implementation
|
||||
* Browser: Uses OPFS (Origin Private File System)
|
||||
* Node.js: Uses built-in fs/promises
|
||||
* Serverless: Uses memory-based fallback
|
||||
*/
|
||||
import { isBrowser, isNode } from '../utils/environment.js';
|
||||
let nodeFs = null;
|
||||
// Dynamic import for Node.js fs (only in Node.js environment)
|
||||
if (isNode()) {
|
||||
try {
|
||||
nodeFs = await import('fs/promises');
|
||||
}
|
||||
catch {
|
||||
// Ignore import errors in non-Node environments
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Browser implementation using OPFS
|
||||
*/
|
||||
class BrowserFS {
|
||||
async getRoot() {
|
||||
if ('storage' in navigator && 'getDirectory' in navigator.storage) {
|
||||
return await navigator.storage.getDirectory();
|
||||
}
|
||||
throw new Error('OPFS not supported in this browser');
|
||||
}
|
||||
async getFileHandle(path, create = false) {
|
||||
const root = await this.getRoot();
|
||||
const parts = path.split('/').filter(p => p);
|
||||
let dir = root;
|
||||
for (let i = 0; i < parts.length - 1; i++) {
|
||||
dir = await dir.getDirectoryHandle(parts[i], { create });
|
||||
}
|
||||
const fileName = parts[parts.length - 1];
|
||||
return await dir.getFileHandle(fileName, { create });
|
||||
}
|
||||
async getDirHandle(path, create = false) {
|
||||
const root = await this.getRoot();
|
||||
const parts = path.split('/').filter(p => p);
|
||||
let dir = root;
|
||||
for (const part of parts) {
|
||||
dir = await dir.getDirectoryHandle(part, { create });
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
async readFile(path, encoding) {
|
||||
try {
|
||||
const fileHandle = await this.getFileHandle(path);
|
||||
const file = await fileHandle.getFile();
|
||||
return await file.text();
|
||||
}
|
||||
catch (error) {
|
||||
throw new Error(`File not found: ${path}`);
|
||||
}
|
||||
}
|
||||
async writeFile(path, data, encoding) {
|
||||
const fileHandle = await this.getFileHandle(path, true);
|
||||
const writable = await fileHandle.createWritable();
|
||||
await writable.write(data);
|
||||
await writable.close();
|
||||
}
|
||||
async mkdir(path, options = { recursive: true }) {
|
||||
await this.getDirHandle(path, true);
|
||||
}
|
||||
async exists(path) {
|
||||
try {
|
||||
await this.getFileHandle(path);
|
||||
return true;
|
||||
}
|
||||
catch {
|
||||
try {
|
||||
await this.getDirHandle(path);
|
||||
return true;
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
async readdir(path, options) {
|
||||
const dir = await this.getDirHandle(path);
|
||||
if (options?.withFileTypes) {
|
||||
const entries = [];
|
||||
for await (const [name, handle] of dir.entries()) {
|
||||
entries.push({
|
||||
name,
|
||||
isDirectory: () => handle.kind === 'directory',
|
||||
isFile: () => handle.kind === 'file'
|
||||
});
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
else {
|
||||
const entries = [];
|
||||
for await (const [name] of dir.entries()) {
|
||||
entries.push(name);
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
async unlink(path) {
|
||||
const parts = path.split('/').filter(p => p);
|
||||
const fileName = parts.pop();
|
||||
const dirPath = parts.join('/');
|
||||
if (dirPath) {
|
||||
const dir = await this.getDirHandle(dirPath);
|
||||
await dir.removeEntry(fileName);
|
||||
}
|
||||
else {
|
||||
const root = await this.getRoot();
|
||||
await root.removeEntry(fileName);
|
||||
}
|
||||
}
|
||||
async stat(path) {
|
||||
try {
|
||||
await this.getFileHandle(path);
|
||||
return { isFile: () => true, isDirectory: () => false };
|
||||
}
|
||||
catch {
|
||||
try {
|
||||
await this.getDirHandle(path);
|
||||
return { isFile: () => false, isDirectory: () => true };
|
||||
}
|
||||
catch {
|
||||
throw new Error(`Path not found: ${path}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
async access(path, mode) {
|
||||
const exists = await this.exists(path);
|
||||
if (!exists) {
|
||||
throw new Error(`ENOENT: no such file or directory, access '${path}'`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Node.js implementation using fs/promises
|
||||
*/
|
||||
class NodeFS {
|
||||
async readFile(path, encoding = 'utf-8') {
|
||||
return await nodeFs.readFile(path, encoding);
|
||||
}
|
||||
async writeFile(path, data, encoding = 'utf-8') {
|
||||
await nodeFs.writeFile(path, data, encoding);
|
||||
}
|
||||
async mkdir(path, options = { recursive: true }) {
|
||||
await nodeFs.mkdir(path, options);
|
||||
}
|
||||
async exists(path) {
|
||||
try {
|
||||
await nodeFs.access(path);
|
||||
return true;
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
async readdir(path, options) {
|
||||
if (options?.withFileTypes) {
|
||||
return await nodeFs.readdir(path, { withFileTypes: true });
|
||||
}
|
||||
return await nodeFs.readdir(path);
|
||||
}
|
||||
async unlink(path) {
|
||||
await nodeFs.unlink(path);
|
||||
}
|
||||
async stat(path) {
|
||||
const stats = await nodeFs.stat(path);
|
||||
return {
|
||||
isFile: () => stats.isFile(),
|
||||
isDirectory: () => stats.isDirectory()
|
||||
};
|
||||
}
|
||||
async access(path, mode) {
|
||||
await nodeFs.access(path, mode);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Memory-based fallback for serverless/edge environments
|
||||
*/
|
||||
class MemoryFS {
|
||||
constructor() {
|
||||
this.files = new Map();
|
||||
this.dirs = new Set();
|
||||
}
|
||||
async readFile(path, encoding) {
|
||||
const content = this.files.get(path);
|
||||
if (content === undefined) {
|
||||
throw new Error(`File not found: ${path}`);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
async writeFile(path, data, encoding) {
|
||||
this.files.set(path, data);
|
||||
// Ensure parent directories exist
|
||||
const parts = path.split('/').slice(0, -1);
|
||||
for (let i = 1; i <= parts.length; i++) {
|
||||
this.dirs.add(parts.slice(0, i).join('/'));
|
||||
}
|
||||
}
|
||||
async mkdir(path, options = { recursive: true }) {
|
||||
this.dirs.add(path);
|
||||
if (options.recursive) {
|
||||
const parts = path.split('/');
|
||||
for (let i = 1; i <= parts.length; i++) {
|
||||
this.dirs.add(parts.slice(0, i).join('/'));
|
||||
}
|
||||
}
|
||||
}
|
||||
async exists(path) {
|
||||
return this.files.has(path) || this.dirs.has(path);
|
||||
}
|
||||
async readdir(path, options) {
|
||||
const entries = new Set();
|
||||
const pathPrefix = path + '/';
|
||||
for (const filePath of this.files.keys()) {
|
||||
if (filePath.startsWith(pathPrefix)) {
|
||||
const relativePath = filePath.slice(pathPrefix.length);
|
||||
const firstSegment = relativePath.split('/')[0];
|
||||
entries.add(firstSegment);
|
||||
}
|
||||
}
|
||||
for (const dirPath of this.dirs) {
|
||||
if (dirPath.startsWith(pathPrefix)) {
|
||||
const relativePath = dirPath.slice(pathPrefix.length);
|
||||
const firstSegment = relativePath.split('/')[0];
|
||||
if (firstSegment)
|
||||
entries.add(firstSegment);
|
||||
}
|
||||
}
|
||||
if (options?.withFileTypes) {
|
||||
return Array.from(entries).map(name => ({
|
||||
name,
|
||||
isDirectory: () => this.dirs.has(path + '/' + name),
|
||||
isFile: () => this.files.has(path + '/' + name)
|
||||
}));
|
||||
}
|
||||
return Array.from(entries);
|
||||
}
|
||||
async unlink(path) {
|
||||
this.files.delete(path);
|
||||
}
|
||||
async stat(path) {
|
||||
const isFile = this.files.has(path);
|
||||
const isDir = this.dirs.has(path);
|
||||
if (!isFile && !isDir) {
|
||||
throw new Error(`Path not found: ${path}`);
|
||||
}
|
||||
return {
|
||||
isFile: () => isFile,
|
||||
isDirectory: () => isDir
|
||||
};
|
||||
}
|
||||
async access(path, mode) {
|
||||
const exists = await this.exists(path);
|
||||
if (!exists) {
|
||||
throw new Error(`ENOENT: no such file or directory, access '${path}'`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Create the appropriate filesystem implementation
|
||||
let fsImpl;
|
||||
if (isBrowser()) {
|
||||
fsImpl = new BrowserFS();
|
||||
}
|
||||
else if (isNode() && nodeFs) {
|
||||
fsImpl = new NodeFS();
|
||||
}
|
||||
else {
|
||||
fsImpl = new MemoryFS();
|
||||
}
|
||||
// Export the filesystem operations
|
||||
export const readFile = fsImpl.readFile.bind(fsImpl);
|
||||
export const writeFile = fsImpl.writeFile.bind(fsImpl);
|
||||
export const mkdir = fsImpl.mkdir.bind(fsImpl);
|
||||
export const exists = fsImpl.exists.bind(fsImpl);
|
||||
export const readdir = fsImpl.readdir.bind(fsImpl);
|
||||
export const unlink = fsImpl.unlink.bind(fsImpl);
|
||||
export const stat = fsImpl.stat.bind(fsImpl);
|
||||
export const access = fsImpl.access.bind(fsImpl);
|
||||
// Default export with promises namespace compatibility
|
||||
export default {
|
||||
readFile,
|
||||
writeFile,
|
||||
mkdir,
|
||||
exists,
|
||||
readdir,
|
||||
unlink,
|
||||
stat,
|
||||
access
|
||||
};
|
||||
// Named export for fs/promises compatibility
|
||||
export const promises = {
|
||||
readFile,
|
||||
writeFile,
|
||||
mkdir,
|
||||
exists,
|
||||
readdir,
|
||||
unlink,
|
||||
stat,
|
||||
access
|
||||
};
|
||||
//# sourceMappingURL=fs.js.map
|
||||
1
dist/universal/fs.js.map
vendored
Normal file
1
dist/universal/fs.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
16
dist/universal/index.d.ts
vendored
Normal file
16
dist/universal/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* Universal adapters for cross-environment compatibility
|
||||
* Provides consistent APIs across Browser, Node.js, and Serverless environments
|
||||
*/
|
||||
export * from './uuid.js';
|
||||
export { default as uuid } from './uuid.js';
|
||||
export * from './crypto.js';
|
||||
export { default as crypto } from './crypto.js';
|
||||
export * from './fs.js';
|
||||
export { default as fs } from './fs.js';
|
||||
export * from './path.js';
|
||||
export { default as path } from './path.js';
|
||||
export * from './events.js';
|
||||
export { default as events } from './events.js';
|
||||
export { v4 as uuidv4 } from './uuid.js';
|
||||
export { EventEmitter } from './events.js';
|
||||
23
dist/universal/index.js
vendored
Normal file
23
dist/universal/index.js
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* Universal adapters for cross-environment compatibility
|
||||
* Provides consistent APIs across Browser, Node.js, and Serverless environments
|
||||
*/
|
||||
// UUID adapter
|
||||
export * from './uuid.js';
|
||||
export { default as uuid } from './uuid.js';
|
||||
// Crypto adapter
|
||||
export * from './crypto.js';
|
||||
export { default as crypto } from './crypto.js';
|
||||
// File system adapter
|
||||
export * from './fs.js';
|
||||
export { default as fs } from './fs.js';
|
||||
// Path adapter
|
||||
export * from './path.js';
|
||||
export { default as path } from './path.js';
|
||||
// Events adapter
|
||||
export * from './events.js';
|
||||
export { default as events } from './events.js';
|
||||
// Convenience re-exports for common patterns
|
||||
export { v4 as uuidv4 } from './uuid.js';
|
||||
export { EventEmitter } from './events.js';
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
dist/universal/index.js.map
vendored
Normal file
1
dist/universal/index.js.map
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/universal/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAe;AACf,cAAc,WAAW,CAAA;AACzB,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAA;AAE3C,mBAAmB;AACnB,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAE/C,sBAAsB;AACtB,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,SAAS,CAAA;AAEvC,eAAe;AACf,cAAc,WAAW,CAAA;AACzB,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAA;AAE3C,iBAAiB;AACjB,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AAE/C,6CAA6C;AAC7C,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA"}
|
||||
51
dist/universal/path.d.ts
vendored
Normal file
51
dist/universal/path.d.ts
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Universal Path implementation
|
||||
* Browser: Manual path operations
|
||||
* Node.js: Uses built-in path module
|
||||
*/
|
||||
/**
|
||||
* Universal path operations
|
||||
*/
|
||||
export declare function join(...paths: string[]): string;
|
||||
export declare function dirname(path: string): string;
|
||||
export declare function basename(path: string, ext?: string): string;
|
||||
export declare function extname(path: string): string;
|
||||
export declare function resolve(...paths: string[]): string;
|
||||
export declare function relative(from: string, to: string): string;
|
||||
export declare function isAbsolute(path: string): boolean;
|
||||
export declare const sep = "/";
|
||||
export declare const delimiter = ":";
|
||||
export declare const posix: {
|
||||
join: typeof join;
|
||||
dirname: typeof dirname;
|
||||
basename: typeof basename;
|
||||
extname: typeof extname;
|
||||
resolve: typeof resolve;
|
||||
relative: typeof relative;
|
||||
isAbsolute: typeof isAbsolute;
|
||||
sep: string;
|
||||
delimiter: string;
|
||||
};
|
||||
declare const _default: {
|
||||
join: typeof join;
|
||||
dirname: typeof dirname;
|
||||
basename: typeof basename;
|
||||
extname: typeof extname;
|
||||
resolve: typeof resolve;
|
||||
relative: typeof relative;
|
||||
isAbsolute: typeof isAbsolute;
|
||||
sep: string;
|
||||
delimiter: string;
|
||||
posix: {
|
||||
join: typeof join;
|
||||
dirname: typeof dirname;
|
||||
basename: typeof basename;
|
||||
extname: typeof extname;
|
||||
resolve: typeof resolve;
|
||||
relative: typeof relative;
|
||||
isAbsolute: typeof isAbsolute;
|
||||
sep: string;
|
||||
delimiter: string;
|
||||
};
|
||||
};
|
||||
export default _default;
|
||||
161
dist/universal/path.js
vendored
Normal file
161
dist/universal/path.js
vendored
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
/**
|
||||
* Universal Path implementation
|
||||
* Browser: Manual path operations
|
||||
* Node.js: Uses built-in path module
|
||||
*/
|
||||
import { isNode } from '../utils/environment.js';
|
||||
let nodePath = null;
|
||||
// Dynamic import for Node.js path (only in Node.js environment)
|
||||
if (isNode()) {
|
||||
try {
|
||||
nodePath = await import('path');
|
||||
}
|
||||
catch {
|
||||
// Ignore import errors in non-Node environments
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Universal path operations
|
||||
*/
|
||||
export function join(...paths) {
|
||||
if (nodePath) {
|
||||
return nodePath.join(...paths);
|
||||
}
|
||||
// Browser fallback implementation
|
||||
const parts = [];
|
||||
for (const path of paths) {
|
||||
if (path) {
|
||||
parts.push(...path.split('/').filter(p => p));
|
||||
}
|
||||
}
|
||||
return parts.join('/');
|
||||
}
|
||||
export function dirname(path) {
|
||||
if (nodePath) {
|
||||
return nodePath.dirname(path);
|
||||
}
|
||||
// Browser fallback implementation
|
||||
const parts = path.split('/').filter(p => p);
|
||||
if (parts.length <= 1)
|
||||
return '.';
|
||||
return parts.slice(0, -1).join('/');
|
||||
}
|
||||
export function basename(path, ext) {
|
||||
if (nodePath) {
|
||||
return nodePath.basename(path, ext);
|
||||
}
|
||||
// Browser fallback implementation
|
||||
const parts = path.split('/');
|
||||
let name = parts[parts.length - 1];
|
||||
if (ext && name.endsWith(ext)) {
|
||||
name = name.slice(0, -ext.length);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
export function extname(path) {
|
||||
if (nodePath) {
|
||||
return nodePath.extname(path);
|
||||
}
|
||||
// Browser fallback implementation
|
||||
const name = basename(path);
|
||||
const lastDot = name.lastIndexOf('.');
|
||||
return lastDot === -1 ? '' : name.slice(lastDot);
|
||||
}
|
||||
export function resolve(...paths) {
|
||||
if (nodePath) {
|
||||
return nodePath.resolve(...paths);
|
||||
}
|
||||
// Browser fallback implementation
|
||||
let resolved = '';
|
||||
let resolvedAbsolute = false;
|
||||
for (let i = paths.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
||||
const path = i >= 0 ? paths[i] : '/';
|
||||
if (!path)
|
||||
continue;
|
||||
resolved = path + '/' + resolved;
|
||||
resolvedAbsolute = path.charAt(0) === '/';
|
||||
}
|
||||
// Normalize the path
|
||||
resolved = normalizeArray(resolved.split('/').filter(p => p), !resolvedAbsolute).join('/');
|
||||
return (resolvedAbsolute ? '/' : '') + resolved;
|
||||
}
|
||||
export function relative(from, to) {
|
||||
if (nodePath) {
|
||||
return nodePath.relative(from, to);
|
||||
}
|
||||
// Browser fallback implementation
|
||||
const fromParts = resolve(from).split('/').filter(p => p);
|
||||
const toParts = resolve(to).split('/').filter(p => p);
|
||||
let commonLength = 0;
|
||||
for (let i = 0; i < Math.min(fromParts.length, toParts.length); i++) {
|
||||
if (fromParts[i] === toParts[i]) {
|
||||
commonLength++;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
const upCount = fromParts.length - commonLength;
|
||||
const upParts = new Array(upCount).fill('..');
|
||||
const downParts = toParts.slice(commonLength);
|
||||
return [...upParts, ...downParts].join('/');
|
||||
}
|
||||
export function isAbsolute(path) {
|
||||
if (nodePath) {
|
||||
return nodePath.isAbsolute(path);
|
||||
}
|
||||
// Browser fallback implementation
|
||||
return path.charAt(0) === '/';
|
||||
}
|
||||
/**
|
||||
* Normalize array helper function
|
||||
*/
|
||||
function normalizeArray(parts, allowAboveRoot) {
|
||||
const res = [];
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const p = parts[i];
|
||||
if (!p || p === '.')
|
||||
continue;
|
||||
if (p === '..') {
|
||||
if (res.length && res[res.length - 1] !== '..') {
|
||||
res.pop();
|
||||
}
|
||||
else if (allowAboveRoot) {
|
||||
res.push('..');
|
||||
}
|
||||
}
|
||||
else {
|
||||
res.push(p);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
// Path separator (always use forward slash for consistency)
|
||||
export const sep = '/';
|
||||
export const delimiter = ':';
|
||||
// POSIX path object for compatibility
|
||||
export const posix = {
|
||||
join,
|
||||
dirname,
|
||||
basename,
|
||||
extname,
|
||||
resolve,
|
||||
relative,
|
||||
isAbsolute,
|
||||
sep: '/',
|
||||
delimiter: ':'
|
||||
};
|
||||
// Default export
|
||||
export default {
|
||||
join,
|
||||
dirname,
|
||||
basename,
|
||||
extname,
|
||||
resolve,
|
||||
relative,
|
||||
isAbsolute,
|
||||
sep,
|
||||
delimiter,
|
||||
posix
|
||||
};
|
||||
//# sourceMappingURL=path.js.map
|
||||
1
dist/universal/path.js.map
vendored
Normal file
1
dist/universal/path.js.map
vendored
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AAI,CAAC,KAAK,IAAI,EAAE,CAAC;YACf,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC/C,GAAG,CAAC,GAAG,EAAE,CAAA;YACX,CAAC;iBAAM,IAAI,cAAc,EAAE,CAAC;gBAC1B,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAChB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACb,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,4DAA4D;AAC5D,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAA;AACtB,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAA;AAE5B,sCAAsC;AACtC,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,IAAI;IACJ,OAAO;IACP,QAAQ;IACR,OAAO;IACP,OAAO;IACP,QAAQ;IACR,UAAU;IACV,GAAG,EAAE,GAAG;IACR,SAAS,EAAE,GAAG;CACf,CAAA;AAED,iBAAiB;AACjB,eAAe;IACb,IAAI;IACJ,OAAO;IACP,QAAQ;IACR,OAAO;IACP,OAAO;IACP,QAAQ;IACR,UAAU;IACV,GAAG;IACH,SAAS;IACT,KAAK;CACN,CAAA"}
|
||||
10
dist/universal/uuid.d.ts
vendored
Normal file
10
dist/universal/uuid.d.ts
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* Universal UUID implementation
|
||||
* Works in all environments: Browser, Node.js, Serverless
|
||||
*/
|
||||
export declare function v4(): string;
|
||||
export { v4 as uuidv4 };
|
||||
declare const _default: {
|
||||
v4: typeof v4;
|
||||
};
|
||||
export default _default;
|
||||
21
dist/universal/uuid.js
vendored
Normal file
21
dist/universal/uuid.js
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* Universal UUID implementation
|
||||
* Works in all environments: Browser, Node.js, Serverless
|
||||
*/
|
||||
export function v4() {
|
||||
// Use crypto.randomUUID if available (Node.js 19+, modern browsers)
|
||||
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
// Fallback implementation for older environments
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
||||
const r = Math.random() * 16 | 0;
|
||||
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
// Named export to match uuid package API
|
||||
export { v4 as uuidv4 };
|
||||
// Default export for convenience
|
||||
export default { v4 };
|
||||
//# sourceMappingURL=uuid.js.map
|
||||
1
dist/universal/uuid.js.map
vendored
Normal file
1
dist/universal/uuid.js.map
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../src/universal/uuid.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,UAAU,EAAE;IAChB,oEAAoE;IACpE,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACvD,OAAO,MAAM,CAAC,UAAU,EAAE,CAAA;IAC5B,CAAC;IAED,iDAAiD;IACjD,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;QACnE,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;QAChC,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAA;QACzC,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IACvB,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,yCAAyC;AACzC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,CAAA;AAEvB,iCAAiC;AACjC,eAAe,EAAE,EAAE,EAAE,CAAA"}
|
||||
Loading…
Add table
Add a link
Reference in a new issue