@tinacms/graphql 1.3.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.
- package/dist/database/level.d.ts +7 -0
- package/dist/index.es.js +54 -56
- package/dist/index.js +54 -56
- package/package.json +1 -1
package/dist/database/level.d.ts
CHANGED
|
@@ -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.3.
|
|
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";
|
|
@@ -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;
|
|
@@ -4169,14 +4203,7 @@ var Database = class {
|
|
|
4169
4203
|
} else {
|
|
4170
4204
|
const tinaSchema = await this.getSchema(this.level);
|
|
4171
4205
|
const extension = path3.extname(filepath);
|
|
4172
|
-
|
|
4173
|
-
try {
|
|
4174
|
-
contentObject = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizePath(filepath));
|
|
4175
|
-
} catch (e) {
|
|
4176
|
-
if (e.code !== "LEVEL_NOT_FOUND") {
|
|
4177
|
-
throw e;
|
|
4178
|
-
}
|
|
4179
|
-
}
|
|
4206
|
+
const contentObject = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizePath(filepath));
|
|
4180
4207
|
if (!contentObject) {
|
|
4181
4208
|
throw new GraphQLError4(`Unable to find record ${filepath}`);
|
|
4182
4209
|
}
|
|
@@ -4223,14 +4250,7 @@ var Database = class {
|
|
|
4223
4250
|
}
|
|
4224
4251
|
await this.onPut(normalizedPath, stringifiedFile);
|
|
4225
4252
|
const putOps = makeIndexOpsForDocument(normalizedPath, collection?.name, collectionIndexDefinitions, payload, "put", this.level);
|
|
4226
|
-
|
|
4227
|
-
try {
|
|
4228
|
-
existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
|
|
4229
|
-
} catch (e) {
|
|
4230
|
-
if (e.code !== "LEVEL_NOT_FOUND") {
|
|
4231
|
-
throw e;
|
|
4232
|
-
}
|
|
4233
|
-
}
|
|
4253
|
+
const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
|
|
4234
4254
|
const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath, collection?.name, collectionIndexDefinitions, existingItem, "del", this.level) : [];
|
|
4235
4255
|
const ops = [
|
|
4236
4256
|
...delOps,
|
|
@@ -4262,14 +4282,7 @@ var Database = class {
|
|
|
4262
4282
|
}
|
|
4263
4283
|
await this.onPut(normalizedPath, stringifiedFile);
|
|
4264
4284
|
const putOps = makeIndexOpsForDocument(normalizedPath, collection, collectionIndexDefinitions, payload, "put", this.level);
|
|
4265
|
-
|
|
4266
|
-
try {
|
|
4267
|
-
existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
|
|
4268
|
-
} catch (e) {
|
|
4269
|
-
if (e.code !== "LEVEL_NOT_FOUND") {
|
|
4270
|
-
throw e;
|
|
4271
|
-
}
|
|
4272
|
-
}
|
|
4285
|
+
const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
|
|
4273
4286
|
const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath, collection, collectionIndexDefinitions, existingItem, "del", this.level) : [];
|
|
4274
4287
|
const ops = [
|
|
4275
4288
|
...delOps,
|
|
@@ -4688,7 +4701,7 @@ var Database = class {
|
|
|
4688
4701
|
};
|
|
4689
4702
|
this.tinaDirectory = config.tinaDirectory || ".tina";
|
|
4690
4703
|
this.bridge = config.bridge;
|
|
4691
|
-
this.rootLevel = config.level;
|
|
4704
|
+
this.rootLevel = config.level && new LevelProxy(config.level);
|
|
4692
4705
|
this.indexStatusCallback = config.indexStatusCallback || defaultStatusCallback;
|
|
4693
4706
|
this.onPut = config.onPut || defaultOnPut;
|
|
4694
4707
|
this.onDelete = config.onDelete || defaultOnDelete;
|
|
@@ -4712,24 +4725,13 @@ var Database = class {
|
|
|
4712
4725
|
return { pathsByCollection, nonCollectionPaths, collections };
|
|
4713
4726
|
}
|
|
4714
4727
|
async updateDatabaseVersion(version2) {
|
|
4715
|
-
const metadataLevel =
|
|
4728
|
+
const metadataLevel = this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
|
|
4716
4729
|
await metadataLevel.put("metadata", { version: version2 });
|
|
4717
4730
|
}
|
|
4718
4731
|
async getDatabaseVersion() {
|
|
4719
|
-
const metadataLevel =
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
const metadata = await metadataLevel.get("metadata");
|
|
4723
|
-
version2 = metadata.version || version2;
|
|
4724
|
-
} catch (e) {
|
|
4725
|
-
if (e.code !== "LEVEL_NOT_FOUND") {
|
|
4726
|
-
throw e;
|
|
4727
|
-
}
|
|
4728
|
-
if (version2) {
|
|
4729
|
-
await metadataLevel.put("metadata", { version: version2 });
|
|
4730
|
-
}
|
|
4731
|
-
}
|
|
4732
|
-
return version2;
|
|
4732
|
+
const metadataLevel = this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
|
|
4733
|
+
const metadata = await metadataLevel.get("metadata");
|
|
4734
|
+
return metadata?.version;
|
|
4733
4735
|
}
|
|
4734
4736
|
async initLevel() {
|
|
4735
4737
|
if (this.level) {
|
|
@@ -4738,10 +4740,12 @@ var Database = class {
|
|
|
4738
4740
|
if (!this.config.version) {
|
|
4739
4741
|
this.level = this.rootLevel;
|
|
4740
4742
|
} else {
|
|
4741
|
-
|
|
4742
|
-
if (version2) {
|
|
4743
|
-
|
|
4743
|
+
let version2 = await this.getDatabaseVersion();
|
|
4744
|
+
if (!version2) {
|
|
4745
|
+
version2 = "";
|
|
4746
|
+
await this.updateDatabaseVersion(version2);
|
|
4744
4747
|
}
|
|
4748
|
+
this.level = this.rootLevel.sublevel(version2, SUBLEVEL_OPTIONS);
|
|
4745
4749
|
}
|
|
4746
4750
|
if (!this.level) {
|
|
4747
4751
|
throw new GraphQLError4("Error initializing LevelDB instance");
|
|
@@ -4813,18 +4817,12 @@ var _deleteIndexContent = async (database, documentPaths, enequeueOps, collectio
|
|
|
4813
4817
|
const rootLevel = database.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
|
|
4814
4818
|
await sequential(documentPaths, async (filepath) => {
|
|
4815
4819
|
const itemKey = normalizePath(filepath);
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
]);
|
|
4823
|
-
}
|
|
4824
|
-
} catch (e) {
|
|
4825
|
-
if (e.code !== "LEVEL_NOT_FOUND") {
|
|
4826
|
-
throw e;
|
|
4827
|
-
}
|
|
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
|
+
]);
|
|
4828
4826
|
}
|
|
4829
4827
|
});
|
|
4830
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.3.
|
|
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";
|
|
@@ -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;
|
|
@@ -4209,14 +4243,7 @@ var Database = class {
|
|
|
4209
4243
|
} else {
|
|
4210
4244
|
const tinaSchema = await this.getSchema(this.level);
|
|
4211
4245
|
const extension = import_path3.default.extname(filepath);
|
|
4212
|
-
|
|
4213
|
-
try {
|
|
4214
|
-
contentObject = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizePath(filepath));
|
|
4215
|
-
} catch (e) {
|
|
4216
|
-
if (e.code !== "LEVEL_NOT_FOUND") {
|
|
4217
|
-
throw e;
|
|
4218
|
-
}
|
|
4219
|
-
}
|
|
4246
|
+
const contentObject = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizePath(filepath));
|
|
4220
4247
|
if (!contentObject) {
|
|
4221
4248
|
throw new import_graphql5.GraphQLError(`Unable to find record ${filepath}`);
|
|
4222
4249
|
}
|
|
@@ -4262,14 +4289,7 @@ var Database = class {
|
|
|
4262
4289
|
}
|
|
4263
4290
|
await this.onPut(normalizedPath, stringifiedFile);
|
|
4264
4291
|
const putOps = makeIndexOpsForDocument(normalizedPath, collection == null ? void 0 : collection.name, collectionIndexDefinitions, payload, "put", this.level);
|
|
4265
|
-
|
|
4266
|
-
try {
|
|
4267
|
-
existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
|
|
4268
|
-
} catch (e) {
|
|
4269
|
-
if (e.code !== "LEVEL_NOT_FOUND") {
|
|
4270
|
-
throw e;
|
|
4271
|
-
}
|
|
4272
|
-
}
|
|
4292
|
+
const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
|
|
4273
4293
|
const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath, collection == null ? void 0 : collection.name, collectionIndexDefinitions, existingItem, "del", this.level) : [];
|
|
4274
4294
|
const ops = [
|
|
4275
4295
|
...delOps,
|
|
@@ -4301,14 +4321,7 @@ var Database = class {
|
|
|
4301
4321
|
}
|
|
4302
4322
|
await this.onPut(normalizedPath, stringifiedFile);
|
|
4303
4323
|
const putOps = makeIndexOpsForDocument(normalizedPath, collection, collectionIndexDefinitions, payload, "put", this.level);
|
|
4304
|
-
|
|
4305
|
-
try {
|
|
4306
|
-
existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
|
|
4307
|
-
} catch (e) {
|
|
4308
|
-
if (e.code !== "LEVEL_NOT_FOUND") {
|
|
4309
|
-
throw e;
|
|
4310
|
-
}
|
|
4311
|
-
}
|
|
4324
|
+
const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
|
|
4312
4325
|
const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath, collection, collectionIndexDefinitions, existingItem, "del", this.level) : [];
|
|
4313
4326
|
const ops = [
|
|
4314
4327
|
...delOps,
|
|
@@ -4730,7 +4743,7 @@ var Database = class {
|
|
|
4730
4743
|
};
|
|
4731
4744
|
this.tinaDirectory = config.tinaDirectory || ".tina";
|
|
4732
4745
|
this.bridge = config.bridge;
|
|
4733
|
-
this.rootLevel = config.level;
|
|
4746
|
+
this.rootLevel = config.level && new LevelProxy(config.level);
|
|
4734
4747
|
this.indexStatusCallback = config.indexStatusCallback || defaultStatusCallback;
|
|
4735
4748
|
this.onPut = config.onPut || defaultOnPut;
|
|
4736
4749
|
this.onDelete = config.onDelete || defaultOnDelete;
|
|
@@ -4754,24 +4767,13 @@ var Database = class {
|
|
|
4754
4767
|
return { pathsByCollection, nonCollectionPaths, collections };
|
|
4755
4768
|
}
|
|
4756
4769
|
async updateDatabaseVersion(version2) {
|
|
4757
|
-
const metadataLevel =
|
|
4770
|
+
const metadataLevel = this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
|
|
4758
4771
|
await metadataLevel.put("metadata", { version: version2 });
|
|
4759
4772
|
}
|
|
4760
4773
|
async getDatabaseVersion() {
|
|
4761
|
-
const metadataLevel =
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
const metadata = await metadataLevel.get("metadata");
|
|
4765
|
-
version2 = metadata.version || version2;
|
|
4766
|
-
} catch (e) {
|
|
4767
|
-
if (e.code !== "LEVEL_NOT_FOUND") {
|
|
4768
|
-
throw e;
|
|
4769
|
-
}
|
|
4770
|
-
if (version2) {
|
|
4771
|
-
await metadataLevel.put("metadata", { version: version2 });
|
|
4772
|
-
}
|
|
4773
|
-
}
|
|
4774
|
-
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;
|
|
4775
4777
|
}
|
|
4776
4778
|
async initLevel() {
|
|
4777
4779
|
if (this.level) {
|
|
@@ -4780,10 +4782,12 @@ var Database = class {
|
|
|
4780
4782
|
if (!this.config.version) {
|
|
4781
4783
|
this.level = this.rootLevel;
|
|
4782
4784
|
} else {
|
|
4783
|
-
|
|
4784
|
-
if (version2) {
|
|
4785
|
-
|
|
4785
|
+
let version2 = await this.getDatabaseVersion();
|
|
4786
|
+
if (!version2) {
|
|
4787
|
+
version2 = "";
|
|
4788
|
+
await this.updateDatabaseVersion(version2);
|
|
4786
4789
|
}
|
|
4790
|
+
this.level = this.rootLevel.sublevel(version2, SUBLEVEL_OPTIONS);
|
|
4787
4791
|
}
|
|
4788
4792
|
if (!this.level) {
|
|
4789
4793
|
throw new import_graphql5.GraphQLError("Error initializing LevelDB instance");
|
|
@@ -4855,18 +4859,12 @@ var _deleteIndexContent = async (database, documentPaths, enequeueOps, collectio
|
|
|
4855
4859
|
const rootLevel = database.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
|
|
4856
4860
|
await sequential(documentPaths, async (filepath) => {
|
|
4857
4861
|
const itemKey = normalizePath(filepath);
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
]);
|
|
4865
|
-
}
|
|
4866
|
-
} catch (e) {
|
|
4867
|
-
if (e.code !== "LEVEL_NOT_FOUND") {
|
|
4868
|
-
throw e;
|
|
4869
|
-
}
|
|
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
|
+
]);
|
|
4870
4868
|
}
|
|
4871
4869
|
});
|
|
4872
4870
|
};
|