Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial intent API implementation #453

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
c025286
Added initial intent models
jonaslagoni Mar 29, 2021
bf46e47
Added parser method
jonaslagoni Mar 29, 2021
d33f824
Added better jsdoc
jonaslagoni Mar 29, 2021
40d7190
Merge branch 'master' into feature/mock_implementation
jonaslagoni Mar 29, 2021
06ec4ea
Changed version
jonaslagoni Mar 30, 2021
44da7bc
Changed naming of intent models
jonaslagoni Mar 30, 2021
f33d3f7
Revert version
jonaslagoni Mar 30, 2021
e3632a0
Added further APIs
jonaslagoni Mar 30, 2021
a2be235
Added more intents
jonaslagoni Mar 30, 2021
ad0fa2b
Added missing name intent for the message
jonaslagoni Mar 30, 2021
5310c62
feat: add fake data for info object
smoya Mar 30, 2021
495fb32
Added message content type intent
jonaslagoni Mar 30, 2021
4cfca6a
Added getter for default content type
jonaslagoni Mar 30, 2021
e5c8489
Updated types
jonaslagoni Mar 31, 2021
25849f5
add some mixins needed for the doc and info
smoya Apr 1, 2021
43fc8d2
rename mixings to mixins :)
smoya Apr 2, 2021
4bd1f74
proper import utils. Next time will be better :)
smoya Apr 2, 2021
023a005
add intent base class
smoya Apr 6, 2021
4bdac34
add schema model
smoya Apr 6, 2021
9ee7acb
add mocking for schemas
smoya Apr 6, 2021
b8b3f32
rename Schema to IntentSchema
smoya Apr 6, 2021
1831edf
fix import
smoya Apr 6, 2021
0dd92db
revert wrong rename
smoya Apr 6, 2021
2fe851e
provide mock schemas as map
smoya Apr 6, 2021
83b21ab
Use proper base class
smoya Apr 6, 2021
e50d9bf
Removed unused intents
jonaslagoni Apr 6, 2021
74b2c92
Merge branch 'master' into feature/mock_implementation
jonaslagoni Apr 7, 2021
ccf0a18
Reworked intent API
jonaslagoni Apr 7, 2021
89b5c22
Updated types
jonaslagoni Apr 12, 2021
d0ac9e1
Removed binding property argument
jonaslagoni Apr 12, 2021
8a5b425
Added operation types
jonaslagoni Apr 12, 2021
c8560c4
Added servers for operation
jonaslagoni Apr 12, 2021
f48ac50
Added mocked content type
jonaslagoni Apr 12, 2021
7ce71d4
Added operations to server
jonaslagoni Apr 12, 2021
f95e147
Added return mock values
jonaslagoni Apr 12, 2021
820199d
Updated types
jonaslagoni Apr 12, 2021
e1e6fa4
Fixed wrong mocks for root object
jonaslagoni Apr 13, 2021
2490442
Fixed base model for intent not mocked correctly.
jonaslagoni Apr 13, 2021
b06e44f
Fixed issues with mock
jonaslagoni Apr 13, 2021
c0f01e9
Removed any json property reference
jonaslagoni Apr 13, 2021
34a54e6
add some extension methods to the base class
smoya Apr 13, 2021
94888f1
Fixed problem with circular dependencies
jonaslagoni Apr 13, 2021
78786bd
Fixed eslint
jonaslagoni Apr 13, 2021
ce172f4
add new models and intents
smoya Apr 13, 2021
f050c4c
add channel-parameter model
smoya Apr 14, 2021
7d77e4d
channel name() + ChannelParameter extending from model at models/
smoya Apr 14, 2021
ddc8599
Message, Tags and Operations
smoya Apr 14, 2021
ac08239
Fix mock for IntentChannelParameter schema properties
smoya Apr 15, 2021
b749b75
Fix message examples() return type
smoya Apr 15, 2021
67be35f
Merge branch 'master' into feature/mock_implementation
jonaslagoni Apr 15, 2021
0747fb3
Security Scheme type as enum constant
smoya Apr 15, 2021
17015e7
Security Scheme ApiKey location as enum constant
smoya Apr 15, 2021
ce905cc
Remove channel name() in favor of path()
smoya Apr 15, 2021
c6db74b
Added external docs
jonaslagoni Apr 20, 2021
b67711f
add missing intents for Operation
smoya Apr 20, 2021
24db64d
Added basic intents
jonaslagoni Apr 20, 2021
3219fb3
Fixed some issues with the API
jonaslagoni Apr 20, 2021
ddb6850
add missing intents for SecurityScheme
smoya Apr 20, 2021
393f3f9
add missing intents for ServerVariable
smoya Apr 20, 2021
18342c5
add missing intents for Server
smoya Apr 20, 2021
1abe1d8
add missing intents for Tag
smoya Apr 20, 2021
441d071
Formatted all intent models
jonaslagoni Apr 21, 2021
e626b57
Added missing property tags
jonaslagoni Apr 21, 2021
8ed49e0
Fixed wrong import
jonaslagoni Apr 21, 2021
ff3040c
Fixed message return type
jonaslagoni Apr 21, 2021
16f3acb
Added missing intent function for root.
jonaslagoni Apr 22, 2021
b066fb8
Moved some intents from asyncapi to info
jonaslagoni Apr 22, 2021
11e2727
Removed unused import
jonaslagoni Apr 22, 2021
7315606
Moved tags to info
jonaslagoni Apr 22, 2021
396aa10
Added correct return type to examples
jonaslagoni Apr 22, 2021
a245978
Removed server security model and added scopes function for security …
jonaslagoni Apr 22, 2021
8c159c6
Added missing functions
jonaslagoni Apr 23, 2021
6c7a9c5
Moved models around
jonaslagoni Jan 11, 2022
3bb3552
Merge branch 'master-main' into feature/mock_implementation
jonaslagoni Jan 11, 2022
8d74371
Moved models around
jonaslagoni Jan 21, 2022
1cd3da3
Merge branch 'master' into feature/mock_implementation
jonaslagoni Jan 21, 2022
543edb2
Moved stuff around
jonaslagoni Jan 21, 2022
5e32ac3
removed unused intent model
jonaslagoni Jan 21, 2022
c7bffd1
Fixed tests
jonaslagoni Jan 21, 2022
660b964
Changed types
jonaslagoni Jan 21, 2022
9fa36ed
Fixed code smells
jonaslagoni Jan 21, 2022
69e92a7
Switched types up
jonaslagoni Jan 21, 2022
918b734
Switched to old operation types
jonaslagoni Jan 21, 2022
34f91f4
Added mocking framework and tests
jonaslagoni Jan 21, 2022
bee1bb2
Added tests
jonaslagoni Jan 21, 2022
2926e6b
Moved stuff around
jonaslagoni Jan 21, 2022
ef3564f
Merge branch 'master' into feature/mock_implementation
jonaslagoni Jan 31, 2022
9baf807
Fixed tests
jonaslagoni Feb 11, 2022
5fdb98b
add intermediate object for Channels, Messages and Operations
smoya Feb 21, 2022
4481bcf
Merge remote-tracking branch 'origin/next-major' into feature/mock_im…
smoya Feb 21, 2022
3a24bb2
fix linting issues
smoya Feb 21, 2022
3ba6710
add Servers object + id() on models
smoya Feb 22, 2022
2594463
add isEmpty
smoya Mar 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
399 changes: 100 additions & 299 deletions lib/models/asyncapi.js

Large diffs are not rendered by default.

37 changes: 9 additions & 28 deletions lib/models/channel-parameter.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
const { mix } = require('./utils');

const Base = require('./base');
const Schema = require('./schema');

const MixinDescription = require('../mixins/description');
const MixinSpecificationExtensions = require('../mixins/specification-extensions');
module.exports = {};

/**
* Implements functions to deal with a ChannelParameter object.
*
* @class
* @alias module:@asyncapi/parser#ChannelParameter
* @extends Base
* @mixes MixinDescription
* @mixes MixinSpecificationExtensions
* @returns {ChannelParameter}
* @alias module:@asyncapi/parser#IntentChannelParameter
*/
class ChannelParameter extends Base {
/**
* @returns {string}
*/
location() {
return this._json.location;
}

class IntentChannelParameter {
/**
* @returns {Schema}
*/
schema() {
if (!this._json.schema) return null;
return new Schema(this._json.schema);
}
*
* @returns {string}
*/
name() { return 'param name'; }
}

module.exports = mix(ChannelParameter, MixinDescription, MixinSpecificationExtensions);
module.exports.IntentChannelParameter = IntentChannelParameter;
128 changes: 61 additions & 67 deletions lib/models/channel.js
Original file line number Diff line number Diff line change
@@ -1,102 +1,96 @@
const { createMapOfType, getMapValueOfType, mix } = require('./utils');

const Base = require('./base');
const ChannelParameter = require('./channel-parameter');
const PublishOperation = require('./publish-operation');
const SubscribeOperation = require('./subscribe-operation');

const MixinDescription = require('../mixins/description');
const MixinBindings = require('../mixins/bindings');
const MixinSpecificationExtensions = require('../mixins/specification-extensions');
module.exports = {};
const ParserError = require('../errors/parser-error');
// eslint-disable-next-line no-unused-vars
const { IntentMessage } = require('./message');
const { IntentOperation } = require('./operation');
const { IntentChannelParameter } = require('./channel-parameter');
const { IntentOperations } = require('./operations');
const { OperationTypes } = require('./operation-types');
const utils = require('../utils');

/**
* Implements functions to deal with a Channel object.
*
* @class
* @alias module:@asyncapi/parser#Channel
* @extends Base
* @mixes MixinDescription
* @mixes MixinBindings
* @mixes MixinSpecificationExtensions
* @returns {Channel}
* @alias module:@asyncapi/parser#IntentChannel
*/
class Channel extends Base {
class IntentChannel {
/**
* @returns {Object<string, ChannelParameter>}
*
* @param {string} document
* @param {string} channelId
*/
parameters() {
return createMapOfType(this._json.parameters, ChannelParameter);
constructor(document, channelId) {
if (document === undefined || document === null || channelId === undefined || channelId === null) throw new ParserError(`Invalid JSON to instantiate the ${this.constructor.name} object.`);
this.document = document;
this.channelId = channelId;
}

/**
* @param {string} name - Name of the parameter.
* @returns {ChannelParameter}
* @returns {IntentOperations}
*/
parameter(name) {
return getMapValueOfType(this._json.parameters, name, ChannelParameter);
operations() {
// TODO should this be done in the constructor so we don't have to do it everytime this method is called?
const operations = [];
if (utils.isVersion2(this.document.json())) { // Ideally we should directly pass the version so we dont need to get from the document
const channel = this.document.channel(this.channelId); // In v2.x channel id is the path
if (channel !== undefined && channel !== null) {
if (channel.hasSubscribe()) operations.push(new IntentOperation(this.document, this.channelId, [OperationTypes.Send]));
if (channel.hasPublish()) operations.push(new IntentOperation(this.document, this.channelId, [OperationTypes.Receive]));
}
}
return new IntentOperations(operations);
}

/**
* @returns {boolean}
* @returns {string}
*/
hasParameters() {
return !!this._json.parameters;
}
id() { return this.channelId; }

/**
* @returns {boolean}
* @returns {string}
*/
hasServers() {
return !!this._json.servers;
}
path() { return 'some/test/path'; }

/**
* @returns {String[]}
* @returns {IntentMessage[]}
*/
servers() {
if (!this._json.servers) return [];
return this._json.servers;
}

messages() { return [new IntentMessage(this.document, this.operations[0])];}

/**
* @param {number} index - Index of the server.
* @returns {String}
*
* @param {string} bindingProtocol
* @returns {boolean}
*/
server(index) {
if (!this._json.servers) return null;
if (typeof index !== 'number') return null;
if (index > this._json.servers.length - 1) return null;
return this._json.servers[+index];
}

hasBinding(bindingProtocol) { return true; }
/**
* @returns {PublishOperation}
*/
publish() {
if (!this._json.publish) return null;
return new PublishOperation(this._json.publish);
}
*
* @param {string} bindingProtocol
* @returns {any|undefined}
*/
binding(bindingProtocol) {return {};}

/**
* @returns {SubscribeOperation}
*
* @returns {boolean}
*/
subscribe() {
if (!this._json.subscribe) return null;
return new SubscribeOperation(this._json.subscribe);
}

hasParameters() { return true; }
/**
* @returns {boolean}
*
* @returns {IntentChannelParameter[]|undefined}
*/
hasPublish() {
return !!this._json.publish;
}
parameters() { return [new IntentChannelParameter()];}

/**
*
* @returns {boolean}
*/
hasSubscribe() {
return !!this._json.subscribe;
}
hasDescription() { return true; }
/**
*
* @returns {string|undefined}
*/
description() {return 'some test description';}
}

module.exports = mix(Channel, MixinDescription, MixinBindings, MixinSpecificationExtensions);
module.exports.IntentChannel = IntentChannel;
70 changes: 70 additions & 0 deletions lib/models/channels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

module.exports = {};
// eslint-disable-next-line no-unused-vars
const { IntentChannel } = require('./channel');

/**
*
* @class
* @alias module:@asyncapi/parser#IntentChannels
*/
class IntentChannels {
/**
*
* @param {IntentChannel[]} channels
*/
constructor(channels) {
this.channels = channels;
}

/**
* @returns {IntentChannel[]}
*/
filterBySend() {
return this.filterBy((channel) => {
return channel.operations().filterBySend().lenght > 0;
});
}

/**
* @returns {IntentChannel[]}
*/
filterByReceive() {
return this.filterBy((channel) => {
return channel.operations().filterByReceive().lenght > 0;
});
}

/**
* @returns {IntentChannel[]}
*/
filterById(channelId) {
return this.filterBy((channel) => {
if (channel.path() === channelId) return true; // TODO Test!!
});
}

/**
* @returns {IntentChannel[]}
*/
filterBy(callbackFn) {
return this.channels.filter(callbackFn);
}

/**
* @returns {IntentChannel[]}
*/
all() {
return this.channels;
}

/**
* @returns boolean
*/
isEmpty() {
return this.channels.length === 0;
}
}

module.exports.IntentChannels = IntentChannels;

53 changes: 27 additions & 26 deletions lib/models/contact.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@

const { mix } = require('./utils');

const Base = require('./base');

const MixinSpecificationExtensions = require('../mixins/specification-extensions');
module.exports = {};

/**
* Implements functions to deal with the Contact object.
*
* @class
* @alias module:@asyncapi/parser#Contact
* @extends Base
* @mixes MixinSpecificationExtensions
* @returns {Contact}
* @alias module:@asyncapi/parser#IntentContact
*/
class Contact extends Base {
class IntentContact {
/**
* @returns {string}
*
* @returns {boolean}
*/
name() {
return this._json.name;
}

hasName() { return true; }
/**
* @returns {string}
* @returns {string|undefined}
*/
url() {
return this._json.url;
}
name() {return 'some name'; }

/**
*
* @returns {boolean}
*/
hasUrl() { return true; }
/**
* @returns {string|undefined}
*/
url() {return 'test.com'; }

/**
* @returns {string}
*
* @returns {boolean}
*/
hasEmail() { return true; }
/**
* @returns {string|undefined}
*/
email() {
return this._json.email;
}
email() {return 'test@test.com'; }
}

module.exports = mix(Contact, MixinSpecificationExtensions);
module.exports.IntentContact = IntentContact;
36 changes: 19 additions & 17 deletions lib/models/correlation-id.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
const { mix } = require('./utils');

const Base = require('./base');

const MixinDescription = require('../mixins/description');
const MixinSpecificationExtensions = require('../mixins/specification-extensions');
module.exports = {};

/**
* Implements functions to deal with a CorrelationId object.
* @class
* @alias module:@asyncapi/parser#CorrelationId
* @extends Base
* @mixes MixinDescription
* @mixes MixinSpecificationExtensions
* @returns {CorrelationId}
* @alias module:@asyncapi/parser#IntentCorrelationId
*/
class CorrelationId extends Base {
class IntentCorrelationId {
/**
* @returns {boolean}
*/
hasDescription() { return true; }
/**
* @returns {string|undefined}
*/
description() { return 'a message description'; }

/**
* @returns {boolean}
*/
hasLocation() { return true; }
/**
* @returns {string}
* @returns {string|undefined}
*/
location() {
return this._json.location;
}
location() { return '$message.header#/correlationId'; }
}

module.exports = mix(CorrelationId, MixinSpecificationExtensions, MixinDescription);
module.exports.IntentCorrelationId = IntentCorrelationId;
Loading