@ozkarjs/vhir
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -8,1 +8,2 @@ export { Consent } from './resource/consent'; | ||
export * from './linearization/ipld'; | ||
export { JsonParser } from './utils/jsonParser'; |
@@ -8,2 +8,3 @@ export { Consent } from './resource/consent'; | ||
export * from './linearization/ipld'; | ||
export { JsonParser } from './utils/jsonParser'; | ||
//# sourceMappingURL=index.js.map |
@@ -27,3 +27,3 @@ import { type Query } from '../query/query'; | ||
export type DatasetInfo = { | ||
keyNumber: number; | ||
keyNumber?: number; | ||
}; | ||
@@ -30,0 +30,0 @@ export type MerkleInfo = { |
@@ -93,2 +93,13 @@ import { MerkleMap } from 'o1js'; | ||
}): MerkleMap; | ||
export declare class JsonParser { | ||
static countKeys(obj: any): number; | ||
static linearDataToMerkleMap(linearData: { | ||
[key: string]: JsonValue; | ||
}): MerkleMap; | ||
static linearizeJson(jsonObject: { | ||
[key: string]: JsonValue; | ||
}, parentKey?: string): { | ||
[key: string]: JsonValue; | ||
}; | ||
} | ||
export {}; |
@@ -42,2 +42,53 @@ import { MerkleMap, Field } from 'o1js'; | ||
} | ||
export class JsonParser { | ||
static countKeys(obj) { | ||
let count = 0; | ||
for (let key in obj) { | ||
if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
count++; | ||
if (typeof obj[key] === 'object' && obj[key] !== null) { | ||
count += this.countKeys(obj[key]); | ||
} | ||
} | ||
} | ||
return count; | ||
} | ||
static linearDataToMerkleMap(linearData) { | ||
const merkleMap = new MerkleMap(); | ||
let value; | ||
for (const [path, value] of Object.entries(linearData)) { | ||
//TODO: handle large strings (bigger than a string packed field) | ||
let fieldValue; | ||
const packedPath = TextInput.fromString(path.toString()); | ||
if (typeof value === 'string') { | ||
fieldValue = TextInput.fromString(value.toString()).packed; | ||
} | ||
else if (typeof value === 'number') { | ||
fieldValue = Field(value); | ||
} | ||
else { | ||
fieldValue = Field(0); | ||
} | ||
//TODO: handle integers and booleans | ||
const packedValue = TextInput.fromString(value.toString()); | ||
merkleMap.set(packedPath.packed, fieldValue); | ||
} | ||
return merkleMap; | ||
} | ||
static linearizeJson(jsonObject, parentKey = '') { | ||
let kvPairs = {}; | ||
for (const key in jsonObject) { | ||
if (!jsonObject.hasOwnProperty(key)) | ||
continue; | ||
const fullKey = parentKey ? `${parentKey}.${key}` : key; | ||
if (typeof jsonObject[key] === 'object' && jsonObject[key] !== null) { | ||
Object.assign(kvPairs, linearizeJson(jsonObject[key], fullKey)); | ||
} | ||
else { | ||
kvPairs[fullKey] = jsonObject[key]; | ||
} | ||
} | ||
return kvPairs; | ||
} | ||
} | ||
//# sourceMappingURL=jsonParser.js.map |
{ | ||
"name": "@ozkarjs/vhir", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"author": "", | ||
@@ -5,0 +5,0 @@ "main": "build/src/index.js", |
import { PrivateKey, verify } from 'o1js'; | ||
import { parseJSON } from '../src/customTypes/jsonParsing'; | ||
import jsontest from './data/jsontest.json'; | ||
import heartbeat from './data/observations/heartbeat.json'; | ||
import heartbeat from './datasample/heartbeat.json'; | ||
import { test, expect, it, describe, beforeAll } from '@jest/globals'; | ||
@@ -24,3 +22,3 @@ import { | ||
import { type PerformanceData } from '../src/types/monitoring.types.js'; | ||
import { Utils } from './utils/utils.js'; | ||
// Get the directory name of the current module | ||
@@ -37,6 +35,6 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
it('correctly verifies value of a specific key', async () => { | ||
const json = parseJSON(JSON.stringify(jsontest)); | ||
json.key('value').assertEqualString('"92"'); | ||
}); | ||
// it('correctly verifies value of a specific key', async () => { | ||
// const json = parseJSON(JSON.stringify(jsontest)); | ||
// json.key('value').assertEqualString('"92"'); | ||
// }); | ||
@@ -181,2 +179,7 @@ it('linearize json and builds a merkle map with direct value storage', async () => { | ||
const keyNumber = Utils.countKeys(heartbeat); | ||
performanceData.datasetInfo ??= {}; // Initialize 'performanceData.datasetInfo' if it is undefined | ||
performanceData.datasetInfo.keyNumber = keyNumber; | ||
const ln = IPLD.LinearModel.fromJS(heartbeat); | ||
@@ -206,6 +209,2 @@ | ||
if (!performanceData.datasetInfo) { | ||
performanceData.datasetInfo = { keyNumber: ln.size }; // Initialize with default values | ||
} | ||
performanceData.merkleInfo.merkleLength = map.witnessLength; | ||
@@ -230,3 +229,2 @@ | ||
proofE.proof | ||
proofE | ||
); | ||
@@ -249,4 +247,4 @@ | ||
__dirname, | ||
'logs/performance/jsonproving/', | ||
`light-${timestamp}.json` | ||
'perflogs/', | ||
`heartbeat-${timestamp}.json` | ||
); | ||
@@ -253,0 +251,0 @@ fs.writeFileSync(logPath, JSON.stringify(performanceData, null, 2)); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
795014
159
7087