Skip to content

Commit

Permalink
feat(sanity): export ConcreteRuleClass class
Browse files Browse the repository at this point in the history
  • Loading branch information
juice49 committed Apr 26, 2024
1 parent 67f5e8e commit 546d0e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
6 changes: 5 additions & 1 deletion packages/sanity/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ export * from './templates'
export * from './theme'
export * from './user-color'
export * from './util'
export {validateDocument, type ValidateDocumentOptions} from './validation'
export {
Rule as ConcreteRuleClass,
validateDocument,
type ValidateDocumentOptions,
} from './validation'
export * from './version'
34 changes: 19 additions & 15 deletions packages/sanity/src/core/validation/Rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,25 @@ const ruleConstraintTypes: RuleTypeConstraint[] = [
'String',
]

// Note: `RuleClass` and `Rule` are split to fit the current `@sanity/types`
// setup. Classes are a bit weird in the `@sanity/types` package because classes
// create an actual javascript class while simultaneously creating a type
// definition.
//
// This implicitly creates two types:
// 1. the instance type — `Rule` and
// 2. the static/class type - `RuleClass`
//
// The `RuleClass` type contains the static methods and the `Rule` instance
// contains the instance methods.
//
// This package exports the RuleClass as a value without implicitly exporting
// an instance definition. This should help reminder downstream users to import
// from the `@sanity/types` package.
/**
* Note: `RuleClass` and `Rule` are split to fit the current `@sanity/types`
* setup. Classes are a bit weird in the `@sanity/types` package because classes
* create an actual javascript class while simultaneously creating a type
* definition.
*
* This implicitly creates two types:
* 1. the instance type — `Rule` and
* 2. the static/class type - `RuleClass`
*
* The `RuleClass` type contains the static methods and the `Rule` instance
* contains the instance methods.
*
* This package exports the RuleClass as a value without implicitly exporting
* an instance definition. This should help reminder downstream users to import
* from the `@sanity/types` package.
*
* @internal
*/
export const Rule: RuleClass = class Rule implements IRule {
static readonly FIELD_REF = FIELD_REF
static array = (def?: SchemaType): Rule => new Rule(def).type('Array')
Expand Down

0 comments on commit 546d0e1

Please sign in to comment.