@tinacms/graphql 0.59.11 → 0.60.2

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/dist/index.js CHANGED
@@ -603,10 +603,10 @@ var require_util_events_to_acorn = __commonJS({
603
603
  }
604
604
  if (estree) {
605
605
  estree.comments = comments;
606
- visit3(estree);
606
+ visit2(estree);
607
607
  }
608
608
  return { estree, error: exception, swallow };
609
- function visit3(esnode) {
609
+ function visit2(esnode) {
610
610
  var point3;
611
611
  var key2;
612
612
  var index3;
@@ -632,10 +632,10 @@ var require_util_events_to_acorn = __commonJS({
632
632
  if ("length" in esnode[key2]) {
633
633
  index3 = -1;
634
634
  while (++index3 < esnode[key2].length) {
635
- visit3(esnode[key2][index3]);
635
+ visit2(esnode[key2][index3]);
636
636
  }
637
637
  } else {
638
- visit3(esnode[key2]);
638
+ visit2(esnode[key2]);
639
639
  }
640
640
  }
641
641
  }
@@ -10244,7 +10244,7 @@ var require_to_markdown2 = __commonJS({
10244
10244
  var phrasing = require_container_phrasing();
10245
10245
  var checkQuote2 = require_check_quote();
10246
10246
  var eol2 = /\r?\n|\r/g;
10247
- function mdxElement2(node, _6, context) {
10247
+ function mdxElement2(node, _4, context) {
10248
10248
  var selfClosing = node.name && (!node.children || !node.children.length);
10249
10249
  var quote = checkQuote2(context);
10250
10250
  var exit2 = context.enter(node.type);
@@ -10404,11 +10404,49 @@ var import_graphql2 = __toModule(require("graphql"));
10404
10404
 
10405
10405
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/ast-builder/index.ts
10406
10406
  var import_lodash = __toModule(require("lodash"));
10407
+
10408
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/util.ts
10409
+ var yup = __toModule(require("yup"));
10410
+ var import_graphql = __toModule(require("graphql"));
10411
+ var sequential = async (items, callback) => {
10412
+ const accum = [];
10413
+ if (!items) {
10414
+ return [];
10415
+ }
10416
+ const reducePromises = async (previous2, endpoint) => {
10417
+ const prev = await previous2;
10418
+ if (prev) {
10419
+ accum.push(prev);
10420
+ }
10421
+ return callback(endpoint, accum.length);
10422
+ };
10423
+ const result = await items.reduce(reducePromises, Promise.resolve());
10424
+ if (result) {
10425
+ accum.push(result);
10426
+ }
10427
+ return accum;
10428
+ };
10429
+ function assertShape(value, yupSchema, errorMessage) {
10430
+ const shape = yupSchema(yup);
10431
+ try {
10432
+ shape.validateSync(value);
10433
+ } catch (e) {
10434
+ const message = errorMessage || `Failed to assertShape - ${e.message}`;
10435
+ throw new import_graphql.GraphQLError(message, null, null, null, null, null, {
10436
+ stack: e.stack
10437
+ });
10438
+ }
10439
+ }
10440
+ var lastItem = (arr) => {
10441
+ return arr[arr.length - 1];
10442
+ };
10443
+
10444
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/ast-builder/index.ts
10407
10445
  var SysFieldDefinition = {
10408
10446
  kind: "Field",
10409
10447
  name: {
10410
10448
  kind: "Name",
10411
- value: "sys"
10449
+ value: "_sys"
10412
10450
  },
10413
10451
  arguments: [],
10414
10452
  directives: [],
@@ -10884,26 +10922,12 @@ var astBuilder = {
10884
10922
  directives: []
10885
10923
  },
10886
10924
  {
10887
- kind: "Field",
10925
+ kind: "FragmentSpread",
10888
10926
  name: {
10889
10927
  kind: "Name",
10890
- value: "data"
10928
+ value: fragName
10891
10929
  },
10892
- arguments: [],
10893
- directives: [],
10894
- selectionSet: {
10895
- kind: "SelectionSet",
10896
- selections: [
10897
- {
10898
- kind: "FragmentSpread",
10899
- name: {
10900
- kind: "Name",
10901
- value: fragName
10902
- },
10903
- directives: []
10904
- }
10905
- ]
10906
- }
10930
+ directives: []
10907
10931
  }
10908
10932
  ]
10909
10933
  }
@@ -10981,26 +11005,12 @@ var astBuilder = {
10981
11005
  },
10982
11006
  SysFieldDefinition,
10983
11007
  {
10984
- kind: "Field",
11008
+ kind: "FragmentSpread",
10985
11009
  name: {
10986
11010
  kind: "Name",
10987
- value: "data"
11011
+ value: fragName
10988
11012
  },
10989
- arguments: [],
10990
- directives: [],
10991
- selectionSet: {
10992
- kind: "SelectionSet",
10993
- selections: [
10994
- {
10995
- kind: "FragmentSpread",
10996
- name: {
10997
- kind: "Name",
10998
- value: fragName
10999
- },
11000
- directives: []
11001
- }
11002
- ]
11003
- }
11013
+ directives: []
11004
11014
  }
11005
11015
  ]
11006
11016
  }
@@ -11125,16 +11135,28 @@ var NAMER = {
11125
11135
  return generateNamespacedFieldName(namespace, "Mutation");
11126
11136
  },
11127
11137
  updateName: (namespace) => {
11128
- return "update" + generateNamespacedFieldName(namespace, "Document");
11138
+ return `update${generateNamespacedFieldName(namespace)}`;
11129
11139
  },
11130
11140
  createName: (namespace) => {
11131
- return "create" + generateNamespacedFieldName(namespace, "Document");
11141
+ return `create${generateNamespacedFieldName(namespace)}`;
11142
+ },
11143
+ documentQueryName: () => {
11144
+ return "document";
11145
+ },
11146
+ documentConnectionQueryName: () => {
11147
+ return "documentConnection";
11148
+ },
11149
+ collectionQueryName: () => {
11150
+ return "collection";
11151
+ },
11152
+ collectionListQueryName: () => {
11153
+ return "collections";
11132
11154
  },
11133
11155
  queryName: (namespace) => {
11134
- return "get" + generateNamespacedFieldName(namespace, "Document");
11156
+ return String(lastItem(namespace));
11135
11157
  },
11136
11158
  generateQueryListName: (namespace) => {
11137
- return "get" + generateNamespacedFieldName(namespace, "List");
11159
+ return `${lastItem(namespace)}Connection`;
11138
11160
  },
11139
11161
  fragmentName: (namespace) => {
11140
11162
  return generateNamespacedFieldName(namespace, "") + "Parts";
@@ -11143,7 +11165,7 @@ var NAMER = {
11143
11165
  return generateNamespacedFieldName(namespace, "Collection");
11144
11166
  },
11145
11167
  documentTypeName: (namespace) => {
11146
- return generateNamespacedFieldName(namespace, "Document");
11168
+ return generateNamespacedFieldName(namespace);
11147
11169
  },
11148
11170
  dataTypeName: (namespace) => {
11149
11171
  return generateNamespacedFieldName(namespace, "");
@@ -11156,42 +11178,6 @@ var NAMER = {
11156
11178
  }
11157
11179
  };
11158
11180
 
11159
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/util.ts
11160
- var yup = __toModule(require("yup"));
11161
- var import_graphql = __toModule(require("graphql"));
11162
- var sequential = async (items, callback) => {
11163
- const accum = [];
11164
- if (!items) {
11165
- return [];
11166
- }
11167
- const reducePromises = async (previous2, endpoint) => {
11168
- const prev = await previous2;
11169
- if (prev) {
11170
- accum.push(prev);
11171
- }
11172
- return callback(endpoint, accum.length);
11173
- };
11174
- const result = await items.reduce(reducePromises, Promise.resolve());
11175
- if (result) {
11176
- accum.push(result);
11177
- }
11178
- return accum;
11179
- };
11180
- function assertShape(value, yupSchema, errorMessage) {
11181
- const shape = yupSchema(yup);
11182
- try {
11183
- shape.validateSync(value);
11184
- } catch (e) {
11185
- const message = errorMessage || `Failed to assertShape - ${e.message}`;
11186
- throw new import_graphql.GraphQLError(message, null, null, null, null, null, {
11187
- stack: e.stack
11188
- });
11189
- }
11190
- }
11191
- var lastItem = (arr) => {
11192
- return arr[arr.length - 1];
11193
- };
11194
-
11195
11181
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/builder/static-definitions.ts
11196
11182
  var interfaceDefinitions = [
11197
11183
  astBuilder.InterfaceTypeDefinition({
@@ -11207,22 +11193,17 @@ var interfaceDefinitions = [
11207
11193
  astBuilder.InterfaceTypeDefinition({
11208
11194
  name: "Document",
11209
11195
  fields: [
11210
- astBuilder.FieldDefinition({
11211
- name: "sys",
11212
- type: astBuilder.TYPES.SystemInfo
11213
- }),
11214
11196
  astBuilder.FieldDefinition({
11215
11197
  name: "id",
11216
11198
  type: astBuilder.TYPES.ID,
11217
11199
  required: true
11218
11200
  }),
11219
11201
  astBuilder.FieldDefinition({
11220
- name: "form",
11221
- type: astBuilder.TYPES.JSON,
11222
- required: true
11202
+ name: "_sys",
11203
+ type: astBuilder.TYPES.SystemInfo
11223
11204
  }),
11224
11205
  astBuilder.FieldDefinition({
11225
- name: "values",
11206
+ name: "_values",
11226
11207
  type: astBuilder.TYPES.JSON,
11227
11208
  required: true
11228
11209
  })
@@ -11236,6 +11217,35 @@ var interfaceDefinitions = [
11236
11217
  name: "totalCount",
11237
11218
  required: true,
11238
11219
  type: astBuilder.TYPES.Number
11220
+ }),
11221
+ astBuilder.FieldDefinition({
11222
+ name: "pageInfo",
11223
+ required: true,
11224
+ type: astBuilder.ObjectTypeDefinition({
11225
+ name: "PageInfo",
11226
+ fields: [
11227
+ astBuilder.FieldDefinition({
11228
+ name: "hasPreviousPage",
11229
+ required: true,
11230
+ type: astBuilder.TYPES.Boolean
11231
+ }),
11232
+ astBuilder.FieldDefinition({
11233
+ name: "hasNextPage",
11234
+ required: true,
11235
+ type: astBuilder.TYPES.Boolean
11236
+ }),
11237
+ astBuilder.FieldDefinition({
11238
+ name: "startCursor",
11239
+ required: true,
11240
+ type: astBuilder.TYPES.String
11241
+ }),
11242
+ astBuilder.FieldDefinition({
11243
+ name: "endCursor",
11244
+ required: true,
11245
+ type: astBuilder.TYPES.String
11246
+ })
11247
+ ]
11248
+ })
11239
11249
  })
11240
11250
  ]
11241
11251
  })
@@ -11254,6 +11264,11 @@ var scalarDefinitions = [
11254
11264
  required: true,
11255
11265
  type: astBuilder.TYPES.String
11256
11266
  }),
11267
+ astBuilder.FieldDefinition({
11268
+ name: "title",
11269
+ required: false,
11270
+ type: astBuilder.TYPES.String
11271
+ }),
11257
11272
  astBuilder.FieldDefinition({
11258
11273
  name: "basename",
11259
11274
  required: true,
@@ -11337,7 +11352,7 @@ var Builder = class {
11337
11352
  constructor(config) {
11338
11353
  this.config = config;
11339
11354
  this.buildCollectionDefinition = async (collections) => {
11340
- const name2 = "getCollection";
11355
+ const name2 = "collection";
11341
11356
  const typeName = "Collection";
11342
11357
  const args = [
11343
11358
  astBuilder.InputValueDefinition({
@@ -11406,7 +11421,7 @@ var Builder = class {
11406
11421
  });
11407
11422
  };
11408
11423
  this.buildMultiCollectionDefinition = async (collections) => {
11409
- const name2 = "getCollections";
11424
+ const name2 = "collections";
11410
11425
  const typeName = "Collection";
11411
11426
  return astBuilder.FieldDefinition({
11412
11427
  type: typeName,
@@ -11436,7 +11451,7 @@ var Builder = class {
11436
11451
  });
11437
11452
  };
11438
11453
  this.multiCollectionDocument = async (collections) => {
11439
- const name2 = "getDocument";
11454
+ const name2 = "document";
11440
11455
  const args = [
11441
11456
  astBuilder.InputValueDefinition({
11442
11457
  name: "collection",
@@ -11459,13 +11474,6 @@ var Builder = class {
11459
11474
  required: true
11460
11475
  });
11461
11476
  };
11462
- this.multiCollectionDocumentFields = async () => {
11463
- return astBuilder.FieldDefinition({
11464
- name: "getDocumentFields",
11465
- required: true,
11466
- type: "JSON"
11467
- });
11468
- };
11469
11477
  this.addMultiCollectionDocumentMutation = async () => {
11470
11478
  return astBuilder.FieldDefinition({
11471
11479
  name: "addPendingDocument",
@@ -11563,15 +11571,6 @@ var Builder = class {
11563
11571
  type: astBuilder.TYPES.MultiCollectionDocument
11564
11572
  });
11565
11573
  };
11566
- this.multiCollectionDocumentList = async (collections) => {
11567
- return this._buildMultiCollectionDocumentListDefinition({
11568
- fieldName: "getDocumentList",
11569
- namespace: ["document"],
11570
- nodeType: astBuilder.TYPES.MultiCollectionDocument,
11571
- collections,
11572
- connectionNamespace: ["document"]
11573
- });
11574
- };
11575
11574
  this.collectionDocument = async (collection) => {
11576
11575
  const name2 = NAMER.queryName([collection.name]);
11577
11576
  const type = await this._buildCollectionDocumentType(collection);
@@ -11743,42 +11742,59 @@ var Builder = class {
11743
11742
  });
11744
11743
  };
11745
11744
  this.buildStaticDefinitions = () => staticDefinitions;
11746
- this._buildCollectionDocumentType = async (collection) => {
11745
+ this._buildCollectionDocumentType = async (collection, suffix = "", extraFields = [], extraInterfaces = []) => {
11747
11746
  const documentTypeName = NAMER.documentTypeName(collection.namespace);
11748
- return astBuilder.ObjectTypeDefinition({
11749
- name: documentTypeName,
11750
- interfaces: [
11751
- astBuilder.NamedType({ name: astBuilder.TYPES.Node }),
11752
- astBuilder.NamedType({ name: astBuilder.TYPES.Document })
11753
- ],
11754
- fields: [
11747
+ const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
11748
+ if (templateInfo.type === "union") {
11749
+ return this._buildObjectOrUnionData(__spreadValues({}, templateInfo), [
11755
11750
  astBuilder.FieldDefinition({
11756
11751
  name: "id",
11757
11752
  required: true,
11758
11753
  type: astBuilder.TYPES.ID
11759
11754
  }),
11760
11755
  astBuilder.FieldDefinition({
11761
- name: "sys",
11756
+ name: "_sys",
11762
11757
  required: true,
11763
11758
  type: astBuilder.TYPES.SystemInfo
11764
11759
  }),
11760
+ ...extraFields,
11765
11761
  astBuilder.FieldDefinition({
11766
- name: "data",
11762
+ name: "_values",
11767
11763
  required: true,
11768
- type: await this._buildObjectOrUnionData(this.tinaSchema.getTemplatesForCollectable(collection))
11769
- }),
11764
+ type: "JSON"
11765
+ })
11766
+ ], [
11767
+ astBuilder.NamedType({ name: astBuilder.TYPES.Node }),
11768
+ astBuilder.NamedType({ name: astBuilder.TYPES.Document }),
11769
+ ...extraInterfaces
11770
+ ], collection);
11771
+ }
11772
+ const fields = templateInfo.template.fields;
11773
+ const templateFields = await sequential(fields, async (field) => {
11774
+ return this._buildDataField(field);
11775
+ });
11776
+ return astBuilder.ObjectTypeDefinition({
11777
+ name: documentTypeName + suffix,
11778
+ interfaces: [
11779
+ astBuilder.NamedType({ name: astBuilder.TYPES.Node }),
11780
+ astBuilder.NamedType({ name: astBuilder.TYPES.Document }),
11781
+ ...extraInterfaces
11782
+ ],
11783
+ fields: [
11784
+ ...templateFields,
11770
11785
  astBuilder.FieldDefinition({
11771
- name: "form",
11786
+ name: "id",
11772
11787
  required: true,
11773
- type: "JSON"
11788
+ type: astBuilder.TYPES.ID
11774
11789
  }),
11775
11790
  astBuilder.FieldDefinition({
11776
- name: "values",
11791
+ name: "_sys",
11777
11792
  required: true,
11778
- type: "JSON"
11793
+ type: astBuilder.TYPES.SystemInfo
11779
11794
  }),
11795
+ ...extraFields,
11780
11796
  astBuilder.FieldDefinition({
11781
- name: "dataJSON",
11797
+ name: "_values",
11782
11798
  required: true,
11783
11799
  type: "JSON"
11784
11800
  })
@@ -11841,9 +11857,21 @@ var Builder = class {
11841
11857
  fieldName,
11842
11858
  collections
11843
11859
  }) => {
11844
- const types = collections.map((collection) => {
11845
- const typeName = NAMER.documentTypeName(collection.namespace);
11846
- return typeName;
11860
+ const types = [];
11861
+ collections.forEach((collection) => {
11862
+ if (collection.fields) {
11863
+ const typeName = NAMER.documentTypeName(collection.namespace);
11864
+ types.push(typeName);
11865
+ }
11866
+ if (collection.templates) {
11867
+ collection.templates.forEach((template) => {
11868
+ if (typeof template === "string") {
11869
+ throw new Error("Global templates not yet supported");
11870
+ }
11871
+ const typeName = NAMER.documentTypeName(template.namespace);
11872
+ types.push(typeName);
11873
+ });
11874
+ }
11847
11875
  });
11848
11876
  const type = astBuilder.UnionTypeDefinition({
11849
11877
  name: fieldName,
@@ -12092,18 +12120,19 @@ var Builder = class {
12092
12120
  })
12093
12121
  });
12094
12122
  };
12095
- this._buildObjectOrUnionData = async (collectableTemplate) => {
12123
+ this._buildObjectOrUnionData = async (collectableTemplate, extraFields = [], extraInterfaces = [], collection) => {
12096
12124
  if (collectableTemplate.type === "union") {
12097
12125
  const name2 = NAMER.dataTypeName(collectableTemplate.namespace);
12098
12126
  const typeMap = {};
12099
12127
  const types = await sequential(collectableTemplate.templates, async (template) => {
12100
- const type = await this._buildTemplateData(template);
12128
+ const type = await this._buildTemplateData(template, extraFields, extraInterfaces);
12101
12129
  typeMap[template.namespace[template.namespace.length - 1]] = type.name.value;
12102
12130
  return type;
12103
12131
  });
12104
12132
  await this.database.addToLookupMap({
12105
12133
  type: name2,
12106
12134
  resolveType: "unionData",
12135
+ collection: collection == null ? void 0 : collection.name,
12107
12136
  typeMap
12108
12137
  });
12109
12138
  return astBuilder.UnionTypeDefinition({ name: name2, types });
@@ -12168,6 +12197,7 @@ var Builder = class {
12168
12197
  fields: [
12169
12198
  astBuilder.FieldDefinition({
12170
12199
  name: "pageInfo",
12200
+ required: true,
12171
12201
  type: astBuilder.TYPES.PageInfo
12172
12202
  }),
12173
12203
  astBuilder.FieldDefinition({
@@ -12183,6 +12213,7 @@ var Builder = class {
12183
12213
  fields: [
12184
12214
  astBuilder.FieldDefinition({
12185
12215
  name: "cursor",
12216
+ required: true,
12186
12217
  type: astBuilder.TYPES.String
12187
12218
  }),
12188
12219
  astBuilder.FieldDefinition({ name: "node", type: nodeType })
@@ -12256,12 +12287,16 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
12256
12287
  }
12257
12288
  }
12258
12289
  };
12259
- this._buildTemplateData = async ({ namespace, fields }) => {
12290
+ this._buildTemplateData = async ({ namespace, fields }, extraFields = [], extraInterfaces = []) => {
12260
12291
  return astBuilder.ObjectTypeDefinition({
12261
12292
  name: NAMER.dataTypeName(namespace),
12262
- fields: await sequential(fields, async (field) => {
12263
- return this._buildDataField(field);
12264
- })
12293
+ interfaces: extraInterfaces || [],
12294
+ fields: [
12295
+ ...await sequential(fields, async (field) => {
12296
+ return this._buildDataField(field);
12297
+ }),
12298
+ ...extraFields
12299
+ ]
12265
12300
  });
12266
12301
  };
12267
12302
  this.tinaSchema = config.tinaSchema;
@@ -12413,7 +12448,7 @@ var validateField = async (field) => {
12413
12448
 
12414
12449
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/package.json
12415
12450
  var name = "@tinacms/graphql";
12416
- var version = "0.59.11";
12451
+ var version = "0.60.2";
12417
12452
  var main = "dist/index.js";
12418
12453
  var typings = "dist/index.d.ts";
12419
12454
  var files = [
@@ -12510,6 +12545,7 @@ var repository = {
12510
12545
  };
12511
12546
  var devDependencies = {
12512
12547
  "@tinacms/datalayer": "workspace:*",
12548
+ "@tinacms/schema-tools": "workspace:*",
12513
12549
  "@tinacms/scripts": "workspace:*",
12514
12550
  "@types/cors": "^2.8.7",
12515
12551
  "@types/estree": "^0.0.50",
@@ -12533,6 +12569,9 @@ var devDependencies = {
12533
12569
  nodemon: "^2.0.4",
12534
12570
  typescript: "^4.3.5"
12535
12571
  };
12572
+ var peerDependencies = {
12573
+ "@tinacms/schema-tools": "*"
12574
+ };
12536
12575
  var package_default = {
12537
12576
  name,
12538
12577
  version,
@@ -12545,7 +12584,8 @@ var package_default = {
12545
12584
  dependencies,
12546
12585
  publishConfig,
12547
12586
  repository,
12548
- devDependencies
12587
+ devDependencies,
12588
+ peerDependencies
12549
12589
  };
12550
12590
 
12551
12591
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/resolver/error.ts
@@ -12816,8 +12856,6 @@ var _buildSchema = async (builder, tinaSchema) => {
12816
12856
  mutationTypeDefinitionFields.push(await builder.buildUpdateCollectionDocumentMutation(collections));
12817
12857
  mutationTypeDefinitionFields.push(await builder.buildDeleteCollectionDocumentMutation(collections));
12818
12858
  mutationTypeDefinitionFields.push(await builder.buildCreateCollectionDocumentMutation(collections));
12819
- queryTypeDefinitionFields.push(await builder.multiCollectionDocumentList(collections));
12820
- queryTypeDefinitionFields.push(await builder.multiCollectionDocumentFields());
12821
12859
  await sequential(collections, async (collection) => {
12822
12860
  queryTypeDefinitionFields.push(await builder.collectionDocument(collection));
12823
12861
  mutationTypeDefinitionFields.push(await builder.updateCollectionDocumentMutation(collection));
@@ -12840,11 +12878,9 @@ var _buildSchema = async (builder, tinaSchema) => {
12840
12878
  };
12841
12879
 
12842
12880
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/resolve.ts
12843
- var import_lodash6 = __toModule(require("lodash"));
12844
12881
  var import_graphql3 = __toModule(require("graphql"));
12845
12882
 
12846
12883
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/resolver/index.ts
12847
- var import_lodash5 = __toModule(require("lodash"));
12848
12884
  var import_path3 = __toModule(require("path"));
12849
12885
  var import_isValid = __toModule(require_isValid());
12850
12886
 
@@ -18951,7 +18987,7 @@ function createTokenizer(parser, initialize, from) {
18951
18987
  function onsuccessfulconstruct(construct, info) {
18952
18988
  addResult(construct, info.from);
18953
18989
  }
18954
- function onsuccessfulcheck(_6, info) {
18990
+ function onsuccessfulcheck(_4, info) {
18955
18991
  info.restore();
18956
18992
  }
18957
18993
  function constructFactory(onreturn, fields) {
@@ -20094,12 +20130,12 @@ var visitParents = function(tree, test, visitor, reverse) {
20094
20130
  let name2;
20095
20131
  if (typeof value.type === "string") {
20096
20132
  name2 = typeof value.tagName === "string" ? value.tagName : typeof value.name === "string" ? value.name : void 0;
20097
- Object.defineProperty(visit3, "name", {
20133
+ Object.defineProperty(visit2, "name", {
20098
20134
  value: "node (" + color(value.type + (name2 ? "<" + name2 + ">" : "")) + ")"
20099
20135
  });
20100
20136
  }
20101
- return visit3;
20102
- function visit3() {
20137
+ return visit2;
20138
+ function visit2() {
20103
20139
  let result = [];
20104
20140
  let subresult;
20105
20141
  let offset;
@@ -20642,13 +20678,13 @@ function indentLines(value, map3) {
20642
20678
  }
20643
20679
 
20644
20680
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/blockquote.js
20645
- function blockquote(node, _6, context) {
20681
+ function blockquote(node, _4, context) {
20646
20682
  const exit2 = context.enter("blockquote");
20647
20683
  const value = indentLines(containerFlow(node, context), map);
20648
20684
  exit2();
20649
20685
  return value;
20650
20686
  }
20651
- function map(line, _6, blank) {
20687
+ function map(line, _4, blank) {
20652
20688
  return ">" + (blank ? "" : " ") + line;
20653
20689
  }
20654
20690
 
@@ -20673,7 +20709,7 @@ function listInScope(stack, list3, none) {
20673
20709
  }
20674
20710
 
20675
20711
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/break.js
20676
- function hardBreak(_6, _1, context, safe2) {
20712
+ function hardBreak(_4, _1, context, safe2) {
20677
20713
  let index2 = -1;
20678
20714
  while (++index2 < context.unsafe.length) {
20679
20715
  if (context.unsafe[index2].character === "\n" && patternInScope(context.stack, context.unsafe[index2])) {
@@ -20813,7 +20849,7 @@ function escapeBackslashes(value, after) {
20813
20849
  }
20814
20850
 
20815
20851
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/code.js
20816
- function code(node, _6, context) {
20852
+ function code(node, _4, context) {
20817
20853
  const marker = checkFence(context);
20818
20854
  const raw = node.value || "";
20819
20855
  const suffix = marker === "`" ? "GraveAccent" : "Tilde";
@@ -20854,7 +20890,7 @@ function code(node, _6, context) {
20854
20890
  exit2();
20855
20891
  return value;
20856
20892
  }
20857
- function map2(line, _6, blank) {
20893
+ function map2(line, _4, blank) {
20858
20894
  return (blank ? "" : " ") + line;
20859
20895
  }
20860
20896
 
@@ -20876,7 +20912,7 @@ function checkQuote(context) {
20876
20912
  }
20877
20913
 
20878
20914
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/definition.js
20879
- function definition2(node, _6, context) {
20915
+ function definition2(node, _4, context) {
20880
20916
  const marker = checkQuote(context);
20881
20917
  const suffix = marker === '"' ? "Quote" : "Apostrophe";
20882
20918
  const exit2 = context.enter("definition");
@@ -20945,7 +20981,7 @@ function containerPhrasing(parent, context, safeOptions) {
20945
20981
 
20946
20982
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/emphasis.js
20947
20983
  emphasis.peek = emphasisPeek;
20948
- function emphasis(node, _6, context) {
20984
+ function emphasis(node, _4, context) {
20949
20985
  const marker = checkEmphasis(context);
20950
20986
  const exit2 = context.enter("emphasis");
20951
20987
  const value = containerPhrasing(node, context, {
@@ -20955,7 +20991,7 @@ function emphasis(node, _6, context) {
20955
20991
  exit2();
20956
20992
  return marker + value + marker;
20957
20993
  }
20958
- function emphasisPeek(_6, _1, context) {
20994
+ function emphasisPeek(_4, _1, context) {
20959
20995
  return context.options.emphasis || "*";
20960
20996
  }
20961
20997
 
@@ -20972,7 +21008,7 @@ function formatHeadingAsSetext(node, context) {
20972
21008
  }
20973
21009
 
20974
21010
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/heading.js
20975
- function heading(node, _6, context) {
21011
+ function heading(node, _4, context) {
20976
21012
  const rank = Math.max(Math.min(6, node.depth || 1), 1);
20977
21013
  if (formatHeadingAsSetext(node, context)) {
20978
21014
  const exit3 = context.enter("headingSetext");
@@ -21009,7 +21045,7 @@ function htmlPeek() {
21009
21045
 
21010
21046
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/image.js
21011
21047
  image.peek = imagePeek;
21012
- function image(node, _6, context) {
21048
+ function image(node, _4, context) {
21013
21049
  const quote = checkQuote(context);
21014
21050
  const suffix = quote === '"' ? "Quote" : "Apostrophe";
21015
21051
  const exit2 = context.enter("image");
@@ -21042,7 +21078,7 @@ function imagePeek() {
21042
21078
 
21043
21079
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/image-reference.js
21044
21080
  imageReference.peek = imageReferencePeek;
21045
- function imageReference(node, _6, context) {
21081
+ function imageReference(node, _4, context) {
21046
21082
  const type = node.referenceType;
21047
21083
  const exit2 = context.enter("imageReference");
21048
21084
  let subexit = context.enter("label");
@@ -21069,7 +21105,7 @@ function imageReferencePeek() {
21069
21105
 
21070
21106
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/inline-code.js
21071
21107
  inlineCode.peek = inlineCodePeek;
21072
- function inlineCode(node, _6, context) {
21108
+ function inlineCode(node, _4, context) {
21073
21109
  let value = node.value || "";
21074
21110
  let sequence = "`";
21075
21111
  let index2 = -1;
@@ -21107,7 +21143,7 @@ function formatLinkAsAutolink(node, context) {
21107
21143
 
21108
21144
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/link.js
21109
21145
  link.peek = linkPeek;
21110
- function link(node, _6, context) {
21146
+ function link(node, _4, context) {
21111
21147
  const quote = checkQuote(context);
21112
21148
  const suffix = quote === '"' ? "Quote" : "Apostrophe";
21113
21149
  let exit2;
@@ -21146,13 +21182,13 @@ function link(node, _6, context) {
21146
21182
  exit2();
21147
21183
  return value;
21148
21184
  }
21149
- function linkPeek(node, _6, context) {
21185
+ function linkPeek(node, _4, context) {
21150
21186
  return formatLinkAsAutolink(node, context) ? "<" : "[";
21151
21187
  }
21152
21188
 
21153
21189
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/link-reference.js
21154
21190
  linkReference.peek = linkReferencePeek;
21155
- function linkReference(node, _6, context) {
21191
+ function linkReference(node, _4, context) {
21156
21192
  const type = node.referenceType;
21157
21193
  const exit2 = context.enter("linkReference");
21158
21194
  let subexit = context.enter("label");
@@ -21310,7 +21346,7 @@ function listItem(node, parent, context) {
21310
21346
  }
21311
21347
 
21312
21348
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/paragraph.js
21313
- function paragraph(node, _6, context) {
21349
+ function paragraph(node, _4, context) {
21314
21350
  const exit2 = context.enter("paragraph");
21315
21351
  const subexit = context.enter("phrasing");
21316
21352
  const value = containerPhrasing(node, context, { before: "\n", after: "\n" });
@@ -21320,7 +21356,7 @@ function paragraph(node, _6, context) {
21320
21356
  }
21321
21357
 
21322
21358
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/root.js
21323
- function root(node, _6, context) {
21359
+ function root(node, _4, context) {
21324
21360
  return containerFlow(node, context);
21325
21361
  }
21326
21362
 
@@ -21335,7 +21371,7 @@ function checkStrong(context) {
21335
21371
 
21336
21372
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/strong.js
21337
21373
  strong.peek = strongPeek;
21338
- function strong(node, _6, context) {
21374
+ function strong(node, _4, context) {
21339
21375
  const marker = checkStrong(context);
21340
21376
  const exit2 = context.enter("strong");
21341
21377
  const value = containerPhrasing(node, context, {
@@ -21345,12 +21381,12 @@ function strong(node, _6, context) {
21345
21381
  exit2();
21346
21382
  return marker + marker + value + marker + marker;
21347
21383
  }
21348
- function strongPeek(_6, _1, context) {
21384
+ function strongPeek(_4, _1, context) {
21349
21385
  return context.options.strong || "*";
21350
21386
  }
21351
21387
 
21352
21388
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/text.js
21353
- function text3(node, _6, context, safeOptions) {
21389
+ function text3(node, _4, context, safeOptions) {
21354
21390
  return safe(context, node.value, safeOptions);
21355
21391
  }
21356
21392
 
@@ -21364,7 +21400,7 @@ function checkRuleRepetition(context) {
21364
21400
  }
21365
21401
 
21366
21402
  // pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/mdast-util-to-markdown-npm-1.2.3-e27fe7fcf9-d50b5c4a9f.zip/node_modules/mdast-util-to-markdown/lib/handle/thematic-break.js
21367
- function thematicBreak2(_6, _1, context) {
21403
+ function thematicBreak2(_4, _1, context) {
21368
21404
  const value = (checkRule(context) + (context.options.ruleSpaces ? " " : "")).repeat(checkRuleRepetition(context));
21369
21405
  return context.options.ruleSpaces ? value.slice(0, -1) : value;
21370
21406
  }
@@ -21867,7 +21903,7 @@ var mdxJsxToMarkdown = {
21867
21903
  fences: true,
21868
21904
  resourceLink: true
21869
21905
  };
21870
- function mdxElement(node, _6, context) {
21906
+ function mdxElement(node, _4, context) {
21871
21907
  const selfClosing = node.name && (!node.children || node.children.length === 0);
21872
21908
  const quote = checkQuote(context);
21873
21909
  const exit2 = context.enter(node.type);
@@ -21903,7 +21939,7 @@ function peekElement() {
21903
21939
  }
21904
21940
  function indent(value) {
21905
21941
  return indentLines(value, map3);
21906
- function map3(line, _6, blank) {
21942
+ function map3(line, _4, blank) {
21907
21943
  return (blank ? "" : " ") + line;
21908
21944
  }
21909
21945
  }
@@ -22426,15 +22462,11 @@ var createResolver2 = (args) => {
22426
22462
  var Resolver = class {
22427
22463
  constructor(init) {
22428
22464
  this.init = init;
22429
- this.resolveCollection = async (collectionName, hasDocuments) => {
22465
+ this.resolveCollection = async (args, collectionName, hasDocuments) => {
22430
22466
  const collection = this.tinaSchema.getCollection(collectionName);
22431
22467
  const extraFields = {};
22432
- let documents = {};
22433
- if (hasDocuments) {
22434
- documents = await this.getDocumentsForCollection(collectionName);
22435
- }
22436
22468
  return __spreadValues(__spreadValues({
22437
- documents
22469
+ documents: { collection, hasDocuments }
22438
22470
  }, collection), extraFields);
22439
22471
  };
22440
22472
  this.getDocument = async (fullPath) => {
@@ -22455,22 +22487,24 @@ var Resolver = class {
22455
22487
  } = import_path3.default.parse(fullPath);
22456
22488
  const relativePath = fullPath.replace("\\", "/").replace(collection.path, "").replace(/^\/|\/$/g, "");
22457
22489
  const breadcrumbs = relativePath.replace(extension2, "").split("/");
22458
- const form = {
22459
- label: collection.label,
22460
- name: basename,
22461
- fields: await sequential(template.fields, async (field) => {
22462
- return this.resolveField(field);
22463
- })
22464
- };
22465
22490
  const data = {
22466
22491
  _collection: rawData._collection,
22467
22492
  _template: rawData._template
22468
22493
  };
22469
22494
  await sequential(template.fields, async (field) => this.resolveFieldData(field, rawData, data));
22470
- return {
22471
- __typename: NAMER.documentTypeName([rawData._collection]),
22472
- id: fullPath,
22473
- sys: {
22495
+ const titleField = template.fields.find((x) => {
22496
+ if (x.type === "string" && (x == null ? void 0 : x.isTitle)) {
22497
+ return true;
22498
+ }
22499
+ });
22500
+ const titleFieldName = titleField == null ? void 0 : titleField.name;
22501
+ const title = data[titleFieldName || " "] || null;
22502
+ return __spreadProps(__spreadValues({
22503
+ __typename: collection.fields ? NAMER.documentTypeName(collection.namespace) : NAMER.documentTypeName(template.namespace),
22504
+ id: fullPath
22505
+ }, data), {
22506
+ _sys: {
22507
+ title,
22474
22508
  basename,
22475
22509
  filename,
22476
22510
  extension: extension2,
@@ -22480,11 +22514,8 @@ var Resolver = class {
22480
22514
  collection,
22481
22515
  template: lastItem(template.namespace)
22482
22516
  },
22483
- data,
22484
- values: data,
22485
- dataJSON: data,
22486
- form
22487
- };
22517
+ _values: data
22518
+ });
22488
22519
  } catch (e) {
22489
22520
  if (e instanceof TinaError) {
22490
22521
  throw new TinaError(e.message, __spreadValues({
@@ -22500,51 +22531,6 @@ var Resolver = class {
22500
22531
  }
22501
22532
  await this.database.delete(fullPath);
22502
22533
  };
22503
- this.getDocumentFields = async () => {
22504
- try {
22505
- const response = {};
22506
- const collections = await this.tinaSchema.getCollections();
22507
- await sequential(collections, async (collection) => {
22508
- const collectable = this.tinaSchema.getTemplatesForCollectable(collection);
22509
- switch (collectable.type) {
22510
- case "object":
22511
- if (collectable.required) {
22512
- console.warn("WARNING: `{type: 'object', required: true}` is unsupported by our User Interface and could result in errors");
22513
- }
22514
- response[collection.name] = {
22515
- collection,
22516
- fields: await sequential(collectable.template.fields, async (field) => {
22517
- return this.resolveField(field);
22518
- }),
22519
- mutationInfo: {
22520
- includeCollection: true,
22521
- includeTemplate: false
22522
- }
22523
- };
22524
- break;
22525
- case "union":
22526
- const templates = {};
22527
- await sequential(collectable.templates, async (template) => {
22528
- templates[lastItem(template.namespace)] = {
22529
- template,
22530
- fields: await sequential(template.fields, async (field) => {
22531
- return this.resolveField(field);
22532
- })
22533
- };
22534
- });
22535
- response[collection.name] = {
22536
- collection,
22537
- templates,
22538
- mutationInfo: { includeCollection: true, includeTemplate: true }
22539
- };
22540
- break;
22541
- }
22542
- });
22543
- return response;
22544
- } catch (e) {
22545
- throw e;
22546
- }
22547
- };
22548
22534
  this.buildObjectMutations = (fieldValue, field) => {
22549
22535
  if (field.fields) {
22550
22536
  const objectTemplate = typeof field.fields === "string" ? this.tinaSchema.getGlobalTemplate(field.fields) : field;
@@ -22863,9 +22849,19 @@ var Resolver = class {
22863
22849
  case "boolean":
22864
22850
  case "number":
22865
22851
  case "reference":
22866
- case "image":
22867
22852
  accumulator[field.name] = value;
22868
22853
  break;
22854
+ case "image":
22855
+ if (this.config) {
22856
+ if (this.config.useRelativeMedia === true) {
22857
+ accumulator[field.name] = value;
22858
+ } else {
22859
+ accumulator[field.name] = `https://assets.tina.io/${this.config.clientId}/${value}`;
22860
+ }
22861
+ } else {
22862
+ accumulator[field.name] = value;
22863
+ }
22864
+ break;
22869
22865
  case "rich-text":
22870
22866
  const tree = parseMDX(value, field);
22871
22867
  accumulator[field.name] = tree;
@@ -22931,137 +22927,7 @@ var Resolver = class {
22931
22927
  }));
22932
22928
  return args.params;
22933
22929
  };
22934
- this.resolveField = async (_c) => {
22935
- var _d = _c, {
22936
- namespace
22937
- } = _d, field = __objRest(_d, [
22938
- "namespace"
22939
- ]);
22940
- field.parentTypename = NAMER.dataTypeName(namespace.filter((_6, i) => i < namespace.length - 1));
22941
- const extraFields = field.ui || {};
22942
- switch (field.type) {
22943
- case "number":
22944
- return __spreadValues(__spreadValues({
22945
- component: "number"
22946
- }, field), extraFields);
22947
- case "datetime":
22948
- return __spreadValues(__spreadValues({
22949
- component: "date"
22950
- }, field), extraFields);
22951
- case "boolean":
22952
- return __spreadValues(__spreadValues({
22953
- component: "toggle"
22954
- }, field), extraFields);
22955
- case "image":
22956
- return __spreadValues(__spreadValues({
22957
- component: "image",
22958
- clearable: true
22959
- }, field), extraFields);
22960
- case "string":
22961
- if (field.options) {
22962
- if (field.list) {
22963
- return __spreadProps(__spreadValues(__spreadValues({
22964
- component: "checkbox-group"
22965
- }, field), extraFields), {
22966
- options: field.options
22967
- });
22968
- }
22969
- return __spreadProps(__spreadValues(__spreadValues({
22970
- component: "select"
22971
- }, field), extraFields), {
22972
- options: [
22973
- { label: `Choose an option`, value: "" },
22974
- ...field.options
22975
- ]
22976
- });
22977
- }
22978
- if (field.list) {
22979
- return __spreadValues(__spreadValues({
22980
- component: "list",
22981
- field: {
22982
- component: "text"
22983
- }
22984
- }, field), extraFields);
22985
- }
22986
- return __spreadValues(__spreadValues({
22987
- component: "text"
22988
- }, field), extraFields);
22989
- case "object":
22990
- const templateInfo = this.tinaSchema.getTemplatesForCollectable(__spreadProps(__spreadValues({}, field), {
22991
- namespace
22992
- }));
22993
- if (templateInfo.type === "object") {
22994
- return __spreadValues(__spreadProps(__spreadValues({}, field), {
22995
- component: field.list ? "group-list" : "group",
22996
- fields: await sequential(templateInfo.template.fields, async (field2) => await this.resolveField(field2))
22997
- }), extraFields);
22998
- } else if (templateInfo.type === "union") {
22999
- const templates2 = {};
23000
- const typeMap2 = {};
23001
- await sequential(templateInfo.templates, async (template) => {
23002
- const extraFields2 = template.ui || {};
23003
- const templateName = lastItem(template.namespace);
23004
- typeMap2[templateName] = NAMER.dataTypeName(template.namespace);
23005
- templates2[lastItem(template.namespace)] = __spreadValues({
23006
- label: template.label || templateName,
23007
- key: templateName,
23008
- fields: await sequential(template.fields, async (field2) => await this.resolveField(field2))
23009
- }, extraFields2);
23010
- return true;
23011
- });
23012
- return __spreadValues(__spreadProps(__spreadValues({}, field), {
23013
- typeMap: typeMap2,
23014
- component: field.list ? "blocks" : "not-implemented",
23015
- templates: templates2
23016
- }), extraFields);
23017
- } else {
23018
- throw new Error(`Unknown object for resolveField function`);
23019
- }
23020
- case "rich-text":
23021
- const templates = {};
23022
- const typeMap = {};
23023
- await sequential(field.templates, async (template) => {
23024
- if (typeof template === "string") {
23025
- throw new Error(`Global templates not yet supported for rich-text`);
23026
- } else {
23027
- const extraFields2 = template.ui || {};
23028
- const templateName = lastItem(template.namespace);
23029
- typeMap[templateName] = NAMER.dataTypeName(template.namespace);
23030
- templates[lastItem(template.namespace)] = __spreadValues({
23031
- label: template.label || templateName,
23032
- key: templateName,
23033
- inline: template.inline,
23034
- name: templateName,
23035
- fields: await sequential(template.fields, async (field2) => await this.resolveField(field2))
23036
- }, extraFields2);
23037
- return true;
23038
- }
23039
- });
23040
- return __spreadValues(__spreadProps(__spreadValues({}, field), {
23041
- templates: Object.values(templates),
23042
- component: "rich-text"
23043
- }), extraFields);
23044
- case "reference":
23045
- const documents = import_lodash5.default.flatten(await sequential(field.collections, async (collectionName) => {
23046
- const collection = this.tinaSchema.getCollection(collectionName);
23047
- return this.database.store.glob(collection.path);
23048
- }));
23049
- return __spreadValues(__spreadProps(__spreadValues({}, field), {
23050
- component: "reference",
23051
- options: [
23052
- { label: "Choose an option", value: "" },
23053
- ...documents.map((document3) => {
23054
- return {
23055
- value: document3,
23056
- label: document3
23057
- };
23058
- })
23059
- ]
23060
- }), extraFields);
23061
- default:
23062
- throw new Error(`Unknown field type ${field.type}`);
23063
- }
23064
- };
22930
+ this.config = init.config;
23065
22931
  this.database = init.database;
23066
22932
  this.tinaSchema = init.tinaSchema;
23067
22933
  }
@@ -23098,6 +22964,7 @@ var resolveDateInput = (value) => {
23098
22964
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/resolve.ts
23099
22965
  var import_relay_operation_optimizer = __toModule(require("@graphql-tools/relay-operation-optimizer"));
23100
22966
  var resolve = async ({
22967
+ config,
23101
22968
  query,
23102
22969
  variables,
23103
22970
  database,
@@ -23106,49 +22973,11 @@ var resolve = async ({
23106
22973
  try {
23107
22974
  const graphQLSchemaAst = await database.getGraphQLSchema();
23108
22975
  const graphQLSchema = (0, import_graphql3.buildASTSchema)(graphQLSchemaAst);
23109
- const config = await database.getTinaSchema();
23110
- const tinaSchema = await createSchema({ schema: config });
23111
- const resolver2 = await createResolver2({ database, tinaSchema });
23112
- const paths = [];
23113
- const mutationPaths = [];
23114
- const ast = (0, import_graphql3.parse)(query);
23115
- const typeInfo = new import_graphql3.TypeInfo(graphQLSchema);
23116
- const referencePathVisitor = () => {
23117
- return {
23118
- leave: {
23119
- Field(node, key2, parent, path6, ancestors) {
23120
- const type = typeInfo.getType();
23121
- if (type) {
23122
- const realType = (0, import_graphql3.getNamedType)(type);
23123
- if (realType instanceof import_graphql3.GraphQLUnionType) {
23124
- const hasNodeInterface = !!realType.getTypes().find((objectType) => objectType.getInterfaces().find((intfc) => intfc.name === "Node"));
23125
- if (hasNodeInterface) {
23126
- const p = [];
23127
- ancestors.forEach((item, index2) => {
23128
- var _a;
23129
- const activePath = path6[index2];
23130
- const result = item[activePath];
23131
- if ((_a = result == null ? void 0 : result.name) == null ? void 0 : _a.value) {
23132
- if (result.kind === "Field") {
23133
- p.push(result.name.value);
23134
- }
23135
- }
23136
- });
23137
- const referenceQuery = buildReferenceQuery(node, [
23138
- ...p,
23139
- node.name.value
23140
- ]);
23141
- if (referenceQuery) {
23142
- paths.push(referenceQuery);
23143
- }
23144
- }
23145
- }
23146
- }
23147
- }
23148
- }
23149
- };
23150
- };
23151
- (0, import_graphql3.visit)(ast, (0, import_graphql3.visitWithTypeInfo)(typeInfo, referencePathVisitor()));
22976
+ const tinaConfig = await database.getTinaSchema();
22977
+ const tinaSchema = await createSchema({
22978
+ schema: tinaConfig
22979
+ });
22980
+ const resolver2 = await createResolver2({ config, database, tinaSchema });
23152
22981
  const res = await (0, import_graphql3.graphql)({
23153
22982
  schema: graphQLSchema,
23154
22983
  source: query,
@@ -23177,25 +23006,22 @@ var resolve = async ({
23177
23006
  if (value) {
23178
23007
  return value;
23179
23008
  }
23180
- if (info.fieldName === "getCollections") {
23181
- const getCollectionNode2 = info.fieldNodes.find((x) => x.name.value === "getCollections");
23182
- const hasDocuments2 = getCollectionNode2.selectionSet.selections.find((x) => {
23009
+ if (info.fieldName === "collections") {
23010
+ const collectionNode2 = info.fieldNodes.find((x) => x.name.value === "collections");
23011
+ const hasDocuments2 = collectionNode2.selectionSet.selections.find((x) => {
23183
23012
  var _a;
23184
23013
  return ((_a = x == null ? void 0 : x.name) == null ? void 0 : _a.value) === "documents";
23185
23014
  });
23186
23015
  return tinaSchema.getCollections().map((collection) => {
23187
- return resolver2.resolveCollection(collection.name, Boolean(hasDocuments2));
23016
+ return resolver2.resolveCollection(args, collection.name, Boolean(hasDocuments2));
23188
23017
  });
23189
23018
  }
23190
- const getCollectionNode = info.fieldNodes.find((x) => x.name.value === "getCollection");
23191
- const hasDocuments = getCollectionNode.selectionSet.selections.find((x) => {
23019
+ const collectionNode = info.fieldNodes.find((x) => x.name.value === "collection");
23020
+ const hasDocuments = collectionNode.selectionSet.selections.find((x) => {
23192
23021
  var _a;
23193
23022
  return ((_a = x == null ? void 0 : x.name) == null ? void 0 : _a.value) === "documents";
23194
23023
  });
23195
- return resolver2.resolveCollection(args.collection, Boolean(hasDocuments));
23196
- }
23197
- if (info.fieldName === "getDocumentFields") {
23198
- return resolver2.getDocumentFields();
23024
+ return resolver2.resolveCollection(args, args.collection, Boolean(hasDocuments));
23199
23025
  }
23200
23026
  if (info.fieldName === "getOptimizedQuery") {
23201
23027
  try {
@@ -23231,7 +23057,7 @@ var resolve = async ({
23231
23057
  });
23232
23058
  }
23233
23059
  if ([
23234
- "getDocument",
23060
+ NAMER.documentQueryName(),
23235
23061
  "createDocument",
23236
23062
  "updateDocument",
23237
23063
  "deleteDocument"
@@ -23245,14 +23071,6 @@ var resolve = async ({
23245
23071
  isAddPendingDocument: false,
23246
23072
  isCollectionSpecific: false
23247
23073
  });
23248
- if (!isMutation) {
23249
- const mutationPath = buildMutationPath(info, {
23250
- relativePath: result2.sys.relativePath
23251
- });
23252
- if (mutationPath) {
23253
- mutationPaths.push(mutationPath);
23254
- }
23255
- }
23256
23074
  return result2;
23257
23075
  }
23258
23076
  return value;
@@ -23264,6 +23082,11 @@ var resolve = async ({
23264
23082
  return { node: document3 };
23265
23083
  })
23266
23084
  };
23085
+ } else if (info.fieldName === "documents" && (value == null ? void 0 : value.collection) && (value == null ? void 0 : value.hasDocuments)) {
23086
+ return resolver2.resolveCollectionConnection({
23087
+ args,
23088
+ collection: value.collection
23089
+ });
23267
23090
  } else {
23268
23091
  throw new Error(`Expected an array for result of ${info.fieldName} at ${info.path}`);
23269
23092
  }
@@ -23279,15 +23102,6 @@ var resolve = async ({
23279
23102
  isAddPendingDocument: false,
23280
23103
  isCollectionSpecific: true
23281
23104
  });
23282
- if (!isMutation) {
23283
- const mutationPath = buildMutationPath(info, {
23284
- collection: tinaSchema.getCollection(lookup.collection),
23285
- relativePath: result.sys.relativePath
23286
- });
23287
- if (mutationPath) {
23288
- mutationPaths.push(mutationPath);
23289
- }
23290
- }
23291
23105
  return result;
23292
23106
  case "collectionDocumentList":
23293
23107
  return resolver2.resolveCollectionConnection({
@@ -23295,6 +23109,19 @@ var resolve = async ({
23295
23109
  collection: tinaSchema.getCollection(lookup.collection)
23296
23110
  });
23297
23111
  case "unionData":
23112
+ if (!value) {
23113
+ if (args.relativePath) {
23114
+ const result2 = await resolver2.resolveDocument({
23115
+ args,
23116
+ collection: lookup.collection,
23117
+ isMutation,
23118
+ isCreation,
23119
+ isAddPendingDocument: false,
23120
+ isCollectionSpecific: true
23121
+ });
23122
+ return result2;
23123
+ }
23124
+ }
23298
23125
  return value;
23299
23126
  default:
23300
23127
  console.error(lookup);
@@ -23302,18 +23129,6 @@ var resolve = async ({
23302
23129
  }
23303
23130
  }
23304
23131
  });
23305
- paths.forEach((p) => {
23306
- const item = import_lodash6.default.get(res, p.path.slice(0, 3));
23307
- if (item) {
23308
- item.paths = [...item.paths || [], p];
23309
- }
23310
- });
23311
- mutationPaths.forEach((mutationPath) => {
23312
- const item = import_lodash6.default.get(res, mutationPath.path);
23313
- if (item) {
23314
- item.mutationInfo = mutationPath;
23315
- }
23316
- });
23317
23132
  if (res.errors) {
23318
23133
  if (!silenceErrors) {
23319
23134
  console.error(res.errors);
@@ -23333,213 +23148,6 @@ var resolve = async ({
23333
23148
  }
23334
23149
  }
23335
23150
  };
23336
- var buildPath = (path6, accum) => {
23337
- if (path6.prev) {
23338
- buildPath(path6.prev, accum);
23339
- }
23340
- accum.push(path6.key);
23341
- return accum;
23342
- };
23343
- var buildReferenceQuery = (fieldNode, path6) => {
23344
- if (fieldNode) {
23345
- const p = path6.map((item) => item === "data" ? "form" : item);
23346
- const dataPath = path6;
23347
- const newNode = __spreadProps(__spreadValues({}, fieldNode), {
23348
- name: { kind: "Name", value: "node" },
23349
- arguments: [
23350
- {
23351
- kind: "Argument",
23352
- name: {
23353
- kind: "Name",
23354
- value: "id"
23355
- },
23356
- value: {
23357
- kind: "Variable",
23358
- name: {
23359
- kind: "Name",
23360
- value: "id"
23361
- }
23362
- }
23363
- }
23364
- ]
23365
- });
23366
- const q = {
23367
- kind: "OperationDefinition",
23368
- operation: "query",
23369
- name: {
23370
- value: "GetNode",
23371
- kind: "Name"
23372
- },
23373
- variableDefinitions: [
23374
- {
23375
- kind: "VariableDefinition",
23376
- variable: {
23377
- kind: "Variable",
23378
- name: {
23379
- kind: "Name",
23380
- value: "id"
23381
- }
23382
- },
23383
- type: {
23384
- kind: "NonNullType",
23385
- type: {
23386
- kind: "NamedType",
23387
- name: {
23388
- kind: "Name",
23389
- value: "String"
23390
- }
23391
- }
23392
- }
23393
- }
23394
- ],
23395
- selectionSet: {
23396
- kind: "SelectionSet",
23397
- selections: [newNode]
23398
- }
23399
- };
23400
- const queryString = (0, import_graphql3.print)(q);
23401
- return {
23402
- path: ["data", ...p.slice(0, -1)],
23403
- dataPath,
23404
- queryString
23405
- };
23406
- }
23407
- };
23408
- var buildMutationPath = (info, {
23409
- collection,
23410
- relativePath
23411
- }) => {
23412
- var _a, _b, _c;
23413
- const queryNode = info.fieldNodes.find((fn) => fn.name.value === info.fieldName);
23414
- if (!queryNode) {
23415
- throw new Error(`exptected to find field node for ${info.fieldName}`);
23416
- }
23417
- const mutationName = collection ? NAMER.updateName([collection.name]) : "updateDocument";
23418
- const mutations = JSON.parse(JSON.stringify((_a = info.schema.getMutationType()) == null ? void 0 : _a.getFields()));
23419
- const mutation = mutations[mutationName];
23420
- if (!mutation) {
23421
- throw new Error(`exptected to find mutation for ${mutationName}`);
23422
- }
23423
- const mutationNode = mutations[mutationName].astNode;
23424
- const newNode = __spreadProps(__spreadValues({}, queryNode), {
23425
- name: { kind: "Name", value: mutation.name },
23426
- arguments: (_b = mutationNode == null ? void 0 : mutationNode.arguments) == null ? void 0 : _b.map((argument) => {
23427
- if (argument.name.value === "relativePath") {
23428
- return {
23429
- kind: "Argument",
23430
- name: {
23431
- kind: "Name",
23432
- value: argument.name.value
23433
- },
23434
- value: {
23435
- kind: "StringValue",
23436
- value: relativePath
23437
- }
23438
- };
23439
- }
23440
- return {
23441
- kind: "Argument",
23442
- name: {
23443
- kind: "Name",
23444
- value: argument.name.value
23445
- },
23446
- value: {
23447
- kind: "Variable",
23448
- name: {
23449
- kind: "Name",
23450
- value: argument.name.value
23451
- }
23452
- }
23453
- };
23454
- })
23455
- });
23456
- const paramArgs = (_c = mutationNode == null ? void 0 : mutationNode.arguments) == null ? void 0 : _c.find((arg) => arg.name.value === "params");
23457
- if (!paramArgs) {
23458
- throw new Error(`Expected to find argument named params for mutation ${mutationName}`);
23459
- }
23460
- const q = {
23461
- kind: "OperationDefinition",
23462
- operation: "mutation",
23463
- name: {
23464
- value: "UpdateDocument",
23465
- kind: "Name"
23466
- },
23467
- variableDefinitions: [
23468
- {
23469
- kind: "VariableDefinition",
23470
- variable: {
23471
- kind: "Variable",
23472
- name: {
23473
- kind: "Name",
23474
- value: "params"
23475
- }
23476
- },
23477
- type: paramArgs == null ? void 0 : paramArgs.type
23478
- }
23479
- ],
23480
- selectionSet: {
23481
- kind: "SelectionSet",
23482
- selections: [newNode]
23483
- }
23484
- };
23485
- const mutationString = addFragmentsToQuery(info, newNode, q);
23486
- return {
23487
- path: ["data", ...buildPath(info.path, []), "form"],
23488
- string: mutationString,
23489
- includeCollection: collection ? false : true,
23490
- includeTemplate: collection ? !!collection.templates : false
23491
- };
23492
- };
23493
- function addFragmentsToQuery(info, fieldNode, q) {
23494
- const fragmentSpreadVisitor = (frag) => {
23495
- return {
23496
- leave: {
23497
- FragmentSpread(node) {
23498
- frag.subFrags.push(node.name.value);
23499
- }
23500
- }
23501
- };
23502
- };
23503
- const frags = [];
23504
- Object.entries(info.fragments).map(([fragmentName, fragmentDefinition]) => {
23505
- const frag = {
23506
- name: fragmentName,
23507
- node: fragmentDefinition,
23508
- subFrags: []
23509
- };
23510
- frags.push(frag);
23511
- (0, import_graphql3.visit)(fragmentDefinition, fragmentSpreadVisitor(frag));
23512
- });
23513
- const n = {
23514
- query: (0, import_graphql3.print)(fieldNode),
23515
- fragments: []
23516
- };
23517
- const visitor = {
23518
- leave: {
23519
- FragmentSpread(node) {
23520
- n.fragments.push(node.name.value);
23521
- }
23522
- }
23523
- };
23524
- (0, import_graphql3.visit)(fieldNode, visitor);
23525
- const getFrags = (fragNames, accum) => {
23526
- fragNames.forEach((fragName) => {
23527
- const frag = frags.find((f) => f.name === fragName);
23528
- if (!frag) {
23529
- throw new Error(`Unable to find fragment ${fragName}`);
23530
- }
23531
- accum.push(frag.node);
23532
- if (frag.subFrags) {
23533
- getFrags(frag.subFrags, accum);
23534
- }
23535
- });
23536
- return accum;
23537
- };
23538
- const fragss = getFrags(n.fragments, []);
23539
- const queryString = `${fragss.map((f) => (0, import_graphql3.print)(f)).join("\n")}
23540
- ${(0, import_graphql3.print)(q)}`;
23541
- return queryString;
23542
- }
23543
23151
 
23544
23152
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/database/index.ts
23545
23153
  var import_path4 = __toModule(require("path"));
@@ -23611,12 +23219,13 @@ var createDatabase = async (config) => {
23611
23219
  };
23612
23220
  var SYSTEM_FILES = ["_schema", "_graphql", "_lookup"];
23613
23221
  var GENERATED_FOLDER = import_path4.default.join(".tina", "__generated__");
23222
+ var defaultStatusCallback = () => Promise.resolve();
23614
23223
  var Database = class {
23615
23224
  constructor(config) {
23616
23225
  this.config = config;
23617
23226
  this.collectionForPath = async (filepath) => {
23618
23227
  const tinaSchema = await this.getSchema();
23619
- const collection = tinaSchema.schema.collections.find((collection2) => filepath.startsWith(collection2.path));
23228
+ const collection = await tinaSchema.getCollectionByFullPath(filepath);
23620
23229
  return collection;
23621
23230
  };
23622
23231
  this.get = async (filepath) => {
@@ -23895,36 +23504,41 @@ var Database = class {
23895
23504
  graphQLSchema,
23896
23505
  tinaSchema
23897
23506
  }) => {
23898
- const lookup = JSON.parse(await this.bridge.get(import_path4.default.join(GENERATED_FOLDER, "_lookup.json")));
23899
- if (this.store.supportsSeeding()) {
23900
- await this.store.clear();
23901
- await this.store.seed(import_path4.default.join(GENERATED_FOLDER, "_graphql.json"), graphQLSchema);
23902
- await this.store.seed(import_path4.default.join(GENERATED_FOLDER, "_schema.json"), tinaSchema.schema);
23903
- await this.store.seed(import_path4.default.join(GENERATED_FOLDER, "_lookup.json"), lookup);
23904
- await this._indexAllContent();
23905
- } else {
23906
- if (this.store.supportsIndexing()) {
23907
- throw new Error(`Schema must be indexed with provided Store`);
23507
+ await this.indexStatusCallbackWrapper(async () => {
23508
+ const lookup = JSON.parse(await this.bridge.get(import_path4.default.join(GENERATED_FOLDER, "_lookup.json")));
23509
+ if (this.store.supportsSeeding()) {
23510
+ await this.store.clear();
23511
+ await this.store.seed(import_path4.default.join(GENERATED_FOLDER, "_graphql.json"), graphQLSchema);
23512
+ await this.store.seed(import_path4.default.join(GENERATED_FOLDER, "_schema.json"), tinaSchema.schema);
23513
+ await this.store.seed(import_path4.default.join(GENERATED_FOLDER, "_lookup.json"), lookup);
23514
+ await this._indexAllContent();
23515
+ } else {
23516
+ if (this.store.supportsIndexing()) {
23517
+ throw new Error(`Schema must be indexed with provided Store`);
23518
+ }
23908
23519
  }
23909
- }
23520
+ });
23910
23521
  };
23911
23522
  this.deleteContentByPaths = async (documentPaths) => {
23912
- const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
23913
- for (const collection of Object.keys(pathsByCollection)) {
23914
- await _deleteIndexContent(this, pathsByCollection[collection], collections[collection]);
23915
- }
23916
- await _deleteIndexContent(this, nonCollectionPaths, null);
23523
+ await this.indexStatusCallbackWrapper(async () => {
23524
+ const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
23525
+ for (const collection of Object.keys(pathsByCollection)) {
23526
+ await _deleteIndexContent(this, pathsByCollection[collection], collections[collection]);
23527
+ }
23528
+ await _deleteIndexContent(this, nonCollectionPaths, null);
23529
+ });
23917
23530
  };
23918
23531
  this.indexContentByPaths = async (documentPaths) => {
23919
- const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
23920
- for (const collection of Object.keys(pathsByCollection)) {
23921
- await _indexContent(this, pathsByCollection[collection], collections[collection]);
23922
- }
23923
- await _indexContent(this, nonCollectionPaths);
23532
+ await this.indexStatusCallbackWrapper(async () => {
23533
+ const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
23534
+ for (const collection of Object.keys(pathsByCollection)) {
23535
+ await _indexContent(this, pathsByCollection[collection], collections[collection]);
23536
+ }
23537
+ await _indexContent(this, nonCollectionPaths);
23538
+ });
23924
23539
  };
23925
23540
  this.delete = async (filepath) => {
23926
- const tinaSchema = await this.getSchema();
23927
- const collection = tinaSchema.schema.collections.find((collection2) => filepath.startsWith(collection2.path));
23541
+ const collection = await this.collectionForPath(filepath);
23928
23542
  let collectionIndexDefinitions;
23929
23543
  if (collection) {
23930
23544
  const indexDefinitions = await this.getIndexDefinitions();
@@ -23958,6 +23572,7 @@ var Database = class {
23958
23572
  };
23959
23573
  this.bridge = config.bridge;
23960
23574
  this.store = config.store;
23575
+ this.indexStatusCallback = config.indexStatusCallback || defaultStatusCallback;
23961
23576
  }
23962
23577
  async partitionPathsByCollection(documentPaths) {
23963
23578
  const pathsByCollection = {};
@@ -23977,6 +23592,16 @@ var Database = class {
23977
23592
  }
23978
23593
  return { pathsByCollection, nonCollectionPaths, collections };
23979
23594
  }
23595
+ async indexStatusCallbackWrapper(fn) {
23596
+ await this.indexStatusCallback({ status: "inprogress" });
23597
+ try {
23598
+ await fn();
23599
+ await this.indexStatusCallback({ status: "complete" });
23600
+ } catch (error) {
23601
+ await this.indexStatusCallback({ status: "failed", error });
23602
+ throw error;
23603
+ }
23604
+ }
23980
23605
  };
23981
23606
  function hasOwnProperty2(obj, prop) {
23982
23607
  return obj.hasOwnProperty(prop);