easy-airtable-api 0.0.15 → 0.0.17

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/README.md +402 -130
  3. package/easy-airtable-api-0.0.17.tgz +0 -0
  4. package/lib/bases.d.ts +18 -0
  5. package/lib/bases.js +40 -0
  6. package/lib/cli.d.ts +2 -0
  7. package/lib/cli.js +82 -0
  8. package/lib/codegen/build.d.ts +2 -0
  9. package/lib/codegen/build.js +25 -0
  10. package/lib/codegen/emit-typescript.d.ts +8 -0
  11. package/lib/codegen/emit-typescript.js +104 -0
  12. package/lib/codegen/generate.d.ts +2 -0
  13. package/lib/codegen/generate.js +23 -0
  14. package/lib/codegen/identifiers.d.ts +7 -0
  15. package/lib/codegen/identifiers.js +51 -0
  16. package/lib/codegen/index.d.ts +3 -0
  17. package/lib/codegen/index.js +2 -0
  18. package/lib/codegen/load-schema.d.ts +3 -0
  19. package/lib/codegen/load-schema.js +28 -0
  20. package/lib/codegen/map-field.d.ts +31 -0
  21. package/lib/codegen/map-field.js +278 -0
  22. package/lib/codegen/normalize-schema.d.ts +11 -0
  23. package/lib/codegen/normalize-schema.js +61 -0
  24. package/lib/codegen/types.d.ts +62 -0
  25. package/lib/codegen/types.js +1 -0
  26. package/lib/codegen/utils.d.ts +14 -0
  27. package/lib/codegen/utils.js +30 -0
  28. package/lib/codegen/write-atomic.d.ts +1 -0
  29. package/lib/codegen/write-atomic.js +11 -0
  30. package/lib/index.d.ts +8 -2
  31. package/lib/index.js +3 -2
  32. package/lib/records.d.ts +75 -9
  33. package/lib/records.js +110 -21
  34. package/lib/requests.d.ts +65 -21
  35. package/lib/requests.js +281 -31
  36. package/lib/types/bases.d.ts +8 -40
  37. package/lib/types/fields.d.ts +8 -8
  38. package/lib/types/metadata.d.ts +24 -0
  39. package/lib/types/metadata.js +1 -0
  40. package/lib/types/records.d.ts +1 -1
  41. package/lib/utils.d.ts +2 -2
  42. package/package.json +17 -9
  43. package/lib/generate-types.d.ts +0 -5
  44. package/lib/generate-types.js +0 -78
@@ -1,3 +1,4 @@
1
+ import type { AirtableBaseSchema } from './metadata.js';
1
2
  type BaseList = {
2
3
  id: string;
3
4
  name: string;
@@ -7,57 +8,24 @@ export type ListBasesResponse = {
7
8
  bases: BaseList[];
8
9
  offset?: string;
9
10
  };
10
- type BasesFieldOptions = {
11
- inverseLinkFieldId?: string;
12
- isReversed?: boolean;
13
- linkedTableId?: string;
14
- prefersSingleRecordLink?: boolean;
15
- };
16
- type Field = {
17
- description?: string;
18
- id: string;
11
+ export type CreateBaseFieldConfig = {
19
12
  name: string;
20
13
  type: string;
21
- options?: BasesFieldOptions;
22
- };
23
- type TableView = {
24
- id: string;
25
- name: string;
26
- type: string;
27
- };
28
- type Table = {
29
14
  description?: string;
30
- fields: Field[];
31
- id: string;
32
- name: string;
33
- primaryFieldId: string;
34
- views: TableView[];
35
- };
36
- export type GetBaseSchemaResponse = {
37
- tables: Table[];
38
- };
39
- type TableConfigFieldOptions = {
40
- color?: string;
41
- icon?: string;
15
+ options?: Record<string, unknown>;
42
16
  };
43
- type TableConfigField = {
44
- description?: string;
17
+ export type CreateBaseTableConfig = {
45
18
  name: string;
46
- type: string;
47
- options?: TableConfigFieldOptions;
48
- };
49
- type BasesTableConfig = {
50
19
  description?: string;
51
- fields: TableConfigField[];
52
- name: string;
20
+ fields: CreateBaseFieldConfig[];
53
21
  };
54
22
  export type CreateBaseRequestBody = {
55
- name: string;
56
- tables: BasesTableConfig[];
57
23
  workspaceId: string;
24
+ name: string;
25
+ tables: CreateBaseTableConfig[];
58
26
  };
59
27
  export type CreateBaseResponse = {
60
28
  id: string;
61
- tables: Table[];
29
+ tables: AirtableBaseSchema['tables'];
62
30
  };
63
31
  export {};
@@ -62,7 +62,7 @@ export interface CollaboratorCell {
62
62
  }
63
63
  export interface SingleCollaboratorFieldTypeAndOptions {
64
64
  type: 'singleCollaborator';
65
- options: {};
65
+ options: Record<string, never>;
66
66
  }
67
67
  export type CountCell = number;
68
68
  export interface CountFieldTypeAndOptions {
@@ -80,7 +80,7 @@ export type CreatedTimeCell = string;
80
80
  export interface CreatedTimeFieldTypeAndOptions {
81
81
  type: 'createdTime';
82
82
  options: {
83
- result?: any;
83
+ result?: unknown;
84
84
  };
85
85
  }
86
86
  export type CurrencyCell = number;
@@ -133,7 +133,7 @@ export interface FormulaFieldTypeAndOptions {
133
133
  formula: string;
134
134
  isValid: boolean;
135
135
  referencedFieldIds: string[] | null;
136
- result: any;
136
+ result: unknown;
137
137
  };
138
138
  }
139
139
  export type LastModifiedByCell = {
@@ -151,7 +151,7 @@ export interface LastModifiedTimeFieldTypeAndOptions {
151
151
  options: {
152
152
  isValid: boolean;
153
153
  referencedFieldIds: string[] | null;
154
- result: any;
154
+ result: unknown;
155
155
  };
156
156
  }
157
157
  export type LinkToAnotherRecordCellV1 = string[];
@@ -173,10 +173,10 @@ export type LongTextCell = string;
173
173
  export interface LongTextFieldTypeAndOptions {
174
174
  type: 'multilineText';
175
175
  }
176
- export type LookupCellV1 = (number | string | boolean | any)[];
176
+ export type LookupCellV1 = (number | string | boolean | unknown)[];
177
177
  export type LookupCellV2 = {
178
178
  valuesByLinkedRecordId: {
179
- [key: string]: any[];
179
+ [key: string]: unknown[];
180
180
  };
181
181
  linkedRecordIds: string[];
182
182
  };
@@ -186,7 +186,7 @@ export interface LookupFieldTypeAndOptions {
186
186
  fieldIdInLinkedTable: string | null;
187
187
  isValid: boolean;
188
188
  recordLinkFieldId: string | null;
189
- result: any;
189
+ result: unknown;
190
190
  };
191
191
  }
192
192
  export type Collaborator = {
@@ -215,7 +215,7 @@ export type RatingOptions = {
215
215
  export type RollupOptions = {
216
216
  fieldIdInLinkedTable?: string;
217
217
  recordLinkFieldId?: string;
218
- result?: any;
218
+ result?: unknown;
219
219
  isValid?: boolean;
220
220
  referencedFieldIds?: string[];
221
221
  };
@@ -0,0 +1,24 @@
1
+ export type AirtableFieldOptions = Record<string, unknown>;
2
+ export interface AirtableFieldSchema {
3
+ id: string;
4
+ name: string;
5
+ type: string;
6
+ description?: string;
7
+ options?: AirtableFieldOptions;
8
+ }
9
+ export interface AirtableViewSchema {
10
+ id: string;
11
+ name: string;
12
+ type: string;
13
+ }
14
+ export interface AirtableTableSchema {
15
+ id: string;
16
+ name: string;
17
+ description?: string;
18
+ primaryFieldId: string;
19
+ fields: AirtableFieldSchema[];
20
+ views?: AirtableViewSchema[];
21
+ }
22
+ export interface AirtableBaseSchema {
23
+ tables: AirtableTableSchema[];
24
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -4,7 +4,7 @@ export type AirtableRecord<Fields = DefaultFieldsType> = {
4
4
  fields: Fields;
5
5
  };
6
6
  type DefaultFieldsType = {
7
- [key: string]: any;
7
+ [key: string]: unknown;
8
8
  };
9
9
  type BaseId = string;
10
10
  type TableIdOrName = string;
package/lib/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { UpdateRecords } from './types/fields';
2
- export declare function getArrayInChunks(records: UpdateRecords): Promise<import("./types/fields").UpdateRecord[][]>;
1
+ import { UpdateRecords } from './types/fields.js';
2
+ export declare function getArrayInChunks(records: UpdateRecords): Promise<import("./types/fields.js").UpdateRecord[][]>;
3
3
  export declare function getErrorMessage(error: Error | unknown): string;
4
4
  export declare function delay(ms?: number): Promise<unknown>;
package/package.json CHANGED
@@ -1,32 +1,40 @@
1
1
  {
2
2
  "name": "easy-airtable-api",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "type": "module",
5
- "description": "An easy way to connect to Airtable via their API.",
5
+ "description": "Lightweight TypeScript-first Airtable client with metadata-based type generation.",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
+ "types": "./lib/index.d.ts",
10
11
  "import": "./lib/index.js"
12
+ },
13
+ "./codegen": {
14
+ "types": "./lib/codegen/index.d.ts",
15
+ "import": "./lib/codegen/index.js"
11
16
  }
12
17
  },
18
+ "bin": {
19
+ "easy-airtable-api": "lib/cli.js"
20
+ },
13
21
  "scripts": {
14
22
  "watch": "tsc --watch",
15
23
  "build": "rm -r ./lib && tsc",
16
- "publish": "npm publish",
24
+ "prepublishOnly": "npm test && npm run build",
25
+ "release": "npm run prepublishOnly && npm pack && npm publish --ignore-scripts",
17
26
  "lint": "eslint 'src/**/*.{ts,tsx}'",
18
- "test": "vitest",
19
- "testGetRecords": "vitest get-records.test.ts",
20
- "testCreateRecords": "vitest create-records.test.ts",
21
- "testUpdateRecords": "vitest update-records.test.ts",
22
- "testDeleteRecords": "vitest delete-records.test.ts"
27
+ "test": "npm run test:all",
28
+ "test:codegen": "vitest run tests/codegen.test.ts",
29
+ "test:integration": "RUN_AIRTABLE_INTEGRATION_TESTS=true vitest run tests/get-record.test.ts tests/get-records.test.ts tests/create-records.test.ts tests/update-records.test.ts tests/delete-records.test.ts",
30
+ "test:all": "vitest run"
23
31
  },
24
32
  "keywords": [
25
33
  "airtable"
26
34
  ],
27
35
  "repository": {
28
36
  "type": "git",
29
- "url": "https://github.com/marcellocurto/easy-airtable-api.git"
37
+ "url": "git+https://github.com/marcellocurto/easy-airtable-api.git"
30
38
  },
31
39
  "homepage": "https://marcellocurto.com/code/easy-airtable-api",
32
40
  "author": "Marcello Curto",
@@ -1,5 +0,0 @@
1
- export declare function generateTypeScriptDefinitions({ apiKey, baseId, tableNameOrId, }: {
2
- apiKey: string;
3
- baseId: string;
4
- tableNameOrId: string;
5
- }): Promise<string>;
@@ -1,78 +0,0 @@
1
- import { getBaseSchema } from './requests';
2
- export async function generateTypeScriptDefinitions({ apiKey, baseId, tableNameOrId, }) {
3
- const schema = await getBaseSchema({ apiKey, baseId });
4
- const table = schema.tables.find((t) => t.id === tableNameOrId || t.name === tableNameOrId);
5
- if (!table) {
6
- throw new Error(`Table with name or ID "${tableNameOrId}" not found.`);
7
- }
8
- let typeDefinitions = `type ${table.name}Fields = {\n`;
9
- table.fields.forEach((field) => {
10
- let fieldName;
11
- if (field.name.includes('"')) {
12
- if (field.name.includes("'")) {
13
- if (field.name.includes('`')) {
14
- fieldName = field.name;
15
- }
16
- else {
17
- fieldName = `\`${field.name}\``;
18
- }
19
- }
20
- else {
21
- fieldName = `'${field.name}'`;
22
- }
23
- }
24
- else {
25
- fieldName = `"${field.name}"`;
26
- }
27
- const typeInfo = mapAirtableTypeToTypeScript(field.type);
28
- const fieldType = typeInfo.readonly
29
- ? `readonly ${typeInfo.type}`
30
- : typeInfo.type;
31
- typeDefinitions += ` ${fieldName}?: ${fieldType};\n`;
32
- });
33
- typeDefinitions += '};\n';
34
- return typeDefinitions;
35
- }
36
- function mapAirtableTypeToTypeScript(airtableType) {
37
- switch (airtableType) {
38
- case 'date':
39
- case 'dateTime':
40
- return { type: 'string', readonly: false };
41
- case 'createdTime':
42
- case 'lastModifiedTime':
43
- return { type: 'string', readonly: true };
44
- case 'number':
45
- case 'currency':
46
- case 'percent':
47
- case 'rating':
48
- case 'duration':
49
- case 'autoNumber':
50
- case 'count':
51
- return { type: 'number', readonly: false };
52
- case 'checkbox':
53
- return { type: 'boolean', readonly: false };
54
- case 'singleSelect':
55
- case 'multipleSelects':
56
- return { type: 'string[]', readonly: false };
57
- case 'attachment':
58
- return { type: 'any[]', readonly: false };
59
- case 'collaborator':
60
- case 'multipleCollaborators':
61
- return {
62
- type: '{ id: string; email?: string; name?: string; permissionLevel?: string; profilePicUrl?: string; }[]',
63
- readonly: false,
64
- };
65
- case 'linkToAnotherRecord':
66
- case 'multipleRecordLinks':
67
- return { type: 'string[]', readonly: false };
68
- case 'lookup':
69
- case 'rollup':
70
- return { type: 'any', readonly: false };
71
- case 'formula':
72
- return { type: 'string | number | boolean | any[]', readonly: true };
73
- case 'syncSource':
74
- return { type: 'string', readonly: false };
75
- default:
76
- return { type: 'any', readonly: false };
77
- }
78
- }