@fy-tools/rpc-server-elysia 0.0.119-alpha.10381

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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # rpc-server-elysia
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build rpc-server-elysia` to build the library.
@@ -0,0 +1,5 @@
1
+ export { App } from './lib/app';
2
+ export { Controller } from './lib/controller';
3
+ export { Route } from './lib/route';
4
+ export type { InstanceFromRoute, RouteInputSchema, RouteToContext, } from './lib/types';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,GACf,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Route = exports.Controller = exports.App = void 0;
4
+ var app_1 = require("./lib/app");
5
+ Object.defineProperty(exports, "App", { enumerable: true, get: function () { return app_1.App; } });
6
+ var controller_1 = require("./lib/controller");
7
+ Object.defineProperty(exports, "Controller", { enumerable: true, get: function () { return controller_1.Controller; } });
8
+ var route_1 = require("./lib/route");
9
+ Object.defineProperty(exports, "Route", { enumerable: true, get: function () { return route_1.Route; } });
@@ -0,0 +1,15 @@
1
+ import type { AnyApp, ControllerByFullPath, ControllerFullPath } from '@fy-tools/rpc-server';
2
+ import type { AnyElysia } from 'elysia';
3
+ import { Controller } from './controller';
4
+ export declare class App<App extends AnyElysia, Schema extends AnyApp> {
5
+ _app: App;
6
+ _schema: Schema;
7
+ /**
8
+ * Controllers.
9
+ * @description Map of all controllers in the schema.
10
+ * */
11
+ C: { [key in ControllerFullPath<Schema["_controllers"][number]>]: Controller<App, ControllerByFullPath<Schema["_controllers"][number], key>>; };
12
+ constructor(_app: App, _schema: Schema);
13
+ build<T extends AnyElysia>(fn: (app: App) => T): import("./app").App<T, Schema>;
14
+ }
15
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/lib/app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,GAAG,CAAC,GAAG,SAAS,SAAS,EAAE,MAAM,SAAS,MAAM;IAYxC,IAAI,EAAE,GAAG;IAAS,OAAO,EAAE,MAAM;IAXpD;;;SAGK;IACE,CAAC,EAAS,GACd,GAAG,IAAI,kBAAkB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CACrE,GAAG,EACH,oBAAoB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,CAC1D,GACF,CAAC;gBAEiB,IAAI,EAAE,GAAG,EAAS,OAAO,EAAE,MAAM;IASpD,KAAK,CAAC,CAAC,SAAS,SAAS,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;CAI/C"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.App = void 0;
4
+ const controller_1 = require("./controller");
5
+ class App {
6
+ _app;
7
+ _schema;
8
+ /**
9
+ * Controllers.
10
+ * @description Map of all controllers in the schema.
11
+ * */
12
+ C = {};
13
+ constructor(_app, _schema) {
14
+ this._app = _app;
15
+ this._schema = _schema;
16
+ for (const i in _schema._controllers_map) {
17
+ this.C[i] = new controller_1.Controller(this._app, _schema._controllers[_schema._controllers_map[i]]);
18
+ }
19
+ }
20
+ build(fn) {
21
+ const newApp = fn(this._app);
22
+ return new App(newApp, this._schema);
23
+ }
24
+ }
25
+ exports.App = App;
@@ -0,0 +1,15 @@
1
+ import type { AnyController, RouteByFullPath, RouteFullPath } from '@fy-tools/rpc-server';
2
+ import type { AnyElysia, Elysia } from 'elysia';
3
+ import { Route } from './route';
4
+ export declare class Controller<App extends AnyElysia = Elysia, Schema extends AnyController = AnyController> {
5
+ _app: App;
6
+ _schema: Schema;
7
+ /**
8
+ * Requests.
9
+ * @description Map of all requests in the schema.
10
+ * */
11
+ R: { [key in RouteFullPath<Schema["_routes"][number]>]: Route<App extends Elysia<infer _ extends string, infer Singleton extends import("elysia").SingletonBase, infer Definitions extends import("elysia").DefinitionBase, infer Metadata extends import("elysia").MetadataBase, infer Routes extends import("elysia").RouteBase, infer Ephemeral extends import("elysia").EphemeralType, infer Volatile extends import("elysia").EphemeralType> ? Elysia<Schema["_basePath"], Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile> : never, RouteByFullPath<Schema["_routes"][number], key>>; };
12
+ constructor(_app: App, _schema: Schema);
13
+ build<T extends AnyElysia>(fn: (app: App) => T): Controller<T, Schema>;
14
+ }
15
+ //# sourceMappingURL=controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/lib/controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,aAAa,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAC,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,qBAAa,UAAU,CACrB,GAAG,SAAS,SAAS,GAAG,MAAM,EAC9B,MAAM,SAAS,aAAa,GAAG,aAAa;IAQzB,IAAI,EAAE,GAAG;IAAS,OAAO,EAAE,MAAM;IANpD;;;SAGK;IACE,CAAC,KAmBD,GAAG,8EAEM,CAAC,uBACD,SAAS,+CACT,WAAW,gDACX,QAAQ,8CACR,MAAM,2CACN,SAAS,+CACT,QAAQ,mMA3Bf;gBAEU,IAAI,EAAE,GAAG,EAAS,OAAO,EAAE,MAAM;IAmDpD,KAAK,CAAC,CAAC,SAAS,SAAS,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;CAI/C"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Controller = void 0;
4
+ const route_1 = require("./route");
5
+ class Controller {
6
+ _app;
7
+ _schema;
8
+ /**
9
+ * Requests.
10
+ * @description Map of all requests in the schema.
11
+ * */
12
+ R;
13
+ constructor(_app, _schema) {
14
+ this._app = _app;
15
+ this._schema = _schema;
16
+ const path = this._schema._basePath;
17
+ const routes = {};
18
+ this._app.group(path, (a) => {
19
+ for (const i in _schema._routes_map) {
20
+ routes[i] = new route_1.Route(a, this._schema._routes[_schema._routes_map[i]]);
21
+ }
22
+ return a;
23
+ });
24
+ this.R = new Proxy(routes, {
25
+ get(target, p, receiver) {
26
+ return routes[p];
27
+ },
28
+ });
29
+ }
30
+ build(fn) {
31
+ const newApp = fn(this._app);
32
+ return new Controller(newApp, this._schema);
33
+ }
34
+ }
35
+ exports.Controller = Controller;
@@ -0,0 +1,14 @@
1
+ import type { AnyRoute, Response } from '@fy-tools/rpc-server';
2
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
3
+ import type { AnyElysia, Elysia } from 'elysia';
4
+ import { InstanceFromRoute, RouteToContext } from './types';
5
+ export declare class Route<App extends AnyElysia = Elysia, Schema extends AnyRoute = AnyRoute> {
6
+ _app: App;
7
+ _schema: Schema;
8
+ constructor(_app: App, _schema: Schema);
9
+ build<T extends AnyElysia>(fn: (app: App) => T): Route<T, Schema>;
10
+ handler<RouteContext extends RouteToContext<App, Schema>>(fn: (ctx: RouteContext) => Promise<Response<Schema>>, hook?: {
11
+ response?: Record<Exclude<number, 200>, StandardSchemaV1>;
12
+ }): InstanceFromRoute<App, Elysia<any, any, any, any, any, any, any>, Schema>;
13
+ }
14
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/lib/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EAIR,QAAQ,EACT,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,qBAAa,KAAK,CAChB,GAAG,SAAS,SAAS,GAAG,MAAM,EAC9B,MAAM,SAAS,QAAQ,GAAG,QAAQ;IAEf,IAAI,EAAE,GAAG;IAAS,OAAO,EAAE,MAAM;gBAAjC,IAAI,EAAE,GAAG,EAAS,OAAO,EAAE,MAAM;IAEpD,KAAK,CAAC,CAAC,SAAS,SAAS,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IAK9C,OAAO,CAAC,YAAY,SAAS,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,EACtD,EAAE,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EACpD,IAAI,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,gBAAgB,CAAC,CAAA;KAAO,GAoBxD,iBAAiB,CAAC,GAAG,6CAAgB,MAAM,CAAC;CAE/D"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Route = void 0;
4
+ class Route {
5
+ _app;
6
+ _schema;
7
+ constructor(_app, _schema) {
8
+ this._app = _app;
9
+ this._schema = _schema;
10
+ }
11
+ build(fn) {
12
+ const newApp = fn(this._app);
13
+ return new Route(newApp, this._schema);
14
+ }
15
+ handler(fn, hook = {}) {
16
+ const response = this._schema._response;
17
+ const routeSchema = {
18
+ response: { 200: response, ...hook.response },
19
+ body: this._schema._body,
20
+ params: this._schema._params,
21
+ query: this._schema._query,
22
+ };
23
+ const route = this._app.route(this._schema._method.toUpperCase(), this._schema._path, fn, { ...hook, ...routeSchema });
24
+ return route;
25
+ }
26
+ }
27
+ exports.Route = Route;
@@ -0,0 +1,27 @@
1
+ import type { Body, Params, Query, Response, Route } from '@fy-tools/rpc-server';
2
+ import { StandardSchemaV1 } from '@standard-schema/spec';
3
+ import type { AnyElysia, CreateEden, Elysia, InferContext, MergeElysiaInstances } from 'elysia';
4
+ export type RouteInputSchema = {
5
+ body?: StandardSchemaV1;
6
+ query?: StandardSchemaV1;
7
+ params?: StandardSchemaV1;
8
+ };
9
+ export type RouteToContext<A extends AnyElysia, T extends Route> = Omit<InferContext<A>, 'body' | 'params' | 'query'> & {
10
+ body: Body<T>;
11
+ params: Params<T>;
12
+ query: Query<T>;
13
+ };
14
+ export type InstanceFromRoute<App, AppRoute, Schema extends Route> = App extends Elysia<infer Path, infer Singleton, infer Definitions, infer Metadata, infer _, infer Ephemeral, infer Volatile> ? MergeElysiaInstances<[
15
+ App,
16
+ AppRoute extends Elysia ? Elysia<Path, Singleton, Definitions, Metadata, CreateEden<Schema['_path'], {
17
+ get: {
18
+ body: Body<Schema>;
19
+ query: Query<Schema>;
20
+ params: Params<Schema>;
21
+ response: {
22
+ 200: Response<Schema>;
23
+ };
24
+ };
25
+ }>, Ephemeral, Volatile> : never
26
+ ]> : never;
27
+ //# sourceMappingURL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AE;YACH,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YACnB,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YACrB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;YACvB,QAAQ,EAAE;gBACR,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;aACvB,CAAC;SACH,CAAC;KACH,CACF,EACD,SAAS,EACT,QAAQ,CACT,GACD,KAAK;CACV,CACF,GACD,KAAK,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@fy-tools/rpc-server-elysia",
3
+ "version": "0.0.119-alpha.10381",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/festusyuma/fy-tools.git",
7
+ "directory": "packages/rpc-server-elysia"
8
+ },
9
+ "main": "./dist/index.js",
10
+ "module": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ "./package.json": "./package.json",
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js",
17
+ "default": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "!**/*.tsbuildinfo"
23
+ ],
24
+ "dependencies": {
25
+ "@fy-tools/rpc-server": "0.0.119-alpha.10381",
26
+ "elysia": "^1.4.29",
27
+ "tslib": "^2.3.0",
28
+ "@standard-schema/spec": "^1.0.0"
29
+ }
30
+ }