Skip to content

Commit

Permalink
chore(server): change default exports to named ones for compatibility (
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Mar 31, 2024
1 parent f8700cd commit ee3c716
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
},
"exports": {
"./package.json": "./package.json",
"./api": "./api/index.js",
"./api/rest": "./api/rest/index.js",
"./api/rpc": "./api/rpc/index.js",
"./express": "./express/index.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { RPCApiHandler } from './rpc';
export { RestApiHandler } from './rest';
2 changes: 2 additions & 0 deletions packages/server/src/api/rest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1664,3 +1664,5 @@ export default function makeHandler(options: Options) {
const handler = new RequestHandler(options);
return handler.handleRequest.bind(handler);
}

export { makeHandler as RestApiHandler };
2 changes: 2 additions & 0 deletions packages/server/src/api/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,5 @@ export default function makeHandler() {
const handler = new RequestHandler();
return handler.handleRequest.bind(handler);
}

export { makeHandler as RPCApiHandler };
2 changes: 1 addition & 1 deletion packages/server/src/express/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as ZenStackMiddleware } from './middleware';
export { ZenStackMiddleware } from './middleware';
export * from './middleware';
6 changes: 4 additions & 2 deletions packages/server/src/express/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { DbClientContract } from '@zenstackhq/runtime';
import type { Handler, Request, Response } from 'express';
import RPCAPIHandler from '../api/rpc';
import { RPCApiHandler } from '../api/rpc';
import { loadAssets } from '../shared';
import { AdapterBaseOptions } from '../types';

Expand Down Expand Up @@ -32,7 +32,7 @@ export interface MiddlewareOptions extends AdapterBaseOptions {
const factory = (options: MiddlewareOptions): Handler => {
const { modelMeta, zodSchemas } = loadAssets(options);

const requestHandler = options.handler || RPCAPIHandler();
const requestHandler = options.handler || RPCApiHandler();

return async (request, response, next) => {
const prisma = (await options.getPrisma(request, response)) as DbClientContract;
Expand Down Expand Up @@ -83,3 +83,5 @@ const factory = (options: MiddlewareOptions): Handler => {
};

export default factory;

export { factory as ZenStackMiddleware };
2 changes: 1 addition & 1 deletion packages/server/src/fastify/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as ZenStackFastifyPlugin } from './plugin';
export { ZenStackFastifyPlugin } from './plugin';
export * from './plugin';
6 changes: 5 additions & 1 deletion packages/server/src/fastify/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ const pluginHandler: FastifyPluginCallback<PluginOptions> = (fastify, options, d
done();
};

export default fp(pluginHandler);
const plugin = fp(pluginHandler);

export default plugin;

export { plugin as ZenStackFastifyPlugin };
4 changes: 2 additions & 2 deletions packages/server/src/next/app-route-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { DbClientContract } from '@zenstackhq/runtime';
import { NextRequest, NextResponse } from 'next/server';
import { AppRouteRequestHandlerOptions } from '.';
import RPCAPIHandler from '../api/rpc';
import { RPCApiHandler } from '../api';
import { loadAssets } from '../shared';

type Context = { params: { path: string[] } };
Expand All @@ -19,7 +19,7 @@ export default function factory(
): (req: NextRequest, context: Context) => Promise<NextResponse> {
const { modelMeta, zodSchemas } = loadAssets(options);

const requestHandler = options.handler || RPCAPIHandler();
const requestHandler = options.handler || RPCApiHandler();

return async (req: NextRequest, context: Context) => {
const prisma = (await options.getPrisma(req)) as DbClientContract;
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/next/pages-route-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { DbClientContract } from '@zenstackhq/runtime';
import { NextApiRequest, NextApiResponse } from 'next';
import { PagesRouteRequestHandlerOptions } from '.';
import RPCAPIHandler from '../api/rpc';
import { RPCApiHandler } from '../api';
import { loadAssets } from '../shared';

/**
Expand All @@ -17,7 +17,7 @@ export default function factory(
): (req: NextApiRequest, res: NextApiResponse) => Promise<void> {
const { modelMeta, zodSchemas } = loadAssets(options);

const requestHandler = options.handler || RPCAPIHandler();
const requestHandler = options.handler || RPCApiHandler();

return async (req: NextApiRequest, res: NextApiResponse) => {
const prisma = (await options.getPrisma(req, res)) as DbClientContract;
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/sveltekit/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ export default function createHandler(options: HandlerOptions): Handle {
return resolve(event);
};
}

export { createHandler as SvelteKitHandler };
2 changes: 1 addition & 1 deletion packages/server/src/sveltekit/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as SvelteKitHandler } from './handler';
export { SvelteKitHandler } from './handler';
export * from './handler';
4 changes: 2 additions & 2 deletions packages/server/tests/api/rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CrudFailureReason, type ZodSchemas } from '@zenstackhq/runtime';
import { loadSchema } from '@zenstackhq/testtools';
import { Decimal } from 'decimal.js';
import SuperJSON from 'superjson';
import RPCAPIHandler from '../../src/api/rpc';
import { RPCApiHandler } from '../../src/api';
import { schema } from '../utils';

describe('RPC API Handler Tests', () => {
Expand Down Expand Up @@ -408,7 +408,7 @@ describe('RPC API Handler Tests', () => {
});

function makeHandler(zodSchemas?: ZodSchemas) {
const _handler = RPCAPIHandler();
const _handler = RPCApiHandler();
return async (args: any) => {
const r = await _handler({ ...args, url: new URL(`http://localhost/${args.path}`), modelMeta, zodSchemas });
return {
Expand Down

0 comments on commit ee3c716

Please sign in to comment.