origamic 0.1.0
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/.prettierrc +4 -0
- package/eslint.config.mjs +37 -0
- package/package.json +34 -0
- package/pre_commit.sh +10 -0
- package/pre_commit_setup.sh +32 -0
- package/src/TODO +1 -0
- package/src/index.ts +1 -0
- package/src/parser.test.ts +1567 -0
- package/src/parser.ts +1359 -0
- package/src/types.ts +142 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.eslint.json +4 -0
- package/tsconfig.json +24 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
export interface Result<T> {
|
|
2
|
+
readonly value: T;
|
|
3
|
+
readonly errors: Error[];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface TemplateFile {
|
|
7
|
+
readonly templates: readonly Template[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface Template {
|
|
11
|
+
readonly name: CodeSlice;
|
|
12
|
+
readonly variantName?: CodeSlice;
|
|
13
|
+
readonly pieces: readonly TemplatePiece[];
|
|
14
|
+
readonly parameters: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type TemplatePiece =
|
|
18
|
+
| {
|
|
19
|
+
readonly kind: "text";
|
|
20
|
+
readonly text: string;
|
|
21
|
+
}
|
|
22
|
+
| {
|
|
23
|
+
readonly kind: "expression";
|
|
24
|
+
readonly expression: string;
|
|
25
|
+
readonly hide: boolean;
|
|
26
|
+
// Indent beyond the regular template indent of the line containing "$"
|
|
27
|
+
readonly extraIndent: string;
|
|
28
|
+
}
|
|
29
|
+
| {
|
|
30
|
+
readonly kind: "schema";
|
|
31
|
+
readonly text: string;
|
|
32
|
+
readonly schema: ResponseSchema | null;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
readonly kind: "example";
|
|
36
|
+
readonly text: string;
|
|
37
|
+
readonly example: ResponseExample;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export interface ResponseSchema {
|
|
41
|
+
readonly codeSlice: CodeSlice;
|
|
42
|
+
readonly declarations: readonly ResponseSchemaDeclaration[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type ResponseSchemaDeclaration =
|
|
46
|
+
| {
|
|
47
|
+
readonly kind: "interface";
|
|
48
|
+
readonly name: CodeSlice;
|
|
49
|
+
readonly codeSlice: CodeSlice;
|
|
50
|
+
}
|
|
51
|
+
| {
|
|
52
|
+
readonly kind: "type";
|
|
53
|
+
readonly name: CodeSlice;
|
|
54
|
+
readonly codeSlice: CodeSlice;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export interface ResponseExample {
|
|
58
|
+
readonly codeSlice: CodeSlice;
|
|
59
|
+
readonly value: JsonValue | null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type JsonValue =
|
|
63
|
+
| JsonObject
|
|
64
|
+
| JsonArray
|
|
65
|
+
| JsonString
|
|
66
|
+
| JsonNumber
|
|
67
|
+
| JsonBoolean
|
|
68
|
+
| JsonNull
|
|
69
|
+
| JsonEllipsis;
|
|
70
|
+
|
|
71
|
+
export interface JsonObject {
|
|
72
|
+
readonly kind: "object";
|
|
73
|
+
readonly codeSlice: CodeSlice;
|
|
74
|
+
readonly entries: readonly JsonObjectEntry[];
|
|
75
|
+
readonly ellipsis?: JsonEllipsis;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface JsonObjectEntry {
|
|
79
|
+
readonly key: JsonString;
|
|
80
|
+
readonly value: JsonValue;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface JsonArray {
|
|
84
|
+
readonly kind: "array";
|
|
85
|
+
readonly codeSlice: CodeSlice;
|
|
86
|
+
readonly values: readonly JsonValue[];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface JsonString {
|
|
90
|
+
readonly kind: "string";
|
|
91
|
+
readonly codeSlice: CodeSlice;
|
|
92
|
+
readonly value: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface JsonNumber {
|
|
96
|
+
readonly kind: "number";
|
|
97
|
+
readonly codeSlice: CodeSlice;
|
|
98
|
+
readonly value: number;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface JsonBoolean {
|
|
102
|
+
readonly kind: "boolean";
|
|
103
|
+
readonly codeSlice: CodeSlice;
|
|
104
|
+
readonly value: boolean;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface JsonNull {
|
|
108
|
+
readonly kind: "null";
|
|
109
|
+
readonly codeSlice: CodeSlice;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface JsonEllipsis {
|
|
113
|
+
readonly kind: "ellipsis";
|
|
114
|
+
readonly codeSlice: CodeSlice;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface CodeSlice {
|
|
118
|
+
readonly text: string;
|
|
119
|
+
readonly startPos: number;
|
|
120
|
+
readonly endPos: number;
|
|
121
|
+
readonly line: Line;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface Line {
|
|
125
|
+
/// 0-based line number
|
|
126
|
+
readonly lineNumber: number;
|
|
127
|
+
readonly startPos: number;
|
|
128
|
+
readonly text: string;
|
|
129
|
+
readonly indent: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export type Error =
|
|
133
|
+
| {
|
|
134
|
+
readonly message: string;
|
|
135
|
+
readonly expected?: undefined;
|
|
136
|
+
readonly codeSlice: CodeSlice;
|
|
137
|
+
}
|
|
138
|
+
| {
|
|
139
|
+
readonly expected: string;
|
|
140
|
+
readonly message?: undefined;
|
|
141
|
+
readonly codeSlice: CodeSlice;
|
|
142
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"rootDir": "./src",
|
|
4
|
+
"lib": ["ES2020"],
|
|
5
|
+
"target": "ES2020",
|
|
6
|
+
"sourceMap": true,
|
|
7
|
+
"composite": true,
|
|
8
|
+
"incremental": true,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"declarationMap": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"noUncheckedIndexedAccess": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"outDir": "dist",
|
|
16
|
+
"allowUnreachableCode": false,
|
|
17
|
+
"noImplicitOverride": true,
|
|
18
|
+
"skipLibCheck": true,
|
|
19
|
+
"types": ["node"],
|
|
20
|
+
"module": "NodeNext",
|
|
21
|
+
"moduleResolution": "NodeNext"
|
|
22
|
+
},
|
|
23
|
+
"include": ["src/**/*"]
|
|
24
|
+
}
|