@portabletext/sanity-bridge 1.1.3 → 1.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/sanity-bridge",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Convert a Sanity Schema to a Portable Text Schema",
5
5
  "keywords": [
6
6
  "sanity",
@@ -38,14 +38,15 @@
38
38
  "dependencies": {
39
39
  "get-random-values-esm": "^1.0.2",
40
40
  "lodash.startcase": "^4.4.0",
41
- "@portabletext/schema": "^1.0.1"
41
+ "@portabletext/schema": "^1.1.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@sanity/pkg-utils": "^7.11.1",
44
+ "@sanity/pkg-utils": "^7.11.9",
45
45
  "@sanity/schema": "^4.5.0",
46
46
  "@sanity/types": "^4.5.0",
47
47
  "@types/lodash.startcase": "^4.4.9",
48
- "typescript": "^5.9.2"
48
+ "typescript": "^5.9.2",
49
+ "vitest": "^3.2.4"
49
50
  },
50
51
  "peerDependencies": {
51
52
  "@sanity/schema": "^4.5.0",
@@ -64,6 +65,8 @@
64
65
  "check:types:watch": "tsc --watch",
65
66
  "clean": "del .turbo && del lib && del node_modules",
66
67
  "dev": "pkg-utils watch",
67
- "lint:fix": "biome lint --write ."
68
+ "lint:fix": "biome lint --write .",
69
+ "test:unit": "vitest run",
70
+ "test:unit:watch": "vitest watch"
68
71
  }
69
72
  }
@@ -0,0 +1,145 @@
1
+ import type {Schema} from '@portabletext/schema'
2
+ import {Schema as SanitySchema} from '@sanity/schema'
3
+ import {
4
+ defineArrayMember,
5
+ defineField,
6
+ type ArrayDefinition,
7
+ } from '@sanity/types'
8
+ import {describe, expect, test} from 'vitest'
9
+ import {sanitySchemaToPortableTextSchema} from './sanity-schema-to-portable-text-schema'
10
+
11
+ describe(sanitySchemaToPortableTextSchema.name, () => {
12
+ const defaultSchema: Schema = {
13
+ block: {
14
+ name: 'block',
15
+ },
16
+ span: {
17
+ name: 'span',
18
+ },
19
+ styles: [
20
+ {
21
+ name: 'normal',
22
+ value: 'normal',
23
+ title: 'Normal',
24
+ },
25
+ {
26
+ name: 'h1',
27
+ value: 'h1',
28
+ title: 'Heading 1',
29
+ },
30
+ {
31
+ name: 'h2',
32
+ value: 'h2',
33
+ title: 'Heading 2',
34
+ },
35
+ {
36
+ name: 'h3',
37
+ value: 'h3',
38
+ title: 'Heading 3',
39
+ },
40
+ {
41
+ name: 'h4',
42
+ value: 'h4',
43
+ title: 'Heading 4',
44
+ },
45
+ {
46
+ name: 'h5',
47
+ value: 'h5',
48
+ title: 'Heading 5',
49
+ },
50
+ {
51
+ name: 'h6',
52
+ value: 'h6',
53
+ title: 'Heading 6',
54
+ },
55
+ {
56
+ name: 'blockquote',
57
+ value: 'blockquote',
58
+ title: 'Quote',
59
+ },
60
+ ],
61
+ lists: [
62
+ {
63
+ name: 'bullet',
64
+ value: 'bullet',
65
+ title: 'Bulleted list',
66
+ },
67
+ {
68
+ name: 'number',
69
+ value: 'number',
70
+ title: 'Numbered list',
71
+ },
72
+ ],
73
+ decorators: [
74
+ {
75
+ name: 'strong',
76
+ value: 'strong',
77
+ title: 'Strong',
78
+ },
79
+ {
80
+ name: 'em',
81
+ value: 'em',
82
+ title: 'Italic',
83
+ },
84
+ {
85
+ name: 'code',
86
+ value: 'code',
87
+ title: 'Code',
88
+ },
89
+ {
90
+ name: 'underline',
91
+ value: 'underline',
92
+ title: 'Underline',
93
+ },
94
+ {
95
+ name: 'strike-through',
96
+ value: 'strike-through',
97
+ title: 'Strike',
98
+ },
99
+ ],
100
+ annotations: [
101
+ {
102
+ name: 'link',
103
+ title: 'Link',
104
+ fields: [
105
+ {
106
+ name: 'href',
107
+ type: 'string',
108
+ title: 'Link',
109
+ },
110
+ ],
111
+ },
112
+ ],
113
+ blockObjects: [],
114
+ inlineObjects: [],
115
+ }
116
+
117
+ test('simple compiled schema', () => {
118
+ const sanitySchema = SanitySchema.compile({
119
+ name: 'test',
120
+ types: [
121
+ defineArrayMember({
122
+ type: 'array',
123
+ name: 'content',
124
+ of: [defineField({type: 'block', name: 'block'})],
125
+ }),
126
+ ],
127
+ })
128
+
129
+ expect(
130
+ sanitySchemaToPortableTextSchema(sanitySchema.get('content')),
131
+ ).toEqual(defaultSchema)
132
+ })
133
+
134
+ test('simple array definition', () => {
135
+ const sanitySchema: ArrayDefinition = {
136
+ type: 'array',
137
+ name: 'content',
138
+ of: [defineField({type: 'block', name: 'block'})],
139
+ }
140
+
141
+ expect(sanitySchemaToPortableTextSchema(sanitySchema)).toEqual(
142
+ defaultSchema,
143
+ )
144
+ })
145
+ })