diff --git a/README.md b/README.md index 887c44f..7a4d7a5 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,28 @@ export default class SomeComponent extends Component { For further documentation on this subject, view the [Engine Linking RFC](https://github.com/emberjs/rfcs/pull/122). +## TypeScript +------------------------------------------------------------------------------ + +The library ships types for TypeScript usage: + +```ts +import Service, { inject as service } from '@ember/service'; +import type EnginesRouterService from 'ember-engines-router-service/services/router'; + +type Transition = ReturnType & { sequence: number }; + +export default class MyService extends Service { + @service declare router: EnginesRouterService; + + doSomeTranstion (): void { + const transition = this.router.transitionToExternal('someRouter'); + transition.data.someKey = 'someValue'; + } +} +``` + + ## Contributing ------------------------------------------------------------------------------ diff --git a/addon/.eslintignore b/addon/.eslintignore index 701947e..f2faadb 100644 --- a/addon/.eslintignore +++ b/addon/.eslintignore @@ -20,3 +20,6 @@ /.node_modules.ember-try/ /bower.json.ember-try /package.json.ember-try + +# type definitions +*.d.ts \ No newline at end of file diff --git a/addon/package.json b/addon/package.json index d33d8eb..6a85081 100644 --- a/addon/package.json +++ b/addon/package.json @@ -18,7 +18,8 @@ }, "files": [ "addon-main.js", - "dist" + "dist", + "types" ], "scripts": { "build": "rollup --config", @@ -36,6 +37,7 @@ "@babel/plugin-proposal-decorators": "^7.17.8", "@embroider/addon-dev": "^1.2.0", "@rollup/plugin-babel": "^5.3.1", + "@types/ember__routing": "^4.0.10", "eslint": "^8.11.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-ember": "^10.5.9", @@ -74,5 +76,12 @@ "./initializers/ember-engines-router-service.js": "./dist/_app_/initializers/ember-engines-router-service.js", "./services/engine-router-service.js": "./dist/_app_/services/engine-router-service.js" } + }, + "typesVersions": { + "*": { + "*": [ + "types/*" + ] + } } } diff --git a/addon/types/services/router.d.ts b/addon/types/services/router.d.ts new file mode 100644 index 0000000..b091c19 --- /dev/null +++ b/addon/types/services/router.d.ts @@ -0,0 +1,11 @@ +import type RouterService from '@ember/routing/router-service'; + +export default interface EnginesRouterService extends Omit< + RouterService, + "currentRoute" | "recognize" | "recognizeAndLoad" +> { + isActiveExternal: RouterService['isActive']; + replaceWithExternal: RouterService['replaceWith']; + transitionToExternal: RouterService['transitionTo']; + urlForExternal: RouterService['urlFor']; +} diff --git a/yarn.lock b/yarn.lock index 9a411a4..fa73e14 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1317,6 +1317,26 @@ ember-cli-version-checker "^3.1.3" ember-compatibility-helpers "^1.1.2" +"@glimmer/component@^1.1.0": + version "1.1.2" + resolved "https://registry.yarnpkg.com/@glimmer/component/-/component-1.1.2.tgz#892ec0c9f0b6b3e41c112be502fde073cf24d17c" + integrity sha512-XyAsEEa4kWOPy+gIdMjJ8XlzA3qrGH55ZDv6nA16ibalCR17k74BI0CztxuRds+Rm6CtbUVgheCVlcCULuqD7A== + dependencies: + "@glimmer/di" "^0.1.9" + "@glimmer/env" "^0.1.7" + "@glimmer/util" "^0.44.0" + broccoli-file-creator "^2.1.1" + broccoli-merge-trees "^3.0.2" + ember-cli-babel "^7.7.3" + ember-cli-get-component-path-option "^1.0.0" + ember-cli-is-package-missing "^1.0.0" + ember-cli-normalize-entity-name "^1.0.0" + ember-cli-path-utils "^1.0.0" + ember-cli-string-utils "^1.1.0" + ember-cli-typescript "3.0.0" + ember-cli-version-checker "^3.1.3" + ember-compatibility-helpers "^1.1.2" + "@glimmer/di@^0.1.9": version "0.1.11" resolved "https://registry.yarnpkg.com/@glimmer/di/-/di-0.1.11.tgz#a6878c07a13a2c2c76fcde598a5c97637bfc4280" @@ -1724,6 +1744,169 @@ dependencies: "@types/ms" "*" +"@types/ember-resolver@*": + version "5.0.11" + resolved "https://registry.yarnpkg.com/@types/ember-resolver/-/ember-resolver-5.0.11.tgz#db931fb5c2d6bda4e29adea132fb48c7ed17aa62" + integrity sha512-2BL9d8kBdNUO9Je6KBF7Q34BSwbQG6vzCzTeSopt8FAmLDfaDU9xDDdyZobpfy9GR36mCSeG9b9wr4bgYh/MYw== + dependencies: + "@types/ember__object" "*" + +"@types/ember@*": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@types/ember/-/ember-4.0.1.tgz#5fe3dc8219b7e0391b2c97d8db945a9e0881badc" + integrity sha512-fYCZtkGq1UqD1rWjvdY4bVQpdZvxkHqVx/B6p2M0cUdyheLNjQgwXfx3o1UU0Bk99mls5Or4ZCnW7s1yliABiw== + dependencies: + "@types/ember__application" "*" + "@types/ember__array" "*" + "@types/ember__component" "*" + "@types/ember__controller" "*" + "@types/ember__debug" "*" + "@types/ember__engine" "*" + "@types/ember__error" "*" + "@types/ember__object" "*" + "@types/ember__polyfills" "*" + "@types/ember__routing" "*" + "@types/ember__runloop" "*" + "@types/ember__service" "*" + "@types/ember__string" "*" + "@types/ember__template" "*" + "@types/ember__test" "*" + "@types/ember__utils" "*" + "@types/htmlbars-inline-precompile" "*" + "@types/rsvp" "*" + +"@types/ember__application@*": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@types/ember__application/-/ember__application-4.0.1.tgz#1bdbd4bf4a995558c5e6297856ad705f181899cc" + integrity sha512-dKyiEHpZRENCRNyS9PQOnYjrcO4QsmeTU+csmiH8B3McYBCp1AKwlnjOd6eTs3O69WDcUq2mFk6BAQM49bAF7Q== + dependencies: + "@glimmer/component" "^1.1.0" + "@types/ember" "*" + "@types/ember-resolver" "*" + "@types/ember__application" "*" + "@types/ember__engine" "*" + "@types/ember__object" "*" + "@types/ember__owner" "*" + "@types/ember__routing" "*" + +"@types/ember__array@*": + version "4.0.2" + resolved "https://registry.yarnpkg.com/@types/ember__array/-/ember__array-4.0.2.tgz#795b377f6cbb9830413227522680feed674aa126" + integrity sha512-d2eU8O5QtqDd/ZqMV3yzIbULh8wPx6UMvxwJ0ThnNgCIFcZLO98deM5w6m5aU6K48Xu1wWzjJBa0jktGSFWXJw== + dependencies: + "@types/ember" "*" + "@types/ember__array" "*" + "@types/ember__object" "*" + +"@types/ember__component@*": + version "4.0.10" + resolved "https://registry.yarnpkg.com/@types/ember__component/-/ember__component-4.0.10.tgz#554d9d384c6441003f0bdfbb709dab7085007cdb" + integrity sha512-ggF6EoKp7o0FKmZ9UKUzsLXHfcho+mKFnHQfUL1k/sUjkHxSd33fIATYuNIGZARRn2JzhYYfRqkgRIRBsoEiaQ== + dependencies: + "@types/ember" "*" + "@types/ember__component" "*" + "@types/ember__object" "*" + +"@types/ember__controller@*": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@types/ember__controller/-/ember__controller-4.0.1.tgz#f181eafc669dfaa29df68746c62941af3b75588a" + integrity sha512-4hX+CjjX2KBpcOyEpcs1SSBmxYlavdAZqcyR23JUnBS+dGjlku15BQu6ZXFKIf84x7izNhC+TrYvAOeLE/Af3w== + dependencies: + "@types/ember__object" "*" + +"@types/ember__debug@*": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@types/ember__debug/-/ember__debug-4.0.1.tgz#1e4a8a1045484295dddc7bd4356d0b3014b0d509" + integrity sha512-qrKk6Ujh6oev7TSB0eB7AEmQWKCt5t84k/K3hDvJXUiLU3YueN0kyt7aPoIAkVjC111A9FqDugl9n60+N5yeEw== + dependencies: + "@types/ember-resolver" "*" + "@types/ember__debug" "*" + "@types/ember__object" "*" + +"@types/ember__engine@*": + version "4.0.2" + resolved "https://registry.yarnpkg.com/@types/ember__engine/-/ember__engine-4.0.2.tgz#01a93c38dce6940a7199435c8ab200c965ba8b73" + integrity sha512-x9c8LtRpYwQnyUiUbGpF2+zrZiA0G3e0lPsprghllWEabnIyvN+GMdtnvt4DmpGQVeUz6JKVdoPAmENBUTTcyg== + dependencies: + "@types/ember-resolver" "*" + "@types/ember__engine" "*" + "@types/ember__object" "*" + "@types/ember__owner" "*" + +"@types/ember__error@*": + version "4.0.0" + resolved "https://registry.yarnpkg.com/@types/ember__error/-/ember__error-4.0.0.tgz#c73037e65c1c3d7060b97f98135ba73c712972b1" + integrity sha512-1WVMR65/QTqPzMWafK2vKEwGafILxRxItbWJng6eEJyKDHRvvHFCl3XzJ4dQjdFcfOlozsn0mmEYCpjKoyzMqA== + +"@types/ember__object@*": + version "4.0.4" + resolved "https://registry.yarnpkg.com/@types/ember__object/-/ember__object-4.0.4.tgz#646a4b56d1d8279d8b21cd8e8265886a569fb87d" + integrity sha512-RwiyzQXKTyFVfZvrYQYtZhfrYAXrNEvtO98vdlzak0MHaks/AkOSNxuTU4tjhfzto4dOcfr6mi8C5mN+yz7LFQ== + dependencies: + "@types/ember" "*" + "@types/ember__object" "*" + "@types/rsvp" "*" + +"@types/ember__owner@*": + version "4.0.0" + resolved "https://registry.yarnpkg.com/@types/ember__owner/-/ember__owner-4.0.0.tgz#2058a8fbf9636774dc79430abd355b07538c51d7" + integrity sha512-7ZotJNCkZUvJpcGHYswQlQsHyRITQ3aNOoFPi86NFxmOXEIVAGVKPHB87w8ZlMmhssG2vitCuNzuQCeDwPaokQ== + +"@types/ember__polyfills@*": + version "4.0.0" + resolved "https://registry.yarnpkg.com/@types/ember__polyfills/-/ember__polyfills-4.0.0.tgz#d83ae94ff2890ad47798315426d9916f39ff4ae6" + integrity sha512-Yk85J18y1Ys6agoIBLdJWu6ZkWe68oaC9JPyW7BhOINVNKm89PXrR/yxdOJ1/vN1Hj7ZZQKq+4X6fz3sxebavA== + +"@types/ember__routing@*", "@types/ember__routing@^4.0.10": + version "4.0.10" + resolved "https://registry.yarnpkg.com/@types/ember__routing/-/ember__routing-4.0.10.tgz#dc8fb1a6024170a1fe7b7ad1a1c061ef73e09789" + integrity sha512-/1k6fqFIV3RZAU64pYXx3nVlHnpqorvQjyq5V4A//kTI/WRcfwCjShgH2jCLrwwpnWo6Pb/y8aOnxyg3ePGy2Q== + dependencies: + "@types/ember" "*" + "@types/ember__controller" "*" + "@types/ember__object" "*" + "@types/ember__routing" "*" + "@types/ember__service" "*" + +"@types/ember__runloop@*": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@types/ember__runloop/-/ember__runloop-4.0.1.tgz#7f6e45af7dbf1158655ef3ad852852b0bf87065f" + integrity sha512-3HrsavVrdgxUkYptQUv/e9RwJG02cV9WbnJxKSvwl9ZYpeX4JbuDVucjTWk5BAvJUVtbiQLPGzLEHZ6daoCbbg== + dependencies: + "@types/ember" "*" + "@types/ember__runloop" "*" + +"@types/ember__service@*": + version "4.0.0" + resolved "https://registry.yarnpkg.com/@types/ember__service/-/ember__service-4.0.0.tgz#ae6164e3b5d927fe17513b49867b52dc0222490d" + integrity sha512-FbN2y6tRb6NIV+kmzQcxRAoB17vH7qHCfzcKlxsmt2EI7fboLTcdeKpZKPBEromRXg83fx67QX1b95WcwSGtaw== + dependencies: + "@types/ember__object" "*" + +"@types/ember__string@*": + version "3.0.9" + resolved "https://registry.yarnpkg.com/@types/ember__string/-/ember__string-3.0.9.tgz#669188ccea5a61777a36bf88a05ba6875dc9b7d7" + integrity sha512-v9QwhhfTTgJH6PCviWlz3JgcraYdSWQoTg2XN5Z7bPgXMJYXczxB/N22L9FnuFgDYdN87yXdTJv6E9rw2YGEhw== + +"@types/ember__template@*": + version "4.0.0" + resolved "https://registry.yarnpkg.com/@types/ember__template/-/ember__template-4.0.0.tgz#3423b6ddc3a6cf0b13a1e0fd5f1a84eec664a095" + integrity sha512-51bAEQecMKpDYRXMmVVfU7excrtxDJixRU7huUsAm4acBCqL2+TmMgTqZEkOQSNy6qnKUc2ktSzX28a9//C6pA== + +"@types/ember__test@*": + version "4.0.0" + resolved "https://registry.yarnpkg.com/@types/ember__test/-/ember__test-4.0.0.tgz#1a7dcbe24fedfc34fa60547b03f130a14397c4b6" + integrity sha512-vI/qhZkexJLN25lp1UAfjJv4R6pPtrQlAmPDXkKd8PNjwRk3KANFVRzdghN7HWhXgQ+s91PbvxEnZ3eZiRPdcQ== + dependencies: + "@types/ember__application" "*" + +"@types/ember__utils@*": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@types/ember__utils/-/ember__utils-4.0.1.tgz#106a7a9652bacc44c735ed1ffd6d3651ac03fdce" + integrity sha512-FhXZ37uY1BNgt63XoPH++PkAsMnF7P5wjPRluXecbFpEFHXP6enFbx1F5vjyoPtFjLEl4R3ftLM5QbEWsuyF5g== + dependencies: + "@types/ember" "*" + "@types/eslint-scope@^3.7.0": version "3.7.3" resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.3.tgz#125b88504b61e3c8bc6f870882003253005c3224" @@ -1804,6 +1987,11 @@ "@types/minimatch" "*" "@types/node" "*" +"@types/htmlbars-inline-precompile@*": + version "3.0.0" + resolved "https://registry.yarnpkg.com/@types/htmlbars-inline-precompile/-/htmlbars-inline-precompile-3.0.0.tgz#4d3f19eeb2af9f4605620e13a566dae3952a4f68" + integrity sha512-n1YwM/Q937KmS9W4Ytran71nzhhcT2FDQI00eRGBNUyeErLZspBdDBewEe1F8tcRlUdsCVo2AZBLJsRjEceTRg== + "@types/http-cache-semantics@*": version "4.0.1" resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz#0ea7b61496902b95890dc4c3a116b60cb8dae812" @@ -1878,6 +2066,11 @@ "@types/glob" "*" "@types/node" "*" +"@types/rsvp@*": + version "4.0.4" + resolved "https://registry.yarnpkg.com/@types/rsvp/-/rsvp-4.0.4.tgz#55e93e7054027f1ad4b4ebc1e60e59eb091e2d32" + integrity sha512-J3Ol++HCC7/hwZhanDvggFYU/GtxHxE/e7cGRWxR04BF7Tt3TqJZ84BkzQgDxmX0uu8IagiyfmfoUlBACh2Ilg== + "@types/serve-static@*": version "1.13.10" resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.10.tgz#f5e0ce8797d2d7cc5ebeda48a52c96c4fa47a8d9"