@saulx/selva
Advanced tools
Comparing version 20.3.0 to 20.4.0
@@ -55,3 +55,2 @@ "use strict"; | ||
function parseGetOpts(schema, props, path, type = '$any', nestedMapping) { | ||
var _a; | ||
let isInherit = false; | ||
@@ -77,2 +76,51 @@ const pathPrefix = path === '' ? '' : path + '.'; | ||
} | ||
else if (k === '$inherit') { | ||
const asAny = props[k]; | ||
if (asAny.$item) { | ||
return [fields, mapping, true, false]; | ||
} | ||
else if (asAny.$merge === true) { | ||
return [fields, mapping, true, false]; | ||
} | ||
let $field = props.$field; | ||
if ($field) { | ||
if (!mapping[$field]) { | ||
mapping[$field] = { targetField: [path] }; | ||
} | ||
else if (!mapping[$field].targetField) { | ||
mapping[$field].targetField = [path]; | ||
} | ||
else { | ||
mapping[$field].targetField.push(path); | ||
} | ||
} | ||
else { | ||
$field = path; | ||
} | ||
const objKeys = Object.keys(props); | ||
if (objKeys.some((key) => !key.startsWith('$'))) { | ||
return [fields, mapping, true, false]; | ||
} | ||
let types = asAny === null || asAny === void 0 ? void 0 : asAny.$type; | ||
if (!types) { | ||
types = []; | ||
} | ||
else if (typeof types === 'string') { | ||
types = [types]; | ||
} | ||
const prefixes = types.map((type) => { | ||
if (type === 'root') { | ||
return 'ro'; | ||
} | ||
return schema.types[type].prefix; | ||
}); | ||
fields.get(type).add(`^${prefixes.join('')}:${$field}`); | ||
if (mapping[$field]) { | ||
mapping[$field].isInherit = true; | ||
} | ||
else { | ||
mapping[$field] = { isInherit: true }; | ||
} | ||
isInherit = true; | ||
} | ||
else if (k === '$field') { | ||
@@ -107,25 +155,2 @@ const $field = props[k]; | ||
} | ||
else if (k === '$inherit') { | ||
let types = (_a = props[k]) === null || _a === void 0 ? void 0 : _a.$type; | ||
if (!types) { | ||
types = []; | ||
} | ||
else if (typeof types === 'string') { | ||
types = [types]; | ||
} | ||
const prefixes = types.map((type) => { | ||
if (type === 'root') { | ||
return 'ro'; | ||
} | ||
return schema.types[type].prefix; | ||
}); | ||
fields.get(type).add(`^${prefixes.join('')}:${path}`); | ||
if (mapping[path]) { | ||
mapping[path].isInherit = true; | ||
} | ||
else { | ||
mapping[path] = { isInherit: true }; | ||
} | ||
isInherit = true; | ||
} | ||
else if (k === '$default') { | ||
@@ -466,2 +491,42 @@ fields.get(type).add(path); | ||
const result = await client.redis.selva_hierarchy_find(ctx.originDescriptors[ctx.db] || { name: ctx.db }, (0, util_2.makeLangArg)(client.schemas[ctx.db].languages, lang), '___selva_hierarchy', ...(0, _1.sourceFieldToFindArgs)(schema, sourceFieldSchema, sourceField, op.recursive, op.byType), ...(0, indexing_1.mkIndex)(schema, op), 'order', ((_c = op.options.sort) === null || _c === void 0 ? void 0 : _c.$field) || '', ((_d = op.options.sort) === null || _d === void 0 ? void 0 : _d.$order) || 'none', 'offset', op.options.offset, 'limit', op.options.limit, ...makeFieldsString(schema, fieldsOpt, isInherit), (0, util_1.padId)(op.id), ...args); | ||
if (isInherit) { | ||
const findIds = result.map((el) => el[0]); | ||
const inheritFields = new Set(); | ||
const inheritTypes = new Set(); | ||
const _ = [...fieldsOpt.get('$any')] | ||
.filter((f) => { | ||
return f.startsWith('^'); | ||
}) | ||
.map((f) => { | ||
const parts = f.split(':'); | ||
const typePart = parts[0].slice(1); | ||
for (let i = 0; i < typePart.length; i += 2) { | ||
const pf = typePart[i] + typePart[i + 1]; | ||
const type = schema.prefixToTypeMapping[pf]; | ||
inheritTypes.add(type); | ||
} | ||
const inheritField = parts[1]; | ||
inheritFields.add(inheritField); | ||
}); | ||
const fork = { | ||
isFork: true, | ||
$or: [...inheritTypes].map((t) => { | ||
return { | ||
$field: 'type', | ||
$operator: '=', | ||
$value: t, | ||
}; | ||
}), | ||
}; | ||
const inheritRpn = (0, selva_query_ast_parser_1.ast2rpn)(schema.types, fork, lang); | ||
const inheritMarkers = findIds.map((id) => { | ||
return (0, _1.addMarker)(client, ctx, { | ||
type: 'ancestors', | ||
id: id, | ||
fields: [...inheritFields], | ||
rpn: inheritRpn, | ||
}); | ||
}); | ||
await Promise.all(inheritMarkers); | ||
} | ||
await checkForNextRefresh(ctx, client, sourceField, (0, util_1.padId)(op.id), op.filter, lang); | ||
@@ -468,0 +533,0 @@ return result; |
{ | ||
"name": "@saulx/selva", | ||
"version": "20.3.0", | ||
"version": "20.4.0", | ||
"license": "MIT", | ||
@@ -54,3 +54,3 @@ "main": "dist/src/index.js", | ||
"@types/pg": "^8.6.1", | ||
"@saulx/selva-server": "20.3.0", | ||
"@saulx/selva-server": "20.4.0", | ||
"before-exit": "1.0.0", | ||
@@ -57,0 +57,0 @@ "async-exec": "^1.1.0", |
Sorry, the diff of this file is not supported yet
1220151
16854