easy-airtable-api 0.0.12 → 0.0.14
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/README.md +6 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/requests.d.ts +25 -0
- package/lib/requests.js +74 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
This is intended as a more accessible and user-friendly alternative to the official Airtable Node.js library.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Our focus has been on delivering an enhanced experience by utilizing types and simplifying the process of retrieving and modifying records through some helpful functions.
|
|
6
6
|
|
|
7
|
-
Currently, this project is in its early stages and requires significant development. Nonetheless, most methods
|
|
7
|
+
Currently, this project is in its early stages and requires significant development. Nonetheless, most methods for retrieving and updating records have already been implemented.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -60,6 +60,10 @@ const records = await getRecords<Fields>({
|
|
|
60
60
|
|
|
61
61
|
## Changelog
|
|
62
62
|
|
|
63
|
+
### 0.0.13
|
|
64
|
+
|
|
65
|
+
- Added generateTypeScriptDefinitions function to generate TypeScript definitions for Airtable tables.
|
|
66
|
+
|
|
63
67
|
### 0.0.12
|
|
64
68
|
|
|
65
69
|
- Reverted making apiKey, baseId, tableId default to undefined
|
package/lib/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getRecord, getRecords, updateRecord, updateRecords, updateRecordsUpsert, deleteRecords } from './requests.js';
|
|
1
|
+
export { getRecord, getRecords, updateRecord, updateRecords, updateRecordsUpsert, deleteRecords, generateTypeScriptDefinitions, } from './requests.js';
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getRecord, getRecords, updateRecord, updateRecords, updateRecordsUpsert, deleteRecords } from './requests.js';
|
|
1
|
+
export { getRecord, getRecords, updateRecord, updateRecords, updateRecordsUpsert, deleteRecords, generateTypeScriptDefinitions, } from './requests.js';
|
package/lib/requests.d.ts
CHANGED
|
@@ -69,3 +69,28 @@ export declare function deleteRecords({ apiKey, baseId, tableId, recordIds, opti
|
|
|
69
69
|
requestInterval?: number;
|
|
70
70
|
};
|
|
71
71
|
}): Promise<DeleteRecordsResponse>;
|
|
72
|
+
type AirtableField = {
|
|
73
|
+
id: string;
|
|
74
|
+
name: string;
|
|
75
|
+
type: string;
|
|
76
|
+
options?: object;
|
|
77
|
+
};
|
|
78
|
+
type AirtableTable = {
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
primaryFieldId: string;
|
|
82
|
+
fields: AirtableField[];
|
|
83
|
+
};
|
|
84
|
+
type AirtableBaseSchema = {
|
|
85
|
+
tables: AirtableTable[];
|
|
86
|
+
};
|
|
87
|
+
export declare function getBaseSchema({ apiKey, baseId, }: {
|
|
88
|
+
apiKey: string;
|
|
89
|
+
baseId: string;
|
|
90
|
+
}): Promise<AirtableBaseSchema>;
|
|
91
|
+
export declare function generateTypeScriptDefinitions({ apiKey, baseId, tableNameOrId, }: {
|
|
92
|
+
apiKey: string;
|
|
93
|
+
baseId: string;
|
|
94
|
+
tableNameOrId: string;
|
|
95
|
+
}): Promise<string>;
|
|
96
|
+
export {};
|
package/lib/requests.js
CHANGED
|
@@ -238,3 +238,77 @@ async function apiRequest({ url, method, apiKey, body, }) {
|
|
|
238
238
|
req.end();
|
|
239
239
|
});
|
|
240
240
|
}
|
|
241
|
+
export async function getBaseSchema({ apiKey, baseId, }) {
|
|
242
|
+
const response = await fetch(`https://api.airtable.com/v0/meta/bases/${baseId}/tables`, {
|
|
243
|
+
method: 'GET',
|
|
244
|
+
headers: {
|
|
245
|
+
Authorization: `Bearer ${apiKey}`,
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
if (!response.ok) {
|
|
249
|
+
throw new Error(`Error fetching base schema: ${response.statusText}`);
|
|
250
|
+
}
|
|
251
|
+
return response.json();
|
|
252
|
+
}
|
|
253
|
+
export async function generateTypeScriptDefinitions({ apiKey, baseId, tableNameOrId, }) {
|
|
254
|
+
const schema = await getBaseSchema({ apiKey, baseId });
|
|
255
|
+
const table = schema.tables.find((t) => t.id === tableNameOrId || t.name === tableNameOrId);
|
|
256
|
+
if (!table) {
|
|
257
|
+
throw new Error(`Table with name or ID "${tableNameOrId}" not found.`);
|
|
258
|
+
}
|
|
259
|
+
let typeDefinitions = `type ${table.name}Fields = {\n`;
|
|
260
|
+
table.fields.forEach((field) => {
|
|
261
|
+
typeDefinitions += ` ${field.name}?: ${mapAirtableTypeToTypeScript(field.type)};\n`;
|
|
262
|
+
});
|
|
263
|
+
typeDefinitions += '};\n';
|
|
264
|
+
return typeDefinitions;
|
|
265
|
+
}
|
|
266
|
+
function mapAirtableTypeToTypeScript(airtableType) {
|
|
267
|
+
switch (airtableType) {
|
|
268
|
+
case 'aiText':
|
|
269
|
+
case 'singleLineText':
|
|
270
|
+
case 'email':
|
|
271
|
+
case 'url':
|
|
272
|
+
case 'phoneNumber':
|
|
273
|
+
case 'multilineText':
|
|
274
|
+
case 'richText':
|
|
275
|
+
case 'button':
|
|
276
|
+
case 'barcode':
|
|
277
|
+
case 'createdTime':
|
|
278
|
+
case 'lastModifiedTime':
|
|
279
|
+
return 'string';
|
|
280
|
+
case 'number':
|
|
281
|
+
case 'currency':
|
|
282
|
+
case 'percent':
|
|
283
|
+
case 'rating':
|
|
284
|
+
case 'duration':
|
|
285
|
+
case 'autoNumber':
|
|
286
|
+
case 'count':
|
|
287
|
+
return 'number';
|
|
288
|
+
case 'checkbox':
|
|
289
|
+
return 'boolean';
|
|
290
|
+
case 'date':
|
|
291
|
+
case 'dateTime':
|
|
292
|
+
return 'Date';
|
|
293
|
+
case 'singleSelect':
|
|
294
|
+
case 'multipleSelects':
|
|
295
|
+
return 'string[]';
|
|
296
|
+
case 'attachment':
|
|
297
|
+
return 'any[]';
|
|
298
|
+
case 'collaborator':
|
|
299
|
+
case 'multipleCollaborators':
|
|
300
|
+
return '{ id: string; email?: string; name?: string; permissionLevel?: string; profilePicUrl?: string; }[]';
|
|
301
|
+
case 'linkToAnotherRecord':
|
|
302
|
+
case 'multipleRecordLinks':
|
|
303
|
+
return 'string[]';
|
|
304
|
+
case 'lookup':
|
|
305
|
+
case 'rollup':
|
|
306
|
+
return 'any';
|
|
307
|
+
case 'formula':
|
|
308
|
+
return 'string | number | boolean | any[]';
|
|
309
|
+
case 'syncSource':
|
|
310
|
+
return 'string';
|
|
311
|
+
default:
|
|
312
|
+
return 'any';
|
|
313
|
+
}
|
|
314
|
+
}
|