feat: add base
This commit is contained in:
		@@ -41,7 +41,6 @@ export class Query {
 | 
				
			|||||||
    if (options.data) {
 | 
					    if (options.data) {
 | 
				
			||||||
      fetchOptions.body = JSON.stringify(options.data);
 | 
					      fetchOptions.body = JSON.stringify(options.data);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    console.log(url.href, fetchOptions);
 | 
					 | 
				
			||||||
    return fetch(url.href, fetchOptions).then(async (response) => {
 | 
					    return fetch(url.href, fetchOptions).then(async (response) => {
 | 
				
			||||||
      if (!response.ok) {
 | 
					      if (!response.ok) {
 | 
				
			||||||
        return { code: response.status, message: response.statusText };
 | 
					        return { code: response.status, message: response.statusText };
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										20
									
								
								src/base.ts
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/base.ts
									
									
									
									
									
								
							@@ -1,6 +1,6 @@
 | 
				
			|||||||
import { Query } from './api.ts';
 | 
					import { Query } from './api.ts';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type NocoApiOptions = {
 | 
					export type NocoApiOptions = {
 | 
				
			||||||
  table?: string;
 | 
					  table?: string;
 | 
				
			||||||
  token?: string;
 | 
					  token?: string;
 | 
				
			||||||
  baseURL?: string;
 | 
					  baseURL?: string;
 | 
				
			||||||
@@ -73,13 +73,13 @@ class Record {
 | 
				
			|||||||
      method: 'GET',
 | 
					      method: 'GET',
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  update(data: { id: Id; [key: string]: any }) {
 | 
					  update(data: { Id?: Id; [key: string]: any }) {
 | 
				
			||||||
    return this.query.makeRequest(`/api/v2/tables/${this.table}/records`, {
 | 
					    return this.query.makeRequest(`/api/v2/tables/${this.table}/records`, {
 | 
				
			||||||
      method: 'PATCH',
 | 
					      method: 'PATCH',
 | 
				
			||||||
      data,
 | 
					      data,
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  delete(data: { id: Id }) {
 | 
					  delete(data: { Id?: Id }) {
 | 
				
			||||||
    return this.query.makeRequest(`/api/v2/tables/${this.table}/records`, {
 | 
					    return this.query.makeRequest(`/api/v2/tables/${this.table}/records`, {
 | 
				
			||||||
      method: 'DELETE',
 | 
					      method: 'DELETE',
 | 
				
			||||||
      data,
 | 
					      data,
 | 
				
			||||||
@@ -90,25 +90,27 @@ class Record {
 | 
				
			|||||||
      method: 'GET',
 | 
					      method: 'GET',
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  listLinks(linkFieldId: Id, id: Id) {
 | 
					  listLinks(linkFieldId: Id, Id: Id) {
 | 
				
			||||||
    return this.query.makeRequest(`/api/v2/tables/${this.table}/links/${linkFieldId}/records/${id}`, {
 | 
					    return this.query.makeRequest(`/api/v2/tables/${this.table}/links/${linkFieldId}/records/${Id}`, {
 | 
				
			||||||
      method: 'GET',
 | 
					      method: 'GET',
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  updateLinks(linkFieldId: Id, id: Id, data: any) {
 | 
					  updateLinks(linkFieldId: Id, Id: Id, data: any) {
 | 
				
			||||||
    return this.query.makeRequest(`/api/v2/tables/${this.table}/links/${linkFieldId}/records/${id}`, {
 | 
					    return this.query.makeRequest(`/api/v2/tables/${this.table}/links/${linkFieldId}/records/${Id}`, {
 | 
				
			||||||
      method: 'POST',
 | 
					      method: 'POST',
 | 
				
			||||||
      data,
 | 
					      data,
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  deleteLinks(linkFieldId: Id, id: Id) {
 | 
					  deleteLinks(linkFieldId: Id, Id: Id) {
 | 
				
			||||||
    return this.query.makeRequest(`/api/v2/tables/${this.table}/links/${linkFieldId}/records/${id}`, {
 | 
					    return this.query.makeRequest(`/api/v2/tables/${this.table}/links/${linkFieldId}/records/${Id}`, {
 | 
				
			||||||
      method: 'DELETE',
 | 
					      method: 'DELETE',
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 | 
					 * TODO
 | 
				
			||||||
 * @url https://nocodb.com/apis/v2/meta
 | 
					 * @url https://nocodb.com/apis/v2/meta
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class Meta {
 | 
					class Meta {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user