Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/0.1.0 alpha.17 #18

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"shy-falcons-sip",
"shy-parrots-approve",
"six-camels-leave",
"swift-days-wash",
"three-lamps-develop",
"tiny-glasses-unite",
"two-pigs-do"
Expand Down
5 changes: 5 additions & 0 deletions .changeset/swift-days-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lens-protocol/metadata': patch
---

**Added** docs generated with typedocs
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist
docs
jsonschemas
pnpm-lock.yaml
.changeset
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @lens-protocol/metadata

## 0.1.0-alpha.17

### Patch Changes

- 8d1f2b1: **Added** docs generated with typedocs

## 0.1.0-alpha.16

### Patch Changes
Expand Down
163 changes: 96 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ Schema validation and TS types for [LIP-2](https://github.com/lens-protocol/LIPs
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Publication metadata](#publication-metadata)
- [Mirror metadata](#mirror-metadata)
- [Profile metadata](#profile-metadata)
- [Compose](#compose)
- [Publication metadata](#publication-metadata)
- [Mirror metadata](#mirror-metadata)
- [Profile metadata](#profile-metadata)
- [Parse](#parse)
- [Publication metadata](#publication-metadata-1)
- [Mirror metadata](#mirror-metadata-1)
- [Profile metadata](#profile-metadata-1)
- [Extract version number](#extract-version-number)
- [Format validation error](#format-validation-error)
- [Types](#types)
- [Narrowing types](#narrowing-types)
- [`PublicationMetadata`](#publicationmetadata)
- [`AccessCondition`](#accesscondition)
- [`MetadataAttribute`](#metadataattribute)
- [Useful types](#useful-types)
- [Legacy metadata formats](#legacy-metadata-formats)
- [Other useful types](#other-useful-types)
- [Legacy metadata formats](#legacy-metadata-formats)
- [JSON schemas](#json-schemas)
- [Versioning](#versioning)
- [Adding a new schema](#adding-a-new-schema)
Expand Down Expand Up @@ -48,38 +54,11 @@ pnpm add @lens-protocol/metadata zod

## Usage

Assuming we have 2 JS objects:

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

### Publication metadata

Publication metadata schema is a union of all _content_ schemas (e.g. `ArticleMetadata`, `AudioMetadata`, etc. but NOT [`MirrorMetadata`](#mirror-metadata)).

Use it to parse the metadata referenced by `contentURI` of `Comment`, `Mirror`, and `Quote` publications.
### Compose

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

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

// OR

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

You can also create compliant `PublicationMetadata` objects via the following builder functions:
You can create compliant `PublicationMetadata` objects via the following builder functions:

```typescript
import {
Expand Down Expand Up @@ -108,7 +87,83 @@ const json = article({
> [!NOTE]
> Use the type definitions to explore the available properties and their types. The builders will throw a `ValidationError` with instructions on how to fix the error if the object is not compliant with the schema.

### Mirror metadata
We also provided a set of builder function for specific metadata sub-types (list to be expanded):

```typescript
import { geoUri } from '@lens-protocol/metadata';

const uri = geoUri({
lat: 51.5074,
lng: 0.1278,
});
```

#### Mirror metadata

You can create compliant `MirrorMetadata` objects via the following builder function:

```typescript
import { mirror } from '@lens-protocol/metadata';

const json = mirror({
appId: 'foobar-app',
});
```

> [!NOTE]
> Use the type definitions to explore the available properties and their types. The builder will throw a `ValidationError` with instructions on how to fix the error if the object is not compliant with the schema.

#### Profile metadata

You can create compliant `ProfileMetadata` objects via the following builder function:

```typescript
import { profile } from '@lens-protocol/metadata';

const json = profile({
name: 'Bob',

bio: 'I am a Lens user',
});
```

> [!NOTE]
> Use the type definitions to explore the available properties and their types. The builder will throw a `ValidationError` with instructions on how to fix the error if the object is not compliant with the schema.

### Parse

Assuming we have 2 JS objects:

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

#### Publication metadata

Publication metadata schema is a union of all _content_ schemas (e.g. `ArticleMetadata`, `AudioMetadata`, etc. but NOT [`MirrorMetadata`](#mirror-metadata)).

Use it to parse the metadata referenced by `contentURI` of `Comment`, `Mirror`, and `Quote` publications.

```typescript
import { PublicationMetadataSchema } from '@lens-protocol/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 }
```

#### Mirror metadata

Mirror metadata schema serve the purpose allowing mirrors be associated to a given Lens app (via the `appId`) as well as specify some operational flags (e.g. `hideFromFeed` and `globalReach`).

Expand All @@ -128,20 +183,7 @@ MirrorMetadataSchema.safeParse(invalid);
// => { success: false, error: ZodError }
```

You can also create compliant `MirrorMetadata` objects via the following builder function:

```typescript
import { mirror } from '@lens-protocol/metadata';

const json = mirror({
appId: 'foobar-app',
});
```

> [!NOTE]
> Use the type definitions to explore the available properties and their types. The builder will throw a `ValidationError` with instructions on how to fix the error if the object is not compliant with the schema.

### Profile metadata
#### Profile metadata

```typescript
import { ProfileMetadataSchema } from '@lens-protocol/metadata';
Expand All @@ -157,21 +199,6 @@ ProfileMetadataSchema.safeParse(invalid);
// => { success: false, error: ZodError }
```

You can also create compliant `ProfileMetadata` objects via the following builder function:

```typescript
import { profile } from '@lens-protocol/metadata';

const json = profile({
name: 'Bob',

bio: 'I am a Lens user',
});
```

> [!NOTE]
> Use the type definitions to explore the available properties and their types. The builder will throw a `ValidationError` with instructions on how to fix the error if the object is not compliant with the schema.

### Extract version number

A convenience `extractVersion` function is available to extract the version from a parsed `PublicationMetadata` or `ProfileMetadata`.
Expand Down Expand Up @@ -206,6 +233,8 @@ if (!result.success) {
}
```

## Types

### Narrowing types

Every time you have a discriminated union, you can use the discriminant to narrow the type. See few examples below.
Expand Down Expand Up @@ -293,7 +322,7 @@ switch (attribute.type) {
}
```

### Useful types
### Other useful types

The package also exports all enums and types that you might need to work with the metadata.

Expand Down Expand Up @@ -354,7 +383,7 @@ import {
} from '@lens-protocol/metadata';
```

### Legacy metadata formats
## Legacy metadata formats

The package also exports parsers for legacy metadata formats via the `@lens-protocol/metadata/legacy` entrypoint.

Expand Down
1 change: 1 addition & 0 deletions docs/.nojekyll
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
99 changes: 99 additions & 0 deletions docs/assets/highlight.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
:root {
--light-hl-0: #008000;
--dark-hl-0: #6A9955;
--light-hl-1: #795E26;
--dark-hl-1: #DCDCAA;
--light-hl-2: #000000;
--dark-hl-2: #D4D4D4;
--light-hl-3: #A31515;
--dark-hl-3: #CE9178;
--light-hl-4: #AF00DB;
--dark-hl-4: #C586C0;
--light-hl-5: #001080;
--dark-hl-5: #9CDCFE;
--light-hl-6: #0000FF;
--dark-hl-6: #569CD6;
--light-hl-7: #0070C1;
--dark-hl-7: #4FC1FF;
--light-hl-8: #098658;
--dark-hl-8: #B5CEA8;
--light-hl-9: #0451A5;
--dark-hl-9: #9CDCFE;
--light-hl-10: #267F99;
--dark-hl-10: #4EC9B0;
--light-code-background: #FFFFFF;
--dark-code-background: #1E1E1E;
}

@media (prefers-color-scheme: light) { :root {
--hl-0: var(--light-hl-0);
--hl-1: var(--light-hl-1);
--hl-2: var(--light-hl-2);
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--hl-7: var(--light-hl-7);
--hl-8: var(--light-hl-8);
--hl-9: var(--light-hl-9);
--hl-10: var(--light-hl-10);
--code-background: var(--light-code-background);
} }

@media (prefers-color-scheme: dark) { :root {
--hl-0: var(--dark-hl-0);
--hl-1: var(--dark-hl-1);
--hl-2: var(--dark-hl-2);
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--hl-7: var(--dark-hl-7);
--hl-8: var(--dark-hl-8);
--hl-9: var(--dark-hl-9);
--hl-10: var(--dark-hl-10);
--code-background: var(--dark-code-background);
} }

:root[data-theme='light'] {
--hl-0: var(--light-hl-0);
--hl-1: var(--light-hl-1);
--hl-2: var(--light-hl-2);
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--hl-7: var(--light-hl-7);
--hl-8: var(--light-hl-8);
--hl-9: var(--light-hl-9);
--hl-10: var(--light-hl-10);
--code-background: var(--light-code-background);
}

:root[data-theme='dark'] {
--hl-0: var(--dark-hl-0);
--hl-1: var(--dark-hl-1);
--hl-2: var(--dark-hl-2);
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--hl-7: var(--dark-hl-7);
--hl-8: var(--dark-hl-8);
--hl-9: var(--dark-hl-9);
--hl-10: var(--dark-hl-10);
--code-background: var(--dark-code-background);
}

.hl-0 { color: var(--hl-0); }
.hl-1 { color: var(--hl-1); }
.hl-2 { color: var(--hl-2); }
.hl-3 { color: var(--hl-3); }
.hl-4 { color: var(--hl-4); }
.hl-5 { color: var(--hl-5); }
.hl-6 { color: var(--hl-6); }
.hl-7 { color: var(--hl-7); }
.hl-8 { color: var(--hl-8); }
.hl-9 { color: var(--hl-9); }
.hl-10 { color: var(--hl-10); }
pre, code { background: var(--code-background); }
59 changes: 59 additions & 0 deletions docs/assets/main.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/assets/search.js

Large diffs are not rendered by default.

Loading