Skip to content
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
5 changes: 0 additions & 5 deletions .changeset/perfect-cobras-destroy.md

This file was deleted.

10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @graphprotocol/grc-20

## 0.1.0

### Minor Changes

- Update ID generation fn name from make -> generate

### Patch Changes

- f8035bf: Add docs for deploying space and generating calldata to publish edits.

## 0.0.9

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Entities throughout The Graph are referenced via globally unique identifiers. Th
```ts
import { ID } from 'graphprotocol/grc-20';

const newId = ID.make();
const newId = ID.generate();
```

### Making ops
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": "@graphprotocol/grc-20",
"version": "0.0.9",
"version": "0.1.0",
"license": "MIT",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/core/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @since 0.0.6
*/

import { make as makeId } from '../id.js';
import { generate } from '../id.js';
import { Relation } from '../relation.js';
import type { CreateRelationOp, SetTripleOp } from '../types.js';
import { getChecksumAddress } from './get-checksum-address.js';
Expand All @@ -32,7 +32,7 @@ type MakeAccountReturnType = {
* @returns ops – The ops for the Account entity: {@link MakeAccountReturnType}
*/
export function make(address: string): MakeAccountReturnType {
const accountId = makeId();
const accountId = generate();
const checkedAddress = getChecksumAddress(address);

return {
Expand Down
2 changes: 1 addition & 1 deletion src/core/base58.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('base58', () => {

const encoded = encodeBase58(given);

// We check the length should be 22 in the ID.make() function and
// We check the length should be 22 in the ID.generate() function and
// re-run encodeBase58 if not.
expect(encoded.length === 22 || encoded.length === 21).toBe(true);

Expand Down
4 changes: 2 additions & 2 deletions src/core/blocks/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @since 0.0.6
*/

import { make as makeId } from '../../id.js';
import { generate } from '../../id.js';
import { Relation } from '../../relation.js';
import { SYSTEM_IDS } from '../../system-ids.js';
import type { CreateRelationOp, SetTripleOp } from '../../types.js';
Expand Down Expand Up @@ -43,7 +43,7 @@ type DataBlockArgs = { fromId: string; sourceType: DataBlockSourceType; position
* @returns ops – The ops for the Data Block entity: {@link Op}[]
*/
export function make({ fromId, sourceType, position, name }: DataBlockArgs): (SetTripleOp | CreateRelationOp)[] {
const newBlockId = makeId();
const newBlockId = generate();

const dataBlockType = Relation.make({
fromId: newBlockId,
Expand Down
4 changes: 2 additions & 2 deletions src/core/blocks/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @since 0.0.6
*/

import { make as makeId } from '../../id.js';
import { generate } from '../../id.js';
import { Relation } from '../../relation.js';
import { SYSTEM_IDS } from '../../system-ids.js';
import type { Op } from '../../types.js';
Expand All @@ -29,7 +29,7 @@ type TextBlockArgs = { fromId: string; text: string; position?: string };
* @returns ops – The ops for the Text Block entity: {@link Op}[]
*/
export function make({ fromId, text, position }: TextBlockArgs): Op[] {
const newBlockId = makeId();
const newBlockId = generate();

const textBlockType = Relation.make({
fromId: newBlockId,
Expand Down
4 changes: 2 additions & 2 deletions src/core/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @since 0.0.6
*/

import { make as makeId } from '../id.js';
import { generate } from '../id.js';
import { Relation } from '../relation.js';
import { SYSTEM_IDS } from '../system-ids.js';
import type { CreateRelationOp, Op, SetTripleOp } from '../types.js';
Expand All @@ -29,7 +29,7 @@ type MakeImageReturnType = {
* @returns ops – The ops for the Image entity: {@link MakeImageReturnType}
*/
export function make(src: string): MakeImageReturnType {
const entityId = makeId();
const entityId = generate();

return {
imageId: entityId,
Expand Down
4 changes: 2 additions & 2 deletions src/core/relation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { INITIAL_RELATION_INDEX_VALUE } from '../../constants.js';
import { make as makeId } from '../id.js';
import { generate } from '../id.js';
import { SYSTEM_IDS } from '../system-ids.js';
import type { CreateRelationOp, DeleteRelationOp } from '../types.js';
import { Position } from './position.js';
Expand Down Expand Up @@ -46,7 +46,7 @@ interface CreateRelationArgs {
* @returns – {@link CreateRelationOp}
*/
export function make(args: CreateRelationArgs): CreateRelationOp {
const newEntityId = args.relationId ?? makeId();
const newEntityId = args.relationId ?? generate();

return {
type: 'CREATE_RELATION',
Expand Down
4 changes: 2 additions & 2 deletions src/id.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect, it } from 'vitest';

import { BASE58_ALLOWED_CHARS } from './core/base58.js';
import { make } from './id.js';
import { generate } from './id.js';

// @NOTE this would be a good candidate for DST-style tests
it('should generate valid base58 encoded id with length of 22', () => {
const id = make();
const id = generate();
expect(id).toBeTypeOf('string');
expect(id.length).toBe(22);
expect(id.split('').every(char => BASE58_ALLOWED_CHARS.includes(char))).toBe(true);
Expand Down
6 changes: 3 additions & 3 deletions src/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import { encodeBase58 } from './core/base58.js';
* ```
* import { ID } from '@graphprotocol/grc-20'
*
* const id = ID.make();
* const id = ID.generate();
* console.log(id) // Gw9uTVTnJdhtczyuzBkL3X
* ```
*
* @returns base58 encoded v4 UUID
*/
export function make() {
export function generate(): string {
const uuid = uuidv4();
const stripped = uuid.replaceAll(/-/g, '');
const id = encodeBase58(stripped);
Expand All @@ -36,5 +36,5 @@ export function make() {
return id;
}

return make();
return generate();
}
4 changes: 2 additions & 2 deletions src/proto/edit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { make as makeId } from '../id.js';
import { generate } from '../id.js';
import type { Op } from '../types.js';
import { ActionType, Edit, Entity, Op as OpBinary, OpType, Relation, Triple } from './gen/src/proto/ipfs_pb.js';

Expand All @@ -12,7 +12,7 @@ export function make({ name, ops, author }: MakeeEditProposalArgs): Uint8Array {
return new Edit({
type: ActionType.ADD_EDIT,
version: '1.0.0',
id: makeId(),
id: generate(),
name,
ops: opsToBinary(ops),
authors: [author],
Expand Down
Loading