Skip to content

Commit

Permalink
Remove createSessionContext export from @keystone-6/core/session
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Sep 12, 2022
1 parent 2317d0b commit 31721b5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-pugs-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': major
---

Removes `createSessionContext` export from `@keystone-6/core/session`
15 changes: 15 additions & 0 deletions packages/core/src/lib/context/session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { IncomingMessage, ServerResponse } from 'http';
import { SessionStrategy, CreateContext, SessionContext } from '../../types';

export async function createSessionContext<T>(
sessionStrategy: SessionStrategy<T>,
req: IncomingMessage,
res: ServerResponse,
createContext: CreateContext
): Promise<SessionContext<T>> {
return {
session: await sessionStrategy.get({ req, createContext }),
startSession: (data: T) => sessionStrategy.start({ res, data, createContext }),
endSession: () => sessionStrategy.end({ req, res, createContext }),
};
}
2 changes: 1 addition & 1 deletion packages/core/src/lib/server/createAdminUIMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import url from 'url';
import path from 'path';
import express from 'express';
import type { KeystoneConfig, CreateContext } from '../../types';
import { createSessionContext } from '../../session';
import { createSessionContext } from '../context/session';

const adminErrorHTMLFilepath = path.join(
path.dirname(require.resolve('@keystone-6/core/package.json')),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/server/createApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Config,
} from 'apollo-server-core';
import type { CreateContext, GraphQLConfig, SessionStrategy } from '../../types';
import { createSessionContext } from '../../session';
import { createSessionContext } from '../context/session';

export const createApolloServerMicro = ({
graphQLSchema,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/server/createExpressServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { GraphQLSchema } from 'graphql';
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.js';
import { ApolloServer } from 'apollo-server-express';
import type { KeystoneConfig, CreateContext, SessionStrategy, GraphQLConfig } from '../../types';
import { createSessionContext } from '../../session';
import { createSessionContext } from '../context/session';
import { createApolloServerExpress } from './createApolloServer';
import { addHealthCheck } from './addHealthCheck';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/scripts/run/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import {
requirePrismaClient,
} from '../../artifacts';
import { ExitError, getAdminPath, getBuiltConfigPath } from '../utils';
import { createSessionContext } from '../../session';
import { AdminMetaRootVal, CreateContext, KeystoneConfig } from '../../types';
import { initialiseLists } from '../../lib/core/types-for-lists';
import { printPrismaSchema } from '../../lib/core/prisma-schema';
import { createSessionContext } from '../../lib/context/session';

const devLoadingHTMLFilepath = path.join(
path.dirname(require.resolve('@keystone-6/core/package.json')),
Expand Down
25 changes: 1 addition & 24 deletions packages/core/src/session/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { IncomingMessage, ServerResponse } from 'http';
import * as cookie from 'cookie';
import Iron from '@hapi/iron';
// uid-safe is what express-session uses so let's just use it
import { sync as uid } from 'uid-safe';
import {
SessionStrategy,
JSONValue,
SessionStoreFunction,
SessionContext,
CreateContext,
} from '../types';
import { SessionStrategy, JSONValue, SessionStoreFunction } from '../types';

function generateSessionId() {
return uid(24);
Expand Down Expand Up @@ -177,19 +170,3 @@ export function storedSessions({
},
};
}

/**
* This is the function createSystem uses to implement the session strategy provided
*/
export async function createSessionContext<T>(
sessionStrategy: SessionStrategy<T>,
req: IncomingMessage,
res: ServerResponse,
createContext: CreateContext
): Promise<SessionContext<T>> {
return {
session: await sessionStrategy.get({ req, createContext }),
startSession: (data: T) => sessionStrategy.start({ res, data, createContext }),
endSession: () => sessionStrategy.end({ req, res, createContext }),
};
}

0 comments on commit 31721b5

Please sign in to comment.