@teambit/schema 0.0.881 → 0.0.882
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/exceptions/index.js +0 -3
- package/dist/exceptions/index.js.map +1 -1
- package/dist/exceptions/parser-not-found.js +0 -3
- package/dist/exceptions/parser-not-found.js.map +1 -1
- package/dist/index.js +0 -9
- package/dist/index.js.map +1 -1
- package/dist/mock/button/button.composition.js +2 -18
- package/dist/mock/button/button.composition.js.map +1 -1
- package/dist/mock/button/button.js +2 -23
- package/dist/mock/button/button.js.map +1 -1
- package/dist/mock/button/index.js +1 -48
- package/dist/mock/button/index.js.map +1 -1
- package/dist/schema-extract.task.js +0 -8
- package/dist/schema-extract.task.js.map +1 -1
- package/dist/schema.aspect.js +0 -5
- package/dist/schema.aspect.js.map +1 -1
- package/dist/schema.cmd.js +0 -18
- package/dist/schema.cmd.js.map +1 -1
- package/dist/schema.composition.js +0 -6
- package/dist/schema.composition.js.map +1 -1
- package/dist/schema.graphql.js +0 -9
- package/dist/schema.graphql.js.map +1 -1
- package/dist/schema.main.runtime.js +7 -60
- package/dist/schema.main.runtime.js.map +1 -1
- package/dist/schema.service.js +1 -9
- package/dist/schema.service.js.map +1 -1
- package/dist/schema.spec.js +10 -48
- package/dist/schema.spec.js.map +1 -1
- package/package-tar/teambit-schema-0.0.882.tgz +0 -0
- package/package.json +7 -7
- package/{preview-1666409808293.js → preview-1666496165706.js} +3 -3
- package/package-tar/teambit-schema-0.0.881.tgz +0 -0
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.Logo = void 0;
|
|
9
|
-
|
|
10
8
|
function _react() {
|
|
11
9
|
const data = _interopRequireDefault(require("react"));
|
|
12
|
-
|
|
13
10
|
_react = function () {
|
|
14
11
|
return data;
|
|
15
12
|
};
|
|
16
|
-
|
|
17
13
|
return data;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
const Logo = () => /*#__PURE__*/_react().default.createElement("div", {
|
|
21
16
|
style: {
|
|
22
17
|
height: '100%',
|
|
@@ -29,7 +24,6 @@ const Logo = () => /*#__PURE__*/_react().default.createElement("div", {
|
|
|
29
24
|
},
|
|
30
25
|
src: "https://static.bit.dev/extensions-icons/code.svg"
|
|
31
26
|
}));
|
|
32
|
-
|
|
33
27
|
exports.Logo = Logo;
|
|
34
28
|
|
|
35
29
|
//# sourceMappingURL=schema.composition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Logo","height","display","justifyContent","width"],"sources":["schema.composition.tsx"],"sourcesContent":["import React from 'react';\n\nexport const Logo = () => (\n <div style={{ height: '100%', display: 'flex', justifyContent: 'center' }}>\n <img style={{ width: 70 }} src=\"https://static.bit.dev/extensions-icons/code.svg\" />\n </div>\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["Logo","height","display","justifyContent","width"],"sources":["schema.composition.tsx"],"sourcesContent":["import React from 'react';\n\nexport const Logo = () => (\n <div style={{ height: '100%', display: 'flex', justifyContent: 'center' }}>\n <img style={{ width: 70 }} src=\"https://static.bit.dev/extensions-icons/code.svg\" />\n </div>\n);\n"],"mappings":";;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,IAAI,GAAG,mBAClB;EAAK,KAAK,EAAE;IAAEC,MAAM,EAAE,MAAM;IAAEC,OAAO,EAAE,MAAM;IAAEC,cAAc,EAAE;EAAS;AAAE,gBACxE;EAAK,KAAK,EAAE;IAAEC,KAAK,EAAE;EAAG,CAAE;EAAC,GAAG,EAAC;AAAkD,EAAG,CAEvF;AAAC"}
|
package/dist/schema.graphql.js
CHANGED
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.promise.js");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.schemaSchema = schemaSchema;
|
|
11
|
-
|
|
12
9
|
function _graphqlTypeJson() {
|
|
13
10
|
const data = require("graphql-type-json");
|
|
14
|
-
|
|
15
11
|
_graphqlTypeJson = function () {
|
|
16
12
|
return data;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
14
|
return data;
|
|
20
15
|
}
|
|
21
|
-
|
|
22
16
|
function _graphqlTag() {
|
|
23
17
|
const data = _interopRequireDefault(require("graphql-tag"));
|
|
24
|
-
|
|
25
18
|
_graphqlTag = function () {
|
|
26
19
|
return data;
|
|
27
20
|
};
|
|
28
|
-
|
|
29
21
|
return data;
|
|
30
22
|
}
|
|
31
|
-
|
|
32
23
|
function schemaSchema(schema) {
|
|
33
24
|
return {
|
|
34
25
|
typeDefs: (0, _graphqlTag().default)`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["schemaSchema","schema","typeDefs","gql","resolvers","JSONObject","GraphQLJSONObject","ComponentHost","getSchema","host","id","componentId","resolveComponentId","component","get","empty","exports","docs"],"sources":["schema.graphql.ts"],"sourcesContent":["import { ComponentFactory } from '@teambit/component';\nimport { GraphQLJSONObject } from 'graphql-type-json';\nimport gql from 'graphql-tag';\n\nimport { SchemaMain } from './schema.main.runtime';\n\nexport function schemaSchema(schema: SchemaMain) {\n return {\n typeDefs: gql`\n scalar JSONObject\n extend type ComponentHost {\n getSchema(id: String!): JSONObject\n }\n `,\n resolvers: {\n JSONObject: GraphQLJSONObject,\n ComponentHost: {\n getSchema: async (host: ComponentFactory, { id }: { id: string }) => {\n const componentId = await host.resolveComponentId(id);\n const component = await host.get(componentId);\n const empty = {\n exports: [],\n };\n\n if (!component) return empty;\n const docs = await schema.getSchema(component);\n if (!docs) return empty;\n\n return docs;\n },\n },\n },\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["schemaSchema","schema","typeDefs","gql","resolvers","JSONObject","GraphQLJSONObject","ComponentHost","getSchema","host","id","componentId","resolveComponentId","component","get","empty","exports","docs"],"sources":["schema.graphql.ts"],"sourcesContent":["import { ComponentFactory } from '@teambit/component';\nimport { GraphQLJSONObject } from 'graphql-type-json';\nimport gql from 'graphql-tag';\n\nimport { SchemaMain } from './schema.main.runtime';\n\nexport function schemaSchema(schema: SchemaMain) {\n return {\n typeDefs: gql`\n scalar JSONObject\n extend type ComponentHost {\n getSchema(id: String!): JSONObject\n }\n `,\n resolvers: {\n JSONObject: GraphQLJSONObject,\n ComponentHost: {\n getSchema: async (host: ComponentFactory, { id }: { id: string }) => {\n const componentId = await host.resolveComponentId(id);\n const component = await host.get(componentId);\n const empty = {\n exports: [],\n };\n\n if (!component) return empty;\n const docs = await schema.getSchema(component);\n if (!docs) return empty;\n\n return docs;\n },\n },\n },\n };\n}\n"],"mappings":";;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIO,SAASA,YAAY,CAACC,MAAkB,EAAE;EAC/C,OAAO;IACLC,QAAQ,EAAE,IAAAC,qBAAG,CAAC;AAClB;AACA;AACA;AACA;AACA,KAAK;IACDC,SAAS,EAAE;MACTC,UAAU,EAAEC,oCAAiB;MAC7BC,aAAa,EAAE;QACbC,SAAS,EAAE,OAAOC,IAAsB,EAAE;UAAEC;QAAmB,CAAC,KAAK;UACnE,MAAMC,WAAW,GAAG,MAAMF,IAAI,CAACG,kBAAkB,CAACF,EAAE,CAAC;UACrD,MAAMG,SAAS,GAAG,MAAMJ,IAAI,CAACK,GAAG,CAACH,WAAW,CAAC;UAC7C,MAAMI,KAAK,GAAG;YACZC,OAAO,EAAE;UACX,CAAC;UAED,IAAI,CAACH,SAAS,EAAE,OAAOE,KAAK;UAC5B,MAAME,IAAI,GAAG,MAAMhB,MAAM,CAACO,SAAS,CAACK,SAAS,CAAC;UAC9C,IAAI,CAACI,IAAI,EAAE,OAAOF,KAAK;UAEvB,OAAOE,IAAI;QACb;MACF;IACF;EACF,CAAC;AACH"}
|
|
@@ -1,128 +1,90 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.array.iterator.js");
|
|
6
|
-
|
|
7
5
|
require("core-js/modules/es.promise.js");
|
|
8
|
-
|
|
9
6
|
require("core-js/modules/es.regexp.exec.js");
|
|
10
|
-
|
|
11
7
|
Object.defineProperty(exports, "__esModule", {
|
|
12
8
|
value: true
|
|
13
9
|
});
|
|
14
10
|
exports.default = exports.SchemaMain = void 0;
|
|
15
|
-
|
|
16
11
|
function _defineProperty2() {
|
|
17
12
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
18
|
-
|
|
19
13
|
_defineProperty2 = function () {
|
|
20
14
|
return data;
|
|
21
15
|
};
|
|
22
|
-
|
|
23
16
|
return data;
|
|
24
17
|
}
|
|
25
|
-
|
|
26
18
|
function _cli() {
|
|
27
19
|
const data = require("@teambit/cli");
|
|
28
|
-
|
|
29
20
|
_cli = function () {
|
|
30
21
|
return data;
|
|
31
22
|
};
|
|
32
|
-
|
|
33
23
|
return data;
|
|
34
24
|
}
|
|
35
|
-
|
|
36
25
|
function _component() {
|
|
37
26
|
const data = _interopRequireDefault(require("@teambit/component"));
|
|
38
|
-
|
|
39
27
|
_component = function () {
|
|
40
28
|
return data;
|
|
41
29
|
};
|
|
42
|
-
|
|
43
30
|
return data;
|
|
44
31
|
}
|
|
45
|
-
|
|
46
32
|
function _harmony() {
|
|
47
33
|
const data = require("@teambit/harmony");
|
|
48
|
-
|
|
49
34
|
_harmony = function () {
|
|
50
35
|
return data;
|
|
51
36
|
};
|
|
52
|
-
|
|
53
37
|
return data;
|
|
54
38
|
}
|
|
55
|
-
|
|
56
39
|
function _graphql() {
|
|
57
40
|
const data = _interopRequireDefault(require("@teambit/graphql"));
|
|
58
|
-
|
|
59
41
|
_graphql = function () {
|
|
60
42
|
return data;
|
|
61
43
|
};
|
|
62
|
-
|
|
63
44
|
return data;
|
|
64
45
|
}
|
|
65
|
-
|
|
66
46
|
function _envs() {
|
|
67
47
|
const data = require("@teambit/envs");
|
|
68
|
-
|
|
69
48
|
_envs = function () {
|
|
70
49
|
return data;
|
|
71
50
|
};
|
|
72
|
-
|
|
73
51
|
return data;
|
|
74
52
|
}
|
|
75
|
-
|
|
76
53
|
function _logger() {
|
|
77
54
|
const data = require("@teambit/logger");
|
|
78
|
-
|
|
79
55
|
_logger = function () {
|
|
80
56
|
return data;
|
|
81
57
|
};
|
|
82
|
-
|
|
83
58
|
return data;
|
|
84
59
|
}
|
|
85
|
-
|
|
86
60
|
function _semanticsEntities() {
|
|
87
61
|
const data = require("@teambit/semantics.entities.semantic-schema");
|
|
88
|
-
|
|
89
62
|
_semanticsEntities = function () {
|
|
90
63
|
return data;
|
|
91
64
|
};
|
|
92
|
-
|
|
93
65
|
return data;
|
|
94
66
|
}
|
|
95
|
-
|
|
96
67
|
function _schema() {
|
|
97
68
|
const data = require("./schema.aspect");
|
|
98
|
-
|
|
99
69
|
_schema = function () {
|
|
100
70
|
return data;
|
|
101
71
|
};
|
|
102
|
-
|
|
103
72
|
return data;
|
|
104
73
|
}
|
|
105
|
-
|
|
106
74
|
function _schema2() {
|
|
107
75
|
const data = require("./schema.cmd");
|
|
108
|
-
|
|
109
76
|
_schema2 = function () {
|
|
110
77
|
return data;
|
|
111
78
|
};
|
|
112
|
-
|
|
113
79
|
return data;
|
|
114
80
|
}
|
|
115
|
-
|
|
116
81
|
function _schema3() {
|
|
117
82
|
const data = require("./schema.graphql");
|
|
118
|
-
|
|
119
83
|
_schema3 = function () {
|
|
120
84
|
return data;
|
|
121
85
|
};
|
|
122
|
-
|
|
123
86
|
return data;
|
|
124
87
|
}
|
|
125
|
-
|
|
126
88
|
/**
|
|
127
89
|
* extension for extracting component schemas.
|
|
128
90
|
*/
|
|
@@ -137,88 +99,75 @@ class SchemaMain {
|
|
|
137
99
|
this.config = config;
|
|
138
100
|
this.logger = logger;
|
|
139
101
|
}
|
|
102
|
+
|
|
140
103
|
/**
|
|
141
104
|
* get the default parser.
|
|
142
105
|
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
106
|
getDefaultParser() {
|
|
146
107
|
return this.parserSlot.get(this.config.defaultParser);
|
|
147
108
|
}
|
|
109
|
+
|
|
148
110
|
/**
|
|
149
111
|
* parse a module into a component schema.
|
|
150
112
|
*/
|
|
151
|
-
|
|
152
|
-
|
|
153
113
|
parseModule(path) {
|
|
154
114
|
const parsers = this.parserSlot.toArray();
|
|
155
115
|
let maybeParser = parsers.find(([, parser]) => {
|
|
156
116
|
const match = path.match(parser.extension);
|
|
157
117
|
return match;
|
|
158
118
|
});
|
|
159
|
-
|
|
160
119
|
if (!maybeParser) {
|
|
161
120
|
maybeParser = [this.config.defaultParser, this.getDefaultParser()];
|
|
162
121
|
}
|
|
163
|
-
|
|
164
122
|
const [, parser] = maybeParser;
|
|
165
123
|
return parser.parseModule(path);
|
|
166
124
|
}
|
|
167
|
-
|
|
168
125
|
getSchemaExtractor(component) {
|
|
169
126
|
const env = this.envs.getEnv(component).env;
|
|
170
|
-
|
|
171
127
|
if (typeof env.getSchemaExtractor === 'undefined') {
|
|
172
128
|
throw new Error(`No SchemaExtractor defined for ${env.name}`);
|
|
173
129
|
}
|
|
174
|
-
|
|
175
130
|
return env.getSchemaExtractor();
|
|
176
131
|
}
|
|
132
|
+
|
|
177
133
|
/**
|
|
178
134
|
* get a schema of a component.
|
|
179
135
|
* @param component target component.
|
|
180
136
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
137
|
async getSchema(component) {
|
|
184
138
|
this.logger.debug(`getSchema of ${component.id.toString()}`);
|
|
185
139
|
const env = this.envs.getEnv(component).env;
|
|
186
|
-
|
|
187
140
|
if (typeof env.getSchemaExtractor === 'undefined') {
|
|
188
141
|
throw new Error(`No SchemaExtractor defined for ${env.name}`);
|
|
189
142
|
}
|
|
190
|
-
|
|
191
143
|
const schemaExtractor = env.getSchemaExtractor();
|
|
192
144
|
return schemaExtractor.extract(component);
|
|
193
145
|
}
|
|
194
|
-
|
|
195
146
|
getSchemaFromObject(obj) {
|
|
196
147
|
return _semanticsEntities().APISchema.fromObject(obj);
|
|
197
148
|
}
|
|
149
|
+
|
|
198
150
|
/**
|
|
199
151
|
* register a new parser.
|
|
200
152
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
203
153
|
registerParser(parser) {
|
|
204
154
|
this.parserSlot.register(parser);
|
|
205
155
|
return this;
|
|
206
156
|
}
|
|
207
|
-
|
|
208
157
|
static async provider([envs, cli, component, graphql, loggerMain], config, [parserSlot]) {
|
|
209
158
|
const logger = loggerMain.createLogger(_schema().SchemaAspect.id);
|
|
210
159
|
const schema = new SchemaMain(parserSlot, envs, config, logger);
|
|
211
160
|
cli.register(new (_schema2().SchemaCommand)(schema, component, logger));
|
|
212
|
-
graphql.register((0, _schema3().schemaSchema)(schema));
|
|
161
|
+
graphql.register((0, _schema3().schemaSchema)(schema));
|
|
162
|
+
|
|
163
|
+
// workspace.onComponentLoad(async (component) => {
|
|
213
164
|
// const apiSchema = await schema.getSchema(component);
|
|
214
165
|
// return {};
|
|
215
166
|
// });
|
|
216
167
|
|
|
217
168
|
return schema;
|
|
218
169
|
}
|
|
219
|
-
|
|
220
170
|
}
|
|
221
|
-
|
|
222
171
|
exports.SchemaMain = SchemaMain;
|
|
223
172
|
(0, _defineProperty2().default)(SchemaMain, "runtime", _cli().MainRuntime);
|
|
224
173
|
(0, _defineProperty2().default)(SchemaMain, "dependencies", [_envs().EnvsAspect, _cli().CLIAspect, _component().default, _graphql().default, _logger().LoggerAspect]);
|
|
@@ -226,9 +175,7 @@ exports.SchemaMain = SchemaMain;
|
|
|
226
175
|
(0, _defineProperty2().default)(SchemaMain, "defaultConfig", {
|
|
227
176
|
defaultParser: 'teambit.typescript/typescript'
|
|
228
177
|
});
|
|
229
|
-
|
|
230
178
|
_schema().SchemaAspect.addRuntime(SchemaMain);
|
|
231
|
-
|
|
232
179
|
var _default = SchemaMain;
|
|
233
180
|
exports.default = _default;
|
|
234
181
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SchemaMain","constructor","parserSlot","envs","config","logger","getDefaultParser","get","defaultParser","parseModule","path","parsers","toArray","maybeParser","find","parser","match","extension","getSchemaExtractor","component","env","getEnv","Error","name","getSchema","debug","id","toString","schemaExtractor","extract","getSchemaFromObject","obj","APISchema","fromObject","registerParser","register","provider","cli","graphql","loggerMain","createLogger","SchemaAspect","schema","SchemaCommand","schemaSchema","MainRuntime","EnvsAspect","CLIAspect","ComponentAspect","GraphqlAspect","LoggerAspect","Slot","withType","addRuntime"],"sources":["schema.main.runtime.ts"],"sourcesContent":["import { MainRuntime, CLIMain, CLIAspect } from '@teambit/cli';\nimport ComponentAspect, { Component, ComponentMain } from '@teambit/component';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport GraphqlAspect, { GraphqlMain } from '@teambit/graphql';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { APISchema, Export } from '@teambit/semantics.entities.semantic-schema';\nimport { Parser } from './parser';\nimport { SchemaAspect } from './schema.aspect';\nimport { SchemaExtractor } from './schema-extractor';\nimport { SchemaCommand } from './schema.cmd';\nimport { schemaSchema } from './schema.graphql';\n\nexport type ParserSlot = SlotRegistry<Parser>;\n\nexport type SchemaConfig = {\n /**\n * default parser\n */\n defaultParser: string;\n};\n\n/**\n * extension for extracting component schemas.\n */\nexport class SchemaMain {\n constructor(\n /**\n * parsers slot.\n */\n private parserSlot: ParserSlot,\n\n private envs: EnvsMain,\n\n private config: SchemaConfig,\n\n private logger: Logger\n ) {}\n\n /**\n * get the default parser.\n */\n getDefaultParser(): Parser {\n return this.parserSlot.get(this.config.defaultParser) as Parser;\n }\n\n /**\n * parse a module into a component schema.\n */\n parseModule(path: string): Export[] {\n const parsers = this.parserSlot.toArray();\n let maybeParser = parsers.find(([, parser]) => {\n const match = path.match(parser.extension);\n return match;\n });\n\n if (!maybeParser) {\n maybeParser = [this.config.defaultParser, this.getDefaultParser()];\n }\n\n const [, parser] = maybeParser;\n return parser.parseModule(path);\n }\n\n getSchemaExtractor(component: Component) {\n const env = this.envs.getEnv(component).env;\n if (typeof env.getSchemaExtractor === 'undefined') {\n throw new Error(`No SchemaExtractor defined for ${env.name}`);\n }\n\n return env.getSchemaExtractor();\n }\n\n /**\n * get a schema of a component.\n * @param component target component.\n */\n async getSchema(component: Component): Promise<APISchema> {\n this.logger.debug(`getSchema of ${component.id.toString()}`);\n const env = this.envs.getEnv(component).env;\n if (typeof env.getSchemaExtractor === 'undefined') {\n throw new Error(`No SchemaExtractor defined for ${env.name}`);\n }\n const schemaExtractor: SchemaExtractor = env.getSchemaExtractor();\n return schemaExtractor.extract(component);\n }\n\n getSchemaFromObject(obj: Record<string, any>): APISchema {\n return APISchema.fromObject(obj);\n }\n\n /**\n * register a new parser.\n */\n registerParser(parser: Parser): SchemaMain {\n this.parserSlot.register(parser);\n return this;\n }\n\n static runtime = MainRuntime;\n static dependencies = [EnvsAspect, CLIAspect, ComponentAspect, GraphqlAspect, LoggerAspect];\n static slots = [Slot.withType<Parser>()];\n\n static defaultConfig = {\n defaultParser: 'teambit.typescript/typescript',\n };\n\n static async provider(\n [envs, cli, component, graphql, loggerMain]: [EnvsMain, CLIMain, ComponentMain, GraphqlMain, LoggerMain],\n config: SchemaConfig,\n [parserSlot]: [ParserSlot]\n ) {\n const logger = loggerMain.createLogger(SchemaAspect.id);\n const schema = new SchemaMain(parserSlot, envs, config, logger);\n cli.register(new SchemaCommand(schema, component, logger));\n graphql.register(schemaSchema(schema));\n\n // workspace.onComponentLoad(async (component) => {\n // const apiSchema = await schema.getSchema(component);\n // return {};\n // });\n\n return schema;\n }\n}\n\nSchemaAspect.addRuntime(SchemaMain);\n\nexport default SchemaMain;\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["SchemaMain","constructor","parserSlot","envs","config","logger","getDefaultParser","get","defaultParser","parseModule","path","parsers","toArray","maybeParser","find","parser","match","extension","getSchemaExtractor","component","env","getEnv","Error","name","getSchema","debug","id","toString","schemaExtractor","extract","getSchemaFromObject","obj","APISchema","fromObject","registerParser","register","provider","cli","graphql","loggerMain","createLogger","SchemaAspect","schema","SchemaCommand","schemaSchema","MainRuntime","EnvsAspect","CLIAspect","ComponentAspect","GraphqlAspect","LoggerAspect","Slot","withType","addRuntime"],"sources":["schema.main.runtime.ts"],"sourcesContent":["import { MainRuntime, CLIMain, CLIAspect } from '@teambit/cli';\nimport ComponentAspect, { Component, ComponentMain } from '@teambit/component';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport GraphqlAspect, { GraphqlMain } from '@teambit/graphql';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { APISchema, Export } from '@teambit/semantics.entities.semantic-schema';\nimport { Parser } from './parser';\nimport { SchemaAspect } from './schema.aspect';\nimport { SchemaExtractor } from './schema-extractor';\nimport { SchemaCommand } from './schema.cmd';\nimport { schemaSchema } from './schema.graphql';\n\nexport type ParserSlot = SlotRegistry<Parser>;\n\nexport type SchemaConfig = {\n /**\n * default parser\n */\n defaultParser: string;\n};\n\n/**\n * extension for extracting component schemas.\n */\nexport class SchemaMain {\n constructor(\n /**\n * parsers slot.\n */\n private parserSlot: ParserSlot,\n\n private envs: EnvsMain,\n\n private config: SchemaConfig,\n\n private logger: Logger\n ) {}\n\n /**\n * get the default parser.\n */\n getDefaultParser(): Parser {\n return this.parserSlot.get(this.config.defaultParser) as Parser;\n }\n\n /**\n * parse a module into a component schema.\n */\n parseModule(path: string): Export[] {\n const parsers = this.parserSlot.toArray();\n let maybeParser = parsers.find(([, parser]) => {\n const match = path.match(parser.extension);\n return match;\n });\n\n if (!maybeParser) {\n maybeParser = [this.config.defaultParser, this.getDefaultParser()];\n }\n\n const [, parser] = maybeParser;\n return parser.parseModule(path);\n }\n\n getSchemaExtractor(component: Component) {\n const env = this.envs.getEnv(component).env;\n if (typeof env.getSchemaExtractor === 'undefined') {\n throw new Error(`No SchemaExtractor defined for ${env.name}`);\n }\n\n return env.getSchemaExtractor();\n }\n\n /**\n * get a schema of a component.\n * @param component target component.\n */\n async getSchema(component: Component): Promise<APISchema> {\n this.logger.debug(`getSchema of ${component.id.toString()}`);\n const env = this.envs.getEnv(component).env;\n if (typeof env.getSchemaExtractor === 'undefined') {\n throw new Error(`No SchemaExtractor defined for ${env.name}`);\n }\n const schemaExtractor: SchemaExtractor = env.getSchemaExtractor();\n return schemaExtractor.extract(component);\n }\n\n getSchemaFromObject(obj: Record<string, any>): APISchema {\n return APISchema.fromObject(obj);\n }\n\n /**\n * register a new parser.\n */\n registerParser(parser: Parser): SchemaMain {\n this.parserSlot.register(parser);\n return this;\n }\n\n static runtime = MainRuntime;\n static dependencies = [EnvsAspect, CLIAspect, ComponentAspect, GraphqlAspect, LoggerAspect];\n static slots = [Slot.withType<Parser>()];\n\n static defaultConfig = {\n defaultParser: 'teambit.typescript/typescript',\n };\n\n static async provider(\n [envs, cli, component, graphql, loggerMain]: [EnvsMain, CLIMain, ComponentMain, GraphqlMain, LoggerMain],\n config: SchemaConfig,\n [parserSlot]: [ParserSlot]\n ) {\n const logger = loggerMain.createLogger(SchemaAspect.id);\n const schema = new SchemaMain(parserSlot, envs, config, logger);\n cli.register(new SchemaCommand(schema, component, logger));\n graphql.register(schemaSchema(schema));\n\n // workspace.onComponentLoad(async (component) => {\n // const apiSchema = await schema.getSchema(component);\n // return {};\n // });\n\n return schema;\n }\n}\n\nSchemaAspect.addRuntime(SchemaMain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AAEkC,GAAG,EAAElB,SAAS,EAAEmB,OAAO,EAAEC,UAAU,CAA8D,EACxGnC,MAAoB,EACpB,CAACF,UAAU,CAAe,EAC1B;IACA,MAAMG,MAAM,GAAGkC,UAAU,CAACC,YAAY,CAACC,sBAAY,CAACf,EAAE,CAAC;IACvD,MAAMgB,MAAM,GAAG,IAAI1C,UAAU,CAACE,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC;IAC/DgC,GAAG,CAACF,QAAQ,CAAC,KAAIQ,wBAAa,EAACD,MAAM,EAAEvB,SAAS,EAAEd,MAAM,CAAC,CAAC;IAC1DiC,OAAO,CAACH,QAAQ,CAAC,IAAAS,uBAAY,EAACF,MAAM,CAAC,CAAC;;IAEtC;IACA;IACA;IACA;;IAEA,OAAOA,MAAM;EACf;AACF;AAAC;AAAA,gCAnGY1C,UAAU,aA0EJ6C,kBAAW;AAAA,gCA1EjB7C,UAAU,kBA2EC,CAAC8C,kBAAU,EAAEC,gBAAS,EAAEC,oBAAe,EAAEC,kBAAa,EAAEC,sBAAY,CAAC;AAAA,gCA3EhFlD,UAAU,WA4EN,CAACmD,eAAI,CAACC,QAAQ,EAAU,CAAC;AAAA,gCA5E7BpD,UAAU,mBA8EE;EACrBQ,aAAa,EAAE;AACjB,CAAC;AAqBHiC,sBAAY,CAACY,UAAU,CAACrD,UAAU,CAAC;AAAC,eAErBA,UAAU;AAAA"}
|
package/dist/schema.service.js
CHANGED
|
@@ -1,39 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.promise.js");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.SchemaService = void 0;
|
|
11
|
-
|
|
12
9
|
function _defineProperty2() {
|
|
13
10
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
-
|
|
15
11
|
_defineProperty2 = function () {
|
|
16
12
|
return data;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
14
|
return data;
|
|
20
15
|
}
|
|
21
|
-
|
|
22
16
|
// import { APISchema } from './schema';
|
|
17
|
+
|
|
23
18
|
class SchemaService {
|
|
24
19
|
constructor() {
|
|
25
20
|
(0, _defineProperty2().default)(this, "name", 'schema');
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
async run(context) {
|
|
29
23
|
return {
|
|
30
24
|
errors: [],
|
|
31
25
|
context
|
|
32
26
|
};
|
|
33
27
|
}
|
|
34
|
-
|
|
35
28
|
}
|
|
36
|
-
|
|
37
29
|
exports.SchemaService = SchemaService;
|
|
38
30
|
|
|
39
31
|
//# sourceMappingURL=schema.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SchemaService","run","context","errors"],"sources":["schema.service.ts"],"sourcesContent":["import { EnvService, ExecutionContext } from '@teambit/envs';\n// import { APISchema } from './schema';\n\nexport class SchemaService implements EnvService<{}> {\n name = 'schema';\n\n async run(context: ExecutionContext) {\n return { errors: [], context };\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["SchemaService","run","context","errors"],"sources":["schema.service.ts"],"sourcesContent":["import { EnvService, ExecutionContext } from '@teambit/envs';\n// import { APISchema } from './schema';\n\nexport class SchemaService implements EnvService<{}> {\n name = 'schema';\n\n async run(context: ExecutionContext) {\n return { errors: [], context };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AACA;;AAEO,MAAMA,aAAa,CAA2B;EAAA;IAAA,8CAC5C,QAAQ;EAAA;EAEf,MAAMC,GAAG,CAACC,OAAyB,EAAE;IACnC,OAAO;MAAEC,MAAM,EAAE,EAAE;MAAED;IAAQ,CAAC;EAChC;AACF;AAAC"}
|
package/dist/schema.spec.js
CHANGED
|
@@ -1,89 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.promise.js");
|
|
6
|
-
|
|
7
5
|
function _path() {
|
|
8
6
|
const data = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
7
|
_path = function () {
|
|
11
8
|
return data;
|
|
12
9
|
};
|
|
13
|
-
|
|
14
10
|
return data;
|
|
15
11
|
}
|
|
16
|
-
|
|
17
12
|
function _fsExtra() {
|
|
18
13
|
const data = _interopRequireDefault(require("fs-extra"));
|
|
19
|
-
|
|
20
14
|
_fsExtra = function () {
|
|
21
15
|
return data;
|
|
22
16
|
};
|
|
23
|
-
|
|
24
17
|
return data;
|
|
25
18
|
}
|
|
26
|
-
|
|
27
19
|
function _semanticsEntities() {
|
|
28
20
|
const data = require("@teambit/semantics.entities.semantic-schema");
|
|
29
|
-
|
|
30
21
|
_semanticsEntities = function () {
|
|
31
22
|
return data;
|
|
32
23
|
};
|
|
33
|
-
|
|
34
24
|
return data;
|
|
35
25
|
}
|
|
36
|
-
|
|
37
26
|
function _harmonyTesting() {
|
|
38
27
|
const data = require("@teambit/harmony.testing.load-aspect");
|
|
39
|
-
|
|
40
28
|
_harmonyTesting = function () {
|
|
41
29
|
return data;
|
|
42
30
|
};
|
|
43
|
-
|
|
44
31
|
return data;
|
|
45
32
|
}
|
|
46
|
-
|
|
47
33
|
function _workspaceTesting() {
|
|
48
34
|
const data = require("@teambit/workspace.testing.mock-workspace");
|
|
49
|
-
|
|
50
35
|
_workspaceTesting = function () {
|
|
51
36
|
return data;
|
|
52
37
|
};
|
|
53
|
-
|
|
54
38
|
return data;
|
|
55
39
|
}
|
|
56
|
-
|
|
57
40
|
function _componentId() {
|
|
58
41
|
const data = require("@teambit/component-id");
|
|
59
|
-
|
|
60
42
|
_componentId = function () {
|
|
61
43
|
return data;
|
|
62
44
|
};
|
|
63
|
-
|
|
64
45
|
return data;
|
|
65
46
|
}
|
|
66
|
-
|
|
67
47
|
function _workspace() {
|
|
68
48
|
const data = _interopRequireDefault(require("@teambit/workspace"));
|
|
69
|
-
|
|
70
49
|
_workspace = function () {
|
|
71
50
|
return data;
|
|
72
51
|
};
|
|
73
|
-
|
|
74
52
|
return data;
|
|
75
53
|
}
|
|
76
|
-
|
|
77
54
|
function _() {
|
|
78
55
|
const data = require(".");
|
|
79
|
-
|
|
80
56
|
_ = function () {
|
|
81
57
|
return data;
|
|
82
58
|
};
|
|
83
|
-
|
|
84
59
|
return data;
|
|
85
60
|
}
|
|
86
|
-
|
|
87
61
|
describe('SchemaAspect', function () {
|
|
88
62
|
let schema;
|
|
89
63
|
let workspace;
|
|
@@ -92,8 +66,8 @@ describe('SchemaAspect', function () {
|
|
|
92
66
|
workspaceData = (0, _workspaceTesting().mockWorkspace)();
|
|
93
67
|
const {
|
|
94
68
|
workspacePath
|
|
95
|
-
} = workspaceData;
|
|
96
|
-
|
|
69
|
+
} = workspaceData;
|
|
70
|
+
// eslint-disable-next-line no-console
|
|
97
71
|
console.log('workspace created at ', workspacePath);
|
|
98
72
|
schema = await (0, _harmonyTesting().loadAspect)(_().SchemaAspect, workspacePath);
|
|
99
73
|
});
|
|
@@ -106,11 +80,8 @@ describe('SchemaAspect', function () {
|
|
|
106
80
|
const {
|
|
107
81
|
workspacePath
|
|
108
82
|
} = workspaceData;
|
|
109
|
-
|
|
110
83
|
const compDir = _path().default.join(workspacePath, 'button');
|
|
111
|
-
|
|
112
84
|
const src = _path().default.join(getMockDir(), 'button');
|
|
113
|
-
|
|
114
85
|
await _fsExtra().default.copy(src, compDir);
|
|
115
86
|
workspace = await (0, _harmonyTesting().loadAspect)(_workspace().default, workspacePath);
|
|
116
87
|
await workspace.track({
|
|
@@ -125,38 +96,31 @@ describe('SchemaAspect', function () {
|
|
|
125
96
|
});
|
|
126
97
|
it('should be able to generate JSON object with all schemas', async () => {
|
|
127
98
|
const results = apiSchema.toObject();
|
|
128
|
-
|
|
129
|
-
|
|
99
|
+
const expectedJsonPath = _path().default.join(getMockDir(), 'button-schemas.json');
|
|
100
|
+
// uncomment the next line temporarily to sync the expected json with new schema changes
|
|
130
101
|
// fs.outputFileSync(expectedJsonPath, JSON.stringify(results, undefined, 2));
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const expectedJson = _fsExtra().default.readJsonSync(expectedJsonPath); // @ts-ignore it exists on Jest. for some reason ts assumes this is Jasmine.
|
|
134
|
-
|
|
135
|
-
|
|
102
|
+
const expectedJson = _fsExtra().default.readJsonSync(expectedJsonPath);
|
|
103
|
+
// @ts-ignore it exists on Jest. for some reason ts assumes this is Jasmine.
|
|
136
104
|
expect(results).toMatchObject(expectedJson);
|
|
137
105
|
});
|
|
138
106
|
});
|
|
139
107
|
describe('getSchemaFromObject', () => {
|
|
140
108
|
it('should be able to deserialize an JSON object to SchemaNode instances', () => {
|
|
141
109
|
const jsonPath = _path().default.join(getMockDir(), 'button-schemas.json');
|
|
142
|
-
|
|
143
110
|
const json = _fsExtra().default.readJsonSync(jsonPath);
|
|
144
|
-
|
|
145
111
|
const apiSchema = schema.getSchemaFromObject(json);
|
|
146
112
|
expect(apiSchema instanceof _semanticsEntities().APISchema).toBeTruthy();
|
|
147
|
-
expect(apiSchema.componentId instanceof _componentId().ComponentID).toBeTruthy();
|
|
148
|
-
|
|
113
|
+
expect(apiSchema.componentId instanceof _componentId().ComponentID).toBeTruthy();
|
|
114
|
+
// @ts-ignore it exists on Jest. for some reason ts assumes this is Jasmine.
|
|
149
115
|
expect(apiSchema.toObject()).toMatchObject(json);
|
|
150
116
|
});
|
|
151
117
|
it('should not throw when it does not recognize the schema', () => {
|
|
152
118
|
const jsonPath = _path().default.join(getMockDir(), 'button-old-schema.json');
|
|
153
|
-
|
|
154
119
|
const json = _fsExtra().default.readJsonSync(jsonPath);
|
|
155
|
-
|
|
156
120
|
const apiSchema = schema.getSchemaFromObject(json);
|
|
157
121
|
expect(apiSchema instanceof _semanticsEntities().APISchema).toBeTruthy();
|
|
158
|
-
expect(apiSchema.module.exports[0] instanceof _semanticsEntities().UnknownSchema).toBeTruthy();
|
|
159
|
-
|
|
122
|
+
expect(apiSchema.module.exports[0] instanceof _semanticsEntities().UnknownSchema).toBeTruthy();
|
|
123
|
+
// @ts-ignore
|
|
160
124
|
expect(apiSchema.module.exports[0].location).toMatchObject({
|
|
161
125
|
file: 'index.ts',
|
|
162
126
|
line: 21,
|
|
@@ -165,13 +129,11 @@ describe('SchemaAspect', function () {
|
|
|
165
129
|
});
|
|
166
130
|
});
|
|
167
131
|
});
|
|
168
|
-
|
|
169
132
|
function getCurrentDir() {
|
|
170
133
|
const currentDir = __dirname;
|
|
171
134
|
if (currentDir.endsWith(`${_path().default.sep}dist`)) return currentDir.slice(0, -5);
|
|
172
135
|
return currentDir;
|
|
173
136
|
}
|
|
174
|
-
|
|
175
137
|
function getMockDir() {
|
|
176
138
|
return _path().default.join(getCurrentDir(), 'mock');
|
|
177
139
|
}
|
package/dist/schema.spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["describe","schema","workspace","workspaceData","beforeAll","mockWorkspace","workspacePath","console","log","loadAspect","SchemaAspect","afterAll","destroyWorkspace","apiSchema","compDir","path","join","src","getMockDir","fs","copy","WorkspaceAspect","track","rootDir","defaultScope","bitMap","write","compId","resolveComponentId","comp","get","getSchema","it","results","toObject","expectedJsonPath","expectedJson","readJsonSync","expect","toMatchObject","jsonPath","json","getSchemaFromObject","APISchema","toBeTruthy","componentId","ComponentID","module","exports","UnknownSchema","location","file","line","character","getCurrentDir","currentDir","__dirname","endsWith","sep","slice"],"sources":["schema.spec.ts"],"sourcesContent":["import path from 'path';\nimport fs from 'fs-extra';\nimport { APISchema, UnknownSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { loadAspect } from '@teambit/harmony.testing.load-aspect';\nimport { mockWorkspace, destroyWorkspace, WorkspaceData } from '@teambit/workspace.testing.mock-workspace';\nimport { ComponentID } from '@teambit/component-id';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { SchemaMain } from './schema.main.runtime';\nimport { SchemaAspect } from '.';\n\ndescribe('SchemaAspect', function () {\n let schema: SchemaMain;\n let workspace: Workspace;\n let workspaceData: WorkspaceData;\n beforeAll(async () => {\n workspaceData = mockWorkspace();\n const { workspacePath } = workspaceData;\n // eslint-disable-next-line no-console\n console.log('workspace created at ', workspacePath);\n schema = await loadAspect(SchemaAspect, workspacePath);\n });\n afterAll(async () => {\n await destroyWorkspace(workspaceData);\n });\n describe('getSchema()', () => {\n let apiSchema: APISchema;\n beforeAll(async () => {\n const { workspacePath } = workspaceData;\n const compDir = path.join(workspacePath, 'button');\n const src = path.join(getMockDir(), 'button');\n await fs.copy(src, compDir);\n workspace = await loadAspect(WorkspaceAspect, workspacePath);\n await workspace.track({ rootDir: compDir, defaultScope: 'org.scope' });\n await workspace.bitMap.write();\n schema = await loadAspect(SchemaAspect, workspacePath);\n const compId = await workspace.resolveComponentId('button');\n const comp = await workspace.get(compId);\n apiSchema = await schema.getSchema(comp);\n });\n it('should be able to generate JSON object with all schemas', async () => {\n const results = apiSchema.toObject();\n const expectedJsonPath = path.join(getMockDir(), 'button-schemas.json');\n // uncomment the next line temporarily to sync the expected json with new schema changes\n // fs.outputFileSync(expectedJsonPath, JSON.stringify(results, undefined, 2));\n const expectedJson = fs.readJsonSync(expectedJsonPath);\n // @ts-ignore it exists on Jest. for some reason ts assumes this is Jasmine.\n expect(results).toMatchObject(expectedJson);\n });\n });\n describe('getSchemaFromObject', () => {\n it('should be able to deserialize an JSON object to SchemaNode instances', () => {\n const jsonPath = path.join(getMockDir(), 'button-schemas.json');\n const json = fs.readJsonSync(jsonPath);\n const apiSchema = schema.getSchemaFromObject(json);\n expect(apiSchema instanceof APISchema).toBeTruthy();\n expect(apiSchema.componentId instanceof ComponentID).toBeTruthy();\n // @ts-ignore it exists on Jest. for some reason ts assumes this is Jasmine.\n expect(apiSchema.toObject()).toMatchObject(json);\n });\n it('should not throw when it does not recognize the schema', () => {\n const jsonPath = path.join(getMockDir(), 'button-old-schema.json');\n const json = fs.readJsonSync(jsonPath);\n const apiSchema = schema.getSchemaFromObject(json);\n expect(apiSchema instanceof APISchema).toBeTruthy();\n expect(apiSchema.module.exports[0] instanceof UnknownSchema).toBeTruthy();\n // @ts-ignore\n expect(apiSchema.module.exports[0].location).toMatchObject({ file: 'index.ts', line: 21, character: 14 });\n });\n });\n});\n\nfunction getCurrentDir() {\n const currentDir = __dirname;\n if (currentDir.endsWith(`${path.sep}dist`)) return currentDir.slice(0, -5);\n return currentDir;\n}\n\nfunction getMockDir() {\n return path.join(getCurrentDir(), 'mock');\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["describe","schema","workspace","workspaceData","beforeAll","mockWorkspace","workspacePath","console","log","loadAspect","SchemaAspect","afterAll","destroyWorkspace","apiSchema","compDir","path","join","src","getMockDir","fs","copy","WorkspaceAspect","track","rootDir","defaultScope","bitMap","write","compId","resolveComponentId","comp","get","getSchema","it","results","toObject","expectedJsonPath","expectedJson","readJsonSync","expect","toMatchObject","jsonPath","json","getSchemaFromObject","APISchema","toBeTruthy","componentId","ComponentID","module","exports","UnknownSchema","location","file","line","character","getCurrentDir","currentDir","__dirname","endsWith","sep","slice"],"sources":["schema.spec.ts"],"sourcesContent":["import path from 'path';\nimport fs from 'fs-extra';\nimport { APISchema, UnknownSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { loadAspect } from '@teambit/harmony.testing.load-aspect';\nimport { mockWorkspace, destroyWorkspace, WorkspaceData } from '@teambit/workspace.testing.mock-workspace';\nimport { ComponentID } from '@teambit/component-id';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { SchemaMain } from './schema.main.runtime';\nimport { SchemaAspect } from '.';\n\ndescribe('SchemaAspect', function () {\n let schema: SchemaMain;\n let workspace: Workspace;\n let workspaceData: WorkspaceData;\n beforeAll(async () => {\n workspaceData = mockWorkspace();\n const { workspacePath } = workspaceData;\n // eslint-disable-next-line no-console\n console.log('workspace created at ', workspacePath);\n schema = await loadAspect(SchemaAspect, workspacePath);\n });\n afterAll(async () => {\n await destroyWorkspace(workspaceData);\n });\n describe('getSchema()', () => {\n let apiSchema: APISchema;\n beforeAll(async () => {\n const { workspacePath } = workspaceData;\n const compDir = path.join(workspacePath, 'button');\n const src = path.join(getMockDir(), 'button');\n await fs.copy(src, compDir);\n workspace = await loadAspect(WorkspaceAspect, workspacePath);\n await workspace.track({ rootDir: compDir, defaultScope: 'org.scope' });\n await workspace.bitMap.write();\n schema = await loadAspect(SchemaAspect, workspacePath);\n const compId = await workspace.resolveComponentId('button');\n const comp = await workspace.get(compId);\n apiSchema = await schema.getSchema(comp);\n });\n it('should be able to generate JSON object with all schemas', async () => {\n const results = apiSchema.toObject();\n const expectedJsonPath = path.join(getMockDir(), 'button-schemas.json');\n // uncomment the next line temporarily to sync the expected json with new schema changes\n // fs.outputFileSync(expectedJsonPath, JSON.stringify(results, undefined, 2));\n const expectedJson = fs.readJsonSync(expectedJsonPath);\n // @ts-ignore it exists on Jest. for some reason ts assumes this is Jasmine.\n expect(results).toMatchObject(expectedJson);\n });\n });\n describe('getSchemaFromObject', () => {\n it('should be able to deserialize an JSON object to SchemaNode instances', () => {\n const jsonPath = path.join(getMockDir(), 'button-schemas.json');\n const json = fs.readJsonSync(jsonPath);\n const apiSchema = schema.getSchemaFromObject(json);\n expect(apiSchema instanceof APISchema).toBeTruthy();\n expect(apiSchema.componentId instanceof ComponentID).toBeTruthy();\n // @ts-ignore it exists on Jest. for some reason ts assumes this is Jasmine.\n expect(apiSchema.toObject()).toMatchObject(json);\n });\n it('should not throw when it does not recognize the schema', () => {\n const jsonPath = path.join(getMockDir(), 'button-old-schema.json');\n const json = fs.readJsonSync(jsonPath);\n const apiSchema = schema.getSchemaFromObject(json);\n expect(apiSchema instanceof APISchema).toBeTruthy();\n expect(apiSchema.module.exports[0] instanceof UnknownSchema).toBeTruthy();\n // @ts-ignore\n expect(apiSchema.module.exports[0].location).toMatchObject({ file: 'index.ts', line: 21, character: 14 });\n });\n });\n});\n\nfunction getCurrentDir() {\n const currentDir = __dirname;\n if (currentDir.endsWith(`${path.sep}dist`)) return currentDir.slice(0, -5);\n return currentDir;\n}\n\nfunction getMockDir() {\n return path.join(getCurrentDir(), 'mock');\n}\n"],"mappings":";;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEAA,QAAQ,CAAC,cAAc,EAAE,YAAY;EACnC,IAAIC,MAAkB;EACtB,IAAIC,SAAoB;EACxB,IAAIC,aAA4B;EAChCC,SAAS,CAAC,YAAY;IACpBD,aAAa,GAAG,IAAAE,iCAAa,GAAE;IAC/B,MAAM;MAAEC;IAAc,CAAC,GAAGH,aAAa;IACvC;IACAI,OAAO,CAACC,GAAG,CAAC,uBAAuB,EAAEF,aAAa,CAAC;IACnDL,MAAM,GAAG,MAAM,IAAAQ,4BAAU,EAACC,gBAAY,EAAEJ,aAAa,CAAC;EACxD,CAAC,CAAC;EACFK,QAAQ,CAAC,YAAY;IACnB,MAAM,IAAAC,oCAAgB,EAACT,aAAa,CAAC;EACvC,CAAC,CAAC;EACFH,QAAQ,CAAC,aAAa,EAAE,MAAM;IAC5B,IAAIa,SAAoB;IACxBT,SAAS,CAAC,YAAY;MACpB,MAAM;QAAEE;MAAc,CAAC,GAAGH,aAAa;MACvC,MAAMW,OAAO,GAAGC,eAAI,CAACC,IAAI,CAACV,aAAa,EAAE,QAAQ,CAAC;MAClD,MAAMW,GAAG,GAAGF,eAAI,CAACC,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