@sanity/media-library-types 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/lib/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@sanity/media-library-types",
3
+ "version": "0.0.1",
4
+ "description": "Type definitions for common Sanity Media Library data structures",
5
+ "keywords": [
6
+ "sanity",
7
+ "media",
8
+ "library",
9
+ "headless",
10
+ "realtime",
11
+ "content",
12
+ "types",
13
+ "typescript"
14
+ ],
15
+ "homepage": "https://www.sanity.io/",
16
+ "bugs": {
17
+ "url": "https://github.com/sanity-io/sanity/issues"
18
+ },
19
+ "license": "MIT",
20
+ "author": "Sanity.io <hello@sanity.io>",
21
+ "sideEffects": false,
22
+ "type": "commonjs",
23
+ "exports": {
24
+ ".": {
25
+ "source": "./src/index.ts",
26
+ "import": "./lib/index.mjs",
27
+ "require": "./lib/index.js",
28
+ "default": "./lib/index.js"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
32
+ "main": "./lib/index.js",
33
+ "module": "./lib/index.mjs",
34
+ "types": "./lib/index.d.ts",
35
+ "files": [
36
+ "lib",
37
+ "src"
38
+ ],
39
+ "dependencies": {},
40
+ "devDependencies": {
41
+ "@sanity/types": "^3.90.0",
42
+ "@sanity/pkg-utils": "^7.2.3",
43
+ "rimraf": "^5.0.10"
44
+ },
45
+ "scripts": {
46
+ "build": "cp ../../../apps/huey/src/lib/schema.types.ts ./src/ && pkg-utils build --strict --check --clean",
47
+ "check:types": "tsc --project tsconfig.json",
48
+ "clean": "rimraf lib",
49
+ "schema-types": "cp ../../../apps/huey/src/lib/schema.types.ts ./src/",
50
+ "watch": "pkg-utils watch"
51
+ }
52
+ }
package/src/assets.ts ADDED
@@ -0,0 +1,159 @@
1
+ import { SanityAsset, SanityAssetCollection, SanityAssetVersion, SanityImageMetadata } from "./schema.types"
2
+ import {type FieldDefinition} from '@sanity/types'
3
+
4
+ export type SanityVideoAsset = {
5
+ _id: string
6
+ _type: 'sanity.videoAsset'
7
+ _createdAt: string
8
+ _updatedAt: string
9
+ _rev: string
10
+ title?: string
11
+ description?: Array<{
12
+ children?: Array<{
13
+ marks?: Array<string>
14
+ text?: string
15
+ _type: 'span'
16
+ _key: string
17
+ }>
18
+ style?: 'normal' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'blockquote'
19
+ listItem?: 'bullet' | 'number'
20
+ markDefs?: Array<{
21
+ href?: string
22
+ _type: 'link'
23
+ _key: string
24
+ }>
25
+ level?: number
26
+ _type: 'block'
27
+ _key: string
28
+ }>
29
+ state: string
30
+ sha1hash?: string
31
+ mimeType?: string
32
+ originalFilename?: string
33
+ size?: number
34
+ uploadId?: string
35
+ path?: string
36
+ url?: string
37
+ extension?: string
38
+ metadata: SanityVideoMetadata
39
+ }
40
+
41
+ export type SanityVideoMetadata = {
42
+ _type: 'sanity.videoMetadata'
43
+ muxAssetId: string
44
+ muxPlaybackIds: Array<{
45
+ _id: string
46
+ _type: string
47
+ policy: string
48
+ _key: string
49
+ }>
50
+ }
51
+
52
+ export type SanityFileAsset = {
53
+ _id: string
54
+ _type: 'sanity.fileAsset'
55
+ _createdAt: string
56
+ _updatedAt: string
57
+ _rev: string
58
+ title?: string
59
+ description?: Array<{
60
+ children?: Array<{
61
+ marks?: Array<string>
62
+ text?: string
63
+ _type: 'span'
64
+ _key: string
65
+ }>
66
+ style?: 'normal' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'blockquote'
67
+ listItem?: 'bullet' | 'number'
68
+ markDefs?: Array<{
69
+ href?: string
70
+ _type: 'link'
71
+ _key: string
72
+ }>
73
+ level?: number
74
+ _type: 'block'
75
+ _key: string
76
+ }>
77
+ state: string
78
+ sha1hash?: string
79
+ mimeType?: string
80
+ originalFilename?: string
81
+ size?: number
82
+ uploadId?: string
83
+ path: string
84
+ extension?: string
85
+ url: string
86
+ }
87
+
88
+ export type SanityImageAsset = {
89
+ _id: string
90
+ _type: 'sanity.imageAsset'
91
+ _createdAt: string
92
+ _updatedAt: string
93
+ _rev: string
94
+ altText?: string
95
+ state: string
96
+ sha1hash?: string
97
+ mimeType?: string
98
+ originalFilename?: string
99
+ size?: number
100
+ uploadId?: string
101
+ path?: string
102
+ extension?: string
103
+ url: string
104
+ metadata: SanityImageMetadata
105
+ }
106
+
107
+ export interface AssetVersion<AssetInstance extends AssetInstanceDocument = AssetInstanceDocument> {
108
+ _key: string
109
+ _type: SanityAssetVersion['_type']
110
+ title?: string
111
+ instance: AssetInstance
112
+ }
113
+
114
+ export type AssetInstanceDocument = SanityImageAsset | SanityVideoAsset | SanityFileAsset
115
+
116
+ export interface Asset<AssetInstance extends AssetInstanceDocument = AssetInstanceDocument> {
117
+ _id: string
118
+ _type: SanityAsset['_type']
119
+ title: string
120
+ assetType: AssetInstance['_type']
121
+ cdnAccessPolicy: SanityAsset['cdnAccessPolicy']
122
+ currentVersion: {
123
+ _ref: string
124
+ }
125
+ aspects?: unknown
126
+ versions: AssetVersion<AssetInstance>[]
127
+ collections: SanityAssetCollection[]
128
+ _createdAt: string
129
+ _updatedAt: string
130
+ _rev: string
131
+ }
132
+
133
+ export type BaseDocument = {
134
+ _id: string
135
+ _type: string
136
+ _rev: string
137
+ _createdAt: string
138
+ _updatedAt: string
139
+ [key: string]: any
140
+ }
141
+
142
+ export interface AssetAspectDocument extends BaseDocument {
143
+ _type: 'sanity.asset.aspect'
144
+ /**
145
+ * The asset type this aspect definition applies to
146
+ * Undefined means that it applies to all asset types
147
+ */
148
+ assetType?: Asset['assetType']
149
+ definition: FieldDefinition
150
+ }
151
+
152
+ export interface UploadSession {
153
+ _id: string
154
+ _type: 'sanity.asset.upload-session'
155
+ title: string
156
+ assets: Asset[]
157
+ _createdAt: string
158
+ _updatedAt: string
159
+ }
package/src/files.ts ADDED
@@ -0,0 +1,12 @@
1
+ export type FileStatus = 'pending' | 'uploading' | 'complete' | 'error'
2
+
3
+ /**
4
+ * Wrapper object for the file upload with progress and status
5
+ */
6
+ export interface FileUpload {
7
+ id: string
8
+ file: File
9
+ status: FileStatus
10
+ progress: number
11
+ error?: Error
12
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './assets'
2
+ export * from './plugin'
3
+ export * from './files'
package/src/plugin.ts ADDED
@@ -0,0 +1,93 @@
1
+ import { Asset } from "./assets"
2
+ import { FileUpload } from "./files"
3
+
4
+ /**
5
+ * Message sent from the plugin when files are uploading
6
+ */
7
+ export type PluginPostMessageUploadFilesProgress = {
8
+ type: 'uploadProgress'
9
+ files: FileUpload[]
10
+ }
11
+
12
+ /**
13
+ * Message sent from the app that the pending uploads are uploaded
14
+ */
15
+ export type PluginPostMessageUploadFilesResponse = {
16
+ type: 'uploadResponse'
17
+ assets: AssetSelectionItemWithLegacySupport[]
18
+ }
19
+
20
+ export interface AssetSelectionItem {
21
+ asset: Asset
22
+ assetInstanceId?: string | null
23
+ }
24
+
25
+ /* This is to support the legacy asset selection API in a transition phase */
26
+ interface AssetSelectionItemWithLegacySupport extends AssetSelectionItem {
27
+ assetId: string
28
+ assetType: string
29
+ assetInstanceId: string // Required
30
+ }
31
+
32
+ export type PluginPostMessageAssetSelection = {
33
+ type: 'assetSelection'
34
+ selection: AssetSelectionItemWithLegacySupport[]
35
+ }
36
+
37
+ /**
38
+ * Message sent from the plugin that a document has been updated
39
+ */
40
+ export type PluginPostMessageDocumentUpdate = {
41
+ type: 'documentUpdate'
42
+ document: {_id: string; _type: string; _rev: string}
43
+ }
44
+
45
+ /**
46
+ * Message sent from the plugin that the user wants to upload files
47
+ */
48
+ export type PluginPostMessageUploadFilesRequest = {
49
+ type: 'uploadRequest'
50
+ files: {id: string; file: File}[]
51
+ }
52
+
53
+ export type PluginPostMessageAbortUploadRequest = {
54
+ type: 'abortUploadRequest'
55
+ files?: {id: string}[]
56
+ }
57
+
58
+ export type PluginPostMessageTokenRequest = {
59
+ type: 'tokenRequest'
60
+ }
61
+
62
+ export type PluginPostMessageTokenResponse = {
63
+ type: 'tokenResponse'
64
+ token: string | null
65
+ }
66
+
67
+ /**
68
+ * Message sent from a plugin page to notify the host that the page is loaded and ready to be interacted with
69
+ */
70
+ export type PluginPostMessagePageLoaded = {
71
+ type: 'pageLoaded'
72
+ page: string
73
+ }
74
+
75
+ /**
76
+ * Message sent from a plugin page that a page is unloaded by the user (for closing the dialog and similar)
77
+ */
78
+ export type PluginPostMessagePageUnloaded = {
79
+ type: 'pageUnloaded'
80
+ page: string
81
+ }
82
+
83
+ export type PluginPostMessage =
84
+ | PluginPostMessageAbortUploadRequest
85
+ | PluginPostMessageAssetSelection
86
+ | PluginPostMessageDocumentUpdate
87
+ | PluginPostMessagePageLoaded
88
+ | PluginPostMessagePageUnloaded
89
+ | PluginPostMessageTokenRequest
90
+ | PluginPostMessageTokenResponse
91
+ | PluginPostMessageUploadFilesProgress
92
+ | PluginPostMessageUploadFilesRequest
93
+ | PluginPostMessageUploadFilesResponse
@@ -0,0 +1,295 @@
1
+ export declare const internalGroqTypeReferenceTo: unique symbol
2
+
3
+ export type SanityAssetUploadSession = {
4
+ _id: string
5
+ _type: 'sanity.asset.upload-session'
6
+ _createdAt: string
7
+ _updatedAt: string
8
+ _rev: string
9
+ title: string
10
+ assets?: Array<{
11
+ _ref: string
12
+ _type: 'reference'
13
+ _weak?: boolean
14
+ _key: string
15
+ [internalGroqTypeReferenceTo]?: 'sanity.asset'
16
+ }>
17
+ _system?: SanitySystem
18
+ }
19
+
20
+ export type SanitySystem = {
21
+ _type: 'sanity.system'
22
+ createdBy?: string
23
+ }
24
+
25
+ export type SanityAssetCollection = {
26
+ _id: string
27
+ _type: 'sanity.asset.collection'
28
+ _createdAt: string
29
+ _updatedAt: string
30
+ _rev: string
31
+ title: string
32
+ description?: string
33
+ assets?: Array<{
34
+ _ref: string
35
+ _type: 'reference'
36
+ _weak?: boolean
37
+ _key: string
38
+ [internalGroqTypeReferenceTo]?: 'sanity.asset'
39
+ }>
40
+ }
41
+
42
+ export type SanityImagePaletteSwatch = {
43
+ _type: 'sanity.imagePaletteSwatch'
44
+ background?: string
45
+ foreground?: string
46
+ population?: number
47
+ title?: string
48
+ }
49
+
50
+ export type SanityImagePalette = {
51
+ _type: 'sanity.imagePalette'
52
+ darkMuted?: SanityImagePaletteSwatch
53
+ lightVibrant?: SanityImagePaletteSwatch
54
+ darkVibrant?: SanityImagePaletteSwatch
55
+ vibrant?: SanityImagePaletteSwatch
56
+ dominant?: SanityImagePaletteSwatch
57
+ lightMuted?: SanityImagePaletteSwatch
58
+ muted?: SanityImagePaletteSwatch
59
+ }
60
+
61
+ export type SanityImageExifTags = {
62
+ _type: 'sanity.imageExifTags'
63
+ Make?: string
64
+ Model?: string
65
+ Orientation?: number
66
+ XResolution?: number
67
+ YResolution?: number
68
+ ResolutionUnit?: number
69
+ Software?: string
70
+ ModifyDate?: string
71
+ ExifOffset?: number
72
+ GPSInfo?: number
73
+ }
74
+
75
+ export type SanityImageExifMetadata = {
76
+ _type: 'sanity.imageExifMetadata'
77
+ ApertureValue?: number
78
+ BrightnessValue?: number
79
+ DateTimeDigitized?: string
80
+ DateTimeOriginal?: string
81
+ ExposureBiasValue?: number
82
+ ExposureMode?: number
83
+ ExposureProgram?: number
84
+ ExposureTime?: number
85
+ FNumber?: number
86
+ Flash?: number
87
+ FocalLength?: number
88
+ FocalLengthIn35mmFormat?: number
89
+ ISO?: number
90
+ LensModel?: string
91
+ WhiteBalance?: number
92
+ GPSLatitude?: number
93
+ GPSLongitude?: number
94
+ GPSAltitude?: number
95
+ Copyright?: string
96
+ Artist?: string
97
+ }
98
+
99
+ export type SanityImageDimensions = {
100
+ _type: 'sanity.imageDimensions'
101
+ height: number
102
+ width: number
103
+ aspectRatio: number
104
+ }
105
+
106
+ export type SanityAsset = {
107
+ _id: string
108
+ _type: 'sanity.asset'
109
+ _createdAt: string
110
+ _updatedAt: string
111
+ _rev: string
112
+ title?: string
113
+ aspects?: unknown
114
+ currentVersion: {
115
+ _ref: string
116
+ _type: 'reference'
117
+ _weak?: boolean
118
+ [internalGroqTypeReferenceTo]?: 'sanity.asset.version'
119
+ }
120
+ versions: Array<
121
+ {
122
+ _key: string
123
+ } & SanityAssetVersion
124
+ >
125
+ assetType: 'sanity.imageAsset' | 'sanity.videoAsset' | 'sanity.fileAsset'
126
+ cdnAccessPolicy: 'public' | 'private'
127
+ }
128
+
129
+ export type SanityAssetVersion = {
130
+ _type: 'sanity.asset.version'
131
+ title?: string
132
+ instance:
133
+ | {
134
+ _ref: string
135
+ _type: 'reference'
136
+ _weak?: boolean
137
+ [internalGroqTypeReferenceTo]?: 'sanity.imageAsset'
138
+ }
139
+ | {
140
+ _ref: string
141
+ _type: 'reference'
142
+ _weak?: boolean
143
+ [internalGroqTypeReferenceTo]?: 'sanity.fileAsset'
144
+ }
145
+ | {
146
+ _ref: string
147
+ _type: 'reference'
148
+ _weak?: boolean
149
+ [internalGroqTypeReferenceTo]?: 'sanity.videoAsset'
150
+ }
151
+ }
152
+
153
+ export type SanityVideoAsset = {
154
+ _id: string
155
+ _type: 'sanity.videoAsset'
156
+ _createdAt: string
157
+ _updatedAt: string
158
+ _rev: string
159
+ title?: string
160
+ description?: Array<{
161
+ children?: Array<{
162
+ marks?: Array<string>
163
+ text?: string
164
+ _type: 'span'
165
+ _key: string
166
+ }>
167
+ style?: 'normal' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'blockquote'
168
+ listItem?: 'bullet' | 'number'
169
+ markDefs?: Array<{
170
+ href?: string
171
+ _type: 'link'
172
+ _key: string
173
+ }>
174
+ level?: number
175
+ _type: 'block'
176
+ _key: string
177
+ }>
178
+ state: string
179
+ sha1hash?: string
180
+ mimeType?: string
181
+ originalFilename?: string
182
+ size?: number
183
+ uploadId?: string
184
+ path?: string
185
+ url?: string
186
+ extension?: string
187
+ metadata: SanityVideoMetadata
188
+ }
189
+
190
+ export type SanityVideoMetadata = {
191
+ _type: 'sanity.videoMetadata'
192
+ muxAssetId: string
193
+ muxPlaybackIds: Array<{
194
+ _id: string
195
+ _type: string
196
+ policy: string
197
+ _key: string
198
+ }>
199
+ }
200
+
201
+ export type SanityFileAsset = {
202
+ _id: string
203
+ _type: 'sanity.fileAsset'
204
+ _createdAt: string
205
+ _updatedAt: string
206
+ _rev: string
207
+ title?: string
208
+ description?: Array<{
209
+ children?: Array<{
210
+ marks?: Array<string>
211
+ text?: string
212
+ _type: 'span'
213
+ _key: string
214
+ }>
215
+ style?: 'normal' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'blockquote'
216
+ listItem?: 'bullet' | 'number'
217
+ markDefs?: Array<{
218
+ href?: string
219
+ _type: 'link'
220
+ _key: string
221
+ }>
222
+ level?: number
223
+ _type: 'block'
224
+ _key: string
225
+ }>
226
+ state: string
227
+ sha1hash?: string
228
+ mimeType?: string
229
+ originalFilename?: string
230
+ size?: number
231
+ uploadId?: string
232
+ path: string
233
+ extension?: string
234
+ url: string
235
+ }
236
+
237
+ export type SanityImageAsset = {
238
+ _id: string
239
+ _type: 'sanity.imageAsset'
240
+ _createdAt: string
241
+ _updatedAt: string
242
+ _rev: string
243
+ altText?: string
244
+ state: string
245
+ sha1hash?: string
246
+ mimeType?: string
247
+ originalFilename?: string
248
+ size?: number
249
+ uploadId?: string
250
+ path?: string
251
+ extension?: string
252
+ url: string
253
+ metadata: SanityImageMetadata
254
+ }
255
+
256
+ export type SanityImageMetadata = {
257
+ _type: 'sanity.imageMetadata'
258
+ location?: Geopoint
259
+ dimensions: SanityImageDimensions
260
+ exif?: SanityImageExifMetadata
261
+ image?: SanityImageExifTags
262
+ palette: SanityImagePalette
263
+ lqip: string
264
+ blurHash: string
265
+ hasAlpha: boolean
266
+ isOpaque: boolean
267
+ }
268
+
269
+ export type Geopoint = {
270
+ _type: 'geopoint'
271
+ lat?: number
272
+ lng?: number
273
+ alt?: number
274
+ }
275
+
276
+ export type SanityAssetInstanceState = string
277
+
278
+ export type AllSanitySchemaTypes =
279
+ | SanityAssetUploadSession
280
+ | SanitySystem
281
+ | SanityAssetCollection
282
+ | SanityImagePaletteSwatch
283
+ | SanityImagePalette
284
+ | SanityImageExifTags
285
+ | SanityImageExifMetadata
286
+ | SanityImageDimensions
287
+ | SanityAsset
288
+ | SanityAssetVersion
289
+ | SanityVideoAsset
290
+ | SanityVideoMetadata
291
+ | SanityFileAsset
292
+ | SanityImageAsset
293
+ | SanityImageMetadata
294
+ | Geopoint
295
+ | SanityAssetInstanceState