Skip to content

Commit

Permalink
Merge pull request #14 from lens-protocol/release/0.1.0-alpha.13
Browse files Browse the repository at this point in the history
Release/0.1.0-alpha.13
  • Loading branch information
cesarenaldi authored Sep 11, 2023
2 parents 35f71d8 + 5fb4624 commit 925619d
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 62 deletions.
1 change: 1 addition & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"quick-pets-itch",
"shy-cougars-boil",
"shy-falcons-sip",
"shy-parrots-approve",
"six-camels-leave",
"three-lamps-develop",
"tiny-glasses-unite",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/shy-parrots-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lens-protocol/metadata': patch
---

**Fixed** `MirrorSchema` id, location, generated JSON schema"
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.13

### Patch Changes

- f1ff3a3: **Fixed** `MirrorSchema` id, location, generated JSON schema"

## 0.1.0-alpha.12

### Patch Changes
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,13 @@ import {
Importing JSON schema in TypeScript is a simple as:

```typescript
import audio from '@lens-protocol/metadata/jsonschemas/publications/audio/1.0.0.json' assert { type: 'json' };
import audio from '@lens-protocol/metadata/jsonschemas/publications/audio/3.0.0.json' assert { type: 'json' };

import audio from '@lens-protocol/metadata/jsonschemas/publications/article/1.0.0.json' assert { type: 'json' };
import audio from '@lens-protocol/metadata/jsonschemas/publications/article/3.0.0.json' assert { type: 'json' };

import embed from '@lens-protocol/metadata/jsonschemas/profile/1.0.0.json' assert { type: 'json' };
import mirror from '@lens-protocol/metadata/jsonschemas/publications/mirror/1.0.0.json' assert { type: 'json' };

import profile from '@lens-protocol/metadata/jsonschemas/profile/2.0.0.json' assert { type: 'json' };
```

You can the use them in your JSON Schema validator of choice, for example [ajv](https://ajv.js.org/).
Expand All @@ -455,7 +457,7 @@ The Lens Protocol Metadata Standards use a **self-describing JSON format**. All

```json
{
"$schema": "https://json-schemas.lens.dev/publications/article/1.0.0.json",
"$schema": "https://json-schemas.lens.dev/publications/article/3.0.0.json",

"lens": {
"id": "b3d7f1a0-1f75-11ec-9621-0242ac130002",
Expand Down
2 changes: 1 addition & 1 deletion 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.12",
"version": "0.1.0-alpha.13",
"description": "Lens Protocol Metadata Standards",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
58 changes: 32 additions & 26 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,21 @@ await fs.ensureDir(outputDir);

// Publication schemas
const schemas = new Map<string, z.ZodSchema<unknown>>([
['publications/3D/1.0.0.json', ThreeDMetadataSchema],
['publications/article/1.0.0.json', ArticleSchema],
['publications/audio/1.0.0.json', AudioSchema],
['publications/checking-in/1.0.0.json', CheckingInSchema],
['publications/embed/1.0.0.json', EmbedSchema],
['publications/event/1.0.0.json', EventSchema],
['publications/image/1.0.0.json', ImageSchema],
['publications/link/1.0.0.json', LinkSchema],
['publications/livestream/1.0.0.json', LivestreamSchema],
['publications/mint/1.0.0.json', MintSchema],
['publications/mirror/1.0.0.json', MirrorMetadataSchema],
['publications/space/1.0.0.json', SpaceSchema],
['publications/story/1.0.0.json', StorySchema],
['publications/text-only/1.0.0.json', TextOnlySchema],
['publications/transaction/1.0.0.json', TransactionSchema],
['publications/video/1.0.0.json', VideoSchema],
['publications/3D/3.0.0.json', ThreeDMetadataSchema],
['publications/article/3.0.0.json', ArticleSchema],
['publications/audio/3.0.0.json', AudioSchema],
['publications/checking-in/3.0.0.json', CheckingInSchema],
['publications/embed/3.0.0.json', EmbedSchema],
['publications/event/3.0.0.json', EventSchema],
['publications/image/3.0.0.json', ImageSchema],
['publications/link/3.0.0.json', LinkSchema],
['publications/livestream/3.0.0.json', LivestreamSchema],
['publications/mint/3.0.0.json', MintSchema],
['publications/space/3.0.0.json', SpaceSchema],
['publications/story/3.0.0.json', StorySchema],
['publications/text-only/3.0.0.json', TextOnlySchema],
['publications/transaction/3.0.0.json', TransactionSchema],
['publications/video/3.0.0.json', VideoSchema],
]);

for (const [path, Schema] of schemas) {
Expand Down Expand Up @@ -108,16 +107,23 @@ for (const [path, Schema] of schemas) {
}

// Profile schema
const outputFile = join(outputDir, 'profile/1.0.0.json');
const others = new Map<string, z.ZodSchema<unknown>>([
['profile/2.0.0.json', ProfileMetadataSchema],
['publications/mirror/1.0.0.json', MirrorMetadataSchema],
]);

await fs.ensureFile(outputFile);
for (const [path, Schema] of others) {
const outputFile = join(outputDir, path);

const jsonSchema = zodToJsonSchema(ProfileMetadataSchema, {
target: 'jsonSchema7',
definitionPath: '$defs',
definitions: {
MetadataAttribute: MetadataAttributeSchema,
},
});
await fs.ensureFile(outputFile);

await fs.writeJSON(outputFile, jsonSchema, { spaces: 2 });
const jsonSchema = zodToJsonSchema(Schema, {
target: 'jsonSchema7',
definitionPath: '$defs',
definitions: {
MetadataAttribute: MetadataAttributeSchema,
},
});

await fs.writeJSON(outputFile, jsonSchema, { spaces: 2 });
}
33 changes: 33 additions & 0 deletions src/publication/MirrorSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { z } from 'zod';

import { MetadataCoreSchema } from './common/index.js';
import { SchemasRoot } from '../constants.js';

export /**
* Mirror metadata schema.
*
* @example
* with `parse`:
* ```typescript
* MirrorMetadata.parse(valid); // => MirrorMetadata
*
* MirrorMetadata.parse(invalid); // => throws ZodError
* ```
*
* @example
* with `safeParse`:
* ```typescript
* MirrorMetadata.safeParse(valid);
* // => { success: true, data: MirrorMetadata }
*
* MirrorMetadata.safeParse(invalid);
* // => { success: false, error: ZodError }
* ```
*/

const MirrorMetadataSchema = z.object({
$schema: z.literal(`${SchemasRoot}/publications/mirror/1.0.0.json`),

lens: MetadataCoreSchema,
});
export type MirrorMetadata = z.infer<typeof MirrorMetadataSchema>;
1 change: 0 additions & 1 deletion src/publication/PublicationSchemaId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export enum PublicationSchemaId {
LINK_LATEST = `${location}/link/3.0.0.json`,
LIVESTREAM_LATEST = `${location}/livestream/3.0.0.json`,
MINT_LATEST = `${location}/mint/3.0.0.json`,
MIRROR_LATEST = `${location}/mirror/3.0.0.json`,
SPACE_LATEST = `${location}/space/3.0.0.json`,
STORY_LATEST = `${location}/story/3.0.0.json`,
TRANSACTION_LATEST = `${location}/transaction/3.0.0.json`,
Expand Down
31 changes: 1 addition & 30 deletions src/publication/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from './ImageSchema.js';
export * from './LinkSchema.js';
export * from './LivestreamSchema.js';
export * from './MintSchema.js';
export * from './MirrorSchema.js';
export * from './PublicationMainFocus.js';
export * from './PublicationSchemaId.js';
export * from './SpaceSchema.js';
Expand All @@ -29,41 +30,11 @@ import { ImageSchema } from './ImageSchema.js';
import { LinkSchema } from './LinkSchema.js';
import { LivestreamSchema } from './LivestreamSchema.js';
import { MintSchema } from './MintSchema.js';
import { PublicationSchemaId } from './PublicationSchemaId.js';
import { SpaceSchema } from './SpaceSchema.js';
import { StorySchema } from './StorySchema.js';
import { TextOnlySchema } from './TextOnlySchema.js';
import { TransactionSchema } from './TransactionSchema.js';
import { VideoSchema } from './VideoSchema.js';
import { MetadataCoreSchema, publicationWith } from './common';

/**
* Mirror metadata schema.
*
* @example
* with `parse`:
* ```typescript
* MirrorMetadata.parse(valid); // => MirrorMetadata
*
* MirrorMetadata.parse(invalid); // => throws ZodError
* ```
*
* @example
* with `safeParse`:
* ```typescript
* MirrorMetadata.safeParse(valid);
* // => { success: true, data: MirrorMetadata }
*
* MirrorMetadata.safeParse(invalid);
* // => { success: false, error: ZodError }
* ```
*/
export const MirrorMetadataSchema = publicationWith({
$schema: z.literal(PublicationSchemaId.MIRROR_LATEST),

lens: MetadataCoreSchema,
});
export type MirrorMetadata = z.infer<typeof MirrorMetadataSchema>;

/**
* A union of all publication metadata schemas.
Expand Down

0 comments on commit 925619d

Please sign in to comment.