132 lines
3.9 KiB
JavaScript
132 lines
3.9 KiB
JavaScript
(function() {
|
|
function tKey(key) {
|
|
return typeof t === 'function' ? t(key) : key;
|
|
}
|
|
|
|
var state = {
|
|
currentStep: 1,
|
|
wizardProtocol: 'rest',
|
|
wizardMode: 'create',
|
|
wizardEditId: null,
|
|
wizardWorkspaceId: null,
|
|
wizardCurrentOperation: null,
|
|
wizardCurrentVersion: null,
|
|
wizardProtoUpload: null,
|
|
wizardDescriptorSetUpload: null,
|
|
wizardSoapWsdlUpload: null,
|
|
wizardSoapXsdUpload: null,
|
|
wizardTestResponsePreview: null,
|
|
grpcDescriptorServices: [],
|
|
soapServiceCatalog: [],
|
|
wizardProtocolCapabilities: null,
|
|
wizardSecrets: [],
|
|
wizardAuthProfiles: [],
|
|
selectedUpstreamId: null,
|
|
editingUpstreamId: null,
|
|
protoParsed: null,
|
|
selectedRpcMethod: null,
|
|
};
|
|
|
|
function defaultProtocolCapabilities() {
|
|
return {
|
|
rest: {
|
|
supports_execution_modes: ['unary', 'window', 'session', 'async_job'],
|
|
supports_transport_behaviors: ['request_response', 'server_stream', 'deferred_result'],
|
|
},
|
|
graphql: {
|
|
supports_execution_modes: ['unary'],
|
|
supports_transport_behaviors: ['request_response'],
|
|
},
|
|
grpc: {
|
|
supports_execution_modes: ['unary', 'window', 'session', 'async_job'],
|
|
supports_transport_behaviors: ['request_response', 'server_stream'],
|
|
},
|
|
websocket: {
|
|
supports_execution_modes: ['window', 'session', 'async_job'],
|
|
supports_transport_behaviors: ['server_stream', 'stateful_session', 'deferred_result'],
|
|
},
|
|
soap: {
|
|
supports_execution_modes: ['unary', 'async_job'],
|
|
supports_transport_behaviors: ['request_response', 'server_stream', 'deferred_result'],
|
|
},
|
|
};
|
|
}
|
|
|
|
function currentProtocolCapabilities() {
|
|
var capabilities = state.wizardProtocolCapabilities || defaultProtocolCapabilities();
|
|
return capabilities[state.wizardProtocol] || capabilities.rest;
|
|
}
|
|
|
|
async function loadProtocolCapabilities() {
|
|
if (!state.wizardWorkspaceId || !window.CrankApi || typeof window.CrankApi.getProtocolCapabilities !== 'function') {
|
|
state.wizardProtocolCapabilities = defaultProtocolCapabilities();
|
|
return state.wizardProtocolCapabilities;
|
|
}
|
|
|
|
try {
|
|
var response = await window.CrankApi.getProtocolCapabilities(state.wizardWorkspaceId);
|
|
var mapped = {};
|
|
(response.items || []).forEach(function(item) {
|
|
mapped[item.protocol] = item;
|
|
});
|
|
state.wizardProtocolCapabilities = mapped;
|
|
} catch (_error) {
|
|
state.wizardProtocolCapabilities = defaultProtocolCapabilities();
|
|
}
|
|
|
|
return state.wizardProtocolCapabilities;
|
|
}
|
|
|
|
function step3Labels() {
|
|
return {
|
|
rest: tKey('wizard.step3.rest.label'),
|
|
graphql: tKey('wizard.step3.graphql.label'),
|
|
grpc: tKey('wizard.step3.grpc.label'),
|
|
websocket: tKey('wizard.step3.websocket.label'),
|
|
soap: tKey('wizard.step3.soap.label'),
|
|
};
|
|
}
|
|
|
|
window.CrankWizardState = {
|
|
state: state,
|
|
defaultProtocolCapabilities: defaultProtocolCapabilities,
|
|
currentProtocolCapabilities: currentProtocolCapabilities,
|
|
loadProtocolCapabilities: loadProtocolCapabilities,
|
|
step3Labels: step3Labels,
|
|
};
|
|
|
|
[
|
|
'currentStep',
|
|
'wizardProtocol',
|
|
'wizardMode',
|
|
'wizardEditId',
|
|
'wizardWorkspaceId',
|
|
'wizardCurrentOperation',
|
|
'wizardCurrentVersion',
|
|
'wizardProtoUpload',
|
|
'wizardDescriptorSetUpload',
|
|
'wizardSoapWsdlUpload',
|
|
'wizardSoapXsdUpload',
|
|
'wizardTestResponsePreview',
|
|
'grpcDescriptorServices',
|
|
'soapServiceCatalog',
|
|
'wizardProtocolCapabilities',
|
|
'wizardSecrets',
|
|
'wizardAuthProfiles',
|
|
'selectedUpstreamId',
|
|
'editingUpstreamId',
|
|
'protoParsed',
|
|
'selectedRpcMethod'
|
|
].forEach(function(key) {
|
|
Object.defineProperty(window, key, {
|
|
configurable: true,
|
|
get: function() {
|
|
return state[key];
|
|
},
|
|
set: function(value) {
|
|
state[key] = value;
|
|
},
|
|
});
|
|
});
|
|
}());
|