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

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,83 @@ 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
+ });
566
+
567
+ // =============================================================================
568
+ // NapiStaticGraph serialization guard
569
+ // Regression: JSON.stringify(NapiStaticGraph) produces {} because NAPI class
570
+ // getters are not enumerable own properties. Any code path that does
571
+ // JSON.stringify(graph) where graph could be a NapiStaticGraph will break.
572
+ // =============================================================================
573
+
574
+ describe('NapiStaticGraph serialization', () => {
575
+ const groupJson = fs.readFileSync(
576
+ path.join(TEST_DATA, 'data', 'models', 'Group.json'),
577
+ 'utf-8'
578
+ );
579
+
580
+ it('JSON.stringify of NapiStaticGraph produces empty object', () => {
581
+ const graph = NapiStaticGraph.fromJsonString(groupJson);
582
+ const stringified = JSON.stringify(graph);
583
+ // This documents the fundamental limitation: NAPI class instances
584
+ // do not serialize via JSON.stringify
585
+ assert.equal(stringified, '{}', 'NapiStaticGraph should stringify to {}');
586
+ });
587
+
588
+ it('NapiResourceModelWrapper.fromGraph accepts NapiStaticGraph directly', () => {
589
+ const graph = NapiStaticGraph.fromJsonString(groupJson);
590
+ // This is the correct NAPI path — no JSON.stringify needed
591
+ const wrapper = NapiResourceModelWrapper.fromGraph(graph, true);
592
+ assert.equal(wrapper.getGraphId(), '07883c9e-b25c-11e9-975a-a4d18cec433a');
593
+ });
594
+
595
+ it('NapiResourceModelWrapper constructor fails with JSON.stringify of NapiStaticGraph', () => {
596
+ const graph = NapiStaticGraph.fromJsonString(groupJson);
597
+ // Demonstrates the bug this regression test guards against
598
+ assert.throws(
599
+ () => new NapiResourceModelWrapper(JSON.stringify(graph), true),
600
+ /Invalid graph JSON/i,
601
+ 'JSON.stringify of NapiStaticGraph should produce invalid input for constructor'
602
+ );
603
+ });
604
+ });
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.99",
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.99",
34
+ "@alizarin/napi-darwin-x64": "2.0.0-alpha.99",
35
+ "@alizarin/napi-linux-x64-gnu": "2.0.0-alpha.99"
36
36
  }
37
37
  }