@kanjijs/openapi 0.2.0-beta.11 → 0.2.0-beta.13

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.
@@ -0,0 +1,14 @@
1
+ import { type Constructor } from "@kanjijs/core";
2
+ export declare class OpenApiGenerator {
3
+ static generate(rootModule: Constructor): {
4
+ openapi: string;
5
+ info: {
6
+ title: string;
7
+ version: string;
8
+ };
9
+ paths: Record<string, any>;
10
+ };
11
+ private static getAllControllers;
12
+ private static normalizePath;
13
+ private static buildParameters;
14
+ }
package/dist/index.js CHANGED
@@ -1017,69 +1017,73 @@ var methodMetadataStore = new WeakMap;
1017
1017
  var controllerMetadataStore = new WeakMap;
1018
1018
  var moduleMetadataStore = new WeakMap;
1019
1019
  var injectionMetadataStore = new WeakMap;
1020
- var MetadataStorage = {
1021
- addRoute(target, methodName, meta) {
1022
- let methods = methodMetadataStore.get(target);
1023
- if (!methods) {
1024
- methods = new Map;
1025
- methodMetadataStore.set(target, methods);
1026
- }
1027
- const existing = methods.get(methodName) || {};
1028
- methods.set(methodName, { ...existing, ...meta });
1029
- },
1030
- addContract(target, methodName, contract) {
1031
- let methods = methodMetadataStore.get(target);
1032
- if (!methods) {
1033
- methods = new Map;
1034
- methodMetadataStore.set(target, methods);
1035
- }
1036
- const existing = methods.get(methodName) || {};
1037
- existing.contract = contract;
1038
- methods.set(methodName, existing);
1039
- },
1040
- addMiddleware(target, middleware, methodName) {
1041
- if (methodName) {
1020
+ var globalStore = globalThis;
1021
+ if (!globalStore.KANJI_METADATA_STORAGE) {
1022
+ globalStore.KANJI_METADATA_STORAGE = {
1023
+ addRoute(target, methodName, meta) {
1024
+ let methods = methodMetadataStore.get(target);
1025
+ if (!methods) {
1026
+ methods = new Map;
1027
+ methodMetadataStore.set(target, methods);
1028
+ }
1029
+ const existing = methods.get(methodName) || {};
1030
+ methods.set(methodName, { ...existing, ...meta });
1031
+ },
1032
+ addContract(target, methodName, contract) {
1042
1033
  let methods = methodMetadataStore.get(target);
1043
1034
  if (!methods) {
1044
1035
  methods = new Map;
1045
1036
  methodMetadataStore.set(target, methods);
1046
1037
  }
1047
1038
  const existing = methods.get(methodName) || {};
1048
- existing.middlewares = [...existing.middlewares || [], middleware];
1039
+ existing.contract = contract;
1049
1040
  methods.set(methodName, existing);
1050
- } else {
1051
- const existing = controllerMetadataStore.get(target) || { prefix: "/" };
1052
- existing.middlewares = [...existing.middlewares || [], middleware];
1053
- controllerMetadataStore.set(target, existing);
1054
- }
1055
- },
1056
- getRoutes(target) {
1057
- return methodMetadataStore.get(target);
1058
- },
1059
- setController(target, meta) {
1060
- controllerMetadataStore.set(target, meta);
1061
- },
1062
- getController(target) {
1063
- return controllerMetadataStore.get(target);
1064
- },
1065
- defineModule(target, meta) {
1066
- moduleMetadataStore.set(target, meta);
1067
- },
1068
- getModule(target) {
1069
- return moduleMetadataStore.get(target);
1070
- },
1071
- addInjection(target, index, token) {
1072
- let injections = injectionMetadataStore.get(target);
1073
- if (!injections) {
1074
- injections = new Map;
1075
- injectionMetadataStore.set(target, injections);
1041
+ },
1042
+ addMiddleware(target, middleware, methodName) {
1043
+ if (methodName) {
1044
+ let methods = methodMetadataStore.get(target);
1045
+ if (!methods) {
1046
+ methods = new Map;
1047
+ methodMetadataStore.set(target, methods);
1048
+ }
1049
+ const existing = methods.get(methodName) || {};
1050
+ existing.middlewares = [...existing.middlewares || [], middleware];
1051
+ methods.set(methodName, existing);
1052
+ } else {
1053
+ const existing = controllerMetadataStore.get(target) || { prefix: "/" };
1054
+ existing.middlewares = [...existing.middlewares || [], middleware];
1055
+ controllerMetadataStore.set(target, existing);
1056
+ }
1057
+ },
1058
+ getRoutes(target) {
1059
+ return methodMetadataStore.get(target);
1060
+ },
1061
+ setController(target, meta) {
1062
+ controllerMetadataStore.set(target, meta);
1063
+ },
1064
+ getController(target) {
1065
+ return controllerMetadataStore.get(target);
1066
+ },
1067
+ defineModule(target, meta) {
1068
+ moduleMetadataStore.set(target, meta);
1069
+ },
1070
+ getModule(target) {
1071
+ return moduleMetadataStore.get(target);
1072
+ },
1073
+ addInjection(target, index, token) {
1074
+ let injections = injectionMetadataStore.get(target);
1075
+ if (!injections) {
1076
+ injections = new Map;
1077
+ injectionMetadataStore.set(target, injections);
1078
+ }
1079
+ injections.set(index, token);
1080
+ },
1081
+ getInjections(target) {
1082
+ return injectionMetadataStore.get(target);
1076
1083
  }
1077
- injections.set(index, token);
1078
- },
1079
- getInjections(target) {
1080
- return injectionMetadataStore.get(target);
1081
- }
1082
- };
1084
+ };
1085
+ }
1086
+ var MetadataStorage = globalStore.KANJI_METADATA_STORAGE;
1083
1087
  function createMethodDecorator(method) {
1084
1088
  return (path = "/") => {
1085
1089
  return (target, propertyKey) => {
@@ -1268,7 +1272,7 @@ class ModuleCompiler {
1268
1272
  const paramTypes = Reflect.getMetadata("design:paramtypes", clazz) || [];
1269
1273
  const injectionTokens = MetadataStorage.getInjections(clazz) || new Map;
1270
1274
  dependencies = paramTypes.map((t, i) => injectionTokens.get(i) || t);
1271
- } else if ("useFactory" in provider && provider.useFactory) {
1275
+ } else if ("useFactory" in provider) {
1272
1276
  targetName = provider.provide?.name || String(provider.provide);
1273
1277
  dependencies = provider.inject || [];
1274
1278
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanjijs/openapi",
3
- "version": "0.2.0-beta.11",
3
+ "version": "0.2.0-beta.13",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -10,10 +10,10 @@
10
10
  "LICENSE"
11
11
  ],
12
12
  "scripts": {
13
- "build": "bun build src/index.ts --outdir dist --target bun"
13
+ "build": "bun build src/index.ts --outdir dist --target bun && tsc --emitDeclarationOnly --declaration --outDir dist"
14
14
  },
15
15
  "dependencies": {
16
- "@kanjijs/core": "^0.2.0-beta.11",
16
+ "@kanjijs/core": "^0.2.0-beta.13",
17
17
  "zod-to-json-schema": "^3.22.0",
18
18
  "zod": "^3.0.0",
19
19
  "reflect-metadata": "^0.2.0"