hide-a-bed 7.1.2 → 7.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.
@@ -198,28 +198,21 @@ const RequestOptions = zod.z.strictObject({
198
198
 
199
199
  //#endregion
200
200
  //#region schema/config.mts
201
- const anyArgs = zod.z.array(zod.z.any());
202
- const LoggerSchema = zod.z.object({
203
- error: zod.z.function({
204
- input: anyArgs,
205
- output: zod.z.void()
206
- }).optional(),
207
- warn: zod.z.function({
208
- input: anyArgs,
209
- output: zod.z.void()
210
- }).optional(),
211
- info: zod.z.function({
212
- input: anyArgs,
213
- output: zod.z.void()
214
- }).optional(),
215
- debug: zod.z.function({
216
- input: anyArgs,
217
- output: zod.z.void()
218
- }).optional()
219
- }).or(zod.z.function({
220
- input: anyArgs,
221
- output: zod.z.void()
222
- }));
201
+ const loggerLevels = [
202
+ "error",
203
+ "warn",
204
+ "info",
205
+ "debug"
206
+ ];
207
+ const isLoggerMethod = (value) => typeof value === "function";
208
+ const LoggerSchema = zod.z.custom((value) => {
209
+ if (isLoggerMethod(value)) return true;
210
+ if (value === null || typeof value !== "object") return false;
211
+ return loggerLevels.every((level) => {
212
+ const method = value[level];
213
+ return method === void 0 || isLoggerMethod(method);
214
+ });
215
+ }, { message: "logger must be a function or object with optional error, warn, info, and debug methods" });
223
216
  const CouchAuth = zod.z.strictObject({
224
217
  username: zod.z.string().describe("basic auth username for CouchDB requests"),
225
218
  password: zod.z.string().describe("basic auth password for CouchDB requests")
@@ -166,28 +166,21 @@ const RequestOptions = z$1.strictObject({
166
166
 
167
167
  //#endregion
168
168
  //#region schema/config.mts
169
- const anyArgs = z$1.array(z$1.any());
170
- const LoggerSchema = z$1.object({
171
- error: z$1.function({
172
- input: anyArgs,
173
- output: z$1.void()
174
- }).optional(),
175
- warn: z$1.function({
176
- input: anyArgs,
177
- output: z$1.void()
178
- }).optional(),
179
- info: z$1.function({
180
- input: anyArgs,
181
- output: z$1.void()
182
- }).optional(),
183
- debug: z$1.function({
184
- input: anyArgs,
185
- output: z$1.void()
186
- }).optional()
187
- }).or(z$1.function({
188
- input: anyArgs,
189
- output: z$1.void()
190
- }));
169
+ const loggerLevels = [
170
+ "error",
171
+ "warn",
172
+ "info",
173
+ "debug"
174
+ ];
175
+ const isLoggerMethod = (value) => typeof value === "function";
176
+ const LoggerSchema = z$1.custom((value) => {
177
+ if (isLoggerMethod(value)) return true;
178
+ if (value === null || typeof value !== "object") return false;
179
+ return loggerLevels.every((level) => {
180
+ const method = value[level];
181
+ return method === void 0 || isLoggerMethod(method);
182
+ });
183
+ }, { message: "logger must be a function or object with optional error, warn, info, and debug methods" });
191
184
  const CouchAuth = z$1.strictObject({
192
185
  username: z$1.string().describe("basic auth username for CouchDB requests"),
193
186
  password: z$1.string().describe("basic auth password for CouchDB requests")
@@ -27,10 +27,7 @@ const createNoopLogger = (): Logger => ({
27
27
  debug: noop
28
28
  })
29
29
 
30
- const bindLoggerMethod = (
31
- logger: Partial<Logger>,
32
- level: keyof Logger
33
- ): LoggerMethod => {
30
+ const bindLoggerMethod = (logger: Partial<Logger>, level: keyof Logger): LoggerMethod => {
34
31
  const method = logger[level]
35
32
  return typeof method === 'function' ? method.bind(logger) : noop
36
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hide-a-bed",
3
- "version": "7.1.2",
3
+ "version": "7.1.3",
4
4
  "description": "An abstraction over couchdb calls that includes easy mock/stubs with pouchdb",
5
5
  "keywords": [
6
6
  "couchdb",
package/schema/config.mts CHANGED
@@ -2,16 +2,35 @@ import { z } from 'zod'
2
2
  import type { StandardSchemaV1 } from '../types/standard-schema.ts'
3
3
  import { RequestOptions } from './request.mts'
4
4
 
5
- const anyArgs = z.array(z.any())
5
+ type LoggerMethod = (...args: unknown[]) => void
6
+ type ObjectLogger = Partial<Record<'error' | 'warn' | 'info' | 'debug', LoggerMethod>>
7
+ type FunctionLogger = (level: keyof ObjectLogger, ...args: unknown[]) => void
8
+ type ConfigLogger = ObjectLogger | FunctionLogger
6
9
 
7
- const LoggerSchema = z
8
- .object({
9
- error: z.function({ input: anyArgs, output: z.void() }).optional(),
10
- warn: z.function({ input: anyArgs, output: z.void() }).optional(),
11
- info: z.function({ input: anyArgs, output: z.void() }).optional(),
12
- debug: z.function({ input: anyArgs, output: z.void() }).optional()
13
- })
14
- .or(z.function({ input: anyArgs, output: z.void() }))
10
+ const loggerLevels = ['error', 'warn', 'info', 'debug'] as const
11
+
12
+ const isLoggerMethod = (value: unknown): value is LoggerMethod => typeof value === 'function'
13
+
14
+ const LoggerSchema = z.custom<ConfigLogger>(
15
+ value => {
16
+ if (isLoggerMethod(value)) {
17
+ return true
18
+ }
19
+
20
+ if (value === null || typeof value !== 'object') {
21
+ return false
22
+ }
23
+
24
+ return loggerLevels.every(level => {
25
+ const method = (value as Record<string, unknown>)[level]
26
+ return method === undefined || isLoggerMethod(method)
27
+ })
28
+ },
29
+ {
30
+ message:
31
+ 'logger must be a function or object with optional error, warn, info, and debug methods'
32
+ }
33
+ )
15
34
 
16
35
  export const CouchAuth = z.strictObject({
17
36
  username: z.string().describe('basic auth username for CouchDB requests'),
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.mts","sourceRoot":"","sources":["../../../../impl/utils/logger.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAE/D,KAAK,YAAY,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEhD,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,YAAY,CAAA;IACnB,IAAI,EAAE,YAAY,CAAA;IAClB,IAAI,EAAE,YAAY,CAAA;IAClB,KAAK,EAAE,YAAY,CAAA;CACpB,CAAA;AA4BD,wBAAgB,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAgC7D"}
1
+ {"version":3,"file":"logger.d.mts","sourceRoot":"","sources":["../../../../impl/utils/logger.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAE/D,KAAK,YAAY,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEhD,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,YAAY,CAAA;IACnB,IAAI,EAAE,YAAY,CAAA;IAClB,IAAI,EAAE,YAAY,CAAA;IAClB,KAAK,EAAE,YAAY,CAAA;CACpB,CAAA;AAyBD,wBAAgB,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAgC7D"}
@@ -1,6 +1,10 @@
1
1
  import { z } from 'zod';
2
2
  import type { StandardSchemaV1 } from '../types/standard-schema.ts';
3
3
  import { RequestOptions } from './request.mts';
4
+ type LoggerMethod = (...args: unknown[]) => void;
5
+ type ObjectLogger = Partial<Record<'error' | 'warn' | 'info' | 'debug', LoggerMethod>>;
6
+ type FunctionLogger = (level: keyof ObjectLogger, ...args: unknown[]) => void;
7
+ type ConfigLogger = ObjectLogger | FunctionLogger;
4
8
  export declare const CouchAuth: z.ZodObject<{
5
9
  username: z.ZodString;
6
10
  password: z.ZodString;
@@ -14,12 +18,7 @@ export declare const CouchConfig: z.ZodObject<{
14
18
  bindWithRetry: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
15
19
  couch: z.ZodCustom<string | URL, string | URL>;
16
20
  initialDelay: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
17
- logger: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
18
- error: z.ZodOptional<z.ZodFunction<z.ZodArray<z.ZodAny>, z.ZodVoid>>;
19
- warn: z.ZodOptional<z.ZodFunction<z.ZodArray<z.ZodAny>, z.ZodVoid>>;
20
- info: z.ZodOptional<z.ZodFunction<z.ZodArray<z.ZodAny>, z.ZodVoid>>;
21
- debug: z.ZodOptional<z.ZodFunction<z.ZodArray<z.ZodAny>, z.ZodVoid>>;
22
- }, z.core.$strip>, z.ZodFunction<z.ZodArray<z.ZodAny>, z.ZodVoid>]>>;
21
+ logger: z.ZodOptional<z.ZodCustom<ConfigLogger, ConfigLogger>>;
23
22
  maxRetries: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
24
23
  request: z.ZodOptional<z.ZodType<RequestOptions, RequestOptions, z.core.$ZodTypeInternals<RequestOptions, RequestOptions>>>;
25
24
  throwOnGetNotFound: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
@@ -31,4 +30,5 @@ export type CouchAuth = StandardSchemaV1.InferOutput<typeof CouchAuth>;
31
30
  export type CouchAuthInput = StandardSchemaV1.InferInput<typeof CouchAuth>;
32
31
  export type CouchConfig = StandardSchemaV1.InferOutput<typeof CouchConfig>;
33
32
  export type CouchConfigInput = StandardSchemaV1.InferInput<typeof CouchConfig>;
33
+ export {};
34
34
  //# sourceMappingURL=config.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../../schema/config.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAa9C,eAAO,MAAM,SAAS;;;kBAGpB,CAAA;AAWF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;kBA6BY,CAAA;AAEpC,MAAM,MAAM,SAAS,GAAG,gBAAgB,CAAC,WAAW,CAAC,OAAO,SAAS,CAAC,CAAA;AACtE,MAAM,MAAM,cAAc,GAAG,gBAAgB,CAAC,UAAU,CAAC,OAAO,SAAS,CAAC,CAAA;AAC1E,MAAM,MAAM,WAAW,GAAG,gBAAgB,CAAC,WAAW,CAAC,OAAO,WAAW,CAAC,CAAA;AAC1E,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,UAAU,CAAC,OAAO,WAAW,CAAC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