Socket
Socket
Sign inDemoInstall

@sanity/types

Package Overview
Dependencies
1
Maintainers
17
Versions
851
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.150.9-review-changes.736 to 1.150.9-review-changes.877

lib/helpers.d.ts

21

lib/assets/types.d.ts

@@ -1,2 +0,8 @@

import { Reference, SanityDocument } from '../documents';
/// <reference types="react" />
import { Reference } from '../reference';
import { SanityDocument } from '../documents';
export interface File {
[key: string]: unknown;
asset: Reference;
}
export interface Image {

@@ -17,2 +23,4 @@ [key: string]: unknown;

originalFilename?: string;
creditLine?: string;
source?: AssetSourceSpec;
}

@@ -74,1 +82,12 @@ export interface ImageAsset extends Asset {

export declare type SwatchName = 'darkMuted' | 'darkVibrant' | 'dominant' | 'lightMuted' | 'lightVibrant' | 'muted' | 'vibrant';
export interface AssetSourceSpec {
id: string;
name: string;
url?: string;
}
export interface AssetSource {
name: string;
title: string;
component: React.ComponentType;
icon?: React.ComponentType;
}

3

lib/documents/asserters.d.ts

@@ -1,5 +0,4 @@

import { KeyedObject, Reference, SanityDocument, TypedObject } from './types';
import { KeyedObject, SanityDocument, TypedObject } from './types';
export declare function isSanityDocument(document: unknown): document is SanityDocument;
export declare function isReference(reference: unknown): reference is Reference;
export declare function isTypedObject(obj: unknown): obj is TypedObject;
export declare function isKeyedObject(obj: unknown): obj is KeyedObject;

@@ -7,24 +7,17 @@ "use strict";

exports.isSanityDocument = isSanityDocument;
exports.isReference = isReference;
exports.isTypedObject = isTypedObject;
exports.isKeyedObject = isKeyedObject;
function isObject(obj) {
return typeof obj === 'object' && obj !== null && !Array.isArray(obj);
}
var _helpers = require("../helpers");
function isSanityDocument(document) {
return isObject(document) && typeof document._id === 'string' && typeof document._type === 'string';
return (0, _helpers.isObject)(document) && typeof document._id === 'string' && typeof document._type === 'string';
}
function isReference(reference) {
return isObject(reference) && typeof reference._ref === 'string';
}
function isTypedObject(obj) {
return isObject(obj) && typeof obj._type === 'string';
return (0, _helpers.isObject)(obj) && typeof obj._type === 'string';
}
function isKeyedObject(obj) {
return isObject(obj) && typeof obj._key === 'string';
return (0, _helpers.isObject)(obj) && typeof obj._key === 'string';
}

@@ -9,10 +9,2 @@ export interface SanityDocument {

}
export interface Reference {
_ref: string;
_key?: string;
_weak?: boolean;
}
export interface WeakReference extends Reference {
_weak: true;
}
export interface TypedObject {

@@ -19,0 +11,0 @@ [key: string]: unknown;

@@ -9,1 +9,3 @@ export * from './slug';

export * from './validation';
export * from './reference';
export * from './mutations';

@@ -101,2 +101,26 @@ "use strict";

});
});
var _reference = require("./reference");
Object.keys(_reference).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _reference[key];
}
});
});
var _mutations = require("./mutations");
Object.keys(_mutations).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _mutations[key];
}
});
});

@@ -1,2 +0,4 @@

import { ObjectSchemaType, SchemaType } from './types';
import { ObjectSchemaType, ReferenceSchemaType, SchemaType, TitledListValue } from './types';
export declare function isObjectSchemaType(type: SchemaType): type is ObjectSchemaType;
export declare function isReferenceSchemaType(type: SchemaType | ReferenceSchemaType): type is ReferenceSchemaType;
export declare function isTitledListValue(item: unknown): item is TitledListValue;

@@ -7,5 +7,15 @@ "use strict";

exports.isObjectSchemaType = isObjectSchemaType;
exports.isReferenceSchemaType = isReferenceSchemaType;
exports.isTitledListValue = isTitledListValue;
function isObjectSchemaType(type) {
return type.jsonType === 'object';
}
function isReferenceSchemaType(type) {
return type.jsonType === 'object' && 'to' in type && Array.isArray(type.to);
}
function isTitledListValue(item) {
return typeof item === 'object' && item !== null && 'title' in item && 'value' in item && Object.keys(item).length === 2;
}

@@ -0,1 +1,4 @@

/// <reference types="react" />
import { ReferenceOptions } from '../reference';
import { AssetSource } from '../assets';
import { SlugOptions } from '../slug';

@@ -13,12 +16,22 @@ export interface Schema {

type?: SchemaType;
readOnly?: boolean;
icon?: React.ComponentType;
/**
* @deprecated
*/
placeholder?: string;
}
export interface TitledListValue<V = unknown> {
_key?: string;
title: string;
value: V;
}
interface EnumListProps<V = unknown> {
list?: TitledListValue<V>[] | V[];
layout?: 'radio' | 'dropdown';
direction?: 'horizontal' | 'vertical';
}
export interface StringSchemaType extends BaseSchemaType {
jsonType: 'string';
options?: {
list?: {
title?: string;
value: string;
}[];
layout?: 'radio' | 'dropdown';
direction?: 'horizontal' | 'vertical';
options?: EnumListProps<string> & {
dateFormat?: string;

@@ -28,4 +41,8 @@ timeFormat?: string;

}
export interface TextSchemaType extends StringSchemaType {
rows?: number;
}
export interface NumberSchemaType extends BaseSchemaType {
jsonType: 'number';
options?: EnumListProps<number>;
}

@@ -40,9 +57,7 @@ export interface BooleanSchemaType extends BaseSchemaType {

jsonType: 'array';
of: Exclude<SchemaType, ArraySchemaType>[];
of: (Exclude<SchemaType, ArraySchemaType> | ReferenceSchemaType)[];
options?: {
list?: {
title?: string;
value: V;
}[] | V[];
list?: TitledListValue<V>[] | V[];
layout?: V extends string ? 'tags' : 'grid';
direction?: 'horizontal' | 'vertical';
sortable?: boolean;

@@ -52,3 +67,3 @@ /**

*/
editModal?: 'dialog' | 'fullscreen' | 'popover';
editModal?: 'dialog' | 'fullscreen' | 'popover' | 'fold';
};

@@ -61,3 +76,3 @@ }

}
export interface SlugSchemaType extends ObjectSchemaType {
export interface SlugSchemaType extends BaseSchemaType {
jsonType: 'object';

@@ -76,2 +91,7 @@ options?: SlugOptions;

}
export interface ObjectSchemaTypeWithOptions extends ObjectSchemaType {
options?: CollapseOptions & {
columns?: number;
};
}
export interface SingleFieldSet {

@@ -86,5 +106,3 @@ single: true;

single?: false;
options?: {
collapsible?: boolean;
collapsed?: boolean;
options?: CollapseOptions & {
columns?: number;

@@ -95,5 +113,31 @@ };

export declare type Fieldset = SingleFieldSet | MultiFieldSet;
export interface CollapseOptions {
collapsable?: boolean;
collapsed?: boolean;
/**
* @deprecated Use `collapsable`/`collapsed`
*/
collapsible?: boolean;
}
export interface ReferenceSchemaType extends ObjectSchemaType {
jsonType: 'object';
to: SchemaType[];
weak?: boolean;
options?: ReferenceOptions;
}
export interface AssetSchemaTypeOptions {
accept?: string;
storeOriginalFilename?: boolean;
}
export interface FileSchemaType extends ObjectSchemaType {
options?: AssetSchemaTypeOptions;
}
export interface ImageSchemaType extends ObjectSchemaType {
options?: AssetSchemaTypeOptions & {
hotspot?: boolean;
metadata?: ('exif' | 'location' | 'lqip' | 'palette')[];
sources?: AssetSource[];
};
}
export declare type SchemaType = ArraySchemaType | BooleanSchemaType | NumberSchemaType | ObjectSchemaType | StringSchemaType;
export {};
{
"name": "@sanity/types",
"version": "1.150.9-review-changes.736+39ff07c30",
"version": "1.150.9-review-changes.877+10212e75d",
"description": "Type definitions for common Sanity data structures",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"sideEffects": false,
"author": "Sanity.io <hello@sanity.io>",

@@ -35,3 +36,3 @@ "license": "MIT",

"homepage": "https://www.sanity.io/",
"gitHead": "39ff07c30315dfc1aa27c881b22087b3a67a451f"
"gitHead": "10212e75d3908bec1ba0e5dff51e02c22624db59"
}

@@ -1,5 +0,11 @@

import {Reference, SanityDocument} from '../documents'
import {Reference} from '../reference'
import {SanityDocument} from '../documents'
export interface File {
[key: string]: unknown // We allow meta-fields on file
asset: Reference
}
export interface Image {
[key: string]: unknown
[key: string]: unknown // We allow meta-fields on image
asset: Reference

@@ -19,2 +25,6 @@ crop?: ImageCrop

originalFilename?: string
// External asset source extensions
creditLine?: string
source?: AssetSourceSpec
}

@@ -92,1 +102,14 @@

| 'vibrant'
export interface AssetSourceSpec {
id: string
name: string
url?: string
}
export interface AssetSource {
name: string
title: string
component: React.ComponentType
icon?: React.ComponentType
}

@@ -1,7 +0,4 @@

import {KeyedObject, Reference, SanityDocument, TypedObject} from './types'
import {isObject} from '../helpers'
import {KeyedObject, SanityDocument, TypedObject} from './types'
function isObject(obj: unknown): obj is Record<string, unknown> {
return typeof obj === 'object' && obj !== null && !Array.isArray(obj)
}
export function isSanityDocument(document: unknown): document is SanityDocument {

@@ -13,6 +10,2 @@ return (

export function isReference(reference: unknown): reference is Reference {
return isObject(reference) && typeof reference._ref === 'string'
}
export function isTypedObject(obj: unknown): obj is TypedObject {

@@ -19,0 +12,0 @@ return isObject(obj) && typeof obj._type === 'string'

@@ -10,12 +10,2 @@ export interface SanityDocument {

export interface Reference {
_ref: string
_key?: string
_weak?: boolean
}
export interface WeakReference extends Reference {
_weak: true
}
export interface TypedObject {

@@ -22,0 +12,0 @@ [key: string]: unknown

@@ -9,1 +9,3 @@ export * from './slug'

export * from './validation'
export * from './reference'
export * from './mutations'

@@ -1,2 +0,2 @@

import {ObjectSchemaType, SchemaType} from './types'
import {ObjectSchemaType, ReferenceSchemaType, SchemaType, TitledListValue} from './types'

@@ -6,1 +6,17 @@ export function isObjectSchemaType(type: SchemaType): type is ObjectSchemaType {

}
export function isReferenceSchemaType(
type: SchemaType | ReferenceSchemaType
): type is ReferenceSchemaType {
return type.jsonType === 'object' && 'to' in type && Array.isArray(type.to)
}
export function isTitledListValue(item: unknown): item is TitledListValue {
return (
typeof item === 'object' &&
item !== null &&
'title' in item &&
'value' in item &&
Object.keys(item).length === 2
)
}
// Note: INCOMPLETE, but it's a start
import {ReferenceOptions} from '../reference'
import {AssetSource} from '../assets'
import {SlugOptions} from '../slug'

@@ -17,11 +18,26 @@

type?: SchemaType
readOnly?: boolean
icon?: React.ComponentType
/**
* @deprecated
*/
placeholder?: string
}
export interface TitledListValue<V = unknown> {
_key?: string
title: string
value: V
}
interface EnumListProps<V = unknown> {
list?: TitledListValue<V>[] | V[]
layout?: 'radio' | 'dropdown'
direction?: 'horizontal' | 'vertical'
}
export interface StringSchemaType extends BaseSchemaType {
jsonType: 'string'
options?: {
list?: {title?: string; value: string}[]
layout?: 'radio' | 'dropdown'
direction?: 'horizontal' | 'vertical'
options?: EnumListProps<string> & {
// Actually just part of date time, but can't find a good way to differentiate

@@ -33,4 +49,9 @@ dateFormat?: string

export interface TextSchemaType extends StringSchemaType {
rows?: number
}
export interface NumberSchemaType extends BaseSchemaType {
jsonType: 'number'
options?: EnumListProps<number>
}

@@ -47,6 +68,7 @@

jsonType: 'array'
of: Exclude<SchemaType, ArraySchemaType>[]
of: (Exclude<SchemaType, ArraySchemaType> | ReferenceSchemaType)[]
options?: {
list?: {title?: string; value: V}[] | V[]
list?: TitledListValue<V>[] | V[]
layout?: V extends string ? 'tags' : 'grid'
direction?: 'horizontal' | 'vertical'
sortable?: boolean

@@ -57,3 +79,3 @@

*/
editModal?: 'dialog' | 'fullscreen' | 'popover'
editModal?: 'dialog' | 'fullscreen' | 'popover' | 'fold'
}

@@ -68,3 +90,3 @@ }

export interface SlugSchemaType extends ObjectSchemaType {
export interface SlugSchemaType extends BaseSchemaType {
jsonType: 'object'

@@ -86,2 +108,8 @@ options?: SlugOptions

export interface ObjectSchemaTypeWithOptions extends ObjectSchemaType {
options?: CollapseOptions & {
columns?: number
}
}
export interface SingleFieldSet {

@@ -97,5 +125,3 @@ single: true

single?: false
options?: {
collapsible?: boolean
collapsed?: boolean
options?: CollapseOptions & {
columns?: number

@@ -108,6 +134,36 @@ }

export interface CollapseOptions {
collapsable?: boolean
collapsed?: boolean
/**
* @deprecated Use `collapsable`/`collapsed`
*/
collapsible?: boolean
}
export interface ReferenceSchemaType extends ObjectSchemaType {
jsonType: 'object'
to: SchemaType[]
weak?: boolean
options?: ReferenceOptions
}
export interface AssetSchemaTypeOptions {
accept?: string
storeOriginalFilename?: boolean
}
export interface FileSchemaType extends ObjectSchemaType {
options?: AssetSchemaTypeOptions
}
export interface ImageSchemaType extends ObjectSchemaType {
options?: AssetSchemaTypeOptions & {
hotspot?: boolean
metadata?: ('exif' | 'location' | 'lqip' | 'palette')[]
sources?: AssetSource[]
}
}
export type SchemaType =

@@ -114,0 +170,0 @@ | ArraySchemaType

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc