feat: get json schema with async node (#246)
This commit is contained in:
parent
ed8c60eb85
commit
5554b1c260
@ -56,6 +56,43 @@ describe('action test', () => {
|
|||||||
expect(response.statusCode).toEqual(200);
|
expect(response.statusCode).toEqual(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('getJsonSchema with async node', async () => {
|
||||||
|
await app
|
||||||
|
.agent()
|
||||||
|
.resource('uiSchemas')
|
||||||
|
.insert({
|
||||||
|
values: {
|
||||||
|
'x-uid': 'n1',
|
||||||
|
name: 'a',
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
b: {
|
||||||
|
'x-async': true,
|
||||||
|
'x-uid': 'n2',
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
c: { 'x-uid': 'n3' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
d: { 'x-uid': 'n4' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
let response = await app.agent().resource('uiSchemas').getJsonSchema({
|
||||||
|
resourceIndex: 'n1',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(response.body.data.properties.b).toBeUndefined();
|
||||||
|
|
||||||
|
response = await app.agent().resource('uiSchemas').getJsonSchema({
|
||||||
|
resourceIndex: 'n1',
|
||||||
|
includeAsyncNode: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(response.body.data.properties.b).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
test('getJsonSchema', async () => {
|
test('getJsonSchema', async () => {
|
||||||
await app
|
await app
|
||||||
.agent()
|
.agent()
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
import { Context } from '@nocobase/actions';
|
import { Context } from '@nocobase/actions';
|
||||||
import lodash from 'lodash';
|
import lodash from 'lodash';
|
||||||
import UiSchemaRepository from '../repository';
|
import UiSchemaRepository from '../repository';
|
||||||
|
import { ActionParams } from '@nocobase/resourcer';
|
||||||
|
|
||||||
const getRepositoryFromCtx = (ctx: Context) => {
|
const getRepositoryFromCtx = (ctx: Context) => {
|
||||||
return ctx.db.getCollection('uiSchemas').repository as UiSchemaRepository;
|
return ctx.db.getCollection('uiSchemas').repository as UiSchemaRepository;
|
||||||
};
|
};
|
||||||
|
|
||||||
const callRepositoryMethod = (method, paramsKey: 'resourceIndex' | 'values') => {
|
const callRepositoryMethod = (method, paramsKey: 'resourceIndex' | 'values', optionsBuilder?) => {
|
||||||
return async (ctx, next) => {
|
return async (ctx, next) => {
|
||||||
const params = lodash.get(ctx.action.params, paramsKey);
|
const params = lodash.get(ctx.action.params, paramsKey);
|
||||||
|
const options = optionsBuilder ? optionsBuilder(ctx.action.params) : {};
|
||||||
|
|
||||||
const repository = getRepositoryFromCtx(ctx);
|
const repository = getRepositoryFromCtx(ctx);
|
||||||
const returnValue = await repository[method](params);
|
const returnValue = await repository[method](params, options);
|
||||||
|
|
||||||
ctx.body = returnValue || {
|
ctx.body = returnValue || {
|
||||||
result: 'ok',
|
result: 'ok',
|
||||||
@ -30,7 +32,12 @@ function parseInsertAdjacentValues(values) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const uiSchemaActions = {
|
export const uiSchemaActions = {
|
||||||
getJsonSchema: callRepositoryMethod('getJsonSchema', 'resourceIndex'),
|
getJsonSchema: callRepositoryMethod('getJsonSchema', 'resourceIndex', (params: ActionParams) => {
|
||||||
|
return {
|
||||||
|
includeAsyncNode: params?.includeAsyncNode,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
|
||||||
getProperties: callRepositoryMethod('getProperties', 'resourceIndex'),
|
getProperties: callRepositoryMethod('getProperties', 'resourceIndex'),
|
||||||
insert: callRepositoryMethod('insert', 'values'),
|
insert: callRepositoryMethod('insert', 'values'),
|
||||||
insertNewSchema: callRepositoryMethod('insertNewSchema', 'values'),
|
insertNewSchema: callRepositoryMethod('insertNewSchema', 'values'),
|
||||||
|
@ -144,7 +144,9 @@ export class UiSchemaRepository extends Repository {
|
|||||||
return carry;
|
return carry;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getProperties(uid: string) {
|
async getProperties(uid: string, options: TransactionAble = {}) {
|
||||||
|
const { transaction } = options;
|
||||||
|
|
||||||
const db = this.database;
|
const db = this.database;
|
||||||
|
|
||||||
const rawSql = `
|
const rawSql = `
|
||||||
@ -161,6 +163,7 @@ export class UiSchemaRepository extends Repository {
|
|||||||
replacements: {
|
replacements: {
|
||||||
ancestor: uid,
|
ancestor: uid,
|
||||||
},
|
},
|
||||||
|
transaction,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (nodes[0].length == 0) {
|
if (nodes[0].length == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user