@doreamonjs/page-creator
Version:
page-creator for doreamonjs
994 lines • 79.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.create = void 0;
const delay_1 = require("@zcorky/delay");
const doreamon_1 = require("@zodash/doreamon");
const request_1 = require("@doreamonjs/request");
const doreamonJSSDK = require("@doreamonjs/sdk");
const confirm = require("@doreamonjs/plugin-confirm");
const dialog = require("@doreamonjs/plugin-dialog");
const popup = require("@doreamonjs/plugin-popup");
const form = require("@doreamonjs/plugin-form");
const log = require("@doreamonjs/plugin-log");
const message = require("@doreamonjs/plugin-message");
const preview = require("@doreamonjs/plugin-preview");
const terminal = require("@doreamonjs/plugin-terminal");
const iframe = require("@doreamonjs/plugin-iframe");
const transfer = require("@doreamonjs/plugin-transfer");
const treeselect = require("@doreamonjs/plugin-tree-select");
const utils_1 = require("./utils");
const requestWithPriority = async (r) => {
await doreamonJSSDK.user.waitForAuthenticated();
return request_1.request(r);
};
const isMobile = () => { var _a, _b; return (_b = (_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, '(max-width: 767px)')) === null || _b === void 0 ? void 0 : _b.matches; };
const NAMESPACES = {
form: form.NAMESPACE,
confirm: confirm.NAMESPACE,
dialog: dialog.NAMESPACE,
popup: popup.NAMESPACE,
log: log.NAMESPACE,
message: message.NAMESPACE,
preview: preview.NAMESPACE,
terminal: terminal.NAMESPACE,
iframe: iframe.NAMESPACE,
transfer: transfer.NAMESPACE,
treeselect: treeselect.NAMESPACE,
};
const scheduler = new utils_1.Scheduler();
scheduler.start();
function create(config, manifest, options) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
const namespace = config.page.namespace;
const isComponent = manifest.type === 'component';
return {
namespace: namespace,
state: {
attributes: {
title: config.title,
description: config.description,
configs: config.configs,
apis: config.apis,
actions: config.actions,
filters: config.filters,
columns: config.columns,
pagination: {
pageSize: (_c = (_b = (_a = config.configs) === null || _a === void 0 ? void 0 : _a.table) === null || _b === void 0 ? void 0 : _b.defaultPageSize) !== null && _c !== void 0 ? _c : 10,
pageSizeOptions: (_f = (_e = (_d = config.configs) === null || _d === void 0 ? void 0 : _d.table) === null || _e === void 0 ? void 0 : _e.defaultPageSizeOptions) !== null && _f !== void 0 ? _f : [
5, 10, 20,
],
current: 1,
total: 1,
},
// global table config
table: (_g = config.configs) === null || _g === void 0 ? void 0 : _g.table,
// categories
categories: {
enable: (_j = (_h = config.configs) === null || _h === void 0 ? void 0 : _h.categories) === null || _j === void 0 ? void 0 : _j.enable,
//
current: (_l = (_k = config === null || config === void 0 ? void 0 : config.configs) === null || _k === void 0 ? void 0 : _k.categories) === null || _l === void 0 ? void 0 : _l.defaultValue,
items: config === null || config === void 0 ? void 0 : config.categories,
},
//
detail: config.detail,
// @TODO
config,
manifest,
},
datasets: {
values: (_o = (_m = manifest.configs) === null || _m === void 0 ? void 0 : _m.datasets) === null || _o === void 0 ? void 0 : _o.defaultValues,
table: (_r = (_q = (_p = manifest.configs) === null || _p === void 0 ? void 0 : _p.datasets) === null || _q === void 0 ? void 0 : _q.defaultTable) !== null && _r !== void 0 ? _r : [],
},
constraints: {
where: {
...((_t = (_s = config.filters) === null || _s === void 0 ? void 0 : _s.reduce((all, one) => {
if (typeof one.initialValue !== 'undefined') {
all[one.dataIndex] = one.initialValue;
}
return all;
}, {})) !== null && _t !== void 0 ? _t : {}),
},
orderBy: [],
},
},
reducers: {
save: (state, { payload }) => ({ ...state, ...payload }),
},
effects: {
// @dispatcher
*dispatcher({ payload }, { call, select, put }) {
var _a, _b, _c, _d, _e, _f, _g;
const type = payload === null || payload === void 0 ? void 0 : payload.type;
let action = (payload === null || payload === void 0 ? void 0 : payload.meta) || {};
const target = payload === null || payload === void 0 ? void 0 : payload.target;
// cross model action
if (action.namespace) {
const { namespace, delay, ...action2 } = action;
yield call(doreamon_1.default.delay, delay || 1000);
return yield put({
type: `${namespace}/dispatcher`,
payload: {
...payload,
meta: action2,
},
});
}
const data = (payload === null || payload === void 0 ? void 0 : payload.data) || (payload === null || payload === void 0 ? void 0 : payload.values) || {};
let pipeline = [];
if (action.pipeline) {
pipeline = action === null || action === void 0 ? void 0 : action.pipeline;
}
else {
// get pipeline from config
const actions = yield select((state) => state[namespace].attributes.actions);
// console.log('actions', actions);
const actionX = actions.find((a) => a.key === action.key);
if (!actionX) {
throw new Error(`can not find action named: ${action.key}`);
}
// @TODO
action = {
...action,
...actionX,
};
if (actionX === null || actionX === void 0 ? void 0 : actionX.pipeline) {
pipeline = actionX.pipeline;
}
else {
throw new Error(`action.pipeline is required`);
}
}
// @TODO filter type => query
if (type === 'filter') {
return yield put({ type: 'service/query', payload: data });
}
// 埋点分析 analytics
// try {
// (window as any).doreamonJSSDK?.analysis?.track?.(action.key, action);
// } catch (error) {
// // do nothing
// }
if (((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) !== 'development') {
const actionType = action.type;
const actionDataKeyMap = (_f = (_e = (_d = (_c = (_b = config.configs) === null || _b === void 0 ? void 0 : _b.analysis) === null || _c === void 0 ? void 0 : _c.action) === null || _d === void 0 ? void 0 : _d.type) === null || _e === void 0 ? void 0 : _e[actionType]) !== null && _f !== void 0 ? _f : {};
// const actionData = doreamon.object.pickAlias(data, actionDataKeyMap);
const actionData = pickAlias((_g = data === null || data === void 0 ? void 0 : data.values) !== null && _g !== void 0 ? _g : {}, actionDataKeyMap);
const attributes = {
namespace,
key: action.key,
title: action.title,
type: action.type,
...actionData,
};
yield put({
type: 'analysiss/track',
payload: { event: action.key, attributes },
});
}
const context = {
pathname: window.location.pathname,
query: doreamon_1.default.qs.parse(window.location.search),
route: yield select((state) => state.router.location),
nav: yield select((state) => state.menus.nav.current),
};
// start pipeline
// from type action
if ((payload === null || payload === void 0 ? void 0 : payload.from) === 'action') {
yield put({
type: 'pipeline/step',
steps: 0,
pipeline,
action: { ...action, context },
payload: payload.actionPayload,
//
target,
});
}
else {
yield put({
type: 'pipeline/step',
steps: 0,
pipeline,
action: { ...action, context },
payload: data,
//
target,
});
}
},
*'pipeline/step'({ steps, pipeline, action, payload, target }, { put, call, take, race }) {
const current = pipeline === null || pipeline === void 0 ? void 0 : pipeline[steps];
if (action.context.pathname !== window.location.pathname) {
return;
}
// 检查是否忽略当前步骤,进入下一个步骤
let isPass = false;
if (typeof (current === null || current === void 0 ? void 0 : current.pass) === 'function') {
isPass = yield call(current.pass, payload.values, current, action, manifest);
}
// if pass, go next step
if (isPass) {
return yield put({
type: 'pipeline/step',
steps: steps + 1,
pipeline,
action,
payload,
target,
});
}
// payload = { values: {} }
// pipeline end
if (steps >= pipeline.length) {
// console.log('one action done(all pipeline):', action, payload);
// @TODO
if (action.callback) {
action.callback(null, payload);
}
if (target) {
const { namespace, effect, props } = target;
const nextEffect = !namespace ? effect : `${namespace}/${effect}`;
yield put({ ...props, type: nextEffect, payload });
yield take(`${nextEffect}/@@end`);
}
return;
}
if (!current || !current.type) {
console.log('pipeline: current is undefined', payload);
throw new Error(`invalid pipeline in action: ${action === null || action === void 0 ? void 0 : action.key}`);
}
yield put({
type: `pipeline/type/${current.type}`,
current,
steps,
pipeline,
action,
target,
payload,
});
if ((current === null || current === void 0 ? void 0 : current.type) === 'service') {
// 会导致页面关闭,应该设计回调成功还是失败
// yield race({
// timeout: call(doreamon.delay, 3000),
// wait: take(`pipeline/type/service`),
// });
yield take(`pipeline/type/service/@@end`);
}
},
*'pipeline/type/form'({ current, steps, pipeline, action, payload, target }, { put, call, select }) {
var _a, _b;
const values = (payload === null || payload === void 0 ? void 0 : payload.values) || {};
let fields = ((_a = current.form) === null || _a === void 0 ? void 0 : _a.fields) || [];
if (typeof fields === 'function') {
// fields = yield call(current.form?.fields, values);
fields = fields.apply(null, [values, pipeline, action, config]);
}
const form = manifestActionPipelineRenderableAttr(values, pipeline, action, config, current.form, [
'type',
'title',
'layout',
'column',
'rules',
'fields',
'mode',
'steps',
'cancelText',
'confirmText',
]);
if (!Array.isArray(fields)) {
throw new Error(`[pipeline/type/form] fields must be array`);
}
// build globals
const state = yield select((state) => state[namespace]);
const { attributes } = state;
const globalRequestConfig = yield call(buildGlobalRequestConfig, ((_b = attributes === null || attributes === void 0 ? void 0 : attributes.configs) === null || _b === void 0 ? void 0 : _b.apis) || {}, options);
yield put({
type: `${NAMESPACES.form}/open`,
payload: {
attributes: {
...form,
//
layout: isMobile() ? 'vertical' : form.layout,
//
context: {
request: globalRequestConfig,
},
//
fields,
target: {
namespace: namespace,
effect: 'pipeline/step',
//
props: {
steps: steps + 1,
pipeline,
action,
target,
},
},
},
datasets: {
...payload,
values,
},
},
});
},
*'pipeline/type/confirm'({ current, steps, pipeline, action, payload, target }, { put, take }) {
var _a;
const values = (payload === null || payload === void 0 ? void 0 : payload.values) || {};
const confirm = manifestActionPipelineRenderableAttr(values, pipeline, action, config, (_a = current.confirm) !== null && _a !== void 0 ? _a : {
title: '操作确认',
description: '是否确认?',
}, [
'type',
'title',
'description',
'cancelText',
'confirmText',
'information',
'descriptionConfig',
]);
yield put({
type: `${NAMESPACES.confirm}/open`,
payload: {
attributes: {
...confirm,
// prevEffect: type,
target: {
namespace: namespace,
effect: `pipeline/step`,
props: {
steps: steps + 1,
pipeline,
action,
target,
},
},
},
datasets: payload,
},
});
},
*'pipeline/type/service'({ current, steps, pipeline, action, payload, target }, { select, put, race, call }) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9;
if ((_a = current.service) === null || _a === void 0 ? void 0 : _a.tip) {
yield put({
type: 'messages/tip/info',
payload: (_b = current.service) === null || _b === void 0 ? void 0 : _b.tip,
});
}
// console.log('pipeline/type/service....', current, action);
const state = yield select((state) => state[namespace]);
const { attributes } = state;
const globalRequestConfig = yield call(buildGlobalRequestConfig, ((_c = attributes === null || attributes === void 0 ? void 0 : attributes.configs) === null || _c === void 0 ? void 0 : _c.apis) || {}, options);
const values = (payload === null || payload === void 0 ? void 0 : payload.values) || {};
const context = {
state,
// @TODO
config: {
global: globalRequestConfig,
},
};
let params = {};
if (typeof ((_d = current.service.request) === null || _d === void 0 ? void 0 : _d.params) === 'function') {
params = yield call((_e = current.service.request) === null || _e === void 0 ? void 0 : _e.params, values, context);
}
else {
params = {
...globalRequestConfig.params,
...values,
id: (_g = (_f = values === null || values === void 0 ? void 0 : values._id) !== null && _f !== void 0 ? _f : values === null || values === void 0 ? void 0 : values.id) !== null && _g !== void 0 ? _g : (_h = globalRequestConfig.params) === null || _h === void 0 ? void 0 : _h.id,
...((_l = (_k = (_j = current.service.request) === null || _j === void 0 ? void 0 : _j.params) === null || _k === void 0 ? void 0 : _k.call(_j, values, context)) !== null && _l !== void 0 ? _l : {}),
};
}
let query = {};
if (typeof ((_m = current.service.request) === null || _m === void 0 ? void 0 : _m.query) === 'function') {
query = yield call((_o = current.service.request) === null || _o === void 0 ? void 0 : _o.query, values, context);
}
else {
query = {
...globalRequestConfig.query,
...(!((_p = current.service.picks) === null || _p === void 0 ? void 0 : _p.query)
? {}
: doreamon_1.default.object.pick(values, current.service.picks.query)),
...(!((_q = current.service.alias) === null || _q === void 0 ? void 0 : _q.query)
? {}
: pick(values, current.service.alias.query)),
};
// pick
if (Array.isArray((_s = (_r = current.service.request) === null || _r === void 0 ? void 0 : _r.query) === null || _s === void 0 ? void 0 : _s.pick)) {
query = doreamon_1.default.object.pick(query, current.service.request.query.pick);
}
}
let body = undefined;
if (typeof ((_t = current.service.request) === null || _t === void 0 ? void 0 : _t.body) === 'function') {
body = yield call((_u = current.service.request) === null || _u === void 0 ? void 0 : _u.body, values, context);
}
else {
body = {
...globalRequestConfig.body,
...(!((_v = current.service.picks) === null || _v === void 0 ? void 0 : _v.body)
? values
: doreamon_1.default.object.pick(values, current.service.picks.body)),
...(!((_w = current.service.alias) === null || _w === void 0 ? void 0 : _w.body)
? {}
: pick(values, current.service.alias.body)),
};
// pick
if (Array.isArray((_y = (_x = current.service.request) === null || _x === void 0 ? void 0 : _x.body) === null || _y === void 0 ? void 0 : _y.pick)) {
body = doreamon_1.default.object.pick(body, current.service.request.body.pick);
}
}
const config = {
...current.service.api,
method: (_z = current.service.method) !== null && _z !== void 0 ? _z : (_0 = current.service.api) === null || _0 === void 0 ? void 0 : _0.method,
path: (_1 = current.service.path) !== null && _1 !== void 0 ? _1 : (_2 = current.service.api) === null || _2 === void 0 ? void 0 : _2.path,
params,
query,
body,
transform: (_3 = current.service.transform) !== null && _3 !== void 0 ? _3 : (_4 = current.service.api) === null || _4 === void 0 ? void 0 : _4.transform,
//
// context,
};
if (current.service.delay) {
yield call(delay_1.delay, current.service.delay);
}
if (typeof current.service.params === 'function') {
config.params = yield call(current.service.params, config, context);
}
if (typeof current.service.query === 'function') {
config.query = yield call(current.service.query, config, context);
}
if (typeof current.service.body === 'function') {
config.body = yield call(current.service.body, config, context);
}
let response;
try {
const timeoutFunc = (ms) => new Promise((resolve) => setTimeout(() => resolve(true), ms));
response = yield race({
data: call(requestWithPriority, config),
timeout: call(timeoutFunc, (_5 = current.service.timeout) !== null && _5 !== void 0 ? _5 : 10000),
});
}
catch (error) {
// @TODO set loading false
// @TODO use dva-loading
// yield put({
// type: '@@DVA_LOADING/HIDE',
// payload: {
// namespace,
// actionType: `${namespace}/pipeline/step`,
// },
// });
// @TODO add timeout
// setTimeout(() => {
// // @TODO set loading false
// // @TODO use dva-loading
// yield put({
// type: '@@DVA_LOADING/HIDE',
// payload: {
// namespace,
// actionType: `${namespace}/pipeline/step`,
// },
// });
// }, 1000);
// @TODO syntax
// yield call(function *() {
// yield call(doreamon.delay, 3000);
// // @TODO set loading false
// // @TODO use dva-loading
// yield put({
// type: '@@DVA_LOADING/HIDE',
// payload: {
// namespace,
// actionType: `${namespace}/pipeline/step`,
// },
// });
// });
yield call(doreamon_1.default.delay, 1000);
// @TODO set loading false
// @TODO use dva-loading
yield put({
type: '@@DVA_LOADING/HIDE',
payload: {
namespace,
actionType: `${namespace}/pipeline/step`,
},
});
throw error;
}
const { data, timeout } = response;
if (timeout) {
yield put({
type: 'messages/tip/error',
payload: ((_6 = current.service.message) === null || _6 === void 0 ? void 0 : _6.failure) || '接口请求超时',
});
if (action === null || action === void 0 ? void 0 : action.callback) {
action.callback(new Error(((_7 = current.service.message) === null || _7 === void 0 ? void 0 : _7.failure) || '接口请求超时'));
}
return false;
}
// service self + service pipeline action + service context action
if (current.service.quiet !== true &&
current.quiet !== true &&
action.quiet != true) {
const actionTitle = typeof action.title == 'string' ? action.title : '操作';
yield put({
type: 'messages/tip/success',
payload: ((_8 = current.service.message) === null || _8 === void 0 ? void 0 : _8.success) || `${actionTitle}成功`,
});
}
if (current.service.refresh !== false &&
current.refresh !== false &&
action.refresh !== false) {
yield put({ type: 'service/query', payload: { page: 1 } });
}
let newValues = data;
if (typeof current.service.values === 'function') {
try {
newValues = yield call(current.service.values, data, values);
}
catch (error) {
console.error(error);
yield put({
type: 'messages/tip/error',
payload: error.message || ((_9 = current.service.message) === null || _9 === void 0 ? void 0 : _9.failure),
});
return;
}
}
else if (doreamon_1.default.is.object(data) &&
'result' in data &&
'code' in data &&
'message' in data) {
// 服务 { code, message, result } 规范,直接返回 result
newValues = data.result;
}
// if (action?.callback) {
// action.callback(null, newValues);
// }
yield call(doreamon_1.default.delay, 300);
yield put({
type: 'pipeline/step',
steps: steps + 1,
pipeline,
action,
payload: { values: newValues },
target,
});
},
*'pipeline/type/navigate'({ current, steps, pipeline, action, payload, target }, { select, put, race, call }) {
var _a, _b, _c;
const navigate = current['navigate'];
const values = (payload === null || payload === void 0 ? void 0 : payload.values) || {};
let href = '';
if ((navigate === null || navigate === void 0 ? void 0 : navigate.format) && typeof navigate.format === 'function') {
href = navigate.format(values);
}
else if (navigate === null || navigate === void 0 ? void 0 : navigate.template) {
href = doreamon_1.default.string.format(navigate.template, {
...values,
id: (_b = (_a = values) === null || _a === void 0 ? void 0 : _a._id) !== null && _b !== void 0 ? _b : (_c = values) === null || _c === void 0 ? void 0 : _c.id,
});
}
else if (navigate === null || navigate === void 0 ? void 0 : navigate.key) {
// 先查找自己,然后查找上级
href = values[navigate === null || navigate === void 0 ? void 0 : navigate.key];
}
// replace $ with location.pathname
href = href.replace(/\$/, window.location.pathname);
const type = navigate === null || navigate === void 0 ? void 0 : navigate.type;
switch (type) {
case 'spa':
// yield put({ type: 'routers/push', payload: href });
yield put({ type: 'menus/navigate', payload: href });
break;
case 'iframe':
yield put({
type: `${NAMESPACES.iframe}/open`,
payload: {
attributes: {
...navigate === null || navigate === void 0 ? void 0 : navigate.iframe,
target: {
namespace: namespace,
effect: 'pipeline/step',
//
props: {
steps: steps + 1,
pipeline,
action,
},
},
},
datasets: {
values: {
src: href,
},
},
},
});
break;
default:
if ((navigate === null || navigate === void 0 ? void 0 : navigate.target) == '_blank') {
window.open(href);
}
else {
window.location.href = href;
}
}
},
*'pipeline/type/copy'({ current, steps, pipeline, action, payload, target }, { put, call }) {
var _a, _b, _c, _d, _e;
const copy = current['copy'];
const values = (payload === null || payload === void 0 ? void 0 : payload.values) || {};
let value = '';
if ((copy === null || copy === void 0 ? void 0 : copy.format) && typeof copy.format === 'function') {
value = copy.format(values);
}
else if (copy === null || copy === void 0 ? void 0 : copy.template) {
value = doreamon_1.default.string.format(copy.template, {
...values,
id: (_b = (_a = values) === null || _a === void 0 ? void 0 : _a._id) !== null && _b !== void 0 ? _b : (_c = values) === null || _c === void 0 ? void 0 : _c.id,
});
}
else if (copy === null || copy === void 0 ? void 0 : copy.key) {
// 先查找自己,然后查找上级
value = values[copy === null || copy === void 0 ? void 0 : copy.key];
}
// replace $ with location.pathname
value = value.replace(/\$/, window.location.pathname);
yield call(doreamon_1.default.dom.clipboard.copy, [value]);
yield put({
type: 'messages/tip/success',
payload: ((_e = (_d = current === null || current === void 0 ? void 0 : current.copy) === null || _d === void 0 ? void 0 : _d.message) === null || _e === void 0 ? void 0 : _e.success) || `${action.title}成功`,
});
},
*'pipeline/type/terminal'({ current, steps, pipeline, action, payload }, { put, select }) {
// const { values, initialValue, ...datasets } = payload;
const values = (payload === null || payload === void 0 ? void 0 : payload.values) || {};
const terminal = manifestActionPipelineRenderableAttr(values, pipeline, action, config, current.terminal, ['url', 'title', 'width']);
yield put({
type: `${NAMESPACES.terminal}/open`,
payload: {
attributes: {
...terminal,
target: {
namespace: namespace,
effect: 'pipeline/step',
//
props: {
steps: steps + 1,
pipeline,
action,
},
},
},
datasets: {
...payload,
values,
},
},
});
},
*'pipeline/type/iframe'({ current, steps, pipeline, action, payload }, { put, select }) {
// const { values, initialValue, ...datasets } = payload;
const values = (payload === null || payload === void 0 ? void 0 : payload.values) || {};
const iframe = manifestActionPipelineRenderableAttr(values, pipeline, action, config, current.iframe, ['url', 'title', 'width']);
yield put({
type: `${NAMESPACES.iframe}/open`,
payload: {
attributes: {
...iframe,
target: {
namespace: namespace,
effect: 'pipeline/step',
//
props: {
steps: steps + 1,
pipeline,
action,
},
},
},
datasets: {
...payload,
values,
},
},
});
},
*'pipeline/type/transfer'({ current, steps, pipeline, action, payload, target }, { put, select }) {
const values = (payload === null || payload === void 0 ? void 0 : payload.values) || {};
const transfer = manifestActionPipelineRenderableAttr(values, pipeline, action, config, current.transfer, ['type', 'title', 'layout', 'titles', 'values']);
if (!transfer.values) {
transfer.values = values;
}
yield put({
type: `${NAMESPACES.transfer}/open`,
payload: {
attributes: {
...transfer,
target: {
namespace: namespace,
effect: 'pipeline/step',
//
props: {
steps: steps + 1,
pipeline,
action,
target,
},
},
},
datasets: {
...payload,
values: transfer.values,
},
},
});
},
*'pipeline/type/treeselect'({ current, steps, pipeline, action, payload, target }, { put, select }) {
const values = (payload === null || payload === void 0 ? void 0 : payload.values) || {};
const treeselect = manifestActionPipelineRenderableAttr(values, pipeline, action, config, current.treeselect, ['type', 'title', 'layout']);
yield put({
type: `${NAMESPACES.treeselect}/open`,
payload: {
attributes: {
...treeselect,
target: {
namespace: namespace,
effect: 'pipeline/step',
//
props: {
steps: steps + 1,
pipeline,
action,
target,
},
},
},
datasets: {
...payload,
values,
},
},
});
},
*'pipeline/type/values'({ current, steps, pipeline, action, payload, target }, { put, select }) {
var _a, _b, _c;
let values = (payload === null || payload === void 0 ? void 0 : payload.values) || {};
if (((_a = current.values) === null || _a === void 0 ? void 0 : _a.ignored) === true) {
values = {};
}
else {
// const { values, initialValue, ...datasets } = payload;
if ((_b = current.values) === null || _b === void 0 ? void 0 : _b.onBefore) {
values = current.values.onBefore.apply(null, [
values,
pipeline,
action,
manifest,
]);
}
if ((_c = current.values) === null || _c === void 0 ? void 0 : _c.pick) {
if (Array.isArray(current.values.pick)) {
// string[]
values = doreamon_1.default.object.pick(values, current.values.pick);
}
else {
values = current.values.pick.apply(null, [
values,
pipeline,
action,
manifest,
]);
}
}
}
yield put({
type: 'pipeline/step',
steps: steps + 1,
pipeline,
action,
payload: {
...payload,
values,
},
target,
});
},
*'pipeline/type/preview'({ current, steps, pipeline, action, payload, target }, { put, select }) {
var _a;
const values = (payload === null || payload === void 0 ? void 0 : payload.values) || {};
const preview = manifestActionPipelineRenderableAttr(values, pipeline, action, config, current.preview, ['title', 'valuesKey', 'fields', 'mode', 'config', 'code']);
yield put({
type: `${NAMESPACES.preview}/open`,
payload: {
attributes: {
...preview,
target: {
namespace: namespace,
effect: 'pipeline/step',
//
props: {
steps: steps + 1,
pipeline,
action,
target,
},
},
},
datasets: {
...payload,
values: !((_a = current === null || current === void 0 ? void 0 : current.preview) === null || _a === void 0 ? void 0 : _a.valuesKey)
? values
: doreamon_1.default.object.get(values, current.preview.valuesKey) ||
{},
},
},
});
},
*'pipeline/type/dialog'({ current, steps, pipeline, action, payload, target }, { put, select }) {
const values = (payload === null || payload === void 0 ? void 0 : payload.values) || {};
const dialog = manifestActionPipelineRenderableAttr(values, pipeline, action, config, current.dialog, [
'title',
'width',
'fullscreen',
'hideHeader',
'hideFooter',
'hideClose',
]);
yield put({
type: `${NAMESPACES.dialog}/open`,
payload: {
attributes: {
...dialog,
target: {
namespace: namespace,
effect: 'pipeline/step',
//
props: {
steps: steps + 1,
pipeline,
action,
target,
},
},
},
datasets: {
...payload,
values,
},
},
});
},
*'pipeline/type/popup'({ current, steps, pipeline, action, payload, target }, { put, select }) {
const values = (payload === null || payload === void 0 ? void 0 : payload.values) || {};
const popup = manifestActionPipelineRenderableAttr(values, pipeline, action, config, current.popup, ['title', 'width']);
yield put({
type: `${NAMESPACES.popup}/open`,
payload: {
attributes: {
...popup,
target: {
namespace: namespace,
effect: 'pipeline/step',
//
props: {
steps: steps + 1,
pipeline,
action,
target,
},
},
},
datasets: {
...payload,
values,
},
},
});
},
*'pipeline/type/action'({ current, steps, pipeline, action, payload, target }, { call, put, select }) {
var _a, _b, _c, _d, _e, _f;
// default namespace is self
const { namespace: actionNamespace, key, callback, } = current.action || {};
if (!key) {
throw new Error('[pipeline.service: action] key is required');
}
if (!target) {
target = {
namespace,
effect: 'pipeline/step',
//
props: {
steps: steps + 1,
pipeline,
action,
},
};
}
// 优先级: current.action.quiet > current.quiet > action.quiet
const isNextActionQuiet = (_c = (_b = (_a = current === null || current === void 0 ? void 0 : current.action) === null || _a === void 0 ? void 0 : _a.quiet) !== null && _b !== void 0 ? _b : current === null || current === void 0 ? void 0 : current.quiet) !== null && _c !== void 0 ? _c : action === null || action === void 0 ? void 0 : action.quiet;
const isNextActionRefresh = (_f = (_e = (_d = current === null || current === void 0 ? void 0 : current.action) === null || _d === void 0 ? void 0 : _d.quiet) !== null && _e !== void 0 ? _e : current === null || current === void 0 ? void 0 : current.refresh) !== null && _f !== void 0 ? _f : action === null || action === void 0 ? void 0 : action.refresh;
yield put({
type: !actionNamespace
? 'dispatcher'
: `${actionNamespace}/dispatcher`,
payload: {
//
meta: {
key,
callback,
// extends from current pipline action + context action
quiet: isNextActionQuiet,
refresh: isNextActionRefresh,
},
// data: {
// //
// },
//
target,
//
// @TODO
from: 'action',
actionPayload: payload,
},
});
// // next pipeline action
// const nextSteps = steps + 1;
// const next = pipeline[nextSteps];
// // last pipeline action
// if (!next) {
// return ;
// }
// yield call(doreamon.delay, 100);
// yield put({
// type: `pipeline/type/${next.type}`,
// current: next,
// steps: nextSteps,
// pipeline,
// action,
// payload,
// });
},
*'pipeline/type/logs'({ current, steps, pipeline, action, payload }, { put, select }) {
// const { values, initialValue, ...datasets } = payload;
const values = (payload === null || payload === void 0 ? void 0 : payload.values) || {};
const logs = manifestActionPipelineRenderableAttr(values, pipeline, action, config, current.logs, [
'log',
'sse',
'sseOptions',
'downloadURL',
'downloadFilename',
'downloadBtnText',
]);
yield put({
type: `${NAMESPACES.log}/open`,
payload: {
attributes: {
...logs,
target: {
namespace: namespace,
effect: 'pipeline/step',
//
props: {
steps: steps + 1,
pipeline,
action,
},
},
},
datasets: {
...payload,
values,
},
},
});
},
*'pipeline/type/message'({ current, steps, pipeline, action, payload }, { put, select }) {
var _a;
const values = (payload === null || payload === void 0 ? void 0 : payload.values) || {};
const message = manifestActionPipelineRenderableAttr(values, pipeline, action, config, (_a = current.message) !== null && _a !== void 0 ? _a : { type: 'info' }, ['type', 'message']);
// const type = current?.message?.type ??