@soulcraft/brainy 0.9.30 → 0.9.32

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/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![Node.js](https://img.shields.io/badge/node-%3E%3D23.0.0-brightgreen.svg)](https://nodejs.org/)
7
7
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.1.6-blue.svg)](https://www.typescriptlang.org/)
8
8
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
9
- [![npm](https://img.shields.io/badge/npm-v0.9.30-blue.svg)](https://www.npmjs.com/package/@soulcraft/brainy)
9
+ [![npm](https://img.shields.io/badge/npm-v0.9.32-blue.svg)](https://www.npmjs.com/package/@soulcraft/brainy)
10
10
 
11
11
  [//]: # ([![Cartographer](https://img.shields.io/badge/Cartographer-Official%20Standard-brightgreen)](https://github.com/sodal-project/cartographer))
12
12
 
package/dist/brainy.js CHANGED
@@ -2684,9 +2684,9 @@ function isBrowser$1() {
2684
2684
  * Check if code is running in a Node.js environment
2685
2685
  */
2686
2686
  function isNode() {
2687
- return typeof process !== 'undefined' &&
2687
+ return (typeof process !== 'undefined' &&
2688
2688
  process.versions != null &&
2689
- process.versions.node != null;
2689
+ process.versions.node != null);
2690
2690
  }
2691
2691
  /**
2692
2692
  * Check if Web Workers are available in the current environment
@@ -2695,26 +2695,21 @@ function areWebWorkersAvailable() {
2695
2695
  return isBrowser$1() && typeof Worker !== 'undefined';
2696
2696
  }
2697
2697
  /**
2698
- * Check if Worker Threads are available in the current environment (Node.js)
2698
+ * Synchronous version that doesn't actually try to load the module
2699
+ * This is safer in ES module environments
2699
2700
  */
2700
- function areWorkerThreadsAvailable() {
2701
+ function areWorkerThreadsAvailableSync() {
2701
2702
  if (!isNode())
2702
2703
  return false;
2703
- try {
2704
- // Dynamic import to avoid errors in browser environments
2705
- require('worker_threads');
2706
- return true;
2707
- }
2708
- catch (e) {
2709
- return false;
2710
- }
2704
+ // In Node.js 12+, worker_threads is available without requiring a flag
2705
+ return parseInt(process.versions.node.split('.')[0]) >= 12;
2711
2706
  }
2712
2707
  /**
2713
2708
  * Determine if threading is available in the current environment
2714
2709
  * Returns true if either Web Workers (browser) or Worker Threads (Node.js) are available
2715
2710
  */
2716
2711
  function isThreadingAvailable() {
2717
- return areWebWorkersAvailable() || areWorkerThreadsAvailable();
2712
+ return areWebWorkersAvailable() || areWorkerThreadsAvailableSync();
2718
2713
  }
2719
2714
 
2720
2715
  /**
@@ -9328,41 +9323,11 @@ class BrainyData {
9328
9323
  }
9329
9324
 
9330
9325
  // Import Node.js built-in modules
9331
- // Using require for compatibility with Node.js
9326
+ // Using dynamic imports for compatibility with ES modules
9332
9327
  let fs;
9333
9328
  let path;
9334
- // Initialize these modules immediately if in Node.js environment
9335
- if (typeof process !== 'undefined' &&
9336
- process.versions &&
9337
- process.versions.node) {
9338
- try {
9339
- // Use require for Node.js built-in modules
9340
- fs = require('fs');
9341
- path = require('path');
9342
- // Verify that path has the required methods
9343
- if (!path || typeof path.resolve !== 'function') {
9344
- throw new Error('path module is missing required methods');
9345
- }
9346
- }
9347
- catch (e) {
9348
- console.warn('Failed to load Node.js modules with require:', e);
9349
- // Try using dynamic import as a fallback
9350
- try {
9351
- // Use a synchronous approach to ensure modules are loaded before continuing
9352
- const pathModule = require('node:path');
9353
- const fsModule = require('node:fs');
9354
- path = pathModule;
9355
- fs = fsModule;
9356
- // Verify that path has the required methods
9357
- if (!path || typeof path.resolve !== 'function') {
9358
- throw new Error('path module from node:path is missing required methods');
9359
- }
9360
- }
9361
- catch (nodeImportError) {
9362
- console.warn('Failed to load Node.js modules with node: prefix:', nodeImportError);
9363
- }
9364
- }
9365
- }
9329
+ // We'll initialize these modules in the init() method
9330
+ // No synchronous loading here to avoid issues with ES modules
9366
9331
  // Constants for directory and file names
9367
9332
  const ROOT_DIR = 'brainy-data';
9368
9333
  const NOUNS_DIR = 'nouns';
@@ -9408,31 +9373,11 @@ class FileSystemStorage {
9408
9373
  console.log('Node.js modules not properly loaded, attempting to load them now');
9409
9374
  // Try multiple approaches to load the modules
9410
9375
  const loadAttempts = [
9411
- // Attempt 1: Use require
9412
- async () => {
9413
- console.log('Attempting to load Node.js modules with require()');
9414
- const fsModule = require('fs');
9415
- const pathModule = require('path');
9416
- if (!pathModule || typeof pathModule.resolve !== 'function') {
9417
- throw new Error('path.resolve is not a function after require()');
9418
- }
9419
- return { fs: fsModule, path: pathModule };
9420
- },
9421
- // Attempt 2: Use require with node: prefix
9422
- async () => {
9423
- console.log('Attempting to load Node.js modules with require("node:...")');
9424
- const fsModule = require('node:fs');
9425
- const pathModule = require('node:path');
9426
- if (!pathModule || typeof pathModule.resolve !== 'function') {
9427
- throw new Error('path.resolve is not a function after require("node:path")');
9428
- }
9429
- return { fs: fsModule, path: pathModule };
9430
- },
9431
- // Attempt 3: Use dynamic import
9376
+ // Attempt 1: Use dynamic import
9432
9377
  async () => {
9433
9378
  console.log('Attempting to load Node.js modules with dynamic import');
9434
- const fsModule = await Promise.resolve().then(function () { return _fsShim$1; });
9435
- const pathModule = await Promise.resolve().then(function () { return _pathShim$1; });
9379
+ const fsModule = await import('fs');
9380
+ const pathModule = await import('path');
9436
9381
  const fsResolved = fsModule.default || fsModule;
9437
9382
  const pathResolved = pathModule.default || pathModule;
9438
9383
  if (!pathResolved || typeof pathResolved.resolve !== 'function') {
@@ -9440,7 +9385,7 @@ class FileSystemStorage {
9440
9385
  }
9441
9386
  return { fs: fsResolved, path: pathResolved };
9442
9387
  },
9443
- // Attempt 4: Use dynamic import with node: prefix
9388
+ // Attempt 2: Use dynamic import with node: prefix
9444
9389
  async () => {
9445
9390
  console.log('Attempting to load Node.js modules with dynamic import("node:...")');
9446
9391
  const fsModule = await import('node:fs');
@@ -22021,12 +21966,12 @@ var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
22021
21966
 
22022
21967
  var require$$0 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1);
22023
21968
 
22024
- var _utilShim = {}; const promises$2 = {};
21969
+ var _utilShim = {}; const promises = {};
22025
21970
 
22026
21971
  var _utilShim$1 = /*#__PURE__*/Object.freeze({
22027
21972
  __proto__: null,
22028
21973
  default: _utilShim,
22029
- promises: promises$2
21974
+ promises: promises
22030
21975
  });
22031
21976
 
22032
21977
  var require$$1 = /*@__PURE__*/getAugmentedNamespace(_utilShim$1);
@@ -87278,22 +87223,6 @@ var universalSentenceEncoder_esm = /*#__PURE__*/Object.freeze({
87278
87223
  version: version
87279
87224
  });
87280
87225
 
87281
- var _fsShim = {}; const promises$1 = {};
87282
-
87283
- var _fsShim$1 = /*#__PURE__*/Object.freeze({
87284
- __proto__: null,
87285
- default: _fsShim,
87286
- promises: promises$1
87287
- });
87288
-
87289
- var _pathShim = {}; const promises = {};
87290
-
87291
- var _pathShim$1 = /*#__PURE__*/Object.freeze({
87292
- __proto__: null,
87293
- default: _pathShim,
87294
- promises: promises
87295
- });
87296
-
87297
87226
  var _child_processShim = /*#__PURE__*/Object.freeze({
87298
87227
  __proto__: null
87299
87228
  });