@tinacms/graphql 0.0.0-ed38135-20250102012919 → 0.0.0-ee8d9a3-20250429131017
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/ast-builder/index.d.ts +0 -1
- package/dist/builder/index.d.ts +2 -2
- package/dist/database/datalayer.d.ts +5 -1
- package/dist/database/index.d.ts +2 -0
- package/dist/index.js +470 -211
- package/dist/index.mjs +434 -179
- package/dist/resolver/index.d.ts +12 -1
- package/dist/resolver/media-utils.d.ts +3 -3
- package/package.json +16 -17
package/dist/index.js
CHANGED
|
@@ -27,8 +27,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
28
|
|
|
29
29
|
// src/index.ts
|
|
30
|
-
var
|
|
31
|
-
__export(
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
32
|
AuditFileSystemBridge: () => AuditFileSystemBridge,
|
|
33
33
|
Database: () => Database,
|
|
34
34
|
FilesystemBridge: () => FilesystemBridge,
|
|
@@ -62,7 +62,7 @@ __export(src_exports, {
|
|
|
62
62
|
transformDocument: () => transformDocument,
|
|
63
63
|
transformDocumentIntoPayload: () => transformDocumentIntoPayload
|
|
64
64
|
});
|
|
65
|
-
module.exports = __toCommonJS(
|
|
65
|
+
module.exports = __toCommonJS(index_exports);
|
|
66
66
|
|
|
67
67
|
// src/build.ts
|
|
68
68
|
var import_graphql2 = require("graphql");
|
|
@@ -1095,41 +1095,6 @@ function* walk(maybeNode, visited = /* @__PURE__ */ new WeakSet()) {
|
|
|
1095
1095
|
yield maybeNode;
|
|
1096
1096
|
visited.add(maybeNode);
|
|
1097
1097
|
}
|
|
1098
|
-
function addNamespaceToSchema(maybeNode, namespace = []) {
|
|
1099
|
-
if (typeof maybeNode === "string") {
|
|
1100
|
-
return maybeNode;
|
|
1101
|
-
}
|
|
1102
|
-
if (typeof maybeNode === "boolean") {
|
|
1103
|
-
return maybeNode;
|
|
1104
|
-
}
|
|
1105
|
-
const newNode = maybeNode;
|
|
1106
|
-
const keys = Object.keys(maybeNode);
|
|
1107
|
-
Object.values(maybeNode).map((m, index) => {
|
|
1108
|
-
const key = keys[index];
|
|
1109
|
-
if (Array.isArray(m)) {
|
|
1110
|
-
newNode[key] = m.map((element) => {
|
|
1111
|
-
if (!element) {
|
|
1112
|
-
return;
|
|
1113
|
-
}
|
|
1114
|
-
if (!element.hasOwnProperty("name")) {
|
|
1115
|
-
return element;
|
|
1116
|
-
}
|
|
1117
|
-
const value = element.name || element.value;
|
|
1118
|
-
return addNamespaceToSchema(element, [...namespace, value]);
|
|
1119
|
-
});
|
|
1120
|
-
} else {
|
|
1121
|
-
if (!m) {
|
|
1122
|
-
return;
|
|
1123
|
-
}
|
|
1124
|
-
if (!m.hasOwnProperty("name")) {
|
|
1125
|
-
newNode[key] = m;
|
|
1126
|
-
} else {
|
|
1127
|
-
newNode[key] = addNamespaceToSchema(m, [...namespace, m.name]);
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
});
|
|
1131
|
-
return { ...newNode, namespace };
|
|
1132
|
-
}
|
|
1133
1098
|
var generateNamespacedFieldName = (names, suffix = "") => {
|
|
1134
1099
|
return (suffix ? [...names, suffix] : names).map(capitalize).join("");
|
|
1135
1100
|
};
|
|
@@ -1949,7 +1914,7 @@ var Builder = class {
|
|
|
1949
1914
|
* ```
|
|
1950
1915
|
*
|
|
1951
1916
|
* @public
|
|
1952
|
-
* @param collection a
|
|
1917
|
+
* @param collection a TinaCloud collection
|
|
1953
1918
|
*/
|
|
1954
1919
|
this.collectionFragment = async (collection) => {
|
|
1955
1920
|
const name = NAMER.dataTypeName(collection.namespace);
|
|
@@ -2965,12 +2930,13 @@ var filterSelections = (arr) => {
|
|
|
2965
2930
|
};
|
|
2966
2931
|
|
|
2967
2932
|
// src/schema/createSchema.ts
|
|
2968
|
-
var
|
|
2933
|
+
var import_schema_tools3 = require("@tinacms/schema-tools");
|
|
2969
2934
|
|
|
2970
2935
|
// src/schema/validate.ts
|
|
2936
|
+
var import_schema_tools = require("@tinacms/schema-tools");
|
|
2971
2937
|
var import_lodash2 = __toESM(require("lodash.clonedeep"));
|
|
2972
2938
|
var yup2 = __toESM(require("yup"));
|
|
2973
|
-
var
|
|
2939
|
+
var import_schema_tools2 = require("@tinacms/schema-tools");
|
|
2974
2940
|
var FIELD_TYPES = [
|
|
2975
2941
|
"string",
|
|
2976
2942
|
"number",
|
|
@@ -2983,7 +2949,7 @@ var FIELD_TYPES = [
|
|
|
2983
2949
|
"password"
|
|
2984
2950
|
];
|
|
2985
2951
|
var validateSchema = async (schema) => {
|
|
2986
|
-
const schema2 = addNamespaceToSchema(
|
|
2952
|
+
const schema2 = (0, import_schema_tools.addNamespaceToSchema)(
|
|
2987
2953
|
(0, import_lodash2.default)(schema)
|
|
2988
2954
|
);
|
|
2989
2955
|
const collections = await sequential(
|
|
@@ -2992,7 +2958,7 @@ var validateSchema = async (schema) => {
|
|
|
2992
2958
|
);
|
|
2993
2959
|
validationCollectionsPathAndMatch(collections);
|
|
2994
2960
|
if (schema2.config) {
|
|
2995
|
-
const config = (0,
|
|
2961
|
+
const config = (0, import_schema_tools2.validateTinaCloudSchemaConfig)(schema2.config);
|
|
2996
2962
|
return {
|
|
2997
2963
|
collections,
|
|
2998
2964
|
config
|
|
@@ -3124,7 +3090,7 @@ var validateField = async (field) => {
|
|
|
3124
3090
|
// package.json
|
|
3125
3091
|
var package_default = {
|
|
3126
3092
|
name: "@tinacms/graphql",
|
|
3127
|
-
version: "1.5.
|
|
3093
|
+
version: "1.5.16",
|
|
3128
3094
|
main: "dist/index.js",
|
|
3129
3095
|
module: "dist/index.mjs",
|
|
3130
3096
|
typings: "dist/index.d.ts",
|
|
@@ -3151,8 +3117,8 @@ var package_default = {
|
|
|
3151
3117
|
build: "tinacms-scripts build",
|
|
3152
3118
|
docs: "pnpm typedoc",
|
|
3153
3119
|
serve: "pnpm nodemon dist/server.js",
|
|
3154
|
-
test: "
|
|
3155
|
-
"test-watch": "
|
|
3120
|
+
test: "vitest run",
|
|
3121
|
+
"test-watch": "vitest"
|
|
3156
3122
|
},
|
|
3157
3123
|
dependencies: {
|
|
3158
3124
|
"@iarna/toml": "^2.2.5",
|
|
@@ -3160,12 +3126,12 @@ var package_default = {
|
|
|
3160
3126
|
"@tinacms/schema-tools": "workspace:*",
|
|
3161
3127
|
"abstract-level": "^1.0.4",
|
|
3162
3128
|
"date-fns": "^2.30.0",
|
|
3163
|
-
"fast-glob": "^3.3.
|
|
3164
|
-
"fs-extra": "^11.
|
|
3129
|
+
"fast-glob": "^3.3.3",
|
|
3130
|
+
"fs-extra": "^11.3.0",
|
|
3165
3131
|
"glob-parent": "^6.0.2",
|
|
3166
3132
|
graphql: "15.8.0",
|
|
3167
3133
|
"gray-matter": "^4.0.3",
|
|
3168
|
-
"isomorphic-git": "^1.
|
|
3134
|
+
"isomorphic-git": "^1.29.0",
|
|
3169
3135
|
"js-sha1": "^0.6.0",
|
|
3170
3136
|
"js-yaml": "^3.14.1",
|
|
3171
3137
|
"jsonpath-plus": "10.1.0",
|
|
@@ -3175,7 +3141,7 @@ var package_default = {
|
|
|
3175
3141
|
"many-level": "^2.0.0",
|
|
3176
3142
|
micromatch: "4.0.8",
|
|
3177
3143
|
"normalize-path": "^3.0.0",
|
|
3178
|
-
"readable-stream": "^4.
|
|
3144
|
+
"readable-stream": "^4.7.0",
|
|
3179
3145
|
scmp: "^2.1.0",
|
|
3180
3146
|
yup: "^0.32.11"
|
|
3181
3147
|
},
|
|
@@ -3193,24 +3159,23 @@ var package_default = {
|
|
|
3193
3159
|
"@types/estree": "^0.0.50",
|
|
3194
3160
|
"@types/express": "^4.17.21",
|
|
3195
3161
|
"@types/fs-extra": "^9.0.13",
|
|
3196
|
-
"@types/jest": "^26.0.24",
|
|
3197
3162
|
"@types/js-yaml": "^3.12.10",
|
|
3198
3163
|
"@types/lodash.camelcase": "^4.3.9",
|
|
3199
3164
|
"@types/lodash.upperfirst": "^4.3.9",
|
|
3200
3165
|
"@types/lru-cache": "^5.1.1",
|
|
3201
3166
|
"@types/mdast": "^3.0.15",
|
|
3202
3167
|
"@types/micromatch": "^4.0.9",
|
|
3203
|
-
"@types/node": "^22.
|
|
3168
|
+
"@types/node": "^22.13.1",
|
|
3204
3169
|
"@types/normalize-path": "^3.0.2",
|
|
3205
3170
|
"@types/ws": "^7.4.7",
|
|
3206
3171
|
"@types/yup": "^0.29.14",
|
|
3207
|
-
jest: "^29.7.0",
|
|
3208
|
-
"jest-diff": "^29.7.0",
|
|
3209
3172
|
"jest-file-snapshot": "^0.5.0",
|
|
3210
|
-
"jest-matcher-utils": "^29.7.0",
|
|
3211
3173
|
"memory-level": "^1.0.0",
|
|
3212
3174
|
nodemon: "3.1.4",
|
|
3213
|
-
typescript: "^5.
|
|
3175
|
+
typescript: "^5.7.3",
|
|
3176
|
+
vite: "^4.5.9",
|
|
3177
|
+
vitest: "^0.32.4",
|
|
3178
|
+
zod: "^3.24.2"
|
|
3214
3179
|
}
|
|
3215
3180
|
};
|
|
3216
3181
|
|
|
@@ -3225,7 +3190,7 @@ var createSchema = async ({
|
|
|
3225
3190
|
if (flags && flags.length > 0) {
|
|
3226
3191
|
meta["flags"] = flags;
|
|
3227
3192
|
}
|
|
3228
|
-
return new
|
|
3193
|
+
return new import_schema_tools3.TinaSchema({
|
|
3229
3194
|
version: {
|
|
3230
3195
|
fullVersion: package_default.version,
|
|
3231
3196
|
major,
|
|
@@ -3367,7 +3332,9 @@ var _buildSchema = async (builder, tinaSchema) => {
|
|
|
3367
3332
|
await builder.buildCreateCollectionFolderMutation()
|
|
3368
3333
|
);
|
|
3369
3334
|
await sequential(collections, async (collection) => {
|
|
3370
|
-
queryTypeDefinitionFields.push(
|
|
3335
|
+
queryTypeDefinitionFields.push(
|
|
3336
|
+
await builder.collectionDocument(collection)
|
|
3337
|
+
);
|
|
3371
3338
|
if (collection.isAuthCollection) {
|
|
3372
3339
|
queryTypeDefinitionFields.push(
|
|
3373
3340
|
await builder.authenticationCollectionDocument(collection)
|
|
@@ -3683,7 +3650,9 @@ var LevelProxyHandler = {
|
|
|
3683
3650
|
throw new Error(`The property, ${property.toString()}, doesn't exist`);
|
|
3684
3651
|
}
|
|
3685
3652
|
if (typeof target[property] !== "function") {
|
|
3686
|
-
throw new Error(
|
|
3653
|
+
throw new Error(
|
|
3654
|
+
`The property, ${property.toString()}, is not a function`
|
|
3655
|
+
);
|
|
3687
3656
|
}
|
|
3688
3657
|
if (property === "get") {
|
|
3689
3658
|
return async (...args) => {
|
|
@@ -3723,7 +3692,7 @@ var import_path2 = __toESM(require("path"));
|
|
|
3723
3692
|
var import_toml = __toESM(require("@iarna/toml"));
|
|
3724
3693
|
var import_js_yaml = __toESM(require("js-yaml"));
|
|
3725
3694
|
var import_gray_matter = __toESM(require("gray-matter"));
|
|
3726
|
-
var
|
|
3695
|
+
var import_schema_tools4 = require("@tinacms/schema-tools");
|
|
3727
3696
|
var import_micromatch = __toESM(require("micromatch"));
|
|
3728
3697
|
var import_path = __toESM(require("path"));
|
|
3729
3698
|
|
|
@@ -3936,7 +3905,7 @@ var scanAllContent = async (tinaSchema, bridge, callback) => {
|
|
|
3936
3905
|
const filesSeen = /* @__PURE__ */ new Map();
|
|
3937
3906
|
const duplicateFiles = /* @__PURE__ */ new Set();
|
|
3938
3907
|
await sequential(tinaSchema.getCollections(), async (collection) => {
|
|
3939
|
-
const normalPath = (0,
|
|
3908
|
+
const normalPath = (0, import_schema_tools4.normalizePath)(collection.path);
|
|
3940
3909
|
const format = collection.format || "md";
|
|
3941
3910
|
const documentPaths = await bridge.glob(normalPath, format);
|
|
3942
3911
|
const matches = tinaSchema.getMatches({ collection });
|
|
@@ -4048,7 +4017,7 @@ var getTemplateForFile = (templateInfo, data) => {
|
|
|
4048
4017
|
throw new Error(`Unable to determine template`);
|
|
4049
4018
|
};
|
|
4050
4019
|
var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo) => {
|
|
4051
|
-
const dataString = await bridge.get((0,
|
|
4020
|
+
const dataString = await bridge.get((0, import_schema_tools4.normalizePath)(filepath));
|
|
4052
4021
|
const data = parseFile(
|
|
4053
4022
|
dataString,
|
|
4054
4023
|
import_path.default.extname(filepath),
|
|
@@ -4070,6 +4039,9 @@ var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo)
|
|
|
4070
4039
|
|
|
4071
4040
|
// src/database/datalayer.ts
|
|
4072
4041
|
var DEFAULT_COLLECTION_SORT_KEY = "__filepath__";
|
|
4042
|
+
var REFS_COLLECTIONS_SORT_KEY = "__refs__";
|
|
4043
|
+
var REFS_REFERENCE_FIELD = "__tina_ref__";
|
|
4044
|
+
var REFS_PATH_FIELD = "__tina_ref_path__";
|
|
4073
4045
|
var DEFAULT_NUMERIC_LPAD = 4;
|
|
4074
4046
|
var applyPadding = (input, pad) => {
|
|
4075
4047
|
if (pad) {
|
|
@@ -4527,7 +4499,7 @@ var FolderTreeBuilder = class {
|
|
|
4527
4499
|
return this._tree;
|
|
4528
4500
|
}
|
|
4529
4501
|
update(documentPath, collectionPath) {
|
|
4530
|
-
let folderPath = import_path2.default.dirname((0,
|
|
4502
|
+
let folderPath = import_path2.default.dirname((0, import_schema_tools4.normalizePath)(documentPath));
|
|
4531
4503
|
if (folderPath === ".") {
|
|
4532
4504
|
folderPath = "";
|
|
4533
4505
|
}
|
|
@@ -4540,7 +4512,7 @@ var FolderTreeBuilder = class {
|
|
|
4540
4512
|
if (!this._tree[current2]) {
|
|
4541
4513
|
this._tree[current2] = /* @__PURE__ */ new Set();
|
|
4542
4514
|
}
|
|
4543
|
-
this._tree[current2].add((0,
|
|
4515
|
+
this._tree[current2].add((0, import_schema_tools4.normalizePath)(import_path2.default.join(current2, part)));
|
|
4544
4516
|
parent.push(part);
|
|
4545
4517
|
});
|
|
4546
4518
|
const current = parent.join("/");
|
|
@@ -4643,6 +4615,57 @@ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opT
|
|
|
4643
4615
|
}
|
|
4644
4616
|
return result;
|
|
4645
4617
|
};
|
|
4618
|
+
var makeRefOpsForDocument = (filepath, collection, references, data, opType, level) => {
|
|
4619
|
+
const result = [];
|
|
4620
|
+
if (collection) {
|
|
4621
|
+
for (const [c, referencePaths] of Object.entries(references || {})) {
|
|
4622
|
+
if (!referencePaths.length) {
|
|
4623
|
+
continue;
|
|
4624
|
+
}
|
|
4625
|
+
const collectionSublevel = level.sublevel(c, SUBLEVEL_OPTIONS);
|
|
4626
|
+
const refSublevel = collectionSublevel.sublevel(
|
|
4627
|
+
REFS_COLLECTIONS_SORT_KEY,
|
|
4628
|
+
SUBLEVEL_OPTIONS
|
|
4629
|
+
);
|
|
4630
|
+
const references2 = {};
|
|
4631
|
+
for (const path7 of referencePaths) {
|
|
4632
|
+
const ref = (0, import_jsonpath_plus.JSONPath)({ path: path7, json: data });
|
|
4633
|
+
if (!ref) {
|
|
4634
|
+
continue;
|
|
4635
|
+
}
|
|
4636
|
+
if (Array.isArray(ref)) {
|
|
4637
|
+
for (const r of ref) {
|
|
4638
|
+
if (!r) {
|
|
4639
|
+
continue;
|
|
4640
|
+
}
|
|
4641
|
+
if (references2[r]) {
|
|
4642
|
+
references2[r].push(path7);
|
|
4643
|
+
} else {
|
|
4644
|
+
references2[r] = [path7];
|
|
4645
|
+
}
|
|
4646
|
+
}
|
|
4647
|
+
} else {
|
|
4648
|
+
if (references2[ref]) {
|
|
4649
|
+
references2[ref].push(path7);
|
|
4650
|
+
} else {
|
|
4651
|
+
references2[ref] = [path7];
|
|
4652
|
+
}
|
|
4653
|
+
}
|
|
4654
|
+
}
|
|
4655
|
+
for (const ref of Object.keys(references2)) {
|
|
4656
|
+
for (const path7 of references2[ref]) {
|
|
4657
|
+
result.push({
|
|
4658
|
+
type: opType,
|
|
4659
|
+
key: `${ref}${INDEX_KEY_FIELD_SEPARATOR}${path7}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
|
|
4660
|
+
sublevel: refSublevel,
|
|
4661
|
+
value: opType === "put" ? {} : void 0
|
|
4662
|
+
});
|
|
4663
|
+
}
|
|
4664
|
+
}
|
|
4665
|
+
}
|
|
4666
|
+
}
|
|
4667
|
+
return result;
|
|
4668
|
+
};
|
|
4646
4669
|
var makeStringEscaper = (regex, replacement) => {
|
|
4647
4670
|
return (input) => {
|
|
4648
4671
|
if (Array.isArray(input)) {
|
|
@@ -4864,24 +4887,33 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
|
|
|
4864
4887
|
throw e;
|
|
4865
4888
|
}
|
|
4866
4889
|
};
|
|
4867
|
-
var updateObjectWithJsonPath = (obj, path7, newValue) => {
|
|
4890
|
+
var updateObjectWithJsonPath = (obj, path7, oldValue, newValue) => {
|
|
4891
|
+
let updated = false;
|
|
4868
4892
|
if (!path7.includes(".") && !path7.includes("[")) {
|
|
4869
|
-
if (path7 in obj) {
|
|
4893
|
+
if (path7 in obj && obj[path7] === oldValue) {
|
|
4870
4894
|
obj[path7] = newValue;
|
|
4895
|
+
updated = true;
|
|
4871
4896
|
}
|
|
4872
|
-
return obj;
|
|
4873
|
-
}
|
|
4874
|
-
const parentPath = path7.replace(/\.[
|
|
4875
|
-
const keyToUpdate = path7.match(/[
|
|
4876
|
-
const parents = (0, import_jsonpath_plus2.JSONPath)({
|
|
4897
|
+
return { object: obj, updated };
|
|
4898
|
+
}
|
|
4899
|
+
const parentPath = path7.replace(/\.[^.\[\]]+$/, "");
|
|
4900
|
+
const keyToUpdate = path7.match(/[^.\[\]]+$/)[0];
|
|
4901
|
+
const parents = (0, import_jsonpath_plus2.JSONPath)({
|
|
4902
|
+
path: parentPath,
|
|
4903
|
+
json: obj,
|
|
4904
|
+
resultType: "value"
|
|
4905
|
+
});
|
|
4877
4906
|
if (parents.length > 0) {
|
|
4878
4907
|
parents.forEach((parent) => {
|
|
4879
4908
|
if (parent && typeof parent === "object" && keyToUpdate in parent) {
|
|
4880
|
-
parent[keyToUpdate]
|
|
4909
|
+
if (parent[keyToUpdate] === oldValue) {
|
|
4910
|
+
parent[keyToUpdate] = newValue;
|
|
4911
|
+
updated = true;
|
|
4912
|
+
}
|
|
4881
4913
|
}
|
|
4882
4914
|
});
|
|
4883
4915
|
}
|
|
4884
|
-
return obj;
|
|
4916
|
+
return { object: obj, updated };
|
|
4885
4917
|
};
|
|
4886
4918
|
var Resolver = class {
|
|
4887
4919
|
constructor(init) {
|
|
@@ -4898,7 +4930,9 @@ var Resolver = class {
|
|
|
4898
4930
|
};
|
|
4899
4931
|
this.getRaw = async (fullPath) => {
|
|
4900
4932
|
if (typeof fullPath !== "string") {
|
|
4901
|
-
throw new Error(
|
|
4933
|
+
throw new Error(
|
|
4934
|
+
`fullPath must be of type string for getDocument request`
|
|
4935
|
+
);
|
|
4902
4936
|
}
|
|
4903
4937
|
return this.database.get(fullPath);
|
|
4904
4938
|
};
|
|
@@ -4927,7 +4961,9 @@ var Resolver = class {
|
|
|
4927
4961
|
};
|
|
4928
4962
|
this.getDocument = async (fullPath, opts = {}) => {
|
|
4929
4963
|
if (typeof fullPath !== "string") {
|
|
4930
|
-
throw new Error(
|
|
4964
|
+
throw new Error(
|
|
4965
|
+
`fullPath must be of type string for getDocument request`
|
|
4966
|
+
);
|
|
4931
4967
|
}
|
|
4932
4968
|
const rawData = await this.getRaw(fullPath);
|
|
4933
4969
|
const hasReferences = (opts == null ? void 0 : opts.checkReferences) ? await this.hasReferences(fullPath, opts.collection) : void 0;
|
|
@@ -4942,7 +4978,9 @@ var Resolver = class {
|
|
|
4942
4978
|
};
|
|
4943
4979
|
this.deleteDocument = async (fullPath) => {
|
|
4944
4980
|
if (typeof fullPath !== "string") {
|
|
4945
|
-
throw new Error(
|
|
4981
|
+
throw new Error(
|
|
4982
|
+
`fullPath must be of type string for getDocument request`
|
|
4983
|
+
);
|
|
4946
4984
|
}
|
|
4947
4985
|
await this.database.delete(fullPath);
|
|
4948
4986
|
};
|
|
@@ -5146,7 +5184,11 @@ var Resolver = class {
|
|
|
5146
5184
|
collection,
|
|
5147
5185
|
doc == null ? void 0 : doc._rawData
|
|
5148
5186
|
);
|
|
5149
|
-
await this.database.put(
|
|
5187
|
+
await this.database.put(
|
|
5188
|
+
realPath,
|
|
5189
|
+
{ ...oldDoc, ...params },
|
|
5190
|
+
collection.name
|
|
5191
|
+
);
|
|
5150
5192
|
return this.getDocument(realPath);
|
|
5151
5193
|
};
|
|
5152
5194
|
/**
|
|
@@ -5260,17 +5302,35 @@ var Resolver = class {
|
|
|
5260
5302
|
await this.deleteDocument(realPath);
|
|
5261
5303
|
if (await this.hasReferences(realPath, collection)) {
|
|
5262
5304
|
const collRefs = await this.findReferences(realPath, collection);
|
|
5263
|
-
for (const [collection2,
|
|
5264
|
-
for (const [
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5305
|
+
for (const [collection2, docsWithRefs] of Object.entries(collRefs)) {
|
|
5306
|
+
for (const [pathToDocWithRef, referencePaths] of Object.entries(
|
|
5307
|
+
docsWithRefs
|
|
5308
|
+
)) {
|
|
5309
|
+
let refDoc = await this.getRaw(pathToDocWithRef);
|
|
5310
|
+
let hasUpdate = false;
|
|
5311
|
+
for (const path7 of referencePaths) {
|
|
5312
|
+
const { object: object2, updated } = updateObjectWithJsonPath(
|
|
5268
5313
|
refDoc,
|
|
5269
|
-
|
|
5314
|
+
path7,
|
|
5315
|
+
realPath,
|
|
5270
5316
|
null
|
|
5271
5317
|
);
|
|
5318
|
+
refDoc = object2;
|
|
5319
|
+
hasUpdate = updated || hasUpdate;
|
|
5320
|
+
}
|
|
5321
|
+
if (hasUpdate) {
|
|
5322
|
+
const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
|
|
5323
|
+
if (!collectionWithRef) {
|
|
5324
|
+
throw new Error(
|
|
5325
|
+
`Unable to find collection for ${pathToDocWithRef}`
|
|
5326
|
+
);
|
|
5327
|
+
}
|
|
5328
|
+
await this.database.put(
|
|
5329
|
+
pathToDocWithRef,
|
|
5330
|
+
refDoc,
|
|
5331
|
+
collectionWithRef.name
|
|
5332
|
+
);
|
|
5272
5333
|
}
|
|
5273
|
-
await this.database.put(refPath, refDoc, collection2);
|
|
5274
5334
|
}
|
|
5275
5335
|
}
|
|
5276
5336
|
}
|
|
@@ -5290,26 +5350,49 @@ var Resolver = class {
|
|
|
5290
5350
|
collection == null ? void 0 : collection.path,
|
|
5291
5351
|
args.params.relativePath
|
|
5292
5352
|
);
|
|
5353
|
+
if (newRealPath === realPath) {
|
|
5354
|
+
return doc;
|
|
5355
|
+
}
|
|
5293
5356
|
await this.database.put(newRealPath, doc._rawData, collection.name);
|
|
5294
5357
|
await this.deleteDocument(realPath);
|
|
5295
5358
|
const collRefs = await this.findReferences(realPath, collection);
|
|
5296
|
-
for (const [collection2,
|
|
5297
|
-
for (const [
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5359
|
+
for (const [collection2, docsWithRefs] of Object.entries(collRefs)) {
|
|
5360
|
+
for (const [pathToDocWithRef, referencePaths] of Object.entries(
|
|
5361
|
+
docsWithRefs
|
|
5362
|
+
)) {
|
|
5363
|
+
let docWithRef = await this.getRaw(pathToDocWithRef);
|
|
5364
|
+
let hasUpdate = false;
|
|
5365
|
+
for (const path7 of referencePaths) {
|
|
5366
|
+
const { object: object2, updated } = updateObjectWithJsonPath(
|
|
5367
|
+
docWithRef,
|
|
5368
|
+
path7,
|
|
5369
|
+
realPath,
|
|
5303
5370
|
newRealPath
|
|
5304
5371
|
);
|
|
5372
|
+
docWithRef = object2;
|
|
5373
|
+
hasUpdate = updated || hasUpdate;
|
|
5374
|
+
}
|
|
5375
|
+
if (hasUpdate) {
|
|
5376
|
+
const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
|
|
5377
|
+
if (!collectionWithRef) {
|
|
5378
|
+
throw new Error(
|
|
5379
|
+
`Unable to find collection for ${pathToDocWithRef}`
|
|
5380
|
+
);
|
|
5381
|
+
}
|
|
5382
|
+
await this.database.put(
|
|
5383
|
+
pathToDocWithRef,
|
|
5384
|
+
docWithRef,
|
|
5385
|
+
collectionWithRef.name
|
|
5386
|
+
);
|
|
5305
5387
|
}
|
|
5306
|
-
await this.database.put(refPath, refDoc, collection2);
|
|
5307
5388
|
}
|
|
5308
5389
|
}
|
|
5309
5390
|
return this.getDocument(newRealPath);
|
|
5310
5391
|
}
|
|
5311
5392
|
if (alreadyExists === false) {
|
|
5312
|
-
throw new Error(
|
|
5393
|
+
throw new Error(
|
|
5394
|
+
`Unable to update document, ${realPath} does not exist`
|
|
5395
|
+
);
|
|
5313
5396
|
}
|
|
5314
5397
|
return this.updateResolveDocument({
|
|
5315
5398
|
collection,
|
|
@@ -5435,35 +5518,30 @@ var Resolver = class {
|
|
|
5435
5518
|
*/
|
|
5436
5519
|
this.hasReferences = async (id, c) => {
|
|
5437
5520
|
let count = 0;
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
(refId) => {
|
|
5459
|
-
count++;
|
|
5460
|
-
return refId;
|
|
5461
|
-
}
|
|
5462
|
-
);
|
|
5463
|
-
if (count) {
|
|
5464
|
-
return true;
|
|
5465
|
-
}
|
|
5521
|
+
await this.database.query(
|
|
5522
|
+
{
|
|
5523
|
+
collection: c.name,
|
|
5524
|
+
filterChain: makeFilterChain({
|
|
5525
|
+
conditions: [
|
|
5526
|
+
{
|
|
5527
|
+
filterPath: REFS_REFERENCE_FIELD,
|
|
5528
|
+
filterExpression: {
|
|
5529
|
+
_type: "string",
|
|
5530
|
+
_list: false,
|
|
5531
|
+
eq: id
|
|
5532
|
+
}
|
|
5533
|
+
}
|
|
5534
|
+
]
|
|
5535
|
+
}),
|
|
5536
|
+
sort: REFS_COLLECTIONS_SORT_KEY
|
|
5537
|
+
},
|
|
5538
|
+
(refId) => {
|
|
5539
|
+
count++;
|
|
5540
|
+
return refId;
|
|
5466
5541
|
}
|
|
5542
|
+
);
|
|
5543
|
+
if (count) {
|
|
5544
|
+
return true;
|
|
5467
5545
|
}
|
|
5468
5546
|
return false;
|
|
5469
5547
|
};
|
|
@@ -5471,46 +5549,41 @@ var Resolver = class {
|
|
|
5471
5549
|
* Finds references to a document
|
|
5472
5550
|
* @param id the id of the document to find references to
|
|
5473
5551
|
* @param c the collection to find references in
|
|
5474
|
-
* @returns
|
|
5552
|
+
* @returns a map of references to the document
|
|
5475
5553
|
*/
|
|
5476
5554
|
this.findReferences = async (id, c) => {
|
|
5477
5555
|
const references = {};
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
_list: false,
|
|
5491
|
-
eq: id
|
|
5492
|
-
}
|
|
5493
|
-
}
|
|
5494
|
-
]
|
|
5495
|
-
}),
|
|
5496
|
-
sort: ref.field.name
|
|
5497
|
-
},
|
|
5498
|
-
(refId) => {
|
|
5499
|
-
if (!references[collection]) {
|
|
5500
|
-
references[collection] = {};
|
|
5501
|
-
}
|
|
5502
|
-
if (!references[collection][refId]) {
|
|
5503
|
-
references[collection][refId] = [];
|
|
5556
|
+
await this.database.query(
|
|
5557
|
+
{
|
|
5558
|
+
collection: c.name,
|
|
5559
|
+
filterChain: makeFilterChain({
|
|
5560
|
+
conditions: [
|
|
5561
|
+
{
|
|
5562
|
+
filterPath: REFS_REFERENCE_FIELD,
|
|
5563
|
+
filterExpression: {
|
|
5564
|
+
_type: "string",
|
|
5565
|
+
_list: false,
|
|
5566
|
+
eq: id
|
|
5567
|
+
}
|
|
5504
5568
|
}
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5569
|
+
]
|
|
5570
|
+
}),
|
|
5571
|
+
sort: REFS_COLLECTIONS_SORT_KEY
|
|
5572
|
+
},
|
|
5573
|
+
(refId, rawItem) => {
|
|
5574
|
+
if (!references[c.name]) {
|
|
5575
|
+
references[c.name] = {};
|
|
5576
|
+
}
|
|
5577
|
+
if (!references[c.name][refId]) {
|
|
5578
|
+
references[c.name][refId] = [];
|
|
5579
|
+
}
|
|
5580
|
+
const referencePath = rawItem == null ? void 0 : rawItem[REFS_PATH_FIELD];
|
|
5581
|
+
if (referencePath) {
|
|
5582
|
+
references[c.name][refId].push(referencePath);
|
|
5583
|
+
}
|
|
5584
|
+
return refId;
|
|
5512
5585
|
}
|
|
5513
|
-
|
|
5586
|
+
);
|
|
5514
5587
|
return references;
|
|
5515
5588
|
};
|
|
5516
5589
|
this.buildFieldMutations = async (fieldParams, template, existingData) => {
|
|
@@ -6234,7 +6307,7 @@ var Database = class {
|
|
|
6234
6307
|
const contentObject = await level.sublevel(
|
|
6235
6308
|
CONTENT_ROOT_PREFIX,
|
|
6236
6309
|
SUBLEVEL_OPTIONS
|
|
6237
|
-
).get((0,
|
|
6310
|
+
).get((0, import_schema_tools4.normalizePath)(filepath));
|
|
6238
6311
|
if (!contentObject) {
|
|
6239
6312
|
throw new NotFoundError(`Unable to find record ${filepath}`);
|
|
6240
6313
|
}
|
|
@@ -6246,6 +6319,7 @@ var Database = class {
|
|
|
6246
6319
|
}
|
|
6247
6320
|
};
|
|
6248
6321
|
this.addPendingDocument = async (filepath, data) => {
|
|
6322
|
+
var _a;
|
|
6249
6323
|
await this.initLevel();
|
|
6250
6324
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
6251
6325
|
const collection = await this.collectionForPath(filepath);
|
|
@@ -6259,7 +6333,8 @@ var Database = class {
|
|
|
6259
6333
|
);
|
|
6260
6334
|
const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
|
|
6261
6335
|
const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
|
|
6262
|
-
const
|
|
6336
|
+
const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collection.name];
|
|
6337
|
+
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
6263
6338
|
if (!(collection == null ? void 0 : collection.isDetached)) {
|
|
6264
6339
|
if (this.bridge) {
|
|
6265
6340
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
@@ -6287,6 +6362,14 @@ var Database = class {
|
|
|
6287
6362
|
let delOps = [];
|
|
6288
6363
|
if (!isGitKeep(normalizedPath, collection)) {
|
|
6289
6364
|
putOps = [
|
|
6365
|
+
...makeRefOpsForDocument(
|
|
6366
|
+
normalizedPath,
|
|
6367
|
+
collection == null ? void 0 : collection.name,
|
|
6368
|
+
collectionReferences,
|
|
6369
|
+
dataFields,
|
|
6370
|
+
"put",
|
|
6371
|
+
level
|
|
6372
|
+
),
|
|
6290
6373
|
...makeIndexOpsForDocument(
|
|
6291
6374
|
normalizedPath,
|
|
6292
6375
|
collection == null ? void 0 : collection.name,
|
|
@@ -6310,6 +6393,14 @@ var Database = class {
|
|
|
6310
6393
|
SUBLEVEL_OPTIONS
|
|
6311
6394
|
).get(normalizedPath);
|
|
6312
6395
|
delOps = existingItem ? [
|
|
6396
|
+
...makeRefOpsForDocument(
|
|
6397
|
+
normalizedPath,
|
|
6398
|
+
collection == null ? void 0 : collection.name,
|
|
6399
|
+
collectionReferences,
|
|
6400
|
+
existingItem,
|
|
6401
|
+
"del",
|
|
6402
|
+
level
|
|
6403
|
+
),
|
|
6313
6404
|
...makeIndexOpsForDocument(
|
|
6314
6405
|
normalizedPath,
|
|
6315
6406
|
collection == null ? void 0 : collection.name,
|
|
@@ -6345,7 +6436,7 @@ var Database = class {
|
|
|
6345
6436
|
await level.batch(ops);
|
|
6346
6437
|
};
|
|
6347
6438
|
this.put = async (filepath, data, collectionName) => {
|
|
6348
|
-
var _a, _b;
|
|
6439
|
+
var _a, _b, _c;
|
|
6349
6440
|
await this.initLevel();
|
|
6350
6441
|
try {
|
|
6351
6442
|
if (SYSTEM_FILES.includes(filepath)) {
|
|
@@ -6358,13 +6449,14 @@ var Database = class {
|
|
|
6358
6449
|
);
|
|
6359
6450
|
collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collectionName];
|
|
6360
6451
|
}
|
|
6361
|
-
const
|
|
6452
|
+
const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collectionName];
|
|
6453
|
+
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
6362
6454
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
6363
6455
|
const collection = await this.collectionForPath(filepath);
|
|
6364
6456
|
if (!collection) {
|
|
6365
6457
|
throw new import_graphql6.GraphQLError(`Unable to find collection for ${filepath}.`);
|
|
6366
6458
|
}
|
|
6367
|
-
if (((
|
|
6459
|
+
if (((_b = collection.match) == null ? void 0 : _b.exclude) || ((_c = collection.match) == null ? void 0 : _c.include)) {
|
|
6368
6460
|
const matches = this.tinaSchema.getMatches({ collection });
|
|
6369
6461
|
const match = import_micromatch2.default.isMatch(filepath, matches);
|
|
6370
6462
|
if (!match) {
|
|
@@ -6405,6 +6497,14 @@ var Database = class {
|
|
|
6405
6497
|
let delOps = [];
|
|
6406
6498
|
if (!isGitKeep(normalizedPath, collection)) {
|
|
6407
6499
|
putOps = [
|
|
6500
|
+
...makeRefOpsForDocument(
|
|
6501
|
+
normalizedPath,
|
|
6502
|
+
collectionName,
|
|
6503
|
+
collectionReferences,
|
|
6504
|
+
dataFields,
|
|
6505
|
+
"put",
|
|
6506
|
+
level
|
|
6507
|
+
),
|
|
6408
6508
|
...makeIndexOpsForDocument(
|
|
6409
6509
|
normalizedPath,
|
|
6410
6510
|
collectionName,
|
|
@@ -6428,6 +6528,14 @@ var Database = class {
|
|
|
6428
6528
|
SUBLEVEL_OPTIONS
|
|
6429
6529
|
).get(normalizedPath);
|
|
6430
6530
|
delOps = existingItem ? [
|
|
6531
|
+
...makeRefOpsForDocument(
|
|
6532
|
+
normalizedPath,
|
|
6533
|
+
collectionName,
|
|
6534
|
+
collectionReferences,
|
|
6535
|
+
existingItem,
|
|
6536
|
+
"del",
|
|
6537
|
+
level
|
|
6538
|
+
),
|
|
6431
6539
|
...makeIndexOpsForDocument(
|
|
6432
6540
|
normalizedPath,
|
|
6433
6541
|
collectionName,
|
|
@@ -6532,7 +6640,7 @@ var Database = class {
|
|
|
6532
6640
|
};
|
|
6533
6641
|
this.getLookup = async (returnType) => {
|
|
6534
6642
|
await this.initLevel();
|
|
6535
|
-
const lookupPath = (0,
|
|
6643
|
+
const lookupPath = (0, import_schema_tools4.normalizePath)(
|
|
6536
6644
|
import_node_path.default.join(this.getGeneratedFolder(), `_lookup.json`)
|
|
6537
6645
|
);
|
|
6538
6646
|
if (!this._lookup) {
|
|
@@ -6545,7 +6653,7 @@ var Database = class {
|
|
|
6545
6653
|
};
|
|
6546
6654
|
this.getGraphQLSchema = async () => {
|
|
6547
6655
|
await this.initLevel();
|
|
6548
|
-
const graphqlPath = (0,
|
|
6656
|
+
const graphqlPath = (0, import_schema_tools4.normalizePath)(
|
|
6549
6657
|
import_node_path.default.join(this.getGeneratedFolder(), `_graphql.json`)
|
|
6550
6658
|
);
|
|
6551
6659
|
return await this.contentLevel.sublevel(
|
|
@@ -6558,7 +6666,7 @@ var Database = class {
|
|
|
6558
6666
|
if (!this.bridge) {
|
|
6559
6667
|
throw new Error(`No bridge configured`);
|
|
6560
6668
|
}
|
|
6561
|
-
const graphqlPath = (0,
|
|
6669
|
+
const graphqlPath = (0, import_schema_tools4.normalizePath)(
|
|
6562
6670
|
import_node_path.default.join(this.getGeneratedFolder(), `_graphql.json`)
|
|
6563
6671
|
);
|
|
6564
6672
|
const _graphql = await this.bridge.get(graphqlPath);
|
|
@@ -6566,7 +6674,7 @@ var Database = class {
|
|
|
6566
6674
|
};
|
|
6567
6675
|
this.getTinaSchema = async (level) => {
|
|
6568
6676
|
await this.initLevel();
|
|
6569
|
-
const schemaPath = (0,
|
|
6677
|
+
const schemaPath = (0, import_schema_tools4.normalizePath)(
|
|
6570
6678
|
import_node_path.default.join(this.getGeneratedFolder(), `_schema.json`)
|
|
6571
6679
|
);
|
|
6572
6680
|
return await (level || this.contentLevel).sublevel(
|
|
@@ -6582,7 +6690,7 @@ var Database = class {
|
|
|
6582
6690
|
const schema = existingSchema || await this.getTinaSchema(level || this.contentLevel);
|
|
6583
6691
|
if (!schema) {
|
|
6584
6692
|
throw new Error(
|
|
6585
|
-
`Unable to get schema from level db: ${(0,
|
|
6693
|
+
`Unable to get schema from level db: ${(0, import_schema_tools4.normalizePath)(
|
|
6586
6694
|
import_node_path.default.join(this.getGeneratedFolder(), `_schema.json`)
|
|
6587
6695
|
)}`
|
|
6588
6696
|
);
|
|
@@ -6590,6 +6698,22 @@ var Database = class {
|
|
|
6590
6698
|
this.tinaSchema = await createSchema({ schema });
|
|
6591
6699
|
return this.tinaSchema;
|
|
6592
6700
|
};
|
|
6701
|
+
this.getCollectionReferences = async (level) => {
|
|
6702
|
+
if (this.collectionReferences) {
|
|
6703
|
+
return this.collectionReferences;
|
|
6704
|
+
}
|
|
6705
|
+
const result = {};
|
|
6706
|
+
const schema = await this.getSchema(level || this.contentLevel);
|
|
6707
|
+
const collections = schema.getCollections();
|
|
6708
|
+
for (const collection of collections) {
|
|
6709
|
+
const collectionReferences = this.tinaSchema.findReferencesFromCollection(
|
|
6710
|
+
collection.name
|
|
6711
|
+
);
|
|
6712
|
+
result[collection.name] = collectionReferences;
|
|
6713
|
+
}
|
|
6714
|
+
this.collectionReferences = result;
|
|
6715
|
+
return result;
|
|
6716
|
+
};
|
|
6593
6717
|
this.getIndexDefinitions = async (level) => {
|
|
6594
6718
|
if (!this.collectionIndexDefinitions) {
|
|
6595
6719
|
await new Promise(async (resolve2, reject) => {
|
|
@@ -6599,11 +6723,53 @@ var Database = class {
|
|
|
6599
6723
|
const collections = schema.getCollections();
|
|
6600
6724
|
for (const collection of collections) {
|
|
6601
6725
|
const indexDefinitions = {
|
|
6602
|
-
[DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
|
|
6726
|
+
[DEFAULT_COLLECTION_SORT_KEY]: { fields: [] },
|
|
6603
6727
|
// provide a default sort key which is the file sort
|
|
6728
|
+
// pseudo-index for the collection's references
|
|
6729
|
+
[REFS_COLLECTIONS_SORT_KEY]: {
|
|
6730
|
+
fields: [
|
|
6731
|
+
{
|
|
6732
|
+
name: REFS_REFERENCE_FIELD,
|
|
6733
|
+
type: "string",
|
|
6734
|
+
list: false
|
|
6735
|
+
},
|
|
6736
|
+
{
|
|
6737
|
+
name: REFS_PATH_FIELD,
|
|
6738
|
+
type: "string",
|
|
6739
|
+
list: false
|
|
6740
|
+
}
|
|
6741
|
+
]
|
|
6742
|
+
}
|
|
6604
6743
|
};
|
|
6605
|
-
|
|
6606
|
-
|
|
6744
|
+
let fields = [];
|
|
6745
|
+
if (collection.templates) {
|
|
6746
|
+
const templateFieldMap = {};
|
|
6747
|
+
const conflictedFields = /* @__PURE__ */ new Set();
|
|
6748
|
+
for (const template of collection.templates) {
|
|
6749
|
+
for (const field of template.fields) {
|
|
6750
|
+
if (!templateFieldMap[field.name]) {
|
|
6751
|
+
templateFieldMap[field.name] = field;
|
|
6752
|
+
} else {
|
|
6753
|
+
if (templateFieldMap[field.name].type !== field.type) {
|
|
6754
|
+
console.warn(
|
|
6755
|
+
`Field ${field.name} has conflicting types in templates - skipping index`
|
|
6756
|
+
);
|
|
6757
|
+
conflictedFields.add(field.name);
|
|
6758
|
+
}
|
|
6759
|
+
}
|
|
6760
|
+
}
|
|
6761
|
+
}
|
|
6762
|
+
for (const conflictedField in conflictedFields) {
|
|
6763
|
+
delete templateFieldMap[conflictedField];
|
|
6764
|
+
}
|
|
6765
|
+
for (const field of Object.values(templateFieldMap)) {
|
|
6766
|
+
fields.push(field);
|
|
6767
|
+
}
|
|
6768
|
+
} else if (collection.fields) {
|
|
6769
|
+
fields = collection.fields;
|
|
6770
|
+
}
|
|
6771
|
+
if (fields) {
|
|
6772
|
+
for (const field of fields) {
|
|
6607
6773
|
if (field.indexed !== void 0 && field.indexed === false || field.type === "object") {
|
|
6608
6774
|
continue;
|
|
6609
6775
|
}
|
|
@@ -6752,29 +6918,36 @@ var Database = class {
|
|
|
6752
6918
|
}
|
|
6753
6919
|
startKey = startKey || key || "";
|
|
6754
6920
|
endKey = key || "";
|
|
6755
|
-
edges = [...edges, { cursor: key, path: filepath }];
|
|
6921
|
+
edges = [...edges, { cursor: key, path: filepath, value: itemRecord }];
|
|
6756
6922
|
}
|
|
6757
6923
|
return {
|
|
6758
|
-
edges: await sequential(
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6924
|
+
edges: await sequential(
|
|
6925
|
+
edges,
|
|
6926
|
+
async ({
|
|
6927
|
+
cursor,
|
|
6928
|
+
path: path7,
|
|
6929
|
+
value
|
|
6930
|
+
}) => {
|
|
6931
|
+
try {
|
|
6932
|
+
const node = await hydrator(path7, value);
|
|
6933
|
+
return {
|
|
6934
|
+
node,
|
|
6935
|
+
cursor: btoa(cursor)
|
|
6936
|
+
};
|
|
6937
|
+
} catch (error) {
|
|
6938
|
+
console.log(error);
|
|
6939
|
+
if (error instanceof Error && (!path7.includes(".tina/__generated__/_graphql.json") || !path7.includes("tina/__generated__/_graphql.json"))) {
|
|
6940
|
+
throw new TinaQueryError({
|
|
6941
|
+
originalError: error,
|
|
6942
|
+
file: path7,
|
|
6943
|
+
collection: collection.name,
|
|
6944
|
+
stack: error.stack
|
|
6945
|
+
});
|
|
6946
|
+
}
|
|
6947
|
+
throw error;
|
|
6774
6948
|
}
|
|
6775
|
-
throw error;
|
|
6776
6949
|
}
|
|
6777
|
-
|
|
6950
|
+
),
|
|
6778
6951
|
pageInfo: {
|
|
6779
6952
|
hasPreviousPage,
|
|
6780
6953
|
hasNextPage,
|
|
@@ -6799,7 +6972,7 @@ var Database = class {
|
|
|
6799
6972
|
try {
|
|
6800
6973
|
lookup = lookupFromLockFile || JSON.parse(
|
|
6801
6974
|
await this.bridge.get(
|
|
6802
|
-
(0,
|
|
6975
|
+
(0, import_schema_tools4.normalizePath)(
|
|
6803
6976
|
import_node_path.default.join(this.getGeneratedFolder(), "_lookup.json")
|
|
6804
6977
|
)
|
|
6805
6978
|
)
|
|
@@ -6824,15 +6997,15 @@ var Database = class {
|
|
|
6824
6997
|
}
|
|
6825
6998
|
const contentRootLevel = nextLevel.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
|
|
6826
6999
|
await contentRootLevel.put(
|
|
6827
|
-
(0,
|
|
7000
|
+
(0, import_schema_tools4.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_graphql.json")),
|
|
6828
7001
|
graphQLSchema
|
|
6829
7002
|
);
|
|
6830
7003
|
await contentRootLevel.put(
|
|
6831
|
-
(0,
|
|
7004
|
+
(0, import_schema_tools4.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_schema.json")),
|
|
6832
7005
|
tinaSchema.schema
|
|
6833
7006
|
);
|
|
6834
7007
|
await contentRootLevel.put(
|
|
6835
|
-
(0,
|
|
7008
|
+
(0, import_schema_tools4.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_lookup.json")),
|
|
6836
7009
|
lookup
|
|
6837
7010
|
);
|
|
6838
7011
|
const result = await this._indexAllContent(
|
|
@@ -6898,13 +7071,14 @@ var Database = class {
|
|
|
6898
7071
|
documentPaths,
|
|
6899
7072
|
async (collection, documentPaths2) => {
|
|
6900
7073
|
if (collection && !collection.isDetached) {
|
|
6901
|
-
await _indexContent(
|
|
6902
|
-
this,
|
|
6903
|
-
this.contentLevel,
|
|
6904
|
-
documentPaths2,
|
|
7074
|
+
await _indexContent({
|
|
7075
|
+
database: this,
|
|
7076
|
+
level: this.contentLevel,
|
|
7077
|
+
documentPaths: documentPaths2,
|
|
6905
7078
|
enqueueOps,
|
|
6906
|
-
collection
|
|
6907
|
-
|
|
7079
|
+
collection,
|
|
7080
|
+
isPartialReindex: true
|
|
7081
|
+
});
|
|
6908
7082
|
}
|
|
6909
7083
|
}
|
|
6910
7084
|
);
|
|
@@ -6914,18 +7088,20 @@ var Database = class {
|
|
|
6914
7088
|
}
|
|
6915
7089
|
};
|
|
6916
7090
|
this.delete = async (filepath) => {
|
|
7091
|
+
var _a;
|
|
6917
7092
|
await this.initLevel();
|
|
6918
7093
|
const collection = await this.collectionForPath(filepath);
|
|
6919
7094
|
if (!collection) {
|
|
6920
7095
|
throw new Error(`No collection found for path: ${filepath}`);
|
|
6921
7096
|
}
|
|
6922
7097
|
const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
|
|
7098
|
+
const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collection.name];
|
|
6923
7099
|
const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
|
|
6924
7100
|
let level = this.contentLevel;
|
|
6925
7101
|
if (collection == null ? void 0 : collection.isDetached) {
|
|
6926
7102
|
level = this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS);
|
|
6927
7103
|
}
|
|
6928
|
-
const normalizedPath = (0,
|
|
7104
|
+
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
6929
7105
|
const rootSublevel = level.sublevel(
|
|
6930
7106
|
CONTENT_ROOT_PREFIX,
|
|
6931
7107
|
SUBLEVEL_OPTIONS
|
|
@@ -6938,6 +7114,14 @@ var Database = class {
|
|
|
6938
7114
|
collection.path || ""
|
|
6939
7115
|
);
|
|
6940
7116
|
await this.contentLevel.batch([
|
|
7117
|
+
...makeRefOpsForDocument(
|
|
7118
|
+
normalizedPath,
|
|
7119
|
+
collection.name,
|
|
7120
|
+
collectionReferences,
|
|
7121
|
+
item,
|
|
7122
|
+
"del",
|
|
7123
|
+
level
|
|
7124
|
+
),
|
|
6941
7125
|
...makeIndexOpsForDocument(
|
|
6942
7126
|
normalizedPath,
|
|
6943
7127
|
collection.name,
|
|
@@ -7002,20 +7186,26 @@ var Database = class {
|
|
|
7002
7186
|
);
|
|
7003
7187
|
const doc = await level2.keys({ limit: 1 }).next();
|
|
7004
7188
|
if (!doc) {
|
|
7005
|
-
await _indexContent(
|
|
7006
|
-
this,
|
|
7007
|
-
level2,
|
|
7008
|
-
contentPaths,
|
|
7189
|
+
await _indexContent({
|
|
7190
|
+
database: this,
|
|
7191
|
+
level: level2,
|
|
7192
|
+
documentPaths: contentPaths,
|
|
7009
7193
|
enqueueOps,
|
|
7010
7194
|
collection,
|
|
7011
|
-
userFields.map((field) => [
|
|
7195
|
+
passwordFields: userFields.map((field) => [
|
|
7012
7196
|
...field.path,
|
|
7013
7197
|
field.passwordFieldName
|
|
7014
7198
|
])
|
|
7015
|
-
);
|
|
7199
|
+
});
|
|
7016
7200
|
}
|
|
7017
7201
|
} else {
|
|
7018
|
-
await _indexContent(
|
|
7202
|
+
await _indexContent({
|
|
7203
|
+
database: this,
|
|
7204
|
+
level,
|
|
7205
|
+
documentPaths: contentPaths,
|
|
7206
|
+
enqueueOps,
|
|
7207
|
+
collection
|
|
7208
|
+
});
|
|
7019
7209
|
}
|
|
7020
7210
|
}
|
|
7021
7211
|
);
|
|
@@ -7154,7 +7344,16 @@ var hashPasswordValues = async (data, passwordFields) => Promise.all(
|
|
|
7154
7344
|
)
|
|
7155
7345
|
);
|
|
7156
7346
|
var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${(collection == null ? void 0 : collection.format) || "md"}`);
|
|
7157
|
-
var _indexContent = async (
|
|
7347
|
+
var _indexContent = async ({
|
|
7348
|
+
database,
|
|
7349
|
+
level,
|
|
7350
|
+
documentPaths,
|
|
7351
|
+
enqueueOps,
|
|
7352
|
+
collection,
|
|
7353
|
+
passwordFields,
|
|
7354
|
+
isPartialReindex
|
|
7355
|
+
}) => {
|
|
7356
|
+
var _a;
|
|
7158
7357
|
let collectionIndexDefinitions;
|
|
7159
7358
|
let collectionPath;
|
|
7160
7359
|
if (collection) {
|
|
@@ -7165,6 +7364,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7165
7364
|
}
|
|
7166
7365
|
collectionPath = collection.path;
|
|
7167
7366
|
}
|
|
7367
|
+
const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
|
|
7168
7368
|
const tinaSchema = await database.getSchema();
|
|
7169
7369
|
let templateInfo = null;
|
|
7170
7370
|
if (collection) {
|
|
@@ -7185,13 +7385,62 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7185
7385
|
if (passwordFields == null ? void 0 : passwordFields.length) {
|
|
7186
7386
|
await hashPasswordValues(aliasedData, passwordFields);
|
|
7187
7387
|
}
|
|
7188
|
-
const normalizedPath = (0,
|
|
7388
|
+
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
7389
|
+
const rootSublevel = level.sublevel(
|
|
7390
|
+
CONTENT_ROOT_PREFIX,
|
|
7391
|
+
SUBLEVEL_OPTIONS
|
|
7392
|
+
);
|
|
7189
7393
|
const folderKey = folderTreeBuilder.update(
|
|
7190
7394
|
normalizedPath,
|
|
7191
7395
|
collectionPath || ""
|
|
7192
7396
|
);
|
|
7397
|
+
if (isPartialReindex) {
|
|
7398
|
+
const item = await rootSublevel.get(normalizedPath);
|
|
7399
|
+
if (item) {
|
|
7400
|
+
await database.contentLevel.batch([
|
|
7401
|
+
...makeRefOpsForDocument(
|
|
7402
|
+
normalizedPath,
|
|
7403
|
+
collection == null ? void 0 : collection.name,
|
|
7404
|
+
collectionReferences,
|
|
7405
|
+
item,
|
|
7406
|
+
"del",
|
|
7407
|
+
level
|
|
7408
|
+
),
|
|
7409
|
+
...makeIndexOpsForDocument(
|
|
7410
|
+
normalizedPath,
|
|
7411
|
+
collection.name,
|
|
7412
|
+
collectionIndexDefinitions,
|
|
7413
|
+
item,
|
|
7414
|
+
"del",
|
|
7415
|
+
level
|
|
7416
|
+
),
|
|
7417
|
+
// folder indices
|
|
7418
|
+
...makeIndexOpsForDocument(
|
|
7419
|
+
normalizedPath,
|
|
7420
|
+
`${collection.name}_${folderKey}`,
|
|
7421
|
+
collectionIndexDefinitions,
|
|
7422
|
+
item,
|
|
7423
|
+
"del",
|
|
7424
|
+
level
|
|
7425
|
+
),
|
|
7426
|
+
{
|
|
7427
|
+
type: "del",
|
|
7428
|
+
key: normalizedPath,
|
|
7429
|
+
sublevel: rootSublevel
|
|
7430
|
+
}
|
|
7431
|
+
]);
|
|
7432
|
+
}
|
|
7433
|
+
}
|
|
7193
7434
|
if (!isGitKeep(filepath, collection)) {
|
|
7194
7435
|
await enqueueOps([
|
|
7436
|
+
...makeRefOpsForDocument(
|
|
7437
|
+
normalizedPath,
|
|
7438
|
+
collection == null ? void 0 : collection.name,
|
|
7439
|
+
collectionReferences,
|
|
7440
|
+
aliasedData,
|
|
7441
|
+
"put",
|
|
7442
|
+
level
|
|
7443
|
+
),
|
|
7195
7444
|
...makeIndexOpsForDocument(
|
|
7196
7445
|
normalizedPath,
|
|
7197
7446
|
collection == null ? void 0 : collection.name,
|
|
@@ -7242,6 +7491,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7242
7491
|
}
|
|
7243
7492
|
};
|
|
7244
7493
|
var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection) => {
|
|
7494
|
+
var _a;
|
|
7245
7495
|
if (!documentPaths.length) {
|
|
7246
7496
|
return;
|
|
7247
7497
|
}
|
|
@@ -7255,6 +7505,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7255
7505
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
7256
7506
|
}
|
|
7257
7507
|
}
|
|
7508
|
+
const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
|
|
7258
7509
|
const tinaSchema = await database.getSchema();
|
|
7259
7510
|
let templateInfo = null;
|
|
7260
7511
|
if (collection) {
|
|
@@ -7266,7 +7517,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7266
7517
|
);
|
|
7267
7518
|
const folderTreeBuilder = new FolderTreeBuilder();
|
|
7268
7519
|
await sequential(documentPaths, async (filepath) => {
|
|
7269
|
-
const itemKey = (0,
|
|
7520
|
+
const itemKey = (0, import_schema_tools4.normalizePath)(filepath);
|
|
7270
7521
|
const item = await rootLevel.get(itemKey);
|
|
7271
7522
|
if (item) {
|
|
7272
7523
|
const folderKey = folderTreeBuilder.update(
|
|
@@ -7278,6 +7529,14 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7278
7529
|
item
|
|
7279
7530
|
) : item;
|
|
7280
7531
|
await enqueueOps([
|
|
7532
|
+
...makeRefOpsForDocument(
|
|
7533
|
+
itemKey,
|
|
7534
|
+
collection == null ? void 0 : collection.name,
|
|
7535
|
+
collectionReferences,
|
|
7536
|
+
aliasedData,
|
|
7537
|
+
"del",
|
|
7538
|
+
database.contentLevel
|
|
7539
|
+
),
|
|
7281
7540
|
...makeIndexOpsForDocument(
|
|
7282
7541
|
itemKey,
|
|
7283
7542
|
collection.name,
|
|
@@ -7353,14 +7612,14 @@ var getChangedFiles = async ({
|
|
|
7353
7612
|
const rootDir = await findGitRoot(dir);
|
|
7354
7613
|
let pathPrefix = "";
|
|
7355
7614
|
if (rootDir !== dir) {
|
|
7356
|
-
pathPrefix = (0,
|
|
7615
|
+
pathPrefix = (0, import_schema_tools4.normalizePath)(dir.substring(rootDir.length + 1));
|
|
7357
7616
|
}
|
|
7358
7617
|
await import_isomorphic_git.default.walk({
|
|
7359
7618
|
fs: fs4,
|
|
7360
7619
|
dir: rootDir,
|
|
7361
7620
|
trees: [import_isomorphic_git.default.TREE({ ref: from }), import_isomorphic_git.default.TREE({ ref: to })],
|
|
7362
7621
|
map: async function(filename, [A, B]) {
|
|
7363
|
-
const relativePath = (0,
|
|
7622
|
+
const relativePath = (0, import_schema_tools4.normalizePath)(filename).substring(pathPrefix.length);
|
|
7364
7623
|
let matches = false;
|
|
7365
7624
|
for (const [key, matcher] of Object.entries(pathFilter)) {
|
|
7366
7625
|
if (relativePath.startsWith(key)) {
|