@atls/nestjs-typesense 0.0.10 → 0.0.12

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
+
@@ -1,4 +1,4 @@
1
- import { OnModuleInit } from '@nestjs/common';
1
+ import type { OnModuleInit } from '@nestjs/common';
2
2
  import { Client } from 'typesense';
3
3
  import { TypesenseMetadataRegistry } from '../metadata/index.js';
4
4
  export declare class TypesenseCollectionsCreator implements OnModuleInit {
@@ -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
  }
@@ -4,6 +4,6 @@ export interface FieldMetadata {
4
4
  index?: boolean;
5
5
  optional?: boolean;
6
6
  }
7
- export type FieldType = 'auto' | 'string' | 'int32' | 'int64' | 'float' | 'bool' | 'geopoint' | 'string[]' | 'int32[]' | 'int64' | 'float[]' | 'bool[]';
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,4 +1,4 @@
1
- import { CollectionFieldSchema } from 'typesense/lib/Typesense/Collection.js';
1
+ import type { CollectionFieldSchema } from 'typesense/lib/Typesense/Collection.js';
2
2
  export interface Schema {
3
3
  name: string;
4
4
  defaultSortingField: string;
@@ -1,7 +1,9 @@
1
+ import type { Schema } from './schema.metadata.js';
1
2
  import { Reflector } from '@nestjs/core';
2
- import { Schema } from './schema.metadata.js';
3
+ type Constructor<T> = new (...args: Array<unknown>) => T;
3
4
  export declare class TypesenseMetadataAccessor {
4
5
  private readonly reflector;
5
6
  constructor(reflector: Reflector);
6
- getTypesenseMetadata(target: any): Schema | undefined;
7
+ getTypesenseMetadata(target: Constructor<unknown> | object): Schema | undefined;
7
8
  }
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([
@@ -1,4 +1,4 @@
1
- import { OnModuleInit } from '@nestjs/common';
1
+ import type { OnModuleInit } from '@nestjs/common';
2
2
  import { DiscoveryService } from '@nestjs/core';
3
3
  import { TypesenseMetadataAccessor } from './typesense.metadata-accessor.js';
4
4
  import { TypesenseMetadataRegistry } from './typesense.metadata-registry.js';
@@ -10,5 +10,5 @@ export declare class TypesenseMetadataExplorer implements OnModuleInit {
10
10
  constructor(discoveryService: DiscoveryService, metadataAccessor: TypesenseMetadataAccessor, metadataRegistry: TypesenseMetadataRegistry);
11
11
  onModuleInit(): void;
12
12
  explore(): void;
13
- lookupSchema(instance: any): void;
13
+ lookupSchema(instance: object): void;
14
14
  }
@@ -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
- import { Schema } from './schema.metadata.js';
2
- type Constructor = new (...args: any[]) => {};
1
+ import type { Schema } from './schema.metadata.js';
2
+ type Constructor = new (...args: Array<unknown>) => object;
3
3
  export declare class TypesenseMetadataRegistry {
4
4
  private logger;
5
5
  private schemas;
@@ -12,7 +12,7 @@ let TypesenseMetadataRegistry = TypesenseMetadataRegistry_1 = class TypesenseMet
12
12
  schemas = new Map();
13
13
  addSchema(target, schema) {
14
14
  if (this.schemas.has(target)) {
15
- this.logger.warn(`Schema ${target} already exists`);
15
+ this.logger.warn(`Schema ${target.toString()} already exists`);
16
16
  }
17
17
  this.schemas.set(target, schema);
18
18
  }
@@ -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,6 +1,8 @@
1
- import { ModuleMetadata } from '@nestjs/common/interfaces';
2
- import { Type } from '@nestjs/common/interfaces';
3
- import { LogLevelDesc } from 'loglevel';
1
+ import type { ModuleMetadata } from '@nestjs/common/interfaces';
2
+ import type { Type } from '@nestjs/common/interfaces';
3
+ import type { InjectionToken } from '@nestjs/common/interfaces';
4
+ import type { OptionalFactoryDependency } from '@nestjs/common/interfaces';
5
+ import type { LogLevelDesc } from 'loglevel';
4
6
  export interface TypesenseNodeOptions {
5
7
  host: string;
6
8
  port: number;
@@ -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: any[]) => Promise<TypesenseModuleOptions> | TypesenseModuleOptions;
25
- inject?: any[];
26
+ useFactory?: (...args: Array<unknown>) => Promise<TypesenseModuleOptions> | TypesenseModuleOptions;
27
+ inject?: Array<InjectionToken | OptionalFactoryDependency>;
26
28
  }
@@ -1,6 +1,6 @@
1
- import { DynamicModule } from '@nestjs/common';
2
- import { TypesenseModuleAsyncOptions } from './typesense-module.interface.js';
3
- import { TypesenseModuleOptions } from './typesense-module.interface.js';
1
+ import type { DynamicModule } from '@nestjs/common';
2
+ import type { TypesenseModuleAsyncOptions } from './typesense-module.interface.js';
3
+ import type { TypesenseModuleOptions } from './typesense-module.interface.js';
4
4
  export declare class TypesenseModule {
5
5
  static register(options?: TypesenseModuleOptions): DynamicModule;
6
6
  static registerAsync(options: TypesenseModuleAsyncOptions): DynamicModule;
@@ -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
- useFactory: (optionsFactory) => optionsFactory.createTypesenseOptions(),
60
- inject: [options.useExisting || options.useClass],
63
+ useFactory: async (optionsFactory) => optionsFactory.createTypesenseOptions(),
64
+ inject: [injectTarget],
61
65
  };
62
66
  }
63
67
  };
@@ -1,5 +1,5 @@
1
- import { Provider } from '@nestjs/common';
2
- import { TypesenseModuleOptions } from './typesense-module.interface.js';
3
- export declare const createTypesenseOptionsProvider: (options?: TypesenseModuleOptions) => Provider[];
4
- export declare const createTypesenseProvider: () => Provider[];
5
- export declare const createTypesenseExportsProvider: () => Provider[];
1
+ import type { Provider } from '@nestjs/common';
2
+ import type { TypesenseModuleOptions } from './typesense-module.interface.js';
3
+ export declare const createTypesenseOptionsProvider: (options?: TypesenseModuleOptions) => Array<Provider>;
4
+ export declare const createTypesenseProvider: () => Array<Provider>;
5
+ export declare const createTypesenseExportsProvider: () => Array<Provider>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atls/nestjs-typesense",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "license": "BSD 3-Clause",
5
5
  "type": "module",
6
6
  "exports": {