chia-changelist-generator
Advanced tools
Comparing version 1.0.0 to 1.0.1
44
index.js
@@ -27,3 +27,3 @@ const Datalayer = require("chia-datalayer"); | ||
const generateChange = async (storeId, key, value) => { | ||
const generateChange = async (storeId, action, key, value) => { | ||
if (!isValidHexadecimal(key)) { | ||
@@ -39,6 +39,16 @@ throw new Error(`Key ${key} is not a valid hexadecimal string`); | ||
const existingKeys = await datalayer.getKeys({ id: storeId }); | ||
if (action === "insert") { | ||
return await generateInsertChange(storeId, existingKeys, key, value); | ||
} else if (action === "delete") { | ||
return await generateDeleteChange(storeId, existingKeys, key); | ||
} else { | ||
throw new Error(`Action ${action} is not supported`); | ||
} | ||
}; | ||
const generateInsertChange = async (existingKeys, key, value) => { | ||
const change = []; | ||
const existingKeys = await datalayer.getKeys({ id: storeId }); | ||
if (existingKeys.includes(key)) { | ||
@@ -60,3 +70,21 @@ change.push({ | ||
const generateChangeList = async (storeId, keyValueArray, options = {}) => { | ||
const generateDeleteChange = async (key) => { | ||
const change = []; | ||
if (existingKeys.includes(key)) { | ||
change.push({ | ||
action: "delete", | ||
key: key, | ||
}); | ||
} | ||
return change; | ||
}; | ||
const generateChangeList = async ( | ||
storeId, | ||
action, | ||
keyValueArray, | ||
options = {} | ||
) => { | ||
if (!options.chunkChangeList) { | ||
@@ -69,4 +97,4 @@ options.chunkChangeList = false; | ||
for (const keyValue of keyValueArray) { | ||
const {key, value} = keyValue; | ||
const change = await generateChange(storeId, key, value); | ||
const { key, value } = keyValue; | ||
const change = await generateChange(storeId, action, key, value); | ||
changeList.push(...change); | ||
@@ -85,3 +113,3 @@ } | ||
decodeHex, | ||
generateChangeList | ||
}; | ||
generateChangeList, | ||
}; |
{ | ||
"name": "chia-changelist-generator", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Easily Generate a ChangeList for Chia DataLayer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6623
94