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: 5 additions & 0 deletions .changeset/rename-grcop-to-op.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphprotocol/grc-20": minor
---

Rename `GrcOp` to `Op` as the primary export. The `GrcOp` type is now deprecated but still available for backwards compatibility.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ const { id: personId, ops: createPersonOps } = Graph.createEntity({
#### Example Flow

```ts
import { Graph, type GrcOp } from '@graphprotocol/grc-20';
import { Graph, type Op } from '@graphprotocol/grc-20';

const ops: Array<GrcOp> = [];
const ops: Array<Op> = [];

// create an age property
const { id: agePropertyId, ops: createAgePropertyOps } = Graph.createProperty({
Expand Down
6 changes: 3 additions & 3 deletions scripts/setup-rank-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Usage: import { ops } from './scripts/setup-rank-types.js'
*/

import type { Op as GrcOp } from '@geoprotocol/grc-20';
import type { Op } from '@geoprotocol/grc-20';
import {
RANK_TYPE,
RANK_TYPE_PROPERTY,
Expand All @@ -22,8 +22,8 @@ import {
import { createProperty } from '../src/graph/create-property.js';
import { createType } from '../src/graph/create-type.js';

const generateRankTypeOps = (): GrcOp[] => {
const ops: GrcOp[] = [];
const generateRankTypeOps = (): Op[] => {
const ops: Op[] = [];

// 1. Create RANK_TYPE_PROPERTY - A TEXT property storing ORDINAL/WEIGHTED
const rankTypeProperty = createProperty({
Expand Down
6 changes: 3 additions & 3 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 type { Op as GrcOp } from '@geoprotocol/grc-20';
import type { Op } from '@geoprotocol/grc-20';
import { createEntity } from '../graph/create-entity.js';
import { createRelation } from '../graph/create-relation.js';
import { generate } from '../id-utils.js';
Expand All @@ -15,7 +15,7 @@ import { ACCOUNT_TYPE, ADDRESS_PROPERTY, NAME_PROPERTY, NETWORK_PROPERTY, TYPES_

type MakeAccountReturnType = {
accountId: string;
ops: GrcOp[];
ops: Op[];
};

/**
Expand All @@ -36,7 +36,7 @@ export function make(address: string): MakeAccountReturnType {
const accountId = generate();
const checkedAddress: string = getChecksumAddress(address);

const ops: GrcOp[] = [];
const ops: Op[] = [];

const { ops: entityOps } = createEntity({
id: accountId,
Expand Down
8 changes: 4 additions & 4 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 type { Op as GrcOp } from '@geoprotocol/grc-20';
import type { Op } from '@geoprotocol/grc-20';
import { createRelation } from '../../graph/create-relation.js';
import { updateEntity } from '../../graph/update-entity.js';
import { Id } from '../../id.js';
Expand Down Expand Up @@ -48,12 +48,12 @@ type DataBlockParams = {
* ```
*
* @param param args {@link TextBlockParams}
* @returns ops – The ops for the Data Block entity: {@link GrcOp}[]
* @returns ops – The ops for the Data Block entity: {@link Op}[]
*/
export function make({ fromId, sourceType, position, name }: DataBlockParams): GrcOp[] {
export function make({ fromId, sourceType, position, name }: DataBlockParams): Op[] {
const newBlockId = generate();

const ops: GrcOp[] = [];
const ops: Op[] = [];
const { ops: dataBlockTypeOps } = createRelation({
fromEntity: newBlockId,
type: TYPES_PROPERTY,
Expand Down
8 changes: 4 additions & 4 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 type { Op as GrcOp } from '@geoprotocol/grc-20';
import type { Op } from '@geoprotocol/grc-20';
import { createRelation } from '../../graph/create-relation.js';
import { updateEntity } from '../../graph/update-entity.js';
import { Id } from '../../id.js';
Expand All @@ -28,12 +28,12 @@ type TextBlockParams = { fromId: string; text: string; position?: string };
* ```
*
* @param param args {@link TextBlockParams}
* @returns ops – The ops for the Text Block entity: {@link GrcOp}[]
* @returns ops – The ops for the Text Block entity: {@link Op}[]
*/
export function make({ fromId, text, position }: TextBlockParams): GrcOp[] {
export function make({ fromId, text, position }: TextBlockParams): Op[] {
const newBlockId = generate();

const ops: GrcOp[] = [];
const ops: Op[] = [];

const { ops: textBlockTypeOps } = createRelation({
fromEntity: newBlockId,
Expand Down
34 changes: 17 additions & 17 deletions src/encoding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
formatId,
type Edit as GrcEdit,
type Id as GrcId,
type Op as GrcOp,
type Op,
parseId,
} from '@geoprotocol/grc-20';
import { describe, expect, it } from 'vitest';
Expand Down Expand Up @@ -55,7 +55,7 @@ describe('GRC-20 v2 Encoding', () => {
expect(decoded.ops.length).toBe(1);
expect(decoded.ops[0]?.type).toBe('createEntity');

const op = decoded.ops[0] as Extract<GrcOp, { type: 'createEntity' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'createEntity' }>;
expect(formatId(op.id)).toBe('3af3e22d21694a078681516710b7ecf1');
expect(op.values.length).toBe(1);
expect(op.values[0]?.value.type).toBe('text');
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('GRC-20 v2 Encoding', () => {
expect(decoded.name).toBe('test');
expect(decoded.ops.length).toBe(1);

const op = decoded.ops[0] as Extract<GrcOp, { type: 'createEntity' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'createEntity' }>;
expect(op.values[0]?.value.type).toBe('float64');
if (op.values[0]?.value.type === 'float64') {
expect(op.values[0].value.value).toBe(42.5);
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('GRC-20 v2 Encoding', () => {
const binary = encodeEdit(edit);
const decoded = decodeEdit(binary);

const op = decoded.ops[0] as Extract<GrcOp, { type: 'createEntity' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'createEntity' }>;
expect(op.values[0]?.value.type).toBe('bool');
if (op.values[0]?.value.type === 'bool') {
expect(op.values[0].value.value).toBe(true);
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('GRC-20 v2 Encoding', () => {
const binary = encodeEdit(edit);
const decoded = decodeEdit(binary);

const op = decoded.ops[0] as Extract<GrcOp, { type: 'createEntity' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'createEntity' }>;
expect(op.values[0]?.value.type).toBe('point');
if (op.values[0]?.value.type === 'point') {
expect(op.values[0].value.lon).toBeCloseTo(-122.4194, 4);
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('GRC-20 v2 Encoding', () => {
const binary = encodeEdit(edit);
const decoded = decodeEdit(binary);

const op = decoded.ops[0] as Extract<GrcOp, { type: 'createEntity' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'createEntity' }>;
expect(op.values[0]?.value.type).toBe('date');
if (op.values[0]?.value.type === 'date') {
expect(op.values[0].value.value).toBe('2024-01-15');
Expand Down Expand Up @@ -256,7 +256,7 @@ describe('GRC-20 v2 Encoding', () => {
const binary = encodeEdit(edit);
const decoded = decodeEdit(binary);

const op = decoded.ops[0] as Extract<GrcOp, { type: 'createEntity' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'createEntity' }>;
expect(op.values[0]?.value.type).toBe('time');
if (op.values[0]?.value.type === 'time') {
expect(op.values[0].value.value).toBe('14:30:00Z');
Expand Down Expand Up @@ -294,7 +294,7 @@ describe('GRC-20 v2 Encoding', () => {
const binary = encodeEdit(edit);
const decoded = decodeEdit(binary);

const op = decoded.ops[0] as Extract<GrcOp, { type: 'createEntity' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'createEntity' }>;
expect(op.values[0]?.value.type).toBe('datetime');
if (op.values[0]?.value.type === 'datetime') {
expect(op.values[0].value.value).toBe('2024-01-15T14:30:00Z');
Expand Down Expand Up @@ -332,7 +332,7 @@ describe('GRC-20 v2 Encoding', () => {
const binary = encodeEdit(edit);
const decoded = decodeEdit(binary);

const op = decoded.ops[0] as Extract<GrcOp, { type: 'createEntity' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'createEntity' }>;
expect(op.values[0]?.value.type).toBe('schedule');
if (op.values[0]?.value.type === 'schedule') {
expect(op.values[0].value.value).toBe('FREQ=WEEKLY;BYDAY=MO,WE,FR');
Expand Down Expand Up @@ -375,7 +375,7 @@ describe('GRC-20 v2 Encoding', () => {
expect(decoded.ops.length).toBe(1);
expect(decoded.ops[0]?.type).toBe('createRelation');

const op = decoded.ops[0] as Extract<GrcOp, { type: 'createRelation' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'createRelation' }>;
expect(formatId(op.id)).toBe('765564cac7e54c61b1dcc28ab77ec6b7');
expect(formatId(op.relationType)).toBe('cf518eafef744aadbc87fe09c2631fcd');
expect(formatId(op.from)).toBe('3af3e22d21694a078681516710b7ecf1');
Expand Down Expand Up @@ -414,7 +414,7 @@ describe('GRC-20 v2 Encoding', () => {
const binary = encodeEdit(edit);
const decoded = decodeEdit(binary);

const op = decoded.ops[0] as Extract<GrcOp, { type: 'createRelation' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'createRelation' }>;
expect(op.fromSpace).toBeDefined();
expect(op.toSpace).toBeDefined();
if (op.fromSpace) expect(formatId(op.fromSpace)).toBe('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
Expand Down Expand Up @@ -445,7 +445,7 @@ describe('GRC-20 v2 Encoding', () => {
expect(decoded.ops.length).toBe(1);
expect(decoded.ops[0]?.type).toBe('deleteRelation');

const op = decoded.ops[0] as Extract<GrcOp, { type: 'deleteRelation' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'deleteRelation' }>;
expect(formatId(op.id)).toBe('765564cac7e54c61b1dcc28ab77ec6b7');
});

Expand Down Expand Up @@ -475,7 +475,7 @@ describe('GRC-20 v2 Encoding', () => {
expect(decoded.ops.length).toBe(1);
expect(decoded.ops[0]?.type).toBe('updateRelation');

const op = decoded.ops[0] as Extract<GrcOp, { type: 'updateRelation' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'updateRelation' }>;
expect(formatId(op.id)).toBe('765564cac7e54c61b1dcc28ab77ec6b7');
expect(op.position).toBe('new-position');
});
Expand All @@ -502,7 +502,7 @@ describe('GRC-20 v2 Encoding', () => {
const binary = encodeEdit(edit);
const decoded = decodeEdit(binary);

const op = decoded.ops[0] as Extract<GrcOp, { type: 'updateRelation' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'updateRelation' }>;
expect(op.unset).toContain('fromSpace');
expect(op.unset).toContain('toSpace');
expect(op.unset).toContain('position');
Expand Down Expand Up @@ -551,7 +551,7 @@ describe('GRC-20 v2 Encoding', () => {
expect(decoded.ops.length).toBe(1);
expect(decoded.ops[0]?.type).toBe('updateEntity');

const op = decoded.ops[0] as Extract<GrcOp, { type: 'updateEntity' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'updateEntity' }>;
expect(formatId(op.id)).toBe('3af3e22d21694a078681516710b7ecf1');
expect(op.set.length).toBe(1);
expect(op.unset.length).toBe(1);
Expand Down Expand Up @@ -581,7 +581,7 @@ describe('GRC-20 v2 Encoding', () => {
expect(decoded.ops.length).toBe(1);
expect(decoded.ops[0]?.type).toBe('deleteEntity');

const op = decoded.ops[0] as Extract<GrcOp, { type: 'deleteEntity' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'deleteEntity' }>;
expect(formatId(op.id)).toBe('3af3e22d21694a078681516710b7ecf1');
});

Expand Down Expand Up @@ -609,7 +609,7 @@ describe('GRC-20 v2 Encoding', () => {
expect(decoded.ops.length).toBe(1);
expect(decoded.ops[0]?.type).toBe('restoreEntity');

const op = decoded.ops[0] as Extract<GrcOp, { type: 'restoreEntity' }>;
const op = decoded.ops[0] as Extract<Op, { type: 'restoreEntity' }>;
expect(formatId(op.id)).toBe('3af3e22d21694a078681516710b7ecf1');
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/graph/create-entity.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
type Op as GrcOp,
type PropertyValue as GrcPropertyValue,
createEntity as grcCreateEntity,
createRelation as grcCreateRelation,
languages,
type Op,
} from '@geoprotocol/grc-20';
import { COVER_PROPERTY, DESCRIPTION_PROPERTY, NAME_PROPERTY, TYPES_PROPERTY } from '../core/ids/system.js';
import { Id } from '../id.js';
Expand Down Expand Up @@ -114,7 +114,7 @@ export const createEntity = ({
}

const id = providedId ?? generate();
let ops: Array<GrcOp> = [];
let ops: Array<Op> = [];

const newValues: Array<GrcPropertyValue> = [];
if (name) {
Expand Down
4 changes: 2 additions & 2 deletions src/graph/create-property.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Op as GrcOp, createRelation as grcCreateRelation } from '@geoprotocol/grc-20';
import { createRelation as grcCreateRelation, type Op } from '@geoprotocol/grc-20';
import {
BOOLEAN,
BYTES,
Expand Down Expand Up @@ -75,7 +75,7 @@ export const createProperty = (params: CreatePropertyParams): CreateResult => {
}
const entityId = id ?? generate();

const ops: Array<GrcOp> = [];
const ops: Array<Op> = [];

// Create the property entity
const { ops: entityOps } = createEntity({
Expand Down
6 changes: 3 additions & 3 deletions src/graph/create-relation.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { CreateEntity, CreateRelation, Op as GrcOp } from '@geoprotocol/grc-20';
import type { CreateEntity, CreateRelation, Op } from '@geoprotocol/grc-20';
import { describe, expect, it } from 'vitest';
import { CLAIM_TYPE, NEWS_STORY_TYPE } from '../core/ids/content.js';
import { COVER_PROPERTY, DESCRIPTION_PROPERTY, NAME_PROPERTY, TYPES_PROPERTY } from '../core/ids/system.js';
import { Id } from '../id.js';
import { toGrcId } from '../id-utils.js';
import { createRelation } from './create-relation.js';

const isCreateRelationOp = (op: GrcOp): op is CreateRelation => {
const isCreateRelationOp = (op: Op): op is CreateRelation => {
return op.type === 'createRelation';
};

const isCreateEntityOp = (op: GrcOp): op is CreateEntity => {
const isCreateEntityOp = (op: Op): op is CreateEntity => {
return op.type === 'createEntity';
};

Expand Down
4 changes: 2 additions & 2 deletions src/graph/create-relation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Op as GrcOp, createRelation as grcCreateRelation } from '@geoprotocol/grc-20';
import { createRelation as grcCreateRelation, type Op } from '@geoprotocol/grc-20';
import { Id } from '../id.js';
import { assertValid, generate, toGrcId } from '../id-utils.js';
import type { CreateResult, RelationParams } from '../types.js';
Expand Down Expand Up @@ -91,7 +91,7 @@ export const createRelation = ({
const id = providedId ?? generate();
const entityId = providedEntityId ?? generate();

const ops: Array<GrcOp> = [];
const ops: Array<Op> = [];

ops.push(
grcCreateRelation({
Expand Down
6 changes: 3 additions & 3 deletions src/graph/create-space.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Op as GrcOp } from '@geoprotocol/grc-20';
import type { Op } from '@geoprotocol/grc-20';
import { IdUtils } from '../../index.js';
import { Id } from '../id.js';
import { getApiOrigin, type Network } from './constants.js';
Expand All @@ -7,7 +7,7 @@ type CreateSpaceParams = {
editorAddress: string;
name: string;
network?: Network;
ops?: GrcOp[];
ops?: Op[];
spaceEntityId?: string;

/**
Expand All @@ -19,7 +19,7 @@ type CreateSpaceParams = {

type BaseDeployParams = {
spaceName: string;
ops?: GrcOp[];
ops?: Op[];
spaceEntityId?: string;
};

Expand Down
6 changes: 3 additions & 3 deletions src/graph/create-type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Op as GrcOp, createRelation as grcCreateRelation } from '@geoprotocol/grc-20';
import { createRelation as grcCreateRelation, type Op } from '@geoprotocol/grc-20';
import { PROPERTIES, SCHEMA_TYPE, TYPES_PROPERTY } from '../core/ids/system.js';
import { Id } from '../id.js';
import { assertValid, generate, toGrcId } from '../id-utils.js';
Expand Down Expand Up @@ -48,7 +48,7 @@ export const createType = ({

// set property "Types" to "Type"
assertValid(id);
(ops as GrcOp[]).push(
(ops as Op[]).push(
grcCreateRelation({
id: toGrcId(generate()),
entity: toGrcId(generate()),
Expand All @@ -62,7 +62,7 @@ export const createType = ({
for (const propertyId of properties) {
assertValid(propertyId, '`propertyId` in `createType`');
// Set Properties on the Type
(ops as GrcOp[]).push(
(ops as Op[]).push(
grcCreateRelation({
id: toGrcId(generate()),
entity: toGrcId(generate()),
Expand Down
Loading
Loading