@teambit/semantics.entities.semantic-schema 0.0.0-e4ef0e951da794f03096a5cc407420f4cde8b878
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/api-schema.ts +167 -0
- package/dist/api-schema.d.ts +36 -0
- package/dist/api-schema.js +171 -0
- package/dist/api-schema.js.map +1 -0
- package/dist/export.d.ts +38 -0
- package/dist/export.js +37 -0
- package/dist/export.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +137 -0
- package/dist/index.js.map +1 -0
- package/dist/schema-node-constructor.d.ts +7 -0
- package/dist/schema-node-constructor.js +3 -0
- package/dist/schema-node-constructor.js.map +1 -0
- package/dist/schema-node.d.ts +51 -0
- package/dist/schema-node.js +67 -0
- package/dist/schema-node.js.map +1 -0
- package/dist/schema-registry.d.ts +17 -0
- package/dist/schema-registry.js +63 -0
- package/dist/schema-registry.js.map +1 -0
- package/dist/schemas/array-literal-expression.d.ts +15 -0
- package/dist/schemas/array-literal-expression.js +48 -0
- package/dist/schemas/array-literal-expression.js.map +1 -0
- package/dist/schemas/class.d.ts +59 -0
- package/dist/schemas/class.js +126 -0
- package/dist/schemas/class.js.map +1 -0
- package/dist/schemas/conditional-type.d.ts +25 -0
- package/dist/schemas/conditional-type.js +67 -0
- package/dist/schemas/conditional-type.js.map +1 -0
- package/dist/schemas/constructor.d.ts +9 -0
- package/dist/schemas/constructor.js +51 -0
- package/dist/schemas/constructor.js.map +1 -0
- package/dist/schemas/decorator.d.ts +35 -0
- package/dist/schemas/decorator.js +70 -0
- package/dist/schemas/decorator.js.map +1 -0
- package/dist/schemas/docs/doc.d.ts +30 -0
- package/dist/schemas/docs/doc.js +74 -0
- package/dist/schemas/docs/doc.js.map +1 -0
- package/dist/schemas/docs/index.d.ts +4 -0
- package/dist/schemas/docs/index.js +59 -0
- package/dist/schemas/docs/index.js.map +1 -0
- package/dist/schemas/docs/property-like-tag.d.ts +26 -0
- package/dist/schemas/docs/property-like-tag.js +59 -0
- package/dist/schemas/docs/property-like-tag.js.map +1 -0
- package/dist/schemas/docs/return-tag.d.ts +25 -0
- package/dist/schemas/docs/return-tag.js +55 -0
- package/dist/schemas/docs/return-tag.js.map +1 -0
- package/dist/schemas/docs/tag.d.ts +45 -0
- package/dist/schemas/docs/tag.js +75 -0
- package/dist/schemas/docs/tag.js.map +1 -0
- package/dist/schemas/enum-member.d.ts +36 -0
- package/dist/schemas/enum-member.js +66 -0
- package/dist/schemas/enum-member.js.map +1 -0
- package/dist/schemas/enum.d.ts +37 -0
- package/dist/schemas/enum.js +87 -0
- package/dist/schemas/enum.js.map +1 -0
- package/dist/schemas/export.d.ts +41 -0
- package/dist/schemas/export.js +92 -0
- package/dist/schemas/export.js.map +1 -0
- package/dist/schemas/expression-with-arguments.d.ts +19 -0
- package/dist/schemas/expression-with-arguments.js +59 -0
- package/dist/schemas/expression-with-arguments.js.map +1 -0
- package/dist/schemas/function-like.d.ts +66 -0
- package/dist/schemas/function-like.js +147 -0
- package/dist/schemas/function-like.js.map +1 -0
- package/dist/schemas/get-accessor.d.ts +22 -0
- package/dist/schemas/get-accessor.js +73 -0
- package/dist/schemas/get-accessor.js.map +1 -0
- package/dist/schemas/ignored.d.ts +17 -0
- package/dist/schemas/ignored.js +54 -0
- package/dist/schemas/ignored.js.map +1 -0
- package/dist/schemas/index-signature.d.ts +23 -0
- package/dist/schemas/index-signature.js +65 -0
- package/dist/schemas/index-signature.js.map +1 -0
- package/dist/schemas/index.d.ts +49 -0
- package/dist/schemas/index.js +623 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/indexed-access-type.d.ts +17 -0
- package/dist/schemas/indexed-access-type.js +55 -0
- package/dist/schemas/indexed-access-type.js.map +1 -0
- package/dist/schemas/inference-type.d.ts +22 -0
- package/dist/schemas/inference-type.js +65 -0
- package/dist/schemas/inference-type.js.map +1 -0
- package/dist/schemas/interface.d.ts +49 -0
- package/dist/schemas/interface.js +108 -0
- package/dist/schemas/interface.js.map +1 -0
- package/dist/schemas/keyword-type.d.ts +15 -0
- package/dist/schemas/keyword-type.js +43 -0
- package/dist/schemas/keyword-type.js.map +1 -0
- package/dist/schemas/literal-type.d.ts +15 -0
- package/dist/schemas/literal-type.js +43 -0
- package/dist/schemas/literal-type.js.map +1 -0
- package/dist/schemas/literal-value.d.ts +12 -0
- package/dist/schemas/literal-value.js +41 -0
- package/dist/schemas/literal-value.js.map +1 -0
- package/dist/schemas/module.d.ts +22 -0
- package/dist/schemas/module.js +87 -0
- package/dist/schemas/module.js.map +1 -0
- package/dist/schemas/named-tuple.d.ts +19 -0
- package/dist/schemas/named-tuple.js +53 -0
- package/dist/schemas/named-tuple.js.map +1 -0
- package/dist/schemas/object-literal-expression.d.ts +18 -0
- package/dist/schemas/object-literal-expression.js +52 -0
- package/dist/schemas/object-literal-expression.js.map +1 -0
- package/dist/schemas/parameter.d.ts +27 -0
- package/dist/schemas/parameter.js +95 -0
- package/dist/schemas/parameter.js.map +1 -0
- package/dist/schemas/parenthesized-type.d.ts +21 -0
- package/dist/schemas/parenthesized-type.js +54 -0
- package/dist/schemas/parenthesized-type.js.map +1 -0
- package/dist/schemas/property-assignment.d.ts +37 -0
- package/dist/schemas/property-assignment.js +67 -0
- package/dist/schemas/property-assignment.js.map +1 -0
- package/dist/schemas/set-accessor.d.ts +28 -0
- package/dist/schemas/set-accessor.js +65 -0
- package/dist/schemas/set-accessor.js.map +1 -0
- package/dist/schemas/template-literal-type-span.d.ts +19 -0
- package/dist/schemas/template-literal-type-span.js +53 -0
- package/dist/schemas/template-literal-type-span.js.map +1 -0
- package/dist/schemas/template-literal-type.d.ts +22 -0
- package/dist/schemas/template-literal-type.js +52 -0
- package/dist/schemas/template-literal-type.js.map +1 -0
- package/dist/schemas/this-type.d.ts +12 -0
- package/dist/schemas/this-type.js +37 -0
- package/dist/schemas/this-type.js.map +1 -0
- package/dist/schemas/tuple-type.d.ts +16 -0
- package/dist/schemas/tuple-type.js +47 -0
- package/dist/schemas/tuple-type.js.map +1 -0
- package/dist/schemas/type-array.d.ts +17 -0
- package/dist/schemas/type-array.js +50 -0
- package/dist/schemas/type-array.js.map +1 -0
- package/dist/schemas/type-intersection.d.ts +17 -0
- package/dist/schemas/type-intersection.js +50 -0
- package/dist/schemas/type-intersection.js.map +1 -0
- package/dist/schemas/type-literal.d.ts +18 -0
- package/dist/schemas/type-literal.js +64 -0
- package/dist/schemas/type-literal.js.map +1 -0
- package/dist/schemas/type-operator.d.ts +19 -0
- package/dist/schemas/type-operator.js +53 -0
- package/dist/schemas/type-operator.js.map +1 -0
- package/dist/schemas/type-predicate.d.ts +33 -0
- package/dist/schemas/type-predicate.js +75 -0
- package/dist/schemas/type-predicate.js.map +1 -0
- package/dist/schemas/type-query.d.ts +23 -0
- package/dist/schemas/type-query.js +59 -0
- package/dist/schemas/type-query.js.map +1 -0
- package/dist/schemas/type-ref.d.ts +80 -0
- package/dist/schemas/type-ref.js +159 -0
- package/dist/schemas/type-ref.js.map +1 -0
- package/dist/schemas/type-union.d.ts +17 -0
- package/dist/schemas/type-union.js +56 -0
- package/dist/schemas/type-union.js.map +1 -0
- package/dist/schemas/type.d.ts +23 -0
- package/dist/schemas/type.js +80 -0
- package/dist/schemas/type.js.map +1 -0
- package/dist/schemas/unimplemented-schema.d.ts +14 -0
- package/dist/schemas/unimplemented-schema.js +43 -0
- package/dist/schemas/unimplemented-schema.js.map +1 -0
- package/dist/schemas/unknown-schema.d.ts +18 -0
- package/dist/schemas/unknown-schema.js +47 -0
- package/dist/schemas/unknown-schema.js.map +1 -0
- package/dist/schemas/unresolved-schema.d.ts +14 -0
- package/dist/schemas/unresolved-schema.js +41 -0
- package/dist/schemas/unresolved-schema.js.map +1 -0
- package/dist/schemas/variable-like.d.ts +47 -0
- package/dist/schemas/variable-like.js +95 -0
- package/dist/schemas/variable-like.js.map +1 -0
- package/dist/semantic-schema.docs.md +6 -0
- package/dist/type.d.ts +1 -0
- package/dist/type.js +3 -0
- package/dist/type.js.map +1 -0
- package/dist/unknown-schema-factory.d.ts +4 -0
- package/dist/unknown-schema-factory.js +19 -0
- package/dist/unknown-schema-factory.js.map +1 -0
- package/export.ts +31 -0
- package/index.ts +13 -0
- package/package.json +46 -0
- package/schema-node-constructor.ts +8 -0
- package/schema-node.ts +96 -0
- package/schema-registry.ts +53 -0
- package/schemas/array-literal-expression.ts +33 -0
- package/schemas/class.ts +135 -0
- package/schemas/conditional-type.ts +63 -0
- package/schemas/constructor.ts +28 -0
- package/schemas/decorator.ts +54 -0
- package/schemas/docs/doc.ts +69 -0
- package/schemas/docs/index.ts +4 -0
- package/schemas/docs/property-like-tag.ts +47 -0
- package/schemas/docs/return-tag.ts +44 -0
- package/schemas/docs/tag.ts +66 -0
- package/schemas/enum-member.ts +57 -0
- package/schemas/enum.ts +73 -0
- package/schemas/export.ts +91 -0
- package/schemas/expression-with-arguments.ts +51 -0
- package/schemas/function-like.ts +154 -0
- package/schemas/get-accessor.ts +57 -0
- package/schemas/ignored.ts +43 -0
- package/schemas/index-signature.ts +49 -0
- package/schemas/index.ts +49 -0
- package/schemas/indexed-access-type.ts +47 -0
- package/schemas/inference-type.ts +60 -0
- package/schemas/interface.ts +94 -0
- package/schemas/keyword-type.ts +34 -0
- package/schemas/literal-type.ts +34 -0
- package/schemas/literal-value.ts +32 -0
- package/schemas/module.ts +87 -0
- package/schemas/named-tuple.ts +39 -0
- package/schemas/object-literal-expression.ts +42 -0
- package/schemas/parameter.ts +104 -0
- package/schemas/parenthesized-type.ts +42 -0
- package/schemas/property-assignment.ts +50 -0
- package/schemas/set-accessor.ts +47 -0
- package/schemas/template-literal-type-span.ts +42 -0
- package/schemas/template-literal-type.ts +40 -0
- package/schemas/this-type.ts +27 -0
- package/schemas/tuple-type.ts +35 -0
- package/schemas/type-array.ts +39 -0
- package/schemas/type-intersection.ts +39 -0
- package/schemas/type-literal.ts +60 -0
- package/schemas/type-operator.ts +41 -0
- package/schemas/type-predicate.ts +64 -0
- package/schemas/type-query.ts +49 -0
- package/schemas/type-ref.ts +143 -0
- package/schemas/type-union.ts +41 -0
- package/schemas/type.ts +61 -0
- package/schemas/unimplemented-schema.ts +35 -0
- package/schemas/unknown-schema.ts +38 -0
- package/schemas/unresolved-schema.ts +32 -0
- package/schemas/variable-like.ts +76 -0
- package/semantic-schema.docs.md +6 -0
- package/type.ts +1 -0
- package/types/asset.d.ts +41 -0
- package/types/style.d.ts +42 -0
- package/unknown-schema-factory.ts +10 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UnknownSchema = void 0;
|
|
7
|
+
function _schemaNode() {
|
|
8
|
+
const data = require("../schema-node");
|
|
9
|
+
_schemaNode = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* needed for better backward and forward compatibility.
|
|
16
|
+
* in case a previous version of the semantic-schema had a schema class that doesn't exist anymore, then it'll be
|
|
17
|
+
* wrapped in this class.
|
|
18
|
+
*/
|
|
19
|
+
class UnknownSchema extends _schemaNode().SchemaNode {
|
|
20
|
+
constructor(location, name, schemaObj) {
|
|
21
|
+
super();
|
|
22
|
+
this.location = location;
|
|
23
|
+
this.name = name;
|
|
24
|
+
this.schemaObj = schemaObj;
|
|
25
|
+
}
|
|
26
|
+
toString() {
|
|
27
|
+
return `<<unknown schema ${this.name}>>`;
|
|
28
|
+
}
|
|
29
|
+
toFullSignature() {
|
|
30
|
+
return this.toString();
|
|
31
|
+
}
|
|
32
|
+
toObject() {
|
|
33
|
+
return {
|
|
34
|
+
...super.toObject(),
|
|
35
|
+
schemaObj: this.schemaObj
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
static fromObject(obj) {
|
|
39
|
+
const location = obj.location;
|
|
40
|
+
const name = obj.name;
|
|
41
|
+
const schemaObj = obj.schemaObj;
|
|
42
|
+
return new UnknownSchema(location, name, schemaObj);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.UnknownSchema = UnknownSchema;
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=unknown-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_schemaNode","data","require","UnknownSchema","SchemaNode","constructor","location","name","schemaObj","toString","toFullSignature","toObject","fromObject","obj","exports"],"sources":["unknown-schema.ts"],"sourcesContent":["import { SchemaLocation, SchemaNode } from '../schema-node';\n\n/**\n * needed for better backward and forward compatibility.\n * in case a previous version of the semantic-schema had a schema class that doesn't exist anymore, then it'll be\n * wrapped in this class.\n */\nexport class UnknownSchema extends SchemaNode {\n constructor(\n readonly location: SchemaLocation,\n readonly name: string,\n readonly schemaObj: Record<string, any>\n ) {\n super();\n }\n\n toString() {\n return `<<unknown schema ${this.name}>>`;\n }\n\n toFullSignature(): string {\n return this.toString();\n }\n\n toObject() {\n return {\n ...super.toObject(),\n schemaObj: this.schemaObj,\n };\n }\n\n static fromObject(obj: Record<string, any>): UnknownSchema {\n const location = obj.location;\n const name = obj.name;\n const schemaObj = obj.schemaObj;\n return new UnknownSchema(location, name, schemaObj);\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA;AACA;AACA;AACA;AACA;AACO,MAAME,aAAa,SAASC,wBAAU,CAAC;EAC5CC,WAAWA,CACAC,QAAwB,EACxBC,IAAY,EACZC,SAA8B,EACvC;IACA,KAAK,CAAC,CAAC;IAAC,KAJCF,QAAwB,GAAxBA,QAAwB;IAAA,KACxBC,IAAY,GAAZA,IAAY;IAAA,KACZC,SAA8B,GAA9BA,SAA8B;EAGzC;EAEAC,QAAQA,CAAA,EAAG;IACT,OAAO,oBAAoB,IAAI,CAACF,IAAI,IAAI;EAC1C;EAEAG,eAAeA,CAAA,EAAW;IACxB,OAAO,IAAI,CAACD,QAAQ,CAAC,CAAC;EACxB;EAEAE,QAAQA,CAAA,EAAG;IACT,OAAO;MACL,GAAG,KAAK,CAACA,QAAQ,CAAC,CAAC;MACnBH,SAAS,EAAE,IAAI,CAACA;IAClB,CAAC;EACH;EAEA,OAAOI,UAAUA,CAACC,GAAwB,EAAiB;IACzD,MAAMP,QAAQ,GAAGO,GAAG,CAACP,QAAQ;IAC7B,MAAMC,IAAI,GAAGM,GAAG,CAACN,IAAI;IACrB,MAAMC,SAAS,GAAGK,GAAG,CAACL,SAAS;IAC/B,OAAO,IAAIL,aAAa,CAACG,QAAQ,EAAEC,IAAI,EAAEC,SAAS,CAAC;EACrD;AACF;AAACM,OAAA,CAAAX,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SchemaLocation, SchemaNode } from '../schema-node';
|
|
2
|
+
/**
|
|
3
|
+
* needed for cases when the exported entity could not be resolved.
|
|
4
|
+
* e.g. exporting mdx variables in the main index.ts file.
|
|
5
|
+
*/
|
|
6
|
+
export declare class UnresolvedSchema extends SchemaNode {
|
|
7
|
+
readonly location: SchemaLocation;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
constructor(location: SchemaLocation, name: string);
|
|
10
|
+
toString(): string;
|
|
11
|
+
toFullSignature(): string;
|
|
12
|
+
toObject(): Record<string, any>;
|
|
13
|
+
static fromObject(obj: Record<string, any>): UnresolvedSchema;
|
|
14
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UnresolvedSchema = void 0;
|
|
7
|
+
function _schemaNode() {
|
|
8
|
+
const data = require("../schema-node");
|
|
9
|
+
_schemaNode = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* needed for cases when the exported entity could not be resolved.
|
|
16
|
+
* e.g. exporting mdx variables in the main index.ts file.
|
|
17
|
+
*/
|
|
18
|
+
class UnresolvedSchema extends _schemaNode().SchemaNode {
|
|
19
|
+
constructor(location, name) {
|
|
20
|
+
super();
|
|
21
|
+
this.location = location;
|
|
22
|
+
this.name = name;
|
|
23
|
+
}
|
|
24
|
+
toString() {
|
|
25
|
+
return this.name;
|
|
26
|
+
}
|
|
27
|
+
toFullSignature() {
|
|
28
|
+
return this.toString();
|
|
29
|
+
}
|
|
30
|
+
toObject() {
|
|
31
|
+
return super.toObject();
|
|
32
|
+
}
|
|
33
|
+
static fromObject(obj) {
|
|
34
|
+
const location = obj.location;
|
|
35
|
+
const name = obj.name;
|
|
36
|
+
return new UnresolvedSchema(location, name);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.UnresolvedSchema = UnresolvedSchema;
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=unresolved-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_schemaNode","data","require","UnresolvedSchema","SchemaNode","constructor","location","name","toString","toFullSignature","toObject","fromObject","obj","exports"],"sources":["unresolved-schema.ts"],"sourcesContent":["import { SchemaLocation, SchemaNode } from '../schema-node';\n\n/**\n * needed for cases when the exported entity could not be resolved.\n * e.g. exporting mdx variables in the main index.ts file.\n */\nexport class UnresolvedSchema extends SchemaNode {\n constructor(\n readonly location: SchemaLocation,\n readonly name: string\n ) {\n super();\n }\n\n toString() {\n return this.name;\n }\n\n toFullSignature(): string {\n return this.toString();\n }\n\n toObject() {\n return super.toObject();\n }\n\n static fromObject(obj: Record<string, any>): UnresolvedSchema {\n const location = obj.location;\n const name = obj.name;\n return new UnresolvedSchema(location, name);\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA;AACA;AACA;AACA;AACO,MAAME,gBAAgB,SAASC,wBAAU,CAAC;EAC/CC,WAAWA,CACAC,QAAwB,EACxBC,IAAY,EACrB;IACA,KAAK,CAAC,CAAC;IAAC,KAHCD,QAAwB,GAAxBA,QAAwB;IAAA,KACxBC,IAAY,GAAZA,IAAY;EAGvB;EAEAC,QAAQA,CAAA,EAAG;IACT,OAAO,IAAI,CAACD,IAAI;EAClB;EAEAE,eAAeA,CAAA,EAAW;IACxB,OAAO,IAAI,CAACD,QAAQ,CAAC,CAAC;EACxB;EAEAE,QAAQA,CAAA,EAAG;IACT,OAAO,KAAK,CAACA,QAAQ,CAAC,CAAC;EACzB;EAEA,OAAOC,UAAUA,CAACC,GAAwB,EAAoB;IAC5D,MAAMN,QAAQ,GAAGM,GAAG,CAACN,QAAQ;IAC7B,MAAMC,IAAI,GAAGK,GAAG,CAACL,IAAI;IACrB,OAAO,IAAIJ,gBAAgB,CAACG,QAAQ,EAAEC,IAAI,CAAC;EAC7C;AACF;AAACM,OAAA,CAAAV,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SchemaLocation, SchemaNode } from '../schema-node';
|
|
2
|
+
import { DocSchema } from './docs';
|
|
3
|
+
/**
|
|
4
|
+
* can be also a property or property-signature
|
|
5
|
+
*/
|
|
6
|
+
export declare class VariableLikeSchema extends SchemaNode {
|
|
7
|
+
readonly location: SchemaLocation;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly signature: string;
|
|
10
|
+
readonly isOptional: boolean;
|
|
11
|
+
readonly defaultValue?: string | undefined;
|
|
12
|
+
type: SchemaNode;
|
|
13
|
+
readonly doc?: DocSchema;
|
|
14
|
+
readonly displaySchemaName = "Variables";
|
|
15
|
+
constructor(location: SchemaLocation, name: string, signature: string, type: SchemaNode, isOptional: boolean, doc?: DocSchema, defaultValue?: string | undefined);
|
|
16
|
+
getNodes(): SchemaNode[];
|
|
17
|
+
toString(options?: {
|
|
18
|
+
color?: boolean;
|
|
19
|
+
}): string;
|
|
20
|
+
toFullSignature(options?: {
|
|
21
|
+
showDocs?: boolean;
|
|
22
|
+
}): string;
|
|
23
|
+
toObject(): {
|
|
24
|
+
name: string;
|
|
25
|
+
signature: string;
|
|
26
|
+
type: Record<string, any>;
|
|
27
|
+
isOptional: boolean;
|
|
28
|
+
doc: {
|
|
29
|
+
__schema: string;
|
|
30
|
+
name: string | undefined;
|
|
31
|
+
location: SchemaLocation;
|
|
32
|
+
signature: string | undefined;
|
|
33
|
+
raw: string;
|
|
34
|
+
comment: string | undefined;
|
|
35
|
+
tags: {
|
|
36
|
+
__schema: string;
|
|
37
|
+
location: SchemaLocation;
|
|
38
|
+
name: string | undefined;
|
|
39
|
+
signature: string | undefined;
|
|
40
|
+
tagName: string;
|
|
41
|
+
comment: string | undefined;
|
|
42
|
+
}[] | undefined;
|
|
43
|
+
} | undefined;
|
|
44
|
+
defaultValue: string | undefined;
|
|
45
|
+
};
|
|
46
|
+
static fromObject(obj: Record<string, any>): VariableLikeSchema;
|
|
47
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VariableLikeSchema = void 0;
|
|
7
|
+
function _chalk() {
|
|
8
|
+
const data = _interopRequireDefault(require("chalk"));
|
|
9
|
+
_chalk = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _schemaNode() {
|
|
15
|
+
const data = require("../schema-node");
|
|
16
|
+
_schemaNode = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _docs() {
|
|
22
|
+
const data = require("./docs");
|
|
23
|
+
_docs = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _schemaRegistry() {
|
|
29
|
+
const data = require("../schema-registry");
|
|
30
|
+
_schemaRegistry = function () {
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
36
|
+
/**
|
|
37
|
+
* can be also a property or property-signature
|
|
38
|
+
*/
|
|
39
|
+
class VariableLikeSchema extends _schemaNode().SchemaNode {
|
|
40
|
+
displaySchemaName = 'Variables';
|
|
41
|
+
constructor(location, name, signature, type, isOptional, doc, defaultValue) {
|
|
42
|
+
super();
|
|
43
|
+
this.location = location;
|
|
44
|
+
this.name = name;
|
|
45
|
+
this.signature = signature;
|
|
46
|
+
this.isOptional = isOptional;
|
|
47
|
+
this.defaultValue = defaultValue;
|
|
48
|
+
this.type = type;
|
|
49
|
+
this.doc = doc;
|
|
50
|
+
}
|
|
51
|
+
getNodes() {
|
|
52
|
+
return [this.type];
|
|
53
|
+
}
|
|
54
|
+
toString(options) {
|
|
55
|
+
const bold = options?.color ? _chalk().default.bold : str => str;
|
|
56
|
+
return `${bold(this.name)}${this.isOptional ? '?' : ''}: ${this.type.toString(options)}`;
|
|
57
|
+
}
|
|
58
|
+
toFullSignature(options) {
|
|
59
|
+
const namePart = `${this.name}${this.isOptional ? '?' : ''}`;
|
|
60
|
+
const typeSignature = this.type.toFullSignature(options);
|
|
61
|
+
let signature = `${namePart}: ${typeSignature}`;
|
|
62
|
+
if (this.defaultValue !== undefined) {
|
|
63
|
+
signature += ` = ${this.defaultValue}`;
|
|
64
|
+
}
|
|
65
|
+
if (options?.showDocs && this.doc) {
|
|
66
|
+
const docString = this.doc.toFullSignature();
|
|
67
|
+
signature = `${docString}\n${signature}`;
|
|
68
|
+
}
|
|
69
|
+
return signature;
|
|
70
|
+
}
|
|
71
|
+
toObject() {
|
|
72
|
+
return {
|
|
73
|
+
...super.toObject(),
|
|
74
|
+
name: this.name,
|
|
75
|
+
signature: this.signature,
|
|
76
|
+
type: this.type.toObject(),
|
|
77
|
+
isOptional: this.isOptional,
|
|
78
|
+
doc: this.doc?.toObject(),
|
|
79
|
+
defaultValue: this.defaultValue
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
static fromObject(obj) {
|
|
83
|
+
const location = obj.location;
|
|
84
|
+
const name = obj.name;
|
|
85
|
+
const signature = obj.signature;
|
|
86
|
+
const type = _schemaRegistry().SchemaRegistry.fromObject(obj.type);
|
|
87
|
+
const isOptional = obj.isOptional;
|
|
88
|
+
const doc = obj.doc ? _docs().DocSchema.fromObject(obj.doc) : undefined;
|
|
89
|
+
const defaultValue = obj.defaultValue;
|
|
90
|
+
return new VariableLikeSchema(location, name, signature, type, isOptional, doc, defaultValue);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.VariableLikeSchema = VariableLikeSchema;
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=variable-like.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_chalk","data","_interopRequireDefault","require","_schemaNode","_docs","_schemaRegistry","e","__esModule","default","VariableLikeSchema","SchemaNode","displaySchemaName","constructor","location","name","signature","type","isOptional","doc","defaultValue","getNodes","toString","options","bold","color","chalk","str","toFullSignature","namePart","typeSignature","undefined","showDocs","docString","toObject","fromObject","obj","SchemaRegistry","DocSchema","exports"],"sources":["variable-like.ts"],"sourcesContent":["import chalk from 'chalk';\nimport { SchemaLocation, SchemaNode } from '../schema-node';\nimport { DocSchema } from './docs';\nimport { SchemaRegistry } from '../schema-registry';\n\n/**\n * can be also a property or property-signature\n */\nexport class VariableLikeSchema extends SchemaNode {\n type: SchemaNode;\n readonly doc?: DocSchema;\n readonly displaySchemaName = 'Variables';\n\n constructor(\n readonly location: SchemaLocation,\n readonly name: string,\n readonly signature: string,\n type: SchemaNode,\n readonly isOptional: boolean,\n doc?: DocSchema,\n readonly defaultValue?: string\n ) {\n super();\n this.type = type;\n this.doc = doc;\n }\n\n getNodes() {\n return [this.type];\n }\n\n toString(options?: { color?: boolean }) {\n const bold = options?.color ? chalk.bold : (str: string) => str;\n return `${bold(this.name)}${this.isOptional ? '?' : ''}: ${this.type.toString(options)}`;\n }\n\n toFullSignature(options?: { showDocs?: boolean }): string {\n const namePart = `${this.name}${this.isOptional ? '?' : ''}`;\n const typeSignature = this.type.toFullSignature(options);\n let signature = `${namePart}: ${typeSignature}`;\n\n if (this.defaultValue !== undefined) {\n signature += ` = ${this.defaultValue}`;\n }\n\n if (options?.showDocs && this.doc) {\n const docString = this.doc.toFullSignature();\n signature = `${docString}\\n${signature}`;\n }\n\n return signature;\n }\n\n toObject() {\n return {\n ...super.toObject(),\n name: this.name,\n signature: this.signature,\n type: this.type.toObject(),\n isOptional: this.isOptional,\n doc: this.doc?.toObject(),\n defaultValue: this.defaultValue,\n };\n }\n\n static fromObject(obj: Record<string, any>): VariableLikeSchema {\n const location = obj.location;\n const name = obj.name;\n const signature = obj.signature;\n const type = SchemaRegistry.fromObject(obj.type);\n const isOptional = obj.isOptional;\n const doc = obj.doc ? DocSchema.fromObject(obj.doc) : undefined;\n const defaultValue = obj.defaultValue;\n return new VariableLikeSchema(location, name, signature, type, isOptional, doc, defaultValue);\n }\n}\n"],"mappings":"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","ignoreList":[]}
|
package/dist/type.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TypeRef = {};
|
package/dist/type.js
ADDED
package/dist/type.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["type.ts"],"sourcesContent":["export type TypeRef = {};\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UnknownSchemaFactory = void 0;
|
|
7
|
+
class UnknownSchemaFactory {
|
|
8
|
+
static create(location, name, schemaObj) {
|
|
9
|
+
// dynamic require() to import UnknownSchema at runtime when it's needed, which breaks the circular dependency.
|
|
10
|
+
// eslint-disable-next-line global-require
|
|
11
|
+
const {
|
|
12
|
+
UnknownSchema
|
|
13
|
+
} = require('./schemas/unknown-schema');
|
|
14
|
+
return new UnknownSchema(location, name, schemaObj);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.UnknownSchemaFactory = UnknownSchemaFactory;
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=unknown-schema-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["UnknownSchemaFactory","create","location","name","schemaObj","UnknownSchema","require","exports"],"sources":["unknown-schema-factory.ts"],"sourcesContent":["import { SchemaLocation } from './schema-node';\n\nexport class UnknownSchemaFactory {\n static create(location: SchemaLocation, name: string, schemaObj: Record<string, any>): any {\n // dynamic require() to import UnknownSchema at runtime when it's needed, which breaks the circular dependency.\n // eslint-disable-next-line global-require\n const { UnknownSchema } = require('./schemas/unknown-schema');\n return new UnknownSchema(location, name, schemaObj);\n }\n}\n"],"mappings":";;;;;;AAEO,MAAMA,oBAAoB,CAAC;EAChC,OAAOC,MAAMA,CAACC,QAAwB,EAAEC,IAAY,EAAEC,SAA8B,EAAO;IACzF;IACA;IACA,MAAM;MAAEC;IAAc,CAAC,GAAGC,OAAO,CAAC,0BAA0B,CAAC;IAC7D,OAAO,IAAID,aAAa,CAACH,QAAQ,EAAEC,IAAI,EAAEC,SAAS,CAAC;EACrD;AACF;AAACG,OAAA,CAAAP,oBAAA,GAAAA,oBAAA","ignoreList":[]}
|
package/export.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type Primitive = string | number | boolean | null | undefined;
|
|
2
|
+
export type StaticProperties = Map<string, Primitive>;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @todo: this was implemented before all other schemas and is used only for composition.
|
|
6
|
+
* it needs to be align with other schemas.
|
|
7
|
+
*/
|
|
8
|
+
export class Export {
|
|
9
|
+
constructor(
|
|
10
|
+
/**
|
|
11
|
+
* named export identifier of the module export.
|
|
12
|
+
*/
|
|
13
|
+
readonly identifier: string,
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* static properties attached to this export
|
|
17
|
+
* @example
|
|
18
|
+
* export hello = () => {};
|
|
19
|
+
* hello.value = "text"; // <-- staticProperty
|
|
20
|
+
* hello.count = 3; // <-- static property
|
|
21
|
+
*/
|
|
22
|
+
readonly staticProperties?: StaticProperties
|
|
23
|
+
) {}
|
|
24
|
+
|
|
25
|
+
toObject() {
|
|
26
|
+
return {
|
|
27
|
+
constructorName: this.constructor.name,
|
|
28
|
+
identifier: this.identifier,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as Schemas from './schemas';
|
|
2
|
+
|
|
3
|
+
export { SchemaNode, ISchemaNode } from './schema-node';
|
|
4
|
+
export { APISchema } from './api-schema';
|
|
5
|
+
export { Export, StaticProperties } from './export';
|
|
6
|
+
export type { SchemaLocation as Location } from './schema-node';
|
|
7
|
+
export { TagName } from './schemas/docs/tag';
|
|
8
|
+
export { SchemaRegistry } from './schema-registry';
|
|
9
|
+
export { SchemaNodeConstructor } from './schema-node-constructor';
|
|
10
|
+
export { Modifier } from './schemas/function-like';
|
|
11
|
+
export { Schemas };
|
|
12
|
+
|
|
13
|
+
export * from './schemas';
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@teambit/semantics.entities.semantic-schema",
|
|
3
|
+
"version": "0.0.0-e4ef0e951da794f03096a5cc407420f4cde8b878",
|
|
4
|
+
"homepage": "https://bit.cloud/teambit/semantics/entities/semantic-schema",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"componentId": {
|
|
7
|
+
"scope": "teambit.semantics",
|
|
8
|
+
"name": "entities/semantic-schema",
|
|
9
|
+
"version": "e4ef0e951da794f03096a5cc407420f4cde8b878"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"chalk": "4.1.2",
|
|
13
|
+
"lodash": "4.17.21",
|
|
14
|
+
"pluralize": "8.0.0",
|
|
15
|
+
"@teambit/component-id": "1.2.4"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/lodash": "4.14.165",
|
|
19
|
+
"@types/pluralize": "0.0.29",
|
|
20
|
+
"@types/mocha": "9.1.0",
|
|
21
|
+
"chai": "4.3.0",
|
|
22
|
+
"@teambit/node.envs.node-babel-mocha": "0.1.18"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {},
|
|
25
|
+
"license": "Apache-2.0",
|
|
26
|
+
"optionalDependencies": {},
|
|
27
|
+
"peerDependenciesMeta": {},
|
|
28
|
+
"private": false,
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=12.22.0"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/teambit/bit"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"bit",
|
|
38
|
+
"components",
|
|
39
|
+
"collaboration",
|
|
40
|
+
"web",
|
|
41
|
+
"react",
|
|
42
|
+
"react-components",
|
|
43
|
+
"angular",
|
|
44
|
+
"angular-components"
|
|
45
|
+
]
|
|
46
|
+
}
|
package/schema-node.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { pickBy } from 'lodash';
|
|
2
|
+
import pluralize from 'pluralize';
|
|
3
|
+
import { DocSchema } from './schemas';
|
|
4
|
+
|
|
5
|
+
export interface ISchemaNode {
|
|
6
|
+
__schema: string;
|
|
7
|
+
location: SchemaLocation;
|
|
8
|
+
doc?: DocSchema;
|
|
9
|
+
signature?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
toObject(): Record<string, any>;
|
|
12
|
+
toString(options?: { color?: boolean }): string;
|
|
13
|
+
toFullSignature(options?: { showDocs?: boolean }): string;
|
|
14
|
+
getNodes(): SchemaNode[];
|
|
15
|
+
findNode(predicate: (node: SchemaNode) => boolean, visitedNodes?: Set<SchemaNode>): SchemaNode | undefined;
|
|
16
|
+
getAllNodesRecursively(visitedNodes?: Set<SchemaNode>): SchemaNode[];
|
|
17
|
+
displaySchemaName: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* a convenient abstract class for all schema to extend.
|
|
22
|
+
* the reason for having it as an abstract class and not an interface, for now, is mostly for the `__schema` prop.
|
|
23
|
+
* this way it won't need to be implemented in each one of the subclasses.
|
|
24
|
+
*/
|
|
25
|
+
export abstract class SchemaNode implements ISchemaNode {
|
|
26
|
+
readonly __schema = this.constructor.name;
|
|
27
|
+
readonly displaySchemaName = pluralize(
|
|
28
|
+
this.constructor.name
|
|
29
|
+
.replace(/Schema$/, '')
|
|
30
|
+
.replace(/([A-Z])/g, ' $1')
|
|
31
|
+
.trim()
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
abstract readonly location: SchemaLocation;
|
|
35
|
+
readonly doc?: DocSchema;
|
|
36
|
+
readonly signature?: string;
|
|
37
|
+
readonly name?: string;
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
|
+
static fromObject(obj: Record<string, any>): SchemaNode {
|
|
40
|
+
throw new Error(`Method 'fromObject' not implemented in subclass.`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
toObject(): Record<string, any> {
|
|
44
|
+
return pickBy(
|
|
45
|
+
{
|
|
46
|
+
__schema: this.__schema,
|
|
47
|
+
location: this.location,
|
|
48
|
+
doc: this.doc ? this.doc.toObject() : undefined,
|
|
49
|
+
signature: this.signature,
|
|
50
|
+
name: this.name,
|
|
51
|
+
},
|
|
52
|
+
(v) => v !== undefined
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
abstract toString(options?: { color?: boolean }): string;
|
|
57
|
+
abstract toFullSignature(options?: { showDocs?: boolean }): string;
|
|
58
|
+
|
|
59
|
+
getNodes(): SchemaNode[] {
|
|
60
|
+
return [this];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getAllNodesRecursively(visitedNodes = new Set<SchemaNode>()): SchemaNode[] {
|
|
64
|
+
if (visitedNodes.has(this)) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
visitedNodes.add(this);
|
|
69
|
+
|
|
70
|
+
const nodes = this.getNodes();
|
|
71
|
+
return [this, ...nodes.flatMap((node) => node.getAllNodesRecursively(visitedNodes))];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
findNode(predicate: (node: SchemaNode) => boolean, visitedNodes = new Set<SchemaNode>()): SchemaNode | undefined {
|
|
75
|
+
if (predicate(this)) return this;
|
|
76
|
+
if (visitedNodes.has(this)) return undefined;
|
|
77
|
+
|
|
78
|
+
visitedNodes.add(this);
|
|
79
|
+
|
|
80
|
+
for (const child of this.getNodes()) {
|
|
81
|
+
const foundNode = child.findNode(predicate, visitedNodes);
|
|
82
|
+
if (foundNode) return foundNode;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type SchemaLocation = {
|
|
90
|
+
/**
|
|
91
|
+
* file-path relative to the component root-dir. normalized to Linux.
|
|
92
|
+
*/
|
|
93
|
+
filePath: string;
|
|
94
|
+
line: number;
|
|
95
|
+
character: number;
|
|
96
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SchemaNodeConstructor } from './schema-node-constructor';
|
|
2
|
+
import { UnknownSchemaFactory } from './unknown-schema-factory';
|
|
3
|
+
|
|
4
|
+
type GetSchemaFunc = () => SchemaNodeConstructor[];
|
|
5
|
+
|
|
6
|
+
export class SchemaRegistry {
|
|
7
|
+
private static instance = new SchemaRegistry();
|
|
8
|
+
private _schemas: Record<string, SchemaNodeConstructor>;
|
|
9
|
+
private _getSchemas: GetSchemaFunc[] = [];
|
|
10
|
+
|
|
11
|
+
private constructor() {
|
|
12
|
+
this._schemas = {};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static registerGetSchemas(getSchemas: GetSchemaFunc) {
|
|
16
|
+
this.instance._getSchemas.push(getSchemas);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated use registerGetSchemas instead
|
|
21
|
+
* registerGetSchemas is better for performance as it lazy-loads the schemas.
|
|
22
|
+
*/
|
|
23
|
+
static register(schema: SchemaNodeConstructor) {
|
|
24
|
+
if (this.instance._schemas[schema.name]) return;
|
|
25
|
+
this.instance._schemas[schema.name] = schema;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static schemas() {
|
|
29
|
+
// this happens only once. as soon as the function is called, it registers all the schemas.
|
|
30
|
+
this.instance._getSchemas.forEach((getSchemas) => {
|
|
31
|
+
const schemas = getSchemas();
|
|
32
|
+
schemas.forEach((schema) => {
|
|
33
|
+
if (this.instance._schemas[schema.name]) return;
|
|
34
|
+
this.instance._schemas[schema.name] = schema;
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
this.instance._getSchemas = [];
|
|
38
|
+
return this.instance._schemas;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static fromObject(obj: Record<string, any>) {
|
|
42
|
+
if (!obj.__schema) {
|
|
43
|
+
throw new Error(`fatal: "__schema" is missing, make sure the transformer is set on SchemaNode type`);
|
|
44
|
+
}
|
|
45
|
+
const schemas = this.schemas();
|
|
46
|
+
const SchemaClass = schemas[obj.__schema];
|
|
47
|
+
if (!SchemaClass) {
|
|
48
|
+
// for backward and forward compatibility, to not break the users, it's better to return an unknown schema than throwing.
|
|
49
|
+
return UnknownSchemaFactory.create(obj.location || { path: '', line: 0, character: 0 }, obj.__schema, obj);
|
|
50
|
+
}
|
|
51
|
+
return SchemaClass.fromObject(obj);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SchemaLocation, SchemaNode } from '../schema-node';
|
|
2
|
+
import { SchemaRegistry } from '../schema-registry';
|
|
3
|
+
|
|
4
|
+
export class ArrayLiteralExpressionSchema extends SchemaNode {
|
|
5
|
+
constructor(
|
|
6
|
+
readonly members: SchemaNode[],
|
|
7
|
+
readonly location: SchemaLocation
|
|
8
|
+
) {
|
|
9
|
+
super();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
toObject() {
|
|
13
|
+
return {
|
|
14
|
+
...super.toObject(),
|
|
15
|
+
members: this.members.map((member) => member.toObject()),
|
|
16
|
+
location: this.location,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static fromObject(obj: Record<string, any>): ArrayLiteralExpressionSchema {
|
|
21
|
+
const members = obj.members.map((member) => SchemaRegistry.fromObject(member));
|
|
22
|
+
return new ArrayLiteralExpressionSchema(members, obj.location);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
toString(): string {
|
|
26
|
+
return `[${this.members.join(', ')}]`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
toFullSignature(options?: { showDocs?: boolean }): string {
|
|
30
|
+
const membersStr = this.members.map((member) => member.toFullSignature(options)).join(', ');
|
|
31
|
+
return `[${membersStr}]`;
|
|
32
|
+
}
|
|
33
|
+
}
|