@zenstackhq/server 2.20.0 → 3.0.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/api.cjs +299 -0
- package/dist/api.cjs.map +1 -0
- package/dist/api.d.cts +28 -0
- package/dist/api.d.ts +28 -0
- package/dist/api.js +264 -0
- package/dist/api.js.map +1 -0
- package/dist/express.cjs +75 -0
- package/dist/express.cjs.map +1 -0
- package/dist/express.d.cts +31 -0
- package/dist/express.d.ts +31 -0
- package/dist/express.js +50 -0
- package/dist/express.js.map +1 -0
- package/dist/types-BH-88xJo.d.cts +68 -0
- package/dist/types-BH-88xJo.d.ts +68 -0
- package/package.json +57 -58
- package/README.md +0 -5
- package/api/base.d.ts +0 -49
- package/api/base.js +0 -19
- package/api/base.js.map +0 -1
- package/api/index.d.ts +0 -2
- package/api/index.js +0 -8
- package/api/index.js.map +0 -1
- package/api/rest/index.d.ts +0 -34
- package/api/rest/index.js +0 -1598
- package/api/rest/index.js.map +0 -1
- package/api/rpc/index.d.ts +0 -4
- package/api/rpc/index.js +0 -248
- package/api/rpc/index.js.map +0 -1
- package/api/utils.d.ts +0 -8
- package/api/utils.js +0 -54
- package/api/utils.js.map +0 -1
- package/elysia/handler.d.ts +0 -44
- package/elysia/handler.js +0 -62
- package/elysia/handler.js.map +0 -1
- package/elysia/index.d.ts +0 -1
- package/elysia/index.js +0 -18
- package/elysia/index.js.map +0 -1
- package/express/index.d.ts +0 -2
- package/express/index.js +0 -21
- package/express/index.js.map +0 -1
- package/express/middleware.d.ts +0 -27
- package/express/middleware.js +0 -58
- package/express/middleware.js.map +0 -1
- package/fastify/index.d.ts +0 -2
- package/fastify/index.js +0 -21
- package/fastify/index.js.map +0 -1
- package/fastify/plugin.d.ts +0 -18
- package/fastify/plugin.js +0 -48
- package/fastify/plugin.js.map +0 -1
- package/hono/handler.d.ts +0 -12
- package/hono/handler.js +0 -47
- package/hono/handler.js.map +0 -1
- package/hono/index.d.ts +0 -1
- package/hono/index.js +0 -18
- package/hono/index.js.map +0 -1
- package/nestjs/api-handler.service.d.ts +0 -15
- package/nestjs/api-handler.service.js +0 -72
- package/nestjs/api-handler.service.js.map +0 -1
- package/nestjs/index.d.ts +0 -3
- package/nestjs/index.js +0 -20
- package/nestjs/index.js.map +0 -1
- package/nestjs/interfaces/api-handler-options.interface.d.ts +0 -17
- package/nestjs/interfaces/api-handler-options.interface.js +0 -3
- package/nestjs/interfaces/api-handler-options.interface.js.map +0 -1
- package/nestjs/interfaces/index.d.ts +0 -2
- package/nestjs/interfaces/index.js +0 -19
- package/nestjs/interfaces/index.js.map +0 -1
- package/nestjs/interfaces/zenstack-module-options.interface.d.ts +0 -35
- package/nestjs/interfaces/zenstack-module-options.interface.js +0 -3
- package/nestjs/interfaces/zenstack-module-options.interface.js.map +0 -1
- package/nestjs/zenstack.constants.d.ts +0 -4
- package/nestjs/zenstack.constants.js +0 -8
- package/nestjs/zenstack.constants.js.map +0 -1
- package/nestjs/zenstack.module.d.ts +0 -12
- package/nestjs/zenstack.module.js +0 -61
- package/nestjs/zenstack.module.js.map +0 -1
- package/next/app-route-handler.d.ts +0 -16
- package/next/app-route-handler.js +0 -65
- package/next/app-route-handler.js.map +0 -1
- package/next/index.d.ts +0 -38
- package/next/index.js +0 -17
- package/next/index.js.map +0 -1
- package/next/pages-route-handler.d.ts +0 -9
- package/next/pages-route-handler.js +0 -45
- package/next/pages-route-handler.js.map +0 -1
- package/nuxt/handler.d.ts +0 -12
- package/nuxt/handler.js +0 -45
- package/nuxt/handler.js.map +0 -1
- package/nuxt/index.d.ts +0 -1
- package/nuxt/index.js +0 -18
- package/nuxt/index.js.map +0 -1
- package/shared.d.ts +0 -20
- package/shared.js +0 -50
- package/shared.js.map +0 -1
- package/sveltekit/handler.d.ts +0 -20
- package/sveltekit/handler.js +0 -68
- package/sveltekit/handler.js.map +0 -1
- package/sveltekit/index.d.ts +0 -2
- package/sveltekit/index.js +0 -21
- package/sveltekit/index.js.map +0 -1
- package/tanstack-start/handler.d.ts +0 -11
- package/tanstack-start/handler.js +0 -75
- package/tanstack-start/handler.js.map +0 -1
- package/tanstack-start/index.d.ts +0 -17
- package/tanstack-start/index.js +0 -16
- package/tanstack-start/index.js.map +0 -1
- package/types.d.ts +0 -49
- package/types.js +0 -3
- package/types.js.map +0 -1
package/express/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/express/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAkD;AAAzC,gHAAA,kBAAkB,OAAA;AAC3B,+CAA6B"}
|
package/express/middleware.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Handler, Request, Response } from 'express';
|
|
2
|
-
import { AdapterBaseOptions } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Express middleware options
|
|
5
|
-
*/
|
|
6
|
-
export interface MiddlewareOptions extends AdapterBaseOptions {
|
|
7
|
-
/**
|
|
8
|
-
* Callback for getting a PrismaClient for the given request
|
|
9
|
-
*/
|
|
10
|
-
getPrisma: (req: Request, res: Response) => unknown | Promise<unknown>;
|
|
11
|
-
/**
|
|
12
|
-
* Controls if the middleware directly sends a response. If set to false,
|
|
13
|
-
* the response is stored in the `res.locals` object and then the middleware
|
|
14
|
-
* calls the `next()` function to pass the control to the next middleware.
|
|
15
|
-
* Subsequent middleware or request handlers need to make sure to send
|
|
16
|
-
* a response.
|
|
17
|
-
*
|
|
18
|
-
* Defaults to true;
|
|
19
|
-
*/
|
|
20
|
-
sendResponse?: boolean;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Creates an Express middleware for handling CRUD requests.
|
|
24
|
-
*/
|
|
25
|
-
declare const factory: (options: MiddlewareOptions) => Handler;
|
|
26
|
-
export default factory;
|
|
27
|
-
export { factory as ZenStackMiddleware };
|
package/express/middleware.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ZenStackMiddleware = void 0;
|
|
4
|
-
const rpc_1 = require("../api/rpc");
|
|
5
|
-
const shared_1 = require("../shared");
|
|
6
|
-
/**
|
|
7
|
-
* Creates an Express middleware for handling CRUD requests.
|
|
8
|
-
*/
|
|
9
|
-
const factory = (options) => {
|
|
10
|
-
const { modelMeta, zodSchemas } = (0, shared_1.loadAssets)(options);
|
|
11
|
-
const requestHandler = options.handler || (0, rpc_1.RPCApiHandler)();
|
|
12
|
-
return async (request, response, next) => {
|
|
13
|
-
const prisma = (await options.getPrisma(request, response));
|
|
14
|
-
const { sendResponse } = options;
|
|
15
|
-
if (sendResponse === false && !prisma) {
|
|
16
|
-
throw new Error('unable to get prisma from request context');
|
|
17
|
-
}
|
|
18
|
-
if (!prisma) {
|
|
19
|
-
return response.status(500).json({ message: 'unable to get prisma from request context' });
|
|
20
|
-
}
|
|
21
|
-
// express converts query parameters with square brackets into object
|
|
22
|
-
// e.g.: filter[foo]=bar is parsed to { filter: { foo: 'bar' } }
|
|
23
|
-
// we need to revert this behavior and reconstruct params from original URL
|
|
24
|
-
const url = request.protocol + '://' + request.get('host') + request.originalUrl;
|
|
25
|
-
const searchParams = new URL(url).searchParams;
|
|
26
|
-
const query = Object.fromEntries(searchParams);
|
|
27
|
-
try {
|
|
28
|
-
const r = await requestHandler({
|
|
29
|
-
method: request.method,
|
|
30
|
-
path: request.path,
|
|
31
|
-
query,
|
|
32
|
-
requestBody: request.body,
|
|
33
|
-
prisma,
|
|
34
|
-
modelMeta,
|
|
35
|
-
zodSchemas,
|
|
36
|
-
logger: options.logger,
|
|
37
|
-
});
|
|
38
|
-
if (sendResponse === false) {
|
|
39
|
-
// attach response and pass control to the next middleware
|
|
40
|
-
response.locals = {
|
|
41
|
-
status: r.status,
|
|
42
|
-
body: r.body,
|
|
43
|
-
};
|
|
44
|
-
return next();
|
|
45
|
-
}
|
|
46
|
-
return response.status(r.status).json(r.body);
|
|
47
|
-
}
|
|
48
|
-
catch (err) {
|
|
49
|
-
if (sendResponse === false) {
|
|
50
|
-
throw err;
|
|
51
|
-
}
|
|
52
|
-
return response.status(500).json({ message: `An unhandled error occurred: ${err}` });
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
exports.ZenStackMiddleware = factory;
|
|
57
|
-
exports.default = factory;
|
|
58
|
-
//# sourceMappingURL=middleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/express/middleware.ts"],"names":[],"mappings":";;;AAGA,oCAA2C;AAC3C,sCAAuC;AAwBvC;;GAEG;AACH,MAAM,OAAO,GAAG,CAAC,OAA0B,EAAW,EAAE;IACpD,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,IAAA,mBAAU,EAAC,OAAO,CAAC,CAAC;IAEtD,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,IAAI,IAAA,mBAAa,GAAE,CAAC;IAE1D,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,CAAC,MAAM,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAqB,CAAC;QAChF,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;QAEjC,IAAI,YAAY,KAAK,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QACjE,CAAC;QAED,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAO,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,2CAA2C,EAAE,CAAC,CAAC;QAC/F,CAAC;QAED,qEAAqE;QACrE,gEAAgE;QAChE,2EAA2E;QAC3E,MAAM,GAAG,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-1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.ZenStackFastifyPlugin = void 0;
|
|
18
|
-
var plugin_1 = require("./plugin");
|
|
19
|
-
Object.defineProperty(exports, "ZenStackFastifyPlugin", { enumerable: true, get: function () { return plugin_1.ZenStackFastifyPlugin; } });
|
|
20
|
-
__exportStar(require("./plugin"), exports);
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
package/fastify/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fastify/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAiD;AAAxC,+GAAA,qBAAqB,OAAA;AAC9B,2CAAyB"}
|
package/fastify/plugin.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { FastifyPluginCallback, FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
-
import { AdapterBaseOptions } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Fastify plugin options
|
|
5
|
-
*/
|
|
6
|
-
export interface PluginOptions extends AdapterBaseOptions {
|
|
7
|
-
/**
|
|
8
|
-
* Url prefix, e.g.: /api
|
|
9
|
-
*/
|
|
10
|
-
prefix: string;
|
|
11
|
-
/**
|
|
12
|
-
* Callback for getting a PrismaClient for the given request
|
|
13
|
-
*/
|
|
14
|
-
getPrisma: (request: FastifyRequest, reply: FastifyReply) => unknown | Promise<unknown>;
|
|
15
|
-
}
|
|
16
|
-
declare const plugin: FastifyPluginCallback<PluginOptions>;
|
|
17
|
-
export default plugin;
|
|
18
|
-
export { plugin as ZenStackFastifyPlugin };
|
package/fastify/plugin.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ZenStackFastifyPlugin = void 0;
|
|
7
|
-
const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
|
|
8
|
-
const rpc_1 = __importDefault(require("../api/rpc"));
|
|
9
|
-
const utils_1 = require("../api/utils");
|
|
10
|
-
const shared_1 = require("../shared");
|
|
11
|
-
/**
|
|
12
|
-
* Fastify plugin for handling CRUD requests.
|
|
13
|
-
*/
|
|
14
|
-
const pluginHandler = (fastify, options, done) => {
|
|
15
|
-
const prefix = options.prefix ?? '';
|
|
16
|
-
(0, utils_1.logInfo)(options.logger, `ZenStackPlugin installing routes at prefix: ${prefix}`);
|
|
17
|
-
const { modelMeta, zodSchemas } = (0, shared_1.loadAssets)(options);
|
|
18
|
-
const requestHandler = options.handler ?? (0, rpc_1.default)();
|
|
19
|
-
fastify.all(`${prefix}/*`, async (request, reply) => {
|
|
20
|
-
const prisma = (await options.getPrisma(request, reply));
|
|
21
|
-
if (!prisma) {
|
|
22
|
-
reply.status(500).send({ message: 'unable to get prisma from request context' });
|
|
23
|
-
return reply;
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
const response = await requestHandler({
|
|
27
|
-
method: request.method,
|
|
28
|
-
path: request.params['*'],
|
|
29
|
-
query: request.query,
|
|
30
|
-
requestBody: request.body,
|
|
31
|
-
prisma,
|
|
32
|
-
modelMeta,
|
|
33
|
-
zodSchemas,
|
|
34
|
-
logger: options.logger,
|
|
35
|
-
});
|
|
36
|
-
reply.status(response.status).send(response.body);
|
|
37
|
-
}
|
|
38
|
-
catch (err) {
|
|
39
|
-
reply.status(500).send({ message: `An unhandled error occurred: ${err}` });
|
|
40
|
-
}
|
|
41
|
-
return reply;
|
|
42
|
-
});
|
|
43
|
-
done();
|
|
44
|
-
};
|
|
45
|
-
const plugin = (0, fastify_plugin_1.default)(pluginHandler);
|
|
46
|
-
exports.ZenStackFastifyPlugin = plugin;
|
|
47
|
-
exports.default = plugin;
|
|
48
|
-
//# sourceMappingURL=plugin.js.map
|
package/fastify/plugin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/fastify/plugin.ts"],"names":[],"mappings":";;;;;;AAGA,oEAAgC;AAChC,qDAAuC;AACvC,wCAAuC;AACvC,sCAAuC;AAkBvC;;GAEG;AACH,MAAM,aAAa,GAAyC,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IACnF,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;IACpC,IAAA,eAAO,EAAC,OAAO,CAAC,MAAM,EAAE,+CAA+C,MAAM,EAAE,CAAC,CAAC;IAEjF,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,IAAA,mBAAU,EAAC,OAAO,CAAC,CAAC;IAEtD,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,IAAI,IAAA,aAAa,GAAE,CAAC;IAE1D,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;QAChD,MAAM,MAAM,GAAG,CAAC,MAAM,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,CAAqB,CAAC;QAC7E,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,2CAA2C,EAAE,CAAC,CAAC;YACjF,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,IAAI,CAAC;YACD,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC;gBAClC,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,IAAI,EAAG,OAAO,CAAC,MAAc,CAAC,GAAG,CAAC;gBAClC,KAAK,EAAE,OAAO,CAAC,KAA0C;gBACzD,WAAW,EAAE,OAAO,CAAC,IAAI;gBACzB,MAAM;gBACN,SAAS;gBACT,UAAU;gBACV,MAAM,EAAE,OAAO,CAAC,MAAM;aACzB,CAAC,CAAC;YACH,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,gCAAgC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC/E,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,IAAI,EAAE,CAAC;AACX,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,IAAA,wBAAE,EAAC,aAAa,CAAC,CAAC;AAId,uCAAqB;AAFxC,kBAAe,MAAM,CAAC"}
|
package/hono/handler.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Context, MiddlewareHandler } from 'hono';
|
|
2
|
-
import { AdapterBaseOptions } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Options for initializing a Hono middleware.
|
|
5
|
-
*/
|
|
6
|
-
export interface HonoOptions extends AdapterBaseOptions {
|
|
7
|
-
/**
|
|
8
|
-
* Callback method for getting a Prisma instance for the given request.
|
|
9
|
-
*/
|
|
10
|
-
getPrisma: (ctx: Context) => Promise<unknown> | unknown;
|
|
11
|
-
}
|
|
12
|
-
export declare function createHonoHandler(options: HonoOptions): MiddlewareHandler;
|
package/hono/handler.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createHonoHandler = createHonoHandler;
|
|
4
|
-
const api_1 = require("../api");
|
|
5
|
-
const shared_1 = require("../shared");
|
|
6
|
-
function createHonoHandler(options) {
|
|
7
|
-
const { modelMeta, zodSchemas } = (0, shared_1.loadAssets)(options);
|
|
8
|
-
const requestHandler = options.handler ?? (0, api_1.RPCApiHandler)();
|
|
9
|
-
return async (ctx) => {
|
|
10
|
-
const prisma = (await options.getPrisma(ctx));
|
|
11
|
-
if (!prisma) {
|
|
12
|
-
return ctx.json({ message: 'unable to get prisma from request context' }, 500);
|
|
13
|
-
}
|
|
14
|
-
const url = new URL(ctx.req.url);
|
|
15
|
-
const query = Object.fromEntries(url.searchParams);
|
|
16
|
-
const path = ctx.req.path.substring(ctx.req.routePath.length - 1);
|
|
17
|
-
if (!path) {
|
|
18
|
-
return ctx.json({ message: 'missing path parameter' }, 400);
|
|
19
|
-
}
|
|
20
|
-
let requestBody;
|
|
21
|
-
if (ctx.req.raw.body) {
|
|
22
|
-
try {
|
|
23
|
-
requestBody = await ctx.req.json();
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
// noop
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
try {
|
|
30
|
-
const r = await requestHandler({
|
|
31
|
-
method: ctx.req.method,
|
|
32
|
-
path,
|
|
33
|
-
query,
|
|
34
|
-
requestBody,
|
|
35
|
-
prisma,
|
|
36
|
-
modelMeta,
|
|
37
|
-
zodSchemas,
|
|
38
|
-
logger: options.logger,
|
|
39
|
-
});
|
|
40
|
-
return ctx.json(r.body, r.status);
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
return ctx.json({ message: `An unhandled error occurred: ${err}` }, 500);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=handler.js.map
|
package/hono/handler.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/hono/handler.ts"],"names":[],"mappings":";;AAiBA,8CA4CC;AA1DD,gCAAuC;AACvC,sCAAuC;AAavC,SAAgB,iBAAiB,CAAC,OAAoB;IAClD,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,IAAA,mBAAU,EAAC,OAAO,CAAC,CAAC;IACtD,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,IAAI,IAAA,mBAAa,GAAE,CAAC;IAE1D,OAAO,KAAK,EAAE,GAAG,EAAE,EAAE;QACjB,MAAM,MAAM,GAAG,CAAC,MAAM,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAqB,CAAC;QAClE,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,2CAA2C,EAAE,EAAE,GAAG,CAAC,CAAC;QACnF,CAAC;QAED,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjC,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAEnD,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAElE,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,EAAE,GAAG,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,WAAoB,CAAC;QACzB,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YACnB,IAAI,CAAC;gBACD,WAAW,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YACvC,CAAC;YAAC,MAAM,CAAC;gBACL,OAAO;YACX,CAAC;QACL,CAAC;QAED,IAAI,CAAC;YACD,MAAM,CAAC,GAAG,MAAM,cAAc,CAAC;gBAC3B,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM;gBACtB,IAAI;gBACJ,KAAK;gBACL,WAAW;gBACX,MAAM;gBACN,SAAS;gBACT,UAAU;gBACV,MAAM,EAAE,OAAO,CAAC,MAAM;aACzB,CAAC,CAAC;YACH,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAc,EAAE,CAAC,CAAC,MAAoB,CAAC,CAAC;QAC9D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,gCAAgC,GAAG,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;QAC7E,CAAC;IACL,CAAC,CAAC;AACN,CAAC"}
|
package/hono/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './handler';
|
package/hono/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./handler"), exports);
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
package/hono/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hono/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { DbClientContract } from '@zenstackhq/runtime';
|
|
2
|
-
import { HttpAdapterHost } from "@nestjs/core";
|
|
3
|
-
import { ApiHandlerOptions } from './interfaces';
|
|
4
|
-
/**
|
|
5
|
-
* The ZenStack API handler service for NestJS. The service is used to handle API requests
|
|
6
|
-
* and forward them to the ZenStack API handler. It is platform agnostic and can be used
|
|
7
|
-
* with any HTTP adapter.
|
|
8
|
-
*/
|
|
9
|
-
export declare class ApiHandlerService {
|
|
10
|
-
private readonly httpAdapterHost;
|
|
11
|
-
private readonly prisma;
|
|
12
|
-
private readonly request;
|
|
13
|
-
constructor(httpAdapterHost: HttpAdapterHost, prisma: DbClientContract, request: unknown);
|
|
14
|
-
handleRequest(options?: ApiHandlerOptions): Promise<unknown>;
|
|
15
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.ApiHandlerService = void 0;
|
|
16
|
-
const common_1 = require("@nestjs/common");
|
|
17
|
-
const core_1 = require("@nestjs/core");
|
|
18
|
-
const shared_1 = require("../shared");
|
|
19
|
-
const rpc_1 = require("../api/rpc");
|
|
20
|
-
const zenstack_constants_1 = require("./zenstack.constants");
|
|
21
|
-
/**
|
|
22
|
-
* The ZenStack API handler service for NestJS. The service is used to handle API requests
|
|
23
|
-
* and forward them to the ZenStack API handler. It is platform agnostic and can be used
|
|
24
|
-
* with any HTTP adapter.
|
|
25
|
-
*/
|
|
26
|
-
let ApiHandlerService = class ApiHandlerService {
|
|
27
|
-
constructor(httpAdapterHost, prisma, request) {
|
|
28
|
-
this.httpAdapterHost = httpAdapterHost;
|
|
29
|
-
this.prisma = prisma;
|
|
30
|
-
this.request = request;
|
|
31
|
-
}
|
|
32
|
-
async handleRequest(options) {
|
|
33
|
-
const { modelMeta, zodSchemas } = (0, shared_1.loadAssets)(options || {});
|
|
34
|
-
const requestHandler = options?.handler || (0, rpc_1.RPCApiHandler)();
|
|
35
|
-
const hostname = this.httpAdapterHost.httpAdapter.getRequestHostname(this.request);
|
|
36
|
-
const requestUrl = this.httpAdapterHost.httpAdapter.getRequestUrl(this.request);
|
|
37
|
-
// prefix with http:// to make a valid url accepted by URL constructor
|
|
38
|
-
const url = new URL(`http://${hostname}${requestUrl}`);
|
|
39
|
-
const method = this.httpAdapterHost.httpAdapter.getRequestMethod(this.request);
|
|
40
|
-
const path = options?.baseUrl && url.pathname.startsWith(options.baseUrl) ? url.pathname.slice(options.baseUrl.length) : url.pathname;
|
|
41
|
-
const searchParams = url.searchParams;
|
|
42
|
-
const query = Object.fromEntries(searchParams);
|
|
43
|
-
const requestBody = this.request.body;
|
|
44
|
-
const response = await requestHandler({
|
|
45
|
-
method,
|
|
46
|
-
path,
|
|
47
|
-
query,
|
|
48
|
-
requestBody,
|
|
49
|
-
prisma: this.prisma,
|
|
50
|
-
modelMeta,
|
|
51
|
-
zodSchemas,
|
|
52
|
-
logger: options?.logger,
|
|
53
|
-
});
|
|
54
|
-
// handle handler error
|
|
55
|
-
// if response code >= 400 throw nestjs HttpException
|
|
56
|
-
// the error response will be generated by nestjs
|
|
57
|
-
// caller can use try/catch to deal with this manually also
|
|
58
|
-
if (response.status >= 400) {
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
-
throw new common_1.HttpException(response.body, response.status);
|
|
61
|
-
}
|
|
62
|
-
return response.body;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
exports.ApiHandlerService = ApiHandlerService;
|
|
66
|
-
exports.ApiHandlerService = ApiHandlerService = __decorate([
|
|
67
|
-
(0, common_1.Injectable)({ scope: common_1.Scope.REQUEST }),
|
|
68
|
-
__param(1, (0, common_1.Inject)(zenstack_constants_1.ENHANCED_PRISMA)),
|
|
69
|
-
__param(2, (0, common_1.Inject)(core_1.REQUEST)),
|
|
70
|
-
__metadata("design:paramtypes", [core_1.HttpAdapterHost, Object, Object])
|
|
71
|
-
], ApiHandlerService);
|
|
72
|
-
//# sourceMappingURL=api-handler.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|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AAC,QAAQ,CAAC;QACtI,MAAM,YAAY,GAAG,GAAG,CAAC,YAAY,CAAC;QACtC,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QAC/C,MAAM,WAAW,GAAI,IAAI,CAAC,OAA6B,CAAC,IAAI,CAAC;QAE7D,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC;YAClC,MAAM;YACN,IAAI;YACJ,KAAK;YACL,WAAW;YACX,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,SAAS;YACT,UAAU;YACV,MAAM,EAAE,OAAO,EAAE,MAAM;SAC1B,CAAC,CAAC;QAEH,uBAAuB;QACvB,qDAAqD;QACrD,iDAAiD;QACjD,2DAA2D;QAC3D,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;YACzB,8DAA8D;YAC9D,MAAM,IAAI,sBAAa,CAAC,QAAQ,CAAC,IAA2B,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;QAClF,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,CAAA;IACxB,CAAC;CACJ,CAAA;AAzCY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,OAAO,EAAE,CAAC;IAI5B,WAAA,IAAA,eAAM,EAAC,oCAAe,CAAC,CAAA;IACvB,WAAA,IAAA,eAAM,EAAC,cAAO,CAAC,CAAA;qCAFkB,sBAAe;GAF5C,iBAAiB,CAyC7B"}
|
package/nestjs/index.d.ts
DELETED
package/nestjs/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./zenstack.module"), exports);
|
|
18
|
-
__exportStar(require("./api-handler.service"), exports);
|
|
19
|
-
__exportStar(require("./zenstack.constants"), exports);
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
package/nestjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nestjs/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,wDAAsC;AACtC,uDAAqC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { AdapterBaseOptions } from "../../types";
|
|
2
|
-
export interface ApiHandlerOptions extends AdapterBaseOptions {
|
|
3
|
-
/**
|
|
4
|
-
* The base URL for the API handler. This is used to determine the base path for the API requests.
|
|
5
|
-
* If you are using the ApiHandlerService in a route with a prefix, you should set this to the prefix.
|
|
6
|
-
*
|
|
7
|
-
* e.g.
|
|
8
|
-
* without baseUrl(API handler default route):
|
|
9
|
-
* - RPC API handler: [model]/findMany
|
|
10
|
-
* - RESTful API handler: /:type
|
|
11
|
-
*
|
|
12
|
-
* with baseUrl(/api/crud):
|
|
13
|
-
* - RPC API handler: /api/crud/[model]/findMany
|
|
14
|
-
* - RESTful API handler: /api/crud/:type
|
|
15
|
-
*/
|
|
16
|
-
baseUrl?: string;
|
|
17
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api-handler-options.interface.js","sourceRoot":"","sources":["../../../src/nestjs/interfaces/api-handler-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./zenstack-module-options.interface"), exports);
|
|
18
|
-
__exportStar(require("./api-handler-options.interface"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/nestjs/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sEAAmD;AACnD,kEAA+C"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { FactoryProvider, ModuleMetadata, Provider } from "@nestjs/common";
|
|
2
|
-
/**
|
|
3
|
-
* ZenStack module options.
|
|
4
|
-
*/
|
|
5
|
-
export interface ZenStackModuleOptions {
|
|
6
|
-
/**
|
|
7
|
-
* A callback for getting an enhanced `PrismaClient`.
|
|
8
|
-
*/
|
|
9
|
-
getEnhancedPrisma: (model?: string | symbol) => unknown;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* ZenStack module async registration options.
|
|
13
|
-
*/
|
|
14
|
-
export interface ZenStackModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
15
|
-
/**
|
|
16
|
-
* Whether the module is global-scoped.
|
|
17
|
-
*/
|
|
18
|
-
global?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* The token to export the enhanced Prisma service. Default is {@link ENHANCED_PRISMA}.
|
|
21
|
-
*/
|
|
22
|
-
exportToken?: string;
|
|
23
|
-
/**
|
|
24
|
-
* The factory function to create the enhancement options.
|
|
25
|
-
*/
|
|
26
|
-
useFactory: (...args: unknown[]) => Promise<ZenStackModuleOptions> | ZenStackModuleOptions;
|
|
27
|
-
/**
|
|
28
|
-
* The dependencies to inject into the factory function.
|
|
29
|
-
*/
|
|
30
|
-
inject?: FactoryProvider['inject'];
|
|
31
|
-
/**
|
|
32
|
-
* Extra providers to facilitate dependency injection.
|
|
33
|
-
*/
|
|
34
|
-
extraProviders?: Provider[];
|
|
35
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zenstack-module-options.interface.js","sourceRoot":"","sources":["../../../src/nestjs/interfaces/zenstack-module-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ENHANCED_PRISMA = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* The default token used to export the enhanced Prisma service.
|
|
6
|
-
*/
|
|
7
|
-
exports.ENHANCED_PRISMA = 'ENHANCED_PRISMA';
|
|
8
|
-
//# sourceMappingURL=zenstack.constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zenstack.constants.js","sourceRoot":"","sources":["../../src/nestjs/zenstack.constants.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,eAAe,GAAG,iBAAiB,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type DynamicModule } from '@nestjs/common';
|
|
2
|
-
import { ZenStackModuleAsyncOptions } from './interfaces';
|
|
3
|
-
/**
|
|
4
|
-
* The ZenStack module for NestJS. The module exports an enhanced Prisma service,
|
|
5
|
-
* by default with token {@link ENHANCED_PRISMA}.
|
|
6
|
-
*/
|
|
7
|
-
export declare class ZenStackModule {
|
|
8
|
-
/**
|
|
9
|
-
* Registers the ZenStack module with the specified options.
|
|
10
|
-
*/
|
|
11
|
-
static registerAsync(options: ZenStackModuleAsyncOptions): DynamicModule;
|
|
12
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var ZenStackModule_1;
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.ZenStackModule = void 0;
|
|
11
|
-
const common_1 = require("@nestjs/common");
|
|
12
|
-
const zenstack_constants_1 = require("./zenstack.constants");
|
|
13
|
-
/**
|
|
14
|
-
* The ZenStack module for NestJS. The module exports an enhanced Prisma service,
|
|
15
|
-
* by default with token {@link ENHANCED_PRISMA}.
|
|
16
|
-
*/
|
|
17
|
-
let ZenStackModule = ZenStackModule_1 = class ZenStackModule {
|
|
18
|
-
/**
|
|
19
|
-
* Registers the ZenStack module with the specified options.
|
|
20
|
-
*/
|
|
21
|
-
static registerAsync(options) {
|
|
22
|
-
return {
|
|
23
|
-
module: ZenStackModule_1,
|
|
24
|
-
global: options?.global,
|
|
25
|
-
imports: options.imports,
|
|
26
|
-
providers: [
|
|
27
|
-
{
|
|
28
|
-
provide: options.exportToken ?? zenstack_constants_1.ENHANCED_PRISMA,
|
|
29
|
-
useFactory: async (
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
-
...args) => {
|
|
32
|
-
const { getEnhancedPrisma } = await options.useFactory(...args);
|
|
33
|
-
if (!getEnhancedPrisma) {
|
|
34
|
-
throw new Error('`getEnhancedPrisma` must be provided in the options');
|
|
35
|
-
}
|
|
36
|
-
// create a proxy to intercept all calls to the Prisma service and forward
|
|
37
|
-
// to the enhanced version
|
|
38
|
-
return new Proxy({}, {
|
|
39
|
-
get(_target, prop) {
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
-
const enhancedPrisma = getEnhancedPrisma(prop);
|
|
42
|
-
if (!enhancedPrisma) {
|
|
43
|
-
throw new Error('`getEnhancedPrisma` must return a valid Prisma client');
|
|
44
|
-
}
|
|
45
|
-
return enhancedPrisma[prop];
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
inject: options.inject,
|
|
50
|
-
},
|
|
51
|
-
...(options.extraProviders ?? []),
|
|
52
|
-
],
|
|
53
|
-
exports: [options.exportToken ?? zenstack_constants_1.ENHANCED_PRISMA],
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
exports.ZenStackModule = ZenStackModule;
|
|
58
|
-
exports.ZenStackModule = ZenStackModule = ZenStackModule_1 = __decorate([
|
|
59
|
-
(0, common_1.Module)({})
|
|
60
|
-
], ZenStackModule);
|
|
61
|
-
//# sourceMappingURL=zenstack.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zenstack.module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Y,wCAAc;yBAAd,cAAc;IAD1B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,cAAc,CA6C1B"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { AppRouteRequestHandlerOptions } from '.';
|
|
3
|
-
type Context = {
|
|
4
|
-
params: Promise<{
|
|
5
|
-
path: string[];
|
|
6
|
-
}>;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Creates a Next.js "app dir" API route request handler which encapsulates Prisma CRUD operations.
|
|
10
|
-
*
|
|
11
|
-
* @remarks Since Next.js 15, `context.params` is asynchronous and must be awaited.
|
|
12
|
-
* @param options Options for initialization
|
|
13
|
-
* @returns An API route request handler
|
|
14
|
-
*/
|
|
15
|
-
export default function factory(options: AppRouteRequestHandlerOptions): (req: NextRequest, context: Context) => Promise<NextResponse>;
|
|
16
|
-
export {};
|