New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@live-change/relations-plugin

Package Overview
Dependencies
Maintainers
0
Versions
254
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@live-change/relations-plugin - npm Package Compare versions

Comparing version 0.9.20 to 0.9.21

3

boundToAny.js
import {
defineAnyProperties, defineAnyIndex,
processModelsAnyAnnotation, generateAnyId
processModelsAnyAnnotation, generateAnyId, defineAnyTypeIndexes
} from './utilsAny.js'

@@ -24,2 +24,3 @@

defineAnyIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
defineAnyTypeIndexes(config, context, context.otherPropertyNames.length === 1)

@@ -26,0 +27,0 @@ defineObjectView(config, context,

@@ -47,7 +47,7 @@ import { extractObjectData, extractIdentifiers } from "./dataUtils.js"

//console.log("BUCKET", bucket)
if(bucket.length == 0) break
if(bucket.length === 0) break
gt = bucket[bucket.length - 1].id
const copyTriggerPromises = bucket.map(entity => cb({ ...entity, id: entity.to }))
await Promise.all(copyTriggerPromises)
} while (bucket.length == bucketSize)
} while (bucket.length === bucketSize)
}

@@ -139,3 +139,3 @@ }

const other = others[i]
if(other == parentType) {
if(other === parentType) {
newIdentifiers[otherPropertyNames[i]] = parent

@@ -142,0 +142,0 @@ }

import {
defineAnyProperties, defineAnyIndexes,
processModelsAnyAnnotation, addAccessControlAnyParents, generateAnyId, defineDeleteByOwnerEvents,
defineParentDeleteTrigger
defineParentDeleteTrigger, defineAnyTypeIndexes
} from './utilsAny.js'

@@ -29,2 +29,3 @@

defineAnyIndexes(context.model, context.otherPropertyNames)
defineAnyTypeIndexes(config, context, false)

@@ -31,0 +32,0 @@ if(config.sortBy) {

{
"name": "@live-change/relations-plugin",
"version": "0.9.20",
"version": "0.9.21",
"description": "",

@@ -25,6 +25,6 @@ "main": "index.js",

"dependencies": {
"@live-change/framework": "^0.9.20",
"@live-change/framework": "^0.9.21",
"pluralize": "^8.0.0"
},
"gitHead": "6524c2dedbb137e95e9aa07eaf9503d68d7b9093"
"gitHead": "362e325d1c636f9c0f2fb6432e209c5c56f46919"
}
import {
defineAnyProperties, defineAnyIndexes,
processModelsAnyAnnotation, generateAnyId, addAccessControlAnyParents,
defineDeleteByOwnerEvents, defineParentDeleteTrigger
defineDeleteByOwnerEvents, defineParentDeleteTrigger, defineAnyTypeIndexes,
} from './utilsAny.js'

@@ -40,2 +40,3 @@

defineAnyIndexes(context.model, context.otherPropertyNames, false)
defineAnyTypeIndexes(config, context, context.otherPropertyNames.length === 1)

@@ -42,0 +43,0 @@ defineObjectView(config, context,

import {
defineAnyProperties, defineAnyIndex, processModelsAnyAnnotation
defineAnyProperties, defineAnyIndex, processModelsAnyAnnotation, defineAnyTypeIndexes
} from './utilsAny.js'

@@ -24,2 +24,3 @@

defineAnyIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
defineAnyTypeIndexes(config, context, false)

@@ -26,0 +27,0 @@ if(config.sortBy) {

@@ -10,3 +10,3 @@ import App from "@live-change/framework"

function extractTypeAndIdParts(otherPropertyNames, properties) {
export function extractTypeAndIdParts(otherPropertyNames, properties) {
const typeAndIdParts = []

@@ -20,3 +20,3 @@ for (const propertyName of otherPropertyNames) {

function extractIdentifiersWithTypes(otherPropertyNames, properties) {
export function extractIdentifiersWithTypes(otherPropertyNames, properties) {
const identifiers = {}

@@ -30,3 +30,4 @@ for (const propertyName of otherPropertyNames) {

function generateAnyId(otherPropertyNames, properties) {
export function generateAnyId(otherPropertyNames, properties) {
/*
console.log("GEN ID", otherPropertyNames, properties, '=>',

@@ -37,3 +38,3 @@ otherPropertyNames

.map(p => JSON.stringify(properties[p])).join(':'))
*/
return otherPropertyNames

@@ -45,3 +46,3 @@ .map(p => [p+'Type', p])

function defineAnyProperties(model, names) {
export function defineAnyProperties(model, names) {
const identifiers = {}

@@ -64,9 +65,10 @@ for (let i = 0; i < names.length; i++) {

function defineAnyIndex(model, what, props) {
export function defineAnyIndex(model, what, props) {
model.indexes['by' + what] = new IndexDefinition({
property: props.map(prop => [prop+'Type', prop]).flat()
property: props.map(prop => [prop+'Type', prop]).flat(),
hash: true
})
}
function defineAnyIndexes(model, props, fullIndex = true) {
export function defineAnyIndexes(model, props, fullIndex = true) {
const propCombinations = allCombinations(props)

@@ -80,3 +82,3 @@ for(const propCombination of propCombinations) {

function processModelsAnyAnnotation(service, app, annotation, multiple, cb) {
export function processModelsAnyAnnotation(service, app, annotation, multiple, cb) {
if (!service) throw new Error("no service")

@@ -158,3 +160,3 @@ if (!app) throw new Error("no app")

function addAccessControlAnyParents(context) {
export function addAccessControlAnyParents(context) {
const { modelRuntime } = context

@@ -178,3 +180,3 @@ context.model.accessControlParents = async (what) => {

function prepareAccessControl(accessControl, names) {
export function prepareAccessControl(accessControl, names) {
if(typeof accessControl == 'object') {

@@ -198,3 +200,3 @@ accessControl.objects = accessControl.objects ?? ((params) => names.map(name => ({

function defineDeleteByOwnerEvents(config, context) {
export function defineDeleteByOwnerEvents(config, context) {
const {

@@ -238,13 +240,54 @@ service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName, otherPropertyNames, reverseRelationWord

function defineParentDeleteTrigger(config, context) {
export function defineParentDeleteTrigger(config, context) {
registerParentDeleteTriggers(context, config)
}
export {
extractTypeAndIdParts, extractIdentifiersWithTypes, defineAnyProperties,
defineAnyIndex, defineAnyIndexes,
processModelsAnyAnnotation, generateAnyId,
addAccessControlAnyParents,
prepareAccessControl,
defineDeleteByOwnerEvents, defineParentDeleteTrigger
export function defineAnyTypeIndexes(config, context, useId = false) {
const { service, model } = context
const tableName = service.name + '_' + model.name
if(useId) { // don't use indexes - only object id's - good for propertyOfAny with one parent
if(context.otherPossibleTypes[0]?.length) return // types defined in definition - no need for index
model.indexes[context.otherPropertyNames[0]+'Types'] = new IndexDefinition({
//property: [propertyName+'Type'],
function: async function(input, output, { tableName }) {
const table = await input.table(tableName)
await table.onChange(async (obj, oldObj) => {
const id = obj?.id ?? oldObj?.id
const type = id.slice(0, id.indexOf(':'))
const count = await table.count({ gte: type+':', lte: type+'_\xFF\xFF\xFF\xFF', limit: 1 })
if(count > 0) {
await output.put({ id: JSON.parse(type) })
} else {
await output.delete({ id: JSON.parse(type) })
}
})
},
parameters: { tableName: tableName }
})
return
}
for(let i = 0; i < context.otherPropertyNames.length; i++) {
const propertyName = context.otherPropertyNames[i]
const propertyTypes = context.otherPossibleTypes[i]
if(propertyTypes.length !== 0) continue // types defined in definition - no need for index
const srcIndexName = 'by' + propertyName[0].toUpperCase() + propertyName.slice(1)
if(!model.indexes[srcIndexName]) throw new Error("Parent index not defined: " + srcIndexName)
model.indexes[propertyName+'Types'] = new IndexDefinition({
//property: [propertyName+'Type'],
function: async function(input, output, { indexName }) {
const index = await input.index(indexName)
await index.onChange(async (obj, oldObj) => {
const id = obj?.id ?? oldObj?.id
const type = id.slice(0, id.indexOf(':'))
const count = await index.count({ gte: type+':', lte: type+'_\xFF\xFF\xFF\xFF', limit: 1 })
if(count > 0) {
await output.put({ id: JSON.parse(type) })
} else {
await output.delete({ id: JSON.parse(type) })
}
})
},
parameters: { indexName: tableName + '_' + srcIndexName }
})
}
}
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