@sheet2db/sdk 1.0.0 → 1.0.1

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 (2) hide show
  1. package/README.md +325 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,325 @@
1
+ # Sheet2DB Documentation
2
+
3
+ ## Overview
4
+
5
+ `Sheet2DB` is a TypeScript class that provides an easy interface to interact with Google Sheets via the `sheet2db` API. This class abstracts the complexity of API calls and provides a simple way to read, write, update, and delete data in Google Sheets. It supports both browser and Node.js environments.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install sheet2db
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Import and Initialize
16
+
17
+ ```typescript
18
+ import Sheet2DB, { Sheet2DBOptions } from 'sheet2db';
19
+
20
+ const options: Sheet2DBOptions = {
21
+ mode: 'apikey',
22
+ apiKey: 'your-api-key',
23
+ spreadsheetId: 'your-spreadsheet-id',
24
+ version: 'v1'
25
+ };
26
+
27
+ const sheet2db = new Sheet2DB(options);
28
+ ```
29
+
30
+ ## Methods
31
+
32
+ ### ReadContent
33
+
34
+ Fetches content from the spreadsheet.
35
+
36
+ #### Parameters
37
+
38
+ - **limit** (optional): `number` - Maximum number of records to return.
39
+ - **offset** (optional): `number` - Number of records to skip before starting to return records.
40
+ - **sheet** (optional): `string` - The name of the sheet to read from.
41
+ - **format** (optional): `'records' | 'dict' | 'series' | 'split' | 'index' | 'raw'` - The format of the returned data.
42
+ - **cast_numbers** (optional): `string` - Cast numbers to specified type.
43
+ - **value_render** (optional): `'FORMATTED_VALUE' | 'UNFORMATTED_VALUE' | 'FORMULA'` - The value render option.
44
+
45
+ #### Example
46
+
47
+ ```typescript
48
+ sheet2db.ReadContent({ sheet: 'Sheet1', limit: 10 })
49
+ .then(data => console.log(data))
50
+ .catch(error => console.error(error));
51
+ ```
52
+
53
+ ### Keys
54
+
55
+ Gets the keys of the spreadsheet.
56
+
57
+ #### Parameters
58
+
59
+ - **sheet** (optional): `string` - The name of the sheet to get keys from.
60
+
61
+ #### Example
62
+
63
+ ```typescript
64
+ sheet2db.Keys({ sheet: 'Sheet1' })
65
+ .then(keys => console.log(keys))
66
+ .catch(error => console.error(error));
67
+ ```
68
+
69
+ ### Count
70
+
71
+ Gets the count of rows in the spreadsheet.
72
+
73
+ #### Parameters
74
+
75
+ - **sheet** (optional): `string` - The name of the sheet to count rows in.
76
+
77
+ #### Example
78
+
79
+ ```typescript
80
+ sheet2db.Count({ sheet: 'Sheet1' })
81
+ .then(count => console.log(count))
82
+ .catch(error => console.error(error));
83
+ ```
84
+
85
+ ### Title
86
+
87
+ Gets the title of the spreadsheet.
88
+
89
+ #### Example
90
+
91
+ ```typescript
92
+ sheet2db.Title()
93
+ .then(title => console.log(title))
94
+ .catch(error => console.error(error));
95
+ ```
96
+
97
+ ### Range
98
+
99
+ Gets a range of values from the spreadsheet.
100
+
101
+ #### Parameters
102
+
103
+ - **range**: `string` - The range to fetch, in A1 notation.
104
+
105
+ #### Example
106
+
107
+ ```typescript
108
+ sheet2db.Range({ range: 'A1:B2' })
109
+ .then(range => console.log(range))
110
+ .catch(error => console.error(error));
111
+ ```
112
+
113
+ ### Search
114
+
115
+ Searches for records in the spreadsheet.
116
+
117
+ #### Parameters
118
+
119
+ - **sheet** (optional): `string` - The name of the sheet to search in.
120
+ - **or** (optional): `boolean` - If true, uses OR logic for the search.
121
+ - **query**: `string` - The search query.
122
+
123
+ #### Example
124
+
125
+ ```typescript
126
+ sheet2db.Search({ query: 'name=John', sheet: 'Sheet1' })
127
+ .then(records => console.log(records))
128
+ .catch(error => console.error(error));
129
+ ```
130
+
131
+ ### Insert
132
+
133
+ Inserts data into the spreadsheet.
134
+
135
+ #### Parameters
136
+
137
+ - **data**: `Record<string, any> | Record<string, any>[]` - The data to insert.
138
+ - **sheet** (optional): `string` - The name of the sheet to insert data into.
139
+
140
+ #### Example
141
+
142
+ ```typescript
143
+ sheet2db.Insert({ data: { name: 'John', age: 30 }, sheet: 'Sheet1' })
144
+ .then(response => console.log(response))
145
+ .catch(error => console.error(error));
146
+ ```
147
+
148
+ ### UpdateRow
149
+
150
+ Updates a specific row in the spreadsheet.
151
+
152
+ #### Parameters
153
+
154
+ - **row**: `number` - The row number to update.
155
+ - **data**: `Record<string, any>` - The data to update.
156
+ - **sheet** (optional): `string` - The name of the sheet to update data in.
157
+
158
+ #### Example
159
+
160
+ ```typescript
161
+ sheet2db.UpdateRow({ row: 1, data: { age: 31 }, sheet: 'Sheet1' })
162
+ .then(response => console.log(response))
163
+ .catch(error => console.error(error));
164
+ ```
165
+
166
+ ### UpdateWithQuery
167
+
168
+ Updates rows based on a query.
169
+
170
+ #### Parameters
171
+
172
+ - **sheet** (optional): `string` - The name of the sheet to update data in.
173
+ - **query**: `string` - The query to identify rows to update.
174
+ - **data**: `Record<string, any>` - The data to update.
175
+
176
+ #### Example
177
+
178
+ ```typescript
179
+ sheet2db.UpdateWithQuery({ query: 'name=John', data: { age: 32 }, sheet: 'Sheet1' })
180
+ .then(response => console.log(response))
181
+ .catch(error => console.error(error));
182
+ ```
183
+
184
+ ### BatchUpdate
185
+
186
+ Updates multiple records in batches.
187
+
188
+ #### Parameters
189
+
190
+ - **sheet** (optional): `string` - The name of the sheet to update data in.
191
+ - **batches**: `{ query: string, record: Record<string, any> }[]` - The batch update data.
192
+
193
+ #### Example
194
+
195
+ ```typescript
196
+ sheet2db.BatchUpdate({ batches: [{ query: 'name=John', record: { age: 33 } }], sheet: 'Sheet1' })
197
+ .then(response => console.log(response))
198
+ .catch(error => console.error(error));
199
+ ```
200
+
201
+ ### DeleteRow
202
+
203
+ Deletes a specific row in the spreadsheet.
204
+
205
+ #### Parameters
206
+
207
+ - **row**: `number` - The row number to delete.
208
+ - **sheet** (optional): `string` - The name of the sheet to delete the row from.
209
+
210
+ #### Example
211
+
212
+ ```typescript
213
+ sheet2db.DeleteRow({ row: 1, sheet: 'Sheet1' })
214
+ .then(response => console.log(response))
215
+ .catch(error => console.error(error));
216
+ ```
217
+
218
+ ### DeleteWithQuery
219
+
220
+ Deletes rows based on a query.
221
+
222
+ #### Parameters
223
+
224
+ - **query**: `string` - The query to identify rows to delete.
225
+ - **sheet** (optional): `string` - The name of the sheet to delete rows from.
226
+
227
+ #### Example
228
+
229
+ ```typescript
230
+ sheet2db.DeleteWithQuery({ query: 'name=John', sheet: 'Sheet1' })
231
+ .then(response => console.log(response))
232
+ .catch(error => console.error(error));
233
+ ```
234
+
235
+ ### Clear
236
+
237
+ Clears all data from a sheet.
238
+
239
+ #### Parameters
240
+
241
+ - **sheet**: `string` - The name of the sheet to clear.
242
+
243
+ #### Example
244
+
245
+ ```typescript
246
+ sheet2db.Clear({ sheet: 'Sheet1' })
247
+ .then(response => console.log(response))
248
+ .catch(error => console.error(error));
249
+ ```
250
+
251
+ ### CreateSheet
252
+
253
+ Creates a new sheet in the spreadsheet.
254
+
255
+ #### Parameters
256
+
257
+ - **title** (optional): `string` - The title of the new sheet.
258
+
259
+ #### Example
260
+
261
+ ```typescript
262
+ sheet2db.CreateSheet({ title: 'NewSheet' })
263
+ .then(response => console.log(response))
264
+ .catch(error => console.error(error));
265
+ ```
266
+
267
+ ### DeleteSheet
268
+
269
+ Deletes a sheet from the spreadsheet.
270
+
271
+ #### Parameters
272
+
273
+ - **sheet**: `string` - The name of the sheet to delete.
274
+
275
+ #### Example
276
+
277
+ ```typescript
278
+ sheet2db.DeleteSheet({ sheet: 'Sheet1' })
279
+ .then(response => console.log(response))
280
+ .catch(error => console.error(error));
281
+ ```
282
+
283
+ ## Configuration Options
284
+
285
+ ### Sheet2DBOptions
286
+
287
+ - **mode**: `'apikey' | 'connectionId'` - Authentication mode.
288
+ - **apiKey**: `string` (required for `'apikey'` mode) - API key for accessing the spreadsheet.
289
+ - **spreadsheetId**: `string` (required for `'apikey'` mode) - The ID of the Google spreadsheet.
290
+ - **version**: `"v1"` - API version, always "v1".
291
+ - **connectionId**: `string` (required for `'connectionId'` mode) - Connection ID for accessing the spreadsheet.
292
+ - **basicAuth**: `{ username: string; password: string; }` (optional for `'connectionId'` mode) - Basic authentication credentials.
293
+ - **jwtAuth**: `{ bearerToken: string; }` (optional for `'connectionId'` mode) - JWT authentication token.
294
+ - **fetchFn**: `typeof fetch` (optional) - Custom fetch function.
295
+
296
+ ## Environment Detection
297
+
298
+ The library automatically detects the environment (browser or Node.js) and uses the appropriate `fetch` implementation.
299
+
300
+ ```typescript
301
+ let fetchFunction: typeof fetch;
302
+
303
+ if (typeof window !== 'undefined' && typeof window.fetch !== 'undefined') {
304
+ fetchFunction = window.fetch.bind(window);
305
+ } else {
306
+ fetchFunction = async (...args) => {
307
+ const fetch = global.fetch;
308
+ return fetch(...args);
309
+ };
310
+ }
311
+ ```
312
+
313
+ ## Error Handling
314
+
315
+ Each method returns a promise that resolves to the API response or rejects with an error.
316
+
317
+ ```typescript
318
+ sheet2db.ReadContent()
319
+ .then(data => console.log(data))
320
+ .catch(error => console.error(error));
321
+ ```
322
+
323
+ ## License
324
+
325
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheet2db/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {