@teambit/schema 0.0.551 → 0.0.556

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/parser.d.ts CHANGED
@@ -1,5 +1,11 @@
1
1
  import { Module } from './schemas';
2
2
  export interface Parser {
3
+ /**
4
+ * regex to apply on which components compiler applies.
5
+ */
3
6
  extension: RegExp;
7
+ /**
8
+ * parse a module.
9
+ */
4
10
  parseModule(modulePath: string): Module;
5
11
  }
@@ -1,5 +1,8 @@
1
1
  import { Component } from '@teambit/component';
2
2
  import { Module } from './schemas';
3
3
  export interface SchemaExtractor {
4
+ /**
5
+ * extract a semantic schema from a component.
6
+ */
4
7
  extract(component: Component): Promise<Module>;
5
8
  }
@@ -7,16 +7,42 @@ import { Module } from './schemas';
7
7
  import { SemanticSchema } from './semantic-schema';
8
8
  export declare type ParserSlot = SlotRegistry<Parser>;
9
9
  export declare type SchemaConfig = {
10
+ /**
11
+ * default parser
12
+ */
10
13
  defaultParser: string;
11
14
  };
15
+ /**
16
+ * extension for extracting component schemas.
17
+ */
12
18
  export declare class SchemaMain {
19
+ /**
20
+ * parsers slot.
21
+ */
13
22
  private parserSlot;
14
23
  private envs;
15
24
  private config;
16
- constructor(parserSlot: ParserSlot, envs: EnvsMain, config: SchemaConfig);
25
+ constructor(
26
+ /**
27
+ * parsers slot.
28
+ */
29
+ parserSlot: ParserSlot, envs: EnvsMain, config: SchemaConfig);
30
+ /**
31
+ * get the default parser.
32
+ */
17
33
  getDefaultParser(): Parser;
34
+ /**
35
+ * parse a module into a component schema.
36
+ */
18
37
  parseModule(path: string): Module;
38
+ /**
39
+ * get a schema of a component.
40
+ * @param component target component.
41
+ */
19
42
  getSchema(component: Component): Promise<SemanticSchema>;
43
+ /**
44
+ * register a new parser.
45
+ */
20
46
  registerParser(parser: Parser): SchemaMain;
21
47
  static runtime: import("@teambit/harmony").RuntimeDefinition;
22
48
  static dependencies: import("@teambit/harmony").Aspect[];
@@ -1,8 +1,30 @@
1
1
  declare type Primitive = string | number | boolean | null | undefined;
2
2
  export declare type StaticProperties = Map<string, Primitive>;
3
3
  export declare class Export {
4
+ /**
5
+ * named export identifier of the module export.
6
+ */
4
7
  readonly identifier: string;
8
+ /**
9
+ * static properties attached to this export
10
+ * @example
11
+ * export hello = () => {};
12
+ * hello.value = "text"; // <-- staticProperty
13
+ * hello.count = 3; // <-- static property
14
+ */
5
15
  readonly staticProperties?: StaticProperties | undefined;
6
- constructor(identifier: string, staticProperties?: StaticProperties | undefined);
16
+ constructor(
17
+ /**
18
+ * named export identifier of the module export.
19
+ */
20
+ identifier: string,
21
+ /**
22
+ * static properties attached to this export
23
+ * @example
24
+ * export hello = () => {};
25
+ * hello.value = "text"; // <-- staticProperty
26
+ * hello.count = 3; // <-- static property
27
+ */
28
+ staticProperties?: StaticProperties | undefined);
7
29
  }
8
30
  export {};
@@ -1,5 +1,12 @@
1
1
  import { Export } from './export';
2
2
  export declare class Module {
3
+ /**
4
+ * all module exports.
5
+ */
3
6
  readonly exports: Export[];
4
- constructor(exports: Export[]);
7
+ constructor(
8
+ /**
9
+ * all module exports.
10
+ */
11
+ exports: Export[]);
5
12
  }
@@ -1,3 +1,6 @@
1
+ /**
2
+ * describes the semantic schema of a component.
3
+ */
1
4
  export interface SemanticSchema {
2
5
  exports: [];
3
6
  }
package/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "@teambit/schema",
3
- "version": "0.0.551",
3
+ "version": "0.0.556",
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.551"
9
+ "version": "0.0.556"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/harmony": "0.2.11",
13
13
  "graphql-tag": "2.12.1",
14
14
  "@babel/runtime": "7.12.18",
15
15
  "core-js": "^3.0.0",
16
- "@teambit/component": "0.0.551",
17
- "@teambit/cli": "0.0.382",
18
- "@teambit/envs": "0.0.551",
19
- "@teambit/graphql": "0.0.551"
16
+ "@teambit/component": "0.0.556",
17
+ "@teambit/cli": "0.0.387",
18
+ "@teambit/envs": "0.0.556",
19
+ "@teambit/graphql": "0.0.556"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/mocha": "5.2.7",
@@ -27,7 +27,7 @@
27
27
  "@types/node": "12.20.4"
28
28
  },
29
29
  "peerDependencies": {
30
- "@teambit/legacy": "1.0.169",
30
+ "@teambit/legacy": "1.0.173",
31
31
  "react-dom": "^16.8.0 || ^17.0.0",
32
32
  "react": "^16.8.0 || ^17.0.0"
33
33
  },
@@ -55,12 +55,18 @@
55
55
  "react": "-"
56
56
  },
57
57
  "peerDependencies": {
58
- "@teambit/legacy": "1.0.169",
58
+ "@teambit/legacy": "1.0.173",
59
59
  "react-dom": "^16.8.0 || ^17.0.0",
60
60
  "react": "^16.8.0 || ^17.0.0"
61
61
  }
62
62
  }
63
63
  },
64
+ "files": [
65
+ "dist",
66
+ "!dist/tsconfig.tsbuildinfo",
67
+ "README.md",
68
+ "README.mdx"
69
+ ],
64
70
  "private": false,
65
71
  "engines": {
66
72
  "node": ">=12.22.0"
@@ -1 +0,0 @@
1
- export { ParserNotFound } from './parser-not-found';
@@ -1,8 +0,0 @@
1
- export class ParserNotFound extends Error {
2
- constructor(readonly filePath: string) {
3
- super(`
4
- no parser is configured to apply on file path: ${filePath}.\n
5
- please use an extension to handle your file extension formats.
6
- `);
7
- }
8
- }
package/index.ts DELETED
@@ -1,6 +0,0 @@
1
- export { Parser } from './parser';
2
- export { SchemaExtractor } from './schema-extractor';
3
- export { Export, Module, StaticProperties } from './schemas';
4
- export type { SchemaMain } from './schema.main.runtime';
5
- export { SchemaAspect } from './schema.aspect';
6
- export { SemanticSchema } from './semantic-schema';
package/parser.ts DELETED
@@ -1,13 +0,0 @@
1
- import { Module } from './schemas';
2
-
3
- export interface Parser {
4
- /**
5
- * regex to apply on which components compiler applies.
6
- */
7
- extension: RegExp;
8
-
9
- /**
10
- * parse a module.
11
- */
12
- parseModule(modulePath: string): Module;
13
- }
@@ -1,9 +0,0 @@
1
- import { Component } from '@teambit/component';
2
- import { Module } from './schemas';
3
-
4
- export interface SchemaExtractor {
5
- /**
6
- * extract a semantic schema from a component.
7
- */
8
- extract(component: Component): Promise<Module>;
9
- }
package/schema.aspect.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const SchemaAspect = Aspect.create({
4
- id: 'teambit.semantics/schema',
5
- });
package/schema.graphql.ts DELETED
@@ -1,35 +0,0 @@
1
- import { ComponentFactory } from '@teambit/component';
2
- import gql from 'graphql-tag';
3
-
4
- import { SchemaMain } from './schema.main.runtime';
5
-
6
- export function schemaSchema(schema: SchemaMain) {
7
- return {
8
- typeDefs: gql`
9
- extend type ComponentHost {
10
- getSchema(id: String!): SchemaDocs
11
- }
12
-
13
- type SchemaDocs {
14
- exports: [String]
15
- }
16
- `,
17
- resolvers: {
18
- ComponentHost: {
19
- getSchema: async (host: ComponentFactory, { id }: { id: string }) => {
20
- const componentId = await host.resolveComponentId(id);
21
- const component = await host.get(componentId);
22
- const empty = {
23
- exports: [],
24
- };
25
-
26
- if (!component) return empty;
27
- const docs = await schema.getSchema(component);
28
- if (!docs) return empty;
29
-
30
- return docs;
31
- },
32
- },
33
- },
34
- };
35
- }
@@ -1,109 +0,0 @@
1
- import { MainRuntime } from '@teambit/cli';
2
- import { Component } from '@teambit/component';
3
- import { Slot, SlotRegistry } from '@teambit/harmony';
4
- import GraphqlAspect, { GraphqlMain } from '@teambit/graphql';
5
- import { EnvsAspect, EnvsMain } from '@teambit/envs';
6
- import { Parser } from './parser';
7
- import { SchemaAspect } from './schema.aspect';
8
- import { Module } from './schemas';
9
- import { SemanticSchema } from './semantic-schema';
10
- import { SchemaExtractor } from './schema-extractor';
11
- import { schemaSchema } from './schema.graphql';
12
-
13
- export type ParserSlot = SlotRegistry<Parser>;
14
-
15
- export type SchemaConfig = {
16
- /**
17
- * default parser
18
- */
19
- defaultParser: string;
20
- };
21
-
22
- /**
23
- * extension for extracting component schemas.
24
- */
25
- export class SchemaMain {
26
- constructor(
27
- /**
28
- * parsers slot.
29
- */
30
- private parserSlot: ParserSlot,
31
-
32
- private envs: EnvsMain,
33
-
34
- private config: SchemaConfig
35
- ) {}
36
-
37
- /**
38
- * get the default parser.
39
- */
40
- getDefaultParser(): Parser {
41
- return this.parserSlot.get(this.config.defaultParser) as Parser;
42
- }
43
-
44
- /**
45
- * parse a module into a component schema.
46
- */
47
- parseModule(path: string): Module {
48
- const parsers = this.parserSlot.toArray();
49
- let maybeParser = parsers.find(([, parser]) => {
50
- const match = path.match(parser.extension);
51
- return match;
52
- });
53
-
54
- if (!maybeParser) {
55
- maybeParser = [this.config.defaultParser, this.getDefaultParser()];
56
- }
57
-
58
- const [, parser] = maybeParser;
59
- return parser.parseModule(path);
60
- }
61
-
62
- /**
63
- * get a schema of a component.
64
- * @param component target component.
65
- */
66
- async getSchema(component: Component): Promise<SemanticSchema> {
67
- const env = this.envs.getEnv(component).env;
68
- if (typeof env.getSchemaExtractor === 'undefined') {
69
- throw new Error(`No SchemaExtractor defined for ${env.name}`);
70
- }
71
- const schemaExtractor: SchemaExtractor = env.getSchemaExtractor();
72
- await schemaExtractor.extract(component);
73
-
74
- return {
75
- exports: [],
76
- };
77
- }
78
-
79
- /**
80
- * register a new parser.
81
- */
82
- registerParser(parser: Parser): SchemaMain {
83
- this.parserSlot.register(parser);
84
- return this;
85
- }
86
-
87
- static runtime = MainRuntime;
88
-
89
- static dependencies = [EnvsAspect, GraphqlAspect];
90
-
91
- static defaultConfig = {
92
- defaultParser: 'teambit.typescript/typescript',
93
- };
94
-
95
- static slots = [Slot.withType<Parser>()];
96
-
97
- static async provider([envs, graphql]: [EnvsMain, GraphqlMain], config: SchemaConfig, [parserSlot]: [ParserSlot]) {
98
- const schema = new SchemaMain(parserSlot, envs, config);
99
- graphql.register(schemaSchema(schema));
100
- // workspace.onComponentLoad(async (component) => {
101
- // const apiSchema = await schema.getSchema(component);
102
- // return {};
103
- // });
104
-
105
- return schema;
106
- }
107
- }
108
-
109
- SchemaAspect.addRuntime(SchemaMain);
package/schema.service.ts DELETED
@@ -1,10 +0,0 @@
1
- import { EnvService, ExecutionContext } from '@teambit/envs';
2
- // import { APISchema } from './schema';
3
-
4
- export class SchemaService implements EnvService<{}> {
5
- name = 'schema';
6
-
7
- async run(context: ExecutionContext) {
8
- return { errors: [], context };
9
- }
10
- }
package/schemas/export.ts DELETED
@@ -1,20 +0,0 @@
1
- type Primitive = string | number | boolean | null | undefined;
2
- export type StaticProperties = Map<string, Primitive>;
3
-
4
- export class Export {
5
- constructor(
6
- /**
7
- * named export identifier of the module export.
8
- */
9
- readonly identifier: string,
10
-
11
- /**
12
- * static properties attached to this export
13
- * @example
14
- * export hello = () => {};
15
- * hello.value = "text"; // <-- staticProperty
16
- * hello.count = 3; // <-- static property
17
- */
18
- readonly staticProperties?: StaticProperties
19
- ) {}
20
- }
package/schemas/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export { Module } from './module';
2
- export { Export, StaticProperties } from './export';
package/schemas/module.ts DELETED
@@ -1,10 +0,0 @@
1
- import { Export } from './export';
2
-
3
- export class Module {
4
- constructor(
5
- /**
6
- * all module exports.
7
- */
8
- readonly exports: Export[]
9
- ) {}
10
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * describes the semantic schema of a component.
3
- */
4
- export interface SemanticSchema {
5
- exports: [];
6
- }
package/tsconfig.json DELETED
@@ -1,35 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "lib": [
4
- "es2019",
5
- "DOM",
6
- "ES6",
7
- "DOM.Iterable",
8
- "ScriptHost"
9
- ],
10
- "target": "es2015",
11
- "module": "commonjs",
12
- "jsx": "react",
13
- "declaration": true,
14
- "sourceMap": true,
15
- "skipLibCheck": true,
16
- "moduleResolution": "node",
17
- "esModuleInterop": true,
18
- "outDir": "dist",
19
- "composite": true,
20
- "emitDeclarationOnly": true,
21
- "experimentalDecorators": true,
22
- "emitDecoratorMetadata": true,
23
- "allowSyntheticDefaultImports": true,
24
- "strictPropertyInitialization": false,
25
- "strict": true,
26
- "noImplicitAny": false,
27
- "rootDir": ".",
28
- "removeComments": true,
29
- "preserveConstEnums": true,
30
- "resolveJsonModule": true
31
- },
32
- "exclude": [
33
- "dist"
34
- ]
35
- }
package/types/asset.d.ts DELETED
@@ -1,29 +0,0 @@
1
- declare module '*.png' {
2
- const value: any;
3
- export = value;
4
- }
5
- declare module '*.svg' {
6
- import type { FunctionComponent, SVGProps } from 'react';
7
-
8
- export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
9
- const src: string;
10
- export default src;
11
- }
12
-
13
- // @TODO Gilad
14
- declare module '*.jpg' {
15
- const value: any;
16
- export = value;
17
- }
18
- declare module '*.jpeg' {
19
- const value: any;
20
- export = value;
21
- }
22
- declare module '*.gif' {
23
- const value: any;
24
- export = value;
25
- }
26
- declare module '*.bmp' {
27
- const value: any;
28
- export = value;
29
- }
package/types/style.d.ts DELETED
@@ -1,42 +0,0 @@
1
- declare module '*.module.css' {
2
- const classes: { readonly [key: string]: string };
3
- export default classes;
4
- }
5
- declare module '*.module.scss' {
6
- const classes: { readonly [key: string]: string };
7
- export default classes;
8
- }
9
- declare module '*.module.sass' {
10
- const classes: { readonly [key: string]: string };
11
- export default classes;
12
- }
13
-
14
- declare module '*.module.less' {
15
- const classes: { readonly [key: string]: string };
16
- export default classes;
17
- }
18
-
19
- declare module '*.less' {
20
- const classes: { readonly [key: string]: string };
21
- export default classes;
22
- }
23
-
24
- declare module '*.css' {
25
- const classes: { readonly [key: string]: string };
26
- export default classes;
27
- }
28
-
29
- declare module '*.sass' {
30
- const classes: { readonly [key: string]: string };
31
- export default classes;
32
- }
33
-
34
- declare module '*.scss' {
35
- const classes: { readonly [key: string]: string };
36
- export default classes;
37
- }
38
-
39
- declare module '*.mdx' {
40
- const component: any;
41
- export default component;
42
- }