From 2c6f346d2d6851401e33fff502ef5719a2ac9919 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 19 Jan 2025 16:12:40 +0800 Subject: [PATCH] fix: remove unused dependencies --- __snapshots__/index.test.ts.js | 9 +++++++++ package.json | 3 +-- src/index.ts | 8 ++++---- test/index.test.ts | 11 +++++++++++ 4 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 __snapshots__/index.test.ts.js create mode 100644 test/index.test.ts diff --git a/__snapshots__/index.test.ts.js b/__snapshots__/index.test.ts.js new file mode 100644 index 0000000..6b9c1e0 --- /dev/null +++ b/__snapshots__/index.test.ts.js @@ -0,0 +1,9 @@ +exports['test/index.test.ts SessionOptions schema should have a valid schema 1'] = { + "key": "koa.sess", + "autoCommit": true, + "overwrite": true, + "httpOnly": true, + "signed": true, + "rolling": false, + "renew": false +} diff --git a/package.json b/package.json index eea068b..c92a61c 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "koa": "2", "mm": "4", "rimraf": "6", + "snap-shot-it": "^7.9.10", "tshy": "3", "tshy-after": "1", "typescript": "5" @@ -33,9 +34,7 @@ "license": "MIT", "dependencies": { "crc": "^3.8.0", - "debug": "^4.3.3", "is-type-of": "^2.2.0", - "uuid": "^8.3.2", "zod": "^3.24.1" }, "engines": { diff --git a/src/index.ts b/src/index.ts index 0652ffe..e116660 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,7 @@ const debug = debuglog('koa-session'); const GET_CONTEXT_SESSION = Symbol('get contextSession'); const CONTEXT_SESSION_INSTANCE = Symbol('contextSession instance'); -const SessionOptionsSchema = z.object({ +export const SessionOptions = z.object({ /** * cookie key * Default is `koa.sess` @@ -159,9 +159,9 @@ const SessionOptionsSchema = z.object({ .optional(), }); -const DEFAULT_SESSION_OPTIONS = SessionOptionsSchema.parse({}); +const DEFAULT_SESSION_OPTIONS = SessionOptions.parse({}); -export type SessionOptions = z.infer; +export type SessionOptions = z.infer; export type CreateSessionOptions = Partial; type Middleware = (ctx: any, next: any) => Promise; @@ -199,7 +199,7 @@ export function createSession(opts: CreateSessionOptions | any, app: any): Middl ...DEFAULT_SESSION_OPTIONS, ...opts, }; - SessionOptionsSchema.parse(options); + SessionOptions.parse(options); options = formatOptions(options); extendContext(app.context, options); diff --git a/test/index.test.ts b/test/index.test.ts new file mode 100644 index 0000000..3b49ed6 --- /dev/null +++ b/test/index.test.ts @@ -0,0 +1,11 @@ +import snapshot from 'snap-shot-it'; +import { SessionOptions } from '../src/index.js'; + +describe('test/index.test.ts', () => { + describe('SessionOptions schema', () => { + it('should have a valid schema', () => { + const parsed = SessionOptions.parse({}); + snapshot(parsed); + }); + }); +});