Skip to content

Commit

Permalink
Merge pull request #17 from lens-protocol/release/0.1.0-alpha.16
Browse files Browse the repository at this point in the history
Release/0.1.0-alpha.16
  • Loading branch information
cesarenaldi authored Sep 14, 2023
2 parents a9f5e00 + b7517fd commit ec30649
Show file tree
Hide file tree
Showing 21 changed files with 766 additions and 17 deletions.
1 change: 1 addition & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"popular-spies-enjoy",
"proud-pens-hammer",
"quick-pets-itch",
"sharp-clocks-tell",
"shiny-pans-fix",
"shy-cougars-boil",
"shy-falcons-sip",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/sharp-clocks-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lens-protocol/metadata': patch
---

**Added** metadata builder functions
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.16

### Patch Changes

- b111da8: **Added** metadata builder functions

## 0.1.0-alpha.15

### Patch Changes
Expand Down
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,35 @@ PublicationMetadataSchema.safeParse(invalid);
// => { success: false, error: ZodError }
```

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

```typescript
import {
article,
audio,
checkingIn,
embed,
event,
image,
link,
livestream,
mint,
space,
story,
textOnly,
threeD,
transaction,
video,
} from '@lens-protocol/metadata';

const json = article({
content: 'The content of the 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

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 @@ -99,6 +128,19 @@ 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

```typescript
Expand All @@ -115,6 +157,21 @@ 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
4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { Config } from 'jest';
const config: Config = {
preset: 'ts-jest',
testEnvironment: 'node',
testRegex: '/__tests__/.*|(\\.|/)spec\\.ts?$',
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
testRegex: '/__tests__/.*|(\\.|/)spec\\.ts$',
testPathIgnorePatterns: ['\\.snap$', '/node_modules/', '/dist/'],
moduleNameMapper: {
// see https://github.com/jestjs/jest/issues/9430#issuecomment-1676252021
'^(\\.{1,2}/.*)\\.js$': '$1',
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lens-protocol/metadata",
"version": "0.1.0-alpha.15",
"version": "0.1.0-alpha.16",
"description": "Lens Protocol Metadata Standards",
"type": "module",
"main": "./dist/index.cjs",
Expand Down Expand Up @@ -64,6 +64,7 @@
"@jest/globals": "^29.6.2",
"@types/fs-extra": "^11.0.1",
"@types/node": "^20.5.0",
"@types/uuid": "^9.0.4",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
"eslint": "^8.47.0",
Expand Down Expand Up @@ -96,5 +97,8 @@
"pnpm": "^8.0.0",
"npm": "^8.19.2"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"dependencies": {
"uuid": "^9.0.1"
}
}
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
SpaceSchema,
StorySchema,
TextOnlySchema,
ThreeDMetadataSchema,
ThreeDSchema,
TransactionSchema,
VideoSchema,
ProfileIdSchema,
Expand All @@ -55,7 +55,7 @@ await fs.ensureDir(outputDir);

// Publication schemas
const schemas = new Map<string, z.ZodSchema<unknown>>([
['publications/3D/3.0.0.json', ThreeDMetadataSchema],
['publications/3D/3.0.0.json', ThreeDSchema],
['publications/article/3.0.0.json', ArticleSchema],
['publications/audio/3.0.0.json', AudioSchema],
['publications/checking-in/3.0.0.json', CheckingInSchema],
Expand Down
25 changes: 25 additions & 0 deletions src/__tests__/__snapshots__/builders.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Given the publication metadata builders when using the article builder should return a valid TextOnlyMetadata 1`] = `
{
"$schema": "https://json-schemas.lens.dev/publications/article/3.0.0.json",
"lens": {
"content": "GM!",
"id": Any<String>,
"locale": "en",
"mainContentFocus": "ARTICLE",
},
}
`;
exports[`Given the publication metadata builders when using the textOnly builder should return a valid TextOnlyMetadata 1`] = `
{
"$schema": "https://json-schemas.lens.dev/publications/text-only/3.0.0.json",
"lens": {
"content": "GM!",
"id": Any<String>,
"locale": "en",
"mainContentFocus": "TEXT_ONLY",
},
}
`;
33 changes: 33 additions & 0 deletions src/__tests__/builders.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, it } from '@jest/globals';

import { ValidationError, article, textOnly } from '../builders.js';

describe(`Given the publication metadata builders`, () => {
describe(`when using the ${article.name} builder`, () => {
it('should return a valid TextOnlyMetadata', () => {
const metadata = article({ content: 'GM!' });

expect(metadata).toMatchSnapshot({
lens: {
id: expect.any(String),
},
});
});

it(`should throw a "${ValidationError.name}" in case of invalid input`, () => {
expect(() => article({ content: '' })).toThrowError(ValidationError);
});
});

describe(`when using the ${textOnly.name} builder`, () => {
it('should return a valid TextOnlyMetadata', () => {
const metadata = textOnly({ content: 'GM!' });

expect(metadata).toMatchSnapshot({
lens: {
id: expect.any(String),
},
});
});
});
});
Loading

0 comments on commit ec30649

Please sign in to comment.