@tinacms/graphql 1.5.18 → 1.5.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/database/util.d.ts +2 -2
- package/dist/index.js +243 -245
- package/dist/index.mjs +244 -246
- package/dist/mdx/index.d.ts +2 -7
- package/dist/resolver/index.d.ts +1 -1
- package/package.json +4 -4
package/dist/database/util.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Collection, CollectionTemplateable, TinaSchema, normalizePath } from '@tinacms/schema-tools';
|
|
1
2
|
import * as yup from 'yup';
|
|
2
|
-
import { Collection, CollectionTemplateable, normalizePath, TinaSchema } from '@tinacms/schema-tools';
|
|
3
|
-
import { Bridge } from './bridge';
|
|
4
3
|
import { ContentFormat, ContentFrontmatterFormat } from '@tinacms/schema-tools';
|
|
4
|
+
import { Bridge } from './bridge';
|
|
5
5
|
export { normalizePath };
|
|
6
6
|
export declare const stringifyFile: (content: object, format: ContentFormat | string, keepTemplateKey: boolean, markdownParseConfig?: {
|
|
7
7
|
frontmatterFormat?: ContentFrontmatterFormat;
|
package/dist/index.js
CHANGED
|
@@ -3083,7 +3083,7 @@ var validateField = async (field) => {
|
|
|
3083
3083
|
// package.json
|
|
3084
3084
|
var package_default = {
|
|
3085
3085
|
name: "@tinacms/graphql",
|
|
3086
|
-
version: "1.5.
|
|
3086
|
+
version: "1.5.19",
|
|
3087
3087
|
main: "dist/index.js",
|
|
3088
3088
|
module: "dist/index.mjs",
|
|
3089
3089
|
typings: "dist/index.d.ts",
|
|
@@ -3374,250 +3374,11 @@ var import_graphql5 = require("graphql");
|
|
|
3374
3374
|
// src/resolver/index.ts
|
|
3375
3375
|
var import_path3 = __toESM(require("path"));
|
|
3376
3376
|
var import_isValid = __toESM(require("date-fns/isValid/index.js"));
|
|
3377
|
+
var import_jsonpath_plus2 = require("jsonpath-plus");
|
|
3377
3378
|
|
|
3378
3379
|
// src/mdx/index.ts
|
|
3379
3380
|
var import_mdx = require("@tinacms/mdx");
|
|
3380
3381
|
|
|
3381
|
-
// src/resolver/index.ts
|
|
3382
|
-
var import_jsonpath_plus2 = require("jsonpath-plus");
|
|
3383
|
-
|
|
3384
|
-
// src/resolver/error.ts
|
|
3385
|
-
var TinaGraphQLError = class extends Error {
|
|
3386
|
-
constructor(message, extensions) {
|
|
3387
|
-
super(message);
|
|
3388
|
-
if (!this.name) {
|
|
3389
|
-
Object.defineProperty(this, "name", { value: "TinaGraphQLError" });
|
|
3390
|
-
}
|
|
3391
|
-
this.extensions = { ...extensions };
|
|
3392
|
-
}
|
|
3393
|
-
};
|
|
3394
|
-
var TinaFetchError = class extends Error {
|
|
3395
|
-
constructor(message, args) {
|
|
3396
|
-
super(message);
|
|
3397
|
-
this.name = "TinaFetchError";
|
|
3398
|
-
this.collection = args.collection;
|
|
3399
|
-
this.stack = args.stack;
|
|
3400
|
-
this.file = args.file;
|
|
3401
|
-
this.originalError = args.originalError;
|
|
3402
|
-
}
|
|
3403
|
-
};
|
|
3404
|
-
var TinaQueryError = class extends TinaFetchError {
|
|
3405
|
-
constructor(args) {
|
|
3406
|
-
super(
|
|
3407
|
-
`Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
3408
|
-
args
|
|
3409
|
-
);
|
|
3410
|
-
}
|
|
3411
|
-
};
|
|
3412
|
-
var TinaParseDocumentError = class extends TinaFetchError {
|
|
3413
|
-
constructor(args) {
|
|
3414
|
-
super(
|
|
3415
|
-
`Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
3416
|
-
args
|
|
3417
|
-
);
|
|
3418
|
-
}
|
|
3419
|
-
toString() {
|
|
3420
|
-
return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
|
|
3421
|
-
}
|
|
3422
|
-
};
|
|
3423
|
-
var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
|
|
3424
|
-
var handleFetchErrorError = (e, verbose) => {
|
|
3425
|
-
if (e instanceof Error) {
|
|
3426
|
-
if (e instanceof TinaFetchError) {
|
|
3427
|
-
if (verbose) {
|
|
3428
|
-
console.log(e.toString());
|
|
3429
|
-
console.log(e);
|
|
3430
|
-
console.log(e.stack);
|
|
3431
|
-
}
|
|
3432
|
-
}
|
|
3433
|
-
} else {
|
|
3434
|
-
console.error(e);
|
|
3435
|
-
}
|
|
3436
|
-
throw e;
|
|
3437
|
-
};
|
|
3438
|
-
|
|
3439
|
-
// src/resolver/filter-utils.ts
|
|
3440
|
-
var resolveReferences = async (filter, fields, resolver) => {
|
|
3441
|
-
for (const fieldKey of Object.keys(filter)) {
|
|
3442
|
-
const fieldDefinition = fields.find(
|
|
3443
|
-
(f) => f.name === fieldKey
|
|
3444
|
-
);
|
|
3445
|
-
if (fieldDefinition) {
|
|
3446
|
-
if (fieldDefinition.type === "reference") {
|
|
3447
|
-
const { edges, values } = await resolver(filter, fieldDefinition);
|
|
3448
|
-
if (edges.length === 1) {
|
|
3449
|
-
filter[fieldKey] = {
|
|
3450
|
-
eq: values[0]
|
|
3451
|
-
};
|
|
3452
|
-
} else if (edges.length > 1) {
|
|
3453
|
-
filter[fieldKey] = {
|
|
3454
|
-
in: values
|
|
3455
|
-
};
|
|
3456
|
-
} else {
|
|
3457
|
-
filter[fieldKey] = {
|
|
3458
|
-
eq: "___null___"
|
|
3459
|
-
};
|
|
3460
|
-
}
|
|
3461
|
-
} else if (fieldDefinition.type === "object") {
|
|
3462
|
-
if (fieldDefinition.templates) {
|
|
3463
|
-
for (const templateName of Object.keys(filter[fieldKey])) {
|
|
3464
|
-
const template = fieldDefinition.templates.find(
|
|
3465
|
-
(template2) => !(typeof template2 === "string") && template2.name === templateName
|
|
3466
|
-
);
|
|
3467
|
-
if (template) {
|
|
3468
|
-
await resolveReferences(
|
|
3469
|
-
filter[fieldKey][templateName],
|
|
3470
|
-
template.fields,
|
|
3471
|
-
resolver
|
|
3472
|
-
);
|
|
3473
|
-
} else {
|
|
3474
|
-
throw new Error(`Template ${templateName} not found`);
|
|
3475
|
-
}
|
|
3476
|
-
}
|
|
3477
|
-
} else {
|
|
3478
|
-
await resolveReferences(
|
|
3479
|
-
filter[fieldKey],
|
|
3480
|
-
fieldDefinition.fields,
|
|
3481
|
-
resolver
|
|
3482
|
-
);
|
|
3483
|
-
}
|
|
3484
|
-
}
|
|
3485
|
-
} else {
|
|
3486
|
-
throw new Error(`Unable to find field ${fieldKey}`);
|
|
3487
|
-
}
|
|
3488
|
-
}
|
|
3489
|
-
};
|
|
3490
|
-
var collectConditionsForChildFields = (filterNode, fields, pathExpression, collectCondition) => {
|
|
3491
|
-
for (const childFieldName of Object.keys(filterNode)) {
|
|
3492
|
-
const childField = fields.find((field) => field.name === childFieldName);
|
|
3493
|
-
if (!childField) {
|
|
3494
|
-
throw new Error(`Unable to find type for field ${childFieldName}`);
|
|
3495
|
-
}
|
|
3496
|
-
collectConditionsForField(
|
|
3497
|
-
childFieldName,
|
|
3498
|
-
childField,
|
|
3499
|
-
filterNode[childFieldName],
|
|
3500
|
-
pathExpression,
|
|
3501
|
-
collectCondition
|
|
3502
|
-
);
|
|
3503
|
-
}
|
|
3504
|
-
};
|
|
3505
|
-
var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
3506
|
-
if (field.list && field.templates) {
|
|
3507
|
-
for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
|
|
3508
|
-
const template = field.templates.find(
|
|
3509
|
-
(template2) => !(typeof template2 === "string") && template2.name === filterKey
|
|
3510
|
-
);
|
|
3511
|
-
const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
|
|
3512
|
-
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
|
|
3513
|
-
collectConditionsForChildFields(
|
|
3514
|
-
childFilterNode,
|
|
3515
|
-
template.fields,
|
|
3516
|
-
filterPath,
|
|
3517
|
-
collectCondition
|
|
3518
|
-
);
|
|
3519
|
-
}
|
|
3520
|
-
} else {
|
|
3521
|
-
const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
|
|
3522
|
-
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
|
|
3523
|
-
collectConditionsForChildFields(
|
|
3524
|
-
filterNode,
|
|
3525
|
-
field.fields,
|
|
3526
|
-
filterPath,
|
|
3527
|
-
collectCondition
|
|
3528
|
-
);
|
|
3529
|
-
}
|
|
3530
|
-
};
|
|
3531
|
-
var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
3532
|
-
if (field.type === "object") {
|
|
3533
|
-
collectConditionsForObjectField(
|
|
3534
|
-
fieldName,
|
|
3535
|
-
field,
|
|
3536
|
-
filterNode,
|
|
3537
|
-
pathExpression,
|
|
3538
|
-
collectCondition
|
|
3539
|
-
);
|
|
3540
|
-
} else {
|
|
3541
|
-
collectCondition({
|
|
3542
|
-
filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
|
|
3543
|
-
filterExpression: {
|
|
3544
|
-
_type: field.type,
|
|
3545
|
-
_list: !!field.list,
|
|
3546
|
-
...filterNode
|
|
3547
|
-
}
|
|
3548
|
-
});
|
|
3549
|
-
}
|
|
3550
|
-
};
|
|
3551
|
-
|
|
3552
|
-
// src/resolver/media-utils.ts
|
|
3553
|
-
var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, schema) => {
|
|
3554
|
-
if (config && value) {
|
|
3555
|
-
if (config.useRelativeMedia === true) {
|
|
3556
|
-
return value;
|
|
3557
|
-
}
|
|
3558
|
-
if (hasTinaMediaConfig(schema) === true) {
|
|
3559
|
-
const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
|
|
3560
|
-
if (typeof value === "string" && value.includes(assetsURL)) {
|
|
3561
|
-
const cleanMediaRoot = cleanUpSlashes(
|
|
3562
|
-
schema.config.media.tina.mediaRoot
|
|
3563
|
-
);
|
|
3564
|
-
const strippedURL = value.replace(assetsURL, "");
|
|
3565
|
-
return `${cleanMediaRoot}${strippedURL}`;
|
|
3566
|
-
}
|
|
3567
|
-
if (Array.isArray(value)) {
|
|
3568
|
-
return value.map((v) => {
|
|
3569
|
-
if (!v || typeof v !== "string") return v;
|
|
3570
|
-
const cleanMediaRoot = cleanUpSlashes(
|
|
3571
|
-
schema.config.media.tina.mediaRoot
|
|
3572
|
-
);
|
|
3573
|
-
const strippedURL = v.replace(assetsURL, "");
|
|
3574
|
-
return `${cleanMediaRoot}${strippedURL}`;
|
|
3575
|
-
});
|
|
3576
|
-
}
|
|
3577
|
-
return value;
|
|
3578
|
-
}
|
|
3579
|
-
return value;
|
|
3580
|
-
} else {
|
|
3581
|
-
return value;
|
|
3582
|
-
}
|
|
3583
|
-
};
|
|
3584
|
-
var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, schema) => {
|
|
3585
|
-
if (config && value) {
|
|
3586
|
-
if (config.useRelativeMedia === true) {
|
|
3587
|
-
return value;
|
|
3588
|
-
}
|
|
3589
|
-
if (hasTinaMediaConfig(schema) === true) {
|
|
3590
|
-
const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
|
|
3591
|
-
if (typeof value === "string") {
|
|
3592
|
-
const strippedValue = value.replace(cleanMediaRoot, "");
|
|
3593
|
-
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
3594
|
-
}
|
|
3595
|
-
if (Array.isArray(value)) {
|
|
3596
|
-
return value.map((v) => {
|
|
3597
|
-
if (!v || typeof v !== "string") return v;
|
|
3598
|
-
const strippedValue = v.replace(cleanMediaRoot, "");
|
|
3599
|
-
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
3600
|
-
});
|
|
3601
|
-
}
|
|
3602
|
-
}
|
|
3603
|
-
return value;
|
|
3604
|
-
} else {
|
|
3605
|
-
return value;
|
|
3606
|
-
}
|
|
3607
|
-
};
|
|
3608
|
-
var cleanUpSlashes = (path7) => {
|
|
3609
|
-
if (path7) {
|
|
3610
|
-
return `/${path7.replace(/^\/+|\/+$/gm, "")}`;
|
|
3611
|
-
}
|
|
3612
|
-
return "";
|
|
3613
|
-
};
|
|
3614
|
-
var hasTinaMediaConfig = (schema) => {
|
|
3615
|
-
if (!schema.config?.media?.tina) return false;
|
|
3616
|
-
if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
|
|
3617
|
-
return false;
|
|
3618
|
-
return true;
|
|
3619
|
-
};
|
|
3620
|
-
|
|
3621
3382
|
// src/resolver/index.ts
|
|
3622
3383
|
var import_graphql3 = require("graphql");
|
|
3623
3384
|
|
|
@@ -3679,11 +3440,11 @@ var import_path2 = __toESM(require("path"));
|
|
|
3679
3440
|
|
|
3680
3441
|
// src/database/util.ts
|
|
3681
3442
|
var import_toml = __toESM(require("@iarna/toml"));
|
|
3682
|
-
var import_js_yaml = __toESM(require("js-yaml"));
|
|
3683
|
-
var import_gray_matter = __toESM(require("gray-matter"));
|
|
3684
3443
|
var import_schema_tools4 = require("@tinacms/schema-tools");
|
|
3685
|
-
var
|
|
3444
|
+
var import_gray_matter = __toESM(require("gray-matter"));
|
|
3445
|
+
var import_js_yaml = __toESM(require("js-yaml"));
|
|
3686
3446
|
var import_path = __toESM(require("path"));
|
|
3447
|
+
var import_micromatch = __toESM(require("micromatch"));
|
|
3687
3448
|
|
|
3688
3449
|
// src/database/alias-utils.ts
|
|
3689
3450
|
var replaceBlockAliases = (template, item) => {
|
|
@@ -4671,6 +4432,243 @@ var stringEscaper = makeStringEscaper(
|
|
|
4671
4432
|
encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR)
|
|
4672
4433
|
);
|
|
4673
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.stack = args.stack;
|
|
4451
|
+
this.file = args.file;
|
|
4452
|
+
this.originalError = args.originalError;
|
|
4453
|
+
}
|
|
4454
|
+
};
|
|
4455
|
+
var TinaQueryError = class extends TinaFetchError {
|
|
4456
|
+
constructor(args) {
|
|
4457
|
+
super(
|
|
4458
|
+
`Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
4459
|
+
args
|
|
4460
|
+
);
|
|
4461
|
+
}
|
|
4462
|
+
};
|
|
4463
|
+
var TinaParseDocumentError = class extends TinaFetchError {
|
|
4464
|
+
constructor(args) {
|
|
4465
|
+
super(
|
|
4466
|
+
`Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
4467
|
+
args
|
|
4468
|
+
);
|
|
4469
|
+
}
|
|
4470
|
+
toString() {
|
|
4471
|
+
return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
|
|
4472
|
+
}
|
|
4473
|
+
};
|
|
4474
|
+
var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
|
|
4475
|
+
var handleFetchErrorError = (e, verbose) => {
|
|
4476
|
+
if (e instanceof Error) {
|
|
4477
|
+
if (e instanceof TinaFetchError) {
|
|
4478
|
+
if (verbose) {
|
|
4479
|
+
console.log(e.toString());
|
|
4480
|
+
console.log(e);
|
|
4481
|
+
console.log(e.stack);
|
|
4482
|
+
}
|
|
4483
|
+
}
|
|
4484
|
+
} else {
|
|
4485
|
+
console.error(e);
|
|
4486
|
+
}
|
|
4487
|
+
throw e;
|
|
4488
|
+
};
|
|
4489
|
+
|
|
4490
|
+
// src/resolver/filter-utils.ts
|
|
4491
|
+
var resolveReferences = async (filter, fields, resolver) => {
|
|
4492
|
+
for (const fieldKey of Object.keys(filter)) {
|
|
4493
|
+
const fieldDefinition = fields.find(
|
|
4494
|
+
(f) => f.name === fieldKey
|
|
4495
|
+
);
|
|
4496
|
+
if (fieldDefinition) {
|
|
4497
|
+
if (fieldDefinition.type === "reference") {
|
|
4498
|
+
const { edges, values } = await resolver(filter, fieldDefinition);
|
|
4499
|
+
if (edges.length === 1) {
|
|
4500
|
+
filter[fieldKey] = {
|
|
4501
|
+
eq: values[0]
|
|
4502
|
+
};
|
|
4503
|
+
} else if (edges.length > 1) {
|
|
4504
|
+
filter[fieldKey] = {
|
|
4505
|
+
in: values
|
|
4506
|
+
};
|
|
4507
|
+
} else {
|
|
4508
|
+
filter[fieldKey] = {
|
|
4509
|
+
eq: "___null___"
|
|
4510
|
+
};
|
|
4511
|
+
}
|
|
4512
|
+
} else if (fieldDefinition.type === "object") {
|
|
4513
|
+
if (fieldDefinition.templates) {
|
|
4514
|
+
for (const templateName of Object.keys(filter[fieldKey])) {
|
|
4515
|
+
const template = fieldDefinition.templates.find(
|
|
4516
|
+
(template2) => !(typeof template2 === "string") && template2.name === templateName
|
|
4517
|
+
);
|
|
4518
|
+
if (template) {
|
|
4519
|
+
await resolveReferences(
|
|
4520
|
+
filter[fieldKey][templateName],
|
|
4521
|
+
template.fields,
|
|
4522
|
+
resolver
|
|
4523
|
+
);
|
|
4524
|
+
} else {
|
|
4525
|
+
throw new Error(`Template ${templateName} not found`);
|
|
4526
|
+
}
|
|
4527
|
+
}
|
|
4528
|
+
} else {
|
|
4529
|
+
await resolveReferences(
|
|
4530
|
+
filter[fieldKey],
|
|
4531
|
+
fieldDefinition.fields,
|
|
4532
|
+
resolver
|
|
4533
|
+
);
|
|
4534
|
+
}
|
|
4535
|
+
}
|
|
4536
|
+
} else {
|
|
4537
|
+
throw new Error(`Unable to find field ${fieldKey}`);
|
|
4538
|
+
}
|
|
4539
|
+
}
|
|
4540
|
+
};
|
|
4541
|
+
var collectConditionsForChildFields = (filterNode, fields, pathExpression, collectCondition) => {
|
|
4542
|
+
for (const childFieldName of Object.keys(filterNode)) {
|
|
4543
|
+
const childField = fields.find((field) => field.name === childFieldName);
|
|
4544
|
+
if (!childField) {
|
|
4545
|
+
throw new Error(`Unable to find type for field ${childFieldName}`);
|
|
4546
|
+
}
|
|
4547
|
+
collectConditionsForField(
|
|
4548
|
+
childFieldName,
|
|
4549
|
+
childField,
|
|
4550
|
+
filterNode[childFieldName],
|
|
4551
|
+
pathExpression,
|
|
4552
|
+
collectCondition
|
|
4553
|
+
);
|
|
4554
|
+
}
|
|
4555
|
+
};
|
|
4556
|
+
var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
4557
|
+
if (field.list && field.templates) {
|
|
4558
|
+
for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
|
|
4559
|
+
const template = field.templates.find(
|
|
4560
|
+
(template2) => !(typeof template2 === "string") && template2.name === filterKey
|
|
4561
|
+
);
|
|
4562
|
+
const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
|
|
4563
|
+
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
|
|
4564
|
+
collectConditionsForChildFields(
|
|
4565
|
+
childFilterNode,
|
|
4566
|
+
template.fields,
|
|
4567
|
+
filterPath,
|
|
4568
|
+
collectCondition
|
|
4569
|
+
);
|
|
4570
|
+
}
|
|
4571
|
+
} else {
|
|
4572
|
+
const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
|
|
4573
|
+
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
|
|
4574
|
+
collectConditionsForChildFields(
|
|
4575
|
+
filterNode,
|
|
4576
|
+
field.fields,
|
|
4577
|
+
filterPath,
|
|
4578
|
+
collectCondition
|
|
4579
|
+
);
|
|
4580
|
+
}
|
|
4581
|
+
};
|
|
4582
|
+
var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
4583
|
+
if (field.type === "object") {
|
|
4584
|
+
collectConditionsForObjectField(
|
|
4585
|
+
fieldName,
|
|
4586
|
+
field,
|
|
4587
|
+
filterNode,
|
|
4588
|
+
pathExpression,
|
|
4589
|
+
collectCondition
|
|
4590
|
+
);
|
|
4591
|
+
} else {
|
|
4592
|
+
collectCondition({
|
|
4593
|
+
filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
|
|
4594
|
+
filterExpression: {
|
|
4595
|
+
_type: field.type,
|
|
4596
|
+
_list: !!field.list,
|
|
4597
|
+
...filterNode
|
|
4598
|
+
}
|
|
4599
|
+
});
|
|
4600
|
+
}
|
|
4601
|
+
};
|
|
4602
|
+
|
|
4603
|
+
// src/resolver/media-utils.ts
|
|
4604
|
+
var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, schema) => {
|
|
4605
|
+
if (config && value) {
|
|
4606
|
+
if (config.useRelativeMedia === true) {
|
|
4607
|
+
return value;
|
|
4608
|
+
}
|
|
4609
|
+
if (hasTinaMediaConfig(schema) === true) {
|
|
4610
|
+
const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
|
|
4611
|
+
if (typeof value === "string" && value.includes(assetsURL)) {
|
|
4612
|
+
const cleanMediaRoot = cleanUpSlashes(
|
|
4613
|
+
schema.config.media.tina.mediaRoot
|
|
4614
|
+
);
|
|
4615
|
+
const strippedURL = value.replace(assetsURL, "");
|
|
4616
|
+
return `${cleanMediaRoot}${strippedURL}`;
|
|
4617
|
+
}
|
|
4618
|
+
if (Array.isArray(value)) {
|
|
4619
|
+
return value.map((v) => {
|
|
4620
|
+
if (!v || typeof v !== "string") return v;
|
|
4621
|
+
const cleanMediaRoot = cleanUpSlashes(
|
|
4622
|
+
schema.config.media.tina.mediaRoot
|
|
4623
|
+
);
|
|
4624
|
+
const strippedURL = v.replace(assetsURL, "");
|
|
4625
|
+
return `${cleanMediaRoot}${strippedURL}`;
|
|
4626
|
+
});
|
|
4627
|
+
}
|
|
4628
|
+
return value;
|
|
4629
|
+
}
|
|
4630
|
+
return value;
|
|
4631
|
+
} else {
|
|
4632
|
+
return value;
|
|
4633
|
+
}
|
|
4634
|
+
};
|
|
4635
|
+
var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, schema) => {
|
|
4636
|
+
if (config && value) {
|
|
4637
|
+
if (config.useRelativeMedia === true) {
|
|
4638
|
+
return value;
|
|
4639
|
+
}
|
|
4640
|
+
if (hasTinaMediaConfig(schema) === true) {
|
|
4641
|
+
const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
|
|
4642
|
+
if (typeof value === "string") {
|
|
4643
|
+
const strippedValue = value.replace(cleanMediaRoot, "");
|
|
4644
|
+
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
4645
|
+
}
|
|
4646
|
+
if (Array.isArray(value)) {
|
|
4647
|
+
return value.map((v) => {
|
|
4648
|
+
if (!v || typeof v !== "string") return v;
|
|
4649
|
+
const strippedValue = v.replace(cleanMediaRoot, "");
|
|
4650
|
+
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
4651
|
+
});
|
|
4652
|
+
}
|
|
4653
|
+
}
|
|
4654
|
+
return value;
|
|
4655
|
+
} else {
|
|
4656
|
+
return value;
|
|
4657
|
+
}
|
|
4658
|
+
};
|
|
4659
|
+
var cleanUpSlashes = (path7) => {
|
|
4660
|
+
if (path7) {
|
|
4661
|
+
return `/${path7.replace(/^\/+|\/+$/gm, "")}`;
|
|
4662
|
+
}
|
|
4663
|
+
return "";
|
|
4664
|
+
};
|
|
4665
|
+
var hasTinaMediaConfig = (schema) => {
|
|
4666
|
+
if (!schema.config?.media?.tina) return false;
|
|
4667
|
+
if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
|
|
4668
|
+
return false;
|
|
4669
|
+
return true;
|
|
4670
|
+
};
|
|
4671
|
+
|
|
4674
4672
|
// src/resolver/index.ts
|
|
4675
4673
|
var createResolver = (args) => {
|
|
4676
4674
|
return new Resolver(args);
|
|
@@ -5636,7 +5634,7 @@ var Resolver = class {
|
|
|
5636
5634
|
}
|
|
5637
5635
|
break;
|
|
5638
5636
|
case "rich-text":
|
|
5639
|
-
accum[fieldName] = (0, import_mdx.
|
|
5637
|
+
accum[fieldName] = (0, import_mdx.serializeMDX)(
|
|
5640
5638
|
fieldValue,
|
|
5641
5639
|
field,
|
|
5642
5640
|
(fieldValue2) => resolveMediaCloudToRelative(
|
package/dist/index.mjs
CHANGED
|
@@ -3019,7 +3019,7 @@ var validateField = async (field) => {
|
|
|
3019
3019
|
// package.json
|
|
3020
3020
|
var package_default = {
|
|
3021
3021
|
name: "@tinacms/graphql",
|
|
3022
|
-
version: "1.5.
|
|
3022
|
+
version: "1.5.19",
|
|
3023
3023
|
main: "dist/index.js",
|
|
3024
3024
|
module: "dist/index.mjs",
|
|
3025
3025
|
typings: "dist/index.d.ts",
|
|
@@ -3310,249 +3310,10 @@ import { graphql, buildASTSchema, getNamedType, GraphQLError as GraphQLError4 }
|
|
|
3310
3310
|
// src/resolver/index.ts
|
|
3311
3311
|
import path3 from "path";
|
|
3312
3312
|
import isValid from "date-fns/isValid/index.js";
|
|
3313
|
-
|
|
3314
|
-
// src/mdx/index.ts
|
|
3315
|
-
import { parseMDX, stringifyMDX } from "@tinacms/mdx";
|
|
3316
|
-
|
|
3317
|
-
// src/resolver/index.ts
|
|
3318
3313
|
import { JSONPath as JSONPath2 } from "jsonpath-plus";
|
|
3319
3314
|
|
|
3320
|
-
// src/
|
|
3321
|
-
|
|
3322
|
-
constructor(message, extensions) {
|
|
3323
|
-
super(message);
|
|
3324
|
-
if (!this.name) {
|
|
3325
|
-
Object.defineProperty(this, "name", { value: "TinaGraphQLError" });
|
|
3326
|
-
}
|
|
3327
|
-
this.extensions = { ...extensions };
|
|
3328
|
-
}
|
|
3329
|
-
};
|
|
3330
|
-
var TinaFetchError = class extends Error {
|
|
3331
|
-
constructor(message, args) {
|
|
3332
|
-
super(message);
|
|
3333
|
-
this.name = "TinaFetchError";
|
|
3334
|
-
this.collection = args.collection;
|
|
3335
|
-
this.stack = args.stack;
|
|
3336
|
-
this.file = args.file;
|
|
3337
|
-
this.originalError = args.originalError;
|
|
3338
|
-
}
|
|
3339
|
-
};
|
|
3340
|
-
var TinaQueryError = class extends TinaFetchError {
|
|
3341
|
-
constructor(args) {
|
|
3342
|
-
super(
|
|
3343
|
-
`Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
3344
|
-
args
|
|
3345
|
-
);
|
|
3346
|
-
}
|
|
3347
|
-
};
|
|
3348
|
-
var TinaParseDocumentError = class extends TinaFetchError {
|
|
3349
|
-
constructor(args) {
|
|
3350
|
-
super(
|
|
3351
|
-
`Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
3352
|
-
args
|
|
3353
|
-
);
|
|
3354
|
-
}
|
|
3355
|
-
toString() {
|
|
3356
|
-
return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
|
|
3357
|
-
}
|
|
3358
|
-
};
|
|
3359
|
-
var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
|
|
3360
|
-
var handleFetchErrorError = (e, verbose) => {
|
|
3361
|
-
if (e instanceof Error) {
|
|
3362
|
-
if (e instanceof TinaFetchError) {
|
|
3363
|
-
if (verbose) {
|
|
3364
|
-
console.log(e.toString());
|
|
3365
|
-
console.log(e);
|
|
3366
|
-
console.log(e.stack);
|
|
3367
|
-
}
|
|
3368
|
-
}
|
|
3369
|
-
} else {
|
|
3370
|
-
console.error(e);
|
|
3371
|
-
}
|
|
3372
|
-
throw e;
|
|
3373
|
-
};
|
|
3374
|
-
|
|
3375
|
-
// src/resolver/filter-utils.ts
|
|
3376
|
-
var resolveReferences = async (filter, fields, resolver) => {
|
|
3377
|
-
for (const fieldKey of Object.keys(filter)) {
|
|
3378
|
-
const fieldDefinition = fields.find(
|
|
3379
|
-
(f) => f.name === fieldKey
|
|
3380
|
-
);
|
|
3381
|
-
if (fieldDefinition) {
|
|
3382
|
-
if (fieldDefinition.type === "reference") {
|
|
3383
|
-
const { edges, values } = await resolver(filter, fieldDefinition);
|
|
3384
|
-
if (edges.length === 1) {
|
|
3385
|
-
filter[fieldKey] = {
|
|
3386
|
-
eq: values[0]
|
|
3387
|
-
};
|
|
3388
|
-
} else if (edges.length > 1) {
|
|
3389
|
-
filter[fieldKey] = {
|
|
3390
|
-
in: values
|
|
3391
|
-
};
|
|
3392
|
-
} else {
|
|
3393
|
-
filter[fieldKey] = {
|
|
3394
|
-
eq: "___null___"
|
|
3395
|
-
};
|
|
3396
|
-
}
|
|
3397
|
-
} else if (fieldDefinition.type === "object") {
|
|
3398
|
-
if (fieldDefinition.templates) {
|
|
3399
|
-
for (const templateName of Object.keys(filter[fieldKey])) {
|
|
3400
|
-
const template = fieldDefinition.templates.find(
|
|
3401
|
-
(template2) => !(typeof template2 === "string") && template2.name === templateName
|
|
3402
|
-
);
|
|
3403
|
-
if (template) {
|
|
3404
|
-
await resolveReferences(
|
|
3405
|
-
filter[fieldKey][templateName],
|
|
3406
|
-
template.fields,
|
|
3407
|
-
resolver
|
|
3408
|
-
);
|
|
3409
|
-
} else {
|
|
3410
|
-
throw new Error(`Template ${templateName} not found`);
|
|
3411
|
-
}
|
|
3412
|
-
}
|
|
3413
|
-
} else {
|
|
3414
|
-
await resolveReferences(
|
|
3415
|
-
filter[fieldKey],
|
|
3416
|
-
fieldDefinition.fields,
|
|
3417
|
-
resolver
|
|
3418
|
-
);
|
|
3419
|
-
}
|
|
3420
|
-
}
|
|
3421
|
-
} else {
|
|
3422
|
-
throw new Error(`Unable to find field ${fieldKey}`);
|
|
3423
|
-
}
|
|
3424
|
-
}
|
|
3425
|
-
};
|
|
3426
|
-
var collectConditionsForChildFields = (filterNode, fields, pathExpression, collectCondition) => {
|
|
3427
|
-
for (const childFieldName of Object.keys(filterNode)) {
|
|
3428
|
-
const childField = fields.find((field) => field.name === childFieldName);
|
|
3429
|
-
if (!childField) {
|
|
3430
|
-
throw new Error(`Unable to find type for field ${childFieldName}`);
|
|
3431
|
-
}
|
|
3432
|
-
collectConditionsForField(
|
|
3433
|
-
childFieldName,
|
|
3434
|
-
childField,
|
|
3435
|
-
filterNode[childFieldName],
|
|
3436
|
-
pathExpression,
|
|
3437
|
-
collectCondition
|
|
3438
|
-
);
|
|
3439
|
-
}
|
|
3440
|
-
};
|
|
3441
|
-
var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
3442
|
-
if (field.list && field.templates) {
|
|
3443
|
-
for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
|
|
3444
|
-
const template = field.templates.find(
|
|
3445
|
-
(template2) => !(typeof template2 === "string") && template2.name === filterKey
|
|
3446
|
-
);
|
|
3447
|
-
const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
|
|
3448
|
-
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
|
|
3449
|
-
collectConditionsForChildFields(
|
|
3450
|
-
childFilterNode,
|
|
3451
|
-
template.fields,
|
|
3452
|
-
filterPath,
|
|
3453
|
-
collectCondition
|
|
3454
|
-
);
|
|
3455
|
-
}
|
|
3456
|
-
} else {
|
|
3457
|
-
const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
|
|
3458
|
-
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
|
|
3459
|
-
collectConditionsForChildFields(
|
|
3460
|
-
filterNode,
|
|
3461
|
-
field.fields,
|
|
3462
|
-
filterPath,
|
|
3463
|
-
collectCondition
|
|
3464
|
-
);
|
|
3465
|
-
}
|
|
3466
|
-
};
|
|
3467
|
-
var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
3468
|
-
if (field.type === "object") {
|
|
3469
|
-
collectConditionsForObjectField(
|
|
3470
|
-
fieldName,
|
|
3471
|
-
field,
|
|
3472
|
-
filterNode,
|
|
3473
|
-
pathExpression,
|
|
3474
|
-
collectCondition
|
|
3475
|
-
);
|
|
3476
|
-
} else {
|
|
3477
|
-
collectCondition({
|
|
3478
|
-
filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
|
|
3479
|
-
filterExpression: {
|
|
3480
|
-
_type: field.type,
|
|
3481
|
-
_list: !!field.list,
|
|
3482
|
-
...filterNode
|
|
3483
|
-
}
|
|
3484
|
-
});
|
|
3485
|
-
}
|
|
3486
|
-
};
|
|
3487
|
-
|
|
3488
|
-
// src/resolver/media-utils.ts
|
|
3489
|
-
var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, schema) => {
|
|
3490
|
-
if (config && value) {
|
|
3491
|
-
if (config.useRelativeMedia === true) {
|
|
3492
|
-
return value;
|
|
3493
|
-
}
|
|
3494
|
-
if (hasTinaMediaConfig(schema) === true) {
|
|
3495
|
-
const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
|
|
3496
|
-
if (typeof value === "string" && value.includes(assetsURL)) {
|
|
3497
|
-
const cleanMediaRoot = cleanUpSlashes(
|
|
3498
|
-
schema.config.media.tina.mediaRoot
|
|
3499
|
-
);
|
|
3500
|
-
const strippedURL = value.replace(assetsURL, "");
|
|
3501
|
-
return `${cleanMediaRoot}${strippedURL}`;
|
|
3502
|
-
}
|
|
3503
|
-
if (Array.isArray(value)) {
|
|
3504
|
-
return value.map((v) => {
|
|
3505
|
-
if (!v || typeof v !== "string") return v;
|
|
3506
|
-
const cleanMediaRoot = cleanUpSlashes(
|
|
3507
|
-
schema.config.media.tina.mediaRoot
|
|
3508
|
-
);
|
|
3509
|
-
const strippedURL = v.replace(assetsURL, "");
|
|
3510
|
-
return `${cleanMediaRoot}${strippedURL}`;
|
|
3511
|
-
});
|
|
3512
|
-
}
|
|
3513
|
-
return value;
|
|
3514
|
-
}
|
|
3515
|
-
return value;
|
|
3516
|
-
} else {
|
|
3517
|
-
return value;
|
|
3518
|
-
}
|
|
3519
|
-
};
|
|
3520
|
-
var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, schema) => {
|
|
3521
|
-
if (config && value) {
|
|
3522
|
-
if (config.useRelativeMedia === true) {
|
|
3523
|
-
return value;
|
|
3524
|
-
}
|
|
3525
|
-
if (hasTinaMediaConfig(schema) === true) {
|
|
3526
|
-
const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
|
|
3527
|
-
if (typeof value === "string") {
|
|
3528
|
-
const strippedValue = value.replace(cleanMediaRoot, "");
|
|
3529
|
-
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
3530
|
-
}
|
|
3531
|
-
if (Array.isArray(value)) {
|
|
3532
|
-
return value.map((v) => {
|
|
3533
|
-
if (!v || typeof v !== "string") return v;
|
|
3534
|
-
const strippedValue = v.replace(cleanMediaRoot, "");
|
|
3535
|
-
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
3536
|
-
});
|
|
3537
|
-
}
|
|
3538
|
-
}
|
|
3539
|
-
return value;
|
|
3540
|
-
} else {
|
|
3541
|
-
return value;
|
|
3542
|
-
}
|
|
3543
|
-
};
|
|
3544
|
-
var cleanUpSlashes = (path7) => {
|
|
3545
|
-
if (path7) {
|
|
3546
|
-
return `/${path7.replace(/^\/+|\/+$/gm, "")}`;
|
|
3547
|
-
}
|
|
3548
|
-
return "";
|
|
3549
|
-
};
|
|
3550
|
-
var hasTinaMediaConfig = (schema) => {
|
|
3551
|
-
if (!schema.config?.media?.tina) return false;
|
|
3552
|
-
if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
|
|
3553
|
-
return false;
|
|
3554
|
-
return true;
|
|
3555
|
-
};
|
|
3315
|
+
// src/mdx/index.ts
|
|
3316
|
+
import { parseMDX, serializeMDX } from "@tinacms/mdx";
|
|
3556
3317
|
|
|
3557
3318
|
// src/resolver/index.ts
|
|
3558
3319
|
import { GraphQLError as GraphQLError2 } from "graphql";
|
|
@@ -3615,13 +3376,13 @@ import path2 from "path";
|
|
|
3615
3376
|
|
|
3616
3377
|
// src/database/util.ts
|
|
3617
3378
|
import toml from "@iarna/toml";
|
|
3618
|
-
import yaml from "js-yaml";
|
|
3619
|
-
import matter from "gray-matter";
|
|
3620
3379
|
import {
|
|
3621
3380
|
normalizePath
|
|
3622
3381
|
} from "@tinacms/schema-tools";
|
|
3623
|
-
import
|
|
3382
|
+
import matter from "gray-matter";
|
|
3383
|
+
import yaml from "js-yaml";
|
|
3624
3384
|
import path from "path";
|
|
3385
|
+
import micromatch from "micromatch";
|
|
3625
3386
|
|
|
3626
3387
|
// src/database/alias-utils.ts
|
|
3627
3388
|
var replaceBlockAliases = (template, item) => {
|
|
@@ -4609,6 +4370,243 @@ var stringEscaper = makeStringEscaper(
|
|
|
4609
4370
|
encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR)
|
|
4610
4371
|
);
|
|
4611
4372
|
|
|
4373
|
+
// src/resolver/error.ts
|
|
4374
|
+
var TinaGraphQLError = class extends Error {
|
|
4375
|
+
constructor(message, extensions) {
|
|
4376
|
+
super(message);
|
|
4377
|
+
if (!this.name) {
|
|
4378
|
+
Object.defineProperty(this, "name", { value: "TinaGraphQLError" });
|
|
4379
|
+
}
|
|
4380
|
+
this.extensions = { ...extensions };
|
|
4381
|
+
}
|
|
4382
|
+
};
|
|
4383
|
+
var TinaFetchError = class extends Error {
|
|
4384
|
+
constructor(message, args) {
|
|
4385
|
+
super(message);
|
|
4386
|
+
this.name = "TinaFetchError";
|
|
4387
|
+
this.collection = args.collection;
|
|
4388
|
+
this.stack = args.stack;
|
|
4389
|
+
this.file = args.file;
|
|
4390
|
+
this.originalError = args.originalError;
|
|
4391
|
+
}
|
|
4392
|
+
};
|
|
4393
|
+
var TinaQueryError = class extends TinaFetchError {
|
|
4394
|
+
constructor(args) {
|
|
4395
|
+
super(
|
|
4396
|
+
`Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
4397
|
+
args
|
|
4398
|
+
);
|
|
4399
|
+
}
|
|
4400
|
+
};
|
|
4401
|
+
var TinaParseDocumentError = class extends TinaFetchError {
|
|
4402
|
+
constructor(args) {
|
|
4403
|
+
super(
|
|
4404
|
+
`Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
4405
|
+
args
|
|
4406
|
+
);
|
|
4407
|
+
}
|
|
4408
|
+
toString() {
|
|
4409
|
+
return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
|
|
4410
|
+
}
|
|
4411
|
+
};
|
|
4412
|
+
var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
|
|
4413
|
+
var handleFetchErrorError = (e, verbose) => {
|
|
4414
|
+
if (e instanceof Error) {
|
|
4415
|
+
if (e instanceof TinaFetchError) {
|
|
4416
|
+
if (verbose) {
|
|
4417
|
+
console.log(e.toString());
|
|
4418
|
+
console.log(e);
|
|
4419
|
+
console.log(e.stack);
|
|
4420
|
+
}
|
|
4421
|
+
}
|
|
4422
|
+
} else {
|
|
4423
|
+
console.error(e);
|
|
4424
|
+
}
|
|
4425
|
+
throw e;
|
|
4426
|
+
};
|
|
4427
|
+
|
|
4428
|
+
// src/resolver/filter-utils.ts
|
|
4429
|
+
var resolveReferences = async (filter, fields, resolver) => {
|
|
4430
|
+
for (const fieldKey of Object.keys(filter)) {
|
|
4431
|
+
const fieldDefinition = fields.find(
|
|
4432
|
+
(f) => f.name === fieldKey
|
|
4433
|
+
);
|
|
4434
|
+
if (fieldDefinition) {
|
|
4435
|
+
if (fieldDefinition.type === "reference") {
|
|
4436
|
+
const { edges, values } = await resolver(filter, fieldDefinition);
|
|
4437
|
+
if (edges.length === 1) {
|
|
4438
|
+
filter[fieldKey] = {
|
|
4439
|
+
eq: values[0]
|
|
4440
|
+
};
|
|
4441
|
+
} else if (edges.length > 1) {
|
|
4442
|
+
filter[fieldKey] = {
|
|
4443
|
+
in: values
|
|
4444
|
+
};
|
|
4445
|
+
} else {
|
|
4446
|
+
filter[fieldKey] = {
|
|
4447
|
+
eq: "___null___"
|
|
4448
|
+
};
|
|
4449
|
+
}
|
|
4450
|
+
} else if (fieldDefinition.type === "object") {
|
|
4451
|
+
if (fieldDefinition.templates) {
|
|
4452
|
+
for (const templateName of Object.keys(filter[fieldKey])) {
|
|
4453
|
+
const template = fieldDefinition.templates.find(
|
|
4454
|
+
(template2) => !(typeof template2 === "string") && template2.name === templateName
|
|
4455
|
+
);
|
|
4456
|
+
if (template) {
|
|
4457
|
+
await resolveReferences(
|
|
4458
|
+
filter[fieldKey][templateName],
|
|
4459
|
+
template.fields,
|
|
4460
|
+
resolver
|
|
4461
|
+
);
|
|
4462
|
+
} else {
|
|
4463
|
+
throw new Error(`Template ${templateName} not found`);
|
|
4464
|
+
}
|
|
4465
|
+
}
|
|
4466
|
+
} else {
|
|
4467
|
+
await resolveReferences(
|
|
4468
|
+
filter[fieldKey],
|
|
4469
|
+
fieldDefinition.fields,
|
|
4470
|
+
resolver
|
|
4471
|
+
);
|
|
4472
|
+
}
|
|
4473
|
+
}
|
|
4474
|
+
} else {
|
|
4475
|
+
throw new Error(`Unable to find field ${fieldKey}`);
|
|
4476
|
+
}
|
|
4477
|
+
}
|
|
4478
|
+
};
|
|
4479
|
+
var collectConditionsForChildFields = (filterNode, fields, pathExpression, collectCondition) => {
|
|
4480
|
+
for (const childFieldName of Object.keys(filterNode)) {
|
|
4481
|
+
const childField = fields.find((field) => field.name === childFieldName);
|
|
4482
|
+
if (!childField) {
|
|
4483
|
+
throw new Error(`Unable to find type for field ${childFieldName}`);
|
|
4484
|
+
}
|
|
4485
|
+
collectConditionsForField(
|
|
4486
|
+
childFieldName,
|
|
4487
|
+
childField,
|
|
4488
|
+
filterNode[childFieldName],
|
|
4489
|
+
pathExpression,
|
|
4490
|
+
collectCondition
|
|
4491
|
+
);
|
|
4492
|
+
}
|
|
4493
|
+
};
|
|
4494
|
+
var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
4495
|
+
if (field.list && field.templates) {
|
|
4496
|
+
for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
|
|
4497
|
+
const template = field.templates.find(
|
|
4498
|
+
(template2) => !(typeof template2 === "string") && template2.name === filterKey
|
|
4499
|
+
);
|
|
4500
|
+
const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
|
|
4501
|
+
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
|
|
4502
|
+
collectConditionsForChildFields(
|
|
4503
|
+
childFilterNode,
|
|
4504
|
+
template.fields,
|
|
4505
|
+
filterPath,
|
|
4506
|
+
collectCondition
|
|
4507
|
+
);
|
|
4508
|
+
}
|
|
4509
|
+
} else {
|
|
4510
|
+
const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
|
|
4511
|
+
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
|
|
4512
|
+
collectConditionsForChildFields(
|
|
4513
|
+
filterNode,
|
|
4514
|
+
field.fields,
|
|
4515
|
+
filterPath,
|
|
4516
|
+
collectCondition
|
|
4517
|
+
);
|
|
4518
|
+
}
|
|
4519
|
+
};
|
|
4520
|
+
var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
4521
|
+
if (field.type === "object") {
|
|
4522
|
+
collectConditionsForObjectField(
|
|
4523
|
+
fieldName,
|
|
4524
|
+
field,
|
|
4525
|
+
filterNode,
|
|
4526
|
+
pathExpression,
|
|
4527
|
+
collectCondition
|
|
4528
|
+
);
|
|
4529
|
+
} else {
|
|
4530
|
+
collectCondition({
|
|
4531
|
+
filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
|
|
4532
|
+
filterExpression: {
|
|
4533
|
+
_type: field.type,
|
|
4534
|
+
_list: !!field.list,
|
|
4535
|
+
...filterNode
|
|
4536
|
+
}
|
|
4537
|
+
});
|
|
4538
|
+
}
|
|
4539
|
+
};
|
|
4540
|
+
|
|
4541
|
+
// src/resolver/media-utils.ts
|
|
4542
|
+
var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, schema) => {
|
|
4543
|
+
if (config && value) {
|
|
4544
|
+
if (config.useRelativeMedia === true) {
|
|
4545
|
+
return value;
|
|
4546
|
+
}
|
|
4547
|
+
if (hasTinaMediaConfig(schema) === true) {
|
|
4548
|
+
const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
|
|
4549
|
+
if (typeof value === "string" && value.includes(assetsURL)) {
|
|
4550
|
+
const cleanMediaRoot = cleanUpSlashes(
|
|
4551
|
+
schema.config.media.tina.mediaRoot
|
|
4552
|
+
);
|
|
4553
|
+
const strippedURL = value.replace(assetsURL, "");
|
|
4554
|
+
return `${cleanMediaRoot}${strippedURL}`;
|
|
4555
|
+
}
|
|
4556
|
+
if (Array.isArray(value)) {
|
|
4557
|
+
return value.map((v) => {
|
|
4558
|
+
if (!v || typeof v !== "string") return v;
|
|
4559
|
+
const cleanMediaRoot = cleanUpSlashes(
|
|
4560
|
+
schema.config.media.tina.mediaRoot
|
|
4561
|
+
);
|
|
4562
|
+
const strippedURL = v.replace(assetsURL, "");
|
|
4563
|
+
return `${cleanMediaRoot}${strippedURL}`;
|
|
4564
|
+
});
|
|
4565
|
+
}
|
|
4566
|
+
return value;
|
|
4567
|
+
}
|
|
4568
|
+
return value;
|
|
4569
|
+
} else {
|
|
4570
|
+
return value;
|
|
4571
|
+
}
|
|
4572
|
+
};
|
|
4573
|
+
var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, schema) => {
|
|
4574
|
+
if (config && value) {
|
|
4575
|
+
if (config.useRelativeMedia === true) {
|
|
4576
|
+
return value;
|
|
4577
|
+
}
|
|
4578
|
+
if (hasTinaMediaConfig(schema) === true) {
|
|
4579
|
+
const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
|
|
4580
|
+
if (typeof value === "string") {
|
|
4581
|
+
const strippedValue = value.replace(cleanMediaRoot, "");
|
|
4582
|
+
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
4583
|
+
}
|
|
4584
|
+
if (Array.isArray(value)) {
|
|
4585
|
+
return value.map((v) => {
|
|
4586
|
+
if (!v || typeof v !== "string") return v;
|
|
4587
|
+
const strippedValue = v.replace(cleanMediaRoot, "");
|
|
4588
|
+
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
4589
|
+
});
|
|
4590
|
+
}
|
|
4591
|
+
}
|
|
4592
|
+
return value;
|
|
4593
|
+
} else {
|
|
4594
|
+
return value;
|
|
4595
|
+
}
|
|
4596
|
+
};
|
|
4597
|
+
var cleanUpSlashes = (path7) => {
|
|
4598
|
+
if (path7) {
|
|
4599
|
+
return `/${path7.replace(/^\/+|\/+$/gm, "")}`;
|
|
4600
|
+
}
|
|
4601
|
+
return "";
|
|
4602
|
+
};
|
|
4603
|
+
var hasTinaMediaConfig = (schema) => {
|
|
4604
|
+
if (!schema.config?.media?.tina) return false;
|
|
4605
|
+
if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
|
|
4606
|
+
return false;
|
|
4607
|
+
return true;
|
|
4608
|
+
};
|
|
4609
|
+
|
|
4612
4610
|
// src/resolver/index.ts
|
|
4613
4611
|
var createResolver = (args) => {
|
|
4614
4612
|
return new Resolver(args);
|
|
@@ -5574,7 +5572,7 @@ var Resolver = class {
|
|
|
5574
5572
|
}
|
|
5575
5573
|
break;
|
|
5576
5574
|
case "rich-text":
|
|
5577
|
-
accum[fieldName] =
|
|
5575
|
+
accum[fieldName] = serializeMDX(
|
|
5578
5576
|
fieldValue,
|
|
5579
5577
|
field,
|
|
5580
5578
|
(fieldValue2) => resolveMediaCloudToRelative(
|
package/dist/mdx/index.d.ts
CHANGED
package/dist/resolver/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
*/
|
|
4
4
|
import { Database } from '../database';
|
|
5
|
-
import type { Collectable, Collection,
|
|
5
|
+
import type { Collectable, Collection, Template, TinaField, TinaSchema } from '@tinacms/schema-tools';
|
|
6
6
|
import type { GraphQLConfig } from '../types';
|
|
7
7
|
interface ResolverConfig {
|
|
8
8
|
config?: GraphQLConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/graphql",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.19",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"readable-stream": "^4.7.0",
|
|
45
45
|
"scmp": "^2.1.0",
|
|
46
46
|
"yup": "^0.32.11",
|
|
47
|
-
"@tinacms/mdx": "1.
|
|
48
|
-
"@tinacms/schema-tools": "1.
|
|
47
|
+
"@tinacms/mdx": "1.7.0",
|
|
48
|
+
"@tinacms/schema-tools": "1.8.0"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"registry": "https://registry.npmjs.org"
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"vite": "^4.5.9",
|
|
76
76
|
"vitest": "^0.32.4",
|
|
77
77
|
"zod": "^3.24.2",
|
|
78
|
-
"@tinacms/schema-tools": "1.
|
|
78
|
+
"@tinacms/schema-tools": "1.8.0",
|
|
79
79
|
"@tinacms/scripts": "1.3.5"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|