-
Notifications
You must be signed in to change notification settings - Fork 4
/
MirrorMetadataSchema.ts
84 lines (79 loc) · 1.88 KB
/
MirrorMetadataSchema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { z } from 'zod';
import { MirrorSchemaId } from './MirrorSchemaId.js';
import {
AppId,
AppIdSchema,
Signature,
SignatureSchema,
nonEmptyStringSchema,
} from '../primitives.js';
import { ShapeCheck } from '../utils.js';
export type MirrorMetadataDetails = {
/**
* A unique identifier that in storages like IPFS ensures the uniqueness of the metadata URI.
*
* Use a UUID if unsure.
*/
id: string;
/**
* The App Id that this publication belongs to.
*/
appId: AppId;
};
const MirrorMetadataDetailsSchema: z.ZodType<MirrorMetadataDetails, z.ZodTypeDef, object> =
z.object(
{
id: nonEmptyStringSchema(
'A unique identifier that in storages like IPFS ensures the uniqueness of the metadata URI. Use a UUID if unsure.',
),
appId: AppIdSchema.describe('The App Id that this publication belongs to.'),
},
{
description: 'The Lens operational metadata fields.',
},
);
/**
* A Mirror metadata object.
*/
export type MirrorMetadata = ShapeCheck<{
/**
* The schema id.
*/
$schema: MirrorSchemaId.LATEST;
/**
* The metadata details.
*/
lens: MirrorMetadataDetails;
/**
* A cryptographic signature of the `lens` data.
*/
signature?: Signature;
}>;
/**
* Mirror metadata schema.
*
* @category Parse
*
* @example
* with `parse`:
* ```ts
* MirrorMetadata.parse(valid); // => MirrorMetadata
*
* MirrorMetadata.parse(invalid); // => throws ZodError
* ```
*
* @example
* with `safeParse`:
* ```ts
* MirrorMetadata.safeParse(valid);
* // => { success: true, data: MirrorMetadata }
*
* MirrorMetadata.safeParse(invalid);
* // => { success: false, error: ZodError }
* ```
*/
export const MirrorMetadataSchema: z.ZodType<MirrorMetadata, z.ZodTypeDef, object> = z.object({
$schema: z.literal(MirrorSchemaId.LATEST),
lens: MirrorMetadataDetailsSchema,
signature: SignatureSchema.optional(),
});