diff --git a/mirage/factories/crate.js b/mirage/factories/crate.js index b5949c92546..97c400bde4c 100644 --- a/mirage/factories/crate.js +++ b/mirage/factories/crate.js @@ -30,16 +30,6 @@ export default Factory.extend({ _owner_teams: () => [], _owner_users: () => [], - links() { - return { - 'owner_user': `/api/v1/crates/${this.id}/owner_user`, - 'owner_team': `/api/v1/crates/${this.id}/owner_team`, - 'reverse_dependencies': `/api/v1/crates/${this.id}/reverse_dependencies`, - 'version_downloads': `/api/v1/crates/${this.id}/downloads`, - 'versions': `/api/v1/crates/${this.id}/versions`, - }; - }, - withVersion: trait({ afterCreate(crate, server) { server.create('version', { crate: crate.id }); diff --git a/mirage/factories/version.js b/mirage/factories/version.js index 232d5ed4f24..3e8165a7454 100644 --- a/mirage/factories/version.js +++ b/mirage/factories/version.js @@ -22,14 +22,6 @@ export default Factory.extend({ features: () => {}, _authors: () => [], - links() { - return { - 'authors': `/api/v1/crates/${this.crate}/${this.num}/authors`, - 'dependencies': `/api/v1/crates/${this.crate}/${this.num}/dependencies`, - 'version_downloads': `/api/v1/crates/${this.crate}/${this.num}/downloads`, - }; - }, - afterCreate(version, server) { let crate = server.schema.crates.find(version.crate); crate.update({ versions: crate.versions.concat(parseInt(version.id, 10)) }); diff --git a/mirage/fixtures/crates.js b/mirage/fixtures/crates.js index ef3704eaf67..d188c0ada31 100644 --- a/mirage/fixtures/crates.js +++ b/mirage/fixtures/crates.js @@ -12,13 +12,6 @@ export default [{ "network", ], "license": "MIT", - "links": { - "owner_user": "/api/v1/crates/nanomsg/owner_user", - "owner_team": "/api/v1/crates/nanomsg/owner_team", - "reverse_dependencies": "/api/v1/crates/nanomsg/reverse_dependencies", - "version_downloads": "/api/v1/crates/nanomsg/downloads", - "versions": "/api/v1/crates/nanomsg/versions", - }, "max_version": "0.7.0-alpha", "name": "nanomsg", "repository": "https://github.com/thehydroimpulse/nanomsg.rs", @@ -60,12 +53,6 @@ export default [{ "id": "rust_mixin", "keywords": ["rust", "plugin", "code-generation"], "license": "MIT/Apache-2.0", - "links": { - "owners": "/api/v1/crates/rust_mixin/owners", - "reverse_dependencies": "/api/v1/crates/rust_mixin/reverse_dependencies", - "version_downloads": "/api/v1/crates/rust_mixin/downloads", - "versions": "/api/v1/crates/rust_mixin/versions" - }, "max_version": "0.0.1", "name": "rust_mixin", "repository": "https://github.com/huonw/external_mixin", @@ -128,12 +115,6 @@ export default [{ "id": "external_mixin", "keywords": ["python", "ruby", "shell", "plugin", "code-generation"], "license": "MIT/Apache-2.0", - "links": { - "owners": "/api/v1/crates/external_mixin/owners", - "reverse_dependencies": "/api/v1/crates/external_mixin/reverse_dependencies", - "version_downloads": "/api/v1/crates/external_mixin/downloads", - "versions": "/api/v1/crates/external_mixin/versions" - }, "max_version": "0.0.1", "name": "external_mixin", "repository": "https://github.com/huonw/external_mixin", @@ -148,12 +129,6 @@ export default [{ "id": "external_mixin_umbrella", "keywords": ["plugin", "code-generation"], "license": "MIT/Apache-2.0", - "links": { - "owners": "/api/v1/crates/external_mixin_umbrella/owners", - "reverse_dependencies": "/api/v1/crates/external_mixin_umbrella/reverse_dependencies", - "version_downloads": "/api/v1/crates/external_mixin_umbrella/downloads", - "versions": "/api/v1/crates/external_mixin_umbrella/versions" - }, "max_version": "0.0.2", "name": "external_mixin_umbrella", "repository": "https://github.com/huonw/external_mixin", @@ -168,12 +143,6 @@ export default [{ "id": "Inflector", "keywords": ["string", "case", "camel", "snake", "inflection"], "license": "BSD-2-Clause", - "links": { - "owners": "/api/v1/crates/Inflector/owners", - "reverse_dependencies": "/api/v1/crates/Inflector/reverse_dependencies", - "version_downloads": "/api/v1/crates/Inflector/downloads", - "versions": "/api/v1/crates/Inflector/versions" - }, "max_version": "0.1.6", "name": "Inflector", "repository": "https://github.com/whatisinternet/inflector", @@ -188,12 +157,6 @@ export default [{ "id": "rs-es", "keywords": ["elasticsearch", "elastic"], "license": "Apache-2.0", - "links": { - "owners": "/api/v1/crates/rs-es/owners", - "reverse_dependencies": "/api/v1/crates/rs-es/reverse_dependencies", - "version_downloads": "/api/v1/crates/rs-es/downloads", - "versions": "/api/v1/crates/rs-es/versions" - }, "max_version": "0.1.17", "name": "rs-es", "repository": "https://github.com/benashford/rs-es", @@ -208,12 +171,6 @@ export default [{ "id": "rust-crypto", "keywords": ["Crypto", "MD5", "Sha1", "Sha2", "AES"], "license": "MIT/Apache-2.0", - "links": { - "owners": "/api/v1/crates/rust-crypto/owners", - "reverse_dependencies": "/api/v1/crates/rust-crypto/reverse_dependencies", - "version_downloads": "/api/v1/crates/rust-crypto/downloads", - "versions": "/api/v1/crates/rust-crypto/versions" - }, "max_version": "0.2.34", "name": "rust-crypto", "repository": "https://github.com/DaGenix/rust-crypto/", @@ -228,12 +185,6 @@ export default [{ "id": "rust-htslib", "keywords": ["htslib", "bam", "bioinformatics", "pileup", "sequencing"], "license": "MIT", - "links": { - "owners": "/api/v1/crates/rust-htslib/owners", - "reverse_dependencies": "/api/v1/crates/rust-htslib/reverse_dependencies", - "version_downloads": "/api/v1/crates/rust-htslib/downloads", - "versions": "/api/v1/crates/rust-htslib/versions" - }, "max_version": "0.5.2", "name": "rust-htslib", "repository": "https://github.com/rust-bio/rust-htslib.git", @@ -248,12 +199,6 @@ export default [{ "id": "kinetic-rust", "keywords": ["Protocol", "Kinetic", "Storage"], "license": "MIT", - "links": { - "owners": "/api/v1/crates/kinetic-rust/owners", - "reverse_dependencies": "/api/v1/crates/kinetic-rust/reverse_dependencies", - "version_downloads": "/api/v1/crates/kinetic-rust/downloads", - "versions": "/api/v1/crates/kinetic-rust/versions" - }, "max_version": "0.0.16", "name": "kinetic-rust", "repository": "https://github.com/icorderi/kinetic-rust/", @@ -268,12 +213,6 @@ export default [{ "id": "rustless", "keywords": ["api", "web", "hyper", "iron", "rest"], "license": "MIT", - "links": { - "owners": "/api/v1/crates/rustless/owners", - "reverse_dependencies": "/api/v1/crates/rustless/reverse_dependencies", - "version_downloads": "/api/v1/crates/rustless/downloads", - "versions": "/api/v1/crates/rustless/versions" - }, "max_version": "0.8.0", "name": "rustless", "repository": "https://crates.io/crates/rustless", @@ -288,12 +227,6 @@ export default [{ "id": "serde", "keywords": ["serde", "serialization"], "license": "MIT/Apache-2.0", - "links": { - "owners": "/api/v1/crates/serde/owners", - "reverse_dependencies": "/api/v1/crates/serde/reverse_dependencies", - "version_downloads": "/api/v1/crates/serde/downloads", - "versions": "/api/v1/crates/serde/versions" - }, "max_version": "0.6.1", "name": "serde", "repository": "https://github.com/serde-rs/serde", @@ -308,12 +241,6 @@ export default [{ "id": "rusted_cypher", "keywords": ["neo4j", "database", "query", "cypher", "graph"], "license": "MIT", - "links": { - "owners": "/api/v1/crates/rusted_cypher/owners", - "reverse_dependencies": "/api/v1/crates/rusted_cypher/reverse_dependencies", - "version_downloads": "/api/v1/crates/rusted_cypher/downloads", - "versions": "/api/v1/crates/rusted_cypher/versions" - }, "max_version": "0.7.1", "name": "rusted_cypher", "repository": "https://github.com/livioribeiro/rusted-cypher", @@ -328,12 +255,6 @@ export default [{ "id": "zlib", "keywords": [], "license": "MIT", - "links": { - "owners": "/api/v1/crates/zlib/owners", - "reverse_dependencies": "/api/v1/crates/zlib/reverse_dependencies", - "version_downloads": "/api/v1/crates/zlib/downloads", - "versions": "/api/v1/crates/zlib/versions" - }, "max_version": "0.0.1", "name": "zlib", "repository": null, @@ -348,12 +269,6 @@ export default [{ "id": "rustful", "keywords": ["web", "rest", "framework", "http", "routing"], "license": "MIT", - "links": { - "owners": "/api/v1/crates/rustful/owners", - "reverse_dependencies": "/api/v1/crates/rustful/reverse_dependencies", - "version_downloads": "/api/v1/crates/rustful/downloads", - "versions": "/api/v1/crates/rustful/versions" - }, "max_version": "0.5.0", "name": "rustful", "repository": "https://github.com/Ogeon/rustful", @@ -368,12 +283,6 @@ export default [{ "id": "postgres", "keywords": ["database", "sql"], "license": "MIT", - "links": { - "owners": "/api/v1/crates/postgres/owners", - "reverse_dependencies": "/api/v1/crates/postgres/reverse_dependencies", - "version_downloads": "/api/v1/crates/postgres/downloads", - "versions": "/api/v1/crates/postgres/versions" - }, "max_version": "0.10.1", "name": "postgres", "repository": "https://github.com/sfackler/rust-postgres", @@ -388,12 +297,6 @@ export default [{ "id": "quickcheck", "keywords": ["testing", "quickcheck", "property", "shrinking", "fuzz"], "license": "Unlicense/MIT", - "links": { - "owners": "/api/v1/crates/quickcheck/owners", - "reverse_dependencies": "/api/v1/crates/quickcheck/reverse_dependencies", - "version_downloads": "/api/v1/crates/quickcheck/downloads", - "versions": "/api/v1/crates/quickcheck/versions" - }, "max_version": "0.2.24", "name": "quickcheck", "repository": "https://github.com/BurntSushi/quickcheck", @@ -408,12 +311,6 @@ export default [{ "id": "quickcheck_macros", "keywords": ["testing", "quickcheck", "property", "shrinking", "fuzz"], "license": "Unlicense/MIT", - "links": { - "owners": "/api/v1/crates/quickcheck_macros/owners", - "reverse_dependencies": "/api/v1/crates/quickcheck_macros/reverse_dependencies", - "version_downloads": "/api/v1/crates/quickcheck_macros/downloads", - "versions": "/api/v1/crates/quickcheck_macros/versions" - }, "max_version": "0.2.24", "name": "quickcheck_macros", "repository": "https://github.com/BurntSushi/quickcheck", @@ -428,12 +325,6 @@ export default [{ "id": "nc_rustlex", "keywords": ["lexer", "lexical", "analyser", "generator"], "license": "MIT", - "links": { - "owners": "/api/v1/crates/nc_rustlex/owners", - "reverse_dependencies": "/api/v1/crates/nc_rustlex/reverse_dependencies", - "version_downloads": "/api/v1/crates/nc_rustlex/downloads", - "versions": "/api/v1/crates/nc_rustlex/versions" - }, "max_version": "0.3.1", "name": "nc_rustlex", "repository": "https://github.com/nicolas-cherel/rustlex", @@ -448,12 +339,6 @@ export default [{ "id": "nom", "keywords": ["parser", "parser-combinators", "parsing", "streaming", "bit"], "license": "MIT", - "links": { - "owners": "/api/v1/crates/nom/owners", - "reverse_dependencies": "/api/v1/crates/nom/reverse_dependencies", - "version_downloads": "/api/v1/crates/nom/downloads", - "versions": "/api/v1/crates/nom/versions" - }, "max_version": "1.0.1", "name": "nom", "repository": "https://github.com/Geal/nom", diff --git a/mirage/fixtures/versions.js b/mirage/fixtures/versions.js index ab061fa92ba..383606a4e13 100644 --- a/mirage/fixtures/versions.js +++ b/mirage/fixtures/versions.js @@ -10,11 +10,6 @@ export default [{ ] }, "id": 40906, - "links": { - "authors": "/api/v1/crates/nanomsg/0.7.0-alpha.1/authors", - "dependencies": "/api/v1/crates/nanomsg/0.7.0-alpha.1/dependencies", - "version_downloads": "/api/v1/crates/nanomsg/0.7.0-alpha.1/downloads" - }, "num": "0.7.0-alpha.1", "updated_at": "2016-12-27T08:40:00Z", "yanked": false, @@ -39,11 +34,6 @@ export default [{ ] }, "id": 40905, - "links": { - "authors": "/api/v1/crates/nanomsg/0.6.1/authors", - "dependencies": "/api/v1/crates/nanomsg/0.6.1/dependencies", - "version_downloads": "/api/v1/crates/nanomsg/0.6.1/downloads" - }, "num": "0.6.1", "updated_at": "2016-12-27T08:40:00Z", "yanked": false, @@ -65,11 +55,6 @@ export default [{ "features": { }, "id": 28431, - "links": { - "authors": "/api/v1/crates/nanomsg/0.6.0/authors", - "dependencies": "/api/v1/crates/nanomsg/0.6.0/dependencies", - "version_downloads": "/api/v1/crates/nanomsg/0.6.0/downloads" - }, "num": "0.6.0", "updated_at": "2016-06-10T20:03:55Z", "yanked": false, @@ -91,11 +76,6 @@ export default [{ "features": { }, "id": 21273, - "links": { - "authors": "/api/v1/crates/nanomsg/0.5.0/authors", - "dependencies": "/api/v1/crates/nanomsg/0.5.0/dependencies", - "version_downloads": "/api/v1/crates/nanomsg/0.5.0/downloads" - }, "num": "0.5.0", "updated_at": "2016-01-24T22:07:58Z", "yanked": false, @@ -117,11 +97,6 @@ export default [{ "features": { }, "id": 18445, - "links": { - "authors": "/api/v1/crates/nanomsg/0.4.2/authors", - "dependencies": "/api/v1/crates/nanomsg/0.4.2/dependencies", - "version_downloads": "/api/v1/crates/nanomsg/0.4.2/downloads" - }, "num": "0.4.2", "updated_at": "2015-12-16T00:01:56Z", "yanked": false, @@ -143,11 +118,6 @@ export default [{ "features": { }, "id": 17384, - "links": { - "authors": "/api/v1/crates/nanomsg/0.4.1/authors", - "dependencies": "/api/v1/crates/nanomsg/0.4.1/dependencies", - "version_downloads": "/api/v1/crates/nanomsg/0.4.1/downloads" - }, "num": "0.4.1", "updated_at": "2015-12-11T23:54:29Z", "yanked": false, @@ -169,11 +139,6 @@ export default [{ "features": { }, "id": 13574, - "links": { - "authors": "/api/v1/crates/nanomsg/0.4.0/authors", - "dependencies": "/api/v1/crates/nanomsg/0.4.0/dependencies", - "version_downloads": "/api/v1/crates/nanomsg/0.4.0/downloads" - }, "num": "0.4.0", "updated_at": "2015-12-11T23:54:29Z", "yanked": false, @@ -195,11 +160,6 @@ export default [{ "features": { }, "id": 9014, - "links": { - "authors": "/api/v1/crates/nanomsg/0.3.4/authors", - "dependencies": "/api/v1/crates/nanomsg/0.3.4/dependencies", - "version_downloads": "/api/v1/crates/nanomsg/0.3.4/downloads" - }, "num": "0.3.4", "updated_at": "2015-12-15T00:03:39Z", "yanked": false, @@ -221,11 +181,6 @@ export default [{ "features": { }, "id": 8236, - "links": { - "authors": "/api/v1/crates/nanomsg/0.3.3/authors", - "dependencies": "/api/v1/crates/nanomsg/0.3.3/dependencies", - "version_downloads": "/api/v1/crates/nanomsg/0.3.3/downloads" - }, "num": "0.3.3", "updated_at": "2015-12-11T23:54:29Z", "yanked": false, @@ -247,11 +202,6 @@ export default [{ "features": { }, "id": 7190, - "links": { - "authors": "/api/v1/crates/nanomsg/0.3.2/authors", - "dependencies": "/api/v1/crates/nanomsg/0.3.2/dependencies", - "version_downloads": "/api/v1/crates/nanomsg/0.3.2/downloads" - }, "num": "0.3.2", "updated_at": "2015-12-11T23:54:29Z", "yanked": false, @@ -273,11 +223,6 @@ export default [{ "features": { }, "id": 4944, - "links": { - "authors": "/api/v1/crates/nanomsg/0.3.1/authors", - "dependencies": "/api/v1/crates/nanomsg/0.3.1/dependencies", - "version_downloads": "/api/v1/crates/nanomsg/0.3.1/downloads" - }, "num": "0.3.1", "updated_at": "2015-12-11T23:54:29Z", "yanked": false, @@ -299,11 +244,6 @@ export default [{ "features": { }, "id": 940, - "links": { - "authors": "/api/v1/crates/nanomsg/0.3.0/authors", - "dependencies": "/api/v1/crates/nanomsg/0.3.0/dependencies", - "version_downloads": "/api/v1/crates/nanomsg/0.3.0/downloads" - }, "num": "0.3.0", "updated_at": "2015-12-11T23:54:29Z", "yanked": false, @@ -325,11 +265,6 @@ export default [{ "features": { }, "id": 924, - "links": { - "authors": "/api/v1/crates/nanomsg/0.2.0/authors", - "dependencies": "/api/v1/crates/nanomsg/0.2.0/dependencies", - "version_downloads": "/api/v1/crates/nanomsg/0.2.0/downloads" - }, "num": "0.2.0", "updated_at": "2015-12-11T23:54:29Z", "yanked": false, @@ -351,11 +286,6 @@ export default [{ "features": { }, "id": 28674, - "links": { - "authors": "/api/v1/crates/unicorn-rpc/0.2.0/authors", - "dependencies": "/api/v1/crates/unicorn-rpc/0.2.0/dependencies", - "version_downloads": "/api/v1/crates/unicorn-rpc/0.2.0/downloads" - }, "num": "0.2.0", "updated_at": "2015-12-11T23:54:29Z", "yanked": false, diff --git a/mirage/serializers/application.js b/mirage/serializers/application.js index e50684bc645..1a966912efa 100644 --- a/mirage/serializers/application.js +++ b/mirage/serializers/application.js @@ -1,3 +1,26 @@ import { ActiveModelSerializer } from 'ember-cli-mirage'; -export default ActiveModelSerializer; +export default ActiveModelSerializer.extend({ + getHashForResource(resource) { + let isModel = this.isModel(resource); + let hash = ActiveModelSerializer.prototype.getHashForResource.apply(this, arguments); + + if (isModel) { + let links = this.links(resource); + if (links) { + hash[0].links = links; + } + } else { + for (let i = 0; i < hash[0].length && i < resource.models.length; i++) { + let links = this.links(resource.models[i]); + if (links) { + hash[0][i].links = links; + } + } + } + + return hash; + }, + + links() {}, +}); diff --git a/mirage/serializers/crate.js b/mirage/serializers/crate.js index ae55f7669a2..5e2a6bc411c 100644 --- a/mirage/serializers/crate.js +++ b/mirage/serializers/crate.js @@ -18,5 +18,15 @@ export default BaseSerializer.extend({ 'repository', 'updated_at', 'versions', - ] + ], + + links(crate) { + return { + 'owner_user': `/api/v1/crates/${crate.id}/owner_user`, + 'owner_team': `/api/v1/crates/${crate.id}/owner_team`, + 'reverse_dependencies': `/api/v1/crates/${crate.id}/reverse_dependencies`, + 'version_downloads': `/api/v1/crates/${crate.id}/downloads`, + 'versions': `/api/v1/crates/${crate.id}/versions`, + }; + }, }); diff --git a/mirage/serializers/version.js b/mirage/serializers/version.js index 341696895a0..b01504f6326 100644 --- a/mirage/serializers/version.js +++ b/mirage/serializers/version.js @@ -12,5 +12,13 @@ export default BaseSerializer.extend({ 'num', 'updated_at', 'yanked', - ] + ], + + links(version) { + return { + 'authors': `/api/v1/crates/${version.crate}/${version.num}/authors`, + 'dependencies': `/api/v1/crates/${version.crate}/${version.num}/dependencies`, + 'version_downloads': `/api/v1/crates/${version.crate}/${version.num}/downloads`, + }; + }, });