We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 09b6ed2 commit fa40d01Copy full SHA for fa40d01
jsonschemas/schema.json
@@ -27,6 +27,9 @@
27
{
28
"$ref": "#/$defs/MintMetadata"
29
},
30
+ {
31
+ "$ref": "#/$defs/CustomMetadata"
32
+ },
33
34
"$ref": "#/$defs/SpaceMetadata"
35
@@ -78,7 +81,8 @@
78
81
"SHORT_VIDEO",
79
82
"3D",
80
83
"STORY",
- "SPACE"
84
+ "SPACE",
85
+ "CUSTOM"
86
]
87
88
"AnyMedia": {
@@ -2306,6 +2310,9 @@
2306
2310
],
2307
2311
"additionalProperties": true
2308
2312
2313
+ "CustomMetadata": {
2314
+ "$ref": "posts/custom/3.0.0.json"
2315
2309
2316
"SpaceMetadata": {
2317
"type": "object",
2318
"properties": {
scripts/build.ts
@@ -39,6 +39,7 @@ import {
39
MetadataIdSchema,
40
MetadataLicenseTypeSchema,
41
MintSchema,
42
+ CustomSchema,
43
NamespaceMetadataSchema,
44
NamespaceRuleMetadataSchema,
45
Nft721MetadataAttributeSchema,
@@ -77,6 +78,7 @@ const schemas = new Map<string, z.ZodSchema<unknown>>([
77
['posts/link/3.0.0.json', LinkSchema],
['posts/livestream/3.0.0.json', LiveStreamSchema],
['posts/mint/3.0.0.json', MintSchema],
+ ['posts/custom/3.0.0.json', CustomSchema],
['posts/space/3.0.0.json', SpaceSchema],
['posts/story/3.0.0.json', StorySchema],
['posts/text-only/3.0.0.json', TextOnlySchema],
@@ -216,6 +218,7 @@ async function generateUmbrellaSchema() {
216
218
LinkMetadata: LinkSchema,
217
219
LiveStreamMetadata: LiveStreamSchema,
220
MintMetadata: MintSchema,
221
+ CustomMetadata: CustomSchema,
222
SpaceMetadata: SpaceSchema,
223
TextOnlyMetadata: TextOnlySchema,
224
StoryMetadata: StorySchema,
src/builders/posts.ts
@@ -28,6 +28,9 @@ import {
type MintMetadata,
type MintMetadataDetails,
+ type CustomMetadata,
+ type CustomMetadataDetails,
PostMainFocus,
PostMetadataSchemaId,
36
type SpaceMetadata,
@@ -652,6 +655,46 @@ export function mint({
652
655
);
653
656
}
654
657
658
+/**
659
+ * @private
660
+ * @privateRemarks MUST stay very @private to produce usable docs
661
+ */
662
+type CustomDetails = InputForPostMetadataDetails<CustomMetadataDetails>;
663
664
+ * All {@link CustomMetadataDetails} fields with:
665
+ * - `id` defaults to a UUID
666
+ * - `locale` defaults to `en`
667
+ * - `mainContentFocus` automatically set to `PostSchemaId.CUSTOM_LATEST`
668
669
+export type CustomOptions = CustomDetails & {
670
+ /**
671
+ * All the {@link NftMetadata} fields.
672
673
+ nft?: NftDetails;
674
+};
675
676
+ * Creates a valid CustomMetadata.
677
678
+export function custom({
679
+ nft,
680
+ locale = DEFAULT_LOCALE,
681
+ id = v4(),
682
+ ...others
683
+}: CustomOptions): CustomMetadata {
684
+ return evaluate(
685
+ CustomSchema.safeParse({
686
+ $schema: PostMetadataSchemaId.CUSTOM_LATEST,
687
+ ...nft,
688
+ lens: {
689
+ id,
690
+ locale,
691
+ mainContentFocus: PostMainFocus.CUSTOM,
692
+ ...others,
693
694
+ }),
695
+ );
696
+}
697
+
698
/**
699
* @private
700
* @privateRemarks MUST stay very @private to produce usable docs
src/post/CustomSchema.ts
@@ -0,0 +1,50 @@
1
+import { z } from 'zod';
2
3
+import { NonEmptyStringSchema, type Signature } from '../primitives.js';
4
+import type { NftMetadata } from '../tokens/eip721.js';
5
+import { PostMainFocus } from './PostMainFocus.js';
6
+import { PostMetadataSchemaId } from './PostMetadataSchemaId.js';
7
+import {
8
+ mainContentFocus,
9
+ metadataDetailsWith,
10
+ postWith,
11
+ type PostMetadataCommon,
12
+} from './common';
13
14
+export type CustomMetadataDetails = PostMetadataCommon & {
15
16
+ * The main focus of the post.
17
18
+ mainContentFocus: PostMainFocus.CUSTOM;
19
20
+ * A JSON string containing any custom data.
21
22
+ value: string;
23
24
25
+const CustomMetadataDetailsSchema: z.ZodType<CustomMetadataDetails, z.ZodTypeDef, object> =
26
+ metadataDetailsWith({
+ mainContentFocus: mainContentFocus(PostMainFocus.CUSTOM),
+ value: NonEmptyStringSchema.describe('A JSON string containing any custom data.'),
+ });
+export type CustomMetadata = NftMetadata & {
+ * The schema id.
+ $schema: PostMetadataSchemaId.CUSTOM_LATEST;
37
38
+ * The metadata details.
+ lens: CustomMetadataDetails;
+ * A cryptographic signature of the `lens` data.
+ signature?: Signature;
46
47
+export const CustomSchema = postWith({
48
+ $schema: z.literal(PostMetadataSchemaId.CUSTOM_LATEST),
49
+ lens: CustomMetadataDetailsSchema,
50
+});
src/post/PostMainFocus.ts
@@ -20,6 +20,7 @@ export enum PostMainFocus {
THREE_D = '3D',
STORY = 'STORY',
SPACE = 'SPACE',
+ CUSTOM = 'CUSTOM',
export const PostMainFocusSchema = z.nativeEnum(PostMainFocus);
src/post/PostMetadataSchemaId.ts
@@ -21,4 +21,5 @@ export enum PostMetadataSchemaId {
TRANSACTION_LATEST = `${location}/transaction/3.0.0.json`,
TEXT_ONLY_LATEST = `${location}/text-only/3.0.0.json`,
VIDEO_LATEST = `${location}/video/3.0.0.json`,
+ CUSTOM_LATEST = `${location}/custom/3.0.0.json`,
src/post/index.ts
@@ -11,6 +11,7 @@ export * from './ImageSchema.js';
export * from './LinkSchema.js';
export * from './LiveStreamSchema.js';
export * from './MintSchema.js';
+export * from './CustomSchema.js';
export * from './PostMainFocus.js';
export * from './PostMetadataSchemaId.js';
export * from './SpaceSchema.js';
@@ -30,6 +31,7 @@ import { type ImageMetadata, ImageSchema } from './ImageSchema.js';
import { type LinkMetadata, LinkSchema } from './LinkSchema.js';
import { type LiveStreamMetadata, LiveStreamSchema } from './LiveStreamSchema.js';
import { type MintMetadata, MintSchema } from './MintSchema.js';
+import { type CustomMetadata, CustomSchema } from './CustomSchema.js';
import { type SpaceMetadata, SpaceSchema } from './SpaceSchema.js';
import { type StoryMetadata, StorySchema } from './StorySchema.js';
import { type TextOnlyMetadata, TextOnlySchema } from './TextOnlySchema.js';
@@ -82,6 +84,7 @@ export type PostMetadata = ShapeCheck<
| LinkMetadata
| LiveStreamMetadata
| MintMetadata
+ | CustomMetadata
| SpaceMetadata
89
| TextOnlyMetadata
90
| StoryMetadata
@@ -124,6 +127,7 @@ export const PostMetadataSchema: z.ZodType<PostMetadata, z.ZodTypeDef, object> =
124
127
LinkSchema,
125
128
LiveStreamSchema,
126
129
130
131
SpaceSchema,
132
TextOnlySchema,
133
StorySchema,
0 commit comments