@oak-digital/types-4-strapi-2 0.5.0 → 0.5.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.
@@ -90,7 +90,7 @@ var Attributes = /** @class */ (function () {
90
90
  var orNull = ' | null';
91
91
  // TODO: only add this in non paranoid mode
92
92
  /* const requiredString = attr.required !== true ? orNull : ''; */
93
- var requiredString = orNull;
93
+ var requiredString = (attr === null || attr === void 0 ? void 0 : attr[constants_1.CERTAINLY_REQUIRED_KEY]) === true ? '' : orNull;
94
94
  var str = " ".concat(attrName).concat(optionalString, ": ");
95
95
  var isArray = false;
96
96
  switch (attr.type) {
@@ -1 +1,2 @@
1
1
  export declare const POPULATE_GENERIC_NAME = "Populate";
2
+ export declare const CERTAINLY_REQUIRED_KEY = "__t4s_required";
package/lib/constants.js CHANGED
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.POPULATE_GENERIC_NAME = void 0;
3
+ exports.CERTAINLY_REQUIRED_KEY = exports.POPULATE_GENERIC_NAME = void 0;
4
4
  exports.POPULATE_GENERIC_NAME = 'Populate';
5
+ exports.CERTAINLY_REQUIRED_KEY = '__t4s_required';
@@ -4,21 +4,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createMediaFormatInterface = exports.createMediaInterface = void 0;
7
+ var constants_1 = require("../constants");
7
8
  var BuiltinComponentInterface_1 = __importDefault(require("./BuiltinComponentInterface"));
8
9
  var BuiltinInterface_1 = __importDefault(require("./BuiltinInterface"));
9
10
  function createMediaInterface(directory, caseTypeName, prefix) {
10
11
  var stringRequiredFields = [
11
12
  'name',
12
- 'alternativeText',
13
- 'caption',
14
13
  'hash',
15
14
  'ext',
16
15
  'mime',
17
16
  'url',
18
17
  'provider',
19
18
  ];
20
- var stringFields = ['previewUrl', 'provider_metadata'];
21
- var numberFields = ['width', 'height', 'size'];
19
+ var stringFields = [
20
+ 'previewUrl',
21
+ 'provider_metadata',
22
+ 'alternativeText',
23
+ 'caption', // nullable in plain text
24
+ ];
25
+ var numberRequiredFields = ['size'];
26
+ // Nullable if you have a plain text file
27
+ var numberFields = ['width', 'height'];
22
28
  var mediaFormat = {
23
29
  type: 'component',
24
30
  repeatable: false,
@@ -38,13 +44,28 @@ function createMediaInterface(directory, caseTypeName, prefix) {
38
44
  },
39
45
  };
40
46
  stringRequiredFields.forEach(function (s) {
41
- mediaAttrs[s] = { type: 'string', required: true };
47
+ var _a;
48
+ mediaAttrs[s] = (_a = {
49
+ type: 'string',
50
+ required: true
51
+ },
52
+ _a[constants_1.CERTAINLY_REQUIRED_KEY] = true,
53
+ _a);
42
54
  });
43
55
  stringFields.forEach(function (s) {
44
56
  mediaAttrs[s] = { type: 'string' };
45
57
  });
46
58
  numberFields.forEach(function (s) {
47
- mediaAttrs[s] = { type: 'integer', required: true };
59
+ mediaAttrs[s] = { type: 'integer' };
60
+ });
61
+ numberRequiredFields.forEach(function (s) {
62
+ var _a;
63
+ mediaAttrs[s] = (_a = {
64
+ type: 'integer',
65
+ required: true
66
+ },
67
+ _a[constants_1.CERTAINLY_REQUIRED_KEY] = true,
68
+ _a);
48
69
  });
49
70
  // const dataAttrs = {
50
71
  // data: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oak-digital/types-4-strapi-2",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Typescript interface generator for Strapi 4 models",
5
5
  "bin": {
6
6
  "t4s": "./bin/index.js"