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

Add ambient TypeScript type information #463

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

# ember-cookies

`ember-cookies` implements an abstract __cookie API that works both in the
`ember-cookies` implements an abstract **cookie API that works both in the
browser (via `document.cookie`) as well as with Fastboot in the server
context__ (using the `request` and `response` accessible via the `fastBoot`
context** (using the `request` and `response` accessible via the `fastBoot`
service).

__Having access to cookies both in the browser as well as in FastBoot is key to
being able to share a common session.__
**Having access to cookies both in the browser as well as in FastBoot is key to
being able to share a common session.**

## Installation

Expand All @@ -20,17 +20,17 @@ Install `ember-cookies` with

```js
// app/controllers/application.js
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
import Controller from "@ember/controller";
import { inject as service } from "@ember/service";
import { computed } from "@ember/object";
const { keys } = Object;

export default Controller.extend({
cookies: service(),

allCookies: computed(function() {
let cookieService = this.get('cookies');
cookieService.write('now', new Date().getTime());
allCookies: computed(function () {
let cookieService = this.get("cookies");
cookieService.write("now", new Date().getTime());

let cookies = cookieService.read();
return keys(cookies).reduce((acc, key) => {
Expand All @@ -39,24 +39,24 @@ export default Controller.extend({

return acc;
}, []);
})
}),
});
```

## API

The `cookies` service has methods for reading and writing cookies:

* `read(name, options = {})`: reads the cookie with the given name, returns its
- `read(name, options = {})`: reads the cookie with the given name, returns its
value as a `String`; options can be used to set `raw` (boolean, disables
URL-decoding the value).
* `write(name, value, options = {})`: writes a cookie with the given name and
- `write(name, value, options = {})`: writes a cookie with the given name and
value; options can be used to set `domain`, `expires` (Date), `maxAge` (time
in seconds), `path`, `secure`, `raw` (boolean, disables URL-encoding the
value) and `sameSite`.
* `clear(name, options = {})`: clears the cookie so that future reads do not
- `clear(name, options = {})`: clears the cookie so that future reads do not
return a value; options can be used to specify `domain`, `path` or `secure`.
* `exists(name)`: checks whether a cookie exists at all (even with a falsy
- `exists(name)`: checks whether a cookie exists at all (even with a falsy
value) and returns `true` if that is the case or `false` otherwise.

## License
Expand Down
40 changes: 40 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
declare module "ember-cookies/services/cookies" {
import Service from "@ember/service";

type ReadOptions = {
raw?: boolean;
domain?: never;
expires?: never;
maxAge?: never;
path?: never;
};

type WriteOptions = {
domain?: string;
path?: string;
secure?: boolean;
raw?: boolean;
sameSite?: "Strict" | "Lax" | "None";
signed?: never;
} & (
| { expires?: Date; maxAge?: never }
| { maxAge?: number; expires?: never }
);

type ClearOptions = {
domain?: string;
path?: string;
secure?: boolean;

expires?: never;
maxAge?: never;
raw?: never;
};

export default class CookiesService extends Service {
public read(name: string, options?: ReadOptions): string;
public write(name: string, value: unknown, options?: WriteOptions): void;
public clear(name: string, options?: ClearOptions): void;
public exists(name: string): boolean;
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "ember-cookies",
"version": "0.5.2",
"description": "Cookies abstraction for Ember.js that works both in the browser as well as with Fastboot on the server.",
"types": "./index.d.ts",
"keywords": [
"ember-addon"
],
Expand All @@ -25,6 +26,7 @@
"ember-cli-babel": "^7.1.0"
},
"devDependencies": {
"@types/ember": "^3.16.0",
"broccoli-asset-rev": "^3.0.0",
"chai": "^4.1.0",
"chalk": "^4.1.0",
Expand Down
165 changes: 165 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,149 @@
dependencies:
"@types/node" "*"

"@types/ember@^3.16.0":
version "3.16.0"
resolved "https://registry.yarnpkg.com/@types/ember/-/ember-3.16.0.tgz#1627b42087556ee366258e37b31ae81571e6e0ca"
integrity sha512-9TBWidO/9ydThgh0Fy7y2DNX7Pb8REoV7tYK+HBFZ2iyc1TwXTNt15gVz0cCyorvsve2OS+vt5wzYvlqgSGlwg==
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/jquery" "*"
"@types/rsvp" "*"

"@types/ember__application@*":
version "3.16.0"
resolved "https://registry.yarnpkg.com/@types/ember__application/-/ember__application-3.16.0.tgz#2765a9db639173d0d9abd72f3a76ca61b0c09b38"
integrity sha512-iudEJJmax99sLJCqmIwt3pM3ZuU6QHScH9ksg1pznwAjDGD3eAXYW6USYcK4KZwEIbXyX86KBBcjwg///Ae5JQ==
dependencies:
"@types/ember__application" "*"
"@types/ember__engine" "*"
"@types/ember__object" "*"
"@types/ember__routing" "*"

"@types/ember__array@*":
version "3.16.1"
resolved "https://registry.yarnpkg.com/@types/ember__array/-/ember__array-3.16.1.tgz#276b67c1218cced62ffc98a5f5fef9c4731c0f11"
integrity sha512-6KfqMT0ta5XCn+5f6gQxsnzU076rN4ckwHNRWx9StNSySb3v4cyMVU7MuLCEQPI3Uwtl3EwluiZWoa7X99y9ZA==
dependencies:
"@types/ember__array" "*"
"@types/ember__object" "*"

"@types/ember__component@*":
version "3.16.0"
resolved "https://registry.yarnpkg.com/@types/ember__component/-/ember__component-3.16.0.tgz#42a5e9c1ff573f5bab6e7ac5e7e4a59a957323cb"
integrity sha512-MnzHTGQ6ic9/wT72Ho3BybEajKFkJOakeYSriVLFQTxbaLwm8RNDrZNPHWGT4FEl6dEf90+2SBJHFagbIPAhng==
dependencies:
"@types/ember__component" "*"
"@types/ember__object" "*"
"@types/jquery" "*"

"@types/ember__controller@*":
version "3.16.1"
resolved "https://registry.yarnpkg.com/@types/ember__controller/-/ember__controller-3.16.1.tgz#a2c0041eac7200cbdd72db26568b5969d8cffbf7"
integrity sha512-fSL09DyM1dePQQMBUCOSyG9PmxJMmeK2+ui5Wo+jr3UyEqyLYYmh2UvBS9qB8xFDHy49wuQq8EIXegRYKJRniw==
dependencies:
"@types/ember__object" "*"

"@types/ember__debug@*":
version "3.16.1"
resolved "https://registry.yarnpkg.com/@types/ember__debug/-/ember__debug-3.16.1.tgz#f1d1e866478a94e4f0ad1bcbcecf22a92a2a2930"
integrity sha512-z8powodH2u9oXPGV4pOUy2Onu+JR+z0AcR0CKNFjJM9CnWMQXr/sTARCCHchillzH36ddFQf5AocdjYCXm9MQg==
dependencies:
"@types/ember__debug" "*"
"@types/ember__engine" "*"
"@types/ember__object" "*"

"@types/ember__engine@*":
version "3.16.0"
resolved "https://registry.yarnpkg.com/@types/ember__engine/-/ember__engine-3.16.0.tgz#c01aea25b87f71805511949507a0e1fe539f8bc4"
integrity sha512-1UOR4jG8NLwnw4pUe3MOvfIJ6rX2RYr9zr9KiLyOYVIQ9lQxfXB6L+U5gf0dUewnWy7h58iZ01FlPGrlwKm2vg==
dependencies:
"@types/ember__engine" "*"
"@types/ember__object" "*"

"@types/ember__error@*":
version "3.16.0"
resolved "https://registry.yarnpkg.com/@types/ember__error/-/ember__error-3.16.0.tgz#5260d2307c47d684f8135de3f772448e969834bb"
integrity sha512-inHhs9w2bEmJql0ddVXeWyqkzPbmyxcJ1Pe+UFf9aYWnLr0S7sZPzSQX4l+tGEjf8BCQvoMLk7TdujIj1LAoRA==

"@types/ember__object@*":
version "3.12.1"
resolved "https://registry.yarnpkg.com/@types/ember__object/-/ember__object-3.12.1.tgz#6700172ac5ea7c99c4f9fe5952d62ccd77dafd90"
integrity sha512-jMk+EYaNwmFH2EE7YBDc5GYJggZZv/LhJ31n8qqYhRct3JmpACxs9fFpE4MpTWOwEd/zCDspI0OjiRnkD7JxTA==
dependencies:
"@types/ember__object" "*"
"@types/rsvp" "*"

"@types/ember__polyfills@*":
version "3.12.0"
resolved "https://registry.yarnpkg.com/@types/ember__polyfills/-/ember__polyfills-3.12.0.tgz#4835569329c1b5b5d401a14add71df050d0a7323"
integrity sha512-2HX4vsvHQbodVdw5z0xmOyocRH56e/MetmUf6EJTjWSE9GX5Ry/VE4FZ6nhYzzrVuPOECj5fJ7kSaI5KugBHfg==

"@types/ember__routing@*":
version "3.16.1"
resolved "https://registry.yarnpkg.com/@types/ember__routing/-/ember__routing-3.16.1.tgz#0fe55145b4164b1692d802ad2cb7ee80945ea51e"
integrity sha512-1FW7TR3zCnEPi36VXx+fOw7bOkI9k2bs4NZ9Buvj2vNSjZajPl33dbVqweOUg/0Zkx6cMZyJSgApk9FXNGielA==
dependencies:
"@types/ember__component" "*"
"@types/ember__controller" "*"
"@types/ember__object" "*"
"@types/ember__routing" "*"
"@types/ember__service" "*"

"@types/ember__runloop@*":
version "3.16.1"
resolved "https://registry.yarnpkg.com/@types/ember__runloop/-/ember__runloop-3.16.1.tgz#7fdd1a9aefe1a76642a76558912446a594ab1dc9"
integrity sha512-roQ8AkummBJMoDNNqRqj7u9v0fHOOVb4jk7stjpWqhKfg15Yxu/c0sMx49GSofmVE/cLREKH8g+2mVwYb+gJDQ==
dependencies:
"@types/ember__runloop" "*"

"@types/ember__service@*":
version "3.16.0"
resolved "https://registry.yarnpkg.com/@types/ember__service/-/ember__service-3.16.0.tgz#d9e0fafea1f0bf87e6928af878a498b5876569aa"
integrity sha512-yOY3tO1xuo53a+UpfvYeXsZRsU8KVSv1odeoU6mN/WRACbNsD1WvYcolsQ/9TPynt5djEvHEHOR2WwQBIvN+1A==
dependencies:
"@types/ember__object" "*"

"@types/ember__string@*":
version "3.16.0"
resolved "https://registry.yarnpkg.com/@types/ember__string/-/ember__string-3.16.0.tgz#6c5389b6d88a38366f421f4502cc416b82890620"
integrity sha512-zmOuSnvS+xKr7kqyRkc9xghWsqqTcP//9soK2KWVhzQltosmpNdkoy+M2upaSZAzhL7wqiUzX99F1ZMDCkwknQ==
dependencies:
"@types/ember__template" "*"

"@types/ember__template@*":
version "3.16.0"
resolved "https://registry.yarnpkg.com/@types/ember__template/-/ember__template-3.16.0.tgz#fe88a8f8319e0b6bccf9ef5eb7f6ee5ff998333e"
integrity sha512-OVr29pQtbyLVJW6h7+wdkeXLHx00p4CY28znsEgO0X2EeF5xyBhmyhTZOWrGbiTU17+Zs9d4KStt5f1Bq4Wgow==

"@types/ember__test@*":
version "3.16.0"
resolved "https://registry.yarnpkg.com/@types/ember__test/-/ember__test-3.16.0.tgz#d7c95364ec6287b6c209b4358230fdb43c30baa2"
integrity sha512-kYenxB1B3LAqMlzY15ER1oJVDBZJLDIYAcIaTJ56V2FU1B2SBHoiAttId/QQs84oElYIYycm1FWGqMgRrk9UpA==
dependencies:
"@types/ember__application" "*"

"@types/ember__utils@*":
version "3.16.0"
resolved "https://registry.yarnpkg.com/@types/ember__utils/-/ember__utils-3.16.0.tgz#987ee0270e65e272a1686ed5a85482129956b7d0"
integrity sha512-fd0q5d+8/XqoH7H51UmdT9wQA6SGW/fB/1yNSD57NHHiVkkT1GUHhPHWCLjnZHtWIM5cS0+gZeCPGou7qOM/6g==

"@types/events@*":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
Expand Down Expand Up @@ -1342,6 +1485,18 @@
"@types/minimatch" "*"
"@types/node" "*"

"@types/htmlbars-inline-precompile@*":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/htmlbars-inline-precompile/-/htmlbars-inline-precompile-1.0.1.tgz#de564513fabb165746aecd76369c87bd85e5bbb4"
integrity sha512-sVD2e6QAAHW0Y6Btse+tTA9k9g0iKm87wjxRsgZRU5EwSooz80tenbV+fA+f2BI2g0G2CqxsS1rIlwQCtPRQow==

"@types/jquery@*":
version "3.5.1"
resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-3.5.1.tgz#cebb057acf5071c40e439f30e840c57a30d406c3"
integrity sha512-Tyctjh56U7eX2b9udu3wG853ASYP0uagChJcQJXLUXEU6C/JiW5qt5dl8ao01VRj1i5pgXPAf8f1mq4+FDLRQg==
dependencies:
"@types/sizzle" "*"

"@types/mime@*":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-2.0.3.tgz#c893b73721db73699943bfc3653b1deb7faa4a3a"
Expand Down Expand Up @@ -1373,6 +1528,11 @@
"@types/glob" "*"
"@types/node" "*"

"@types/rsvp@*":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@types/rsvp/-/rsvp-4.0.3.tgz#4a1223158453257bce09d42b9eef7cfa6d257482"
integrity sha512-OpRwxbgx16nL/0/7ol0WoLLyLaMXBvtPOHjqLljnzAB/E7Qk1wtjytxgBhOTBMZvuLXnJUqfnjb4W/QclNFvSA==

"@types/serve-static@*":
version "1.13.4"
resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.4.tgz#6662a93583e5a6cabca1b23592eb91e12fa80e7c"
Expand All @@ -1381,6 +1541,11 @@
"@types/express-serve-static-core" "*"
"@types/mime" "*"

"@types/sizzle@*":
version "2.3.2"
resolved "https://registry.yarnpkg.com/@types/sizzle/-/sizzle-2.3.2.tgz#a811b8c18e2babab7d542b3365887ae2e4d9de47"
integrity sha512-7EJYyKTL7tFR8+gDbB6Wwz/arpGa0Mywk1TJbNzKzHtzbwVmY4HR9WqS5VV7dsBUKQmPNr192jHr/VpBluj/hg==

"@types/symlink-or-copy@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@types/symlink-or-copy/-/symlink-or-copy-1.2.0.tgz#4151a81b4052c80bc2becbae09f3a9ec010a9c7a"
Expand Down