Skip to content

Commit 114176e

Browse files
committed
fix!: renamed timestamp name methods
Renamed the following: getDeletedAtColumn -> getDeletedAtName getCreatedAtColumn -> getCreatedAtName getUpdatedAtColumn -> getUpdatedAtName
1 parent 19a1304 commit 114176e

10 files changed

+77
-77
lines changed

src/Calliope/Concerns/BuildsQuery.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ export default class BuildsQuery extends HasAttributes {
10371037
* @return {this}
10381038
*/
10391039
public latest(column?: string): this {
1040-
column = column ?? (this as unknown as Model).getCreatedAtColumn();
1040+
column = column ?? (this as unknown as Model).getCreatedAtName();
10411041

10421042
return this.orderBy(this.setServerStringCase(column), 'desc');
10431043
}
@@ -1063,7 +1063,7 @@ export default class BuildsQuery extends HasAttributes {
10631063
* @return {this}
10641064
*/
10651065
public oldest(column?: string): this {
1066-
column = column ?? (this as unknown as Model).getCreatedAtColumn();
1066+
column = column ?? (this as unknown as Model).getCreatedAtName();
10671067

10681068
return this.orderBy(this.setServerStringCase(column), 'asc');
10691069
}

src/Calliope/Concerns/HasTimestamps.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default class HasTimestamps extends HasRelations {
3434
*
3535
* @return {string}
3636
*/
37-
public getCreatedAtColumn(): string {
37+
public getCreatedAtName(): string {
3838
return this.setStringCase((this.constructor as unknown as HasTimestamps).createdAt as string);
3939
}
4040

@@ -43,7 +43,7 @@ export default class HasTimestamps extends HasRelations {
4343
*
4444
* @return {string}
4545
*/
46-
public getUpdatedAtColumn(): string {
46+
public getUpdatedAtName(): string {
4747
return this.setStringCase((this.constructor as unknown as HasTimestamps).updatedAt as string);
4848
}
4949

@@ -69,7 +69,7 @@ export default class HasTimestamps extends HasRelations {
6969
// @ts-expect-error
7070
(this as unknown as Model).throwIfModelDoesntExistsWhenCalling('touch');
7171

72-
const updatedAt = this.getUpdatedAtColumn();
72+
const updatedAt = this.getUpdatedAtName();
7373

7474
return this.setEndpoint(finish(this.getEndpoint(), '/') + String((this as unknown as Model).getKey()))
7575
.patch({ [updatedAt]: new Date().toISOString() })
@@ -95,8 +95,8 @@ export default class HasTimestamps extends HasRelations {
9595
// @ts-expect-error
9696
(this as unknown as Model).throwIfModelDoesntExistsWhenCalling('freshTimestamps');
9797

98-
const createdAt = this.getCreatedAtColumn();
99-
const updatedAt = this.getUpdatedAtColumn();
98+
const createdAt = this.getCreatedAtName();
99+
const updatedAt = this.getUpdatedAtName();
100100

101101
return this.select([createdAt, updatedAt])
102102
.whereKey((this as unknown as Model).getKey()!)

src/Calliope/Concerns/SoftDeletes.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ export default class SoftDeletes extends HasTimestamps {
2626
* @return {boolean}
2727
*/
2828
public trashed(): boolean {
29-
return !!this.getAttribute(this.getDeletedAtColumn());
29+
return !!this.getAttribute(this.getDeletedAtName());
3030
}
3131

3232
/**
3333
* Get the name of the deleted at attribute.
3434
*
3535
* @return {string}
3636
*/
37-
public getDeletedAtColumn(): string {
37+
public getDeletedAtName(): string {
3838
return this.setStringCase((this.constructor as unknown as SoftDeletes).deletedAt as string);
3939
}
4040

@@ -59,7 +59,7 @@ export default class SoftDeletes extends HasTimestamps {
5959
return super.delete(data);
6060
}
6161

62-
const deletedAt = this.getDeletedAtColumn();
62+
const deletedAt = this.getDeletedAtName();
6363

6464
if (this.getAttribute(deletedAt)) {
6565
return this as unknown as T;
@@ -84,7 +84,7 @@ export default class SoftDeletes extends HasTimestamps {
8484
* @return {Promise<this>}
8585
*/
8686
public async restore(): Promise<this> {
87-
if (!this.usesSoftDeletes() || !this.getAttribute(this.getDeletedAtColumn())) {
87+
if (!this.usesSoftDeletes() || !this.getAttribute(this.getDeletedAtName())) {
8888
return this;
8989
}
9090

@@ -96,9 +96,9 @@ export default class SoftDeletes extends HasTimestamps {
9696
}
9797

9898
return this.setEndpoint(finish(this.getEndpoint(), '/') + String((this as unknown as Model).getKey()))
99-
.patch({ [this.getDeletedAtColumn()]: null })
99+
.patch({ [this.getDeletedAtName()]: null })
100100
.then(model => {
101-
const deletedAt = this.getDeletedAtColumn();
101+
const deletedAt = this.getDeletedAtName();
102102

103103
return this.setAttribute(deletedAt, model.getAttribute(deletedAt, null)).syncOriginal(deletedAt);
104104
});

src/Calliope/Factory/FactoryBuilder.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,12 @@ export default class FactoryBuilder<T extends Model> {
317317
}
318318

319319
if (model.usesTimestamps()) {
320-
if (!model.getAttribute(model.getCreatedAtColumn())) {
321-
model.setAttribute(model.getCreatedAtColumn(), new Date().toISOString());
320+
if (!model.getAttribute(model.getCreatedAtName())) {
321+
model.setAttribute(model.getCreatedAtName(), new Date().toISOString());
322322
}
323323

324-
if (!model.getAttribute(model.getUpdatedAtColumn())) {
325-
model.setAttribute(model.getUpdatedAtColumn(), new Date().toISOString());
324+
if (!model.getAttribute(model.getUpdatedAtName())) {
325+
model.setAttribute(model.getUpdatedAtName(), new Date().toISOString());
326326
}
327327
}
328328

@@ -404,12 +404,12 @@ export default class FactoryBuilder<T extends Model> {
404404
});
405405

406406
if (this.model.usesTimestamps()) {
407-
attributes[this.model.getCreatedAtColumn()] = attributes[this.model.getCreatedAtColumn()] ?? null;
408-
attributes[this.model.getUpdatedAtColumn()] = attributes[this.model.getUpdatedAtColumn()] ?? null;
407+
attributes[this.model.getCreatedAtName()] = attributes[this.model.getCreatedAtName()] ?? null;
408+
attributes[this.model.getUpdatedAtName()] = attributes[this.model.getUpdatedAtName()] ?? null;
409409
}
410410

411411
if (this.model.usesSoftDeletes()) {
412-
attributes[this.model.getDeletedAtColumn()] = attributes[this.model.getDeletedAtColumn()] ?? null;
412+
attributes[this.model.getDeletedAtName()] = attributes[this.model.getDeletedAtName()] ?? null;
413413
}
414414

415415
compiledAttributeArray.push(this.resolveAttributes(attributes, compiledAttributes));

src/Calliope/Model.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ export default class Model extends SoftDeletes implements HasFactory {
3030
const lastSyncedAt = '_' + this.setStringCase('last_synced_at');
3131

3232
if (boolean && this.usesTimestamps()) {
33-
boolean = !!this.getAttribute(this.getCreatedAtColumn());
33+
boolean = !!this.getAttribute(this.getCreatedAtName());
3434
}
3535

3636
if (boolean && this.usesSoftDeletes()) {
37-
boolean = !this.getAttribute(this.getDeletedAtColumn());
37+
boolean = !this.getAttribute(this.getDeletedAtName());
3838
}
3939

4040
return boolean && lastSyncedAt in this && !!this[lastSyncedAt];
@@ -92,9 +92,9 @@ export default class Model extends SoftDeletes implements HasFactory {
9292
public replicate(except?: MaybeArray<string>): this {
9393
const excluded = new Set([
9494
this.getKeyName(),
95-
this.getCreatedAtColumn(),
96-
this.getUpdatedAtColumn(),
97-
this.getDeletedAtColumn()
95+
this.getCreatedAtName(),
96+
this.getUpdatedAtName(),
97+
this.getDeletedAtName()
9898
]);
9999

100100
if (except) {

tests/Calliope/Concerns/BuildsQuery.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ describe('BuildsQuery', () => {
946946
it('should be able to be called statically', () => {
947947
// it will be present when used from the model
948948
// eslint-disable-next-line jest/unbound-method,@typescript-eslint/unbound-method
949-
BuildsQuery.prototype.getCreatedAtColumn = builder.getCreatedAtColumn;
949+
BuildsQuery.prototype.getCreatedAtName = builder.getCreatedAtName;
950950

951951
builder = BuildsQuery.latest();
952952
// @ts-expect-error
@@ -972,7 +972,7 @@ describe('BuildsQuery', () => {
972972
it('should be able to be called statically', () => {
973973
// it will be present when used from the model
974974
// eslint-disable-next-line jest/unbound-method,@typescript-eslint/unbound-method
975-
BuildsQuery.prototype.getCreatedAtColumn = builder.getCreatedAtColumn;
975+
BuildsQuery.prototype.getCreatedAtName = builder.getCreatedAtName;
976976

977977
builder = BuildsQuery.oldest();
978978
// @ts-expect-error

tests/Calliope/Concerns/HasTimestamps.test.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ describe('HasTimestamps', () => {
1414
fetchMock.mockResponseOnce(async () => Promise.resolve(
1515
buildResponse(User.factory()
1616
.create()
17-
.only([hasTimestamps.getCreatedAtColumn(), hasTimestamps.getUpdatedAtColumn()])
17+
.only([hasTimestamps.getCreatedAtName(), hasTimestamps.getUpdatedAtName()])
1818
)
1919
));
2020
});
2121

2222
describe('getCreatedAtColumn', () => {
2323
it('should return the createdAt column', () => {
24-
expect(hasTimestamps.getCreatedAtColumn()).toBe('createdAt');
24+
expect(hasTimestamps.getCreatedAtName()).toBe('createdAt');
2525
});
2626

2727
it('should return the createdAt column correctly if overridden', () => {
@@ -30,13 +30,13 @@ describe('HasTimestamps', () => {
3030
}
3131
hasTimestamps = new MyUser;
3232

33-
expect(hasTimestamps.getCreatedAtColumn()).toBe('myCreatedAt');
33+
expect(hasTimestamps.getCreatedAtName()).toBe('myCreatedAt');
3434
});
3535
});
3636

3737
describe('getUpdatedAtColumn', () => {
3838
it('should return the updatedAt column', () => {
39-
expect(hasTimestamps.getUpdatedAtColumn()).toBe('updatedAt');
39+
expect(hasTimestamps.getUpdatedAtName()).toBe('updatedAt');
4040
});
4141

4242
it('should return the updatedAt column correctly if overridden', () => {
@@ -45,7 +45,7 @@ describe('HasTimestamps', () => {
4545
}
4646
hasTimestamps = new MyUser;
4747

48-
expect(hasTimestamps.getUpdatedAtColumn()).toBe('myUpdatedAt');
48+
expect(hasTimestamps.getUpdatedAtName()).toBe('myUpdatedAt');
4949
});
5050
});
5151

@@ -75,14 +75,14 @@ describe('HasTimestamps', () => {
7575
});
7676

7777
it('should update the timestamps', async () => {
78-
const createdAt = hasTimestamps.getAttribute(hasTimestamps.getCreatedAtColumn());
79-
const updatedAt = hasTimestamps.getAttribute(hasTimestamps.getUpdatedAtColumn());
78+
const createdAt = hasTimestamps.getAttribute(hasTimestamps.getCreatedAtName());
79+
const updatedAt = hasTimestamps.getAttribute(hasTimestamps.getUpdatedAtName());
8080

8181
jest.advanceTimersByTime(1000);
8282
await hasTimestamps.touch();
8383

84-
expect(hasTimestamps.getAttribute(hasTimestamps.getCreatedAtColumn())).toBe(createdAt);
85-
expect(hasTimestamps.getAttribute(hasTimestamps.getUpdatedAtColumn())).not.toBe(updatedAt);
84+
expect(hasTimestamps.getAttribute(hasTimestamps.getCreatedAtName())).toBe(createdAt);
85+
expect(hasTimestamps.getAttribute(hasTimestamps.getUpdatedAtName())).not.toBe(updatedAt);
8686
});
8787

8888
it('should throw an error if updated at column is not in the response', async () => {
@@ -93,7 +93,7 @@ describe('HasTimestamps', () => {
9393
const failingFunc = jest.fn(async () => hasTimestamps.touch());
9494

9595
await expect(failingFunc).rejects.toThrow(new InvalidArgumentException(
96-
'\'' + hasTimestamps.getUpdatedAtColumn() + '\' is not found in the response model.'
96+
'\'' + hasTimestamps.getUpdatedAtName() + '\' is not found in the response model.'
9797
));
9898
});
9999

@@ -141,14 +141,14 @@ describe('HasTimestamps', () => {
141141
buildResponse({ updated_at: new Date().toISOString(), created_at: new Date().toISOString() })
142142
));
143143

144-
const createdAt = hasTimestamps.getAttribute(hasTimestamps.getCreatedAtColumn());
145-
const updatedAt = hasTimestamps.getAttribute(hasTimestamps.getUpdatedAtColumn());
144+
const createdAt = hasTimestamps.getAttribute(hasTimestamps.getCreatedAtName());
145+
const updatedAt = hasTimestamps.getAttribute(hasTimestamps.getUpdatedAtName());
146146

147147
jest.advanceTimersByTime(1000);
148148
await hasTimestamps.freshTimestamps();
149149

150-
expect(hasTimestamps.getAttribute(hasTimestamps.getCreatedAtColumn())).not.toBe(createdAt);
151-
expect(hasTimestamps.getAttribute(hasTimestamps.getUpdatedAtColumn())).not.toBe(updatedAt);
150+
expect(hasTimestamps.getAttribute(hasTimestamps.getCreatedAtName())).not.toBe(createdAt);
151+
expect(hasTimestamps.getAttribute(hasTimestamps.getUpdatedAtName())).not.toBe(updatedAt);
152152
});
153153

154154
it('should return itself instead of new instance', async () => {
@@ -166,7 +166,7 @@ describe('HasTimestamps', () => {
166166
const failingFunc = jest.fn(async () => hasTimestamps.freshTimestamps());
167167

168168
await expect(failingFunc).rejects.toThrow(new InvalidArgumentException(
169-
'\'' + hasTimestamps.getCreatedAtColumn() + '\' is not found in the response model.'
169+
'\'' + hasTimestamps.getCreatedAtName() + '\' is not found in the response model.'
170170
));
171171
});
172172

@@ -178,7 +178,7 @@ describe('HasTimestamps', () => {
178178
const failingFunc = jest.fn(async () => hasTimestamps.freshTimestamps());
179179

180180
await expect(failingFunc).rejects.toThrow(new InvalidArgumentException(
181-
'\'' + hasTimestamps.getUpdatedAtColumn() + '\' is not found in the response model.'
181+
'\'' + hasTimestamps.getUpdatedAtName() + '\' is not found in the response model.'
182182
));
183183
});
184184

0 commit comments

Comments
 (0)