@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 +6 -0
- package/dist/database/index.d.ts +8 -0
- package/dist/index.js +40 -22
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/database/index.d.ts
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
23474
|
-
|
|
23475
|
-
|
|
23476
|
-
|
|
23477
|
-
|
|
23478
|
-
|
|
23479
|
-
|
|
23480
|
-
|
|
23481
|
-
|
|
23482
|
-
|
|
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
|
-
|
|
23488
|
-
|
|
23489
|
-
|
|
23490
|
-
|
|
23491
|
-
|
|
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
|
-
|
|
23495
|
-
|
|
23496
|
-
|
|
23497
|
-
|
|
23498
|
-
|
|
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);
|