@teambit/schema 0.0.885 → 0.0.887
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/index.d.ts +1 -0
- package/dist/index.js +39 -2
- package/dist/index.js.map +1 -1
- package/dist/mock/button-schemas.json +43 -3
- package/dist/schema.main.runtime.d.ts +14 -2
- package/dist/schema.main.runtime.js +60 -9
- package/dist/schema.main.runtime.js.map +1 -1
- package/dist/schema.task.d.ts +20 -0
- package/dist/schema.task.js +112 -0
- package/dist/schema.task.js.map +1 -0
- package/mock/button-schemas.json +43 -3
- package/package-tar/teambit-schema-0.0.887.tgz +0 -0
- package/package.json +16 -16
- package/{preview-1666755696699.js → preview-1667014802517.js} +3 -3
- package/dist/schema-extract.task.d.ts +0 -8
- package/dist/schema-extract.task.js +0 -27
- package/dist/schema-extract.task.js.map +0 -1
- package/package-tar/teambit-schema-0.0.885.tgz +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { Parser } from './parser';
|
|
2
2
|
export { SchemaExtractor } from './schema-extractor';
|
|
3
|
+
export { SchemaTask, SCHEMA_ARTIFACT_NAME, SCHEMA_TASK_NAME, getSchemaArtifactDef, getSchemaArtifactPath, } from './schema.task';
|
|
3
4
|
export type { SchemaMain } from './schema.main.runtime';
|
|
4
5
|
export { SchemaAspect } from './schema.aspect';
|
package/dist/index.js
CHANGED
|
@@ -9,10 +9,22 @@ Object.defineProperty(exports, "Parser", {
|
|
|
9
9
|
return _parser().Parser;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "SCHEMA_ARTIFACT_NAME", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _schema().SCHEMA_ARTIFACT_NAME;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "SCHEMA_TASK_NAME", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _schema().SCHEMA_TASK_NAME;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
12
24
|
Object.defineProperty(exports, "SchemaAspect", {
|
|
13
25
|
enumerable: true,
|
|
14
26
|
get: function () {
|
|
15
|
-
return
|
|
27
|
+
return _schema2().SchemaAspect;
|
|
16
28
|
}
|
|
17
29
|
});
|
|
18
30
|
Object.defineProperty(exports, "SchemaExtractor", {
|
|
@@ -21,6 +33,24 @@ Object.defineProperty(exports, "SchemaExtractor", {
|
|
|
21
33
|
return _schemaExtractor().SchemaExtractor;
|
|
22
34
|
}
|
|
23
35
|
});
|
|
36
|
+
Object.defineProperty(exports, "SchemaTask", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _schema().SchemaTask;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "getSchemaArtifactDef", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _schema().getSchemaArtifactDef;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "getSchemaArtifactPath", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _schema().getSchemaArtifactPath;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
24
54
|
function _parser() {
|
|
25
55
|
const data = require("./parser");
|
|
26
56
|
_parser = function () {
|
|
@@ -36,11 +66,18 @@ function _schemaExtractor() {
|
|
|
36
66
|
return data;
|
|
37
67
|
}
|
|
38
68
|
function _schema() {
|
|
39
|
-
const data = require("./schema.
|
|
69
|
+
const data = require("./schema.task");
|
|
40
70
|
_schema = function () {
|
|
41
71
|
return data;
|
|
42
72
|
};
|
|
43
73
|
return data;
|
|
44
74
|
}
|
|
75
|
+
function _schema2() {
|
|
76
|
+
const data = require("./schema.aspect");
|
|
77
|
+
_schema2 = function () {
|
|
78
|
+
return data;
|
|
79
|
+
};
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
45
82
|
|
|
46
83
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { Parser } from './parser';\nexport { SchemaExtractor } from './schema-extractor';\nexport type { SchemaMain } from './schema.main.runtime';\nexport { SchemaAspect } from './schema.aspect';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { Parser } from './parser';\nexport { SchemaExtractor } from './schema-extractor';\nexport {\n SchemaTask,\n SCHEMA_ARTIFACT_NAME,\n SCHEMA_TASK_NAME,\n getSchemaArtifactDef,\n getSchemaArtifactPath,\n} from './schema.task';\nexport type { SchemaMain } from './schema.main.runtime';\nexport { SchemaAspect } from './schema.aspect';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAQA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
|
|
@@ -220,7 +220,7 @@
|
|
|
220
220
|
"character": 3
|
|
221
221
|
},
|
|
222
222
|
"name": "children",
|
|
223
|
-
"signature": "(property) children:
|
|
223
|
+
"signature": "(property) children: ReactNode",
|
|
224
224
|
"isOptional": false,
|
|
225
225
|
"type": {
|
|
226
226
|
"__schema": "InferenceTypeSchema",
|
|
@@ -230,6 +230,16 @@
|
|
|
230
230
|
"character": 13
|
|
231
231
|
},
|
|
232
232
|
"name": "ReactNode"
|
|
233
|
+
},
|
|
234
|
+
"doc": {
|
|
235
|
+
"__schema": "DocSchema",
|
|
236
|
+
"location": {
|
|
237
|
+
"filePath": "button.tsx",
|
|
238
|
+
"line": 10,
|
|
239
|
+
"character": 3
|
|
240
|
+
},
|
|
241
|
+
"raw": "/**\n * children of the Button.\n */",
|
|
242
|
+
"comment": "children of the Button."
|
|
233
243
|
}
|
|
234
244
|
},
|
|
235
245
|
{
|
|
@@ -250,6 +260,16 @@
|
|
|
250
260
|
"character": 10
|
|
251
261
|
},
|
|
252
262
|
"name": "string"
|
|
263
|
+
},
|
|
264
|
+
"doc": {
|
|
265
|
+
"__schema": "DocSchema",
|
|
266
|
+
"location": {
|
|
267
|
+
"filePath": "button.tsx",
|
|
268
|
+
"line": 15,
|
|
269
|
+
"character": 3
|
|
270
|
+
},
|
|
271
|
+
"raw": "/**\n * link to target page. once href is used, Button is considered an A tag.\n */",
|
|
272
|
+
"comment": "link to target page. once href is used, Button is considered an A tag."
|
|
253
273
|
}
|
|
254
274
|
},
|
|
255
275
|
{
|
|
@@ -270,6 +290,16 @@
|
|
|
270
290
|
"character": 15
|
|
271
291
|
},
|
|
272
292
|
"name": "string"
|
|
293
|
+
},
|
|
294
|
+
"doc": {
|
|
295
|
+
"__schema": "DocSchema",
|
|
296
|
+
"location": {
|
|
297
|
+
"filePath": "button.tsx",
|
|
298
|
+
"line": 20,
|
|
299
|
+
"character": 3
|
|
300
|
+
},
|
|
301
|
+
"raw": "/**\n * class names to inject.\n */",
|
|
302
|
+
"comment": "class names to inject."
|
|
273
303
|
}
|
|
274
304
|
}
|
|
275
305
|
]
|
|
@@ -732,7 +762,7 @@
|
|
|
732
762
|
"character": 3
|
|
733
763
|
},
|
|
734
764
|
"name": "getter",
|
|
735
|
-
"signature": "(
|
|
765
|
+
"signature": "(getter) ClassSomething.getter: string",
|
|
736
766
|
"type": {
|
|
737
767
|
"__schema": "InferenceTypeSchema",
|
|
738
768
|
"location": {
|
|
@@ -751,7 +781,7 @@
|
|
|
751
781
|
"character": 3
|
|
752
782
|
},
|
|
753
783
|
"name": "setter",
|
|
754
|
-
"signature": "(
|
|
784
|
+
"signature": "(setter) ClassSomething.setter: boolean",
|
|
755
785
|
"param": {
|
|
756
786
|
"__schema": "ParameterSchema",
|
|
757
787
|
"location": {
|
|
@@ -1716,6 +1746,16 @@
|
|
|
1716
1746
|
"type": "(type parameter) N in type If<T, U, Y, N>",
|
|
1717
1747
|
"name": "N"
|
|
1718
1748
|
}
|
|
1749
|
+
},
|
|
1750
|
+
"doc": {
|
|
1751
|
+
"__schema": "DocSchema",
|
|
1752
|
+
"location": {
|
|
1753
|
+
"filePath": "index.ts",
|
|
1754
|
+
"line": 124,
|
|
1755
|
+
"character": 1
|
|
1756
|
+
},
|
|
1757
|
+
"raw": "/**\n * Conditional Generic Type\n */",
|
|
1758
|
+
"comment": "Conditional Generic Type"
|
|
1719
1759
|
}
|
|
1720
1760
|
}
|
|
1721
1761
|
]
|
|
@@ -5,6 +5,8 @@ import { GraphqlMain } from '@teambit/graphql';
|
|
|
5
5
|
import { EnvsMain } from '@teambit/envs';
|
|
6
6
|
import { Logger, LoggerMain } from '@teambit/logger';
|
|
7
7
|
import { APISchema, Export } from '@teambit/semantics.entities.semantic-schema';
|
|
8
|
+
import { BuilderMain } from '@teambit/builder';
|
|
9
|
+
import { Workspace } from '@teambit/workspace';
|
|
8
10
|
import { Parser } from './parser';
|
|
9
11
|
import { SchemaExtractor } from './schema-extractor';
|
|
10
12
|
export declare type ParserSlot = SlotRegistry<Parser>;
|
|
@@ -24,12 +26,14 @@ export declare class SchemaMain {
|
|
|
24
26
|
private parserSlot;
|
|
25
27
|
private envs;
|
|
26
28
|
private config;
|
|
29
|
+
private builder;
|
|
30
|
+
private workspace;
|
|
27
31
|
private logger;
|
|
28
32
|
constructor(
|
|
29
33
|
/**
|
|
30
34
|
* parsers slot.
|
|
31
35
|
*/
|
|
32
|
-
parserSlot: ParserSlot, envs: EnvsMain, config: SchemaConfig, logger: Logger);
|
|
36
|
+
parserSlot: ParserSlot, envs: EnvsMain, config: SchemaConfig, builder: BuilderMain, workspace: Workspace, logger: Logger);
|
|
33
37
|
/**
|
|
34
38
|
* get the default parser.
|
|
35
39
|
*/
|
|
@@ -55,6 +59,14 @@ export declare class SchemaMain {
|
|
|
55
59
|
static defaultConfig: {
|
|
56
60
|
defaultParser: string;
|
|
57
61
|
};
|
|
58
|
-
static provider([envs, cli, component, graphql, loggerMain
|
|
62
|
+
static provider([envs, cli, component, graphql, loggerMain, builder, workspace]: [
|
|
63
|
+
EnvsMain,
|
|
64
|
+
CLIMain,
|
|
65
|
+
ComponentMain,
|
|
66
|
+
GraphqlMain,
|
|
67
|
+
LoggerMain,
|
|
68
|
+
BuilderMain,
|
|
69
|
+
Workspace
|
|
70
|
+
], config: SchemaConfig, [parserSlot]: [ParserSlot]): Promise<SchemaMain>;
|
|
59
71
|
}
|
|
60
72
|
export default SchemaMain;
|
|
@@ -64,6 +64,20 @@ function _semanticsEntities() {
|
|
|
64
64
|
};
|
|
65
65
|
return data;
|
|
66
66
|
}
|
|
67
|
+
function _builder() {
|
|
68
|
+
const data = require("@teambit/builder");
|
|
69
|
+
_builder = function () {
|
|
70
|
+
return data;
|
|
71
|
+
};
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
74
|
+
function _workspace() {
|
|
75
|
+
const data = require("@teambit/workspace");
|
|
76
|
+
_workspace = function () {
|
|
77
|
+
return data;
|
|
78
|
+
};
|
|
79
|
+
return data;
|
|
80
|
+
}
|
|
67
81
|
function _schema() {
|
|
68
82
|
const data = require("./schema.aspect");
|
|
69
83
|
_schema = function () {
|
|
@@ -85,6 +99,13 @@ function _schema3() {
|
|
|
85
99
|
};
|
|
86
100
|
return data;
|
|
87
101
|
}
|
|
102
|
+
function _schema4() {
|
|
103
|
+
const data = require("./schema.task");
|
|
104
|
+
_schema4 = function () {
|
|
105
|
+
return data;
|
|
106
|
+
};
|
|
107
|
+
return data;
|
|
108
|
+
}
|
|
88
109
|
/**
|
|
89
110
|
* extension for extracting component schemas.
|
|
90
111
|
*/
|
|
@@ -93,10 +114,12 @@ class SchemaMain {
|
|
|
93
114
|
/**
|
|
94
115
|
* parsers slot.
|
|
95
116
|
*/
|
|
96
|
-
parserSlot, envs, config, logger) {
|
|
117
|
+
parserSlot, envs, config, builder, workspace, logger) {
|
|
97
118
|
this.parserSlot = parserSlot;
|
|
98
119
|
this.envs = envs;
|
|
99
120
|
this.config = config;
|
|
121
|
+
this.builder = builder;
|
|
122
|
+
this.workspace = workspace;
|
|
100
123
|
this.logger = logger;
|
|
101
124
|
}
|
|
102
125
|
|
|
@@ -136,12 +159,38 @@ class SchemaMain {
|
|
|
136
159
|
*/
|
|
137
160
|
async getSchema(component) {
|
|
138
161
|
this.logger.debug(`getSchema of ${component.id.toString()}`);
|
|
139
|
-
|
|
140
|
-
if
|
|
141
|
-
|
|
162
|
+
|
|
163
|
+
// if on workspace get schema from ts server
|
|
164
|
+
if (this.workspace) {
|
|
165
|
+
const env = this.envs.getEnv(component).env;
|
|
166
|
+
if (typeof env.getSchemaExtractor === 'undefined') {
|
|
167
|
+
throw new Error(`No SchemaExtractor defined for ${env.name}`);
|
|
168
|
+
}
|
|
169
|
+
const schemaExtractor = env.getSchemaExtractor();
|
|
170
|
+
return schemaExtractor.extract(component);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// on scope get schema from builder api
|
|
174
|
+
const schemaArtifact = await this.builder.getArtifactsVinylByAspectAndTaskName(component, _schema().SchemaAspect.id, _schema4().SCHEMA_TASK_NAME);
|
|
175
|
+
if (schemaArtifact.length === 0) {
|
|
176
|
+
/**
|
|
177
|
+
* return empty schema
|
|
178
|
+
* when tag/snap without build
|
|
179
|
+
* or backwards compatibility
|
|
180
|
+
*/
|
|
181
|
+
return _semanticsEntities().APISchema.empty(component.id);
|
|
182
|
+
}
|
|
183
|
+
const schemaJsonStr = schemaArtifact[0].contents.toString('utf-8');
|
|
184
|
+
try {
|
|
185
|
+
const schemaJson = JSON.parse(schemaJsonStr);
|
|
186
|
+
return this.getSchemaFromObject(schemaJson);
|
|
187
|
+
} catch (e) {
|
|
188
|
+
if (e instanceof SyntaxError) {
|
|
189
|
+
this.logger.error(e.message);
|
|
190
|
+
throw new Error(`Invalid schema.json for ${component.id}`);
|
|
191
|
+
}
|
|
192
|
+
throw e;
|
|
142
193
|
}
|
|
143
|
-
const schemaExtractor = env.getSchemaExtractor();
|
|
144
|
-
return schemaExtractor.extract(component);
|
|
145
194
|
}
|
|
146
195
|
getSchemaFromObject(obj) {
|
|
147
196
|
return _semanticsEntities().APISchema.fromObject(obj);
|
|
@@ -154,9 +203,11 @@ class SchemaMain {
|
|
|
154
203
|
this.parserSlot.register(parser);
|
|
155
204
|
return this;
|
|
156
205
|
}
|
|
157
|
-
static async provider([envs, cli, component, graphql, loggerMain], config, [parserSlot]) {
|
|
206
|
+
static async provider([envs, cli, component, graphql, loggerMain, builder, workspace], config, [parserSlot]) {
|
|
158
207
|
const logger = loggerMain.createLogger(_schema().SchemaAspect.id);
|
|
159
|
-
const schema = new SchemaMain(parserSlot, envs, config, logger);
|
|
208
|
+
const schema = new SchemaMain(parserSlot, envs, config, builder, workspace, logger);
|
|
209
|
+
const schemaTask = new (_schema4().SchemaTask)(_schema().SchemaAspect.id, schema, logger);
|
|
210
|
+
builder.registerBuildTasks([schemaTask]);
|
|
160
211
|
cli.register(new (_schema2().SchemaCommand)(schema, component, logger));
|
|
161
212
|
graphql.register((0, _schema3().schemaSchema)(schema));
|
|
162
213
|
|
|
@@ -170,7 +221,7 @@ class SchemaMain {
|
|
|
170
221
|
}
|
|
171
222
|
exports.SchemaMain = SchemaMain;
|
|
172
223
|
(0, _defineProperty2().default)(SchemaMain, "runtime", _cli().MainRuntime);
|
|
173
|
-
(0, _defineProperty2().default)(SchemaMain, "dependencies", [_envs().EnvsAspect, _cli().CLIAspect, _component().default, _graphql().default, _logger().LoggerAspect]);
|
|
224
|
+
(0, _defineProperty2().default)(SchemaMain, "dependencies", [_envs().EnvsAspect, _cli().CLIAspect, _component().default, _graphql().default, _logger().LoggerAspect, _builder().BuilderAspect, _workspace().WorkspaceAspect]);
|
|
174
225
|
(0, _defineProperty2().default)(SchemaMain, "slots", [_harmony().Slot.withType()]);
|
|
175
226
|
(0, _defineProperty2().default)(SchemaMain, "defaultConfig", {
|
|
176
227
|
defaultParser: 'teambit.typescript/typescript'
|
|
@@ -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":";;;;;;;;;;;;;;;;;AAA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,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"}
|
|
1
|
+
{"version":3,"names":["SchemaMain","constructor","parserSlot","envs","config","builder","workspace","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","schemaArtifact","getArtifactsVinylByAspectAndTaskName","SchemaAspect","SCHEMA_TASK_NAME","length","APISchema","empty","schemaJsonStr","contents","schemaJson","JSON","parse","getSchemaFromObject","e","SyntaxError","error","message","obj","fromObject","registerParser","register","provider","cli","graphql","loggerMain","createLogger","schema","schemaTask","SchemaTask","registerBuildTasks","SchemaCommand","schemaSchema","MainRuntime","EnvsAspect","CLIAspect","ComponentAspect","GraphqlAspect","LoggerAspect","BuilderAspect","WorkspaceAspect","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 { BuilderMain, BuilderAspect } from '@teambit/builder';\nimport { Workspace, WorkspaceAspect } from '@teambit/workspace';\nimport { Parser } from './parser';\nimport { SchemaAspect } from './schema.aspect';\nimport { SchemaExtractor } from './schema-extractor';\nimport { SchemaCommand } from './schema.cmd';\nimport { schemaSchema } from './schema.graphql';\nimport { SchemaTask, SCHEMA_TASK_NAME } from './schema.task';\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 builder: BuilderMain,\n\n private workspace: Workspace,\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\n // if on workspace get schema from ts server\n if (this.workspace) {\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 // on scope get schema from builder api\n const schemaArtifact = await this.builder.getArtifactsVinylByAspectAndTaskName(\n component,\n SchemaAspect.id,\n SCHEMA_TASK_NAME\n );\n\n if (schemaArtifact.length === 0) {\n /**\n * return empty schema\n * when tag/snap without build\n * or backwards compatibility\n */\n return APISchema.empty(component.id);\n }\n\n const schemaJsonStr = schemaArtifact[0].contents.toString('utf-8');\n\n try {\n const schemaJson = JSON.parse(schemaJsonStr);\n return this.getSchemaFromObject(schemaJson);\n } catch (e) {\n if (e instanceof SyntaxError) {\n this.logger.error(e.message);\n throw new Error(`Invalid schema.json for ${component.id}`);\n }\n throw e;\n }\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 = [\n EnvsAspect,\n CLIAspect,\n ComponentAspect,\n GraphqlAspect,\n LoggerAspect,\n BuilderAspect,\n WorkspaceAspect,\n ];\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, builder, workspace]: [\n EnvsMain,\n CLIMain,\n ComponentMain,\n GraphqlMain,\n LoggerMain,\n BuilderMain,\n Workspace\n ],\n config: SchemaConfig,\n [parserSlot]: [ParserSlot]\n ) {\n const logger = loggerMain.createLogger(SchemaAspect.id);\n const schema = new SchemaMain(parserSlot, envs, config, builder, workspace, logger);\n const schemaTask = new SchemaTask(SchemaAspect.id, schema, logger);\n builder.registerBuildTasks([schemaTask]);\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":";;;;;;;;;;;;;;;;;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;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAWA;AACA;AACA;AACO,MAAMA,UAAU,CAAC;EACtBC,WAAW;EACT;AACJ;AACA;EACYC,UAAsB,EAEtBC,IAAc,EAEdC,MAAoB,EAEpBC,OAAoB,EAEpBC,SAAoB,EAEpBC,MAAc,EACtB;IAAA,KAXQL,UAAsB,GAAtBA,UAAsB;IAAA,KAEtBC,IAAc,GAAdA,IAAc;IAAA,KAEdC,MAAoB,GAApBA,MAAoB;IAAA,KAEpBC,OAAoB,GAApBA,OAAoB;IAAA,KA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,UAAU;AAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BuildContext, BuiltTaskResult, BuildTask, TaskLocation, ArtifactDefinition } from '@teambit/builder';
|
|
2
|
+
import { Logger } from '@teambit/logger';
|
|
3
|
+
import { SchemaMain } from './schema.main.runtime';
|
|
4
|
+
export declare const SCHEMA_TASK_NAME = "ExtractSchema";
|
|
5
|
+
export declare const SCHEMA_ARTIFACT_NAME = "schema";
|
|
6
|
+
/**
|
|
7
|
+
* extract and persist the component schema as a json file
|
|
8
|
+
*/
|
|
9
|
+
export declare class SchemaTask implements BuildTask {
|
|
10
|
+
readonly aspectId: string;
|
|
11
|
+
private schema;
|
|
12
|
+
private logger;
|
|
13
|
+
readonly name = "ExtractSchema";
|
|
14
|
+
readonly location: TaskLocation;
|
|
15
|
+
readonly description = "extract api schema for a set of components";
|
|
16
|
+
constructor(aspectId: string, schema: SchemaMain, logger: Logger);
|
|
17
|
+
execute(context: BuildContext): Promise<BuiltTaskResult>;
|
|
18
|
+
}
|
|
19
|
+
export declare function getSchemaArtifactPath(): string;
|
|
20
|
+
export declare function getSchemaArtifactDef(): ArtifactDefinition;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
require("core-js/modules/es.promise.js");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.SchemaTask = exports.SCHEMA_TASK_NAME = exports.SCHEMA_ARTIFACT_NAME = void 0;
|
|
9
|
+
exports.getSchemaArtifactDef = getSchemaArtifactDef;
|
|
10
|
+
exports.getSchemaArtifactPath = getSchemaArtifactPath;
|
|
11
|
+
function _defineProperty2() {
|
|
12
|
+
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
_defineProperty2 = function () {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
function _builder() {
|
|
19
|
+
const data = require("@teambit/builder");
|
|
20
|
+
_builder = function () {
|
|
21
|
+
return data;
|
|
22
|
+
};
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
function _fsExtra() {
|
|
26
|
+
const data = _interopRequireDefault(require("fs-extra"));
|
|
27
|
+
_fsExtra = function () {
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
function _pMapSeries() {
|
|
33
|
+
const data = _interopRequireDefault(require("p-map-series"));
|
|
34
|
+
_pMapSeries = function () {
|
|
35
|
+
return data;
|
|
36
|
+
};
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
function _path() {
|
|
40
|
+
const data = require("path");
|
|
41
|
+
_path = function () {
|
|
42
|
+
return data;
|
|
43
|
+
};
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
const SCHEMA_TASK_NAME = 'ExtractSchema';
|
|
47
|
+
exports.SCHEMA_TASK_NAME = SCHEMA_TASK_NAME;
|
|
48
|
+
const SCHEMA_ARTIFACT_NAME = 'schema';
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* extract and persist the component schema as a json file
|
|
52
|
+
*/
|
|
53
|
+
exports.SCHEMA_ARTIFACT_NAME = SCHEMA_ARTIFACT_NAME;
|
|
54
|
+
class SchemaTask {
|
|
55
|
+
constructor(aspectId, schema, logger) {
|
|
56
|
+
this.aspectId = aspectId;
|
|
57
|
+
this.schema = schema;
|
|
58
|
+
this.logger = logger;
|
|
59
|
+
(0, _defineProperty2().default)(this, "name", SCHEMA_TASK_NAME);
|
|
60
|
+
(0, _defineProperty2().default)(this, "location", 'end');
|
|
61
|
+
(0, _defineProperty2().default)(this, "description", 'extract api schema for a set of components');
|
|
62
|
+
}
|
|
63
|
+
async execute(context) {
|
|
64
|
+
const startTime = Date.now();
|
|
65
|
+
const capsules = context.capsuleNetwork.seedersCapsules;
|
|
66
|
+
const schemaResult = [];
|
|
67
|
+
// persist schema json
|
|
68
|
+
await (0, _pMapSeries().default)(capsules, async capsule => {
|
|
69
|
+
const component = capsule.component;
|
|
70
|
+
try {
|
|
71
|
+
const schema = await this.schema.getSchema(component);
|
|
72
|
+
const schemaObj = schema.toObject();
|
|
73
|
+
await _fsExtra().default.outputFile((0, _path().join)(capsule.path, getSchemaArtifactPath()), JSON.stringify(schemaObj, null, 2));
|
|
74
|
+
schemaResult.push({
|
|
75
|
+
component,
|
|
76
|
+
startTime,
|
|
77
|
+
endTime: Date.now()
|
|
78
|
+
});
|
|
79
|
+
} catch (e) {
|
|
80
|
+
/**
|
|
81
|
+
* @todo once schema extractor is more stable change this to an error
|
|
82
|
+
*/
|
|
83
|
+
if (e instanceof Error) {
|
|
84
|
+
schemaResult.push({
|
|
85
|
+
component,
|
|
86
|
+
startTime,
|
|
87
|
+
endTime: Date.now(),
|
|
88
|
+
warnings: [e.message]
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
artifacts: [getSchemaArtifactDef()],
|
|
95
|
+
componentsResults: schemaResult
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.SchemaTask = SchemaTask;
|
|
100
|
+
function getSchemaArtifactPath() {
|
|
101
|
+
return (0, _path().join)(_builder().CAPSULE_ARTIFACTS_DIR, 'schema.json');
|
|
102
|
+
}
|
|
103
|
+
function getSchemaArtifactDef() {
|
|
104
|
+
const def = {
|
|
105
|
+
name: SCHEMA_ARTIFACT_NAME,
|
|
106
|
+
rootDir: _builder().CAPSULE_ARTIFACTS_DIR,
|
|
107
|
+
globPatterns: ['schema.json']
|
|
108
|
+
};
|
|
109
|
+
return def;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=schema.task.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SCHEMA_TASK_NAME","SCHEMA_ARTIFACT_NAME","SchemaTask","constructor","aspectId","schema","logger","execute","context","startTime","Date","now","capsules","capsuleNetwork","seedersCapsules","schemaResult","pMapSeries","capsule","component","getSchema","schemaObj","toObject","fs","outputFile","join","path","getSchemaArtifactPath","JSON","stringify","push","endTime","e","Error","warnings","message","artifacts","getSchemaArtifactDef","componentsResults","CAPSULE_ARTIFACTS_DIR","def","name","rootDir","globPatterns"],"sources":["schema.task.ts"],"sourcesContent":["import {\n BuildContext,\n BuiltTaskResult,\n BuildTask,\n TaskLocation,\n CAPSULE_ARTIFACTS_DIR,\n ComponentResult,\n ArtifactDefinition,\n} from '@teambit/builder';\nimport { Logger } from '@teambit/logger';\nimport fs from 'fs-extra';\nimport pMapSeries from 'p-map-series';\nimport { join } from 'path';\nimport { SchemaMain } from './schema.main.runtime';\n\nexport const SCHEMA_TASK_NAME = 'ExtractSchema';\nexport const SCHEMA_ARTIFACT_NAME = 'schema';\n\n/**\n * extract and persist the component schema as a json file\n */\nexport class SchemaTask implements BuildTask {\n readonly name = SCHEMA_TASK_NAME;\n readonly location: TaskLocation = 'end';\n readonly description = 'extract api schema for a set of components';\n\n constructor(readonly aspectId: string, private schema: SchemaMain, private logger: Logger) {}\n\n async execute(context: BuildContext): Promise<BuiltTaskResult> {\n const startTime = Date.now();\n const capsules = context.capsuleNetwork.seedersCapsules;\n const schemaResult: ComponentResult[] = [];\n // persist schema json\n await pMapSeries(capsules, async (capsule) => {\n const component = capsule.component;\n try {\n const schema = await this.schema.getSchema(component);\n const schemaObj = schema.toObject();\n await fs.outputFile(join(capsule.path, getSchemaArtifactPath()), JSON.stringify(schemaObj, null, 2));\n schemaResult.push({\n component,\n startTime,\n endTime: Date.now(),\n });\n } catch (e) {\n /**\n * @todo once schema extractor is more stable change this to an error\n */\n if (e instanceof Error) {\n schemaResult.push({\n component,\n startTime,\n endTime: Date.now(),\n warnings: [e.message],\n });\n }\n }\n });\n return {\n artifacts: [getSchemaArtifactDef()],\n componentsResults: schemaResult,\n };\n }\n}\n\nexport function getSchemaArtifactPath() {\n return join(CAPSULE_ARTIFACTS_DIR, 'schema.json');\n}\n\nexport function getSchemaArtifactDef() {\n const def: ArtifactDefinition = {\n name: SCHEMA_ARTIFACT_NAME,\n rootDir: CAPSULE_ARTIFACTS_DIR,\n globPatterns: ['schema.json'],\n };\n\n return def;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAUA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGO,MAAMA,gBAAgB,GAAG,eAAe;AAAC;AACzC,MAAMC,oBAAoB,GAAG,QAAQ;;AAE5C;AACA;AACA;AAFA;AAGO,MAAMC,UAAU,CAAsB;EAK3CC,WAAW,CAAUC,QAAgB,EAAUC,MAAkB,EAAUC,MAAc,EAAE;IAAA,KAAtEF,QAAgB,GAAhBA,QAAgB;IAAA,KAAUC,MAAkB,GAAlBA,MAAkB;IAAA,KAAUC,MAAc,GAAdA,MAAc;IAAA,8CAJzEN,gBAAgB;IAAA,kDACE,KAAK;IAAA,qDAChB,4CAA4C;EAEyB;EAE5F,MAAMO,OAAO,CAACC,OAAqB,EAA4B;IAC7D,MAAMC,SAAS,GAAGC,IAAI,CAACC,GAAG,EAAE;IAC5B,MAAMC,QAAQ,GAAGJ,OAAO,CAACK,cAAc,CAACC,eAAe;IACvD,MAAMC,YAA+B,GAAG,EAAE;IAC1C;IACA,MAAM,IAAAC,qBAAU,EAACJ,QAAQ,EAAE,MAAOK,OAAO,IAAK;MAC5C,MAAMC,SAAS,GAAGD,OAAO,CAACC,SAAS;MACnC,IAAI;QACF,MAAMb,MAAM,GAAG,MAAM,IAAI,CAACA,MAAM,CAACc,SAAS,CAACD,SAAS,CAAC;QACrD,MAAME,SAAS,GAAGf,MAAM,CAACgB,QAAQ,EAAE;QACnC,MAAMC,kBAAE,CAACC,UAAU,CAAC,IAAAC,YAAI,EAACP,OAAO,CAACQ,IAAI,EAAEC,qBAAqB,EAAE,CAAC,EAAEC,IAAI,CAACC,SAAS,CAACR,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACpGL,YAAY,CAACc,IAAI,CAAC;UAChBX,SAAS;UACTT,SAAS;UACTqB,OAAO,EAAEpB,IAAI,CAACC,GAAG;QACnB,CAAC,CAAC;MACJ,CAAC,CAAC,OAAOoB,CAAC,EAAE;QACV;AACR;AACA;QACQ,IAAIA,CAAC,YAAYC,KAAK,EAAE;UACtBjB,YAAY,CAACc,IAAI,CAAC;YAChBX,SAAS;YACTT,SAAS;YACTqB,OAAO,EAAEpB,IAAI,CAACC,GAAG,EAAE;YACnBsB,QAAQ,EAAE,CAACF,CAAC,CAACG,OAAO;UACtB,CAAC,CAAC;QACJ;MACF;IACF,CAAC,CAAC;IACF,OAAO;MACLC,SAAS,EAAE,CAACC,oBAAoB,EAAE,CAAC;MACnCC,iBAAiB,EAAEtB;IACrB,CAAC;EACH;AACF;AAAC;AAEM,SAASW,qBAAqB,GAAG;EACtC,OAAO,IAAAF,YAAI,EAACc,gCAAqB,EAAE,aAAa,CAAC;AACnD;AAEO,SAASF,oBAAoB,GAAG;EACrC,MAAMG,GAAuB,GAAG;IAC9BC,IAAI,EAAEvC,oBAAoB;IAC1BwC,OAAO,EAAEH,gCAAqB;IAC9BI,YAAY,EAAE,CAAC,aAAa;EAC9B,CAAC;EAED,OAAOH,GAAG;AACZ"}
|
package/mock/button-schemas.json
CHANGED
|
@@ -220,7 +220,7 @@
|
|
|
220
220
|
"character": 3
|
|
221
221
|
},
|
|
222
222
|
"name": "children",
|
|
223
|
-
"signature": "(property) children:
|
|
223
|
+
"signature": "(property) children: ReactNode",
|
|
224
224
|
"isOptional": false,
|
|
225
225
|
"type": {
|
|
226
226
|
"__schema": "InferenceTypeSchema",
|
|
@@ -230,6 +230,16 @@
|
|
|
230
230
|
"character": 13
|
|
231
231
|
},
|
|
232
232
|
"name": "ReactNode"
|
|
233
|
+
},
|
|
234
|
+
"doc": {
|
|
235
|
+
"__schema": "DocSchema",
|
|
236
|
+
"location": {
|
|
237
|
+
"filePath": "button.tsx",
|
|
238
|
+
"line": 10,
|
|
239
|
+
"character": 3
|
|
240
|
+
},
|
|
241
|
+
"raw": "/**\n * children of the Button.\n */",
|
|
242
|
+
"comment": "children of the Button."
|
|
233
243
|
}
|
|
234
244
|
},
|
|
235
245
|
{
|
|
@@ -250,6 +260,16 @@
|
|
|
250
260
|
"character": 10
|
|
251
261
|
},
|
|
252
262
|
"name": "string"
|
|
263
|
+
},
|
|
264
|
+
"doc": {
|
|
265
|
+
"__schema": "DocSchema",
|
|
266
|
+
"location": {
|
|
267
|
+
"filePath": "button.tsx",
|
|
268
|
+
"line": 15,
|
|
269
|
+
"character": 3
|
|
270
|
+
},
|
|
271
|
+
"raw": "/**\n * link to target page. once href is used, Button is considered an A tag.\n */",
|
|
272
|
+
"comment": "link to target page. once href is used, Button is considered an A tag."
|
|
253
273
|
}
|
|
254
274
|
},
|
|
255
275
|
{
|
|
@@ -270,6 +290,16 @@
|
|
|
270
290
|
"character": 15
|
|
271
291
|
},
|
|
272
292
|
"name": "string"
|
|
293
|
+
},
|
|
294
|
+
"doc": {
|
|
295
|
+
"__schema": "DocSchema",
|
|
296
|
+
"location": {
|
|
297
|
+
"filePath": "button.tsx",
|
|
298
|
+
"line": 20,
|
|
299
|
+
"character": 3
|
|
300
|
+
},
|
|
301
|
+
"raw": "/**\n * class names to inject.\n */",
|
|
302
|
+
"comment": "class names to inject."
|
|
273
303
|
}
|
|
274
304
|
}
|
|
275
305
|
]
|
|
@@ -732,7 +762,7 @@
|
|
|
732
762
|
"character": 3
|
|
733
763
|
},
|
|
734
764
|
"name": "getter",
|
|
735
|
-
"signature": "(
|
|
765
|
+
"signature": "(getter) ClassSomething.getter: string",
|
|
736
766
|
"type": {
|
|
737
767
|
"__schema": "InferenceTypeSchema",
|
|
738
768
|
"location": {
|
|
@@ -751,7 +781,7 @@
|
|
|
751
781
|
"character": 3
|
|
752
782
|
},
|
|
753
783
|
"name": "setter",
|
|
754
|
-
"signature": "(
|
|
784
|
+
"signature": "(setter) ClassSomething.setter: boolean",
|
|
755
785
|
"param": {
|
|
756
786
|
"__schema": "ParameterSchema",
|
|
757
787
|
"location": {
|
|
@@ -1716,6 +1746,16 @@
|
|
|
1716
1746
|
"type": "(type parameter) N in type If<T, U, Y, N>",
|
|
1717
1747
|
"name": "N"
|
|
1718
1748
|
}
|
|
1749
|
+
},
|
|
1750
|
+
"doc": {
|
|
1751
|
+
"__schema": "DocSchema",
|
|
1752
|
+
"location": {
|
|
1753
|
+
"filePath": "index.ts",
|
|
1754
|
+
"line": 124,
|
|
1755
|
+
"character": 1
|
|
1756
|
+
},
|
|
1757
|
+
"raw": "/**\n * Conditional Generic Type\n */",
|
|
1758
|
+
"comment": "Conditional Generic Type"
|
|
1719
1759
|
}
|
|
1720
1760
|
}
|
|
1721
1761
|
]
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/schema",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.887",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/semantics/schema",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.semantics",
|
|
8
8
|
"name": "schema",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.887"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"p-map-series": "2.1.0",
|
|
13
13
|
"graphql-tag": "2.12.1",
|
|
14
14
|
"graphql-type-json": "0.3.2",
|
|
15
|
-
"
|
|
15
|
+
"fs-extra": "10.0.0",
|
|
16
|
+
"@babel/runtime": "7.20.0",
|
|
16
17
|
"core-js": "^3.0.0",
|
|
17
18
|
"@teambit/harmony": "0.3.3",
|
|
18
19
|
"@teambit/base-react.navigation.link": "2.0.27",
|
|
19
|
-
"@teambit/semantics.entities.semantic-schema": "0.0.
|
|
20
|
-
"@teambit/
|
|
21
|
-
"@teambit/
|
|
22
|
-
"@teambit/
|
|
23
|
-
"@teambit/
|
|
24
|
-
"@teambit/envs": "0.0.
|
|
25
|
-
"@teambit/graphql": "0.0.
|
|
20
|
+
"@teambit/semantics.entities.semantic-schema": "0.0.40",
|
|
21
|
+
"@teambit/component": "0.0.887",
|
|
22
|
+
"@teambit/cli": "0.0.595",
|
|
23
|
+
"@teambit/logger": "0.0.688",
|
|
24
|
+
"@teambit/builder": "0.0.887",
|
|
25
|
+
"@teambit/envs": "0.0.887",
|
|
26
|
+
"@teambit/graphql": "0.0.887",
|
|
27
|
+
"@teambit/workspace": "0.0.887"
|
|
26
28
|
},
|
|
27
29
|
"devDependencies": {
|
|
28
30
|
"@types/react": "^17.0.8",
|
|
29
|
-
"fs-extra": "10.0.0",
|
|
30
31
|
"@types/fs-extra": "9.0.7",
|
|
31
32
|
"@types/mocha": "9.1.0",
|
|
32
33
|
"@types/testing-library__jest-dom": "5.9.5",
|
|
33
34
|
"@types/jest": "^26.0.0",
|
|
34
35
|
"@types/react-dom": "^17.0.5",
|
|
35
36
|
"@types/node": "12.20.4",
|
|
36
|
-
"@teambit/component-id": "0.0.
|
|
37
|
-
"@teambit/harmony.testing.load-aspect": "0.0.
|
|
38
|
-
"@teambit/workspace.testing.mock-workspace": "0.0.
|
|
39
|
-
"@teambit/workspace": "0.0.885"
|
|
37
|
+
"@teambit/component-id": "0.0.419",
|
|
38
|
+
"@teambit/harmony.testing.load-aspect": "0.0.15",
|
|
39
|
+
"@teambit/workspace.testing.mock-workspace": "0.0.14"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@teambit/legacy": "1.0.
|
|
42
|
+
"@teambit/legacy": "1.0.379",
|
|
43
43
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
44
44
|
"react": "^16.8.0 || ^17.0.0"
|
|
45
45
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@0.0.
|
|
2
|
-
import * as compositions_1 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@0.0.
|
|
3
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@0.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@0.0.887/dist/schema.composition.js';
|
|
2
|
+
import * as compositions_1 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@0.0.887/dist/mock/button/button.composition.js';
|
|
3
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@0.0.887/dist/schema.docs.mdx';
|
|
4
4
|
|
|
5
5
|
export const compositions = [compositions_0, compositions_1];
|
|
6
6
|
export const overview = [overview_0];
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BuildTask, BuiltTaskResult } from '@teambit/builder';
|
|
2
|
-
export declare class SchemaExtract implements BuildTask {
|
|
3
|
-
readonly aspectId: string;
|
|
4
|
-
name: string;
|
|
5
|
-
description: string;
|
|
6
|
-
constructor(aspectId: string);
|
|
7
|
-
execute(): Promise<BuiltTaskResult>;
|
|
8
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.SchemaExtract = void 0;
|
|
8
|
-
function _defineProperty2() {
|
|
9
|
-
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
-
_defineProperty2 = function () {
|
|
11
|
-
return data;
|
|
12
|
-
};
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
15
|
-
class SchemaExtract {
|
|
16
|
-
constructor(aspectId) {
|
|
17
|
-
this.aspectId = aspectId;
|
|
18
|
-
(0, _defineProperty2().default)(this, "name", 'schema-extraction');
|
|
19
|
-
(0, _defineProperty2().default)(this, "description", 'extract api schema for a set of components');
|
|
20
|
-
}
|
|
21
|
-
execute() {
|
|
22
|
-
throw new Error('Method not implemented.');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.SchemaExtract = SchemaExtract;
|
|
26
|
-
|
|
27
|
-
//# sourceMappingURL=schema-extract.task.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["SchemaExtract","constructor","aspectId","execute","Error"],"sources":["schema-extract.task.ts"],"sourcesContent":["import { BuildTask, BuiltTaskResult } from '@teambit/builder';\n\nexport class SchemaExtract implements BuildTask {\n name = 'schema-extraction';\n description = 'extract api schema for a set of components';\n\n constructor(readonly aspectId: string) {}\n\n execute(): Promise<BuiltTaskResult> {\n throw new Error('Method not implemented.');\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAEO,MAAMA,aAAa,CAAsB;EAI9CC,WAAW,CAAUC,QAAgB,EAAE;IAAA,KAAlBA,QAAgB,GAAhBA,QAAgB;IAAA,8CAH9B,mBAAmB;IAAA,qDACZ,4CAA4C;EAElB;EAExCC,OAAO,GAA6B;IAClC,MAAM,IAAIC,KAAK,CAAC,yBAAyB,CAAC;EAC5C;AACF;AAAC"}
|
|
Binary file
|