easy-airtable-api 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/README.md +55 -1
- package/package.json +5 -2
- package/easy-airtable-api-0.1.0.tgz +0 -0
- package/lib/bases.d.ts +0 -18
- package/lib/bases.js +0 -40
- package/lib/cli.d.ts +0 -2
- package/lib/cli.js +0 -82
- package/lib/codegen/build.d.ts +0 -2
- package/lib/codegen/build.js +0 -25
- package/lib/codegen/emit-typescript.d.ts +0 -8
- package/lib/codegen/emit-typescript.js +0 -117
- package/lib/codegen/generate.d.ts +0 -2
- package/lib/codegen/generate.js +0 -23
- package/lib/codegen/identifiers.d.ts +0 -11
- package/lib/codegen/identifiers.js +0 -73
- package/lib/codegen/index.d.ts +0 -3
- package/lib/codegen/index.js +0 -2
- package/lib/codegen/load-schema.d.ts +0 -3
- package/lib/codegen/load-schema.js +0 -28
- package/lib/codegen/map-field.d.ts +0 -30
- package/lib/codegen/map-field.js +0 -296
- package/lib/codegen/normalize-schema.d.ts +0 -11
- package/lib/codegen/normalize-schema.js +0 -79
- package/lib/codegen/types.d.ts +0 -64
- package/lib/codegen/types.js +0 -1
- package/lib/codegen/utils.d.ts +0 -14
- package/lib/codegen/utils.js +0 -30
- package/lib/codegen/write-atomic.d.ts +0 -1
- package/lib/codegen/write-atomic.js +0 -11
- package/lib/index.d.ts +0 -8
- package/lib/index.js +0 -3
- package/lib/records.d.ts +0 -197
- package/lib/records.js +0 -300
- package/lib/requests.d.ts +0 -74
- package/lib/requests.js +0 -362
- package/lib/types/bases.d.ts +0 -31
- package/lib/types/bases.js +0 -1
- package/lib/types/fields.d.ts +0 -330
- package/lib/types/fields.js +0 -1
- package/lib/types/metadata.d.ts +0 -24
- package/lib/types/metadata.js +0 -1
- package/lib/types/records.d.ts +0 -130
- package/lib/types/records.js +0 -1
- package/lib/types/tables.d.ts +0 -99
- package/lib/types/tables.js +0 -1
- package/lib/utils.d.ts +0 -4
- package/lib/utils.js +0 -19
package/lib/records.d.ts
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { AirtableRecord, DeleteRecordResponse, DeleteRecordsResponse, GeneratedRecordFieldsCompatibleGetRecordOptions, GeneratedRecordFieldsCompatibleGetRecordsOptions, GetRecordQueryParameters, GetRecordsQueryParameters } from './types/records.js';
|
|
2
|
-
import type { AirtableRetryOptions } from './requests.js';
|
|
3
|
-
export declare function getRecord<Fields>({ apiKey, baseId, tableId, recordId, options, retry, }: {
|
|
4
|
-
apiKey: string;
|
|
5
|
-
baseId: string;
|
|
6
|
-
tableId: string;
|
|
7
|
-
recordId: string;
|
|
8
|
-
options?: GeneratedRecordFieldsCompatibleGetRecordOptions;
|
|
9
|
-
retry?: AirtableRetryOptions;
|
|
10
|
-
}): Promise<AirtableRecord<Fields>>;
|
|
11
|
-
export declare function getRecord({ apiKey, baseId, tableId, recordId, options, retry, }: {
|
|
12
|
-
apiKey: string;
|
|
13
|
-
baseId: string;
|
|
14
|
-
tableId: string;
|
|
15
|
-
recordId: string;
|
|
16
|
-
options?: GetRecordQueryParameters;
|
|
17
|
-
retry?: AirtableRetryOptions;
|
|
18
|
-
}): Promise<AirtableRecord<Record<string, unknown>>>;
|
|
19
|
-
export declare function getRecordsPage<Fields>({ apiKey, baseId, tableId, options, retry, }: {
|
|
20
|
-
apiKey: string;
|
|
21
|
-
baseId: string;
|
|
22
|
-
tableId: string;
|
|
23
|
-
options?: GeneratedRecordFieldsCompatibleGetRecordsOptions;
|
|
24
|
-
retry?: AirtableRetryOptions;
|
|
25
|
-
}): Promise<{
|
|
26
|
-
records: AirtableRecord<Fields>[];
|
|
27
|
-
offset?: string;
|
|
28
|
-
}>;
|
|
29
|
-
export declare function getRecordsPage({ apiKey, baseId, tableId, options, retry, }: {
|
|
30
|
-
apiKey: string;
|
|
31
|
-
baseId: string;
|
|
32
|
-
tableId: string;
|
|
33
|
-
options?: GetRecordsQueryParameters;
|
|
34
|
-
retry?: AirtableRetryOptions;
|
|
35
|
-
}): Promise<{
|
|
36
|
-
records: AirtableRecord<Record<string, unknown>>[];
|
|
37
|
-
offset?: string;
|
|
38
|
-
}>;
|
|
39
|
-
export declare function iterateRecordsPages<Fields>({ apiKey, baseId, tableId, options, retry, }: {
|
|
40
|
-
apiKey: string;
|
|
41
|
-
baseId: string;
|
|
42
|
-
tableId: string;
|
|
43
|
-
options?: GeneratedRecordFieldsCompatibleGetRecordsOptions;
|
|
44
|
-
retry?: AirtableRetryOptions;
|
|
45
|
-
}): AsyncGenerator<{
|
|
46
|
-
records: AirtableRecord<Fields>[];
|
|
47
|
-
offset?: string;
|
|
48
|
-
}>;
|
|
49
|
-
export declare function iterateRecordsPages({ apiKey, baseId, tableId, options, retry, }: {
|
|
50
|
-
apiKey: string;
|
|
51
|
-
baseId: string;
|
|
52
|
-
tableId: string;
|
|
53
|
-
options?: GetRecordsQueryParameters;
|
|
54
|
-
retry?: AirtableRetryOptions;
|
|
55
|
-
}): AsyncGenerator<{
|
|
56
|
-
records: AirtableRecord<Record<string, unknown>>[];
|
|
57
|
-
offset?: string;
|
|
58
|
-
}>;
|
|
59
|
-
export declare function getRecords<Fields>({ apiKey, baseId, tableId, options, retry, }: {
|
|
60
|
-
apiKey: string;
|
|
61
|
-
baseId: string;
|
|
62
|
-
tableId: string;
|
|
63
|
-
options?: GeneratedRecordFieldsCompatibleGetRecordsOptions;
|
|
64
|
-
retry?: AirtableRetryOptions;
|
|
65
|
-
}): Promise<AirtableRecord<Fields>[]>;
|
|
66
|
-
export declare function getRecords({ apiKey, baseId, tableId, options, retry, }: {
|
|
67
|
-
apiKey: string;
|
|
68
|
-
baseId: string;
|
|
69
|
-
tableId: string;
|
|
70
|
-
options?: GetRecordsQueryParameters;
|
|
71
|
-
retry?: AirtableRetryOptions;
|
|
72
|
-
}): Promise<AirtableRecord<Record<string, unknown>>[]>;
|
|
73
|
-
export declare function updateRecord<Fields>({ apiKey, baseId, tableId, recordId, fields, options, retry, }: {
|
|
74
|
-
apiKey: string;
|
|
75
|
-
baseId: string;
|
|
76
|
-
tableId: string;
|
|
77
|
-
recordId: string;
|
|
78
|
-
fields: Fields;
|
|
79
|
-
options?: {
|
|
80
|
-
typecast?: boolean;
|
|
81
|
-
returnFieldsByFieldId?: boolean;
|
|
82
|
-
overwriteFieldsNotSpecified?: boolean;
|
|
83
|
-
};
|
|
84
|
-
retry?: AirtableRetryOptions;
|
|
85
|
-
}): Promise<AirtableRecord<Fields>>;
|
|
86
|
-
export declare function replaceRecord<Fields>({ apiKey, baseId, tableId, recordId, fields, options, retry, }: {
|
|
87
|
-
apiKey: string;
|
|
88
|
-
baseId: string;
|
|
89
|
-
tableId: string;
|
|
90
|
-
recordId: string;
|
|
91
|
-
fields: Fields;
|
|
92
|
-
options?: {
|
|
93
|
-
typecast?: boolean;
|
|
94
|
-
returnFieldsByFieldId?: boolean;
|
|
95
|
-
};
|
|
96
|
-
retry?: AirtableRetryOptions;
|
|
97
|
-
}): Promise<AirtableRecord<Fields>>;
|
|
98
|
-
export declare function updateRecords<Fields>({ apiKey, baseId, tableId, records, options, retry, }: {
|
|
99
|
-
apiKey: string;
|
|
100
|
-
baseId: string;
|
|
101
|
-
tableId: string;
|
|
102
|
-
records: {
|
|
103
|
-
id: string;
|
|
104
|
-
fields: Fields;
|
|
105
|
-
}[];
|
|
106
|
-
options?: {
|
|
107
|
-
typecast?: boolean;
|
|
108
|
-
returnFieldsByFieldId?: boolean;
|
|
109
|
-
overwriteFieldsNotSpecified?: boolean;
|
|
110
|
-
requestInterval?: number;
|
|
111
|
-
};
|
|
112
|
-
retry?: AirtableRetryOptions;
|
|
113
|
-
}): Promise<{
|
|
114
|
-
records: AirtableRecord<Fields>[];
|
|
115
|
-
}>;
|
|
116
|
-
export declare function replaceRecords<Fields>({ apiKey, baseId, tableId, records, options, retry, }: {
|
|
117
|
-
apiKey: string;
|
|
118
|
-
baseId: string;
|
|
119
|
-
tableId: string;
|
|
120
|
-
records: {
|
|
121
|
-
id: string;
|
|
122
|
-
fields: Fields;
|
|
123
|
-
}[];
|
|
124
|
-
options?: {
|
|
125
|
-
typecast?: boolean;
|
|
126
|
-
returnFieldsByFieldId?: boolean;
|
|
127
|
-
requestInterval?: number;
|
|
128
|
-
};
|
|
129
|
-
retry?: AirtableRetryOptions;
|
|
130
|
-
}): Promise<{
|
|
131
|
-
records: AirtableRecord<Fields>[];
|
|
132
|
-
}>;
|
|
133
|
-
export declare function updateRecordsUpsert<Fields>({ apiKey, baseId, tableId, records, options, retry, }: {
|
|
134
|
-
apiKey: string;
|
|
135
|
-
baseId: string;
|
|
136
|
-
tableId: string;
|
|
137
|
-
records: {
|
|
138
|
-
id?: string;
|
|
139
|
-
fields: Fields;
|
|
140
|
-
}[];
|
|
141
|
-
options?: {
|
|
142
|
-
fieldsToMergeOn: string[];
|
|
143
|
-
typecast?: boolean;
|
|
144
|
-
returnFieldsByFieldId?: boolean;
|
|
145
|
-
overwriteFieldsNotSpecified?: boolean;
|
|
146
|
-
requestInterval?: number;
|
|
147
|
-
};
|
|
148
|
-
retry?: AirtableRetryOptions;
|
|
149
|
-
}): Promise<{
|
|
150
|
-
createdRecords: string[];
|
|
151
|
-
updatedRecords: string[];
|
|
152
|
-
records: AirtableRecord<Fields>[];
|
|
153
|
-
}>;
|
|
154
|
-
export declare function deleteRecord({ apiKey, baseId, tableId, recordId, retry, }: {
|
|
155
|
-
apiKey: string;
|
|
156
|
-
baseId: string;
|
|
157
|
-
tableId: string;
|
|
158
|
-
recordId: string;
|
|
159
|
-
retry?: AirtableRetryOptions;
|
|
160
|
-
}): Promise<DeleteRecordResponse>;
|
|
161
|
-
export declare function deleteRecords({ apiKey, baseId, tableId, recordIds, options, retry, }: {
|
|
162
|
-
apiKey: string;
|
|
163
|
-
baseId: string;
|
|
164
|
-
tableId: string;
|
|
165
|
-
recordIds: string[];
|
|
166
|
-
options?: {
|
|
167
|
-
requestInterval?: number;
|
|
168
|
-
};
|
|
169
|
-
retry?: AirtableRetryOptions;
|
|
170
|
-
}): Promise<DeleteRecordsResponse>;
|
|
171
|
-
export declare function createRecord<Fields>({ apiKey, baseId, tableId, fields, options, retry, }: {
|
|
172
|
-
apiKey: string;
|
|
173
|
-
baseId: string;
|
|
174
|
-
tableId: string;
|
|
175
|
-
fields: Fields;
|
|
176
|
-
options?: {
|
|
177
|
-
typecast?: boolean;
|
|
178
|
-
returnFieldsByFieldId?: boolean;
|
|
179
|
-
};
|
|
180
|
-
retry?: AirtableRetryOptions;
|
|
181
|
-
}): Promise<AirtableRecord<Fields>>;
|
|
182
|
-
export declare function createRecords<Fields>({ apiKey, baseId, tableId, records, options, retry, }: {
|
|
183
|
-
apiKey: string;
|
|
184
|
-
baseId: string;
|
|
185
|
-
tableId: string;
|
|
186
|
-
records: {
|
|
187
|
-
fields: Fields;
|
|
188
|
-
}[];
|
|
189
|
-
options?: {
|
|
190
|
-
typecast?: boolean;
|
|
191
|
-
returnFieldsByFieldId?: boolean;
|
|
192
|
-
requestInterval?: number;
|
|
193
|
-
};
|
|
194
|
-
retry?: AirtableRetryOptions;
|
|
195
|
-
}): Promise<{
|
|
196
|
-
records: AirtableRecord<Fields>[];
|
|
197
|
-
}>;
|
package/lib/records.js
DELETED
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import { appendQueryToEndpoint, airtableRequest } from './requests.js';
|
|
2
|
-
import { delay } from './utils.js';
|
|
3
|
-
export async function getRecord({ apiKey, baseId, tableId, recordId, options, retry, }) {
|
|
4
|
-
const endpoint = appendQueryToEndpoint(`/${recordId}`, {
|
|
5
|
-
cellFormat: options?.cellFormat,
|
|
6
|
-
returnFieldsByFieldId: options?.returnFieldsByFieldId,
|
|
7
|
-
});
|
|
8
|
-
return await airtableRequest({
|
|
9
|
-
apiKey,
|
|
10
|
-
baseId,
|
|
11
|
-
tableId,
|
|
12
|
-
endpoint,
|
|
13
|
-
method: 'GET',
|
|
14
|
-
retry,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
export async function getRecordsPage({ apiKey, baseId, tableId, options, retry, }) {
|
|
18
|
-
validateGetRecordsOptions(options);
|
|
19
|
-
return await airtableRequest({
|
|
20
|
-
apiKey,
|
|
21
|
-
baseId,
|
|
22
|
-
tableId,
|
|
23
|
-
endpoint: '/listRecords',
|
|
24
|
-
method: 'POST',
|
|
25
|
-
body: options,
|
|
26
|
-
retry,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
export async function* iterateRecordsPages({ apiKey, baseId, tableId, options, retry, }) {
|
|
30
|
-
let currentOffset;
|
|
31
|
-
do {
|
|
32
|
-
const requestBody = currentOffset
|
|
33
|
-
? { ...options, offset: currentOffset }
|
|
34
|
-
: options;
|
|
35
|
-
const response = (await getRecordsPage({
|
|
36
|
-
apiKey,
|
|
37
|
-
baseId,
|
|
38
|
-
tableId,
|
|
39
|
-
options: requestBody,
|
|
40
|
-
retry,
|
|
41
|
-
}));
|
|
42
|
-
yield response;
|
|
43
|
-
currentOffset = response.offset;
|
|
44
|
-
if (currentOffset && (options?.maxRecords ?? 100) > 100) {
|
|
45
|
-
const interval = options?.requestInterval || 500;
|
|
46
|
-
await delay(interval);
|
|
47
|
-
}
|
|
48
|
-
} while (currentOffset);
|
|
49
|
-
}
|
|
50
|
-
export async function getRecords({ apiKey, baseId, tableId, options, retry, }) {
|
|
51
|
-
validateGetRecordsOptions(options);
|
|
52
|
-
let records = [];
|
|
53
|
-
for await (const page of iterateRecordsPages({
|
|
54
|
-
apiKey,
|
|
55
|
-
baseId,
|
|
56
|
-
tableId,
|
|
57
|
-
options,
|
|
58
|
-
retry,
|
|
59
|
-
})) {
|
|
60
|
-
records = records.concat(page.records);
|
|
61
|
-
}
|
|
62
|
-
return records;
|
|
63
|
-
}
|
|
64
|
-
function validateGetRecordsOptions(options) {
|
|
65
|
-
if (!options)
|
|
66
|
-
return;
|
|
67
|
-
if (options.cellFormat === 'string') {
|
|
68
|
-
if (!options.timeZone || !options.userLocale) {
|
|
69
|
-
throw new Error('The timeZone and userLocale parameters are required when using string as the cellFormat.');
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
export async function updateRecord({ apiKey, baseId, tableId, recordId, fields, options, retry, }) {
|
|
74
|
-
return await airtableRequest({
|
|
75
|
-
apiKey,
|
|
76
|
-
baseId,
|
|
77
|
-
tableId,
|
|
78
|
-
endpoint: `/${recordId}`,
|
|
79
|
-
method: options?.overwriteFieldsNotSpecified === true ? 'PUT' : 'PATCH',
|
|
80
|
-
body: {
|
|
81
|
-
fields,
|
|
82
|
-
typecast: options?.typecast === true ? true : false,
|
|
83
|
-
returnFieldsByFieldId: options?.returnFieldsByFieldId === true ? true : false,
|
|
84
|
-
},
|
|
85
|
-
retry,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
export async function replaceRecord({ apiKey, baseId, tableId, recordId, fields, options, retry, }) {
|
|
89
|
-
return await airtableRequest({
|
|
90
|
-
apiKey,
|
|
91
|
-
baseId,
|
|
92
|
-
tableId,
|
|
93
|
-
endpoint: `/${recordId}`,
|
|
94
|
-
method: 'PUT',
|
|
95
|
-
body: {
|
|
96
|
-
fields,
|
|
97
|
-
typecast: options?.typecast ?? false,
|
|
98
|
-
returnFieldsByFieldId: options?.returnFieldsByFieldId ?? false,
|
|
99
|
-
},
|
|
100
|
-
retry,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
export async function updateRecords({ apiKey, baseId, tableId, records, options, retry, }) {
|
|
104
|
-
if (!Array.isArray(records) || records.length === 0) {
|
|
105
|
-
throw new Error('The records array is empty or not provided. Please provide a non-empty array of records to update.');
|
|
106
|
-
}
|
|
107
|
-
const chunkSize = 10;
|
|
108
|
-
const chunks = [];
|
|
109
|
-
for (let i = 0; i < records.length; i += chunkSize) {
|
|
110
|
-
chunks.push(records.slice(i, i + chunkSize));
|
|
111
|
-
}
|
|
112
|
-
let combinedResults = [];
|
|
113
|
-
for (const chunk of chunks) {
|
|
114
|
-
const result = await airtableRequest({
|
|
115
|
-
apiKey,
|
|
116
|
-
baseId,
|
|
117
|
-
tableId,
|
|
118
|
-
endpoint: '/',
|
|
119
|
-
method: options?.overwriteFieldsNotSpecified === true ? 'PUT' : 'PATCH',
|
|
120
|
-
body: {
|
|
121
|
-
records: chunk,
|
|
122
|
-
typecast: options?.typecast ?? false,
|
|
123
|
-
returnFieldsByFieldId: options?.returnFieldsByFieldId ?? false,
|
|
124
|
-
},
|
|
125
|
-
retry,
|
|
126
|
-
});
|
|
127
|
-
combinedResults = combinedResults.concat(result.records);
|
|
128
|
-
if (records.length > chunkSize &&
|
|
129
|
-
chunks.indexOf(chunk) < chunks.length - 1) {
|
|
130
|
-
const interval = options?.requestInterval || 500;
|
|
131
|
-
await delay(interval);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return { records: combinedResults };
|
|
135
|
-
}
|
|
136
|
-
export async function replaceRecords({ apiKey, baseId, tableId, records, options, retry, }) {
|
|
137
|
-
if (!Array.isArray(records) || records.length === 0) {
|
|
138
|
-
throw new Error('The records array is empty or not provided. Please provide a non-empty array of records to update.');
|
|
139
|
-
}
|
|
140
|
-
const chunkSize = 10;
|
|
141
|
-
const chunks = [];
|
|
142
|
-
for (let i = 0; i < records.length; i += chunkSize) {
|
|
143
|
-
chunks.push(records.slice(i, i + chunkSize));
|
|
144
|
-
}
|
|
145
|
-
let combinedResults = [];
|
|
146
|
-
for (const chunk of chunks) {
|
|
147
|
-
const result = await airtableRequest({
|
|
148
|
-
apiKey,
|
|
149
|
-
baseId,
|
|
150
|
-
tableId,
|
|
151
|
-
endpoint: '/',
|
|
152
|
-
method: 'PUT',
|
|
153
|
-
body: {
|
|
154
|
-
records: chunk,
|
|
155
|
-
typecast: options?.typecast ?? false,
|
|
156
|
-
returnFieldsByFieldId: options?.returnFieldsByFieldId ?? false,
|
|
157
|
-
},
|
|
158
|
-
retry,
|
|
159
|
-
});
|
|
160
|
-
combinedResults = combinedResults.concat(result.records);
|
|
161
|
-
if (records.length > chunkSize &&
|
|
162
|
-
chunks.indexOf(chunk) < chunks.length - 1) {
|
|
163
|
-
const interval = options?.requestInterval || 500;
|
|
164
|
-
await delay(interval);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return { records: combinedResults };
|
|
168
|
-
}
|
|
169
|
-
export async function updateRecordsUpsert({ apiKey, baseId, tableId, records, options, retry, }) {
|
|
170
|
-
if (!Array.isArray(records) || records.length === 0) {
|
|
171
|
-
throw new Error('The records array is empty or not provided. Please provide a non-empty array of records to update.');
|
|
172
|
-
}
|
|
173
|
-
if (!Array.isArray(options?.fieldsToMergeOn) ||
|
|
174
|
-
options?.fieldsToMergeOn.length === 0) {
|
|
175
|
-
throw new Error('fieldsToMergeOn must be an array of strings.');
|
|
176
|
-
}
|
|
177
|
-
const chunkSize = 10;
|
|
178
|
-
const chunks = [];
|
|
179
|
-
for (let i = 0; i < records.length; i += chunkSize) {
|
|
180
|
-
chunks.push(records.slice(i, i + chunkSize));
|
|
181
|
-
}
|
|
182
|
-
let allCreatedRecords = [];
|
|
183
|
-
let allUpdatedRecords = [];
|
|
184
|
-
let allRecords = [];
|
|
185
|
-
for (const chunk of chunks) {
|
|
186
|
-
const result = await airtableRequest({
|
|
187
|
-
apiKey,
|
|
188
|
-
baseId,
|
|
189
|
-
tableId,
|
|
190
|
-
endpoint: '/',
|
|
191
|
-
method: options?.overwriteFieldsNotSpecified === true ? 'PUT' : 'PATCH',
|
|
192
|
-
body: {
|
|
193
|
-
records: chunk,
|
|
194
|
-
typecast: options?.typecast ?? false,
|
|
195
|
-
returnFieldsByFieldId: options?.returnFieldsByFieldId ?? false,
|
|
196
|
-
performUpsert: { fieldsToMergeOn: options.fieldsToMergeOn },
|
|
197
|
-
},
|
|
198
|
-
retry,
|
|
199
|
-
});
|
|
200
|
-
allCreatedRecords = allCreatedRecords.concat(result.createdRecords);
|
|
201
|
-
allUpdatedRecords = allUpdatedRecords.concat(result.updatedRecords);
|
|
202
|
-
allRecords = allRecords.concat(result.records);
|
|
203
|
-
if (records.length > chunkSize && chunks.indexOf(chunk) < chunks.length - 1) {
|
|
204
|
-
const interval = options?.requestInterval || 500;
|
|
205
|
-
await delay(interval);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return {
|
|
209
|
-
createdRecords: allCreatedRecords,
|
|
210
|
-
updatedRecords: allUpdatedRecords,
|
|
211
|
-
records: allRecords,
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
export async function deleteRecord({ apiKey, baseId, tableId, recordId, retry, }) {
|
|
215
|
-
return await airtableRequest({
|
|
216
|
-
apiKey,
|
|
217
|
-
baseId,
|
|
218
|
-
tableId,
|
|
219
|
-
endpoint: `/${recordId}`,
|
|
220
|
-
method: 'DELETE',
|
|
221
|
-
retry,
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
export async function deleteRecords({ apiKey, baseId, tableId, recordIds, options, retry, }) {
|
|
225
|
-
if (!Array.isArray(recordIds) || recordIds.length === 0) {
|
|
226
|
-
throw new Error('The record ids array is empty or not provided. Please provide a non-empty array of record ids to delete the records.');
|
|
227
|
-
}
|
|
228
|
-
const chunkSize = 10;
|
|
229
|
-
const chunks = [];
|
|
230
|
-
for (let i = 0; i < recordIds.length; i += chunkSize) {
|
|
231
|
-
chunks.push(recordIds.slice(i, i + chunkSize));
|
|
232
|
-
}
|
|
233
|
-
let combinedResults = [];
|
|
234
|
-
for (const chunk of chunks) {
|
|
235
|
-
const result = await airtableRequest({
|
|
236
|
-
apiKey,
|
|
237
|
-
baseId,
|
|
238
|
-
tableId,
|
|
239
|
-
endpoint: appendQueryToEndpoint('', {
|
|
240
|
-
'records[]': chunk,
|
|
241
|
-
}),
|
|
242
|
-
method: 'DELETE',
|
|
243
|
-
retry,
|
|
244
|
-
});
|
|
245
|
-
combinedResults = combinedResults.concat(result.records);
|
|
246
|
-
if (recordIds.length > chunkSize && chunks.indexOf(chunk) < chunks.length - 1) {
|
|
247
|
-
const interval = options?.requestInterval || 500;
|
|
248
|
-
await delay(interval);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return { records: combinedResults };
|
|
252
|
-
}
|
|
253
|
-
export async function createRecord({ apiKey, baseId, tableId, fields, options, retry, }) {
|
|
254
|
-
return await airtableRequest({
|
|
255
|
-
apiKey,
|
|
256
|
-
baseId,
|
|
257
|
-
tableId,
|
|
258
|
-
endpoint: '',
|
|
259
|
-
method: 'POST',
|
|
260
|
-
body: {
|
|
261
|
-
fields,
|
|
262
|
-
typecast: options?.typecast ?? false,
|
|
263
|
-
returnFieldsByFieldId: options?.returnFieldsByFieldId ?? false,
|
|
264
|
-
},
|
|
265
|
-
retry,
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
export async function createRecords({ apiKey, baseId, tableId, records, options, retry, }) {
|
|
269
|
-
if (!Array.isArray(records) || records.length === 0) {
|
|
270
|
-
throw new Error('The records array is empty or not provided. Please provide a non-empty array of records to create.');
|
|
271
|
-
}
|
|
272
|
-
const chunkSize = 10;
|
|
273
|
-
const chunks = [];
|
|
274
|
-
for (let i = 0; i < records.length; i += chunkSize) {
|
|
275
|
-
chunks.push(records.slice(i, i + chunkSize));
|
|
276
|
-
}
|
|
277
|
-
let combinedResults = [];
|
|
278
|
-
for (const chunk of chunks) {
|
|
279
|
-
const result = await airtableRequest({
|
|
280
|
-
apiKey,
|
|
281
|
-
baseId,
|
|
282
|
-
tableId,
|
|
283
|
-
endpoint: '',
|
|
284
|
-
method: 'POST',
|
|
285
|
-
body: {
|
|
286
|
-
records: chunk,
|
|
287
|
-
typecast: options?.typecast ?? false,
|
|
288
|
-
returnFieldsByFieldId: options?.returnFieldsByFieldId ?? false,
|
|
289
|
-
},
|
|
290
|
-
retry,
|
|
291
|
-
});
|
|
292
|
-
combinedResults = combinedResults.concat(result.records);
|
|
293
|
-
if (records.length > chunkSize &&
|
|
294
|
-
chunks.indexOf(chunk) < chunks.length - 1) {
|
|
295
|
-
const interval = options?.requestInterval || 500;
|
|
296
|
-
await delay(interval);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return { records: combinedResults };
|
|
300
|
-
}
|
package/lib/requests.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { RequestMethods } from './types/tables.js';
|
|
2
|
-
export type AirtableQueryValue = string | number | boolean | Array<string | number | boolean> | undefined;
|
|
3
|
-
export type AirtableRetryOptions = {
|
|
4
|
-
maxRetries?: number;
|
|
5
|
-
baseDelayMs?: number;
|
|
6
|
-
maxDelayMs?: number;
|
|
7
|
-
retryOn429?: boolean;
|
|
8
|
-
retryOn5xx?: boolean;
|
|
9
|
-
retryOnNetworkErrors?: boolean;
|
|
10
|
-
useJitter?: boolean;
|
|
11
|
-
};
|
|
12
|
-
export declare class AirtableApiError extends Error {
|
|
13
|
-
statusCode?: number;
|
|
14
|
-
airtableType?: string;
|
|
15
|
-
retryable: boolean;
|
|
16
|
-
retryAfterMs?: number;
|
|
17
|
-
cause?: unknown;
|
|
18
|
-
request?: {
|
|
19
|
-
method: string;
|
|
20
|
-
baseId?: string;
|
|
21
|
-
tableId?: string;
|
|
22
|
-
path?: string;
|
|
23
|
-
};
|
|
24
|
-
constructor({ message, statusCode, airtableType, retryable, request, retryAfterMs, cause, }: {
|
|
25
|
-
message: string;
|
|
26
|
-
statusCode?: number;
|
|
27
|
-
airtableType?: string;
|
|
28
|
-
retryable: boolean;
|
|
29
|
-
retryAfterMs?: number;
|
|
30
|
-
cause?: unknown;
|
|
31
|
-
request?: {
|
|
32
|
-
method: string;
|
|
33
|
-
baseId?: string;
|
|
34
|
-
tableId?: string;
|
|
35
|
-
path?: string;
|
|
36
|
-
};
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
export declare function buildQueryString(query: Record<string, AirtableQueryValue>): string;
|
|
40
|
-
export declare function appendQueryToEndpoint(endpoint: string, query: Record<string, AirtableQueryValue>): string;
|
|
41
|
-
export declare function airtableApiRequest<T>(request: {
|
|
42
|
-
apiKey: string;
|
|
43
|
-
path: string;
|
|
44
|
-
method: RequestMethods;
|
|
45
|
-
query?: Record<string, AirtableQueryValue>;
|
|
46
|
-
body?: unknown;
|
|
47
|
-
apiURL?: string;
|
|
48
|
-
retry?: AirtableRetryOptions;
|
|
49
|
-
requestContext?: {
|
|
50
|
-
method: string;
|
|
51
|
-
baseId?: string;
|
|
52
|
-
tableId?: string;
|
|
53
|
-
path?: string;
|
|
54
|
-
};
|
|
55
|
-
}): Promise<T>;
|
|
56
|
-
export declare function airtableRequestRaw<T = unknown>(request: {
|
|
57
|
-
apiKey: string;
|
|
58
|
-
method: RequestMethods;
|
|
59
|
-
path: string;
|
|
60
|
-
query?: Record<string, AirtableQueryValue>;
|
|
61
|
-
body?: unknown;
|
|
62
|
-
apiURL?: string;
|
|
63
|
-
retry?: AirtableRetryOptions;
|
|
64
|
-
}): Promise<T>;
|
|
65
|
-
export declare function airtableRequest<T>(request: {
|
|
66
|
-
apiKey: string;
|
|
67
|
-
baseId: string;
|
|
68
|
-
tableId: string;
|
|
69
|
-
endpoint: string;
|
|
70
|
-
method: RequestMethods;
|
|
71
|
-
body?: object;
|
|
72
|
-
apiURL?: string;
|
|
73
|
-
retry?: AirtableRetryOptions;
|
|
74
|
-
}): Promise<T>;
|