@tinacms/graphql 1.2.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,3 +19,10 @@ export declare type BatchOp = PutOp | DelOp;
19
19
  export declare const INDEX_KEY_FIELD_SEPARATOR = "\u001D";
20
20
  export declare const CONTENT_ROOT_PREFIX = "~";
21
21
  export declare const SUBLEVEL_OPTIONS: AbstractSublevelOptions<string, Record<string, any>>;
22
+ export declare class LevelWrapper {
23
+ private level;
24
+ constructor(level: Level);
25
+ }
26
+ export declare class LevelProxy {
27
+ constructor(level: Level);
28
+ }
package/dist/index.es.js CHANGED
@@ -2427,7 +2427,7 @@ var validateField = async (field) => {
2427
2427
 
2428
2428
  // package.json
2429
2429
  var name = "@tinacms/graphql";
2430
- var version = "1.2.0";
2430
+ var version = "1.3.1";
2431
2431
  var main = "dist/index.js";
2432
2432
  var module = "dist/index.es.js";
2433
2433
  var typings = "dist/index.d.ts";
@@ -2749,7 +2749,7 @@ var TinaQueryError = class extends TinaFetchError {
2749
2749
  };
2750
2750
  var TinaParseDocumentError = class extends TinaFetchError {
2751
2751
  constructor(args) {
2752
- super(`Error Parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`, args);
2752
+ super(`Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`, args);
2753
2753
  }
2754
2754
  toString() {
2755
2755
  return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
@@ -2926,6 +2926,40 @@ var SUBLEVEL_OPTIONS = {
2926
2926
  separator: INDEX_KEY_FIELD_SEPARATOR,
2927
2927
  valueEncoding: "json"
2928
2928
  };
2929
+ var LevelProxyHandler = {
2930
+ get: function(target, property) {
2931
+ if (!target[property]) {
2932
+ throw new Error(`The property, ${property.toString()}, doesn't exist`);
2933
+ }
2934
+ if (typeof target[property] !== "function") {
2935
+ throw new Error(`The property, ${property.toString()}, is not a function`);
2936
+ }
2937
+ if (property === "get") {
2938
+ return async (...args) => {
2939
+ let result;
2940
+ try {
2941
+ result = await target[property].apply(target, args);
2942
+ } catch (e) {
2943
+ if (e.code !== "LEVEL_NOT_FOUND") {
2944
+ throw e;
2945
+ }
2946
+ }
2947
+ return result;
2948
+ };
2949
+ } else if (property === "sublevel") {
2950
+ return (...args) => {
2951
+ return new Proxy(target[property].apply(target, args), LevelProxyHandler);
2952
+ };
2953
+ } else {
2954
+ return (...args) => target[property].apply(target, args);
2955
+ }
2956
+ }
2957
+ };
2958
+ var LevelProxy = class {
2959
+ constructor(level) {
2960
+ return new Proxy(level, LevelProxyHandler);
2961
+ }
2962
+ };
2929
2963
 
2930
2964
  // src/database/datalayer.ts
2931
2965
  var OP;
@@ -4096,6 +4130,7 @@ ${$_body}`, strippedContent, {
4096
4130
  case ".json":
4097
4131
  return JSON.stringify(strippedContent, null, 2);
4098
4132
  case ".yaml":
4133
+ case ".yml":
4099
4134
  return yaml.safeDump(strippedContent);
4100
4135
  case ".toml":
4101
4136
  return toml.stringify(strippedContent);
@@ -4130,6 +4165,7 @@ var parseFile = (content, format, yupSchema, markdownParseConfig) => {
4130
4165
  }
4131
4166
  return toml.parse(content);
4132
4167
  case ".yaml":
4168
+ case ".yml":
4133
4169
  if (!content) {
4134
4170
  return {};
4135
4171
  }
@@ -4214,14 +4250,7 @@ var Database = class {
4214
4250
  }
4215
4251
  await this.onPut(normalizedPath, stringifiedFile);
4216
4252
  const putOps = makeIndexOpsForDocument(normalizedPath, collection?.name, collectionIndexDefinitions, payload, "put", this.level);
4217
- let existingItem;
4218
- try {
4219
- existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
4220
- } catch (e) {
4221
- if (e.code !== "LEVEL_NOT_FOUND") {
4222
- throw e;
4223
- }
4224
- }
4253
+ const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
4225
4254
  const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath, collection?.name, collectionIndexDefinitions, existingItem, "del", this.level) : [];
4226
4255
  const ops = [
4227
4256
  ...delOps,
@@ -4253,14 +4282,7 @@ var Database = class {
4253
4282
  }
4254
4283
  await this.onPut(normalizedPath, stringifiedFile);
4255
4284
  const putOps = makeIndexOpsForDocument(normalizedPath, collection, collectionIndexDefinitions, payload, "put", this.level);
4256
- let existingItem;
4257
- try {
4258
- existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
4259
- } catch (e) {
4260
- if (e.code !== "LEVEL_NOT_FOUND") {
4261
- throw e;
4262
- }
4263
- }
4285
+ const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
4264
4286
  const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath, collection, collectionIndexDefinitions, existingItem, "del", this.level) : [];
4265
4287
  const ops = [
4266
4288
  ...delOps,
@@ -4679,7 +4701,7 @@ var Database = class {
4679
4701
  };
4680
4702
  this.tinaDirectory = config.tinaDirectory || ".tina";
4681
4703
  this.bridge = config.bridge;
4682
- this.rootLevel = config.level;
4704
+ this.rootLevel = config.level && new LevelProxy(config.level);
4683
4705
  this.indexStatusCallback = config.indexStatusCallback || defaultStatusCallback;
4684
4706
  this.onPut = config.onPut || defaultOnPut;
4685
4707
  this.onDelete = config.onDelete || defaultOnDelete;
@@ -4703,24 +4725,13 @@ var Database = class {
4703
4725
  return { pathsByCollection, nonCollectionPaths, collections };
4704
4726
  }
4705
4727
  async updateDatabaseVersion(version2) {
4706
- const metadataLevel = await this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
4728
+ const metadataLevel = this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
4707
4729
  await metadataLevel.put("metadata", { version: version2 });
4708
4730
  }
4709
4731
  async getDatabaseVersion() {
4710
- const metadataLevel = await this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
4711
- let version2;
4712
- try {
4713
- const metadata = await metadataLevel.get("metadata");
4714
- version2 = metadata.version || version2;
4715
- } catch (e) {
4716
- if (e.code !== "LEVEL_NOT_FOUND") {
4717
- throw e;
4718
- }
4719
- if (version2) {
4720
- await metadataLevel.put("metadata", { version: version2 });
4721
- }
4722
- }
4723
- return version2;
4732
+ const metadataLevel = this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
4733
+ const metadata = await metadataLevel.get("metadata");
4734
+ return metadata?.version;
4724
4735
  }
4725
4736
  async initLevel() {
4726
4737
  if (this.level) {
@@ -4729,10 +4740,15 @@ var Database = class {
4729
4740
  if (!this.config.version) {
4730
4741
  this.level = this.rootLevel;
4731
4742
  } else {
4732
- const version2 = await this.getDatabaseVersion();
4733
- if (version2) {
4734
- this.level = this.rootLevel.sublevel(version2, SUBLEVEL_OPTIONS);
4743
+ let version2 = await this.getDatabaseVersion();
4744
+ if (!version2) {
4745
+ version2 = "";
4746
+ await this.updateDatabaseVersion(version2);
4735
4747
  }
4748
+ this.level = this.rootLevel.sublevel(version2, SUBLEVEL_OPTIONS);
4749
+ }
4750
+ if (!this.level) {
4751
+ throw new GraphQLError4("Error initializing LevelDB instance");
4736
4752
  }
4737
4753
  }
4738
4754
  clearCache() {
@@ -4801,18 +4817,12 @@ var _deleteIndexContent = async (database, documentPaths, enequeueOps, collectio
4801
4817
  const rootLevel = database.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
4802
4818
  await sequential(documentPaths, async (filepath) => {
4803
4819
  const itemKey = normalizePath(filepath);
4804
- try {
4805
- const item = await rootLevel.get(itemKey);
4806
- if (item) {
4807
- await enequeueOps([
4808
- ...makeIndexOpsForDocument(itemKey, collection.name, collectionIndexDefinitions, item, "del", database.level),
4809
- { type: "del", key: itemKey, sublevel: rootLevel }
4810
- ]);
4811
- }
4812
- } catch (e) {
4813
- if (e.code !== "LEVEL_NOT_FOUND") {
4814
- throw e;
4815
- }
4820
+ const item = await rootLevel.get(itemKey);
4821
+ if (item) {
4822
+ await enequeueOps([
4823
+ ...makeIndexOpsForDocument(itemKey, collection.name, collectionIndexDefinitions, item, "del", database.level),
4824
+ { type: "del", key: itemKey, sublevel: rootLevel }
4825
+ ]);
4816
4826
  }
4817
4827
  });
4818
4828
  };
package/dist/index.js CHANGED
@@ -2483,7 +2483,7 @@ var validateField = async (field) => {
2483
2483
 
2484
2484
  // package.json
2485
2485
  var name = "@tinacms/graphql";
2486
- var version = "1.2.0";
2486
+ var version = "1.3.1";
2487
2487
  var main = "dist/index.js";
2488
2488
  var module2 = "dist/index.es.js";
2489
2489
  var typings = "dist/index.d.ts";
@@ -2798,7 +2798,7 @@ var TinaQueryError = class extends TinaFetchError {
2798
2798
  };
2799
2799
  var TinaParseDocumentError = class extends TinaFetchError {
2800
2800
  constructor(args) {
2801
- super(`Error Parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`, args);
2801
+ super(`Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`, args);
2802
2802
  }
2803
2803
  toString() {
2804
2804
  return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
@@ -2975,6 +2975,40 @@ var SUBLEVEL_OPTIONS = {
2975
2975
  separator: INDEX_KEY_FIELD_SEPARATOR,
2976
2976
  valueEncoding: "json"
2977
2977
  };
2978
+ var LevelProxyHandler = {
2979
+ get: function(target, property) {
2980
+ if (!target[property]) {
2981
+ throw new Error(`The property, ${property.toString()}, doesn't exist`);
2982
+ }
2983
+ if (typeof target[property] !== "function") {
2984
+ throw new Error(`The property, ${property.toString()}, is not a function`);
2985
+ }
2986
+ if (property === "get") {
2987
+ return async (...args) => {
2988
+ let result;
2989
+ try {
2990
+ result = await target[property].apply(target, args);
2991
+ } catch (e) {
2992
+ if (e.code !== "LEVEL_NOT_FOUND") {
2993
+ throw e;
2994
+ }
2995
+ }
2996
+ return result;
2997
+ };
2998
+ } else if (property === "sublevel") {
2999
+ return (...args) => {
3000
+ return new Proxy(target[property].apply(target, args), LevelProxyHandler);
3001
+ };
3002
+ } else {
3003
+ return (...args) => target[property].apply(target, args);
3004
+ }
3005
+ }
3006
+ };
3007
+ var LevelProxy = class {
3008
+ constructor(level) {
3009
+ return new Proxy(level, LevelProxyHandler);
3010
+ }
3011
+ };
2978
3012
 
2979
3013
  // src/database/datalayer.ts
2980
3014
  var OP;
@@ -4138,6 +4172,7 @@ ${$_body}`, strippedContent, {
4138
4172
  case ".json":
4139
4173
  return JSON.stringify(strippedContent, null, 2);
4140
4174
  case ".yaml":
4175
+ case ".yml":
4141
4176
  return import_js_yaml.default.safeDump(strippedContent);
4142
4177
  case ".toml":
4143
4178
  return import_toml.default.stringify(strippedContent);
@@ -4171,6 +4206,7 @@ var parseFile = (content, format, yupSchema, markdownParseConfig) => {
4171
4206
  }
4172
4207
  return import_toml.default.parse(content);
4173
4208
  case ".yaml":
4209
+ case ".yml":
4174
4210
  if (!content) {
4175
4211
  return {};
4176
4212
  }
@@ -4253,14 +4289,7 @@ var Database = class {
4253
4289
  }
4254
4290
  await this.onPut(normalizedPath, stringifiedFile);
4255
4291
  const putOps = makeIndexOpsForDocument(normalizedPath, collection == null ? void 0 : collection.name, collectionIndexDefinitions, payload, "put", this.level);
4256
- let existingItem;
4257
- try {
4258
- existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
4259
- } catch (e) {
4260
- if (e.code !== "LEVEL_NOT_FOUND") {
4261
- throw e;
4262
- }
4263
- }
4292
+ const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
4264
4293
  const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath, collection == null ? void 0 : collection.name, collectionIndexDefinitions, existingItem, "del", this.level) : [];
4265
4294
  const ops = [
4266
4295
  ...delOps,
@@ -4292,14 +4321,7 @@ var Database = class {
4292
4321
  }
4293
4322
  await this.onPut(normalizedPath, stringifiedFile);
4294
4323
  const putOps = makeIndexOpsForDocument(normalizedPath, collection, collectionIndexDefinitions, payload, "put", this.level);
4295
- let existingItem;
4296
- try {
4297
- existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
4298
- } catch (e) {
4299
- if (e.code !== "LEVEL_NOT_FOUND") {
4300
- throw e;
4301
- }
4302
- }
4324
+ const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
4303
4325
  const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath, collection, collectionIndexDefinitions, existingItem, "del", this.level) : [];
4304
4326
  const ops = [
4305
4327
  ...delOps,
@@ -4721,7 +4743,7 @@ var Database = class {
4721
4743
  };
4722
4744
  this.tinaDirectory = config.tinaDirectory || ".tina";
4723
4745
  this.bridge = config.bridge;
4724
- this.rootLevel = config.level;
4746
+ this.rootLevel = config.level && new LevelProxy(config.level);
4725
4747
  this.indexStatusCallback = config.indexStatusCallback || defaultStatusCallback;
4726
4748
  this.onPut = config.onPut || defaultOnPut;
4727
4749
  this.onDelete = config.onDelete || defaultOnDelete;
@@ -4745,24 +4767,13 @@ var Database = class {
4745
4767
  return { pathsByCollection, nonCollectionPaths, collections };
4746
4768
  }
4747
4769
  async updateDatabaseVersion(version2) {
4748
- const metadataLevel = await this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
4770
+ const metadataLevel = this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
4749
4771
  await metadataLevel.put("metadata", { version: version2 });
4750
4772
  }
4751
4773
  async getDatabaseVersion() {
4752
- const metadataLevel = await this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
4753
- let version2;
4754
- try {
4755
- const metadata = await metadataLevel.get("metadata");
4756
- version2 = metadata.version || version2;
4757
- } catch (e) {
4758
- if (e.code !== "LEVEL_NOT_FOUND") {
4759
- throw e;
4760
- }
4761
- if (version2) {
4762
- await metadataLevel.put("metadata", { version: version2 });
4763
- }
4764
- }
4765
- return version2;
4774
+ const metadataLevel = this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
4775
+ const metadata = await metadataLevel.get("metadata");
4776
+ return metadata == null ? void 0 : metadata.version;
4766
4777
  }
4767
4778
  async initLevel() {
4768
4779
  if (this.level) {
@@ -4771,10 +4782,15 @@ var Database = class {
4771
4782
  if (!this.config.version) {
4772
4783
  this.level = this.rootLevel;
4773
4784
  } else {
4774
- const version2 = await this.getDatabaseVersion();
4775
- if (version2) {
4776
- this.level = this.rootLevel.sublevel(version2, SUBLEVEL_OPTIONS);
4785
+ let version2 = await this.getDatabaseVersion();
4786
+ if (!version2) {
4787
+ version2 = "";
4788
+ await this.updateDatabaseVersion(version2);
4777
4789
  }
4790
+ this.level = this.rootLevel.sublevel(version2, SUBLEVEL_OPTIONS);
4791
+ }
4792
+ if (!this.level) {
4793
+ throw new import_graphql5.GraphQLError("Error initializing LevelDB instance");
4778
4794
  }
4779
4795
  }
4780
4796
  clearCache() {
@@ -4843,18 +4859,12 @@ var _deleteIndexContent = async (database, documentPaths, enequeueOps, collectio
4843
4859
  const rootLevel = database.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
4844
4860
  await sequential(documentPaths, async (filepath) => {
4845
4861
  const itemKey = normalizePath(filepath);
4846
- try {
4847
- const item = await rootLevel.get(itemKey);
4848
- if (item) {
4849
- await enequeueOps([
4850
- ...makeIndexOpsForDocument(itemKey, collection.name, collectionIndexDefinitions, item, "del", database.level),
4851
- { type: "del", key: itemKey, sublevel: rootLevel }
4852
- ]);
4853
- }
4854
- } catch (e) {
4855
- if (e.code !== "LEVEL_NOT_FOUND") {
4856
- throw e;
4857
- }
4862
+ const item = await rootLevel.get(itemKey);
4863
+ if (item) {
4864
+ await enequeueOps([
4865
+ ...makeIndexOpsForDocument(itemKey, collection.name, collectionIndexDefinitions, item, "del", database.level),
4866
+ { type: "del", key: itemKey, sublevel: rootLevel }
4867
+ ]);
4858
4868
  }
4859
4869
  });
4860
4870
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.es.js",
6
6
  "typings": "dist/index.d.ts",
@@ -25,8 +25,8 @@
25
25
  "dependencies": {
26
26
  "@graphql-tools/relay-operation-optimizer": "^6.4.1",
27
27
  "@iarna/toml": "^2.2.5",
28
- "@tinacms/mdx": "1.2.0",
29
- "@tinacms/schema-tools": "1.3.0",
28
+ "@tinacms/mdx": "1.3.0",
29
+ "@tinacms/schema-tools": "1.3.1",
30
30
  "abstract-level": "^1.0.3",
31
31
  "body-parser": "^1.19.0",
32
32
  "cors": "^2.8.5",
@@ -82,7 +82,7 @@
82
82
  "directory": "packages/tina-graphql"
83
83
  },
84
84
  "devDependencies": {
85
- "@tinacms/schema-tools": "1.3.0",
85
+ "@tinacms/schema-tools": "1.3.1",
86
86
  "@tinacms/scripts": "1.0.2",
87
87
  "@types/cors": "^2.8.7",
88
88
  "@types/estree": "^0.0.50",