@domain.js/main 0.1.2 → 0.1.3

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.
@@ -1,2 +1,2 @@
1
- #! /usr/bin/env ts-node
1
+ #! /usr/bin/env node
2
2
  export {};
package/dist/cli/index.js CHANGED
@@ -1,4 +1,4 @@
1
- #! /usr/bin/env ts-node
1
+ #! /usr/bin/env node
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const fs = require("fs");
@@ -31,12 +31,12 @@ export interface Profile {
31
31
  export interface HttpCodes {
32
32
  [propName: string]: number;
33
33
  }
34
- interface _Domain {
35
- [propName: string]: (profile: Profile, params: any) => any | _Domain;
34
+ export interface Domain {
35
+ [propName: string]: (profile: Profile, params: any) => any | Domain;
36
+ }
37
+ export interface GetSchemaByPath {
38
+ (methodPath: string): [any, any];
36
39
  }
37
- export declare type Domain = _Domain & {
38
- _getSchemaByPath(methodPath: string): [any, any];
39
- };
40
40
  export interface Err {
41
41
  message: string;
42
42
  code?: number | string;
@@ -1,10 +1,11 @@
1
1
  import * as restify from "restify";
2
2
  import { Router } from "./router";
3
- import { Cnf, Domain, Profile, HttpCodes } from "./defines";
3
+ import { Cnf, Domain, Profile, HttpCodes, GetSchemaByPath } from "./defines";
4
4
  interface Deps {
5
5
  routers(r: ReturnType<typeof Router>): void;
6
6
  domain: Domain;
7
7
  httpCodes: HttpCodes;
8
+ getSchemaByPath: GetSchemaByPath;
8
9
  swaggerDocJson?: any;
9
10
  makeProfileHook?: (obj: Profile, req: restify.Request) => any;
10
11
  }
@@ -6,7 +6,7 @@ const router_1 = require("./router");
6
6
  const utils_1 = require("./utils");
7
7
  function Main(cnf, deps) {
8
8
  const utils = (0, utils_1.Utils)(cnf);
9
- const { routers, domain, httpCodes, swaggerDocJson, makeProfileHook } = deps;
9
+ const { routers, getSchemaByPath, domain, httpCodes, swaggerDocJson, makeProfileHook } = deps;
10
10
  const server = restify.createServer();
11
11
  server.use(restify.plugins.queryParser());
12
12
  server.use(restify.plugins.bodyParser({
@@ -18,6 +18,7 @@ function Main(cnf, deps) {
18
18
  server,
19
19
  httpCodes,
20
20
  makeProfileHook,
21
+ getSchemaByPath,
21
22
  domain,
22
23
  apisRoute: cnf.apisRoute,
23
24
  swagger: [cnf.swaggerApiPath, swaggerDocJson],
@@ -1,8 +1,9 @@
1
1
  import * as restify from "restify";
2
2
  import { Utils } from "./utils";
3
- import { HttpCodes, Domain, Profile } from "./defines";
3
+ import { HttpCodes, Domain, Profile, GetSchemaByPath } from "./defines";
4
4
  interface Deps {
5
5
  domain: Domain;
6
+ getSchemaByPath: GetSchemaByPath;
6
7
  utils: ReturnType<typeof Utils>;
7
8
  server: restify.Server;
8
9
  httpCodes: HttpCodes;
@@ -5,7 +5,7 @@ const _ = require("lodash");
5
5
  const errors = require("restify-errors");
6
6
  const swaggerUi = require("swagger-ui-restify");
7
7
  function Router(deps) {
8
- const { domain, apisRoute, utils, server, httpCodes = {}, makeProfileHook, swagger = ["", {}], } = deps;
8
+ const { domain, apisRoute, getSchemaByPath, utils, server, httpCodes = {}, makeProfileHook, swagger = ["", {}], } = deps;
9
9
  const { ucwords, makeParams, makeProfile, outputCSV, jsonSchema2Swagger } = utils;
10
10
  // 改写 HttpErrorToJSON 处理 data
11
11
  const HttpErrorToJSON = errors.HttpError.prototype.toJSON;
@@ -56,7 +56,7 @@ function Router(deps) {
56
56
  const { path } = req.query;
57
57
  try {
58
58
  const { all } = req.query;
59
- const schema = domain._getSchemaByPath(path);
59
+ const schema = getSchemaByPath(path);
60
60
  res.send(all === undefined ? schema[1] : schema);
61
61
  }
62
62
  catch (e) {
@@ -72,7 +72,7 @@ function Router(deps) {
72
72
  let apiSchema = [];
73
73
  let desc = "";
74
74
  try {
75
- apiSchema = domain._getSchemaByPath(methodPath);
75
+ apiSchema = getSchemaByPath(methodPath);
76
76
  desc = apiSchema[1] ? apiSchema[1].description : "unknow";
77
77
  apiSchema = jsonSchema2Swagger(apiSchema[1] ? apiSchema[1] : {}, verb, methodPath, swaggerDocJson);
78
78
  }
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
+ "bin": "dist/cli/index.js",
6
7
  "scripts": {
7
8
  "build": "tsc",
8
9
  "test": "export NODE_ENV=test && jest ./src --coverage",