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
7 changes: 7 additions & 0 deletions .changeset/bitter-dancers-lead.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@graphprotocol/hypergraph-react": minor
"@graphprotocol/hypergraph": minor
---

rename Type.Text to Type.String

6 changes: 3 additions & 3 deletions apps/create-hypergraph/template-nextjs/app/schema.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Entity, Type } from '@graphprotocol/hypergraph';

export class Address extends Entity.Class<Address>('Address')({
name: Type.Text,
description: Type.Text,
name: Type.String,
description: Type.String,
}) {}

export class Project extends Entity.Class<Project>('Project')({
name: Type.Text,
name: Type.String,
}) {}
6 changes: 3 additions & 3 deletions apps/create-hypergraph/template-vite-react/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Entity, Type } from '@graphprotocol/hypergraph';

export class Address extends Entity.Class<Address>('Address')({
name: Type.Text,
description: Type.Text,
name: Type.String,
description: Type.String,
}) {}

export class Project extends Entity.Class<Project>('Project')({
name: Type.Text,
name: Type.String,
}) {}
18 changes: 9 additions & 9 deletions apps/events/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import { Entity, Type } from '@graphprotocol/hypergraph';

export class User extends Entity.Class<User>('User')({
name: Type.Text,
name: Type.String,
}) {}

export class Todo extends Entity.Class<Todo>('Todo')({
name: Type.Text,
name: Type.String,
completed: Type.Boolean,
assignees: Type.Relation(User),
}) {}

export class Todo2 extends Entity.Class<Todo2>('Todo2')({
name: Type.Text,
name: Type.String,
checked: Type.Boolean,
assignees: Type.Relation(User),
due: Type.Date,
amount: Type.Number,
point: Type.Point,
website: Type.Text,
website: Type.String,
}) {}

export class JobOffer extends Entity.Class<JobOffer>('JobOffer')({
name: Type.Text,
name: Type.String,
salary: Type.Number,
}) {}

export class Company extends Entity.Class<Company>('Company')({
name: Type.Text,
// address: Type.Text,
name: Type.String,
// address: Type.String,
jobOffers: Type.Relation(JobOffer),
}) {}

export class Event extends Entity.Class<Event>('Event')({
name: Type.Text,
description: Type.optional(Type.Text),
name: Type.String,
description: Type.optional(Type.String),
sponsors: Type.Relation(Company),
}) {}
8 changes: 4 additions & 4 deletions docs/docs/filtering-query-results.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Note: Filtering is not yet supported for public data.

```tsx
export class Event extends Entity.Class<Event>("Event")({
name: Type.Text,
name: Type.String,
cancelled: Type.Boolean,
}) {}

Expand All @@ -29,7 +29,7 @@ The filter API supports different filters for different property types and offer
exists: true/false, // filter by existence of the property
}

// text filter
// string filter
{
is: "text", // exact match
contains: "text",
Expand Down Expand Up @@ -131,7 +131,7 @@ const { data } = useQuery(Person, {
```tsx
// schema
export class Todo extends Entity.Class<Todo2>('Todo')({
name: Type.Text,
name: Type.String,
checked: Type.Boolean,
assignees: Type.Relation(User),
})
Expand Down Expand Up @@ -174,7 +174,7 @@ const { data } = useQuery(Person, {
```tsx
// schema
export class Todo extends Entity.Class<Todo2>('Todo')({
name: Type.Text,
name: Type.String,
checked: Type.Boolean,
assignees: Type.Relation(User, {
entity: {
Expand Down
18 changes: 9 additions & 9 deletions docs/docs/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Here is an example of a schema for an Event app with the properties `name` and `
import { Entity, Type } from '@graphprotocol/hypergraph';

export class Event extends Entity.Class<Event>('Event')({
name: Type.Text,
description: Type.Text,
name: Type.String,
description: Type.String,
}) {}
```

Expand All @@ -23,19 +23,19 @@ In order to define relations between Types, you can use the `Type.Relation` type
import { Entity, Type } from '@graphprotocol/hypergraph';

export class Company extends Entity.Class<Company>('Company')({
name: Type.Text,
name: Type.String,
}) {}

export class Event extends Entity.Class<Event>('Event')({
name: Type.Text,
description: Type.Text,
name: Type.String,
description: Type.String,
sponsors: Type.Relation(Company),
}) {}
```

## Available Types

- `Type.Text` (string)
- `Type.String` (string)
- `Type.Number` (number)
- `Type.Date` (date)
- `Type.Boolean` (boolean)
Expand All @@ -48,7 +48,7 @@ Example:
import { Entity, Type } from '@graphprotocol/hypergraph';

export class Company extends Entity.Class<Company>('Company')({
name: Type.Text,
name: Type.String,
employees: Type.Number,
founded: Type.Date,
active: Type.Boolean,
Expand All @@ -64,8 +64,8 @@ You can make a field optional by wrapping it in `Type.optional`.
import { Entity, Type } from '@graphprotocol/hypergraph';

export class Company extends Entity.Class<Company>('Company')({
name: Type.Text,
description: Type.optional(Type.Text),
name: Type.String,
description: Type.optional(Type.String),
founded: Type.optional(Type.Date),
}) {}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ afterEach(() => {

describe('HypergraphSpaceContext', () => {
class Person extends Entity.Class<Person>('Person')({
name: Type.Text,
name: Type.String,
age: Type.Number,
}) {}

class User extends Entity.Class<User>('User')({
name: Type.Text,
email: Type.Text,
name: Type.String,
email: Type.String,
}) {}

class Event extends Entity.Class<Event>('Event')({
name: Type.Text,
name: Type.String,
}) {}

const spaceId = '1e5e39da-a00d-4fd8-b53b-98095337112f';
Expand Down
10 changes: 5 additions & 5 deletions packages/hypergraph-react/test/prepare-publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ afterEach(() => {
describe('preparePublish', () => {
// Test entity classes
class Person extends Entity.Class<Person>('Person')({
name: Type.Text,
name: Type.String,
age: Type.Number,
email: Type.optional(Type.Text),
email: Type.optional(Type.String),
isActive: Type.Boolean,
birthDate: Type.Date,
location: Type.Point,
}) {}

class Company extends Entity.Class<Company>('Company')({
name: Type.Text,
name: Type.String,
employees: Type.Relation(Person),
}) {}

// Entity class for testing optional types
class OptionalFieldsEntity extends Entity.Class<OptionalFieldsEntity>('OptionalFieldsEntity')({
name: Type.Text, // required field
name: Type.String, // required field
optionalNumber: Type.optional(Type.Number),
optionalBoolean: Type.optional(Type.Boolean),
optionalDate: Type.optional(Type.Date),
Expand Down Expand Up @@ -323,7 +323,7 @@ describe('preparePublish', () => {

it('should throw error when mapping entry is not found', async () => {
class UnmappedEntity extends Entity.Class<UnmappedEntity>('UnmappedEntity')({
name: Type.Text,
name: Type.String,
}) {}

const entity = {
Expand Down
8 changes: 4 additions & 4 deletions packages/hypergraph/src/entity/findMany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
EntityFieldFilter,
EntityFilter,
EntityNumberFilter,
EntityTextFilter,
EntityStringFilter,
} from './types.js';

const documentChangeListener: {
Expand Down Expand Up @@ -298,19 +298,19 @@ export function findMany<const S extends AnyNoContext>(

if (typeof fieldValue === 'string') {
if ('startsWith' in fieldFilter) {
const textFilter = fieldFilter as EntityTextFilter;
const textFilter = fieldFilter as EntityStringFilter;
if (textFilter.startsWith !== undefined && !fieldValue.startsWith(textFilter.startsWith)) {
return false;
}
}
if ('endsWith' in fieldFilter) {
const textFilter = fieldFilter as EntityTextFilter;
const textFilter = fieldFilter as EntityStringFilter;
if (textFilter.endsWith !== undefined && !fieldValue.endsWith(textFilter.endsWith)) {
return false;
}
}
if ('contains' in fieldFilter) {
const textFilter = fieldFilter as EntityTextFilter;
const textFilter = fieldFilter as EntityStringFilter;
if (textFilter.contains !== undefined && !fieldValue.includes(textFilter.contains)) {
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/hypergraph/src/entity/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ export type EntityNumberFilter = {
or?: EntityNumberFilter[];
};

export type EntityTextFilter = {
export type EntityStringFilter = {
is?: string;
startsWith?: string;
endsWith?: string;
contains?: string;
equals?: string;
not?: EntityTextFilter;
or?: EntityTextFilter[];
not?: EntityStringFilter;
or?: EntityStringFilter[];
};

export type CrossFieldFilter<T> = {
Expand Down
6 changes: 3 additions & 3 deletions packages/hypergraph/src/mapping/Mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export type SchemaDataTypeRelation = typeof SchemaDataTypeRelation.Type;
/**
* @since 0.2.0
*/
export const SchemaDataTypePrimitive = EffectSchema.Literal('Text', 'Number', 'Boolean', 'Date', 'Point');
export const SchemaDataTypePrimitive = EffectSchema.Literal('String', 'Number', 'Boolean', 'Date', 'Point');
/**
* @since 0.2.0
*/
Expand Down Expand Up @@ -195,7 +195,7 @@ export const Schema = EffectSchema.Struct({
{
name: 'Account',
knowledgeGraphId: null,
properties: [{ name: 'username', knowledgeGraphId: null, dataType: 'Text' }],
properties: [{ name: 'username', knowledgeGraphId: null, dataType: 'String' }],
},
],
},
Expand All @@ -204,7 +204,7 @@ export const Schema = EffectSchema.Struct({
{
name: 'Account',
knowledgeGraphId: 'a5fd07b1-120f-46c6-b46f-387ef98396a6',
properties: [{ name: 'name', knowledgeGraphId: 'a126ca53-0c8e-48d5-b888-82c734c38935', dataType: 'Text' }],
properties: [{ name: 'name', knowledgeGraphId: 'a126ca53-0c8e-48d5-b888-82c734c38935', dataType: 'String' }],
},
],
},
Expand Down
4 changes: 2 additions & 2 deletions packages/hypergraph/src/type-utils/type-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import * as Type from '../type/type.js';
// biome-ignore lint/suspicious/noExplicitAny: TODO
export const isStringOrOptionalStringType = (type: any) => {
if (type.ast && type.ast._tag === 'PropertySignatureDeclaration' && type.ast.isOptional) {
return type.from === Type.Text;
return type.from === Type.String;
}
return type === Type.Text;
return type === Type.String;
};

// biome-ignore lint/suspicious/noExplicitAny: TODO
Expand Down
3 changes: 2 additions & 1 deletion packages/hypergraph/src/type/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as Schema from 'effect/Schema';
import { Field } from '../entity/entity.js';
import type { AnyNoContext, EntityWithRelation } from '../entity/types.js';

export const Text = Schema.String;
// biome-ignore lint/suspicious/noShadowRestrictedNames: is part of a namespaces module and therefor ok
export const String = Schema.String;
// biome-ignore lint/suspicious/noShadowRestrictedNames: is part of a namespaces module and therefor ok
export const Number = Schema.Number;
// biome-ignore lint/suspicious/noShadowRestrictedNames: is part of a namespaces module and therefor ok
Expand Down
10 changes: 5 additions & 5 deletions packages/hypergraph/test/entity/entity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ import { idToAutomergeId } from '../../src/utils/automergeId.js';

describe('Entity', () => {
class Person extends Entity.Class<Person>('Person')({
name: Type.Text,
name: Type.String,
age: Type.Number,
}) {}

class User extends Entity.Class<User>('User')({
name: Type.Text,
email: Type.Text,
name: Type.String,
email: Type.String,
}) {}

class Badge extends Entity.Class<Badge>('Badge')({
name: Type.Text,
name: Type.String,
}) {}

class Event extends Entity.Class<Event>('Event')({
name: Type.Text,
name: Type.String,
}) {}

const spaceId = '1e5e39da-a00d-4fd8-b53b-98095337112f';
Expand Down
8 changes: 4 additions & 4 deletions packages/hypergraph/test/entity/findMany.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { idToAutomergeId } from '../../src/utils/automergeId.js';
describe('findMany with filters', () => {
// Define entity classes for testing
class Person extends Entity.Class<Person>('Person')({
name: Type.Text,
name: Type.String,
age: Type.Number,
isActive: Type.Boolean,
}) {}

class Product extends Entity.Class<Product>('Product')({
name: Type.Text,
name: Type.String,
price: Type.Number,
category: Type.Text,
category: Type.String,
}) {}

const spaceId = '1e5e39da-a00d-4fd8-b53b-98095337112f';
Expand All @@ -34,7 +34,7 @@ describe('findMany with filters', () => {
handle.doneLoading();
});

describe('Text filters', () => {
describe('String filters', () => {
it('should filter entities by exact text match', () => {
// Create test entities
Entity.create(handle, Person)({ name: 'John', age: 30, isActive: true });
Expand Down
Loading
Loading