@oak-digital/types-4-strapi-2 0.2.3 → 0.2.4

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/README.md CHANGED
@@ -45,6 +45,7 @@ This can be done with the `--out` flag like in the following example.
45
45
 
46
46
  ### Planned features
47
47
 
48
+ * Support for localization
48
49
  * Support if you are using other plugins, such as `url-alias`, which should add extra fields for some interfaces.
49
50
 
50
51
  ## Help
@@ -1,4 +1,4 @@
1
- import { RelationNames } from "./Interface";
1
+ import { RelationNames } from './Interface';
2
2
  export default class Attributes {
3
3
  Attrs: Record<string, Record<string, any>>;
4
4
  private RelationNames;
@@ -9,11 +9,11 @@ var Attributes = /** @class */ (function () {
9
9
  Attributes.prototype.isAttributeOptional = function (attr) {
10
10
  // If it is a component / relation / dynamiczone it is always optional due to population
11
11
  switch (attr.type) {
12
- case "nested":
12
+ case 'nested':
13
13
  return attr.nullable === true;
14
- case "component":
15
- case "dynamiczone":
16
- case "relation":
14
+ case 'component':
15
+ case 'dynamiczone':
16
+ case 'relation':
17
17
  return true;
18
18
  default:
19
19
  break;
@@ -26,18 +26,18 @@ var Attributes = /** @class */ (function () {
26
26
  var attr = this.Attrs[attrName];
27
27
  var dependencyNames = [];
28
28
  switch (attr.type) {
29
- case "nested":
29
+ case 'nested':
30
30
  var attrs = new Attributes(attr.fields, this.RelationNames);
31
31
  dependencyNames.push.apply(dependencyNames, attrs.getDependencies());
32
32
  break;
33
- case "relation":
33
+ case 'relation':
34
34
  dependencyNames.push(attr.target);
35
35
  break;
36
- case "component":
36
+ case 'component':
37
37
  dependencyNames.push(attr.component);
38
38
  break;
39
- case "media":
40
- dependencyNames.push("builtins::Media");
39
+ case 'media':
40
+ dependencyNames.push('builtins::Media');
41
41
  break;
42
42
  default:
43
43
  continue;
@@ -55,70 +55,70 @@ var Attributes = /** @class */ (function () {
55
55
  return dependencies;
56
56
  };
57
57
  Attributes.prototype.attributeToString = function (attrName, attr) {
58
- var _a, _b;
58
+ var _a;
59
59
  var optionalString = this.isAttributeOptional(attr) ? '?' : '';
60
60
  var str = " ".concat(attrName).concat(optionalString, ": ");
61
61
  var isArray = false;
62
62
  switch (attr.type) {
63
63
  // types-4-strapi-2 specific, used for builtin types
64
- case "nested":
64
+ case 'nested':
65
65
  // Be careful with recursion
66
66
  // console.log(attr);
67
67
  var newAttrs = new Attributes(attr.fields, this.RelationNames);
68
68
  str += newAttrs.toString();
69
69
  break;
70
- case "relation":
70
+ case 'relation':
71
71
  var apiName = attr.target;
72
72
  // console.log(this.RelationNames, apiName)
73
73
  var dependencyName = this.RelationNames[apiName].name;
74
- isArray = attr.relation.endsWith("ToMany");
75
- str += dependencyName;
74
+ var relationMultipleString = attr.relation.endsWith('ToMany') ? '[]' : ' | null';
75
+ str += "{ data: ".concat(dependencyName).concat(relationMultipleString, "; }");
76
76
  break;
77
- case "component":
77
+ case 'component':
78
78
  var componentName = attr.component;
79
79
  var relationNameObj = this.RelationNames[componentName];
80
80
  var dependencyComponentName = relationNameObj.name;
81
81
  isArray = (_a = attr.repeatable) !== null && _a !== void 0 ? _a : false;
82
82
  str += dependencyComponentName;
83
83
  break;
84
- case "media":
85
- var mediaOptional = attr.required !== true ? "?" : "";
86
- str += "{ data".concat(mediaOptional, ": ").concat(this.RelationNames["builtins::Media"].name, "; }");
87
- isArray = (_b = attr.multiple) !== null && _b !== void 0 ? _b : false;
84
+ case 'media':
85
+ var mediaOptional = attr.required !== true ? '?' : '';
86
+ var mediaMultipleString = attr.multiple ? '[]' : ' | null';
87
+ str += "{ data".concat(mediaOptional, ": ").concat(this.RelationNames['builtins::Media'].name).concat(mediaMultipleString, "; }");
88
88
  break;
89
- case "password":
89
+ case 'password':
90
90
  return null;
91
- case "enumeration":
92
- var hasDefault = "default" in attr;
91
+ case 'enumeration':
92
+ var hasDefault = 'default' in attr;
93
93
  var enums = attr.enum.map(function (en) { return "\"".concat(en, "\""); });
94
- enums.push("null");
95
- var typeString = enums.join(" | ");
94
+ enums.push('null');
95
+ var typeString = enums.join(' | ');
96
96
  str += typeString;
97
97
  break;
98
- case "string":
99
- case "text":
100
- case "richtext":
101
- case "email":
102
- case "uid":
103
- str += "string";
98
+ case 'string':
99
+ case 'text':
100
+ case 'richtext':
101
+ case 'email':
102
+ case 'uid':
103
+ str += 'string';
104
104
  break;
105
- case "integer":
106
- case "biginteger":
107
- case "decimal":
108
- case "float":
109
- str += "number";
105
+ case 'integer':
106
+ case 'biginteger':
107
+ case 'decimal':
108
+ case 'float':
109
+ str += 'number';
110
110
  break;
111
- case "date":
112
- case "datetime":
113
- case "time":
114
- str += "Date";
111
+ case 'date':
112
+ case 'datetime':
113
+ case 'time':
114
+ str += 'Date';
115
115
  break;
116
- case "boolean":
116
+ case 'boolean':
117
117
  str += attr.type;
118
118
  break;
119
- case "json":
119
+ case 'json':
120
120
  default:
121
- str += "any";
121
+ str += 'any';
122
122
  break;
123
123
  }
124
124
  var isArrayString = isArray ? '[]' : '';
@@ -135,13 +135,13 @@ var Attributes = /** @class */ (function () {
135
135
  }
136
136
  strings.push(attrString);
137
137
  }
138
- return strings.map(function (s) { return "".concat(s, "\n"); }).join("");
138
+ return strings.map(function (s) { return "".concat(s, "\n"); }).join('');
139
139
  };
140
140
  Attributes.prototype.toString = function () {
141
- var strings = ["{"];
141
+ var strings = ['{'];
142
142
  strings.push(this.toFieldsString());
143
- strings.push("}");
144
- return strings.join("\n");
143
+ strings.push('}');
144
+ return strings.join('\n');
145
145
  };
146
146
  return Attributes;
147
147
  }());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oak-digital/types-4-strapi-2",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Typescript interface generator for Strapi 4 models",
5
5
  "bin": {
6
6
  "t4s": "./bin/index.js"