@alizarin/napi 0.2.1-alpha.83 → 0.2.1-alpha.84

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 { NapiPrebuildLoader, NapiStaticGraph, NapiStaticResourceRegistry, NapiResourceModelWrapper, NapiResourceInstanceWrapper } from '../index.js';
7
+ import { NapiStaticGraph, NapiStaticResourceRegistry, NapiResourceModelWrapper, NapiResourceInstanceWrapper } from '../index.js';
8
8
 
9
9
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
10
  const TEST_DATA = path.resolve(__dirname, '..', '..', '..', 'tests');
@@ -59,15 +59,6 @@ describe('NapiStaticResourceRegistry', () => {
59
59
  });
60
60
  });
61
61
 
62
- describe('NapiPrebuildLoader', () => {
63
- it('throws for nonexistent directory', () => {
64
- assert.throws(
65
- () => new NapiPrebuildLoader('/nonexistent/path'),
66
- /not found/i
67
- );
68
- });
69
- });
70
-
71
62
  // =============================================================================
72
63
  // NapiResourceModelWrapper
73
64
  // =============================================================================
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@alizarin/napi",
3
- "version": "0.2.1-alpha.83",
3
+ "version": "0.2.1-alpha.84",
4
4
  "license": "AGPL-3.0-or-later",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/flaxandteal/alizarin",
8
+ "directory": "crates/alizarin-napi"
9
+ },
5
10
  "main": "index.js",
6
11
  "types": "index.d.ts",
7
12
  "bin": {
@@ -25,8 +30,8 @@
25
30
  "@napi-rs/cli": "^2.18.0"
26
31
  },
27
32
  "optionalDependencies": {
28
- "@alizarin/napi-win32-x64-msvc": "0.2.1-alpha.83",
29
- "@alizarin/napi-darwin-x64": "0.2.1-alpha.83",
30
- "@alizarin/napi-linux-x64-gnu": "0.2.1-alpha.83"
33
+ "@alizarin/napi-win32-x64-msvc": "0.2.1-alpha.84",
34
+ "@alizarin/napi-darwin-x64": "0.2.1-alpha.84",
35
+ "@alizarin/napi-linux-x64-gnu": "0.2.1-alpha.84"
31
36
  }
32
37
  }
package/src/lib.rs CHANGED
@@ -12,7 +12,7 @@ use alizarin_core::skos::SkosCollection;
12
12
  use alizarin_core::type_serialization::SerializationContext;
13
13
  use alizarin_core::{
14
14
  build_graph_from_model_csvs, build_resources_from_business_csv, wrap_business_data,
15
- PrebuildLoader, StaticGraph, StaticResource, StaticResourceRegistry,
15
+ StaticGraph, StaticResource, StaticResourceRegistry,
16
16
  };
17
17
 
18
18
  // ============================================================================
@@ -43,87 +43,6 @@ fn loader_err(e: alizarin_core::LoaderError) -> napi::Error {
43
43
  napi::Error::from_reason(e.to_string())
44
44
  }
45
45
 
46
- // ============================================================================
47
- // NapiPrebuildLoader
48
- // ============================================================================
49
-
50
- #[napi]
51
- pub struct NapiPrebuildLoader {
52
- inner: PrebuildLoader,
53
- }
54
-
55
- #[napi]
56
- impl NapiPrebuildLoader {
57
- #[napi(constructor)]
58
- pub fn new(path: String) -> Result<Self> {
59
- let inner = PrebuildLoader::new(&path).map_err(loader_err)?;
60
- Ok(NapiPrebuildLoader { inner })
61
- }
62
-
63
- /// Load a single graph from a JSON file path (relative to prebuild root or absolute).
64
- #[napi]
65
- pub fn load_graph(&self, path: String) -> Result<NapiStaticGraph> {
66
- let graph = self.inner.load_graph(&path).map_err(loader_err)?;
67
- Ok(NapiStaticGraph { inner: graph })
68
- }
69
-
70
- /// Load all graphs from prebuild/graphs/resource_models/
71
- #[napi]
72
- pub fn load_all_graphs(&self) -> Result<Vec<NapiStaticGraph>> {
73
- let graphs = self.inner.load_all_graphs().map_err(loader_err)?;
74
- Ok(graphs
75
- .into_iter()
76
- .map(|g| NapiStaticGraph { inner: g })
77
- .collect())
78
- }
79
-
80
- /// Load full resources (with tiles) from a single business data file,
81
- /// filtered by graph ID.
82
- #[napi]
83
- pub fn load_full_resources_from_file(
84
- &self,
85
- path: String,
86
- graph_id: String,
87
- ) -> Result<serde_json::Value> {
88
- let resources = self
89
- .inner
90
- .load_full_resources_from_file(std::path::Path::new(&path), &graph_id)
91
- .map_err(loader_err)?;
92
- serde_json::to_value(&resources).map_err(|e| napi::Error::from_reason(e.to_string()))
93
- }
94
-
95
- /// Find all business data JSON files in the prebuild directory.
96
- #[napi]
97
- pub fn find_business_data_files(&self) -> Result<Vec<String>> {
98
- let files = self.inner.find_business_data_files().map_err(loader_err)?;
99
- Ok(files.into_iter().map(|p| p.display().to_string()).collect())
100
- }
101
-
102
- /// Get prebuild directory info.
103
- #[napi]
104
- pub fn get_info(&self) -> Result<serde_json::Value> {
105
- let info = self.inner.get_info().map_err(loader_err)?;
106
- Ok(serde_json::json!({
107
- "path": info.path.display().to_string(),
108
- "hasGraphs": info.has_graphs,
109
- "hasBusinessData": info.has_business_data,
110
- "hasReferenceData": info.has_reference_data,
111
- "hasIndexTemplates": info.has_index_templates,
112
- "graphFiles": info.graph_files.iter().map(|p| p.display().to_string()).collect::<Vec<_>>(),
113
- }))
114
- }
115
-
116
- /// Count resources for a given graph ID.
117
- #[napi]
118
- pub fn count_resources_for_graph(&self, graph_id: String) -> Result<u32> {
119
- let count = self
120
- .inner
121
- .count_resources_for_graph(&graph_id)
122
- .map_err(loader_err)?;
123
- Ok(count as u32)
124
- }
125
- }
126
-
127
46
  // ============================================================================
128
47
  // NapiPrebuildExporter
129
48
  // ============================================================================
@@ -609,3 +528,35 @@ pub fn get_registered_extension_handlers() -> Vec<String> {
609
528
  .map(|s| s.to_string())
610
529
  .collect()
611
530
  }
531
+
532
+ // ============================================================================
533
+ // Prebuild import (high-level convenience)
534
+ // ============================================================================
535
+
536
+ /// Import a prebuild/pkg directory: register graphs, load SKOS collections,
537
+ /// and load ontology configs.
538
+ ///
539
+ /// 1. Loads and registers all graphs from graphs/resource_models/ and graphs/branches/
540
+ /// 2. Parses SKOS XML from reference_data/collections/ into the global RDM cache
541
+ /// 3. Loads ontology configs from ontologies/ (if present)
542
+ ///
543
+ /// Returns `{ graphIds, collectionIds, collections, ontologyConfigs }`.
544
+ #[napi(js_name = "importPrebuild")]
545
+ pub fn import_prebuild(prebuild_dir: String, base_uri: String) -> Result<serde_json::Value> {
546
+ let result = alizarin_core::import_prebuild(&prebuild_dir, &base_uri).map_err(loader_err)?;
547
+
548
+ let collections_json = serde_json::to_value(&result.collections)
549
+ .map_err(|e| napi::Error::from_reason(e.to_string()))?;
550
+ let ontology_configs: Vec<serde_json::Value> = result
551
+ .ontology_configs
552
+ .iter()
553
+ .filter_map(|c| serde_json::to_value(c).ok())
554
+ .collect();
555
+
556
+ Ok(serde_json::json!({
557
+ "graphIds": result.graph_ids,
558
+ "collectionIds": result.collection_ids,
559
+ "collections": collections_json,
560
+ "ontologyConfigs": ontology_configs,
561
+ }))
562
+ }