• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

teableio / teable / 8389034572

22 Mar 2024 10:38AM CUT coverage: 26.087% (-2.1%) from 28.208%
8389034572

Pull #487

github

web-flow
Merge 3045b1f94 into a06c6afb1
Pull Request #487: refactor: move zod schema to openapi

2100 of 3363 branches covered (62.44%)

282 of 757 new or added lines in 74 files covered. (37.25%)

224 existing lines in 8 files now uncovered.

25574 of 98035 relevant lines covered (26.09%)

5.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/openapi/src/selection/range.ts
1
import type { RouteConfig } from '@asteasolutions/zod-to-openapi';
×
NEW
2
import { filterSchema, groupSchema } from '@teable/core';
×
3
import { axios } from '../axios';
×
NEW
4
import { contentQueryBaseSchema, orderBySchema } from '../record';
×
5
import { registerRoute, urlBuilder } from '../utils';
×
6
import { z } from '../zod';
×
7

×
8
export const GET_IDS_FROM_RANGES_URL = '/table/{tableId}/selection/range-to-id';
×
9

×
10
export enum RangeType {
×
11
  Rows = 'rows',
×
12
  Columns = 'columns',
×
13
}
×
14

×
15
export const cellSchema = z.tuple([z.number(), z.number()]);
×
16

×
17
export type ICell = z.infer<typeof cellSchema>;
×
18

×
19
const rangeTypeSchema = z.nativeEnum(RangeType).optional().openapi({
×
20
  description: 'Types of non-contiguous selections',
×
21
  example: RangeType.Columns,
×
22
});
×
23

×
24
export const rangesSchema = z.array(cellSchema).min(1, {
×
25
  message: 'The range parameter must be a valid 2D array with even length.',
×
26
});
×
27

×
28
export const rangesRoSchema = contentQueryBaseSchema.extend({
×
29
  filter: filterSchema.optional(),
×
30
  orderBy: orderBySchema.optional(),
×
31
  groupBy: groupSchema.optional(),
×
32
  ranges: rangesSchema.openapi({
×
33
    description:
×
34
      'The parameter "ranges" is used to represent the coordinates of a selected range in a table. ',
×
35
    example: [
×
36
      [0, 0],
×
37
      [1, 1],
×
38
    ],
×
39
  }),
×
40
  type: rangeTypeSchema,
×
41
});
×
42

×
43
export type IRangesRo = z.infer<typeof rangesRoSchema>;
×
44

×
45
export const rangesQuerySchema = contentQueryBaseSchema.extend({
×
46
  ranges: z
×
47
    .string()
×
48
    .transform((value, ctx) => {
×
49
      const parsingResult = rangesSchema.safeParse(JSON.parse(value));
×
50
      if (!parsingResult.success) {
×
51
        parsingResult.error.issues.forEach((issue) => {
×
52
          ctx.addIssue(issue);
×
53
        });
×
54
        return z.NEVER;
×
55
      }
×
56
      return parsingResult.data;
×
57
    })
×
58
    .openapi({
×
59
      type: 'string',
×
60
      description:
×
61
        'The parameter "ranges" is used to represent the coordinates [column, row][] of a selected range in a table. ',
×
62
      example: '[[0, 0], [1, 1]]',
×
63
    }),
×
64
  type: rangeTypeSchema,
×
65
});
×
66

×
67
export enum IdReturnType {
×
68
  RecordId = 'recordId',
×
69
  FieldId = 'fieldId',
×
70
  All = 'all',
×
71
}
×
72

×
73
export const rangesToIdQuerySchema = rangesQuerySchema.extend({
×
74
  returnType: z.nativeEnum(IdReturnType).openapi({ description: 'Define which Id to return.' }),
×
75
});
×
76

×
77
export type IRangesToIdQuery = z.infer<typeof rangesToIdQuerySchema>;
×
78

×
79
export const rangesToIdVoSchema = z.object({
×
80
  recordIds: z.array(z.string()).optional(),
×
81
  fieldIds: z.array(z.string()).optional(),
×
82
});
×
83

×
84
export type IRangesToIdVo = z.infer<typeof rangesToIdVoSchema>;
×
85

×
86
export const GetIdsFromRangesRoute: RouteConfig = registerRoute({
×
87
  method: 'get',
×
88
  path: GET_IDS_FROM_RANGES_URL,
×
89
  description: 'Get the id of records and fields from the selected range',
×
90
  request: {
×
91
    params: z.object({
×
92
      tableId: z.string(),
×
93
    }),
×
94
    query: rangesToIdQuerySchema,
×
95
  },
×
96
  responses: {
×
97
    200: {
×
98
      description: 'Copy content',
×
99
      content: {
×
100
        'application/json': {
×
101
          schema: rangesToIdVoSchema,
×
102
        },
×
103
      },
×
104
    },
×
105
  },
×
106
  tags: ['selection'],
×
107
});
×
108

×
109
export const getIdsFromRanges = async (tableId: string, rangesToIdQuery: IRangesToIdQuery) => {
×
110
  return axios.get<IRangesToIdVo>(
×
111
    urlBuilder(GET_IDS_FROM_RANGES_URL, {
×
112
      tableId,
×
113
    }),
×
114
    {
×
115
      params: {
×
116
        ...rangesToIdQuery,
×
117
        filter: JSON.stringify(rangesToIdQuery.filter),
×
118
        orderBy: JSON.stringify(rangesToIdQuery.orderBy),
×
119
        ranges: JSON.stringify(rangesToIdQuery.ranges),
×
120
      },
×
121
    }
×
122
  );
×
123
};
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc