Skip to content

Commit

Permalink
feat: feed, graph, username builders
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarenaldi committed Nov 8, 2024
1 parent 7fa5f07 commit b4a1b77
Show file tree
Hide file tree
Showing 16 changed files with 316 additions and 128 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"lint:eslint": "pnpm eslint",
"lint:typecheck": "tsc --noEmit",
"lint:prettier": "prettier --check .",
"lint:prettier:fix": "prettier --check --w .",
"prepublish": "pnpm clean:dist && pnpm lint && pnpm test && pnpm build",
"test": "jest \"src/.+.\\.spec\\.ts\"",
"typedoc:docs": "typedoc",
Expand Down
3 changes: 0 additions & 3 deletions src/account/AccountMetadataSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ const AccountMetadataDetailsSchema: z.ZodType<AccountMetadataDetails, z.ZodTypeD
{ description: 'The Lens specific metadata details.' },
);

/**
* Use this to create Account metadata objects.
*/
export type AccountMetadata = {
/**
* The schema id.
Expand Down
51 changes: 51 additions & 0 deletions src/builders/feed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { v4 } from 'uuid';

import { evaluate } from './ValidationError';
import { FeedMetadataSchemaId, FeedMetadata, FeedMetadataSchema } from '../feed';

export type FeedOptions = {
/**
* A unique identifier that in storages like IPFS ensures the uniqueness of the metadata URI.
*
* @defaultValue a UUID
*/
id?: string;
/**
* The name of the Feed.
*/
name: string;
/**
* The human-friendly title for the Feed.
*/
title: string;
/**
* Optional markdown formatted description of the Feed.
*/
description?: string | null;
};

/**
* Creates a valid FeedMetadata.
*
* ```ts
* const metadata = feed({
* name: 'XYZ',
* title: 'Not Just Another Feed… or is it?',
* description: 'Bringing you one step closer to achieving absolutely nothing, but in style!',
* });
* ```
*
* @category Compose
* @param input - Use your IDE suggestions for an enhanced development experience
*/
export function feed({ id = v4(), ...others }: FeedOptions): FeedMetadata {
return evaluate(
FeedMetadataSchema.safeParse({
$schema: FeedMetadataSchemaId.LATEST,
lens: {
id,
...others,
},
}),
);
}
51 changes: 51 additions & 0 deletions src/builders/graph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { v4 } from 'uuid';

import { evaluate } from './ValidationError';
import { GraphMetadataSchemaId, GraphMetadata, GraphMetadataSchema } from '../graph';

export type GraphOptions = {
/**
* A unique identifier that in storages like IPFS ensures the uniqueness of the metadata URI.
*
* @defaultValue a UUID
*/
id?: string;
/**
* The name of the Graph.
*/
name: string;
/**
* The human-friendly title for the Graph.
*/
title: string;
/**
* Optional markdown formatted description of the Graph.
*/
description?: string | null;
};

/**
* Creates a valid GraphMetadata.
*
* ```ts
* const metadata = graph({
* name: 'XYZ',
* title: 'Not Just Another Graph… or is it?',
* description: 'Bringing you one step closer to achieving absolutely nothing, but in style!',
* });
* ```
*
* @category Compose
* @param input - Use your IDE suggestions for an enhanced development experience
*/
export function graph({ id = v4(), ...others }: GraphOptions): GraphMetadata {
return evaluate(
GraphMetadataSchema.safeParse({
$schema: GraphMetadataSchemaId.LATEST,
lens: {
id,
...others,
},
}),
);
}
3 changes: 3 additions & 0 deletions src/builders/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export * from './account.js';
export * from './app.js';
export * from './encryption.js';
export * from './feed.js';
export * from './graph.js';
export * from './modules.js';
export * from './posts.js';
export * from './username.js';
export { ValidationError } from './ValidationError.js';
Loading

0 comments on commit b4a1b77

Please sign in to comment.