@takeshape/schema 8.234.3 → 8.236.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/util/index.d.ts +1 -0
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +13 -0
- package/dist/util/patch-schema.d.ts +9 -0
- package/dist/util/patch-schema.d.ts.map +1 -0
- package/dist/util/patch-schema.js +56 -0
- package/es/util/index.js +2 -1
- package/es/util/patch-schema.js +42 -0
- package/package.json +4 -4
package/dist/util/index.d.ts
CHANGED
package/dist/util/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
|
package/dist/util/index.js
CHANGED
|
@@ -106,4 +106,17 @@ Object.keys(_formConfig).forEach(function (key) {
|
|
|
106
106
|
return _formConfig[key];
|
|
107
107
|
}
|
|
108
108
|
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
var _patchSchema = require("./patch-schema");
|
|
112
|
+
|
|
113
|
+
Object.keys(_patchSchema).forEach(function (key) {
|
|
114
|
+
if (key === "default" || key === "__esModule") return;
|
|
115
|
+
if (key in exports && exports[key] === _patchSchema[key]) return;
|
|
116
|
+
Object.defineProperty(exports, key, {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function () {
|
|
119
|
+
return _patchSchema[key];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
109
122
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ProjectSchema } from '../project-schema';
|
|
2
|
+
import { ProjectSchemaUpdate } from '../migration/types';
|
|
3
|
+
export declare function shallowMerge<T>(original: Record<string, T> | undefined, update: Record<string, T | null> | undefined): Record<string, T>;
|
|
4
|
+
/**
|
|
5
|
+
* Apply a schema update to a schema.
|
|
6
|
+
* Resulting schema is not assumed to be valid and should be validated if appropriate.
|
|
7
|
+
*/
|
|
8
|
+
export declare function patchSchema(projectSchema: ProjectSchema, update: ProjectSchemaUpdate, incrementVersion?: boolean): ProjectSchema;
|
|
9
|
+
//# sourceMappingURL=patch-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch-schema.d.ts","sourceRoot":"","sources":["../../../src/util/patch-schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AAavD,wBAAgB,YAAY,CAAC,CAAC,EAC5B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,EACvC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS,GAC3C,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAenB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,mBAAmB,EAC3B,gBAAgB,UAAO,GACtB,aAAa,CAgBf"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.patchSchema = patchSchema;
|
|
7
|
+
exports.shallowMerge = shallowMerge;
|
|
8
|
+
|
|
9
|
+
var _forIn = _interopRequireDefault(require("lodash/forIn"));
|
|
10
|
+
|
|
11
|
+
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
12
|
+
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
|
|
15
|
+
const schemaUpdateMergedKeys = ['queries', 'mutations', 'shapes', 'workflows', 'forms', 'services', 'indexedShapes'];
|
|
16
|
+
|
|
17
|
+
function shallowMerge(original, update) {
|
|
18
|
+
const result = { ...original
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
if (update) {
|
|
22
|
+
(0, _forIn.default)(update, (obj, key) => {
|
|
23
|
+
// Null is a sentinel value to indicate delete
|
|
24
|
+
if (obj === null) {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
26
|
+
delete result[key];
|
|
27
|
+
} else {
|
|
28
|
+
result[key] = obj;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Apply a schema update to a schema.
|
|
37
|
+
* Resulting schema is not assumed to be valid and should be validated if appropriate.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
function patchSchema(projectSchema, update, incrementVersion = true) {
|
|
42
|
+
const version = update.version ?? projectSchema.version; // Patch old schema with update
|
|
43
|
+
|
|
44
|
+
const updatedSchema = { ...projectSchema,
|
|
45
|
+
...(0, _omit.default)(update, schemaUpdateMergedKeys),
|
|
46
|
+
version: incrementVersion ? version + 1 : version
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
for (const key of schemaUpdateMergedKeys) {
|
|
50
|
+
if (update[key]) {
|
|
51
|
+
updatedSchema[key] = shallowMerge(projectSchema[key], update[key]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return updatedSchema;
|
|
56
|
+
}
|
package/es/util/index.js
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import forIn from 'lodash/forIn';
|
|
2
|
+
import omit from 'lodash/omit';
|
|
3
|
+
const schemaUpdateMergedKeys = ['queries', 'mutations', 'shapes', 'workflows', 'forms', 'services', 'indexedShapes'];
|
|
4
|
+
export function shallowMerge(original, update) {
|
|
5
|
+
const result = { ...original
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
if (update) {
|
|
9
|
+
forIn(update, (obj, key) => {
|
|
10
|
+
// Null is a sentinel value to indicate delete
|
|
11
|
+
if (obj === null) {
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
13
|
+
delete result[key];
|
|
14
|
+
} else {
|
|
15
|
+
result[key] = obj;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Apply a schema update to a schema.
|
|
24
|
+
* Resulting schema is not assumed to be valid and should be validated if appropriate.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
export function patchSchema(projectSchema, update, incrementVersion = true) {
|
|
28
|
+
const version = update.version ?? projectSchema.version; // Patch old schema with update
|
|
29
|
+
|
|
30
|
+
const updatedSchema = { ...projectSchema,
|
|
31
|
+
...omit(update, schemaUpdateMergedKeys),
|
|
32
|
+
version: incrementVersion ? version + 1 : version
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
for (const key of schemaUpdateMergedKeys) {
|
|
36
|
+
if (update[key]) {
|
|
37
|
+
updatedSchema[key] = shallowMerge(projectSchema[key], update[key]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return updatedSchema;
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/schema",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.236.1",
|
|
4
4
|
"description": "TakeShape Schema",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"examples"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@takeshape/errors": "8.
|
|
25
|
-
"@takeshape/json-schema": "8.
|
|
26
|
-
"@takeshape/util": "8.
|
|
24
|
+
"@takeshape/errors": "8.236.1",
|
|
25
|
+
"@takeshape/json-schema": "8.236.1",
|
|
26
|
+
"@takeshape/util": "8.236.1",
|
|
27
27
|
"ajv": "^8.10.0",
|
|
28
28
|
"ajv-formats": "^2.1.1",
|
|
29
29
|
"blueimp-md5": "^2.10.0",
|