@code0-tech/definition-reader 0.0.9 → 0.0.10

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.
@@ -0,0 +1,2 @@
1
+ export { Definition } from './src/parser.js';
2
+ export type { Feature, MetaType, Meta } from './src/types.js';
package/build/index.js ADDED
@@ -0,0 +1 @@
1
+ export { Definition } from './src/parser.js';
@@ -0,0 +1,2 @@
1
+ import { Feature } from "./types.js";
2
+ export declare const Definition: (rootPath: string) => Feature[];
@@ -0,0 +1,50 @@
1
+ import { Reader } from './reader.js';
2
+ import { MetaType } from "./types.js";
3
+ export const Definition = (rootPath) => {
4
+ const meta = Reader(rootPath);
5
+ if (!meta)
6
+ return [];
7
+ const features = [];
8
+ for (const m of meta) {
9
+ let feature = features.find((f) => f.name === m.name);
10
+ if (feature) {
11
+ appendMeta(feature, m);
12
+ }
13
+ else {
14
+ feature = {
15
+ name: m.name,
16
+ dataTypes: [],
17
+ flowTypes: [],
18
+ runtimeFunctions: [],
19
+ };
20
+ appendMeta(feature, m);
21
+ features.push(feature);
22
+ }
23
+ }
24
+ return features;
25
+ };
26
+ function appendMeta(feature, meta) {
27
+ const definition = meta.data;
28
+ try {
29
+ switch (meta.type) {
30
+ case MetaType.DataType: {
31
+ const parsed = JSON.parse(definition);
32
+ feature.dataTypes.push(parsed);
33
+ break;
34
+ }
35
+ case MetaType.FlowType: {
36
+ const parsed = JSON.parse(definition);
37
+ feature.flowTypes.push(parsed);
38
+ break;
39
+ }
40
+ case MetaType.RuntimeFunction: {
41
+ const parsed = JSON.parse(definition);
42
+ feature.runtimeFunctions.push(parsed);
43
+ break;
44
+ }
45
+ }
46
+ }
47
+ catch (err) {
48
+ console.error(`Error parsing ${meta.type} ${meta.name} ${definition}:`, err);
49
+ }
50
+ }
@@ -0,0 +1,2 @@
1
+ import { Meta } from "./types.js";
2
+ export declare const Reader: (rootPath: string) => Meta[];
@@ -0,0 +1,75 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { MetaType } from "./types.js";
4
+ export const Reader = (rootPath) => {
5
+ const result = [];
6
+ try {
7
+ const features = fs.readdirSync(rootPath, { withFileTypes: true });
8
+ for (const featureDirent of features) {
9
+ if (!featureDirent.isDirectory())
10
+ continue;
11
+ const featurePath = path.join(rootPath, featureDirent.name);
12
+ const featureName = featureDirent.name;
13
+ const typeDirs = fs.readdirSync(featurePath, { withFileTypes: true });
14
+ for (const typeDirent of typeDirs) {
15
+ if (!typeDirent.isDirectory())
16
+ continue;
17
+ const metaType = matchMetaType(typeDirent.name);
18
+ if (!metaType)
19
+ continue;
20
+ const typePath = path.join(featurePath, typeDirent.name);
21
+ const definitions = fs.readdirSync(typePath, { withFileTypes: true });
22
+ for (const def of definitions) {
23
+ const defPath = path.join(typePath, def.name);
24
+ if (def.isFile()) {
25
+ if (!defPath.endsWith('.json'))
26
+ continue;
27
+ try {
28
+ const content = fs.readFileSync(defPath, 'utf-8');
29
+ const meta = { name: featureName, type: metaType, data: content };
30
+ result.push(meta);
31
+ }
32
+ catch (err) {
33
+ console.error(`Error reading file: ${defPath}`, err);
34
+ }
35
+ }
36
+ else if (def.isDirectory()) {
37
+ const subDefinitions = fs.readdirSync(defPath, { withFileTypes: true });
38
+ for (const subDef of subDefinitions) {
39
+ const subPath = path.join(defPath, subDef.name);
40
+ if (!subPath.endsWith('.json'))
41
+ continue;
42
+ if (!subDef.isFile())
43
+ continue;
44
+ try {
45
+ const content = fs.readFileSync(subPath, 'utf-8');
46
+ const meta = { name: featureName, type: metaType, data: content };
47
+ result.push(meta);
48
+ }
49
+ catch (err) {
50
+ console.error(`Error reading file: ${subPath}`, err);
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
57
+ return result;
58
+ }
59
+ catch (err) {
60
+ console.error(`Error reading path ${rootPath}:`, err);
61
+ return [];
62
+ }
63
+ };
64
+ function matchMetaType(name) {
65
+ switch (name) {
66
+ case 'flow_type':
67
+ return MetaType.FlowType;
68
+ case 'data_type':
69
+ return MetaType.DataType;
70
+ case 'runtime_definition':
71
+ return MetaType.RuntimeFunction;
72
+ default:
73
+ return null;
74
+ }
75
+ }
@@ -0,0 +1,17 @@
1
+ import { DataType, FlowType, RuntimeFunctionDefinition } from "@code0-tech/sagittarius-graphql-types";
2
+ export declare enum MetaType {
3
+ FlowType = "FlowType",
4
+ DataType = "DataType",
5
+ RuntimeFunction = "RuntimeFunction"
6
+ }
7
+ export interface Meta {
8
+ name: string;
9
+ type: MetaType;
10
+ data: string;
11
+ }
12
+ export interface Feature {
13
+ name: string;
14
+ dataTypes: DataType[];
15
+ flowTypes: FlowType[];
16
+ runtimeFunctions: RuntimeFunctionDefinition[];
17
+ }
@@ -0,0 +1,6 @@
1
+ export var MetaType;
2
+ (function (MetaType) {
3
+ MetaType["FlowType"] = "FlowType";
4
+ MetaType["DataType"] = "DataType";
5
+ MetaType["RuntimeFunction"] = "RuntimeFunction";
6
+ })(MetaType || (MetaType = {}));
package/package.json CHANGED
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "name": "@code0-tech/definition-reader",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "Reader for Code0-Definitions",
5
- "main": "index.js",
6
- "types": "index.d.ts",
5
+ "main": "./build/index.js",
6
+ "types": "./build/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./build/index.js",
10
+ "types": "./build/index.d.ts"
11
+ }
12
+ },
7
13
  "type": "module",
8
14
  "scripts": {
9
15
  "build": "tsc"
@@ -20,10 +26,7 @@
20
26
  "url": "git+https://github.com/code0-tech/code0-definitions.git"
21
27
  },
22
28
  "files": [
23
- "src",
24
- "index.d.ts",
25
- "index.js",
26
- "package.json"
29
+ "build"
27
30
  ],
28
31
  "publishConfig": {
29
32
  "access": "public"
package/index.d.ts DELETED
@@ -1,20 +0,0 @@
1
- import {DataType, FlowType, RuntimeFunctionDefinition} from "@code0-tech/sagittarius-graphql-types";
2
-
3
- export enum MetaType {
4
- FlowType = 'FlowType',
5
- DataType = 'DataType',
6
- RuntimeFunction = 'RuntimeFunction',
7
- }
8
-
9
- export interface Meta {
10
- name: string;
11
- type: MetaType;
12
- data: string[];
13
- }
14
-
15
- export interface Feature {
16
- name: string;
17
- dataTypes: DataType[];
18
- flowTypes: FlowType[];
19
- runtimeFunctions: RuntimeFunctionDefinition[];
20
- }
package/index.js DELETED
@@ -1,3 +0,0 @@
1
- import {Definition} from './src/parser';
2
-
3
- export {Definition};
package/src/parser.js DELETED
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Definition = void 0;
4
- const reader_1 = require("./reader");
5
- const index_1 = require("../index");
6
- const Definition = (rootPath) => {
7
- const meta = (0, reader_1.Reader)(rootPath);
8
- if (!meta)
9
- return [];
10
- const features = [];
11
- for (const m of meta) {
12
- let feature = features.find((f) => f.name === m.name);
13
- if (feature) {
14
- appendMeta(feature, m);
15
- }
16
- else {
17
- feature = {
18
- name: m.name,
19
- dataTypes: [],
20
- flowTypes: [],
21
- runtimeFunctions: [],
22
- };
23
- appendMeta(feature, m);
24
- features.push(feature);
25
- }
26
- }
27
- return features;
28
- };
29
- exports.Definition = Definition;
30
- function appendMeta(feature, meta) {
31
- for (const definition of meta.data) {
32
- try {
33
- switch (meta.type) {
34
- case index_1.MetaType.DataType: {
35
- const parsed = JSON.parse(definition);
36
- feature.dataTypes.push(parsed);
37
- break;
38
- }
39
- case index_1.MetaType.FlowType: {
40
- const parsed = JSON.parse(definition);
41
- feature.flowTypes.push(parsed);
42
- break;
43
- }
44
- case index_1.MetaType.RuntimeFunction: {
45
- const parsed = JSON.parse(definition);
46
- feature.runtimeFunctions.push(parsed);
47
- break;
48
- }
49
- }
50
- }
51
- catch (err) {
52
- console.error(`Error parsing ${meta.type} ${meta.name}:`, err);
53
- }
54
- }
55
- }
package/src/parser.ts DELETED
@@ -1,54 +0,0 @@
1
- import {Reader} from './reader';
2
- import {DataType, FlowType, RuntimeFunctionDefinition} from "@code0-tech/sagittarius-graphql-types";
3
- import {Feature, Meta, MetaType} from "../index";
4
-
5
- export const Definition = (rootPath: string): Feature[] => {
6
- const meta = Reader(rootPath);
7
- if (!meta) return [];
8
- const features: Feature[] = [];
9
-
10
- for (const m of meta) {
11
- let feature = features.find((f) => f.name === m.name);
12
-
13
- if (feature) {
14
- appendMeta(feature, m);
15
- } else {
16
- feature = {
17
- name: m.name,
18
- dataTypes: [],
19
- flowTypes: [],
20
- runtimeFunctions: [],
21
- };
22
- appendMeta(feature, m);
23
- features.push(feature);
24
- }
25
- }
26
-
27
- return features;
28
- }
29
-
30
- function appendMeta(feature: Feature, meta: Meta): void {
31
- for (const definition of meta.data) {
32
- try {
33
- switch (meta.type) {
34
- case MetaType.DataType: {
35
- const parsed = JSON.parse(definition) as DataType;
36
- feature.dataTypes.push(parsed);
37
- break;
38
- }
39
- case MetaType.FlowType: {
40
- const parsed = JSON.parse(definition) as FlowType;
41
- feature.flowTypes.push(parsed);
42
- break;
43
- }
44
- case MetaType.RuntimeFunction: {
45
- const parsed = JSON.parse(definition) as RuntimeFunctionDefinition;
46
- feature.runtimeFunctions.push(parsed);
47
- break;
48
- }
49
- }
50
- } catch (err: any) {
51
- console.error(`Error parsing ${meta.type} ${meta.name}:`, err);
52
- }
53
- }
54
- }
package/src/reader.js DELETED
@@ -1,126 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Reader = void 0;
37
- const fs = __importStar(require("fs"));
38
- const path = __importStar(require("path"));
39
- const index_1 = require("../index");
40
- const Reader = (rootPath) => {
41
- const result = [];
42
- try {
43
- const features = fs.readdirSync(rootPath, { withFileTypes: true });
44
- for (const featureDirent of features) {
45
- if (!featureDirent.isDirectory())
46
- continue;
47
- const featurePath = path.join(rootPath, featureDirent.name);
48
- const featureName = featureDirent.name;
49
- const typeDirs = fs.readdirSync(featurePath, { withFileTypes: true });
50
- for (const typeDirent of typeDirs) {
51
- if (!typeDirent.isDirectory())
52
- continue;
53
- const metaType = matchMetaType(typeDirent.name);
54
- if (!metaType)
55
- continue;
56
- const typePath = path.join(featurePath, typeDirent.name);
57
- const definitions = fs.readdirSync(typePath, { withFileTypes: true });
58
- for (const def of definitions) {
59
- const defPath = path.join(typePath, def.name);
60
- if (def.isFile()) {
61
- const meta = MetaReader(featureName, metaType, defPath);
62
- if (meta)
63
- result.push(meta);
64
- }
65
- else if (def.isDirectory()) {
66
- const subDefinitions = fs.readdirSync(defPath, { withFileTypes: true });
67
- for (const subDef of subDefinitions) {
68
- const subPath = path.join(defPath, subDef.name);
69
- if (!subDef.isFile())
70
- continue;
71
- const meta = MetaReader(featureName, metaType, subPath);
72
- if (meta)
73
- result.push(meta);
74
- }
75
- }
76
- }
77
- }
78
- }
79
- return result;
80
- }
81
- catch (err) {
82
- console.error(`Error reading path ${rootPath}:`, err);
83
- return [];
84
- }
85
- };
86
- exports.Reader = Reader;
87
- const MetaReader = (name, type, filePath) => {
88
- let content;
89
- try {
90
- content = fs.readFileSync(filePath, 'utf-8');
91
- }
92
- catch (err) {
93
- console.error(`Error reading file: ${filePath}`, err);
94
- return null;
95
- }
96
- const lines = content.split('\n');
97
- let insideCode = false;
98
- const currentBlock = [];
99
- const codeSnippets = [];
100
- for (const line of lines) {
101
- if (line.includes('```')) {
102
- insideCode = !insideCode;
103
- if (!insideCode) {
104
- codeSnippets.push(currentBlock.join(' '));
105
- currentBlock.length = 0;
106
- }
107
- continue;
108
- }
109
- if (insideCode) {
110
- currentBlock.push(line);
111
- }
112
- }
113
- return { name, type, data: codeSnippets };
114
- };
115
- function matchMetaType(name) {
116
- switch (name) {
117
- case 'flow_type':
118
- return index_1.MetaType.FlowType;
119
- case 'data_type':
120
- return index_1.MetaType.DataType;
121
- case 'runtime_definition':
122
- return index_1.MetaType.RuntimeFunction;
123
- default:
124
- return null;
125
- }
126
- }
package/src/reader.ts DELETED
@@ -1,101 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import {Meta, MetaType} from "../index";
4
-
5
- export const Reader = (rootPath: string): Meta[] => {
6
- const result: Meta[] = [];
7
-
8
- try {
9
- const features = fs.readdirSync(rootPath, { withFileTypes: true });
10
-
11
- for (const featureDirent of features) {
12
- if (!featureDirent.isDirectory()) continue;
13
-
14
- const featurePath = path.join(rootPath, featureDirent.name);
15
- const featureName = featureDirent.name;
16
-
17
- const typeDirs = fs.readdirSync(featurePath, { withFileTypes: true });
18
-
19
- for (const typeDirent of typeDirs) {
20
- if (!typeDirent.isDirectory()) continue;
21
-
22
- const metaType = matchMetaType(typeDirent.name);
23
- if (!metaType) continue;
24
-
25
- const typePath = path.join(featurePath, typeDirent.name);
26
- const definitions = fs.readdirSync(typePath, { withFileTypes: true });
27
-
28
- for (const def of definitions) {
29
- const defPath = path.join(typePath, def.name);
30
-
31
- if (def.isFile()) {
32
- const meta = MetaReader(featureName, metaType, defPath);
33
- if (meta) result.push(meta);
34
- } else if (def.isDirectory()) {
35
- const subDefinitions = fs.readdirSync(defPath, { withFileTypes: true });
36
-
37
- for (const subDef of subDefinitions) {
38
- const subPath = path.join(defPath, subDef.name);
39
- if (!subDef.isFile()) continue;
40
-
41
- const meta = MetaReader(featureName, metaType, subPath);
42
- if (meta) result.push(meta);
43
- }
44
- }
45
- }
46
- }
47
- }
48
-
49
- return result
50
- } catch (err) {
51
- console.error(`Error reading path ${rootPath}:`, err);
52
- return [];
53
- }
54
- }
55
-
56
- const MetaReader = (name: string, type: MetaType, filePath: string): Meta | null => {
57
- let content: string;
58
-
59
- try {
60
- content = fs.readFileSync(filePath, 'utf-8');
61
- } catch (err) {
62
- console.error(`Error reading file: ${filePath}`, err);
63
- return null;
64
- }
65
-
66
- const lines = content.split('\n');
67
- let insideCode = false;
68
- const currentBlock: string[] = [];
69
- const codeSnippets: string[] = [];
70
-
71
- for (const line of lines) {
72
- if (line.includes('```')) {
73
- insideCode = !insideCode;
74
-
75
- if (!insideCode) {
76
- codeSnippets.push(currentBlock.join(' '));
77
- currentBlock.length = 0;
78
- }
79
- continue;
80
- }
81
-
82
- if (insideCode) {
83
- currentBlock.push(line);
84
- }
85
- }
86
-
87
- return { name, type, data: codeSnippets };
88
- }
89
-
90
- function matchMetaType(name: string): MetaType | null {
91
- switch (name) {
92
- case 'flow_type':
93
- return MetaType.FlowType;
94
- case 'data_type':
95
- return MetaType.DataType;
96
- case 'runtime_definition':
97
- return MetaType.RuntimeFunction;
98
- default:
99
- return null;
100
- }
101
- }