codeclimate-connector-sdk
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -20,4 +20,4 @@ "use strict"; | ||
return new RecordProducer_1.RecordProducerFacade({ | ||
produce: function (record) { | ||
_this.logger.info("Produced record: " + JSON.stringify(record, null, " ")); | ||
produce: function (envelope) { | ||
_this.logger.info("Produced record: " + JSON.stringify(envelope.record, null, " ")); | ||
} | ||
@@ -24,0 +24,0 @@ }); |
@@ -0,3 +1,7 @@ | ||
export interface RecordEnvelope { | ||
extractedAt?: Date; | ||
record: object; | ||
} | ||
export interface RecordProducer { | ||
produce: (object: any) => void; | ||
produce: (RecordEnvelope: any) => void; | ||
} | ||
@@ -11,3 +15,3 @@ export declare class InvalidRecordError extends Error { | ||
constructor(implementation: RecordProducer); | ||
produce(record: object): void; | ||
produce(envelope: RecordEnvelope): void; | ||
} |
@@ -41,8 +41,8 @@ "use strict"; | ||
} | ||
RecordProducerFacade.prototype.produce = function (record) { | ||
var validator = new RecordValidator_1.RecordValidator(record); | ||
RecordProducerFacade.prototype.produce = function (envelope) { | ||
var validator = new RecordValidator_1.RecordValidator(envelope.record); | ||
if (!validator.isValid) { | ||
throw new InvalidRecordError(validator.errors.join(", ")); | ||
} | ||
this.implementation.produce(record); | ||
this.implementation.produce(envelope); | ||
}; | ||
@@ -49,0 +49,0 @@ return RecordProducerFacade; |
@@ -8,3 +8,5 @@ export declare class RecordValidator { | ||
get errors(): string[]; | ||
private get schemaPaths(); | ||
private get ajv(); | ||
private get recordTypeDasherize(); | ||
private get recordSchemaRef(); | ||
@@ -11,0 +13,0 @@ private get isValidType(); |
@@ -6,3 +6,3 @@ "use strict"; | ||
var fs_1 = require("fs"); | ||
var schemaPath = path_1.resolve(__dirname, "../schemas/records.json"); | ||
var schemaDirPath = path_1.resolve(__dirname, "../schemas/"); | ||
var RecordValidator = /** @class */ (function () { | ||
@@ -26,7 +26,7 @@ function RecordValidator(record) { | ||
if (!this.isValidType) { | ||
if (!this.record["type"]) { | ||
return ["missing required attribute \"type\""]; | ||
if (!this.record["_type"]) { | ||
return ["missing required attribute \"_type\""]; | ||
} | ||
else { | ||
return ["\"" + this.record["type"] + "\" is not a recognized record type"]; | ||
return ["\"" + this.record["_type"] + "\" is not a recognized record type"]; | ||
} | ||
@@ -60,7 +60,19 @@ } | ||
}); | ||
Object.defineProperty(RecordValidator.prototype, "schemaPaths", { | ||
get: function () { | ||
return fs_1.readdirSync(schemaDirPath).filter(function (path) { | ||
return /\.schema\.json$/.test(path); | ||
}); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(RecordValidator.prototype, "ajv", { | ||
get: function () { | ||
var _this = this; | ||
if (!this._ajv) { | ||
this._ajv = new Ajv({ allErrors: true }); | ||
this._ajv.addSchema(JSON.parse(fs_1.readFileSync(schemaPath).toString()), "records"); | ||
this.schemaPaths.forEach(function (path) { | ||
_this._ajv.addSchema(JSON.parse(fs_1.readFileSync(path_1.resolve(schemaDirPath, path)).toString())); | ||
}); | ||
} | ||
@@ -72,5 +84,17 @@ return this._ajv; | ||
}); | ||
Object.defineProperty(RecordValidator.prototype, "recordTypeDasherize", { | ||
// record types are FooBar, keys in the json schema defs are fooBar | ||
get: function () { | ||
var t = this.record["_type"] || "MissingType"; | ||
var initalDowned = "" + t[0].toLowerCase() + t.slice(1); | ||
return initalDowned.replace(/([a-z])([A-Z])/, function (_m, l, r) { | ||
return l + "-" + r.toLowerCase(); | ||
}); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(RecordValidator.prototype, "recordSchemaRef", { | ||
get: function () { | ||
return "records#/$definitions/" + this.record["type"].toLowerCase(); | ||
return "https://platform.codeclimate.com/schemas/" + this.recordTypeDasherize; | ||
}, | ||
@@ -82,3 +106,3 @@ enumerable: true, | ||
get: function () { | ||
if (!this.record["type"]) { | ||
if (!this.record["_type"]) { | ||
return false; | ||
@@ -85,0 +109,0 @@ } |
interface StreamRecord { | ||
type: string; | ||
attributes: { | ||
id: string; | ||
self: string; | ||
name: string; | ||
htmlUrl?: string; | ||
}; | ||
_type: string; | ||
id: string; | ||
self: string; | ||
name: string; | ||
htmlUrl?: string; | ||
} | ||
@@ -10,0 +8,0 @@ export declare class Stream { |
@@ -6,3 +6,3 @@ "use strict"; | ||
function Stream(record) { | ||
if (record["type"] !== "Stream") { | ||
if (record["_type"] !== "Stream") { | ||
throw "This doesn't look like a Stream record: " + JSON.stringify(record); | ||
@@ -18,3 +18,3 @@ } | ||
get: function () { | ||
return this.record.attributes.id; | ||
return this.record.id; | ||
}, | ||
@@ -26,3 +26,3 @@ enumerable: true, | ||
get: function () { | ||
return this.record.attributes.name; | ||
return this.record.name; | ||
}, | ||
@@ -34,3 +34,3 @@ enumerable: true, | ||
get: function () { | ||
return this.record.attributes.htmlUrl; | ||
return this.record.htmlUrl; | ||
}, | ||
@@ -42,3 +42,3 @@ enumerable: true, | ||
get: function () { | ||
return this.record.attributes.self; | ||
return this.record.self; | ||
}, | ||
@@ -45,0 +45,0 @@ enumerable: true, |
@@ -47,3 +47,3 @@ "use strict"; | ||
var _this = _super.call(this, { | ||
produce: function (record) { return _this._records.push(record); } | ||
produce: function (envelope) { return _this._records.push(envelope.record); } | ||
}) || this; | ||
@@ -50,0 +50,0 @@ _this._records = []; |
{ | ||
"name": "codeclimate-connector-sdk", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "SDK for developing connectors for the Code Climate Platform", | ||
@@ -11,3 +11,4 @@ "license": "AGPL-3.0-only", | ||
"prepublishOnly": "yarn clean && yarn build && yarn test", | ||
"postpublish": "git push && git push --tags" | ||
"postpublish": "git push && git push --tags", | ||
"schema-md": "jsonschema2md -d ./schemas/ -x - -o docs/schemas/" | ||
}, | ||
@@ -30,2 +31,3 @@ "files": [ | ||
"devDependencies": { | ||
"@adobe/jsonschema2md": "^4.0.13", | ||
"@types/jest": "^25.1.3", | ||
@@ -32,0 +34,0 @@ "@types/node": "^13.7.4", |
@@ -7,7 +7,6 @@ # Code Climate Connector SDK | ||
## Development | ||
## Record schemas | ||
Clone this repo, run `yarn install` to install dependencies. `yarn test` will | ||
run unit tests. See [DEVELOPERS.md](DEVELOPERS.md) for more in depth details | ||
about working on this package. | ||
See [docs/schemas/README.md](docs/schemas/README.md) for a reference of the | ||
types of records Code Climate Connectors can use. | ||
@@ -32,1 +31,8 @@ ## CLI | ||
See https://github.com/codeclimate/create-codeclimate-connector. | ||
## Development | ||
Clone this repo, run `yarn install` to install dependencies. `yarn test` will | ||
run unit tests. See [DEVELOPERS.md](DEVELOPERS.md) for more in depth details | ||
about working on this package. | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60
1778
37
114977
8