@atls/nestjs-typesense 0.0.11 → 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 +25 -0
- package/dist/collections/typesense-colletctions.creator.js +4 -1
- package/dist/decorators/field.decorator.d.ts +1 -1
- package/dist/decorators/schema.decorator.js +8 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/metadata/typesense.metadata-accessor.d.ts +2 -2
- package/dist/metadata/typesense.metadata-accessor.js +13 -15
- package/dist/metadata/typesense.metadata-explorer.js +6 -2
- package/dist/metadata/typesense.metadata-registry.d.ts +1 -1
- package/dist/module/index.d.ts +1 -1
- package/dist/module/index.js +0 -1
- package/dist/module/typesense-module.interface.d.ts +4 -2
- package/dist/module/typesense.module.js +5 -1
- package/package.json +1 -1
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
|
|
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
|
|
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) =>
|
|
6
|
-
name
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
package/dist/index.js
CHANGED
|
@@ -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<
|
|
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<
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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 ||
|
|
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
|
-
|
|
44
|
+
const constructor = instance.constructor;
|
|
45
|
+
this.metadataRegistry.addSchema(constructor, metadata);
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
};
|
package/dist/module/index.d.ts
CHANGED
package/dist/module/index.js
CHANGED
|
@@ -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<
|
|
25
|
-
inject?: Array<
|
|
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: [
|
|
64
|
+
inject: [injectTarget],
|
|
61
65
|
};
|
|
62
66
|
}
|
|
63
67
|
};
|