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

@contember/schema-utils

Package Overview
Dependencies
Maintainers
5
Versions
259
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contember/schema-utils - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0-alpha.2

93

dist/src/acl/PredicateDefinitionProcessor.js

@@ -13,56 +13,61 @@ "use strict";

processInternal(entity, definition, handler, path) {
return Object.entries(definition).reduce((result, [key, value]) => {
const result = {};
for (const [key, value] of Object.entries(definition)) {
if (value === undefined) {
return result;
// do nothing
}
if (key === 'not') {
return {
...result,
not: this.processInternal(entity, value, handler, [
...path,
key,
]),
};
else if (key === 'not') {
result.not = this.processInternal(entity, value, handler, [
...path,
key,
]);
}
else if (key === 'and' || key === 'or') {
return {
...result,
[key]: value.map(it => this.processInternal(entity, it, handler, [...path, key])),
};
result[key] = value.map(it => this.processInternal(entity, it, handler, [...path, key]));
}
if (!entity.fields[key] && handler.handleUndefinedField) {
else if (!entity.fields[key] && handler.handleUndefinedField) {
const undefinedResult = handler.handleUndefinedField({ entity, name: key, value, path });
if (undefinedResult !== undefined) {
return { ...result, [key]: undefinedResult };
result[key] = undefinedResult;
}
}
const fieldWhere = (0, model_1.acceptFieldVisitor)(this.schema, entity, key, {
visitColumn: ({ entity, column }) => {
return handler.handleColumn({ entity, column, value: value, path });
},
visitRelation: ({ entity, relation, targetEntity }) => {
const processedValue = handler.handleRelation({
relation,
entity,
targetEntity,
value: value,
path,
});
if (typeof processedValue === 'object' &&
processedValue !== null &&
'constructor' in processedValue &&
processedValue.constructor.name === 'Object') {
return this.processInternal(targetEntity, processedValue, handler, [...path, key]);
}
return processedValue;
},
});
if (fieldWhere === undefined) {
return result;
else {
const fieldWhere = (0, model_1.acceptFieldVisitor)(this.schema, entity, key, {
visitColumn: ({ entity, column }) => {
return handler.handleColumn({
entity,
column,
value: value,
path,
});
},
visitRelation: ({ entity, relation, targetEntity }) => {
const processedValue = handler.handleRelation({
relation,
entity,
targetEntity,
value: value,
path,
});
if (typeof processedValue === 'object' &&
processedValue !== null &&
'constructor' in processedValue &&
processedValue.constructor.name === 'Object') {
return this.processInternal(targetEntity, processedValue, handler, [...path, key]);
}
return processedValue;
},
});
if (fieldWhere === undefined) {
// do nothing
}
else if (Array.isArray(fieldWhere) && fieldWhere.length === 2) {
result[fieldWhere[0]] = fieldWhere[1];
}
else {
result[key] = fieldWhere;
}
}
if (Array.isArray(fieldWhere) && fieldWhere.length === 2) {
return { ...result, [fieldWhere[0]]: fieldWhere[1] };
}
return { ...result, [key]: fieldWhere };
}, {});
}
return result;
}

@@ -69,0 +74,0 @@ }

@@ -25,2 +25,6 @@ import * as Typesafe from '@contember/typesafe';

readonly view?: Model.View | undefined;
readonly orderBy?: readonly {
readonly path: readonly string[];
readonly direction: Model.OrderDirection;
}[] | undefined;
};

@@ -27,0 +31,0 @@ };

@@ -146,2 +146,3 @@ "use strict";

view: viewSchema,
orderBy: orderBySchema,
}));

@@ -148,0 +149,0 @@ const entitySchemaCheck = true;

{
"name": "@contember/schema-utils",
"version": "1.2.1",
"version": "1.3.0-alpha.2",
"license": "Apache-2.0",

@@ -11,4 +11,4 @@ "main": "dist/src/index.js",

"dependencies": {
"@contember/schema": "^1.2.1",
"@contember/typesafe": "^1.2.1"
"@contember/schema": "^1.3.0-alpha.2",
"@contember/typesafe": "^1.3.0-alpha.2"
},

@@ -15,0 +15,0 @@ "devDependencies": {

import { acceptFieldVisitor } from '../model'
import { Acl, Input, Model } from '@contember/schema'
import { Acl, Input, Model, Writable } from '@contember/schema'

@@ -14,2 +14,3 @@ class PredicateDefinitionProcessor {

}
private processInternal<WhereValue, PredicateExtension = never>(

@@ -21,68 +22,66 @@ entity: Model.Entity,

): Input.Where<WhereValue> {
return Object.entries(definition).reduce((result, [key, value]) => {
const result: Writable<Input.Where<WhereValue>> = {}
for (const [key, value] of Object.entries(definition)) {
if (value === undefined) {
return result
}
if (key === 'not') {
return {
...result,
not: this.processInternal(entity, value as Acl.PredicateDefinition<PredicateExtension>, handler, [
...path,
key,
]),
}
// do nothing
} else if (key === 'not') {
result.not = this.processInternal(entity, value as Acl.PredicateDefinition<PredicateExtension>, handler, [
...path,
key,
])
} else if (key === 'and' || key === 'or') {
return {
...result,
[key]: (value as Acl.PredicateDefinition[]).map(it =>
this.processInternal(entity, it, handler, [...path, key]),
),
}
}
if (!entity.fields[key] && handler.handleUndefinedField) {
result[key] = (value as Acl.PredicateDefinition[]).map(it =>
this.processInternal(entity, it, handler, [...path, key]),
)
} else if (!entity.fields[key] && handler.handleUndefinedField) {
const undefinedResult = handler.handleUndefinedField({ entity, name: key, value, path })
if (undefinedResult !== undefined) {
return { ...result, [key]: undefinedResult }
result[key] = undefinedResult as (typeof result)[keyof typeof result]
}
}
const fieldWhere = acceptFieldVisitor<
WhereValue | Input.Where | Input.Condition | [string, WhereValue | Input.Where | Input.Condition] | undefined
>(this.schema, entity, key, {
visitColumn: ({ entity, column }) => {
return handler.handleColumn({ entity, column, value: value as Input.Condition | PredicateExtension, path })
},
visitRelation: ({ entity, relation, targetEntity }) => {
const processedValue = handler.handleRelation({
relation,
entity,
targetEntity,
value: value as Acl.PredicateVariable | PredicateExtension,
path,
})
if (
typeof processedValue === 'object' &&
processedValue !== null &&
'constructor' in processedValue &&
processedValue.constructor.name === 'Object'
) {
return this.processInternal(
} else {
const fieldWhere = acceptFieldVisitor<
WhereValue | Input.Where | Input.Condition | [string, WhereValue | Input.Where | Input.Condition] | undefined
>(this.schema, entity, key, {
visitColumn: ({ entity, column }) => {
return handler.handleColumn({
entity,
column,
value: value as Input.Condition | PredicateExtension,
path,
})
},
visitRelation: ({ entity, relation, targetEntity }) => {
const processedValue = handler.handleRelation({
relation,
entity,
targetEntity,
processedValue as Acl.PredicateDefinition<PredicateExtension>,
handler,
[...path, key],
)
}
return processedValue
},
})
if (fieldWhere === undefined) {
return result
value: value as Acl.PredicateVariable | PredicateExtension,
path,
})
if (
typeof processedValue === 'object' &&
processedValue !== null &&
'constructor' in processedValue &&
processedValue.constructor.name === 'Object'
) {
return this.processInternal(
targetEntity,
processedValue as Acl.PredicateDefinition<PredicateExtension>,
handler,
[...path, key],
)
}
return processedValue
},
})
if (fieldWhere === undefined) {
// do nothing
} else if (Array.isArray(fieldWhere) && fieldWhere.length === 2) {
result[fieldWhere[0]] = fieldWhere[1] as (typeof result)[keyof typeof result]
} else {
result[key] = fieldWhere as (typeof result)[keyof typeof result]
}
}
if (Array.isArray(fieldWhere) && fieldWhere.length === 2) {
return { ...result, [fieldWhere[0]]: fieldWhere[1] }
}
return { ...result, [key]: fieldWhere }
}, {})
}
return result
}

@@ -89,0 +88,0 @@ }

@@ -8,9 +8,5 @@ {

"references": [
{
"path": "../../schema/src"
},
{
"path": "../../typesafe/src"
}
{ "path": "../../schema/src" },
{ "path": "../../typesafe/src" }
]
}

@@ -172,2 +172,3 @@ import * as Typesafe from '@contember/typesafe'

view: viewSchema,
orderBy: orderBySchema,
}),

@@ -174,0 +175,0 @@ )

@@ -8,6 +8,4 @@ {

"references": [
{
"path": "../src"
}
{ "path": "../src" }
]
}

@@ -5,9 +5,5 @@ {

"references": [
{
"path": "./src"
},
{
"path": "./tests"
}
{ "path": "./src" },
{ "path": "./tests" }
]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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