|
1 | | -import { |
2 | | - intersect, |
3 | | - lazy, |
4 | | - number, |
5 | | - object, |
6 | | - parser, |
7 | | - pipe, |
8 | | - readonly, |
9 | | - string, |
10 | | - transform, |
11 | | - union, |
12 | | - type GenericSchema |
13 | | -} from 'valibot'; |
| 1 | +import { intersect, lazy, number, object, parser, string, union, type GenericSchema } from 'valibot'; |
14 | 2 | import jsonLinkedDataProperty from '../private/jsonLinkedDataProperty'; |
15 | 3 | import { claimSchema } from './Claim'; |
16 | 4 | import { |
@@ -199,31 +187,22 @@ let creativeWorkSchema_: GenericSchema<CreativeWorkInput, CreativeWorkOutput>; |
199 | 187 |
|
200 | 188 | // This is for cyclic dependency. |
201 | 189 | // eslint-disable-next-line prefer-const |
202 | | -creativeWorkSchema_ = pipe( |
203 | | - intersect([ |
204 | | - pipe( |
205 | | - lazy(() => thingSchema), |
206 | | - // TODO: `intersect()` seems doesn't like frozen objects. |
207 | | - // Related to https://github.com/open-circle/valibot/pull/1463. |
208 | | - transform(value => ({ ...value })) |
209 | | - ), |
210 | | - object({ |
211 | | - abstract: jsonLinkedDataProperty(string()), |
212 | | - author: jsonLinkedDataProperty(union([lazy(() => personSchema), string()])), |
213 | | - citation: jsonLinkedDataProperty(lazy(() => claimSchema)), |
214 | | - creativeWorkStatus: jsonLinkedDataProperty(creativeWorkStatusSchema), |
215 | | - isBasedOn: jsonLinkedDataProperty(lazy(() => softwareSourceCodeSchema)), |
216 | | - isPartOf: jsonLinkedDataProperty(lazy(() => creativeWorkSchema_)), |
217 | | - keywords: jsonLinkedDataProperty(union([lazy(() => definedTermSchema), string()])), |
218 | | - pattern: jsonLinkedDataProperty(lazy(() => definedTermSchema)), |
219 | | - position: jsonLinkedDataProperty(union([number(), string()])), |
220 | | - text: jsonLinkedDataProperty(string()), |
221 | | - usageInfo: jsonLinkedDataProperty(lazy(() => creativeWorkSchema_)) |
222 | | - }) |
223 | | - ]), |
224 | | - readonly(), |
225 | | - transform(value => Object.freeze({ ...value })) |
226 | | -); |
| 190 | +creativeWorkSchema_ = intersect([ |
| 191 | + lazy(() => thingSchema), |
| 192 | + object({ |
| 193 | + abstract: jsonLinkedDataProperty(string()), |
| 194 | + author: jsonLinkedDataProperty(union([lazy(() => personSchema), string()])), |
| 195 | + citation: jsonLinkedDataProperty(lazy(() => claimSchema)), |
| 196 | + creativeWorkStatus: jsonLinkedDataProperty(creativeWorkStatusSchema), |
| 197 | + isBasedOn: jsonLinkedDataProperty(lazy(() => softwareSourceCodeSchema)), |
| 198 | + isPartOf: jsonLinkedDataProperty(lazy(() => creativeWorkSchema_)), |
| 199 | + keywords: jsonLinkedDataProperty(union([lazy(() => definedTermSchema), string()])), |
| 200 | + pattern: jsonLinkedDataProperty(lazy(() => definedTermSchema)), |
| 201 | + position: jsonLinkedDataProperty(union([number(), string()])), |
| 202 | + text: jsonLinkedDataProperty(string()), |
| 203 | + usageInfo: jsonLinkedDataProperty(lazy(() => creativeWorkSchema_)) |
| 204 | + }) |
| 205 | +]); |
227 | 206 |
|
228 | 207 | // Constantize here, so we are exporting a const than a let. |
229 | 208 | const creativeWorkSchema = creativeWorkSchema_; |
|
0 commit comments