@tinacms/graphql 0.60.0 → 0.60.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # tina-graphql
2
2
 
3
+ ## 0.60.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 3b11ff6ad: Add optional indexing status callback to Database
8
+
3
9
  ## 0.60.0
4
10
 
5
11
  ### Minor Changes
@@ -15,9 +15,15 @@ import type { DocumentNode } from 'graphql';
15
15
  import type { TinaSchema } from '../schema';
16
16
  import type { TinaCloudSchemaBase } from '../types';
17
17
  import type { Bridge } from './bridge';
18
+ declare type IndexStatusEvent = {
19
+ status: 'inprogress' | 'complete' | 'failed';
20
+ error?: Error;
21
+ };
22
+ declare type IndexStatusCallback = (event: IndexStatusEvent) => Promise<void>;
18
23
  declare type CreateDatabase = {
19
24
  bridge: Bridge;
20
25
  store: Store;
26
+ indexStatusCallback?: IndexStatusCallback;
21
27
  };
22
28
  export declare const createDatabase: (config: CreateDatabase) => Promise<Database>;
23
29
  /** Options for {@link Database.query} **/
@@ -34,6 +40,7 @@ export declare class Database {
34
40
  config: CreateDatabase;
35
41
  bridge: Bridge;
36
42
  store: Store;
43
+ indexStatusCallback: IndexStatusCallback | undefined;
37
44
  private tinaSchema;
38
45
  private collectionIndexDefinitions;
39
46
  private _lookup;
@@ -82,6 +89,7 @@ export declare class Database {
82
89
  graphQLSchema: DocumentNode;
83
90
  tinaSchema: TinaSchema;
84
91
  }) => Promise<void>;
92
+ private indexStatusCallbackWrapper;
85
93
  indexContent: ({ graphQLSchema, tinaSchema, }: {
86
94
  graphQLSchema: DocumentNode;
87
95
  tinaSchema: TinaSchema;
package/dist/index.js CHANGED
@@ -12443,7 +12443,7 @@ var validateField = async (field) => {
12443
12443
 
12444
12444
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/package.json
12445
12445
  var name = "@tinacms/graphql";
12446
- var version = "0.60.0";
12446
+ var version = "0.60.1";
12447
12447
  var main = "dist/index.js";
12448
12448
  var typings = "dist/index.d.ts";
12449
12449
  var files = [
@@ -23186,6 +23186,7 @@ var createDatabase = async (config) => {
23186
23186
  };
23187
23187
  var SYSTEM_FILES = ["_schema", "_graphql", "_lookup"];
23188
23188
  var GENERATED_FOLDER = import_path4.default.join(".tina", "__generated__");
23189
+ var defaultStatusCallback = () => Promise.resolve();
23189
23190
  var Database = class {
23190
23191
  constructor(config) {
23191
23192
  this.config = config;
@@ -23470,32 +23471,38 @@ var Database = class {
23470
23471
  graphQLSchema,
23471
23472
  tinaSchema
23472
23473
  }) => {
23473
- const lookup = JSON.parse(await this.bridge.get(import_path4.default.join(GENERATED_FOLDER, "_lookup.json")));
23474
- if (this.store.supportsSeeding()) {
23475
- await this.store.clear();
23476
- await this.store.seed(import_path4.default.join(GENERATED_FOLDER, "_graphql.json"), graphQLSchema);
23477
- await this.store.seed(import_path4.default.join(GENERATED_FOLDER, "_schema.json"), tinaSchema.schema);
23478
- await this.store.seed(import_path4.default.join(GENERATED_FOLDER, "_lookup.json"), lookup);
23479
- await this._indexAllContent();
23480
- } else {
23481
- if (this.store.supportsIndexing()) {
23482
- throw new Error(`Schema must be indexed with provided Store`);
23474
+ await this.indexStatusCallbackWrapper(async () => {
23475
+ const lookup = JSON.parse(await this.bridge.get(import_path4.default.join(GENERATED_FOLDER, "_lookup.json")));
23476
+ if (this.store.supportsSeeding()) {
23477
+ await this.store.clear();
23478
+ await this.store.seed(import_path4.default.join(GENERATED_FOLDER, "_graphql.json"), graphQLSchema);
23479
+ await this.store.seed(import_path4.default.join(GENERATED_FOLDER, "_schema.json"), tinaSchema.schema);
23480
+ await this.store.seed(import_path4.default.join(GENERATED_FOLDER, "_lookup.json"), lookup);
23481
+ await this._indexAllContent();
23482
+ } else {
23483
+ if (this.store.supportsIndexing()) {
23484
+ throw new Error(`Schema must be indexed with provided Store`);
23485
+ }
23483
23486
  }
23484
- }
23487
+ });
23485
23488
  };
23486
23489
  this.deleteContentByPaths = async (documentPaths) => {
23487
- const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
23488
- for (const collection of Object.keys(pathsByCollection)) {
23489
- await _deleteIndexContent(this, pathsByCollection[collection], collections[collection]);
23490
- }
23491
- await _deleteIndexContent(this, nonCollectionPaths, null);
23490
+ await this.indexStatusCallbackWrapper(async () => {
23491
+ const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
23492
+ for (const collection of Object.keys(pathsByCollection)) {
23493
+ await _deleteIndexContent(this, pathsByCollection[collection], collections[collection]);
23494
+ }
23495
+ await _deleteIndexContent(this, nonCollectionPaths, null);
23496
+ });
23492
23497
  };
23493
23498
  this.indexContentByPaths = async (documentPaths) => {
23494
- const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
23495
- for (const collection of Object.keys(pathsByCollection)) {
23496
- await _indexContent(this, pathsByCollection[collection], collections[collection]);
23497
- }
23498
- await _indexContent(this, nonCollectionPaths);
23499
+ await this.indexStatusCallbackWrapper(async () => {
23500
+ const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
23501
+ for (const collection of Object.keys(pathsByCollection)) {
23502
+ await _indexContent(this, pathsByCollection[collection], collections[collection]);
23503
+ }
23504
+ await _indexContent(this, nonCollectionPaths);
23505
+ });
23499
23506
  };
23500
23507
  this.delete = async (filepath) => {
23501
23508
  const tinaSchema = await this.getSchema();
@@ -23533,6 +23540,7 @@ var Database = class {
23533
23540
  };
23534
23541
  this.bridge = config.bridge;
23535
23542
  this.store = config.store;
23543
+ this.indexStatusCallback = config.indexStatusCallback || defaultStatusCallback;
23536
23544
  }
23537
23545
  async partitionPathsByCollection(documentPaths) {
23538
23546
  const pathsByCollection = {};
@@ -23552,6 +23560,16 @@ var Database = class {
23552
23560
  }
23553
23561
  return { pathsByCollection, nonCollectionPaths, collections };
23554
23562
  }
23563
+ async indexStatusCallbackWrapper(fn) {
23564
+ await this.indexStatusCallback({ status: "inprogress" });
23565
+ try {
23566
+ await fn();
23567
+ await this.indexStatusCallback({ status: "complete" });
23568
+ } catch (error) {
23569
+ await this.indexStatusCallback({ status: "failed", error });
23570
+ throw error;
23571
+ }
23572
+ }
23555
23573
  };
23556
23574
  function hasOwnProperty2(obj, prop) {
23557
23575
  return obj.hasOwnProperty(prop);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "0.60.0",
3
+ "version": "0.60.1",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [