@tinacms/graphql 0.0.0-db8aa8e-20250228034006 → 0.0.0-ddc5e8e-20250611011547
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/README.md +144 -0
- package/dist/builder/index.d.ts +2 -2
- package/dist/database/bridge/filesystem.d.ts +1 -1
- package/dist/database/util.d.ts +5 -8
- package/dist/index.js +327 -247
- package/dist/index.mjs +207 -101
- package/dist/resolver/index.d.ts +8 -5
- package/dist/resolver/media-utils.d.ts +3 -3
- package/dist/schema/createSchema.d.ts +0 -3
- package/dist/schema/validate.d.ts +0 -3
- package/package.json +5 -7
- package/readme.md +0 -194
package/dist/index.js
CHANGED
|
@@ -1435,13 +1435,12 @@ var checkPasswordHash = async ({
|
|
|
1435
1435
|
return true;
|
|
1436
1436
|
};
|
|
1437
1437
|
var mapUserFields = (collectable, prefix = []) => {
|
|
1438
|
-
var _a, _b, _c, _d, _e;
|
|
1439
1438
|
const results = [];
|
|
1440
|
-
const passwordFields =
|
|
1439
|
+
const passwordFields = collectable.fields?.filter((field) => field.type === "password") || [];
|
|
1441
1440
|
if (passwordFields.length > 1) {
|
|
1442
1441
|
throw new Error("Only one password field is allowed");
|
|
1443
1442
|
}
|
|
1444
|
-
const idFields =
|
|
1443
|
+
const idFields = collectable.fields?.filter((field) => field.uid) || [];
|
|
1445
1444
|
if (idFields.length > 1) {
|
|
1446
1445
|
throw new Error("Only one uid field is allowed");
|
|
1447
1446
|
}
|
|
@@ -1449,11 +1448,11 @@ var mapUserFields = (collectable, prefix = []) => {
|
|
|
1449
1448
|
results.push({
|
|
1450
1449
|
path: prefix,
|
|
1451
1450
|
collectable,
|
|
1452
|
-
idFieldName:
|
|
1453
|
-
passwordFieldName:
|
|
1451
|
+
idFieldName: idFields[0]?.name,
|
|
1452
|
+
passwordFieldName: passwordFields[0]?.name
|
|
1454
1453
|
});
|
|
1455
1454
|
}
|
|
1456
|
-
|
|
1455
|
+
collectable.fields?.forEach((field) => {
|
|
1457
1456
|
if (field.type === "object" && field.fields) {
|
|
1458
1457
|
results.push(...mapUserFields(field, [...prefix, field.name]));
|
|
1459
1458
|
}
|
|
@@ -1914,7 +1913,7 @@ var Builder = class {
|
|
|
1914
1913
|
* ```
|
|
1915
1914
|
*
|
|
1916
1915
|
* @public
|
|
1917
|
-
* @param collection a
|
|
1916
|
+
* @param collection a TinaCloud collection
|
|
1918
1917
|
*/
|
|
1919
1918
|
this.collectionFragment = async (collection) => {
|
|
1920
1919
|
const name = NAMER.dataTypeName(collection.namespace);
|
|
@@ -1944,13 +1943,12 @@ var Builder = class {
|
|
|
1944
1943
|
*
|
|
1945
1944
|
* */
|
|
1946
1945
|
this._getCollectionFragmentSelections = async (collection, depth) => {
|
|
1947
|
-
var _a;
|
|
1948
1946
|
const selections = [];
|
|
1949
1947
|
selections.push({
|
|
1950
1948
|
name: { kind: "Name", value: "__typename" },
|
|
1951
1949
|
kind: "Field"
|
|
1952
1950
|
});
|
|
1953
|
-
if (
|
|
1951
|
+
if (collection.fields?.length > 0) {
|
|
1954
1952
|
await sequential(collection.fields, async (x) => {
|
|
1955
1953
|
const field = await this._buildFieldNodeForFragments(x, depth);
|
|
1956
1954
|
selections.push(field);
|
|
@@ -1965,7 +1963,6 @@ var Builder = class {
|
|
|
1965
1963
|
return selections;
|
|
1966
1964
|
};
|
|
1967
1965
|
this._buildFieldNodeForFragments = async (field, depth) => {
|
|
1968
|
-
var _a, _b;
|
|
1969
1966
|
switch (field.type) {
|
|
1970
1967
|
case "string":
|
|
1971
1968
|
case "image":
|
|
@@ -1998,7 +1995,7 @@ var Builder = class {
|
|
|
1998
1995
|
selections: filterSelections([passwordValue, passwordChangeRequired])
|
|
1999
1996
|
});
|
|
2000
1997
|
case "object":
|
|
2001
|
-
if (
|
|
1998
|
+
if (field.fields?.length > 0) {
|
|
2002
1999
|
const selections2 = [];
|
|
2003
2000
|
await sequential(field.fields, async (item) => {
|
|
2004
2001
|
const field2 = await this._buildFieldNodeForFragments(item, depth);
|
|
@@ -2011,7 +2008,7 @@ var Builder = class {
|
|
|
2011
2008
|
...filterSelections(selections2)
|
|
2012
2009
|
]
|
|
2013
2010
|
});
|
|
2014
|
-
} else if (
|
|
2011
|
+
} else if (field.templates?.length > 0) {
|
|
2015
2012
|
const selections2 = [];
|
|
2016
2013
|
await sequential(field.templates, async (tem) => {
|
|
2017
2014
|
if (typeof tem === "object") {
|
|
@@ -2673,7 +2670,7 @@ var Builder = class {
|
|
|
2673
2670
|
this.addToLookupMap({
|
|
2674
2671
|
type: name,
|
|
2675
2672
|
resolveType: "unionData",
|
|
2676
|
-
collection: collection
|
|
2673
|
+
collection: collection?.name,
|
|
2677
2674
|
typeMap
|
|
2678
2675
|
});
|
|
2679
2676
|
return astBuilder.UnionTypeDefinition({ name, types });
|
|
@@ -2883,9 +2880,8 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
|
|
|
2883
2880
|
]
|
|
2884
2881
|
});
|
|
2885
2882
|
};
|
|
2886
|
-
var _a, _b, _c, _d;
|
|
2887
2883
|
this.maxDepth = // @ts-ignore
|
|
2888
|
-
|
|
2884
|
+
config?.tinaSchema.schema?.config?.client?.referenceDepth ?? 2;
|
|
2889
2885
|
this.tinaSchema = config.tinaSchema;
|
|
2890
2886
|
this.lookupMap = {};
|
|
2891
2887
|
}
|
|
@@ -2974,7 +2970,7 @@ var validationCollectionsPathAndMatch = (collections) => {
|
|
|
2974
2970
|
return;
|
|
2975
2971
|
}
|
|
2976
2972
|
const noMatchCollections = collections.filter((x) => {
|
|
2977
|
-
return typeof
|
|
2973
|
+
return typeof x?.match === "undefined";
|
|
2978
2974
|
}).map((x) => `${x.path}${x.format || "md"}`);
|
|
2979
2975
|
if (noMatchCollections.length !== new Set(noMatchCollections).size) {
|
|
2980
2976
|
throw new Error(
|
|
@@ -2985,10 +2981,7 @@ var validationCollectionsPathAndMatch = (collections) => {
|
|
|
2985
2981
|
const hasMatchAndPath = collections.filter((x) => {
|
|
2986
2982
|
return typeof x.path !== "undefined" && typeof x.match !== "undefined";
|
|
2987
2983
|
}).map(
|
|
2988
|
-
(x) => {
|
|
2989
|
-
var _a, _b;
|
|
2990
|
-
return `${x.path}|${((_a = x == null ? void 0 : x.match) == null ? void 0 : _a.exclude) || ""}|${((_b = x == null ? void 0 : x.match) == null ? void 0 : _b.include) || ""}|${x.format || "md"}`;
|
|
2991
|
-
}
|
|
2984
|
+
(x) => `${x.path}|${x?.match?.exclude || ""}|${x?.match?.include || ""}|${x.format || "md"}`
|
|
2992
2985
|
);
|
|
2993
2986
|
if (hasMatchAndPath.length !== new Set(hasMatchAndPath).size) {
|
|
2994
2987
|
throw new Error(
|
|
@@ -3012,7 +3005,7 @@ var validationCollectionsPathAndMatch = (collections) => {
|
|
|
3012
3005
|
);
|
|
3013
3006
|
}
|
|
3014
3007
|
const matches = collectionsArr.map(
|
|
3015
|
-
(x) => typeof
|
|
3008
|
+
(x) => typeof x?.match === "object" ? JSON.stringify(x.match) : ""
|
|
3016
3009
|
);
|
|
3017
3010
|
if (matches.length === new Set(matches).size) {
|
|
3018
3011
|
return;
|
|
@@ -3090,7 +3083,7 @@ var validateField = async (field) => {
|
|
|
3090
3083
|
// package.json
|
|
3091
3084
|
var package_default = {
|
|
3092
3085
|
name: "@tinacms/graphql",
|
|
3093
|
-
version: "1.5.
|
|
3086
|
+
version: "1.5.18",
|
|
3094
3087
|
main: "dist/index.js",
|
|
3095
3088
|
module: "dist/index.mjs",
|
|
3096
3089
|
typings: "dist/index.d.ts",
|
|
@@ -3116,33 +3109,32 @@ var package_default = {
|
|
|
3116
3109
|
types: "pnpm tsc",
|
|
3117
3110
|
build: "tinacms-scripts build",
|
|
3118
3111
|
docs: "pnpm typedoc",
|
|
3119
|
-
serve: "pnpm nodemon dist/server.js",
|
|
3120
3112
|
test: "vitest run",
|
|
3121
3113
|
"test-watch": "vitest"
|
|
3122
3114
|
},
|
|
3123
3115
|
dependencies: {
|
|
3124
|
-
"@iarna/toml": "
|
|
3116
|
+
"@iarna/toml": "catalog:",
|
|
3125
3117
|
"@tinacms/mdx": "workspace:*",
|
|
3126
3118
|
"@tinacms/schema-tools": "workspace:*",
|
|
3127
|
-
"abstract-level": "
|
|
3119
|
+
"abstract-level": "catalog:",
|
|
3128
3120
|
"date-fns": "^2.30.0",
|
|
3129
|
-
"fast-glob": "
|
|
3130
|
-
"fs-extra": "
|
|
3131
|
-
"glob-parent": "
|
|
3121
|
+
"fast-glob": "catalog:",
|
|
3122
|
+
"fs-extra": "catalog:",
|
|
3123
|
+
"glob-parent": "catalog:",
|
|
3132
3124
|
graphql: "15.8.0",
|
|
3133
|
-
"gray-matter": "
|
|
3134
|
-
"isomorphic-git": "
|
|
3135
|
-
"js-sha1": "
|
|
3125
|
+
"gray-matter": "catalog:",
|
|
3126
|
+
"isomorphic-git": "catalog:",
|
|
3127
|
+
"js-sha1": "catalog:",
|
|
3136
3128
|
"js-yaml": "^3.14.1",
|
|
3137
|
-
"jsonpath-plus": "
|
|
3138
|
-
"lodash.clonedeep": "
|
|
3139
|
-
"lodash.set": "
|
|
3140
|
-
"lodash.uniqby": "
|
|
3141
|
-
"many-level": "
|
|
3142
|
-
micromatch: "
|
|
3143
|
-
"normalize-path": "
|
|
3144
|
-
"readable-stream": "
|
|
3145
|
-
scmp: "
|
|
3129
|
+
"jsonpath-plus": "catalog:",
|
|
3130
|
+
"lodash.clonedeep": "catalog:",
|
|
3131
|
+
"lodash.set": "catalog:",
|
|
3132
|
+
"lodash.uniqby": "catalog:",
|
|
3133
|
+
"many-level": "catalog:",
|
|
3134
|
+
micromatch: "catalog:",
|
|
3135
|
+
"normalize-path": "catalog:",
|
|
3136
|
+
"readable-stream": "catalog:",
|
|
3137
|
+
scmp: "catalog:",
|
|
3146
3138
|
yup: "^0.32.11"
|
|
3147
3139
|
},
|
|
3148
3140
|
publishConfig: {
|
|
@@ -3157,21 +3149,20 @@ var package_default = {
|
|
|
3157
3149
|
"@tinacms/scripts": "workspace:*",
|
|
3158
3150
|
"@types/cors": "^2.8.17",
|
|
3159
3151
|
"@types/estree": "^0.0.50",
|
|
3160
|
-
"@types/express": "
|
|
3152
|
+
"@types/express": "catalog:",
|
|
3161
3153
|
"@types/fs-extra": "^9.0.13",
|
|
3162
3154
|
"@types/js-yaml": "^3.12.10",
|
|
3163
|
-
"@types/lodash.camelcase": "
|
|
3164
|
-
"@types/lodash.upperfirst": "
|
|
3165
|
-
"@types/lru-cache": "
|
|
3166
|
-
"@types/mdast": "
|
|
3167
|
-
"@types/micromatch": "
|
|
3155
|
+
"@types/lodash.camelcase": "catalog:",
|
|
3156
|
+
"@types/lodash.upperfirst": "catalog:",
|
|
3157
|
+
"@types/lru-cache": "catalog:",
|
|
3158
|
+
"@types/mdast": "catalog:",
|
|
3159
|
+
"@types/micromatch": "catalog:",
|
|
3168
3160
|
"@types/node": "^22.13.1",
|
|
3169
|
-
"@types/normalize-path": "
|
|
3170
|
-
"@types/ws": "
|
|
3161
|
+
"@types/normalize-path": "catalog:",
|
|
3162
|
+
"@types/ws": "catalog:",
|
|
3171
3163
|
"@types/yup": "^0.29.14",
|
|
3172
3164
|
"jest-file-snapshot": "^0.5.0",
|
|
3173
|
-
"memory-level": "
|
|
3174
|
-
nodemon: "3.1.4",
|
|
3165
|
+
"memory-level": "catalog:",
|
|
3175
3166
|
typescript: "^5.7.3",
|
|
3176
3167
|
vite: "^4.5.9",
|
|
3177
3168
|
vitest: "^0.32.4",
|
|
@@ -3257,7 +3248,6 @@ var _buildQueries = async (builder, tinaSchema) => {
|
|
|
3257
3248
|
const operationsDefinitions = [];
|
|
3258
3249
|
const collections = tinaSchema.getCollections();
|
|
3259
3250
|
await sequential(collections, async (collection) => {
|
|
3260
|
-
var _a, _b, _c;
|
|
3261
3251
|
const queryName = NAMER.queryName(collection.namespace);
|
|
3262
3252
|
const queryListName = NAMER.generateQueryListName(collection.namespace);
|
|
3263
3253
|
const queryFilterTypeName = NAMER.dataFilterTypeName(collection.namespace);
|
|
@@ -3272,7 +3262,7 @@ var _buildQueries = async (builder, tinaSchema) => {
|
|
|
3272
3262
|
filterType: queryFilterTypeName,
|
|
3273
3263
|
// look for flag to see if the data layer is enabled
|
|
3274
3264
|
dataLayer: Boolean(
|
|
3275
|
-
|
|
3265
|
+
tinaSchema.config?.meta?.flags?.find((x) => x === "experimentalData")
|
|
3276
3266
|
)
|
|
3277
3267
|
})
|
|
3278
3268
|
);
|
|
@@ -3332,7 +3322,9 @@ var _buildSchema = async (builder, tinaSchema) => {
|
|
|
3332
3322
|
await builder.buildCreateCollectionFolderMutation()
|
|
3333
3323
|
);
|
|
3334
3324
|
await sequential(collections, async (collection) => {
|
|
3335
|
-
queryTypeDefinitionFields.push(
|
|
3325
|
+
queryTypeDefinitionFields.push(
|
|
3326
|
+
await builder.collectionDocument(collection)
|
|
3327
|
+
);
|
|
3336
3328
|
if (collection.isAuthCollection) {
|
|
3337
3329
|
queryTypeDefinitionFields.push(
|
|
3338
3330
|
await builder.authenticationCollectionDocument(collection)
|
|
@@ -3620,9 +3612,8 @@ var cleanUpSlashes = (path7) => {
|
|
|
3620
3612
|
return "";
|
|
3621
3613
|
};
|
|
3622
3614
|
var hasTinaMediaConfig = (schema) => {
|
|
3623
|
-
|
|
3624
|
-
if (
|
|
3625
|
-
if (typeof ((_e = (_d = (_c = schema.config) == null ? void 0 : _c.media) == null ? void 0 : _d.tina) == null ? void 0 : _e.publicFolder) !== "string" && typeof ((_h = (_g = (_f = schema.config) == null ? void 0 : _f.media) == null ? void 0 : _g.tina) == null ? void 0 : _h.mediaRoot) !== "string")
|
|
3615
|
+
if (!schema.config?.media?.tina) return false;
|
|
3616
|
+
if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
|
|
3626
3617
|
return false;
|
|
3627
3618
|
return true;
|
|
3628
3619
|
};
|
|
@@ -3648,7 +3639,9 @@ var LevelProxyHandler = {
|
|
|
3648
3639
|
throw new Error(`The property, ${property.toString()}, doesn't exist`);
|
|
3649
3640
|
}
|
|
3650
3641
|
if (typeof target[property] !== "function") {
|
|
3651
|
-
throw new Error(
|
|
3642
|
+
throw new Error(
|
|
3643
|
+
`The property, ${property.toString()}, is not a function`
|
|
3644
|
+
);
|
|
3652
3645
|
}
|
|
3653
3646
|
if (property === "get") {
|
|
3654
3647
|
return async (...args) => {
|
|
@@ -3727,22 +3720,20 @@ var replaceNameOverrides = (template, obj) => {
|
|
|
3727
3720
|
}
|
|
3728
3721
|
};
|
|
3729
3722
|
function isBlockField(field) {
|
|
3730
|
-
|
|
3731
|
-
return field && field.type === "object" && ((_a = field.templates) == null ? void 0 : _a.length) > 0;
|
|
3723
|
+
return field && field.type === "object" && field.templates?.length > 0;
|
|
3732
3724
|
}
|
|
3733
3725
|
var _replaceNameOverrides = (fields, obj) => {
|
|
3734
3726
|
const output = {};
|
|
3735
3727
|
Object.keys(obj).forEach((key) => {
|
|
3736
3728
|
const field = fields.find(
|
|
3737
|
-
(fieldWithMatchingAlias) => (
|
|
3729
|
+
(fieldWithMatchingAlias) => (fieldWithMatchingAlias?.nameOverride || fieldWithMatchingAlias?.name) === key
|
|
3738
3730
|
);
|
|
3739
|
-
output[
|
|
3731
|
+
output[field?.name || key] = field?.type == "object" ? replaceNameOverrides(field, obj[key]) : obj[key];
|
|
3740
3732
|
});
|
|
3741
3733
|
return output;
|
|
3742
3734
|
};
|
|
3743
3735
|
var getTemplateForData = (field, data) => {
|
|
3744
|
-
|
|
3745
|
-
if ((_a = field.templates) == null ? void 0 : _a.length) {
|
|
3736
|
+
if (field.templates?.length) {
|
|
3746
3737
|
const templateKey = "_template";
|
|
3747
3738
|
if (data[templateKey]) {
|
|
3748
3739
|
const result = field.templates.find(
|
|
@@ -3800,8 +3791,8 @@ var _applyNameOverrides = (fields, obj) => {
|
|
|
3800
3791
|
const output = {};
|
|
3801
3792
|
Object.keys(obj).forEach((key) => {
|
|
3802
3793
|
const field = fields.find((field2) => field2.name === key);
|
|
3803
|
-
const outputKey =
|
|
3804
|
-
output[outputKey] =
|
|
3794
|
+
const outputKey = field?.nameOverride || key;
|
|
3795
|
+
output[outputKey] = field?.type === "object" ? applyNameOverrides(field, obj[key]) : obj[key];
|
|
3805
3796
|
});
|
|
3806
3797
|
return output;
|
|
3807
3798
|
};
|
|
@@ -3814,7 +3805,6 @@ var matterEngines = {
|
|
|
3814
3805
|
}
|
|
3815
3806
|
};
|
|
3816
3807
|
var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
|
|
3817
|
-
var _a, _b;
|
|
3818
3808
|
const {
|
|
3819
3809
|
_relativePath,
|
|
3820
3810
|
_keepTemplateKey,
|
|
@@ -3838,9 +3828,9 @@ var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
|
|
|
3838
3828
|
${$_body}`,
|
|
3839
3829
|
strippedContent,
|
|
3840
3830
|
{
|
|
3841
|
-
language:
|
|
3831
|
+
language: markdownParseConfig?.frontmatterFormat ?? "yaml",
|
|
3842
3832
|
engines: matterEngines,
|
|
3843
|
-
delimiters:
|
|
3833
|
+
delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---"
|
|
3844
3834
|
}
|
|
3845
3835
|
);
|
|
3846
3836
|
return ok;
|
|
@@ -3856,15 +3846,14 @@ ${$_body}`,
|
|
|
3856
3846
|
}
|
|
3857
3847
|
};
|
|
3858
3848
|
var parseFile = (content, format, yupSchema, markdownParseConfig) => {
|
|
3859
|
-
var _a, _b;
|
|
3860
3849
|
try {
|
|
3861
3850
|
switch (format) {
|
|
3862
3851
|
case ".markdown":
|
|
3863
3852
|
case ".mdx":
|
|
3864
3853
|
case ".md":
|
|
3865
3854
|
const contentJSON = (0, import_gray_matter.default)(content || "", {
|
|
3866
|
-
language:
|
|
3867
|
-
delimiters:
|
|
3855
|
+
language: markdownParseConfig?.frontmatterFormat ?? "yaml",
|
|
3856
|
+
delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---",
|
|
3868
3857
|
engines: matterEngines
|
|
3869
3858
|
});
|
|
3870
3859
|
const markdownData = {
|
|
@@ -3963,7 +3952,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
|
|
|
3963
3952
|
),
|
|
3964
3953
|
template: void 0
|
|
3965
3954
|
} : tinaSchema.getCollectionAndTemplateByFullPath(filepath, templateName);
|
|
3966
|
-
const field = template
|
|
3955
|
+
const field = template?.fields.find((field2) => {
|
|
3967
3956
|
if (field2.type === "string" || field2.type === "rich-text") {
|
|
3968
3957
|
if (field2.isBody) {
|
|
3969
3958
|
return true;
|
|
@@ -3983,7 +3972,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
|
|
|
3983
3972
|
...data,
|
|
3984
3973
|
_collection: collection.name,
|
|
3985
3974
|
_keepTemplateKey: !!collection.templates,
|
|
3986
|
-
_template:
|
|
3975
|
+
_template: template?.namespace ? lastItem(template?.namespace) : void 0,
|
|
3987
3976
|
_relativePath: filepath.replace(collection.path, "").replace(/^\/|\/$/g, ""),
|
|
3988
3977
|
_id: filepath
|
|
3989
3978
|
};
|
|
@@ -3992,10 +3981,10 @@ function hasOwnProperty(obj, prop) {
|
|
|
3992
3981
|
return obj.hasOwnProperty(prop);
|
|
3993
3982
|
}
|
|
3994
3983
|
var getTemplateForFile = (templateInfo, data) => {
|
|
3995
|
-
if (
|
|
3984
|
+
if (templateInfo?.type === "object") {
|
|
3996
3985
|
return templateInfo.template;
|
|
3997
3986
|
}
|
|
3998
|
-
if (
|
|
3987
|
+
if (templateInfo?.type === "union") {
|
|
3999
3988
|
if (hasOwnProperty(data, "_template")) {
|
|
4000
3989
|
const template = templateInfo.templates.find(
|
|
4001
3990
|
(t) => lastItem(t.namespace) === data._template
|
|
@@ -4019,8 +4008,8 @@ var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo)
|
|
|
4019
4008
|
import_path.default.extname(filepath),
|
|
4020
4009
|
(yup3) => yup3.object({}),
|
|
4021
4010
|
{
|
|
4022
|
-
frontmatterDelimiters: collection
|
|
4023
|
-
frontmatterFormat: collection
|
|
4011
|
+
frontmatterDelimiters: collection?.frontmatterDelimiters,
|
|
4012
|
+
frontmatterFormat: collection?.frontmatterFormat
|
|
4024
4013
|
}
|
|
4025
4014
|
);
|
|
4026
4015
|
const template = getTemplateForFile(templateInfo, data);
|
|
@@ -4626,8 +4615,14 @@ var makeRefOpsForDocument = (filepath, collection, references, data, opType, lev
|
|
|
4626
4615
|
const references2 = {};
|
|
4627
4616
|
for (const path7 of referencePaths) {
|
|
4628
4617
|
const ref = (0, import_jsonpath_plus.JSONPath)({ path: path7, json: data });
|
|
4618
|
+
if (!ref) {
|
|
4619
|
+
continue;
|
|
4620
|
+
}
|
|
4629
4621
|
if (Array.isArray(ref)) {
|
|
4630
4622
|
for (const r of ref) {
|
|
4623
|
+
if (!r) {
|
|
4624
|
+
continue;
|
|
4625
|
+
}
|
|
4631
4626
|
if (references2[r]) {
|
|
4632
4627
|
references2[r].push(path7);
|
|
4633
4628
|
} else {
|
|
@@ -4681,7 +4676,6 @@ var createResolver = (args) => {
|
|
|
4681
4676
|
return new Resolver(args);
|
|
4682
4677
|
};
|
|
4683
4678
|
var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
|
|
4684
|
-
var _a, _b;
|
|
4685
4679
|
if (!rawData) {
|
|
4686
4680
|
return void 0;
|
|
4687
4681
|
}
|
|
@@ -4709,7 +4703,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
|
|
|
4709
4703
|
accumulator[field.name] = {
|
|
4710
4704
|
value: void 0,
|
|
4711
4705
|
// never resolve the password hash
|
|
4712
|
-
passwordChangeRequired:
|
|
4706
|
+
passwordChangeRequired: value["passwordChangeRequired"] ?? false
|
|
4713
4707
|
};
|
|
4714
4708
|
break;
|
|
4715
4709
|
case "image":
|
|
@@ -4725,11 +4719,11 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
|
|
|
4725
4719
|
field,
|
|
4726
4720
|
(value2) => resolveMediaRelativeToCloud(value2, config, tinaSchema.schema)
|
|
4727
4721
|
);
|
|
4728
|
-
if (
|
|
4722
|
+
if (tree?.children[0]?.type === "invalid_markdown") {
|
|
4729
4723
|
if (isAudit) {
|
|
4730
|
-
const invalidNode = tree
|
|
4724
|
+
const invalidNode = tree?.children[0];
|
|
4731
4725
|
throw new import_graphql3.GraphQLError(
|
|
4732
|
-
`${invalidNode
|
|
4726
|
+
`${invalidNode?.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`
|
|
4733
4727
|
);
|
|
4734
4728
|
}
|
|
4735
4729
|
}
|
|
@@ -4842,11 +4836,11 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
|
|
|
4842
4836
|
});
|
|
4843
4837
|
}
|
|
4844
4838
|
const titleField = template.fields.find((x) => {
|
|
4845
|
-
if (x.type === "string" &&
|
|
4839
|
+
if (x.type === "string" && x?.isTitle) {
|
|
4846
4840
|
return true;
|
|
4847
4841
|
}
|
|
4848
4842
|
});
|
|
4849
|
-
const titleFieldName = titleField
|
|
4843
|
+
const titleFieldName = titleField?.name;
|
|
4850
4844
|
const title = data[titleFieldName || " "] || null;
|
|
4851
4845
|
return {
|
|
4852
4846
|
__typename: collection.fields ? NAMER.documentTypeName(collection.namespace) : NAMER.documentTypeName(template.namespace),
|
|
@@ -4878,25 +4872,32 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
|
|
|
4878
4872
|
}
|
|
4879
4873
|
};
|
|
4880
4874
|
var updateObjectWithJsonPath = (obj, path7, oldValue, newValue) => {
|
|
4875
|
+
let updated = false;
|
|
4881
4876
|
if (!path7.includes(".") && !path7.includes("[")) {
|
|
4882
4877
|
if (path7 in obj && obj[path7] === oldValue) {
|
|
4883
4878
|
obj[path7] = newValue;
|
|
4879
|
+
updated = true;
|
|
4884
4880
|
}
|
|
4885
|
-
return obj;
|
|
4881
|
+
return { object: obj, updated };
|
|
4886
4882
|
}
|
|
4887
4883
|
const parentPath = path7.replace(/\.[^.\[\]]+$/, "");
|
|
4888
4884
|
const keyToUpdate = path7.match(/[^.\[\]]+$/)[0];
|
|
4889
|
-
const parents = (0, import_jsonpath_plus2.JSONPath)({
|
|
4885
|
+
const parents = (0, import_jsonpath_plus2.JSONPath)({
|
|
4886
|
+
path: parentPath,
|
|
4887
|
+
json: obj,
|
|
4888
|
+
resultType: "value"
|
|
4889
|
+
});
|
|
4890
4890
|
if (parents.length > 0) {
|
|
4891
4891
|
parents.forEach((parent) => {
|
|
4892
4892
|
if (parent && typeof parent === "object" && keyToUpdate in parent) {
|
|
4893
4893
|
if (parent[keyToUpdate] === oldValue) {
|
|
4894
4894
|
parent[keyToUpdate] = newValue;
|
|
4895
|
+
updated = true;
|
|
4895
4896
|
}
|
|
4896
4897
|
}
|
|
4897
4898
|
});
|
|
4898
4899
|
}
|
|
4899
|
-
return obj;
|
|
4900
|
+
return { object: obj, updated };
|
|
4900
4901
|
};
|
|
4901
4902
|
var Resolver = class {
|
|
4902
4903
|
constructor(init) {
|
|
@@ -4913,7 +4914,9 @@ var Resolver = class {
|
|
|
4913
4914
|
};
|
|
4914
4915
|
this.getRaw = async (fullPath) => {
|
|
4915
4916
|
if (typeof fullPath !== "string") {
|
|
4916
|
-
throw new Error(
|
|
4917
|
+
throw new Error(
|
|
4918
|
+
`fullPath must be of type string for getDocument request`
|
|
4919
|
+
);
|
|
4917
4920
|
}
|
|
4918
4921
|
return this.database.get(fullPath);
|
|
4919
4922
|
};
|
|
@@ -4942,10 +4945,12 @@ var Resolver = class {
|
|
|
4942
4945
|
};
|
|
4943
4946
|
this.getDocument = async (fullPath, opts = {}) => {
|
|
4944
4947
|
if (typeof fullPath !== "string") {
|
|
4945
|
-
throw new Error(
|
|
4948
|
+
throw new Error(
|
|
4949
|
+
`fullPath must be of type string for getDocument request`
|
|
4950
|
+
);
|
|
4946
4951
|
}
|
|
4947
4952
|
const rawData = await this.getRaw(fullPath);
|
|
4948
|
-
const hasReferences =
|
|
4953
|
+
const hasReferences = opts?.checkReferences ? await this.hasReferences(fullPath, opts.collection) : void 0;
|
|
4949
4954
|
return transformDocumentIntoPayload(
|
|
4950
4955
|
fullPath,
|
|
4951
4956
|
rawData,
|
|
@@ -4957,7 +4962,9 @@ var Resolver = class {
|
|
|
4957
4962
|
};
|
|
4958
4963
|
this.deleteDocument = async (fullPath) => {
|
|
4959
4964
|
if (typeof fullPath !== "string") {
|
|
4960
|
-
throw new Error(
|
|
4965
|
+
throw new Error(
|
|
4966
|
+
`fullPath must be of type string for getDocument request`
|
|
4967
|
+
);
|
|
4961
4968
|
}
|
|
4962
4969
|
await this.database.delete(fullPath);
|
|
4963
4970
|
};
|
|
@@ -4983,9 +4990,9 @@ var Resolver = class {
|
|
|
4983
4990
|
return this.buildFieldMutations(
|
|
4984
4991
|
item,
|
|
4985
4992
|
objectTemplate,
|
|
4986
|
-
idField && existingData &&
|
|
4993
|
+
idField && existingData && existingData?.find(
|
|
4987
4994
|
(d) => d[idField.name] === item[idField.name]
|
|
4988
|
-
)
|
|
4995
|
+
)
|
|
4989
4996
|
);
|
|
4990
4997
|
}
|
|
4991
4998
|
)
|
|
@@ -5111,7 +5118,7 @@ var Resolver = class {
|
|
|
5111
5118
|
isCollectionSpecific
|
|
5112
5119
|
}) => {
|
|
5113
5120
|
const doc = await this.getDocument(realPath);
|
|
5114
|
-
const oldDoc = this.resolveLegacyValues(
|
|
5121
|
+
const oldDoc = this.resolveLegacyValues(doc?._rawData || {}, collection);
|
|
5115
5122
|
if (isAddPendingDocument === true) {
|
|
5116
5123
|
const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
|
|
5117
5124
|
const params2 = this.buildParams(args);
|
|
@@ -5121,7 +5128,7 @@ var Resolver = class {
|
|
|
5121
5128
|
const values = await this.buildFieldMutations(
|
|
5122
5129
|
params2,
|
|
5123
5130
|
templateInfo.template,
|
|
5124
|
-
doc
|
|
5131
|
+
doc?._rawData
|
|
5125
5132
|
);
|
|
5126
5133
|
await this.database.put(
|
|
5127
5134
|
realPath,
|
|
@@ -5145,7 +5152,7 @@ var Resolver = class {
|
|
|
5145
5152
|
// @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
|
|
5146
5153
|
templateParams,
|
|
5147
5154
|
template,
|
|
5148
|
-
doc
|
|
5155
|
+
doc?._rawData
|
|
5149
5156
|
),
|
|
5150
5157
|
_template: lastItem(template.namespace)
|
|
5151
5158
|
};
|
|
@@ -5159,9 +5166,13 @@ var Resolver = class {
|
|
|
5159
5166
|
//@ts-ignore
|
|
5160
5167
|
isCollectionSpecific ? args.params : args.params[collection.name],
|
|
5161
5168
|
collection,
|
|
5162
|
-
doc
|
|
5169
|
+
doc?._rawData
|
|
5170
|
+
);
|
|
5171
|
+
await this.database.put(
|
|
5172
|
+
realPath,
|
|
5173
|
+
{ ...oldDoc, ...params },
|
|
5174
|
+
collection.name
|
|
5163
5175
|
);
|
|
5164
|
-
await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
|
|
5165
5176
|
return this.getDocument(realPath);
|
|
5166
5177
|
};
|
|
5167
5178
|
/**
|
|
@@ -5171,7 +5182,6 @@ var Resolver = class {
|
|
|
5171
5182
|
this.resolveLegacyValues = (oldDoc, collection) => {
|
|
5172
5183
|
const legacyValues = {};
|
|
5173
5184
|
Object.entries(oldDoc).forEach(([key, value]) => {
|
|
5174
|
-
var _a;
|
|
5175
5185
|
const reservedKeys = [
|
|
5176
5186
|
"$_body",
|
|
5177
5187
|
"_collection",
|
|
@@ -5184,7 +5194,7 @@ var Resolver = class {
|
|
|
5184
5194
|
return;
|
|
5185
5195
|
}
|
|
5186
5196
|
if (oldDoc._template && collection.templates) {
|
|
5187
|
-
const template =
|
|
5197
|
+
const template = collection.templates?.find(
|
|
5188
5198
|
({ name }) => name === oldDoc._template
|
|
5189
5199
|
);
|
|
5190
5200
|
if (template) {
|
|
@@ -5231,7 +5241,7 @@ var Resolver = class {
|
|
|
5231
5241
|
(yup3) => yup3.object({ relativePath: yup3.string().required() })
|
|
5232
5242
|
);
|
|
5233
5243
|
const collection = await this.tinaSchema.getCollection(collectionLookup);
|
|
5234
|
-
let realPath = import_path3.default.join(collection
|
|
5244
|
+
let realPath = import_path3.default.join(collection?.path, args.relativePath);
|
|
5235
5245
|
if (isFolderCreation) {
|
|
5236
5246
|
realPath = `${realPath}/.gitkeep.${collection.format || "md"}`;
|
|
5237
5247
|
}
|
|
@@ -5280,10 +5290,30 @@ var Resolver = class {
|
|
|
5280
5290
|
docsWithRefs
|
|
5281
5291
|
)) {
|
|
5282
5292
|
let refDoc = await this.getRaw(pathToDocWithRef);
|
|
5293
|
+
let hasUpdate = false;
|
|
5283
5294
|
for (const path7 of referencePaths) {
|
|
5284
|
-
|
|
5295
|
+
const { object: object2, updated } = updateObjectWithJsonPath(
|
|
5296
|
+
refDoc,
|
|
5297
|
+
path7,
|
|
5298
|
+
realPath,
|
|
5299
|
+
null
|
|
5300
|
+
);
|
|
5301
|
+
refDoc = object2;
|
|
5302
|
+
hasUpdate = updated || hasUpdate;
|
|
5303
|
+
}
|
|
5304
|
+
if (hasUpdate) {
|
|
5305
|
+
const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
|
|
5306
|
+
if (!collectionWithRef) {
|
|
5307
|
+
throw new Error(
|
|
5308
|
+
`Unable to find collection for ${pathToDocWithRef}`
|
|
5309
|
+
);
|
|
5310
|
+
}
|
|
5311
|
+
await this.database.put(
|
|
5312
|
+
pathToDocWithRef,
|
|
5313
|
+
refDoc,
|
|
5314
|
+
collectionWithRef.name
|
|
5315
|
+
);
|
|
5285
5316
|
}
|
|
5286
|
-
await this.database.put(pathToDocWithRef, refDoc, collection2);
|
|
5287
5317
|
}
|
|
5288
5318
|
}
|
|
5289
5319
|
}
|
|
@@ -5295,12 +5325,12 @@ var Resolver = class {
|
|
|
5295
5325
|
(yup3) => yup3.object({ params: yup3.object().required() })
|
|
5296
5326
|
);
|
|
5297
5327
|
assertShape(
|
|
5298
|
-
args
|
|
5328
|
+
args?.params,
|
|
5299
5329
|
(yup3) => yup3.object({ relativePath: yup3.string().required() })
|
|
5300
5330
|
);
|
|
5301
5331
|
const doc = await this.getDocument(realPath);
|
|
5302
5332
|
const newRealPath = import_path3.default.join(
|
|
5303
|
-
collection
|
|
5333
|
+
collection?.path,
|
|
5304
5334
|
args.params.relativePath
|
|
5305
5335
|
);
|
|
5306
5336
|
if (newRealPath === realPath) {
|
|
@@ -5314,21 +5344,38 @@ var Resolver = class {
|
|
|
5314
5344
|
docsWithRefs
|
|
5315
5345
|
)) {
|
|
5316
5346
|
let docWithRef = await this.getRaw(pathToDocWithRef);
|
|
5347
|
+
let hasUpdate = false;
|
|
5317
5348
|
for (const path7 of referencePaths) {
|
|
5318
|
-
|
|
5349
|
+
const { object: object2, updated } = updateObjectWithJsonPath(
|
|
5319
5350
|
docWithRef,
|
|
5320
5351
|
path7,
|
|
5321
5352
|
realPath,
|
|
5322
5353
|
newRealPath
|
|
5323
5354
|
);
|
|
5355
|
+
docWithRef = object2;
|
|
5356
|
+
hasUpdate = updated || hasUpdate;
|
|
5357
|
+
}
|
|
5358
|
+
if (hasUpdate) {
|
|
5359
|
+
const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
|
|
5360
|
+
if (!collectionWithRef) {
|
|
5361
|
+
throw new Error(
|
|
5362
|
+
`Unable to find collection for ${pathToDocWithRef}`
|
|
5363
|
+
);
|
|
5364
|
+
}
|
|
5365
|
+
await this.database.put(
|
|
5366
|
+
pathToDocWithRef,
|
|
5367
|
+
docWithRef,
|
|
5368
|
+
collectionWithRef.name
|
|
5369
|
+
);
|
|
5324
5370
|
}
|
|
5325
|
-
await this.database.put(pathToDocWithRef, docWithRef, collection2);
|
|
5326
5371
|
}
|
|
5327
5372
|
}
|
|
5328
5373
|
return this.getDocument(newRealPath);
|
|
5329
5374
|
}
|
|
5330
5375
|
if (alreadyExists === false) {
|
|
5331
|
-
throw new Error(
|
|
5376
|
+
throw new Error(
|
|
5377
|
+
`Unable to update document, ${realPath} does not exist`
|
|
5378
|
+
);
|
|
5332
5379
|
}
|
|
5333
5380
|
return this.updateResolveDocument({
|
|
5334
5381
|
collection,
|
|
@@ -5513,7 +5560,7 @@ var Resolver = class {
|
|
|
5513
5560
|
if (!references[c.name][refId]) {
|
|
5514
5561
|
references[c.name][refId] = [];
|
|
5515
5562
|
}
|
|
5516
|
-
const referencePath = rawItem
|
|
5563
|
+
const referencePath = rawItem?.[REFS_PATH_FIELD];
|
|
5517
5564
|
if (referencePath) {
|
|
5518
5565
|
references[c.name][refId].push(referencePath);
|
|
5519
5566
|
}
|
|
@@ -5523,7 +5570,6 @@ var Resolver = class {
|
|
|
5523
5570
|
return references;
|
|
5524
5571
|
};
|
|
5525
5572
|
this.buildFieldMutations = async (fieldParams, template, existingData) => {
|
|
5526
|
-
var _a;
|
|
5527
5573
|
const accum = {};
|
|
5528
5574
|
for (const passwordField of template.fields.filter(
|
|
5529
5575
|
(f) => f.type === "password"
|
|
@@ -5566,7 +5612,7 @@ var Resolver = class {
|
|
|
5566
5612
|
accum[fieldName] = await this.buildObjectMutations(
|
|
5567
5613
|
fieldValue,
|
|
5568
5614
|
field,
|
|
5569
|
-
existingData
|
|
5615
|
+
existingData?.[fieldName]
|
|
5570
5616
|
);
|
|
5571
5617
|
break;
|
|
5572
5618
|
case "password":
|
|
@@ -5585,7 +5631,7 @@ var Resolver = class {
|
|
|
5585
5631
|
} else {
|
|
5586
5632
|
accum[fieldName] = {
|
|
5587
5633
|
...fieldValue,
|
|
5588
|
-
value:
|
|
5634
|
+
value: existingData?.[fieldName]?.["value"]
|
|
5589
5635
|
};
|
|
5590
5636
|
}
|
|
5591
5637
|
break;
|
|
@@ -5720,9 +5766,8 @@ var resolve = async ({
|
|
|
5720
5766
|
isAudit,
|
|
5721
5767
|
ctxUser
|
|
5722
5768
|
}) => {
|
|
5723
|
-
var _a;
|
|
5724
5769
|
try {
|
|
5725
|
-
const verboseValue = verbose
|
|
5770
|
+
const verboseValue = verbose ?? true;
|
|
5726
5771
|
const graphQLSchemaAst = await database.getGraphQLSchema();
|
|
5727
5772
|
if (!graphQLSchemaAst) {
|
|
5728
5773
|
throw new import_graphql5.GraphQLError("GraphQL schema not found");
|
|
@@ -5734,7 +5779,7 @@ var resolve = async ({
|
|
|
5734
5779
|
// @ts-ignore
|
|
5735
5780
|
schema: tinaConfig,
|
|
5736
5781
|
// @ts-ignore
|
|
5737
|
-
flags:
|
|
5782
|
+
flags: tinaConfig?.meta?.flags
|
|
5738
5783
|
});
|
|
5739
5784
|
const resolver = createResolver({
|
|
5740
5785
|
config,
|
|
@@ -5759,7 +5804,6 @@ var resolve = async ({
|
|
|
5759
5804
|
throw new Error(`Unable to find lookup key for ${namedType}`);
|
|
5760
5805
|
},
|
|
5761
5806
|
fieldResolver: async (source = {}, _args = {}, _context, info) => {
|
|
5762
|
-
var _a2, _b, _c, _d;
|
|
5763
5807
|
try {
|
|
5764
5808
|
const args = JSON.parse(JSON.stringify(_args));
|
|
5765
5809
|
const returnType = (0, import_graphql5.getNamedType)(info.returnType).toString();
|
|
@@ -5776,8 +5820,7 @@ var resolve = async ({
|
|
|
5776
5820
|
);
|
|
5777
5821
|
const hasDocuments2 = collectionNode2.selectionSet.selections.find(
|
|
5778
5822
|
(x) => {
|
|
5779
|
-
|
|
5780
|
-
return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
|
|
5823
|
+
return x?.name?.value === "documents";
|
|
5781
5824
|
}
|
|
5782
5825
|
);
|
|
5783
5826
|
return tinaSchema.getCollections().map((collection) => {
|
|
@@ -5793,8 +5836,7 @@ var resolve = async ({
|
|
|
5793
5836
|
);
|
|
5794
5837
|
const hasDocuments = collectionNode.selectionSet.selections.find(
|
|
5795
5838
|
(x) => {
|
|
5796
|
-
|
|
5797
|
-
return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
|
|
5839
|
+
return x?.name?.value === "documents";
|
|
5798
5840
|
}
|
|
5799
5841
|
);
|
|
5800
5842
|
return resolver.resolveCollection(
|
|
@@ -5813,7 +5855,7 @@ var resolve = async ({
|
|
|
5813
5855
|
}
|
|
5814
5856
|
}
|
|
5815
5857
|
if (info.fieldName === "authenticate" || info.fieldName === "authorize") {
|
|
5816
|
-
const sub = args.sub ||
|
|
5858
|
+
const sub = args.sub || ctxUser?.sub;
|
|
5817
5859
|
const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
|
|
5818
5860
|
if (!collection) {
|
|
5819
5861
|
throw new Error("Auth collection not found");
|
|
@@ -5861,7 +5903,7 @@ var resolve = async ({
|
|
|
5861
5903
|
return user;
|
|
5862
5904
|
}
|
|
5863
5905
|
if (info.fieldName === "updatePassword") {
|
|
5864
|
-
if (!
|
|
5906
|
+
if (!ctxUser?.sub) {
|
|
5865
5907
|
throw new Error("Not authorized");
|
|
5866
5908
|
}
|
|
5867
5909
|
if (!args.password) {
|
|
@@ -5944,7 +5986,7 @@ var resolve = async ({
|
|
|
5944
5986
|
if (typeof value === "string" && value !== "") {
|
|
5945
5987
|
return resolver.getDocument(value);
|
|
5946
5988
|
}
|
|
5947
|
-
if (
|
|
5989
|
+
if (args?.collection && info.fieldName === "addPendingDocument") {
|
|
5948
5990
|
return resolver.resolveDocument({
|
|
5949
5991
|
args: { ...args, params: {} },
|
|
5950
5992
|
collection: args.collection,
|
|
@@ -5968,7 +6010,7 @@ var resolve = async ({
|
|
|
5968
6010
|
// Right now this is the only case for deletion
|
|
5969
6011
|
isDeletion: info.fieldName === "deleteDocument",
|
|
5970
6012
|
isFolderCreation: info.fieldName === "createFolder",
|
|
5971
|
-
isUpdateName: Boolean(
|
|
6013
|
+
isUpdateName: Boolean(args?.params?.relativePath),
|
|
5972
6014
|
isAddPendingDocument: false,
|
|
5973
6015
|
isCollectionSpecific: false
|
|
5974
6016
|
});
|
|
@@ -5987,16 +6029,16 @@ var resolve = async ({
|
|
|
5987
6029
|
})
|
|
5988
6030
|
};
|
|
5989
6031
|
}
|
|
5990
|
-
if (info.fieldName === "documents" &&
|
|
6032
|
+
if (info.fieldName === "documents" && value?.collection && value?.hasDocuments) {
|
|
5991
6033
|
let filter = args.filter;
|
|
5992
6034
|
if (
|
|
5993
6035
|
// 1. Make sure that the filter exists
|
|
5994
|
-
typeof
|
|
6036
|
+
typeof args?.filter !== "undefined" && args?.filter !== null && // 2. Make sure that the collection name exists
|
|
5995
6037
|
// @ts-ignore
|
|
5996
|
-
typeof
|
|
6038
|
+
typeof value?.collection?.name === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
|
|
5997
6039
|
// @ts-ignore
|
|
5998
|
-
Object.keys(args.filter).includes(
|
|
5999
|
-
typeof args.filter[
|
|
6040
|
+
Object.keys(args.filter).includes(value?.collection?.name) && // @ts-ignore
|
|
6041
|
+
typeof args.filter[value?.collection?.name] !== "undefined"
|
|
6000
6042
|
) {
|
|
6001
6043
|
filter = args.filter[value.collection.name];
|
|
6002
6044
|
}
|
|
@@ -6133,15 +6175,15 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
|
|
|
6133
6175
|
};
|
|
6134
6176
|
|
|
6135
6177
|
// src/database/index.ts
|
|
6136
|
-
var import_node_path = __toESM(require("path"));
|
|
6178
|
+
var import_node_path = __toESM(require("node:path"));
|
|
6137
6179
|
var import_graphql6 = require("graphql");
|
|
6138
6180
|
var import_micromatch2 = __toESM(require("micromatch"));
|
|
6139
6181
|
var import_js_sha12 = __toESM(require("js-sha1"));
|
|
6140
6182
|
var import_lodash5 = __toESM(require("lodash.set"));
|
|
6141
6183
|
var createLocalDatabase = (config) => {
|
|
6142
|
-
const level = new TinaLevelClient(config
|
|
6184
|
+
const level = new TinaLevelClient(config?.port);
|
|
6143
6185
|
level.openConnection();
|
|
6144
|
-
const fsBridge = new FilesystemBridge(
|
|
6186
|
+
const fsBridge = new FilesystemBridge(config?.rootPath || process.cwd());
|
|
6145
6187
|
return new Database({
|
|
6146
6188
|
bridge: fsBridge,
|
|
6147
6189
|
...config || {},
|
|
@@ -6214,7 +6256,7 @@ var Database = class {
|
|
|
6214
6256
|
);
|
|
6215
6257
|
}
|
|
6216
6258
|
const metadata = await metadataLevel.get(`metadata_${key}`);
|
|
6217
|
-
return metadata
|
|
6259
|
+
return metadata?.value;
|
|
6218
6260
|
};
|
|
6219
6261
|
this.setMetadata = async (key, value) => {
|
|
6220
6262
|
await this.initLevel();
|
|
@@ -6236,7 +6278,7 @@ var Database = class {
|
|
|
6236
6278
|
let level = this.contentLevel;
|
|
6237
6279
|
if (this.appLevel) {
|
|
6238
6280
|
collection = await this.collectionForPath(filepath);
|
|
6239
|
-
if (collection
|
|
6281
|
+
if (collection?.isDetached) {
|
|
6240
6282
|
level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
|
|
6241
6283
|
}
|
|
6242
6284
|
}
|
|
@@ -6255,7 +6297,6 @@ var Database = class {
|
|
|
6255
6297
|
}
|
|
6256
6298
|
};
|
|
6257
6299
|
this.addPendingDocument = async (filepath, data) => {
|
|
6258
|
-
var _a;
|
|
6259
6300
|
await this.initLevel();
|
|
6260
6301
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
6261
6302
|
const collection = await this.collectionForPath(filepath);
|
|
@@ -6268,10 +6309,10 @@ var Database = class {
|
|
|
6268
6309
|
collection
|
|
6269
6310
|
);
|
|
6270
6311
|
const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
|
|
6271
|
-
const collectionIndexDefinitions = indexDefinitions
|
|
6272
|
-
const collectionReferences = (
|
|
6312
|
+
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
6313
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
|
|
6273
6314
|
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
6274
|
-
if (!
|
|
6315
|
+
if (!collection?.isDetached) {
|
|
6275
6316
|
if (this.bridge) {
|
|
6276
6317
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
6277
6318
|
}
|
|
@@ -6289,7 +6330,7 @@ var Database = class {
|
|
|
6289
6330
|
}
|
|
6290
6331
|
}
|
|
6291
6332
|
let level = this.contentLevel;
|
|
6292
|
-
if (collection
|
|
6333
|
+
if (collection?.isDetached) {
|
|
6293
6334
|
level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
|
|
6294
6335
|
}
|
|
6295
6336
|
const folderTreeBuilder = new FolderTreeBuilder();
|
|
@@ -6300,7 +6341,7 @@ var Database = class {
|
|
|
6300
6341
|
putOps = [
|
|
6301
6342
|
...makeRefOpsForDocument(
|
|
6302
6343
|
normalizedPath,
|
|
6303
|
-
collection
|
|
6344
|
+
collection?.name,
|
|
6304
6345
|
collectionReferences,
|
|
6305
6346
|
dataFields,
|
|
6306
6347
|
"put",
|
|
@@ -6308,7 +6349,7 @@ var Database = class {
|
|
|
6308
6349
|
),
|
|
6309
6350
|
...makeIndexOpsForDocument(
|
|
6310
6351
|
normalizedPath,
|
|
6311
|
-
collection
|
|
6352
|
+
collection?.name,
|
|
6312
6353
|
collectionIndexDefinitions,
|
|
6313
6354
|
dataFields,
|
|
6314
6355
|
"put",
|
|
@@ -6317,7 +6358,7 @@ var Database = class {
|
|
|
6317
6358
|
// folder indices
|
|
6318
6359
|
...makeIndexOpsForDocument(
|
|
6319
6360
|
normalizedPath,
|
|
6320
|
-
`${collection
|
|
6361
|
+
`${collection?.name}_${folderKey}`,
|
|
6321
6362
|
collectionIndexDefinitions,
|
|
6322
6363
|
dataFields,
|
|
6323
6364
|
"put",
|
|
@@ -6331,7 +6372,7 @@ var Database = class {
|
|
|
6331
6372
|
delOps = existingItem ? [
|
|
6332
6373
|
...makeRefOpsForDocument(
|
|
6333
6374
|
normalizedPath,
|
|
6334
|
-
collection
|
|
6375
|
+
collection?.name,
|
|
6335
6376
|
collectionReferences,
|
|
6336
6377
|
existingItem,
|
|
6337
6378
|
"del",
|
|
@@ -6339,7 +6380,7 @@ var Database = class {
|
|
|
6339
6380
|
),
|
|
6340
6381
|
...makeIndexOpsForDocument(
|
|
6341
6382
|
normalizedPath,
|
|
6342
|
-
collection
|
|
6383
|
+
collection?.name,
|
|
6343
6384
|
collectionIndexDefinitions,
|
|
6344
6385
|
existingItem,
|
|
6345
6386
|
"del",
|
|
@@ -6348,7 +6389,7 @@ var Database = class {
|
|
|
6348
6389
|
// folder indices
|
|
6349
6390
|
...makeIndexOpsForDocument(
|
|
6350
6391
|
normalizedPath,
|
|
6351
|
-
`${collection
|
|
6392
|
+
`${collection?.name}_${folderKey}`,
|
|
6352
6393
|
collectionIndexDefinitions,
|
|
6353
6394
|
existingItem,
|
|
6354
6395
|
"del",
|
|
@@ -6372,7 +6413,6 @@ var Database = class {
|
|
|
6372
6413
|
await level.batch(ops);
|
|
6373
6414
|
};
|
|
6374
6415
|
this.put = async (filepath, data, collectionName) => {
|
|
6375
|
-
var _a, _b, _c;
|
|
6376
6416
|
await this.initLevel();
|
|
6377
6417
|
try {
|
|
6378
6418
|
if (SYSTEM_FILES.includes(filepath)) {
|
|
@@ -6383,16 +6423,16 @@ var Database = class {
|
|
|
6383
6423
|
const indexDefinitions = await this.getIndexDefinitions(
|
|
6384
6424
|
this.contentLevel
|
|
6385
6425
|
);
|
|
6386
|
-
collectionIndexDefinitions = indexDefinitions
|
|
6426
|
+
collectionIndexDefinitions = indexDefinitions?.[collectionName];
|
|
6387
6427
|
}
|
|
6388
|
-
const collectionReferences = (
|
|
6428
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collectionName];
|
|
6389
6429
|
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
6390
6430
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
6391
6431
|
const collection = await this.collectionForPath(filepath);
|
|
6392
6432
|
if (!collection) {
|
|
6393
6433
|
throw new import_graphql6.GraphQLError(`Unable to find collection for ${filepath}.`);
|
|
6394
6434
|
}
|
|
6395
|
-
if (
|
|
6435
|
+
if (collection.match?.exclude || collection.match?.include) {
|
|
6396
6436
|
const matches = this.tinaSchema.getMatches({ collection });
|
|
6397
6437
|
const match = import_micromatch2.default.isMatch(filepath, matches);
|
|
6398
6438
|
if (!match) {
|
|
@@ -6406,7 +6446,7 @@ var Database = class {
|
|
|
6406
6446
|
const stringifiedFile = filepath.endsWith(
|
|
6407
6447
|
`.gitkeep.${collection.format || "md"}`
|
|
6408
6448
|
) ? "" : await this.stringifyFile(filepath, dataFields, collection);
|
|
6409
|
-
if (!
|
|
6449
|
+
if (!collection?.isDetached) {
|
|
6410
6450
|
if (this.bridge) {
|
|
6411
6451
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
6412
6452
|
}
|
|
@@ -6428,7 +6468,7 @@ var Database = class {
|
|
|
6428
6468
|
filepath,
|
|
6429
6469
|
collection.path || ""
|
|
6430
6470
|
);
|
|
6431
|
-
const level =
|
|
6471
|
+
const level = collection?.isDetached ? this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS) : this.contentLevel;
|
|
6432
6472
|
let putOps = [];
|
|
6433
6473
|
let delOps = [];
|
|
6434
6474
|
if (!isGitKeep(normalizedPath, collection)) {
|
|
@@ -6452,7 +6492,7 @@ var Database = class {
|
|
|
6452
6492
|
// folder indices
|
|
6453
6493
|
...makeIndexOpsForDocument(
|
|
6454
6494
|
normalizedPath,
|
|
6455
|
-
`${collection
|
|
6495
|
+
`${collection?.name}_${folderKey}`,
|
|
6456
6496
|
collectionIndexDefinitions,
|
|
6457
6497
|
dataFields,
|
|
6458
6498
|
"put",
|
|
@@ -6483,7 +6523,7 @@ var Database = class {
|
|
|
6483
6523
|
// folder indices
|
|
6484
6524
|
...makeIndexOpsForDocument(
|
|
6485
6525
|
normalizedPath,
|
|
6486
|
-
`${collection
|
|
6526
|
+
`${collection?.name}_${folderKey}`,
|
|
6487
6527
|
collectionIndexDefinitions,
|
|
6488
6528
|
existingItem,
|
|
6489
6529
|
"del",
|
|
@@ -6560,8 +6600,8 @@ var Database = class {
|
|
|
6560
6600
|
writeTemplateKey,
|
|
6561
6601
|
//templateInfo.type === 'union',
|
|
6562
6602
|
{
|
|
6563
|
-
frontmatterFormat: collection
|
|
6564
|
-
frontmatterDelimiters: collection
|
|
6603
|
+
frontmatterFormat: collection?.frontmatterFormat,
|
|
6604
|
+
frontmatterDelimiters: collection?.frontmatterDelimiters
|
|
6565
6605
|
}
|
|
6566
6606
|
);
|
|
6567
6607
|
};
|
|
@@ -6677,8 +6717,35 @@ var Database = class {
|
|
|
6677
6717
|
]
|
|
6678
6718
|
}
|
|
6679
6719
|
};
|
|
6680
|
-
|
|
6681
|
-
|
|
6720
|
+
let fields = [];
|
|
6721
|
+
if (collection.templates) {
|
|
6722
|
+
const templateFieldMap = {};
|
|
6723
|
+
const conflictedFields = /* @__PURE__ */ new Set();
|
|
6724
|
+
for (const template of collection.templates) {
|
|
6725
|
+
for (const field of template.fields) {
|
|
6726
|
+
if (!templateFieldMap[field.name]) {
|
|
6727
|
+
templateFieldMap[field.name] = field;
|
|
6728
|
+
} else {
|
|
6729
|
+
if (templateFieldMap[field.name].type !== field.type) {
|
|
6730
|
+
console.warn(
|
|
6731
|
+
`Field ${field.name} has conflicting types in templates - skipping index`
|
|
6732
|
+
);
|
|
6733
|
+
conflictedFields.add(field.name);
|
|
6734
|
+
}
|
|
6735
|
+
}
|
|
6736
|
+
}
|
|
6737
|
+
}
|
|
6738
|
+
for (const conflictedField in conflictedFields) {
|
|
6739
|
+
delete templateFieldMap[conflictedField];
|
|
6740
|
+
}
|
|
6741
|
+
for (const field of Object.values(templateFieldMap)) {
|
|
6742
|
+
fields.push(field);
|
|
6743
|
+
}
|
|
6744
|
+
} else if (collection.fields) {
|
|
6745
|
+
fields = collection.fields;
|
|
6746
|
+
}
|
|
6747
|
+
if (fields) {
|
|
6748
|
+
for (const field of fields) {
|
|
6682
6749
|
if (field.indexed !== void 0 && field.indexed === false || field.type === "object") {
|
|
6683
6750
|
continue;
|
|
6684
6751
|
}
|
|
@@ -6703,8 +6770,8 @@ var Database = class {
|
|
|
6703
6770
|
);
|
|
6704
6771
|
return {
|
|
6705
6772
|
name: indexField.name,
|
|
6706
|
-
type: field
|
|
6707
|
-
list: !!
|
|
6773
|
+
type: field?.type,
|
|
6774
|
+
list: !!field?.list
|
|
6708
6775
|
};
|
|
6709
6776
|
})
|
|
6710
6777
|
};
|
|
@@ -6730,7 +6797,6 @@ var Database = class {
|
|
|
6730
6797
|
return true;
|
|
6731
6798
|
};
|
|
6732
6799
|
this.query = async (queryOptions, hydrator) => {
|
|
6733
|
-
var _a;
|
|
6734
6800
|
await this.initLevel();
|
|
6735
6801
|
const {
|
|
6736
6802
|
first,
|
|
@@ -6758,14 +6824,14 @@ var Database = class {
|
|
|
6758
6824
|
const allIndexDefinitions = await this.getIndexDefinitions(
|
|
6759
6825
|
this.contentLevel
|
|
6760
6826
|
);
|
|
6761
|
-
const indexDefinitions = allIndexDefinitions
|
|
6827
|
+
const indexDefinitions = allIndexDefinitions?.[collection.name];
|
|
6762
6828
|
if (!indexDefinitions) {
|
|
6763
6829
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
6764
6830
|
}
|
|
6765
6831
|
const filterChain = coerceFilterChainOperands(rawFilterChain);
|
|
6766
|
-
const indexDefinition = sort &&
|
|
6832
|
+
const indexDefinition = sort && indexDefinitions?.[sort];
|
|
6767
6833
|
const filterSuffixes = indexDefinition && makeFilterSuffixes(filterChain, indexDefinition);
|
|
6768
|
-
const level =
|
|
6834
|
+
const level = collection?.isDetached ? this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS) : this.contentLevel;
|
|
6769
6835
|
const rootLevel = level.sublevel(
|
|
6770
6836
|
CONTENT_ROOT_PREFIX,
|
|
6771
6837
|
SUBLEVEL_OPTIONS
|
|
@@ -6775,17 +6841,17 @@ var Database = class {
|
|
|
6775
6841
|
SUBLEVEL_OPTIONS
|
|
6776
6842
|
).sublevel(sort, SUBLEVEL_OPTIONS) : rootLevel;
|
|
6777
6843
|
if (!query.gt && !query.gte) {
|
|
6778
|
-
query.gte =
|
|
6844
|
+
query.gte = filterSuffixes?.left ? filterSuffixes.left : "";
|
|
6779
6845
|
}
|
|
6780
6846
|
if (!query.lt && !query.lte) {
|
|
6781
|
-
query.lte =
|
|
6847
|
+
query.lte = filterSuffixes?.right ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
|
|
6782
6848
|
}
|
|
6783
6849
|
let edges = [];
|
|
6784
6850
|
let startKey = "";
|
|
6785
6851
|
let endKey = "";
|
|
6786
6852
|
let hasPreviousPage = false;
|
|
6787
6853
|
let hasNextPage = false;
|
|
6788
|
-
const fieldsPattern =
|
|
6854
|
+
const fieldsPattern = indexDefinition?.fields?.length ? `${indexDefinition.fields.map((p) => `(?<${p.name}>.+)${INDEX_KEY_FIELD_SEPARATOR}`).join("")}` : "";
|
|
6789
6855
|
const valuesRegex = indexDefinition ? new RegExp(`^${fieldsPattern}(?<_filepath_>.+)`) : new RegExp(`^(?<_filepath_>.+)`);
|
|
6790
6856
|
const itemFilter = makeFilter({ filterChain });
|
|
6791
6857
|
const iterator = sublevel.iterator(query);
|
|
@@ -6980,13 +7046,14 @@ var Database = class {
|
|
|
6980
7046
|
documentPaths,
|
|
6981
7047
|
async (collection, documentPaths2) => {
|
|
6982
7048
|
if (collection && !collection.isDetached) {
|
|
6983
|
-
await _indexContent(
|
|
6984
|
-
this,
|
|
6985
|
-
this.contentLevel,
|
|
6986
|
-
documentPaths2,
|
|
7049
|
+
await _indexContent({
|
|
7050
|
+
database: this,
|
|
7051
|
+
level: this.contentLevel,
|
|
7052
|
+
documentPaths: documentPaths2,
|
|
6987
7053
|
enqueueOps,
|
|
6988
|
-
collection
|
|
6989
|
-
|
|
7054
|
+
collection,
|
|
7055
|
+
isPartialReindex: true
|
|
7056
|
+
});
|
|
6990
7057
|
}
|
|
6991
7058
|
}
|
|
6992
7059
|
);
|
|
@@ -6996,18 +7063,17 @@ var Database = class {
|
|
|
6996
7063
|
}
|
|
6997
7064
|
};
|
|
6998
7065
|
this.delete = async (filepath) => {
|
|
6999
|
-
var _a;
|
|
7000
7066
|
await this.initLevel();
|
|
7001
7067
|
const collection = await this.collectionForPath(filepath);
|
|
7002
7068
|
if (!collection) {
|
|
7003
7069
|
throw new Error(`No collection found for path: ${filepath}`);
|
|
7004
7070
|
}
|
|
7005
7071
|
const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
|
|
7006
|
-
const collectionReferences = (
|
|
7007
|
-
const collectionIndexDefinitions = indexDefinitions
|
|
7072
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
|
|
7073
|
+
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
7008
7074
|
let level = this.contentLevel;
|
|
7009
|
-
if (collection
|
|
7010
|
-
level = this.appLevel.sublevel(collection
|
|
7075
|
+
if (collection?.isDetached) {
|
|
7076
|
+
level = this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS);
|
|
7011
7077
|
}
|
|
7012
7078
|
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
7013
7079
|
const rootSublevel = level.sublevel(
|
|
@@ -7054,7 +7120,7 @@ var Database = class {
|
|
|
7054
7120
|
}
|
|
7055
7121
|
]);
|
|
7056
7122
|
}
|
|
7057
|
-
if (!
|
|
7123
|
+
if (!collection?.isDetached) {
|
|
7058
7124
|
if (this.bridge) {
|
|
7059
7125
|
await this.bridge.delete(normalizedPath);
|
|
7060
7126
|
}
|
|
@@ -7094,20 +7160,26 @@ var Database = class {
|
|
|
7094
7160
|
);
|
|
7095
7161
|
const doc = await level2.keys({ limit: 1 }).next();
|
|
7096
7162
|
if (!doc) {
|
|
7097
|
-
await _indexContent(
|
|
7098
|
-
this,
|
|
7099
|
-
level2,
|
|
7100
|
-
contentPaths,
|
|
7163
|
+
await _indexContent({
|
|
7164
|
+
database: this,
|
|
7165
|
+
level: level2,
|
|
7166
|
+
documentPaths: contentPaths,
|
|
7101
7167
|
enqueueOps,
|
|
7102
7168
|
collection,
|
|
7103
|
-
userFields.map((field) => [
|
|
7169
|
+
passwordFields: userFields.map((field) => [
|
|
7104
7170
|
...field.path,
|
|
7105
7171
|
field.passwordFieldName
|
|
7106
7172
|
])
|
|
7107
|
-
);
|
|
7173
|
+
});
|
|
7108
7174
|
}
|
|
7109
7175
|
} else {
|
|
7110
|
-
await _indexContent(
|
|
7176
|
+
await _indexContent({
|
|
7177
|
+
database: this,
|
|
7178
|
+
level,
|
|
7179
|
+
documentPaths: contentPaths,
|
|
7180
|
+
enqueueOps,
|
|
7181
|
+
collection
|
|
7182
|
+
});
|
|
7111
7183
|
}
|
|
7112
7184
|
}
|
|
7113
7185
|
);
|
|
@@ -7143,7 +7215,7 @@ var Database = class {
|
|
|
7143
7215
|
);
|
|
7144
7216
|
}
|
|
7145
7217
|
const metadata = await metadataLevel.get("metadata");
|
|
7146
|
-
return metadata
|
|
7218
|
+
return metadata?.version;
|
|
7147
7219
|
}
|
|
7148
7220
|
async initLevel() {
|
|
7149
7221
|
if (this.contentLevel) {
|
|
@@ -7229,7 +7301,7 @@ var hashPasswordVisitor = async (node, path7) => {
|
|
|
7229
7301
|
};
|
|
7230
7302
|
var visitNodes = async (node, path7, callback) => {
|
|
7231
7303
|
const [currentLevel, ...remainingLevels] = path7;
|
|
7232
|
-
if (!
|
|
7304
|
+
if (!remainingLevels?.length) {
|
|
7233
7305
|
return callback(node, path7);
|
|
7234
7306
|
}
|
|
7235
7307
|
if (Array.isArray(node[currentLevel])) {
|
|
@@ -7245,20 +7317,27 @@ var hashPasswordValues = async (data, passwordFields) => Promise.all(
|
|
|
7245
7317
|
async (passwordField) => visitNodes(data, passwordField, hashPasswordVisitor)
|
|
7246
7318
|
)
|
|
7247
7319
|
);
|
|
7248
|
-
var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${
|
|
7249
|
-
var _indexContent = async (
|
|
7250
|
-
|
|
7320
|
+
var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${collection?.format || "md"}`);
|
|
7321
|
+
var _indexContent = async ({
|
|
7322
|
+
database,
|
|
7323
|
+
level,
|
|
7324
|
+
documentPaths,
|
|
7325
|
+
enqueueOps,
|
|
7326
|
+
collection,
|
|
7327
|
+
passwordFields,
|
|
7328
|
+
isPartialReindex
|
|
7329
|
+
}) => {
|
|
7251
7330
|
let collectionIndexDefinitions;
|
|
7252
7331
|
let collectionPath;
|
|
7253
7332
|
if (collection) {
|
|
7254
7333
|
const indexDefinitions = await database.getIndexDefinitions(level);
|
|
7255
|
-
collectionIndexDefinitions = indexDefinitions
|
|
7334
|
+
collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
7256
7335
|
if (!collectionIndexDefinitions) {
|
|
7257
7336
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
7258
7337
|
}
|
|
7259
7338
|
collectionPath = collection.path;
|
|
7260
7339
|
}
|
|
7261
|
-
const collectionReferences = (
|
|
7340
|
+
const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
|
|
7262
7341
|
const tinaSchema = await database.getSchema();
|
|
7263
7342
|
let templateInfo = null;
|
|
7264
7343
|
if (collection) {
|
|
@@ -7276,7 +7355,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7276
7355
|
if (!aliasedData) {
|
|
7277
7356
|
return;
|
|
7278
7357
|
}
|
|
7279
|
-
if (passwordFields
|
|
7358
|
+
if (passwordFields?.length) {
|
|
7280
7359
|
await hashPasswordValues(aliasedData, passwordFields);
|
|
7281
7360
|
}
|
|
7282
7361
|
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
@@ -7288,46 +7367,48 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7288
7367
|
normalizedPath,
|
|
7289
7368
|
collectionPath || ""
|
|
7290
7369
|
);
|
|
7291
|
-
|
|
7292
|
-
|
|
7293
|
-
|
|
7294
|
-
|
|
7295
|
-
|
|
7296
|
-
|
|
7297
|
-
|
|
7298
|
-
|
|
7299
|
-
|
|
7300
|
-
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
|
|
7304
|
-
|
|
7305
|
-
|
|
7306
|
-
|
|
7307
|
-
|
|
7308
|
-
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
|
|
7313
|
-
|
|
7314
|
-
|
|
7315
|
-
|
|
7316
|
-
|
|
7317
|
-
|
|
7318
|
-
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7370
|
+
if (isPartialReindex) {
|
|
7371
|
+
const item = await rootSublevel.get(normalizedPath);
|
|
7372
|
+
if (item) {
|
|
7373
|
+
await database.contentLevel.batch([
|
|
7374
|
+
...makeRefOpsForDocument(
|
|
7375
|
+
normalizedPath,
|
|
7376
|
+
collection?.name,
|
|
7377
|
+
collectionReferences,
|
|
7378
|
+
item,
|
|
7379
|
+
"del",
|
|
7380
|
+
level
|
|
7381
|
+
),
|
|
7382
|
+
...makeIndexOpsForDocument(
|
|
7383
|
+
normalizedPath,
|
|
7384
|
+
collection.name,
|
|
7385
|
+
collectionIndexDefinitions,
|
|
7386
|
+
item,
|
|
7387
|
+
"del",
|
|
7388
|
+
level
|
|
7389
|
+
),
|
|
7390
|
+
// folder indices
|
|
7391
|
+
...makeIndexOpsForDocument(
|
|
7392
|
+
normalizedPath,
|
|
7393
|
+
`${collection.name}_${folderKey}`,
|
|
7394
|
+
collectionIndexDefinitions,
|
|
7395
|
+
item,
|
|
7396
|
+
"del",
|
|
7397
|
+
level
|
|
7398
|
+
),
|
|
7399
|
+
{
|
|
7400
|
+
type: "del",
|
|
7401
|
+
key: normalizedPath,
|
|
7402
|
+
sublevel: rootSublevel
|
|
7403
|
+
}
|
|
7404
|
+
]);
|
|
7405
|
+
}
|
|
7325
7406
|
}
|
|
7326
7407
|
if (!isGitKeep(filepath, collection)) {
|
|
7327
7408
|
await enqueueOps([
|
|
7328
7409
|
...makeRefOpsForDocument(
|
|
7329
7410
|
normalizedPath,
|
|
7330
|
-
collection
|
|
7411
|
+
collection?.name,
|
|
7331
7412
|
collectionReferences,
|
|
7332
7413
|
aliasedData,
|
|
7333
7414
|
"put",
|
|
@@ -7335,7 +7416,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7335
7416
|
),
|
|
7336
7417
|
...makeIndexOpsForDocument(
|
|
7337
7418
|
normalizedPath,
|
|
7338
|
-
collection
|
|
7419
|
+
collection?.name,
|
|
7339
7420
|
collectionIndexDefinitions,
|
|
7340
7421
|
aliasedData,
|
|
7341
7422
|
"put",
|
|
@@ -7344,7 +7425,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7344
7425
|
// folder indexes
|
|
7345
7426
|
...makeIndexOpsForDocument(
|
|
7346
7427
|
normalizedPath,
|
|
7347
|
-
`${collection
|
|
7428
|
+
`${collection?.name}_${folderKey}`,
|
|
7348
7429
|
collectionIndexDefinitions,
|
|
7349
7430
|
aliasedData,
|
|
7350
7431
|
"put",
|
|
@@ -7365,7 +7446,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7365
7446
|
throw new TinaFetchError(`Unable to seed ${filepath}`, {
|
|
7366
7447
|
originalError: error,
|
|
7367
7448
|
file: filepath,
|
|
7368
|
-
collection: collection
|
|
7449
|
+
collection: collection?.name,
|
|
7369
7450
|
stack: error.stack
|
|
7370
7451
|
});
|
|
7371
7452
|
}
|
|
@@ -7383,7 +7464,6 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7383
7464
|
}
|
|
7384
7465
|
};
|
|
7385
7466
|
var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection) => {
|
|
7386
|
-
var _a;
|
|
7387
7467
|
if (!documentPaths.length) {
|
|
7388
7468
|
return;
|
|
7389
7469
|
}
|
|
@@ -7392,12 +7472,12 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7392
7472
|
const indexDefinitions = await database.getIndexDefinitions(
|
|
7393
7473
|
database.contentLevel
|
|
7394
7474
|
);
|
|
7395
|
-
collectionIndexDefinitions = indexDefinitions
|
|
7475
|
+
collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
7396
7476
|
if (!collectionIndexDefinitions) {
|
|
7397
7477
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
7398
7478
|
}
|
|
7399
7479
|
}
|
|
7400
|
-
const collectionReferences = (
|
|
7480
|
+
const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
|
|
7401
7481
|
const tinaSchema = await database.getSchema();
|
|
7402
7482
|
let templateInfo = null;
|
|
7403
7483
|
if (collection) {
|
|
@@ -7414,7 +7494,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7414
7494
|
if (item) {
|
|
7415
7495
|
const folderKey = folderTreeBuilder.update(
|
|
7416
7496
|
itemKey,
|
|
7417
|
-
|
|
7497
|
+
collection?.path || ""
|
|
7418
7498
|
);
|
|
7419
7499
|
const aliasedData = templateInfo ? replaceNameOverrides(
|
|
7420
7500
|
getTemplateForFile(templateInfo, item),
|
|
@@ -7423,7 +7503,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7423
7503
|
await enqueueOps([
|
|
7424
7504
|
...makeRefOpsForDocument(
|
|
7425
7505
|
itemKey,
|
|
7426
|
-
collection
|
|
7506
|
+
collection?.name,
|
|
7427
7507
|
collectionReferences,
|
|
7428
7508
|
aliasedData,
|
|
7429
7509
|
"del",
|
|
@@ -7440,7 +7520,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7440
7520
|
// folder indexes
|
|
7441
7521
|
...makeIndexOpsForDocument(
|
|
7442
7522
|
itemKey,
|
|
7443
|
-
`${collection
|
|
7523
|
+
`${collection?.name}_${folderKey}`,
|
|
7444
7524
|
collectionIndexDefinitions,
|
|
7445
7525
|
aliasedData,
|
|
7446
7526
|
"del",
|
|
@@ -7525,12 +7605,12 @@ var getChangedFiles = async ({
|
|
|
7525
7605
|
}
|
|
7526
7606
|
}
|
|
7527
7607
|
}
|
|
7528
|
-
if (await
|
|
7608
|
+
if (await B?.type() === "tree") {
|
|
7529
7609
|
return;
|
|
7530
7610
|
}
|
|
7531
7611
|
if (matches) {
|
|
7532
|
-
const oidA = await
|
|
7533
|
-
const oidB = await
|
|
7612
|
+
const oidA = await A?.oid();
|
|
7613
|
+
const oidB = await B?.oid();
|
|
7534
7614
|
if (oidA !== oidB) {
|
|
7535
7615
|
if (oidA === void 0) {
|
|
7536
7616
|
results.added.push(relativePath);
|
|
@@ -7558,8 +7638,8 @@ var import_path5 = __toESM(require("path"));
|
|
|
7558
7638
|
var import_normalize_path = __toESM(require("normalize-path"));
|
|
7559
7639
|
var FilesystemBridge = class {
|
|
7560
7640
|
constructor(rootPath, outputPath) {
|
|
7561
|
-
this.rootPath = rootPath
|
|
7562
|
-
this.outputPath = outputPath
|
|
7641
|
+
this.rootPath = import_path5.default.resolve(rootPath);
|
|
7642
|
+
this.outputPath = outputPath ? import_path5.default.resolve(outputPath) : this.rootPath;
|
|
7563
7643
|
}
|
|
7564
7644
|
async glob(pattern, extension) {
|
|
7565
7645
|
const basePath = import_path5.default.join(this.outputPath, ...pattern.split("/"));
|
|
@@ -7571,19 +7651,19 @@ var FilesystemBridge = class {
|
|
|
7571
7651
|
}
|
|
7572
7652
|
);
|
|
7573
7653
|
const posixRootPath = (0, import_normalize_path.default)(this.outputPath);
|
|
7574
|
-
return items.map(
|
|
7575
|
-
|
|
7576
|
-
|
|
7654
|
+
return items.map(
|
|
7655
|
+
(item) => item.substring(posixRootPath.length).replace(/^\/|\/$/g, "")
|
|
7656
|
+
);
|
|
7577
7657
|
}
|
|
7578
7658
|
async delete(filepath) {
|
|
7579
7659
|
await import_fs_extra2.default.remove(import_path5.default.join(this.outputPath, filepath));
|
|
7580
7660
|
}
|
|
7581
7661
|
async get(filepath) {
|
|
7582
|
-
return import_fs_extra2.default.
|
|
7662
|
+
return (await import_fs_extra2.default.readFile(import_path5.default.join(this.outputPath, filepath))).toString();
|
|
7583
7663
|
}
|
|
7584
7664
|
async put(filepath, data, basePathOverride) {
|
|
7585
7665
|
const basePath = basePathOverride || this.outputPath;
|
|
7586
|
-
await import_fs_extra2.default.
|
|
7666
|
+
await import_fs_extra2.default.outputFile(import_path5.default.join(basePath, filepath), data);
|
|
7587
7667
|
}
|
|
7588
7668
|
};
|
|
7589
7669
|
var AuditFileSystemBridge = class extends FilesystemBridge {
|