Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lens-protocol/metadata

Package Overview
Dependencies
Maintainers
9
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lens-protocol/metadata

Lens Protocol Metadata Standards

  • 0.1.0-alpha.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
9
Created
Source

Lens Protocol Metadata Standards

Schema vaidation and TS types for LIP-2 Lens Protocol Metadata Standards.

Features

  • Zod schema definitions
  • JSON Schema definitions
  • TypeScript type definitions

Installation

# npm:
npm install @lens-protocol/metadata zod

# yarn:
yarn add @lens-protocol/metadata zod

# pnpm:
pnpm add @lens-protocol/metadata zod

[!NOTE]
zod is marked as optional peer dependency, so if you all you need is the JSON Schema definitions, you can install @lens-protocol/metadata without zod.

Usage

Parsing and validating metadata

import { PublicationMetadataSchema } from '@lens-protocol/metadata';

const valid = {
  /** example of valid publication metadata **/
};
const invalid = {
  /** example of invalid publication metadata **/
};

PublicationMetadataSchema.parse(valid); // => PublicationMetadata
PublicationMetadataSchema.parse(invalid); // => throws ZodError

// OR

PublicationMetadataSchema.safeParse(valid);
// => { success: true, data: PublicationMetadata }
PublicationMetadataSchema.safeParse(invalid);
// => { success: false, error: ZodError }

Format validation error

ZodError contains all the information needed to inform you about the validation error, but it's not very user friendly. You can use formatZodError to get a more readable error message.

import { PublicationMetadataSchema, formatZodError } from '@lens-protocol/metadata';

const result = PublicationMetadataSchema.safeParse(invalid);

if (!result.success) {
  console.log(formatZodError(result.error));
}

Narrowing types

import { PublicationMetadata, PublicationMetadataSchema, SchemaId } from '@lens-protocol/metadata';

const publicationMetadata = PublicationMetadataSchema.parse(valid);

switch (publicationMetadata.$schema) {
  case SchemaId.ARTICLE:
    // publicationMetadata is ArticleMetadata
    break;
  case SchemaId.AUDIO:
    // publicationMetadata is AudioMetadata
    break;
  case SchemaId.IMAGE:
    // publicationMetadata is ImageMetadata
    break;
  case SchemaId.TEXT_ONLY:
    // publicationMetadata is TextOnlyMetadata
    break;

  // ...
}

JSON schemas

Importing JSON schema in TypeScript is a simple as:

import audio from '@lens-protocol/metadata/jsonschemas/audio/1-0-0.json' assert { type: 'json' };

import embed from '@lens-protocol/metadata/jsonschemas/embed/1-0-0.json' assert { type: 'json' };

You can the use them in your JSON Schema validator of choice, for example ajv.

Contributing

To contribute to the Lens Protocol Metadata Standards, please fork this repository and submit a pull request with your changes.

To build the project, run:

pnpm build

Add changeset with:

pnpm changeset add

Use keepachangelog format for the changeset message.

Releasing

Release flow is managed by changesets.

To release a new version follow the steps below:

  1. Create a new branch from main with the name release/<version>
  2. Build the project
pnpm install && pnpm build
  1. Update relevant package.json's versions and update CHANGELOG.md for each package:
pnpm changeset version
  1. Review, commit and push the changes
  2. Create a PR from release/<version> to main
  3. Once approved, publish with (you need to be logged in to npm authorized to publish under @lens-protocol):
pnpm changeset publish
  1. Push the tags
git push origin release/<version> --follow-tags
  1. Merge the PR with a merge commit

License

Lens Protocol Metadata Standards is MIT licensed

Support

See the Lens API and SDK channel on our Discord

Keywords

FAQs

Package last updated on 18 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc