@tinacms/graphql 0.0.0-202231421406 → 0.0.0-2022320202159

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,16 +1,17 @@
1
1
  # tina-graphql
2
2
 
3
- ## 0.0.0-202231421406
3
+ ## 0.0.0-2022320202159
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - 4da32454b: Modify database to write config json files without whitespace to reduce file sizes
8
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
9
10
  - 06666d39f: Link to MDX documentation when unregistered component error occurs
10
11
  - 3e2d9e43a: Adds new GraphQL `deleteDocument` mutation and logic
11
12
  - Updated dependencies [a2906d6fe]
12
13
  - Updated dependencies [3e2d9e43a]
13
- - @tinacms/datalayer@0.0.0-202231421406
14
+ - @tinacms/datalayer@0.0.0-2022320202159
14
15
 
15
16
  ## 0.59.10
16
17
 
@@ -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<{
package/dist/index.js CHANGED
@@ -22624,8 +22624,7 @@ var Resolver = class {
22624
22624
  return this.getDocument(realPath);
22625
22625
  }
22626
22626
  const params = this.buildObjectMutations(args.params[collection.name], collection);
22627
- console.log("calling put3", realPath);
22628
- await this.database.put(realPath, params);
22627
+ await this.database.put(realPath, params, collection.name);
22629
22628
  return this.getDocument(realPath);
22630
22629
  };
22631
22630
  this.updateResolveDocument = async ({
@@ -22642,8 +22641,7 @@ var Resolver = class {
22642
22641
  case "object":
22643
22642
  if (params2) {
22644
22643
  const values = this.buildFieldMutations(params2, templateInfo.template);
22645
- console.log("calling put", realPath);
22646
- await this.database.put(realPath, values);
22644
+ await this.database.put(realPath, values, collection.name);
22647
22645
  }
22648
22646
  break;
22649
22647
  case "union":
@@ -22656,16 +22654,14 @@ var Resolver = class {
22656
22654
  const values = __spreadProps(__spreadValues({}, this.buildFieldMutations(templateParams, template)), {
22657
22655
  _template: lastItem(template.namespace)
22658
22656
  });
22659
- console.log("calling put4", realPath);
22660
- await this.database.put(realPath, values);
22657
+ await this.database.put(realPath, values, collection.name);
22661
22658
  }
22662
22659
  });
22663
22660
  }
22664
22661
  return this.getDocument(realPath);
22665
22662
  }
22666
22663
  const params = this.buildObjectMutations(isCollectionSpecific ? args.params : args.params[collection.name], collection);
22667
- console.log("calling put2", realPath);
22668
- await this.database.put(realPath, params);
22664
+ await this.database.put(realPath, params, collection.name);
22669
22665
  return this.getDocument(realPath);
22670
22666
  };
22671
22667
  this.resolveDocument = async ({
@@ -23618,6 +23614,11 @@ var GENERATED_FOLDER = import_path4.default.join(".tina", "__generated__");
23618
23614
  var Database = class {
23619
23615
  constructor(config) {
23620
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
+ };
23621
23622
  this.get = async (filepath) => {
23622
23623
  if (SYSTEM_FILES.includes(filepath)) {
23623
23624
  throw new Error(`Unexpected get for config file ${filepath}`);
@@ -23657,8 +23658,7 @@ var Database = class {
23657
23658
  };
23658
23659
  this.addPendingDocument = async (filepath, data) => {
23659
23660
  const { stringifiedFile, payload, keepTemplateKey } = await this.stringifyFile(filepath, data);
23660
- const tinaSchema = await this.getSchema();
23661
- const collection = tinaSchema.schema.collections.find((collection2) => filepath.startsWith(collection2.path));
23661
+ const collection = await this.collectionForPath(filepath);
23662
23662
  let collectionIndexDefinitions;
23663
23663
  if (collection) {
23664
23664
  const indexDefinitions = await this.getIndexDefinitions();
@@ -23669,23 +23669,18 @@ var Database = class {
23669
23669
  }
23670
23670
  await this.store.put(filepath, payload, {
23671
23671
  keepTemplateKey,
23672
- collection: collection.name,
23672
+ collection: collection == null ? void 0 : collection.name,
23673
23673
  indexDefinitions: collectionIndexDefinitions
23674
23674
  });
23675
23675
  };
23676
- this.put = async (filepath, data) => {
23677
- console.log("Database.put", filepath, data);
23676
+ this.put = async (filepath, data, collection) => {
23678
23677
  if (SYSTEM_FILES.includes(filepath)) {
23679
23678
  throw new Error(`Unexpected put for config file ${filepath}`);
23680
23679
  } else {
23681
- const tinaSchema = await this.getSchema();
23682
- const collection = tinaSchema.schema.collections.find((collection2) => filepath.startsWith(collection2.path));
23683
- console.log("Database.put", collection);
23684
23680
  let collectionIndexDefinitions;
23685
23681
  if (collection) {
23686
- console.log(collection == null ? void 0 : collection.name);
23687
23682
  const indexDefinitions = await this.getIndexDefinitions();
23688
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
23683
+ collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection];
23689
23684
  }
23690
23685
  const { stringifiedFile, payload, keepTemplateKey } = await this.stringifyFile(filepath, data);
23691
23686
  if (this.store.supportsSeeding()) {
@@ -23693,7 +23688,7 @@ var Database = class {
23693
23688
  }
23694
23689
  await this.store.put(filepath, payload, {
23695
23690
  keepTemplateKey,
23696
- collection: collection.name,
23691
+ collection,
23697
23692
  indexDefinitions: collectionIndexDefinitions
23698
23693
  });
23699
23694
  }
@@ -23914,44 +23909,14 @@ var Database = class {
23914
23909
  }
23915
23910
  };
23916
23911
  this.deleteContentByPaths = async (documentPaths) => {
23917
- const pathsByCollection = {};
23918
- const nonCollectionPaths = [];
23919
- const collections = {};
23920
- const tinaSchema = await this.getSchema();
23921
- for (const documentPath of documentPaths) {
23922
- const collection = tinaSchema.schema.collections.find((collection2) => documentPath.startsWith(collection2.path));
23923
- if (collection) {
23924
- if (!pathsByCollection[collection.name]) {
23925
- pathsByCollection[collection.name] = [];
23926
- }
23927
- collections[collection.name] = collection;
23928
- pathsByCollection[collection.name].push(documentPath);
23929
- } else {
23930
- nonCollectionPaths.push(documentPath);
23931
- }
23932
- }
23912
+ const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
23933
23913
  for (const collection of Object.keys(pathsByCollection)) {
23934
23914
  await _deleteIndexContent(this, pathsByCollection[collection], collections[collection]);
23935
23915
  }
23936
23916
  await _deleteIndexContent(this, nonCollectionPaths, null);
23937
23917
  };
23938
23918
  this.indexContentByPaths = async (documentPaths) => {
23939
- const pathsByCollection = {};
23940
- const nonCollectionPaths = [];
23941
- const collections = {};
23942
- const tinaSchema = await this.getSchema();
23943
- for (const documentPath of documentPaths) {
23944
- const collection = tinaSchema.schema.collections.find((collection2) => documentPath.startsWith(collection2.path));
23945
- if (collection) {
23946
- if (!pathsByCollection[collection.name]) {
23947
- pathsByCollection[collection.name] = [];
23948
- }
23949
- collections[collection.name] = collection;
23950
- pathsByCollection[collection.name].push(documentPath);
23951
- } else {
23952
- nonCollectionPaths.push(documentPath);
23953
- }
23954
- }
23919
+ const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
23955
23920
  for (const collection of Object.keys(pathsByCollection)) {
23956
23921
  await _indexContent(this, pathsByCollection[collection], collections[collection]);
23957
23922
  }
@@ -23994,6 +23959,24 @@ var Database = class {
23994
23959
  this.bridge = config.bridge;
23995
23960
  this.store = config.store;
23996
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
+ }
23997
23980
  };
23998
23981
  function hasOwnProperty2(obj, prop) {
23999
23982
  return obj.hasOwnProperty(prop);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "0.0.0-202231421406",
3
+ "version": "0.0.0-2022320202159",
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.0.0-202231421406",
49
+ "@tinacms/datalayer": "0.0.0-2022320202159",
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.0.0-202231421406",
99
+ "@tinacms/datalayer": "0.0.0-2022320202159",
100
100
  "@tinacms/scripts": "0.50.7",
101
101
  "@types/cors": "^2.8.7",
102
102
  "@types/estree": "^0.0.50",