@tinacms/graphql 0.59.10 → 0.59.11

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,18 @@
1
1
  # tina-graphql
2
2
 
3
+ ## 0.59.11
4
+
5
+ ### Patch Changes
6
+
7
+ - 4da32454b: Modify database to write config json files without whitespace to reduce file sizes
8
+ - 921709a7e: Adds validation to the schema instead of only using typescript types
9
+ - 558cc4368: Make schema init platform-aware and refactor database put requests
10
+ - 06666d39f: Link to MDX documentation when unregistered component error occurs
11
+ - 3e2d9e43a: Adds new GraphQL `deleteDocument` mutation and logic
12
+ - Updated dependencies [a2906d6fe]
13
+ - Updated dependencies [3e2d9e43a]
14
+ - @tinacms/datalayer@0.1.1
15
+
3
16
  ## 0.59.10
4
17
 
5
18
  ### Patch Changes
@@ -138,6 +138,20 @@ export declare class Builder {
138
138
  * @param collections
139
139
  */
140
140
  buildUpdateCollectionDocumentMutation: (collections: TinaCloudCollectionEnriched[]) => Promise<import("graphql").FieldDefinitionNode>;
141
+ /**
142
+ * ```graphql
143
+ * # ex.
144
+ * {
145
+ * deleteDocument(relativePath: $relativePath, params: $params) {
146
+ * id
147
+ * data {...}
148
+ * }
149
+ * }
150
+ * ```
151
+ *
152
+ * @param collections
153
+ */
154
+ buildDeleteCollectionDocumentMutation: (collections: TinaCloudCollectionEnriched[]) => Promise<import("graphql").FieldDefinitionNode>;
141
155
  /**
142
156
  * ```graphql
143
157
  * # ex.
@@ -15,6 +15,7 @@ export interface Bridge {
15
15
  glob(pattern: string): Promise<string[]>;
16
16
  get(filepath: string): Promise<string>;
17
17
  put(filepath: string, data: string): Promise<void>;
18
+ delete(filepath: string): Promise<void>;
18
19
  /**
19
20
  * Whether this bridge supports the ability to build the schema.
20
21
  */
@@ -40,13 +40,15 @@ export declare class Database {
40
40
  private _graphql;
41
41
  private _tinaSchema;
42
42
  constructor(config: CreateDatabase);
43
+ private collectionForPath;
44
+ private partitionPathsByCollection;
43
45
  get: <T extends object>(filepath: string) => Promise<T>;
44
46
  addPendingDocument: (filepath: string, data: {
45
47
  [key: string]: unknown;
46
48
  }) => Promise<void>;
47
49
  put: (filepath: string, data: {
48
50
  [key: string]: unknown;
49
- }) => Promise<boolean>;
51
+ }, collection?: string) => Promise<boolean>;
50
52
  stringifyFile: (filepath: string, data: {
51
53
  [key: string]: unknown;
52
54
  }) => Promise<{
@@ -84,7 +86,9 @@ export declare class Database {
84
86
  graphQLSchema: DocumentNode;
85
87
  tinaSchema: TinaSchema;
86
88
  }) => Promise<void>;
89
+ deleteContentByPaths: (documentPaths: string[]) => Promise<void>;
87
90
  indexContentByPaths: (documentPaths: string[]) => Promise<void>;
91
+ delete: (filepath: string) => Promise<void>;
88
92
  _indexAllContent: () => Promise<void>;
89
93
  addToLookupMap: (lookup: LookupMapType) => Promise<void>;
90
94
  }
package/dist/index.js CHANGED
@@ -11398,7 +11398,12 @@ var Builder = class {
11398
11398
  documentsType
11399
11399
  ]
11400
11400
  });
11401
- return astBuilder.FieldDefinition({ type, name: name2, args, required: true });
11401
+ return astBuilder.FieldDefinition({
11402
+ type,
11403
+ name: name2,
11404
+ args,
11405
+ required: true
11406
+ });
11402
11407
  };
11403
11408
  this.buildMultiCollectionDefinition = async (collections) => {
11404
11409
  const name2 = "getCollections";
@@ -11539,6 +11544,25 @@ var Builder = class {
11539
11544
  type: astBuilder.TYPES.MultiCollectionDocument
11540
11545
  });
11541
11546
  };
11547
+ this.buildDeleteCollectionDocumentMutation = async (collections) => {
11548
+ return astBuilder.FieldDefinition({
11549
+ name: "deleteDocument",
11550
+ args: [
11551
+ astBuilder.InputValueDefinition({
11552
+ name: "collection",
11553
+ required: false,
11554
+ type: astBuilder.TYPES.String
11555
+ }),
11556
+ astBuilder.InputValueDefinition({
11557
+ name: "relativePath",
11558
+ required: true,
11559
+ type: astBuilder.TYPES.String
11560
+ })
11561
+ ],
11562
+ required: true,
11563
+ type: astBuilder.TYPES.MultiCollectionDocument
11564
+ });
11565
+ };
11542
11566
  this.multiCollectionDocumentList = async (collections) => {
11543
11567
  return this._buildMultiCollectionDocumentListDefinition({
11544
11568
  fieldName: "getDocumentList",
@@ -12101,7 +12125,7 @@ var Builder = class {
12101
12125
  fields: await sequential(collections, async (collection2) => {
12102
12126
  return astBuilder.InputValueDefinition({
12103
12127
  name: collection2.name,
12104
- type: await this._filterCollectionDocumentType(collection2)
12128
+ type: NAMER.dataFilterTypeName(collection2.namespace)
12105
12129
  });
12106
12130
  })
12107
12131
  })
@@ -12389,7 +12413,7 @@ var validateField = async (field) => {
12389
12413
 
12390
12414
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/package.json
12391
12415
  var name = "@tinacms/graphql";
12392
- var version = "0.59.10";
12416
+ var version = "0.59.11";
12393
12417
  var main = "dist/index.js";
12394
12418
  var typings = "dist/index.d.ts";
12395
12419
  var files = [
@@ -12790,6 +12814,7 @@ var _buildSchema = async (builder, tinaSchema) => {
12790
12814
  queryTypeDefinitionFields.push(await builder.multiCollectionDocument(collections));
12791
12815
  mutationTypeDefinitionFields.push(await builder.addMultiCollectionDocumentMutation());
12792
12816
  mutationTypeDefinitionFields.push(await builder.buildUpdateCollectionDocumentMutation(collections));
12817
+ mutationTypeDefinitionFields.push(await builder.buildDeleteCollectionDocumentMutation(collections));
12793
12818
  mutationTypeDefinitionFields.push(await builder.buildCreateCollectionDocumentMutation(collections));
12794
12819
  queryTypeDefinitionFields.push(await builder.multiCollectionDocumentList(collections));
12795
12820
  queryTypeDefinitionFields.push(await builder.multiCollectionDocumentFields());
@@ -20147,7 +20172,7 @@ var parseMDXInner = (tree, field) => {
20147
20172
  if (!template) {
20148
20173
  if ((0, import_lodash4.isNull)(node.name)) {
20149
20174
  } else {
20150
- throw new Error(`Found unregistered JSX or HTML: <${node.name}>. Please ensure all structured elements have been registered with your schema.`);
20175
+ throw new Error(`Found unregistered JSX or HTML: <${node.name}>. Please ensure all structured elements have been registered with your schema. https://tina.io/docs/editing/mdx/`);
20151
20176
  }
20152
20177
  }
20153
20178
  if (node.children.length > 0) {
@@ -22469,6 +22494,12 @@ var Resolver = class {
22469
22494
  throw e;
22470
22495
  }
22471
22496
  };
22497
+ this.deleteDocument = async (fullPath) => {
22498
+ if (typeof fullPath !== "string") {
22499
+ throw new Error(`fullPath must be of type string for getDocument request`);
22500
+ }
22501
+ await this.database.delete(fullPath);
22502
+ };
22472
22503
  this.getDocumentFields = async () => {
22473
22504
  try {
22474
22505
  const response = {};
@@ -22593,7 +22624,7 @@ var Resolver = class {
22593
22624
  return this.getDocument(realPath);
22594
22625
  }
22595
22626
  const params = this.buildObjectMutations(args.params[collection.name], collection);
22596
- await this.database.put(realPath, params);
22627
+ await this.database.put(realPath, params, collection.name);
22597
22628
  return this.getDocument(realPath);
22598
22629
  };
22599
22630
  this.updateResolveDocument = async ({
@@ -22610,7 +22641,7 @@ var Resolver = class {
22610
22641
  case "object":
22611
22642
  if (params2) {
22612
22643
  const values = this.buildFieldMutations(params2, templateInfo.template);
22613
- await this.database.put(realPath, values);
22644
+ await this.database.put(realPath, values, collection.name);
22614
22645
  }
22615
22646
  break;
22616
22647
  case "union":
@@ -22623,14 +22654,14 @@ var Resolver = class {
22623
22654
  const values = __spreadProps(__spreadValues({}, this.buildFieldMutations(templateParams, template)), {
22624
22655
  _template: lastItem(template.namespace)
22625
22656
  });
22626
- await this.database.put(realPath, values);
22657
+ await this.database.put(realPath, values, collection.name);
22627
22658
  }
22628
22659
  });
22629
22660
  }
22630
22661
  return this.getDocument(realPath);
22631
22662
  }
22632
22663
  const params = this.buildObjectMutations(isCollectionSpecific ? args.params : args.params[collection.name], collection);
22633
- await this.database.put(realPath, params);
22664
+ await this.database.put(realPath, params, collection.name);
22634
22665
  return this.getDocument(realPath);
22635
22666
  };
22636
22667
  this.resolveDocument = async ({
@@ -22638,6 +22669,7 @@ var Resolver = class {
22638
22669
  collection: collectionName,
22639
22670
  isMutation,
22640
22671
  isCreation,
22672
+ isDeletion,
22641
22673
  isAddPendingDocument,
22642
22674
  isCollectionSpecific
22643
22675
  }) => {
@@ -22665,6 +22697,14 @@ var Resolver = class {
22665
22697
  isAddPendingDocument
22666
22698
  });
22667
22699
  }
22700
+ if (isDeletion) {
22701
+ if (!alreadyExists) {
22702
+ throw new Error(`Unable to delete document, ${realPath} does not exist`);
22703
+ }
22704
+ const doc = await this.getDocument(realPath);
22705
+ await this.deleteDocument(realPath);
22706
+ return doc;
22707
+ }
22668
22708
  if (alreadyExists === false) {
22669
22709
  throw new Error(`Unable to update document, ${realPath} does not exist`);
22670
22710
  }
@@ -23190,12 +23230,18 @@ var resolve = async ({
23190
23230
  isAddPendingDocument: true
23191
23231
  });
23192
23232
  }
23193
- if (["getDocument", "createDocument", "updateDocument"].includes(info.fieldName)) {
23233
+ if ([
23234
+ "getDocument",
23235
+ "createDocument",
23236
+ "updateDocument",
23237
+ "deleteDocument"
23238
+ ].includes(info.fieldName)) {
23194
23239
  const result2 = await resolver2.resolveDocument({
23195
23240
  args,
23196
23241
  collection: args.collection,
23197
23242
  isMutation,
23198
23243
  isCreation,
23244
+ isDeletion: info.fieldName === "deleteDocument",
23199
23245
  isAddPendingDocument: false,
23200
23246
  isCollectionSpecific: false
23201
23247
  });
@@ -23568,6 +23614,11 @@ var GENERATED_FOLDER = import_path4.default.join(".tina", "__generated__");
23568
23614
  var Database = class {
23569
23615
  constructor(config) {
23570
23616
  this.config = config;
23617
+ this.collectionForPath = async (filepath) => {
23618
+ const tinaSchema = await this.getSchema();
23619
+ const collection = tinaSchema.schema.collections.find((collection2) => filepath.startsWith(collection2.path));
23620
+ return collection;
23621
+ };
23571
23622
  this.get = async (filepath) => {
23572
23623
  if (SYSTEM_FILES.includes(filepath)) {
23573
23624
  throw new Error(`Unexpected get for config file ${filepath}`);
@@ -23607,8 +23658,7 @@ var Database = class {
23607
23658
  };
23608
23659
  this.addPendingDocument = async (filepath, data) => {
23609
23660
  const { stringifiedFile, payload, keepTemplateKey } = await this.stringifyFile(filepath, data);
23610
- const tinaSchema = await this.getSchema();
23611
- const collection = tinaSchema.schema.collections.find((collection2) => filepath.startsWith(collection2.path));
23661
+ const collection = await this.collectionForPath(filepath);
23612
23662
  let collectionIndexDefinitions;
23613
23663
  if (collection) {
23614
23664
  const indexDefinitions = await this.getIndexDefinitions();
@@ -23619,20 +23669,18 @@ var Database = class {
23619
23669
  }
23620
23670
  await this.store.put(filepath, payload, {
23621
23671
  keepTemplateKey,
23622
- collection: collection.name,
23672
+ collection: collection == null ? void 0 : collection.name,
23623
23673
  indexDefinitions: collectionIndexDefinitions
23624
23674
  });
23625
23675
  };
23626
- this.put = async (filepath, data) => {
23676
+ this.put = async (filepath, data, collection) => {
23627
23677
  if (SYSTEM_FILES.includes(filepath)) {
23628
23678
  throw new Error(`Unexpected put for config file ${filepath}`);
23629
23679
  } else {
23630
- const tinaSchema = await this.getSchema();
23631
- const collection = tinaSchema.schema.collections.find((collection2) => filepath.startsWith(collection2.path));
23632
23680
  let collectionIndexDefinitions;
23633
23681
  if (collection) {
23634
23682
  const indexDefinitions = await this.getIndexDefinitions();
23635
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
23683
+ collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection];
23636
23684
  }
23637
23685
  const { stringifiedFile, payload, keepTemplateKey } = await this.stringifyFile(filepath, data);
23638
23686
  if (this.store.supportsSeeding()) {
@@ -23640,7 +23688,7 @@ var Database = class {
23640
23688
  }
23641
23689
  await this.store.put(filepath, payload, {
23642
23690
  keepTemplateKey,
23643
- collection: collection.name,
23691
+ collection,
23644
23692
  indexDefinitions: collectionIndexDefinitions
23645
23693
  });
23646
23694
  }
@@ -23839,8 +23887,8 @@ var Database = class {
23839
23887
  tinaSchema
23840
23888
  }) => {
23841
23889
  if (this.bridge.supportsBuilding()) {
23842
- await this.bridge.putConfig(import_path4.default.join(GENERATED_FOLDER, `_graphql.json`), JSON.stringify(graphQLSchema, null, 2));
23843
- await this.bridge.putConfig(import_path4.default.join(GENERATED_FOLDER, `_schema.json`), JSON.stringify(tinaSchema.schema, null, 2));
23890
+ await this.bridge.putConfig(import_path4.default.join(GENERATED_FOLDER, `_graphql.json`), JSON.stringify(graphQLSchema));
23891
+ await this.bridge.putConfig(import_path4.default.join(GENERATED_FOLDER, `_schema.json`), JSON.stringify(tinaSchema.schema));
23844
23892
  }
23845
23893
  };
23846
23894
  this.indexContent = async ({
@@ -23860,28 +23908,34 @@ var Database = class {
23860
23908
  }
23861
23909
  }
23862
23910
  };
23863
- this.indexContentByPaths = async (documentPaths) => {
23864
- const pathsByCollection = {};
23865
- const nonCollectionPaths = [];
23866
- const collections = {};
23867
- const tinaSchema = await this.getSchema();
23868
- for (const documentPath of documentPaths) {
23869
- const collection = tinaSchema.schema.collections.find((collection2) => documentPath.startsWith(collection2.path));
23870
- if (collection) {
23871
- if (!pathsByCollection[collection.name]) {
23872
- pathsByCollection[collection.name] = [];
23873
- }
23874
- collections[collection.name] = collection;
23875
- pathsByCollection[collection.name].push(documentPath);
23876
- } else {
23877
- nonCollectionPaths.push(documentPath);
23878
- }
23911
+ 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]);
23879
23915
  }
23916
+ await _deleteIndexContent(this, nonCollectionPaths, null);
23917
+ };
23918
+ this.indexContentByPaths = async (documentPaths) => {
23919
+ const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
23880
23920
  for (const collection of Object.keys(pathsByCollection)) {
23881
23921
  await _indexContent(this, pathsByCollection[collection], collections[collection]);
23882
23922
  }
23883
23923
  await _indexContent(this, nonCollectionPaths);
23884
23924
  };
23925
+ this.delete = async (filepath) => {
23926
+ const tinaSchema = await this.getSchema();
23927
+ const collection = tinaSchema.schema.collections.find((collection2) => filepath.startsWith(collection2.path));
23928
+ let collectionIndexDefinitions;
23929
+ if (collection) {
23930
+ const indexDefinitions = await this.getIndexDefinitions();
23931
+ collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
23932
+ }
23933
+ await this.store.delete(filepath, {
23934
+ collection: collection.name,
23935
+ indexDefinitions: collectionIndexDefinitions
23936
+ });
23937
+ await this.bridge.delete(filepath);
23938
+ };
23885
23939
  this._indexAllContent = async () => {
23886
23940
  const tinaSchema = await this.getSchema();
23887
23941
  await sequential(tinaSchema.getCollections(), async (collection) => {
@@ -23900,11 +23954,29 @@ var Database = class {
23900
23954
  const updatedLookup = __spreadProps(__spreadValues({}, lookupMap), {
23901
23955
  [lookup.type]: lookup
23902
23956
  });
23903
- await this.bridge.putConfig(lookupPath, JSON.stringify(updatedLookup, null, 2));
23957
+ await this.bridge.putConfig(lookupPath, JSON.stringify(updatedLookup));
23904
23958
  };
23905
23959
  this.bridge = config.bridge;
23906
23960
  this.store = config.store;
23907
23961
  }
23962
+ async partitionPathsByCollection(documentPaths) {
23963
+ const pathsByCollection = {};
23964
+ const nonCollectionPaths = [];
23965
+ const collections = {};
23966
+ for (const documentPath of documentPaths) {
23967
+ const collection = await this.collectionForPath(documentPath);
23968
+ if (collection) {
23969
+ if (!pathsByCollection[collection.name]) {
23970
+ pathsByCollection[collection.name] = [];
23971
+ }
23972
+ collections[collection.name] = collection;
23973
+ pathsByCollection[collection.name].push(documentPath);
23974
+ } else {
23975
+ nonCollectionPaths.push(documentPath);
23976
+ }
23977
+ }
23978
+ return { pathsByCollection, nonCollectionPaths, collections };
23979
+ }
23908
23980
  };
23909
23981
  function hasOwnProperty2(obj, prop) {
23910
23982
  return obj.hasOwnProperty(prop);
@@ -23934,6 +24006,23 @@ var _indexContent = async (database, documentPaths, collection) => {
23934
24006
  }
23935
24007
  });
23936
24008
  };
24009
+ var _deleteIndexContent = async (database, documentPaths, collection) => {
24010
+ let deleteOptions = void 0;
24011
+ if (collection) {
24012
+ const indexDefinitions = await database.getIndexDefinitions();
24013
+ const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
24014
+ if (!collectionIndexDefinitions) {
24015
+ throw new Error(`No indexDefinitions for collection ${collection.name}`);
24016
+ }
24017
+ deleteOptions = {
24018
+ collection: collection.name,
24019
+ indexDefinitions: collectionIndexDefinitions
24020
+ };
24021
+ }
24022
+ await sequential(documentPaths, async (filepath) => {
24023
+ database.store.delete(filepath, deleteOptions);
24024
+ });
24025
+ };
23937
24026
 
23938
24027
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/index.ts
23939
24028
  var buildSchema = async (rootPath, database) => {
@@ -1,15 +1,15 @@
1
1
  /**
2
- Copyright 2021 Forestry.io Holdings, Inc.
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
13
  import { ReferenceTypeInner, TinaFieldInner } from '../types';
14
14
  import type { FilterCondition } from '@tinacms/datalayer';
15
15
  export declare type ReferenceResolver = (filter: Record<string, object>, fieldDefinition: ReferenceTypeInner) => Promise<{
@@ -90,6 +90,7 @@ export declare class Resolver {
90
90
  fields: unknown[];
91
91
  };
92
92
  }>;
93
+ deleteDocument: (fullPath: unknown) => Promise<void>;
93
94
  getDocumentFields: () => Promise<{}>;
94
95
  buildObjectMutations: (fieldValue: any, field: Collectable) => {
95
96
  [key: string]: unknown;
@@ -169,11 +170,12 @@ export declare class Resolver {
169
170
  fields: unknown[];
170
171
  };
171
172
  }>;
172
- resolveDocument: ({ args, collection: collectionName, isMutation, isCreation, isAddPendingDocument, isCollectionSpecific, }: {
173
+ resolveDocument: ({ args, collection: collectionName, isMutation, isCreation, isDeletion, isAddPendingDocument, isCollectionSpecific, }: {
173
174
  args: unknown;
174
175
  collection?: string;
175
176
  isMutation: boolean;
176
177
  isCreation?: boolean;
178
+ isDeletion?: boolean;
177
179
  isAddPendingDocument?: boolean;
178
180
  isCollectionSpecific?: boolean;
179
181
  }) => Promise<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "0.59.10",
3
+ "version": "0.59.11",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@graphql-tools/relay-operation-optimizer": "^6.4.1",
49
- "@tinacms/datalayer": "0.1.0",
49
+ "@tinacms/datalayer": "0.1.1",
50
50
  "body-parser": "^1.19.0",
51
51
  "cors": "^2.8.5",
52
52
  "dataloader": "^2.0.0",
@@ -96,7 +96,7 @@
96
96
  "directory": "packages/tina-graphql"
97
97
  },
98
98
  "devDependencies": {
99
- "@tinacms/datalayer": "0.1.0",
99
+ "@tinacms/datalayer": "0.1.1",
100
100
  "@tinacms/scripts": "0.50.7",
101
101
  "@types/cors": "^2.8.7",
102
102
  "@types/estree": "^0.0.50",