-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(io): io support crud function, update faas-demo example
- Loading branch information
Showing
15 changed files
with
3,271 additions
and
8,508 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
data: { | ||
name: `旧书铺-${new Date()}`, | ||
cover: | ||
'https://cloud-minapp-47549.cloud.ifanrusercontent.com/1rmlh9degSiaF4ua.jpg', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
id: '65fa8a4ae37f7c453e7b7045', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { createFaas } from '@mincloudx/faas'; | ||
import io from '@/io'; | ||
|
||
interface EventParams { | ||
data: { | ||
name: string; | ||
cover: string; | ||
}; | ||
} | ||
|
||
export default createFaas<EventParams>(async function main(event) { | ||
const { data } = event.data; | ||
|
||
const record = await io.channel.create(data); | ||
console.log('create result:', record); | ||
|
||
const updatedResult = await io.channel.update(record.id, { | ||
data: { | ||
description: 'This is description.', | ||
}, | ||
}); | ||
console.log('updated result:', updatedResult); | ||
|
||
const channel = await io.channel.get(record.id, { | ||
select: ['id', 'name', 'cover', 'description'], | ||
}); | ||
console.log('get result:', channel); | ||
|
||
return channel; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createFaas } from '@mincloudx/faas'; | ||
import io from '@/io'; | ||
|
||
interface EventParams { | ||
id: string; | ||
} | ||
|
||
export default createFaas<EventParams>(async function main(event) { | ||
const { id } = event.data; | ||
// const result = await io.channel.delete(id); | ||
|
||
const query = io.getQuery({ id }); | ||
const result = await io.channel.delete(query); | ||
console.log('delete result:', result); | ||
|
||
return result; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createIo } from '@mincloudx/io'; | ||
|
||
export default createIo({ | ||
tables: ['channel'], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,14 @@ | ||
import { getBaaS } from './baas'; | ||
import { getBaaS, getBaseIo } from './baas'; | ||
import { createTableOperation, Operation } from './operations'; | ||
|
||
export function createIo<T extends string>(options: { tables?: T[] } = {}) { | ||
const BaaS = getBaaS(); | ||
const io = getBaseIo(BaaS); | ||
|
||
const io = { | ||
get query() { | ||
return new BaaS.Query(); | ||
}, | ||
|
||
get user() { | ||
return new BaaS.User(); | ||
}, | ||
|
||
get file() { | ||
return new BaaS.File(); | ||
}, | ||
|
||
table(tableName: string) { | ||
return new BaaS.TableObject(tableName); | ||
}, | ||
}; | ||
|
||
const dynamicIo: { [K in T]?: Operation } = {}; | ||
const dynamicIo = {} as { [K in T]: Operation }; | ||
options.tables?.forEach(tableName => { | ||
dynamicIo[tableName] = createTableOperation(tableName); | ||
}); | ||
|
||
return Object.assign(io, dynamicIo); | ||
return Object.assign(dynamicIo, io); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.