@tinacms/graphql 0.0.0-dced6ab-20250611061422 → 0.0.0-dde3eb3-20251028070343

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/index.js CHANGED
@@ -2777,7 +2777,7 @@ var Builder = class {
2777
2777
  this._buildDataField = async (field) => {
2778
2778
  const listWarningMsg = `
2779
2779
  WARNING: The user interface for ${field.type} does not support \`list: true\`
2780
- Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2780
+ Visit https://tina.io/docs/r/content-fields/#list-fields/ for more information
2781
2781
 
2782
2782
  `;
2783
2783
  switch (field.type) {
@@ -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.18",
3086
+ version: "1.6.1",
3087
3087
  main: "dist/index.js",
3088
3088
  module: "dist/index.mjs",
3089
3089
  typings: "dist/index.d.ts",
@@ -3166,7 +3166,7 @@ var package_default = {
3166
3166
  typescript: "^5.7.3",
3167
3167
  vite: "^4.5.9",
3168
3168
  vitest: "^0.32.4",
3169
- zod: "^3.24.2"
3169
+ zod: "catalog:"
3170
3170
  }
3171
3171
  };
3172
3172
 
@@ -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 import_micromatch = __toESM(require("micromatch"));
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) => {
@@ -4570,106 +4331,342 @@ var makeFolderOpsForCollection = (folderTree, collection, indexDefinitions, opTy
4570
4331
  });
4571
4332
  }
4572
4333
  }
4573
- return result;
4334
+ return result;
4335
+ };
4336
+ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opType, level, escapeStr = stringEscaper) => {
4337
+ const result = [];
4338
+ if (collection) {
4339
+ const collectionSublevel = level.sublevel(collection, SUBLEVEL_OPTIONS);
4340
+ for (const [sort, definition] of Object.entries(indexDefinitions)) {
4341
+ const indexedValue = makeKeyForField(definition, data, escapeStr);
4342
+ const indexSublevel = collectionSublevel.sublevel(sort, SUBLEVEL_OPTIONS);
4343
+ if (sort === DEFAULT_COLLECTION_SORT_KEY) {
4344
+ result.push({
4345
+ type: opType,
4346
+ key: filepath,
4347
+ sublevel: indexSublevel,
4348
+ value: opType === "put" ? {} : void 0
4349
+ });
4350
+ } else {
4351
+ if (indexedValue) {
4352
+ result.push({
4353
+ type: opType,
4354
+ key: `${indexedValue}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
4355
+ sublevel: indexSublevel,
4356
+ value: opType === "put" ? {} : void 0
4357
+ });
4358
+ }
4359
+ }
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
+ }
4574
4580
  };
4575
- var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opType, level, escapeStr = stringEscaper) => {
4576
- const result = [];
4577
- if (collection) {
4578
- const collectionSublevel = level.sublevel(collection, SUBLEVEL_OPTIONS);
4579
- for (const [sort, definition] of Object.entries(indexDefinitions)) {
4580
- const indexedValue = makeKeyForField(definition, data, escapeStr);
4581
- const indexSublevel = collectionSublevel.sublevel(sort, SUBLEVEL_OPTIONS);
4582
- if (sort === DEFAULT_COLLECTION_SORT_KEY) {
4583
- result.push({
4584
- type: opType,
4585
- key: filepath,
4586
- sublevel: indexSublevel,
4587
- value: opType === "put" ? {} : void 0
4588
- });
4589
- } else {
4590
- if (indexedValue) {
4591
- result.push({
4592
- type: opType,
4593
- key: `${indexedValue}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
4594
- sublevel: indexSublevel,
4595
- value: opType === "put" ? {} : void 0
4596
- });
4597
- }
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
4598
4597
  }
4599
- }
4598
+ });
4600
4599
  }
4601
- return result;
4602
4600
  };
4603
- var makeRefOpsForDocument = (filepath, collection, references, data, opType, level) => {
4604
- const result = [];
4605
- if (collection) {
4606
- for (const [c, referencePaths] of Object.entries(references || {})) {
4607
- if (!referencePaths.length) {
4608
- continue;
4609
- }
4610
- const collectionSublevel = level.sublevel(c, SUBLEVEL_OPTIONS);
4611
- const refSublevel = collectionSublevel.sublevel(
4612
- REFS_COLLECTIONS_SORT_KEY,
4613
- SUBLEVEL_OPTIONS
4614
- );
4615
- const references2 = {};
4616
- for (const path7 of referencePaths) {
4617
- const ref = (0, import_jsonpath_plus.JSONPath)({ path: path7, json: data });
4618
- if (!ref) {
4619
- continue;
4620
- }
4621
- if (Array.isArray(ref)) {
4622
- for (const r of ref) {
4623
- if (!r) {
4624
- continue;
4625
- }
4626
- if (references2[r]) {
4627
- references2[r].push(path7);
4628
- } else {
4629
- references2[r] = [path7];
4630
- }
4631
- }
4632
- } else {
4633
- if (references2[ref]) {
4634
- references2[ref].push(path7);
4635
- } else {
4636
- references2[ref] = [path7];
4637
- }
4638
- }
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}`;
4639
4616
  }
4640
- for (const ref of Object.keys(references2)) {
4641
- for (const path7 of references2[ref]) {
4642
- result.push({
4643
- type: opType,
4644
- key: `${ref}${INDEX_KEY_FIELD_SEPARATOR}${path7}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
4645
- sublevel: refSublevel,
4646
- value: opType === "put" ? {} : void 0
4647
- });
4648
- }
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
+ });
4649
4626
  }
4627
+ return value;
4650
4628
  }
4629
+ return value;
4630
+ } else {
4631
+ return value;
4651
4632
  }
4652
- return result;
4653
4633
  };
4654
- var makeStringEscaper = (regex, replacement) => {
4655
- return (input) => {
4656
- if (Array.isArray(input)) {
4657
- return input.map(
4658
- (val) => val.replace(regex, replacement)
4659
- );
4660
- } else {
4661
- if (typeof input === "string") {
4662
- return input.replace(regex, replacement);
4663
- } else {
4664
- return input;
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
+ });
4665
4651
  }
4666
4652
  }
4667
- };
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;
4668
4669
  };
4669
- var stringEscaper = makeStringEscaper(
4670
- new RegExp(INDEX_KEY_FIELD_SEPARATOR, "gm"),
4671
- encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR)
4672
- );
4673
4670
 
4674
4671
  // src/resolver/index.ts
4675
4672
  var createResolver = (args) => {
@@ -4831,8 +4828,7 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4831
4828
  originalError: e,
4832
4829
  collection: collection.name,
4833
4830
  includeAuditMessage: !isAudit,
4834
- file: relativePath,
4835
- stack: e.stack
4831
+ file: relativePath
4836
4832
  });
4837
4833
  }
4838
4834
  const titleField = template.fields.find((x) => {
@@ -5636,7 +5632,7 @@ var Resolver = class {
5636
5632
  }
5637
5633
  break;
5638
5634
  case "rich-text":
5639
- accum[fieldName] = (0, import_mdx.stringifyMDX)(
5635
+ accum[fieldName] = (0, import_mdx.serializeMDX)(
5640
5636
  fieldValue,
5641
5637
  field,
5642
5638
  (fieldValue2) => resolveMediaCloudToRelative(
@@ -5743,8 +5739,129 @@ var resolveDateInput = (value) => {
5743
5739
  return date;
5744
5740
  };
5745
5741
 
5746
- // src/resolve.ts
5742
+ // src/resolver/auth-fields.ts
5747
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
+ }
5748
5865
 
5749
5866
  // src/error.ts
5750
5867
  var import_graphql4 = require("graphql");
@@ -5854,119 +5971,33 @@ var resolve = async ({
5854
5971
  );
5855
5972
  }
5856
5973
  }
5857
- if (info.fieldName === "authenticate" || info.fieldName === "authorize") {
5858
- const sub = args.sub || ctxUser?.sub;
5859
- const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
5860
- if (!collection) {
5861
- throw new Error("Auth collection not found");
5862
- }
5863
- const userFields = mapUserFields(collection, ["_rawData"]);
5864
- if (!userFields.length) {
5865
- throw new Error(
5866
- `No user field found in collection ${collection.name}`
5867
- );
5868
- }
5869
- if (userFields.length > 1) {
5870
- throw new Error(
5871
- `Multiple user fields found in collection ${collection.name}`
5872
- );
5873
- }
5874
- const userField = userFields[0];
5875
- const realPath = `${collection.path}/index.json`;
5876
- const userDoc = await resolver.getDocument(realPath);
5877
- const users = get(userDoc, userField.path);
5878
- if (!users) {
5879
- throw new Error("No users found");
5880
- }
5881
- const { idFieldName, passwordFieldName } = userField;
5882
- if (!idFieldName) {
5883
- throw new Error("No uid field found on user field");
5884
- }
5885
- const user = users.find((u) => u[idFieldName] === sub);
5886
- if (!user) {
5887
- return null;
5888
- }
5889
- if (info.fieldName === "authenticate") {
5890
- const saltedHash = get(user, [passwordFieldName || "", "value"]);
5891
- if (!saltedHash) {
5892
- throw new Error("No password field found on user field");
5893
- }
5894
- const matches = await checkPasswordHash({
5895
- saltedHash,
5896
- password: args.password
5897
- });
5898
- if (matches) {
5899
- return user;
5900
- }
5901
- return null;
5902
- }
5903
- 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
+ });
5904
5992
  }
5905
5993
  if (info.fieldName === "updatePassword") {
5906
- if (!ctxUser?.sub) {
5907
- throw new Error("Not authorized");
5908
- }
5909
- if (!args.password) {
5910
- throw new Error("No password provided");
5911
- }
5912
- const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
5913
- if (!collection) {
5914
- throw new Error("Auth collection not found");
5915
- }
5916
- const userFields = mapUserFields(collection, ["_rawData"]);
5917
- if (!userFields.length) {
5918
- throw new Error(
5919
- `No user field found in collection ${collection.name}`
5920
- );
5921
- }
5922
- if (userFields.length > 1) {
5923
- throw new Error(
5924
- `Multiple user fields found in collection ${collection.name}`
5925
- );
5926
- }
5927
- const userField = userFields[0];
5928
- const realPath = `${collection.path}/index.json`;
5929
- const userDoc = await resolver.getDocument(realPath);
5930
- const users = get(userDoc, userField.path);
5931
- if (!users) {
5932
- throw new Error("No users found");
5933
- }
5934
- const { idFieldName, passwordFieldName } = userField;
5935
- const user = users.find((u) => u[idFieldName] === ctxUser.sub);
5936
- if (!user) {
5937
- throw new Error("Not authorized");
5938
- }
5939
- user[passwordFieldName] = {
5940
- value: args.password,
5941
- passwordChangeRequired: false
5942
- };
5943
- const params = {};
5944
- (0, import_lodash4.default)(
5945
- params,
5946
- userField.path.slice(1),
5947
- // remove _rawData from users path
5948
- users.map((u) => {
5949
- if (user[idFieldName] === u[idFieldName]) {
5950
- return user;
5951
- }
5952
- return {
5953
- // don't overwrite other users' passwords
5954
- ...u,
5955
- [passwordFieldName]: {
5956
- ...u[passwordFieldName],
5957
- value: ""
5958
- }
5959
- };
5960
- })
5961
- );
5962
- await resolver.updateResolveDocument({
5963
- collection,
5964
- args: { params },
5965
- realPath,
5966
- isCollectionSpecific: true,
5967
- isAddPendingDocument: false
5994
+ return handleUpdatePassword({
5995
+ tinaSchema,
5996
+ resolver,
5997
+ password: args.password,
5998
+ info,
5999
+ ctxUser
5968
6000
  });
5969
- return true;
5970
6001
  }
5971
6002
  if (!lookup) {
5972
6003
  return value;
@@ -6554,8 +6585,7 @@ var Database = class {
6554
6585
  throw new TinaFetchError(`Error in PUT for ${filepath}`, {
6555
6586
  originalError: error,
6556
6587
  file: filepath,
6557
- collection: collectionName,
6558
- stack: error.stack
6588
+ collection: collectionName
6559
6589
  });
6560
6590
  }
6561
6591
  };
@@ -6915,8 +6945,7 @@ var Database = class {
6915
6945
  throw new TinaQueryError({
6916
6946
  originalError: error,
6917
6947
  file: path7,
6918
- collection: collection.name,
6919
- stack: error.stack
6948
+ collection: collection.name
6920
6949
  });
6921
6950
  }
6922
6951
  throw error;
@@ -7446,8 +7475,7 @@ var _indexContent = async ({
7446
7475
  throw new TinaFetchError(`Unable to seed ${filepath}`, {
7447
7476
  originalError: error,
7448
7477
  file: filepath,
7449
- collection: collection?.name,
7450
- stack: error.stack
7478
+ collection: collection?.name
7451
7479
  });
7452
7480
  }
7453
7481
  });