Skip to content

Commit

Permalink
refactor internal app api post, epost.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardo2016 committed Mar 23, 2019
1 parent de5dc61 commit dec8557
Show file tree
Hide file tree
Showing 27 changed files with 788 additions and 459 deletions.
19 changes: 11 additions & 8 deletions @types/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,37 +73,37 @@ declare namespace FibApp {
type FibAppIneternalApiFunction__Find = FibAppInternalTypedApi__Find<FibAppApiFunctionResponse>

interface FibAppIneternalApiFunction__Put {
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType, data: FibAppReqData): FibAppApiFunctionResponse;
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType | FxOrmInstance.Instance, data: FibAppReqData): FibAppApiFunctionResponse;
}

interface FibAppIneternalApiFunction__Del {
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType): FibAppApiFunctionResponse;
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType | FxOrmInstance.Instance): FibAppApiFunctionResponse;
}

interface FibAppInternalTypedApi__Eget<RT = any> {
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType, extend: FibAppACL.ACLExtendModelNameType, rid?: AppIdType): RT;
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType | FxOrmInstance.Instance, extend: FibAppACL.ACLExtendModelNameType, rid?: AppIdType): RT;
}
type FibAppIneternalApiFunction__Eget = FibAppInternalTypedApi__Eget<FibAppApiFunctionResponse>

interface FibAppInternalTypedApi__Efind<RT = any> {
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType, extend: FibAppACL.ACLExtendModelNameType): RT;
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType | FxOrmInstance.Instance, extend: FibAppACL.ACLExtendModelNameType): RT;
}
type FibAppIneternalApiFunction__Efind = FibAppInternalTypedApi__Efind<FibAppApiFunctionResponse>

interface FibAppIneternalApiFunction__Epost {
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType, extend: FibAppACL.ACLExtendModelNameType, data: FibDataPayload): FibAppApiFunctionResponse;
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType | FxOrmInstance.Instance, extend: FibAppACL.ACLExtendModelNameType, data: FibDataPayload): FibAppApiFunctionResponse;
}

interface FibAppIneternalApiFunction__Eput {
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType, extend: FibAppACL.ACLExtendModelNameType, rid: AppIdType, data: FibDataPayload): FibAppApiFunctionResponse;
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType | FxOrmInstance.Instance, extend: FibAppACL.ACLExtendModelNameType, rid: AppIdType, data: FibDataPayload): FibAppApiFunctionResponse;
}

interface FibAppIneternalApiFunction__Edel {
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType, extend: FibAppACL.ACLExtendModelNameType, rid: AppIdType): FibAppApiFunctionResponse;
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType | FxOrmInstance.Instance, extend: FibAppACL.ACLExtendModelNameType, rid: AppIdType): FibAppApiFunctionResponse;
}

interface FibAppIneternalApiFunction__Elink {
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType, extend: FibAppACL.ACLExtendModelNameType, data: FibDataPayload): FibAppApiFunctionResponse;
(req: FibAppReq, db: FibAppORM, cls: FxOrmNS.Model, id: AppIdType | FxOrmInstance.Instance, extend: FibAppACL.ACLExtendModelNameType, data: FibDataPayload): FibAppApiFunctionResponse;
}
/* internal api function :end */

Expand Down Expand Up @@ -250,6 +250,9 @@ declare namespace FibApp {
req_resource_extend?: string

response_headers?: object

/* usually used by server side */
// all_map?: boolean
}

type FibAppReqResourceType = 'unknown' | 'json' | 'html' | 'css' | 'js'
Expand Down
11 changes: 11 additions & 0 deletions demo/defs/city/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const push = require('fib-push');

module.exports = db => {
var City = db.define('city', {
code: {
type: 'text',
required: true
},
name: String
});
};
18 changes: 12 additions & 6 deletions demo/defs/extend-multiple-level/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ describe("extend multiple level", () => {
var rep = http.post(tSrvInfo.appUrlBase + '/level', {
json: TESTDATA.l1
});


assert.equal(rep.statusCode, 201)
top_id = rep.json().id
});

Expand Down Expand Up @@ -107,6 +108,7 @@ describe("extend multiple level", () => {
on: { many_sublevels_id: { ne: ${t} } }
`,
extra_cond: ``,
// debug_only: true
},
[
{ name: `l1:name` },
Expand All @@ -121,7 +123,7 @@ describe("extend multiple level", () => {
extend: "many_sublevels"
on: { many_sublevels_id: "${t}" }
`,
extra_cond: ''
extra_cond: ``
},
[
undefined
Expand All @@ -135,7 +137,7 @@ describe("extend multiple level", () => {
extend: "many_sublevels"
on: { since: { eq: "${t}" } }
`,
extra_cond: ''
extra_cond: ``
},
[
undefined
Expand Down Expand Up @@ -316,16 +318,20 @@ describe("extend multiple level", () => {
[
'only join_where for extra fields',
{
l1_where: '',
l1_findby_kv: ``,
l1_where: `
order: "-name"
`,
l1_findby_kv: `
`,
extra_cond: `join_where: {
since: {
ne: "${all_many_sublevels[1].extra.since}"
modifiers: {
is_date: true
}
}
}`
}`,
// debug_only: true,
},
[
{ name: `l1:name` },
Expand Down
19 changes: 19 additions & 0 deletions demo/defs/extend/__test__/mock-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"init_people": [{
"name": "tom",
"sex": "male",
"age": 35
}, {
"name": "alice",
"sex": "female",
"age": 32
}, {
"name": "jack",
"sex": "male",
"age": 8
}, {
"name": "lily",
"sex": "female",
"age": 4
}]
}
3 changes: 3 additions & 0 deletions demo/defs/extend/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
module.exports = db => {
var People = db.models.people;
var City = db.models.city;

People.hasOne("mother", People);
People.hasOne("father", People);
People.hasOne("husband", People);
People.hasOne("wife", People, {reverse: 'husbands'});
People.hasMany("childs", People);

People.hasOne("city", City, {required: true});

People.hasMany("friends", People, {
hobby: String,
meeting_time: {
Expand Down
Loading

0 comments on commit dec8557

Please sign in to comment.