diff --git a/docs/core/concepts/normalization.md b/docs/core/concepts/normalization.md index f534213f1c2c..a612e50f4ea5 100644 --- a/docs/core/concepts/normalization.md +++ b/docs/core/concepts/normalization.md @@ -29,10 +29,6 @@ class Todo extends Entity { readonly userId: number = 0; readonly title: string = ''; readonly completed: boolean = false; - - pk() { - return `${this.id}`; - } } ``` @@ -40,9 +36,6 @@ class Todo extends Entity { import { Entity } from '@data-client/endpoint'; class Todo extends Entity { - pk() { - return `${this.id}`; - } } ``` diff --git a/docs/core/guides/ssr.md b/docs/core/guides/ssr.md index 2b47bb96a4f9..5c51b13d4022 100644 --- a/docs/core/guides/ssr.md +++ b/docs/core/guides/ssr.md @@ -94,10 +94,6 @@ class User extends Entity { id = ''; username = ''; - pk() { - return this.id; - } - // highlight-next-line static key = 'User'; } diff --git a/examples/coin-app/src/resources/Currency.ts b/examples/coin-app/src/resources/Currency.ts index f1d8666aa148..344751293d14 100644 --- a/examples/coin-app/src/resources/Currency.ts +++ b/examples/coin-app/src/resources/Currency.ts @@ -36,10 +36,6 @@ export class Currency extends Entity { return iconTable[this.id]?.img_url; } - pk(): string { - return this.id; - } - static key = 'Currency'; static process( diff --git a/examples/coin-app/src/resources/Product.ts b/examples/coin-app/src/resources/Product.ts index c12c5707d2ac..f130a7534f79 100644 --- a/examples/coin-app/src/resources/Product.ts +++ b/examples/coin-app/src/resources/Product.ts @@ -11,10 +11,6 @@ export class Product extends Entity { trading_disabled = false; stats = Stats.fromJS(); - pk(): string { - return this.id; - } - static key = 'Product'; static schema = { stats: Stats, diff --git a/examples/github-app/src/resources/Base.ts b/examples/github-app/src/resources/Base.ts index 01391650feb0..7fb3bbfd13a8 100644 --- a/examples/github-app/src/resources/Base.ts +++ b/examples/github-app/src/resources/Base.ts @@ -24,10 +24,6 @@ const HOST = 'https://api.github.com'; export class GithubEntity extends Entity { readonly id: number = -1; - - pk() { - return this.id?.toString(); - } } export const GithubGqlEndpoint = new GQLEndpoint( diff --git a/examples/github-app/src/resources/Label.tsx b/examples/github-app/src/resources/Label.tsx index a9e0378a3e41..81c52150503c 100644 --- a/examples/github-app/src/resources/Label.tsx +++ b/examples/github-app/src/resources/Label.tsx @@ -7,10 +7,6 @@ export class Label extends GithubEntity { readonly description: string = ''; readonly color: string = '000000'; readonly default: boolean = false; - - pk() { - return this.id?.toString(); - } } export const LabelResource = githubResource({ path: '/repos/:owner/:repo/labels/:name', diff --git a/examples/github-app/src/resources/Push.ts b/examples/github-app/src/resources/Push.ts index 30715dbf2922..3900ae97091f 100644 --- a/examples/github-app/src/resources/Push.ts +++ b/examples/github-app/src/resources/Push.ts @@ -10,7 +10,7 @@ export class Push extends GithubEntity { commits: Commit[] = []; pk() { - return `${this.pushId}`; + return this.pushId; } } diff --git a/examples/github-app/src/resources/Reaction.tsx b/examples/github-app/src/resources/Reaction.tsx index 58e5681f4a1c..f743af24679f 100644 --- a/examples/github-app/src/resources/Reaction.tsx +++ b/examples/github-app/src/resources/Reaction.tsx @@ -14,10 +14,6 @@ export class Reaction extends GithubEntity { return contentToIcon[this.content]; } - pk() { - return this.id?.toString(); - } - static schema = { user: User, createdAt: Temporal.Instant.from, diff --git a/examples/nextjs/resources/PlaceholderBaseResource.ts b/examples/nextjs/resources/PlaceholderBaseResource.ts index 9ad4d5fa4aba..21c92cf4c5ce 100644 --- a/examples/nextjs/resources/PlaceholderBaseResource.ts +++ b/examples/nextjs/resources/PlaceholderBaseResource.ts @@ -7,12 +7,8 @@ import { } from '@data-client/rest'; export abstract class PlaceholderEntity extends Entity { - id = 0; - // all Resources of `jsonplaceholder` use an id for the primary key - pk() { - return `${this.id}`; - } + id = 0; } /** Common patterns in the https://jsonplaceholder.typicode.com API */ diff --git a/examples/normalizr-github/schema.js b/examples/normalizr-github/schema.js index e357317ba247..cfd19253f5b3 100644 --- a/examples/normalizr-github/schema.js +++ b/examples/normalizr-github/schema.js @@ -1,16 +1,8 @@ import { schema, Entity } from '@data-client/endpoint'; -class BaseEntity extends Entity { - id = 0; +export class User extends Entity {} - pk() { - return this.id; - } -} - -export class User extends BaseEntity {} - -export class Commit extends BaseEntity { +export class Commit extends Entity { sha = ''; static schema = { @@ -23,15 +15,15 @@ export class Commit extends BaseEntity { } } -export class Label extends BaseEntity {} +export class Label extends Entity {} -export class Milestone extends BaseEntity { +export class Milestone extends Entity { static schema = { creator: User, }; } -export class Issue extends BaseEntity { +export class Issue extends Entity { static schema = { assignee: User, assignees: [User], @@ -41,7 +33,7 @@ export class Issue extends BaseEntity { }; } -export class PullRequest extends BaseEntity { +export class PullRequest extends Entity { static schema = { assignee: User, assignees: [User], diff --git a/examples/normalizr-redux/src/api/schema.js b/examples/normalizr-redux/src/api/schema.js index db1dd9994d76..cfd19253f5b3 100644 --- a/examples/normalizr-redux/src/api/schema.js +++ b/examples/normalizr-redux/src/api/schema.js @@ -1,16 +1,8 @@ import { schema, Entity } from '@data-client/endpoint'; -class BaseEntity extends Entity { - id = 0; +export class User extends Entity {} - pk() { - return `${this.id}`; - } -} - -export class User extends BaseEntity {} - -export class Commit extends BaseEntity { +export class Commit extends Entity { sha = ''; static schema = { @@ -23,15 +15,15 @@ export class Commit extends BaseEntity { } } -export class Label extends BaseEntity {} +export class Label extends Entity {} -export class Milestone extends BaseEntity { +export class Milestone extends Entity { static schema = { creator: User, }; } -export class Issue extends BaseEntity { +export class Issue extends Entity { static schema = { assignee: User, assignees: [User], @@ -41,7 +33,7 @@ export class Issue extends BaseEntity { }; } -export class PullRequest extends BaseEntity { +export class PullRequest extends Entity { static schema = { assignee: User, assignees: [User], diff --git a/examples/normalizr-relationships/schema.js b/examples/normalizr-relationships/schema.js index cdc516f44ff6..8ff6612b0776 100644 --- a/examples/normalizr-relationships/schema.js +++ b/examples/normalizr-relationships/schema.js @@ -1,14 +1,6 @@ import { Entity } from '@data-client/endpoint'; -class BaseEntity extends Entity { - id = 0; - - pk() { - return this.id; - } -} - -class User extends BaseEntity { +class User extends Entity { static process(value, parent, key) { switch (key) { case 'author': @@ -29,7 +21,7 @@ class User extends BaseEntity { }; } } -class Comment extends BaseEntity { +class Comment extends Entity { static schema = { commenter: User, }; @@ -39,7 +31,7 @@ class Comment extends BaseEntity { } } -class Post extends BaseEntity { +class Post extends Entity { static schema = { author: User, comments: [Comment], diff --git a/examples/todo-app/src/resources/PlaceholderBaseResource.ts b/examples/todo-app/src/resources/PlaceholderBaseResource.ts index f07a982b0984..7820acd1b51e 100644 --- a/examples/todo-app/src/resources/PlaceholderBaseResource.ts +++ b/examples/todo-app/src/resources/PlaceholderBaseResource.ts @@ -8,12 +8,8 @@ import { import { v4 as uuid } from 'uuid'; export abstract class PlaceholderEntity extends Entity { - id = 0; - // all Resources of `jsonplaceholder` use an id for the primary key - pk() { - return `${this.id}`; - } + id = 0; } /** Common patterns in the https://jsonplaceholder.typicode.com API */ diff --git a/website/src/fixtures/posts-collection.ts b/website/src/fixtures/posts-collection.ts index c53ff9bb4aef..026f43a063d7 100644 --- a/website/src/fixtures/posts-collection.ts +++ b/website/src/fixtures/posts-collection.ts @@ -6,10 +6,6 @@ class Post extends Entity { title = ''; group = ''; author = ''; - - pk() { - return this.id; - } } export const getPosts = new RestEndpoint({ path: '/:group/posts', diff --git a/website/src/fixtures/profiles.ts b/website/src/fixtures/profiles.ts index ddafc0150dcb..377ffb07148b 100644 --- a/website/src/fixtures/profiles.ts +++ b/website/src/fixtures/profiles.ts @@ -1,4 +1,4 @@ -import { Entity, resource, RestEndpoint } from '@data-client/rest'; +import { Entity, resource } from '@data-client/rest'; export class Profile extends Entity { id: number | undefined = undefined; @@ -6,10 +6,6 @@ export class Profile extends Entity { fullName = ''; bio = ''; - pk() { - return this.id?.toString(); - } - static key = 'Profile'; }