@tinacms/graphql 1.4.34 → 1.4.36

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.
@@ -134,6 +134,20 @@ export declare class Builder {
134
134
  * @param collections
135
135
  */
136
136
  buildDeleteCollectionDocumentMutation: (collections: Collection<true>[]) => Promise<FieldDefinitionNode>;
137
+ /**
138
+ * ```graphql
139
+ * # ex.
140
+ * {
141
+ * createFolder(folderName: $folderName, params: $params) {
142
+ * id
143
+ * data {...}
144
+ * }
145
+ * }
146
+ * ```
147
+ *
148
+ * @param collections
149
+ */
150
+ buildCreateCollectionFolderMutation: () => Promise<FieldDefinitionNode>;
137
151
  /**
138
152
  * ```graphql
139
153
  * # ex.
package/dist/index.js CHANGED
@@ -1685,6 +1685,25 @@ var Builder = class {
1685
1685
  type: astBuilder.TYPES.MultiCollectionDocument
1686
1686
  });
1687
1687
  };
1688
+ this.buildCreateCollectionFolderMutation = async () => {
1689
+ return astBuilder.FieldDefinition({
1690
+ name: "createFolder",
1691
+ args: [
1692
+ astBuilder.InputValueDefinition({
1693
+ name: "collection",
1694
+ required: false,
1695
+ type: astBuilder.TYPES.String
1696
+ }),
1697
+ astBuilder.InputValueDefinition({
1698
+ name: "relativePath",
1699
+ required: true,
1700
+ type: astBuilder.TYPES.String
1701
+ })
1702
+ ],
1703
+ required: true,
1704
+ type: astBuilder.TYPES.MultiCollectionDocument
1705
+ });
1706
+ };
1688
1707
  this.collectionDocument = async (collection) => {
1689
1708
  const name = NAMER.queryName([collection.name]);
1690
1709
  const type = await this._buildCollectionDocumentType(collection);
@@ -2855,7 +2874,7 @@ var validateField = async (field) => {
2855
2874
  // package.json
2856
2875
  var package_default = {
2857
2876
  name: "@tinacms/graphql",
2858
- version: "1.4.34",
2877
+ version: "1.4.36",
2859
2878
  main: "dist/index.js",
2860
2879
  module: "dist/index.mjs",
2861
2880
  typings: "dist/index.d.ts",
@@ -2880,8 +2899,8 @@ var package_default = {
2880
2899
  scripts: {
2881
2900
  types: "pnpm tsc",
2882
2901
  build: "tinacms-scripts build",
2883
- docs: "yarn typedoc",
2884
- serve: "yarn nodemon dist/server.js",
2902
+ docs: "pnpm typedoc",
2903
+ serve: "pnpm nodemon dist/server.js",
2885
2904
  test: "jest",
2886
2905
  "test-watch": "jest --watch"
2887
2906
  },
@@ -2890,12 +2909,7 @@ var package_default = {
2890
2909
  "@tinacms/mdx": "workspace:*",
2891
2910
  "@tinacms/schema-tools": "workspace:*",
2892
2911
  "abstract-level": "^1.0.3",
2893
- "body-parser": "^1.19.0",
2894
- cors: "^2.8.5",
2895
- dataloader: "^2.0.0",
2896
2912
  "date-fns": "^2.21.1",
2897
- "encoding-down": "^7.1.0",
2898
- "estree-walker": "^3.0.0",
2899
2913
  "fast-glob": "^3.2.5",
2900
2914
  "fs-extra": "^9.0.1",
2901
2915
  "glob-parent": "^6.0.2",
@@ -2945,7 +2959,7 @@ var package_default = {
2945
2959
  "jest-matcher-utils": "^29.5.0",
2946
2960
  "memory-level": "^1.0.0",
2947
2961
  nodemon: "2.0.19",
2948
- typescript: "4.3.5"
2962
+ typescript: "4.6.4"
2949
2963
  }
2950
2964
  };
2951
2965
 
@@ -3095,6 +3109,9 @@ var _buildSchema = async (builder, tinaSchema) => {
3095
3109
  mutationTypeDefinitionFields.push(
3096
3110
  await builder.buildCreateCollectionDocumentMutation(collections)
3097
3111
  );
3112
+ mutationTypeDefinitionFields.push(
3113
+ await builder.buildCreateCollectionFolderMutation()
3114
+ );
3098
3115
  await sequential(collections, async (collection) => {
3099
3116
  queryTypeDefinitionFields.push(await builder.collectionDocument(collection));
3100
3117
  if (collection.isAuthCollection) {
@@ -4877,6 +4894,7 @@ var Resolver = class {
4877
4894
  isMutation,
4878
4895
  isCreation,
4879
4896
  isDeletion,
4897
+ isFolderCreation,
4880
4898
  isAddPendingDocument,
4881
4899
  isCollectionSpecific,
4882
4900
  isUpdateName
@@ -4900,7 +4918,10 @@ var Resolver = class {
4900
4918
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
4901
4919
  );
4902
4920
  const collection = await this.tinaSchema.getCollection(collectionLookup);
4903
- const realPath = import_path3.default.join(collection == null ? void 0 : collection.path, args.relativePath);
4921
+ let realPath = import_path3.default.join(collection == null ? void 0 : collection.path, args.relativePath);
4922
+ if (isFolderCreation) {
4923
+ realPath = `${realPath}/.gitkeep.${collection.format || "md"}`;
4924
+ }
4904
4925
  const alreadyExists = await this.database.documentExists(realPath);
4905
4926
  if (isMutation) {
4906
4927
  if (isCreation) {
@@ -4913,6 +4934,16 @@ var Resolver = class {
4913
4934
  args,
4914
4935
  isAddPendingDocument
4915
4936
  });
4937
+ } else if (isFolderCreation) {
4938
+ if (alreadyExists === true) {
4939
+ throw new Error(`Unable to add folder, ${realPath} already exists`);
4940
+ }
4941
+ await this.database.put(
4942
+ realPath,
4943
+ { _is_tina_folder_placeholder: true },
4944
+ collection.name
4945
+ );
4946
+ return this.getDocument(realPath);
4916
4947
  }
4917
4948
  if (!alreadyExists) {
4918
4949
  if (isDeletion) {
@@ -5475,7 +5506,8 @@ var resolve = async ({
5475
5506
  NAMER.documentQueryName(),
5476
5507
  "createDocument",
5477
5508
  "updateDocument",
5478
- "deleteDocument"
5509
+ "deleteDocument",
5510
+ "createFolder"
5479
5511
  ].includes(info.fieldName)) {
5480
5512
  const result2 = await resolver.resolveDocument({
5481
5513
  args,
@@ -5483,6 +5515,7 @@ var resolve = async ({
5483
5515
  isMutation,
5484
5516
  isCreation,
5485
5517
  isDeletion: info.fieldName === "deleteDocument",
5518
+ isFolderCreation: info.fieldName === "createFolder",
5486
5519
  isUpdateName: Boolean((_a2 = args == null ? void 0 : args.params) == null ? void 0 : _a2.relativePath),
5487
5520
  isAddPendingDocument: false,
5488
5521
  isCollectionSpecific: false
@@ -5854,11 +5887,9 @@ var Database = class {
5854
5887
  );
5855
5888
  }
5856
5889
  }
5857
- const stringifiedFile = await this.stringifyFile(
5858
- filepath,
5859
- dataFields,
5860
- collection
5861
- );
5890
+ const stringifiedFile = filepath.endsWith(
5891
+ `.gitkeep.${collection.format || "md"}`
5892
+ ) ? "" : await this.stringifyFile(filepath, dataFields, collection);
5862
5893
  if (!(collection == null ? void 0 : collection.isDetached)) {
5863
5894
  if (this.bridge) {
5864
5895
  await this.bridge.put(normalizedPath, stringifiedFile);
package/dist/index.mjs CHANGED
@@ -1622,6 +1622,25 @@ var Builder = class {
1622
1622
  type: astBuilder.TYPES.MultiCollectionDocument
1623
1623
  });
1624
1624
  };
1625
+ this.buildCreateCollectionFolderMutation = async () => {
1626
+ return astBuilder.FieldDefinition({
1627
+ name: "createFolder",
1628
+ args: [
1629
+ astBuilder.InputValueDefinition({
1630
+ name: "collection",
1631
+ required: false,
1632
+ type: astBuilder.TYPES.String
1633
+ }),
1634
+ astBuilder.InputValueDefinition({
1635
+ name: "relativePath",
1636
+ required: true,
1637
+ type: astBuilder.TYPES.String
1638
+ })
1639
+ ],
1640
+ required: true,
1641
+ type: astBuilder.TYPES.MultiCollectionDocument
1642
+ });
1643
+ };
1625
1644
  this.collectionDocument = async (collection) => {
1626
1645
  const name = NAMER.queryName([collection.name]);
1627
1646
  const type = await this._buildCollectionDocumentType(collection);
@@ -2788,7 +2807,7 @@ var validateField = async (field) => {
2788
2807
  // package.json
2789
2808
  var package_default = {
2790
2809
  name: "@tinacms/graphql",
2791
- version: "1.4.34",
2810
+ version: "1.4.36",
2792
2811
  main: "dist/index.js",
2793
2812
  module: "dist/index.mjs",
2794
2813
  typings: "dist/index.d.ts",
@@ -2813,8 +2832,8 @@ var package_default = {
2813
2832
  scripts: {
2814
2833
  types: "pnpm tsc",
2815
2834
  build: "tinacms-scripts build",
2816
- docs: "yarn typedoc",
2817
- serve: "yarn nodemon dist/server.js",
2835
+ docs: "pnpm typedoc",
2836
+ serve: "pnpm nodemon dist/server.js",
2818
2837
  test: "jest",
2819
2838
  "test-watch": "jest --watch"
2820
2839
  },
@@ -2823,12 +2842,7 @@ var package_default = {
2823
2842
  "@tinacms/mdx": "workspace:*",
2824
2843
  "@tinacms/schema-tools": "workspace:*",
2825
2844
  "abstract-level": "^1.0.3",
2826
- "body-parser": "^1.19.0",
2827
- cors: "^2.8.5",
2828
- dataloader: "^2.0.0",
2829
2845
  "date-fns": "^2.21.1",
2830
- "encoding-down": "^7.1.0",
2831
- "estree-walker": "^3.0.0",
2832
2846
  "fast-glob": "^3.2.5",
2833
2847
  "fs-extra": "^9.0.1",
2834
2848
  "glob-parent": "^6.0.2",
@@ -2878,7 +2892,7 @@ var package_default = {
2878
2892
  "jest-matcher-utils": "^29.5.0",
2879
2893
  "memory-level": "^1.0.0",
2880
2894
  nodemon: "2.0.19",
2881
- typescript: "4.3.5"
2895
+ typescript: "4.6.4"
2882
2896
  }
2883
2897
  };
2884
2898
 
@@ -3027,6 +3041,9 @@ var _buildSchema = async (builder, tinaSchema) => {
3027
3041
  mutationTypeDefinitionFields.push(
3028
3042
  await builder.buildCreateCollectionDocumentMutation(collections)
3029
3043
  );
3044
+ mutationTypeDefinitionFields.push(
3045
+ await builder.buildCreateCollectionFolderMutation()
3046
+ );
3030
3047
  await sequential(collections, async (collection) => {
3031
3048
  queryTypeDefinitionFields.push(await builder.collectionDocument(collection));
3032
3049
  if (collection.isAuthCollection) {
@@ -4804,6 +4821,7 @@ var Resolver = class {
4804
4821
  isMutation,
4805
4822
  isCreation,
4806
4823
  isDeletion,
4824
+ isFolderCreation,
4807
4825
  isAddPendingDocument,
4808
4826
  isCollectionSpecific,
4809
4827
  isUpdateName
@@ -4827,7 +4845,10 @@ var Resolver = class {
4827
4845
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
4828
4846
  );
4829
4847
  const collection = await this.tinaSchema.getCollection(collectionLookup);
4830
- const realPath = path3.join(collection?.path, args.relativePath);
4848
+ let realPath = path3.join(collection?.path, args.relativePath);
4849
+ if (isFolderCreation) {
4850
+ realPath = `${realPath}/.gitkeep.${collection.format || "md"}`;
4851
+ }
4831
4852
  const alreadyExists = await this.database.documentExists(realPath);
4832
4853
  if (isMutation) {
4833
4854
  if (isCreation) {
@@ -4840,6 +4861,16 @@ var Resolver = class {
4840
4861
  args,
4841
4862
  isAddPendingDocument
4842
4863
  });
4864
+ } else if (isFolderCreation) {
4865
+ if (alreadyExists === true) {
4866
+ throw new Error(`Unable to add folder, ${realPath} already exists`);
4867
+ }
4868
+ await this.database.put(
4869
+ realPath,
4870
+ { _is_tina_folder_placeholder: true },
4871
+ collection.name
4872
+ );
4873
+ return this.getDocument(realPath);
4843
4874
  }
4844
4875
  if (!alreadyExists) {
4845
4876
  if (isDeletion) {
@@ -5397,7 +5428,8 @@ var resolve = async ({
5397
5428
  NAMER.documentQueryName(),
5398
5429
  "createDocument",
5399
5430
  "updateDocument",
5400
- "deleteDocument"
5431
+ "deleteDocument",
5432
+ "createFolder"
5401
5433
  ].includes(info.fieldName)) {
5402
5434
  const result2 = await resolver.resolveDocument({
5403
5435
  args,
@@ -5405,6 +5437,7 @@ var resolve = async ({
5405
5437
  isMutation,
5406
5438
  isCreation,
5407
5439
  isDeletion: info.fieldName === "deleteDocument",
5440
+ isFolderCreation: info.fieldName === "createFolder",
5408
5441
  isUpdateName: Boolean(args?.params?.relativePath),
5409
5442
  isAddPendingDocument: false,
5410
5443
  isCollectionSpecific: false
@@ -5775,11 +5808,9 @@ var Database = class {
5775
5808
  );
5776
5809
  }
5777
5810
  }
5778
- const stringifiedFile = await this.stringifyFile(
5779
- filepath,
5780
- dataFields,
5781
- collection
5782
- );
5811
+ const stringifiedFile = filepath.endsWith(
5812
+ `.gitkeep.${collection.format || "md"}`
5813
+ ) ? "" : await this.stringifyFile(filepath, dataFields, collection);
5783
5814
  if (!collection?.isDetached) {
5784
5815
  if (this.bridge) {
5785
5816
  await this.bridge.put(normalizedPath, stringifiedFile);
@@ -66,6 +66,9 @@ export declare class Resolver {
66
66
  ui?: import("@tinacms/schema-tools").UICollection<any, any, any>;
67
67
  defaultItem?: import("@tinacms/schema-tools").DefaultItem<Record<string, any>>;
68
68
  frontmatterFormat?: "json" | "yaml" | "toml";
69
+ /**
70
+ * For generic functions (like `createDocument()` and `updateDocument()`), `collection` is the top key of the `params`
71
+ */
69
72
  frontmatterDelimiters?: string | [string, string];
70
73
  match?: {
71
74
  include?: string;
@@ -94,6 +97,9 @@ export declare class Resolver {
94
97
  ui?: import("@tinacms/schema-tools").UICollection<any, any, any>;
95
98
  defaultItem?: import("@tinacms/schema-tools").DefaultItem<Record<string, any>>;
96
99
  frontmatterFormat?: "json" | "yaml" | "toml";
100
+ /**
101
+ * For generic functions (like `createDocument()` and `updateDocument()`), `collection` is the top key of the `params`
102
+ */
97
103
  frontmatterDelimiters?: string | [string, string];
98
104
  match?: {
99
105
  include?: string;
@@ -237,12 +243,13 @@ export declare class Resolver {
237
243
  * values are not eliminated from Tina when new values are saved
238
244
  */
239
245
  resolveLegacyValues: (oldDoc: any, collection: Collection<true>) => {};
240
- resolveDocument: ({ args, collection: collectionName, isMutation, isCreation, isDeletion, isAddPendingDocument, isCollectionSpecific, isUpdateName, }: {
246
+ resolveDocument: ({ args, collection: collectionName, isMutation, isCreation, isDeletion, isFolderCreation, isAddPendingDocument, isCollectionSpecific, isUpdateName, }: {
241
247
  args: unknown;
242
248
  collection?: string;
243
249
  isMutation: boolean;
244
250
  isCreation?: boolean;
245
251
  isDeletion?: boolean;
252
+ isFolderCreation?: boolean;
246
253
  isAddPendingDocument?: boolean;
247
254
  isCollectionSpecific?: boolean;
248
255
  isUpdateName?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "1.4.34",
3
+ "version": "1.4.36",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "typings": "dist/index.d.ts",
@@ -24,15 +24,8 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@iarna/toml": "^2.2.5",
27
- "@tinacms/mdx": "1.3.24",
28
- "@tinacms/schema-tools": "1.4.15",
29
27
  "abstract-level": "^1.0.3",
30
- "body-parser": "^1.19.0",
31
- "cors": "^2.8.5",
32
- "dataloader": "^2.0.0",
33
28
  "date-fns": "^2.21.1",
34
- "encoding-down": "^7.1.0",
35
- "estree-walker": "^3.0.0",
36
29
  "fast-glob": "^3.2.5",
37
30
  "fs-extra": "^9.0.1",
38
31
  "glob-parent": "^6.0.2",
@@ -48,7 +41,9 @@
48
41
  "normalize-path": "^3.0.0",
49
42
  "readable-stream": "^4.3.0",
50
43
  "scmp": "^2.1.0",
51
- "yup": "^0.32.9"
44
+ "yup": "^0.32.9",
45
+ "@tinacms/mdx": "1.3.26",
46
+ "@tinacms/schema-tools": "1.4.17"
52
47
  },
53
48
  "publishConfig": {
54
49
  "registry": "https://registry.npmjs.org"
@@ -58,8 +53,6 @@
58
53
  "directory": "packages/tina-graphql"
59
54
  },
60
55
  "devDependencies": {
61
- "@tinacms/schema-tools": "1.4.15",
62
- "@tinacms/scripts": "1.1.3",
63
56
  "@types/cors": "^2.8.7",
64
57
  "@types/estree": "^0.0.50",
65
58
  "@types/express": "^4.17.8",
@@ -82,13 +75,15 @@
82
75
  "jest-matcher-utils": "^29.5.0",
83
76
  "memory-level": "^1.0.0",
84
77
  "nodemon": "2.0.19",
85
- "typescript": "4.3.5"
78
+ "typescript": "4.6.4",
79
+ "@tinacms/schema-tools": "1.4.17",
80
+ "@tinacms/scripts": "1.1.5"
86
81
  },
87
82
  "scripts": {
88
83
  "types": "pnpm tsc",
89
84
  "build": "tinacms-scripts build",
90
- "docs": "yarn typedoc",
91
- "serve": "yarn nodemon dist/server.js",
85
+ "docs": "pnpm typedoc",
86
+ "serve": "pnpm nodemon dist/server.js",
92
87
  "test": "jest",
93
88
  "test-watch": "jest --watch"
94
89
  }