@tinacms/graphql 0.0.0-202231073 → 0.0.0-2022311143526

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # tina-graphql
2
2
 
3
- ## 0.0.0-202231073
3
+ ## 0.0.0-2022311143526
4
4
 
5
5
  ### Patch Changes
6
6
 
@@ -38,10 +38,9 @@
38
38
  Before this fix, `breadcrumbs` was only the `basename` of the file minus the `extension`. So `my-folder-a/my-folder-b/my-file.md` would have `breadcrumbs` of `['my-file']`. With this change, `breadcrumbs` will be `['my-folder-a','my-folder-b','my-file']` (leaving out the `content/<collection>`).
39
39
 
40
40
  - e8b0de1f7: Add `parentTypename` to fields to allow us to disambiguate between fields which have the same field names but different types. Example, an event from field name of `blocks.0.title` could belong to a `Cta` block or a `Hero` block, both of which have a `title` field.
41
- - Updated dependencies [8b3be903f]
42
41
  - Updated dependencies [a87e1e6fa]
43
42
  - Updated dependencies [b01f2e382]
44
- - @tinacms/datalayer@0.0.0-202231073
43
+ - @tinacms/datalayer@0.0.0-2022311143526
45
44
 
46
45
  ## 0.59.8
47
46
 
@@ -147,6 +147,10 @@ export declare const NAMER: {
147
147
  dataMutationTypeName: (namespace: string[]) => string;
148
148
  updateName: (namespace: string[]) => string;
149
149
  createName: (namespace: string[]) => string;
150
+ documentQueryName: () => string;
151
+ documentConnectionQueryName: () => string;
152
+ collectionQueryName: () => string;
153
+ collectionListQueryName: () => string;
150
154
  queryName: (namespace: string[]) => string;
151
155
  generateQueryListName: (namespace: string[]) => string;
152
156
  fragmentName: (namespace: string[]) => string;
@@ -138,6 +138,20 @@ export declare class Builder {
138
138
  * @param collections
139
139
  */
140
140
  buildUpdateCollectionDocumentMutation: (collections: TinaCloudCollectionEnriched[]) => Promise<import("graphql").FieldDefinitionNode>;
141
+ /**
142
+ * ```graphql
143
+ * # ex.
144
+ * {
145
+ * deleteDocument(relativePath: $relativePath, params: $params) {
146
+ * id
147
+ * data {...}
148
+ * }
149
+ * }
150
+ * ```
151
+ *
152
+ * @param collections
153
+ */
154
+ buildDeleteCollectionDocumentMutation: (collections: TinaCloudCollectionEnriched[]) => Promise<import("graphql").FieldDefinitionNode>;
141
155
  /**
142
156
  * ```graphql
143
157
  * # ex.
@@ -15,6 +15,7 @@ export interface Bridge {
15
15
  glob(pattern: string): Promise<string[]>;
16
16
  get(filepath: string): Promise<string>;
17
17
  put(filepath: string, data: string): Promise<void>;
18
+ delete(filepath: string): Promise<void>;
18
19
  /**
19
20
  * Whether this bridge supports the ability to build the schema.
20
21
  */
@@ -85,6 +85,7 @@ export declare class Database {
85
85
  tinaSchema: TinaSchema;
86
86
  }) => Promise<void>;
87
87
  indexContentByPaths: (documentPaths: string[]) => Promise<void>;
88
+ delete: (filepath: string) => Promise<void>;
88
89
  _indexAllContent: () => Promise<void>;
89
90
  addToLookupMap: (lookup: LookupMapType) => Promise<void>;
90
91
  }
package/dist/index.js CHANGED
@@ -10404,6 +10404,44 @@ var import_graphql2 = __toModule(require("graphql"));
10404
10404
 
10405
10405
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/ast-builder/index.ts
10406
10406
  var import_lodash = __toModule(require("lodash"));
10407
+
10408
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/util.ts
10409
+ var yup = __toModule(require("yup"));
10410
+ var import_graphql = __toModule(require("graphql"));
10411
+ var sequential = async (items, callback) => {
10412
+ const accum = [];
10413
+ if (!items) {
10414
+ return [];
10415
+ }
10416
+ const reducePromises = async (previous2, endpoint) => {
10417
+ const prev = await previous2;
10418
+ if (prev) {
10419
+ accum.push(prev);
10420
+ }
10421
+ return callback(endpoint, accum.length);
10422
+ };
10423
+ const result = await items.reduce(reducePromises, Promise.resolve());
10424
+ if (result) {
10425
+ accum.push(result);
10426
+ }
10427
+ return accum;
10428
+ };
10429
+ function assertShape(value, yupSchema, errorMessage) {
10430
+ const shape = yupSchema(yup);
10431
+ try {
10432
+ shape.validateSync(value);
10433
+ } catch (e) {
10434
+ const message = errorMessage || `Failed to assertShape - ${e.message}`;
10435
+ throw new import_graphql.GraphQLError(message, null, null, null, null, null, {
10436
+ stack: e.stack
10437
+ });
10438
+ }
10439
+ }
10440
+ var lastItem = (arr) => {
10441
+ return arr[arr.length - 1];
10442
+ };
10443
+
10444
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/ast-builder/index.ts
10407
10445
  var SysFieldDefinition = {
10408
10446
  kind: "Field",
10409
10447
  name: {
@@ -11125,19 +11163,31 @@ var NAMER = {
11125
11163
  return generateNamespacedFieldName(namespace, "Mutation");
11126
11164
  },
11127
11165
  updateName: (namespace) => {
11128
- return "update" + generateNamespacedFieldName(namespace, "Document");
11166
+ return `update${generateNamespacedFieldName(namespace)}`;
11129
11167
  },
11130
11168
  createName: (namespace) => {
11131
- return "create" + generateNamespacedFieldName(namespace, "Document");
11169
+ return `create${generateNamespacedFieldName(namespace)}`;
11170
+ },
11171
+ documentQueryName: () => {
11172
+ return "document";
11173
+ },
11174
+ documentConnectionQueryName: () => {
11175
+ return "documentConnection";
11176
+ },
11177
+ collectionQueryName: () => {
11178
+ return "collection";
11179
+ },
11180
+ collectionListQueryName: () => {
11181
+ return "collections";
11132
11182
  },
11133
11183
  queryName: (namespace) => {
11134
- return "get" + generateNamespacedFieldName(namespace, "Document");
11184
+ return String(lastItem(namespace));
11135
11185
  },
11136
11186
  generateQueryListName: (namespace) => {
11137
- return "get" + generateNamespacedFieldName(namespace, "List");
11187
+ return `${lastItem(namespace)}Connection`;
11138
11188
  },
11139
11189
  fragmentName: (namespace) => {
11140
- return generateNamespacedFieldName(namespace, "") + "Parts";
11190
+ return `${generateNamespacedFieldName(namespace, "")}Parts`;
11141
11191
  },
11142
11192
  collectionTypeName: (namespace) => {
11143
11193
  return generateNamespacedFieldName(namespace, "Collection");
@@ -11156,42 +11206,6 @@ var NAMER = {
11156
11206
  }
11157
11207
  };
11158
11208
 
11159
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/util.ts
11160
- var yup = __toModule(require("yup"));
11161
- var import_graphql = __toModule(require("graphql"));
11162
- var sequential = async (items, callback) => {
11163
- const accum = [];
11164
- if (!items) {
11165
- return [];
11166
- }
11167
- const reducePromises = async (previous2, endpoint) => {
11168
- const prev = await previous2;
11169
- if (prev) {
11170
- accum.push(prev);
11171
- }
11172
- return callback(endpoint, accum.length);
11173
- };
11174
- const result = await items.reduce(reducePromises, Promise.resolve());
11175
- if (result) {
11176
- accum.push(result);
11177
- }
11178
- return accum;
11179
- };
11180
- function assertShape(value, yupSchema, errorMessage) {
11181
- const shape = yupSchema(yup);
11182
- try {
11183
- shape.validateSync(value);
11184
- } catch (e) {
11185
- const message = errorMessage || `Failed to assertShape - ${e.message}`;
11186
- throw new import_graphql.GraphQLError(message, null, null, null, null, null, {
11187
- stack: e.stack
11188
- });
11189
- }
11190
- }
11191
- var lastItem = (arr) => {
11192
- return arr[arr.length - 1];
11193
- };
11194
-
11195
11209
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/builder/static-definitions.ts
11196
11210
  var interfaceDefinitions = [
11197
11211
  astBuilder.InterfaceTypeDefinition({
@@ -11337,7 +11351,7 @@ var Builder = class {
11337
11351
  constructor(config) {
11338
11352
  this.config = config;
11339
11353
  this.buildCollectionDefinition = async (collections) => {
11340
- const name2 = "getCollection";
11354
+ const name2 = NAMER.collectionQueryName();
11341
11355
  const typeName = "Collection";
11342
11356
  const args = [
11343
11357
  astBuilder.InputValueDefinition({
@@ -11401,7 +11415,7 @@ var Builder = class {
11401
11415
  return astBuilder.FieldDefinition({ type, name: name2, args, required: true });
11402
11416
  };
11403
11417
  this.buildMultiCollectionDefinition = async (collections) => {
11404
- const name2 = "getCollections";
11418
+ const name2 = NAMER.collectionListQueryName();
11405
11419
  const typeName = "Collection";
11406
11420
  return astBuilder.FieldDefinition({
11407
11421
  type: typeName,
@@ -11431,7 +11445,7 @@ var Builder = class {
11431
11445
  });
11432
11446
  };
11433
11447
  this.multiCollectionDocument = async (collections) => {
11434
- const name2 = "getDocument";
11448
+ const name2 = NAMER.documentQueryName();
11435
11449
  const args = [
11436
11450
  astBuilder.InputValueDefinition({
11437
11451
  name: "collection",
@@ -11539,9 +11553,28 @@ var Builder = class {
11539
11553
  type: astBuilder.TYPES.MultiCollectionDocument
11540
11554
  });
11541
11555
  };
11556
+ this.buildDeleteCollectionDocumentMutation = async (collections) => {
11557
+ return astBuilder.FieldDefinition({
11558
+ name: "deleteDocument",
11559
+ args: [
11560
+ astBuilder.InputValueDefinition({
11561
+ name: "collection",
11562
+ required: false,
11563
+ type: astBuilder.TYPES.String
11564
+ }),
11565
+ astBuilder.InputValueDefinition({
11566
+ name: "relativePath",
11567
+ required: true,
11568
+ type: astBuilder.TYPES.String
11569
+ })
11570
+ ],
11571
+ required: true,
11572
+ type: astBuilder.TYPES.MultiCollectionDocument
11573
+ });
11574
+ };
11542
11575
  this.multiCollectionDocumentList = async (collections) => {
11543
11576
  return this._buildMultiCollectionDocumentListDefinition({
11544
- fieldName: "getDocumentList",
11577
+ fieldName: NAMER.documentConnectionQueryName(),
11545
11578
  namespace: ["document"],
11546
11579
  nodeType: astBuilder.TYPES.MultiCollectionDocument,
11547
11580
  collections,
@@ -12790,6 +12823,7 @@ var _buildSchema = async (builder, tinaSchema) => {
12790
12823
  queryTypeDefinitionFields.push(await builder.multiCollectionDocument(collections));
12791
12824
  mutationTypeDefinitionFields.push(await builder.addMultiCollectionDocumentMutation());
12792
12825
  mutationTypeDefinitionFields.push(await builder.buildUpdateCollectionDocumentMutation(collections));
12826
+ mutationTypeDefinitionFields.push(await builder.buildDeleteCollectionDocumentMutation(collections));
12793
12827
  mutationTypeDefinitionFields.push(await builder.buildCreateCollectionDocumentMutation(collections));
12794
12828
  queryTypeDefinitionFields.push(await builder.multiCollectionDocumentList(collections));
12795
12829
  queryTypeDefinitionFields.push(await builder.multiCollectionDocumentFields());
@@ -22469,6 +22503,12 @@ var Resolver = class {
22469
22503
  throw e;
22470
22504
  }
22471
22505
  };
22506
+ this.deleteDocument = async (fullPath) => {
22507
+ if (typeof fullPath !== "string") {
22508
+ throw new Error(`fullPath must be of type string for getDocument request`);
22509
+ }
22510
+ await this.database.delete(fullPath);
22511
+ };
22472
22512
  this.getDocumentFields = async () => {
22473
22513
  try {
22474
22514
  const response = {};
@@ -22638,6 +22678,7 @@ var Resolver = class {
22638
22678
  collection: collectionName,
22639
22679
  isMutation,
22640
22680
  isCreation,
22681
+ isDeletion,
22641
22682
  isAddPendingDocument,
22642
22683
  isCollectionSpecific
22643
22684
  }) => {
@@ -22665,6 +22706,14 @@ var Resolver = class {
22665
22706
  isAddPendingDocument
22666
22707
  });
22667
22708
  }
22709
+ if (isDeletion) {
22710
+ if (!alreadyExists) {
22711
+ throw new Error(`Unable to delete document, ${realPath} does not exist`);
22712
+ }
22713
+ const doc = await this.getDocument(realPath);
22714
+ await this.deleteDocument(realPath);
22715
+ return doc;
22716
+ }
22668
22717
  if (alreadyExists === false) {
22669
22718
  throw new Error(`Unable to update document, ${realPath} does not exist`);
22670
22719
  }
@@ -23137,8 +23186,8 @@ var resolve = async ({
23137
23186
  if (value) {
23138
23187
  return value;
23139
23188
  }
23140
- if (info.fieldName === "getCollections") {
23141
- const getCollectionNode2 = info.fieldNodes.find((x) => x.name.value === "getCollections");
23189
+ if (info.fieldName === "collections") {
23190
+ const getCollectionNode2 = info.fieldNodes.find((x) => x.name.value === "collections");
23142
23191
  const hasDocuments2 = getCollectionNode2.selectionSet.selections.find((x) => {
23143
23192
  var _a;
23144
23193
  return ((_a = x == null ? void 0 : x.name) == null ? void 0 : _a.value) === "documents";
@@ -23147,7 +23196,7 @@ var resolve = async ({
23147
23196
  return resolver2.resolveCollection(collection.name, Boolean(hasDocuments2));
23148
23197
  });
23149
23198
  }
23150
- const getCollectionNode = info.fieldNodes.find((x) => x.name.value === "getCollection");
23199
+ const getCollectionNode = info.fieldNodes.find((x) => x.name.value === "collection");
23151
23200
  const hasDocuments = getCollectionNode.selectionSet.selections.find((x) => {
23152
23201
  var _a;
23153
23202
  return ((_a = x == null ? void 0 : x.name) == null ? void 0 : _a.value) === "documents";
@@ -23190,12 +23239,18 @@ var resolve = async ({
23190
23239
  isAddPendingDocument: true
23191
23240
  });
23192
23241
  }
23193
- if (["getDocument", "createDocument", "updateDocument"].includes(info.fieldName)) {
23242
+ if ([
23243
+ NAMER.documentQueryName(),
23244
+ "createDocument",
23245
+ "updateDocument",
23246
+ "deleteDocument"
23247
+ ].includes(info.fieldName)) {
23194
23248
  const result2 = await resolver2.resolveDocument({
23195
23249
  args,
23196
23250
  collection: args.collection,
23197
23251
  isMutation,
23198
23252
  isCreation,
23253
+ isDeletion: info.fieldName === "deleteDocument",
23199
23254
  isAddPendingDocument: false,
23200
23255
  isCollectionSpecific: false
23201
23256
  });
@@ -23748,8 +23803,7 @@ var Database = class {
23748
23803
  fields: [
23749
23804
  {
23750
23805
  name: field.name,
23751
- type: field.type,
23752
- pad: field.type === "number" ? { fillString: "0", maxLength: import_datalayer2.DEFAULT_NUMERIC_LPAD } : void 0
23806
+ type: field.type
23753
23807
  }
23754
23808
  ]
23755
23809
  };
@@ -23882,6 +23936,22 @@ var Database = class {
23882
23936
  }
23883
23937
  await _indexContent(this, nonCollectionPaths);
23884
23938
  };
23939
+ this.delete = async (filepath) => {
23940
+ const tinaSchema = await this.getSchema();
23941
+ const collection = tinaSchema.schema.collections.find((collection2) => filepath.startsWith(collection2.path));
23942
+ let collectionIndexDefinitions;
23943
+ if (collection) {
23944
+ const indexDefinitions = await this.getIndexDefinitions();
23945
+ collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
23946
+ }
23947
+ await this.store.delete(filepath, {
23948
+ collection: collection.name,
23949
+ indexDefinitions: collectionIndexDefinitions
23950
+ });
23951
+ if (this.store.supportsSeeding()) {
23952
+ await this.bridge.delete(filepath);
23953
+ }
23954
+ };
23885
23955
  this._indexAllContent = async () => {
23886
23956
  const tinaSchema = await this.getSchema();
23887
23957
  await sequential(tinaSchema.getCollections(), async (collection) => {
@@ -90,6 +90,7 @@ export declare class Resolver {
90
90
  fields: unknown[];
91
91
  };
92
92
  }>;
93
+ deleteDocument: (fullPath: unknown) => Promise<void>;
93
94
  getDocumentFields: () => Promise<{}>;
94
95
  buildObjectMutations: (fieldValue: any, field: Collectable) => {
95
96
  [key: string]: unknown;
@@ -169,11 +170,12 @@ export declare class Resolver {
169
170
  fields: unknown[];
170
171
  };
171
172
  }>;
172
- resolveDocument: ({ args, collection: collectionName, isMutation, isCreation, isAddPendingDocument, isCollectionSpecific, }: {
173
+ resolveDocument: ({ args, collection: collectionName, isMutation, isCreation, isDeletion, isAddPendingDocument, isCollectionSpecific, }: {
173
174
  args: unknown;
174
175
  collection?: string;
175
176
  isMutation: boolean;
176
177
  isCreation?: boolean;
178
+ isDeletion?: boolean;
177
179
  isAddPendingDocument?: boolean;
178
180
  isCollectionSpecific?: boolean;
179
181
  }) => Promise<{
package/dist/types.d.ts CHANGED
@@ -65,6 +65,7 @@ export declare type TinaIndex = {
65
65
  name: string;
66
66
  fields: {
67
67
  name: string;
68
+ default?: string | number | boolean;
68
69
  }[];
69
70
  };
70
71
  export declare type TinaFieldBase = TinaFieldInner<false>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "0.0.0-202231073",
3
+ "version": "0.0.0-2022311143526",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@graphql-tools/relay-operation-optimizer": "^6.4.1",
49
- "@tinacms/datalayer": "0.0.0-202231073",
49
+ "@tinacms/datalayer": "0.0.0-2022311143526",
50
50
  "body-parser": "^1.19.0",
51
51
  "cors": "^2.8.5",
52
52
  "dataloader": "^2.0.0",
@@ -96,7 +96,7 @@
96
96
  "directory": "packages/tina-graphql"
97
97
  },
98
98
  "devDependencies": {
99
- "@tinacms/datalayer": "0.0.0-202231073",
99
+ "@tinacms/datalayer": "0.0.0-2022311143526",
100
100
  "@tinacms/scripts": "0.50.7",
101
101
  "@types/cors": "^2.8.7",
102
102
  "@types/estree": "^0.0.50",