@modern-js/bff-core 3.0.0-alpha.1 → 3.0.0-alpha.2

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.
@@ -24,9 +24,8 @@ var __webpack_require__ = {};
24
24
  var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
- generateClient: ()=>generateClient,
28
- DEFAULT_CLIENT_REQUEST_CREATOR: ()=>DEFAULT_CLIENT_REQUEST_CREATOR,
29
- INNER_CLIENT_REQUEST_CREATOR: ()=>INNER_CLIENT_REQUEST_CREATOR
27
+ INNER_CLIENT_REQUEST_CREATOR: ()=>INNER_CLIENT_REQUEST_CREATOR,
28
+ generateClient: ()=>generateClient
30
29
  });
31
30
  const external_path_namespaceObject = require("path");
32
31
  const index_js_namespaceObject = require("../router/index.js");
@@ -40,7 +39,6 @@ const getPackageName = (appDir)=>{
40
39
  return;
41
40
  }
42
41
  };
43
- const DEFAULT_CLIENT_REQUEST_CREATOR = '@modern-js/create-request';
44
42
  const INNER_CLIENT_REQUEST_CREATOR = '@modern-js/plugin-bff/client';
45
43
  const generateClient = async ({ appDir, resourcePath, apiDir, lambdaDir, prefix, port, target, requestCreator, fetcher, requireResolve = require.resolve, httpMethodDecider, domain })=>{
46
44
  requestCreator = requestCreator || INNER_CLIENT_REQUEST_CREATOR;
@@ -87,11 +85,9 @@ const generateClient = async ({ appDir, resourcePath, apiDir, lambdaDir, prefix,
87
85
  ${fetcher ? `import { fetch } from '${fetcher}';\n` : ''}`;
88
86
  return (0, external_result_js_namespaceObject.Ok)(`${importCode}\n${handlersCode}`);
89
87
  };
90
- exports.DEFAULT_CLIENT_REQUEST_CREATOR = __webpack_exports__.DEFAULT_CLIENT_REQUEST_CREATOR;
91
88
  exports.INNER_CLIENT_REQUEST_CREATOR = __webpack_exports__.INNER_CLIENT_REQUEST_CREATOR;
92
89
  exports.generateClient = __webpack_exports__.generateClient;
93
90
  for(var __rspack_i in __webpack_exports__)if (-1 === [
94
- "DEFAULT_CLIENT_REQUEST_CREATOR",
95
91
  "INNER_CLIENT_REQUEST_CREATOR",
96
92
  "generateClient"
97
93
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
@@ -69,7 +69,7 @@ const clearRouteName = (routeName)=>{
69
69
  const isHandler = (input)=>input && 'function' == typeof input;
70
70
  const isFunction = (input)=>input && '[object Function]' === ({}).toString.call(input);
71
71
  const requireHandlerModule = async (modulePath)=>{
72
- const originRequire = 'test' === process.env.NODE_ENV ? jest.requireActual : utils_namespaceObject.compatibleRequire;
72
+ const originRequire = 'test' === process.env.NODE_ENV ? require : utils_namespaceObject.compatibleRequire;
73
73
  const module = await originRequire(modulePath, false);
74
74
  if (isFunction(module)) return {
75
75
  default: module
package/dist/esm/api.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import "reflect-metadata";
2
2
  import koa_compose from "koa-compose";
3
- import { HANDLER_WITH_META, validateFunction } from "./utils";
3
+ import { HANDLER_WITH_META, validateFunction } from "./utils/index.mjs";
4
4
  function Api(...args) {
5
5
  const handler = args.pop();
6
6
  validateFunction(handler, 'Apihandler');
@@ -1,6 +1,6 @@
1
1
  import { resolve } from "path";
2
- import { ApiRouter } from "../router";
3
- import { Err, Ok } from "./result";
2
+ import { ApiRouter } from "../router/index.mjs";
3
+ import { Err, Ok } from "./result.mjs";
4
4
  const getPackageName = (appDir)=>{
5
5
  try {
6
6
  const packageJsonPath = resolve(appDir, './package.json');
@@ -10,7 +10,6 @@ const getPackageName = (appDir)=>{
10
10
  return;
11
11
  }
12
12
  };
13
- const DEFAULT_CLIENT_REQUEST_CREATOR = '@modern-js/create-request';
14
13
  const INNER_CLIENT_REQUEST_CREATOR = '@modern-js/plugin-bff/client';
15
14
  const generateClient = async ({ appDir, resourcePath, apiDir, lambdaDir, prefix, port, target, requestCreator, fetcher, requireResolve = require.resolve, httpMethodDecider, domain })=>{
16
15
  requestCreator = requestCreator || INNER_CLIENT_REQUEST_CREATOR;
@@ -57,4 +56,4 @@ const generateClient = async ({ appDir, resourcePath, apiDir, lambdaDir, prefix,
57
56
  ${fetcher ? `import { fetch } from '${fetcher}';\n` : ''}`;
58
57
  return Ok(`${importCode}\n${handlersCode}`);
59
58
  };
60
- export { DEFAULT_CLIENT_REQUEST_CREATOR, INNER_CLIENT_REQUEST_CREATOR, generateClient };
59
+ export { INNER_CLIENT_REQUEST_CREATOR, generateClient };
@@ -1 +1 @@
1
- export * from "./generateClient";
1
+ export * from "./generateClient.mjs";
@@ -1,8 +1,8 @@
1
- import { Api } from "./api";
2
- import { HttpError, ValidationError } from "./errors/http";
3
- import { HANDLER_WITH_META, INPUT_PARAMS_DECIDER, createStorage, getRelativeRuntimePath, isInputParamsDeciderHandler, isWithMetaHandler, registerPaths } from "./utils";
4
- export * from "./router";
5
- export * from "./types";
6
- export * from "./client";
7
- export * from "./operators/http";
1
+ import { Api } from "./api.mjs";
2
+ import { HttpError, ValidationError } from "./errors/http.mjs";
3
+ import { HANDLER_WITH_META, INPUT_PARAMS_DECIDER, createStorage, getRelativeRuntimePath, isInputParamsDeciderHandler, isWithMetaHandler, registerPaths } from "./utils/index.mjs";
4
+ export * from "./router/index.mjs";
5
+ export * from "./types.mjs";
6
+ export * from "./client/index.mjs";
7
+ export * from "./operators/http.mjs";
8
8
  export { Api, HANDLER_WITH_META, HttpError, INPUT_PARAMS_DECIDER, ValidationError, createStorage, getRelativeRuntimePath, isInputParamsDeciderHandler, isWithMetaHandler, registerPaths };
@@ -1,5 +1,5 @@
1
- import { ValidationError } from "../errors/http";
2
- import { HttpMetadata, HttpMethod, OperatorType, ResponseMetaType, TriggerType } from "../types";
1
+ import { ValidationError } from "../errors/http.mjs";
2
+ import { HttpMetadata, HttpMethod, OperatorType, ResponseMetaType, TriggerType } from "../types.mjs";
3
3
  const validateInput = async (schema, input)=>{
4
4
  try {
5
5
  return await schema.parseAsync(input);
@@ -1,4 +1,4 @@
1
- import { HttpMethod } from "../types";
1
+ import { HttpMethod } from "../types.mjs";
2
2
  const AllHttpMethods = Object.values(HttpMethod);
3
3
  const FRAMEWORK_MODE_LAMBDA_DIR = 'lambda';
4
4
  const FRAMEWORK_MODE_APP_DIR = 'app';
@@ -1,12 +1,12 @@
1
1
  import path from "path";
2
2
  import { fs, logger } from "@modern-js/utils";
3
3
  import "reflect-metadata";
4
- import { HttpMethod, OperatorType, TriggerType, httpMethods } from "../types";
5
- import { INPUT_PARAMS_DECIDER, debug } from "../utils";
6
- import { API_FILE_RULES, FRAMEWORK_MODE_LAMBDA_DIR } from "./constants";
7
- import { getFiles, getPathFromFilename, requireHandlerModule, sortRoutes } from "./utils";
8
- export * from "./types";
9
- export * from "./constants";
4
+ import { HttpMethod, OperatorType, TriggerType, httpMethods } from "../types.mjs";
5
+ import { INPUT_PARAMS_DECIDER, debug } from "../utils/index.mjs";
6
+ import { API_FILE_RULES, FRAMEWORK_MODE_LAMBDA_DIR } from "./constants.mjs";
7
+ import { getFiles, getPathFromFilename, requireHandlerModule, sortRoutes } from "./utils.mjs";
8
+ export * from "./types.mjs";
9
+ export * from "./constants.mjs";
10
10
  class ApiRouter {
11
11
  isExistLambda() {
12
12
  return this.existLambdaDir;
@@ -1,6 +1,6 @@
1
1
  import path from "path";
2
2
  import { compatibleRequire, globby } from "@modern-js/utils";
3
- import { INDEX_SUFFIX } from "./constants";
3
+ import { INDEX_SUFFIX } from "./constants.mjs";
4
4
  const getFiles = (lambdaDir, rules)=>globby.sync(rules, {
5
5
  cwd: lambdaDir,
6
6
  gitignore: true
@@ -27,7 +27,7 @@ const clearRouteName = (routeName)=>{
27
27
  const isHandler = (input)=>input && 'function' == typeof input;
28
28
  const isFunction = (input)=>input && '[object Function]' === ({}).toString.call(input);
29
29
  const requireHandlerModule = async (modulePath)=>{
30
- const originRequire = 'test' === process.env.NODE_ENV ? jest.requireActual : compatibleRequire;
30
+ const originRequire = 'test' === process.env.NODE_ENV ? require : compatibleRequire;
31
31
  const module = await originRequire(modulePath, false);
32
32
  if (isFunction(module)) return {
33
33
  default: module
@@ -1,6 +1,6 @@
1
- import { debug } from "./debug";
2
- export * from "./storage";
3
- export * from "./alias";
4
- export * from "./meta";
5
- export * from "./validate";
1
+ import { debug } from "./debug.mjs";
2
+ export * from "./storage.mjs";
3
+ export * from "./alias.mjs";
4
+ export * from "./meta.mjs";
5
+ export * from "./validate.mjs";
6
6
  export { debug };
@@ -1,3 +1,5 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
1
3
  import "reflect-metadata";
2
4
  import koa_compose from "koa-compose";
3
5
  import { HANDLER_WITH_META, validateFunction } from "./utils/index.mjs";
@@ -1,3 +1,5 @@
1
+ import __rslib_shim_module__ from "node:module";
2
+ const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
1
3
  import { resolve } from "path";
2
4
  import { ApiRouter } from "../router/index.mjs";
3
5
  import { Err, Ok } from "./result.mjs";
@@ -10,7 +12,6 @@ const getPackageName = (appDir)=>{
10
12
  return;
11
13
  }
12
14
  };
13
- const DEFAULT_CLIENT_REQUEST_CREATOR = '@modern-js/create-request';
14
15
  const INNER_CLIENT_REQUEST_CREATOR = '@modern-js/plugin-bff/client';
15
16
  const generateClient = async ({ appDir, resourcePath, apiDir, lambdaDir, prefix, port, target, requestCreator, fetcher, requireResolve = require.resolve, httpMethodDecider, domain })=>{
16
17
  requestCreator = requestCreator || INNER_CLIENT_REQUEST_CREATOR;
@@ -57,4 +58,4 @@ const generateClient = async ({ appDir, resourcePath, apiDir, lambdaDir, prefix,
57
58
  ${fetcher ? `import { fetch } from '${fetcher}';\n` : ''}`;
58
59
  return Ok(`${importCode}\n${handlersCode}`);
59
60
  };
60
- export { DEFAULT_CLIENT_REQUEST_CREATOR, INNER_CLIENT_REQUEST_CREATOR, generateClient };
61
+ export { INNER_CLIENT_REQUEST_CREATOR, generateClient };
@@ -1 +1,3 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
1
3
  export * from "./generateClient.mjs";
@@ -1,3 +1,5 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
1
3
  const Err = (value)=>{
2
4
  const err = {
3
5
  kind: 'Err',
@@ -0,0 +1,2 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
@@ -1,3 +1,5 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
1
3
  class HttpError extends Error {
2
4
  constructor(status, message){
3
5
  super(message);
@@ -1,3 +1,5 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
1
3
  import { Api } from "./api.mjs";
2
4
  import { HttpError, ValidationError } from "./errors/http.mjs";
3
5
  import { HANDLER_WITH_META, INPUT_PARAMS_DECIDER, createStorage, getRelativeRuntimePath, isInputParamsDeciderHandler, isWithMetaHandler, registerPaths } from "./utils/index.mjs";
@@ -1,3 +1,5 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
1
3
  import { ValidationError } from "../errors/http.mjs";
2
4
  import { HttpMetadata, HttpMethod, OperatorType, ResponseMetaType, TriggerType } from "../types.mjs";
3
5
  const validateInput = async (schema, input)=>{
@@ -1,3 +1,5 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
1
3
  import { HttpMethod } from "../types.mjs";
2
4
  const AllHttpMethods = Object.values(HttpMethod);
3
5
  const FRAMEWORK_MODE_LAMBDA_DIR = 'lambda';
@@ -1,3 +1,5 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
1
3
  import path from "path";
2
4
  import { fs, logger } from "@modern-js/utils";
3
5
  import "reflect-metadata";
@@ -0,0 +1,2 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
@@ -1,3 +1,5 @@
1
+ import __rslib_shim_module__ from "node:module";
2
+ const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
1
3
  import path from "path";
2
4
  import { compatibleRequire, globby } from "@modern-js/utils";
3
5
  import { INDEX_SUFFIX } from "./constants.mjs";
@@ -27,7 +29,7 @@ const clearRouteName = (routeName)=>{
27
29
  const isHandler = (input)=>input && 'function' == typeof input;
28
30
  const isFunction = (input)=>input && '[object Function]' === ({}).toString.call(input);
29
31
  const requireHandlerModule = async (modulePath)=>{
30
- const originRequire = 'test' === process.env.NODE_ENV ? jest.requireActual : compatibleRequire;
32
+ const originRequire = 'test' === process.env.NODE_ENV ? require : compatibleRequire;
31
33
  const module = await originRequire(modulePath, false);
32
34
  if (isFunction(module)) return {
33
35
  default: module
@@ -1,3 +1,5 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
1
3
  var types_OperatorType = /*#__PURE__*/ function(OperatorType) {
2
4
  OperatorType[OperatorType["Trigger"] = 0] = "Trigger";
3
5
  OperatorType[OperatorType["Middleware"] = 1] = "Middleware";
@@ -1,3 +1,5 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
1
3
  import fs from "fs";
2
4
  import module_0 from "module";
3
5
  import { platform } from "os";
@@ -1,3 +1,5 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
1
3
  import { createDebugger } from "@modern-js/utils";
2
4
  const debug = createDebugger('bff');
3
5
  export { debug };
@@ -1,3 +1,5 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
1
3
  import { debug } from "./debug.mjs";
2
4
  export * from "./storage.mjs";
3
5
  export * from "./alias.mjs";
@@ -1,3 +1,5 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
1
3
  const HANDLER_WITH_META = 'HANDLER_WITH_META';
2
4
  const INPUT_PARAMS_DECIDER = 'INPUT_PARAMS_DECIDER';
3
5
  const isWithMetaHandler = (handler)=>'function' == typeof handler && handler[HANDLER_WITH_META];
@@ -1,3 +1,5 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
1
3
  import { AsyncLocalStorage } from "async_hooks";
2
4
  const createStorage = ()=>{
3
5
  let storage;
@@ -1,3 +1,5 @@
1
+ import "node:module";
2
+ /*#__PURE__*/ import.meta.url;
1
3
  import util from "util";
2
4
  const getTypeErrorMessage = (actual)=>{
3
5
  let msg = '';
@@ -16,6 +16,5 @@ export type GenClientOptions = {
16
16
  httpMethodDecider?: HttpMethodDecider;
17
17
  domain?: string;
18
18
  };
19
- export declare const DEFAULT_CLIENT_REQUEST_CREATOR = "@modern-js/create-request";
20
19
  export declare const INNER_CLIENT_REQUEST_CREATOR = "@modern-js/plugin-bff/client";
21
20
  export declare const generateClient: ({ appDir, resourcePath, apiDir, lambdaDir, prefix, port, target, requestCreator, fetcher, requireResolve, httpMethodDecider, domain, }: GenClientOptions) => Promise<GenClientResult>;
package/package.json CHANGED
@@ -15,15 +15,16 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.0.0-alpha.1",
19
- "jsnext:source": "./src/index.ts",
18
+ "version": "3.0.0-alpha.2",
20
19
  "types": "./dist/types/index.d.ts",
21
20
  "main": "./dist/cjs/index.js",
22
- "module": "./dist/esm/index.js",
23
21
  "exports": {
24
22
  ".": {
25
23
  "types": "./dist/types/index.d.ts",
26
- "jsnext:source": "./src/index.ts",
24
+ "node": {
25
+ "import": "./dist/esm-node/index.mjs",
26
+ "require": "./dist/cjs/index.js"
27
+ },
27
28
  "default": "./dist/cjs/index.js"
28
29
  }
29
30
  },
@@ -32,21 +33,19 @@
32
33
  "koa-compose": "^4.1.0",
33
34
  "reflect-metadata": "^0.2.2",
34
35
  "type-fest": "2.19.0",
35
- "@modern-js/utils": "3.0.0-alpha.1"
36
+ "@modern-js/utils": "3.0.0-alpha.2"
36
37
  },
37
38
  "devDependencies": {
38
- "@types/jest": "^29.5.14",
39
+ "@rslib/core": "0.19.3",
39
40
  "@types/koa-compose": "^3.2.9",
40
41
  "@types/node": "^20",
41
- "jest": "^29.7.0",
42
42
  "ts-node": "^10.9.2",
43
43
  "tsconfig-paths": "^4.2.0",
44
- "@rslib/core": "0.19.1",
45
44
  "typescript": "^5",
46
45
  "zod": "^3.25.76",
47
- "@modern-js/types": "3.0.0-alpha.1",
48
- "@scripts/jest-config": "2.66.0",
49
- "@modern-js/rslib": "2.68.10"
46
+ "@modern-js/rslib": "2.68.10",
47
+ "@modern-js/types": "3.0.0-alpha.2",
48
+ "@scripts/rstest-config": "2.66.0"
50
49
  },
51
50
  "peerDependencies": {
52
51
  "ts-node": "^10.9.2",
@@ -65,6 +64,6 @@
65
64
  "scripts": {
66
65
  "dev": "rslib build --watch",
67
66
  "build": "rslib build",
68
- "test": "jest --passWithNoTests"
67
+ "test": "rstest --passWithNoTests"
69
68
  }
70
69
  }
@@ -0,0 +1,10 @@
1
+ import { withTestPreset } from '@scripts/rstest-config';
2
+
3
+ export default withTestPreset({
4
+ setupFiles: ['@scripts/rstest-config/setup.ts'],
5
+ root: __dirname,
6
+ globals: true,
7
+ env: {
8
+ npm_package_name: 'tests',
9
+ },
10
+ });