@live-change/framework
Advanced tools
Comparing version 0.3.6 to 0.3.7
@@ -36,2 +36,4 @@ const utils = require("../utils.js") | ||
const defaults = utils.generateDefault(model.properties) | ||
if(!service.events[genName("Created")]) { // Events: | ||
@@ -41,3 +43,7 @@ service.event({ | ||
async execute(props) { | ||
await modelRuntime().create({ ...props.data, id: props[idName] }) | ||
console.log("CREATE !!!!") | ||
const data = utils.mergeDeep({}, defaults, props.data) | ||
console.log("DEFAULTS", JSON.stringify(defaults, null, " ")) | ||
console.log(`CREATE ${modelName} WITH DATA ${JSON.stringify(data, null, " ")}`) | ||
await modelRuntime().create({ ...data, id: props[idName] }) | ||
} | ||
@@ -44,0 +50,0 @@ }) |
@@ -116,2 +116,3 @@ | ||
async applyOps(ops) { | ||
if(ops.length == 0) return; | ||
let size = 0 | ||
@@ -118,0 +119,0 @@ for(const op of ops) { |
@@ -207,29 +207,37 @@ const { typeName } = require("../utils.js") | ||
if(reindex) { | ||
const currentAlias = await getCurrentAlias(model) | ||
const currentVersion = +currentAlias.slice(currentAlias.lastIndexOf("_")+1) | ||
const newVersion = currentVersion + 1 | ||
const newAlias = generateIndexName(model)+"_"+newVersion | ||
const metadata = generateMetadata(service.models[model]) | ||
console.log("METADATA", JSON.stringify(metadata,null, " ")) | ||
await search.indices.create({ | ||
index: newAlias, | ||
body: metadata | ||
}) | ||
try { | ||
const currentAlias = await getCurrentAlias(model) | ||
const currentVersion = +currentAlias.slice(currentAlias.lastIndexOf("_") + 1) | ||
const newVersion = currentVersion + 1 | ||
const newAlias = generateIndexName(model) + "_" + newVersion | ||
const metadata = generateMetadata(service.models[model]) | ||
console.log("METADATA", JSON.stringify(metadata, null, " ")) | ||
await search.indices.create({ | ||
index: newAlias, | ||
body: metadata | ||
}) | ||
for(let change of changes) { /// Create properties before reindex | ||
if(change.operation == 'createProperty') | ||
if(typeof change.property.defaultValue != 'undefined') | ||
await setPropertyDefaultValue(currentAlias, change.name, change.property.defaultValue) | ||
} | ||
for(let change of changes) { /// Create properties before reindex | ||
if(change.operation == 'createProperty') | ||
if(typeof change.property.defaultValue != 'undefined') | ||
await setPropertyDefaultValue(currentAlias, change.name, change.property.defaultValue) | ||
} | ||
await search.reindex({ body: { | ||
source: { index: currentAlias }, | ||
dest: { index: newAlias } | ||
}}) | ||
await search.reindex({ | ||
body: { | ||
source: { index: currentAlias }, | ||
dest: { index: newAlias } | ||
} | ||
}) | ||
await search.indices.putAlias({ | ||
name: generateIndexName(model), | ||
index: newAlias | ||
}) | ||
await search.indices.delete({ index: currentAlias }) | ||
await search.indices.putAlias({ | ||
name: generateIndexName(model), | ||
index: newAlias | ||
}) | ||
await search.indices.delete({ index: currentAlias }) | ||
} catch(error) { | ||
if(error.meta) console.error("REINDEXING ERROR", JSON.stringify(error.meta)) | ||
else console.error("REINDEXING ERROR", error) | ||
throw error | ||
} | ||
} else { | ||
@@ -236,0 +244,0 @@ for(let change of changes) { |
@@ -207,5 +207,18 @@ const fs = require("fs") | ||
function generateDefault(properties) { | ||
let result = {} | ||
for(const propName in properties) { | ||
const property = properties[propName] | ||
if(property.defaultValue) { | ||
result[propName] = property.defaultValue | ||
} else if(property.type == Object) { | ||
result[propName] = generateDefault(property.properties) | ||
} | ||
} | ||
return result | ||
} | ||
module.exports = { | ||
typeName, toJSON, setDifference, mapDifference, crudChanges, loadJson, saveJson, exists, | ||
getProperty, setProperty, getField, setField, isObject, mergeDeep | ||
getProperty, setProperty, getField, setField, isObject, mergeDeep, generateDefault | ||
} |
{ | ||
"name": "@live-change/framework", | ||
"version": "0.3.6", | ||
"version": "0.3.7", | ||
"description": "Live Change Framework - ultimate solution for real time mobile/web apps", | ||
@@ -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
117024
3252