@tinacms/graphql 0.0.0-dced6ab-20250611061422 → 0.0.0-dd2089d-20251128055623

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.mjs CHANGED
@@ -1,6 +1,8 @@
1
1
  // src/build.ts
2
- import { print } from "graphql";
3
- import uniqBy2 from "lodash.uniqby";
2
+ import {
3
+ print
4
+ } from "graphql";
5
+ import { uniqBy as uniqBy2 } from "es-toolkit";
4
6
 
5
7
  // src/util.ts
6
8
  import * as yup from "yup";
@@ -56,7 +58,7 @@ var flattenDeep = (arr) => arr.flatMap(
56
58
  );
57
59
 
58
60
  // src/ast-builder/index.ts
59
- import uniqBy from "lodash.uniqby";
61
+ import { uniqBy } from "es-toolkit";
60
62
  var SysFieldDefinition = {
61
63
  kind: "Field",
62
64
  name: {
@@ -977,6 +979,7 @@ var astBuilder = {
977
979
  ...extractInlineTypes(ast.globalTemplates),
978
980
  ...ast.definitions
979
981
  ],
982
+ // @ts-ignore - all nodes have a name property in practice
980
983
  (field) => field.name.value
981
984
  );
982
985
  return {
@@ -2711,7 +2714,7 @@ var Builder = class {
2711
2714
  this._buildDataField = async (field) => {
2712
2715
  const listWarningMsg = `
2713
2716
  WARNING: The user interface for ${field.type} does not support \`list: true\`
2714
- Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2717
+ Visit https://tina.io/docs/r/content-fields/#list-fields/ for more information
2715
2718
 
2716
2719
  `;
2717
2720
  switch (field.type) {
@@ -2864,8 +2867,8 @@ import { TinaSchema } from "@tinacms/schema-tools";
2864
2867
 
2865
2868
  // src/schema/validate.ts
2866
2869
  import { addNamespaceToSchema } from "@tinacms/schema-tools";
2867
- import deepClone from "lodash.clonedeep";
2868
2870
  import * as yup2 from "yup";
2871
+ import { cloneDeep } from "es-toolkit";
2869
2872
  import {
2870
2873
  validateTinaCloudSchemaConfig
2871
2874
  } from "@tinacms/schema-tools";
@@ -2882,7 +2885,7 @@ var FIELD_TYPES = [
2882
2885
  ];
2883
2886
  var validateSchema = async (schema) => {
2884
2887
  const schema2 = addNamespaceToSchema(
2885
- deepClone(schema)
2888
+ cloneDeep(schema)
2886
2889
  );
2887
2890
  const collections = await sequential(
2888
2891
  schema2.collections,
@@ -3019,7 +3022,7 @@ var validateField = async (field) => {
3019
3022
  // package.json
3020
3023
  var package_default = {
3021
3024
  name: "@tinacms/graphql",
3022
- version: "1.5.18",
3025
+ version: "1.6.2",
3023
3026
  main: "dist/index.js",
3024
3027
  module: "dist/index.mjs",
3025
3028
  typings: "dist/index.d.ts",
@@ -3054,6 +3057,7 @@ var package_default = {
3054
3057
  "@tinacms/schema-tools": "workspace:*",
3055
3058
  "abstract-level": "catalog:",
3056
3059
  "date-fns": "^2.30.0",
3060
+ "es-toolkit": "^1.42.0",
3057
3061
  "fast-glob": "catalog:",
3058
3062
  "fs-extra": "catalog:",
3059
3063
  "glob-parent": "catalog:",
@@ -3063,15 +3067,12 @@ var package_default = {
3063
3067
  "js-sha1": "catalog:",
3064
3068
  "js-yaml": "^3.14.1",
3065
3069
  "jsonpath-plus": "catalog:",
3066
- "lodash.clonedeep": "catalog:",
3067
- "lodash.set": "catalog:",
3068
- "lodash.uniqby": "catalog:",
3069
3070
  "many-level": "catalog:",
3070
3071
  micromatch: "catalog:",
3071
3072
  "normalize-path": "catalog:",
3072
3073
  "readable-stream": "catalog:",
3073
3074
  scmp: "catalog:",
3074
- yup: "^0.32.11"
3075
+ yup: "^1.6.1"
3075
3076
  },
3076
3077
  publishConfig: {
3077
3078
  registry: "https://registry.npmjs.org"
@@ -3088,21 +3089,18 @@ var package_default = {
3088
3089
  "@types/express": "catalog:",
3089
3090
  "@types/fs-extra": "^9.0.13",
3090
3091
  "@types/js-yaml": "^3.12.10",
3091
- "@types/lodash.camelcase": "catalog:",
3092
- "@types/lodash.upperfirst": "catalog:",
3093
3092
  "@types/lru-cache": "catalog:",
3094
3093
  "@types/mdast": "catalog:",
3095
3094
  "@types/micromatch": "catalog:",
3096
3095
  "@types/node": "^22.13.1",
3097
3096
  "@types/normalize-path": "catalog:",
3098
3097
  "@types/ws": "catalog:",
3099
- "@types/yup": "^0.29.14",
3100
3098
  "jest-file-snapshot": "^0.5.0",
3101
3099
  "memory-level": "catalog:",
3102
3100
  typescript: "^5.7.3",
3103
3101
  vite: "^4.5.9",
3104
3102
  vitest: "^0.32.4",
3105
- zod: "^3.24.2"
3103
+ zod: "catalog:"
3106
3104
  }
3107
3105
  };
3108
3106
 
@@ -3173,8 +3171,8 @@ var _buildFragments = async (builder, tinaSchema) => {
3173
3171
  const fragDoc = {
3174
3172
  kind: "Document",
3175
3173
  definitions: uniqBy2(
3176
- // @ts-ignore
3177
3174
  extractInlineTypes(fragmentDefinitionsFields),
3175
+ // @ts-ignore - all nodes returned by extractInlineTypes have a name property
3178
3176
  (node) => node.name.value
3179
3177
  )
3180
3178
  };
@@ -3206,8 +3204,8 @@ var _buildQueries = async (builder, tinaSchema) => {
3206
3204
  const queryDoc = {
3207
3205
  kind: "Document",
3208
3206
  definitions: uniqBy2(
3209
- // @ts-ignore
3210
3207
  extractInlineTypes(operationsDefinitions),
3208
+ // @ts-ignore - all nodes returned by extractInlineTypes have a name property
3211
3209
  (node) => node.name.value
3212
3210
  )
3213
3211
  };
@@ -3294,14 +3292,15 @@ var _buildSchema = async (builder, tinaSchema) => {
3294
3292
  fields: mutationTypeDefinitionFields
3295
3293
  })
3296
3294
  );
3297
- return {
3295
+ const schema = {
3298
3296
  kind: "Document",
3299
3297
  definitions: uniqBy2(
3300
- // @ts-ignore
3301
3298
  extractInlineTypes(definitions),
3299
+ // @ts-ignore - all nodes returned by extractInlineTypes have a name property
3302
3300
  (node) => node.name.value
3303
3301
  )
3304
3302
  };
3303
+ return schema;
3305
3304
  };
3306
3305
 
3307
3306
  // src/resolve.ts
@@ -3310,249 +3309,10 @@ import { graphql, buildASTSchema, getNamedType, GraphQLError as GraphQLError4 }
3310
3309
  // src/resolver/index.ts
3311
3310
  import path3 from "path";
3312
3311
  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
3312
  import { JSONPath as JSONPath2 } from "jsonpath-plus";
3319
3313
 
3320
- // src/resolver/error.ts
3321
- var TinaGraphQLError = class extends Error {
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
- };
3314
+ // src/mdx/index.ts
3315
+ import { parseMDX, serializeMDX } from "@tinacms/mdx";
3556
3316
 
3557
3317
  // src/resolver/index.ts
3558
3318
  import { GraphQLError as GraphQLError2 } from "graphql";
@@ -3615,13 +3375,13 @@ import path2 from "path";
3615
3375
 
3616
3376
  // src/database/util.ts
3617
3377
  import toml from "@iarna/toml";
3618
- import yaml from "js-yaml";
3619
- import matter from "gray-matter";
3620
3378
  import {
3621
3379
  normalizePath
3622
3380
  } from "@tinacms/schema-tools";
3623
- import micromatch from "micromatch";
3381
+ import matter from "gray-matter";
3382
+ import yaml from "js-yaml";
3624
3383
  import path from "path";
3384
+ import micromatch from "micromatch";
3625
3385
 
3626
3386
  // src/database/alias-utils.ts
3627
3387
  var replaceBlockAliases = (template, item) => {
@@ -4609,11 +4369,247 @@ var stringEscaper = makeStringEscaper(
4609
4369
  encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR)
4610
4370
  );
4611
4371
 
4612
- // src/resolver/index.ts
4613
- var createResolver = (args) => {
4614
- return new Resolver(args);
4615
- };
4616
- var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
4372
+ // src/resolver/error.ts
4373
+ var TinaGraphQLError = class extends Error {
4374
+ constructor(message, extensions) {
4375
+ super(message);
4376
+ if (!this.name) {
4377
+ Object.defineProperty(this, "name", { value: "TinaGraphQLError" });
4378
+ }
4379
+ this.extensions = { ...extensions };
4380
+ }
4381
+ };
4382
+ var TinaFetchError = class extends Error {
4383
+ constructor(message, args) {
4384
+ super(message);
4385
+ this.name = "TinaFetchError";
4386
+ this.collection = args.collection;
4387
+ this.file = args.file;
4388
+ this.originalError = args.originalError;
4389
+ }
4390
+ };
4391
+ var TinaQueryError = class extends TinaFetchError {
4392
+ constructor(args) {
4393
+ super(
4394
+ `Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
4395
+ args
4396
+ );
4397
+ }
4398
+ };
4399
+ var TinaParseDocumentError = class extends TinaFetchError {
4400
+ constructor(args) {
4401
+ super(
4402
+ `Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
4403
+ args
4404
+ );
4405
+ }
4406
+ toString() {
4407
+ return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
4408
+ }
4409
+ };
4410
+ var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
4411
+ var handleFetchErrorError = (e, verbose) => {
4412
+ if (e instanceof Error) {
4413
+ if (e instanceof TinaFetchError) {
4414
+ if (verbose) {
4415
+ console.log(e.toString());
4416
+ console.log(e);
4417
+ console.log(e.stack);
4418
+ }
4419
+ }
4420
+ } else {
4421
+ console.error(e);
4422
+ }
4423
+ throw e;
4424
+ };
4425
+
4426
+ // src/resolver/filter-utils.ts
4427
+ var resolveReferences = async (filter, fields, resolver) => {
4428
+ for (const fieldKey of Object.keys(filter)) {
4429
+ const fieldDefinition = fields.find(
4430
+ (f) => f.name === fieldKey
4431
+ );
4432
+ if (fieldDefinition) {
4433
+ if (fieldDefinition.type === "reference") {
4434
+ const { edges, values } = await resolver(filter, fieldDefinition);
4435
+ if (edges.length === 1) {
4436
+ filter[fieldKey] = {
4437
+ eq: values[0]
4438
+ };
4439
+ } else if (edges.length > 1) {
4440
+ filter[fieldKey] = {
4441
+ in: values
4442
+ };
4443
+ } else {
4444
+ filter[fieldKey] = {
4445
+ eq: "___null___"
4446
+ };
4447
+ }
4448
+ } else if (fieldDefinition.type === "object") {
4449
+ if (fieldDefinition.templates) {
4450
+ for (const templateName of Object.keys(filter[fieldKey])) {
4451
+ const template = fieldDefinition.templates.find(
4452
+ (template2) => !(typeof template2 === "string") && template2.name === templateName
4453
+ );
4454
+ if (template) {
4455
+ await resolveReferences(
4456
+ filter[fieldKey][templateName],
4457
+ template.fields,
4458
+ resolver
4459
+ );
4460
+ } else {
4461
+ throw new Error(`Template ${templateName} not found`);
4462
+ }
4463
+ }
4464
+ } else {
4465
+ await resolveReferences(
4466
+ filter[fieldKey],
4467
+ fieldDefinition.fields,
4468
+ resolver
4469
+ );
4470
+ }
4471
+ }
4472
+ } else {
4473
+ throw new Error(`Unable to find field ${fieldKey}`);
4474
+ }
4475
+ }
4476
+ };
4477
+ var collectConditionsForChildFields = (filterNode, fields, pathExpression, collectCondition) => {
4478
+ for (const childFieldName of Object.keys(filterNode)) {
4479
+ const childField = fields.find((field) => field.name === childFieldName);
4480
+ if (!childField) {
4481
+ throw new Error(`Unable to find type for field ${childFieldName}`);
4482
+ }
4483
+ collectConditionsForField(
4484
+ childFieldName,
4485
+ childField,
4486
+ filterNode[childFieldName],
4487
+ pathExpression,
4488
+ collectCondition
4489
+ );
4490
+ }
4491
+ };
4492
+ var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
4493
+ if (field.list && field.templates) {
4494
+ for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
4495
+ const template = field.templates.find(
4496
+ (template2) => !(typeof template2 === "string") && template2.name === filterKey
4497
+ );
4498
+ const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
4499
+ const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
4500
+ collectConditionsForChildFields(
4501
+ childFilterNode,
4502
+ template.fields,
4503
+ filterPath,
4504
+ collectCondition
4505
+ );
4506
+ }
4507
+ } else {
4508
+ const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
4509
+ const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
4510
+ collectConditionsForChildFields(
4511
+ filterNode,
4512
+ field.fields,
4513
+ filterPath,
4514
+ collectCondition
4515
+ );
4516
+ }
4517
+ };
4518
+ var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
4519
+ if (field.type === "object") {
4520
+ collectConditionsForObjectField(
4521
+ fieldName,
4522
+ field,
4523
+ filterNode,
4524
+ pathExpression,
4525
+ collectCondition
4526
+ );
4527
+ } else {
4528
+ collectCondition({
4529
+ filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
4530
+ filterExpression: {
4531
+ _type: field.type,
4532
+ _list: !!field.list,
4533
+ ...filterNode
4534
+ }
4535
+ });
4536
+ }
4537
+ };
4538
+
4539
+ // src/resolver/media-utils.ts
4540
+ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, schema) => {
4541
+ if (config && value) {
4542
+ if (config.useRelativeMedia === true) {
4543
+ return value;
4544
+ }
4545
+ if (hasTinaMediaConfig(schema) === true) {
4546
+ const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
4547
+ if (typeof value === "string" && value.includes(assetsURL)) {
4548
+ const cleanMediaRoot = cleanUpSlashes(
4549
+ schema.config.media.tina.mediaRoot
4550
+ );
4551
+ const strippedURL = value.replace(assetsURL, "");
4552
+ return `${cleanMediaRoot}${strippedURL}`;
4553
+ }
4554
+ if (Array.isArray(value)) {
4555
+ return value.map((v) => {
4556
+ if (!v || typeof v !== "string") return v;
4557
+ const cleanMediaRoot = cleanUpSlashes(
4558
+ schema.config.media.tina.mediaRoot
4559
+ );
4560
+ const strippedURL = v.replace(assetsURL, "");
4561
+ return `${cleanMediaRoot}${strippedURL}`;
4562
+ });
4563
+ }
4564
+ return value;
4565
+ }
4566
+ return value;
4567
+ } else {
4568
+ return value;
4569
+ }
4570
+ };
4571
+ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, schema) => {
4572
+ if (config && value) {
4573
+ if (config.useRelativeMedia === true) {
4574
+ return value;
4575
+ }
4576
+ if (hasTinaMediaConfig(schema) === true) {
4577
+ const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
4578
+ if (typeof value === "string") {
4579
+ const strippedValue = value.replace(cleanMediaRoot, "");
4580
+ return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
4581
+ }
4582
+ if (Array.isArray(value)) {
4583
+ return value.map((v) => {
4584
+ if (!v || typeof v !== "string") return v;
4585
+ const strippedValue = v.replace(cleanMediaRoot, "");
4586
+ return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
4587
+ });
4588
+ }
4589
+ }
4590
+ return value;
4591
+ } else {
4592
+ return value;
4593
+ }
4594
+ };
4595
+ var cleanUpSlashes = (path7) => {
4596
+ if (path7) {
4597
+ return `/${path7.replace(/^\/+|\/+$/gm, "")}`;
4598
+ }
4599
+ return "";
4600
+ };
4601
+ var hasTinaMediaConfig = (schema) => {
4602
+ if (!schema.config?.media?.tina) return false;
4603
+ if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
4604
+ return false;
4605
+ return true;
4606
+ };
4607
+
4608
+ // src/resolver/index.ts
4609
+ var createResolver = (args) => {
4610
+ return new Resolver(args);
4611
+ };
4612
+ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
4617
4613
  if (!rawData) {
4618
4614
  return void 0;
4619
4615
  }
@@ -4769,8 +4765,7 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4769
4765
  originalError: e,
4770
4766
  collection: collection.name,
4771
4767
  includeAuditMessage: !isAudit,
4772
- file: relativePath,
4773
- stack: e.stack
4768
+ file: relativePath
4774
4769
  });
4775
4770
  }
4776
4771
  const titleField = template.fields.find((x) => {
@@ -5574,7 +5569,7 @@ var Resolver = class {
5574
5569
  }
5575
5570
  break;
5576
5571
  case "rich-text":
5577
- accum[fieldName] = stringifyMDX(
5572
+ accum[fieldName] = serializeMDX(
5578
5573
  fieldValue,
5579
5574
  field,
5580
5575
  (fieldValue2) => resolveMediaCloudToRelative(
@@ -5681,8 +5676,129 @@ var resolveDateInput = (value) => {
5681
5676
  return date;
5682
5677
  };
5683
5678
 
5684
- // src/resolve.ts
5685
- import set from "lodash.set";
5679
+ // src/resolver/auth-fields.ts
5680
+ import { set } from "es-toolkit/compat";
5681
+ async function getUserDocumentContext(tinaSchema, resolver) {
5682
+ const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
5683
+ if (!collection) {
5684
+ throw new Error("Auth collection not found");
5685
+ }
5686
+ const userFields = mapUserFields(collection, ["_rawData"]);
5687
+ if (!userFields.length) {
5688
+ throw new Error(`No user field found in collection ${collection.name}`);
5689
+ }
5690
+ if (userFields.length > 1) {
5691
+ throw new Error(
5692
+ `Multiple user fields found in collection ${collection.name}`
5693
+ );
5694
+ }
5695
+ const userField = userFields[0];
5696
+ const realPath = `${collection.path}/index.json`;
5697
+ const userDoc = await resolver.getDocument(realPath);
5698
+ const users = get(userDoc, userField.path);
5699
+ if (!users) {
5700
+ throw new Error("No users found");
5701
+ }
5702
+ return { collection, userField, users, userDoc, realPath };
5703
+ }
5704
+ function findUserInCollection(users, userField, userSub) {
5705
+ const { idFieldName } = userField;
5706
+ if (!idFieldName) {
5707
+ throw new Error("No uid field found on user field");
5708
+ }
5709
+ return users.find((u) => u[idFieldName] === userSub) || null;
5710
+ }
5711
+ async function handleAuthenticate({
5712
+ tinaSchema,
5713
+ resolver,
5714
+ sub,
5715
+ password,
5716
+ ctxUser
5717
+ }) {
5718
+ const userSub = sub || ctxUser?.sub;
5719
+ const { userField, users } = await getUserDocumentContext(
5720
+ tinaSchema,
5721
+ resolver
5722
+ );
5723
+ const user = findUserInCollection(users, userField, userSub);
5724
+ if (!user) {
5725
+ return null;
5726
+ }
5727
+ const { passwordFieldName } = userField;
5728
+ const saltedHash = get(user, [passwordFieldName || "", "value"]);
5729
+ if (!saltedHash) {
5730
+ throw new Error("No password field found on user field");
5731
+ }
5732
+ const matches = await checkPasswordHash({
5733
+ saltedHash,
5734
+ password
5735
+ });
5736
+ return matches ? user : null;
5737
+ }
5738
+ async function handleAuthorize({
5739
+ tinaSchema,
5740
+ resolver,
5741
+ sub,
5742
+ ctxUser
5743
+ }) {
5744
+ const userSub = sub || ctxUser?.sub;
5745
+ const { userField, users } = await getUserDocumentContext(
5746
+ tinaSchema,
5747
+ resolver
5748
+ );
5749
+ const user = findUserInCollection(users, userField, userSub);
5750
+ return user ? user : null;
5751
+ }
5752
+ async function handleUpdatePassword({
5753
+ tinaSchema,
5754
+ resolver,
5755
+ password,
5756
+ ctxUser
5757
+ }) {
5758
+ if (!ctxUser?.sub) {
5759
+ throw new Error("Not authorized");
5760
+ }
5761
+ if (!password) {
5762
+ throw new Error("No password provided");
5763
+ }
5764
+ const { collection, userField, users, realPath } = await getUserDocumentContext(tinaSchema, resolver);
5765
+ const { idFieldName, passwordFieldName } = userField;
5766
+ const user = users.find((u) => u[idFieldName] === ctxUser.sub);
5767
+ if (!user) {
5768
+ throw new Error("Not authorized");
5769
+ }
5770
+ user[passwordFieldName] = {
5771
+ value: password,
5772
+ passwordChangeRequired: false
5773
+ };
5774
+ const params = {};
5775
+ set(
5776
+ params,
5777
+ userField.path.slice(1),
5778
+ // remove _rawData from users path
5779
+ users.map((u) => {
5780
+ if (user[idFieldName] === u[idFieldName]) {
5781
+ return user;
5782
+ }
5783
+ return {
5784
+ // don't overwrite other users' passwords
5785
+ ...u,
5786
+ [passwordFieldName]: {
5787
+ ...u[passwordFieldName],
5788
+ value: ""
5789
+ }
5790
+ };
5791
+ })
5792
+ );
5793
+ await resolver.updateResolveDocument({
5794
+ collection,
5795
+ args: { params },
5796
+ realPath,
5797
+ isCollectionSpecific: true,
5798
+ isAddPendingDocument: false
5799
+ });
5800
+ return true;
5801
+ }
5686
5802
 
5687
5803
  // src/error.ts
5688
5804
  import { GraphQLError as GraphQLError3 } from "graphql";
@@ -5792,119 +5908,33 @@ var resolve = async ({
5792
5908
  );
5793
5909
  }
5794
5910
  }
5795
- if (info.fieldName === "authenticate" || info.fieldName === "authorize") {
5796
- const sub = args.sub || ctxUser?.sub;
5797
- const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
5798
- if (!collection) {
5799
- throw new Error("Auth collection not found");
5800
- }
5801
- const userFields = mapUserFields(collection, ["_rawData"]);
5802
- if (!userFields.length) {
5803
- throw new Error(
5804
- `No user field found in collection ${collection.name}`
5805
- );
5806
- }
5807
- if (userFields.length > 1) {
5808
- throw new Error(
5809
- `Multiple user fields found in collection ${collection.name}`
5810
- );
5811
- }
5812
- const userField = userFields[0];
5813
- const realPath = `${collection.path}/index.json`;
5814
- const userDoc = await resolver.getDocument(realPath);
5815
- const users = get(userDoc, userField.path);
5816
- if (!users) {
5817
- throw new Error("No users found");
5818
- }
5819
- const { idFieldName, passwordFieldName } = userField;
5820
- if (!idFieldName) {
5821
- throw new Error("No uid field found on user field");
5822
- }
5823
- const user = users.find((u) => u[idFieldName] === sub);
5824
- if (!user) {
5825
- return null;
5826
- }
5827
- if (info.fieldName === "authenticate") {
5828
- const saltedHash = get(user, [passwordFieldName || "", "value"]);
5829
- if (!saltedHash) {
5830
- throw new Error("No password field found on user field");
5831
- }
5832
- const matches = await checkPasswordHash({
5833
- saltedHash,
5834
- password: args.password
5835
- });
5836
- if (matches) {
5837
- return user;
5838
- }
5839
- return null;
5840
- }
5841
- return user;
5911
+ if (info.fieldName === "authenticate") {
5912
+ return handleAuthenticate({
5913
+ tinaSchema,
5914
+ resolver,
5915
+ sub: args.sub,
5916
+ password: args.password,
5917
+ info,
5918
+ ctxUser
5919
+ });
5920
+ }
5921
+ if (info.fieldName === "authorize") {
5922
+ return handleAuthorize({
5923
+ tinaSchema,
5924
+ resolver,
5925
+ sub: args.sub,
5926
+ info,
5927
+ ctxUser
5928
+ });
5842
5929
  }
5843
5930
  if (info.fieldName === "updatePassword") {
5844
- if (!ctxUser?.sub) {
5845
- throw new Error("Not authorized");
5846
- }
5847
- if (!args.password) {
5848
- throw new Error("No password provided");
5849
- }
5850
- const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
5851
- if (!collection) {
5852
- throw new Error("Auth collection not found");
5853
- }
5854
- const userFields = mapUserFields(collection, ["_rawData"]);
5855
- if (!userFields.length) {
5856
- throw new Error(
5857
- `No user field found in collection ${collection.name}`
5858
- );
5859
- }
5860
- if (userFields.length > 1) {
5861
- throw new Error(
5862
- `Multiple user fields found in collection ${collection.name}`
5863
- );
5864
- }
5865
- const userField = userFields[0];
5866
- const realPath = `${collection.path}/index.json`;
5867
- const userDoc = await resolver.getDocument(realPath);
5868
- const users = get(userDoc, userField.path);
5869
- if (!users) {
5870
- throw new Error("No users found");
5871
- }
5872
- const { idFieldName, passwordFieldName } = userField;
5873
- const user = users.find((u) => u[idFieldName] === ctxUser.sub);
5874
- if (!user) {
5875
- throw new Error("Not authorized");
5876
- }
5877
- user[passwordFieldName] = {
5878
- value: args.password,
5879
- passwordChangeRequired: false
5880
- };
5881
- const params = {};
5882
- set(
5883
- params,
5884
- userField.path.slice(1),
5885
- // remove _rawData from users path
5886
- users.map((u) => {
5887
- if (user[idFieldName] === u[idFieldName]) {
5888
- return user;
5889
- }
5890
- return {
5891
- // don't overwrite other users' passwords
5892
- ...u,
5893
- [passwordFieldName]: {
5894
- ...u[passwordFieldName],
5895
- value: ""
5896
- }
5897
- };
5898
- })
5899
- );
5900
- await resolver.updateResolveDocument({
5901
- collection,
5902
- args: { params },
5903
- realPath,
5904
- isCollectionSpecific: true,
5905
- isAddPendingDocument: false
5931
+ return handleUpdatePassword({
5932
+ tinaSchema,
5933
+ resolver,
5934
+ password: args.password,
5935
+ info,
5936
+ ctxUser
5906
5937
  });
5907
- return true;
5908
5938
  }
5909
5939
  if (!lookup) {
5910
5940
  return value;
@@ -6117,7 +6147,7 @@ import path4 from "node:path";
6117
6147
  import { GraphQLError as GraphQLError5 } from "graphql";
6118
6148
  import micromatch2 from "micromatch";
6119
6149
  import sha2 from "js-sha1";
6120
- import set2 from "lodash.set";
6150
+ import { set as set2 } from "es-toolkit/compat";
6121
6151
  var createLocalDatabase = (config) => {
6122
6152
  const level = new TinaLevelClient(config?.port);
6123
6153
  level.openConnection();
@@ -6492,8 +6522,7 @@ var Database = class {
6492
6522
  throw new TinaFetchError(`Error in PUT for ${filepath}`, {
6493
6523
  originalError: error,
6494
6524
  file: filepath,
6495
- collection: collectionName,
6496
- stack: error.stack
6525
+ collection: collectionName
6497
6526
  });
6498
6527
  }
6499
6528
  };
@@ -6853,8 +6882,7 @@ var Database = class {
6853
6882
  throw new TinaQueryError({
6854
6883
  originalError: error,
6855
6884
  file: path7,
6856
- collection: collection.name,
6857
- stack: error.stack
6885
+ collection: collection.name
6858
6886
  });
6859
6887
  }
6860
6888
  throw error;
@@ -7384,8 +7412,7 @@ var _indexContent = async ({
7384
7412
  throw new TinaFetchError(`Unable to seed ${filepath}`, {
7385
7413
  originalError: error,
7386
7414
  file: filepath,
7387
- collection: collection?.name,
7388
- stack: error.stack
7415
+ collection: collection?.name
7389
7416
  });
7390
7417
  }
7391
7418
  });