Skip to content

Commit 1cfb214

Browse files
authored
Add editor charts api (#3078)
1 parent 824ae9f commit 1cfb214

File tree

11 files changed

+65
-6
lines changed

11 files changed

+65
-6
lines changed

src/server/components/public-api/utils/init-public-api-swagger.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ export const initPublicApiSwagger = (app: ExpressKit) => {
9393
const swaggerOptions = {
9494
url: jsonPath,
9595
validatorUrl: null,
96+
tagsSorter: 'alpha',
97+
operationsSorter: 'alpha',
9698
};
9799

98100
app.express.use(
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const registeredComponents = new Set<string>();
2+
3+
export const registerComponentId = (id: string): string => {
4+
if (registeredComponents.has(id)) {
5+
throw new Error(`OpenAPI component ${id} is already registered`);
6+
}
7+
8+
registeredComponents.add(id);
9+
10+
return id;
11+
};

src/shared/schema/gateway-utils.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const VALIDATION_SCHEMA_KEY = Symbol('$schema');
2323
const registerValidationSchema = <T extends object>(value: T, schema: TypedActionSchema): T => {
2424
Object.defineProperty(value, VALIDATION_SCHEMA_KEY, {
2525
value: schema,
26-
enumerable: false,
26+
configurable: true,
2727
});
2828

2929
return value;
@@ -62,6 +62,39 @@ export const createTypedAction = <TOutput, TParams, TTransformed = TOutput>(
6262
return registerValidationSchema(actionConfig, schemaValidationObject);
6363
};
6464

65+
export const createExtendedTypedAction =
66+
<TConfigOutput, TConfigParams, TConfigTransformed = TConfigOutput>(
67+
actionConfig: ApiServiceActionConfig<
68+
AppContext,
69+
Request,
70+
Response,
71+
TConfigOutput,
72+
TConfigParams,
73+
TConfigTransformed
74+
>,
75+
) =>
76+
<TResult extends TConfigTransformed, TParams extends TConfigParams>(schema: {
77+
resultSchema: z.ZodType<TResult>;
78+
paramsSchema: z.ZodType<TParams>;
79+
}) => {
80+
const schemaValidationObject = {
81+
paramsSchema: schema.paramsSchema,
82+
resultSchema: schema.resultSchema,
83+
};
84+
85+
return registerValidationSchema(
86+
actionConfig as unknown as ApiServiceActionConfig<
87+
AppContext,
88+
Request,
89+
Response,
90+
TConfigOutput,
91+
TParams,
92+
TResult
93+
>,
94+
schemaValidationObject,
95+
);
96+
};
97+
6598
type AuthArgsData = {
6699
userAccessToken?: string;
67100
serviceUserAccessToken?: string;

src/shared/schema/mix/schemas/ql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const deleteQLChartResultSchema = z.object({});
88

99
export const getQLChartArgsSchema = z.strictObject({
1010
chartId: z.string(),
11-
workbookId: z.union([z.string(), z.null()]).optional(),
11+
workbookId: z.string().nullable().optional(),
1212
revId: z.string().optional(),
1313
includePermissions: z.boolean().optional(),
1414
includeLinks: z.boolean().optional(),

src/shared/schema/mix/schemas/wizard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const deleteWizardChartResultSchema = z.object({});
88

99
export const getWizardChartArgsSchema = z.strictObject({
1010
chartId: z.string(),
11-
workbookId: z.union([z.string(), z.null()]).optional(),
11+
workbookId: z.string().nullable().optional(),
1212
revId: z.string().optional(),
1313
includePermissions: z.boolean().optional(),
1414
includeLinks: z.boolean().optional(),

src/shared/schema/us/actions/editor.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const editorActions = {
1616
path: () => `${PATH_PREFIX}/entries`,
1717
params: (
1818
{
19+
version,
1920
type,
2021
key,
2122
data,
@@ -31,6 +32,7 @@ export const editorActions = {
3132
) => {
3233
return {
3334
body: {
35+
version,
3436
scope: 'widget',
3537
type,
3638
key,
@@ -52,9 +54,13 @@ export const editorActions = {
5254
method: 'POST',
5355
path: ({entryId}) => `${PATH_PREFIX}/entries/${filterUrlFragment(entryId)}`,
5456

55-
params: ({data, mode, revId, meta = {}, links, annotation, description = ''}, headers) => {
57+
params: (
58+
{version, data, mode, revId, meta = {}, links, annotation, description = ''},
59+
headers,
60+
) => {
5661
return {
5762
body: {
63+
version,
5864
mode,
5965
meta,
6066
data,

src/shared/schema/us/schemas/entries/list-directory.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ export const listDirectoryArgsSchema = z.object({
1919
page: z.number().optional(),
2020
pageSize: z.number().optional(),
2121
includePermissionsInfo: z.boolean().optional(),
22-
// Broken in US controller
23-
// ignoreWorkbookEntries: z.boolean().optional(),
2422
});
2523

2624
export const listDirectoryBreadCrumbSchema = z.object({

src/shared/schema/us/types/editor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface CreateEditorChartResponse extends EntryFields {
77
}
88

99
export interface CreateEditorChartArgs {
10+
version?: number;
1011
type: string;
1112
data: EntryFieldData;
1213
key?: string;
@@ -24,6 +25,7 @@ export interface UpdateEditorChartResponse extends EntryFields {
2425
}
2526

2627
export interface UpdateEditorChartArgs {
28+
version?: number;
2729
entryId: string;
2830
mode: 'save' | 'publish';
2931
data: EntryFieldData;

src/shared/schema/us/types/fields.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type EntryFieldPublishedId = null | string;
88

99
// corresponds to RETURN_COLUMNS from US
1010
export interface EntryFields {
11+
version?: number | null;
1112
displayAlias?: string | null;
1213
createdAt: string;
1314
createdBy: string;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function assertNonEmptyArray<T>(arr: T[], message?: string): asserts arr is [T, ...T[]] {
2+
if (arr.length === 0) {
3+
throw new Error(message ?? 'Array must not be empty!');
4+
}
5+
}

0 commit comments

Comments
 (0)