@soulcraft/brainy 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -3
- package/README.md +427 -111
- package/bin/brainy.js +340 -62
- package/dist/api/ConfigAPI.d.ts +67 -0
- package/dist/api/ConfigAPI.js +166 -0
- package/dist/api/DataAPI.d.ts +123 -0
- package/dist/api/DataAPI.js +391 -0
- package/dist/api/SecurityAPI.d.ts +50 -0
- package/dist/api/SecurityAPI.js +139 -0
- package/dist/api/UniversalImportAPI.d.ts +134 -0
- package/dist/api/UniversalImportAPI.js +615 -0
- package/dist/augmentationManager.js +12 -7
- package/dist/augmentationPipeline.d.ts +0 -61
- package/dist/augmentationPipeline.js +0 -87
- package/dist/augmentationRegistry.d.ts +1 -1
- package/dist/augmentationRegistry.js +1 -1
- package/dist/augmentations/apiServerAugmentation.d.ts +27 -1
- package/dist/augmentations/apiServerAugmentation.js +290 -9
- package/dist/augmentations/auditLogAugmentation.d.ts +109 -0
- package/dist/augmentations/auditLogAugmentation.js +358 -0
- package/dist/augmentations/batchProcessingAugmentation.d.ts +3 -2
- package/dist/augmentations/batchProcessingAugmentation.js +123 -22
- package/dist/augmentations/brainyAugmentation.d.ts +142 -8
- package/dist/augmentations/brainyAugmentation.js +179 -2
- package/dist/augmentations/cacheAugmentation.d.ts +8 -5
- package/dist/augmentations/cacheAugmentation.js +116 -17
- package/dist/augmentations/conduitAugmentations.d.ts +2 -2
- package/dist/augmentations/conduitAugmentations.js +2 -2
- package/dist/augmentations/configResolver.d.ts +122 -0
- package/dist/augmentations/configResolver.js +440 -0
- package/dist/augmentations/connectionPoolAugmentation.d.ts +3 -1
- package/dist/augmentations/connectionPoolAugmentation.js +37 -12
- package/dist/augmentations/defaultAugmentations.d.ts +14 -10
- package/dist/augmentations/defaultAugmentations.js +16 -11
- package/dist/augmentations/discovery/catalogDiscovery.d.ts +142 -0
- package/dist/augmentations/discovery/catalogDiscovery.js +249 -0
- package/dist/augmentations/discovery/localDiscovery.d.ts +84 -0
- package/dist/augmentations/discovery/localDiscovery.js +246 -0
- package/dist/augmentations/discovery/runtimeLoader.d.ts +97 -0
- package/dist/augmentations/discovery/runtimeLoader.js +337 -0
- package/dist/augmentations/discovery.d.ts +152 -0
- package/dist/augmentations/discovery.js +441 -0
- package/dist/augmentations/display/cache.d.ts +130 -0
- package/dist/augmentations/display/cache.js +319 -0
- package/dist/augmentations/display/fieldPatterns.d.ts +52 -0
- package/dist/augmentations/display/fieldPatterns.js +393 -0
- package/dist/augmentations/display/iconMappings.d.ts +57 -0
- package/dist/augmentations/display/iconMappings.js +68 -0
- package/dist/augmentations/display/intelligentComputation.d.ts +109 -0
- package/dist/augmentations/display/intelligentComputation.js +462 -0
- package/dist/augmentations/display/types.d.ts +203 -0
- package/dist/augmentations/display/types.js +7 -0
- package/dist/augmentations/entityRegistryAugmentation.d.ts +3 -1
- package/dist/augmentations/entityRegistryAugmentation.js +5 -1
- package/dist/augmentations/indexAugmentation.d.ts +5 -3
- package/dist/augmentations/indexAugmentation.js +5 -2
- package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +24 -7
- package/dist/augmentations/intelligentVerbScoringAugmentation.js +111 -27
- package/dist/augmentations/manifest.d.ts +176 -0
- package/dist/augmentations/manifest.js +8 -0
- package/dist/augmentations/marketplace/AugmentationMarketplace.d.ts +168 -0
- package/dist/augmentations/marketplace/AugmentationMarketplace.js +329 -0
- package/dist/augmentations/marketplace/cli.d.ts +47 -0
- package/dist/augmentations/marketplace/cli.js +265 -0
- package/dist/augmentations/metricsAugmentation.d.ts +3 -3
- package/dist/augmentations/metricsAugmentation.js +2 -2
- package/dist/augmentations/monitoringAugmentation.d.ts +3 -3
- package/dist/augmentations/monitoringAugmentation.js +2 -2
- package/dist/augmentations/neuralImport.d.ts +1 -1
- package/dist/augmentations/neuralImport.js +4 -4
- package/dist/augmentations/rateLimitAugmentation.d.ts +82 -0
- package/dist/augmentations/rateLimitAugmentation.js +321 -0
- package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +2 -2
- package/dist/augmentations/requestDeduplicatorAugmentation.js +1 -1
- package/dist/augmentations/storageAugmentation.d.ts +1 -1
- package/dist/augmentations/storageAugmentation.js +2 -2
- package/dist/augmentations/storageAugmentations.d.ts +37 -8
- package/dist/augmentations/storageAugmentations.js +204 -15
- package/dist/augmentations/synapseAugmentation.d.ts +1 -1
- package/dist/augmentations/synapseAugmentation.js +35 -16
- package/dist/augmentations/typeMatching/brainyTypes.d.ts +83 -0
- package/dist/augmentations/typeMatching/brainyTypes.js +425 -0
- package/dist/augmentations/typeMatching/intelligentTypeMatcher.d.ts +39 -59
- package/dist/augmentations/typeMatching/intelligentTypeMatcher.js +103 -389
- package/dist/augmentations/universalDisplayAugmentation.d.ts +191 -0
- package/dist/augmentations/universalDisplayAugmentation.js +371 -0
- package/dist/brainy-unified.d.ts +106 -0
- package/dist/brainy-unified.js +327 -0
- package/dist/brainy.d.ts +277 -0
- package/dist/brainy.js +1241 -0
- package/dist/brainyData.d.ts +56 -111
- package/dist/brainyData.js +912 -756
- package/dist/brainyDataV3.d.ts +186 -0
- package/dist/brainyDataV3.js +337 -0
- package/dist/config/distributedPresets-new.d.ts +118 -0
- package/dist/config/distributedPresets-new.js +318 -0
- package/dist/config/distributedPresets.d.ts +118 -0
- package/dist/config/distributedPresets.js +318 -0
- package/dist/config/extensibleConfig.d.ts +99 -0
- package/dist/config/extensibleConfig.js +268 -0
- package/dist/config/index.d.ts +17 -0
- package/dist/config/index.js +35 -0
- package/dist/config/modelAutoConfig.d.ts +32 -0
- package/dist/config/modelAutoConfig.js +139 -0
- package/dist/config/modelPrecisionManager.d.ts +42 -0
- package/dist/config/modelPrecisionManager.js +98 -0
- package/dist/config/sharedConfigManager.d.ts +67 -0
- package/dist/config/sharedConfigManager.js +215 -0
- package/dist/config/storageAutoConfig.d.ts +41 -0
- package/dist/config/storageAutoConfig.js +328 -0
- package/dist/config/zeroConfig.d.ts +68 -0
- package/dist/config/zeroConfig.js +301 -0
- package/dist/cortex/backupRestore.d.ts +2 -2
- package/dist/cortex/backupRestore.js +85 -27
- package/dist/cortex/healthCheck.d.ts +2 -2
- package/dist/cortex/neuralImport.d.ts +2 -2
- package/dist/cortex/neuralImport.js +18 -13
- package/dist/cortex/performanceMonitor.d.ts +2 -2
- package/dist/critical/model-guardian.d.ts +4 -0
- package/dist/critical/model-guardian.js +31 -11
- package/dist/demo.d.ts +4 -4
- package/dist/demo.js +7 -7
- package/dist/distributed/cacheSync.d.ts +112 -0
- package/dist/distributed/cacheSync.js +265 -0
- package/dist/distributed/coordinator.d.ts +193 -0
- package/dist/distributed/coordinator.js +548 -0
- package/dist/distributed/httpTransport.d.ts +120 -0
- package/dist/distributed/httpTransport.js +446 -0
- package/dist/distributed/index.d.ts +8 -0
- package/dist/distributed/index.js +5 -0
- package/dist/distributed/networkTransport.d.ts +132 -0
- package/dist/distributed/networkTransport.js +633 -0
- package/dist/distributed/queryPlanner.d.ts +104 -0
- package/dist/distributed/queryPlanner.js +327 -0
- package/dist/distributed/readWriteSeparation.d.ts +134 -0
- package/dist/distributed/readWriteSeparation.js +350 -0
- package/dist/distributed/shardManager.d.ts +114 -0
- package/dist/distributed/shardManager.js +357 -0
- package/dist/distributed/shardMigration.d.ts +110 -0
- package/dist/distributed/shardMigration.js +289 -0
- package/dist/distributed/storageDiscovery.d.ts +160 -0
- package/dist/distributed/storageDiscovery.js +551 -0
- package/dist/embeddings/CachedEmbeddings.d.ts +40 -0
- package/dist/embeddings/CachedEmbeddings.js +146 -0
- package/dist/embeddings/EmbeddingManager.d.ts +102 -0
- package/dist/embeddings/EmbeddingManager.js +291 -0
- package/dist/embeddings/SingletonModelManager.d.ts +95 -0
- package/dist/embeddings/SingletonModelManager.js +220 -0
- package/dist/embeddings/index.d.ts +12 -0
- package/dist/embeddings/index.js +16 -0
- package/dist/embeddings/lightweight-embedder.d.ts +0 -1
- package/dist/embeddings/lightweight-embedder.js +4 -12
- package/dist/embeddings/model-manager.d.ts +11 -0
- package/dist/embeddings/model-manager.js +43 -7
- package/dist/embeddings/universal-memory-manager.d.ts +1 -1
- package/dist/embeddings/universal-memory-manager.js +27 -67
- package/dist/embeddings/worker-embedding.js +4 -8
- package/dist/errors/brainyError.d.ts +5 -1
- package/dist/errors/brainyError.js +12 -0
- package/dist/examples/basicUsage.js +7 -4
- package/dist/graph/graphAdjacencyIndex.d.ts +96 -0
- package/dist/graph/graphAdjacencyIndex.js +288 -0
- package/dist/graph/pathfinding.js +4 -2
- package/dist/hnsw/scaledHNSWSystem.js +11 -2
- package/dist/importManager.js +8 -5
- package/dist/index.d.ts +17 -22
- package/dist/index.js +37 -23
- package/dist/mcp/brainyMCPAdapter.d.ts +4 -4
- package/dist/mcp/brainyMCPAdapter.js +5 -5
- package/dist/mcp/brainyMCPService.d.ts +3 -3
- package/dist/mcp/brainyMCPService.js +3 -11
- package/dist/mcp/mcpAugmentationToolset.js +20 -30
- package/dist/neural/embeddedPatterns.d.ts +1 -1
- package/dist/neural/embeddedPatterns.js +2 -2
- package/dist/neural/entityExtractor.d.ts +65 -0
- package/dist/neural/entityExtractor.js +316 -0
- package/dist/neural/improvedNeuralAPI.d.ts +357 -0
- package/dist/neural/improvedNeuralAPI.js +2628 -0
- package/dist/neural/naturalLanguageProcessor.d.ts +155 -10
- package/dist/neural/naturalLanguageProcessor.js +941 -66
- package/dist/neural/naturalLanguageProcessorStatic.d.ts +2 -2
- package/dist/neural/naturalLanguageProcessorStatic.js +3 -3
- package/dist/neural/neuralAPI.js +8 -2
- package/dist/neural/patternLibrary.d.ts +57 -3
- package/dist/neural/patternLibrary.js +348 -13
- package/dist/neural/staticPatternMatcher.d.ts +2 -2
- package/dist/neural/staticPatternMatcher.js +2 -2
- package/dist/neural/types.d.ts +287 -0
- package/dist/neural/types.js +24 -0
- package/dist/shared/default-augmentations.d.ts +3 -3
- package/dist/shared/default-augmentations.js +5 -5
- package/dist/storage/adapters/baseStorageAdapter.d.ts +42 -0
- package/dist/storage/adapters/fileSystemStorage.d.ts +26 -2
- package/dist/storage/adapters/fileSystemStorage.js +218 -15
- package/dist/storage/adapters/memoryStorage.d.ts +4 -4
- package/dist/storage/adapters/memoryStorage.js +17 -12
- package/dist/storage/adapters/opfsStorage.d.ts +2 -2
- package/dist/storage/adapters/opfsStorage.js +2 -2
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +2 -2
- package/dist/storage/adapters/s3CompatibleStorage.js +2 -2
- package/dist/storage/backwardCompatibility.d.ts +10 -78
- package/dist/storage/backwardCompatibility.js +17 -132
- package/dist/storage/baseStorage.d.ts +18 -2
- package/dist/storage/baseStorage.js +74 -3
- package/dist/storage/cacheManager.js +2 -2
- package/dist/storage/readOnlyOptimizations.js +8 -3
- package/dist/streaming/pipeline.d.ts +154 -0
- package/dist/streaming/pipeline.js +551 -0
- package/dist/triple/TripleIntelligence.d.ts +25 -110
- package/dist/triple/TripleIntelligence.js +4 -574
- package/dist/triple/TripleIntelligenceSystem.d.ts +159 -0
- package/dist/triple/TripleIntelligenceSystem.js +519 -0
- package/dist/types/apiTypes.d.ts +278 -0
- package/dist/types/apiTypes.js +33 -0
- package/dist/types/brainy.types.d.ts +308 -0
- package/dist/types/brainy.types.js +8 -0
- package/dist/types/brainyDataInterface.d.ts +5 -8
- package/dist/types/brainyDataInterface.js +2 -2
- package/dist/types/graphTypes.js +2 -2
- package/dist/universal/crypto.d.ts +11 -1
- package/dist/universal/crypto.js +24 -93
- package/dist/universal/events.d.ts +3 -2
- package/dist/universal/events.js +6 -75
- package/dist/universal/fs.d.ts +2 -3
- package/dist/universal/fs.js +5 -211
- package/dist/universal/path.d.ts +3 -2
- package/dist/universal/path.js +22 -78
- package/dist/universal/uuid.d.ts +1 -1
- package/dist/universal/uuid.js +1 -1
- package/dist/utils/brainyTypes.d.ts +217 -0
- package/dist/utils/brainyTypes.js +261 -0
- package/dist/utils/cacheAutoConfig.d.ts +3 -3
- package/dist/utils/embedding.d.ts +9 -4
- package/dist/utils/embedding.js +89 -26
- package/dist/utils/enhancedLogger.d.ts +104 -0
- package/dist/utils/enhancedLogger.js +232 -0
- package/dist/utils/hybridModelManager.d.ts +19 -28
- package/dist/utils/hybridModelManager.js +36 -200
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/intelligentTypeMapper.d.ts +60 -0
- package/dist/utils/intelligentTypeMapper.js +349 -0
- package/dist/utils/metadataIndex.d.ts +118 -1
- package/dist/utils/metadataIndex.js +539 -16
- package/dist/utils/nodeVersionCheck.d.ts +24 -0
- package/dist/utils/nodeVersionCheck.js +65 -0
- package/dist/utils/paramValidation.d.ts +39 -0
- package/dist/utils/paramValidation.js +192 -0
- package/dist/utils/rateLimiter.d.ts +160 -0
- package/dist/utils/rateLimiter.js +271 -0
- package/dist/utils/statistics.d.ts +4 -4
- package/dist/utils/statistics.js +3 -3
- package/dist/utils/structuredLogger.d.ts +146 -0
- package/dist/utils/structuredLogger.js +394 -0
- package/dist/utils/textEncoding.js +2 -1
- package/dist/utils/typeValidation.d.ts +59 -0
- package/dist/utils/typeValidation.js +374 -0
- package/dist/utils/version.js +19 -3
- package/package.json +15 -17
- package/scripts/download-models.cjs +94 -20
- package/dist/augmentations/walAugmentation.d.ts +0 -109
- package/dist/augmentations/walAugmentation.js +0 -516
- package/dist/browserFramework.d.ts +0 -15
- package/dist/browserFramework.js +0 -31
- package/dist/browserFramework.minimal.d.ts +0 -14
- package/dist/browserFramework.minimal.js +0 -31
- package/dist/chat/BrainyChat.d.ts +0 -121
- package/dist/chat/BrainyChat.js +0 -396
- package/dist/chat/ChatCLI.d.ts +0 -61
- package/dist/chat/ChatCLI.js +0 -351
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Universal Crypto implementation
|
|
3
|
-
*
|
|
3
|
+
* Framework-friendly: Trusts that frameworks provide crypto polyfills
|
|
4
|
+
* Works in all environments: Browser (via framework), Node.js, Serverless
|
|
4
5
|
*/
|
|
5
6
|
/**
|
|
6
7
|
* Generate random bytes
|
|
8
|
+
* Framework-friendly: Assumes crypto API is available via framework polyfills
|
|
7
9
|
*/
|
|
8
10
|
export declare function randomBytes(size: number): Uint8Array;
|
|
9
11
|
/**
|
|
10
12
|
* Generate random UUID
|
|
13
|
+
* Framework-friendly: Assumes crypto.randomUUID is available via framework polyfills
|
|
11
14
|
*/
|
|
12
15
|
export declare function randomUUID(): string;
|
|
13
16
|
/**
|
|
14
17
|
* Create hash (simplified interface)
|
|
18
|
+
* Framework-friendly: Relies on Node.js crypto or framework-provided implementations
|
|
15
19
|
*/
|
|
16
20
|
export declare function createHash(algorithm: string): {
|
|
17
21
|
update: (data: string | Uint8Array) => any;
|
|
@@ -19,6 +23,7 @@ export declare function createHash(algorithm: string): {
|
|
|
19
23
|
};
|
|
20
24
|
/**
|
|
21
25
|
* Create HMAC
|
|
26
|
+
* Framework-friendly: Relies on Node.js crypto or framework-provided implementations
|
|
22
27
|
*/
|
|
23
28
|
export declare function createHmac(algorithm: string, key: string | Uint8Array): {
|
|
24
29
|
update: (data: string | Uint8Array) => any;
|
|
@@ -26,14 +31,17 @@ export declare function createHmac(algorithm: string, key: string | Uint8Array):
|
|
|
26
31
|
};
|
|
27
32
|
/**
|
|
28
33
|
* PBKDF2 synchronous
|
|
34
|
+
* Framework-friendly: Relies on Node.js crypto or framework-provided implementations
|
|
29
35
|
*/
|
|
30
36
|
export declare function pbkdf2Sync(password: string | Uint8Array, salt: string | Uint8Array, iterations: number, keylen: number, digest: string): Uint8Array;
|
|
31
37
|
/**
|
|
32
38
|
* Scrypt synchronous
|
|
39
|
+
* Framework-friendly: Relies on Node.js crypto or framework-provided implementations
|
|
33
40
|
*/
|
|
34
41
|
export declare function scryptSync(password: string | Uint8Array, salt: string | Uint8Array, keylen: number, options?: any): Uint8Array;
|
|
35
42
|
/**
|
|
36
43
|
* Create cipher
|
|
44
|
+
* Framework-friendly: Relies on Node.js crypto or framework-provided implementations
|
|
37
45
|
*/
|
|
38
46
|
export declare function createCipheriv(algorithm: string, key: Uint8Array, iv: Uint8Array): {
|
|
39
47
|
update: (data: string, inputEncoding?: string, outputEncoding?: string) => string;
|
|
@@ -41,6 +49,7 @@ export declare function createCipheriv(algorithm: string, key: Uint8Array, iv: U
|
|
|
41
49
|
};
|
|
42
50
|
/**
|
|
43
51
|
* Create decipher
|
|
52
|
+
* Framework-friendly: Relies on Node.js crypto or framework-provided implementations
|
|
44
53
|
*/
|
|
45
54
|
export declare function createDecipheriv(algorithm: string, key: Uint8Array, iv: Uint8Array): {
|
|
46
55
|
update: (data: string, inputEncoding?: string, outputEncoding?: string) => string;
|
|
@@ -48,6 +57,7 @@ export declare function createDecipheriv(algorithm: string, key: Uint8Array, iv:
|
|
|
48
57
|
};
|
|
49
58
|
/**
|
|
50
59
|
* Timing safe equal
|
|
60
|
+
* Framework-friendly: Relies on Node.js crypto or framework-provided implementations
|
|
51
61
|
*/
|
|
52
62
|
export declare function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
53
63
|
declare const _default: {
|
package/dist/universal/crypto.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Universal Crypto implementation
|
|
3
|
-
*
|
|
3
|
+
* Framework-friendly: Trusts that frameworks provide crypto polyfills
|
|
4
|
+
* Works in all environments: Browser (via framework), Node.js, Serverless
|
|
4
5
|
*/
|
|
5
|
-
import {
|
|
6
|
+
import { isNode } from '../utils/environment.js';
|
|
6
7
|
let nodeCrypto = null;
|
|
7
8
|
// Dynamic import for Node.js crypto (only in Node.js environment)
|
|
8
9
|
if (isNode()) {
|
|
@@ -15,29 +16,26 @@ if (isNode()) {
|
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* Generate random bytes
|
|
19
|
+
* Framework-friendly: Assumes crypto API is available via framework polyfills
|
|
18
20
|
*/
|
|
19
21
|
export function randomBytes(size) {
|
|
20
|
-
if (
|
|
21
|
-
// Use Web Crypto API (available in browsers and modern Node.js)
|
|
22
|
+
if (typeof crypto !== 'undefined') {
|
|
23
|
+
// Use Web Crypto API (available in browsers via framework polyfills and modern Node.js)
|
|
22
24
|
const array = new Uint8Array(size);
|
|
23
25
|
crypto.getRandomValues(array);
|
|
24
26
|
return array;
|
|
25
27
|
}
|
|
26
28
|
else if (nodeCrypto) {
|
|
27
|
-
// Use Node.js crypto
|
|
29
|
+
// Use Node.js crypto
|
|
28
30
|
return new Uint8Array(nodeCrypto.randomBytes(size));
|
|
29
31
|
}
|
|
30
32
|
else {
|
|
31
|
-
|
|
32
|
-
const array = new Uint8Array(size);
|
|
33
|
-
for (let i = 0; i < size; i++) {
|
|
34
|
-
array[i] = Math.floor(Math.random() * 256);
|
|
35
|
-
}
|
|
36
|
-
return array;
|
|
33
|
+
throw new Error('Crypto API not available. Framework bundlers should provide crypto polyfills.');
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
36
|
/**
|
|
40
37
|
* Generate random UUID
|
|
38
|
+
* Framework-friendly: Assumes crypto.randomUUID is available via framework polyfills
|
|
41
39
|
*/
|
|
42
40
|
export function randomUUID() {
|
|
43
41
|
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
|
@@ -47,158 +45,91 @@ export function randomUUID() {
|
|
|
47
45
|
return nodeCrypto.randomUUID();
|
|
48
46
|
}
|
|
49
47
|
else {
|
|
50
|
-
|
|
51
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
52
|
-
const r = Math.random() * 16 | 0;
|
|
53
|
-
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
54
|
-
return v.toString(16);
|
|
55
|
-
});
|
|
48
|
+
throw new Error('crypto.randomUUID not available. Framework bundlers should provide crypto polyfills.');
|
|
56
49
|
}
|
|
57
50
|
}
|
|
58
51
|
/**
|
|
59
52
|
* Create hash (simplified interface)
|
|
53
|
+
* Framework-friendly: Relies on Node.js crypto or framework-provided implementations
|
|
60
54
|
*/
|
|
61
55
|
export function createHash(algorithm) {
|
|
62
56
|
if (nodeCrypto && nodeCrypto.createHash) {
|
|
63
57
|
return nodeCrypto.createHash(algorithm);
|
|
64
58
|
}
|
|
65
59
|
else {
|
|
66
|
-
|
|
67
|
-
let hash = 0;
|
|
68
|
-
const hashObj = {
|
|
69
|
-
update: (data) => {
|
|
70
|
-
const text = typeof data === 'string' ? data : new TextDecoder().decode(data);
|
|
71
|
-
for (let i = 0; i < text.length; i++) {
|
|
72
|
-
const char = text.charCodeAt(i);
|
|
73
|
-
hash = ((hash << 5) - hash) + char;
|
|
74
|
-
hash = hash & hash; // Convert to 32-bit integer
|
|
75
|
-
}
|
|
76
|
-
return hashObj;
|
|
77
|
-
},
|
|
78
|
-
digest: (encoding) => {
|
|
79
|
-
return Math.abs(hash).toString(16);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
return hashObj;
|
|
60
|
+
throw new Error(`createHash not available. For browser environments, frameworks should provide crypto polyfills or use Web Crypto API directly.`);
|
|
83
61
|
}
|
|
84
62
|
}
|
|
85
63
|
/**
|
|
86
64
|
* Create HMAC
|
|
65
|
+
* Framework-friendly: Relies on Node.js crypto or framework-provided implementations
|
|
87
66
|
*/
|
|
88
67
|
export function createHmac(algorithm, key) {
|
|
89
68
|
if (nodeCrypto && nodeCrypto.createHmac) {
|
|
90
69
|
return nodeCrypto.createHmac(algorithm, key);
|
|
91
70
|
}
|
|
92
71
|
else {
|
|
93
|
-
|
|
94
|
-
return createHash(algorithm);
|
|
72
|
+
throw new Error(`createHmac not available. For browser environments, frameworks should provide crypto polyfills or use Web Crypto API directly.`);
|
|
95
73
|
}
|
|
96
74
|
}
|
|
97
75
|
/**
|
|
98
76
|
* PBKDF2 synchronous
|
|
77
|
+
* Framework-friendly: Relies on Node.js crypto or framework-provided implementations
|
|
99
78
|
*/
|
|
100
79
|
export function pbkdf2Sync(password, salt, iterations, keylen, digest) {
|
|
101
80
|
if (nodeCrypto && nodeCrypto.pbkdf2Sync) {
|
|
102
81
|
return new Uint8Array(nodeCrypto.pbkdf2Sync(password, salt, iterations, keylen, digest));
|
|
103
82
|
}
|
|
104
83
|
else {
|
|
105
|
-
|
|
106
|
-
const result = new Uint8Array(keylen);
|
|
107
|
-
const passwordStr = typeof password === 'string' ? password : new TextDecoder().decode(password);
|
|
108
|
-
const saltStr = typeof salt === 'string' ? salt : new TextDecoder().decode(salt);
|
|
109
|
-
let hash = 0;
|
|
110
|
-
const combined = passwordStr + saltStr;
|
|
111
|
-
for (let i = 0; i < combined.length; i++) {
|
|
112
|
-
hash = ((hash << 5) - hash) + combined.charCodeAt(i);
|
|
113
|
-
hash = hash & hash;
|
|
114
|
-
}
|
|
115
|
-
for (let i = 0; i < keylen; i++) {
|
|
116
|
-
result[i] = (Math.abs(hash + i) % 256);
|
|
117
|
-
}
|
|
118
|
-
return result;
|
|
84
|
+
throw new Error(`pbkdf2Sync not available. For browser environments, frameworks should provide crypto polyfills or use Web Crypto API directly.`);
|
|
119
85
|
}
|
|
120
86
|
}
|
|
121
87
|
/**
|
|
122
88
|
* Scrypt synchronous
|
|
89
|
+
* Framework-friendly: Relies on Node.js crypto or framework-provided implementations
|
|
123
90
|
*/
|
|
124
91
|
export function scryptSync(password, salt, keylen, options) {
|
|
125
92
|
if (nodeCrypto && nodeCrypto.scryptSync) {
|
|
126
93
|
return new Uint8Array(nodeCrypto.scryptSync(password, salt, keylen, options));
|
|
127
94
|
}
|
|
128
95
|
else {
|
|
129
|
-
|
|
130
|
-
return pbkdf2Sync(password, salt, 10000, keylen, 'sha256');
|
|
96
|
+
throw new Error(`scryptSync not available. For browser environments, frameworks should provide crypto polyfills or use Web Crypto API directly.`);
|
|
131
97
|
}
|
|
132
98
|
}
|
|
133
99
|
/**
|
|
134
100
|
* Create cipher
|
|
101
|
+
* Framework-friendly: Relies on Node.js crypto or framework-provided implementations
|
|
135
102
|
*/
|
|
136
103
|
export function createCipheriv(algorithm, key, iv) {
|
|
137
104
|
if (nodeCrypto && nodeCrypto.createCipheriv) {
|
|
138
105
|
return nodeCrypto.createCipheriv(algorithm, key, iv);
|
|
139
106
|
}
|
|
140
107
|
else {
|
|
141
|
-
|
|
142
|
-
let encrypted = '';
|
|
143
|
-
return {
|
|
144
|
-
update: (data, inputEncoding, outputEncoding) => {
|
|
145
|
-
for (let i = 0; i < data.length; i++) {
|
|
146
|
-
const char = data.charCodeAt(i);
|
|
147
|
-
const keyByte = key[i % key.length];
|
|
148
|
-
const ivByte = iv[i % iv.length];
|
|
149
|
-
encrypted += String.fromCharCode(char ^ keyByte ^ ivByte);
|
|
150
|
-
}
|
|
151
|
-
return outputEncoding === 'hex' ? Buffer.from(encrypted, 'binary').toString('hex') : encrypted;
|
|
152
|
-
},
|
|
153
|
-
final: (outputEncoding) => {
|
|
154
|
-
return outputEncoding === 'hex' ? '' : '';
|
|
155
|
-
}
|
|
156
|
-
};
|
|
108
|
+
throw new Error(`createCipheriv not available. For browser environments, frameworks should provide crypto polyfills or use Web Crypto API directly.`);
|
|
157
109
|
}
|
|
158
110
|
}
|
|
159
111
|
/**
|
|
160
112
|
* Create decipher
|
|
113
|
+
* Framework-friendly: Relies on Node.js crypto or framework-provided implementations
|
|
161
114
|
*/
|
|
162
115
|
export function createDecipheriv(algorithm, key, iv) {
|
|
163
116
|
if (nodeCrypto && nodeCrypto.createDecipheriv) {
|
|
164
117
|
return nodeCrypto.createDecipheriv(algorithm, key, iv);
|
|
165
118
|
}
|
|
166
119
|
else {
|
|
167
|
-
|
|
168
|
-
let decrypted = '';
|
|
169
|
-
return {
|
|
170
|
-
update: (data, inputEncoding, outputEncoding) => {
|
|
171
|
-
const input = inputEncoding === 'hex' ? Buffer.from(data, 'hex').toString('binary') : data;
|
|
172
|
-
for (let i = 0; i < input.length; i++) {
|
|
173
|
-
const char = input.charCodeAt(i);
|
|
174
|
-
const keyByte = key[i % key.length];
|
|
175
|
-
const ivByte = iv[i % iv.length];
|
|
176
|
-
decrypted += String.fromCharCode(char ^ keyByte ^ ivByte);
|
|
177
|
-
}
|
|
178
|
-
return decrypted;
|
|
179
|
-
},
|
|
180
|
-
final: (outputEncoding) => {
|
|
181
|
-
return '';
|
|
182
|
-
}
|
|
183
|
-
};
|
|
120
|
+
throw new Error(`createDecipheriv not available. For browser environments, frameworks should provide crypto polyfills or use Web Crypto API directly.`);
|
|
184
121
|
}
|
|
185
122
|
}
|
|
186
123
|
/**
|
|
187
124
|
* Timing safe equal
|
|
125
|
+
* Framework-friendly: Relies on Node.js crypto or framework-provided implementations
|
|
188
126
|
*/
|
|
189
127
|
export function timingSafeEqual(a, b) {
|
|
190
128
|
if (nodeCrypto && nodeCrypto.timingSafeEqual) {
|
|
191
129
|
return nodeCrypto.timingSafeEqual(a, b);
|
|
192
130
|
}
|
|
193
131
|
else {
|
|
194
|
-
|
|
195
|
-
if (a.length !== b.length)
|
|
196
|
-
return false;
|
|
197
|
-
let result = 0;
|
|
198
|
-
for (let i = 0; i < a.length; i++) {
|
|
199
|
-
result |= a[i] ^ b[i];
|
|
200
|
-
}
|
|
201
|
-
return result === 0;
|
|
132
|
+
throw new Error(`timingSafeEqual not available. For browser environments, frameworks should provide crypto polyfills or use Web Crypto API directly.`);
|
|
202
133
|
}
|
|
203
134
|
}
|
|
204
135
|
export default {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Universal Events implementation
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Framework-friendly: Trusts that frameworks provide events polyfills
|
|
4
|
+
* Works in all environments: Browser (via framework), Node.js, Serverless
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* Universal EventEmitter interface
|
|
@@ -16,6 +16,7 @@ export interface UniversalEventEmitter {
|
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Universal EventEmitter class
|
|
19
|
+
* Framework-friendly: Assumes events API is available via framework polyfills
|
|
19
20
|
*/
|
|
20
21
|
export declare class EventEmitter implements UniversalEventEmitter {
|
|
21
22
|
private emitter;
|
package/dist/universal/events.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Universal Events implementation
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Framework-friendly: Trusts that frameworks provide events polyfills
|
|
4
|
+
* Works in all environments: Browser (via framework), Node.js, Serverless
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { isNode } from '../utils/environment.js';
|
|
7
7
|
let nodeEvents = null;
|
|
8
8
|
// Dynamic import for Node.js events (only in Node.js environment)
|
|
9
9
|
if (isNode()) {
|
|
@@ -14,73 +14,6 @@ if (isNode()) {
|
|
|
14
14
|
// Ignore import errors in non-Node environments
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Browser implementation using EventTarget
|
|
19
|
-
*/
|
|
20
|
-
class BrowserEventEmitter extends EventTarget {
|
|
21
|
-
constructor() {
|
|
22
|
-
super(...arguments);
|
|
23
|
-
this.listeners = new Map();
|
|
24
|
-
}
|
|
25
|
-
on(event, listener) {
|
|
26
|
-
if (!this.listeners.has(event)) {
|
|
27
|
-
this.listeners.set(event, new Set());
|
|
28
|
-
}
|
|
29
|
-
this.listeners.get(event).add(listener);
|
|
30
|
-
const handler = (e) => {
|
|
31
|
-
const customEvent = e;
|
|
32
|
-
listener(...(customEvent.detail || []));
|
|
33
|
-
};
|
|
34
|
-
listener.__handler = handler;
|
|
35
|
-
this.addEventListener(event, handler);
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
off(event, listener) {
|
|
39
|
-
const eventListeners = this.listeners.get(event);
|
|
40
|
-
if (eventListeners) {
|
|
41
|
-
eventListeners.delete(listener);
|
|
42
|
-
const handler = listener.__handler;
|
|
43
|
-
if (handler) {
|
|
44
|
-
this.removeEventListener(event, handler);
|
|
45
|
-
delete listener.__handler;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
emit(event, ...args) {
|
|
51
|
-
const customEvent = new CustomEvent(event, { detail: args });
|
|
52
|
-
this.dispatchEvent(customEvent);
|
|
53
|
-
const eventListeners = this.listeners.get(event);
|
|
54
|
-
return eventListeners ? eventListeners.size > 0 : false;
|
|
55
|
-
}
|
|
56
|
-
once(event, listener) {
|
|
57
|
-
const onceListener = (...args) => {
|
|
58
|
-
this.off(event, onceListener);
|
|
59
|
-
listener(...args);
|
|
60
|
-
};
|
|
61
|
-
return this.on(event, onceListener);
|
|
62
|
-
}
|
|
63
|
-
removeAllListeners(event) {
|
|
64
|
-
if (event) {
|
|
65
|
-
const eventListeners = this.listeners.get(event);
|
|
66
|
-
if (eventListeners) {
|
|
67
|
-
for (const listener of eventListeners) {
|
|
68
|
-
this.off(event, listener);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
for (const [eventName] of this.listeners) {
|
|
74
|
-
this.removeAllListeners(eventName);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
listenerCount(event) {
|
|
80
|
-
const eventListeners = this.listeners.get(event);
|
|
81
|
-
return eventListeners ? eventListeners.size : 0;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
17
|
/**
|
|
85
18
|
* Node.js implementation using events.EventEmitter
|
|
86
19
|
*/
|
|
@@ -113,17 +46,15 @@ class NodeEventEmitter {
|
|
|
113
46
|
}
|
|
114
47
|
/**
|
|
115
48
|
* Universal EventEmitter class
|
|
49
|
+
* Framework-friendly: Assumes events API is available via framework polyfills
|
|
116
50
|
*/
|
|
117
51
|
export class EventEmitter {
|
|
118
52
|
constructor() {
|
|
119
|
-
if (
|
|
120
|
-
this.emitter = new BrowserEventEmitter();
|
|
121
|
-
}
|
|
122
|
-
else if (isNode() && nodeEvents) {
|
|
53
|
+
if (isNode() && nodeEvents) {
|
|
123
54
|
this.emitter = new NodeEventEmitter();
|
|
124
55
|
}
|
|
125
56
|
else {
|
|
126
|
-
|
|
57
|
+
throw new Error('Events operations not available. Framework bundlers should provide events polyfills.');
|
|
127
58
|
}
|
|
128
59
|
}
|
|
129
60
|
on(event, listener) {
|
package/dist/universal/fs.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Universal File System implementation
|
|
3
|
-
*
|
|
4
|
-
* Node.js
|
|
5
|
-
* Serverless: Uses memory-based fallback
|
|
3
|
+
* Framework-friendly: Trusts that frameworks provide fs polyfills
|
|
4
|
+
* Works in all environments: Browser (via framework), Node.js, Serverless
|
|
6
5
|
*/
|
|
7
6
|
/**
|
|
8
7
|
* Universal file operations interface
|
package/dist/universal/fs.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Universal File System implementation
|
|
3
|
-
*
|
|
4
|
-
* Node.js
|
|
5
|
-
* Serverless: Uses memory-based fallback
|
|
3
|
+
* Framework-friendly: Trusts that frameworks provide fs polyfills
|
|
4
|
+
* Works in all environments: Browser (via framework), Node.js, Serverless
|
|
6
5
|
*/
|
|
7
|
-
import {
|
|
6
|
+
import { isNode } from '../utils/environment.js';
|
|
8
7
|
let nodeFs = null;
|
|
9
8
|
// Dynamic import for Node.js fs (only in Node.js environment)
|
|
10
9
|
if (isNode()) {
|
|
@@ -15,125 +14,6 @@ if (isNode()) {
|
|
|
15
14
|
// Ignore import errors in non-Node environments
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Browser implementation using OPFS
|
|
20
|
-
*/
|
|
21
|
-
class BrowserFS {
|
|
22
|
-
async getRoot() {
|
|
23
|
-
if ('storage' in navigator && 'getDirectory' in navigator.storage) {
|
|
24
|
-
return await navigator.storage.getDirectory();
|
|
25
|
-
}
|
|
26
|
-
throw new Error('OPFS not supported in this browser');
|
|
27
|
-
}
|
|
28
|
-
async getFileHandle(path, create = false) {
|
|
29
|
-
const root = await this.getRoot();
|
|
30
|
-
const parts = path.split('/').filter(p => p);
|
|
31
|
-
let dir = root;
|
|
32
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
33
|
-
dir = await dir.getDirectoryHandle(parts[i], { create });
|
|
34
|
-
}
|
|
35
|
-
const fileName = parts[parts.length - 1];
|
|
36
|
-
return await dir.getFileHandle(fileName, { create });
|
|
37
|
-
}
|
|
38
|
-
async getDirHandle(path, create = false) {
|
|
39
|
-
const root = await this.getRoot();
|
|
40
|
-
const parts = path.split('/').filter(p => p);
|
|
41
|
-
let dir = root;
|
|
42
|
-
for (const part of parts) {
|
|
43
|
-
dir = await dir.getDirectoryHandle(part, { create });
|
|
44
|
-
}
|
|
45
|
-
return dir;
|
|
46
|
-
}
|
|
47
|
-
async readFile(path, encoding) {
|
|
48
|
-
try {
|
|
49
|
-
const fileHandle = await this.getFileHandle(path);
|
|
50
|
-
const file = await fileHandle.getFile();
|
|
51
|
-
return await file.text();
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
throw new Error(`File not found: ${path}`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
async writeFile(path, data, encoding) {
|
|
58
|
-
const fileHandle = await this.getFileHandle(path, true);
|
|
59
|
-
const writable = await fileHandle.createWritable();
|
|
60
|
-
await writable.write(data);
|
|
61
|
-
await writable.close();
|
|
62
|
-
}
|
|
63
|
-
async mkdir(path, options = { recursive: true }) {
|
|
64
|
-
await this.getDirHandle(path, true);
|
|
65
|
-
}
|
|
66
|
-
async exists(path) {
|
|
67
|
-
try {
|
|
68
|
-
await this.getFileHandle(path);
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
try {
|
|
73
|
-
await this.getDirHandle(path);
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async readdir(path, options) {
|
|
82
|
-
const dir = await this.getDirHandle(path);
|
|
83
|
-
if (options?.withFileTypes) {
|
|
84
|
-
const entries = [];
|
|
85
|
-
for await (const [name, handle] of dir.entries()) {
|
|
86
|
-
entries.push({
|
|
87
|
-
name,
|
|
88
|
-
isDirectory: () => handle.kind === 'directory',
|
|
89
|
-
isFile: () => handle.kind === 'file'
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
return entries;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
const entries = [];
|
|
96
|
-
for await (const [name] of dir.entries()) {
|
|
97
|
-
entries.push(name);
|
|
98
|
-
}
|
|
99
|
-
return entries;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
async unlink(path) {
|
|
103
|
-
const parts = path.split('/').filter(p => p);
|
|
104
|
-
const fileName = parts.pop();
|
|
105
|
-
const dirPath = parts.join('/');
|
|
106
|
-
if (dirPath) {
|
|
107
|
-
const dir = await this.getDirHandle(dirPath);
|
|
108
|
-
await dir.removeEntry(fileName);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
const root = await this.getRoot();
|
|
112
|
-
await root.removeEntry(fileName);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
async stat(path) {
|
|
116
|
-
try {
|
|
117
|
-
await this.getFileHandle(path);
|
|
118
|
-
return { isFile: () => true, isDirectory: () => false };
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
try {
|
|
122
|
-
await this.getDirHandle(path);
|
|
123
|
-
return { isFile: () => false, isDirectory: () => true };
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
throw new Error(`Path not found: ${path}`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
async access(path, mode) {
|
|
131
|
-
const exists = await this.exists(path);
|
|
132
|
-
if (!exists) {
|
|
133
|
-
throw new Error(`ENOENT: no such file or directory, access '${path}'`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
17
|
/**
|
|
138
18
|
* Node.js implementation using fs/promises
|
|
139
19
|
*/
|
|
@@ -176,99 +56,13 @@ class NodeFS {
|
|
|
176
56
|
await nodeFs.access(path, mode);
|
|
177
57
|
}
|
|
178
58
|
}
|
|
179
|
-
/**
|
|
180
|
-
* Memory-based fallback for serverless/edge environments
|
|
181
|
-
*/
|
|
182
|
-
class MemoryFS {
|
|
183
|
-
constructor() {
|
|
184
|
-
this.files = new Map();
|
|
185
|
-
this.dirs = new Set();
|
|
186
|
-
}
|
|
187
|
-
async readFile(path, encoding) {
|
|
188
|
-
const content = this.files.get(path);
|
|
189
|
-
if (content === undefined) {
|
|
190
|
-
throw new Error(`File not found: ${path}`);
|
|
191
|
-
}
|
|
192
|
-
return content;
|
|
193
|
-
}
|
|
194
|
-
async writeFile(path, data, encoding) {
|
|
195
|
-
this.files.set(path, data);
|
|
196
|
-
// Ensure parent directories exist
|
|
197
|
-
const parts = path.split('/').slice(0, -1);
|
|
198
|
-
for (let i = 1; i <= parts.length; i++) {
|
|
199
|
-
this.dirs.add(parts.slice(0, i).join('/'));
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
async mkdir(path, options = { recursive: true }) {
|
|
203
|
-
this.dirs.add(path);
|
|
204
|
-
if (options.recursive) {
|
|
205
|
-
const parts = path.split('/');
|
|
206
|
-
for (let i = 1; i <= parts.length; i++) {
|
|
207
|
-
this.dirs.add(parts.slice(0, i).join('/'));
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
async exists(path) {
|
|
212
|
-
return this.files.has(path) || this.dirs.has(path);
|
|
213
|
-
}
|
|
214
|
-
async readdir(path, options) {
|
|
215
|
-
const entries = new Set();
|
|
216
|
-
const pathPrefix = path + '/';
|
|
217
|
-
for (const filePath of this.files.keys()) {
|
|
218
|
-
if (filePath.startsWith(pathPrefix)) {
|
|
219
|
-
const relativePath = filePath.slice(pathPrefix.length);
|
|
220
|
-
const firstSegment = relativePath.split('/')[0];
|
|
221
|
-
entries.add(firstSegment);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
for (const dirPath of this.dirs) {
|
|
225
|
-
if (dirPath.startsWith(pathPrefix)) {
|
|
226
|
-
const relativePath = dirPath.slice(pathPrefix.length);
|
|
227
|
-
const firstSegment = relativePath.split('/')[0];
|
|
228
|
-
if (firstSegment)
|
|
229
|
-
entries.add(firstSegment);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
if (options?.withFileTypes) {
|
|
233
|
-
return Array.from(entries).map(name => ({
|
|
234
|
-
name,
|
|
235
|
-
isDirectory: () => this.dirs.has(path + '/' + name),
|
|
236
|
-
isFile: () => this.files.has(path + '/' + name)
|
|
237
|
-
}));
|
|
238
|
-
}
|
|
239
|
-
return Array.from(entries);
|
|
240
|
-
}
|
|
241
|
-
async unlink(path) {
|
|
242
|
-
this.files.delete(path);
|
|
243
|
-
}
|
|
244
|
-
async stat(path) {
|
|
245
|
-
const isFile = this.files.has(path);
|
|
246
|
-
const isDir = this.dirs.has(path);
|
|
247
|
-
if (!isFile && !isDir) {
|
|
248
|
-
throw new Error(`Path not found: ${path}`);
|
|
249
|
-
}
|
|
250
|
-
return {
|
|
251
|
-
isFile: () => isFile,
|
|
252
|
-
isDirectory: () => isDir
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
async access(path, mode) {
|
|
256
|
-
const exists = await this.exists(path);
|
|
257
|
-
if (!exists) {
|
|
258
|
-
throw new Error(`ENOENT: no such file or directory, access '${path}'`);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
59
|
// Create the appropriate filesystem implementation
|
|
263
60
|
let fsImpl;
|
|
264
|
-
if (
|
|
265
|
-
fsImpl = new BrowserFS();
|
|
266
|
-
}
|
|
267
|
-
else if (isNode() && nodeFs) {
|
|
61
|
+
if (isNode() && nodeFs) {
|
|
268
62
|
fsImpl = new NodeFS();
|
|
269
63
|
}
|
|
270
64
|
else {
|
|
271
|
-
|
|
65
|
+
throw new Error('File system operations not available. Framework bundlers should provide fs polyfills or use storage adapters like OPFS, Memory, or S3.');
|
|
272
66
|
}
|
|
273
67
|
// Export the filesystem operations
|
|
274
68
|
export const readFile = fsImpl.readFile.bind(fsImpl);
|
package/dist/universal/path.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Universal Path implementation
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Framework-friendly: Trusts that frameworks provide path polyfills
|
|
4
|
+
* Works in all environments: Browser (via framework), Node.js, Serverless
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* Universal path operations
|
|
8
|
+
* Framework-friendly: Assumes path API is available via framework polyfills
|
|
8
9
|
*/
|
|
9
10
|
export declare function join(...paths: string[]): string;
|
|
10
11
|
export declare function dirname(path: string): string;
|