@tinacms/graphql 0.0.0-d28d795-20250427004334 → 0.0.0-d4c653b-20251027224657
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/database/bridge/filesystem.d.ts +1 -1
- package/dist/database/util.d.ts +6 -9
- package/dist/index.d.ts +32 -1
- package/dist/index.js +668 -657
- package/dist/index.mjs +554 -517
- package/dist/mdx/index.d.ts +2 -7
- package/dist/resolver/auth-fields.d.ts +31 -0
- package/dist/resolver/error.d.ts +1 -2
- package/dist/resolver/index.d.ts +5 -5
- 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
|
}
|
|
@@ -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 });
|
|
@@ -2780,7 +2777,7 @@ var Builder = class {
|
|
|
2780
2777
|
this._buildDataField = async (field) => {
|
|
2781
2778
|
const listWarningMsg = `
|
|
2782
2779
|
WARNING: The user interface for ${field.type} does not support \`list: true\`
|
|
2783
|
-
Visit https://tina.io/docs/
|
|
2780
|
+
Visit https://tina.io/docs/r/content-fields/#list-fields/ for more information
|
|
2784
2781
|
|
|
2785
2782
|
`;
|
|
2786
2783
|
switch (field.type) {
|
|
@@ -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.
|
|
3086
|
+
version: "1.6.1",
|
|
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,25 +3149,24 @@ 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",
|
|
3178
|
-
zod: "
|
|
3169
|
+
zod: "catalog:"
|
|
3179
3170
|
}
|
|
3180
3171
|
};
|
|
3181
3172
|
|
|
@@ -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
|
);
|
|
@@ -3384,251 +3374,11 @@ var import_graphql5 = require("graphql");
|
|
|
3384
3374
|
// src/resolver/index.ts
|
|
3385
3375
|
var import_path3 = __toESM(require("path"));
|
|
3386
3376
|
var import_isValid = __toESM(require("date-fns/isValid/index.js"));
|
|
3377
|
+
var import_jsonpath_plus2 = require("jsonpath-plus");
|
|
3387
3378
|
|
|
3388
3379
|
// src/mdx/index.ts
|
|
3389
3380
|
var import_mdx = require("@tinacms/mdx");
|
|
3390
3381
|
|
|
3391
|
-
// src/resolver/index.ts
|
|
3392
|
-
var import_jsonpath_plus2 = require("jsonpath-plus");
|
|
3393
|
-
|
|
3394
|
-
// src/resolver/error.ts
|
|
3395
|
-
var TinaGraphQLError = class extends Error {
|
|
3396
|
-
constructor(message, extensions) {
|
|
3397
|
-
super(message);
|
|
3398
|
-
if (!this.name) {
|
|
3399
|
-
Object.defineProperty(this, "name", { value: "TinaGraphQLError" });
|
|
3400
|
-
}
|
|
3401
|
-
this.extensions = { ...extensions };
|
|
3402
|
-
}
|
|
3403
|
-
};
|
|
3404
|
-
var TinaFetchError = class extends Error {
|
|
3405
|
-
constructor(message, args) {
|
|
3406
|
-
super(message);
|
|
3407
|
-
this.name = "TinaFetchError";
|
|
3408
|
-
this.collection = args.collection;
|
|
3409
|
-
this.stack = args.stack;
|
|
3410
|
-
this.file = args.file;
|
|
3411
|
-
this.originalError = args.originalError;
|
|
3412
|
-
}
|
|
3413
|
-
};
|
|
3414
|
-
var TinaQueryError = class extends TinaFetchError {
|
|
3415
|
-
constructor(args) {
|
|
3416
|
-
super(
|
|
3417
|
-
`Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
3418
|
-
args
|
|
3419
|
-
);
|
|
3420
|
-
}
|
|
3421
|
-
};
|
|
3422
|
-
var TinaParseDocumentError = class extends TinaFetchError {
|
|
3423
|
-
constructor(args) {
|
|
3424
|
-
super(
|
|
3425
|
-
`Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
3426
|
-
args
|
|
3427
|
-
);
|
|
3428
|
-
}
|
|
3429
|
-
toString() {
|
|
3430
|
-
return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
|
|
3431
|
-
}
|
|
3432
|
-
};
|
|
3433
|
-
var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
|
|
3434
|
-
var handleFetchErrorError = (e, verbose) => {
|
|
3435
|
-
if (e instanceof Error) {
|
|
3436
|
-
if (e instanceof TinaFetchError) {
|
|
3437
|
-
if (verbose) {
|
|
3438
|
-
console.log(e.toString());
|
|
3439
|
-
console.log(e);
|
|
3440
|
-
console.log(e.stack);
|
|
3441
|
-
}
|
|
3442
|
-
}
|
|
3443
|
-
} else {
|
|
3444
|
-
console.error(e);
|
|
3445
|
-
}
|
|
3446
|
-
throw e;
|
|
3447
|
-
};
|
|
3448
|
-
|
|
3449
|
-
// src/resolver/filter-utils.ts
|
|
3450
|
-
var resolveReferences = async (filter, fields, resolver) => {
|
|
3451
|
-
for (const fieldKey of Object.keys(filter)) {
|
|
3452
|
-
const fieldDefinition = fields.find(
|
|
3453
|
-
(f) => f.name === fieldKey
|
|
3454
|
-
);
|
|
3455
|
-
if (fieldDefinition) {
|
|
3456
|
-
if (fieldDefinition.type === "reference") {
|
|
3457
|
-
const { edges, values } = await resolver(filter, fieldDefinition);
|
|
3458
|
-
if (edges.length === 1) {
|
|
3459
|
-
filter[fieldKey] = {
|
|
3460
|
-
eq: values[0]
|
|
3461
|
-
};
|
|
3462
|
-
} else if (edges.length > 1) {
|
|
3463
|
-
filter[fieldKey] = {
|
|
3464
|
-
in: values
|
|
3465
|
-
};
|
|
3466
|
-
} else {
|
|
3467
|
-
filter[fieldKey] = {
|
|
3468
|
-
eq: "___null___"
|
|
3469
|
-
};
|
|
3470
|
-
}
|
|
3471
|
-
} else if (fieldDefinition.type === "object") {
|
|
3472
|
-
if (fieldDefinition.templates) {
|
|
3473
|
-
for (const templateName of Object.keys(filter[fieldKey])) {
|
|
3474
|
-
const template = fieldDefinition.templates.find(
|
|
3475
|
-
(template2) => !(typeof template2 === "string") && template2.name === templateName
|
|
3476
|
-
);
|
|
3477
|
-
if (template) {
|
|
3478
|
-
await resolveReferences(
|
|
3479
|
-
filter[fieldKey][templateName],
|
|
3480
|
-
template.fields,
|
|
3481
|
-
resolver
|
|
3482
|
-
);
|
|
3483
|
-
} else {
|
|
3484
|
-
throw new Error(`Template ${templateName} not found`);
|
|
3485
|
-
}
|
|
3486
|
-
}
|
|
3487
|
-
} else {
|
|
3488
|
-
await resolveReferences(
|
|
3489
|
-
filter[fieldKey],
|
|
3490
|
-
fieldDefinition.fields,
|
|
3491
|
-
resolver
|
|
3492
|
-
);
|
|
3493
|
-
}
|
|
3494
|
-
}
|
|
3495
|
-
} else {
|
|
3496
|
-
throw new Error(`Unable to find field ${fieldKey}`);
|
|
3497
|
-
}
|
|
3498
|
-
}
|
|
3499
|
-
};
|
|
3500
|
-
var collectConditionsForChildFields = (filterNode, fields, pathExpression, collectCondition) => {
|
|
3501
|
-
for (const childFieldName of Object.keys(filterNode)) {
|
|
3502
|
-
const childField = fields.find((field) => field.name === childFieldName);
|
|
3503
|
-
if (!childField) {
|
|
3504
|
-
throw new Error(`Unable to find type for field ${childFieldName}`);
|
|
3505
|
-
}
|
|
3506
|
-
collectConditionsForField(
|
|
3507
|
-
childFieldName,
|
|
3508
|
-
childField,
|
|
3509
|
-
filterNode[childFieldName],
|
|
3510
|
-
pathExpression,
|
|
3511
|
-
collectCondition
|
|
3512
|
-
);
|
|
3513
|
-
}
|
|
3514
|
-
};
|
|
3515
|
-
var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
3516
|
-
if (field.list && field.templates) {
|
|
3517
|
-
for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
|
|
3518
|
-
const template = field.templates.find(
|
|
3519
|
-
(template2) => !(typeof template2 === "string") && template2.name === filterKey
|
|
3520
|
-
);
|
|
3521
|
-
const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
|
|
3522
|
-
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
|
|
3523
|
-
collectConditionsForChildFields(
|
|
3524
|
-
childFilterNode,
|
|
3525
|
-
template.fields,
|
|
3526
|
-
filterPath,
|
|
3527
|
-
collectCondition
|
|
3528
|
-
);
|
|
3529
|
-
}
|
|
3530
|
-
} else {
|
|
3531
|
-
const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
|
|
3532
|
-
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
|
|
3533
|
-
collectConditionsForChildFields(
|
|
3534
|
-
filterNode,
|
|
3535
|
-
field.fields,
|
|
3536
|
-
filterPath,
|
|
3537
|
-
collectCondition
|
|
3538
|
-
);
|
|
3539
|
-
}
|
|
3540
|
-
};
|
|
3541
|
-
var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
3542
|
-
if (field.type === "object") {
|
|
3543
|
-
collectConditionsForObjectField(
|
|
3544
|
-
fieldName,
|
|
3545
|
-
field,
|
|
3546
|
-
filterNode,
|
|
3547
|
-
pathExpression,
|
|
3548
|
-
collectCondition
|
|
3549
|
-
);
|
|
3550
|
-
} else {
|
|
3551
|
-
collectCondition({
|
|
3552
|
-
filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
|
|
3553
|
-
filterExpression: {
|
|
3554
|
-
_type: field.type,
|
|
3555
|
-
_list: !!field.list,
|
|
3556
|
-
...filterNode
|
|
3557
|
-
}
|
|
3558
|
-
});
|
|
3559
|
-
}
|
|
3560
|
-
};
|
|
3561
|
-
|
|
3562
|
-
// src/resolver/media-utils.ts
|
|
3563
|
-
var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, schema) => {
|
|
3564
|
-
if (config && value) {
|
|
3565
|
-
if (config.useRelativeMedia === true) {
|
|
3566
|
-
return value;
|
|
3567
|
-
}
|
|
3568
|
-
if (hasTinaMediaConfig(schema) === true) {
|
|
3569
|
-
const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
|
|
3570
|
-
if (typeof value === "string" && value.includes(assetsURL)) {
|
|
3571
|
-
const cleanMediaRoot = cleanUpSlashes(
|
|
3572
|
-
schema.config.media.tina.mediaRoot
|
|
3573
|
-
);
|
|
3574
|
-
const strippedURL = value.replace(assetsURL, "");
|
|
3575
|
-
return `${cleanMediaRoot}${strippedURL}`;
|
|
3576
|
-
}
|
|
3577
|
-
if (Array.isArray(value)) {
|
|
3578
|
-
return value.map((v) => {
|
|
3579
|
-
if (!v || typeof v !== "string") return v;
|
|
3580
|
-
const cleanMediaRoot = cleanUpSlashes(
|
|
3581
|
-
schema.config.media.tina.mediaRoot
|
|
3582
|
-
);
|
|
3583
|
-
const strippedURL = v.replace(assetsURL, "");
|
|
3584
|
-
return `${cleanMediaRoot}${strippedURL}`;
|
|
3585
|
-
});
|
|
3586
|
-
}
|
|
3587
|
-
return value;
|
|
3588
|
-
}
|
|
3589
|
-
return value;
|
|
3590
|
-
} else {
|
|
3591
|
-
return value;
|
|
3592
|
-
}
|
|
3593
|
-
};
|
|
3594
|
-
var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, schema) => {
|
|
3595
|
-
if (config && value) {
|
|
3596
|
-
if (config.useRelativeMedia === true) {
|
|
3597
|
-
return value;
|
|
3598
|
-
}
|
|
3599
|
-
if (hasTinaMediaConfig(schema) === true) {
|
|
3600
|
-
const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
|
|
3601
|
-
if (typeof value === "string") {
|
|
3602
|
-
const strippedValue = value.replace(cleanMediaRoot, "");
|
|
3603
|
-
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
3604
|
-
}
|
|
3605
|
-
if (Array.isArray(value)) {
|
|
3606
|
-
return value.map((v) => {
|
|
3607
|
-
if (!v || typeof v !== "string") return v;
|
|
3608
|
-
const strippedValue = v.replace(cleanMediaRoot, "");
|
|
3609
|
-
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
3610
|
-
});
|
|
3611
|
-
}
|
|
3612
|
-
}
|
|
3613
|
-
return value;
|
|
3614
|
-
} else {
|
|
3615
|
-
return value;
|
|
3616
|
-
}
|
|
3617
|
-
};
|
|
3618
|
-
var cleanUpSlashes = (path7) => {
|
|
3619
|
-
if (path7) {
|
|
3620
|
-
return `/${path7.replace(/^\/+|\/+$/gm, "")}`;
|
|
3621
|
-
}
|
|
3622
|
-
return "";
|
|
3623
|
-
};
|
|
3624
|
-
var hasTinaMediaConfig = (schema) => {
|
|
3625
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3626
|
-
if (!((_b = (_a = schema.config) == null ? void 0 : _a.media) == null ? void 0 : _b.tina)) return false;
|
|
3627
|
-
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")
|
|
3628
|
-
return false;
|
|
3629
|
-
return true;
|
|
3630
|
-
};
|
|
3631
|
-
|
|
3632
3382
|
// src/resolver/index.ts
|
|
3633
3383
|
var import_graphql3 = require("graphql");
|
|
3634
3384
|
|
|
@@ -3690,11 +3440,11 @@ var import_path2 = __toESM(require("path"));
|
|
|
3690
3440
|
|
|
3691
3441
|
// src/database/util.ts
|
|
3692
3442
|
var import_toml = __toESM(require("@iarna/toml"));
|
|
3693
|
-
var import_js_yaml = __toESM(require("js-yaml"));
|
|
3694
|
-
var import_gray_matter = __toESM(require("gray-matter"));
|
|
3695
3443
|
var import_schema_tools4 = require("@tinacms/schema-tools");
|
|
3696
|
-
var
|
|
3444
|
+
var import_gray_matter = __toESM(require("gray-matter"));
|
|
3445
|
+
var import_js_yaml = __toESM(require("js-yaml"));
|
|
3697
3446
|
var import_path = __toESM(require("path"));
|
|
3447
|
+
var import_micromatch = __toESM(require("micromatch"));
|
|
3698
3448
|
|
|
3699
3449
|
// src/database/alias-utils.ts
|
|
3700
3450
|
var replaceBlockAliases = (template, item) => {
|
|
@@ -3731,22 +3481,20 @@ var replaceNameOverrides = (template, obj) => {
|
|
|
3731
3481
|
}
|
|
3732
3482
|
};
|
|
3733
3483
|
function isBlockField(field) {
|
|
3734
|
-
|
|
3735
|
-
return field && field.type === "object" && ((_a = field.templates) == null ? void 0 : _a.length) > 0;
|
|
3484
|
+
return field && field.type === "object" && field.templates?.length > 0;
|
|
3736
3485
|
}
|
|
3737
3486
|
var _replaceNameOverrides = (fields, obj) => {
|
|
3738
3487
|
const output = {};
|
|
3739
3488
|
Object.keys(obj).forEach((key) => {
|
|
3740
3489
|
const field = fields.find(
|
|
3741
|
-
(fieldWithMatchingAlias) => (
|
|
3490
|
+
(fieldWithMatchingAlias) => (fieldWithMatchingAlias?.nameOverride || fieldWithMatchingAlias?.name) === key
|
|
3742
3491
|
);
|
|
3743
|
-
output[
|
|
3492
|
+
output[field?.name || key] = field?.type == "object" ? replaceNameOverrides(field, obj[key]) : obj[key];
|
|
3744
3493
|
});
|
|
3745
3494
|
return output;
|
|
3746
3495
|
};
|
|
3747
3496
|
var getTemplateForData = (field, data) => {
|
|
3748
|
-
|
|
3749
|
-
if ((_a = field.templates) == null ? void 0 : _a.length) {
|
|
3497
|
+
if (field.templates?.length) {
|
|
3750
3498
|
const templateKey = "_template";
|
|
3751
3499
|
if (data[templateKey]) {
|
|
3752
3500
|
const result = field.templates.find(
|
|
@@ -3804,8 +3552,8 @@ var _applyNameOverrides = (fields, obj) => {
|
|
|
3804
3552
|
const output = {};
|
|
3805
3553
|
Object.keys(obj).forEach((key) => {
|
|
3806
3554
|
const field = fields.find((field2) => field2.name === key);
|
|
3807
|
-
const outputKey =
|
|
3808
|
-
output[outputKey] =
|
|
3555
|
+
const outputKey = field?.nameOverride || key;
|
|
3556
|
+
output[outputKey] = field?.type === "object" ? applyNameOverrides(field, obj[key]) : obj[key];
|
|
3809
3557
|
});
|
|
3810
3558
|
return output;
|
|
3811
3559
|
};
|
|
@@ -3818,7 +3566,6 @@ var matterEngines = {
|
|
|
3818
3566
|
}
|
|
3819
3567
|
};
|
|
3820
3568
|
var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
|
|
3821
|
-
var _a, _b;
|
|
3822
3569
|
const {
|
|
3823
3570
|
_relativePath,
|
|
3824
3571
|
_keepTemplateKey,
|
|
@@ -3842,9 +3589,9 @@ var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
|
|
|
3842
3589
|
${$_body}`,
|
|
3843
3590
|
strippedContent,
|
|
3844
3591
|
{
|
|
3845
|
-
language:
|
|
3592
|
+
language: markdownParseConfig?.frontmatterFormat ?? "yaml",
|
|
3846
3593
|
engines: matterEngines,
|
|
3847
|
-
delimiters:
|
|
3594
|
+
delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---"
|
|
3848
3595
|
}
|
|
3849
3596
|
);
|
|
3850
3597
|
return ok;
|
|
@@ -3860,15 +3607,14 @@ ${$_body}`,
|
|
|
3860
3607
|
}
|
|
3861
3608
|
};
|
|
3862
3609
|
var parseFile = (content, format, yupSchema, markdownParseConfig) => {
|
|
3863
|
-
var _a, _b;
|
|
3864
3610
|
try {
|
|
3865
3611
|
switch (format) {
|
|
3866
3612
|
case ".markdown":
|
|
3867
3613
|
case ".mdx":
|
|
3868
3614
|
case ".md":
|
|
3869
3615
|
const contentJSON = (0, import_gray_matter.default)(content || "", {
|
|
3870
|
-
language:
|
|
3871
|
-
delimiters:
|
|
3616
|
+
language: markdownParseConfig?.frontmatterFormat ?? "yaml",
|
|
3617
|
+
delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---",
|
|
3872
3618
|
engines: matterEngines
|
|
3873
3619
|
});
|
|
3874
3620
|
const markdownData = {
|
|
@@ -3967,7 +3713,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
|
|
|
3967
3713
|
),
|
|
3968
3714
|
template: void 0
|
|
3969
3715
|
} : tinaSchema.getCollectionAndTemplateByFullPath(filepath, templateName);
|
|
3970
|
-
const field = template
|
|
3716
|
+
const field = template?.fields.find((field2) => {
|
|
3971
3717
|
if (field2.type === "string" || field2.type === "rich-text") {
|
|
3972
3718
|
if (field2.isBody) {
|
|
3973
3719
|
return true;
|
|
@@ -3987,7 +3733,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
|
|
|
3987
3733
|
...data,
|
|
3988
3734
|
_collection: collection.name,
|
|
3989
3735
|
_keepTemplateKey: !!collection.templates,
|
|
3990
|
-
_template:
|
|
3736
|
+
_template: template?.namespace ? lastItem(template?.namespace) : void 0,
|
|
3991
3737
|
_relativePath: filepath.replace(collection.path, "").replace(/^\/|\/$/g, ""),
|
|
3992
3738
|
_id: filepath
|
|
3993
3739
|
};
|
|
@@ -3996,10 +3742,10 @@ function hasOwnProperty(obj, prop) {
|
|
|
3996
3742
|
return obj.hasOwnProperty(prop);
|
|
3997
3743
|
}
|
|
3998
3744
|
var getTemplateForFile = (templateInfo, data) => {
|
|
3999
|
-
if (
|
|
3745
|
+
if (templateInfo?.type === "object") {
|
|
4000
3746
|
return templateInfo.template;
|
|
4001
3747
|
}
|
|
4002
|
-
if (
|
|
3748
|
+
if (templateInfo?.type === "union") {
|
|
4003
3749
|
if (hasOwnProperty(data, "_template")) {
|
|
4004
3750
|
const template = templateInfo.templates.find(
|
|
4005
3751
|
(t) => lastItem(t.namespace) === data._template
|
|
@@ -4023,8 +3769,8 @@ var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo)
|
|
|
4023
3769
|
import_path.default.extname(filepath),
|
|
4024
3770
|
(yup3) => yup3.object({}),
|
|
4025
3771
|
{
|
|
4026
|
-
frontmatterDelimiters: collection
|
|
4027
|
-
frontmatterFormat: collection
|
|
3772
|
+
frontmatterDelimiters: collection?.frontmatterDelimiters,
|
|
3773
|
+
frontmatterFormat: collection?.frontmatterFormat
|
|
4028
3774
|
}
|
|
4029
3775
|
);
|
|
4030
3776
|
const template = getTemplateForFile(templateInfo, data);
|
|
@@ -4611,87 +4357,322 @@ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opT
|
|
|
4611
4357
|
});
|
|
4612
4358
|
}
|
|
4613
4359
|
}
|
|
4614
|
-
}
|
|
4360
|
+
}
|
|
4361
|
+
}
|
|
4362
|
+
return result;
|
|
4363
|
+
};
|
|
4364
|
+
var makeRefOpsForDocument = (filepath, collection, references, data, opType, level) => {
|
|
4365
|
+
const result = [];
|
|
4366
|
+
if (collection) {
|
|
4367
|
+
for (const [c, referencePaths] of Object.entries(references || {})) {
|
|
4368
|
+
if (!referencePaths.length) {
|
|
4369
|
+
continue;
|
|
4370
|
+
}
|
|
4371
|
+
const collectionSublevel = level.sublevel(c, SUBLEVEL_OPTIONS);
|
|
4372
|
+
const refSublevel = collectionSublevel.sublevel(
|
|
4373
|
+
REFS_COLLECTIONS_SORT_KEY,
|
|
4374
|
+
SUBLEVEL_OPTIONS
|
|
4375
|
+
);
|
|
4376
|
+
const references2 = {};
|
|
4377
|
+
for (const path7 of referencePaths) {
|
|
4378
|
+
const ref = (0, import_jsonpath_plus.JSONPath)({ path: path7, json: data });
|
|
4379
|
+
if (!ref) {
|
|
4380
|
+
continue;
|
|
4381
|
+
}
|
|
4382
|
+
if (Array.isArray(ref)) {
|
|
4383
|
+
for (const r of ref) {
|
|
4384
|
+
if (!r) {
|
|
4385
|
+
continue;
|
|
4386
|
+
}
|
|
4387
|
+
if (references2[r]) {
|
|
4388
|
+
references2[r].push(path7);
|
|
4389
|
+
} else {
|
|
4390
|
+
references2[r] = [path7];
|
|
4391
|
+
}
|
|
4392
|
+
}
|
|
4393
|
+
} else {
|
|
4394
|
+
if (references2[ref]) {
|
|
4395
|
+
references2[ref].push(path7);
|
|
4396
|
+
} else {
|
|
4397
|
+
references2[ref] = [path7];
|
|
4398
|
+
}
|
|
4399
|
+
}
|
|
4400
|
+
}
|
|
4401
|
+
for (const ref of Object.keys(references2)) {
|
|
4402
|
+
for (const path7 of references2[ref]) {
|
|
4403
|
+
result.push({
|
|
4404
|
+
type: opType,
|
|
4405
|
+
key: `${ref}${INDEX_KEY_FIELD_SEPARATOR}${path7}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
|
|
4406
|
+
sublevel: refSublevel,
|
|
4407
|
+
value: opType === "put" ? {} : void 0
|
|
4408
|
+
});
|
|
4409
|
+
}
|
|
4410
|
+
}
|
|
4411
|
+
}
|
|
4412
|
+
}
|
|
4413
|
+
return result;
|
|
4414
|
+
};
|
|
4415
|
+
var makeStringEscaper = (regex, replacement) => {
|
|
4416
|
+
return (input) => {
|
|
4417
|
+
if (Array.isArray(input)) {
|
|
4418
|
+
return input.map(
|
|
4419
|
+
(val) => val.replace(regex, replacement)
|
|
4420
|
+
);
|
|
4421
|
+
} else {
|
|
4422
|
+
if (typeof input === "string") {
|
|
4423
|
+
return input.replace(regex, replacement);
|
|
4424
|
+
} else {
|
|
4425
|
+
return input;
|
|
4426
|
+
}
|
|
4427
|
+
}
|
|
4428
|
+
};
|
|
4429
|
+
};
|
|
4430
|
+
var stringEscaper = makeStringEscaper(
|
|
4431
|
+
new RegExp(INDEX_KEY_FIELD_SEPARATOR, "gm"),
|
|
4432
|
+
encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR)
|
|
4433
|
+
);
|
|
4434
|
+
|
|
4435
|
+
// src/resolver/error.ts
|
|
4436
|
+
var TinaGraphQLError = class extends Error {
|
|
4437
|
+
constructor(message, extensions) {
|
|
4438
|
+
super(message);
|
|
4439
|
+
if (!this.name) {
|
|
4440
|
+
Object.defineProperty(this, "name", { value: "TinaGraphQLError" });
|
|
4441
|
+
}
|
|
4442
|
+
this.extensions = { ...extensions };
|
|
4443
|
+
}
|
|
4444
|
+
};
|
|
4445
|
+
var TinaFetchError = class extends Error {
|
|
4446
|
+
constructor(message, args) {
|
|
4447
|
+
super(message);
|
|
4448
|
+
this.name = "TinaFetchError";
|
|
4449
|
+
this.collection = args.collection;
|
|
4450
|
+
this.file = args.file;
|
|
4451
|
+
this.originalError = args.originalError;
|
|
4452
|
+
}
|
|
4453
|
+
};
|
|
4454
|
+
var TinaQueryError = class extends TinaFetchError {
|
|
4455
|
+
constructor(args) {
|
|
4456
|
+
super(
|
|
4457
|
+
`Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
4458
|
+
args
|
|
4459
|
+
);
|
|
4460
|
+
}
|
|
4461
|
+
};
|
|
4462
|
+
var TinaParseDocumentError = class extends TinaFetchError {
|
|
4463
|
+
constructor(args) {
|
|
4464
|
+
super(
|
|
4465
|
+
`Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
4466
|
+
args
|
|
4467
|
+
);
|
|
4468
|
+
}
|
|
4469
|
+
toString() {
|
|
4470
|
+
return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
|
|
4471
|
+
}
|
|
4472
|
+
};
|
|
4473
|
+
var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
|
|
4474
|
+
var handleFetchErrorError = (e, verbose) => {
|
|
4475
|
+
if (e instanceof Error) {
|
|
4476
|
+
if (e instanceof TinaFetchError) {
|
|
4477
|
+
if (verbose) {
|
|
4478
|
+
console.log(e.toString());
|
|
4479
|
+
console.log(e);
|
|
4480
|
+
console.log(e.stack);
|
|
4481
|
+
}
|
|
4482
|
+
}
|
|
4483
|
+
} else {
|
|
4484
|
+
console.error(e);
|
|
4485
|
+
}
|
|
4486
|
+
throw e;
|
|
4487
|
+
};
|
|
4488
|
+
|
|
4489
|
+
// src/resolver/filter-utils.ts
|
|
4490
|
+
var resolveReferences = async (filter, fields, resolver) => {
|
|
4491
|
+
for (const fieldKey of Object.keys(filter)) {
|
|
4492
|
+
const fieldDefinition = fields.find(
|
|
4493
|
+
(f) => f.name === fieldKey
|
|
4494
|
+
);
|
|
4495
|
+
if (fieldDefinition) {
|
|
4496
|
+
if (fieldDefinition.type === "reference") {
|
|
4497
|
+
const { edges, values } = await resolver(filter, fieldDefinition);
|
|
4498
|
+
if (edges.length === 1) {
|
|
4499
|
+
filter[fieldKey] = {
|
|
4500
|
+
eq: values[0]
|
|
4501
|
+
};
|
|
4502
|
+
} else if (edges.length > 1) {
|
|
4503
|
+
filter[fieldKey] = {
|
|
4504
|
+
in: values
|
|
4505
|
+
};
|
|
4506
|
+
} else {
|
|
4507
|
+
filter[fieldKey] = {
|
|
4508
|
+
eq: "___null___"
|
|
4509
|
+
};
|
|
4510
|
+
}
|
|
4511
|
+
} else if (fieldDefinition.type === "object") {
|
|
4512
|
+
if (fieldDefinition.templates) {
|
|
4513
|
+
for (const templateName of Object.keys(filter[fieldKey])) {
|
|
4514
|
+
const template = fieldDefinition.templates.find(
|
|
4515
|
+
(template2) => !(typeof template2 === "string") && template2.name === templateName
|
|
4516
|
+
);
|
|
4517
|
+
if (template) {
|
|
4518
|
+
await resolveReferences(
|
|
4519
|
+
filter[fieldKey][templateName],
|
|
4520
|
+
template.fields,
|
|
4521
|
+
resolver
|
|
4522
|
+
);
|
|
4523
|
+
} else {
|
|
4524
|
+
throw new Error(`Template ${templateName} not found`);
|
|
4525
|
+
}
|
|
4526
|
+
}
|
|
4527
|
+
} else {
|
|
4528
|
+
await resolveReferences(
|
|
4529
|
+
filter[fieldKey],
|
|
4530
|
+
fieldDefinition.fields,
|
|
4531
|
+
resolver
|
|
4532
|
+
);
|
|
4533
|
+
}
|
|
4534
|
+
}
|
|
4535
|
+
} else {
|
|
4536
|
+
throw new Error(`Unable to find field ${fieldKey}`);
|
|
4537
|
+
}
|
|
4538
|
+
}
|
|
4539
|
+
};
|
|
4540
|
+
var collectConditionsForChildFields = (filterNode, fields, pathExpression, collectCondition) => {
|
|
4541
|
+
for (const childFieldName of Object.keys(filterNode)) {
|
|
4542
|
+
const childField = fields.find((field) => field.name === childFieldName);
|
|
4543
|
+
if (!childField) {
|
|
4544
|
+
throw new Error(`Unable to find type for field ${childFieldName}`);
|
|
4545
|
+
}
|
|
4546
|
+
collectConditionsForField(
|
|
4547
|
+
childFieldName,
|
|
4548
|
+
childField,
|
|
4549
|
+
filterNode[childFieldName],
|
|
4550
|
+
pathExpression,
|
|
4551
|
+
collectCondition
|
|
4552
|
+
);
|
|
4553
|
+
}
|
|
4554
|
+
};
|
|
4555
|
+
var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
4556
|
+
if (field.list && field.templates) {
|
|
4557
|
+
for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
|
|
4558
|
+
const template = field.templates.find(
|
|
4559
|
+
(template2) => !(typeof template2 === "string") && template2.name === filterKey
|
|
4560
|
+
);
|
|
4561
|
+
const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
|
|
4562
|
+
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
|
|
4563
|
+
collectConditionsForChildFields(
|
|
4564
|
+
childFilterNode,
|
|
4565
|
+
template.fields,
|
|
4566
|
+
filterPath,
|
|
4567
|
+
collectCondition
|
|
4568
|
+
);
|
|
4569
|
+
}
|
|
4570
|
+
} else {
|
|
4571
|
+
const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
|
|
4572
|
+
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
|
|
4573
|
+
collectConditionsForChildFields(
|
|
4574
|
+
filterNode,
|
|
4575
|
+
field.fields,
|
|
4576
|
+
filterPath,
|
|
4577
|
+
collectCondition
|
|
4578
|
+
);
|
|
4579
|
+
}
|
|
4580
|
+
};
|
|
4581
|
+
var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
4582
|
+
if (field.type === "object") {
|
|
4583
|
+
collectConditionsForObjectField(
|
|
4584
|
+
fieldName,
|
|
4585
|
+
field,
|
|
4586
|
+
filterNode,
|
|
4587
|
+
pathExpression,
|
|
4588
|
+
collectCondition
|
|
4589
|
+
);
|
|
4590
|
+
} else {
|
|
4591
|
+
collectCondition({
|
|
4592
|
+
filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
|
|
4593
|
+
filterExpression: {
|
|
4594
|
+
_type: field.type,
|
|
4595
|
+
_list: !!field.list,
|
|
4596
|
+
...filterNode
|
|
4597
|
+
}
|
|
4598
|
+
});
|
|
4615
4599
|
}
|
|
4616
|
-
return result;
|
|
4617
4600
|
};
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
const
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
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
|
-
}
|
|
4601
|
+
|
|
4602
|
+
// src/resolver/media-utils.ts
|
|
4603
|
+
var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, schema) => {
|
|
4604
|
+
if (config && value) {
|
|
4605
|
+
if (config.useRelativeMedia === true) {
|
|
4606
|
+
return value;
|
|
4607
|
+
}
|
|
4608
|
+
if (hasTinaMediaConfig(schema) === true) {
|
|
4609
|
+
const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
|
|
4610
|
+
if (typeof value === "string" && value.includes(assetsURL)) {
|
|
4611
|
+
const cleanMediaRoot = cleanUpSlashes(
|
|
4612
|
+
schema.config.media.tina.mediaRoot
|
|
4613
|
+
);
|
|
4614
|
+
const strippedURL = value.replace(assetsURL, "");
|
|
4615
|
+
return `${cleanMediaRoot}${strippedURL}`;
|
|
4654
4616
|
}
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
}
|
|
4663
|
-
}
|
|
4617
|
+
if (Array.isArray(value)) {
|
|
4618
|
+
return value.map((v) => {
|
|
4619
|
+
if (!v || typeof v !== "string") return v;
|
|
4620
|
+
const cleanMediaRoot = cleanUpSlashes(
|
|
4621
|
+
schema.config.media.tina.mediaRoot
|
|
4622
|
+
);
|
|
4623
|
+
const strippedURL = v.replace(assetsURL, "");
|
|
4624
|
+
return `${cleanMediaRoot}${strippedURL}`;
|
|
4625
|
+
});
|
|
4664
4626
|
}
|
|
4627
|
+
return value;
|
|
4665
4628
|
}
|
|
4629
|
+
return value;
|
|
4630
|
+
} else {
|
|
4631
|
+
return value;
|
|
4666
4632
|
}
|
|
4667
|
-
return result;
|
|
4668
4633
|
};
|
|
4669
|
-
var
|
|
4670
|
-
|
|
4671
|
-
if (
|
|
4672
|
-
return
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
if (typeof
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4634
|
+
var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, schema) => {
|
|
4635
|
+
if (config && value) {
|
|
4636
|
+
if (config.useRelativeMedia === true) {
|
|
4637
|
+
return value;
|
|
4638
|
+
}
|
|
4639
|
+
if (hasTinaMediaConfig(schema) === true) {
|
|
4640
|
+
const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
|
|
4641
|
+
if (typeof value === "string") {
|
|
4642
|
+
const strippedValue = value.replace(cleanMediaRoot, "");
|
|
4643
|
+
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
4644
|
+
}
|
|
4645
|
+
if (Array.isArray(value)) {
|
|
4646
|
+
return value.map((v) => {
|
|
4647
|
+
if (!v || typeof v !== "string") return v;
|
|
4648
|
+
const strippedValue = v.replace(cleanMediaRoot, "");
|
|
4649
|
+
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
4650
|
+
});
|
|
4680
4651
|
}
|
|
4681
4652
|
}
|
|
4682
|
-
|
|
4653
|
+
return value;
|
|
4654
|
+
} else {
|
|
4655
|
+
return value;
|
|
4656
|
+
}
|
|
4657
|
+
};
|
|
4658
|
+
var cleanUpSlashes = (path7) => {
|
|
4659
|
+
if (path7) {
|
|
4660
|
+
return `/${path7.replace(/^\/+|\/+$/gm, "")}`;
|
|
4661
|
+
}
|
|
4662
|
+
return "";
|
|
4663
|
+
};
|
|
4664
|
+
var hasTinaMediaConfig = (schema) => {
|
|
4665
|
+
if (!schema.config?.media?.tina) return false;
|
|
4666
|
+
if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
|
|
4667
|
+
return false;
|
|
4668
|
+
return true;
|
|
4683
4669
|
};
|
|
4684
|
-
var stringEscaper = makeStringEscaper(
|
|
4685
|
-
new RegExp(INDEX_KEY_FIELD_SEPARATOR, "gm"),
|
|
4686
|
-
encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR)
|
|
4687
|
-
);
|
|
4688
4670
|
|
|
4689
4671
|
// src/resolver/index.ts
|
|
4690
4672
|
var createResolver = (args) => {
|
|
4691
4673
|
return new Resolver(args);
|
|
4692
4674
|
};
|
|
4693
4675
|
var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
|
|
4694
|
-
var _a, _b;
|
|
4695
4676
|
if (!rawData) {
|
|
4696
4677
|
return void 0;
|
|
4697
4678
|
}
|
|
@@ -4719,7 +4700,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
|
|
|
4719
4700
|
accumulator[field.name] = {
|
|
4720
4701
|
value: void 0,
|
|
4721
4702
|
// never resolve the password hash
|
|
4722
|
-
passwordChangeRequired:
|
|
4703
|
+
passwordChangeRequired: value["passwordChangeRequired"] ?? false
|
|
4723
4704
|
};
|
|
4724
4705
|
break;
|
|
4725
4706
|
case "image":
|
|
@@ -4735,11 +4716,11 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
|
|
|
4735
4716
|
field,
|
|
4736
4717
|
(value2) => resolveMediaRelativeToCloud(value2, config, tinaSchema.schema)
|
|
4737
4718
|
);
|
|
4738
|
-
if (
|
|
4719
|
+
if (tree?.children[0]?.type === "invalid_markdown") {
|
|
4739
4720
|
if (isAudit) {
|
|
4740
|
-
const invalidNode = tree
|
|
4721
|
+
const invalidNode = tree?.children[0];
|
|
4741
4722
|
throw new import_graphql3.GraphQLError(
|
|
4742
|
-
`${invalidNode
|
|
4723
|
+
`${invalidNode?.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`
|
|
4743
4724
|
);
|
|
4744
4725
|
}
|
|
4745
4726
|
}
|
|
@@ -4847,16 +4828,15 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
|
|
|
4847
4828
|
originalError: e,
|
|
4848
4829
|
collection: collection.name,
|
|
4849
4830
|
includeAuditMessage: !isAudit,
|
|
4850
|
-
file: relativePath
|
|
4851
|
-
stack: e.stack
|
|
4831
|
+
file: relativePath
|
|
4852
4832
|
});
|
|
4853
4833
|
}
|
|
4854
4834
|
const titleField = template.fields.find((x) => {
|
|
4855
|
-
if (x.type === "string" &&
|
|
4835
|
+
if (x.type === "string" && x?.isTitle) {
|
|
4856
4836
|
return true;
|
|
4857
4837
|
}
|
|
4858
4838
|
});
|
|
4859
|
-
const titleFieldName = titleField
|
|
4839
|
+
const titleFieldName = titleField?.name;
|
|
4860
4840
|
const title = data[titleFieldName || " "] || null;
|
|
4861
4841
|
return {
|
|
4862
4842
|
__typename: collection.fields ? NAMER.documentTypeName(collection.namespace) : NAMER.documentTypeName(template.namespace),
|
|
@@ -4966,7 +4946,7 @@ var Resolver = class {
|
|
|
4966
4946
|
);
|
|
4967
4947
|
}
|
|
4968
4948
|
const rawData = await this.getRaw(fullPath);
|
|
4969
|
-
const hasReferences =
|
|
4949
|
+
const hasReferences = opts?.checkReferences ? await this.hasReferences(fullPath, opts.collection) : void 0;
|
|
4970
4950
|
return transformDocumentIntoPayload(
|
|
4971
4951
|
fullPath,
|
|
4972
4952
|
rawData,
|
|
@@ -5006,9 +4986,9 @@ var Resolver = class {
|
|
|
5006
4986
|
return this.buildFieldMutations(
|
|
5007
4987
|
item,
|
|
5008
4988
|
objectTemplate,
|
|
5009
|
-
idField && existingData &&
|
|
4989
|
+
idField && existingData && existingData?.find(
|
|
5010
4990
|
(d) => d[idField.name] === item[idField.name]
|
|
5011
|
-
)
|
|
4991
|
+
)
|
|
5012
4992
|
);
|
|
5013
4993
|
}
|
|
5014
4994
|
)
|
|
@@ -5134,7 +5114,7 @@ var Resolver = class {
|
|
|
5134
5114
|
isCollectionSpecific
|
|
5135
5115
|
}) => {
|
|
5136
5116
|
const doc = await this.getDocument(realPath);
|
|
5137
|
-
const oldDoc = this.resolveLegacyValues(
|
|
5117
|
+
const oldDoc = this.resolveLegacyValues(doc?._rawData || {}, collection);
|
|
5138
5118
|
if (isAddPendingDocument === true) {
|
|
5139
5119
|
const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
|
|
5140
5120
|
const params2 = this.buildParams(args);
|
|
@@ -5144,7 +5124,7 @@ var Resolver = class {
|
|
|
5144
5124
|
const values = await this.buildFieldMutations(
|
|
5145
5125
|
params2,
|
|
5146
5126
|
templateInfo.template,
|
|
5147
|
-
doc
|
|
5127
|
+
doc?._rawData
|
|
5148
5128
|
);
|
|
5149
5129
|
await this.database.put(
|
|
5150
5130
|
realPath,
|
|
@@ -5168,7 +5148,7 @@ var Resolver = class {
|
|
|
5168
5148
|
// @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
|
|
5169
5149
|
templateParams,
|
|
5170
5150
|
template,
|
|
5171
|
-
doc
|
|
5151
|
+
doc?._rawData
|
|
5172
5152
|
),
|
|
5173
5153
|
_template: lastItem(template.namespace)
|
|
5174
5154
|
};
|
|
@@ -5182,7 +5162,7 @@ var Resolver = class {
|
|
|
5182
5162
|
//@ts-ignore
|
|
5183
5163
|
isCollectionSpecific ? args.params : args.params[collection.name],
|
|
5184
5164
|
collection,
|
|
5185
|
-
doc
|
|
5165
|
+
doc?._rawData
|
|
5186
5166
|
);
|
|
5187
5167
|
await this.database.put(
|
|
5188
5168
|
realPath,
|
|
@@ -5198,7 +5178,6 @@ var Resolver = class {
|
|
|
5198
5178
|
this.resolveLegacyValues = (oldDoc, collection) => {
|
|
5199
5179
|
const legacyValues = {};
|
|
5200
5180
|
Object.entries(oldDoc).forEach(([key, value]) => {
|
|
5201
|
-
var _a;
|
|
5202
5181
|
const reservedKeys = [
|
|
5203
5182
|
"$_body",
|
|
5204
5183
|
"_collection",
|
|
@@ -5211,7 +5190,7 @@ var Resolver = class {
|
|
|
5211
5190
|
return;
|
|
5212
5191
|
}
|
|
5213
5192
|
if (oldDoc._template && collection.templates) {
|
|
5214
|
-
const template =
|
|
5193
|
+
const template = collection.templates?.find(
|
|
5215
5194
|
({ name }) => name === oldDoc._template
|
|
5216
5195
|
);
|
|
5217
5196
|
if (template) {
|
|
@@ -5258,7 +5237,7 @@ var Resolver = class {
|
|
|
5258
5237
|
(yup3) => yup3.object({ relativePath: yup3.string().required() })
|
|
5259
5238
|
);
|
|
5260
5239
|
const collection = await this.tinaSchema.getCollection(collectionLookup);
|
|
5261
|
-
let realPath = import_path3.default.join(collection
|
|
5240
|
+
let realPath = import_path3.default.join(collection?.path, args.relativePath);
|
|
5262
5241
|
if (isFolderCreation) {
|
|
5263
5242
|
realPath = `${realPath}/.gitkeep.${collection.format || "md"}`;
|
|
5264
5243
|
}
|
|
@@ -5342,12 +5321,12 @@ var Resolver = class {
|
|
|
5342
5321
|
(yup3) => yup3.object({ params: yup3.object().required() })
|
|
5343
5322
|
);
|
|
5344
5323
|
assertShape(
|
|
5345
|
-
args
|
|
5324
|
+
args?.params,
|
|
5346
5325
|
(yup3) => yup3.object({ relativePath: yup3.string().required() })
|
|
5347
5326
|
);
|
|
5348
5327
|
const doc = await this.getDocument(realPath);
|
|
5349
5328
|
const newRealPath = import_path3.default.join(
|
|
5350
|
-
collection
|
|
5329
|
+
collection?.path,
|
|
5351
5330
|
args.params.relativePath
|
|
5352
5331
|
);
|
|
5353
5332
|
if (newRealPath === realPath) {
|
|
@@ -5577,7 +5556,7 @@ var Resolver = class {
|
|
|
5577
5556
|
if (!references[c.name][refId]) {
|
|
5578
5557
|
references[c.name][refId] = [];
|
|
5579
5558
|
}
|
|
5580
|
-
const referencePath = rawItem
|
|
5559
|
+
const referencePath = rawItem?.[REFS_PATH_FIELD];
|
|
5581
5560
|
if (referencePath) {
|
|
5582
5561
|
references[c.name][refId].push(referencePath);
|
|
5583
5562
|
}
|
|
@@ -5587,7 +5566,6 @@ var Resolver = class {
|
|
|
5587
5566
|
return references;
|
|
5588
5567
|
};
|
|
5589
5568
|
this.buildFieldMutations = async (fieldParams, template, existingData) => {
|
|
5590
|
-
var _a;
|
|
5591
5569
|
const accum = {};
|
|
5592
5570
|
for (const passwordField of template.fields.filter(
|
|
5593
5571
|
(f) => f.type === "password"
|
|
@@ -5630,7 +5608,7 @@ var Resolver = class {
|
|
|
5630
5608
|
accum[fieldName] = await this.buildObjectMutations(
|
|
5631
5609
|
fieldValue,
|
|
5632
5610
|
field,
|
|
5633
|
-
existingData
|
|
5611
|
+
existingData?.[fieldName]
|
|
5634
5612
|
);
|
|
5635
5613
|
break;
|
|
5636
5614
|
case "password":
|
|
@@ -5649,12 +5627,12 @@ var Resolver = class {
|
|
|
5649
5627
|
} else {
|
|
5650
5628
|
accum[fieldName] = {
|
|
5651
5629
|
...fieldValue,
|
|
5652
|
-
value:
|
|
5630
|
+
value: existingData?.[fieldName]?.["value"]
|
|
5653
5631
|
};
|
|
5654
5632
|
}
|
|
5655
5633
|
break;
|
|
5656
5634
|
case "rich-text":
|
|
5657
|
-
accum[fieldName] = (0, import_mdx.
|
|
5635
|
+
accum[fieldName] = (0, import_mdx.serializeMDX)(
|
|
5658
5636
|
fieldValue,
|
|
5659
5637
|
field,
|
|
5660
5638
|
(fieldValue2) => resolveMediaCloudToRelative(
|
|
@@ -5761,8 +5739,129 @@ var resolveDateInput = (value) => {
|
|
|
5761
5739
|
return date;
|
|
5762
5740
|
};
|
|
5763
5741
|
|
|
5764
|
-
// src/
|
|
5742
|
+
// src/resolver/auth-fields.ts
|
|
5765
5743
|
var import_lodash4 = __toESM(require("lodash.set"));
|
|
5744
|
+
async function getUserDocumentContext(tinaSchema, resolver) {
|
|
5745
|
+
const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
|
|
5746
|
+
if (!collection) {
|
|
5747
|
+
throw new Error("Auth collection not found");
|
|
5748
|
+
}
|
|
5749
|
+
const userFields = mapUserFields(collection, ["_rawData"]);
|
|
5750
|
+
if (!userFields.length) {
|
|
5751
|
+
throw new Error(`No user field found in collection ${collection.name}`);
|
|
5752
|
+
}
|
|
5753
|
+
if (userFields.length > 1) {
|
|
5754
|
+
throw new Error(
|
|
5755
|
+
`Multiple user fields found in collection ${collection.name}`
|
|
5756
|
+
);
|
|
5757
|
+
}
|
|
5758
|
+
const userField = userFields[0];
|
|
5759
|
+
const realPath = `${collection.path}/index.json`;
|
|
5760
|
+
const userDoc = await resolver.getDocument(realPath);
|
|
5761
|
+
const users = get(userDoc, userField.path);
|
|
5762
|
+
if (!users) {
|
|
5763
|
+
throw new Error("No users found");
|
|
5764
|
+
}
|
|
5765
|
+
return { collection, userField, users, userDoc, realPath };
|
|
5766
|
+
}
|
|
5767
|
+
function findUserInCollection(users, userField, userSub) {
|
|
5768
|
+
const { idFieldName } = userField;
|
|
5769
|
+
if (!idFieldName) {
|
|
5770
|
+
throw new Error("No uid field found on user field");
|
|
5771
|
+
}
|
|
5772
|
+
return users.find((u) => u[idFieldName] === userSub) || null;
|
|
5773
|
+
}
|
|
5774
|
+
async function handleAuthenticate({
|
|
5775
|
+
tinaSchema,
|
|
5776
|
+
resolver,
|
|
5777
|
+
sub,
|
|
5778
|
+
password,
|
|
5779
|
+
ctxUser
|
|
5780
|
+
}) {
|
|
5781
|
+
const userSub = sub || ctxUser?.sub;
|
|
5782
|
+
const { userField, users } = await getUserDocumentContext(
|
|
5783
|
+
tinaSchema,
|
|
5784
|
+
resolver
|
|
5785
|
+
);
|
|
5786
|
+
const user = findUserInCollection(users, userField, userSub);
|
|
5787
|
+
if (!user) {
|
|
5788
|
+
return null;
|
|
5789
|
+
}
|
|
5790
|
+
const { passwordFieldName } = userField;
|
|
5791
|
+
const saltedHash = get(user, [passwordFieldName || "", "value"]);
|
|
5792
|
+
if (!saltedHash) {
|
|
5793
|
+
throw new Error("No password field found on user field");
|
|
5794
|
+
}
|
|
5795
|
+
const matches = await checkPasswordHash({
|
|
5796
|
+
saltedHash,
|
|
5797
|
+
password
|
|
5798
|
+
});
|
|
5799
|
+
return matches ? user : null;
|
|
5800
|
+
}
|
|
5801
|
+
async function handleAuthorize({
|
|
5802
|
+
tinaSchema,
|
|
5803
|
+
resolver,
|
|
5804
|
+
sub,
|
|
5805
|
+
ctxUser
|
|
5806
|
+
}) {
|
|
5807
|
+
const userSub = sub || ctxUser?.sub;
|
|
5808
|
+
const { userField, users } = await getUserDocumentContext(
|
|
5809
|
+
tinaSchema,
|
|
5810
|
+
resolver
|
|
5811
|
+
);
|
|
5812
|
+
const user = findUserInCollection(users, userField, userSub);
|
|
5813
|
+
return user ? user : null;
|
|
5814
|
+
}
|
|
5815
|
+
async function handleUpdatePassword({
|
|
5816
|
+
tinaSchema,
|
|
5817
|
+
resolver,
|
|
5818
|
+
password,
|
|
5819
|
+
ctxUser
|
|
5820
|
+
}) {
|
|
5821
|
+
if (!ctxUser?.sub) {
|
|
5822
|
+
throw new Error("Not authorized");
|
|
5823
|
+
}
|
|
5824
|
+
if (!password) {
|
|
5825
|
+
throw new Error("No password provided");
|
|
5826
|
+
}
|
|
5827
|
+
const { collection, userField, users, realPath } = await getUserDocumentContext(tinaSchema, resolver);
|
|
5828
|
+
const { idFieldName, passwordFieldName } = userField;
|
|
5829
|
+
const user = users.find((u) => u[idFieldName] === ctxUser.sub);
|
|
5830
|
+
if (!user) {
|
|
5831
|
+
throw new Error("Not authorized");
|
|
5832
|
+
}
|
|
5833
|
+
user[passwordFieldName] = {
|
|
5834
|
+
value: password,
|
|
5835
|
+
passwordChangeRequired: false
|
|
5836
|
+
};
|
|
5837
|
+
const params = {};
|
|
5838
|
+
(0, import_lodash4.default)(
|
|
5839
|
+
params,
|
|
5840
|
+
userField.path.slice(1),
|
|
5841
|
+
// remove _rawData from users path
|
|
5842
|
+
users.map((u) => {
|
|
5843
|
+
if (user[idFieldName] === u[idFieldName]) {
|
|
5844
|
+
return user;
|
|
5845
|
+
}
|
|
5846
|
+
return {
|
|
5847
|
+
// don't overwrite other users' passwords
|
|
5848
|
+
...u,
|
|
5849
|
+
[passwordFieldName]: {
|
|
5850
|
+
...u[passwordFieldName],
|
|
5851
|
+
value: ""
|
|
5852
|
+
}
|
|
5853
|
+
};
|
|
5854
|
+
})
|
|
5855
|
+
);
|
|
5856
|
+
await resolver.updateResolveDocument({
|
|
5857
|
+
collection,
|
|
5858
|
+
args: { params },
|
|
5859
|
+
realPath,
|
|
5860
|
+
isCollectionSpecific: true,
|
|
5861
|
+
isAddPendingDocument: false
|
|
5862
|
+
});
|
|
5863
|
+
return true;
|
|
5864
|
+
}
|
|
5766
5865
|
|
|
5767
5866
|
// src/error.ts
|
|
5768
5867
|
var import_graphql4 = require("graphql");
|
|
@@ -5784,9 +5883,8 @@ var resolve = async ({
|
|
|
5784
5883
|
isAudit,
|
|
5785
5884
|
ctxUser
|
|
5786
5885
|
}) => {
|
|
5787
|
-
var _a;
|
|
5788
5886
|
try {
|
|
5789
|
-
const verboseValue = verbose
|
|
5887
|
+
const verboseValue = verbose ?? true;
|
|
5790
5888
|
const graphQLSchemaAst = await database.getGraphQLSchema();
|
|
5791
5889
|
if (!graphQLSchemaAst) {
|
|
5792
5890
|
throw new import_graphql5.GraphQLError("GraphQL schema not found");
|
|
@@ -5798,7 +5896,7 @@ var resolve = async ({
|
|
|
5798
5896
|
// @ts-ignore
|
|
5799
5897
|
schema: tinaConfig,
|
|
5800
5898
|
// @ts-ignore
|
|
5801
|
-
flags:
|
|
5899
|
+
flags: tinaConfig?.meta?.flags
|
|
5802
5900
|
});
|
|
5803
5901
|
const resolver = createResolver({
|
|
5804
5902
|
config,
|
|
@@ -5823,7 +5921,6 @@ var resolve = async ({
|
|
|
5823
5921
|
throw new Error(`Unable to find lookup key for ${namedType}`);
|
|
5824
5922
|
},
|
|
5825
5923
|
fieldResolver: async (source = {}, _args = {}, _context, info) => {
|
|
5826
|
-
var _a2, _b, _c, _d;
|
|
5827
5924
|
try {
|
|
5828
5925
|
const args = JSON.parse(JSON.stringify(_args));
|
|
5829
5926
|
const returnType = (0, import_graphql5.getNamedType)(info.returnType).toString();
|
|
@@ -5840,8 +5937,7 @@ var resolve = async ({
|
|
|
5840
5937
|
);
|
|
5841
5938
|
const hasDocuments2 = collectionNode2.selectionSet.selections.find(
|
|
5842
5939
|
(x) => {
|
|
5843
|
-
|
|
5844
|
-
return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
|
|
5940
|
+
return x?.name?.value === "documents";
|
|
5845
5941
|
}
|
|
5846
5942
|
);
|
|
5847
5943
|
return tinaSchema.getCollections().map((collection) => {
|
|
@@ -5857,8 +5953,7 @@ var resolve = async ({
|
|
|
5857
5953
|
);
|
|
5858
5954
|
const hasDocuments = collectionNode.selectionSet.selections.find(
|
|
5859
5955
|
(x) => {
|
|
5860
|
-
|
|
5861
|
-
return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
|
|
5956
|
+
return x?.name?.value === "documents";
|
|
5862
5957
|
}
|
|
5863
5958
|
);
|
|
5864
5959
|
return resolver.resolveCollection(
|
|
@@ -5876,119 +5971,33 @@ var resolve = async ({
|
|
|
5876
5971
|
);
|
|
5877
5972
|
}
|
|
5878
5973
|
}
|
|
5879
|
-
if (info.fieldName === "authenticate"
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
const realPath = `${collection.path}/index.json`;
|
|
5898
|
-
const userDoc = await resolver.getDocument(realPath);
|
|
5899
|
-
const users = get(userDoc, userField.path);
|
|
5900
|
-
if (!users) {
|
|
5901
|
-
throw new Error("No users found");
|
|
5902
|
-
}
|
|
5903
|
-
const { idFieldName, passwordFieldName } = userField;
|
|
5904
|
-
if (!idFieldName) {
|
|
5905
|
-
throw new Error("No uid field found on user field");
|
|
5906
|
-
}
|
|
5907
|
-
const user = users.find((u) => u[idFieldName] === sub);
|
|
5908
|
-
if (!user) {
|
|
5909
|
-
return null;
|
|
5910
|
-
}
|
|
5911
|
-
if (info.fieldName === "authenticate") {
|
|
5912
|
-
const saltedHash = get(user, [passwordFieldName || "", "value"]);
|
|
5913
|
-
if (!saltedHash) {
|
|
5914
|
-
throw new Error("No password field found on user field");
|
|
5915
|
-
}
|
|
5916
|
-
const matches = await checkPasswordHash({
|
|
5917
|
-
saltedHash,
|
|
5918
|
-
password: args.password
|
|
5919
|
-
});
|
|
5920
|
-
if (matches) {
|
|
5921
|
-
return user;
|
|
5922
|
-
}
|
|
5923
|
-
return null;
|
|
5924
|
-
}
|
|
5925
|
-
return user;
|
|
5974
|
+
if (info.fieldName === "authenticate") {
|
|
5975
|
+
return handleAuthenticate({
|
|
5976
|
+
tinaSchema,
|
|
5977
|
+
resolver,
|
|
5978
|
+
sub: args.sub,
|
|
5979
|
+
password: args.password,
|
|
5980
|
+
info,
|
|
5981
|
+
ctxUser
|
|
5982
|
+
});
|
|
5983
|
+
}
|
|
5984
|
+
if (info.fieldName === "authorize") {
|
|
5985
|
+
return handleAuthorize({
|
|
5986
|
+
tinaSchema,
|
|
5987
|
+
resolver,
|
|
5988
|
+
sub: args.sub,
|
|
5989
|
+
info,
|
|
5990
|
+
ctxUser
|
|
5991
|
+
});
|
|
5926
5992
|
}
|
|
5927
5993
|
if (info.fieldName === "updatePassword") {
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
|
|
5935
|
-
if (!collection) {
|
|
5936
|
-
throw new Error("Auth collection not found");
|
|
5937
|
-
}
|
|
5938
|
-
const userFields = mapUserFields(collection, ["_rawData"]);
|
|
5939
|
-
if (!userFields.length) {
|
|
5940
|
-
throw new Error(
|
|
5941
|
-
`No user field found in collection ${collection.name}`
|
|
5942
|
-
);
|
|
5943
|
-
}
|
|
5944
|
-
if (userFields.length > 1) {
|
|
5945
|
-
throw new Error(
|
|
5946
|
-
`Multiple user fields found in collection ${collection.name}`
|
|
5947
|
-
);
|
|
5948
|
-
}
|
|
5949
|
-
const userField = userFields[0];
|
|
5950
|
-
const realPath = `${collection.path}/index.json`;
|
|
5951
|
-
const userDoc = await resolver.getDocument(realPath);
|
|
5952
|
-
const users = get(userDoc, userField.path);
|
|
5953
|
-
if (!users) {
|
|
5954
|
-
throw new Error("No users found");
|
|
5955
|
-
}
|
|
5956
|
-
const { idFieldName, passwordFieldName } = userField;
|
|
5957
|
-
const user = users.find((u) => u[idFieldName] === ctxUser.sub);
|
|
5958
|
-
if (!user) {
|
|
5959
|
-
throw new Error("Not authorized");
|
|
5960
|
-
}
|
|
5961
|
-
user[passwordFieldName] = {
|
|
5962
|
-
value: args.password,
|
|
5963
|
-
passwordChangeRequired: false
|
|
5964
|
-
};
|
|
5965
|
-
const params = {};
|
|
5966
|
-
(0, import_lodash4.default)(
|
|
5967
|
-
params,
|
|
5968
|
-
userField.path.slice(1),
|
|
5969
|
-
// remove _rawData from users path
|
|
5970
|
-
users.map((u) => {
|
|
5971
|
-
if (user[idFieldName] === u[idFieldName]) {
|
|
5972
|
-
return user;
|
|
5973
|
-
}
|
|
5974
|
-
return {
|
|
5975
|
-
// don't overwrite other users' passwords
|
|
5976
|
-
...u,
|
|
5977
|
-
[passwordFieldName]: {
|
|
5978
|
-
...u[passwordFieldName],
|
|
5979
|
-
value: ""
|
|
5980
|
-
}
|
|
5981
|
-
};
|
|
5982
|
-
})
|
|
5983
|
-
);
|
|
5984
|
-
await resolver.updateResolveDocument({
|
|
5985
|
-
collection,
|
|
5986
|
-
args: { params },
|
|
5987
|
-
realPath,
|
|
5988
|
-
isCollectionSpecific: true,
|
|
5989
|
-
isAddPendingDocument: false
|
|
5994
|
+
return handleUpdatePassword({
|
|
5995
|
+
tinaSchema,
|
|
5996
|
+
resolver,
|
|
5997
|
+
password: args.password,
|
|
5998
|
+
info,
|
|
5999
|
+
ctxUser
|
|
5990
6000
|
});
|
|
5991
|
-
return true;
|
|
5992
6001
|
}
|
|
5993
6002
|
if (!lookup) {
|
|
5994
6003
|
return value;
|
|
@@ -6008,7 +6017,7 @@ var resolve = async ({
|
|
|
6008
6017
|
if (typeof value === "string" && value !== "") {
|
|
6009
6018
|
return resolver.getDocument(value);
|
|
6010
6019
|
}
|
|
6011
|
-
if (
|
|
6020
|
+
if (args?.collection && info.fieldName === "addPendingDocument") {
|
|
6012
6021
|
return resolver.resolveDocument({
|
|
6013
6022
|
args: { ...args, params: {} },
|
|
6014
6023
|
collection: args.collection,
|
|
@@ -6032,7 +6041,7 @@ var resolve = async ({
|
|
|
6032
6041
|
// Right now this is the only case for deletion
|
|
6033
6042
|
isDeletion: info.fieldName === "deleteDocument",
|
|
6034
6043
|
isFolderCreation: info.fieldName === "createFolder",
|
|
6035
|
-
isUpdateName: Boolean(
|
|
6044
|
+
isUpdateName: Boolean(args?.params?.relativePath),
|
|
6036
6045
|
isAddPendingDocument: false,
|
|
6037
6046
|
isCollectionSpecific: false
|
|
6038
6047
|
});
|
|
@@ -6051,16 +6060,16 @@ var resolve = async ({
|
|
|
6051
6060
|
})
|
|
6052
6061
|
};
|
|
6053
6062
|
}
|
|
6054
|
-
if (info.fieldName === "documents" &&
|
|
6063
|
+
if (info.fieldName === "documents" && value?.collection && value?.hasDocuments) {
|
|
6055
6064
|
let filter = args.filter;
|
|
6056
6065
|
if (
|
|
6057
6066
|
// 1. Make sure that the filter exists
|
|
6058
|
-
typeof
|
|
6067
|
+
typeof args?.filter !== "undefined" && args?.filter !== null && // 2. Make sure that the collection name exists
|
|
6059
6068
|
// @ts-ignore
|
|
6060
|
-
typeof
|
|
6069
|
+
typeof value?.collection?.name === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
|
|
6061
6070
|
// @ts-ignore
|
|
6062
|
-
Object.keys(args.filter).includes(
|
|
6063
|
-
typeof args.filter[
|
|
6071
|
+
Object.keys(args.filter).includes(value?.collection?.name) && // @ts-ignore
|
|
6072
|
+
typeof args.filter[value?.collection?.name] !== "undefined"
|
|
6064
6073
|
) {
|
|
6065
6074
|
filter = args.filter[value.collection.name];
|
|
6066
6075
|
}
|
|
@@ -6197,15 +6206,15 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
|
|
|
6197
6206
|
};
|
|
6198
6207
|
|
|
6199
6208
|
// src/database/index.ts
|
|
6200
|
-
var import_node_path = __toESM(require("path"));
|
|
6209
|
+
var import_node_path = __toESM(require("node:path"));
|
|
6201
6210
|
var import_graphql6 = require("graphql");
|
|
6202
6211
|
var import_micromatch2 = __toESM(require("micromatch"));
|
|
6203
6212
|
var import_js_sha12 = __toESM(require("js-sha1"));
|
|
6204
6213
|
var import_lodash5 = __toESM(require("lodash.set"));
|
|
6205
6214
|
var createLocalDatabase = (config) => {
|
|
6206
|
-
const level = new TinaLevelClient(config
|
|
6215
|
+
const level = new TinaLevelClient(config?.port);
|
|
6207
6216
|
level.openConnection();
|
|
6208
|
-
const fsBridge = new FilesystemBridge(
|
|
6217
|
+
const fsBridge = new FilesystemBridge(config?.rootPath || process.cwd());
|
|
6209
6218
|
return new Database({
|
|
6210
6219
|
bridge: fsBridge,
|
|
6211
6220
|
...config || {},
|
|
@@ -6278,7 +6287,7 @@ var Database = class {
|
|
|
6278
6287
|
);
|
|
6279
6288
|
}
|
|
6280
6289
|
const metadata = await metadataLevel.get(`metadata_${key}`);
|
|
6281
|
-
return metadata
|
|
6290
|
+
return metadata?.value;
|
|
6282
6291
|
};
|
|
6283
6292
|
this.setMetadata = async (key, value) => {
|
|
6284
6293
|
await this.initLevel();
|
|
@@ -6300,7 +6309,7 @@ var Database = class {
|
|
|
6300
6309
|
let level = this.contentLevel;
|
|
6301
6310
|
if (this.appLevel) {
|
|
6302
6311
|
collection = await this.collectionForPath(filepath);
|
|
6303
|
-
if (collection
|
|
6312
|
+
if (collection?.isDetached) {
|
|
6304
6313
|
level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
|
|
6305
6314
|
}
|
|
6306
6315
|
}
|
|
@@ -6319,7 +6328,6 @@ var Database = class {
|
|
|
6319
6328
|
}
|
|
6320
6329
|
};
|
|
6321
6330
|
this.addPendingDocument = async (filepath, data) => {
|
|
6322
|
-
var _a;
|
|
6323
6331
|
await this.initLevel();
|
|
6324
6332
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
6325
6333
|
const collection = await this.collectionForPath(filepath);
|
|
@@ -6332,10 +6340,10 @@ var Database = class {
|
|
|
6332
6340
|
collection
|
|
6333
6341
|
);
|
|
6334
6342
|
const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
|
|
6335
|
-
const collectionIndexDefinitions = indexDefinitions
|
|
6336
|
-
const collectionReferences = (
|
|
6343
|
+
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
6344
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
|
|
6337
6345
|
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
6338
|
-
if (!
|
|
6346
|
+
if (!collection?.isDetached) {
|
|
6339
6347
|
if (this.bridge) {
|
|
6340
6348
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
6341
6349
|
}
|
|
@@ -6353,7 +6361,7 @@ var Database = class {
|
|
|
6353
6361
|
}
|
|
6354
6362
|
}
|
|
6355
6363
|
let level = this.contentLevel;
|
|
6356
|
-
if (collection
|
|
6364
|
+
if (collection?.isDetached) {
|
|
6357
6365
|
level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
|
|
6358
6366
|
}
|
|
6359
6367
|
const folderTreeBuilder = new FolderTreeBuilder();
|
|
@@ -6364,7 +6372,7 @@ var Database = class {
|
|
|
6364
6372
|
putOps = [
|
|
6365
6373
|
...makeRefOpsForDocument(
|
|
6366
6374
|
normalizedPath,
|
|
6367
|
-
collection
|
|
6375
|
+
collection?.name,
|
|
6368
6376
|
collectionReferences,
|
|
6369
6377
|
dataFields,
|
|
6370
6378
|
"put",
|
|
@@ -6372,7 +6380,7 @@ var Database = class {
|
|
|
6372
6380
|
),
|
|
6373
6381
|
...makeIndexOpsForDocument(
|
|
6374
6382
|
normalizedPath,
|
|
6375
|
-
collection
|
|
6383
|
+
collection?.name,
|
|
6376
6384
|
collectionIndexDefinitions,
|
|
6377
6385
|
dataFields,
|
|
6378
6386
|
"put",
|
|
@@ -6381,7 +6389,7 @@ var Database = class {
|
|
|
6381
6389
|
// folder indices
|
|
6382
6390
|
...makeIndexOpsForDocument(
|
|
6383
6391
|
normalizedPath,
|
|
6384
|
-
`${collection
|
|
6392
|
+
`${collection?.name}_${folderKey}`,
|
|
6385
6393
|
collectionIndexDefinitions,
|
|
6386
6394
|
dataFields,
|
|
6387
6395
|
"put",
|
|
@@ -6395,7 +6403,7 @@ var Database = class {
|
|
|
6395
6403
|
delOps = existingItem ? [
|
|
6396
6404
|
...makeRefOpsForDocument(
|
|
6397
6405
|
normalizedPath,
|
|
6398
|
-
collection
|
|
6406
|
+
collection?.name,
|
|
6399
6407
|
collectionReferences,
|
|
6400
6408
|
existingItem,
|
|
6401
6409
|
"del",
|
|
@@ -6403,7 +6411,7 @@ var Database = class {
|
|
|
6403
6411
|
),
|
|
6404
6412
|
...makeIndexOpsForDocument(
|
|
6405
6413
|
normalizedPath,
|
|
6406
|
-
collection
|
|
6414
|
+
collection?.name,
|
|
6407
6415
|
collectionIndexDefinitions,
|
|
6408
6416
|
existingItem,
|
|
6409
6417
|
"del",
|
|
@@ -6412,7 +6420,7 @@ var Database = class {
|
|
|
6412
6420
|
// folder indices
|
|
6413
6421
|
...makeIndexOpsForDocument(
|
|
6414
6422
|
normalizedPath,
|
|
6415
|
-
`${collection
|
|
6423
|
+
`${collection?.name}_${folderKey}`,
|
|
6416
6424
|
collectionIndexDefinitions,
|
|
6417
6425
|
existingItem,
|
|
6418
6426
|
"del",
|
|
@@ -6436,7 +6444,6 @@ var Database = class {
|
|
|
6436
6444
|
await level.batch(ops);
|
|
6437
6445
|
};
|
|
6438
6446
|
this.put = async (filepath, data, collectionName) => {
|
|
6439
|
-
var _a, _b, _c;
|
|
6440
6447
|
await this.initLevel();
|
|
6441
6448
|
try {
|
|
6442
6449
|
if (SYSTEM_FILES.includes(filepath)) {
|
|
@@ -6447,16 +6454,16 @@ var Database = class {
|
|
|
6447
6454
|
const indexDefinitions = await this.getIndexDefinitions(
|
|
6448
6455
|
this.contentLevel
|
|
6449
6456
|
);
|
|
6450
|
-
collectionIndexDefinitions = indexDefinitions
|
|
6457
|
+
collectionIndexDefinitions = indexDefinitions?.[collectionName];
|
|
6451
6458
|
}
|
|
6452
|
-
const collectionReferences = (
|
|
6459
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collectionName];
|
|
6453
6460
|
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
6454
6461
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
6455
6462
|
const collection = await this.collectionForPath(filepath);
|
|
6456
6463
|
if (!collection) {
|
|
6457
6464
|
throw new import_graphql6.GraphQLError(`Unable to find collection for ${filepath}.`);
|
|
6458
6465
|
}
|
|
6459
|
-
if (
|
|
6466
|
+
if (collection.match?.exclude || collection.match?.include) {
|
|
6460
6467
|
const matches = this.tinaSchema.getMatches({ collection });
|
|
6461
6468
|
const match = import_micromatch2.default.isMatch(filepath, matches);
|
|
6462
6469
|
if (!match) {
|
|
@@ -6470,7 +6477,7 @@ var Database = class {
|
|
|
6470
6477
|
const stringifiedFile = filepath.endsWith(
|
|
6471
6478
|
`.gitkeep.${collection.format || "md"}`
|
|
6472
6479
|
) ? "" : await this.stringifyFile(filepath, dataFields, collection);
|
|
6473
|
-
if (!
|
|
6480
|
+
if (!collection?.isDetached) {
|
|
6474
6481
|
if (this.bridge) {
|
|
6475
6482
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
6476
6483
|
}
|
|
@@ -6492,7 +6499,7 @@ var Database = class {
|
|
|
6492
6499
|
filepath,
|
|
6493
6500
|
collection.path || ""
|
|
6494
6501
|
);
|
|
6495
|
-
const level =
|
|
6502
|
+
const level = collection?.isDetached ? this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS) : this.contentLevel;
|
|
6496
6503
|
let putOps = [];
|
|
6497
6504
|
let delOps = [];
|
|
6498
6505
|
if (!isGitKeep(normalizedPath, collection)) {
|
|
@@ -6516,7 +6523,7 @@ var Database = class {
|
|
|
6516
6523
|
// folder indices
|
|
6517
6524
|
...makeIndexOpsForDocument(
|
|
6518
6525
|
normalizedPath,
|
|
6519
|
-
`${collection
|
|
6526
|
+
`${collection?.name}_${folderKey}`,
|
|
6520
6527
|
collectionIndexDefinitions,
|
|
6521
6528
|
dataFields,
|
|
6522
6529
|
"put",
|
|
@@ -6547,7 +6554,7 @@ var Database = class {
|
|
|
6547
6554
|
// folder indices
|
|
6548
6555
|
...makeIndexOpsForDocument(
|
|
6549
6556
|
normalizedPath,
|
|
6550
|
-
`${collection
|
|
6557
|
+
`${collection?.name}_${folderKey}`,
|
|
6551
6558
|
collectionIndexDefinitions,
|
|
6552
6559
|
existingItem,
|
|
6553
6560
|
"del",
|
|
@@ -6578,8 +6585,7 @@ var Database = class {
|
|
|
6578
6585
|
throw new TinaFetchError(`Error in PUT for ${filepath}`, {
|
|
6579
6586
|
originalError: error,
|
|
6580
6587
|
file: filepath,
|
|
6581
|
-
collection: collectionName
|
|
6582
|
-
stack: error.stack
|
|
6588
|
+
collection: collectionName
|
|
6583
6589
|
});
|
|
6584
6590
|
}
|
|
6585
6591
|
};
|
|
@@ -6624,8 +6630,8 @@ var Database = class {
|
|
|
6624
6630
|
writeTemplateKey,
|
|
6625
6631
|
//templateInfo.type === 'union',
|
|
6626
6632
|
{
|
|
6627
|
-
frontmatterFormat: collection
|
|
6628
|
-
frontmatterDelimiters: collection
|
|
6633
|
+
frontmatterFormat: collection?.frontmatterFormat,
|
|
6634
|
+
frontmatterDelimiters: collection?.frontmatterDelimiters
|
|
6629
6635
|
}
|
|
6630
6636
|
);
|
|
6631
6637
|
};
|
|
@@ -6794,8 +6800,8 @@ var Database = class {
|
|
|
6794
6800
|
);
|
|
6795
6801
|
return {
|
|
6796
6802
|
name: indexField.name,
|
|
6797
|
-
type: field
|
|
6798
|
-
list: !!
|
|
6803
|
+
type: field?.type,
|
|
6804
|
+
list: !!field?.list
|
|
6799
6805
|
};
|
|
6800
6806
|
})
|
|
6801
6807
|
};
|
|
@@ -6821,7 +6827,6 @@ var Database = class {
|
|
|
6821
6827
|
return true;
|
|
6822
6828
|
};
|
|
6823
6829
|
this.query = async (queryOptions, hydrator) => {
|
|
6824
|
-
var _a;
|
|
6825
6830
|
await this.initLevel();
|
|
6826
6831
|
const {
|
|
6827
6832
|
first,
|
|
@@ -6849,14 +6854,14 @@ var Database = class {
|
|
|
6849
6854
|
const allIndexDefinitions = await this.getIndexDefinitions(
|
|
6850
6855
|
this.contentLevel
|
|
6851
6856
|
);
|
|
6852
|
-
const indexDefinitions = allIndexDefinitions
|
|
6857
|
+
const indexDefinitions = allIndexDefinitions?.[collection.name];
|
|
6853
6858
|
if (!indexDefinitions) {
|
|
6854
6859
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
6855
6860
|
}
|
|
6856
6861
|
const filterChain = coerceFilterChainOperands(rawFilterChain);
|
|
6857
|
-
const indexDefinition = sort &&
|
|
6862
|
+
const indexDefinition = sort && indexDefinitions?.[sort];
|
|
6858
6863
|
const filterSuffixes = indexDefinition && makeFilterSuffixes(filterChain, indexDefinition);
|
|
6859
|
-
const level =
|
|
6864
|
+
const level = collection?.isDetached ? this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS) : this.contentLevel;
|
|
6860
6865
|
const rootLevel = level.sublevel(
|
|
6861
6866
|
CONTENT_ROOT_PREFIX,
|
|
6862
6867
|
SUBLEVEL_OPTIONS
|
|
@@ -6866,17 +6871,17 @@ var Database = class {
|
|
|
6866
6871
|
SUBLEVEL_OPTIONS
|
|
6867
6872
|
).sublevel(sort, SUBLEVEL_OPTIONS) : rootLevel;
|
|
6868
6873
|
if (!query.gt && !query.gte) {
|
|
6869
|
-
query.gte =
|
|
6874
|
+
query.gte = filterSuffixes?.left ? filterSuffixes.left : "";
|
|
6870
6875
|
}
|
|
6871
6876
|
if (!query.lt && !query.lte) {
|
|
6872
|
-
query.lte =
|
|
6877
|
+
query.lte = filterSuffixes?.right ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
|
|
6873
6878
|
}
|
|
6874
6879
|
let edges = [];
|
|
6875
6880
|
let startKey = "";
|
|
6876
6881
|
let endKey = "";
|
|
6877
6882
|
let hasPreviousPage = false;
|
|
6878
6883
|
let hasNextPage = false;
|
|
6879
|
-
const fieldsPattern =
|
|
6884
|
+
const fieldsPattern = indexDefinition?.fields?.length ? `${indexDefinition.fields.map((p) => `(?<${p.name}>.+)${INDEX_KEY_FIELD_SEPARATOR}`).join("")}` : "";
|
|
6880
6885
|
const valuesRegex = indexDefinition ? new RegExp(`^${fieldsPattern}(?<_filepath_>.+)`) : new RegExp(`^(?<_filepath_>.+)`);
|
|
6881
6886
|
const itemFilter = makeFilter({ filterChain });
|
|
6882
6887
|
const iterator = sublevel.iterator(query);
|
|
@@ -6940,8 +6945,7 @@ var Database = class {
|
|
|
6940
6945
|
throw new TinaQueryError({
|
|
6941
6946
|
originalError: error,
|
|
6942
6947
|
file: path7,
|
|
6943
|
-
collection: collection.name
|
|
6944
|
-
stack: error.stack
|
|
6948
|
+
collection: collection.name
|
|
6945
6949
|
});
|
|
6946
6950
|
}
|
|
6947
6951
|
throw error;
|
|
@@ -7071,13 +7075,14 @@ var Database = class {
|
|
|
7071
7075
|
documentPaths,
|
|
7072
7076
|
async (collection, documentPaths2) => {
|
|
7073
7077
|
if (collection && !collection.isDetached) {
|
|
7074
|
-
await _indexContent(
|
|
7075
|
-
this,
|
|
7076
|
-
this.contentLevel,
|
|
7077
|
-
documentPaths2,
|
|
7078
|
+
await _indexContent({
|
|
7079
|
+
database: this,
|
|
7080
|
+
level: this.contentLevel,
|
|
7081
|
+
documentPaths: documentPaths2,
|
|
7078
7082
|
enqueueOps,
|
|
7079
|
-
collection
|
|
7080
|
-
|
|
7083
|
+
collection,
|
|
7084
|
+
isPartialReindex: true
|
|
7085
|
+
});
|
|
7081
7086
|
}
|
|
7082
7087
|
}
|
|
7083
7088
|
);
|
|
@@ -7087,18 +7092,17 @@ var Database = class {
|
|
|
7087
7092
|
}
|
|
7088
7093
|
};
|
|
7089
7094
|
this.delete = async (filepath) => {
|
|
7090
|
-
var _a;
|
|
7091
7095
|
await this.initLevel();
|
|
7092
7096
|
const collection = await this.collectionForPath(filepath);
|
|
7093
7097
|
if (!collection) {
|
|
7094
7098
|
throw new Error(`No collection found for path: ${filepath}`);
|
|
7095
7099
|
}
|
|
7096
7100
|
const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
|
|
7097
|
-
const collectionReferences = (
|
|
7098
|
-
const collectionIndexDefinitions = indexDefinitions
|
|
7101
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
|
|
7102
|
+
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
7099
7103
|
let level = this.contentLevel;
|
|
7100
|
-
if (collection
|
|
7101
|
-
level = this.appLevel.sublevel(collection
|
|
7104
|
+
if (collection?.isDetached) {
|
|
7105
|
+
level = this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS);
|
|
7102
7106
|
}
|
|
7103
7107
|
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
7104
7108
|
const rootSublevel = level.sublevel(
|
|
@@ -7145,7 +7149,7 @@ var Database = class {
|
|
|
7145
7149
|
}
|
|
7146
7150
|
]);
|
|
7147
7151
|
}
|
|
7148
|
-
if (!
|
|
7152
|
+
if (!collection?.isDetached) {
|
|
7149
7153
|
if (this.bridge) {
|
|
7150
7154
|
await this.bridge.delete(normalizedPath);
|
|
7151
7155
|
}
|
|
@@ -7185,26 +7189,26 @@ var Database = class {
|
|
|
7185
7189
|
);
|
|
7186
7190
|
const doc = await level2.keys({ limit: 1 }).next();
|
|
7187
7191
|
if (!doc) {
|
|
7188
|
-
await _indexContent(
|
|
7189
|
-
this,
|
|
7190
|
-
level2,
|
|
7191
|
-
contentPaths,
|
|
7192
|
+
await _indexContent({
|
|
7193
|
+
database: this,
|
|
7194
|
+
level: level2,
|
|
7195
|
+
documentPaths: contentPaths,
|
|
7192
7196
|
enqueueOps,
|
|
7193
7197
|
collection,
|
|
7194
|
-
userFields.map((field) => [
|
|
7198
|
+
passwordFields: userFields.map((field) => [
|
|
7195
7199
|
...field.path,
|
|
7196
7200
|
field.passwordFieldName
|
|
7197
7201
|
])
|
|
7198
|
-
);
|
|
7202
|
+
});
|
|
7199
7203
|
}
|
|
7200
7204
|
} else {
|
|
7201
|
-
await _indexContent(
|
|
7202
|
-
this,
|
|
7205
|
+
await _indexContent({
|
|
7206
|
+
database: this,
|
|
7203
7207
|
level,
|
|
7204
|
-
contentPaths,
|
|
7208
|
+
documentPaths: contentPaths,
|
|
7205
7209
|
enqueueOps,
|
|
7206
7210
|
collection
|
|
7207
|
-
);
|
|
7211
|
+
});
|
|
7208
7212
|
}
|
|
7209
7213
|
}
|
|
7210
7214
|
);
|
|
@@ -7240,7 +7244,7 @@ var Database = class {
|
|
|
7240
7244
|
);
|
|
7241
7245
|
}
|
|
7242
7246
|
const metadata = await metadataLevel.get("metadata");
|
|
7243
|
-
return metadata
|
|
7247
|
+
return metadata?.version;
|
|
7244
7248
|
}
|
|
7245
7249
|
async initLevel() {
|
|
7246
7250
|
if (this.contentLevel) {
|
|
@@ -7326,7 +7330,7 @@ var hashPasswordVisitor = async (node, path7) => {
|
|
|
7326
7330
|
};
|
|
7327
7331
|
var visitNodes = async (node, path7, callback) => {
|
|
7328
7332
|
const [currentLevel, ...remainingLevels] = path7;
|
|
7329
|
-
if (!
|
|
7333
|
+
if (!remainingLevels?.length) {
|
|
7330
7334
|
return callback(node, path7);
|
|
7331
7335
|
}
|
|
7332
7336
|
if (Array.isArray(node[currentLevel])) {
|
|
@@ -7342,20 +7346,27 @@ var hashPasswordValues = async (data, passwordFields) => Promise.all(
|
|
|
7342
7346
|
async (passwordField) => visitNodes(data, passwordField, hashPasswordVisitor)
|
|
7343
7347
|
)
|
|
7344
7348
|
);
|
|
7345
|
-
var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${
|
|
7346
|
-
var _indexContent = async (
|
|
7347
|
-
|
|
7349
|
+
var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${collection?.format || "md"}`);
|
|
7350
|
+
var _indexContent = async ({
|
|
7351
|
+
database,
|
|
7352
|
+
level,
|
|
7353
|
+
documentPaths,
|
|
7354
|
+
enqueueOps,
|
|
7355
|
+
collection,
|
|
7356
|
+
passwordFields,
|
|
7357
|
+
isPartialReindex
|
|
7358
|
+
}) => {
|
|
7348
7359
|
let collectionIndexDefinitions;
|
|
7349
7360
|
let collectionPath;
|
|
7350
7361
|
if (collection) {
|
|
7351
7362
|
const indexDefinitions = await database.getIndexDefinitions(level);
|
|
7352
|
-
collectionIndexDefinitions = indexDefinitions
|
|
7363
|
+
collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
7353
7364
|
if (!collectionIndexDefinitions) {
|
|
7354
7365
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
7355
7366
|
}
|
|
7356
7367
|
collectionPath = collection.path;
|
|
7357
7368
|
}
|
|
7358
|
-
const collectionReferences = (
|
|
7369
|
+
const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
|
|
7359
7370
|
const tinaSchema = await database.getSchema();
|
|
7360
7371
|
let templateInfo = null;
|
|
7361
7372
|
if (collection) {
|
|
@@ -7373,7 +7384,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7373
7384
|
if (!aliasedData) {
|
|
7374
7385
|
return;
|
|
7375
7386
|
}
|
|
7376
|
-
if (passwordFields
|
|
7387
|
+
if (passwordFields?.length) {
|
|
7377
7388
|
await hashPasswordValues(aliasedData, passwordFields);
|
|
7378
7389
|
}
|
|
7379
7390
|
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
@@ -7385,46 +7396,48 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7385
7396
|
normalizedPath,
|
|
7386
7397
|
collectionPath || ""
|
|
7387
7398
|
);
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
|
|
7404
|
-
|
|
7405
|
-
|
|
7406
|
-
|
|
7407
|
-
|
|
7408
|
-
|
|
7409
|
-
|
|
7410
|
-
|
|
7411
|
-
|
|
7412
|
-
|
|
7413
|
-
|
|
7414
|
-
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7399
|
+
if (isPartialReindex) {
|
|
7400
|
+
const item = await rootSublevel.get(normalizedPath);
|
|
7401
|
+
if (item) {
|
|
7402
|
+
await database.contentLevel.batch([
|
|
7403
|
+
...makeRefOpsForDocument(
|
|
7404
|
+
normalizedPath,
|
|
7405
|
+
collection?.name,
|
|
7406
|
+
collectionReferences,
|
|
7407
|
+
item,
|
|
7408
|
+
"del",
|
|
7409
|
+
level
|
|
7410
|
+
),
|
|
7411
|
+
...makeIndexOpsForDocument(
|
|
7412
|
+
normalizedPath,
|
|
7413
|
+
collection.name,
|
|
7414
|
+
collectionIndexDefinitions,
|
|
7415
|
+
item,
|
|
7416
|
+
"del",
|
|
7417
|
+
level
|
|
7418
|
+
),
|
|
7419
|
+
// folder indices
|
|
7420
|
+
...makeIndexOpsForDocument(
|
|
7421
|
+
normalizedPath,
|
|
7422
|
+
`${collection.name}_${folderKey}`,
|
|
7423
|
+
collectionIndexDefinitions,
|
|
7424
|
+
item,
|
|
7425
|
+
"del",
|
|
7426
|
+
level
|
|
7427
|
+
),
|
|
7428
|
+
{
|
|
7429
|
+
type: "del",
|
|
7430
|
+
key: normalizedPath,
|
|
7431
|
+
sublevel: rootSublevel
|
|
7432
|
+
}
|
|
7433
|
+
]);
|
|
7434
|
+
}
|
|
7422
7435
|
}
|
|
7423
7436
|
if (!isGitKeep(filepath, collection)) {
|
|
7424
7437
|
await enqueueOps([
|
|
7425
7438
|
...makeRefOpsForDocument(
|
|
7426
7439
|
normalizedPath,
|
|
7427
|
-
collection
|
|
7440
|
+
collection?.name,
|
|
7428
7441
|
collectionReferences,
|
|
7429
7442
|
aliasedData,
|
|
7430
7443
|
"put",
|
|
@@ -7432,7 +7445,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7432
7445
|
),
|
|
7433
7446
|
...makeIndexOpsForDocument(
|
|
7434
7447
|
normalizedPath,
|
|
7435
|
-
collection
|
|
7448
|
+
collection?.name,
|
|
7436
7449
|
collectionIndexDefinitions,
|
|
7437
7450
|
aliasedData,
|
|
7438
7451
|
"put",
|
|
@@ -7441,7 +7454,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7441
7454
|
// folder indexes
|
|
7442
7455
|
...makeIndexOpsForDocument(
|
|
7443
7456
|
normalizedPath,
|
|
7444
|
-
`${collection
|
|
7457
|
+
`${collection?.name}_${folderKey}`,
|
|
7445
7458
|
collectionIndexDefinitions,
|
|
7446
7459
|
aliasedData,
|
|
7447
7460
|
"put",
|
|
@@ -7462,8 +7475,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7462
7475
|
throw new TinaFetchError(`Unable to seed ${filepath}`, {
|
|
7463
7476
|
originalError: error,
|
|
7464
7477
|
file: filepath,
|
|
7465
|
-
collection: collection
|
|
7466
|
-
stack: error.stack
|
|
7478
|
+
collection: collection?.name
|
|
7467
7479
|
});
|
|
7468
7480
|
}
|
|
7469
7481
|
});
|
|
@@ -7480,7 +7492,6 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7480
7492
|
}
|
|
7481
7493
|
};
|
|
7482
7494
|
var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection) => {
|
|
7483
|
-
var _a;
|
|
7484
7495
|
if (!documentPaths.length) {
|
|
7485
7496
|
return;
|
|
7486
7497
|
}
|
|
@@ -7489,12 +7500,12 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7489
7500
|
const indexDefinitions = await database.getIndexDefinitions(
|
|
7490
7501
|
database.contentLevel
|
|
7491
7502
|
);
|
|
7492
|
-
collectionIndexDefinitions = indexDefinitions
|
|
7503
|
+
collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
7493
7504
|
if (!collectionIndexDefinitions) {
|
|
7494
7505
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
7495
7506
|
}
|
|
7496
7507
|
}
|
|
7497
|
-
const collectionReferences = (
|
|
7508
|
+
const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
|
|
7498
7509
|
const tinaSchema = await database.getSchema();
|
|
7499
7510
|
let templateInfo = null;
|
|
7500
7511
|
if (collection) {
|
|
@@ -7511,7 +7522,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7511
7522
|
if (item) {
|
|
7512
7523
|
const folderKey = folderTreeBuilder.update(
|
|
7513
7524
|
itemKey,
|
|
7514
|
-
|
|
7525
|
+
collection?.path || ""
|
|
7515
7526
|
);
|
|
7516
7527
|
const aliasedData = templateInfo ? replaceNameOverrides(
|
|
7517
7528
|
getTemplateForFile(templateInfo, item),
|
|
@@ -7520,7 +7531,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7520
7531
|
await enqueueOps([
|
|
7521
7532
|
...makeRefOpsForDocument(
|
|
7522
7533
|
itemKey,
|
|
7523
|
-
collection
|
|
7534
|
+
collection?.name,
|
|
7524
7535
|
collectionReferences,
|
|
7525
7536
|
aliasedData,
|
|
7526
7537
|
"del",
|
|
@@ -7537,7 +7548,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7537
7548
|
// folder indexes
|
|
7538
7549
|
...makeIndexOpsForDocument(
|
|
7539
7550
|
itemKey,
|
|
7540
|
-
`${collection
|
|
7551
|
+
`${collection?.name}_${folderKey}`,
|
|
7541
7552
|
collectionIndexDefinitions,
|
|
7542
7553
|
aliasedData,
|
|
7543
7554
|
"del",
|
|
@@ -7622,12 +7633,12 @@ var getChangedFiles = async ({
|
|
|
7622
7633
|
}
|
|
7623
7634
|
}
|
|
7624
7635
|
}
|
|
7625
|
-
if (await
|
|
7636
|
+
if (await B?.type() === "tree") {
|
|
7626
7637
|
return;
|
|
7627
7638
|
}
|
|
7628
7639
|
if (matches) {
|
|
7629
|
-
const oidA = await
|
|
7630
|
-
const oidB = await
|
|
7640
|
+
const oidA = await A?.oid();
|
|
7641
|
+
const oidB = await B?.oid();
|
|
7631
7642
|
if (oidA !== oidB) {
|
|
7632
7643
|
if (oidA === void 0) {
|
|
7633
7644
|
results.added.push(relativePath);
|
|
@@ -7655,8 +7666,8 @@ var import_path5 = __toESM(require("path"));
|
|
|
7655
7666
|
var import_normalize_path = __toESM(require("normalize-path"));
|
|
7656
7667
|
var FilesystemBridge = class {
|
|
7657
7668
|
constructor(rootPath, outputPath) {
|
|
7658
|
-
this.rootPath = rootPath
|
|
7659
|
-
this.outputPath = outputPath
|
|
7669
|
+
this.rootPath = import_path5.default.resolve(rootPath);
|
|
7670
|
+
this.outputPath = outputPath ? import_path5.default.resolve(outputPath) : this.rootPath;
|
|
7660
7671
|
}
|
|
7661
7672
|
async glob(pattern, extension) {
|
|
7662
7673
|
const basePath = import_path5.default.join(this.outputPath, ...pattern.split("/"));
|
|
@@ -7668,19 +7679,19 @@ var FilesystemBridge = class {
|
|
|
7668
7679
|
}
|
|
7669
7680
|
);
|
|
7670
7681
|
const posixRootPath = (0, import_normalize_path.default)(this.outputPath);
|
|
7671
|
-
return items.map(
|
|
7672
|
-
|
|
7673
|
-
|
|
7682
|
+
return items.map(
|
|
7683
|
+
(item) => item.substring(posixRootPath.length).replace(/^\/|\/$/g, "")
|
|
7684
|
+
);
|
|
7674
7685
|
}
|
|
7675
7686
|
async delete(filepath) {
|
|
7676
7687
|
await import_fs_extra2.default.remove(import_path5.default.join(this.outputPath, filepath));
|
|
7677
7688
|
}
|
|
7678
7689
|
async get(filepath) {
|
|
7679
|
-
return import_fs_extra2.default.
|
|
7690
|
+
return (await import_fs_extra2.default.readFile(import_path5.default.join(this.outputPath, filepath))).toString();
|
|
7680
7691
|
}
|
|
7681
7692
|
async put(filepath, data, basePathOverride) {
|
|
7682
7693
|
const basePath = basePathOverride || this.outputPath;
|
|
7683
|
-
await import_fs_extra2.default.
|
|
7694
|
+
await import_fs_extra2.default.outputFile(import_path5.default.join(basePath, filepath), data);
|
|
7684
7695
|
}
|
|
7685
7696
|
};
|
|
7686
7697
|
var AuditFileSystemBridge = class extends FilesystemBridge {
|