@alizarin/napi 2.0.0-alpha.93 → 2.0.0-alpha.94
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/{alizarin-napi-2.0.0-alpha.93.tgz → alizarin-napi-2.0.0-alpha.94.tgz} +0 -0
- package/alizarin-napi.darwin-arm64.node +0 -0
- package/alizarin-napi.darwin-x64.node +0 -0
- package/alizarin-napi.linux-x64-gnu.node +0 -0
- package/alizarin-napi.win32-x64-msvc.node +0 -0
- package/index.d.ts +37 -0
- package/index.js +6 -1
- package/package.json +4 -4
- package/src/instance_wrapper_napi.rs +75 -0
- package/src/lib.rs +76 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.d.ts
CHANGED
|
@@ -44,6 +44,24 @@ export declare function getRegisteredExtensionHandlers(): Array<string>
|
|
|
44
44
|
export declare function parseSkosXml(xmlContent: string, baseUri: string): any
|
|
45
45
|
/** Parse SKOS RDF/XML and return a single collection (the first one found). */
|
|
46
46
|
export declare function parseSkosXmlToCollection(xmlContent: string, baseUri: string): any
|
|
47
|
+
/**
|
|
48
|
+
* Build a mapping from node alias to collection ID based on graph definition.
|
|
49
|
+
*
|
|
50
|
+
* Equivalent to WASM's `buildAliasToCollectionMap`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildAliasToCollectionMap(graphJson: string, resolvableDatatypes?: Array<string> | undefined | null, configKeys?: Array<string> | undefined | null): Record<string, string>
|
|
53
|
+
/**
|
|
54
|
+
* Scan a JSON tree to find which collections are needed for resolution.
|
|
55
|
+
*
|
|
56
|
+
* Equivalent to WASM's `findNeededCollections`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function findNeededCollections(treeJson: string, aliasToCollection: Record<string, string>): Array<string>
|
|
59
|
+
/** Check if a string is a valid UUID. */
|
|
60
|
+
export declare function isValidUuid(s: string): boolean
|
|
61
|
+
/** Get the default resolvable datatypes (concept, concept-list). */
|
|
62
|
+
export declare function getDefaultResolvableDatatypes(): Array<string>
|
|
63
|
+
/** Get the default config keys for collection IDs. */
|
|
64
|
+
export declare function getDefaultConfigKeys(): Array<string>
|
|
47
65
|
/**
|
|
48
66
|
* Import a prebuild/pkg directory: register graphs, load SKOS collections,
|
|
49
67
|
* and load ontology configs.
|
|
@@ -62,6 +80,18 @@ export declare class NapiRdmCache {
|
|
|
62
80
|
/** Load a single collection from JSON. */
|
|
63
81
|
loadCollectionJson(jsonStr: string): void
|
|
64
82
|
get collectionCount(): number
|
|
83
|
+
/** Check if a collection is already in the cache. */
|
|
84
|
+
hasCollection(collectionId: string): boolean
|
|
85
|
+
/** Add a collection from a JSON string of concepts. */
|
|
86
|
+
addCollectionFromJson(collectionId: string, jsonStr: string): void
|
|
87
|
+
/** Get the parent concept ID for a concept within a collection. */
|
|
88
|
+
getParentId(collectionId: string, conceptId: string): string | null
|
|
89
|
+
/** Remove a collection from the cache. */
|
|
90
|
+
removeCollection(collectionId: string): boolean
|
|
91
|
+
/** Clear all collections from the cache. */
|
|
92
|
+
clear(): void
|
|
93
|
+
/** Resolve labels to UUIDs using this cache for lookups. */
|
|
94
|
+
resolveLabels(treeJson: string, aliasToCollection: Record<string, string>, strict: boolean): any
|
|
65
95
|
}
|
|
66
96
|
export declare class NapiNodeConfigManager {
|
|
67
97
|
constructor()
|
|
@@ -211,6 +241,13 @@ export declare class NapiResourceInstanceWrapper {
|
|
|
211
241
|
ensureNodegroup(allValuesJs: any, allNodegroupsJs: any, nodegroupId: string, addIfMissing: boolean, nodegroupPermissionsJs: any, doImpliedNodegroups: boolean): NapiEnsureNodegroupResult
|
|
212
242
|
/** Build pseudo values from tiles for a specific nodegroup. */
|
|
213
243
|
valuesFromResourceNodegroup(existingValuesJs: any, nodegroupTileIds: Array<string>, nodegroupId: string): NapiValuesFromNodegroupResult
|
|
244
|
+
/**
|
|
245
|
+
* Resolve a dot-separated path to its target node metadata without needing tiles.
|
|
246
|
+
*
|
|
247
|
+
* Returns { nodegroupId, isSingle, targetNodeId } — enough for the JS layer to
|
|
248
|
+
* lazy-load just that nodegroup's tiles before calling getValuesAtPath.
|
|
249
|
+
*/
|
|
250
|
+
resolvePath(path: string): any
|
|
214
251
|
/** Resolve a dot-separated path and return a PseudoList. */
|
|
215
252
|
getValuesAtPath(path: string): NapiPseudoList
|
|
216
253
|
/**
|
package/index.js
CHANGED
|
@@ -310,7 +310,7 @@ if (!nativeBinding) {
|
|
|
310
310
|
throw new Error(`Failed to load native binding`)
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
-
const { NapiRdmCache, NapiNodeConfigManager, NapiTileData, NapiStaticTile, NapiPseudoValue, NapiPseudoList, NapiPopulateResult, NapiEnsureNodegroupResult, NapiValuesFromNodegroupResult, NapiResourceInstanceWrapper, NapiResourceModelWrapper, NapiPrebuildExporter, NapiStaticGraph, NapiStaticResourceRegistry, buildGraphFromCsvs, buildBusinessDataFromCsv, extensionCoerce, extensionRenderDisplay, extensionResolveMarkers, hasExtensionHandler, getRegisteredExtensionHandlers, parseSkosXml, parseSkosXmlToCollection, importPrebuild } = nativeBinding
|
|
313
|
+
const { NapiRdmCache, NapiNodeConfigManager, NapiTileData, NapiStaticTile, NapiPseudoValue, NapiPseudoList, NapiPopulateResult, NapiEnsureNodegroupResult, NapiValuesFromNodegroupResult, NapiResourceInstanceWrapper, NapiResourceModelWrapper, NapiPrebuildExporter, NapiStaticGraph, NapiStaticResourceRegistry, buildGraphFromCsvs, buildBusinessDataFromCsv, extensionCoerce, extensionRenderDisplay, extensionResolveMarkers, hasExtensionHandler, getRegisteredExtensionHandlers, parseSkosXml, parseSkosXmlToCollection, buildAliasToCollectionMap, findNeededCollections, isValidUuid, getDefaultResolvableDatatypes, getDefaultConfigKeys, importPrebuild } = nativeBinding
|
|
314
314
|
|
|
315
315
|
module.exports.NapiRdmCache = NapiRdmCache
|
|
316
316
|
module.exports.NapiNodeConfigManager = NapiNodeConfigManager
|
|
@@ -335,4 +335,9 @@ module.exports.hasExtensionHandler = hasExtensionHandler
|
|
|
335
335
|
module.exports.getRegisteredExtensionHandlers = getRegisteredExtensionHandlers
|
|
336
336
|
module.exports.parseSkosXml = parseSkosXml
|
|
337
337
|
module.exports.parseSkosXmlToCollection = parseSkosXmlToCollection
|
|
338
|
+
module.exports.buildAliasToCollectionMap = buildAliasToCollectionMap
|
|
339
|
+
module.exports.findNeededCollections = findNeededCollections
|
|
340
|
+
module.exports.isValidUuid = isValidUuid
|
|
341
|
+
module.exports.getDefaultResolvableDatatypes = getDefaultResolvableDatatypes
|
|
342
|
+
module.exports.getDefaultConfigKeys = getDefaultConfigKeys
|
|
338
343
|
module.exports.importPrebuild = importPrebuild
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alizarin/napi",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.94",
|
|
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.
|
|
34
|
-
"@alizarin/napi-darwin-x64": "2.0.0-alpha.
|
|
35
|
-
"@alizarin/napi-linux-x64-gnu": "2.0.0-alpha.
|
|
33
|
+
"@alizarin/napi-win32-x64-msvc": "2.0.0-alpha.94",
|
|
34
|
+
"@alizarin/napi-darwin-x64": "2.0.0-alpha.94",
|
|
35
|
+
"@alizarin/napi-linux-x64-gnu": "2.0.0-alpha.94"
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -82,6 +82,64 @@ impl NapiRdmCache {
|
|
|
82
82
|
pub fn collection_count(&self) -> u32 {
|
|
83
83
|
self.inner.len() as u32
|
|
84
84
|
}
|
|
85
|
+
|
|
86
|
+
/// Check if a collection is already in the cache.
|
|
87
|
+
#[napi]
|
|
88
|
+
pub fn has_collection(&self, collection_id: String) -> bool {
|
|
89
|
+
self.inner.has_collection(&collection_id)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/// Add a collection from a JSON string of concepts.
|
|
93
|
+
#[napi]
|
|
94
|
+
pub fn add_collection_from_json(
|
|
95
|
+
&mut self,
|
|
96
|
+
collection_id: String,
|
|
97
|
+
json_str: String,
|
|
98
|
+
) -> Result<()> {
|
|
99
|
+
self.inner
|
|
100
|
+
.add_collection_from_json(&collection_id, &json_str)
|
|
101
|
+
.map_err(|e| napi::Error::from_reason(format!("Failed to add collection: {e}")))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/// Get the parent concept ID for a concept within a collection.
|
|
105
|
+
#[napi]
|
|
106
|
+
pub fn get_parent_id(&self, collection_id: String, concept_id: String) -> Option<String> {
|
|
107
|
+
self.inner.get_parent_id(&collection_id, &concept_id)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/// Remove a collection from the cache.
|
|
111
|
+
#[napi]
|
|
112
|
+
pub fn remove_collection(&mut self, collection_id: String) -> bool {
|
|
113
|
+
self.inner.remove_collection(&collection_id)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/// Clear all collections from the cache.
|
|
117
|
+
#[napi]
|
|
118
|
+
pub fn clear(&mut self) {
|
|
119
|
+
self.inner.clear();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/// Resolve labels to UUIDs using this cache for lookups.
|
|
123
|
+
#[napi]
|
|
124
|
+
pub fn resolve_labels(
|
|
125
|
+
&self,
|
|
126
|
+
tree_json: String,
|
|
127
|
+
alias_to_collection: HashMap<String, String>,
|
|
128
|
+
strict: bool,
|
|
129
|
+
) -> Result<serde_json::Value> {
|
|
130
|
+
let tree: serde_json::Value = serde_json::from_str(&tree_json)
|
|
131
|
+
.map_err(|e| napi::Error::from_reason(format!("Invalid tree JSON: {e}")))?;
|
|
132
|
+
|
|
133
|
+
let resolved = alizarin_core::label_resolution::resolve_labels(
|
|
134
|
+
tree,
|
|
135
|
+
&alias_to_collection,
|
|
136
|
+
&self.inner,
|
|
137
|
+
strict,
|
|
138
|
+
)
|
|
139
|
+
.map_err(|e| napi::Error::from_reason(e.message))?;
|
|
140
|
+
|
|
141
|
+
Ok(resolved)
|
|
142
|
+
}
|
|
85
143
|
}
|
|
86
144
|
|
|
87
145
|
// =============================================================================
|
|
@@ -1128,6 +1186,23 @@ impl NapiResourceInstanceWrapper {
|
|
|
1128
1186
|
// Path resolution
|
|
1129
1187
|
// =========================================================================
|
|
1130
1188
|
|
|
1189
|
+
/// Resolve a dot-separated path to its target node metadata without needing tiles.
|
|
1190
|
+
///
|
|
1191
|
+
/// Returns { nodegroupId, isSingle, targetNodeId } — enough for the JS layer to
|
|
1192
|
+
/// lazy-load just that nodegroup's tiles before calling getValuesAtPath.
|
|
1193
|
+
#[napi(js_name = "resolvePath")]
|
|
1194
|
+
pub fn resolve_path(&self, path: String) -> Result<serde_json::Value> {
|
|
1195
|
+
let info = self
|
|
1196
|
+
.inner
|
|
1197
|
+
.resolve_path(&path, &self.model_access)
|
|
1198
|
+
.map_err(|e| napi::Error::from_reason(e.to_string()))?;
|
|
1199
|
+
Ok(serde_json::json!({
|
|
1200
|
+
"nodegroupId": info.nodegroup_id,
|
|
1201
|
+
"isSingle": info.is_single,
|
|
1202
|
+
"targetNodeId": info.target_node.nodeid,
|
|
1203
|
+
}))
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1131
1206
|
/// Resolve a dot-separated path and return a PseudoList.
|
|
1132
1207
|
#[napi]
|
|
1133
1208
|
pub fn get_values_at_path(&self, path: String) -> Result<NapiPseudoList> {
|
package/src/lib.rs
CHANGED
|
@@ -558,6 +558,82 @@ pub fn parse_skos_xml_to_collection(
|
|
|
558
558
|
serde_json::to_value(&collection).map_err(|e| napi::Error::from_reason(e.to_string()))
|
|
559
559
|
}
|
|
560
560
|
|
|
561
|
+
// ============================================================================
|
|
562
|
+
// Label resolution utilities
|
|
563
|
+
// ============================================================================
|
|
564
|
+
|
|
565
|
+
/// Build a mapping from node alias to collection ID based on graph definition.
|
|
566
|
+
///
|
|
567
|
+
/// Equivalent to WASM's `buildAliasToCollectionMap`.
|
|
568
|
+
#[napi(js_name = "buildAliasToCollectionMap")]
|
|
569
|
+
pub fn build_alias_to_collection_map(
|
|
570
|
+
graph_json: String,
|
|
571
|
+
resolvable_datatypes: Option<Vec<String>>,
|
|
572
|
+
config_keys: Option<Vec<String>>,
|
|
573
|
+
) -> Result<HashMap<String, String>> {
|
|
574
|
+
let graph: serde_json::Value = serde_json::from_str(&graph_json)
|
|
575
|
+
.map_err(|e| napi::Error::from_reason(format!("Invalid graph JSON: {e}")))?;
|
|
576
|
+
|
|
577
|
+
let config = alizarin_core::LabelResolutionConfig {
|
|
578
|
+
resolvable_datatypes: resolvable_datatypes.unwrap_or_else(|| {
|
|
579
|
+
alizarin_core::DEFAULT_RESOLVABLE_DATATYPES
|
|
580
|
+
.iter()
|
|
581
|
+
.map(|s| s.to_string())
|
|
582
|
+
.collect()
|
|
583
|
+
}),
|
|
584
|
+
config_keys: config_keys.unwrap_or_else(|| {
|
|
585
|
+
alizarin_core::DEFAULT_CONFIG_KEYS
|
|
586
|
+
.iter()
|
|
587
|
+
.map(|s| s.to_string())
|
|
588
|
+
.collect()
|
|
589
|
+
}),
|
|
590
|
+
strict: false,
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
Ok(alizarin_core::build_alias_to_collection_map(
|
|
594
|
+
&graph, &config,
|
|
595
|
+
))
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/// Scan a JSON tree to find which collections are needed for resolution.
|
|
599
|
+
///
|
|
600
|
+
/// Equivalent to WASM's `findNeededCollections`.
|
|
601
|
+
#[napi(js_name = "findNeededCollections")]
|
|
602
|
+
pub fn find_needed_collections(
|
|
603
|
+
tree_json: String,
|
|
604
|
+
alias_to_collection: HashMap<String, String>,
|
|
605
|
+
) -> Result<Vec<String>> {
|
|
606
|
+
let tree: serde_json::Value = serde_json::from_str(&tree_json)
|
|
607
|
+
.map_err(|e| napi::Error::from_reason(format!("Invalid tree JSON: {e}")))?;
|
|
608
|
+
|
|
609
|
+
let needed = alizarin_core::find_needed_collections(&tree, &alias_to_collection);
|
|
610
|
+
Ok(needed.into_iter().collect())
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/// Check if a string is a valid UUID.
|
|
614
|
+
#[napi(js_name = "isValidUuid")]
|
|
615
|
+
pub fn is_valid_uuid(s: String) -> bool {
|
|
616
|
+
alizarin_core::is_valid_uuid(&s)
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/// Get the default resolvable datatypes (concept, concept-list).
|
|
620
|
+
#[napi(js_name = "getDefaultResolvableDatatypes")]
|
|
621
|
+
pub fn get_default_resolvable_datatypes() -> Vec<String> {
|
|
622
|
+
alizarin_core::DEFAULT_RESOLVABLE_DATATYPES
|
|
623
|
+
.iter()
|
|
624
|
+
.map(|s| s.to_string())
|
|
625
|
+
.collect()
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/// Get the default config keys for collection IDs.
|
|
629
|
+
#[napi(js_name = "getDefaultConfigKeys")]
|
|
630
|
+
pub fn get_default_config_keys() -> Vec<String> {
|
|
631
|
+
alizarin_core::DEFAULT_CONFIG_KEYS
|
|
632
|
+
.iter()
|
|
633
|
+
.map(|s| s.to_string())
|
|
634
|
+
.collect()
|
|
635
|
+
}
|
|
636
|
+
|
|
561
637
|
// ============================================================================
|
|
562
638
|
// Prebuild import (high-level convenience)
|
|
563
639
|
// ============================================================================
|