@takeshape/schema 9.103.28 → 9.104.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"create-input-schema.d.ts","sourceRoot":"","sources":["../../src/create-input-schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,iBAAiB,EAAE,WAAW,EAAE,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAGhF,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAkBD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,iBAAiB,GAAG,WAAW,GAAG,cAAc,EAC1F,MAAM,EAAE,CAAC,EACT,OAAO,GAAE,wBAA6B,GACrC,CAAC,CAsDH"}
1
+ {"version":3,"file":"create-input-schema.d.ts","sourceRoot":"","sources":["../../src/create-input-schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,iBAAiB,EAAE,WAAW,EAAE,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhF,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAkBD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,iBAAiB,GAAG,WAAW,GAAG,cAAc,EAC1F,MAAM,EAAE,CAAC,EACT,OAAO,GAAE,wBAA6B,GACrC,CAAC,CA4DH"}
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.createInputSchema = createInputSchema;
7
7
  var _defaults = _interopRequireDefault(require("lodash/fp/defaults"));
8
8
  var _util = require("@takeshape/util");
9
- var _omitBy = _interopRequireDefault(require("lodash/omitBy"));
10
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
10
  const inputSchemaCache = new Map();
12
11
  function getInputSchemaCache(options) {
@@ -32,43 +31,43 @@ function createInputSchema(schema, options = {}) {
32
31
  if (rewrittenSchema) {
33
32
  return rewrittenSchema;
34
33
  }
35
- rewrittenSchema = JSON.parse(JSON.stringify(schema), (_key, value) => {
36
- if ((0, _util.isRecord)(value)) {
37
- // Remove required
38
- if (options.isUpdate && Array.isArray(value.required) && value.required.length) {
39
- delete value.required;
40
- }
34
+ rewrittenSchema = (0, _util.deepCloneWith)(schema, (value, key, parent, clone) => {
35
+ // Remove required
36
+ if (options.isUpdate && key === 'required' && Array.isArray(value) && value.length) {
37
+ return _util.REMOVE;
38
+ }
41
39
 
42
- // Remove default
43
- if (options.isUpdate && value.type !== undefined && value.default !== undefined) {
44
- delete value.default;
45
- }
46
- if (value.type === 'object' && (0, _util.isRecord)(value.properties)) {
47
- return {
48
- ...value,
49
- properties: (0, _omitBy.default)(value.properties, prop => (0, _util.isRecord)(prop) && prop['@resolver'] && !prop['@input'])
50
- };
51
- }
52
- if ((0, _util.isRecord)(value['@input'])) {
53
- const {
54
- '@input': input,
55
- '@l10n': l10n,
56
- '@syncLocaleStructure': syncLocaleStructure,
57
- '@mapping': mapping,
58
- title,
59
- ...output
60
- } = value;
61
- return {
62
- ...input,
63
- title,
64
- '@l10n': l10n,
65
- '@syncLocaleStructure': syncLocaleStructure,
66
- '@mapping': mapping,
67
- '@output': output
68
- };
40
+ // Remove default
41
+ if (options.isUpdate && key === 'default' && value !== undefined && (0, _util.isIterableObject)(parent) && parent.type !== undefined) {
42
+ return _util.REMOVE;
43
+ }
44
+ if (key === 'properties' && (0, _util.isIterableObject)(value) && (0, _util.isIterableObject)(parent) && parent.type === 'object') {
45
+ const newProperties = {};
46
+ for (const [key, prop] of Object.entries(value)) {
47
+ if ((0, _util.isIterableObject)(prop) && (!prop['@resolver'] || prop['@input'])) {
48
+ newProperties[key] = clone(prop, key, value);
49
+ }
69
50
  }
51
+ return newProperties;
52
+ }
53
+ if ((0, _util.isIterableObject)(value) && (0, _util.isIterableObject)(value['@input'])) {
54
+ const {
55
+ '@input': input,
56
+ '@l10n': l10n,
57
+ '@syncLocaleStructure': syncLocaleStructure,
58
+ '@mapping': mapping,
59
+ title,
60
+ ...output
61
+ } = value;
62
+ return {
63
+ ...clone(input, '@input', value),
64
+ title,
65
+ '@l10n': l10n,
66
+ '@syncLocaleStructure': syncLocaleStructure,
67
+ '@mapping': mapping,
68
+ '@output': output
69
+ };
70
70
  }
71
- return value;
72
71
  });
73
72
  inputSchemaCache.set(schema, rewrittenSchema);
74
73
  return rewrittenSchema;
@@ -394,13 +394,17 @@ function getModelBuiltInProperties(projectSchema, shape) {
394
394
  _enabled: {
395
395
  title: 'Enabled',
396
396
  type: 'boolean',
397
- '@deprecationReason': showDeprecationReason ? 'Use _status instead' : undefined
397
+ ...(showDeprecationReason ? {
398
+ '@deprecationReason': 'Use _status instead'
399
+ } : {})
398
400
  },
399
401
  _enabledAt: {
400
402
  title: 'Enabled Date',
401
403
  type: 'string',
402
404
  format: 'date-time',
403
- '@deprecationReason': showDeprecationReason ? 'Use a custom date field instead' : undefined
405
+ ...(showDeprecationReason ? {
406
+ '@deprecationReason': 'Use a custom date field instead'
407
+ } : {})
404
408
  }
405
409
  };
406
410
  if ((0, _apiVersion.workflowsEnabled)(apiVersion)) {
@@ -1,6 +1,5 @@
1
1
  import defaults from 'lodash/fp/defaults';
2
- import { isRecord } from '@takeshape/util';
3
- import omitBy from 'lodash/omitBy';
2
+ import { isIterableObject, deepCloneWith, REMOVE } from '@takeshape/util';
4
3
  const inputSchemaCache = new Map();
5
4
  function getInputSchemaCache(options) {
6
5
  // Ensure key order does not invalidate the cache
@@ -25,43 +24,43 @@ export function createInputSchema(schema, options = {}) {
25
24
  if (rewrittenSchema) {
26
25
  return rewrittenSchema;
27
26
  }
28
- rewrittenSchema = JSON.parse(JSON.stringify(schema), (_key, value) => {
29
- if (isRecord(value)) {
30
- // Remove required
31
- if (options.isUpdate && Array.isArray(value.required) && value.required.length) {
32
- delete value.required;
33
- }
27
+ rewrittenSchema = deepCloneWith(schema, (value, key, parent, clone) => {
28
+ // Remove required
29
+ if (options.isUpdate && key === 'required' && Array.isArray(value) && value.length) {
30
+ return REMOVE;
31
+ }
34
32
 
35
- // Remove default
36
- if (options.isUpdate && value.type !== undefined && value.default !== undefined) {
37
- delete value.default;
38
- }
39
- if (value.type === 'object' && isRecord(value.properties)) {
40
- return {
41
- ...value,
42
- properties: omitBy(value.properties, prop => isRecord(prop) && prop['@resolver'] && !prop['@input'])
43
- };
44
- }
45
- if (isRecord(value['@input'])) {
46
- const {
47
- '@input': input,
48
- '@l10n': l10n,
49
- '@syncLocaleStructure': syncLocaleStructure,
50
- '@mapping': mapping,
51
- title,
52
- ...output
53
- } = value;
54
- return {
55
- ...input,
56
- title,
57
- '@l10n': l10n,
58
- '@syncLocaleStructure': syncLocaleStructure,
59
- '@mapping': mapping,
60
- '@output': output
61
- };
33
+ // Remove default
34
+ if (options.isUpdate && key === 'default' && value !== undefined && isIterableObject(parent) && parent.type !== undefined) {
35
+ return REMOVE;
36
+ }
37
+ if (key === 'properties' && isIterableObject(value) && isIterableObject(parent) && parent.type === 'object') {
38
+ const newProperties = {};
39
+ for (const [key, prop] of Object.entries(value)) {
40
+ if (isIterableObject(prop) && (!prop['@resolver'] || prop['@input'])) {
41
+ newProperties[key] = clone(prop, key, value);
42
+ }
62
43
  }
44
+ return newProperties;
45
+ }
46
+ if (isIterableObject(value) && isIterableObject(value['@input'])) {
47
+ const {
48
+ '@input': input,
49
+ '@l10n': l10n,
50
+ '@syncLocaleStructure': syncLocaleStructure,
51
+ '@mapping': mapping,
52
+ title,
53
+ ...output
54
+ } = value;
55
+ return {
56
+ ...clone(input, '@input', value),
57
+ title,
58
+ '@l10n': l10n,
59
+ '@syncLocaleStructure': syncLocaleStructure,
60
+ '@mapping': mapping,
61
+ '@output': output
62
+ };
63
63
  }
64
- return value;
65
64
  });
66
65
  inputSchemaCache.set(schema, rewrittenSchema);
67
66
  return rewrittenSchema;
package/es/schema-util.js CHANGED
@@ -319,13 +319,17 @@ export function getModelBuiltInProperties(projectSchema, shape) {
319
319
  _enabled: {
320
320
  title: 'Enabled',
321
321
  type: 'boolean',
322
- '@deprecationReason': showDeprecationReason ? 'Use _status instead' : undefined
322
+ ...(showDeprecationReason ? {
323
+ '@deprecationReason': 'Use _status instead'
324
+ } : {})
323
325
  },
324
326
  _enabledAt: {
325
327
  title: 'Enabled Date',
326
328
  type: 'string',
327
329
  format: 'date-time',
328
- '@deprecationReason': showDeprecationReason ? 'Use a custom date field instead' : undefined
330
+ ...(showDeprecationReason ? {
331
+ '@deprecationReason': 'Use a custom date field instead'
332
+ } : {})
329
333
  }
330
334
  };
331
335
  if (workflowsEnabled(apiVersion)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeshape/schema",
3
- "version": "9.103.28",
3
+ "version": "9.104.0",
4
4
  "description": "TakeShape Schema",
5
5
  "homepage": "https://www.takeshape.io",
6
6
  "repository": {
@@ -28,9 +28,9 @@
28
28
  "p-reduce": "^2.1.0",
29
29
  "semver": "^7.3.2",
30
30
  "tiny-invariant": "^1.2.0",
31
- "@takeshape/errors": "9.103.28",
32
- "@takeshape/json-schema": "9.103.28",
33
- "@takeshape/util": "9.103.28"
31
+ "@takeshape/errors": "9.104.0",
32
+ "@takeshape/util": "9.104.0",
33
+ "@takeshape/json-schema": "9.104.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@takeshape/json-schema-to-typescript": "^11.0.0",
@@ -46,7 +46,7 @@
46
46
  "meow": "^9.0.0",
47
47
  "p-map": "^5.0.0",
48
48
  "shortid": "^2.2.15",
49
- "@takeshape/typescript-jest-junit-reporter": "9.103.28"
49
+ "@takeshape/typescript-jest-junit-reporter": "9.104.0"
50
50
  },
51
51
  "engines": {
52
52
  "node": ">=16"