Skip to content

Commit

Permalink
Redefine types for validations in a way that works for doc generation
Browse files Browse the repository at this point in the history
  • Loading branch information
aledalgrande committed Mar 20, 2024
1 parent 392861a commit 8e6f4d3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import {Metafield} from './metafields';
interface Metafield {
description?: string;
id: string;
namespace: string;
key: string;
value: string;
type: string;
}

interface Validation {
/**
* the validation's gid when active in a shop
*/
id: string;
/**
* the metafields owned by the validation
*/
metafields: Metafield[];
}

interface ShopifyFunction {
/**
* the validation function's unique identifier
*/
id: string;
}

/**
* The object that exposes the validation with its settings.
*/
export interface ValidationData {
validation?: {
/**
* the validation's gid when active in a shop
*/
id: string;
/**
* the metafields owned by the validation
*/
metafields: Metafield[];
};
shopifyFunction: {
/**
* the validation function's unique identifier
*/
id: string;
};
validation?: Validation;
shopifyFunction: ShopifyFunction;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ const supportedDefinitionTypes = [

export type SupportedDefinitionType = typeof supportedDefinitionTypes[number];

export interface Metafield {
description?: string;
id: string;
namespace: string;
key: string;
value: string;
type: string;
}

interface MetafieldUpdateChange {
type: 'updateMetafield';
key: string;
Expand All @@ -80,6 +71,6 @@ type MetafieldChangeResult =
| MetafieldChangeSuccess
| MetafieldChangeResultError;

export interface ApplyMetafieldChange {
(change: MetafieldChange): Promise<MetafieldChangeResult>;
}
export type ApplyMetafieldChange = (
change: MetafieldChange,
) => Promise<MetafieldChangeResult>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs';

const data: ReferenceEntityTemplateSchema = {
name: 'Validation Settings API',
description:
'This API is available Validation Settings extensions. Refer to the [tutorial](/docs/apps/checkout/validation/create-complex-validation-rules) for more information. Note that the [`FunctionSettings`](/docs/api/admin-extensions/components/forms/functionsettings) component is required to build Validation Settings extensions.',
isVisualComponent: false,
type: 'API',
definitions: [
{
title: 'applyMetafieldChange',
description: 'Applies a change to the validation settings.',
type: 'ApplyMetafieldChange',
},
{
title: 'data',
description: 'The object that exposes the validation with its settings.',
type: 'ValidationData',
},
],
category: 'API',
related: [],
};

export default data;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {ValidationData} from './launch-options';
export interface ValidationSettingsApi<
ExtensionTarget extends AnyExtensionTarget,
> extends StandardApi<ExtensionTarget> {
/**
* Applies a change to the validation settings.
*/
applyMetafieldChange: ApplyMetafieldChange;
data: ValidationData;
}

0 comments on commit 8e6f4d3

Please sign in to comment.