@open-norantec/utilities 2.9.0 → 2.9.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,8 +24,9 @@ interface AuthenticationMethod<Bindings extends BindingsType, SS extends z.ZodOb
24
24
  }
25
25
  type AuthenticationMethodMap<Bindings extends BindingsType, SS extends z.ZodObject> = Record<string, AuthenticationMethod<Bindings, SS>>;
26
26
  type AuthKey<AMM extends AuthenticationMethodMap<{}, z.ZodObject>> = Extract<keyof AMM, string>;
27
- type HandlerContext<IS extends HTTPBodyType, Bindings extends BindingsType, SS extends z.ZodObject, A extends Array<keyof AuthenticationMethodMap<Bindings, SS>>, HWR> = BaseContext<Bindings, SS> & {
27
+ type HandlerContext<IS extends HTTPBodyType, Bindings extends BindingsType, SS extends z.ZodObject, A extends Array<keyof AuthenticationMethodMap<Bindings, SS>>, HWR, G> = BaseContext<Bindings, SS> & {
28
28
  authentication: A extends [] ? null : A[number];
29
+ globals: G;
29
30
  identifier: string;
30
31
  input: IS extends string ? ReadableStreamDefaultReader<Uint8Array> : z.infer<IS>;
31
32
  wrapped: HWR;
@@ -58,7 +59,7 @@ export declare class HonoUtil {
58
59
  outputSchema: OS;
59
60
  authenticationTypes?: A;
60
61
  operationId?: string;
61
- }, handler: (context: HandlerContext<IS, Bindings, SS, A, HWR>) => Promise<z.infer<OS>>) => void;
62
+ }, handler: (context: HandlerContext<IS, Bindings, SS, A, HWR, G>) => Promise<z.infer<OS>>) => void;
62
63
  getApp: () => Hono<{
63
64
  Bindings: Bindings;
64
65
  }, import("hono/types").BlankSchema, "/">;
@@ -75,6 +75,7 @@ class HonoUtil {
75
75
  paths: {},
76
76
  }, _.omit(openAPIObject, ['paths']));
77
77
  const globals = onAppInitialized === null || onAppInitialized === void 0 ? void 0 : onAppInitialized(hookContext);
78
+ const getGlobals = () => (_.isObject(globals) ? Object.assign({}, globals) : globals);
78
79
  Object.entries(config).forEach(([pathname, { inputSchema, outputSchema, operationId, authenticationTypes, handler }]) => {
79
80
  openAPIDocument.paths[`${openAPIPrefix}${pathname}`.replace(/^\/+/g, '/')] = {
80
81
  post: {
@@ -109,7 +110,8 @@ class HonoUtil {
109
110
  },
110
111
  };
111
112
  app.post(pathname, (c) => __awaiter(this, void 0, void 0, function* () {
112
- const wrapped = (yield Promise.resolve(onBeforeHandling === null || onBeforeHandling === void 0 ? void 0 : onBeforeHandling(Object.assign(Object.assign({}, hookContext), { globals: globals }))));
113
+ const wrapped = (yield Promise.resolve(onBeforeHandling === null || onBeforeHandling === void 0 ? void 0 : onBeforeHandling(Object.assign(Object.assign({}, hookContext), { globals: getGlobals() }))));
114
+ const getWrapped = () => (_.isObject(wrapped) ? Object.assign({}, wrapped) : wrapped);
113
115
  const input = typeof inputSchema === 'string' ? c.req.raw.body.getReader() : inputSchema.parse(yield c.req.json());
114
116
  const headers = c.req.header();
115
117
  const baseContext = {
@@ -152,11 +154,11 @@ class HonoUtil {
152
154
  return c.json({ error: authenticateResult.message }, authenticateResult instanceof StatusError ? authenticateResult.status : 400);
153
155
  }
154
156
  const { authentication, authenticationValue } = authenticateResult;
155
- let output = yield attempt_util_class_1.AttemptUtil.execPromise(handler(Object.assign({ input, authentication: authentication, identifier: authenticationValue, wrapped: wrapped }, baseContext)));
157
+ let output = yield attempt_util_class_1.AttemptUtil.execPromise(handler(Object.assign({ input, authentication: authentication, identifier: authenticationValue, wrapped: getWrapped(), globals: getGlobals() }, baseContext)));
156
158
  if (!(output instanceof Error) && typeof outputSchema !== 'string') {
157
159
  output = attempt_util_class_1.AttemptUtil.exec(() => outputSchema.parse(output));
158
160
  }
159
- onAfterHandling === null || onAfterHandling === void 0 ? void 0 : onAfterHandling(Object.assign(Object.assign(Object.assign({}, hookContext), baseContext), { wrapped: wrapped, authentication: authentication, identifier: authenticationValue, globals: globals }), output instanceof Error ? output : null);
161
+ onAfterHandling === null || onAfterHandling === void 0 ? void 0 : onAfterHandling(Object.assign(Object.assign(Object.assign({}, hookContext), baseContext), { wrapped: getWrapped(), authentication: authentication, identifier: authenticationValue, globals: getGlobals() }), output instanceof Error ? output : null);
160
162
  return typeof outputSchema === 'string'
161
163
  ? c.body(output, 200, { 'Content-Type': outputSchema })
162
164
  : c.json(output instanceof Error ? { error: output.message } : { data: output }, output instanceof Error ? (output instanceof StatusError ? output.status : 500) : 200);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-norantec/utilities",
3
- "version": "2.9.0",
3
+ "version": "2.9.2",
4
4
  "description": "NoranTec Utilities",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {