@tinacms/graphql 0.57.1 → 0.57.2

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,5 +1,11 @@
1
1
  # tina-graphql
2
2
 
3
+ ## 0.57.2
4
+
5
+ ### Patch Changes
6
+
7
+ - edb2f4011: Trim path property on collections during compilation
8
+
3
9
  ## 0.57.1
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -6395,15 +6395,15 @@ var require_acorn_jsx = __commonJS({
6395
6395
  }
6396
6396
  return acornJsx;
6397
6397
  }
6398
- function getQualifiedJSXName(object) {
6399
- if (!object)
6400
- return object;
6401
- if (object.type === "JSXIdentifier")
6402
- return object.name;
6403
- if (object.type === "JSXNamespacedName")
6404
- return object.namespace.name + ":" + object.name.name;
6405
- if (object.type === "JSXMemberExpression")
6406
- return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
6398
+ function getQualifiedJSXName(object2) {
6399
+ if (!object2)
6400
+ return object2;
6401
+ if (object2.type === "JSXIdentifier")
6402
+ return object2.name;
6403
+ if (object2.type === "JSXNamespacedName")
6404
+ return object2.namespace.name + ":" + object2.name.name;
6405
+ if (object2.type === "JSXMemberExpression")
6406
+ return getQualifiedJSXName(object2.object) + "." + getQualifiedJSXName(object2.property);
6407
6407
  }
6408
6408
  module2.exports = function(options) {
6409
6409
  options = options || {};
@@ -6946,8 +6946,8 @@ var require_micromark_extension_mdxjs = __commonJS({
6946
6946
  var require_min_indent = __commonJS({
6947
6947
  "pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/min-indent-npm-1.0.1-77031f50e1-c3aeea46bc.zip/node_modules/min-indent/index.js"(exports, module2) {
6948
6948
  "use strict";
6949
- module2.exports = (string3) => {
6950
- const match = string3.match(/^[ \t]*(?=\S)/gm);
6949
+ module2.exports = (string4) => {
6950
+ const match = string4.match(/^[ \t]*(?=\S)/gm);
6951
6951
  if (!match) {
6952
6952
  return 0;
6953
6953
  }
@@ -6961,13 +6961,13 @@ var require_strip_indent = __commonJS({
6961
6961
  "pnp:/home/runner/work/tinacms/tinacms/.yarn/cache/strip-indent-npm-3.0.0-519e75a28d-4a7860e943.zip/node_modules/strip-indent/index.js"(exports, module2) {
6962
6962
  "use strict";
6963
6963
  var minIndent = require_min_indent();
6964
- module2.exports = (string3) => {
6965
- const indent2 = minIndent(string3);
6964
+ module2.exports = (string4) => {
6965
+ const indent2 = minIndent(string4);
6966
6966
  if (indent2 === 0) {
6967
- return string3;
6967
+ return string4;
6968
6968
  }
6969
6969
  const regex = new RegExp(`^[ \\t]{${indent2}}`, "gm");
6970
- return string3.replace(regex, "");
6970
+ return string4.replace(regex, "");
6971
6971
  };
6972
6972
  }
6973
6973
  });
@@ -11168,6 +11168,9 @@ function addNamespaceToSchema(maybeNode, namespace = []) {
11168
11168
  const key2 = keys2[index2];
11169
11169
  if (Array.isArray(m)) {
11170
11170
  newNode[key2] = m.map((element) => {
11171
+ if (!element) {
11172
+ return;
11173
+ }
11171
11174
  if (!element.hasOwnProperty("name")) {
11172
11175
  return element;
11173
11176
  }
@@ -11175,6 +11178,9 @@ function addNamespaceToSchema(maybeNode, namespace = []) {
11175
11178
  return addNamespaceToSchema(element, [...namespace, value]);
11176
11179
  });
11177
11180
  } else {
11181
+ if (!m) {
11182
+ return;
11183
+ }
11178
11184
  if (!m.hasOwnProperty("name")) {
11179
11185
  newNode[key2] = m;
11180
11186
  } else {
@@ -12120,8 +12126,77 @@ var filterSelections = (arr) => {
12120
12126
  return arr.filter(Boolean);
12121
12127
  };
12122
12128
 
12123
- // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/primitives/schema/index.ts
12129
+ // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/primitives/schema/validate.ts
12124
12130
  var import_lodash3 = __toModule(require("lodash"));
12131
+ var yup2 = __toModule(require("yup"));
12132
+ var FIELD_TYPES = [
12133
+ "string",
12134
+ "number",
12135
+ "boolean",
12136
+ "datetime",
12137
+ "image",
12138
+ "reference",
12139
+ "object",
12140
+ "rich-text"
12141
+ ];
12142
+ var validateSchema = async (schema) => {
12143
+ const schema2 = addNamespaceToSchema(import_lodash3.default.cloneDeep(schema));
12144
+ const collections = await sequential(schema2.collections, async (collection) => validateCollection(collection));
12145
+ return {
12146
+ collections
12147
+ };
12148
+ };
12149
+ var validateCollection = async (collection) => {
12150
+ let templates = [];
12151
+ let fields = [];
12152
+ const messageName = collection.namespace.join(".");
12153
+ const collectionSchema = yup2.object({
12154
+ name: yup2.string().matches(/^[a-zA-Z0-9_]*$/, {
12155
+ message: (obj) => `Collection's "name" must match ${obj.regex} at ${messageName}`
12156
+ }).required(),
12157
+ label: yup2.string().required(),
12158
+ path: yup2.string().required().transform((value) => {
12159
+ return value.replace(/^\/|\/$/g, "");
12160
+ })
12161
+ });
12162
+ await collectionSchema.validate(collection);
12163
+ const validCollection = await collectionSchema.cast(collection);
12164
+ if (validCollection.templates) {
12165
+ templates = await sequential(validCollection.templates, async (template) => {
12166
+ if (typeof template === "string") {
12167
+ throw new Error(`Global templates are not yet supported`);
12168
+ }
12169
+ const fields2 = await sequential(template.fields, async (field) => {
12170
+ return validateField(field);
12171
+ });
12172
+ return __spreadValues(__spreadValues({}, validCollection), fields2);
12173
+ });
12174
+ }
12175
+ if (validCollection.fields) {
12176
+ if (typeof validCollection.fields === "string") {
12177
+ throw new Error(`Global templates are not yet supported`);
12178
+ }
12179
+ fields = await sequential(validCollection.fields, async (field) => {
12180
+ return validateField(field);
12181
+ });
12182
+ return __spreadProps(__spreadValues({}, validCollection), {
12183
+ fields
12184
+ });
12185
+ }
12186
+ return collection;
12187
+ };
12188
+ var validateField = async (field) => {
12189
+ const messageName = field.namespace.join(".");
12190
+ const schema = yup2.object({
12191
+ name: yup2.string().matches(/^[a-zA-Z0-9_]*$/, {
12192
+ message: (obj) => `Field's 'name' must match ${obj.regex} at ${messageName}`
12193
+ }).required(),
12194
+ label: yup2.string().required(),
12195
+ type: yup2.string().oneOf(FIELD_TYPES, (obj) => `'type' must be one of: ${obj.values}, but got '${obj.value}' at ${messageName}`)
12196
+ });
12197
+ await schema.validate(field);
12198
+ return field;
12199
+ };
12125
12200
 
12126
12201
  // pnp:/home/runner/work/tinacms/tinacms/packages/@tinacms/graphql/src/primitives/resolver/error.ts
12127
12202
  var TinaError = class extends Error {
@@ -12138,7 +12213,8 @@ var TinaError = class extends Error {
12138
12213
  var createSchema = async ({
12139
12214
  schema
12140
12215
  }) => {
12141
- return new TinaSchema(schema);
12216
+ const validSchema = await validateSchema(schema);
12217
+ return new TinaSchema(validSchema);
12142
12218
  };
12143
12219
  var TinaSchema = class {
12144
12220
  constructor(config) {
@@ -12223,7 +12299,7 @@ var TinaSchema = class {
12223
12299
  case "object":
12224
12300
  return templateInfo.template;
12225
12301
  case "union":
12226
- assertShape(data, (yup2) => yup2.object({ _template: yup2.string().required() }));
12302
+ assertShape(data, (yup3) => yup3.object({ _template: yup3.string().required() }));
12227
12303
  const template = templateInfo.templates.find((template2) => template2.namespace[template2.namespace.length - 1] === data._template);
12228
12304
  if (!template) {
12229
12305
  throw new TinaError(`Expected to find template named '${data._template}' for collection '${lastItem(collection.namespace)}'`, {
@@ -12280,7 +12356,7 @@ var TinaSchema = class {
12280
12356
  }
12281
12357
  }
12282
12358
  };
12283
- this.schema = addNamespaceToSchema(import_lodash3.default.cloneDeep(config));
12359
+ this.schema = config;
12284
12360
  }
12285
12361
  };
12286
12362
 
@@ -18220,7 +18296,7 @@ function initializeFlow(effects) {
18220
18296
  var resolver = {
18221
18297
  resolveAll: createResolver()
18222
18298
  };
18223
- var string = initializeFactory("string");
18299
+ var string2 = initializeFactory("string");
18224
18300
  var text = initializeFactory("text");
18225
18301
  function initializeFactory(field) {
18226
18302
  return {
@@ -18645,7 +18721,7 @@ __export(constructs_exports, {
18645
18721
  flow: () => flow2,
18646
18722
  flowInitial: () => flowInitial,
18647
18723
  insideSpan: () => insideSpan,
18648
- string: () => string2,
18724
+ string: () => string3,
18649
18725
  text: () => text2
18650
18726
  });
18651
18727
  var document2 = {
@@ -18682,7 +18758,7 @@ var flow2 = {
18682
18758
  [96]: codeFenced,
18683
18759
  [126]: codeFenced
18684
18760
  };
18685
- var string2 = {
18761
+ var string3 = {
18686
18762
  [38]: characterReference,
18687
18763
  [92]: characterEscape
18688
18764
  };
@@ -18720,7 +18796,7 @@ function parse(options = {}) {
18720
18796
  content: create(content),
18721
18797
  document: create(document),
18722
18798
  flow: create(flow),
18723
- string: create(string),
18799
+ string: create(string2),
18724
18800
  text: create(text)
18725
18801
  };
18726
18802
  return parser;
@@ -19313,9 +19389,9 @@ function compiler(options = {}) {
19313
19389
  }
19314
19390
  function onexitlabeltext(token) {
19315
19391
  const ancestor = this.stack[this.stack.length - 2];
19316
- const string3 = this.sliceSerialize(token);
19317
- ancestor.label = decodeString(string3);
19318
- ancestor.identifier = normalizeIdentifier(string3).toLowerCase();
19392
+ const string4 = this.sliceSerialize(token);
19393
+ ancestor.label = decodeString(string4);
19394
+ ancestor.identifier = normalizeIdentifier(string4).toLowerCase();
19319
19395
  }
19320
19396
  function onexitlabel() {
19321
19397
  const fragment = this.stack[this.stack.length - 1];
@@ -22047,10 +22123,10 @@ var Resolver = class {
22047
22123
  collectionLookup = Object.keys(args.params)[0];
22048
22124
  }
22049
22125
  const collectionNames = this.tinaSchema.getCollections().map((item) => item.name);
22050
- assertShape(collectionLookup, (yup2) => {
22051
- return yup2.mixed().oneOf(collectionNames);
22126
+ assertShape(collectionLookup, (yup3) => {
22127
+ return yup3.mixed().oneOf(collectionNames);
22052
22128
  }, `"collection" must be one of: [${collectionNames.join(", ")}] but got ${collectionLookup}`);
22053
- assertShape(args, (yup2) => yup2.object({ relativePath: yup2.string().required() }));
22129
+ assertShape(args, (yup3) => yup3.object({ relativePath: yup3.string().required() }));
22054
22130
  const collection = await this.tinaSchema.getCollection(collectionLookup);
22055
22131
  const realPath = import_path4.default.join(collection == null ? void 0 : collection.path, args.relativePath);
22056
22132
  const alreadyExists = await this.database.documentExists(realPath);
@@ -22149,7 +22225,7 @@ var Resolver = class {
22149
22225
  if (!rawData) {
22150
22226
  return void 0;
22151
22227
  }
22152
- assertShape(rawData, (yup2) => yup2.object());
22228
+ assertShape(rawData, (yup3) => yup3.object());
22153
22229
  const value = rawData[field.name];
22154
22230
  switch (field.type) {
22155
22231
  case "string":
@@ -22173,7 +22249,7 @@ var Resolver = class {
22173
22249
  if (!value) {
22174
22250
  return;
22175
22251
  }
22176
- assertShape(value, (yup2) => yup2.array().of(yup2.object().required()));
22252
+ assertShape(value, (yup3) => yup3.array().of(yup3.object().required()));
22177
22253
  accumulator[field.name] = await sequential(value, async (item) => {
22178
22254
  const template = await this.tinaSchema.getTemplateForData({
22179
22255
  data: item,
@@ -22217,15 +22293,15 @@ var Resolver = class {
22217
22293
  };
22218
22294
  this.buildParams = (args) => {
22219
22295
  try {
22220
- assertShape(args, (yup2) => yup2.object({
22221
- collection: yup2.string().required(),
22222
- params: yup2.object().required()
22296
+ assertShape(args, (yup3) => yup3.object({
22297
+ collection: yup3.string().required(),
22298
+ params: yup3.object().required()
22223
22299
  }));
22224
22300
  return args.params[args.collection];
22225
22301
  } catch (e) {
22226
22302
  }
22227
- assertShape(args, (yup2) => yup2.object({
22228
- params: yup2.object().required()
22303
+ assertShape(args, (yup3) => yup3.object({
22304
+ params: yup3.object().required()
22229
22305
  }));
22230
22306
  return args.params;
22231
22307
  };
@@ -22462,7 +22538,7 @@ var resolve = async ({
22462
22538
  const isCreation = lookup[info.fieldName] === "create";
22463
22539
  switch (lookup.resolveType) {
22464
22540
  case "nodeDocument":
22465
- assertShape(args, (yup2) => yup2.object({ id: yup2.string().required() }));
22541
+ assertShape(args, (yup3) => yup3.object({ id: yup3.string().required() }));
22466
22542
  return resolver2.getDocument(args.id);
22467
22543
  case "multiCollectionDocument":
22468
22544
  if (typeof value === "string") {
@@ -22498,7 +22574,7 @@ var resolve = async ({
22498
22574
  }
22499
22575
  return value;
22500
22576
  case "multiCollectionDocumentList":
22501
- assertShape(value, (yup2) => yup2.array().of(yup2.string()));
22577
+ assertShape(value, (yup3) => yup3.array().of(yup3.string()));
22502
22578
  return resolver2.resolveCollectionConnections({
22503
22579
  ids: value || []
22504
22580
  });
@@ -22826,7 +22902,7 @@ var Database = class {
22826
22902
  const tinaSchema = await this.getSchema();
22827
22903
  const extension2 = import_path6.default.extname(filepath);
22828
22904
  const contentString = await this.bridge.get(filepath);
22829
- const contentObject = this.parseFile(contentString, extension2, (yup2) => yup2.object({}));
22905
+ const contentObject = this.parseFile(contentString, extension2, (yup3) => yup3.object({}));
22830
22906
  const templateName = hasOwnProperty2(contentObject, "_template") && typeof contentObject._template === "string" ? contentObject._template : void 0;
22831
22907
  const { collection, template } = await tinaSchema.getCollectionAndTemplateByFullPath(filepath, templateName);
22832
22908
  const field = template.fields.find((field2) => {
@@ -0,0 +1,14 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ import type { TinaCloudSchemaBase } from '../types';
14
+ export declare const validateSchema: (schema: TinaCloudSchemaBase) => Promise<TinaCloudSchemaBase>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "0.57.1",
3
+ "version": "0.57.2",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [