@alizarin/napi 2.0.0-alpha.97 → 2.0.0-alpha.98

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.
@@ -4,7 +4,7 @@ import path from 'node:path';
4
4
  import fs from 'node:fs';
5
5
  import { fileURLToPath } from 'node:url';
6
6
 
7
- import { NapiStaticGraph, NapiStaticResourceRegistry, NapiResourceModelWrapper, NapiResourceInstanceWrapper } from '../index.js';
7
+ import { NapiStaticGraph, NapiStaticResourceRegistry, NapiResourceModelWrapper, NapiResourceInstanceWrapper, NapiNodeConfigManager } from '../index.js';
8
8
 
9
9
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
10
  const TEST_DATA = path.resolve(__dirname, '..', '..', '..', 'tests');
@@ -522,3 +522,44 @@ describe('NapiResourceInstanceWrapper methods', () => {
522
522
  assert.equal(tiles.length, 0, 'should be empty');
523
523
  });
524
524
  });
525
+
526
+ // =============================================================================
527
+ // NapiNodeConfigManager + NapiStaticGraph integration
528
+ // Regression: loadFromGraph used JSON.stringify on a NapiStaticGraph, which
529
+ // produced {} because NAPI class getters are not enumerable own properties.
530
+ // The fix uses buildFromGraph (direct struct reference) instead.
531
+ // =============================================================================
532
+
533
+ describe('NapiNodeConfigManager', () => {
534
+ const personJson = fs.readFileSync(
535
+ path.join(TEST_DATA, 'data', 'models', 'Person.json'),
536
+ 'utf-8'
537
+ );
538
+
539
+ it('buildFromGraph accepts a NapiStaticGraph without error', () => {
540
+ const graph = NapiStaticGraph.fromJsonString(personJson);
541
+ const ncm = new NapiNodeConfigManager();
542
+ // This is the path that failed when using JSON.stringify(napiGraph)
543
+ ncm.buildFromGraph(graph);
544
+ });
545
+
546
+ it('buildFromGraphJson fails on JSON.stringify of a NapiStaticGraph', () => {
547
+ const graph = NapiStaticGraph.fromJsonString(personJson);
548
+ const ncm = new NapiNodeConfigManager();
549
+ // Demonstrates the bug: NAPI objects don't stringify their getters
550
+ const stringified = JSON.stringify(graph);
551
+ assert.throws(
552
+ () => ncm.buildFromGraphJson(stringified),
553
+ /Failed to parse graph/i,
554
+ 'JSON.stringify of NapiStaticGraph should produce invalid graph JSON'
555
+ );
556
+ });
557
+
558
+ it('buildFromGraphJson works with raw graph JSON', () => {
559
+ const parsed = JSON.parse(personJson);
560
+ const graphObj = parsed.graph ? parsed.graph[0] : parsed;
561
+ const ncm = new NapiNodeConfigManager();
562
+ // Raw JS object stringifies correctly
563
+ ncm.buildFromGraphJson(JSON.stringify(graphObj));
564
+ });
565
+ });
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alizarin/napi",
3
- "version": "2.0.0-alpha.97",
3
+ "version": "2.0.0-alpha.98",
4
4
  "license": "AGPL-3.0-or-later",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,8 +30,8 @@
30
30
  "@napi-rs/cli": "^2.18.0"
31
31
  },
32
32
  "optionalDependencies": {
33
- "@alizarin/napi-win32-x64-msvc": "2.0.0-alpha.97",
34
- "@alizarin/napi-darwin-x64": "2.0.0-alpha.97",
35
- "@alizarin/napi-linux-x64-gnu": "2.0.0-alpha.97"
33
+ "@alizarin/napi-win32-x64-msvc": "2.0.0-alpha.98",
34
+ "@alizarin/napi-darwin-x64": "2.0.0-alpha.98",
35
+ "@alizarin/napi-linux-x64-gnu": "2.0.0-alpha.98"
36
36
  }
37
37
  }