@tinacms/schema-tools 0.1.0 → 0.1.1

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/dist/index.es.js CHANGED
@@ -7,6 +7,9 @@ function addNamespaceToSchema(maybeNode, namespace = []) {
7
7
  if (typeof maybeNode === "boolean") {
8
8
  return maybeNode;
9
9
  }
10
+ if (typeof maybeNode === "function") {
11
+ return maybeNode;
12
+ }
10
13
  const newNode = { ...maybeNode };
11
14
  const keys = Object.keys(maybeNode);
12
15
  Object.values(maybeNode).map((m, index) => {
@@ -169,12 +172,7 @@ class TinaSchema {
169
172
  };
170
173
  this.getCollectionAndTemplateByFullPath = (filepath, templateName) => {
171
174
  let template;
172
- const collection = this.getCollections().find((collection2) => {
173
- return filepath.replace("\\", "/").startsWith(collection2.path);
174
- });
175
- if (!collection) {
176
- throw new Error(`Unable to find collection for file at ${filepath}`);
177
- }
175
+ const collection = this.getCollectionByFullPath(filepath);
178
176
  const templates = this.getTemplatesForCollectable(collection);
179
177
  if (templates.type === "union") {
180
178
  if (templateName) {
@@ -438,7 +436,9 @@ const parseZodError = ({ zodError }) => {
438
436
  const name = z.string({
439
437
  required_error: "Name is required but not provided",
440
438
  invalid_type_error: "Name must be a string"
441
- });
439
+ }).refine((val) => val.match(/^[a-zA-Z0-9_]*$/) !== null, (val) => ({
440
+ message: `name, "${val}" must be alphanumeric and can only contain underscores`
441
+ }));
442
442
  const TypeName = [
443
443
  "string",
444
444
  "boolean",
package/dist/index.js CHANGED
@@ -34,6 +34,9 @@
34
34
  if (typeof maybeNode === "boolean") {
35
35
  return maybeNode;
36
36
  }
37
+ if (typeof maybeNode === "function") {
38
+ return maybeNode;
39
+ }
37
40
  const newNode = { ...maybeNode };
38
41
  const keys = Object.keys(maybeNode);
39
42
  Object.values(maybeNode).map((m, index) => {
@@ -196,12 +199,7 @@
196
199
  };
197
200
  this.getCollectionAndTemplateByFullPath = (filepath, templateName) => {
198
201
  let template;
199
- const collection = this.getCollections().find((collection2) => {
200
- return filepath.replace("\\", "/").startsWith(collection2.path);
201
- });
202
- if (!collection) {
203
- throw new Error(`Unable to find collection for file at ${filepath}`);
204
- }
202
+ const collection = this.getCollectionByFullPath(filepath);
205
203
  const templates = this.getTemplatesForCollectable(collection);
206
204
  if (templates.type === "union") {
207
205
  if (templateName) {
@@ -465,7 +463,9 @@
465
463
  const name = z.z.string({
466
464
  required_error: "Name is required but not provided",
467
465
  invalid_type_error: "Name must be a string"
468
- });
466
+ }).refine((val) => val.match(/^[a-zA-Z0-9_]*$/) !== null, (val) => ({
467
+ message: `name, "${val}" must be alphanumeric and can only contain underscores`
468
+ }));
469
469
  const TypeName = [
470
470
  "string",
471
471
  "boolean",
@@ -44,11 +44,46 @@ export declare type TinaCloudCollection<WithNamespace extends boolean> = Collect
44
44
  export declare type TinaCloudCollectionBase = TinaCloudCollection<false>;
45
45
  export declare type TinaCloudCollectionEnriched = TinaCloudCollection<true>;
46
46
  declare type FormatType = 'json' | 'md' | 'markdown' | 'mdx';
47
+ declare type Document = {
48
+ _sys: {
49
+ title?: string;
50
+ template: string;
51
+ breadcrumbs: string[];
52
+ path: string;
53
+ basename: string;
54
+ relativePath: string;
55
+ filename: string;
56
+ extension: string;
57
+ };
58
+ };
47
59
  interface BaseCollection {
48
60
  label?: string;
49
61
  name: string;
50
62
  path: string;
51
63
  format?: FormatType;
64
+ ui?: {
65
+ /**
66
+ * Forms for this collection will be editable from the global sidebar rather than the form panel
67
+ */
68
+ global?: boolean | {
69
+ icon?: any;
70
+ layout: 'fullscreen' | 'popup';
71
+ };
72
+ /**
73
+ * Provide the path that your document is viewable on your site
74
+ *
75
+ * eg:
76
+ * ```ts
77
+ * router: ({ document }) => {
78
+ * return `blog-posts/${document._sys.filename}`;
79
+ * }
80
+ * ```
81
+ */
82
+ router?: (args: {
83
+ document: Document;
84
+ collection: TinaCloudCollection<true>;
85
+ }) => string | undefined;
86
+ };
52
87
  match?: string;
53
88
  }
54
89
  declare type CollectionTemplates<WithNamespace extends boolean> = WithNamespace extends true ? CollectionTemplatesWithNamespace<WithNamespace> : CollectionTemplatesInner<WithNamespace>;
@@ -11,4 +11,4 @@ See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
13
  import { z } from 'zod';
14
- export declare const name: z.ZodString;
14
+ export declare const name: z.ZodEffects<z.ZodString, string, string>;
@@ -14,13 +14,13 @@ import { z } from 'zod';
14
14
  export declare const TinaCloudSchemaZod: z.ZodEffects<z.ZodObject<{
15
15
  collections: z.ZodArray<z.ZodEffects<z.ZodObject<z.extendShape<{
16
16
  label: z.ZodOptional<z.ZodString>;
17
- name: z.ZodString;
17
+ name: z.ZodEffects<z.ZodString, string, string>;
18
18
  format: z.ZodOptional<z.ZodEnum<["json", "md", "markdown", "mdx"]>>;
19
19
  }, {
20
20
  fields: z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodType<import("..").TinaFieldInner<false>, z.ZodTypeDef, import("..").TinaFieldInner<false>>, "many">>, import("..").TinaFieldInner<false>[], import("..").TinaFieldInner<false>[]>, import("..").TinaFieldInner<false>[], import("..").TinaFieldInner<false>[]>;
21
21
  templates: z.ZodEffects<z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodObject<{
22
22
  label: z.ZodString;
23
- name: z.ZodString;
23
+ name: z.ZodEffects<z.ZodString, string, string>;
24
24
  fields: z.ZodArray<z.ZodType<import("..").TinaFieldInner<false>, z.ZodTypeDef, import("..").TinaFieldInner<false>>, "many">;
25
25
  }, "strip", z.ZodTypeAny, {
26
26
  name?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/schema-tools",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "exports": {
@@ -23,7 +23,7 @@
23
23
  ]
24
24
  },
25
25
  "devDependencies": {
26
- "@tinacms/scripts": "0.51.0",
26
+ "@tinacms/scripts": "0.51.1",
27
27
  "@types/yup": "^0.29.10",
28
28
  "jest": "^27.0.6",
29
29
  "react": "17.0.2",