@tinacms/graphql 0.0.0-20240507230056 → 0.0.0-20240603083347

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.
@@ -127,7 +127,7 @@ export declare class Database {
127
127
  getSchema: (level?: Level, existingSchema?: Schema) => Promise<TinaSchema>;
128
128
  getIndexDefinitions: (level?: Level) => Promise<Record<string, Record<string, IndexDefinition>>>;
129
129
  documentExists: (fullpath: unknown) => Promise<boolean>;
130
- query: (queryOptions: QueryOptions, hydrator: any, cache?: Record<string, any>) => Promise<{
130
+ query: (queryOptions: QueryOptions, hydrator: any) => Promise<{
131
131
  edges: {
132
132
  node: any;
133
133
  cursor: string;
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);
@@ -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) {
@@ -4353,7 +4375,7 @@ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opT
4353
4375
  type: opType,
4354
4376
  key: filepath,
4355
4377
  sublevel: indexSublevel,
4356
- value: opType === "put" ? data : void 0
4378
+ value: opType === "put" ? {} : void 0
4357
4379
  });
4358
4380
  } else {
4359
4381
  if (indexedValue) {
@@ -4361,7 +4383,7 @@ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opT
4361
4383
  type: opType,
4362
4384
  key: `${indexedValue}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
4363
4385
  sublevel: indexSublevel,
4364
- value: opType === "put" ? data : void 0
4386
+ value: opType === "put" ? {} : void 0
4365
4387
  });
4366
4388
  }
4367
4389
  }
@@ -4390,9 +4412,7 @@ var stringEscaper = makeStringEscaper(
4390
4412
  );
4391
4413
 
4392
4414
  // src/resolver/index.ts
4393
- var queryCache;
4394
4415
  var createResolver = (args) => {
4395
- queryCache = {};
4396
4416
  return new Resolver(args);
4397
4417
  };
4398
4418
  var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
@@ -4614,10 +4634,7 @@ var Resolver = class {
4614
4634
  `fullPath must be of type string for getDocumentOrDirectory request`
4615
4635
  );
4616
4636
  }
4617
- let rawData = queryCache[fullPath];
4618
- if (!rawData) {
4619
- rawData = await this.getRaw(fullPath);
4620
- }
4637
+ const rawData = await this.getRaw(fullPath);
4621
4638
  if (rawData["__folderBasename"]) {
4622
4639
  return {
4623
4640
  __typename: "Folder",
@@ -4882,6 +4899,7 @@ var Resolver = class {
4882
4899
  isMutation,
4883
4900
  isCreation,
4884
4901
  isDeletion,
4902
+ isFolderCreation,
4885
4903
  isAddPendingDocument,
4886
4904
  isCollectionSpecific,
4887
4905
  isUpdateName
@@ -4905,7 +4923,10 @@ var Resolver = class {
4905
4923
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
4906
4924
  );
4907
4925
  const collection = await this.tinaSchema.getCollection(collectionLookup);
4908
- 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
+ }
4909
4930
  const alreadyExists = await this.database.documentExists(realPath);
4910
4931
  if (isMutation) {
4911
4932
  if (isCreation) {
@@ -4918,6 +4939,16 @@ var Resolver = class {
4918
4939
  args,
4919
4940
  isAddPendingDocument
4920
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);
4921
4952
  }
4922
4953
  if (!alreadyExists) {
4923
4954
  if (isDeletion) {
@@ -5054,8 +5085,7 @@ var Resolver = class {
5054
5085
  };
5055
5086
  const result = await this.database.query(
5056
5087
  queryOptions,
5057
- hydrator ? hydrator : this.getDocumentOrDirectory,
5058
- queryCache
5088
+ hydrator ? hydrator : this.getDocumentOrDirectory
5059
5089
  );
5060
5090
  const edges = result.edges;
5061
5091
  const pageInfo = result.pageInfo;
@@ -5481,7 +5511,8 @@ var resolve = async ({
5481
5511
  NAMER.documentQueryName(),
5482
5512
  "createDocument",
5483
5513
  "updateDocument",
5484
- "deleteDocument"
5514
+ "deleteDocument",
5515
+ "createFolder"
5485
5516
  ].includes(info.fieldName)) {
5486
5517
  const result2 = await resolver.resolveDocument({
5487
5518
  args,
@@ -5489,6 +5520,7 @@ var resolve = async ({
5489
5520
  isMutation,
5490
5521
  isCreation,
5491
5522
  isDeletion: info.fieldName === "deleteDocument",
5523
+ isFolderCreation: info.fieldName === "createFolder",
5492
5524
  isUpdateName: Boolean((_a2 = args == null ? void 0 : args.params) == null ? void 0 : _a2.relativePath),
5493
5525
  isAddPendingDocument: false,
5494
5526
  isCollectionSpecific: false
@@ -5832,6 +5864,7 @@ var Database = class {
5832
5864
  this.put = async (filepath, data, collectionName) => {
5833
5865
  var _a, _b;
5834
5866
  await this.initLevel();
5867
+ const isGitKeep = filepath.endsWith(".gitkeep");
5835
5868
  try {
5836
5869
  if (SYSTEM_FILES.includes(filepath)) {
5837
5870
  throw new Error(`Unexpected put for config file ${filepath}`);
@@ -5860,11 +5893,7 @@ var Database = class {
5860
5893
  );
5861
5894
  }
5862
5895
  }
5863
- const stringifiedFile = await this.stringifyFile(
5864
- filepath,
5865
- dataFields,
5866
- collection
5867
- );
5896
+ const stringifiedFile = isGitKeep ? "" : await this.stringifyFile(filepath, dataFields, collection);
5868
5897
  if (!(collection == null ? void 0 : collection.isDetached)) {
5869
5898
  if (this.bridge) {
5870
5899
  await this.bridge.put(normalizedPath, stringifiedFile);
@@ -6132,7 +6161,7 @@ var Database = class {
6132
6161
  }
6133
6162
  return true;
6134
6163
  };
6135
- this.query = async (queryOptions, hydrator, cache = {}) => {
6164
+ this.query = async (queryOptions, hydrator) => {
6136
6165
  var _a;
6137
6166
  await this.initLevel();
6138
6167
  const {
@@ -6228,7 +6257,6 @@ var Database = class {
6228
6257
  }
6229
6258
  break;
6230
6259
  }
6231
- cache[filepath] = { ...value, _collection: collection.name };
6232
6260
  startKey = startKey || key || "";
6233
6261
  endKey = key || "";
6234
6262
  edges = [...edges, { cursor: key, path: filepath }];
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);
@@ -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) {
@@ -4282,7 +4304,7 @@ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opT
4282
4304
  type: opType,
4283
4305
  key: filepath,
4284
4306
  sublevel: indexSublevel,
4285
- value: opType === "put" ? data : void 0
4307
+ value: opType === "put" ? {} : void 0
4286
4308
  });
4287
4309
  } else {
4288
4310
  if (indexedValue) {
@@ -4290,7 +4312,7 @@ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opT
4290
4312
  type: opType,
4291
4313
  key: `${indexedValue}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
4292
4314
  sublevel: indexSublevel,
4293
- value: opType === "put" ? data : void 0
4315
+ value: opType === "put" ? {} : void 0
4294
4316
  });
4295
4317
  }
4296
4318
  }
@@ -4319,9 +4341,7 @@ var stringEscaper = makeStringEscaper(
4319
4341
  );
4320
4342
 
4321
4343
  // src/resolver/index.ts
4322
- var queryCache;
4323
4344
  var createResolver = (args) => {
4324
- queryCache = {};
4325
4345
  return new Resolver(args);
4326
4346
  };
4327
4347
  var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
@@ -4542,10 +4562,7 @@ var Resolver = class {
4542
4562
  `fullPath must be of type string for getDocumentOrDirectory request`
4543
4563
  );
4544
4564
  }
4545
- let rawData = queryCache[fullPath];
4546
- if (!rawData) {
4547
- rawData = await this.getRaw(fullPath);
4548
- }
4565
+ const rawData = await this.getRaw(fullPath);
4549
4566
  if (rawData["__folderBasename"]) {
4550
4567
  return {
4551
4568
  __typename: "Folder",
@@ -4809,6 +4826,7 @@ var Resolver = class {
4809
4826
  isMutation,
4810
4827
  isCreation,
4811
4828
  isDeletion,
4829
+ isFolderCreation,
4812
4830
  isAddPendingDocument,
4813
4831
  isCollectionSpecific,
4814
4832
  isUpdateName
@@ -4832,7 +4850,10 @@ var Resolver = class {
4832
4850
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
4833
4851
  );
4834
4852
  const collection = await this.tinaSchema.getCollection(collectionLookup);
4835
- 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
+ }
4836
4857
  const alreadyExists = await this.database.documentExists(realPath);
4837
4858
  if (isMutation) {
4838
4859
  if (isCreation) {
@@ -4845,6 +4866,16 @@ var Resolver = class {
4845
4866
  args,
4846
4867
  isAddPendingDocument
4847
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);
4848
4879
  }
4849
4880
  if (!alreadyExists) {
4850
4881
  if (isDeletion) {
@@ -4981,8 +5012,7 @@ var Resolver = class {
4981
5012
  };
4982
5013
  const result = await this.database.query(
4983
5014
  queryOptions,
4984
- hydrator ? hydrator : this.getDocumentOrDirectory,
4985
- queryCache
5015
+ hydrator ? hydrator : this.getDocumentOrDirectory
4986
5016
  );
4987
5017
  const edges = result.edges;
4988
5018
  const pageInfo = result.pageInfo;
@@ -5403,7 +5433,8 @@ var resolve = async ({
5403
5433
  NAMER.documentQueryName(),
5404
5434
  "createDocument",
5405
5435
  "updateDocument",
5406
- "deleteDocument"
5436
+ "deleteDocument",
5437
+ "createFolder"
5407
5438
  ].includes(info.fieldName)) {
5408
5439
  const result2 = await resolver.resolveDocument({
5409
5440
  args,
@@ -5411,6 +5442,7 @@ var resolve = async ({
5411
5442
  isMutation,
5412
5443
  isCreation,
5413
5444
  isDeletion: info.fieldName === "deleteDocument",
5445
+ isFolderCreation: info.fieldName === "createFolder",
5414
5446
  isUpdateName: Boolean(args?.params?.relativePath),
5415
5447
  isAddPendingDocument: false,
5416
5448
  isCollectionSpecific: false
@@ -5753,6 +5785,7 @@ var Database = class {
5753
5785
  };
5754
5786
  this.put = async (filepath, data, collectionName) => {
5755
5787
  await this.initLevel();
5788
+ const isGitKeep = filepath.endsWith(".gitkeep");
5756
5789
  try {
5757
5790
  if (SYSTEM_FILES.includes(filepath)) {
5758
5791
  throw new Error(`Unexpected put for config file ${filepath}`);
@@ -5781,11 +5814,7 @@ var Database = class {
5781
5814
  );
5782
5815
  }
5783
5816
  }
5784
- const stringifiedFile = await this.stringifyFile(
5785
- filepath,
5786
- dataFields,
5787
- collection
5788
- );
5817
+ const stringifiedFile = isGitKeep ? "" : await this.stringifyFile(filepath, dataFields, collection);
5789
5818
  if (!collection?.isDetached) {
5790
5819
  if (this.bridge) {
5791
5820
  await this.bridge.put(normalizedPath, stringifiedFile);
@@ -6053,7 +6082,7 @@ var Database = class {
6053
6082
  }
6054
6083
  return true;
6055
6084
  };
6056
- this.query = async (queryOptions, hydrator, cache = {}) => {
6085
+ this.query = async (queryOptions, hydrator) => {
6057
6086
  await this.initLevel();
6058
6087
  const {
6059
6088
  first,
@@ -6148,7 +6177,6 @@ var Database = class {
6148
6177
  }
6149
6178
  break;
6150
6179
  }
6151
- cache[filepath] = { ...value, _collection: collection.name };
6152
6180
  startKey = startKey || key || "";
6153
6181
  endKey = key || "";
6154
6182
  edges = [...edges, { cursor: key, path: filepath }];
@@ -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": "0.0.0-20240507230056",
3
+ "version": "0.0.0-20240603083347",
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": "0.0.0-20240603083347",
28
+ "@tinacms/schema-tools": "0.0.0-20240603083347",
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": "0.0.0-20240603083347",
62
+ "@tinacms/scripts": "0.0.0-20240603083347",
63
63
  "@types/cors": "^2.8.7",
64
64
  "@types/estree": "^0.0.50",
65
65
  "@types/express": "^4.17.8",