Comparing version 1.13.22 to 1.13.23
@@ -148,3 +148,3 @@ /// <reference types="fibjs" /> | ||
interface AppInternalCommunicationObj { | ||
inst?: FxOrmNS.Instance | ||
inst?: FxOrmNS.Instance | null | ||
acl?: FibAppACL.RoleActDescriptor | ||
@@ -214,3 +214,4 @@ error?: FibAppFinalError | ||
where?: string | FibApp.ReqWhere | ||
findby?: FibApp.ReqFindByItem|FibApp.ReqFindByItem[] | ||
// findby?: FibApp.ReqFindByItem|FibApp.ReqFindByItem[] | ||
findby?: FibApp.ReqFindByItem | ||
keys?: string | string[] | ||
@@ -217,0 +218,0 @@ skip?: number |
@@ -76,9 +76,9 @@ /// <reference types="fibjs" /> | ||
interface ExtendModelWrapper { | ||
// 'hasOne', 'hasMany' | ||
type: string; | ||
type: 'hasOne' | 'hasMany' | 'extendsTo'; | ||
reversed?: boolean; | ||
model: FibApp.FibAppORMModel; | ||
assoc_model: FibApp.FibAppORMModel; | ||
} | ||
interface FibAppFixedOrmExtendModelWrapper extends ExtendModelWrapper { | ||
extraProperties: { | ||
model_associated_models: { | ||
[modelName: string]: FibAppORMModel | ||
@@ -85,0 +85,0 @@ } |
@@ -14,2 +14,8 @@ /// <reference types="fibjs" /> | ||
} | ||
interface FilteredFindByInfo<T = any> { | ||
accessor: string, | ||
conditions: FxSqlQuerySubQuery.SubQueryConditions | ||
accessor_payload: FxOrmQuery.IChainFind | FxOrmModel.Model | ||
} | ||
} |
v1.13.22 / 2019-02-20 | ||
v1.13.23 / 2019-03-03 | ||
================== | ||
* support using rest api for extendsTo-type association. | ||
* rename `WEBX_CI_DB_DEBUG` to `WEBX_TEST_DB_DEBUG`. | ||
* test case fix. | ||
* upgrade @fxjs/orm; fix bad implements for findby-query in hasOne-type association. | ||
v1.13.22 / 2019-02-20 | ||
===================== | ||
* Release v1.13.22 | ||
* upgrade @fxjs/orm. | ||
@@ -6,0 +15,0 @@ |
@@ -55,2 +55,4 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
}); | ||
if (rel_model.type === 'extendsTo') | ||
return api.eput(req, orm, cls, id, extend, undefined, Object.assign({}, data)); | ||
const obj = get_1._get(cls, id, req.session, "write"); | ||
@@ -115,3 +117,6 @@ if (obj.error) | ||
}; | ||
const _createBy = rel_model.model.extends[spec_keys['createdBy']]; | ||
const is_extendsTo = rel_model.type === 'extendsTo'; | ||
const extendsToAssoc = is_extendsTo ? orm_assoc_1.get_extendsto_association_item(obj.inst, extend) : null; | ||
const key_model = is_extendsTo ? rel_model.assoc_model : rel_model.model; | ||
const _createBy = key_model.extends[spec_keys['createdBy']]; | ||
let _opt; | ||
@@ -125,4 +130,3 @@ let ros = []; | ||
delete d.extra; | ||
// const ro = new rel_model.model(d); | ||
const ro = ormUtils.create_instance_for_internal_api(rel_model.model, { | ||
let ro = ormUtils.create_instance_for_internal_api(key_model, { | ||
data: d, | ||
@@ -135,11 +139,13 @@ req_info: req | ||
} | ||
if (rel_model.reversed) { | ||
if (key_model.reversed) { | ||
obj.inst[extend] = ro; | ||
obj.inst.saveSync(); | ||
} | ||
else { | ||
else if (!is_extendsTo) { | ||
ro.saveSync(); | ||
} | ||
else { | ||
} | ||
const r_ext_d = {}; | ||
for (const k in rel_model.model.extends) { | ||
for (const k in key_model.extends) { | ||
if (d[k] !== undefined) { | ||
@@ -163,12 +169,20 @@ r_ext_d[k] = d[k]; | ||
ros = [_create(data)]; | ||
if (!rel_model.reversed) { | ||
if (!key_model.reversed) { | ||
let _opt, assoc; | ||
if (rel_model.type === 'hasOne') { | ||
assoc = orm_assoc_1.get_one_association_item(obj.inst, extend); | ||
_opt = assoc.setAccessor; | ||
switch (rel_model.type) { | ||
default: | ||
break; | ||
case 'extendsTo': | ||
assoc = extendsToAssoc; | ||
_opt = assoc.setAccessor; | ||
break; | ||
case 'hasOne': | ||
assoc = orm_assoc_1.get_one_association_item(obj.inst, extend); | ||
_opt = assoc.setAccessor; | ||
break; | ||
case 'hasMany': | ||
assoc = orm_assoc_1.get_many_association_item(obj.inst, extend); | ||
_opt = assoc.addAccessor; | ||
break; | ||
} | ||
else { | ||
assoc = orm_assoc_1.get_many_association_item(obj.inst, extend); | ||
_opt = assoc.addAccessor; | ||
} | ||
for (const i in ros) { | ||
@@ -200,3 +214,4 @@ const ro = ros[i]; | ||
}); | ||
if (rel_model.type === 'hasOne' && !rel_model.reversed) | ||
if ((rel_model.type === 'hasOne' && !rel_model.reversed) | ||
|| rel_model.type === 'extendsTo') | ||
return api.eget(req, orm, cls, id, extend); | ||
@@ -218,7 +233,3 @@ let obj; | ||
return err_info_1.err_info(4030001, { classname: cls.model_name }, rel_model.model.cid); | ||
let _association; | ||
if (rel_model.type === 'hasOne') | ||
_association = orm_assoc_1.get_one_association_item(obj.inst, extend); | ||
else | ||
_association = orm_assoc_1.get_many_association_item(obj.inst, extend); | ||
let _association = orm_assoc_1.get_association_item_by_reltype(rel_model.type, obj.inst, extend); | ||
return { | ||
@@ -232,2 +243,6 @@ success: query_1.found_result_selector(_find(req, obj.inst[_association.getAccessor].call(obj.inst).find(), obj.inst, extend), !query_1.is_count_required(req.query) ? 'results' : '') | ||
return robj; | ||
if (!robj.inst) | ||
return { | ||
success: null | ||
}; | ||
ormUtils.attach_internal_api_requestinfo_to_instance(robj.inst, { data: null, req_info: req }); | ||
@@ -244,25 +259,26 @@ return { | ||
const rel_model = cls.extends[extend]; | ||
if (rel_model.type === 'hasMany') { | ||
robj.base[orm_assoc_1.get_many_association_item(robj.base, extend).delAccessor + 'Sync'].call(robj.base, robj.inst); | ||
return { | ||
success: { | ||
id: robj.base.id, | ||
updatedAt: robj.base.updatedAt | ||
} | ||
}; | ||
switch (rel_model.type) { | ||
default: | ||
throw `invalid rel_model.type ${rel_model.type}`; | ||
case 'extendsTo': | ||
robj.base[orm_assoc_1.get_extendsto_association_item(robj.base, extend).delAccessor + 'Sync'].call(robj.base); | ||
break; | ||
case 'hasOne': | ||
if (rel_model.reversed) | ||
return err_info_1.err_info(4040003, { | ||
extend: extend, | ||
classname: rel_model.model.model_name | ||
}, rel_model.model.cid); | ||
robj.base[orm_assoc_1.get_one_association_item(robj.base, extend).delAccessor + 'Sync'].call(robj.base); | ||
break; | ||
case 'hasMany': | ||
robj.base[orm_assoc_1.get_many_association_item(robj.base, extend).delAccessor + 'Sync'].call(robj.base, robj.inst); | ||
break; | ||
} | ||
if (rel_model.type === 'hasOne') { | ||
if (rel_model.reversed) | ||
return err_info_1.err_info(4040003, { | ||
extend: extend, | ||
classname: rel_model.model.model_name | ||
}, rel_model.model.cid); | ||
robj.base[orm_assoc_1.get_one_association_item(robj.base, extend).delAccessor + 'Sync'].call(robj.base); | ||
return { | ||
success: { | ||
id: robj.base.id, | ||
updatedAt: robj.base.updatedAt | ||
} | ||
}; | ||
} | ||
return { | ||
success: { | ||
id: robj.base.id, | ||
updatedAt: robj.base.updatedAt | ||
} | ||
}; | ||
}; | ||
@@ -269,0 +285,0 @@ } |
@@ -188,56 +188,71 @@ const util = require("util"); | ||
var rel_model = _extends[f]; | ||
if (!rel_model.model) { | ||
if (rel_model.type !== 'extendsTo' && !rel_model.model) { | ||
throw `association ${f} defined for model ${m.model_name} but no valid related model, detailed information: \n ${JSON.stringify(rel_model, null, '\t')}`; | ||
} | ||
if (rel_model.type === 'hasOne' && !rel_model.reversed) | ||
fields[f] = { | ||
type: types[rel_model.model.model_name].type, | ||
resolve: eget_resolve(m, f) | ||
}; | ||
else { | ||
let type_has_many = new graphql.GraphQLList(types[rel_model.model.model_name].type); | ||
let type_has_many_mixin_extra = null; | ||
let has_many_association = null; | ||
if (!no_extra_fields) { | ||
has_many_association = orm_assoc_1.check_hasmany_extend_extraprops((new m()), f); | ||
if (has_many_association) { | ||
// hasMany-assoc-style result: alone mode(recommendation) | ||
type_has_many = new graphql.GraphQLList(new graphql.GraphQLObjectType({ | ||
name: `${m.model_name}__${f}__aloneExtraWrapper`, | ||
fields: get_fields_hasmanyextra_alone(m, f, has_many_association, get_fields(rel_model.model, true)), | ||
})); | ||
// hasMany-assoc-style result: mixin mode | ||
type_has_many_mixin_extra = new graphql.GraphQLList(new graphql.GraphQLObjectType({ | ||
name: `${m.model_name}__${f}__mixinExtraWrapper`, | ||
fields: get_fields_hasmanyextra_mixins(m, has_many_association, get_fields(rel_model.model, true)), | ||
})); | ||
switch (rel_model.type) { | ||
default: | ||
break; | ||
case 'extendsTo': | ||
fields[f] = { | ||
type: types[rel_model.assoc_model.model_name].type, | ||
resolve: eget_resolve(m, f) | ||
}; | ||
break; | ||
case 'hasOne': | ||
if (!rel_model.reversed) { | ||
fields[f] = { | ||
type: types[rel_model.model.model_name].type, | ||
resolve: eget_resolve(m, f) | ||
}; | ||
break; | ||
} | ||
} | ||
fields[f] = { | ||
type: type_has_many, | ||
args: hasManyArgs, | ||
resolve: efind_many_resolve(m, f) | ||
}; | ||
var extend_paging_uname = get_extend_paging_unique_name(m, rel_model, f); | ||
fields[`paging_${f}`] = { | ||
type: ( | ||
/** | ||
* there maybe repeative call to `get_fields`, and the name of this type should always keep unique | ||
*/ | ||
extend_paging_types[extend_paging_uname] = extend_paging_types[extend_paging_uname] | ||
|| new graphql.GraphQLObjectType({ | ||
name: extend_paging_uname, | ||
case 'hasMany': | ||
{ | ||
let type_has_many = new graphql.GraphQLList(types[rel_model.model.model_name].type); | ||
let type_has_many_mixin_extra = null; | ||
let has_many_association = null; | ||
if (!no_extra_fields) { | ||
has_many_association = orm_assoc_1.check_hasmany_extend_extraprops((new m()), f); | ||
if (has_many_association) { | ||
// hasMany-assoc-style result: alone mode(recommendation) | ||
type_has_many = new graphql.GraphQLList(new graphql.GraphQLObjectType({ | ||
name: `${m.model_name}__${f}__aloneExtraWrapper`, | ||
fields: get_fields_hasmanyextra_alone(m, f, has_many_association, get_fields(rel_model.model, true)), | ||
})); | ||
// hasMany-assoc-style result: mixin mode | ||
type_has_many_mixin_extra = new graphql.GraphQLList(new graphql.GraphQLObjectType({ | ||
name: `${m.model_name}__${f}__mixinExtraWrapper`, | ||
fields: get_fields_hasmanyextra_mixins(m, has_many_association, get_fields(rel_model.model, true)), | ||
})); | ||
} | ||
} | ||
fields[f] = { | ||
type: type_has_many, | ||
args: hasManyArgs, | ||
fields: paging_fields(fields[f].type) | ||
})), | ||
args: hasManyArgs, | ||
resolve: efind_many_resolve(m, f, 'paging') | ||
}; | ||
if (type_has_many_mixin_extra) { | ||
fields[`${f}__extra`] = { | ||
type: type_has_many_mixin_extra, | ||
args: hasManyArgs, | ||
resolve: efind_many_resolve(m, f) | ||
}; | ||
} | ||
resolve: efind_many_resolve(m, f) | ||
}; | ||
var extend_paging_uname = get_extend_paging_unique_name(m, rel_model, f); | ||
fields[`paging_${f}`] = { | ||
type: ( | ||
/** | ||
* there maybe repeative call to `get_fields`, and the name of this type should always keep unique | ||
*/ | ||
extend_paging_types[extend_paging_uname] = extend_paging_types[extend_paging_uname] | ||
|| new graphql.GraphQLObjectType({ | ||
name: extend_paging_uname, | ||
args: hasManyArgs, | ||
fields: paging_fields(fields[f].type) | ||
})), | ||
args: hasManyArgs, | ||
resolve: efind_many_resolve(m, f, 'paging') | ||
}; | ||
if (type_has_many_mixin_extra) { | ||
fields[`${f}__extra`] = { | ||
type: type_has_many_mixin_extra, | ||
args: hasManyArgs, | ||
resolve: efind_many_resolve(m, f) | ||
}; | ||
} | ||
} | ||
break; | ||
} | ||
@@ -244,0 +259,0 @@ } |
@@ -59,32 +59,56 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
} | ||
var assoc_model = null; | ||
m.extends[extend_name] = { | ||
type: 'hasOne', | ||
model: model, | ||
get assoc_model() { | ||
return assoc_model; | ||
}, | ||
// it's meaningless, just keep same format with `hasMany` | ||
extraProperties: {} | ||
model_associated_models: {} | ||
}; | ||
if (orm_hasOne_opts !== undefined && orm_hasOne_opts.reversed) | ||
m.extends[extend_name].reversed = true; | ||
return _hasOne.apply(this, slice.call(arguments)); | ||
return (assoc_model = _hasOne.apply(this, slice.call(arguments))); | ||
}; | ||
var _hasMany = m.hasMany; | ||
m.hasMany = function (extend_name, model) { | ||
var extraProperties = {}, orm_hasMany_opts = {}; | ||
var model_associated_models = {}, orm_hasMany_opts = {}; | ||
if (arguments.length >= 4) { | ||
extraProperties = arguments[2]; | ||
model_associated_models = arguments[2]; | ||
orm_hasMany_opts = arguments[3]; | ||
} | ||
else { | ||
extraProperties = {}; | ||
model_associated_models = {}; | ||
orm_hasMany_opts = arguments[2]; | ||
} | ||
var assoc_model = null; | ||
m.extends[extend_name] = { | ||
type: 'hasMany', | ||
model: model, | ||
extraProperties: extraProperties | ||
get assoc_model() { | ||
return assoc_model; | ||
}, | ||
model_associated_models: model_associated_models | ||
}; | ||
if (orm_hasMany_opts && orm_hasMany_opts.reversed) | ||
m.extends[extend_name].reversed = true; | ||
return _hasMany.apply(this, slice.call(arguments)); | ||
return (assoc_model = _hasMany.apply(this, slice.call(arguments))); | ||
}; | ||
var _extendsTo = m.extendsTo; | ||
m.extendsTo = function (extend_name, assoc_props, orm_extendsTo_opts) { | ||
orm_extendsTo_opts = orm_extendsTo_opts || {}; | ||
orm_extendsTo_opts.hooks = orm_extendsTo_opts.hooks || {}; | ||
var assoc_model = null; | ||
m.extends[extend_name] = { | ||
type: 'extendsTo', | ||
// it's meaningless, just keep same format with `hasMany` | ||
model: null, | ||
get assoc_model() { | ||
return assoc_model; | ||
}, | ||
model_associated_models: {} | ||
}; | ||
return (assoc_model = _extendsTo.apply(this, slice.call(arguments))); | ||
}; | ||
return m; | ||
@@ -91,0 +115,0 @@ } |
@@ -6,5 +6,11 @@ const checkout_acl_1 = require("./checkout_acl"); | ||
var query = req.query; | ||
var { exists, findby_accessor = '', findby_conditions } = query_1.query_filter_findby(req, exec.model) || {}; | ||
if (findby_conditions && findby_accessor) | ||
exec = exec.model[findby_accessor](findby_conditions); | ||
var findby = query_1.parse_findby(req); | ||
var { exists, findby_infos } = query_1.query_filter_findby(findby, exec.model, { req, pre_exec: exec }); | ||
if (findby_infos && findby_infos.length) { | ||
findby_infos.forEach(findby_info => { | ||
if (findby_info.accessor_payload && findby_info.accessor && findby_info.conditions) { | ||
exec = findby_info.accessor_payload[findby_info.accessor](findby_info.conditions); | ||
} | ||
}); | ||
} | ||
if (exists && exec.whereExists) { | ||
@@ -11,0 +17,0 @@ exec = exec.whereExists(exists); |
@@ -60,35 +60,50 @@ /// <reference path="../../@types/index.d.ts" /> | ||
} | ||
var __opt; | ||
if (rel_model.type === 'hasOne') { | ||
if (rel_model.reversed) | ||
__opt = iobj.inst[orm_assoc_1.get_one_association_item(iobj.inst, extend).getAccessor].call(iobj.inst); | ||
else { | ||
var rid1 = iobj.inst[Object.keys(orm_assoc_1.get_one_association_item(iobj.inst, extend).field)[0]]; | ||
if (rid === undefined) | ||
rid = rid1; | ||
else if (rid != rid1) | ||
return wrap_error(err_info_1.err_info(4040002, { | ||
id: rid, | ||
classname: `${cls.model_name}.${extend}` | ||
}, rel_model.model.cid)); | ||
__opt = rel_model.model.find(); | ||
} | ||
var __opt, is_extendsTo = rel_model.type === 'extendsTo', key_model = is_extendsTo ? rel_model.assoc_model : rel_model.model, assoc = orm_assoc_1.get_association_item_by_reltype(rel_model.type, iobj.inst, extend); | ||
switch (rel_model.type) { | ||
default: | ||
throw `invalid rel_model.type ${rel_model.type}`; | ||
case 'extendsTo': | ||
__opt = assoc.model.find({}); | ||
rid = iobj.inst.id; | ||
break; | ||
case 'hasOne': | ||
if (rel_model.reversed) | ||
__opt = iobj.inst[assoc.getAccessor].call(iobj.inst); | ||
else { | ||
var rid1 = iobj.inst[Object.keys(assoc.field)[0]]; | ||
if (rid === undefined) | ||
rid = rid1; | ||
else if (rid != rid1) | ||
return wrap_error(err_info_1.err_info(4040002, { | ||
id: rid, | ||
classname: `${cls.model_name}.${extend}` | ||
}, rel_model.model.cid)); | ||
__opt = rel_model.model.find(); | ||
} | ||
break; | ||
case 'hasMany': | ||
__opt = iobj.inst[assoc.getAccessor].call(iobj.inst); | ||
break; | ||
} | ||
else | ||
__opt = iobj.inst[orm_assoc_1.get_many_association_item(iobj.inst, extend).getAccessor].call(iobj.inst); | ||
var riobj = { | ||
base: iobj.inst, | ||
inst: __opt.where({ | ||
inst: is_extendsTo ? __opt.firstSync() : __opt.where({ | ||
id: rid | ||
}).firstSync() | ||
}; | ||
if (riobj.inst === null) | ||
if (is_extendsTo && riobj.inst === null) { | ||
return { | ||
riobj, | ||
iobj | ||
}; | ||
} | ||
if (riobj.inst == null) | ||
return wrap_error(err_info_1.err_info(4040002, { | ||
id: rid, | ||
classname: `${cls.model_name}.${extend}` | ||
}, rel_model.model.cid)); | ||
}, key_model.cid)); | ||
if (act) { | ||
var acl = checkout_acl_1.checkout_robj_acl(session, act, iobj.inst, riobj.inst, extend); | ||
if (!acl) | ||
return wrap_error(err_info_1.err_info(4030001, { classname: cls.model_name }, rel_model.model.cid)); | ||
return wrap_error(err_info_1.err_info(4030001, { classname: cls.model_name }, key_model.cid)); | ||
riobj.acl = acl; | ||
@@ -95,0 +110,0 @@ } |
@@ -22,2 +22,24 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.get_one_association_item = get_one_association_item; | ||
function get_extendsto_associations(instance) { | ||
return instance.__opts.extend_associations; | ||
} | ||
exports.get_extendsto_associations = get_extendsto_associations; | ||
function get_extendsto_association_item(instance, extend_name) { | ||
const extendsto_assocs = get_extendsto_associations(instance); | ||
return extendsto_assocs.find(a => a.name === extend_name); | ||
} | ||
exports.get_extendsto_association_item = get_extendsto_association_item; | ||
function get_association_item_by_reltype(reltype, inst, extend) { | ||
switch (reltype) { | ||
default: | ||
throw 'invalid association reltype!'; | ||
case 'extendsTo': | ||
return get_extendsto_association_item(inst, extend); | ||
case 'hasOne': | ||
return get_one_association_item(inst, extend); | ||
case 'hasMany': | ||
return get_many_association_item(inst, extend); | ||
} | ||
} | ||
exports.get_association_item_by_reltype = get_association_item_by_reltype; | ||
function check_hasmany_extend_extraprops(instance, extend_name) { | ||
@@ -24,0 +46,0 @@ var has_many_association = instance.__opts.many_associations.find(a => a.name === extend_name); |
@@ -7,2 +7,3 @@ /// <reference lib="es2017" /> | ||
const checkout_acl_1 = require("./checkout_acl"); | ||
const str_1 = require("./str"); | ||
function query_filter_where(query) { | ||
@@ -17,19 +18,11 @@ var where = query.where; | ||
exports.query_filter_where = query_filter_where; | ||
function query_filter_findby(req, base_model) { | ||
const query = req.query; | ||
var findby = (query.findby || null); | ||
if (typeof findby === 'string') { | ||
try { | ||
findby = JSON.parse(findby); | ||
} | ||
catch (e) { | ||
findby = null; | ||
} | ||
} | ||
function query_filter_findby(findby, base_model, opts) { | ||
const { req, pre_exec = null } = opts; | ||
const __wrapper = { exists: null, findby_infos: [] }; | ||
if (!findby) | ||
return; | ||
if (!findby.extend) | ||
return; | ||
let hasmany_assoc, hasone_assoc; | ||
let exists = null, findby_accessor = null, findby_conditions = null; | ||
return __wrapper; | ||
if (!findby.extend || typeof findby.extend !== 'string') | ||
return __wrapper; | ||
let hasmany_assoc; | ||
let hasone_assoc; | ||
const base_instance = new base_model(); | ||
@@ -42,3 +35,3 @@ if (findby.on | ||
if (!checkout_acl_1.checkout_acl(req.session, 'find', base_model.ACL, findby.extend)) | ||
return; | ||
return __wrapper; | ||
/** | ||
@@ -48,4 +41,4 @@ * @description code below means 'support single key only' | ||
// const mg_assocks = Object.values(hasmany_assoc.mergeAssocId).map(x => x.mapsTo); | ||
// if (mg_assocks.length !== 1 || mks.length !== 1) return ; | ||
exists = [ | ||
// if (mg_assocks.length !== 1 || mks.length !== 1) return __wrapper; | ||
__wrapper.exists = [ | ||
{ | ||
@@ -57,15 +50,34 @@ table: hasmany_assoc.mergeTable, | ||
]; | ||
exists = convert_exists(exists); | ||
__wrapper.exists = convert_exists(__wrapper.exists); | ||
} | ||
else if (findby.where | ||
&& (hasone_assoc = orm_assoc_1.get_one_association_item(base_instance, findby.extend))) { | ||
else if (findby.where) { | ||
let findby_conditions = findby.where; | ||
if (!filter_conditions(findby_conditions)) | ||
return; | ||
return __wrapper; | ||
const rel_model = base_model.extends[findby.extend]; | ||
const is_extendsTo = rel_model.type === 'extendsTo'; | ||
findby_conditions = convert_where(findby_conditions); | ||
if (!checkout_acl_1.checkout_acl(req.session, 'find', base_model.ACL, findby.extend)) | ||
return; | ||
const assocTplName = hasone_assoc.getAccessor.slice(3); | ||
findby_accessor = typeof base_instance.model[assocTplName] === 'function' ? assocTplName : null; | ||
findby_conditions = findby.where; | ||
return __wrapper; | ||
let accessor_fn = null, accessor_name = null, accessor_payload = null; | ||
let findby_accessor_name = `findBy${str_1.ucfirst(findby.extend)}`; | ||
; | ||
[ | ||
base_model | ||
].forEach(test_payload => { | ||
if (accessor_name) | ||
return; | ||
accessor_fn = test_payload[findby_accessor_name]; | ||
if (typeof accessor_fn === 'function') { | ||
accessor_payload = test_payload; | ||
accessor_name = findby_accessor_name; | ||
} | ||
}); | ||
__wrapper.findby_infos.push({ | ||
accessor: accessor_name, | ||
accessor_payload: accessor_payload, | ||
conditions: findby_conditions | ||
}); | ||
} | ||
return { exists, findby_accessor, findby_conditions }; | ||
return __wrapper; | ||
} | ||
@@ -173,2 +185,16 @@ exports.query_filter_findby = query_filter_findby; | ||
; | ||
function parse_findby(req) { | ||
const query = req.query; | ||
var findby = (query.findby || null); | ||
if (typeof findby === 'string') { | ||
try { | ||
findby = JSON.parse(findby); | ||
} | ||
catch (e) { | ||
findby = null; | ||
} | ||
} | ||
return findby; | ||
} | ||
exports.parse_findby = parse_findby; | ||
// internal helper function for `filter_exist_item_link` | ||
@@ -175,0 +201,0 @@ function filter_link_tuple(tuple) { |
{ | ||
"name": "fib-app", | ||
"version": "1.13.22", | ||
"version": "1.13.23", | ||
"description": "", | ||
@@ -24,3 +24,3 @@ "main": "./lib", | ||
"dependencies": { | ||
"@fxjs/orm": "^1.8.6", | ||
"@fxjs/orm": "^1.8.7", | ||
"@types/fibjs": "^0.26.5", | ||
@@ -45,3 +45,3 @@ "fib-graphql": "^1.0.0", | ||
"peerDependencies": { | ||
"@fxjs/orm": "1.8.x" | ||
"@fxjs/orm": ">= 1.8.7 < 2" | ||
}, | ||
@@ -48,0 +48,0 @@ "ci": { |
813370
53
3319
Updated@fxjs/orm@^1.8.7