@tinacms/graphql 0.60.0 → 0.60.3

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,28 @@
1
1
  # tina-graphql
2
2
 
3
+ ## 0.60.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 79d112d79: Update cli to accept tinaCloudMediaStore flag and add to metadata during schema compilation
8
+ - 3f46c6706: Fixed issue where generated SDK would not work with templates
9
+ - db9168578: Adds support for an `assetsHost` when resolving `image` fields with `useRelativeMedia`
10
+ - 91d6e6758: Fix issues with experimentalData on windows related to path separator inconsistency and interference with the .tina/**generated** folder
11
+
12
+ ## 0.60.2
13
+
14
+ ### Patch Changes
15
+
16
+ - 08cdb672a: Adds `useRelativeMedia` support to local graphql client
17
+ - fdbfe9a16: Fixes issue where on windows documents could not be deleted localy
18
+ - 6e2ed31a2: Added `isTitle` property to the schema that allows the title to be displayed in the CMS
19
+
20
+ ## 0.60.1
21
+
22
+ ### Patch Changes
23
+
24
+ - 3b11ff6ad: Add optional indexing status callback to Database
25
+
3
26
  ## 0.60.0
4
27
 
5
28
  ### Minor Changes
package/dist/build.d.ts CHANGED
@@ -12,8 +12,9 @@ limitations under the License.
12
12
  */
13
13
  import type { TinaSchema } from './schema';
14
14
  import { Database } from './database';
15
- export declare const indexDB: ({ database, config, buildSDK, }: {
15
+ export declare const indexDB: ({ database, config, flags, buildSDK, }: {
16
16
  database: Database;
17
17
  config: TinaSchema['config'];
18
+ flags?: string[];
18
19
  buildSDK?: boolean;
19
20
  }) => Promise<void>;
@@ -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;
@@ -14,3 +14,4 @@ import * as yup from 'yup';
14
14
  export declare const stringifyFile: (content: object, format: FormatType | string, keepTemplateKey: boolean) => string;
15
15
  export declare const parseFile: <T extends object>(content: string, format: FormatType | string, yupSchema: (args: typeof yup) => yup.ObjectSchema<any>) => T;
16
16
  export declare type FormatType = 'json' | 'md' | 'mdx' | 'markdown';
17
+ export declare const normalizePath: (filepath: string) => string;
package/dist/index.d.ts CHANGED
@@ -20,7 +20,7 @@ export type { Store } from '@tinacms/datalayer';
20
20
  export type { Bridge } from './database/bridge';
21
21
  export { sequential, assertShape } from './util';
22
22
  export { stringifyFile, parseFile } from './database/util';
23
- export declare const buildSchema: (rootPath: string, database: Database) => Promise<import("graphql").GraphQLSchema>;
23
+ export declare const buildSchema: (rootPath: string, database: Database, flags?: string[]) => Promise<import("graphql").GraphQLSchema>;
24
24
  import type { TinaCloudSchema as TinaCloudSchemaBase, TinaCloudCollection as TinaCloudCollectionBase, TinaCloudTemplateBase as TinaTemplate, TinaFieldBase } from './types';
25
25
  export declare type TinaCloudSchema = TinaCloudSchemaBase<false>;
26
26
  export declare type TinaSchema = TinaCloudSchema;
package/dist/index.js CHANGED
@@ -10911,15 +10911,31 @@ var astBuilder = {
10911
10911
  selectionSet: {
10912
10912
  kind: "SelectionSet",
10913
10913
  selections: [
10914
- SysFieldDefinition,
10915
10914
  {
10916
- kind: "Field",
10917
- name: {
10918
- kind: "Name",
10919
- value: "id"
10915
+ kind: "InlineFragment",
10916
+ typeCondition: {
10917
+ kind: "NamedType",
10918
+ name: {
10919
+ kind: "Name",
10920
+ value: "Document"
10921
+ }
10920
10922
  },
10921
- arguments: [],
10922
- directives: []
10923
+ directives: [],
10924
+ selectionSet: {
10925
+ kind: "SelectionSet",
10926
+ selections: [
10927
+ SysFieldDefinition,
10928
+ {
10929
+ kind: "Field",
10930
+ name: {
10931
+ kind: "Name",
10932
+ value: "id"
10933
+ },
10934
+ arguments: [],
10935
+ directives: []
10936
+ }
10937
+ ]
10938
+ }
10923
10939
  },
10924
10940
  {
10925
10941
  kind: "FragmentSpread",
@@ -10995,15 +11011,31 @@ var astBuilder = {
10995
11011
  kind: "SelectionSet",
10996
11012
  selections: [
10997
11013
  {
10998
- kind: "Field",
10999
- name: {
11000
- kind: "Name",
11001
- value: "id"
11014
+ kind: "InlineFragment",
11015
+ typeCondition: {
11016
+ kind: "NamedType",
11017
+ name: {
11018
+ kind: "Name",
11019
+ value: "Document"
11020
+ }
11002
11021
  },
11003
- arguments: [],
11004
- directives: []
11022
+ directives: [],
11023
+ selectionSet: {
11024
+ kind: "SelectionSet",
11025
+ selections: [
11026
+ SysFieldDefinition,
11027
+ {
11028
+ kind: "Field",
11029
+ name: {
11030
+ kind: "Name",
11031
+ value: "id"
11032
+ },
11033
+ arguments: [],
11034
+ directives: []
11035
+ }
11036
+ ]
11037
+ }
11005
11038
  },
11006
- SysFieldDefinition,
11007
11039
  {
11008
11040
  kind: "FragmentSpread",
11009
11041
  name: {
@@ -11264,6 +11296,11 @@ var scalarDefinitions = [
11264
11296
  required: true,
11265
11297
  type: astBuilder.TYPES.String
11266
11298
  }),
11299
+ astBuilder.FieldDefinition({
11300
+ name: "title",
11301
+ required: false,
11302
+ type: astBuilder.TYPES.String
11303
+ }),
11267
11304
  astBuilder.FieldDefinition({
11268
11305
  name: "basename",
11269
11306
  required: true,
@@ -12443,7 +12480,7 @@ var validateField = async (field) => {
12443
12480
 
12444
12481
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/package.json
12445
12482
  var name = "@tinacms/graphql";
12446
- var version = "0.60.0";
12483
+ var version = "0.60.3";
12447
12484
  var main = "dist/index.js";
12448
12485
  var typings = "dist/index.d.ts";
12449
12486
  var files = [
@@ -12485,7 +12522,8 @@ var scripts = {
12485
12522
  build: 'echo "Run `yarn build` from the root of the repository instead"',
12486
12523
  docs: "yarn typedoc",
12487
12524
  serve: "yarn nodemon dist/server.js",
12488
- test: "jest"
12525
+ test: "jest",
12526
+ "test-watch": "jest --watch"
12489
12527
  };
12490
12528
  var dependencies = {
12491
12529
  "@graphql-tools/relay-operation-optimizer": "^6.4.1",
@@ -12540,6 +12578,7 @@ var repository = {
12540
12578
  };
12541
12579
  var devDependencies = {
12542
12580
  "@tinacms/datalayer": "workspace:*",
12581
+ "@tinacms/schema-tools": "workspace:*",
12543
12582
  "@tinacms/scripts": "workspace:*",
12544
12583
  "@types/cors": "^2.8.7",
12545
12584
  "@types/estree": "^0.0.50",
@@ -12563,6 +12602,9 @@ var devDependencies = {
12563
12602
  nodemon: "^2.0.4",
12564
12603
  typescript: "^4.3.5"
12565
12604
  };
12605
+ var peerDependencies = {
12606
+ "@tinacms/schema-tools": "*"
12607
+ };
12566
12608
  var package_default = {
12567
12609
  name,
12568
12610
  version,
@@ -12575,7 +12617,8 @@ var package_default = {
12575
12617
  dependencies,
12576
12618
  publishConfig,
12577
12619
  repository,
12578
- devDependencies
12620
+ devDependencies,
12621
+ peerDependencies
12579
12622
  };
12580
12623
 
12581
12624
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/resolver/error.ts
@@ -12763,11 +12806,13 @@ var import_path = __toModule(require("path"));
12763
12806
  var indexDB = async ({
12764
12807
  database,
12765
12808
  config,
12809
+ flags = [],
12766
12810
  buildSDK = true
12767
12811
  }) => {
12768
- const flags = [];
12769
12812
  if (database.store.supportsIndexing()) {
12770
- flags.push("experimentalData");
12813
+ if (flags.indexOf("experimentalData") === -1) {
12814
+ flags.push("experimentalData");
12815
+ }
12771
12816
  }
12772
12817
  const tinaSchema = await createSchema({ schema: config, flags });
12773
12818
  const builder = await createBuilder({
@@ -22452,15 +22497,11 @@ var createResolver2 = (args) => {
22452
22497
  var Resolver = class {
22453
22498
  constructor(init) {
22454
22499
  this.init = init;
22455
- this.resolveCollection = async (collectionName, hasDocuments) => {
22500
+ this.resolveCollection = async (args, collectionName, hasDocuments) => {
22456
22501
  const collection = this.tinaSchema.getCollection(collectionName);
22457
22502
  const extraFields = {};
22458
- let documents = {};
22459
- if (hasDocuments) {
22460
- documents = await this.getDocumentsForCollection(collectionName);
22461
- }
22462
22503
  return __spreadValues(__spreadValues({
22463
- documents
22504
+ documents: { collection, hasDocuments }
22464
22505
  }, collection), extraFields);
22465
22506
  };
22466
22507
  this.getDocument = async (fullPath) => {
@@ -22486,11 +22527,19 @@ var Resolver = class {
22486
22527
  _template: rawData._template
22487
22528
  };
22488
22529
  await sequential(template.fields, async (field) => this.resolveFieldData(field, rawData, data));
22530
+ const titleField = template.fields.find((x) => {
22531
+ if (x.type === "string" && (x == null ? void 0 : x.isTitle)) {
22532
+ return true;
22533
+ }
22534
+ });
22535
+ const titleFieldName = titleField == null ? void 0 : titleField.name;
22536
+ const title = data[titleFieldName || " "] || null;
22489
22537
  return __spreadProps(__spreadValues({
22490
22538
  __typename: collection.fields ? NAMER.documentTypeName(collection.namespace) : NAMER.documentTypeName(template.namespace),
22491
22539
  id: fullPath
22492
22540
  }, data), {
22493
22541
  _sys: {
22542
+ title,
22494
22543
  basename,
22495
22544
  filename,
22496
22545
  extension: extension2,
@@ -22835,9 +22884,19 @@ var Resolver = class {
22835
22884
  case "boolean":
22836
22885
  case "number":
22837
22886
  case "reference":
22838
- case "image":
22839
22887
  accumulator[field.name] = value;
22840
22888
  break;
22889
+ case "image":
22890
+ if (this.config) {
22891
+ if (this.config.useRelativeMedia === true) {
22892
+ accumulator[field.name] = value;
22893
+ } else {
22894
+ accumulator[field.name] = `https://${this.config.assetsHost}/${this.config.clientId}/${value}`;
22895
+ }
22896
+ } else {
22897
+ accumulator[field.name] = value;
22898
+ }
22899
+ break;
22841
22900
  case "rich-text":
22842
22901
  const tree = parseMDX(value, field);
22843
22902
  accumulator[field.name] = tree;
@@ -22903,6 +22962,7 @@ var Resolver = class {
22903
22962
  }));
22904
22963
  return args.params;
22905
22964
  };
22965
+ this.config = init.config;
22906
22966
  this.database = init.database;
22907
22967
  this.tinaSchema = init.tinaSchema;
22908
22968
  }
@@ -22939,6 +22999,7 @@ var resolveDateInput = (value) => {
22939
22999
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/resolve.ts
22940
23000
  var import_relay_operation_optimizer = __toModule(require("@graphql-tools/relay-operation-optimizer"));
22941
23001
  var resolve = async ({
23002
+ config,
22942
23003
  query,
22943
23004
  variables,
22944
23005
  database,
@@ -22947,9 +23008,11 @@ var resolve = async ({
22947
23008
  try {
22948
23009
  const graphQLSchemaAst = await database.getGraphQLSchema();
22949
23010
  const graphQLSchema = (0, import_graphql3.buildASTSchema)(graphQLSchemaAst);
22950
- const config = await database.getTinaSchema();
22951
- const tinaSchema = await createSchema({ schema: config });
22952
- const resolver2 = await createResolver2({ database, tinaSchema });
23011
+ const tinaConfig = await database.getTinaSchema();
23012
+ const tinaSchema = await createSchema({
23013
+ schema: tinaConfig
23014
+ });
23015
+ const resolver2 = await createResolver2({ config, database, tinaSchema });
22953
23016
  const res = await (0, import_graphql3.graphql)({
22954
23017
  schema: graphQLSchema,
22955
23018
  source: query,
@@ -22985,7 +23048,7 @@ var resolve = async ({
22985
23048
  return ((_a = x == null ? void 0 : x.name) == null ? void 0 : _a.value) === "documents";
22986
23049
  });
22987
23050
  return tinaSchema.getCollections().map((collection) => {
22988
- return resolver2.resolveCollection(collection.name, Boolean(hasDocuments2));
23051
+ return resolver2.resolveCollection(args, collection.name, Boolean(hasDocuments2));
22989
23052
  });
22990
23053
  }
22991
23054
  const collectionNode = info.fieldNodes.find((x) => x.name.value === "collection");
@@ -22993,7 +23056,7 @@ var resolve = async ({
22993
23056
  var _a;
22994
23057
  return ((_a = x == null ? void 0 : x.name) == null ? void 0 : _a.value) === "documents";
22995
23058
  });
22996
- return resolver2.resolveCollection(args.collection, Boolean(hasDocuments));
23059
+ return resolver2.resolveCollection(args, args.collection, Boolean(hasDocuments));
22997
23060
  }
22998
23061
  if (info.fieldName === "getOptimizedQuery") {
22999
23062
  try {
@@ -23054,6 +23117,11 @@ var resolve = async ({
23054
23117
  return { node: document3 };
23055
23118
  })
23056
23119
  };
23120
+ } else if (info.fieldName === "documents" && (value == null ? void 0 : value.collection) && (value == null ? void 0 : value.hasDocuments)) {
23121
+ return resolver2.resolveCollectionConnection({
23122
+ args,
23123
+ collection: value.collection
23124
+ });
23057
23125
  } else {
23058
23126
  throw new Error(`Expected an array for result of ${info.fieldName} at ${info.path}`);
23059
23127
  }
@@ -23175,6 +23243,7 @@ var parseFile = (content3, format, yupSchema) => {
23175
23243
  throw new Error(`Must specify a valid format, got ${format}`);
23176
23244
  }
23177
23245
  };
23246
+ var normalizePath = (filepath) => filepath.replace(/\\/g, "/");
23178
23247
 
23179
23248
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/database/index.ts
23180
23249
  var import_datalayer2 = __toModule(require("@tinacms/datalayer"));
@@ -23186,12 +23255,13 @@ var createDatabase = async (config) => {
23186
23255
  };
23187
23256
  var SYSTEM_FILES = ["_schema", "_graphql", "_lookup"];
23188
23257
  var GENERATED_FOLDER = import_path4.default.join(".tina", "__generated__");
23258
+ var defaultStatusCallback = () => Promise.resolve();
23189
23259
  var Database = class {
23190
23260
  constructor(config) {
23191
23261
  this.config = config;
23192
23262
  this.collectionForPath = async (filepath) => {
23193
23263
  const tinaSchema = await this.getSchema();
23194
- const collection = tinaSchema.schema.collections.find((collection2) => filepath.startsWith(collection2.path));
23264
+ const collection = await tinaSchema.getCollectionByFullPath(filepath);
23195
23265
  return collection;
23196
23266
  };
23197
23267
  this.get = async (filepath) => {
@@ -23200,7 +23270,7 @@ var Database = class {
23200
23270
  } else {
23201
23271
  const tinaSchema = await this.getSchema();
23202
23272
  const extension2 = import_path4.default.extname(filepath);
23203
- const contentObject = await this.store.get(filepath);
23273
+ const contentObject = await this.store.get(normalizePath(filepath));
23204
23274
  if (!contentObject) {
23205
23275
  throw new import_graphql4.GraphQLError(`Unable to find record ${filepath}`);
23206
23276
  }
@@ -23240,9 +23310,9 @@ var Database = class {
23240
23310
  collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
23241
23311
  }
23242
23312
  if (this.store.supportsSeeding()) {
23243
- await this.bridge.put(filepath, stringifiedFile);
23313
+ await this.bridge.put(normalizePath(filepath), stringifiedFile);
23244
23314
  }
23245
- await this.store.put(filepath, payload, {
23315
+ await this.store.put(normalizePath(filepath), payload, {
23246
23316
  keepTemplateKey,
23247
23317
  collection: collection == null ? void 0 : collection.name,
23248
23318
  indexDefinitions: collectionIndexDefinitions
@@ -23259,9 +23329,9 @@ var Database = class {
23259
23329
  }
23260
23330
  const { stringifiedFile, payload, keepTemplateKey } = await this.stringifyFile(filepath, data);
23261
23331
  if (this.store.supportsSeeding()) {
23262
- await this.bridge.put(filepath, stringifiedFile);
23332
+ await this.bridge.put(normalizePath(filepath), stringifiedFile);
23263
23333
  }
23264
- await this.store.put(filepath, payload, {
23334
+ await this.store.put(normalizePath(filepath), payload, {
23265
23335
  keepTemplateKey,
23266
23336
  collection,
23267
23337
  indexDefinitions: collectionIndexDefinitions
@@ -23326,23 +23396,23 @@ var Database = class {
23326
23396
  this.getLookup = async (returnType) => {
23327
23397
  const lookupPath = import_path4.default.join(GENERATED_FOLDER, `_lookup.json`);
23328
23398
  if (!this._lookup) {
23329
- const _lookup = await this.store.get(lookupPath);
23399
+ const _lookup = await this.store.get(normalizePath(lookupPath));
23330
23400
  this._lookup = _lookup;
23331
23401
  }
23332
23402
  return this._lookup[returnType];
23333
23403
  };
23334
23404
  this.getGraphQLSchema = async () => {
23335
23405
  const graphqlPath = import_path4.default.join(GENERATED_FOLDER, `_graphql.json`);
23336
- return this.store.get(graphqlPath);
23406
+ return this.store.get(normalizePath(graphqlPath));
23337
23407
  };
23338
23408
  this.getGraphQLSchemaFromBridge = async () => {
23339
23409
  const graphqlPath = import_path4.default.join(GENERATED_FOLDER, `_graphql.json`);
23340
- const _graphql = await this.bridge.get(graphqlPath);
23410
+ const _graphql = await this.bridge.get(normalizePath(graphqlPath));
23341
23411
  return JSON.parse(_graphql);
23342
23412
  };
23343
23413
  this.getTinaSchema = async () => {
23344
23414
  const schemaPath = import_path4.default.join(GENERATED_FOLDER, `_schema.json`);
23345
- return this.store.get(schemaPath);
23415
+ return this.store.get(normalizePath(schemaPath));
23346
23416
  };
23347
23417
  this.getSchema = async () => {
23348
23418
  if (this.tinaSchema) {
@@ -23462,59 +23532,64 @@ var Database = class {
23462
23532
  tinaSchema
23463
23533
  }) => {
23464
23534
  if (this.bridge.supportsBuilding()) {
23465
- await this.bridge.putConfig(import_path4.default.join(GENERATED_FOLDER, `_graphql.json`), JSON.stringify(graphQLSchema));
23466
- await this.bridge.putConfig(import_path4.default.join(GENERATED_FOLDER, `_schema.json`), JSON.stringify(tinaSchema.schema));
23535
+ await this.bridge.putConfig(normalizePath(import_path4.default.join(GENERATED_FOLDER, `_graphql.json`)), JSON.stringify(graphQLSchema));
23536
+ await this.bridge.putConfig(normalizePath(import_path4.default.join(GENERATED_FOLDER, `_schema.json`)), JSON.stringify(tinaSchema.schema));
23467
23537
  }
23468
23538
  };
23469
23539
  this.indexContent = async ({
23470
23540
  graphQLSchema,
23471
23541
  tinaSchema
23472
23542
  }) => {
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`);
23543
+ await this.indexStatusCallbackWrapper(async () => {
23544
+ const lookup = JSON.parse(await this.bridge.get(normalizePath(import_path4.default.join(GENERATED_FOLDER, "_lookup.json"))));
23545
+ if (this.store.supportsSeeding()) {
23546
+ await this.store.clear();
23547
+ await this.store.seed(normalizePath(import_path4.default.join(GENERATED_FOLDER, "_graphql.json")), graphQLSchema);
23548
+ await this.store.seed(normalizePath(import_path4.default.join(GENERATED_FOLDER, "_schema.json")), tinaSchema.schema);
23549
+ await this.store.seed(normalizePath(import_path4.default.join(GENERATED_FOLDER, "_lookup.json")), lookup);
23550
+ await this._indexAllContent();
23551
+ } else {
23552
+ if (this.store.supportsIndexing()) {
23553
+ throw new Error(`Schema must be indexed with provided Store`);
23554
+ }
23483
23555
  }
23484
- }
23556
+ });
23485
23557
  };
23486
23558
  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);
23559
+ await this.indexStatusCallbackWrapper(async () => {
23560
+ const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
23561
+ for (const collection of Object.keys(pathsByCollection)) {
23562
+ await _deleteIndexContent(this, pathsByCollection[collection], collections[collection]);
23563
+ }
23564
+ await _deleteIndexContent(this, nonCollectionPaths, null);
23565
+ });
23492
23566
  };
23493
23567
  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);
23568
+ await this.indexStatusCallbackWrapper(async () => {
23569
+ const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
23570
+ for (const collection of Object.keys(pathsByCollection)) {
23571
+ await _indexContent(this, pathsByCollection[collection], collections[collection]);
23572
+ }
23573
+ await _indexContent(this, nonCollectionPaths);
23574
+ });
23499
23575
  };
23500
23576
  this.delete = async (filepath) => {
23501
- const tinaSchema = await this.getSchema();
23502
- const collection = tinaSchema.schema.collections.find((collection2) => filepath.startsWith(collection2.path));
23577
+ const collection = await this.collectionForPath(filepath);
23503
23578
  let collectionIndexDefinitions;
23504
23579
  if (collection) {
23505
23580
  const indexDefinitions = await this.getIndexDefinitions();
23506
23581
  collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
23507
23582
  }
23508
- await this.store.delete(filepath, {
23583
+ await this.store.delete(normalizePath(filepath), {
23509
23584
  collection: collection.name,
23510
23585
  indexDefinitions: collectionIndexDefinitions
23511
23586
  });
23512
- await this.bridge.delete(filepath);
23587
+ await this.bridge.delete(normalizePath(filepath));
23513
23588
  };
23514
23589
  this._indexAllContent = async () => {
23515
23590
  const tinaSchema = await this.getSchema();
23516
23591
  await sequential(tinaSchema.getCollections(), async (collection) => {
23517
- const documentPaths = await this.bridge.glob(collection.path);
23592
+ const documentPaths = await this.bridge.glob(normalizePath(collection.path));
23518
23593
  await _indexContent(this, documentPaths, collection);
23519
23594
  });
23520
23595
  };
@@ -23522,17 +23597,18 @@ var Database = class {
23522
23597
  const lookupPath = import_path4.default.join(GENERATED_FOLDER, `_lookup.json`);
23523
23598
  let lookupMap;
23524
23599
  try {
23525
- lookupMap = JSON.parse(await this.bridge.get(lookupPath));
23600
+ lookupMap = JSON.parse(await this.bridge.get(normalizePath(lookupPath)));
23526
23601
  } catch (e) {
23527
23602
  lookupMap = {};
23528
23603
  }
23529
23604
  const updatedLookup = __spreadProps(__spreadValues({}, lookupMap), {
23530
23605
  [lookup.type]: lookup
23531
23606
  });
23532
- await this.bridge.putConfig(lookupPath, JSON.stringify(updatedLookup));
23607
+ await this.bridge.putConfig(normalizePath(lookupPath), JSON.stringify(updatedLookup));
23533
23608
  };
23534
23609
  this.bridge = config.bridge;
23535
23610
  this.store = config.store;
23611
+ this.indexStatusCallback = config.indexStatusCallback || defaultStatusCallback;
23536
23612
  }
23537
23613
  async partitionPathsByCollection(documentPaths) {
23538
23614
  const pathsByCollection = {};
@@ -23552,6 +23628,16 @@ var Database = class {
23552
23628
  }
23553
23629
  return { pathsByCollection, nonCollectionPaths, collections };
23554
23630
  }
23631
+ async indexStatusCallbackWrapper(fn) {
23632
+ await this.indexStatusCallback({ status: "inprogress" });
23633
+ try {
23634
+ await fn();
23635
+ await this.indexStatusCallback({ status: "complete" });
23636
+ } catch (error) {
23637
+ await this.indexStatusCallback({ status: "failed", error });
23638
+ throw error;
23639
+ }
23640
+ }
23555
23641
  };
23556
23642
  function hasOwnProperty2(obj, prop) {
23557
23643
  return obj.hasOwnProperty(prop);
@@ -23574,10 +23660,10 @@ var _indexContent = async (database, documentPaths, collection) => {
23574
23660
  };
23575
23661
  }
23576
23662
  await sequential(documentPaths, async (filepath) => {
23577
- const dataString = await database.bridge.get(filepath);
23663
+ const dataString = await database.bridge.get(normalizePath(filepath));
23578
23664
  const data = parseFile(dataString, import_path4.default.extname(filepath), (yup3) => yup3.object({}));
23579
23665
  if (database.store.supportsSeeding()) {
23580
- await database.store.seed(filepath, data, seedOptions);
23666
+ await database.store.seed(normalizePath(filepath), data, seedOptions);
23581
23667
  }
23582
23668
  });
23583
23669
  };
@@ -23600,11 +23686,11 @@ var _deleteIndexContent = async (database, documentPaths, collection) => {
23600
23686
  };
23601
23687
 
23602
23688
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/index.ts
23603
- var buildSchema = async (rootPath, database) => {
23689
+ var buildSchema = async (rootPath, database, flags) => {
23604
23690
  const tempConfig = import_path5.default.join(rootPath, ".tina", "__generated__", "config");
23605
23691
  const config = await import_fs_extra2.default.readFileSync(import_path5.default.join(tempConfig, "schema.json")).toString();
23606
23692
  await import_fs_extra2.default.rmdir(tempConfig, { recursive: true });
23607
- await indexDB({ database, config: JSON.parse(config) });
23693
+ await indexDB({ database, config: JSON.parse(config), flags });
23608
23694
  const gqlAst = await database.getGraphQLSchemaFromBridge();
23609
23695
  return (0, import_graphql5.buildASTSchema)(gqlAst);
23610
23696
  };
package/dist/resolve.d.ts CHANGED
@@ -11,7 +11,9 @@ See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
13
  import type { Database } from './database';
14
- export declare const resolve: ({ query, variables, database, silenceErrors, }: {
14
+ import type { GraphQLConfig } from './types';
15
+ export declare const resolve: ({ config, query, variables, database, silenceErrors, }: {
16
+ config?: GraphQLConfig;
15
17
  query: string;
16
18
  variables: object;
17
19
  database: Database;
@@ -11,10 +11,10 @@ See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
13
  import { Database } from '../database';
14
- import { TinaSchema } from '../schema';
15
- import type { Collectable, ReferenceTypeWithNamespace, TinaCloudCollection } from '../types';
16
- import { TinaFieldInner } from '../types';
14
+ import type { Collectable, ReferenceTypeWithNamespace, TinaCloudCollection, TinaFieldInner, TinaSchema } from '@tinacms/schema-tools';
15
+ import type { GraphQLConfig } from '../types';
17
16
  interface ResolverConfig {
17
+ config?: GraphQLConfig;
18
18
  database: Database;
19
19
  tinaSchema: TinaSchema;
20
20
  }
@@ -25,11 +25,12 @@ export declare const createResolver: (args: ResolverConfig) => Resolver;
25
25
  */
26
26
  export declare class Resolver {
27
27
  init: ResolverConfig;
28
+ config: GraphQLConfig;
28
29
  database: Database;
29
30
  tinaSchema: TinaSchema;
30
31
  constructor(init: ResolverConfig);
31
- resolveCollection: (collectionName: string, hasDocuments?: boolean) => Promise<{
32
- fields: string | TinaFieldInner<true>[];
32
+ resolveCollection: (args: any, collectionName: string, hasDocuments?: boolean) => Promise<{
33
+ fields: TinaFieldInner<true>[];
33
34
  templates?: undefined;
34
35
  references?: ReferenceTypeWithNamespace[];
35
36
  namespace: string[];
@@ -38,14 +39,18 @@ export declare class Resolver {
38
39
  path: string;
39
40
  format?: "json" | "md" | "markdown" | "mdx";
40
41
  match?: string;
41
- indexes?: import("../types").TinaIndex[];
42
- documents: {};
42
+ documents: {
43
+ collection: TinaCloudCollection<true>;
44
+ hasDocuments: boolean;
45
+ };
43
46
  } | {
44
47
  templates: (string | {
45
48
  label: string;
46
49
  name: string;
47
50
  fields: TinaFieldInner<true>[];
48
- ui?: object;
51
+ ui?: object | (import("@tinacms/schema-tools").UIField<any, any> & {
52
+ previewSrc: string;
53
+ });
49
54
  namespace: string[];
50
55
  })[];
51
56
  fields?: undefined;
@@ -56,11 +61,14 @@ export declare class Resolver {
56
61
  path: string;
57
62
  format?: "json" | "md" | "markdown" | "mdx";
58
63
  match?: string;
59
- indexes?: import("../types").TinaIndex[];
60
- documents: {};
64
+ documents: {
65
+ collection: TinaCloudCollection<true>;
66
+ hasDocuments: boolean;
67
+ };
61
68
  }>;
62
69
  getDocument: (fullPath: unknown) => Promise<{
63
70
  _sys: {
71
+ title: any;
64
72
  basename: string;
65
73
  filename: string;
66
74
  extension: string;
@@ -92,6 +100,7 @@ export declare class Resolver {
92
100
  isAddPendingDocument: boolean;
93
101
  }) => Promise<{
94
102
  _sys: {
103
+ title: any;
95
104
  basename: string;
96
105
  filename: string;
97
106
  extension: string;
@@ -118,6 +127,7 @@ export declare class Resolver {
118
127
  isCollectionSpecific: boolean;
119
128
  }) => Promise<{
120
129
  _sys: {
130
+ title: any;
121
131
  basename: string;
122
132
  filename: string;
123
133
  extension: string;
@@ -146,6 +156,7 @@ export declare class Resolver {
146
156
  isCollectionSpecific?: boolean;
147
157
  }) => Promise<{
148
158
  _sys: {
159
+ title: any;
149
160
  basename: string;
150
161
  filename: string;
151
162
  extension: string;
@@ -171,6 +182,7 @@ export declare class Resolver {
171
182
  edges: {
172
183
  node: {
173
184
  _sys: {
185
+ title: any;
174
186
  basename: string;
175
187
  filename: string;
176
188
  extension: string;
package/dist/types.d.ts CHANGED
@@ -263,4 +263,11 @@ export declare type Templateable = {
263
263
  fields: TinaFieldEnriched[];
264
264
  ui?: object;
265
265
  };
266
+ export declare type GraphQLConfig = {
267
+ useRelativeMedia: true;
268
+ } | {
269
+ useRelativeMedia: false;
270
+ clientId: string;
271
+ assetsHost: string;
272
+ };
266
273
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "0.60.0",
3
+ "version": "0.60.3",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -42,7 +42,8 @@
42
42
  "build": "echo \"Run `yarn build` from the root of the repository instead\"",
43
43
  "docs": "yarn typedoc",
44
44
  "serve": "yarn nodemon dist/server.js",
45
- "test": "jest"
45
+ "test": "jest",
46
+ "test-watch": "jest --watch"
46
47
  },
47
48
  "dependencies": {
48
49
  "@graphql-tools/relay-operation-optimizer": "^6.4.1",
@@ -97,6 +98,7 @@
97
98
  },
98
99
  "devDependencies": {
99
100
  "@tinacms/datalayer": "0.1.1",
101
+ "@tinacms/schema-tools": "0.0.4",
100
102
  "@tinacms/scripts": "0.50.7",
101
103
  "@types/cors": "^2.8.7",
102
104
  "@types/estree": "^0.0.50",
@@ -119,5 +121,8 @@
119
121
  "jest-matcher-utils": "27.0.6",
120
122
  "nodemon": "^2.0.4",
121
123
  "typescript": "^4.3.5"
124
+ },
125
+ "peerDependencies": {
126
+ "@tinacms/schema-tools": "*"
122
127
  }
123
128
  }