@open-norantec/herbal 1.0.2 → 2.0.0-alpha.0

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,6 +1,6 @@
1
1
  import 'reflect-metadata';
2
2
  import { Constructor } from 'type-fest';
3
- import { OpenAPIObject } from 'zod-openapi/dist/openapi3-ts/dist/model/openapi31';
3
+ import { OpenAPIObject } from 'openapi3-ts/oas31';
4
4
  export interface CreateClientOptions {
5
5
  Module: Constructor<any>;
6
6
  }
package/dist/core.d.ts CHANGED
@@ -1,44 +1,44 @@
1
1
  import 'reflect-metadata';
2
2
  import { HeaderUtil } from '@open-norantec/utilities/dist/header-util.class';
3
- import { z } from 'zod';
4
3
  import { Request, RequestContext } from './types/request.type';
4
+ import { z } from '@open-norantec/utilities';
5
5
  import 'reflect-metadata';
6
6
  import { Request as ExpressRequest } from 'express';
7
7
  import { Constructor } from 'type-fest';
8
8
  import { AuthAdapter } from './abstracts/auth-adapter.abstract.class';
9
- import { PathsObject } from 'zod-openapi/dist/openapi3-ts/dist/model/openapi31';
9
+ import { PathsObject } from 'openapi3-ts/oas31';
10
10
  export * from '@nestjs/core';
11
- export type MethodHandler<IS extends z.Schema<any>, OS extends z.Schema<any>> = (request: Request, input: unknown, headers: ReturnType<typeof HeaderUtil.parse>) => Promise<{
11
+ export type MethodHandler<IS extends z.ZodType<any>, OS extends z.ZodType<any>> = (request: Request, input: unknown, headers: ReturnType<typeof HeaderUtil.parse>) => Promise<{
12
12
  request: z.infer<IS>;
13
13
  response: z.infer<OS>;
14
14
  }>;
15
15
  type ClientGroups = Array<string> | null | undefined;
16
16
  type ClienttGroupsFactory = (defaultGroupName: string) => ClientGroups;
17
- export interface MethodRegisterOptions<IS extends z.Schema<any>, OS extends z.Schema<any>> {
17
+ export interface MethodRegisterOptions<IS extends z.ZodType<any>, OS extends z.ZodType<any>> {
18
18
  inputSchema: IS;
19
19
  outputSchema: OS;
20
20
  authAdapters?: Constructor<AuthAdapter>[];
21
21
  clientGroups?: ClientGroups | ClienttGroupsFactory;
22
22
  disableTransaction?: boolean;
23
23
  }
24
- export type MethodRegisterFn<C> = <IS extends z.Schema<any>, OS extends z.Schema<any>>(name: string, options: MethodRegisterOptions<IS, OS>, callback: MethodCallback<IS, OS, C>) => void;
25
- export interface MethodContext<IS extends z.Schema<any>> extends RequestContext {
24
+ export type MethodRegisterFn<C> = <IS extends z.ZodType<any>, OS extends z.ZodType<any>>(name: string, options: MethodRegisterOptions<IS, OS>, callback: MethodCallback<IS, OS, C>) => void;
25
+ export interface MethodContext<IS extends z.ZodType<any>> extends RequestContext {
26
26
  headers: ReturnType<typeof HeaderUtil.parse>;
27
27
  input: z.infer<IS>;
28
28
  url: string;
29
29
  }
30
- export type MethodCallContext<IS extends z.Schema<any>> = Omit<MethodContext<IS>, 'input'>;
31
- export type MethodCallback<IS extends z.Schema<any>, OS extends z.Schema<any>, C> = (this: C, context: MethodContext<IS>) => Promise<z.infer<OS>>;
32
- declare class MethodConfig<IS extends z.Schema<any>, OS extends z.Schema<any>, C> {
30
+ export type MethodCallContext<IS extends z.ZodType<any>> = Omit<MethodContext<IS>, 'input'>;
31
+ export type MethodCallback<IS extends z.ZodType<any>, OS extends z.ZodType<any>, C> = (this: C, context: MethodContext<IS>) => Promise<z.infer<OS>>;
32
+ declare class MethodConfig<IS extends z.ZodType<any>, OS extends z.ZodType<any>, C> {
33
33
  readonly name: string;
34
34
  readonly options: MethodRegisterOptions<IS, OS>;
35
35
  protected readonly callback: MethodCallback<IS, OS, C>;
36
36
  constructor(name: string, options: MethodRegisterOptions<IS, OS>, callback: MethodCallback<IS, OS, C>);
37
- call(controller: C, callContext: MethodCallContext<IS>): Promise<z.TypeOf<OS>>;
37
+ call(controller: C, callContext: MethodCallContext<IS>): Promise<z.core.output<OS>>;
38
38
  }
39
39
  declare class MethodPool {
40
40
  protected readonly methods: Map<string, MethodConfig<any, any, any>>;
41
- registerMethod<IS extends z.Schema<any>, OS extends z.Schema<any>, C>(name: string, options: MethodRegisterOptions<IS, OS>, callback: MethodCallback<IS, OS, C>): void;
41
+ registerMethod<IS extends z.ZodType<any>, OS extends z.ZodType<any>, C>(name: string, options: MethodRegisterOptions<IS, OS>, callback: MethodCallback<IS, OS, C>): void;
42
42
  transactionDisabled(name: string): boolean | undefined;
43
43
  getCallFn(name: string): ((controller: any, callContext: MethodCallContext<any>) => Promise<any>) | null;
44
44
  getAuthAdapters(name: string): Constructor<AuthAdapter>[] | null | undefined;
package/dist/core.js CHANGED
@@ -90,7 +90,6 @@ exports.ControllerUtil = exports.getMethodPool = exports.getControllerName = exp
90
90
  require("reflect-metadata");
91
91
  var common_1 = require("@nestjs/common");
92
92
  var header_util_class_1 = require("@open-norantec/utilities/dist/header-util.class");
93
- var zod_1 = require("zod");
94
93
  var string_util_class_1 = require("@open-norantec/utilities/dist/string-util.class");
95
94
  var utilities_1 = require("@open-norantec/utilities");
96
95
  require("reflect-metadata");
@@ -106,7 +105,6 @@ var operators_1 = require("rxjs/operators");
106
105
  var logger_service_1 = require("./modules/logger/logger.service");
107
106
  var sequelize_typescript_1 = require("sequelize-typescript");
108
107
  var decorators_1 = require("./decorators");
109
- var zod_openapi_1 = require("zod-openapi");
110
108
  __exportStar(require("@nestjs/core"), exports);
111
109
  var HANDLE_REQUEST_INSTANCE_SYMBOL = '$handleRequestInstance';
112
110
  var METHOD_POOL = Symbol();
@@ -130,7 +128,7 @@ var MethodConfig = (function () {
130
128
  _g.trys.push([1, 3, , 4]);
131
129
  parsedBody_1 = _.attempt(function () { return JSON.parse((callContext === null || callContext === void 0 ? void 0 : callContext.rawBody) || ''); });
132
130
  input = _.attempt(function () { return (parsedBody_1 instanceof Error ? undefined : inputSchema.parse(parsedBody_1)); });
133
- if (input instanceof zod_1.ZodError) {
131
+ if (input instanceof utilities_1.ZodError) {
134
132
  throw new common_2.BadRequestException({
135
133
  from: 'request',
136
134
  invalidParams: (_c = (_b = (_a = input === null || input === void 0 ? void 0 : input.issues) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, function (item) { var _a, _b; return (_b = (_a = item === null || item === void 0 ? void 0 : item.path) === null || _a === void 0 ? void 0 : _a.join) === null || _b === void 0 ? void 0 : _b.call(_a, '.'); })) !== null && _c !== void 0 ? _c : [],
@@ -142,7 +140,7 @@ var MethodConfig = (function () {
142
140
  case 2:
143
141
  rawResponse_1 = _g.sent();
144
142
  response = _.attempt(function () { return outputSchema.parse(rawResponse_1); });
145
- if (response instanceof zod_1.ZodError) {
143
+ if (response instanceof utilities_1.ZodError) {
146
144
  throw new common_2.BadRequestException({
147
145
  from: 'response',
148
146
  invalidParams: (_f = (_e = (_d = response === null || response === void 0 ? void 0 : response.issues) === null || _d === void 0 ? void 0 : _d.map) === null || _e === void 0 ? void 0 : _e.call(_d, function (item) { var _a, _b; return (_b = (_a = item === null || item === void 0 ? void 0 : item.path) === null || _a === void 0 ? void 0 : _a.join) === null || _b === void 0 ? void 0 : _b.call(_a, '.'); })) !== null && _f !== void 0 ? _f : [],
@@ -213,7 +211,7 @@ var MethodPool = (function () {
213
211
  required: true,
214
212
  content: {
215
213
  'application/json': {
216
- schema: (0, zod_openapi_1.createSchema)(config.options.inputSchema).schema,
214
+ schema: config.options.inputSchema,
217
215
  },
218
216
  },
219
217
  },
@@ -221,10 +219,12 @@ var MethodPool = (function () {
221
219
  '200': {
222
220
  description: 'Response for method ' + name,
223
221
  content: {
224
- 'application/json': (0, zod_openapi_1.createSchema)(zod_1.z.object({
225
- data: config.options.outputSchema,
226
- token: zod_1.z.string().nullable(),
227
- })),
222
+ 'application/json': utilities_1.z
223
+ .object({
224
+ data: config.options.outputSchema.toJSONSchema(),
225
+ token: utilities_1.z.string().nullable(),
226
+ })
227
+ .toJSONSchema(),
228
228
  },
229
229
  },
230
230
  },
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@open-norantec/herbal",
3
- "version": "1.0.2",
3
+ "version": "2.0.0-alpha.0",
4
4
  "description": "Herbal is a builder and toolchain for Nest.js applications",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
8
8
  "build": "rimraf dist && tsc -b",
9
- "postinstall": "node ./bin/herbal-patch.js"
9
+ "postinstall": "node ./bin/herbal-patch.js",
10
+ "upgrade": "npm i @open-norantec/forge@latest -S && npm i @open-norantec/utilities@latest -D"
10
11
  },
11
12
  "repository": {
12
13
  "type": "git",
@@ -31,15 +32,16 @@
31
32
  },
32
33
  "homepage": "https://github.com/norantec/herbal#readme",
33
34
  "peerDependencies": {
35
+ "@open-norantec/utilities": ">= 2.0.0",
34
36
  "express": ">=4.0.0 <5.0.0",
35
37
  "typescript": ">=5.1.0 <5.2.0"
36
38
  },
37
39
  "dependencies": {
38
40
  "@nestjs/common": "^10.0.0",
39
41
  "@nestjs/core": "^10.4.19",
42
+ "@nestjs/platform-express": "^10.4.22",
40
43
  "@nestjs/sequelize": "^10.0.1",
41
- "@open-norantec/forge": "^2.0.0",
42
- "@open-norantec/utilities": "^1.0.0",
44
+ "@open-norantec/forge": "^3.0.0-alpha.2",
43
45
  "commander": "^12.1.0",
44
46
  "fs-extra": "^11.3.4",
45
47
  "json-schema-to-typescript": "^15.0.4",
@@ -53,11 +55,10 @@
53
55
  "sequelize-typescript": "^2.1.5",
54
56
  "type-fest": "^4.41.0",
55
57
  "typescript": ">=5.1.0 <5.2.0",
56
- "uuid": "^11.1.0",
57
- "zod": "^3.25.67",
58
- "zod-openapi": "4.2.4"
58
+ "uuid": "^11.1.0"
59
59
  },
60
60
  "devDependencies": {
61
+ "@open-norantec/utilities": "^2.0.2",
61
62
  "@types/express": "^5.0.3",
62
63
  "@types/fs-extra": "^11.0.4",
63
64
  "@types/lodash": "^4.17.16",
@@ -65,6 +66,7 @@
65
66
  "cross-env": "^7.0.3",
66
67
  "eslint": "^8.0.0",
67
68
  "express": "^4.21.2",
69
+ "openapi3-ts": "^4.5.0",
68
70
  "rimraf": "^6.0.1",
69
71
  "ts-node": "^10.0.0"
70
72
  }