@tinacms/schema-tools 0.0.0-20220907211113 → 0.0.0-20220907220830

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.d.ts CHANGED
@@ -13,4 +13,3 @@ limitations under the License.
13
13
  export * from './schema';
14
14
  export * from './types';
15
15
  export * from './validate';
16
- export * from './util/namer';
package/dist/index.es.js CHANGED
@@ -214,72 +214,6 @@ class TinaSchema {
214
214
  return template;
215
215
  }
216
216
  };
217
- this.transformPayload = (collectionName, payload) => {
218
- const collection = this.getCollection(collectionName);
219
- if (collection.templates) {
220
- const template = collection.templates.find((template2) => {
221
- if (typeof template2 === "string") {
222
- throw new Error("Global templates not supported");
223
- }
224
- return payload["_template"] === template2.name;
225
- });
226
- if (!template) {
227
- console.error(payload);
228
- throw new Error(`Unable to find template for payload`);
229
- }
230
- if (typeof template === "string") {
231
- throw new Error("Global templates not supported");
232
- }
233
- return {
234
- [collectionName]: {
235
- [template.name]: this.transformCollectablePayload(payload, template)
236
- }
237
- };
238
- } else {
239
- return {
240
- [collectionName]: this.transformCollectablePayload(payload, collection)
241
- };
242
- }
243
- };
244
- this.transformCollectablePayload = (payload, collection) => {
245
- const accumulator = {};
246
- Object.entries(payload).forEach(([key, value]) => {
247
- if (typeof collection.fields === "string") {
248
- throw new Error("Global templates not supported");
249
- }
250
- const field = collection.fields.find((field2) => {
251
- if (typeof field2 === "string") {
252
- throw new Error("Global templates not supported");
253
- }
254
- return field2.name === key;
255
- });
256
- if (field) {
257
- accumulator[key] = this.transformField(field, value);
258
- }
259
- });
260
- return accumulator;
261
- };
262
- this.transformField = (field, value) => {
263
- if (field.type === "object")
264
- if (field.templates) {
265
- if (field.list) {
266
- assertShape(value, (yup2) => yup2.array(yup2.object({ _template: yup2.string().required() })));
267
- return value.map((item) => {
268
- const { _template, ...rest } = item;
269
- return { [_template]: rest };
270
- });
271
- } else {
272
- assertShape(value, (yup2) => yup2.object({ _template: yup2.string().required() }));
273
- const { _template, ...rest } = value;
274
- return { [_template]: rest };
275
- }
276
- } else {
277
- return value;
278
- }
279
- else {
280
- return value;
281
- }
282
- };
283
217
  this.isMarkdownCollection = (collectionName) => {
284
218
  const collection = this.getCollection(collectionName);
285
219
  const format = collection.format;
@@ -330,9 +264,9 @@ class TinaSchema {
330
264
  this.schema = config;
331
265
  }
332
266
  }
333
- const resolveField = (field, schema) => {
267
+ const resolveField = ({ namespace, ...field }, schema) => {
334
268
  var _a;
335
- field.parentTypename = NAMER.dataTypeName(field.namespace.filter((_, i) => i < field.namespace.length - 1));
269
+ field.parentTypename = NAMER.dataTypeName(namespace.filter((_, i) => i < namespace.length - 1));
336
270
  const extraFields = field.ui || {};
337
271
  switch (field.type) {
338
272
  case "number":
@@ -393,7 +327,10 @@ const resolveField = (field, schema) => {
393
327
  ...extraFields
394
328
  };
395
329
  case "object":
396
- const templateInfo = schema.getTemplatesForCollectable(field);
330
+ const templateInfo = schema.getTemplatesForCollectable({
331
+ ...field,
332
+ namespace
333
+ });
397
334
  if (templateInfo.type === "object") {
398
335
  return {
399
336
  ...field,
@@ -411,7 +348,6 @@ const resolveField = (field, schema) => {
411
348
  templates2[lastItem(template.namespace)] = {
412
349
  label: template.label || templateName,
413
350
  key: templateName,
414
- namespace: [...field.namespace, templateName],
415
351
  fields: template.fields.map((field2) => resolveField(field2, schema)),
416
352
  ...extraFields2
417
353
  };
@@ -420,7 +356,6 @@ const resolveField = (field, schema) => {
420
356
  return {
421
357
  ...field,
422
358
  typeMap: typeMap2,
423
- namespace: field.namespace,
424
359
  component: field.list ? "blocks" : "not-implemented",
425
360
  templates: templates2,
426
361
  ...extraFields
@@ -785,4 +720,4 @@ const validateSchema = ({
785
720
  }
786
721
  }
787
722
  };
788
- export { NAMER, TinaSchema, TinaSchemaValidationError, addNamespaceToSchema, resolveField, resolveForm, validateSchema, validateTinaCloudSchemaConfig };
723
+ export { TinaSchema, TinaSchemaValidationError, addNamespaceToSchema, resolveField, resolveForm, validateSchema, validateTinaCloudSchemaConfig };
package/dist/index.js CHANGED
@@ -241,72 +241,6 @@
241
241
  return template;
242
242
  }
243
243
  };
244
- this.transformPayload = (collectionName, payload) => {
245
- const collection = this.getCollection(collectionName);
246
- if (collection.templates) {
247
- const template = collection.templates.find((template2) => {
248
- if (typeof template2 === "string") {
249
- throw new Error("Global templates not supported");
250
- }
251
- return payload["_template"] === template2.name;
252
- });
253
- if (!template) {
254
- console.error(payload);
255
- throw new Error(`Unable to find template for payload`);
256
- }
257
- if (typeof template === "string") {
258
- throw new Error("Global templates not supported");
259
- }
260
- return {
261
- [collectionName]: {
262
- [template.name]: this.transformCollectablePayload(payload, template)
263
- }
264
- };
265
- } else {
266
- return {
267
- [collectionName]: this.transformCollectablePayload(payload, collection)
268
- };
269
- }
270
- };
271
- this.transformCollectablePayload = (payload, collection) => {
272
- const accumulator = {};
273
- Object.entries(payload).forEach(([key, value]) => {
274
- if (typeof collection.fields === "string") {
275
- throw new Error("Global templates not supported");
276
- }
277
- const field = collection.fields.find((field2) => {
278
- if (typeof field2 === "string") {
279
- throw new Error("Global templates not supported");
280
- }
281
- return field2.name === key;
282
- });
283
- if (field) {
284
- accumulator[key] = this.transformField(field, value);
285
- }
286
- });
287
- return accumulator;
288
- };
289
- this.transformField = (field, value) => {
290
- if (field.type === "object")
291
- if (field.templates) {
292
- if (field.list) {
293
- assertShape(value, (yup2) => yup2.array(yup2.object({ _template: yup2.string().required() })));
294
- return value.map((item) => {
295
- const { _template, ...rest } = item;
296
- return { [_template]: rest };
297
- });
298
- } else {
299
- assertShape(value, (yup2) => yup2.object({ _template: yup2.string().required() }));
300
- const { _template, ...rest } = value;
301
- return { [_template]: rest };
302
- }
303
- } else {
304
- return value;
305
- }
306
- else {
307
- return value;
308
- }
309
- };
310
244
  this.isMarkdownCollection = (collectionName) => {
311
245
  const collection = this.getCollection(collectionName);
312
246
  const format = collection.format;
@@ -357,9 +291,9 @@
357
291
  this.schema = config;
358
292
  }
359
293
  }
360
- const resolveField = (field, schema) => {
294
+ const resolveField = ({ namespace, ...field }, schema) => {
361
295
  var _a;
362
- field.parentTypename = NAMER.dataTypeName(field.namespace.filter((_, i) => i < field.namespace.length - 1));
296
+ field.parentTypename = NAMER.dataTypeName(namespace.filter((_, i) => i < namespace.length - 1));
363
297
  const extraFields = field.ui || {};
364
298
  switch (field.type) {
365
299
  case "number":
@@ -420,7 +354,10 @@
420
354
  ...extraFields
421
355
  };
422
356
  case "object":
423
- const templateInfo = schema.getTemplatesForCollectable(field);
357
+ const templateInfo = schema.getTemplatesForCollectable({
358
+ ...field,
359
+ namespace
360
+ });
424
361
  if (templateInfo.type === "object") {
425
362
  return {
426
363
  ...field,
@@ -438,7 +375,6 @@
438
375
  templates2[lastItem(template.namespace)] = {
439
376
  label: template.label || templateName,
440
377
  key: templateName,
441
- namespace: [...field.namespace, templateName],
442
378
  fields: template.fields.map((field2) => resolveField(field2, schema)),
443
379
  ...extraFields2
444
380
  };
@@ -447,7 +383,6 @@
447
383
  return {
448
384
  ...field,
449
385
  typeMap: typeMap2,
450
- namespace: field.namespace,
451
386
  component: field.list ? "blocks" : "not-implemented",
452
387
  templates: templates2,
453
388
  ...extraFields
@@ -812,7 +747,6 @@
812
747
  }
813
748
  }
814
749
  };
815
- exports2.NAMER = NAMER;
816
750
  exports2.TinaSchema = TinaSchema;
817
751
  exports2.TinaSchemaValidationError = TinaSchemaValidationError;
818
752
  exports2.addNamespaceToSchema = addNamespaceToSchema;
@@ -64,13 +64,6 @@ export declare class TinaSchema {
64
64
  data?: unknown;
65
65
  collection: Collectable;
66
66
  }) => Templateable;
67
- transformPayload: (collectionName: string, payload: object) => {
68
- [x: string]: {
69
- [x: string]: {};
70
- };
71
- };
72
- private transformCollectablePayload;
73
- private transformField;
74
67
  isMarkdownCollection: (collectionName: string) => boolean;
75
68
  /**
76
69
  * Gets the template or templates from the item.
@@ -21,9 +21,4 @@ import { TinaSchema } from './TinaSchema';
21
21
  * @param {TinaSchema} schema the entireT Tina Schema
22
22
  * @returns unknown
23
23
  */
24
- export declare const resolveField: (field: TinaFieldEnriched, schema: TinaSchema) => {
25
- [key: string]: unknown;
26
- name: string;
27
- component: string;
28
- type: string;
29
- };
24
+ export declare const resolveField: ({ namespace, ...field }: TinaFieldEnriched, schema: TinaSchema) => unknown;
@@ -18,10 +18,5 @@ export declare const resolveForm: ({ collection, basename, template, schema, }:
18
18
  id: string;
19
19
  label: string;
20
20
  name: string;
21
- fields: {
22
- [key: string]: unknown;
23
- name: string;
24
- component: string;
25
- type: string;
26
- }[];
21
+ fields: unknown[];
27
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/schema-tools",
3
- "version": "0.0.0-20220907211113",
3
+ "version": "0.0.0-20220907220830",
4
4
  "main": "dist/index.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "exports": {