@nshiab/simple-data-analysis 6.0.0 → 6.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.
- package/README.md +128 -11
- package/esm/class/SimpleDB.d.ts +1 -0
- package/esm/class/SimpleDB.d.ts.map +1 -1
- package/esm/class/SimpleDB.js +1 -0
- package/esm/class/SimpleTable.d.ts +75 -64
- package/esm/class/SimpleTable.d.ts.map +1 -1
- package/esm/class/SimpleTable.js +75 -64
- package/llm.md +150 -124
- package/package.json +1 -1
- package/script/class/SimpleDB.d.ts +1 -0
- package/script/class/SimpleDB.d.ts.map +1 -1
- package/script/class/SimpleDB.js +1 -0
- package/script/class/SimpleTable.d.ts +75 -64
- package/script/class/SimpleTable.d.ts.map +1 -1
- package/script/class/SimpleTable.js +75 -64
package/esm/class/SimpleTable.js
CHANGED
|
@@ -64,9 +64,9 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
64
64
|
*
|
|
65
65
|
* This method automatically appends instructions to your prompt; set `verbose` to `true` to see the full prompt.
|
|
66
66
|
*
|
|
67
|
-
* This method supports Gemini, Vertex AI, and Ollama.
|
|
67
|
+
* This method supports Gemini, Vertex AI, and Ollama.
|
|
68
68
|
*
|
|
69
|
-
*
|
|
69
|
+
* Environment variables are named configuration values supplied to the running process. By default, this method reads `AI_PROVIDER` (`"gemini"` or `"ollama"`; defaults to `"gemini"`), `AI_MODEL` (for example, `"gemini-3-flash-preview"` or `"gemma3:4b"`), and, for Gemini, either `AI_KEY` (for example, `"your-gemini-api-key"`) or both `AI_PROJECT` (for example, `"my-google-cloud-project"`) and `AI_LOCATION` (for example, `"us-central1"`). Values passed through `generation` override the corresponding environment values. When using Ollama, ensure it is running.
|
|
70
70
|
*
|
|
71
71
|
* To manage rate limits, use `batchSize` to process multiple rows per request and `rateLimitPerMinute` to pace requests across the worker pool. The `concurrency` option controls how many requests may run in parallel.
|
|
72
72
|
*
|
|
@@ -88,7 +88,7 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
88
88
|
* @param options.concurrency - The number of concurrent requests to send. Defaults to `1`.
|
|
89
89
|
* @param options.errorColumn - The optional column where per-row error messages are stored. When omitted, a failed batch throws.
|
|
90
90
|
* @param options.logProgress - If `true`, logs request-pool progress. Defaults to `false`.
|
|
91
|
-
* @param options.generation - Gemini or Ollama generation configuration.
|
|
91
|
+
* @param options.generation - Optional Gemini or Ollama generation configuration.
|
|
92
92
|
* @param options.test - A function to validate the returned data. If it throws an error, the request will be retried (if `retry` is set). Defaults to `undefined`.
|
|
93
93
|
* @param options.retry - The number of times to retry the request in case of failure. Defaults to `0`.
|
|
94
94
|
* @param options.retryCheck - A function that receives an error and returns whether it should be retried. Defaults to `undefined`.
|
|
@@ -146,6 +146,10 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
146
146
|
*
|
|
147
147
|
* @example
|
|
148
148
|
* ```ts
|
|
149
|
+
* // Set these environment variables before running:
|
|
150
|
+
* // AI_PROVIDER=gemini
|
|
151
|
+
* // AI_MODEL=gemini-3-flash-preview
|
|
152
|
+
* // AI_KEY=your-gemini-api-key
|
|
149
153
|
* const cities = await sdb
|
|
150
154
|
* .newTable("cities")
|
|
151
155
|
* .loadArray([
|
|
@@ -187,9 +191,9 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
187
191
|
/**
|
|
188
192
|
* Generates embeddings for a specified text column and stores the results in a new column.
|
|
189
193
|
*
|
|
190
|
-
* This method supports Gemini, Vertex AI, and Ollama embeddings.
|
|
194
|
+
* This method supports Gemini, Vertex AI, and Ollama embeddings.
|
|
191
195
|
*
|
|
192
|
-
*
|
|
196
|
+
* Environment variables are named configuration values supplied to the running process. By default, this method reads `AI_EMBEDDINGS_PROVIDER` (`"gemini"` or `"ollama"`; defaults to `"gemini"`), `AI_EMBEDDINGS_MODEL` (for example, `"gemini-embedding-001"` or `"nomic-embed-text"`), and, for Gemini, either `AI_KEY` (for example, `"your-gemini-api-key"`) or both `AI_PROJECT` (for example, `"my-google-cloud-project"`) and `AI_LOCATION` (for example, `"us-central1"`). Values passed through `embeddings` override the corresponding environment values. When using Ollama, ensure it is running.
|
|
193
197
|
*
|
|
194
198
|
* To manage rate limits, use `rateLimitPerMinute` to introduce delays between requests. For higher rate limits (business/professional accounts), `concurrency` allows parallel requests.
|
|
195
199
|
*
|
|
@@ -211,7 +215,7 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
211
215
|
* @param options.efSearch - The number of candidate vertices to consider during search. Higher values result in more accurate searches but increase search time. Defaults to 64.
|
|
212
216
|
* @param options.M - The maximum number of neighbors to keep for each vertex in the graph. Higher values result in more accurate indexes but increase build time and memory usage. Defaults to 16.
|
|
213
217
|
* @param options.concurrency - The number of concurrent requests to send. Defaults to `1`.
|
|
214
|
-
* @param options.embeddings - Gemini or Ollama embedding configuration.
|
|
218
|
+
* @param options.embeddings - Optional Gemini or Ollama embedding configuration.
|
|
215
219
|
* @param options.rateLimitPerMinute - The rate limit for AI requests in requests per minute. The method will wait between requests if necessary. Defaults to `undefined` (no limit).
|
|
216
220
|
* @param options.verbose - If `true`, logs additional debugging information. Defaults to `false`.
|
|
217
221
|
* @returns The table, so methods can be chained.
|
|
@@ -219,6 +223,10 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
219
223
|
*
|
|
220
224
|
* @example
|
|
221
225
|
* ```ts
|
|
226
|
+
* // Set these environment variables before running:
|
|
227
|
+
* // AI_EMBEDDINGS_PROVIDER=gemini
|
|
228
|
+
* // AI_EMBEDDINGS_MODEL=gemini-embedding-001
|
|
229
|
+
* // AI_KEY=your-gemini-api-key
|
|
222
230
|
* const food = await sdb
|
|
223
231
|
* .newTable("food")
|
|
224
232
|
* .loadArray([
|
|
@@ -230,10 +238,6 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
230
238
|
* { food: "tacos" },
|
|
231
239
|
* ])
|
|
232
240
|
* .aiEmbeddings("food", "embeddings", {
|
|
233
|
-
* embeddings: {
|
|
234
|
-
* provider: "gemini",
|
|
235
|
-
* model: "gemini-embedding-001",
|
|
236
|
-
* },
|
|
237
241
|
* rateLimitPerMinute: 15,
|
|
238
242
|
* createIndex: true,
|
|
239
243
|
* verbose: true,
|
|
@@ -259,7 +263,7 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
259
263
|
* Creates an embedding from a specified text and returns the most similar text content based on their embeddings.
|
|
260
264
|
* This method is useful for semantic search and text similarity tasks, computing cosine distance and sorting results by similarity.
|
|
261
265
|
*
|
|
262
|
-
*
|
|
266
|
+
* Environment variables are named configuration values supplied to the running process. By default, this method reads `AI_EMBEDDINGS_PROVIDER` (`"gemini"` or `"ollama"`; defaults to `"gemini"`), `AI_EMBEDDINGS_MODEL` (for example, `"gemini-embedding-001"` or `"nomic-embed-text"`), and, for Gemini, either `AI_KEY` (for example, `"your-gemini-api-key"`) or both `AI_PROJECT` (for example, `"my-google-cloud-project"`) and `AI_LOCATION` (for example, `"us-central1"`). Values passed through `embeddings` override the corresponding environment values.
|
|
263
267
|
*
|
|
264
268
|
* Gemini, Vertex AI, and Ollama are supported. The selected provider and model must match those used to create the stored embedding column so the vectors share the same dimensions and embedding space.
|
|
265
269
|
*
|
|
@@ -280,13 +284,17 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
280
284
|
* @param options.efSearch - The number of candidate vertices to consider during search. Higher values result in more accurate searches but increase search time. Defaults to 64.
|
|
281
285
|
* @param options.M - The maximum number of neighbors to keep for each vertex in the graph. Higher values result in more accurate indexes but increase build time and memory usage. Defaults to 16.
|
|
282
286
|
* @param options.outputTable - The name of the output table where the results will be stored. If not provided, the current table will be modified. Defaults to `undefined`.
|
|
283
|
-
* @param options.embeddings - Gemini or Ollama embedding configuration.
|
|
287
|
+
* @param options.embeddings - Optional Gemini or Ollama embedding configuration.
|
|
284
288
|
* @param options.verbose - If `true`, logs additional debugging information. Defaults to `false`.
|
|
285
289
|
* @returns The table that will contain the similarity results, so methods can be chained.
|
|
286
290
|
* @category AI
|
|
287
291
|
*
|
|
288
292
|
* @example
|
|
289
293
|
* ```ts
|
|
294
|
+
* // Set these environment variables before running:
|
|
295
|
+
* // AI_EMBEDDINGS_PROVIDER=gemini
|
|
296
|
+
* // AI_EMBEDDINGS_MODEL=gemini-embedding-001
|
|
297
|
+
* // AI_KEY=your-gemini-api-key
|
|
290
298
|
* const similarFood = await sdb
|
|
291
299
|
* .newTable("food")
|
|
292
300
|
* .loadArray([
|
|
@@ -297,18 +305,9 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
297
305
|
* { food: "salad" },
|
|
298
306
|
* { food: "tacos" },
|
|
299
307
|
* ])
|
|
300
|
-
* .aiEmbeddings("food", "embeddings"
|
|
301
|
-
* embeddings: {
|
|
302
|
-
* provider: "gemini",
|
|
303
|
-
* model: "gemini-embedding-001",
|
|
304
|
-
* },
|
|
305
|
-
* })
|
|
308
|
+
* .aiEmbeddings("food", "embeddings")
|
|
306
309
|
* .aiVectorSimilarity("italian food", "embeddings", 3, {
|
|
307
310
|
* createIndex: true,
|
|
308
|
-
* embeddings: {
|
|
309
|
-
* provider: "gemini",
|
|
310
|
-
* model: "gemini-embedding-001",
|
|
311
|
-
* },
|
|
312
311
|
* minSimilarity: 0.6,
|
|
313
312
|
* similarityColumn: "score",
|
|
314
313
|
* })
|
|
@@ -343,7 +342,9 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
343
342
|
*
|
|
344
343
|
* Remove `.journalism-cache` and `.sda-cache` to clear existing cache entries. Remember to add both directories to your `.gitignore`.
|
|
345
344
|
*
|
|
346
|
-
* This method supports Gemini, Vertex AI, and Ollama embeddings.
|
|
345
|
+
* This method supports Gemini, Vertex AI, and Ollama embeddings.
|
|
346
|
+
*
|
|
347
|
+
* Environment variables are named configuration values supplied to the running process. By default, this method reads `AI_EMBEDDINGS_PROVIDER` (`"gemini"` or `"ollama"`; defaults to `"gemini"`), `AI_EMBEDDINGS_MODEL` (for example, `"gemini-embedding-001"` or `"nomic-embed-text"`), and, for Gemini, either `AI_KEY` (for example, `"your-gemini-api-key"`) or both `AI_PROJECT` (for example, `"my-google-cloud-project"`) and `AI_LOCATION` (for example, `"us-central1"`). Values passed through `embeddings` override the corresponding environment values.
|
|
347
348
|
*
|
|
348
349
|
* The selected embedding provider is used for both stored row embeddings and the query embedding.
|
|
349
350
|
*
|
|
@@ -357,7 +358,7 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
357
358
|
* @param textColumn - The name of the column containing the text content to search through.
|
|
358
359
|
* @param nbResults - The number of most similar rows to retrieve.
|
|
359
360
|
* @param options - Configuration options for the hybrid search.
|
|
360
|
-
* @param options.embeddings - Gemini or Ollama embedding configuration.
|
|
361
|
+
* @param options.embeddings - Optional Gemini or Ollama embedding configuration.
|
|
361
362
|
* @param options.verbose - If `true`, logs additional debugging information. Defaults to `false`.
|
|
362
363
|
* @param options.createIndex - If `true`, creates an HNSW index when vector search is enabled. The BM25 FTS index is managed automatically whenever BM25 search is enabled. Defaults to `false`.
|
|
363
364
|
* @param options.efConstruction - The number of candidate vertices to consider during index construction. Higher values result in more accurate indexes but increase build time. Defaults to 128.
|
|
@@ -385,16 +386,16 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
385
386
|
*
|
|
386
387
|
* @example
|
|
387
388
|
* ```ts
|
|
389
|
+
* // Set these environment variables before running:
|
|
390
|
+
* // AI_EMBEDDINGS_PROVIDER=gemini
|
|
391
|
+
* // AI_EMBEDDINGS_MODEL=gemini-embedding-001
|
|
392
|
+
* // AI_KEY=your-gemini-api-key
|
|
388
393
|
* // Load a dataset of recipes
|
|
389
394
|
* const sdb = new SimpleDB();
|
|
390
395
|
* const results = await sdb
|
|
391
396
|
* .newTable("recipes")
|
|
392
397
|
* .loadData("recipes.parquet")
|
|
393
398
|
* .hybridSearch("buttery pastry for breakfast", "Dish", "Recipe", 10, {
|
|
394
|
-
* embeddings: {
|
|
395
|
-
* provider: "gemini",
|
|
396
|
-
* model: "gemini-embedding-001",
|
|
397
|
-
* },
|
|
398
399
|
* verbose: true,
|
|
399
400
|
* })
|
|
400
401
|
* .log();
|
|
@@ -422,9 +423,11 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
422
423
|
*
|
|
423
424
|
* Remove `.journalism-cache` and `.sda-cache` to clear existing cache entries. Remember to add both directories to your `.gitignore`.
|
|
424
425
|
*
|
|
425
|
-
* Generation and embeddings are independently configurable.
|
|
426
|
+
* Generation and embeddings are independently configurable.
|
|
427
|
+
*
|
|
428
|
+
* Environment variables are named configuration values supplied to the running process. By default, generation reads `AI_PROVIDER` (`"gemini"` or `"ollama"`; defaults to `"gemini"`) and `AI_MODEL` (for example, `"gemini-3-flash-preview"` or `"gemma3:4b"`), while embeddings read `AI_EMBEDDINGS_PROVIDER` (`"gemini"` or `"ollama"`; defaults to `"gemini"`) and `AI_EMBEDDINGS_MODEL` (for example, `"gemini-embedding-001"` or `"nomic-embed-text"`). Gemini generation and embeddings also read either `AI_KEY` (for example, `"your-gemini-api-key"`) or both `AI_PROJECT` (for example, `"my-google-cloud-project"`) and `AI_LOCATION` (for example, `"us-central1"`). Values passed through either option override its environment defaults.
|
|
426
429
|
*
|
|
427
|
-
* For example, `generation.provider` can be `"gemini"` while `embeddings.provider` is `"ollama"
|
|
430
|
+
* For example, `generation.provider` can be `"gemini"` while `embeddings.provider` is `"ollama"`; the same mix can be selected through `AI_PROVIDER=gemini` and `AI_EMBEDDINGS_PROVIDER=ollama`.
|
|
428
431
|
*
|
|
429
432
|
* Ollama temperature defaults to 0. Gemini uses the provider's default temperature.
|
|
430
433
|
*
|
|
@@ -437,8 +440,8 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
437
440
|
* @param textColumn - The name of the column containing the text content to search through and use as context.
|
|
438
441
|
* @param nbResults - The number of most similar rows to retrieve and use as context for the AI.
|
|
439
442
|
* @param options - Configuration options for the RAG process.
|
|
440
|
-
* @param options.generation - Gemini or Ollama generation configuration.
|
|
441
|
-
* @param options.embeddings - Gemini or Ollama embedding configuration.
|
|
443
|
+
* @param options.generation - Optional Gemini or Ollama generation configuration.
|
|
444
|
+
* @param options.embeddings - Optional Gemini or Ollama embedding configuration.
|
|
442
445
|
* @param options.verbose - If `true`, logs additional debugging information. Defaults to `false`.
|
|
443
446
|
* @param options.includeThoughts - If `true`, includes the AI model's reasoning process in the logged output when using models that support extended thinking. Only relevant when used with thinking-capable models. Defaults to `false`.
|
|
444
447
|
* @param options.metrics - An object to track cumulative metrics across multiple AI requests. Pass an object with totalCost, totalInputTokens, totalOutputTokens, and totalRequests properties (all initialized to 0). The function will update these values after each request. Note: totalCost is only calculated for Google GenAI models, not for Ollama.
|
|
@@ -466,6 +469,12 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
466
469
|
*
|
|
467
470
|
* @example
|
|
468
471
|
* ```ts
|
|
472
|
+
* // Set these environment variables before running:
|
|
473
|
+
* // AI_PROVIDER=gemini
|
|
474
|
+
* // AI_MODEL=gemini-3-flash-preview
|
|
475
|
+
* // AI_KEY=your-gemini-api-key
|
|
476
|
+
* // AI_EMBEDDINGS_PROVIDER=ollama
|
|
477
|
+
* // AI_EMBEDDINGS_MODEL=nomic-embed-text
|
|
469
478
|
* // Load a dataset of recipes
|
|
470
479
|
* const sdb = new SimpleDB();
|
|
471
480
|
* const answer = await sdb
|
|
@@ -476,17 +485,7 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
476
485
|
* "Dish", // Column with unique IDs
|
|
477
486
|
* "Recipe", // Column with text to search
|
|
478
487
|
* 10, // The 10 most relevant recipes passed to the LLM
|
|
479
|
-
* {
|
|
480
|
-
* generation: {
|
|
481
|
-
* provider: "gemini",
|
|
482
|
-
* model: "gemini-3-flash-preview",
|
|
483
|
-
* },
|
|
484
|
-
* embeddings: {
|
|
485
|
-
* provider: "ollama",
|
|
486
|
-
* model: "nomic-embed-text",
|
|
487
|
-
* },
|
|
488
|
-
* verbose: true, // Log debugging information and timings
|
|
489
|
-
* },
|
|
488
|
+
* { verbose: true }, // Log debugging information and timings
|
|
490
489
|
* );
|
|
491
490
|
*
|
|
492
491
|
* console.log(answer);
|
|
@@ -516,9 +515,9 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
516
515
|
* Generates and executes a SQL query based on a prompt.
|
|
517
516
|
* Additional instructions, such as column types, are automatically added to your prompt. Set `verbose` to `true` to see the full prompt.
|
|
518
517
|
*
|
|
519
|
-
* This method supports Gemini, Vertex AI, and Ollama.
|
|
518
|
+
* This method supports Gemini, Vertex AI, and Ollama.
|
|
520
519
|
*
|
|
521
|
-
*
|
|
520
|
+
* Environment variables are named configuration values supplied to the running process. By default, this method reads `AI_PROVIDER` (`"gemini"` or `"ollama"`; defaults to `"gemini"`), `AI_MODEL` (for example, `"gemini-3-flash-preview"` or `"gemma3:4b"`), and, for Gemini, either `AI_KEY` (for example, `"your-gemini-api-key"`) or both `AI_PROJECT` (for example, `"my-google-cloud-project"`) and `AI_LOCATION` (for example, `"us-central1"`). Values passed through `generation` override the corresponding environment values. When using Ollama, ensure it is running.
|
|
522
521
|
*
|
|
523
522
|
* Ollama temperature defaults to 0, while Gemini uses the provider's default. Provider-specific controls live under `generation`.
|
|
524
523
|
*
|
|
@@ -528,7 +527,7 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
528
527
|
* @param prompt - The input string to guide the AI in generating the SQL query.
|
|
529
528
|
* @param options - Configuration options for the AI request.
|
|
530
529
|
* @param options.extraInstructions - Additional instructions to append to the prompt, providing more context or guidance for the AI.
|
|
531
|
-
* @param options.generation - Gemini or Ollama generation configuration.
|
|
530
|
+
* @param options.generation - Optional Gemini or Ollama generation configuration.
|
|
532
531
|
* @param options.outputTable - The name of a new table where the results will be stored. If not provided, the current table will be replaced with the query results.
|
|
533
532
|
* @param options.verbose - If `true`, logs additional debugging information, including the full prompt sent to the AI. Defaults to `false`.
|
|
534
533
|
* @param options.includeThoughts - If `true`, includes the AI model's reasoning process in the logged output when using models that support extended thinking. Only relevant when used with thinking-capable models. Defaults to `false`.
|
|
@@ -537,17 +536,17 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
537
536
|
*
|
|
538
537
|
* @example
|
|
539
538
|
* ```ts
|
|
539
|
+
* // Set these environment variables before running:
|
|
540
|
+
* // AI_PROVIDER=gemini
|
|
541
|
+
* // AI_MODEL=gemini-3-flash-preview
|
|
542
|
+
* // AI_KEY=your-gemini-api-key
|
|
540
543
|
* // The AI will generate a query that will be executed, and
|
|
541
544
|
* // the result will replace the existing table.
|
|
542
545
|
* // If run again, it will use the previous query from the cache.
|
|
543
546
|
* // Don't forget to add .journalism-cache to your .gitignore file!
|
|
544
547
|
* const averageSalaryByDepartment = await table
|
|
545
548
|
* .aiQuery("Give me the average salary by department", {
|
|
546
|
-
*
|
|
547
|
-
* provider: "gemini",
|
|
548
|
-
* model: "gemini-3-flash-preview",
|
|
549
|
-
* },
|
|
550
|
-
* verbose: true,
|
|
549
|
+
* verbose: true,
|
|
551
550
|
* })
|
|
552
551
|
* .log();
|
|
553
552
|
* ```
|
|
@@ -586,7 +585,9 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
586
585
|
* Writes the table data to a Google Sheet.
|
|
587
586
|
* This method uses the `pushToSheet` function from the [journalism-google library](https://jsr.io/@nshiab/journalism-google). Refer to its documentation for more details.
|
|
588
587
|
*
|
|
589
|
-
* By default, the selected tab is overwritten and values are written without Google Sheets interpretation.
|
|
588
|
+
* By default, the selected tab is overwritten and values are written without Google Sheets interpretation.
|
|
589
|
+
*
|
|
590
|
+
* Environment variables are named configuration values supplied to the running process. For authentication, this method reads `GOOGLE_SERVICE_ACCOUNT_EMAIL` (for example, `"service-account@example.iam.gserviceaccount.com"`) with `GOOGLE_PRIVATE_KEY` (for example, `"-----BEGIN PRIVATE KEY-----\n..."`). Alternatively, set `GOOGLE_APPLICATION_CREDENTIALS` to a service-account JSON path (for example, `"./service-account.json"`). Values passed through `options.credentials` override these environment values. For detailed setup instructions, refer to the node-google-spreadsheet authentication guide: https://theoephraim.github.io/node-google-spreadsheet/#/guides/authentication.
|
|
590
591
|
*
|
|
591
592
|
* @param sheetUrl - A Google Sheets URL. It can point to a spreadsheet or a specific tab.
|
|
592
593
|
* @param options - An optional object with configuration options:
|
|
@@ -596,7 +597,7 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
596
597
|
* @param options.prepend - Text to add above the header row in overwrite mode.
|
|
597
598
|
* @param options.lastUpdate - If `true`, adds a UTC timestamp. Pass a Canadian time zone to use it for the timestamp. Available only in overwrite mode.
|
|
598
599
|
* @param options.raw - If `true`, writes values without Google Sheets interpretation. Defaults to `true`.
|
|
599
|
-
* @param options.credentials -
|
|
600
|
+
* @param options.credentials - Optional Google service-account credentials.
|
|
600
601
|
* @param options.credentials.email - The Google service-account email.
|
|
601
602
|
* @param options.credentials.privateKey - The Google service-account private key.
|
|
602
603
|
* @returns A promise that resolves when the data has been written to the sheet.
|
|
@@ -604,6 +605,9 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
604
605
|
*
|
|
605
606
|
* @example
|
|
606
607
|
* ```ts
|
|
608
|
+
* // Set these environment variables before running:
|
|
609
|
+
* // GOOGLE_SERVICE_ACCOUNT_EMAIL=service-account@example.iam.gserviceaccount.com
|
|
610
|
+
* // GOOGLE_PRIVATE_KEY=-----BEGIN PRIVATE KEY-----\n...
|
|
607
611
|
* // Load, transform, and write data to a Google Sheet
|
|
608
612
|
* await sdb
|
|
609
613
|
* .newTable()
|
|
@@ -664,19 +668,22 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
664
668
|
* Loads data from a Google Sheet into the table.
|
|
665
669
|
* This method uses the `getSheetData` function from the [journalism library](https://jsr.io/@nshiab/journalism). Refer to its documentation for more details.
|
|
666
670
|
*
|
|
667
|
-
*
|
|
671
|
+
* Environment variables are named configuration values supplied to the running process. By default, this method reads `GOOGLE_SERVICE_ACCOUNT_EMAIL` (for example, `"service-account@example.iam.gserviceaccount.com"`) with `GOOGLE_PRIVATE_KEY` (for example, `"-----BEGIN PRIVATE KEY-----\n..."`). Alternatively, set `GOOGLE_APPLICATION_CREDENTIALS` to a service-account JSON path (for example, `"./service-account.json"`).
|
|
668
672
|
* The download is queued and runs in chain order at the next awaited observer or `run()` call.
|
|
669
673
|
*
|
|
670
674
|
* @param sheetUrl - The URL pointing to a specific Google Sheet (e.g., `"https://docs.google.com/spreadsheets/d/.../edit#gid=0"`).
|
|
671
675
|
* @param options - An optional object with configuration options:
|
|
672
676
|
* @param options.skip - The number of rows to skip from the top of the sheet before reading data. Useful when the sheet contains metadata or headers that should not be included in the data.
|
|
673
|
-
* @param options.apiEmailEnvVar -
|
|
674
|
-
* @param options.apiKeyEnvVar -
|
|
677
|
+
* @param options.apiEmailEnvVar - A custom environment-variable name from which to read the Google service-account email. Defaults to `"GOOGLE_SERVICE_ACCOUNT_EMAIL"`.
|
|
678
|
+
* @param options.apiKeyEnvVar - A custom environment-variable name from which to read the Google service-account private key. Defaults to `"GOOGLE_PRIVATE_KEY"`.
|
|
675
679
|
* @returns The table, so methods can be chained.
|
|
676
680
|
* @category Loading Data
|
|
677
681
|
*
|
|
678
682
|
* @example
|
|
679
683
|
* ```ts
|
|
684
|
+
* // Set these environment variables before running:
|
|
685
|
+
* // GOOGLE_SERVICE_ACCOUNT_EMAIL=service-account@example.iam.gserviceaccount.com
|
|
686
|
+
* // GOOGLE_PRIVATE_KEY=-----BEGIN PRIVATE KEY-----\n...
|
|
680
687
|
* // Load data from a Google Sheet
|
|
681
688
|
* const sheetData = await sdb
|
|
682
689
|
* .newTable("sheetData")
|
|
@@ -702,11 +709,11 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
702
709
|
/**
|
|
703
710
|
* Writes the table data as CSV to a Datawrapper chart or table.
|
|
704
711
|
*
|
|
705
|
-
*
|
|
712
|
+
* Environment variables are named configuration values supplied to the running process. By default, this method reads the API key from `DATAWRAPPER_KEY` (for example, `"your-datawrapper-api-key"`).
|
|
706
713
|
*
|
|
707
714
|
* @param chartId - The unique ID of the Datawrapper chart or table to update. This ID can be found in the Datawrapper URL or dashboard.
|
|
708
715
|
* @param options - An optional object with configuration options:
|
|
709
|
-
* @param options.apiKeyEnvVar -
|
|
716
|
+
* @param options.apiKeyEnvVar - A custom environment-variable name from which to read the Datawrapper API key. Defaults to `"DATAWRAPPER_KEY"`.
|
|
710
717
|
* @param options.note - A string to update the chart's notes field with (e.g., a last-updated timestamp).
|
|
711
718
|
* @param options.republish - If `true`, republishes the chart after updating the data. Defaults to `false`.
|
|
712
719
|
* @returns A promise that resolves when the data has been sent to Datawrapper.
|
|
@@ -714,6 +721,7 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
714
721
|
*
|
|
715
722
|
* @example
|
|
716
723
|
* ```ts
|
|
724
|
+
* // Set DATAWRAPPER_KEY=your-datawrapper-api-key before running.
|
|
717
725
|
* // Load, transform, and send data to a Datawrapper chart
|
|
718
726
|
* await sdb
|
|
719
727
|
* .newTable()
|
|
@@ -737,17 +745,18 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
737
745
|
/**
|
|
738
746
|
* Loads data from a Datawrapper chart or table into the table.
|
|
739
747
|
*
|
|
740
|
-
*
|
|
748
|
+
* Environment variables are named configuration values supplied to the running process. By default, this method reads the API key from `DATAWRAPPER_KEY` (for example, `"your-datawrapper-api-key"`).
|
|
741
749
|
* The download is queued and runs in chain order at the next awaited observer or `run()` call.
|
|
742
750
|
*
|
|
743
751
|
* @param chartId - The unique ID of the Datawrapper chart or table. This ID can be found in the Datawrapper URL or dashboard.
|
|
744
752
|
* @param options - An optional object with configuration options:
|
|
745
|
-
* @param options.apiKeyEnvVar -
|
|
753
|
+
* @param options.apiKeyEnvVar - A custom environment-variable name from which to read the Datawrapper API key. Defaults to `"DATAWRAPPER_KEY"`.
|
|
746
754
|
* @returns The table, so methods can be chained.
|
|
747
755
|
* @category Loading Data
|
|
748
756
|
*
|
|
749
757
|
* @example
|
|
750
758
|
* ```ts
|
|
759
|
+
* // Set DATAWRAPPER_KEY=your-datawrapper-api-key before running.
|
|
751
760
|
* // Load data from a Datawrapper chart
|
|
752
761
|
* const chartData = await sdb
|
|
753
762
|
* .newTable("chartData")
|
|
@@ -762,11 +771,11 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
762
771
|
/**
|
|
763
772
|
* Writes the table's geospatial data as GeoJSON to a Datawrapper map.
|
|
764
773
|
*
|
|
765
|
-
*
|
|
774
|
+
* Environment variables are named configuration values supplied to the running process. By default, this method reads the API key from `DATAWRAPPER_KEY` (for example, `"your-datawrapper-api-key"`).
|
|
766
775
|
*
|
|
767
776
|
* @param chartId - The unique ID of the Datawrapper map to update. This ID can be found in the Datawrapper URL or dashboard.
|
|
768
777
|
* @param options - An optional object with configuration options:
|
|
769
|
-
* @param options.apiKeyEnvVar -
|
|
778
|
+
* @param options.apiKeyEnvVar - A custom environment-variable name from which to read the Datawrapper API key. Defaults to `"DATAWRAPPER_KEY"`.
|
|
770
779
|
* @param options.column - The name of the geometry column to use. If omitted, the method will automatically attempt to find a geometry column.
|
|
771
780
|
* @param options.note - A string to update the map's notes field with.
|
|
772
781
|
* @param options.republish - If `true`, republishes the map after updating the data. Defaults to `false`.
|
|
@@ -775,6 +784,7 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
775
784
|
*
|
|
776
785
|
* @example
|
|
777
786
|
* ```ts
|
|
787
|
+
* // Set DATAWRAPPER_KEY=your-datawrapper-api-key before running.
|
|
778
788
|
* // Load, transform, and send geospatial data to a Datawrapper map
|
|
779
789
|
* await sdb
|
|
780
790
|
* .newTable()
|
|
@@ -798,19 +808,20 @@ export default class SimpleTable extends SimpleTableCore {
|
|
|
798
808
|
/**
|
|
799
809
|
* Loads geospatial data from a Datawrapper map into the table.
|
|
800
810
|
*
|
|
801
|
-
*
|
|
811
|
+
* Environment variables are named configuration values supplied to the running process. By default, this method reads the API key from `DATAWRAPPER_KEY` (for example, `"your-datawrapper-api-key"`).
|
|
802
812
|
*
|
|
803
813
|
* The data is temporarily written to `.sda-cache/tmp/dataviz/<uuid>.geojson` and removed after loading. Remember to add `.sda-cache` to your `.gitignore`.
|
|
804
814
|
* The download is queued and runs in chain order at the next awaited observer or `run()` call.
|
|
805
815
|
*
|
|
806
816
|
* @param chartId - The unique ID of the Datawrapper map. This ID can be found in the Datawrapper URL or dashboard.
|
|
807
817
|
* @param options - An optional object with configuration options:
|
|
808
|
-
* @param options.apiKeyEnvVar -
|
|
818
|
+
* @param options.apiKeyEnvVar - A custom environment-variable name from which to read the Datawrapper API key. Defaults to `"DATAWRAPPER_KEY"`.
|
|
809
819
|
* @returns The table, so methods can be chained.
|
|
810
820
|
* @category Loading Data
|
|
811
821
|
*
|
|
812
822
|
* @example
|
|
813
823
|
* ```ts
|
|
824
|
+
* // Set DATAWRAPPER_KEY=your-datawrapper-api-key before running.
|
|
814
825
|
* // Load geo data from a Datawrapper map
|
|
815
826
|
* const mapData = await sdb
|
|
816
827
|
* .newTable("mapData")
|