-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vladimir Ubogovich
committed
Aug 11, 2021
1 parent
349f533
commit f434e51
Showing
7 changed files
with
116 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@qualifyze/airtable": major | ||
--- | ||
|
||
[BREAKING CHANGE] Make AirtableRecord.data non-nullable. | ||
It's always an object once any operation is executed, and it's inconvenient | ||
to cast it to non-nullable in the calling code. The consumers should check | ||
their code for `AirtableRecord` constructor or `data` property usage. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { FieldsValidator, UnknownFields } from "./fields"; | ||
import { ActionPointOptions } from "./action-point"; | ||
import { RestMethod, UnknownActionPayload } from "./endpoint"; | ||
import { | ||
RecordDataValidation, | ||
DeletedRecord, | ||
DeletedRecordValidation, | ||
} from "./raw-types"; | ||
import { TableActionPoint } from "./table"; | ||
import { AirtableRecord } from "./record"; | ||
|
||
export type RecordDataSource<Fields extends UnknownFields> = TableActionPoint & | ||
FieldsValidator<Fields>; | ||
|
||
export interface RecordActionPoint { | ||
runRecordAction<P extends UnknownActionPayload, R>( | ||
method: RestMethod, | ||
{ path, ...options }: ActionPointOptions<P, R> | ||
): Promise<R>; | ||
} | ||
|
||
export class AirtableRecordDraft<Fields extends UnknownFields> | ||
implements RecordActionPoint | ||
{ | ||
public readonly source: RecordDataSource<Fields>; | ||
public readonly id: string; | ||
|
||
constructor(source: RecordDataSource<Fields>, id: string) { | ||
this.source = source; | ||
this.id = id; | ||
} | ||
|
||
runRecordAction<P extends UnknownActionPayload, R>( | ||
method: RestMethod, | ||
{ path, ...options }: ActionPointOptions<P, R> | ||
): Promise<R> { | ||
return this.source.runTableAction(method, { | ||
path: path ? `${this.id}/${path}` : this.id, | ||
...options, | ||
}); | ||
} | ||
|
||
async fetch(): Promise<AirtableRecord<Fields>> { | ||
const { fields } = await this.runRecordAction("GET", { | ||
responseValidation: new RecordDataValidation(this.source), | ||
}); | ||
return new AirtableRecord(this.source, this.id, fields); | ||
} | ||
|
||
async update(data: Fields): Promise<AirtableRecord<Fields>> { | ||
const { id, fields } = await this.runRecordAction("PATCH", { | ||
responseValidation: new RecordDataValidation(this.source), | ||
payload: { | ||
body: { | ||
fields: data, | ||
}, | ||
}, | ||
}); | ||
|
||
return new AirtableRecord(this.source, id, fields); | ||
} | ||
|
||
async replace(data: Fields): Promise<AirtableRecord<Fields>> { | ||
const { id, fields } = await this.runRecordAction("PUT", { | ||
responseValidation: new RecordDataValidation(this.source), | ||
payload: { | ||
body: { | ||
fields: data, | ||
}, | ||
}, | ||
}); | ||
|
||
return new AirtableRecord(this.source, id, fields); | ||
} | ||
|
||
destroy(): Promise<DeletedRecord> { | ||
return this.runRecordAction("DELETE", { | ||
responseValidation: new DeletedRecordValidation(), | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters