Skip to content

Commit abf57ce

Browse files
author
Build Agent
committed
feat: implement latest oca-sdk-rs
Replace oca-bundle-semantics and oca-ast-semantics (external) with oca-sdk-rs (local) to consolidate dependencies and leverage the comprehensive API already available in oca-sdk-rs v2.0.0-rc.5. This migration maintains backward compatibility while improving dependency management and reducing external dependencies. Update README with: - Installation instructions - Feature overview - Multiple usage examples covering: - Build process explanation - Migration notes from oca-bundle-semantics - Available overlay types reference - Dependencies information Completely rewrite the WASM bindings to remove OCABox and Overlay remnants, focusing on OCABundle parsing and manipulation: New Features: - parseOCABundle() - parse JSON to OCABundle object - validateBundle() - validate OCABundle (placeholder for now) - bundleToJSON() - convert OCABundle to JSON string - getBundleDigest() - extract bundle digest (SAID) - getBundleVersion() - extract bundle version - getBundleType() - extract bundle type - getBundleClassification() - extract classification - getBundleAttributes() - get all attributes - getBundleFlaggedAttributes() - get all flagged attributes - hasOverlays() - check if bundle has overlays - getOverlayCount() - get number of overlays - getOverlayNames() - get all overlay names OCABundle Creation: - createEmptyBundle() - create empty bundle with classification - createBundleWithAttributes() - create bundle with attributes - createBundleWithOverlay() - create bundle with overlay - addAttributeToBundle() - add attribute to bundle - removeAttributeFromBundle() - remove attribute from bundle - addOverlayToBundle() - add overlay to bundle - removeOverlayFromBundle() - remove overlay from bundle
1 parent 20b856e commit abf57ce

5 files changed

Lines changed: 1302 additions & 1066 deletions

File tree

js/README.md

Lines changed: 216 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,225 @@
1-
## JS WASM bindings
1+
## JavaScript WASM Bindings
22

3-
### Build
3+
This package provides JavaScript bindings for OCA (Overlays Capture
4+
Architecture) using WebAssembly.
45

5-
Building local NPM package
6-
in `js/wasm` directory:
7-
`bash build-pkg.sh`
6+
It expose oca-sdk-rs into Java Scritp Ecosystem.
87

9-
### Run [tests](example/test)
8+
### Features
109

11-
Go to js/example directory and install dependencies
10+
-**Load and validate OCA bundles** from JSON
11+
-**Build OCA bundles** with attributes, overlays, and metadata
12+
-**Parse and generate AST** (Abstract Syntax Tree)
13+
-**Attribute validation** with overlay definitions
14+
-**Multiple attribute types**: Text, Numeric, Boolean, DateTime, Binary, Reference, Array, etc.
15+
-**Overlay support**: Meta, Label, Format, Information, CharacterEncoding, Unit, Conformances, EntryCodes, Entry, Link, and more
16+
-**Framing support** for ontology alignment
1217

18+
### Installation
19+
20+
```bash
21+
# Install locally
22+
cd oca-bindings/js
23+
yarn install
24+
25+
# Or use npm
26+
npm install
27+
28+
# Build the WASM package
29+
cd wasm
30+
bash build-pkg.sh
31+
32+
# The package will be built in the `pkg` directory
33+
```
34+
35+
### Usage Examples
36+
37+
#### Basic OCA Bundle Creation
38+
39+
```javascript
40+
const { OCABox, Attribute, create_nested_attr_type_from_js } = require('oca.js');
41+
42+
// Create a new OCA bundle
43+
const oca = new OCABox()
44+
.addClassification("GICS:35102020")
45+
.generateBundle();
46+
47+
console.log('OCA Bundle:', oca);
48+
```
49+
50+
#### Adding Attributes
51+
52+
```javascript
53+
const numericType = create_nested_attr_type_from_js("Numeric");
54+
const oca = new OCABox()
55+
.addClassification("GICS:35102020")
56+
.addAttribute(
57+
new Attribute("age")
58+
.setAttributeType(numericType)
59+
.setLabel({ eng: "Age", pol: "Wiek" })
60+
.setFormat("0-120")
61+
)
62+
.generateBundle();
1363
```
64+
65+
#### Working with Multiple Languages
66+
67+
```javascript
68+
const oca = new OCABox()
69+
.addClassification("GICS:35102020")
70+
.addMeta("name", {
71+
eng: "Driving Licence",
72+
pol: "Prawo Jazdy"
73+
})
74+
.addMeta("description", {
75+
eng: "DL desc",
76+
pol: "PJ desc"
77+
})
78+
.generateBundle();
79+
```
80+
81+
#### Parsing Existing OCA Bundles
82+
83+
```javascript
84+
const oca_bundle_json = require('./path/to/oca.json');
85+
const oca_box = new OCABox()
86+
.load(oca_bundle_json)
87+
.addClassification("test_classification");
88+
89+
const attributes = oca_box.attributes();
90+
const meta = oca_box.meta();
91+
92+
console.log('Attributes:', attributes);
93+
console.log('Metadata:', meta);
94+
```
95+
96+
#### Generating AST
97+
98+
```javascript
99+
const oca_box = new OCABox().load(oca_bundle_json);
100+
const ast = oca_box.toAST();
101+
102+
console.log('AST Version:', ast.version);
103+
console.log('Commands:', ast.commands);
104+
```
105+
106+
#### Attribute Types Support
107+
108+
```javascript
109+
const textType = create_nested_attr_type_from_js("Text");
110+
const numericType = create_nested_attr_type_from_js("Numeric");
111+
const booleanType = create_nested_attr_type_from_js("Boolean");
112+
const dateTimeType = create_nested_attr_type_from_js("DateTime");
113+
const binaryType = create_nested_attr_type_from_js("Binary");
114+
115+
// Create array types
116+
const arrayType = create_nested_attr_type_from_js(["Text"]);
117+
const arrayTypeWithRef = create_nested_attr_type_from_js(["refs:ABC123"]);
118+
119+
// Reference to another bundle
120+
const refType = create_nested_attr_type_from_js("refs:EF5ERATRBBN_ewEo9buQbznirhBmvrSSC0O2GIR4Gbfs");
121+
```
122+
123+
#### Overlays
124+
125+
The OCA bundle supports various overlay types:
126+
127+
```javascript
128+
const oca = new OCABox()
129+
.addClassification("GICS:35102020")
130+
.addMeta("name", { eng: "Name" })
131+
.addMeta("description", { eng: "Description" })
132+
.addAttribute(
133+
new Attribute("attr_name")
134+
.setAttributeType(numericType)
135+
.setLabel({ eng: "Name: " })
136+
.setInformation({ eng: "En info" })
137+
.setEntries({
138+
o1: { eng: "Option 1", pol: "Opcja 1" },
139+
o2: { eng: "Option 2", pol: "Opcja 2" }
140+
})
141+
.setLinks({ "target_bundle_said": "name" })
142+
.setFramings({
143+
frame_id: "SNOMEDCT",
144+
frame_label: "Clinical Terms",
145+
frame_location: "https://bioportal.bioontology.org/ontologies/SNOMEDCT",
146+
frame_version: "2023AA"
147+
}, {
148+
"http://purl.bioontology.org/ontology/snomedct/703503000": {
149+
predicate_id: "skos:exactMatch",
150+
framing_justification: "semapv:ManualMappingCuration",
151+
}
152+
})
153+
)
154+
.generateBundle();
155+
```
156+
157+
### Validation
158+
159+
```javascript
160+
const { Validator } = require('oca.js');
161+
const oca = new OCABox().addClassification("GICS:35102020").generateBundle();
162+
const validator = new Validator();
163+
164+
const result = validator.validate(oca);
165+
console.log('Valid:', result.success);
166+
if (!result.success) {
167+
console.log('Errors:', result.errors);
168+
}
169+
```
170+
171+
### TypeScript Support
172+
173+
The bindings include TypeScript definitions. You can use them in TypeScript projects:
174+
175+
```typescript
176+
import { OCABox, Attribute, create_nested_attr_type_from_js } from 'oca.js';
177+
178+
const numericType = create_nested_attr_type_from_js("Numeric");
179+
const oca = new OCABox()
180+
.addClassification("GICS:35102020")
181+
.addAttribute(
182+
new Attribute("age")
183+
.setAttributeType(numericType)
184+
.setLabel({ eng: "Age" })
185+
)
186+
.generateBundle();
187+
```
188+
189+
### Running Tests
190+
191+
```bash
192+
# Install dependencies
193+
cd example
14194
yarn install
195+
# or
196+
npm install
197+
198+
# Run all tests
15199
yarn test
200+
# or
201+
npm test
202+
203+
# Run a specific test
204+
yarn test parsing-oca.test.ts
16205
```
206+
207+
### Build Process
208+
209+
The build process uses `wasm-bindgen` to compile Rust code to JavaScript:
210+
211+
1. **Rust compilation**: `cargo build --target wasm32-unknown-unknown --release`
212+
2. **WASM generation**: `wasm-bindgen` converts .wasm to JS bindings
213+
3. **Package generation**: Creates npm package in `pkg/` directory
214+
4. **TypeScript definitions**: Automatically generated from Rust code
215+
216+
### License
217+
218+
**EUPL-1.2** (European Union Public License)
219+
220+
### Links
221+
222+
- [OCA Specification](https://github.com/the-human-colossus-foundation/oca-spec)
223+
- [OCA SDK](https://github.com/THCLab/oca-sdk-rs)
224+
- [OCA Bindings (Dart)](./dart)
225+
- [OCA Bindings (Flutter)](./dart)

0 commit comments

Comments
 (0)