Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@live-change/framework

Package Overview
Dependencies
Maintainers
1
Versions
316
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@live-change/framework - npm Package Compare versions

Comparing version 0.3.14 to 0.3.15

38

lib/runtime/SearchIndexer.js

@@ -12,4 +12,33 @@

function prepareArray(data, of) {
if(!data) return
if(of.properties) for(let i = 0; i < data.length; i++) prepareObject(data[i], of)
if(of.of) for(let i = 0; i < data.length; i++) prepareArray(data[i], of.of)
}
function prepareObject(data, props) {
if(!data) return
for(const propName in props) {
if(!data.hasOwnProperty(propName)) continue
const prop = props[propName]
if(prop.properties) {
prepareObject(data[propName], prop.properties)
}
if(prop.of) {
prepareArray(data[propName], prop.of)
}
if(prop.search) {
if(Array.isArray(prop.search)) {
for(const search of prop.search) {
if(search.name) data[search.name] = data[propName]
}
} else {
if(prop.search.name) data[prop.search.name] = data[propName]
}
}
}
}
class SearchIndexer {
constructor(dao, databaseName, sourceType, sourceName, elasticsearch, indexName ) {
constructor(dao, databaseName, sourceType, sourceName, elasticsearch, indexName, model ) {
this.dao = dao

@@ -21,2 +50,3 @@ this.databaseName = databaseName

this.indexName = indexName
this.model = model
this.state = SEARCH_INDEX_NOTSTARTED

@@ -39,2 +69,6 @@ this.lastUpdateId = ''

prepareObject(object) {
prepareObject(object, this.model.properties)
}
async start() {

@@ -159,2 +193,3 @@ const searchIndexState = await this.dao.get(

operations[pos++] = { index: { _id: op.operation.object.id } }
this.prepareObject(op.operation.object)
operations[pos++] = op.operation.object

@@ -242,2 +277,3 @@ }

operations[i * 2] = { index: { _id: rows[i].id } }
this.prepareObject(rows[i])
operations[i * 2 + 1] = rows[i]

@@ -244,0 +280,0 @@ }

4

lib/runtime/Service.js

@@ -220,3 +220,3 @@ const Model = require("./Model.js")

const indexer = new SearchIndexer(
this.dao, this.databaseName, 'Table', model.tableName, elasticsearch, indexName
this.dao, this.databaseName, 'Table', model.tableName, elasticsearch, indexName, model.definition
)

@@ -231,3 +231,3 @@ this.searchIndexers.push(indexer)

const indexer = new SearchIndexer(
this.dao, this.databaseName, 'Index', model.tableName, elasticsearch, indexName
this.dao, this.databaseName, 'Index', model.tableName, elasticsearch, indexName, index.definition
)

@@ -234,0 +234,0 @@ this.searchIndexers.push(indexer)

const { typeName } = require("../utils.js")
const SearchIndexer = require("../runtime/SearchIndexer.js")
function generatePropertyMapping(property) {
function generatePropertyMapping(property, search) {
//console.log("GENERATE PROPERTY MAPPING", property)
let options = property.search ? JSON.parse(JSON.stringify(property.search)) : {}
let options = search ? JSON.parse(JSON.stringify(search)) : {}
if(property.search === false) options.enabled = false

@@ -18,18 +19,34 @@ if(!options.type) {

}
if(options.type == 'object' && !options.properties) {
options.properties = {}
for(let propName in property.properties) {
options.properties[propName] = generatePropertyMapping(property.properties[propName])
//console.log("GENERATED PROPERTY MAPPING", property, ":", options)
return options
}
function generatePropertyMappings(property, propName) {
const bindings = property.search
? (Array.isArray(property.search) ? property.search : [ property.search ])
: [null]
const mappings = {}
for(const binding of bindings) {
const options = generatePropertyMapping(property, binding)
//console.log("OPTIONS", options)
if(options.type == 'object' && !options.properties) {
options.properties = {}
for(let propName in property.properties) {
const mappings = generatePropertyMappings(property.properties[propName], propName)
for(let key in mappings) options.properties[key] = mappings[key]
}
options.include_in_root = true
}
options.include_in_root = true
}
if(options.type == 'array') {
if(typeName(property.of) != "Object") {
return generatePropertyMapping(property.of)
} else {
options.type = 'nested'
if(options.type == 'array') {
if(typeName(property.of) != "Object") {
return generatePropertyMappings(property.of, propName)
} else {
options.type = 'nested'
}
}
delete options.name
mappings[(binding && binding.name) || propName] = options
}
//console.log("GENERATED PROPERTY MAPPING", property, ":", options)
return options
//console.log("PROPERTY MAPPINGS", propName, mappings)
return mappings
}

@@ -39,4 +56,5 @@

let properties = {}
for(let propName in model.properties) {
properties[propName] = generatePropertyMapping(model.properties[propName])
for(const propName in model.properties) {
const mappings = generatePropertyMappings(model.properties[propName], propName)
for(let key in mappings) properties[key] = mappings[key]
}

@@ -126,4 +144,4 @@ let settings = (typeof model.search == 'object') ? model.search.settings : undefined

let definition = service.models[model]
if(!definition.search) return;
for(let change of changes) {
if(!definition.search && change.operation!='searchDisabled' && change.operation!='deleteModel') return
switch (change.operation) {

@@ -168,5 +186,9 @@ case "createModel": {

case "searchDisabled": {
const currentAlias = await getCurrentAlias(change.model)
await search.indices.delete({ name: currentAlias })
await search.indices.deleteAlias({ name: generateIndexName(change.model) })
console.log("SEARCH DISABLED")
const indexName = generateIndexName(change.model)
const currentAlias = await getCurrentAlias(change.model).catch(e=>null)
console.log("DELETE INDEX", currentAlias, "AND ALIAS", indexName)
if(currentAlias) await search.indices.delete({ index: currentAlias }).catch(e=>{})
await search.indices.deleteAlias({ name: indexName }).catch(e=>{})
await app.dao.request(['database', 'delete'], app.databaseName, 'searchIndexes', indexName)
} break

@@ -229,3 +251,3 @@ case "renameModel": {

await search.reindex({
/*await search.reindex({
body: {

@@ -235,4 +257,9 @@ source: { index: currentAlias },

}
})
})*/
const indexer = new SearchIndexer(app.dao, app.databaseName, 'Table',
generateTableName(model), search, newAlias, service.models[model])
await indexer.copyAll()
await search.indices.putAlias({

@@ -239,0 +266,0 @@ name: generateIndexName(model),

{
"name": "@live-change/framework",
"version": "0.3.14",
"version": "0.3.15",
"description": "Live Change Framework - ultimate solution for real time mobile/web apps",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc