@atls/nestjs-typesense 0.0.11 → 0.0.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+
2
+
3
+ ## [0.0.12](https://github.com/atls/nestjs/compare/@atls/nestjs-typesense@0.0.11...@atls/nestjs-typesense@0.0.12) (2025-12-31)
4
+
5
+
6
+
7
+
8
+
9
+
10
+ ## 0.0.11 (2025-12-31)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+
16
+ * **packages:** linter errors ([204ce22](https://github.com/atls/nestjs/commit/204ce229e375b09ffd69d93e47c08bd1d1fbea1b))
17
+ * **packages:** tests ([ae0f308](https://github.com/atls/nestjs/commit/ae0f308e695cfe39b4e2d38b6a33be4f7e5a8821))
18
+ * typecheck, build ([1f9ca05](https://github.com/atls/nestjs/commit/1f9ca0533705c5977ccbfd152a59f545d3f01f1c))
19
+
20
+ ### Features
21
+
22
+
23
+ * **common:** bump yarn, trigger release ([#338](https://github.com/atls/nestjs/issues/338)) ([9837d48](https://github.com/atls/nestjs/commit/9837d482f75928a3ac132d0306ab6de04d8a04b9))
24
+
25
+
@@ -29,7 +29,10 @@ let TypesenseCollectionsCreator = TypesenseCollectionsCreator_1 = class Typesens
29
29
  await this.typesense.collections(schema.name).retrieve();
30
30
  }
31
31
  catch (error) {
32
- if (error.httpStatus === 404) {
32
+ if (error &&
33
+ typeof error === 'object' &&
34
+ 'httpStatus' in error &&
35
+ error.httpStatus === 404) {
33
36
  await this.typesense.collections().create(schema);
34
37
  }
35
38
  }
@@ -6,4 +6,4 @@ export interface FieldMetadata {
6
6
  }
7
7
  export type FieldType = 'auto' | 'bool' | 'bool[]' | 'float' | 'float[]' | 'geopoint' | 'int32' | 'int32[]' | 'int64' | 'int64[]' | 'string' | 'string[]';
8
8
  export declare const FIELD_METADATA = "__fieldMetadata__";
9
- export declare const Field: (type: FieldType, options?: FieldMetadata) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol | undefined, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void;
9
+ export declare const Field: (type: FieldType, options?: FieldMetadata) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -2,8 +2,11 @@ import { SetMetadata } from '@nestjs/common';
2
2
  import { applyDecorators } from '@nestjs/common';
3
3
  import decamelize from 'decamelize';
4
4
  export const SCHEMA_METADATA = '__schemaMetadata__';
5
- export const Schema = (options = {}) => applyDecorators((target, key, descriptor) => SetMetadata(SCHEMA_METADATA, {
6
- name: options.name ||
7
- decamelize(target.name, { separator: '-', preserveConsecutiveUppercase: false }),
8
- defaultSortingField: options.defaultSortingField,
9
- })(target, key, descriptor));
5
+ export const Schema = (options = {}) => applyDecorators((target, key, descriptor) => {
6
+ const targetName = typeof target === 'function' && 'name' in target ? String(target.name) : '';
7
+ return SetMetadata(SCHEMA_METADATA, {
8
+ name: options.name ||
9
+ decamelize(targetName, { separator: '-', preserveConsecutiveUppercase: false }),
10
+ defaultSortingField: options.defaultSortingField,
11
+ })(target, key, descriptor);
12
+ });
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './collections/index.js';
2
- export * from './metadata/index.js';
3
2
  export * from './decorators/index.js';
3
+ export * from './metadata/index.js';
4
4
  export * from './module/index.js';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from "./collections/index.js";
2
- export * from "./metadata/index.js";
3
2
  export * from "./decorators/index.js";
3
+ export * from "./metadata/index.js";
4
4
  export * from "./module/index.js";
@@ -1,9 +1,9 @@
1
1
  import type { Schema } from './schema.metadata.js';
2
2
  import { Reflector } from '@nestjs/core';
3
- type Constructor<T> = new (...args: Array<any>) => T;
3
+ type Constructor<T> = new (...args: Array<unknown>) => T;
4
4
  export declare class TypesenseMetadataAccessor {
5
5
  private readonly reflector;
6
6
  constructor(reflector: Reflector);
7
- getTypesenseMetadata(target: Constructor<any> | object): Schema | undefined;
7
+ getTypesenseMetadata(target: Constructor<unknown> | object): Schema | undefined;
8
8
  }
9
9
  export {};
@@ -17,22 +17,20 @@ let TypesenseMetadataAccessor = class TypesenseMetadataAccessor {
17
17
  this.reflector = reflector;
18
18
  }
19
19
  getTypesenseMetadata(target) {
20
- if (target.constructor) {
21
- const schema = this.reflector.get(SCHEMA_METADATA, target.constructor);
22
- const fields = this.reflector.get(FIELD_METADATA, target.constructor);
23
- if (!schema) {
24
- return undefined;
25
- }
26
- if (!(fields || schema.auto)) {
27
- return undefined;
28
- }
29
- return {
30
- name: schema.name,
31
- defaultSortingField: schema.defaultSortingField,
32
- fields: [...(schema.auto ? [{ name: '.*', type: 'auto' }] : []), ...(fields || [])],
33
- };
20
+ const constructor = typeof target === 'function' ? target : target.constructor;
21
+ const schema = this.reflector.get(SCHEMA_METADATA, constructor);
22
+ const fields = this.reflector.get(FIELD_METADATA, constructor);
23
+ if (!schema) {
24
+ return undefined;
34
25
  }
35
- return undefined;
26
+ if (!(fields || schema.auto)) {
27
+ return undefined;
28
+ }
29
+ return {
30
+ name: schema.name,
31
+ defaultSortingField: schema.defaultSortingField,
32
+ fields: [...(schema.auto ? [{ name: '.*', type: 'auto' }] : []), ...(fields || [])],
33
+ };
36
34
  }
37
35
  };
38
36
  TypesenseMetadataAccessor = __decorate([
@@ -29,7 +29,10 @@ let TypesenseMetadataExplorer = TypesenseMetadataExplorer_1 = class TypesenseMet
29
29
  explore() {
30
30
  this.discoveryService.getProviders().forEach((wrapper) => {
31
31
  const { instance } = wrapper;
32
- if (!instance || !Object.getPrototypeOf(instance)) {
32
+ if (!instance || (typeof instance !== 'object' && typeof instance !== 'function')) {
33
+ return;
34
+ }
35
+ if (!Object.getPrototypeOf(instance)) {
33
36
  return;
34
37
  }
35
38
  this.lookupSchema(instance);
@@ -38,7 +41,8 @@ let TypesenseMetadataExplorer = TypesenseMetadataExplorer_1 = class TypesenseMet
38
41
  lookupSchema(instance) {
39
42
  const metadata = this.metadataAccessor.getTypesenseMetadata(instance);
40
43
  if (metadata) {
41
- this.metadataRegistry.addSchema(instance.constructor, metadata);
44
+ const constructor = instance.constructor;
45
+ this.metadataRegistry.addSchema(constructor, metadata);
42
46
  }
43
47
  }
44
48
  };
@@ -1,5 +1,5 @@
1
1
  import type { Schema } from './schema.metadata.js';
2
- type Constructor = new (...args: Array<any>) => object;
2
+ type Constructor = new (...args: Array<unknown>) => object;
3
3
  export declare class TypesenseMetadataRegistry {
4
4
  private logger;
5
5
  private schemas;
@@ -1,3 +1,3 @@
1
- export * from './typesense-module.interface.js';
1
+ export type * from './typesense-module.interface.js';
2
2
  export * from './typesense.constants.js';
3
3
  export * from './typesense.module.js';
@@ -1,3 +1,2 @@
1
- export * from "./typesense-module.interface.js";
2
1
  export * from "./typesense.constants.js";
3
2
  export * from "./typesense.module.js";
@@ -1,5 +1,7 @@
1
1
  import type { ModuleMetadata } from '@nestjs/common/interfaces';
2
2
  import type { Type } from '@nestjs/common/interfaces';
3
+ import type { InjectionToken } from '@nestjs/common/interfaces';
4
+ import type { OptionalFactoryDependency } from '@nestjs/common/interfaces';
3
5
  import type { LogLevelDesc } from 'loglevel';
4
6
  export interface TypesenseNodeOptions {
5
7
  host: string;
@@ -21,6 +23,6 @@ export interface TypesenseOptionsFactory {
21
23
  export interface TypesenseModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
22
24
  useExisting?: Type<TypesenseOptionsFactory>;
23
25
  useClass?: Type<TypesenseOptionsFactory>;
24
- useFactory?: (...args: Array<any>) => Promise<TypesenseModuleOptions> | TypesenseModuleOptions;
25
- inject?: Array<any>;
26
+ useFactory?: (...args: Array<unknown>) => Promise<TypesenseModuleOptions> | TypesenseModuleOptions;
27
+ inject?: Array<InjectionToken | OptionalFactoryDependency>;
26
28
  }
@@ -54,10 +54,14 @@ let TypesenseModule = TypesenseModule_1 = class TypesenseModule {
54
54
  inject: options.inject || [],
55
55
  };
56
56
  }
57
+ const injectTarget = options.useExisting ?? options.useClass;
58
+ if (!injectTarget) {
59
+ throw new Error('TypesenseModule requires useExisting, useClass, or useFactory');
60
+ }
57
61
  return {
58
62
  provide: TYPESENSE_MODULE_OPTIONS,
59
63
  useFactory: async (optionsFactory) => optionsFactory.createTypesenseOptions(),
60
- inject: [options.useExisting || options.useClass],
64
+ inject: [injectTarget],
61
65
  };
62
66
  }
63
67
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atls/nestjs-typesense",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "license": "BSD 3-Clause",
5
5
  "type": "module",
6
6
  "exports": {