@tinacms/graphql 1.4.34 → 1.4.35

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.35",
2859
2878
  main: "dist/index.js",
2860
2879
  module: "dist/index.mjs",
2861
2880
  typings: "dist/index.d.ts",
@@ -3095,6 +3114,9 @@ var _buildSchema = async (builder, tinaSchema) => {
3095
3114
  mutationTypeDefinitionFields.push(
3096
3115
  await builder.buildCreateCollectionDocumentMutation(collections)
3097
3116
  );
3117
+ mutationTypeDefinitionFields.push(
3118
+ await builder.buildCreateCollectionFolderMutation()
3119
+ );
3098
3120
  await sequential(collections, async (collection) => {
3099
3121
  queryTypeDefinitionFields.push(await builder.collectionDocument(collection));
3100
3122
  if (collection.isAuthCollection) {
@@ -4877,6 +4899,7 @@ var Resolver = class {
4877
4899
  isMutation,
4878
4900
  isCreation,
4879
4901
  isDeletion,
4902
+ isFolderCreation,
4880
4903
  isAddPendingDocument,
4881
4904
  isCollectionSpecific,
4882
4905
  isUpdateName
@@ -4900,7 +4923,10 @@ var Resolver = class {
4900
4923
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
4901
4924
  );
4902
4925
  const collection = await this.tinaSchema.getCollection(collectionLookup);
4903
- const realPath = import_path3.default.join(collection == null ? void 0 : collection.path, args.relativePath);
4926
+ let realPath = import_path3.default.join(collection == null ? void 0 : collection.path, args.relativePath);
4927
+ if (isFolderCreation) {
4928
+ realPath = `${realPath}/.gitkeep`;
4929
+ }
4904
4930
  const alreadyExists = await this.database.documentExists(realPath);
4905
4931
  if (isMutation) {
4906
4932
  if (isCreation) {
@@ -4913,6 +4939,16 @@ var Resolver = class {
4913
4939
  args,
4914
4940
  isAddPendingDocument
4915
4941
  });
4942
+ } else if (isFolderCreation) {
4943
+ if (alreadyExists === true) {
4944
+ throw new Error(`Unable to add folder, ${realPath} already exists`);
4945
+ }
4946
+ await this.database.put(
4947
+ realPath,
4948
+ { _is_tina_folder_placeholder: true },
4949
+ collection.name
4950
+ );
4951
+ return this.getDocument(realPath);
4916
4952
  }
4917
4953
  if (!alreadyExists) {
4918
4954
  if (isDeletion) {
@@ -5475,7 +5511,8 @@ var resolve = async ({
5475
5511
  NAMER.documentQueryName(),
5476
5512
  "createDocument",
5477
5513
  "updateDocument",
5478
- "deleteDocument"
5514
+ "deleteDocument",
5515
+ "createFolder"
5479
5516
  ].includes(info.fieldName)) {
5480
5517
  const result2 = await resolver.resolveDocument({
5481
5518
  args,
@@ -5483,6 +5520,7 @@ var resolve = async ({
5483
5520
  isMutation,
5484
5521
  isCreation,
5485
5522
  isDeletion: info.fieldName === "deleteDocument",
5523
+ isFolderCreation: info.fieldName === "createFolder",
5486
5524
  isUpdateName: Boolean((_a2 = args == null ? void 0 : args.params) == null ? void 0 : _a2.relativePath),
5487
5525
  isAddPendingDocument: false,
5488
5526
  isCollectionSpecific: false
@@ -5826,6 +5864,7 @@ var Database = class {
5826
5864
  this.put = async (filepath, data, collectionName) => {
5827
5865
  var _a, _b;
5828
5866
  await this.initLevel();
5867
+ const isGitKeep = filepath.endsWith(".gitkeep");
5829
5868
  try {
5830
5869
  if (SYSTEM_FILES.includes(filepath)) {
5831
5870
  throw new Error(`Unexpected put for config file ${filepath}`);
@@ -5854,11 +5893,7 @@ var Database = class {
5854
5893
  );
5855
5894
  }
5856
5895
  }
5857
- const stringifiedFile = await this.stringifyFile(
5858
- filepath,
5859
- dataFields,
5860
- collection
5861
- );
5896
+ const stringifiedFile = isGitKeep ? "" : await this.stringifyFile(filepath, dataFields, collection);
5862
5897
  if (!(collection == null ? void 0 : collection.isDetached)) {
5863
5898
  if (this.bridge) {
5864
5899
  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.35",
2792
2811
  main: "dist/index.js",
2793
2812
  module: "dist/index.mjs",
2794
2813
  typings: "dist/index.d.ts",
@@ -3027,6 +3046,9 @@ var _buildSchema = async (builder, tinaSchema) => {
3027
3046
  mutationTypeDefinitionFields.push(
3028
3047
  await builder.buildCreateCollectionDocumentMutation(collections)
3029
3048
  );
3049
+ mutationTypeDefinitionFields.push(
3050
+ await builder.buildCreateCollectionFolderMutation()
3051
+ );
3030
3052
  await sequential(collections, async (collection) => {
3031
3053
  queryTypeDefinitionFields.push(await builder.collectionDocument(collection));
3032
3054
  if (collection.isAuthCollection) {
@@ -4804,6 +4826,7 @@ var Resolver = class {
4804
4826
  isMutation,
4805
4827
  isCreation,
4806
4828
  isDeletion,
4829
+ isFolderCreation,
4807
4830
  isAddPendingDocument,
4808
4831
  isCollectionSpecific,
4809
4832
  isUpdateName
@@ -4827,7 +4850,10 @@ var Resolver = class {
4827
4850
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
4828
4851
  );
4829
4852
  const collection = await this.tinaSchema.getCollection(collectionLookup);
4830
- const realPath = path3.join(collection?.path, args.relativePath);
4853
+ let realPath = path3.join(collection?.path, args.relativePath);
4854
+ if (isFolderCreation) {
4855
+ realPath = `${realPath}/.gitkeep`;
4856
+ }
4831
4857
  const alreadyExists = await this.database.documentExists(realPath);
4832
4858
  if (isMutation) {
4833
4859
  if (isCreation) {
@@ -4840,6 +4866,16 @@ var Resolver = class {
4840
4866
  args,
4841
4867
  isAddPendingDocument
4842
4868
  });
4869
+ } else if (isFolderCreation) {
4870
+ if (alreadyExists === true) {
4871
+ throw new Error(`Unable to add folder, ${realPath} already exists`);
4872
+ }
4873
+ await this.database.put(
4874
+ realPath,
4875
+ { _is_tina_folder_placeholder: true },
4876
+ collection.name
4877
+ );
4878
+ return this.getDocument(realPath);
4843
4879
  }
4844
4880
  if (!alreadyExists) {
4845
4881
  if (isDeletion) {
@@ -5397,7 +5433,8 @@ var resolve = async ({
5397
5433
  NAMER.documentQueryName(),
5398
5434
  "createDocument",
5399
5435
  "updateDocument",
5400
- "deleteDocument"
5436
+ "deleteDocument",
5437
+ "createFolder"
5401
5438
  ].includes(info.fieldName)) {
5402
5439
  const result2 = await resolver.resolveDocument({
5403
5440
  args,
@@ -5405,6 +5442,7 @@ var resolve = async ({
5405
5442
  isMutation,
5406
5443
  isCreation,
5407
5444
  isDeletion: info.fieldName === "deleteDocument",
5445
+ isFolderCreation: info.fieldName === "createFolder",
5408
5446
  isUpdateName: Boolean(args?.params?.relativePath),
5409
5447
  isAddPendingDocument: false,
5410
5448
  isCollectionSpecific: false
@@ -5747,6 +5785,7 @@ var Database = class {
5747
5785
  };
5748
5786
  this.put = async (filepath, data, collectionName) => {
5749
5787
  await this.initLevel();
5788
+ const isGitKeep = filepath.endsWith(".gitkeep");
5750
5789
  try {
5751
5790
  if (SYSTEM_FILES.includes(filepath)) {
5752
5791
  throw new Error(`Unexpected put for config file ${filepath}`);
@@ -5775,11 +5814,7 @@ var Database = class {
5775
5814
  );
5776
5815
  }
5777
5816
  }
5778
- const stringifiedFile = await this.stringifyFile(
5779
- filepath,
5780
- dataFields,
5781
- collection
5782
- );
5817
+ const stringifiedFile = isGitKeep ? "" : await this.stringifyFile(filepath, dataFields, collection);
5783
5818
  if (!collection?.isDetached) {
5784
5819
  if (this.bridge) {
5785
5820
  await this.bridge.put(normalizedPath, stringifiedFile);
@@ -52,7 +52,9 @@ export declare class Resolver {
52
52
  constructor(init: ResolverConfig);
53
53
  resolveCollection: (args: any, collectionName: string, hasDocuments?: boolean) => Promise<{
54
54
  fields: TinaField<true>[];
55
- templates?: undefined;
55
+ templates?: undefined; /**
56
+ * createDocument, create<Collection>Document
57
+ */
56
58
  label?: string;
57
59
  name: string;
58
60
  path: string;
@@ -66,6 +68,9 @@ export declare class Resolver {
66
68
  ui?: import("@tinacms/schema-tools").UICollection<any, any, any>;
67
69
  defaultItem?: import("@tinacms/schema-tools").DefaultItem<Record<string, any>>;
68
70
  frontmatterFormat?: "json" | "yaml" | "toml";
71
+ /**
72
+ * For generic functions (like `createDocument()` and `updateDocument()`), `collection` is the top key of the `params`
73
+ */
69
74
  frontmatterDelimiters?: string | [string, string];
70
75
  match?: {
71
76
  include?: string;
@@ -94,6 +99,9 @@ export declare class Resolver {
94
99
  ui?: import("@tinacms/schema-tools").UICollection<any, any, any>;
95
100
  defaultItem?: import("@tinacms/schema-tools").DefaultItem<Record<string, any>>;
96
101
  frontmatterFormat?: "json" | "yaml" | "toml";
102
+ /**
103
+ * For generic functions (like `createDocument()` and `updateDocument()`), `collection` is the top key of the `params`
104
+ */
97
105
  frontmatterDelimiters?: string | [string, string];
98
106
  match?: {
99
107
  include?: string;
@@ -237,12 +245,13 @@ export declare class Resolver {
237
245
  * values are not eliminated from Tina when new values are saved
238
246
  */
239
247
  resolveLegacyValues: (oldDoc: any, collection: Collection<true>) => {};
240
- resolveDocument: ({ args, collection: collectionName, isMutation, isCreation, isDeletion, isAddPendingDocument, isCollectionSpecific, isUpdateName, }: {
248
+ resolveDocument: ({ args, collection: collectionName, isMutation, isCreation, isDeletion, isFolderCreation, isAddPendingDocument, isCollectionSpecific, isUpdateName, }: {
241
249
  args: unknown;
242
250
  collection?: string;
243
251
  isMutation: boolean;
244
252
  isCreation?: boolean;
245
253
  isDeletion?: boolean;
254
+ isFolderCreation?: boolean;
246
255
  isAddPendingDocument?: boolean;
247
256
  isCollectionSpecific?: boolean;
248
257
  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.35",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "typings": "dist/index.d.ts",
@@ -24,8 +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",
27
+ "@tinacms/mdx": "1.3.25",
28
+ "@tinacms/schema-tools": "1.4.16",
29
29
  "abstract-level": "^1.0.3",
30
30
  "body-parser": "^1.19.0",
31
31
  "cors": "^2.8.5",
@@ -58,8 +58,8 @@
58
58
  "directory": "packages/tina-graphql"
59
59
  },
60
60
  "devDependencies": {
61
- "@tinacms/schema-tools": "1.4.15",
62
- "@tinacms/scripts": "1.1.3",
61
+ "@tinacms/schema-tools": "1.4.16",
62
+ "@tinacms/scripts": "1.1.4",
63
63
  "@types/cors": "^2.8.7",
64
64
  "@types/estree": "^0.0.50",
65
65
  "@types/express": "^4.17.8",