Skip to content

Commit

Permalink
Merge pull request #553 from seznam/fix-dependencies
Browse files Browse the repository at this point in the history
fix: OC chaining
  • Loading branch information
jsimck authored Feb 5, 2024
2 parents d608f70 + 677dfcc commit 00d9f4c
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-rockets-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ima/core": patch
---

Fixed OC chaining and missing type for Response cookie options.
12 changes: 8 additions & 4 deletions packages/core/src/config/bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ type AddOCPrefixes<T, P extends string> = {
[K in keyof T as K extends string ? `${P}${K}` : never]: T[K] | null;
};

type WithOCOptional<T> = AddOCPrefixes<T, '?'>;
type WithOCSpread<T> = AddOCPrefixes<T, '...'>;
type WithOCOptionalSpread<T> = AddOCPrefixes<T, '...?'>;
type AddOCChaining<T> = {
[K in keyof T as K extends string ? `${K}` | `${K}.${string}` : never]: T[K];
};

type WithOCOptional<T> = AddOCPrefixes<AddOCChaining<T>, '?'>;
type WithOCSpread<T> = AddOCPrefixes<AddOCChaining<T>, '...'>;
type WithOCOptionalSpread<T> = AddOCPrefixes<AddOCChaining<T>, '...?'>;

export type DecoratedOCAliasMap = OCAliasMap &
export type DecoratedOCAliasMap = AddOCChaining<OCAliasMap> &
WithOCOptional<OCAliasMap> &
WithOCOptionalSpread<OCAliasMap> &
WithOCSpread<OCAliasMap>;
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/router/ClientRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export class ClientRouter extends AbstractRouter {
RouteFactory,
Dispatcher,
Window,
// @ts-expect-error `FIXME`
'?$Settings.$Router.middlewareTimeout',
];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/router/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class Response {
setCookie(
name: string,
value: boolean | number | string,
options = {}
options: CookieOptions = {}
): this {
if ($Debug) {
if (this._response && this._response.headersSent) {
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/router/ServerRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class ServerRouter extends AbstractRouter {
Dispatcher,
Request,
Response,
// @ts-expect-error `FIXME`
'?$Settings.$Router.middlewareTimeout',
];
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/storage/CookieStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ const COOKIE_SEPARATOR = '; ';

export type CookieOptions = {
domain?: string;
expires?: number | Date;
expires?: Date;
httpOnly?: boolean;
maxAge?: number;
path?: string;
sameSite?: string;
sameSite?: 'none' | 'lax' | 'strict' | undefined;
secure?: boolean;
partitioned?: boolean;
};
Expand Down Expand Up @@ -73,7 +73,7 @@ export class CookieStorage extends Storage<Cookie['value']> {
partitioned: false,
httpOnly: false,
domain: '',
sameSite: 'Lax',
sameSite: 'lax',
};

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/storage/__tests__/CookieStorageSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('ima.storage.CookieStorage', () => {
const setCookieStringWithDomain =
'cok3=hello3; Path=/; Domain=localhost:3001; Expires=Fri, 31 Dec 9999 23:59:59 GMT';
const setCookieStringWithComplex =
'cok3="hello3"; Domain=localhost:3001; Expires=Fri, 31 Dec 9999 23:59:59 GMT; HttpOnly; Secure; Partitioned; Path=/; SameSite=Lax';
'cok3="hello3"; Domain=localhost:3001; Expires=Fri, 31 Dec 9999 23:59:59 GMT; HttpOnly; Secure; Partitioned; Path=/; SameSite=lax';
const setCookieStringWithMaxAge =
'cok3="hello3"; Domain=localhost:3001; Expires=Fri, 31 Dec 9999 23:59:59 GMT; Max-Age=5; HttpOnly; Partitioned; Secure; Path=/';
const cookiesStringForCookieHeader = 'cok1=hello; cok2=hello2';
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('ima.storage.CookieStorage', () => {
(cookie['_storage'].get('cok1') as Cookie).options.expires
).not.toBeNull();
expect((cookie['_storage'].get('cok1') as Cookie).options.sameSite).toBe(
'Lax'
'lax'
);
expect((cookie['_storage'].get('cok2') as Cookie).options.path).toBe('/');
});
Expand Down Expand Up @@ -240,7 +240,7 @@ describe('ima.storage.CookieStorage', () => {
secure: true,
path: '/',
domain: 'localhost:3001',
sameSite: 'Lax',
sameSite: 'lax',
partitioned: true,
});
});
Expand Down

0 comments on commit 00d9f4c

Please sign in to comment.