@danceroutine/tango-resources 1.11.1 → 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.
Files changed (56) hide show
  1. package/dist/chunk-D7D4PA-g.js +13 -0
  2. package/dist/index-D6sfTSEj.d.ts +902 -0
  3. package/dist/index.d.ts +12 -23
  4. package/dist/index.js +96 -152
  5. package/dist/index.js.map +1 -1
  6. package/dist/view/index.d.ts +2 -8
  7. package/dist/view/index.js +2 -3
  8. package/dist/{view-DUHg6AXl.js → view-C9B5Lln3.js} +151 -59
  9. package/dist/view-C9B5Lln3.js.map +1 -0
  10. package/package.json +6 -6
  11. package/dist/context/RequestContext.d.ts +0 -46
  12. package/dist/context/index.d.ts +0 -5
  13. package/dist/filters/FilterSet.d.ts +0 -95
  14. package/dist/filters/FilterType.d.ts +0 -2
  15. package/dist/filters/RangeOperator.d.ts +0 -2
  16. package/dist/filters/index.d.ts +0 -7
  17. package/dist/filters/inferModelFieldParsers.d.ts +0 -9
  18. package/dist/filters/internal/InternalFilterLookup.d.ts +0 -15
  19. package/dist/filters/internal/InternalFilterType.d.ts +0 -7
  20. package/dist/filters/internal/InternalRangeOperator.d.ts +0 -6
  21. package/dist/pagination/BasePaginator.d.ts +0 -4
  22. package/dist/pagination/CursorPaginationInput.d.ts +0 -7
  23. package/dist/pagination/OffsetPaginationInput.d.ts +0 -7
  24. package/dist/pagination/PaginatedResponse.d.ts +0 -12
  25. package/dist/pagination/Paginator.d.ts +0 -21
  26. package/dist/pagination/index.d.ts +0 -12
  27. package/dist/paginators/CursorPaginator.d.ts +0 -65
  28. package/dist/paginators/OffsetPaginator.d.ts +0 -74
  29. package/dist/paginators/index.d.ts +0 -5
  30. package/dist/resource/OpenAPIDescription.d.ts +0 -23
  31. package/dist/resource/ResourceModelLike.d.ts +0 -22
  32. package/dist/resource/index.d.ts +0 -5
  33. package/dist/serializer/ModelSerializer.d.ts +0 -67
  34. package/dist/serializer/Serializer.d.ts +0 -75
  35. package/dist/serializer/index.d.ts +0 -6
  36. package/dist/serializer/internal/InternalSerializerRelationKind.d.ts +0 -11
  37. package/dist/serializer/relation.d.ts +0 -45
  38. package/dist/view/APIView.d.ts +0 -26
  39. package/dist/view/GenericAPIView.d.ts +0 -60
  40. package/dist/view/generics/CreateAPIView.d.ts +0 -10
  41. package/dist/view/generics/ListAPIView.d.ts +0 -10
  42. package/dist/view/generics/ListCreateAPIView.d.ts +0 -11
  43. package/dist/view/generics/RetrieveAPIView.d.ts +0 -10
  44. package/dist/view/generics/RetrieveDestroyAPIView.d.ts +0 -11
  45. package/dist/view/generics/RetrieveUpdateAPIView.d.ts +0 -12
  46. package/dist/view/generics/RetrieveUpdateDestroyAPIView.d.ts +0 -13
  47. package/dist/view/generics/index.d.ts +0 -10
  48. package/dist/view/mixins/CreateModelMixin.d.ts +0 -11
  49. package/dist/view/mixins/DestroyModelMixin.d.ts +0 -11
  50. package/dist/view/mixins/ListModelMixin.d.ts +0 -11
  51. package/dist/view/mixins/RetrieveModelMixin.d.ts +0 -11
  52. package/dist/view/mixins/UpdateModelMixin.d.ts +0 -12
  53. package/dist/view/mixins/index.d.ts +0 -8
  54. package/dist/view-DUHg6AXl.js.map +0 -1
  55. package/dist/viewset/ModelViewSet.d.ts +0 -112
  56. package/dist/viewset/index.d.ts +0 -5
@@ -1,46 +0,0 @@
1
- import { TangoRequest } from '@danceroutine/tango-core';
2
- /**
3
- * Default user shape for RequestContext.
4
- * Consumers can provide their own user type via the TUser generic parameter.
5
- */
6
- export interface BaseUser {
7
- id: string | number;
8
- roles?: string[];
9
- }
10
- /**
11
- * Normalized request context passed through the framework adapter into viewset methods.
12
- * Generic over the user type so consumers can plug in their own auth infrastructure.
13
- */
14
- export declare class RequestContext<TUser = BaseUser> {
15
- readonly request: TangoRequest;
16
- user: TUser | null;
17
- params: Record<string, string>;
18
- static readonly BRAND: "tango.resources.request_context";
19
- readonly __tangoBrand: typeof RequestContext.BRAND;
20
- private state;
21
- constructor(request: TangoRequest, user?: TUser | null, params?: Record<string, string>);
22
- /**
23
- * Narrow an unknown value to `RequestContext`.
24
- */
25
- static isRequestContext<TUser = BaseUser>(value: unknown): value is RequestContext<TUser>;
26
- /**
27
- * Construct a context with optional user payload.
28
- */
29
- static create<TUser = BaseUser>(request: Request, user?: TUser | null): RequestContext<TUser>;
30
- /**
31
- * Store arbitrary per-request state for downstream middleware/handlers.
32
- */
33
- setState<T>(key: string | symbol, value: T): void;
34
- /**
35
- * Retrieve previously stored request state.
36
- */
37
- getState<T>(key: string | symbol): T | undefined;
38
- /**
39
- * Check whether a state key has been set.
40
- */
41
- hasState(key: string | symbol): boolean;
42
- /**
43
- * Clone the context, including route params and request-local state.
44
- */
45
- clone(): RequestContext<TUser>;
46
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * Domain boundary barrel: centralizes this subdomain's public contract.
3
- */
4
- export type { BaseUser } from './RequestContext';
5
- export { RequestContext } from './RequestContext';
@@ -1,95 +0,0 @@
1
- import { TangoQueryParams } from '@danceroutine/tango-core';
2
- import type { FilterInput, FilterValue, LookupType } from '@danceroutine/tango-orm';
3
- import { InternalFilterType } from './internal/InternalFilterType';
4
- import type { RangeOperator } from './RangeOperator';
5
- type FilterFieldRef<T extends Record<string, unknown>> = Extract<keyof T, string> | string;
6
- /**
7
- * Configuration for how a query parameter should be resolved into a filter.
8
- * Supports scalar equality, case-insensitive search, range comparisons, IN queries, and custom logic.
9
- */
10
- export type FilterResolver<T extends Record<string, unknown>> = {
11
- type: typeof InternalFilterType.SCALAR;
12
- column: FilterFieldRef<T>;
13
- } | {
14
- type: typeof InternalFilterType.ILIKE;
15
- columns: FilterFieldRef<T>[];
16
- } | {
17
- type: typeof InternalFilterType.RANGE;
18
- column: FilterFieldRef<T>;
19
- op: RangeOperator;
20
- } | {
21
- type: typeof InternalFilterType.IN;
22
- column: FilterFieldRef<T>;
23
- } | {
24
- type: typeof InternalFilterType.CUSTOM;
25
- apply: (value: string | string[] | undefined) => FilterInput<T> | undefined;
26
- };
27
- export type FilterLookup = LookupType;
28
- export type FilterValueParser = (raw: string | string[]) => FilterValue | FilterValue[] | undefined;
29
- export type FieldFilterDeclaration = true | readonly FilterLookup[] | {
30
- lookups?: readonly FilterLookup[];
31
- param?: string;
32
- parse?: FilterValueParser;
33
- };
34
- export type AliasFilterDeclaration<T extends Record<string, unknown>> = FilterResolver<T> | {
35
- field: FilterFieldRef<T>;
36
- lookup?: FilterLookup;
37
- parse?: FilterValueParser;
38
- } | {
39
- fields: readonly FilterFieldRef<T>[];
40
- lookup?: FilterLookup;
41
- parse?: FilterValueParser;
42
- };
43
- export interface FilterSetDefineConfig<T extends Record<string, unknown>> {
44
- fields?: Partial<Record<string, FieldFilterDeclaration>>;
45
- aliases?: Record<string, AliasFilterDeclaration<T>>;
46
- parsers?: Partial<Record<string, FilterValueParser>>;
47
- all?: '__all__';
48
- }
49
- /**
50
- * Declarative query-param to filter translation.
51
- *
52
- * A `FilterSet` lets viewsets expose safe, explicit filtering behavior
53
- * without leaking raw ORM filter syntax to request handlers.
54
- */
55
- export declare class FilterSet<T extends Record<string, unknown>> {
56
- private readonly spec;
57
- private readonly allowAllParams;
58
- static readonly BRAND: "tango.resources.filter_set";
59
- readonly __tangoBrand: typeof FilterSet.BRAND;
60
- /**
61
- * Resolve matching query parameters into ORM filter inputs.
62
- */
63
- constructor(spec: Record<string, FilterResolver<T>>, allowAllParams?: boolean);
64
- /**
65
- * Build a filter set from Django-style field declarations.
66
- */
67
- static define<T extends Record<string, unknown>>(config: FilterSetDefineConfig<T>): FilterSet<T>;
68
- /**
69
- * Narrow an unknown value to `FilterSet`.
70
- */
71
- static isFilterSet<T extends Record<string, unknown>>(value: unknown): value is FilterSet<T>;
72
- private static normalizeDefineConfig;
73
- private static addFieldDeclaration;
74
- private static isLookupArray;
75
- private static normalizeAliasDeclaration;
76
- private static isFilterResolverDeclaration;
77
- private static createMultiFieldResolver;
78
- private static createLookupResolver;
79
- private static resolveLookupFilter;
80
- private static resolveLookupParam;
81
- private static resolveParserValue;
82
- private static toScalarString;
83
- /**
84
- * Return a new filter set with parser-aware scalar/range/in resolvers for matching fields.
85
- */
86
- withFieldParsers(parsers: Partial<Record<string, FilterValueParser>>): FilterSet<T>;
87
- /**
88
- * Apply all configured resolvers against query params.
89
- */
90
- apply(params: TangoQueryParams): FilterInput<T>[];
91
- private buildAllResolver;
92
- private resolveFilter;
93
- private applyFieldParserOverride;
94
- }
95
- export {};
@@ -1,2 +0,0 @@
1
- import type { InternalFilterType } from './internal/InternalFilterType';
2
- export type FilterType = (typeof InternalFilterType)[keyof typeof InternalFilterType];
@@ -1,2 +0,0 @@
1
- import type { InternalRangeOperator } from './internal/InternalRangeOperator';
2
- export type RangeOperator = (typeof InternalRangeOperator)[keyof typeof InternalRangeOperator];
@@ -1,7 +0,0 @@
1
- /**
2
- * Domain boundary barrel: centralizes this subdomain's public contract.
3
- */
4
- export type { FilterType } from './FilterType';
5
- export type { RangeOperator } from './RangeOperator';
6
- export type { AliasFilterDeclaration, FieldFilterDeclaration, FilterLookup, FilterResolver, FilterSetDefineConfig, FilterValueParser, } from './FilterSet';
7
- export { FilterSet } from './FilterSet';
@@ -1,9 +0,0 @@
1
- import type { ResourceModelLike } from '../resource/index';
2
- import type { FilterValueParser } from './FilterSet';
3
- /**
4
- * Infer resource-level query-value parsers from Tango model metadata.
5
- *
6
- * Parsers are inferred conservatively from field metadata so HTTP query filters
7
- * can be coerced into typed ORM inputs without framework-specific glue.
8
- */
9
- export declare function inferModelFieldParsers<T extends Record<string, unknown>>(model: ResourceModelLike<T>): Partial<Record<keyof T, FilterValueParser>>;
@@ -1,15 +0,0 @@
1
- export declare const InternalFilterLookup: {
2
- readonly EXACT: "exact";
3
- readonly LT: "lt";
4
- readonly LTE: "lte";
5
- readonly GT: "gt";
6
- readonly GTE: "gte";
7
- readonly IN: "in";
8
- readonly ISNULL: "isnull";
9
- readonly CONTAINS: "contains";
10
- readonly ICONTAINS: "icontains";
11
- readonly STARTSWITH: "startswith";
12
- readonly ISTARTSWITH: "istartswith";
13
- readonly ENDSWITH: "endswith";
14
- readonly IENDSWITH: "iendswith";
15
- };
@@ -1,7 +0,0 @@
1
- export declare const InternalFilterType: {
2
- readonly SCALAR: "scalar";
3
- readonly ILIKE: "ilike";
4
- readonly RANGE: "range";
5
- readonly IN: "in";
6
- readonly CUSTOM: "custom";
7
- };
@@ -1,6 +0,0 @@
1
- export declare const InternalRangeOperator: {
2
- readonly GTE: "gte";
3
- readonly LTE: "lte";
4
- readonly GT: "gt";
5
- readonly LT: "lt";
6
- };
@@ -1,4 +0,0 @@
1
- import { QueryResult } from '@danceroutine/tango-orm';
2
- export declare abstract class BasePaginator {
3
- protected resolveQueryResultRows<T>(rows: readonly T[] | QueryResult<T>): T[];
4
- }
@@ -1,7 +0,0 @@
1
- import { z } from 'zod';
2
- export type CursorPaginationInputValue = {
3
- limit?: number;
4
- cursor: string | null;
5
- ordering?: string;
6
- };
7
- export declare const CursorPaginationInput: z.ZodType<CursorPaginationInputValue>;
@@ -1,7 +0,0 @@
1
- import { z } from 'zod';
2
- export type OffsetPaginationInputValue = {
3
- limit: number;
4
- offset: number;
5
- page?: number;
6
- };
7
- export declare const OffsetPaginationInput: z.ZodType<OffsetPaginationInputValue>;
@@ -1,12 +0,0 @@
1
- export interface BasePaginatedResponse<T> {
2
- results: T[];
3
- next?: string | null;
4
- previous?: string | null;
5
- }
6
- export interface OffsetPaginatedResponse<T> extends BasePaginatedResponse<T> {
7
- count?: number;
8
- }
9
- export interface CursorPaginatedResponse<T> extends BasePaginatedResponse<T> {
10
- count?: never;
11
- }
12
- export type PaginatedResponse<T> = OffsetPaginatedResponse<T> | CursorPaginatedResponse<T>;
@@ -1,21 +0,0 @@
1
- import type { TangoQueryParams } from '@danceroutine/tango-core';
2
- import type { PaginatedResponse } from './PaginatedResponse';
3
- import type { QueryResult, QuerySet } from '@danceroutine/tango-orm';
4
- export interface Page<T> {
5
- results: T[];
6
- hasNext(): boolean;
7
- hasPrevious(): boolean;
8
- nextPageNumber(): number | null;
9
- previousPageNumber(): number | null;
10
- startIndex(): number;
11
- endIndex(): number;
12
- }
13
- export interface Paginator<TModel extends Record<string, unknown>, TResult = TModel, TResponse extends PaginatedResponse<TResult> = PaginatedResponse<TResult>> {
14
- parse(params: TangoQueryParams): void;
15
- apply<TBaseResult extends Record<string, unknown>, TSourceModel, THydrated extends Record<string, unknown>>(queryset: QuerySet<TModel, TBaseResult, TSourceModel, THydrated>): QuerySet<TModel, TBaseResult, TSourceModel, THydrated>;
16
- needsTotalCount(): boolean;
17
- toResponse(results: readonly TResult[] | QueryResult<TResult>, context?: {
18
- totalCount?: number;
19
- params?: TangoQueryParams;
20
- }): TResponse;
21
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Domain boundary barrel: centralizes this subdomain's public contract.
3
- */
4
- export { OffsetPaginator } from '../paginators/OffsetPaginator';
5
- export { CursorPaginator } from '../paginators/CursorPaginator';
6
- export { OffsetPaginationInput } from './OffsetPaginationInput';
7
- export type { OffsetPaginationInputValue } from './OffsetPaginationInput';
8
- export { CursorPaginationInput } from './CursorPaginationInput';
9
- export type { CursorPaginationInputValue } from './CursorPaginationInput';
10
- export type { Paginator, Page } from './Paginator';
11
- export type { BasePaginatedResponse, CursorPaginatedResponse, OffsetPaginatedResponse, PaginatedResponse, } from './PaginatedResponse';
12
- export { BasePaginator } from './BasePaginator';
@@ -1,65 +0,0 @@
1
- import { TangoQueryParams } from '@danceroutine/tango-core';
2
- import type { QueryResult, QuerySet } from '@danceroutine/tango-orm';
3
- import { BasePaginator } from '../pagination/BasePaginator';
4
- import type { Paginator, Page } from '../pagination/Paginator';
5
- import type { CursorPaginatedResponse } from '../pagination/PaginatedResponse';
6
- /**
7
- * Cursor-based paginator for stable forward navigation with opaque cursor tokens.
8
- * It supports `limit`, `cursor`, and `ordering` query params and returns DRF-style
9
- * paginated envelopes with cursor links.
10
- */
11
- export declare class CursorPaginator<T extends Record<string, unknown>> extends BasePaginator implements Paginator<T, T, CursorPaginatedResponse<T>> {
12
- private queryset;
13
- private perPage;
14
- private cursorField;
15
- static readonly BRAND: "tango.resources.cursor_paginator";
16
- readonly __tangoBrand: typeof CursorPaginator.BRAND;
17
- private limit;
18
- private cursor;
19
- private direction;
20
- private nextCursor;
21
- private previousCursor;
22
- constructor(queryset: QuerySet<T>, perPage?: number, cursorField?: keyof T);
23
- /**
24
- * Narrow an unknown value to `CursorPaginator`.
25
- */
26
- static isCursorPaginator<T extends Record<string, unknown>>(value: unknown): value is CursorPaginator<T>;
27
- /**
28
- * Parse cursor pagination parameters from Tango query params.
29
- */
30
- parse(params: TangoQueryParams): void;
31
- /**
32
- * Parse params and return compatibility `{ limit, offset }` shape.
33
- */
34
- parseParams(params: TangoQueryParams): {
35
- limit: number;
36
- offset: number;
37
- };
38
- /**
39
- * Build a paginated response payload with cursor links.
40
- */
41
- needsTotalCount(): boolean;
42
- toResponse<TResult>(results: readonly TResult[] | QueryResult<TResult>, _context?: {
43
- totalCount?: number;
44
- params?: TangoQueryParams;
45
- }): CursorPaginatedResponse<TResult>;
46
- /**
47
- * Backward-compatible alias for `toResponse`.
48
- */
49
- getPaginatedResponse<TResult>(results: readonly TResult[] | QueryResult<TResult>, _totalCount?: number): CursorPaginatedResponse<TResult>;
50
- /**
51
- * Apply cursor constraints and ordering to a queryset.
52
- */
53
- apply<TBaseResult extends Record<string, unknown>, TSourceModel, THydrated extends Record<string, unknown>>(queryset: QuerySet<T, TBaseResult, TSourceModel, THydrated>): QuerySet<T, TBaseResult, TSourceModel, THydrated>;
54
- /**
55
- * Fetch the next cursor page.
56
- */
57
- paginate(cursor?: string): Promise<Page<T>>;
58
- /**
59
- * Cursor paginators only support page `1` as an entry point.
60
- */
61
- getPage(page: number): Promise<Page<T>>;
62
- private buildPageLink;
63
- private encodeCursor;
64
- private decodeCursor;
65
- }
@@ -1,74 +0,0 @@
1
- import { TangoQueryParams } from '@danceroutine/tango-core';
2
- import type { QueryResult, QuerySet } from '@danceroutine/tango-orm';
3
- import { BasePaginator } from '../pagination/BasePaginator';
4
- import type { Paginator, Page } from '../pagination/Paginator';
5
- import type { OffsetPaginatedResponse } from '../pagination/PaginatedResponse';
6
- /**
7
- * Offset/limit paginator modelled after DRF's LimitOffsetPagination.
8
- * Handles parsing limit/offset/page from URL query params and building
9
- * the paginated response envelope with next/previous links.
10
- *
11
- * @example
12
- * ```typescript
13
- * const paginator = new OffsetPaginator(queryset);
14
- * const { limit, offset } = paginator.parseParams(searchParams);
15
- * const results = await queryset.limit(limit).offset(offset).fetchAll();
16
- * const response = paginator.getPaginatedResponse(results, totalCount);
17
- * ```
18
- */
19
- export declare class OffsetPaginator<T extends Record<string, unknown>> extends BasePaginator implements Paginator<T, T, OffsetPaginatedResponse<T>> {
20
- private queryset;
21
- private perPage;
22
- static readonly BRAND: "tango.resources.offset_paginator";
23
- readonly __tangoBrand: typeof OffsetPaginator.BRAND;
24
- private limit;
25
- private offset;
26
- constructor(queryset: QuerySet<T>, perPage?: number);
27
- /**
28
- * Narrow an unknown value to `OffsetPaginator`.
29
- */
30
- static isOffsetPaginator<T extends Record<string, unknown>>(value: unknown): value is OffsetPaginator<T>;
31
- /**
32
- * Parse limit, offset, and page from Tango query params.
33
- * If `page` is provided, it's converted to an offset.
34
- * Stores parsed values for use by getPaginatedResponse.
35
- */
36
- parse(params: TangoQueryParams): void;
37
- /**
38
- * Parse params and return `{ limit, offset }` for compatibility callers.
39
- */
40
- parseParams(params: TangoQueryParams): {
41
- limit: number;
42
- offset: number;
43
- };
44
- /**
45
- * Build a DRF-style paginated response with count, next, and previous links.
46
- * Uses the limit/offset stored from the most recent parseParams call.
47
- */
48
- needsTotalCount(): boolean;
49
- toResponse<TResult>(results: readonly TResult[] | QueryResult<TResult>, context?: {
50
- totalCount?: number;
51
- params?: TangoQueryParams;
52
- }): OffsetPaginatedResponse<TResult>;
53
- /**
54
- * Backward-compatible alias for `toResponse`.
55
- */
56
- getPaginatedResponse<TResult>(results: readonly TResult[] | QueryResult<TResult>, totalCount?: number, params?: TangoQueryParams): OffsetPaginatedResponse<TResult>;
57
- /**
58
- * Apply current limit/offset to a queryset.
59
- */
60
- apply<TBaseResult extends Record<string, unknown>, TSourceModel, THydrated extends Record<string, unknown>>(queryset: QuerySet<T, TBaseResult, TSourceModel, THydrated>): QuerySet<T, TBaseResult, TSourceModel, THydrated>;
61
- /**
62
- * Fetch a 1-based page number from the bound queryset.
63
- */
64
- paginate(page: number): Promise<Page<T>>;
65
- /**
66
- * Fetch a 1-based page and return page metadata.
67
- */
68
- getPage(page: number): Promise<Page<T>>;
69
- /**
70
- * Count total rows for the current queryset state.
71
- */
72
- count(): Promise<number>;
73
- private buildPageLink;
74
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * Domain boundary barrel: centralizes this subdomain's public contract.
3
- */
4
- export { CursorPaginator } from './CursorPaginator';
5
- export { OffsetPaginator } from './OffsetPaginator';
@@ -1,23 +0,0 @@
1
- import type { APIViewMethod } from '../view/APIView';
2
- import type { ResolvedViewSetActionDescriptor } from '../viewset/ModelViewSet';
3
- import type { ResourceModelLike } from './ResourceModelLike';
4
- import type { AnyModelSerializer } from '../serializer/index';
5
- type SearchFieldRef<TModel extends Record<string, unknown>> = Extract<keyof TModel, string> | string;
6
- export type GenericAPIViewOpenAPIDescription<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel> = AnyModelSerializer<TModel>> = {
7
- model: ResourceModelLike<TModel> & {
8
- metadata: NonNullable<ResourceModelLike<TModel>['metadata']>;
9
- };
10
- outputSchema: TSerializer['outputSchema'];
11
- createSchema: TSerializer['createSchema'];
12
- updateSchema: TSerializer['updateSchema'];
13
- searchFields: readonly SearchFieldRef<TModel>[];
14
- orderingFields: readonly (keyof TModel)[];
15
- lookupField: keyof TModel;
16
- lookupParam: string;
17
- allowedMethods: readonly APIViewMethod[];
18
- usesDefaultOffsetPagination: boolean;
19
- };
20
- export type ModelViewSetOpenAPIDescription<TModel extends Record<string, unknown>, TSerializer extends AnyModelSerializer<TModel> = AnyModelSerializer<TModel>> = GenericAPIViewOpenAPIDescription<TModel, TSerializer> & {
21
- actions: readonly ResolvedViewSetActionDescriptor[];
22
- };
23
- export {};
@@ -1,22 +0,0 @@
1
- import type { ManagerLike } from '@danceroutine/tango-orm';
2
- export type ResourceModelFieldMetadata = {
3
- name: string;
4
- type: string;
5
- notNull?: boolean;
6
- default?: unknown;
7
- primaryKey?: boolean;
8
- };
9
- export type ResourceModelMetadata = {
10
- name: string;
11
- fields: ResourceModelFieldMetadata[];
12
- };
13
- export type ResourceModelLike<TModel extends Record<string, unknown>, TModelRecord extends Record<string, unknown> = TModel> = {
14
- /**
15
- * Resource-layer contracts own the outward representation. The underlying
16
- * model may materialize a richer ORM record, so the manager record type is kept
17
- * separate from the serializer-facing model shape.
18
- */
19
- readonly objects: ManagerLike<TModelRecord>;
20
- readonly metadata?: ResourceModelMetadata;
21
- readonly __tangoModelShape?: TModel;
22
- };
@@ -1,5 +0,0 @@
1
- /**
2
- * Domain boundary barrel: centralizes shared resource metadata contracts.
3
- */
4
- export type { ResourceModelFieldMetadata, ResourceModelLike, ResourceModelMetadata } from './ResourceModelLike';
5
- export type { GenericAPIViewOpenAPIDescription, ModelViewSetOpenAPIDescription } from './OpenAPIDescription';
@@ -1,67 +0,0 @@
1
- import type { ManagerLike } from '@danceroutine/tango-orm';
2
- import type { ResourceModelLike } from '../resource/ResourceModelLike';
3
- import { Serializer, type AnySerializerClass, type SerializerClass, type SerializerCreateInput, type SerializerOutput, type SerializerOutputResolvers, type SerializerSchema, type SerializerUpdateInput } from './Serializer';
4
- import type { ModelSerializerRelationFields } from './relation';
5
- export type ModelSerializerClass<TModel extends Record<string, unknown> = Record<string, unknown>, TCreateSchema extends SerializerSchema = SerializerSchema, TUpdateSchema extends SerializerSchema = SerializerSchema, TOutputSchema extends SerializerSchema = SerializerSchema, TModelRecord extends Record<string, unknown> = TModel> = SerializerClass<TCreateSchema, TUpdateSchema, TOutputSchema, TModelRecord> & {
6
- new (): ModelSerializer<TModel, TCreateSchema, TUpdateSchema, TOutputSchema, TModelRecord>;
7
- readonly model?: ResourceModelLike<TModel, TModelRecord>;
8
- readonly relationFields?: ModelSerializerRelationFields<TModelRecord>;
9
- };
10
- export type AnyModelSerializer<TModel extends Record<string, unknown> = Record<string, unknown>> = ModelSerializerClass<TModel, SerializerSchema, SerializerSchema, SerializerSchema, any>;
11
- export type AnyModelSerializerClass = AnyModelSerializer;
12
- /**
13
- * Zod-backed serializer with default model-manager persistence behavior.
14
- */
15
- export declare abstract class ModelSerializer<TModel extends Record<string, unknown>, TCreateSchema extends SerializerSchema, TUpdateSchema extends SerializerSchema, TOutputSchema extends SerializerSchema, TModelRecord extends Record<string, unknown> = TModel> extends Serializer<TCreateSchema, TUpdateSchema, TOutputSchema, TModelRecord> {
16
- static readonly model?: unknown;
17
- static readonly relationFields: ModelSerializerRelationFields<Record<string, unknown>> | undefined;
18
- /**
19
- * Return the Tango model backing this serializer.
20
- */
21
- getModel(): ResourceModelLike<TModel, TModelRecord>;
22
- /**
23
- * Return the manager used for create and update workflows.
24
- */
25
- getManager(): ManagerLike<TModelRecord>;
26
- /**
27
- * Return the declarative relation-field map for this serializer.
28
- */
29
- getRelationFields(): ModelSerializerRelationFields<TModelRecord>;
30
- /**
31
- * Merge relation-field read resolvers into the serializer output path.
32
- */
33
- getOutputResolvers(): SerializerOutputResolvers<TModelRecord>;
34
- /**
35
- * Validate, enrich, persist, and serialize a create workflow.
36
- */
37
- create(input: unknown): Promise<SerializerOutput<ModelSerializerClass<TModel, TCreateSchema, TUpdateSchema, TOutputSchema, TModelRecord>>>;
38
- /**
39
- * Validate, enrich, persist, and serialize an update workflow.
40
- */
41
- update(id: TModelRecord[keyof TModelRecord], input: unknown): Promise<SerializerOutput<ModelSerializerClass<TModel, TCreateSchema, TUpdateSchema, TOutputSchema, TModelRecord>>>;
42
- /**
43
- * Override to normalize create input for this resource workflow before the
44
- * manager call.
45
- *
46
- * Model-owned persistence rules belong in model hooks so they also run for
47
- * scripts and direct manager usage.
48
- */
49
- protected beforeCreate(data: SerializerCreateInput<ModelSerializerClass<TModel, TCreateSchema, TUpdateSchema, TOutputSchema, TModelRecord>>): Promise<Partial<TModelRecord>>;
50
- /**
51
- * Override to normalize update input for this resource workflow before the
52
- * manager call.
53
- *
54
- * Model-owned persistence rules belong in model hooks so they also run for
55
- * scripts and direct manager usage.
56
- */
57
- protected beforeUpdate(_id: TModelRecord[keyof TModelRecord], data: SerializerUpdateInput<ModelSerializerClass<TModel, TCreateSchema, TUpdateSchema, TOutputSchema, TModelRecord>>): Promise<Partial<TModelRecord>>;
58
- private extractRelationWrites;
59
- private stripRelationFields;
60
- private applyRelationWrites;
61
- private serializeRelationField;
62
- private syncManyToManyRelation;
63
- private resolveWriteTargets;
64
- private getManyToManyManager;
65
- private getManyToManyRelationMeta;
66
- }
67
- export type { AnySerializerClass };
@@ -1,75 +0,0 @@
1
- import { z } from 'zod';
2
- export type SerializerSchema = z.ZodTypeAny;
3
- export type SerializerClass<TCreateSchema extends SerializerSchema = SerializerSchema, TUpdateSchema extends SerializerSchema = SerializerSchema, TOutputSchema extends SerializerSchema = SerializerSchema, TRecord = unknown> = {
4
- new (): Serializer<TCreateSchema, TUpdateSchema, TOutputSchema, TRecord>;
5
- readonly createSchema: TCreateSchema;
6
- readonly updateSchema: TUpdateSchema;
7
- readonly outputSchema: TOutputSchema;
8
- readonly outputResolvers?: SerializerOutputResolvers<TRecord>;
9
- };
10
- export type AnySerializerClass = SerializerClass<SerializerSchema, SerializerSchema, SerializerSchema, any>;
11
- export type SerializerCreateInput<TSerializer extends AnySerializerClass> = z.output<TSerializer['createSchema']>;
12
- export type SerializerUpdateInput<TSerializer extends AnySerializerClass> = z.output<TSerializer['updateSchema']>;
13
- export type SerializerOutput<TSerializer extends AnySerializerClass> = z.output<TSerializer['outputSchema']>;
14
- export type SerializerOutputResolver<TRecord = unknown> = (record: TRecord) => unknown | Promise<unknown>;
15
- export type SerializerOutputResolvers<TRecord = unknown> = Record<string, SerializerOutputResolver<TRecord>>;
16
- /**
17
- * DRF-inspired base serializer backed by Zod schemas.
18
- *
19
- * Tango serializers keep Zod as the source of truth for validation and type
20
- * inference while centralizing create, update, and representation workflows in
21
- * one class-owned contract.
22
- */
23
- export declare abstract class Serializer<TCreateSchema extends SerializerSchema, TUpdateSchema extends SerializerSchema, TOutputSchema extends SerializerSchema, TRecord = unknown> {
24
- static readonly createSchema: SerializerSchema;
25
- static readonly updateSchema: SerializerSchema;
26
- static readonly outputSchema: SerializerSchema;
27
- static readonly outputResolvers: SerializerOutputResolvers<// oxlint-disable-next-line typescript/no-explicit-any
28
- any> | undefined;
29
- /**
30
- * Return the serializer class for the current instance.
31
- */
32
- getSerializerClass(): SerializerClass<TCreateSchema, TUpdateSchema, TOutputSchema, TRecord>;
33
- /**
34
- * Return the Zod schema used for create payloads.
35
- */
36
- getCreateSchema(): TCreateSchema;
37
- /**
38
- * Return the Zod schema used for update payloads.
39
- */
40
- getUpdateSchema(): TUpdateSchema;
41
- /**
42
- * Return the Zod schema used for serialized output.
43
- */
44
- getOutputSchema(): TOutputSchema;
45
- /**
46
- * Return the resolver map used to enrich serializer output fields before
47
- * the outward Zod schema parses the final response shape.
48
- */
49
- getOutputResolvers(): SerializerOutputResolvers<TRecord>;
50
- /**
51
- * Validate unknown input for create workflows.
52
- */
53
- deserializeCreate(input: unknown): z.output<TCreateSchema>;
54
- /**
55
- * Validate unknown input for update workflows.
56
- */
57
- deserializeUpdate(input: unknown): z.output<TUpdateSchema>;
58
- /**
59
- * Convert a persisted record into its outward-facing representation.
60
- *
61
- * @deprecated Use `serialize(...)` instead so serializer-owned output
62
- * resolvers run before the outward Zod schema parses the response shape.
63
- */
64
- toRepresentation(record: TRecord): z.output<TOutputSchema>;
65
- /**
66
- * Resolve serializer-owned output fields and parse the outward response
67
- * contract.
68
- */
69
- serialize(record: TRecord): Promise<z.output<TOutputSchema>>;
70
- /**
71
- * Serialize many records through the same outward response contract.
72
- */
73
- serializeMany(records: readonly TRecord[]): Promise<z.output<TOutputSchema>[]>;
74
- private applyOutputResolvers;
75
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * Domain boundary barrel: centralizes this subdomain's public contract.
3
- */
4
- export { Serializer, type SerializerClass, type AnySerializerClass, type SerializerCreateInput, type SerializerOutputResolver, type SerializerOutputResolvers, type SerializerUpdateInput, type SerializerOutput, type SerializerSchema, } from './Serializer';
5
- export { ModelSerializer, type ModelSerializerClass, type AnyModelSerializer, type AnyModelSerializerClass, } from './ModelSerializer';
6
- export { relation, type ModelSerializerRelationFields, type ManyToManyManagerKeys, type ManyToManyRelationField, type ManyToManyReadStrategy, type ManyToManyWriteStrategy, } from './relation';
@@ -1,11 +0,0 @@
1
- export declare const InternalSerializerRelationKind: {
2
- readonly MANY_TO_MANY: "manyToMany";
3
- };
4
- export declare const InternalManyToManyReadStrategyKind: {
5
- readonly PK_LIST: "pkList";
6
- readonly NESTED: "nested";
7
- };
8
- export declare const InternalManyToManyWriteStrategyKind: {
9
- readonly PK_LIST: "pkList";
10
- readonly SLUG_LIST: "slugList";
11
- };