@tinacms/graphql 2.2.5 → 2.3.1

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
@@ -3035,7 +3035,7 @@ var validateField = async (field) => {
3035
3035
  var package_default = {
3036
3036
  name: "@tinacms/graphql",
3037
3037
  type: "module",
3038
- version: "2.2.5",
3038
+ version: "2.3.1",
3039
3039
  main: "dist/index.js",
3040
3040
  module: "./dist/index.js",
3041
3041
  files: [
@@ -3779,6 +3779,9 @@ var getTemplateForFile = (templateInfo, data) => {
3779
3779
  throw new Error(`Unable to determine template`);
3780
3780
  };
3781
3781
  var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo) => {
3782
+ if (filepath.endsWith(".gitkeep")) {
3783
+ return { _is_tina_folder_placeholder: true };
3784
+ }
3782
3785
  const dataString = await bridge.get(normalizePath(filepath));
3783
3786
  const data = parseFile(
3784
3787
  dataString,
@@ -4638,21 +4641,17 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
4638
4641
  }
4639
4642
  if (hasTinaMediaConfig(schema) === true) {
4640
4643
  const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
4644
+ const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
4641
4645
  if (typeof value === "string" && value.includes(assetsURL)) {
4642
- const cleanMediaRoot = cleanUpSlashes(
4643
- schema.config.media.tina.mediaRoot
4644
- );
4645
- const strippedURL = value.replace(assetsURL, "");
4646
- return `${cleanMediaRoot}${strippedURL}`;
4646
+ return `${cleanMediaRoot}${stripStagingPrefix(
4647
+ value.replace(assetsURL, "")
4648
+ )}`;
4647
4649
  }
4648
4650
  if (Array.isArray(value)) {
4649
4651
  return value.map((v) => {
4650
4652
  if (!v || typeof v !== "string") return v;
4651
- const cleanMediaRoot = cleanUpSlashes(
4652
- schema.config.media.tina.mediaRoot
4653
- );
4654
4653
  const strippedURL = v.replace(assetsURL, "");
4655
- return `${cleanMediaRoot}${strippedURL}`;
4654
+ return `${cleanMediaRoot}${stripStagingPrefix(strippedURL)}`;
4656
4655
  });
4657
4656
  }
4658
4657
  return value;
@@ -4669,15 +4668,16 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
4669
4668
  }
4670
4669
  if (hasTinaMediaConfig(schema) === true) {
4671
4670
  const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
4671
+ const prefix = stagingPrefix(config);
4672
4672
  if (typeof value === "string") {
4673
4673
  const strippedValue = value.replace(cleanMediaRoot, "");
4674
- return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
4674
+ return `https://${config.assetsHost}/${config.clientId}${prefix}${strippedValue}`;
4675
4675
  }
4676
4676
  if (Array.isArray(value)) {
4677
4677
  return value.map((v) => {
4678
4678
  if (!v || typeof v !== "string") return v;
4679
4679
  const strippedValue = v.replace(cleanMediaRoot, "");
4680
- return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
4680
+ return `https://${config.assetsHost}/${config.clientId}${prefix}${strippedValue}`;
4681
4681
  });
4682
4682
  }
4683
4683
  }
@@ -4686,6 +4686,12 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
4686
4686
  return value;
4687
4687
  }
4688
4688
  };
4689
+ var stagingPrefix = (config) => config.branch && config.branch !== config.mediaBranch ? `/__staging/${encodeURIComponent(config.branch)}` : "";
4690
+ var STAGING_SEGMENT = /^\/__staging\/[^/]+(\/.*)$/;
4691
+ var stripStagingPrefix = (path9) => {
4692
+ const match = path9.match(STAGING_SEGMENT);
4693
+ return match ? match[1] : path9;
4694
+ };
4689
4695
  var cleanUpSlashes = (path9) => {
4690
4696
  if (path9) {
4691
4697
  return `/${path9.replace(/^\/+|\/+$/gm, "")}`;
@@ -5358,6 +5364,12 @@ var Resolver = class _Resolver {
5358
5364
  if (newRealPath === realPath) {
5359
5365
  return doc;
5360
5366
  }
5367
+ const newPathAlreadyExists = await this.database.documentExists(newRealPath);
5368
+ if (newPathAlreadyExists) {
5369
+ throw new Error(
5370
+ `Unable to rename document, ${newRealPath} already exists`
5371
+ );
5372
+ }
5361
5373
  await this.database.put(newRealPath, doc._rawData, collection.name);
5362
5374
  await this.deleteDocument(realPath);
5363
5375
  const collRefs = await this.findReferences(realPath, collection);
@@ -6912,7 +6924,10 @@ var Database = class {
6912
6924
  if (!collection) {
6913
6925
  throw new GraphQLError5(`Unable to find collection for ${filepath}.`);
6914
6926
  }
6915
- if (collection.match?.exclude || collection.match?.include) {
6927
+ const isFolderPlaceholder = filepath.endsWith(
6928
+ `.gitkeep.${collection.format || "md"}`
6929
+ );
6930
+ if (!isFolderPlaceholder && (collection.match?.exclude || collection.match?.include)) {
6916
6931
  const matches = this.tinaSchema.getMatches({ collection });
6917
6932
  const match = micromatch2.isMatch(filepath, matches);
6918
6933
  if (!match) {
@@ -7836,8 +7851,9 @@ var _indexContent = async ({
7836
7851
  ]);
7837
7852
  }
7838
7853
  }
7854
+ let putOps = [];
7839
7855
  if (!isGitKeep(filepath, collection)) {
7840
- await enqueueOps([
7856
+ putOps = [
7841
7857
  ...makeRefOpsForDocument(
7842
7858
  normalizedPath,
7843
7859
  collection?.name,
@@ -7862,18 +7878,21 @@ var _indexContent = async ({
7862
7878
  aliasedData,
7863
7879
  "put",
7864
7880
  level
7865
- ),
7866
- {
7867
- type: "put",
7868
- key: normalizedPath,
7869
- value: aliasedData,
7870
- sublevel: level.sublevel(
7871
- CONTENT_ROOT_PREFIX,
7872
- SUBLEVEL_OPTIONS
7873
- )
7874
- }
7875
- ]);
7881
+ )
7882
+ ];
7876
7883
  }
7884
+ await enqueueOps([
7885
+ ...putOps,
7886
+ {
7887
+ type: "put",
7888
+ key: normalizedPath,
7889
+ value: aliasedData,
7890
+ sublevel: level.sublevel(
7891
+ CONTENT_ROOT_PREFIX,
7892
+ SUBLEVEL_OPTIONS
7893
+ )
7894
+ }
7895
+ ]);
7877
7896
  } catch (error) {
7878
7897
  throw new TinaFetchError(`Unable to seed ${filepath}`, {
7879
7898
  originalError: error,
@@ -8648,3 +8667,8 @@ export {
8648
8667
  };
8649
8668
  //! Replaces _.get()
8650
8669
  //! Replaces _.flattenDeep()
8670
+ /**
8671
+ * @license
8672
+ * Copyright 2023 Forestry.io Holdings, Inc.
8673
+ * SPDX-License-Identifier: Apache-2.0
8674
+ */
@@ -11,6 +11,11 @@ interface ResolverConfig {
11
11
  isAudit: boolean;
12
12
  }
13
13
  export declare const createResolver: (args: ResolverConfig) => Resolver;
14
+ export declare const resolveFieldData: ({ namespace, ...field }: TinaField<true>, rawData: unknown, accumulator: {
15
+ [key: string]: unknown;
16
+ }, tinaSchema: TinaSchema, config?: GraphQLConfig, isAudit?: boolean) => Promise<{
17
+ [key: string]: unknown;
18
+ }>;
14
19
  export declare const transformDocumentIntoPayload: (fullPath: string, rawData: {
15
20
  _collection: any;
16
21
  _template: any;
@@ -1,6 +1,8 @@
1
1
  /**
2
-
3
- */
2
+ * @license
3
+ * Copyright 2023 Forestry.io Holdings, Inc.
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
4
6
  import type { Schema } from '@tinacms/schema-tools';
5
7
  import type { GraphQLConfig } from '../types';
6
8
  /**
package/dist/types.d.ts CHANGED
@@ -7,4 +7,6 @@ export type GraphQLConfig = {
7
7
  useRelativeMedia: false;
8
8
  clientId: string;
9
9
  assetsHost: string;
10
+ branch?: string;
11
+ mediaBranch?: string;
10
12
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
3
  "type": "module",
4
- "version": "2.2.5",
4
+ "version": "2.3.1",
5
5
  "main": "dist/index.js",
6
6
  "module": "./dist/index.js",
7
7
  "files": [
@@ -43,8 +43,8 @@
43
43
  "normalize-path": "^3.0.0",
44
44
  "readable-stream": "^4.7.0",
45
45
  "yup": "^1.6.1",
46
- "@tinacms/mdx": "2.1.2",
47
- "@tinacms/schema-tools": "2.7.2"
46
+ "@tinacms/mdx": "2.1.4",
47
+ "@tinacms/schema-tools": "2.7.4"
48
48
  },
49
49
  "publishConfig": {
50
50
  "registry": "https://registry.npmjs.org"
@@ -72,8 +72,8 @@
72
72
  "vite": "^4.5.9",
73
73
  "vitest": "^0.32.4",
74
74
  "zod": "^3.24.2",
75
- "@tinacms/scripts": "1.6.0",
76
- "@tinacms/schema-tools": "2.7.2"
75
+ "@tinacms/schema-tools": "2.7.4",
76
+ "@tinacms/scripts": "1.6.1"
77
77
  },
78
78
  "scripts": {
79
79
  "types": "pnpm tsc",