@takeshape/schema 8.35.1 → 8.35.2

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.
Files changed (75) hide show
  1. package/es/index.js +3 -3
  2. package/es/migration/index.js +82 -0
  3. package/es/migration/to/v3.0.0.js +245 -0
  4. package/es/{migration-utils.js → migration/to/v3.1.0.js} +40 -8
  5. package/es/migration/to/v3.10.0.js +56 -0
  6. package/es/migration/to/v3.11.0.js +99 -0
  7. package/es/migration/to/v3.2.0.js +10 -0
  8. package/es/migration/to/v3.3.0.js +16 -0
  9. package/es/migration/to/v3.4.0.js +10 -0
  10. package/es/migration/to/v3.5.0.js +10 -0
  11. package/es/migration/to/v3.5.1.js +10 -0
  12. package/es/migration/to/v3.6.0.js +10 -0
  13. package/es/migration/to/v3.7.0.js +10 -0
  14. package/es/migration/to/v3.8.0.js +10 -0
  15. package/es/migration/to/v3.9.0.js +83 -0
  16. package/es/migration/types.js +1 -0
  17. package/es/migration/utils.js +23 -0
  18. package/lib/index.d.ts +3 -3
  19. package/lib/index.d.ts.map +1 -1
  20. package/lib/index.js +13 -36
  21. package/lib/migration/index.d.ts +7 -0
  22. package/lib/migration/index.d.ts.map +1 -0
  23. package/lib/migration/index.js +128 -0
  24. package/lib/migration/to/v3.0.0.d.ts +4 -0
  25. package/lib/migration/to/v3.0.0.d.ts.map +1 -0
  26. package/lib/migration/to/v3.0.0.js +260 -0
  27. package/lib/migration/to/v3.1.0.d.ts +5 -0
  28. package/lib/migration/to/v3.1.0.d.ts.map +1 -0
  29. package/lib/{migration-utils.js → migration/to/v3.1.0.js} +40 -10
  30. package/lib/migration/to/v3.10.0.d.ts +4 -0
  31. package/lib/migration/to/v3.10.0.d.ts.map +1 -0
  32. package/lib/migration/to/v3.10.0.js +66 -0
  33. package/lib/migration/to/v3.11.0.d.ts +5 -0
  34. package/lib/migration/to/v3.11.0.d.ts.map +1 -0
  35. package/lib/migration/to/v3.11.0.js +109 -0
  36. package/lib/migration/to/v3.2.0.d.ts +4 -0
  37. package/lib/migration/to/v3.2.0.d.ts.map +1 -0
  38. package/lib/migration/to/v3.2.0.js +18 -0
  39. package/lib/migration/to/v3.3.0.d.ts +5 -0
  40. package/lib/migration/to/v3.3.0.d.ts.map +1 -0
  41. package/lib/migration/to/v3.3.0.js +24 -0
  42. package/lib/migration/to/v3.4.0.d.ts +4 -0
  43. package/lib/migration/to/v3.4.0.d.ts.map +1 -0
  44. package/lib/migration/to/v3.4.0.js +18 -0
  45. package/lib/migration/to/v3.5.0.d.ts +4 -0
  46. package/lib/migration/to/v3.5.0.d.ts.map +1 -0
  47. package/lib/migration/to/v3.5.0.js +18 -0
  48. package/lib/migration/to/v3.5.1.d.ts +4 -0
  49. package/lib/migration/to/v3.5.1.d.ts.map +1 -0
  50. package/lib/migration/to/v3.5.1.js +18 -0
  51. package/lib/migration/to/v3.6.0.d.ts +4 -0
  52. package/lib/migration/to/v3.6.0.d.ts.map +1 -0
  53. package/lib/migration/to/v3.6.0.js +18 -0
  54. package/lib/migration/to/v3.7.0.d.ts +4 -0
  55. package/lib/migration/to/v3.7.0.d.ts.map +1 -0
  56. package/lib/migration/to/v3.7.0.js +18 -0
  57. package/lib/migration/to/v3.8.0.d.ts +4 -0
  58. package/lib/migration/to/v3.8.0.d.ts.map +1 -0
  59. package/lib/migration/to/v3.8.0.js +18 -0
  60. package/lib/migration/to/v3.9.0.d.ts +4 -0
  61. package/lib/migration/to/v3.9.0.d.ts.map +1 -0
  62. package/lib/migration/to/v3.9.0.js +91 -0
  63. package/lib/migration/types.d.ts +14 -0
  64. package/lib/migration/types.d.ts.map +1 -0
  65. package/lib/migration/types.js +5 -0
  66. package/lib/migration/utils.d.ts +5 -0
  67. package/lib/migration/utils.d.ts.map +1 -0
  68. package/lib/migration/utils.js +34 -0
  69. package/package.json +4 -4
  70. package/es/migration.js +0 -677
  71. package/lib/migration-utils.d.ts +0 -18
  72. package/lib/migration-utils.d.ts.map +0 -1
  73. package/lib/migration.d.ts +0 -59
  74. package/lib/migration.d.ts.map +0 -1
  75. package/lib/migration.js +0 -739
@@ -0,0 +1,83 @@
1
+ import { visit } from '@takeshape/util';
2
+
3
+ function migrateToV3_9_0(projectSchema) {
4
+ /**
5
+ * Resolver props that are guaranteed in this version, and dependent on the
6
+ * resolver type. Ensure they exist.
7
+ */
8
+ const ensureResolverOptions = resolver => {
9
+ if (resolver.name.startsWith('takeshape')) {
10
+ if (!resolver.shapeName) {
11
+ var _resolver$options, _resolver$options2, _resolver$options3, _resolver$options4;
12
+
13
+ resolver.shapeName = ((_resolver$options = resolver.options) === null || _resolver$options === void 0 ? void 0 : _resolver$options.model) ?? ((_resolver$options2 = resolver.options) === null || _resolver$options2 === void 0 ? void 0 : _resolver$options2.indexedShape) ?? '';
14
+ (_resolver$options3 = resolver.options) === null || _resolver$options3 === void 0 ? true : delete _resolver$options3.model;
15
+ (_resolver$options4 = resolver.options) === null || _resolver$options4 === void 0 ? true : delete _resolver$options4.indexedShape;
16
+ }
17
+ }
18
+
19
+ if (resolver.name.startsWith('graphql')) {
20
+ if (!resolver.fieldName) {
21
+ var _resolver$options5, _resolver$options6;
22
+
23
+ resolver.fieldName = ((_resolver$options5 = resolver.options) === null || _resolver$options5 === void 0 ? void 0 : _resolver$options5.fieldName) ?? '';
24
+ (_resolver$options6 = resolver.options) === null || _resolver$options6 === void 0 ? true : delete _resolver$options6.fieldName;
25
+ }
26
+ }
27
+
28
+ if (resolver.name.startsWith('awsLambda')) {
29
+ if (!resolver.functionName) {
30
+ var _resolver$options7, _resolver$options8;
31
+
32
+ resolver.functionName = ((_resolver$options7 = resolver.options) === null || _resolver$options7 === void 0 ? void 0 : _resolver$options7.functionName) ?? '';
33
+ (_resolver$options8 = resolver.options) === null || _resolver$options8 === void 0 ? true : delete _resolver$options8.functionName;
34
+ }
35
+ }
36
+
37
+ if (resolver.name.startsWith('rest')) {
38
+ if (!resolver.path) {
39
+ var _resolver$options11;
40
+
41
+ if (resolver.pathParams) {
42
+ var _resolver$options9;
43
+
44
+ resolver.path = { ...resolver.pathParams,
45
+ serialize: { ...resolver.pathParams.serialize,
46
+ template: (_resolver$options9 = resolver.options) === null || _resolver$options9 === void 0 ? void 0 : _resolver$options9.path
47
+ }
48
+ };
49
+ } else {
50
+ var _resolver$options10;
51
+
52
+ resolver.path = ((_resolver$options10 = resolver.options) === null || _resolver$options10 === void 0 ? void 0 : _resolver$options10.path) ?? '';
53
+ }
54
+
55
+ (_resolver$options11 = resolver.options) === null || _resolver$options11 === void 0 ? true : delete _resolver$options11.path;
56
+ }
57
+ }
58
+ /**
59
+ * `resolver.name` was previously validated with app code and v3.9.0
60
+ * enumerates the previous validation, making this assertion safe.
61
+ */
62
+
63
+
64
+ return resolver;
65
+ };
66
+ /**
67
+ * Function will visit each resolver in the schema and mutate them.
68
+ */
69
+
70
+
71
+ visit(projectSchema, ['resolver', '@resolver'], resolver => {
72
+ if (resolver.compose) {
73
+ resolver.compose.forEach(ensureResolverOptions);
74
+ } else {
75
+ ensureResolverOptions(resolver);
76
+ }
77
+ });
78
+ return { ...projectSchema,
79
+ schemaVersion: '3.9.0'
80
+ };
81
+ }
82
+
83
+ export default migrateToV3_9_0;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ export function formatDate(timestamp) {
2
+ return (timestamp ? new Date(timestamp) : new Date()).toISOString();
3
+ }
4
+ export function getRelationshipSchema(relationship) {
5
+ const itemSchema = {
6
+ $ref: '#/shapes/TSRelationship/schema'
7
+ };
8
+
9
+ if (relationship.type === 'multiple') {
10
+ return {
11
+ type: 'array',
12
+ items: itemSchema,
13
+ '@relationship': relationship
14
+ };
15
+ }
16
+
17
+ return { ...itemSchema,
18
+ '@relationship': relationship
19
+ };
20
+ }
21
+ export function normalizeSchemaVersion(version) {
22
+ return version === undefined ? '1' : version;
23
+ }
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export type { ProjectSchemaUpdate, ProjectSchemaMigrationContext } from './migration';
1
+ export type { ProjectSchemaUpdate, ProjectSchemaMigrationContext } from './migration/types';
2
+ export type { User } from './user-schema';
2
3
  export * from './content-schema-transform';
3
4
  export * from './get-is-leaf';
4
5
  export * from './project-schema';
@@ -9,9 +10,8 @@ export * from './taxonomies';
9
10
  export * from './workflows';
10
11
  export * from './builtin-schema';
11
12
  export * from './auth-schemas';
12
- export type { User } from './user-schema';
13
13
  export * from './api-version';
14
- export { listTypePrefix, ensureLatest, normalizeSchemaVersion, getRelationshipSchema, migrateToLatestProjectSchema } from './migration';
14
+ export * from './migration';
15
15
  export * from './validate';
16
16
  export { builtInShapes } from './builtin-schema';
17
17
  export * from './versions';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,mBAAmB,EAAE,6BAA6B,EAAC,MAAM,aAAa,CAAC;AACpF,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAE/B,YAAY,EAAC,IAAI,EAAC,MAAM,eAAe,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,cAAc,EACd,YAAY,EACZ,sBAAsB,EACtB,qBAAqB,EACrB,4BAA4B,EAC7B,MAAM,aAAa,CAAC;AACrB,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAC/C,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,mBAAmB,EAAE,6BAA6B,EAAC,MAAM,mBAAmB,CAAC;AAE1F,YAAY,EAAC,IAAI,EAAC,MAAM,eAAe,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAC/C,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
package/lib/index.js CHANGED
@@ -4,12 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
- builtInShapes: true,
8
- listTypePrefix: true,
9
- ensureLatest: true,
10
- normalizeSchemaVersion: true,
11
- getRelationshipSchema: true,
12
- migrateToLatestProjectSchema: true
7
+ builtInShapes: true
13
8
  };
14
9
  Object.defineProperty(exports, "builtInShapes", {
15
10
  enumerable: true,
@@ -17,36 +12,6 @@ Object.defineProperty(exports, "builtInShapes", {
17
12
  return _builtinSchema.builtInShapes;
18
13
  }
19
14
  });
20
- Object.defineProperty(exports, "ensureLatest", {
21
- enumerable: true,
22
- get: function () {
23
- return _migration.ensureLatest;
24
- }
25
- });
26
- Object.defineProperty(exports, "getRelationshipSchema", {
27
- enumerable: true,
28
- get: function () {
29
- return _migration.getRelationshipSchema;
30
- }
31
- });
32
- Object.defineProperty(exports, "listTypePrefix", {
33
- enumerable: true,
34
- get: function () {
35
- return _migration.listTypePrefix;
36
- }
37
- });
38
- Object.defineProperty(exports, "migrateToLatestProjectSchema", {
39
- enumerable: true,
40
- get: function () {
41
- return _migration.migrateToLatestProjectSchema;
42
- }
43
- });
44
- Object.defineProperty(exports, "normalizeSchemaVersion", {
45
- enumerable: true,
46
- get: function () {
47
- return _migration.normalizeSchemaVersion;
48
- }
49
- });
50
15
 
51
16
  var _contentSchemaTransform = require("./content-schema-transform");
52
17
 
@@ -204,6 +169,18 @@ Object.keys(_apiVersion).forEach(function (key) {
204
169
 
205
170
  var _migration = require("./migration");
206
171
 
172
+ Object.keys(_migration).forEach(function (key) {
173
+ if (key === "default" || key === "__esModule") return;
174
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
175
+ if (key in exports && exports[key] === _migration[key]) return;
176
+ Object.defineProperty(exports, key, {
177
+ enumerable: true,
178
+ get: function () {
179
+ return _migration[key];
180
+ }
181
+ });
182
+ });
183
+
207
184
  var _validate = require("./validate");
208
185
 
209
186
  Object.keys(_validate).forEach(function (key) {
@@ -0,0 +1,7 @@
1
+ import type { ProjectSchema, AnyProjectSchema } from '../project-schema';
2
+ import type { ProjectSchemaMigrationContext } from './types';
3
+ export * from './utils';
4
+ export declare const listTypePrefix = "PaginatedList";
5
+ export declare function migrateToLatestProjectSchema(context: ProjectSchemaMigrationContext, projectSchema: AnyProjectSchema): Promise<ProjectSchema>;
6
+ export declare function ensureLatest(context: ProjectSchemaMigrationContext, schema?: AnyProjectSchema): Promise<ProjectSchema | undefined>;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migration/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AACvE,OAAO,KAAK,EAAC,6BAA6B,EAAC,MAAM,SAAS,CAAC;AA+B3D,cAAc,SAAS,CAAC;AAExB,eAAO,MAAM,cAAc,kBAAkB,CAAC;AAE9C,wBAAsB,4BAA4B,CAChD,OAAO,EAAE,6BAA6B,EACtC,aAAa,EAAE,gBAAgB,GAC9B,OAAO,CAAC,aAAa,CAAC,CA0DxB;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,6BAA6B,EACtC,MAAM,CAAC,EAAE,gBAAgB,GACxB,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAMpC"}
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ listTypePrefix: true,
8
+ migrateToLatestProjectSchema: true,
9
+ ensureLatest: true
10
+ };
11
+ exports.ensureLatest = ensureLatest;
12
+ exports.listTypePrefix = void 0;
13
+ exports.migrateToLatestProjectSchema = migrateToLatestProjectSchema;
14
+
15
+ var _utils = require("../types/utils");
16
+
17
+ var _v = _interopRequireDefault(require("./to/v3.0.0"));
18
+
19
+ var _v2 = _interopRequireDefault(require("./to/v3.1.0"));
20
+
21
+ var _v3 = _interopRequireDefault(require("./to/v3.2.0"));
22
+
23
+ var _v4 = _interopRequireDefault(require("./to/v3.3.0"));
24
+
25
+ var _v5 = _interopRequireDefault(require("./to/v3.4.0"));
26
+
27
+ var _v6 = _interopRequireDefault(require("./to/v3.5.0"));
28
+
29
+ var _v7 = _interopRequireDefault(require("./to/v3.5.1"));
30
+
31
+ var _v8 = _interopRequireDefault(require("./to/v3.6.0"));
32
+
33
+ var _v9 = _interopRequireDefault(require("./to/v3.7.0"));
34
+
35
+ var _v10 = _interopRequireDefault(require("./to/v3.8.0"));
36
+
37
+ var _v11 = _interopRequireDefault(require("./to/v3.9.0"));
38
+
39
+ var _v12 = _interopRequireDefault(require("./to/v3.10.0"));
40
+
41
+ var _v13 = _interopRequireDefault(require("./to/v3.11.0"));
42
+
43
+ var _utils2 = require("./utils");
44
+
45
+ Object.keys(_utils2).forEach(function (key) {
46
+ if (key === "default" || key === "__esModule") return;
47
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
48
+ if (key in exports && exports[key] === _utils2[key]) return;
49
+ Object.defineProperty(exports, key, {
50
+ enumerable: true,
51
+ get: function () {
52
+ return _utils2[key];
53
+ }
54
+ });
55
+ });
56
+
57
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
58
+
59
+ const listTypePrefix = 'PaginatedList';
60
+ exports.listTypePrefix = listTypePrefix;
61
+
62
+ async function migrateToLatestProjectSchema(context, projectSchema) {
63
+ if (projectSchema.schemaVersion === '4.0.0') {
64
+ throw new Error('You are using an unreleased schema version. Migration is not possible');
65
+ }
66
+
67
+ if ((0, _utils.isProjectSchemaV1)(projectSchema)) {
68
+ projectSchema = (0, _v.default)(projectSchema);
69
+ }
70
+
71
+ if ((0, _utils.isProjectSchemaV3)(projectSchema)) {
72
+ projectSchema = await (0, _v2.default)(context, projectSchema);
73
+ }
74
+
75
+ if ((0, _utils.isProjectSchemaV3_1)(projectSchema)) {
76
+ projectSchema = (0, _v3.default)(projectSchema);
77
+ }
78
+
79
+ if ((0, _utils.isProjectSchemaV3_2)(projectSchema)) {
80
+ projectSchema = await (0, _v4.default)(context, projectSchema);
81
+ }
82
+
83
+ if ((0, _utils.isProjectSchemaV3_3)(projectSchema)) {
84
+ projectSchema = (0, _v5.default)(projectSchema);
85
+ }
86
+
87
+ if ((0, _utils.isProjectSchemaV3_4)(projectSchema)) {
88
+ projectSchema = (0, _v6.default)(projectSchema);
89
+ }
90
+
91
+ if ((0, _utils.isProjectSchemaV3_5)(projectSchema)) {
92
+ projectSchema = (0, _v7.default)(projectSchema);
93
+ }
94
+
95
+ if ((0, _utils.isProjectSchemaV3_5_1)(projectSchema)) {
96
+ projectSchema = (0, _v8.default)(projectSchema);
97
+ }
98
+
99
+ if ((0, _utils.isProjectSchemaV3_6)(projectSchema)) {
100
+ projectSchema = (0, _v9.default)(projectSchema);
101
+ }
102
+
103
+ if ((0, _utils.isProjectSchemaV3_7)(projectSchema)) {
104
+ projectSchema = (0, _v10.default)(projectSchema);
105
+ }
106
+
107
+ if ((0, _utils.isProjectSchemaV3_8)(projectSchema)) {
108
+ projectSchema = (0, _v11.default)(projectSchema);
109
+ }
110
+
111
+ if ((0, _utils.isProjectSchemaV3_9)(projectSchema)) {
112
+ projectSchema = (0, _v12.default)(projectSchema);
113
+ }
114
+
115
+ if ((0, _utils.isProjectSchemaV3_10)(projectSchema)) {
116
+ projectSchema = (0, _v13.default)(context, projectSchema);
117
+ }
118
+
119
+ return projectSchema;
120
+ }
121
+
122
+ async function ensureLatest(context, schema) {
123
+ if (!schema || (0, _utils.isLatestProjectSchema)(schema)) {
124
+ return schema;
125
+ }
126
+
127
+ return migrateToLatestProjectSchema(context, schema);
128
+ }
@@ -0,0 +1,4 @@
1
+ import type { ProjectSchemaV1_0_0, ProjectSchemaV3_0_0 } from '../../project-schema';
2
+ declare function migrateToV3_0_0(projectSchema: ProjectSchemaV1_0_0): ProjectSchemaV3_0_0;
3
+ export default migrateToV3_0_0;
4
+ //# sourceMappingURL=v3.0.0.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v3.0.0.d.ts","sourceRoot":"","sources":["../../../../src/migration/to/v3.0.0.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,mBAAmB,EACnB,mBAAmB,EAQpB,MAAM,sBAAsB,CAAC;AAiN9B,iBAAS,eAAe,CAAC,aAAa,EAAE,mBAAmB,GAAG,mBAAmB,CAuBhF;AAED,eAAe,eAAe,CAAC"}
@@ -0,0 +1,260 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _forEach = _interopRequireDefault(require("lodash/forEach"));
9
+
10
+ var _pick = _interopRequireDefault(require("lodash/pick"));
11
+
12
+ var _util = require("@takeshape/util");
13
+
14
+ var _schemaUtil = require("../../schema-util");
15
+
16
+ var _utils = require("../utils");
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ const annotationMap = {
21
+ l10n: '@l10n',
22
+ sensitive: '@sensitive',
23
+ syncLocaleStructure: '@syncLocaleStructure'
24
+ };
25
+
26
+ function isColor(schema) {
27
+ const {
28
+ type,
29
+ properties
30
+ } = schema;
31
+ return Boolean(type === 'object' && properties && properties.hsl && properties.hsv && properties.rgb && properties.hex);
32
+ }
33
+
34
+ function getModelType(contentType) {
35
+ if (contentType.single) {
36
+ return 'single';
37
+ }
38
+
39
+ if (contentType.taxonomy) {
40
+ return 'taxonomy';
41
+ }
42
+
43
+ return 'multiple';
44
+ } // eslint-disable-next-line complexity
45
+
46
+
47
+ function migrateToContentSchemaV3(params) {
48
+ const {
49
+ schema,
50
+ service,
51
+ name,
52
+ key,
53
+ setSource,
54
+ omitAllSources
55
+ } = params;
56
+ const {
57
+ type
58
+ } = schema;
59
+ const mapping = !omitAllSources && key && setSource !== false && name !== key ? `${service}.${key}` : undefined;
60
+ (0, _forEach.default)(schema, (value, key) => {
61
+ if (annotationMap[key]) {
62
+ const newAnnotation = annotationMap[key];
63
+ schema[newAnnotation] = value; // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
64
+
65
+ delete schema[key];
66
+ }
67
+ });
68
+
69
+ if (type === 'string' || type === 'boolean' || type === 'number' || type === 'integer') {
70
+ return {
71
+ schema: { ...(0, _pick.default)(schema, _schemaUtil.scalarSchemaKeys),
72
+ '@mapping': mapping
73
+ }
74
+ };
75
+ }
76
+
77
+ const {
78
+ relationship
79
+ } = schema;
80
+
81
+ if (relationship) {
82
+ const {
83
+ contentTypeIds,
84
+ type: relationshipType,
85
+ relatedName
86
+ } = relationship;
87
+ return {
88
+ schema: { ...(0, _pick.default)(schema, relationshipType === 'multiple' ? _schemaUtil.multipleRelationshipSchemaKeys : _schemaUtil.schemaMetadataKeys),
89
+ '@mapping': mapping,
90
+ ...(0, _utils.getRelationshipSchema)({
91
+ shapeIds: contentTypeIds,
92
+ type: relationshipType ?? 'single',
93
+ // Type is optional on assets
94
+ relatedName
95
+ })
96
+ }
97
+ };
98
+ }
99
+
100
+ if (type === 'object' && schema.draftjs) {
101
+ return {
102
+ schema: { ...(0, _pick.default)(schema, _schemaUtil.scalarSchemaKeys),
103
+ '@mapping': mapping,
104
+ '@tag': 'draftjs'
105
+ }
106
+ };
107
+ }
108
+
109
+ if (isColor(schema)) {
110
+ return {
111
+ schema: { ...(0, _pick.default)(schema, _schemaUtil.scalarSchemaKeys),
112
+ $ref: '#/shapes/TSColor/schema',
113
+ '@mapping': mapping
114
+ }
115
+ };
116
+ }
117
+
118
+ if (type === 'object' && schema.properties) {
119
+ const properties = {};
120
+ const shapes = {};
121
+ const shapeTitle = [params.shapeTitle, (0, _util.pascalCase)(schema.title ?? params.name)].filter(Boolean).join(' ');
122
+ const shapeName = `${params.shapeName}${(0, _util.pascalCase)(params.name)}`;
123
+ const contentSourceId = `takeshape:local:${shapeName}`;
124
+ (0, _forEach.default)(schema.properties, (propSchema, name) => {
125
+ const {
126
+ schema: migratedPropSchema,
127
+ hoistedShapes
128
+ } = migrateToContentSchemaV3({ ...params,
129
+ shapeName,
130
+ shapeTitle,
131
+ depth: params.depth + 1,
132
+ schema: propSchema,
133
+ parentSchema: schema,
134
+ service: contentSourceId,
135
+ key: propSchema.key ?? name,
136
+ name,
137
+ setSource: true
138
+ });
139
+ properties[name] = migratedPropSchema;
140
+ Object.assign(shapes, hoistedShapes);
141
+ });
142
+
143
+ if (params.depth > 0) {
144
+ const {
145
+ title,
146
+ description,
147
+ ...rest
148
+ } = schema;
149
+ return {
150
+ schema: {
151
+ title,
152
+ description,
153
+ '@mapping': mapping,
154
+ $ref: `#/shapes/${shapeName}/schema`
155
+ },
156
+ hoistedShapes: { ...shapes,
157
+ [shapeName]: {
158
+ id: name === key ? shapeName : key,
159
+ name: shapeName,
160
+ title: shapeTitle,
161
+ schema: { ...(0, _pick.default)(rest, _schemaUtil.objectSchemaKeys),
162
+ type: 'object',
163
+ properties
164
+ }
165
+ }
166
+ }
167
+ };
168
+ }
169
+
170
+ return {
171
+ schema: { ...(0, _pick.default)(schema, _schemaUtil.objectSchemaKeys),
172
+ properties,
173
+ '@mapping': mapping
174
+ },
175
+ hoistedShapes: shapes
176
+ };
177
+ }
178
+
179
+ if (schema.type === 'array' && schema.items) {
180
+ const {
181
+ schema: itemSchema,
182
+ hoistedShapes
183
+ } = migrateToContentSchemaV3({ ...params,
184
+ schema: schema.items,
185
+ parentSchema: schema,
186
+ service: 'parent',
187
+ setSource: false
188
+ });
189
+ return {
190
+ schema: { ...(0, _pick.default)(schema, _schemaUtil.arraySchemaKeys),
191
+ items: itemSchema,
192
+ '@mapping': mapping
193
+ },
194
+ hoistedShapes
195
+ };
196
+ }
197
+
198
+ throw new Error(`Unknown schema type "${type}"`);
199
+ }
200
+
201
+ function contentTypeToShape(contentType, contentTypeId) {
202
+ const title = contentType.title ?? contentType.name;
203
+ const name = (0, _util.pascalCase)(contentType.name);
204
+ const contentSourceId = `takeshape:local:${name}`;
205
+ const {
206
+ schema,
207
+ hoistedShapes
208
+ } = migrateToContentSchemaV3({
209
+ shapeName: name,
210
+ shapeTitle: title,
211
+ schema: contentType.schema,
212
+ service: contentSourceId,
213
+ name: '',
214
+ key: '',
215
+ depth: 0
216
+ });
217
+ return {
218
+ [name]: {
219
+ id: contentTypeId,
220
+ name,
221
+ title,
222
+ model: {
223
+ type: getModelType(contentType)
224
+ },
225
+ workflow: contentType.workflow,
226
+ schema: schema
227
+ },
228
+ ...hoistedShapes
229
+ };
230
+ }
231
+
232
+ function migrateToV3_0_0(projectSchema) {
233
+ const {
234
+ contentTypes,
235
+ created,
236
+ updated,
237
+ ...rest
238
+ } = projectSchema;
239
+ const shapes = {};
240
+ const forms = {};
241
+ Object.keys(contentTypes).forEach(contentTypeId => {
242
+ const contentType = contentTypes[contentTypeId];
243
+ Object.assign(shapes, contentTypeToShape(contentType, contentTypeId));
244
+ forms[(0, _util.pascalCase)(contentType.name)] = contentType.forms;
245
+ }); // Use deepClone to drop undefined values, this improves compatibility with validation and testing
246
+ // Schemas are typically saved in Dynamo or JSON files which also remove undefined values
247
+ // Dropping them here is done for consistency's sake
248
+
249
+ return (0, _util.deepClone)({ ...rest,
250
+ ...(0, _schemaUtil.getShapeQueriesAndMutations)(Object.values(shapes)),
251
+ schemaVersion: '3',
252
+ created: (0, _utils.formatDate)(created),
253
+ updated: (0, _utils.formatDate)(updated),
254
+ shapes,
255
+ forms
256
+ });
257
+ }
258
+
259
+ var _default = migrateToV3_0_0;
260
+ exports.default = _default;
@@ -0,0 +1,5 @@
1
+ import type { ProjectSchemaV3_0_0, ProjectSchemaV3_1_0 } from '../../project-schema';
2
+ import type { ProjectSchemaMigrationContext } from '../types';
3
+ declare function migrateToV3_1(context: ProjectSchemaMigrationContext, projectSchema: ProjectSchemaV3_0_0): Promise<ProjectSchemaV3_1_0>;
4
+ export default migrateToV3_1;
5
+ //# sourceMappingURL=v3.1.0.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v3.1.0.d.ts","sourceRoot":"","sources":["../../../../src/migration/to/v3.1.0.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EAIpB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAC,6BAA6B,EAAC,MAAM,UAAU,CAAC;AAiM5D,iBAAe,aAAa,CAC1B,OAAO,EAAE,6BAA6B,EACtC,aAAa,EAAE,mBAAmB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CAgC9B;AAED,eAAe,aAAa,CAAC"}