Skip to content

Commit 87a65ba

Browse files
committed
docs: Remove unneeded id pk from examples
1 parent 9ebc6cd commit 87a65ba

File tree

17 files changed

+62
-176
lines changed

17 files changed

+62
-176
lines changed

.changeset/fast-jars-run.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@data-client/endpoint': patch
3+
'@data-client/rest': patch
4+
'@data-client/graphql': patch
5+
---
6+
7+
Fix Entity types for TS 4.0 and below

docs/core/concepts/normalization.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,13 @@ class Todo extends Entity {
2929
readonly userId: number = 0;
3030
readonly title: string = '';
3131
readonly completed: boolean = false;
32-
33-
pk() {
34-
return `${this.id}`;
35-
}
3632
}
3733
```
3834
3935
```js
4036
import { Entity } from '@data-client/endpoint';
4137
4238
class Todo extends Entity {
43-
pk() {
44-
return `${this.id}`;
45-
}
4639
}
4740
```
4841

docs/core/guides/ssr.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ class User extends Entity {
9494
id = '';
9595
username = '';
9696

97-
pk() {
98-
return this.id;
99-
}
100-
10197
// highlight-next-line
10298
static key = 'User';
10399
}

examples/coin-app/src/resources/Currency.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ export class Currency extends Entity {
3636
return iconTable[this.id]?.img_url;
3737
}
3838

39-
pk(): string {
40-
return this.id;
41-
}
42-
4339
static key = 'Currency';
4440

4541
static process(

examples/coin-app/src/resources/Product.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ export class Product extends Entity {
1111
trading_disabled = false;
1212
stats = Stats.fromJS();
1313

14-
pk(): string {
15-
return this.id;
16-
}
17-
1814
static key = 'Product';
1915
static schema = {
2016
stats: Stats,

examples/github-app/src/resources/Base.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ const HOST = 'https://api.github.com';
2424

2525
export class GithubEntity extends Entity {
2626
readonly id: number = -1;
27-
28-
pk() {
29-
return this.id?.toString();
30-
}
3127
}
3228

3329
export const GithubGqlEndpoint = new GQLEndpoint(

examples/github-app/src/resources/Label.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ export class Label extends GithubEntity {
77
readonly description: string = '';
88
readonly color: string = '000000';
99
readonly default: boolean = false;
10-
11-
pk() {
12-
return this.id?.toString();
13-
}
1410
}
1511
export const LabelResource = githubResource({
1612
path: '/repos/:owner/:repo/labels/:name',

examples/github-app/src/resources/Push.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class Push extends GithubEntity {
1010
commits: Commit[] = [];
1111

1212
pk() {
13-
return `${this.pushId}`;
13+
return this.pushId;
1414
}
1515
}
1616

examples/github-app/src/resources/Reaction.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ export class Reaction extends GithubEntity {
1414
return contentToIcon[this.content];
1515
}
1616

17-
pk() {
18-
return this.id?.toString();
19-
}
20-
2117
static schema = {
2218
user: User,
2319
createdAt: Temporal.Instant.from,

examples/nextjs/resources/PlaceholderBaseResource.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ import {
77
} from '@data-client/rest';
88

99
export abstract class PlaceholderEntity extends Entity {
10-
id = 0;
11-
1210
// all Resources of `jsonplaceholder` use an id for the primary key
13-
pk() {
14-
return `${this.id}`;
15-
}
11+
id = 0;
1612
}
1713

1814
/** Common patterns in the https://jsonplaceholder.typicode.com API */

examples/normalizr-github/schema.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
import { schema, Entity } from '@data-client/endpoint';
22

3-
class BaseEntity extends Entity {
4-
id = 0;
3+
export class User extends Entity {}
54

6-
pk() {
7-
return this.id;
8-
}
9-
}
10-
11-
export class User extends BaseEntity {}
12-
13-
export class Commit extends BaseEntity {
5+
export class Commit extends Entity {
146
sha = '';
157

168
static schema = {
@@ -23,15 +15,15 @@ export class Commit extends BaseEntity {
2315
}
2416
}
2517

26-
export class Label extends BaseEntity {}
18+
export class Label extends Entity {}
2719

28-
export class Milestone extends BaseEntity {
20+
export class Milestone extends Entity {
2921
static schema = {
3022
creator: User,
3123
};
3224
}
3325

34-
export class Issue extends BaseEntity {
26+
export class Issue extends Entity {
3527
static schema = {
3628
assignee: User,
3729
assignees: [User],
@@ -41,7 +33,7 @@ export class Issue extends BaseEntity {
4133
};
4234
}
4335

44-
export class PullRequest extends BaseEntity {
36+
export class PullRequest extends Entity {
4537
static schema = {
4638
assignee: User,
4739
assignees: [User],

examples/normalizr-redux/src/api/schema.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
import { schema, Entity } from '@data-client/endpoint';
22

3-
class BaseEntity extends Entity {
4-
id = 0;
3+
export class User extends Entity {}
54

6-
pk() {
7-
return `${this.id}`;
8-
}
9-
}
10-
11-
export class User extends BaseEntity {}
12-
13-
export class Commit extends BaseEntity {
5+
export class Commit extends Entity {
146
sha = '';
157

168
static schema = {
@@ -23,15 +15,15 @@ export class Commit extends BaseEntity {
2315
}
2416
}
2517

26-
export class Label extends BaseEntity {}
18+
export class Label extends Entity {}
2719

28-
export class Milestone extends BaseEntity {
20+
export class Milestone extends Entity {
2921
static schema = {
3022
creator: User,
3123
};
3224
}
3325

34-
export class Issue extends BaseEntity {
26+
export class Issue extends Entity {
3527
static schema = {
3628
assignee: User,
3729
assignees: [User],
@@ -41,7 +33,7 @@ export class Issue extends BaseEntity {
4133
};
4234
}
4335

44-
export class PullRequest extends BaseEntity {
36+
export class PullRequest extends Entity {
4537
static schema = {
4638
assignee: User,
4739
assignees: [User],

examples/normalizr-relationships/schema.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import { Entity } from '@data-client/endpoint';
22

3-
class BaseEntity extends Entity {
4-
id = 0;
5-
6-
pk() {
7-
return this.id;
8-
}
9-
}
10-
11-
class User extends BaseEntity {
3+
class User extends Entity {
124
static process(value, parent, key) {
135
switch (key) {
146
case 'author':
@@ -29,7 +21,7 @@ class User extends BaseEntity {
2921
};
3022
}
3123
}
32-
class Comment extends BaseEntity {
24+
class Comment extends Entity {
3325
static schema = {
3426
commenter: User,
3527
};
@@ -39,7 +31,7 @@ class Comment extends BaseEntity {
3931
}
4032
}
4133

42-
class Post extends BaseEntity {
34+
class Post extends Entity {
4335
static schema = {
4436
author: User,
4537
comments: [Comment],

examples/todo-app/src/resources/PlaceholderBaseResource.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ import {
88
import { v4 as uuid } from 'uuid';
99

1010
export abstract class PlaceholderEntity extends Entity {
11-
id = 0;
12-
1311
// all Resources of `jsonplaceholder` use an id for the primary key
14-
pk() {
15-
return `${this.id}`;
16-
}
12+
id = 0;
1713
}
1814

1915
/** Common patterns in the https://jsonplaceholder.typicode.com API */
Lines changed: 36 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,45 @@
11
// we just removed instances of 'abstract new'
22
import { AbstractInstanceType } from '../normal.js';
3-
declare const Entity_base: import('./EntitySchema.js').IEntityClass<
4-
new (...args: any[]) => {
5-
pk(
6-
parent?: any,
7-
key?: string | undefined,
8-
args?: readonly any[] | undefined,
9-
): string | number | undefined;
10-
}
11-
> &
12-
(new (...args: any[]) => {
13-
pk(
14-
parent?: any,
15-
key?: string | undefined,
16-
args?: readonly any[] | undefined,
17-
): string | number | undefined;
18-
});
3+
declare const Entity_base: import("./EntityTypes.js").IEntityClass<new (...args: any[]) => {
4+
pk(parent?: any, key?: string, args?: readonly any[]): string | number | undefined;
5+
}> & (new (...args: any[]) => {
6+
pk(parent?: any, key?: string, args?: readonly any[]): string | number | undefined;
7+
});
198
/**
209
* Represents data that should be deduped by specifying a primary key.
2110
* @see https://dataclient.io/rest/api/Entity
2211
*/
2312
export default abstract class Entity extends Entity_base {
24-
/**
25-
* A unique identifier for each Entity
26-
*
27-
* @param [parent] When normalizing, the object which included the entity
28-
* @param [key] When normalizing, the key where this entity was found
29-
* @param [args] ...args sent to Endpoint
30-
* @see https://dataclient.io/rest/api/Entity#pk
31-
*/
32-
abstract pk(
33-
parent?: any,
34-
key?: string,
35-
args?: readonly any[],
36-
): string | number | undefined;
37-
38-
/** Control how automatic schema validation is handled
39-
*
40-
* `undefined`: Defaults - throw error in worst offense
41-
* 'warn': only ever warn
42-
* 'silent': Don't bother with processing at all
43-
*
44-
* Note: this only applies to non-nested members.
45-
*/
46-
protected static automaticValidation?: 'warn' | 'silent';
47-
/** Factory method to convert from Plain JS Objects.
48-
*
49-
* @param [props] Plain Object of properties to assign.
50-
* @see https://dataclient.io/rest/api/Entity#fromJS
51-
*/
52-
static fromJS: <T extends typeof Entity>(
53-
this: T,
54-
props?: Partial<AbstractInstanceType<T>>,
55-
) => AbstractInstanceType<T>;
56-
57-
/**
58-
* A unique identifier for each Entity
59-
*
60-
* @param [value] POJO of the entity or subset used
61-
* @param [parent] When normalizing, the object which included the entity
62-
* @param [key] When normalizing, the key where this entity was found
63-
* @param [args] ...args sent to Endpoint
64-
*/
65-
static pk: <T extends typeof Entity>(
66-
this: T,
67-
value: Partial<AbstractInstanceType<T>>,
68-
parent?: any,
69-
key?: string,
70-
args?: any[],
71-
) => string | number | undefined;
72-
73-
/** Do any transformations when first receiving input
74-
*
75-
* @see https://dataclient.io/rest/api/Entity#process
76-
*/
77-
static process(
78-
input: any,
79-
parent: any,
80-
key: string | undefined,
81-
args: any[],
82-
): any;
83-
84-
/** Returning a string indicates an error (the string is the message)
85-
* @see https://dataclient.io/rest/api/Entity#validate
86-
*/
87-
static validate(processedEntity: any): string | undefined;
88-
static denormalize: <T extends typeof Entity>(
89-
this: T,
90-
input: any,
91-
args: readonly any[],
92-
unvisit: (schema: any, input: any) => any,
93-
) => AbstractInstanceType<T>;
13+
/** Control how automatic schema validation is handled
14+
*
15+
* `undefined`: Defaults - throw error in worst offense
16+
* 'warn': only ever warn
17+
* 'silent': Don't bother with processing at all
18+
*
19+
* Note: this only applies to non-nested members.
20+
*/
21+
protected static automaticValidation?: 'warn' | 'silent';
22+
/** Factory method to convert from Plain JS Objects.
23+
*
24+
* @see https://dataclient.io/rest/api/Entity#fromJS
25+
* @param [props] Plain Object of properties to assign.
26+
*/
27+
static fromJS: <T extends typeof Entity>(this: T, props?: Partial<AbstractInstanceType<T>>) => AbstractInstanceType<T>;
28+
/**
29+
* A unique identifier for each Entity
30+
*
31+
* @see https://dataclient.io/rest/api/Entity#pk
32+
* @param [value] POJO of the entity or subset used
33+
* @param [parent] When normalizing, the object which included the entity
34+
* @param [key] When normalizing, the key where this entity was found
35+
* @param [args] ...args sent to Endpoint
36+
*/
37+
static pk: <T extends typeof Entity>(this: T, value: Partial<AbstractInstanceType<T>>, parent?: any, key?: string, args?: any[]) => string | number | undefined;
38+
/** Do any transformations when first receiving input
39+
*
40+
* @see https://dataclient.io/rest/api/Entity#process
41+
*/
42+
static process(input: any, parent: any, key: string | undefined, args: any[]): any;
43+
static denormalize: <T extends typeof Entity>(this: T, input: any, args: readonly any[], unvisit: (schema: any, input: any) => any) => AbstractInstanceType<T>;
9444
}
9545
export {};

0 commit comments

Comments
 (0)