@lintai/sdk 0.1.3 → 0.2.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/dist/index.d.ts +47 -145
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +114 -114
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,161 +1,63 @@
|
|
|
1
|
-
export type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} | {
|
|
16
|
-
type: "calling";
|
|
17
|
-
query: QueryValue;
|
|
18
|
-
} | {
|
|
19
|
-
type: "transitivelyCalling";
|
|
20
|
-
query: QueryValue;
|
|
21
|
-
};
|
|
22
|
-
export type FunctionView = {
|
|
23
|
-
name: string;
|
|
24
|
-
kind: string;
|
|
25
|
-
filePath: string;
|
|
26
|
-
containerName: string;
|
|
27
|
-
semanticKey: string;
|
|
28
|
-
containsAwait: boolean;
|
|
29
|
-
isExported: boolean;
|
|
30
|
-
isAsync: boolean;
|
|
31
|
-
parameterCount: number;
|
|
32
|
-
returnTypeText: string;
|
|
33
|
-
parameterTypeTexts: string[];
|
|
34
|
-
sourceLocation: SourceLocation;
|
|
35
|
-
};
|
|
36
|
-
export type ImportedSymbolView = {
|
|
37
|
-
name: string;
|
|
38
|
-
kind: "default" | "namespace" | "named";
|
|
39
|
-
isTypeOnly: boolean;
|
|
40
|
-
};
|
|
41
|
-
export type ImportEdgeView = {
|
|
42
|
-
specifier: string;
|
|
43
|
-
fromPath: string;
|
|
44
|
-
toPath: string;
|
|
45
|
-
semanticKey: string;
|
|
46
|
-
importedSymbols: ImportedSymbolView[];
|
|
47
|
-
hasDefaultImport: boolean;
|
|
48
|
-
hasNamespaceImport: boolean;
|
|
49
|
-
hasNamedImports: boolean;
|
|
50
|
-
isTypeOnly: boolean;
|
|
51
|
-
sourceLocation: SourceLocation;
|
|
52
|
-
};
|
|
53
|
-
export type CallEdgeView = {
|
|
54
|
-
fromName: string;
|
|
55
|
-
toName: string;
|
|
56
|
-
fromPath: string;
|
|
57
|
-
toPath: string;
|
|
58
|
-
semanticKey: string;
|
|
59
|
-
sourceLocation: SourceLocation;
|
|
60
|
-
};
|
|
61
|
-
export type TypeRefView = {
|
|
62
|
-
name: string;
|
|
63
|
-
filePath: string;
|
|
64
|
-
targetPath: string;
|
|
65
|
-
semanticKey: string;
|
|
66
|
-
sourceLocation: SourceLocation;
|
|
67
|
-
};
|
|
68
|
-
export type AccessView = {
|
|
69
|
-
root: string;
|
|
70
|
-
accessPath: string;
|
|
71
|
-
origin: "special_form";
|
|
72
|
-
filePath: string;
|
|
73
|
-
semanticKey: string;
|
|
74
|
-
sourceLocation: SourceLocation;
|
|
75
|
-
};
|
|
76
|
-
export type SourceLocation = {
|
|
77
|
-
file: string;
|
|
78
|
-
startLine: number;
|
|
79
|
-
startColumn: number;
|
|
80
|
-
endLine: number;
|
|
81
|
-
endColumn: number;
|
|
82
|
-
};
|
|
83
|
-
export type AssertionContext = {
|
|
1
|
+
export type Fragment = {
|
|
2
|
+
readonly __lintaiKind: "fragment";
|
|
3
|
+
readonly text: string;
|
|
4
|
+
};
|
|
5
|
+
export type Name = {
|
|
6
|
+
readonly __lintaiKind: "name";
|
|
7
|
+
readonly value: string;
|
|
8
|
+
};
|
|
9
|
+
export type DlValue = string | number | Name | Fragment;
|
|
10
|
+
export type FactValue = string | number | Name;
|
|
11
|
+
export type Facts = Record<string, FactValue[][]>;
|
|
12
|
+
export type RowValue = string | number;
|
|
13
|
+
export type Row = Record<string, RowValue>;
|
|
14
|
+
export type MessageContext = {
|
|
84
15
|
assertion_id: string;
|
|
85
16
|
};
|
|
86
17
|
export type RuleContext<Env, Setup> = {
|
|
87
18
|
env: Env;
|
|
88
19
|
setup: Setup;
|
|
89
20
|
};
|
|
90
|
-
export type
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
query: QueryValue;
|
|
94
|
-
};
|
|
95
|
-
type BaseQuery = {
|
|
96
|
-
__lintaiKind: "query";
|
|
97
|
-
entity: QueryKind;
|
|
98
|
-
ops: QueryOperation[];
|
|
99
|
-
isEmpty(): AssertionValue;
|
|
100
|
-
};
|
|
101
|
-
export type FunctionsQuery = BaseQuery & {
|
|
102
|
-
entity: "functions";
|
|
103
|
-
in(pattern: string): FunctionsQuery;
|
|
104
|
-
where(predicate: Predicate<FunctionView>): FunctionsQuery;
|
|
105
|
-
calling(other: FunctionsQuery): FunctionsQuery;
|
|
106
|
-
transitivelyCalling(other: FunctionsQuery): FunctionsQuery;
|
|
107
|
-
};
|
|
108
|
-
export type ImportsQuery = BaseQuery & {
|
|
109
|
-
entity: "imports";
|
|
110
|
-
from(pattern: string): ImportsQuery;
|
|
111
|
-
to(pattern: string): ImportsQuery;
|
|
112
|
-
where(predicate: Predicate<ImportEdgeView>): ImportsQuery;
|
|
113
|
-
};
|
|
114
|
-
export type CallsQuery = BaseQuery & {
|
|
115
|
-
entity: "calls";
|
|
116
|
-
from(pattern: string): CallsQuery;
|
|
117
|
-
to(pattern: string): CallsQuery;
|
|
118
|
-
where(predicate: Predicate<CallEdgeView>): CallsQuery;
|
|
119
|
-
};
|
|
120
|
-
export type TypeRefsQuery = BaseQuery & {
|
|
121
|
-
entity: "typeRefs";
|
|
122
|
-
in(pattern: string): TypeRefsQuery;
|
|
123
|
-
where(predicate: Predicate<TypeRefView>): TypeRefsQuery;
|
|
21
|
+
export type SetupContext<Env> = {
|
|
22
|
+
env: Env;
|
|
23
|
+
workspaceRoot: string;
|
|
124
24
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
25
|
+
declare function name(value: string): Name;
|
|
26
|
+
declare function dlTag(strings: TemplateStringsArray, ...values: DlValue[]): Fragment;
|
|
27
|
+
export type Dl = typeof dlTag & {
|
|
28
|
+
readonly name: typeof name;
|
|
129
29
|
};
|
|
130
|
-
export
|
|
131
|
-
type
|
|
30
|
+
export declare const dl: Dl;
|
|
31
|
+
export type ProgramInput<Env, Setup> = Fragment | ((ctx: RuleContext<Env, Setup>) => Fragment);
|
|
32
|
+
type RuleSpec<Env, Setup> = {
|
|
132
33
|
id: string;
|
|
133
34
|
versionValue?: number;
|
|
134
|
-
setupFn?: (
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
messageFn?: (
|
|
140
|
-
};
|
|
141
|
-
declare class RuleDefinition<Env, Setup
|
|
35
|
+
setupFn?: (ctx: SetupContext<Env>) => Setup | Promise<Setup>;
|
|
36
|
+
factsFn?: (ctx: RuleContext<Env, Setup>) => Facts;
|
|
37
|
+
programValue?: ProgramInput<Env, Setup>;
|
|
38
|
+
reportPredicates?: readonly string[];
|
|
39
|
+
expectNonEmptyPredicates?: readonly string[];
|
|
40
|
+
messageFn?: (row: Row, ctx: MessageContext) => string;
|
|
41
|
+
};
|
|
42
|
+
export declare class RuleDefinition<Env, Setup> {
|
|
142
43
|
private readonly spec;
|
|
143
44
|
readonly id: string;
|
|
144
45
|
readonly versionValue?: number;
|
|
145
|
-
readonly setupFn?:
|
|
146
|
-
readonly
|
|
147
|
-
readonly
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
46
|
+
readonly setupFn?: RuleSpec<Env, Setup>["setupFn"];
|
|
47
|
+
readonly factsFn?: RuleSpec<Env, Setup>["factsFn"];
|
|
48
|
+
readonly programValue?: RuleSpec<Env, Setup>["programValue"];
|
|
49
|
+
readonly reportPredicates?: readonly string[];
|
|
50
|
+
readonly expectNonEmptyPredicates?: readonly string[];
|
|
51
|
+
readonly messageFn?: RuleSpec<Env, Setup>["messageFn"];
|
|
52
|
+
constructor(spec: RuleSpec<Env, Setup>);
|
|
53
|
+
version(versionValue: number): RuleDefinition<Env, Setup>;
|
|
54
|
+
setup<NextSetup>(setupFn: (ctx: SetupContext<Env>) => NextSetup | Promise<NextSetup>): RuleDefinition<Env, Awaited<NextSetup>>;
|
|
55
|
+
facts(factsFn: (ctx: RuleContext<Env, Setup>) => Facts): RuleDefinition<Env, Setup>;
|
|
56
|
+
program(programValue: ProgramInput<Env, Setup>): RuleDefinition<Env, Setup>;
|
|
57
|
+
report(...predicates: string[]): RuleDefinition<Env, Setup>;
|
|
58
|
+
expectNonEmpty(...predicates: string[]): RuleDefinition<Env, Setup>;
|
|
59
|
+
message(messageFn: (row: Row, ctx: MessageContext) => string): RuleDefinition<Env, Setup>;
|
|
153
60
|
}
|
|
154
|
-
export declare function rule<Env = Record<string, any>, Setup = Record<string, never
|
|
155
|
-
export declare function functions(): FunctionsQuery;
|
|
156
|
-
export declare function imports(): ImportsQuery;
|
|
157
|
-
export declare function calls(): CallsQuery;
|
|
158
|
-
export declare function typeRefs(): TypeRefsQuery;
|
|
159
|
-
export declare function accesses(): AccessesQuery;
|
|
61
|
+
export declare function rule<Env = Record<string, any>, Setup = Record<string, never>>(id: string): RuleDefinition<Env, Setup>;
|
|
160
62
|
export {};
|
|
161
63
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG;IACtB,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG;IAClB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM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
|
4
|
+
value !== null &&
|
|
5
|
+
value.__lintaiKind === kind);
|
|
6
|
+
}
|
|
7
|
+
function describe(value) {
|
|
8
|
+
if (value === null)
|
|
9
|
+
return "null";
|
|
10
|
+
if (Array.isArray(value))
|
|
11
|
+
return "an array";
|
|
12
|
+
return typeof value;
|
|
13
|
+
}
|
|
14
|
+
function hex(code, width) {
|
|
15
|
+
return code.toString(16).padStart(width, "0");
|
|
16
|
+
}
|
|
17
|
+
function escapeString(value) {
|
|
18
|
+
let result = '"';
|
|
19
|
+
for (const char of value) {
|
|
20
|
+
const code = char.codePointAt(0) ?? 0;
|
|
21
|
+
switch (char) {
|
|
22
|
+
case "\\":
|
|
23
|
+
result += "\\\\";
|
|
24
|
+
break;
|
|
25
|
+
case '"':
|
|
26
|
+
result += '\\"';
|
|
27
|
+
break;
|
|
28
|
+
case "'":
|
|
29
|
+
result += "\\'";
|
|
30
|
+
break;
|
|
31
|
+
case "\n":
|
|
32
|
+
result += "\\n";
|
|
33
|
+
break;
|
|
34
|
+
case "\t":
|
|
35
|
+
result += "\\t";
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
if (code < 0x20 || code === 0x7f) {
|
|
39
|
+
result += `\\x${hex(code, 2)}`;
|
|
40
|
+
}
|
|
41
|
+
else if (code > 0x7e) {
|
|
42
|
+
result += `\\u{${hex(code, 4)}}`;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
result += char;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return `${result}"`;
|
|
50
|
+
}
|
|
51
|
+
function formatNumber(value) {
|
|
52
|
+
if (!Number.isFinite(value)) {
|
|
53
|
+
throw new TypeError(`dl: cannot interpolate non-finite number ${value}`);
|
|
54
|
+
}
|
|
55
|
+
if (Number.isInteger(value)) {
|
|
56
|
+
if (!Number.isSafeInteger(value)) {
|
|
57
|
+
throw new TypeError(`dl: integer ${value} is outside the safe integer range`);
|
|
58
|
+
}
|
|
59
|
+
return String(value);
|
|
60
|
+
}
|
|
61
|
+
const text = String(value);
|
|
62
|
+
if (text.includes("e")) {
|
|
63
|
+
throw new TypeError(`dl: cannot interpolate ${value}; use a number without an exponent`);
|
|
64
|
+
}
|
|
65
|
+
return text;
|
|
66
|
+
}
|
|
67
|
+
function formatValue(value) {
|
|
68
|
+
if (typeof value === "string")
|
|
69
|
+
return escapeString(value);
|
|
70
|
+
if (typeof value === "number")
|
|
71
|
+
return formatNumber(value);
|
|
72
|
+
if (isTagged(value, "fragment"))
|
|
73
|
+
return value.text;
|
|
74
|
+
if (isTagged(value, "name"))
|
|
75
|
+
return `/${value.value}`;
|
|
76
|
+
throw new TypeError(`dl: cannot interpolate ${describe(value)}; use a string, a finite number, dl.name() or a dl fragment`);
|
|
77
|
+
}
|
|
78
|
+
function name(value) {
|
|
79
|
+
if (typeof value !== "string" || !namePattern.test(value)) {
|
|
80
|
+
throw new TypeError(`dl.name: ${JSON.stringify(value)} is not a valid name; it must match ${namePattern}`);
|
|
81
|
+
}
|
|
82
|
+
return Object.freeze({ __lintaiKind: "name", value });
|
|
83
|
+
}
|
|
84
|
+
function dlTag(strings, ...values) {
|
|
85
|
+
let text = strings[0] ?? "";
|
|
86
|
+
for (let index = 0; index < values.length; index++) {
|
|
87
|
+
text += formatValue(values[index]);
|
|
88
|
+
text += strings[index + 1] ?? "";
|
|
89
|
+
}
|
|
90
|
+
return Object.freeze({ __lintaiKind: "fragment", text });
|
|
91
|
+
}
|
|
92
|
+
export const dl = Object.defineProperty((strings, ...values) => dlTag(strings, ...values), "name", { value: name, enumerable: true });
|
|
93
|
+
export class RuleDefinition {
|
|
2
94
|
spec;
|
|
3
95
|
id;
|
|
4
96
|
versionValue;
|
|
5
97
|
setupFn;
|
|
6
|
-
|
|
98
|
+
factsFn;
|
|
99
|
+
programValue;
|
|
100
|
+
reportPredicates;
|
|
101
|
+
expectNonEmptyPredicates;
|
|
7
102
|
messageFn;
|
|
8
103
|
constructor(spec) {
|
|
9
104
|
this.spec = spec;
|
|
10
105
|
this.id = spec.id;
|
|
11
106
|
this.versionValue = spec.versionValue;
|
|
12
107
|
this.setupFn = spec.setupFn;
|
|
13
|
-
this.
|
|
108
|
+
this.factsFn = spec.factsFn;
|
|
109
|
+
this.programValue = spec.programValue;
|
|
110
|
+
this.reportPredicates = spec.reportPredicates;
|
|
111
|
+
this.expectNonEmptyPredicates = spec.expectNonEmptyPredicates;
|
|
14
112
|
this.messageFn = spec.messageFn;
|
|
15
113
|
}
|
|
16
114
|
version(versionValue) {
|
|
@@ -19,124 +117,26 @@ class RuleDefinition {
|
|
|
19
117
|
setup(setupFn) {
|
|
20
118
|
return new RuleDefinition({
|
|
21
119
|
...this.spec,
|
|
22
|
-
setupFn,
|
|
120
|
+
setupFn: setupFn,
|
|
23
121
|
});
|
|
24
122
|
}
|
|
25
|
-
|
|
26
|
-
return new RuleDefinition({
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
123
|
+
facts(factsFn) {
|
|
124
|
+
return new RuleDefinition({ ...this.spec, factsFn });
|
|
125
|
+
}
|
|
126
|
+
program(programValue) {
|
|
127
|
+
return new RuleDefinition({ ...this.spec, programValue });
|
|
128
|
+
}
|
|
129
|
+
report(...predicates) {
|
|
130
|
+
return new RuleDefinition({ ...this.spec, reportPredicates: predicates });
|
|
131
|
+
}
|
|
132
|
+
expectNonEmpty(...predicates) {
|
|
133
|
+
return new RuleDefinition({ ...this.spec, expectNonEmptyPredicates: predicates });
|
|
30
134
|
}
|
|
31
135
|
message(messageFn) {
|
|
32
|
-
return new RuleDefinition({
|
|
33
|
-
...this.spec,
|
|
34
|
-
messageFn,
|
|
35
|
-
});
|
|
136
|
+
return new RuleDefinition({ ...this.spec, messageFn });
|
|
36
137
|
}
|
|
37
138
|
}
|
|
38
|
-
function createBaseQuery(entity, ops) {
|
|
39
|
-
return {
|
|
40
|
-
__lintaiKind: "query",
|
|
41
|
-
entity,
|
|
42
|
-
ops,
|
|
43
|
-
isEmpty() {
|
|
44
|
-
return {
|
|
45
|
-
__lintaiKind: "assertion",
|
|
46
|
-
terminal: "isEmpty",
|
|
47
|
-
query: this,
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function createFunctionsQuery(ops = []) {
|
|
53
|
-
return {
|
|
54
|
-
...createBaseQuery("functions", ops),
|
|
55
|
-
entity: "functions",
|
|
56
|
-
in(pattern) {
|
|
57
|
-
return createFunctionsQuery([...ops, { type: "in", value: pattern }]);
|
|
58
|
-
},
|
|
59
|
-
where(predicate) {
|
|
60
|
-
return createFunctionsQuery([...ops, { type: "where", handler: predicate }]);
|
|
61
|
-
},
|
|
62
|
-
calling(other) {
|
|
63
|
-
return createFunctionsQuery([...ops, { type: "calling", query: other }]);
|
|
64
|
-
},
|
|
65
|
-
transitivelyCalling(other) {
|
|
66
|
-
return createFunctionsQuery([...ops, { type: "transitivelyCalling", query: other }]);
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function createImportsQuery(ops = []) {
|
|
71
|
-
return {
|
|
72
|
-
...createBaseQuery("imports", ops),
|
|
73
|
-
entity: "imports",
|
|
74
|
-
from(pattern) {
|
|
75
|
-
return createImportsQuery([...ops, { type: "from", value: pattern }]);
|
|
76
|
-
},
|
|
77
|
-
to(pattern) {
|
|
78
|
-
return createImportsQuery([...ops, { type: "to", value: pattern }]);
|
|
79
|
-
},
|
|
80
|
-
where(predicate) {
|
|
81
|
-
return createImportsQuery([...ops, { type: "where", handler: predicate }]);
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
function createCallsQuery(ops = []) {
|
|
86
|
-
return {
|
|
87
|
-
...createBaseQuery("calls", ops),
|
|
88
|
-
entity: "calls",
|
|
89
|
-
from(pattern) {
|
|
90
|
-
return createCallsQuery([...ops, { type: "from", value: pattern }]);
|
|
91
|
-
},
|
|
92
|
-
to(pattern) {
|
|
93
|
-
return createCallsQuery([...ops, { type: "to", value: pattern }]);
|
|
94
|
-
},
|
|
95
|
-
where(predicate) {
|
|
96
|
-
return createCallsQuery([...ops, { type: "where", handler: predicate }]);
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
function createTypeRefsQuery(ops = []) {
|
|
101
|
-
return {
|
|
102
|
-
...createBaseQuery("typeRefs", ops),
|
|
103
|
-
entity: "typeRefs",
|
|
104
|
-
in(pattern) {
|
|
105
|
-
return createTypeRefsQuery([...ops, { type: "in", value: pattern }]);
|
|
106
|
-
},
|
|
107
|
-
where(predicate) {
|
|
108
|
-
return createTypeRefsQuery([...ops, { type: "where", handler: predicate }]);
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function createAccessesQuery(ops = []) {
|
|
113
|
-
return {
|
|
114
|
-
...createBaseQuery("accesses", ops),
|
|
115
|
-
entity: "accesses",
|
|
116
|
-
in(pattern) {
|
|
117
|
-
return createAccessesQuery([...ops, { type: "in", value: pattern }]);
|
|
118
|
-
},
|
|
119
|
-
where(predicate) {
|
|
120
|
-
return createAccessesQuery([...ops, { type: "where", handler: predicate }]);
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
139
|
export function rule(id) {
|
|
125
140
|
return new RuleDefinition({ id });
|
|
126
141
|
}
|
|
127
|
-
export function functions() {
|
|
128
|
-
return createFunctionsQuery();
|
|
129
|
-
}
|
|
130
|
-
export function imports() {
|
|
131
|
-
return createImportsQuery();
|
|
132
|
-
}
|
|
133
|
-
export function calls() {
|
|
134
|
-
return createCallsQuery();
|
|
135
|
-
}
|
|
136
|
-
export function typeRefs() {
|
|
137
|
-
return createTypeRefsQuery();
|
|
138
|
-
}
|
|
139
|
-
export function accesses() {
|
|
140
|
-
return createAccessesQuery();
|
|
141
|
-
}
|
|
142
142
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkCA,MAAM,WAAW,GAAG,kCAAkC,CAAC;AAEvD,SAAS,QAAQ,CAAC,KAAc,EAAE,IAAyB;IAC1D,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACb,KAAoC,CAAC,YAAY,KAAK,IAAI,CAC3D,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC/B,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,UAAU,CAAC;IAC5C,OAAO,OAAO,KAAK,CAAC;AACrB,CAAC;AAED,SAAS,GAAG,CAAC,IAAY,EAAE,KAAa;IACvC,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,YAAY,CAAC,KAAa;IAClC,IAAI,MAAM,GAAG,GAAG,CAAC;IACjB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACtC,QAAQ,IAAI,EAAE,CAAC;YACd,KAAK,IAAI;gBACR,MAAM,IAAI,MAAM,CAAC;gBACjB,MAAM;YACP,KAAK,GAAG;gBACP,MAAM,IAAI,KAAK,CAAC;gBAChB,MAAM;YACP,KAAK,GAAG;gBACP,MAAM,IAAI,KAAK,CAAC;gBAChB,MAAM;YACP,KAAK,IAAI;gBACR,MAAM,IAAI,KAAK,CAAC;gBAChB,MAAM;YACP,KAAK,IAAI;gBACR,MAAM,IAAI,KAAK,CAAC;gBAChB,MAAM;YACP;gBACC,IAAI,IAAI,GAAG,IA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OAAO,IAAI,cAAc,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,CAAC,GAAG,UAAoB;QAC7B,OAAO,IAAI,cAAc,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,gBAAgB,EAAE,UAAU,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED,cAAc,CAAC,GAAG,UAAoB;QACrC,OAAO,IAAI,cAAc,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,wBAAwB,EAAE,UAAU,EAAE,CAAC,CAAC;IACnF,CAAC;IAED,OAAO,CAAC,SAAoD;QAC3D,OAAO,IAAI,cAAc,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IACxD,CAAC;CACD;AAED,MAAM,UAAU,IAAI,CACnB,EAAU;IAEV,OAAO,IAAI,cAAc,CAAa,EAAE,EAAE,EAAE,CAAC,CAAC;AAC/C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lintai/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"url": "https://github.com/bigbizze/lintai/issues"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
|
-
"dist"
|
|
16
|
+
"dist",
|
|
17
|
+
"!dist/**/*.test.*"
|
|
17
18
|
],
|
|
18
19
|
"exports": {
|
|
19
20
|
".": {
|
|
@@ -35,6 +36,7 @@
|
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|
|
37
38
|
"build": "tsc",
|
|
38
|
-
"dev": "tsc --watch"
|
|
39
|
+
"dev": "tsc --watch",
|
|
40
|
+
"test": "node --test 'dist/**/*.test.js'"
|
|
39
41
|
}
|
|
40
42
|
}
|