@danceroutine/tango-resources 1.11.0 → 1.11.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.
- package/dist/chunk-D7D4PA-g.js +13 -0
- package/dist/index-D6sfTSEj.d.ts +902 -0
- package/dist/index.d.ts +12 -23
- package/dist/index.js +96 -152
- package/dist/index.js.map +1 -1
- package/dist/view/index.d.ts +2 -8
- package/dist/view/index.js +2 -3
- package/dist/{view-DUHg6AXl.js → view-C9B5Lln3.js} +151 -59
- package/dist/view-C9B5Lln3.js.map +1 -0
- package/package.json +7 -7
- package/dist/context/RequestContext.d.ts +0 -46
- package/dist/context/index.d.ts +0 -5
- package/dist/filters/FilterSet.d.ts +0 -95
- package/dist/filters/FilterType.d.ts +0 -2
- package/dist/filters/RangeOperator.d.ts +0 -2
- package/dist/filters/index.d.ts +0 -7
- package/dist/filters/inferModelFieldParsers.d.ts +0 -9
- package/dist/filters/internal/InternalFilterLookup.d.ts +0 -15
- package/dist/filters/internal/InternalFilterType.d.ts +0 -7
- package/dist/filters/internal/InternalRangeOperator.d.ts +0 -6
- package/dist/pagination/BasePaginator.d.ts +0 -4
- package/dist/pagination/CursorPaginationInput.d.ts +0 -7
- package/dist/pagination/OffsetPaginationInput.d.ts +0 -7
- package/dist/pagination/PaginatedResponse.d.ts +0 -12
- package/dist/pagination/Paginator.d.ts +0 -21
- package/dist/pagination/index.d.ts +0 -12
- package/dist/paginators/CursorPaginator.d.ts +0 -65
- package/dist/paginators/OffsetPaginator.d.ts +0 -74
- package/dist/paginators/index.d.ts +0 -5
- package/dist/resource/OpenAPIDescription.d.ts +0 -23
- package/dist/resource/ResourceModelLike.d.ts +0 -22
- package/dist/resource/index.d.ts +0 -5
- package/dist/serializer/ModelSerializer.d.ts +0 -67
- package/dist/serializer/Serializer.d.ts +0 -75
- package/dist/serializer/index.d.ts +0 -6
- package/dist/serializer/internal/InternalSerializerRelationKind.d.ts +0 -11
- package/dist/serializer/relation.d.ts +0 -45
- package/dist/view/APIView.d.ts +0 -26
- package/dist/view/GenericAPIView.d.ts +0 -60
- package/dist/view/generics/CreateAPIView.d.ts +0 -10
- package/dist/view/generics/ListAPIView.d.ts +0 -10
- package/dist/view/generics/ListCreateAPIView.d.ts +0 -11
- package/dist/view/generics/RetrieveAPIView.d.ts +0 -10
- package/dist/view/generics/RetrieveDestroyAPIView.d.ts +0 -11
- package/dist/view/generics/RetrieveUpdateAPIView.d.ts +0 -12
- package/dist/view/generics/RetrieveUpdateDestroyAPIView.d.ts +0 -13
- package/dist/view/generics/index.d.ts +0 -10
- package/dist/view/mixins/CreateModelMixin.d.ts +0 -11
- package/dist/view/mixins/DestroyModelMixin.d.ts +0 -11
- package/dist/view/mixins/ListModelMixin.d.ts +0 -11
- package/dist/view/mixins/RetrieveModelMixin.d.ts +0 -11
- package/dist/view/mixins/UpdateModelMixin.d.ts +0 -12
- package/dist/view/mixins/index.d.ts +0 -8
- package/dist/view-DUHg6AXl.js.map +0 -1
- package/dist/viewset/ModelViewSet.d.ts +0 -112
- package/dist/viewset/index.d.ts +0 -5
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import type { ManyToManyRelatedManager } from '@danceroutine/tango-orm';
|
|
3
|
-
import type { ResourceModelLike } from '../resource/ResourceModelLike';
|
|
4
|
-
import { InternalManyToManyReadStrategyKind, InternalManyToManyWriteStrategyKind, InternalSerializerRelationKind } from './internal/InternalSerializerRelationKind';
|
|
5
|
-
type AnyRecord = Record<string, unknown>;
|
|
6
|
-
export type ManyToManyManagerKeys<TRecord extends AnyRecord> = Extract<{
|
|
7
|
-
[K in keyof TRecord]: TRecord[K] extends ManyToManyRelatedManager<AnyRecord> ? K : never;
|
|
8
|
-
}[keyof TRecord], string>;
|
|
9
|
-
export type ManyToManyTargetRow<TRecord extends AnyRecord, TFieldName extends ManyToManyManagerKeys<TRecord>> = TRecord[TFieldName] extends ManyToManyRelatedManager<infer TTarget extends AnyRecord> ? TTarget : never;
|
|
10
|
-
export type ManyToManyPkListStrategy = {
|
|
11
|
-
kind: typeof InternalManyToManyReadStrategyKind.PK_LIST | typeof InternalManyToManyWriteStrategyKind.PK_LIST;
|
|
12
|
-
};
|
|
13
|
-
export type ManyToManyNestedStrategy = {
|
|
14
|
-
kind: typeof InternalManyToManyReadStrategyKind.NESTED;
|
|
15
|
-
schema: z.ZodTypeAny;
|
|
16
|
-
};
|
|
17
|
-
export type ManyToManySlugListStrategy<TTarget extends AnyRecord> = {
|
|
18
|
-
kind: typeof InternalManyToManyWriteStrategyKind.SLUG_LIST;
|
|
19
|
-
model: ResourceModelLike<any, any>;
|
|
20
|
-
lookupField: Extract<keyof TTarget, string>;
|
|
21
|
-
createIfMissing?: boolean;
|
|
22
|
-
buildCreateInput?: (value: string) => Partial<TTarget>;
|
|
23
|
-
};
|
|
24
|
-
export type ManyToManyReadStrategy = ManyToManyPkListStrategy | ManyToManyNestedStrategy;
|
|
25
|
-
export type ManyToManyWriteStrategy<TTarget extends AnyRecord> = ManyToManyPkListStrategy | ManyToManySlugListStrategy<TTarget>;
|
|
26
|
-
export type ManyToManyRelationField<TRecord extends AnyRecord, TFieldName extends ManyToManyManagerKeys<TRecord>> = {
|
|
27
|
-
kind: typeof InternalSerializerRelationKind.MANY_TO_MANY;
|
|
28
|
-
read: ManyToManyReadStrategy;
|
|
29
|
-
write: ManyToManyWriteStrategy<ManyToManyTargetRow<TRecord, TFieldName>>;
|
|
30
|
-
};
|
|
31
|
-
export type ModelSerializerRelationFields<TRecord extends AnyRecord> = Partial<{
|
|
32
|
-
[K in ManyToManyManagerKeys<TRecord>]: ManyToManyRelationField<TRecord, K>;
|
|
33
|
-
}>;
|
|
34
|
-
declare function pkList(): ManyToManyPkListStrategy;
|
|
35
|
-
declare function nested(schema: z.ZodTypeAny): ManyToManyNestedStrategy;
|
|
36
|
-
declare function slugList<TTarget extends AnyRecord>(options: Omit<ManyToManySlugListStrategy<TTarget>, 'kind'>): ManyToManySlugListStrategy<TTarget>;
|
|
37
|
-
declare function manyToMany(config?: Partial<Pick<ManyToManyRelationField<any, any>, 'read' | 'write'>>): ManyToManyRelationField<any, any>;
|
|
38
|
-
export type RelationHelpers = {
|
|
39
|
-
manyToMany: typeof manyToMany;
|
|
40
|
-
pkList: typeof pkList;
|
|
41
|
-
nested: typeof nested;
|
|
42
|
-
slugList: typeof slugList;
|
|
43
|
-
};
|
|
44
|
-
export declare const relation: RelationHelpers;
|
|
45
|
-
export {};
|
package/dist/view/APIView.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { TangoResponse } from '@danceroutine/tango-core';
|
|
2
|
-
import { RequestContext } from '../context/index';
|
|
3
|
-
export type APIViewMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
4
|
-
/**
|
|
5
|
-
* Lightweight class-based request dispatcher for non-model API endpoints.
|
|
6
|
-
*/
|
|
7
|
-
export declare abstract class APIView {
|
|
8
|
-
static readonly BRAND: "tango.resources.api_view";
|
|
9
|
-
readonly __tangoBrand: typeof APIView.BRAND;
|
|
10
|
-
/**
|
|
11
|
-
* Narrow an unknown value to `APIView`.
|
|
12
|
-
*/
|
|
13
|
-
static isAPIView(value: unknown): value is APIView;
|
|
14
|
-
/**
|
|
15
|
-
* Dispatch the request to the handler for the current HTTP method.
|
|
16
|
-
*/
|
|
17
|
-
dispatch(ctx: RequestContext): Promise<TangoResponse>;
|
|
18
|
-
getAllowedMethods(): readonly APIViewMethod[];
|
|
19
|
-
protected get(_ctx: RequestContext): Promise<TangoResponse>;
|
|
20
|
-
protected post(_ctx: RequestContext): Promise<TangoResponse>;
|
|
21
|
-
protected put(_ctx: RequestContext): Promise<TangoResponse>;
|
|
22
|
-
protected patch(_ctx: RequestContext): Promise<TangoResponse>;
|
|
23
|
-
protected delete(_ctx: RequestContext): Promise<TangoResponse>;
|
|
24
|
-
protected httpMethodNotAllowed(): TangoResponse;
|
|
25
|
-
private getMethodHandler;
|
|
26
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { TangoResponse } from '@danceroutine/tango-core';
|
|
2
|
-
import { type ManagerLike, type QuerySet } from '@danceroutine/tango-orm';
|
|
3
|
-
import type { Paginator } from '../pagination/index';
|
|
4
|
-
import { APIView } from './APIView';
|
|
5
|
-
import { RequestContext } from '../context/index';
|
|
6
|
-
import type { FilterSet } from '../filters/index';
|
|
7
|
-
import type { GenericAPIViewOpenAPIDescription } from '../resource/index';
|
|
8
|
-
import type { AnyModelSerializer, SerializerOutput } from '../serializer/index';
|
|
9
|
-
type SearchFieldRef<TModel extends Record<string, unknown>> = Extract<keyof TModel, string> | string;
|
|
10
|
-
export interface GenericAPIViewConfig<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> {
|
|
11
|
-
serializer: TSerializer;
|
|
12
|
-
filters?: FilterSet<TModel>;
|
|
13
|
-
orderingFields?: (keyof TModel)[];
|
|
14
|
-
searchFields?: SearchFieldRef<TModel>[];
|
|
15
|
-
lookupField?: keyof TModel;
|
|
16
|
-
lookupParam?: string;
|
|
17
|
-
paginatorFactory?: (queryset: QuerySet<TModel>) => Paginator<TModel, SerializerOutput<TSerializer>>;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Generic API base class that centralizes query/build/validation helpers.
|
|
21
|
-
*/
|
|
22
|
-
export declare abstract class GenericAPIView<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> extends APIView {
|
|
23
|
-
protected readonly serializerClass: TSerializer;
|
|
24
|
-
protected readonly filters?: FilterSet<TModel>;
|
|
25
|
-
protected readonly orderingFields: readonly (keyof TModel)[];
|
|
26
|
-
protected readonly searchFields: readonly SearchFieldRef<TModel>[];
|
|
27
|
-
protected readonly lookupField?: keyof TModel;
|
|
28
|
-
protected readonly lookupParam: string;
|
|
29
|
-
protected readonly paginatorFactory?: (queryset: QuerySet<TModel>) => Paginator<TModel, SerializerOutput<TSerializer>>;
|
|
30
|
-
private serializer?;
|
|
31
|
-
constructor(config: GenericAPIViewConfig<TModel, TSerializer>);
|
|
32
|
-
/**
|
|
33
|
-
* Return the serializer class that owns this resource contract.
|
|
34
|
-
*/
|
|
35
|
-
getSerializerClass(): TSerializer;
|
|
36
|
-
/**
|
|
37
|
-
* Return the serializer instance for the current resource.
|
|
38
|
-
*/
|
|
39
|
-
getSerializer(): InstanceType<TSerializer>;
|
|
40
|
-
/**
|
|
41
|
-
* Describe the public HTTP contract that this resource contributes to OpenAPI generation.
|
|
42
|
-
*/
|
|
43
|
-
describeOpenAPI(): GenericAPIViewOpenAPIDescription<TModel, TSerializer>;
|
|
44
|
-
protected getManager(): ManagerLike<TModel>;
|
|
45
|
-
protected getOutputSchema(): TSerializer['outputSchema'];
|
|
46
|
-
protected getCreateSchema(): TSerializer['createSchema'];
|
|
47
|
-
protected getUpdateSchema(): TSerializer['updateSchema'];
|
|
48
|
-
protected getLookupField(): keyof TModel;
|
|
49
|
-
protected getLookupValue(ctx: RequestContext): string | null;
|
|
50
|
-
protected getPaginator(queryset: QuerySet<TModel>): Paginator<TModel, SerializerOutput<TSerializer>>;
|
|
51
|
-
protected performList(ctx: RequestContext): Promise<TangoResponse>;
|
|
52
|
-
protected performCreate(ctx: RequestContext): Promise<TangoResponse>;
|
|
53
|
-
protected performRetrieve(ctx: RequestContext): Promise<TangoResponse>;
|
|
54
|
-
protected performUpdate(ctx: RequestContext): Promise<TangoResponse>;
|
|
55
|
-
protected performDestroy(ctx: RequestContext): Promise<TangoResponse>;
|
|
56
|
-
protected handleError(error: unknown): TangoResponse;
|
|
57
|
-
private requireModelMetadata;
|
|
58
|
-
private getLookupFieldFromMetadata;
|
|
59
|
-
}
|
|
60
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { CreateModelMixin } from '../mixins/CreateModelMixin';
|
|
2
|
-
import type { TangoResponse } from '@danceroutine/tango-core';
|
|
3
|
-
import { RequestContext } from '../../context/index';
|
|
4
|
-
import type { AnyModelSerializer } from '../../serializer/index';
|
|
5
|
-
/**
|
|
6
|
-
* Generic API view for endpoints that only support resource creation.
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class CreateAPIView<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> extends CreateModelMixin<TModel, TSerializer> {
|
|
9
|
-
protected post(ctx: RequestContext): Promise<TangoResponse>;
|
|
10
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ListModelMixin } from '../mixins/ListModelMixin';
|
|
2
|
-
import type { TangoResponse } from '@danceroutine/tango-core';
|
|
3
|
-
import { RequestContext } from '../../context/index';
|
|
4
|
-
import type { AnyModelSerializer } from '../../serializer/index';
|
|
5
|
-
/**
|
|
6
|
-
* Generic API view for endpoints that only expose a list operation.
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class ListAPIView<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> extends ListModelMixin<TModel, TSerializer> {
|
|
9
|
-
protected get(ctx: RequestContext): Promise<TangoResponse>;
|
|
10
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { GenericAPIView } from '../GenericAPIView';
|
|
2
|
-
import type { TangoResponse } from '@danceroutine/tango-core';
|
|
3
|
-
import { RequestContext } from '../../context/index';
|
|
4
|
-
import type { AnyModelSerializer } from '../../serializer/index';
|
|
5
|
-
/**
|
|
6
|
-
* Generic API view for collection endpoints that list and create resources.
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class ListCreateAPIView<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> extends GenericAPIView<TModel, TSerializer> {
|
|
9
|
-
protected get(ctx: RequestContext): Promise<TangoResponse>;
|
|
10
|
-
protected post(ctx: RequestContext): Promise<TangoResponse>;
|
|
11
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { RetrieveModelMixin } from '../mixins/RetrieveModelMixin';
|
|
2
|
-
import type { TangoResponse } from '@danceroutine/tango-core';
|
|
3
|
-
import { RequestContext } from '../../context/index';
|
|
4
|
-
import type { AnyModelSerializer } from '../../serializer/index';
|
|
5
|
-
/**
|
|
6
|
-
* Generic API view for endpoints that retrieve a single resource by lookup.
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class RetrieveAPIView<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> extends RetrieveModelMixin<TModel, TSerializer> {
|
|
9
|
-
protected get(ctx: RequestContext): Promise<TangoResponse>;
|
|
10
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { GenericAPIView } from '../GenericAPIView';
|
|
2
|
-
import type { TangoResponse } from '@danceroutine/tango-core';
|
|
3
|
-
import { RequestContext } from '../../context/index';
|
|
4
|
-
import type { AnyModelSerializer } from '../../serializer/index';
|
|
5
|
-
/**
|
|
6
|
-
* Generic API view for endpoints that retrieve and delete a single resource.
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class RetrieveDestroyAPIView<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> extends GenericAPIView<TModel, TSerializer> {
|
|
9
|
-
protected get(ctx: RequestContext): Promise<TangoResponse>;
|
|
10
|
-
protected delete(ctx: RequestContext): Promise<TangoResponse>;
|
|
11
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { GenericAPIView } from '../GenericAPIView';
|
|
2
|
-
import type { TangoResponse } from '@danceroutine/tango-core';
|
|
3
|
-
import { RequestContext } from '../../context/index';
|
|
4
|
-
import type { AnyModelSerializer } from '../../serializer/index';
|
|
5
|
-
/**
|
|
6
|
-
* Generic API view for endpoints that retrieve and update a single resource.
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class RetrieveUpdateAPIView<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> extends GenericAPIView<TModel, TSerializer> {
|
|
9
|
-
protected get(ctx: RequestContext): Promise<TangoResponse>;
|
|
10
|
-
protected put(ctx: RequestContext): Promise<TangoResponse>;
|
|
11
|
-
protected patch(ctx: RequestContext): Promise<TangoResponse>;
|
|
12
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { GenericAPIView } from '../GenericAPIView';
|
|
2
|
-
import type { TangoResponse } from '@danceroutine/tango-core';
|
|
3
|
-
import { RequestContext } from '../../context/index';
|
|
4
|
-
import type { AnyModelSerializer } from '../../serializer/index';
|
|
5
|
-
/**
|
|
6
|
-
* Generic API view for full detail endpoints that retrieve, update, and delete.
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class RetrieveUpdateDestroyAPIView<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> extends GenericAPIView<TModel, TSerializer> {
|
|
9
|
-
protected get(ctx: RequestContext): Promise<TangoResponse>;
|
|
10
|
-
protected put(ctx: RequestContext): Promise<TangoResponse>;
|
|
11
|
-
protected patch(ctx: RequestContext): Promise<TangoResponse>;
|
|
12
|
-
protected delete(ctx: RequestContext): Promise<TangoResponse>;
|
|
13
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Domain boundary barrel: centralizes this subdomain's public contract.
|
|
3
|
-
*/
|
|
4
|
-
export { ListAPIView } from './ListAPIView';
|
|
5
|
-
export { CreateAPIView } from './CreateAPIView';
|
|
6
|
-
export { RetrieveAPIView } from './RetrieveAPIView';
|
|
7
|
-
export { ListCreateAPIView } from './ListCreateAPIView';
|
|
8
|
-
export { RetrieveUpdateAPIView } from './RetrieveUpdateAPIView';
|
|
9
|
-
export { RetrieveDestroyAPIView } from './RetrieveDestroyAPIView';
|
|
10
|
-
export { RetrieveUpdateDestroyAPIView } from './RetrieveUpdateDestroyAPIView';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { GenericAPIView } from '../GenericAPIView';
|
|
2
|
-
import type { TangoResponse } from '@danceroutine/tango-core';
|
|
3
|
-
import { RequestContext } from '../../context/index';
|
|
4
|
-
import type { AnyModelSerializer } from '../../serializer/index';
|
|
5
|
-
/**
|
|
6
|
-
* Mixin that wires `POST` requests to the generic create implementation.
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class CreateModelMixin<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> extends GenericAPIView<TModel, TSerializer> {
|
|
9
|
-
protected create(ctx: RequestContext): Promise<TangoResponse>;
|
|
10
|
-
protected post(ctx: RequestContext): Promise<TangoResponse>;
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { GenericAPIView } from '../GenericAPIView';
|
|
2
|
-
import type { TangoResponse } from '@danceroutine/tango-core';
|
|
3
|
-
import { RequestContext } from '../../context/index';
|
|
4
|
-
import type { AnyModelSerializer } from '../../serializer/index';
|
|
5
|
-
/**
|
|
6
|
-
* Mixin that wires `DELETE` requests to the generic destroy implementation.
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class DestroyModelMixin<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> extends GenericAPIView<TModel, TSerializer> {
|
|
9
|
-
protected destroy(ctx: RequestContext): Promise<TangoResponse>;
|
|
10
|
-
protected delete(ctx: RequestContext): Promise<TangoResponse>;
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { GenericAPIView } from '../GenericAPIView';
|
|
2
|
-
import type { TangoResponse } from '@danceroutine/tango-core';
|
|
3
|
-
import { RequestContext } from '../../context/index';
|
|
4
|
-
import type { AnyModelSerializer } from '../../serializer/index';
|
|
5
|
-
/**
|
|
6
|
-
* Mixin that wires `GET` requests to the generic list implementation.
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class ListModelMixin<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> extends GenericAPIView<TModel, TSerializer> {
|
|
9
|
-
protected list(ctx: RequestContext): Promise<TangoResponse>;
|
|
10
|
-
protected get(ctx: RequestContext): Promise<TangoResponse>;
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { GenericAPIView } from '../GenericAPIView';
|
|
2
|
-
import type { TangoResponse } from '@danceroutine/tango-core';
|
|
3
|
-
import { RequestContext } from '../../context/index';
|
|
4
|
-
import type { AnyModelSerializer } from '../../serializer/index';
|
|
5
|
-
/**
|
|
6
|
-
* Mixin that wires `GET` requests to the generic retrieve implementation.
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class RetrieveModelMixin<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> extends GenericAPIView<TModel, TSerializer> {
|
|
9
|
-
protected retrieve(ctx: RequestContext): Promise<TangoResponse>;
|
|
10
|
-
protected get(ctx: RequestContext): Promise<TangoResponse>;
|
|
11
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { GenericAPIView } from '../GenericAPIView';
|
|
2
|
-
import type { TangoResponse } from '@danceroutine/tango-core';
|
|
3
|
-
import { RequestContext } from '../../context/index';
|
|
4
|
-
import type { AnyModelSerializer } from '../../serializer/index';
|
|
5
|
-
/**
|
|
6
|
-
* Mixin that wires `PUT` and `PATCH` requests to the generic update implementation.
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class UpdateModelMixin<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> extends GenericAPIView<TModel, TSerializer> {
|
|
9
|
-
protected update(ctx: RequestContext): Promise<TangoResponse>;
|
|
10
|
-
protected put(ctx: RequestContext): Promise<TangoResponse>;
|
|
11
|
-
protected patch(ctx: RequestContext): Promise<TangoResponse>;
|
|
12
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Domain boundary barrel: centralizes this subdomain's public contract.
|
|
3
|
-
*/
|
|
4
|
-
export { ListModelMixin } from './ListModelMixin';
|
|
5
|
-
export { CreateModelMixin } from './CreateModelMixin';
|
|
6
|
-
export { RetrieveModelMixin } from './RetrieveModelMixin';
|
|
7
|
-
export { UpdateModelMixin } from './UpdateModelMixin';
|
|
8
|
-
export { DestroyModelMixin } from './DestroyModelMixin';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"view-DUHg6AXl.js","names":["rows: readonly T[] | QueryResult<T>","OffsetPaginationInput: z.ZodType<OffsetPaginationInputValue>","results: T[]","pageNumber: number","perPage: number","totalCount?: number","value: unknown","queryset: QuerySet<T>","params: TangoQueryParams","results: readonly TResult[] | QueryResult<TResult>","context?: { totalCount?: number; params?: TangoQueryParams }","response: OffsetPaginatedResponse<TResult>","params?: TangoQueryParams","queryset: QuerySet<T, TBaseResult, TSourceModel, THydrated>","page: number","offset: number","raw: string | string[]","model: ResourceModelLike<T>","parsers: Partial<Record<keyof T, FilterValueParser>>","value: unknown","ctx: RequestContext","allowed: APIViewMethod[]","_ctx: RequestContext","method: APIViewMethod","method: string","config: GenericAPIViewConfig<TModel, TSerializer>","ctx: RequestContext","queryset: QuerySet<TModel>","searchFilters: FilterInput<TModel>[]","error: unknown","model: ResourceModelLike<TModel> & {\n metadata: NonNullable<ResourceModelLike<TModel>['metadata']>;\n }","ctx: RequestContext","ctx: RequestContext","ctx: RequestContext","ctx: RequestContext","ctx: RequestContext","ctx: RequestContext","ctx: RequestContext","ctx: RequestContext","ctx: RequestContext","ctx: RequestContext","ctx: RequestContext","ctx: RequestContext"],"sources":["../src/pagination/BasePaginator.ts","../src/pagination/OffsetPaginationInput.ts","../src/paginators/OffsetPaginator.ts","../src/filters/inferModelFieldParsers.ts","../src/view/APIView.ts","../src/view/GenericAPIView.ts","../src/view/mixins/ListModelMixin.ts","../src/view/mixins/CreateModelMixin.ts","../src/view/mixins/RetrieveModelMixin.ts","../src/view/mixins/UpdateModelMixin.ts","../src/view/mixins/DestroyModelMixin.ts","../src/view/generics/ListAPIView.ts","../src/view/generics/CreateAPIView.ts","../src/view/generics/RetrieveAPIView.ts","../src/view/generics/ListCreateAPIView.ts","../src/view/generics/RetrieveUpdateAPIView.ts","../src/view/generics/RetrieveDestroyAPIView.ts","../src/view/generics/RetrieveUpdateDestroyAPIView.ts","../src/view/index.ts"],"sourcesContent":["import { QueryResult } from '@danceroutine/tango-orm';\n\nexport abstract class BasePaginator {\n protected resolveQueryResultRows<T>(rows: readonly T[] | QueryResult<T>): T[] {\n if (QueryResult.isQueryResult<T>(rows)) {\n return rows.toArray();\n }\n return [...rows];\n }\n}\n","import { z } from 'zod';\n\nexport type OffsetPaginationInputValue = {\n limit: number;\n offset: number;\n page?: number;\n};\n\nexport const OffsetPaginationInput: z.ZodType<OffsetPaginationInputValue> = z.object({\n limit: z.coerce\n .number()\n .int()\n .min(1)\n .default(25)\n .transform((value) => Math.min(value, 100)),\n offset: z.coerce.number().int().min(0).default(0),\n page: z.coerce.number().int().min(1).optional(),\n});\n","import { TangoQueryParams } from '@danceroutine/tango-core';\nimport type { QueryResult, QuerySet } from '@danceroutine/tango-orm';\nimport { BasePaginator } from '../pagination/BasePaginator';\nimport type { Paginator, Page } from '../pagination/Paginator';\nimport type { OffsetPaginatedResponse } from '../pagination/PaginatedResponse';\nimport { OffsetPaginationInput } from '../pagination/OffsetPaginationInput';\n\nclass OffsetPage<T> implements Page<T> {\n static readonly BRAND = 'tango.resources.offset_page' as const;\n readonly __tangoBrand: typeof OffsetPage.BRAND = OffsetPage.BRAND;\n\n constructor(\n public readonly results: T[],\n private readonly pageNumber: number,\n private readonly perPage: number,\n private readonly totalCount?: number\n ) {}\n\n static isOffsetPage<T>(value: unknown): value is OffsetPage<T> {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === OffsetPage.BRAND\n );\n }\n\n /** Whether a next page exists based on known total count. */\n hasNext(): boolean {\n if (this.totalCount === undefined) {\n return false;\n }\n return this.endIndex() < this.totalCount;\n }\n\n /** Whether a previous page exists. */\n hasPrevious(): boolean {\n return this.pageNumber > 1;\n }\n\n /** The next page number, if available. */\n nextPageNumber(): number | null {\n return this.hasNext() ? this.pageNumber + 1 : null;\n }\n\n /** The previous page number, if available. */\n previousPageNumber(): number | null {\n return this.hasPrevious() ? this.pageNumber - 1 : null;\n }\n\n /** Zero-based start index of this page in the full result set. */\n startIndex(): number {\n return (this.pageNumber - 1) * this.perPage;\n }\n\n /** Exclusive end index of this page in the full result set. */\n endIndex(): number {\n return this.startIndex() + this.results.length;\n }\n}\n\n/**\n * Offset/limit paginator modelled after DRF's LimitOffsetPagination.\n * Handles parsing limit/offset/page from URL query params and building\n * the paginated response envelope with next/previous links.\n *\n * @example\n * ```typescript\n * const paginator = new OffsetPaginator(queryset);\n * const { limit, offset } = paginator.parseParams(searchParams);\n * const results = await queryset.limit(limit).offset(offset).fetchAll();\n * const response = paginator.getPaginatedResponse(results, totalCount);\n * ```\n */\nexport class OffsetPaginator<T extends Record<string, unknown>>\n extends BasePaginator\n implements Paginator<T, T, OffsetPaginatedResponse<T>>\n{\n static readonly BRAND = 'tango.resources.offset_paginator' as const;\n readonly __tangoBrand: typeof OffsetPaginator.BRAND = OffsetPaginator.BRAND;\n private limit = 25;\n private offset = 0;\n\n constructor(\n private queryset: QuerySet<T>,\n private perPage: number = 25\n ) {\n super();\n this.limit = perPage;\n }\n\n /**\n * Narrow an unknown value to `OffsetPaginator`.\n */\n static isOffsetPaginator<T extends Record<string, unknown>>(value: unknown): value is OffsetPaginator<T> {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === OffsetPaginator.BRAND\n );\n }\n\n /**\n * Parse limit, offset, and page from Tango query params.\n * If `page` is provided, it's converted to an offset.\n * Stores parsed values for use by getPaginatedResponse.\n */\n parse(params: TangoQueryParams): void {\n const input = {\n limit: params.get('limit') ?? undefined,\n offset: params.get('offset') ?? undefined,\n page: params.get('page') ?? undefined,\n };\n\n const parsed = OffsetPaginationInput.parse(input);\n\n if (parsed.page) {\n parsed.offset = (parsed.page - 1) * parsed.limit;\n }\n\n this.limit = parsed.limit;\n this.offset = parsed.offset;\n }\n\n /**\n * Parse params and return `{ limit, offset }` for compatibility callers.\n */\n parseParams(params: TangoQueryParams): { limit: number; offset: number } {\n this.parse(params);\n return { limit: this.limit, offset: this.offset };\n }\n\n /**\n * Build a DRF-style paginated response with count, next, and previous links.\n * Uses the limit/offset stored from the most recent parseParams call.\n */\n needsTotalCount(): boolean {\n return true;\n }\n\n toResponse<TResult>(\n results: readonly TResult[] | QueryResult<TResult>,\n context?: { totalCount?: number; params?: TangoQueryParams }\n ): OffsetPaginatedResponse<TResult> {\n const totalCount = context?.totalCount;\n const response: OffsetPaginatedResponse<TResult> = { results: this.resolveQueryResultRows(results) };\n\n if (totalCount !== undefined) {\n response.count = totalCount;\n\n if (this.offset + this.limit < totalCount) {\n response.next = this.buildPageLink(this.offset + this.limit, context?.params);\n }\n\n if (this.offset > 0) {\n const prevOffset = Math.max(0, this.offset - this.limit);\n response.previous = this.buildPageLink(prevOffset, context?.params);\n }\n }\n\n return response;\n }\n\n /**\n * Backward-compatible alias for `toResponse`.\n */\n getPaginatedResponse<TResult>(\n results: readonly TResult[] | QueryResult<TResult>,\n totalCount?: number,\n params?: TangoQueryParams\n ): OffsetPaginatedResponse<TResult> {\n return this.toResponse(results, { totalCount, params });\n }\n\n /**\n * Apply current limit/offset to a queryset.\n */\n apply<TBaseResult extends Record<string, unknown>, TSourceModel, THydrated extends Record<string, unknown>>(\n queryset: QuerySet<T, TBaseResult, TSourceModel, THydrated>\n ): QuerySet<T, TBaseResult, TSourceModel, THydrated> {\n return queryset.limit(this.limit).offset(this.offset);\n }\n\n /**\n * Fetch a 1-based page number from the bound queryset.\n */\n async paginate(page: number): Promise<Page<T>> {\n return this.getPage(page);\n }\n\n /**\n * Fetch a 1-based page and return page metadata.\n */\n async getPage(page: number): Promise<Page<T>> {\n const offset = (page - 1) * this.perPage;\n const results = await this.queryset.offset(offset).limit(this.perPage).fetch();\n\n const totalCount = await this.count();\n\n return new OffsetPage(this.resolveQueryResultRows(results), page, this.perPage, totalCount);\n }\n\n /**\n * Count total rows for the current queryset state.\n */\n async count(): Promise<number> {\n return this.queryset.count();\n }\n\n private buildPageLink(offset: number, params?: TangoQueryParams): string {\n if (!params) {\n return `?limit=${this.limit}&offset=${offset}`;\n }\n\n return params\n .withValues({\n limit: this.limit,\n offset,\n page: null,\n })\n .toRelativeURL();\n }\n}\n","import type { ResourceModelLike } from '../resource/index';\nimport type { FilterValueParser } from './FilterSet';\n\nfunction normalizeParserTokens(raw: string | string[]): string[] {\n const tokens = Array.isArray(raw) ? raw : String(raw).split(',');\n const normalized = tokens.map((value) => value.trim());\n return normalized.every((value) => value.length > 0) ? normalized : [];\n}\n\nfunction createBooleanParser(): FilterValueParser {\n return (raw) => {\n const values = normalizeParserTokens(raw);\n if (values.length === 0) {\n return undefined;\n }\n\n const parsed = values.map((value) => {\n const normalized = value.toLowerCase();\n\n if (normalized === 'true' || normalized === '1') {\n return true;\n }\n\n if (normalized === 'false' || normalized === '0') {\n return false;\n }\n\n return null;\n });\n\n if (parsed.some((value) => value === null)) {\n return undefined;\n }\n\n return parsed.length === 1 ? parsed[0]! : (parsed as boolean[]);\n };\n}\n\nfunction createIntegerParser(): FilterValueParser {\n return (raw) => {\n const values = normalizeParserTokens(raw);\n if (values.length === 0) {\n return undefined;\n }\n\n const parsed = values.map(Number);\n\n if (parsed.some((value) => !Number.isInteger(value))) {\n return undefined;\n }\n\n return parsed.length === 1 ? parsed[0] : parsed;\n };\n}\n\nfunction createTimestampParser(): FilterValueParser {\n return (raw) => {\n const values = normalizeParserTokens(raw);\n if (values.length === 0) {\n return undefined;\n }\n\n const parsed = values.map((value) => {\n const date = new Date(value);\n return Number.isNaN(date.getTime()) ? null : date;\n });\n\n if (parsed.some((value) => value === null)) {\n return undefined;\n }\n\n return parsed.length === 1 ? parsed[0]! : (parsed as Date[]);\n };\n}\n\n/**\n * Infer resource-level query-value parsers from Tango model metadata.\n *\n * Parsers are inferred conservatively from field metadata so HTTP query filters\n * can be coerced into typed ORM inputs without framework-specific glue.\n */\nexport function inferModelFieldParsers<T extends Record<string, unknown>>(\n model: ResourceModelLike<T>\n): Partial<Record<keyof T, FilterValueParser>> {\n const metadata = model.metadata;\n if (!metadata) {\n return {};\n }\n\n const parsers: Partial<Record<keyof T, FilterValueParser>> = {};\n\n for (const field of metadata.fields) {\n switch (field.type) {\n case 'bool':\n parsers[field.name as keyof T] = createBooleanParser();\n break;\n case 'serial':\n case 'int':\n case 'bigint':\n parsers[field.name as keyof T] = createIntegerParser();\n break;\n case 'timestamptz':\n parsers[field.name as keyof T] = createTimestampParser();\n break;\n default:\n break;\n }\n }\n\n return parsers;\n}\n","import { TangoResponse } from '@danceroutine/tango-core';\nimport { RequestContext } from '../context/index';\n\nexport type APIViewMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\ntype APIViewMethodHandler = (ctx: RequestContext) => Promise<TangoResponse>;\n\n/**\n * Lightweight class-based request dispatcher for non-model API endpoints.\n */\nexport abstract class APIView {\n static readonly BRAND = 'tango.resources.api_view' as const;\n readonly __tangoBrand: typeof APIView.BRAND = APIView.BRAND;\n\n /**\n * Narrow an unknown value to `APIView`.\n */\n static isAPIView(value: unknown): value is APIView {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === APIView.BRAND\n );\n }\n\n /**\n * Dispatch the request to the handler for the current HTTP method.\n */\n async dispatch(ctx: RequestContext): Promise<TangoResponse> {\n const method = normalizeMethod(ctx.request.method);\n if (!method) {\n return this.httpMethodNotAllowed();\n }\n\n const handler = this.getMethodHandler(method);\n return handler(ctx);\n }\n\n getAllowedMethods(): readonly APIViewMethod[] {\n const allowed: APIViewMethod[] = [];\n if (this.get !== APIView.prototype.get) {\n allowed.push('GET');\n }\n if (this.post !== APIView.prototype.post) {\n allowed.push('POST');\n }\n if (this.put !== APIView.prototype.put) {\n allowed.push('PUT');\n }\n if (this.patch !== APIView.prototype.patch) {\n allowed.push('PATCH');\n }\n if (this.delete !== APIView.prototype.delete) {\n allowed.push('DELETE');\n }\n return allowed;\n }\n\n protected get(_ctx: RequestContext): Promise<TangoResponse> {\n return Promise.resolve(this.httpMethodNotAllowed());\n }\n\n protected post(_ctx: RequestContext): Promise<TangoResponse> {\n return Promise.resolve(this.httpMethodNotAllowed());\n }\n\n protected put(_ctx: RequestContext): Promise<TangoResponse> {\n return Promise.resolve(this.httpMethodNotAllowed());\n }\n\n protected patch(_ctx: RequestContext): Promise<TangoResponse> {\n return Promise.resolve(this.httpMethodNotAllowed());\n }\n\n protected delete(_ctx: RequestContext): Promise<TangoResponse> {\n return Promise.resolve(this.httpMethodNotAllowed());\n }\n\n protected httpMethodNotAllowed(): TangoResponse {\n return TangoResponse.methodNotAllowed(this.getAllowedMethods());\n }\n\n private getMethodHandler(method: APIViewMethod): APIViewMethodHandler {\n if (method === 'GET') {\n return (ctx) => this.get(ctx);\n }\n if (method === 'POST') {\n return (ctx) => this.post(ctx);\n }\n if (method === 'PUT') {\n return (ctx) => this.put(ctx);\n }\n if (method === 'PATCH') {\n return (ctx) => this.patch(ctx);\n }\n return (ctx) => this.delete(ctx);\n }\n}\n\nfunction normalizeMethod(method: string): APIViewMethod | null {\n const upper = method.toUpperCase();\n if (upper === 'GET') {\n return 'GET';\n }\n if (upper === 'POST') {\n return 'POST';\n }\n if (upper === 'PUT') {\n return 'PUT';\n }\n if (upper === 'PATCH') {\n return 'PATCH';\n }\n if (upper === 'DELETE') {\n return 'DELETE';\n }\n return null;\n}\n","import { HttpErrorFactory, TangoResponse, type JsonValue, NotFoundError } from '@danceroutine/tango-core';\nimport { Q, type FilterInput, type ManagerLike, type QuerySet } from '@danceroutine/tango-orm';\nimport type { OffsetPaginatedResponse, Paginator } from '../pagination/index';\nimport { OffsetPaginator } from '../paginators/OffsetPaginator';\nimport { APIView } from './APIView';\nimport { RequestContext } from '../context/index';\nimport type { FilterSet } from '../filters/index';\nimport { inferModelFieldParsers } from '../filters/inferModelFieldParsers';\nimport type { GenericAPIViewOpenAPIDescription } from '../resource/index';\nimport type { AnyModelSerializer, SerializerOutput } from '../serializer/index';\nimport type { ResourceModelLike } from '../resource/index';\n\ntype SearchFieldRef<TModel extends Record<string, unknown>> = Extract<keyof TModel, string> | string;\n\nexport interface GenericAPIViewConfig<\n TModel extends Record<string, unknown>,\n TSerializer extends AnyModelSerializer<TModel>,\n> {\n serializer: TSerializer;\n filters?: FilterSet<TModel>;\n orderingFields?: (keyof TModel)[];\n searchFields?: SearchFieldRef<TModel>[];\n lookupField?: keyof TModel;\n lookupParam?: string;\n paginatorFactory?: (queryset: QuerySet<TModel>) => Paginator<TModel, SerializerOutput<TSerializer>>;\n}\n\n/**\n * Generic API base class that centralizes query/build/validation helpers.\n */\nexport abstract class GenericAPIView<\n TModel extends Record<string, unknown>,\n TSerializer extends AnyModelSerializer<TModel>,\n> extends APIView {\n protected readonly serializerClass: TSerializer;\n protected readonly filters?: FilterSet<TModel>;\n protected readonly orderingFields: readonly (keyof TModel)[];\n protected readonly searchFields: readonly SearchFieldRef<TModel>[];\n protected readonly lookupField?: keyof TModel;\n protected readonly lookupParam: string;\n protected readonly paginatorFactory?: (\n queryset: QuerySet<TModel>\n ) => Paginator<TModel, SerializerOutput<TSerializer>>;\n private serializer?: InstanceType<TSerializer>;\n\n constructor(config: GenericAPIViewConfig<TModel, TSerializer>) {\n super();\n this.serializerClass = config.serializer;\n this.filters = config.filters;\n this.orderingFields = config.orderingFields ?? [];\n this.searchFields = config.searchFields ?? [];\n this.lookupField = config.lookupField;\n this.lookupParam = config.lookupParam ?? 'id';\n this.paginatorFactory = config.paginatorFactory;\n }\n\n /**\n * Return the serializer class that owns this resource contract.\n */\n getSerializerClass(): TSerializer {\n return this.serializerClass;\n }\n\n /**\n * Return the serializer instance for the current resource.\n */\n getSerializer(): InstanceType<TSerializer> {\n if (!this.serializer) {\n this.serializer = new this.serializerClass() as InstanceType<TSerializer>;\n }\n\n return this.serializer;\n }\n\n /**\n * Describe the public HTTP contract that this resource contributes to OpenAPI generation.\n */\n describeOpenAPI(): GenericAPIViewOpenAPIDescription<TModel, TSerializer> {\n const model = this.requireModelMetadata();\n return {\n model,\n outputSchema: this.getOutputSchema(),\n createSchema: this.getCreateSchema(),\n updateSchema: this.getUpdateSchema(),\n searchFields: this.searchFields,\n orderingFields: this.orderingFields,\n lookupField: this.lookupField ?? this.getLookupFieldFromMetadata(model),\n lookupParam: this.lookupParam,\n allowedMethods: this.getAllowedMethods(),\n usesDefaultOffsetPagination: !this.paginatorFactory,\n };\n }\n\n protected getManager(): ManagerLike<TModel> {\n return this.getSerializer().getManager();\n }\n\n protected getOutputSchema(): TSerializer['outputSchema'] {\n return this.getSerializer().getOutputSchema() as TSerializer['outputSchema'];\n }\n\n protected getCreateSchema(): TSerializer['createSchema'] {\n return this.getSerializer().getCreateSchema() as TSerializer['createSchema'];\n }\n\n protected getUpdateSchema(): TSerializer['updateSchema'] {\n return this.getSerializer().getUpdateSchema() as TSerializer['updateSchema'];\n }\n\n protected getLookupField(): keyof TModel {\n return this.lookupField ?? (this.getManager().meta.pk as keyof TModel);\n }\n\n protected getLookupValue(ctx: RequestContext): string | null {\n const value = ctx.params[this.lookupParam]?.trim();\n return value || null;\n }\n\n protected getPaginator(queryset: QuerySet<TModel>): Paginator<TModel, SerializerOutput<TSerializer>> {\n if (this.paginatorFactory) {\n return this.paginatorFactory(queryset);\n }\n return new OffsetPaginator<TModel>(queryset) as Paginator<TModel, SerializerOutput<TSerializer>>;\n }\n\n protected async performList(ctx: RequestContext): Promise<TangoResponse> {\n try {\n const params = ctx.request.queryParams;\n const baseQueryset = this.getManager().query();\n const paginator = this.getPaginator(baseQueryset);\n paginator.parse(params);\n\n let qs = baseQueryset;\n\n if (this.filters) {\n const filterInputs = this.filters\n .withFieldParsers(inferModelFieldParsers(this.getSerializer().getModel()))\n .apply(params);\n if (filterInputs.length > 0) {\n qs = qs.filter(Q.and(...filterInputs));\n }\n }\n\n const search = params.getSearch();\n if (search && this.searchFields.length > 0) {\n const searchFilters: FilterInput<TModel>[] = this.searchFields.map((field) => {\n const lookup = `${String(field)}__icontains`;\n return { [lookup]: search } as FilterInput<TModel>;\n });\n qs = qs.filter(Q.or(...searchFilters));\n }\n\n const ordering = params.getOrdering();\n if (ordering.length > 0) {\n const orderTokens = ordering.filter((field) => {\n const cleanField = field.startsWith('-') ? field.slice(1) : field;\n return this.orderingFields.includes(cleanField as keyof TModel);\n });\n if (orderTokens.length > 0) {\n qs = qs.orderBy(...orderTokens.map((token) => token as keyof TModel | `-${string & keyof TModel}`));\n }\n }\n\n const paginatedQueryset = paginator.apply(qs);\n const resultPromise = paginatedQueryset.fetch();\n const totalCountPromise = paginator.needsTotalCount()\n ? qs.count()\n : Promise.resolve<number | undefined>(undefined);\n const [result, totalCount] = await Promise.all([resultPromise, totalCountPromise]);\n const serializer = this.getSerializer();\n const rows = await serializer.serializeMany(result.items);\n const response = paginator.toResponse(rows as SerializerOutput<TSerializer>[], {\n totalCount,\n }) as OffsetPaginatedResponse<SerializerOutput<TSerializer>>;\n\n return TangoResponse.json(response as unknown as JsonValue, { status: 200 });\n } catch (error) {\n return this.handleError(error);\n }\n }\n\n protected async performCreate(ctx: RequestContext): Promise<TangoResponse> {\n try {\n const body = await ctx.request.json();\n const result = await this.getSerializer().create(body);\n\n return TangoResponse.created(undefined, result as JsonValue);\n } catch (error) {\n return this.handleError(error);\n }\n }\n\n protected async performRetrieve(ctx: RequestContext): Promise<TangoResponse> {\n try {\n const value = this.getLookupValue(ctx);\n if (!value) {\n throw new NotFoundError('Lookup parameter was not provided.');\n }\n\n const lookupField = this.getLookupField();\n const filterByLookup = { [lookupField]: value } as FilterInput<TModel>;\n const result = await this.getManager().query().filter(filterByLookup).fetchOne();\n if (!result) {\n throw new NotFoundError(\n `No ${this.getManager().meta.table} record found for ${String(lookupField)}=${value}.`\n );\n }\n\n return TangoResponse.json((await this.getSerializer().serialize(result)) as JsonValue, { status: 200 });\n } catch (error) {\n return this.handleError(error);\n }\n }\n\n protected async performUpdate(ctx: RequestContext): Promise<TangoResponse> {\n try {\n const value = this.getLookupValue(ctx);\n if (!value) {\n throw new NotFoundError('Lookup parameter was not provided.');\n }\n\n const body = await ctx.request.json();\n const result = await this.getSerializer().update(value as TModel[keyof TModel], body);\n\n return TangoResponse.json(result as JsonValue, { status: 200 });\n } catch (error) {\n return this.handleError(error);\n }\n }\n\n protected async performDestroy(ctx: RequestContext): Promise<TangoResponse> {\n try {\n const value = this.getLookupValue(ctx);\n if (!value) {\n throw new NotFoundError('Lookup parameter was not provided.');\n }\n\n await this.getManager().delete(value as TModel[keyof TModel]);\n return TangoResponse.noContent();\n } catch (error) {\n return this.handleError(error);\n }\n }\n\n protected handleError(error: unknown): TangoResponse {\n const httpError = HttpErrorFactory.toHttpError(error);\n return TangoResponse.json(httpError.body as JsonValue, { status: httpError.status });\n }\n\n private requireModelMetadata(): ResourceModelLike<TModel> & {\n metadata: NonNullable<ResourceModelLike<TModel>['metadata']>;\n } {\n const model = this.getSerializer().getModel();\n\n if (!model.metadata) {\n throw new Error('OpenAPI generation requires Tango model metadata on GenericAPIView models.');\n }\n\n return model as ResourceModelLike<TModel> & {\n metadata: NonNullable<ResourceModelLike<TModel>['metadata']>;\n };\n }\n\n private getLookupFieldFromMetadata(\n model: ResourceModelLike<TModel> & {\n metadata: NonNullable<ResourceModelLike<TModel>['metadata']>;\n }\n ): keyof TModel {\n const primaryKeyField = model.metadata.fields.find((field) => field.primaryKey);\n\n if (!primaryKeyField) {\n throw new Error('OpenAPI generation requires a primary key field in Tango model metadata.');\n }\n\n return primaryKeyField.name as keyof TModel;\n }\n}\n","import { GenericAPIView } from '../GenericAPIView';\nimport type { TangoResponse } from '@danceroutine/tango-core';\nimport { RequestContext } from '../../context/index';\nimport type { AnyModelSerializer } from '../../serializer/index';\n\n/**\n * Mixin that wires `GET` requests to the generic list implementation.\n */\nexport abstract class ListModelMixin<\n TModel extends Record<string, unknown>,\n TSerializer extends AnyModelSerializer<TModel>,\n> extends GenericAPIView<TModel, TSerializer> {\n protected list(ctx: RequestContext): Promise<TangoResponse> {\n return this.performList(ctx);\n }\n\n protected override get(ctx: RequestContext): Promise<TangoResponse> {\n return this.list(ctx);\n }\n}\n","import { GenericAPIView } from '../GenericAPIView';\nimport type { TangoResponse } from '@danceroutine/tango-core';\nimport { RequestContext } from '../../context/index';\nimport type { AnyModelSerializer } from '../../serializer/index';\n\n/**\n * Mixin that wires `POST` requests to the generic create implementation.\n */\nexport abstract class CreateModelMixin<\n TModel extends Record<string, unknown>,\n TSerializer extends AnyModelSerializer<TModel>,\n> extends GenericAPIView<TModel, TSerializer> {\n protected create(ctx: RequestContext): Promise<TangoResponse> {\n return this.performCreate(ctx);\n }\n\n protected override post(ctx: RequestContext): Promise<TangoResponse> {\n return this.create(ctx);\n }\n}\n","import { GenericAPIView } from '../GenericAPIView';\nimport type { TangoResponse } from '@danceroutine/tango-core';\nimport { RequestContext } from '../../context/index';\nimport type { AnyModelSerializer } from '../../serializer/index';\n\n/**\n * Mixin that wires `GET` requests to the generic retrieve implementation.\n */\nexport abstract class RetrieveModelMixin<\n TModel extends Record<string, unknown>,\n TSerializer extends AnyModelSerializer<TModel>,\n> extends GenericAPIView<TModel, TSerializer> {\n protected retrieve(ctx: RequestContext): Promise<TangoResponse> {\n return this.performRetrieve(ctx);\n }\n\n protected override get(ctx: RequestContext): Promise<TangoResponse> {\n return this.retrieve(ctx);\n }\n}\n","import { GenericAPIView } from '../GenericAPIView';\nimport type { TangoResponse } from '@danceroutine/tango-core';\nimport { RequestContext } from '../../context/index';\nimport type { AnyModelSerializer } from '../../serializer/index';\n\n/**\n * Mixin that wires `PUT` and `PATCH` requests to the generic update implementation.\n */\nexport abstract class UpdateModelMixin<\n TModel extends Record<string, unknown>,\n TSerializer extends AnyModelSerializer<TModel>,\n> extends GenericAPIView<TModel, TSerializer> {\n protected update(ctx: RequestContext): Promise<TangoResponse> {\n return this.performUpdate(ctx);\n }\n\n protected override put(ctx: RequestContext): Promise<TangoResponse> {\n return this.update(ctx);\n }\n\n protected override patch(ctx: RequestContext): Promise<TangoResponse> {\n return this.update(ctx);\n }\n}\n","import { GenericAPIView } from '../GenericAPIView';\nimport type { TangoResponse } from '@danceroutine/tango-core';\nimport { RequestContext } from '../../context/index';\nimport type { AnyModelSerializer } from '../../serializer/index';\n\n/**\n * Mixin that wires `DELETE` requests to the generic destroy implementation.\n */\nexport abstract class DestroyModelMixin<\n TModel extends Record<string, unknown>,\n TSerializer extends AnyModelSerializer<TModel>,\n> extends GenericAPIView<TModel, TSerializer> {\n protected destroy(ctx: RequestContext): Promise<TangoResponse> {\n return this.performDestroy(ctx);\n }\n\n protected override delete(ctx: RequestContext): Promise<TangoResponse> {\n return this.destroy(ctx);\n }\n}\n","import { ListModelMixin } from '../mixins/ListModelMixin';\nimport type { TangoResponse } from '@danceroutine/tango-core';\nimport { RequestContext } from '../../context/index';\nimport type { AnyModelSerializer } from '../../serializer/index';\n\n/**\n * Generic API view for endpoints that only expose a list operation.\n */\nexport abstract class ListAPIView<\n TModel extends Record<string, unknown>,\n TSerializer extends AnyModelSerializer<TModel>,\n> extends ListModelMixin<TModel, TSerializer> {\n protected override get(ctx: RequestContext): Promise<TangoResponse> {\n return super.get(ctx);\n }\n}\n","import { CreateModelMixin } from '../mixins/CreateModelMixin';\nimport type { TangoResponse } from '@danceroutine/tango-core';\nimport { RequestContext } from '../../context/index';\nimport type { AnyModelSerializer } from '../../serializer/index';\n\n/**\n * Generic API view for endpoints that only support resource creation.\n */\nexport abstract class CreateAPIView<\n TModel extends Record<string, unknown>,\n TSerializer extends AnyModelSerializer<TModel>,\n> extends CreateModelMixin<TModel, TSerializer> {\n protected override post(ctx: RequestContext): Promise<TangoResponse> {\n return super.post(ctx);\n }\n}\n","import { RetrieveModelMixin } from '../mixins/RetrieveModelMixin';\nimport type { TangoResponse } from '@danceroutine/tango-core';\nimport { RequestContext } from '../../context/index';\nimport type { AnyModelSerializer } from '../../serializer/index';\n\n/**\n * Generic API view for endpoints that retrieve a single resource by lookup.\n */\nexport abstract class RetrieveAPIView<\n TModel extends Record<string, unknown>,\n TSerializer extends AnyModelSerializer<TModel>,\n> extends RetrieveModelMixin<TModel, TSerializer> {\n protected override get(ctx: RequestContext): Promise<TangoResponse> {\n return super.get(ctx);\n }\n}\n","import { GenericAPIView } from '../GenericAPIView';\nimport type { TangoResponse } from '@danceroutine/tango-core';\nimport { RequestContext } from '../../context/index';\nimport type { AnyModelSerializer } from '../../serializer/index';\n\n/**\n * Generic API view for collection endpoints that list and create resources.\n */\nexport abstract class ListCreateAPIView<\n TModel extends Record<string, unknown>,\n TSerializer extends AnyModelSerializer<TModel>,\n> extends GenericAPIView<TModel, TSerializer> {\n protected override get(ctx: RequestContext): Promise<TangoResponse> {\n return this.performList(ctx);\n }\n\n protected override post(ctx: RequestContext): Promise<TangoResponse> {\n return this.performCreate(ctx);\n }\n}\n","import { GenericAPIView } from '../GenericAPIView';\nimport type { TangoResponse } from '@danceroutine/tango-core';\nimport { RequestContext } from '../../context/index';\nimport type { AnyModelSerializer } from '../../serializer/index';\n\n/**\n * Generic API view for endpoints that retrieve and update a single resource.\n */\nexport abstract class RetrieveUpdateAPIView<\n TModel extends Record<string, unknown>,\n TSerializer extends AnyModelSerializer<TModel>,\n> extends GenericAPIView<TModel, TSerializer> {\n protected override get(ctx: RequestContext): Promise<TangoResponse> {\n return this.performRetrieve(ctx);\n }\n\n protected override put(ctx: RequestContext): Promise<TangoResponse> {\n return this.performUpdate(ctx);\n }\n\n protected override patch(ctx: RequestContext): Promise<TangoResponse> {\n return this.performUpdate(ctx);\n }\n}\n","import { GenericAPIView } from '../GenericAPIView';\nimport type { TangoResponse } from '@danceroutine/tango-core';\nimport { RequestContext } from '../../context/index';\nimport type { AnyModelSerializer } from '../../serializer/index';\n\n/**\n * Generic API view for endpoints that retrieve and delete a single resource.\n */\nexport abstract class RetrieveDestroyAPIView<\n TModel extends Record<string, unknown>,\n TSerializer extends AnyModelSerializer<TModel>,\n> extends GenericAPIView<TModel, TSerializer> {\n protected override get(ctx: RequestContext): Promise<TangoResponse> {\n return this.performRetrieve(ctx);\n }\n\n protected override delete(ctx: RequestContext): Promise<TangoResponse> {\n return this.performDestroy(ctx);\n }\n}\n","import { GenericAPIView } from '../GenericAPIView';\nimport type { TangoResponse } from '@danceroutine/tango-core';\nimport { RequestContext } from '../../context/index';\nimport type { AnyModelSerializer } from '../../serializer/index';\n\n/**\n * Generic API view for full detail endpoints that retrieve, update, and delete.\n */\nexport abstract class RetrieveUpdateDestroyAPIView<\n TModel extends Record<string, unknown>,\n TSerializer extends AnyModelSerializer<TModel>,\n> extends GenericAPIView<TModel, TSerializer> {\n protected override get(ctx: RequestContext): Promise<TangoResponse> {\n return this.performRetrieve(ctx);\n }\n\n protected override put(ctx: RequestContext): Promise<TangoResponse> {\n return this.performUpdate(ctx);\n }\n\n protected override patch(ctx: RequestContext): Promise<TangoResponse> {\n return this.performUpdate(ctx);\n }\n\n protected override delete(ctx: RequestContext): Promise<TangoResponse> {\n return this.performDestroy(ctx);\n }\n}\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\n\nexport { APIView, type APIViewMethod } from './APIView';\nexport { GenericAPIView, type GenericAPIViewConfig } from './GenericAPIView';\nexport type { GenericAPIViewOpenAPIDescription } from '../resource/index';\nexport {\n ListModelMixin,\n CreateModelMixin,\n RetrieveModelMixin,\n UpdateModelMixin,\n DestroyModelMixin,\n} from './mixins/index';\nexport {\n ListAPIView,\n CreateAPIView,\n RetrieveAPIView,\n ListCreateAPIView,\n RetrieveUpdateAPIView,\n RetrieveDestroyAPIView,\n RetrieveUpdateDestroyAPIView,\n} from './generics/index';\n"],"mappings":";;;;;;;;;;;;;;;IAEsB,gBAAf,MAA6B;CAChC,uBAAoCA,MAA0C;AAC1E,MAAI,YAAY,cAAiB,KAAK,CAClC,QAAO,KAAK,SAAS;AAEzB,SAAO,CAAC,GAAG,IAAK;CACnB;AACJ;;;;MCDYC,wBAA+D,EAAE,OAAO;CACjF,OAAO,EAAE,OACJ,QAAQ,CACR,KAAK,CACL,IAAI,EAAE,CACN,QAAQ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CACnC;CAED,OAA0BA,KAA6C;AACnE,SAAO,KAAK,eAAe,IAAI;CAClC;AACJ;;;;ICXqB,+BAAf,cAGG,eAAoC;CAC1C,IAAuBC,KAA6C;AAChE,SAAO,KAAK,gBAAgB,IAAI;CACnC;CAED,IAAuBA,KAA6C;AAChE,SAAO,KAAK,cAAc,IAAI;CACjC;CAED,MAAyBA,KAA6C;AAClE,SAAO,KAAK,cAAc,IAAI;CACjC;CAED,OAA0BA,KAA6C;AACnE,SAAO,KAAK,eAAe,IAAI;CAClC;AACJ"}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import type { ManagerLike, QuerySet } from '@danceroutine/tango-orm';
|
|
2
|
-
import { TangoResponse } from '@danceroutine/tango-core';
|
|
3
|
-
import type { RequestContext } from '../context/index';
|
|
4
|
-
import type { FilterSet } from '../filters/index';
|
|
5
|
-
import type { Paginator } from '../pagination/index';
|
|
6
|
-
import type { ModelViewSetOpenAPIDescription } from '../resource/index';
|
|
7
|
-
import type { AnyModelSerializer, AnyModelSerializerClass, SerializerOutput } from '../serializer/index';
|
|
8
|
-
export type ViewSetActionScope = 'detail' | 'collection';
|
|
9
|
-
export type ViewSetActionMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
10
|
-
export interface ViewSetActionDescriptor {
|
|
11
|
-
name: string;
|
|
12
|
-
scope: ViewSetActionScope;
|
|
13
|
-
methods: readonly ViewSetActionMethod[];
|
|
14
|
-
path?: string;
|
|
15
|
-
}
|
|
16
|
-
export interface ResolvedViewSetActionDescriptor extends ViewSetActionDescriptor {
|
|
17
|
-
path: string;
|
|
18
|
-
}
|
|
19
|
-
type AnyModelViewSet = ModelViewSet<Record<string, unknown>, AnyModelSerializerClass>;
|
|
20
|
-
type SearchFieldRef<TModel extends Record<string, unknown>> = Extract<keyof TModel, string> | string;
|
|
21
|
-
/**
|
|
22
|
-
* Configuration for a ModelViewSet, defining how a serializer-backed model is exposed as an API resource.
|
|
23
|
-
*/
|
|
24
|
-
export interface ModelViewSetConfig<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> {
|
|
25
|
-
/** Serializer class that owns validation, representation, and persistence hooks */
|
|
26
|
-
serializer: TSerializer;
|
|
27
|
-
/** Optional filter set defining which query parameters can filter the list endpoint */
|
|
28
|
-
filters?: FilterSet<TModel>;
|
|
29
|
-
/** Fields that clients are allowed to sort by via query parameters */
|
|
30
|
-
orderingFields?: (keyof TModel)[];
|
|
31
|
-
/** Fields that are searched when a free-text search query parameter is provided */
|
|
32
|
-
searchFields?: SearchFieldRef<TModel>[];
|
|
33
|
-
/** Optional paginator factory used by list endpoints. */
|
|
34
|
-
paginatorFactory?: (queryset: QuerySet<TModel>) => Paginator<TModel, SerializerOutput<TSerializer>>;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Base class for creating RESTful API viewsets with built-in CRUD operations.
|
|
38
|
-
* Provides list, retrieve, create, update, and delete methods with filtering,
|
|
39
|
-
* search, pagination, and ordering support.
|
|
40
|
-
*/
|
|
41
|
-
export declare abstract class ModelViewSet<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel>> {
|
|
42
|
-
static readonly BRAND: "tango.resources.model_view_set";
|
|
43
|
-
static readonly actions: readonly ViewSetActionDescriptor[];
|
|
44
|
-
readonly __tangoBrand: typeof ModelViewSet.BRAND;
|
|
45
|
-
protected readonly serializerClass: TSerializer;
|
|
46
|
-
protected readonly filters?: FilterSet<TModel>;
|
|
47
|
-
protected readonly orderingFields: (keyof TModel)[];
|
|
48
|
-
protected readonly searchFields: SearchFieldRef<TModel>[];
|
|
49
|
-
protected readonly paginatorFactory?: (queryset: QuerySet<TModel>) => Paginator<TModel, SerializerOutput<TSerializer>>;
|
|
50
|
-
private serializer?;
|
|
51
|
-
constructor(config: ModelViewSetConfig<TModel, TSerializer>);
|
|
52
|
-
/**
|
|
53
|
-
* Return the custom action descriptors declared by a viewset or constructor.
|
|
54
|
-
*/
|
|
55
|
-
static getActions(viewsetOrConstructor: AnyModelViewSet | (new (...args: never[]) => AnyModelViewSet)): readonly ResolvedViewSetActionDescriptor[];
|
|
56
|
-
/**
|
|
57
|
-
* Narrow an unknown value to `ModelViewSet`.
|
|
58
|
-
*/
|
|
59
|
-
static isModelViewSet(value: unknown): value is ModelViewSet<Record<string, unknown>, AnyModelSerializerClass>;
|
|
60
|
-
/**
|
|
61
|
-
* Preserve literal action inference while validating the descriptor shape.
|
|
62
|
-
*/
|
|
63
|
-
static defineViewSetActions<const T extends readonly ViewSetActionDescriptor[]>(actions: T): T;
|
|
64
|
-
private static resolvePathFromDescriptor;
|
|
65
|
-
private static toKebabCase;
|
|
66
|
-
/**
|
|
67
|
-
* Return the serializer class that owns this resource contract.
|
|
68
|
-
*/
|
|
69
|
-
getSerializerClass(): TSerializer;
|
|
70
|
-
/**
|
|
71
|
-
* Return the serializer instance for the current resource.
|
|
72
|
-
*/
|
|
73
|
-
getSerializer(): InstanceType<TSerializer>;
|
|
74
|
-
/**
|
|
75
|
-
* Describe the public HTTP contract that this resource contributes to OpenAPI generation.
|
|
76
|
-
*/
|
|
77
|
-
describeOpenAPI(): ModelViewSetOpenAPIDescription<TModel, TSerializer>;
|
|
78
|
-
/**
|
|
79
|
-
* List endpoint with filtering, search, ordering, and offset pagination.
|
|
80
|
-
*/
|
|
81
|
-
list(ctx: RequestContext): Promise<TangoResponse>;
|
|
82
|
-
/**
|
|
83
|
-
* Retrieve endpoint for a single resource by id.
|
|
84
|
-
*/
|
|
85
|
-
retrieve(_ctx: RequestContext, id: string): Promise<TangoResponse>;
|
|
86
|
-
/**
|
|
87
|
-
* Create endpoint: validate input, persist, and return serialized output.
|
|
88
|
-
*/
|
|
89
|
-
create(ctx: RequestContext): Promise<TangoResponse>;
|
|
90
|
-
/**
|
|
91
|
-
* Update endpoint: validate partial payload and persist by id.
|
|
92
|
-
*/
|
|
93
|
-
update(ctx: RequestContext, id: string): Promise<TangoResponse>;
|
|
94
|
-
/**
|
|
95
|
-
* Destroy endpoint: delete a resource by id.
|
|
96
|
-
*/
|
|
97
|
-
destroy(_ctx: RequestContext, id: string): Promise<TangoResponse>;
|
|
98
|
-
protected getPaginator(queryset: QuerySet<TModel>): Paginator<TModel, SerializerOutput<TSerializer>>;
|
|
99
|
-
protected getManager(): ManagerLike<TModel>;
|
|
100
|
-
/**
|
|
101
|
-
* Convert thrown errors into normalized HTTP responses.
|
|
102
|
-
*/
|
|
103
|
-
protected handleError(error: unknown): TangoResponse;
|
|
104
|
-
/**
|
|
105
|
-
* Resolve route path segment(s) for a custom action.
|
|
106
|
-
* Override this in subclasses to customize path derivation globally.
|
|
107
|
-
*/
|
|
108
|
-
protected resolveActionPath(action: ViewSetActionDescriptor): string;
|
|
109
|
-
private requireModelMetadata;
|
|
110
|
-
private getLookupFieldFromMetadata;
|
|
111
|
-
}
|
|
112
|
-
export {};
|
package/dist/viewset/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Domain boundary barrel: centralizes this subdomain's public contract.
|
|
3
|
-
*/
|
|
4
|
-
export { ModelViewSet, type ModelViewSetConfig, type ViewSetActionDescriptor, type ViewSetActionMethod, type ViewSetActionScope, type ResolvedViewSetActionDescriptor, } from './ModelViewSet';
|
|
5
|
-
export type { ModelViewSetOpenAPIDescription } from '../resource/index';
|