@romaintaillandier1978/dotenv-never-lies 1.1.1 → 1.3.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/README.md +103 -42
- package/dist/cli/commands/assert.d.ts +3 -4
- package/dist/cli/commands/assert.d.ts.map +1 -1
- package/dist/cli/commands/explain.d.ts +2 -3
- package/dist/cli/commands/explain.d.ts.map +1 -1
- package/dist/cli/commands/export.d.ts +4 -3
- package/dist/cli/commands/export.d.ts.map +1 -1
- package/dist/cli/commands/export.js +46 -0
- package/dist/cli/commands/generate.d.ts +2 -2
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/infer.d.ts +15 -0
- package/dist/cli/commands/infer.d.ts.map +1 -0
- package/dist/cli/commands/infer.js +86 -0
- package/dist/cli/commands/init.d.ts +15 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +30 -0
- package/dist/cli/commands/program.d.ts +4 -0
- package/dist/cli/commands/program.d.ts.map +1 -0
- package/dist/cli/commands/program.js +1 -0
- package/dist/cli/index.js +74 -30
- package/dist/cli/utils/infer-schema.d.ts +2 -2
- package/dist/cli/utils/infer-schema.d.ts.map +1 -1
- package/dist/cli/utils/infer-schema.js +20 -22
- package/dist/cli/utils/printer.d.ts +2 -0
- package/dist/cli/utils/printer.d.ts.map +1 -1
- package/dist/cli/utils/printer.js +104 -1
- package/dist/core.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/infer/__tests__/port-vs-version.test.d.ts +2 -0
- package/dist/infer/__tests__/port-vs-version.test.d.ts.map +1 -0
- package/dist/infer/__tests__/port-vs-version.test.js +32 -0
- package/dist/infer/__tests__/rules/basic.test.d.ts +2 -0
- package/dist/infer/__tests__/rules/basic.test.d.ts.map +1 -0
- package/dist/infer/__tests__/rules/basic.test.js +85 -0
- package/dist/infer/__tests__/rules/boolean.test.d.ts +2 -0
- package/dist/infer/__tests__/rules/boolean.test.d.ts.map +1 -0
- package/dist/infer/__tests__/rules/boolean.test.js +34 -0
- package/dist/infer/__tests__/rules/duration.test.d.ts +2 -0
- package/dist/infer/__tests__/rules/duration.test.d.ts.map +1 -0
- package/dist/infer/__tests__/rules/duration.test.js +24 -0
- package/dist/infer/__tests__/rules/ip.test.d.ts +2 -0
- package/dist/infer/__tests__/rules/ip.test.d.ts.map +1 -0
- package/dist/infer/__tests__/rules/ip.test.js +24 -0
- package/dist/infer/__tests__/rules/json.test.d.ts +2 -0
- package/dist/infer/__tests__/rules/json.test.d.ts.map +1 -0
- package/dist/infer/__tests__/rules/json.test.js +38 -0
- package/dist/infer/__tests__/rules/list.test.d.ts +2 -0
- package/dist/infer/__tests__/rules/list.test.d.ts.map +1 -0
- package/dist/infer/__tests__/rules/list.test.js +130 -0
- package/dist/infer/__tests__/rules/port.test.d.ts +2 -0
- package/dist/infer/__tests__/rules/port.test.d.ts.map +1 -0
- package/dist/infer/__tests__/rules/port.test.js +24 -0
- package/dist/infer/__tests__/rules/url.test.d.ts +2 -0
- package/dist/infer/__tests__/rules/url.test.d.ts.map +1 -0
- package/dist/infer/__tests__/rules/url.test.js +39 -0
- package/dist/infer/__tests__/rules/version.test.d.ts +2 -0
- package/dist/infer/__tests__/rules/version.test.d.ts.map +1 -0
- package/dist/infer/__tests__/rules/version.test.js +37 -0
- package/dist/infer/generated/basic.d.ts +8 -0
- package/dist/infer/generated/basic.d.ts.map +1 -0
- package/dist/infer/generated/basic.js +24 -0
- package/dist/infer/generated/boolean.d.ts +3 -0
- package/dist/infer/generated/boolean.d.ts.map +1 -0
- package/dist/infer/generated/boolean.js +9 -0
- package/dist/infer/generated/duration.d.ts +3 -0
- package/dist/infer/generated/duration.d.ts.map +1 -0
- package/dist/infer/generated/duration.js +9 -0
- package/dist/infer/generated/ip.d.ts +3 -0
- package/dist/infer/generated/ip.d.ts.map +1 -0
- package/dist/infer/generated/ip.js +9 -0
- package/dist/infer/generated/json.d.ts +4 -0
- package/dist/infer/generated/json.d.ts.map +1 -0
- package/dist/infer/generated/json.js +10 -0
- package/dist/infer/generated/list.d.ts +8 -0
- package/dist/infer/generated/list.d.ts.map +1 -0
- package/dist/infer/generated/list.js +49 -0
- package/dist/infer/generated/port.d.ts +4 -0
- package/dist/infer/generated/port.d.ts.map +1 -0
- package/dist/infer/generated/port.js +10 -0
- package/dist/infer/generated/url.d.ts +14 -0
- package/dist/infer/generated/url.d.ts.map +1 -0
- package/dist/infer/generated/url.js +30 -0
- package/dist/infer/generated/version.d.ts +4 -0
- package/dist/infer/generated/version.d.ts.map +1 -0
- package/dist/infer/generated/version.js +10 -0
- package/dist/infer/helpers.d.ts +11 -0
- package/dist/infer/helpers.d.ts.map +1 -0
- package/dist/infer/helpers.js +41 -0
- package/dist/infer/index.d.ts +4 -0
- package/dist/infer/index.d.ts.map +1 -0
- package/dist/infer/index.js +35 -0
- package/dist/infer/rules/basic.d.ts +11 -0
- package/dist/infer/rules/basic.d.ts.map +1 -0
- package/dist/infer/rules/basic.js +90 -0
- package/dist/infer/rules/boolean.d.ts +3 -0
- package/dist/infer/rules/boolean.d.ts.map +1 -0
- package/dist/infer/rules/boolean.js +25 -0
- package/dist/infer/rules/duration.d.ts +3 -0
- package/dist/infer/rules/duration.d.ts.map +1 -0
- package/dist/infer/rules/duration.js +25 -0
- package/dist/infer/rules/ip.d.ts +3 -0
- package/dist/infer/rules/ip.d.ts.map +1 -0
- package/dist/infer/rules/ip.js +25 -0
- package/dist/infer/rules/json.d.ts +3 -0
- package/dist/infer/rules/json.d.ts.map +1 -0
- package/dist/infer/rules/json.js +59 -0
- package/dist/infer/rules/list.d.ts +12 -0
- package/dist/infer/rules/list.d.ts.map +1 -0
- package/dist/infer/rules/list.js +221 -0
- package/dist/infer/rules/port.d.ts +3 -0
- package/dist/infer/rules/port.d.ts.map +1 -0
- package/dist/infer/rules/port.js +30 -0
- package/dist/infer/rules/url.d.ts +4 -0
- package/dist/infer/rules/url.d.ts.map +1 -0
- package/dist/infer/rules/url.js +143 -0
- package/dist/infer/rules/version.d.ts +3 -0
- package/dist/infer/rules/version.d.ts.map +1 -0
- package/dist/infer/rules/version.js +26 -0
- package/dist/infer/types.d.ts +87 -0
- package/dist/infer/types.d.ts.map +1 -0
- package/dist/infer/types.js +1 -0
- package/dist/infer-rules/basic.d.ts +5 -0
- package/dist/infer-rules/basic.d.ts.map +1 -0
- package/dist/infer-rules/basic.js +48 -0
- package/dist/infer-rules/boolean.d.ts +3 -0
- package/dist/infer-rules/boolean.d.ts.map +1 -0
- package/dist/infer-rules/boolean.js +25 -0
- package/dist/infer-rules/dotted.d.ts +4 -0
- package/dist/infer-rules/dotted.d.ts.map +1 -0
- package/dist/infer-rules/dotted.js +48 -0
- package/dist/infer-rules/duration.d.ts +3 -0
- package/dist/infer-rules/duration.d.ts.map +1 -0
- package/dist/infer-rules/duration.js +25 -0
- package/dist/infer-rules/index.d.ts +50 -0
- package/dist/infer-rules/index.d.ts.map +1 -0
- package/dist/infer-rules/index.js +42 -0
- package/dist/infer-rules/json.d.ts +3 -0
- package/dist/infer-rules/json.d.ts.map +1 -0
- package/dist/infer-rules/json.js +50 -0
- package/dist/infer-rules/list.d.ts +5 -0
- package/dist/infer-rules/list.d.ts.map +1 -0
- package/dist/infer-rules/list.js +200 -0
- package/dist/infer-rules/path.d.ts +5 -0
- package/dist/infer-rules/path.d.ts.map +1 -0
- package/dist/infer-rules/path.js +78 -0
- package/dist/infer-rules/port.d.ts +3 -0
- package/dist/infer-rules/port.d.ts.map +1 -0
- package/dist/infer-rules/port.js +26 -0
- package/dist/infer-rules/simple.d.ts +3 -0
- package/dist/infer-rules/simple.d.ts.map +1 -0
- package/dist/infer-rules/simple.js +37 -0
- package/dist/infer-rules/url.d.ts +4 -0
- package/dist/infer-rules/url.d.ts.map +1 -0
- package/dist/infer-rules/url.js +149 -0
- package/dist/llm-kit/context.json.d.ts +2 -0
- package/dist/llm-kit/context.json.d.ts.map +1 -0
- package/dist/llm-kit/context.json.js +22 -0
- package/dist/sample/DNLTest.d.ts +2 -0
- package/dist/sample/DNLTest.d.ts.map +1 -0
- package/dist/sample/DNLTest.js +4 -0
- package/dist/sample/debug.d.ts +2 -0
- package/dist/sample/debug.d.ts.map +1 -0
- package/dist/sample/debug.js +5 -0
- package/dist/sample/env.dnl.d.ts +426 -0
- package/dist/sample/env.dnl.d.ts.map +1 -0
- package/dist/sample/env.dnl.js +429 -0
- package/dist/schemas/bool.d.ts +9 -0
- package/dist/schemas/bool.d.ts.map +1 -0
- package/dist/schemas/bool.js +22 -0
- package/dist/schemas/boolean.d.ts +9 -0
- package/dist/schemas/boolean.d.ts.map +1 -0
- package/dist/schemas/boolean.js +23 -0
- package/dist/schemas/dotted.d.ts +21 -0
- package/dist/schemas/dotted.d.ts.map +1 -0
- package/dist/schemas/dotted.js +45 -0
- package/dist/schemas/duration.d.ts +11 -0
- package/dist/schemas/duration.d.ts.map +1 -0
- package/dist/schemas/duration.js +44 -0
- package/dist/schemas/index.d.ts +9 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +8 -0
- package/dist/schemas/ip-and-version.d.ts +12 -0
- package/dist/schemas/ip-and-version.d.ts.map +1 -0
- package/dist/schemas/ip-and-version.js +35 -0
- package/dist/schemas/ip.d.ts +11 -0
- package/dist/schemas/ip.d.ts.map +1 -0
- package/dist/schemas/ip.js +33 -0
- package/dist/schemas/json.d.ts +15 -0
- package/dist/schemas/json.d.ts.map +1 -0
- package/dist/schemas/json.js +34 -0
- package/dist/schemas/list.d.ts +89 -0
- package/dist/schemas/list.d.ts.map +1 -0
- package/dist/schemas/list.js +139 -0
- package/dist/schemas/path.d.ts +23 -0
- package/dist/schemas/path.d.ts.map +1 -0
- package/dist/schemas/path.js +33 -0
- package/dist/schemas/port.d.ts +8 -0
- package/dist/schemas/port.d.ts.map +1 -0
- package/dist/schemas/port.js +9 -0
- package/dist/schemas/urls.d.ts +15 -0
- package/dist/schemas/urls.d.ts.map +1 -0
- package/dist/schemas/urls.js +54 -0
- package/package.json +11 -6
- package/dist/DnlTest.d.ts +0 -2
- package/dist/DnlTest.d.ts.map +0 -1
- package/dist/DnlTest.js +0 -12
- package/dist/cli/utils/exitCodes.d.ts +0 -8
- package/dist/cli/utils/exitCodes.d.ts.map +0 -1
- package/dist/cli/utils/exitCodes.js +0 -8
- package/dist/romaintaillandier1978-dotenv-never-lies-0.3.0.tgz +0 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { looksLikeUrl, looksLikeHttpUrl, looksLikeDbUrl, looksLikeQueueUrl, looksLikeWsUrl, looksLikeStorageUrl, looksLikeOtherUrl, } from "../../schemas/urls.js";
|
|
2
|
+
import { matchesEnvKey } from "../helpers.js";
|
|
3
|
+
import { databaseUrlGenSchema, httpUrlGenSchema, otherUrlGenSchema, queueUrlGenSchema, storageUrlGenSchema, wsUrlSchemaGen } from "../generated/url.js";
|
|
4
|
+
import { zUrlGenSchema } from "../generated/basic.js";
|
|
5
|
+
export const URL_KEYS = ["URL", "URI", "LINK", "ENDPOINT", "API_URL", "API_ENDPOINT", "API_LINK", "API_URI"];
|
|
6
|
+
const DB_KEYS = ["DB", "DATABASE", "DB_URL", "DATABASE_URL", "DB_URI", "DATABASE_URI"];
|
|
7
|
+
const QUEUE_KEYS = ["QUEUE", "MESSAGE_QUEUE", "MESSAGE_QUEUE_URL", "MESSAGE_QUEUE_URI", "MESSAGE_QUEUE_LINK", "MESSAGE_QUEUE_ENDPOINT"];
|
|
8
|
+
const WS_KEYS = ["WS", "WEBSOCKET", "WEBSOCKET_URL", "WEBSOCKET_URI", "WEBSOCKET_LINK", "WEBSOCKET_ENDPOINT"];
|
|
9
|
+
const STORAGE_KEYS = ["STORAGE", "STORAGE_URL", "STORAGE_URI", "STORAGE_LINK", "STORAGE_ENDPOINT"];
|
|
10
|
+
const OTHER_KEYS = ["OTHER", "MISC", "MISC_URL", "MISC_URI", "MISC_LINK", "MISC_ENDPOINT"];
|
|
11
|
+
const subUrlRule = (input) => {
|
|
12
|
+
input.confidence += 2;
|
|
13
|
+
const reasons = [`Valid ${input.message} URL (+2)`];
|
|
14
|
+
const { matched, reason } = matchesEnvKey(input.name, input.keys);
|
|
15
|
+
if (matched) {
|
|
16
|
+
input.confidence += 2;
|
|
17
|
+
reasons.push(`${reason} (+2)`);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
generated: input.schema,
|
|
21
|
+
confidence: input.confidence,
|
|
22
|
+
reasons,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const subUrlRules = {
|
|
26
|
+
HTTP: (name) => {
|
|
27
|
+
return {
|
|
28
|
+
message: "HTTP",
|
|
29
|
+
keys: URL_KEYS,
|
|
30
|
+
schema: httpUrlGenSchema(name),
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
DATABASE: (name) => {
|
|
34
|
+
return {
|
|
35
|
+
message: "database",
|
|
36
|
+
keys: DB_KEYS,
|
|
37
|
+
schema: databaseUrlGenSchema(name),
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
QUEUE: (name) => {
|
|
41
|
+
return {
|
|
42
|
+
message: "queue",
|
|
43
|
+
keys: QUEUE_KEYS,
|
|
44
|
+
schema: queueUrlGenSchema(name),
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
WS: (name) => {
|
|
48
|
+
return {
|
|
49
|
+
message: "ws",
|
|
50
|
+
keys: WS_KEYS,
|
|
51
|
+
schema: wsUrlSchemaGen(name),
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
STORAGE: (name) => {
|
|
55
|
+
return {
|
|
56
|
+
message: "storage",
|
|
57
|
+
keys: STORAGE_KEYS,
|
|
58
|
+
schema: storageUrlGenSchema(name),
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
OTHER: (name) => {
|
|
62
|
+
return {
|
|
63
|
+
message: "other",
|
|
64
|
+
keys: OTHER_KEYS,
|
|
65
|
+
schema: otherUrlGenSchema(name),
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
export const urlRule = {
|
|
70
|
+
type: "url",
|
|
71
|
+
priority: 5,
|
|
72
|
+
threshold: 5,
|
|
73
|
+
tryInfer({ name, rawValue }) {
|
|
74
|
+
if (!looksLikeUrl(rawValue))
|
|
75
|
+
return null;
|
|
76
|
+
let confidence = 5;
|
|
77
|
+
const reasons = ["Valid URL (+5)"];
|
|
78
|
+
const { matched, reason } = matchesEnvKey(name, URL_KEYS);
|
|
79
|
+
if (matched) {
|
|
80
|
+
confidence += 2;
|
|
81
|
+
reasons.push(`${reason} (+2)`);
|
|
82
|
+
}
|
|
83
|
+
if (looksLikeHttpUrl(rawValue)) {
|
|
84
|
+
return subUrlRule({
|
|
85
|
+
name,
|
|
86
|
+
rawValue,
|
|
87
|
+
confidence,
|
|
88
|
+
reasons,
|
|
89
|
+
...subUrlRules.HTTP(name),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (looksLikeDbUrl(rawValue)) {
|
|
93
|
+
return subUrlRule({
|
|
94
|
+
name,
|
|
95
|
+
rawValue,
|
|
96
|
+
confidence,
|
|
97
|
+
reasons,
|
|
98
|
+
...subUrlRules.DATABASE(name),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (looksLikeQueueUrl(rawValue)) {
|
|
102
|
+
return subUrlRule({
|
|
103
|
+
name,
|
|
104
|
+
rawValue,
|
|
105
|
+
confidence,
|
|
106
|
+
reasons,
|
|
107
|
+
...subUrlRules.QUEUE(name),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (looksLikeWsUrl(rawValue)) {
|
|
111
|
+
return subUrlRule({
|
|
112
|
+
name,
|
|
113
|
+
rawValue,
|
|
114
|
+
confidence,
|
|
115
|
+
reasons,
|
|
116
|
+
...subUrlRules.WS(name),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (looksLikeStorageUrl(rawValue)) {
|
|
120
|
+
return subUrlRule({
|
|
121
|
+
name,
|
|
122
|
+
rawValue,
|
|
123
|
+
confidence,
|
|
124
|
+
reasons,
|
|
125
|
+
...subUrlRules.STORAGE(name),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (looksLikeOtherUrl(rawValue)) {
|
|
129
|
+
return subUrlRule({
|
|
130
|
+
name,
|
|
131
|
+
rawValue,
|
|
132
|
+
confidence,
|
|
133
|
+
reasons,
|
|
134
|
+
...subUrlRules.OTHER(name),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
generated: zUrlGenSchema,
|
|
139
|
+
confidence,
|
|
140
|
+
reasons,
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/infer/rules/version.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAOxC,eAAO,MAAM,WAAW,EAAE,SAsBzB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { looksLikeVersion } from "../../schemas/dotted.js";
|
|
2
|
+
import { matchesEnvKey } from "../helpers.js";
|
|
3
|
+
import { versionGenSchema } from "../generated/version.js";
|
|
4
|
+
const VERSION_KEYS = ["VERSION", "SEMVER", "TAG", "RELEASE"];
|
|
5
|
+
// Note : NEVER add 2 parts version (2.0), it will conflict with numberRules (numberSchema)
|
|
6
|
+
export const versionRule = {
|
|
7
|
+
type: "version",
|
|
8
|
+
priority: 5.3,
|
|
9
|
+
threshold: 5,
|
|
10
|
+
tryInfer({ name, rawValue }) {
|
|
11
|
+
if (!looksLikeVersion(rawValue))
|
|
12
|
+
return null;
|
|
13
|
+
let confidence = 5;
|
|
14
|
+
const reasons = ["Value matches strict version format"];
|
|
15
|
+
const { matched, reason } = matchesEnvKey(name, VERSION_KEYS);
|
|
16
|
+
if (matched) {
|
|
17
|
+
confidence += 1;
|
|
18
|
+
reasons.push(`${reason} (+1)`);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
generated: versionGenSchema(name),
|
|
22
|
+
confidence,
|
|
23
|
+
reasons,
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* represent an import in a generated env.dnl.ts file
|
|
3
|
+
*/
|
|
4
|
+
export type Import = {
|
|
5
|
+
/**
|
|
6
|
+
* exact name of the element to import at the top of the generated env.dnl.ts file, ex: "jsonSchema"
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* exact name of the package to import, ex: "@romaintaillandier1978/dotenv-never-lies"
|
|
11
|
+
*/
|
|
12
|
+
from: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* represent a generated schema in a generated env.dnl.ts file, with associated import(s)
|
|
16
|
+
* ex: {
|
|
17
|
+
* code: `jsonSchema("${name}")`,
|
|
18
|
+
* imports: [{ name: "jsonSchema", from: "@romaintaillandier1978/dotenv-never-lies" }]
|
|
19
|
+
* }
|
|
20
|
+
*/
|
|
21
|
+
export type GeneratedSchema = {
|
|
22
|
+
/**
|
|
23
|
+
* The code that will be written in the dnl schema output, ex: "z.string()" or `jsonSchema("${name}")`
|
|
24
|
+
*/
|
|
25
|
+
code: string;
|
|
26
|
+
/**
|
|
27
|
+
* What to import in dnl schema to support this schema. (set to [] to ignore zod imports.)
|
|
28
|
+
*/
|
|
29
|
+
imports: Import[];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Result of an inference
|
|
33
|
+
*/
|
|
34
|
+
export type InferResult = {
|
|
35
|
+
/**
|
|
36
|
+
* Generated code and imports
|
|
37
|
+
*/
|
|
38
|
+
generated: GeneratedSchema;
|
|
39
|
+
/**
|
|
40
|
+
* Confidence level (0–10 typically)
|
|
41
|
+
*/
|
|
42
|
+
confidence: number;
|
|
43
|
+
/**
|
|
44
|
+
* for verbose mode
|
|
45
|
+
*/
|
|
46
|
+
reasons: string[];
|
|
47
|
+
/**
|
|
48
|
+
* for warnings, to inject in dnl schema. (not too much)
|
|
49
|
+
*/
|
|
50
|
+
warnings?: string[];
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Input for an inference or one .env entry
|
|
54
|
+
*/
|
|
55
|
+
export type InferInput = {
|
|
56
|
+
/**
|
|
57
|
+
* Name of the .env entry
|
|
58
|
+
*/
|
|
59
|
+
name: string;
|
|
60
|
+
/**
|
|
61
|
+
* Raw value of the .env entry
|
|
62
|
+
*/
|
|
63
|
+
rawValue: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* A reliable rule for an inference.
|
|
67
|
+
*/
|
|
68
|
+
export type InferRule = {
|
|
69
|
+
/**
|
|
70
|
+
* Logical identifier (json, boolean, duration, etc.)
|
|
71
|
+
*/
|
|
72
|
+
type: string;
|
|
73
|
+
/**
|
|
74
|
+
* Global order (higher = higher priority)
|
|
75
|
+
*/
|
|
76
|
+
priority: number;
|
|
77
|
+
/**
|
|
78
|
+
* Minimum threshold to accept this inference
|
|
79
|
+
*/
|
|
80
|
+
threshold: number;
|
|
81
|
+
/**
|
|
82
|
+
* Tries to infer a schema for the input.
|
|
83
|
+
* Returns null if the rule does not apply at all.
|
|
84
|
+
*/
|
|
85
|
+
tryInfer(input: InferInput): InferResult | null;
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/infer/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;IACjB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACtB;;OAEG;IACH,SAAS,EAAE,eAAe,CAAC;IAC3B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACrB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACpB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,IAAI,CAAC;CACnD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic.d.ts","sourceRoot":"","sources":["../../src/infer-rules/basic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,eAAO,MAAM,UAAU,EAAE,aAqBxB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,aAevB,CAAC;AACF,eAAO,MAAM,UAAU,EAAE,aAaxB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export const numberRule = {
|
|
2
|
+
type: "number",
|
|
3
|
+
priority: 4,
|
|
4
|
+
threshold: 5,
|
|
5
|
+
tryInfer({ rawValue }) {
|
|
6
|
+
const n = Number(rawValue);
|
|
7
|
+
if (Number.isNaN(n))
|
|
8
|
+
return null;
|
|
9
|
+
// float ou entier hors port
|
|
10
|
+
if (rawValue.includes(".") || n < 1 || n > 65535) {
|
|
11
|
+
return {
|
|
12
|
+
schema: "z.coerce.number()",
|
|
13
|
+
importedSchemas: [],
|
|
14
|
+
confidence: 6,
|
|
15
|
+
reasons: ["numeric value"],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
export const emailRule = {
|
|
22
|
+
type: "email",
|
|
23
|
+
priority: 4,
|
|
24
|
+
threshold: 5,
|
|
25
|
+
tryInfer({ rawValue }) {
|
|
26
|
+
if (!/^[^@]+@[^@]+\.[^@]+$/.test(rawValue))
|
|
27
|
+
return null;
|
|
28
|
+
return {
|
|
29
|
+
schema: "z.email()",
|
|
30
|
+
importedSchemas: [],
|
|
31
|
+
confidence: 6,
|
|
32
|
+
reasons: ["Email-like value"],
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
export const stringRule = {
|
|
37
|
+
type: "string",
|
|
38
|
+
priority: 0,
|
|
39
|
+
threshold: 0,
|
|
40
|
+
tryInfer() {
|
|
41
|
+
return {
|
|
42
|
+
schema: "z.string()",
|
|
43
|
+
importedSchemas: [],
|
|
44
|
+
confidence: 0,
|
|
45
|
+
reasons: ["Fallback to string"],
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../src/infer-rules/boolean.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAC;AAI1D,eAAO,MAAM,WAAW,EAAE,aAqBzB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { looksLikeValidBoolean } from "../schemas/boolean.js";
|
|
2
|
+
import { matchesEnvKey } from "./index.js";
|
|
3
|
+
const BOOLEAN_KEYS = ["IS_", "HAS_", "ENABLE_", "DISABLE_", "_ENABLED", "_DISABLED", "ALLOW_", "DENY_"];
|
|
4
|
+
export const booleanRule = {
|
|
5
|
+
type: "boolean",
|
|
6
|
+
priority: 6,
|
|
7
|
+
threshold: 5,
|
|
8
|
+
tryInfer({ name, rawValue }) {
|
|
9
|
+
if (!looksLikeValidBoolean(rawValue))
|
|
10
|
+
return null;
|
|
11
|
+
let confidence = 6; // valeur bool = signal fort
|
|
12
|
+
const reasons = ["Value matches strict boolean format"];
|
|
13
|
+
const { matched, reason } = matchesEnvKey(name, BOOLEAN_KEYS);
|
|
14
|
+
if (matched) {
|
|
15
|
+
confidence += 1;
|
|
16
|
+
reasons.push(`${reason} (+1)`);
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
schema: `boolSchema("${name}")`,
|
|
20
|
+
importedSchemas: ["boolSchema"],
|
|
21
|
+
confidence: 10,
|
|
22
|
+
reasons,
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dotted.d.ts","sourceRoot":"","sources":["../../src/infer-rules/dotted.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAC;AAI1D,eAAO,MAAM,MAAM,EAAE,aAuBpB,CAAC;AAIF,eAAO,MAAM,WAAW,EAAE,aAuBzB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { looksLikeIp, looksLikeVersion } from "../schemas/dotted.js";
|
|
2
|
+
import { matchesEnvKey } from "./index.js";
|
|
3
|
+
const IP_KEYS = ["_IP", "_ADDRESS", "_HOST", "_HOSTNAME"];
|
|
4
|
+
export const ipRule = {
|
|
5
|
+
type: "ip",
|
|
6
|
+
priority: 5.5,
|
|
7
|
+
threshold: 5,
|
|
8
|
+
tryInfer({ name, rawValue }) {
|
|
9
|
+
if (!looksLikeIp(rawValue))
|
|
10
|
+
return null;
|
|
11
|
+
let confidence = 5;
|
|
12
|
+
const reasons = ["Value matches strict ip format"];
|
|
13
|
+
const { matched, reason } = matchesEnvKey(name, IP_KEYS);
|
|
14
|
+
if (matched) {
|
|
15
|
+
confidence += 1;
|
|
16
|
+
reasons.push(`${reason} (+1)`);
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
schema: `ipSchema(${JSON.stringify(name)})`,
|
|
20
|
+
importedSchemas: ["ipSchema"],
|
|
21
|
+
confidence,
|
|
22
|
+
reasons,
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const VERSION_KEYS = ["_VERSION", "_SEMVER", "_TAG", "_RELEASE"];
|
|
27
|
+
export const versionRule = {
|
|
28
|
+
type: "version",
|
|
29
|
+
priority: 5.3,
|
|
30
|
+
threshold: 5,
|
|
31
|
+
tryInfer({ name, rawValue }) {
|
|
32
|
+
if (!looksLikeVersion(rawValue))
|
|
33
|
+
return null;
|
|
34
|
+
let confidence = 5;
|
|
35
|
+
const reasons = ["Value matches strict version format"];
|
|
36
|
+
const { matched, reason } = matchesEnvKey(name, VERSION_KEYS);
|
|
37
|
+
if (matched) {
|
|
38
|
+
confidence += 1;
|
|
39
|
+
reasons.push(`${reason} (+1)`);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
schema: `versionSchema(${JSON.stringify(name)})`,
|
|
43
|
+
importedSchemas: ["versionSchema"],
|
|
44
|
+
confidence,
|
|
45
|
+
reasons,
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/infer-rules/duration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAC;AAI1D,eAAO,MAAM,YAAY,EAAE,aAuB1B,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { looksLikeValidDuration } from "../schemas/duration.js";
|
|
2
|
+
import { matchesEnvKey } from "./index.js";
|
|
3
|
+
const DURATION_KEYS = ["_TIMEOUT", "_TTL", "_DELAY", "_DURATION", "_INTERVAL"];
|
|
4
|
+
export const durationRule = {
|
|
5
|
+
type: "duration",
|
|
6
|
+
priority: 6,
|
|
7
|
+
threshold: 5,
|
|
8
|
+
tryInfer({ name, rawValue }) {
|
|
9
|
+
if (!looksLikeValidDuration(rawValue))
|
|
10
|
+
return null;
|
|
11
|
+
let confidence = 6;
|
|
12
|
+
const reasons = ["Value matches strict duration format"];
|
|
13
|
+
const { matched, reason } = matchesEnvKey(name, DURATION_KEYS);
|
|
14
|
+
if (matched) {
|
|
15
|
+
confidence += 1;
|
|
16
|
+
reasons.push(`${reason} (+1)`);
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
schema: `durationSchema(${JSON.stringify(name)})`,
|
|
20
|
+
importedSchemas: ["durationSchema"],
|
|
21
|
+
confidence,
|
|
22
|
+
reasons,
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export type InferenceResult = {
|
|
2
|
+
/**
|
|
3
|
+
* Code TS sérialisé, ex:
|
|
4
|
+
* "z.string()"
|
|
5
|
+
* "jsonSchema(\"${name}\")"
|
|
6
|
+
*/
|
|
7
|
+
schema: string;
|
|
8
|
+
/**
|
|
9
|
+
nom exact de l'élément à importer au top du fichier env.dnl.tsgénéré, ex: "jsonSchema"
|
|
10
|
+
*/
|
|
11
|
+
importedSchemas: Array<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Niveau de confiance (0–10 typiquement)
|
|
14
|
+
*/
|
|
15
|
+
confidence: number;
|
|
16
|
+
/**
|
|
17
|
+
* Optionnel, pour debug / warnings futurs
|
|
18
|
+
*/
|
|
19
|
+
reasons?: string[];
|
|
20
|
+
};
|
|
21
|
+
export type InferenceInput = {
|
|
22
|
+
name: string;
|
|
23
|
+
rawValue: string;
|
|
24
|
+
};
|
|
25
|
+
export type InferencePass = {
|
|
26
|
+
/**
|
|
27
|
+
* Identifiant logique (json, boolean, duration, etc.)
|
|
28
|
+
*/
|
|
29
|
+
type: string;
|
|
30
|
+
/**
|
|
31
|
+
* Ordre global (plus haut = plus prioritaire)
|
|
32
|
+
*/
|
|
33
|
+
priority: number;
|
|
34
|
+
/**
|
|
35
|
+
* Seuil minimum pour accepter cette inférence
|
|
36
|
+
*/
|
|
37
|
+
threshold: number;
|
|
38
|
+
/**
|
|
39
|
+
* Tente une inférence.
|
|
40
|
+
* Retourne null si la règle ne s'applique pas du tout.
|
|
41
|
+
*/
|
|
42
|
+
tryInfer(input: InferenceInput): InferenceResult | null;
|
|
43
|
+
};
|
|
44
|
+
export declare const inferencePasses: InferencePass[];
|
|
45
|
+
export declare const listInferencePasses: InferencePass[];
|
|
46
|
+
export declare const matchesEnvKey: (name: string, keys: string[]) => {
|
|
47
|
+
matched: boolean;
|
|
48
|
+
reason: string;
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/infer-rules/index.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,eAAe,GAAG;IAC1B;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC/B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IACxB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,cAAc,GAAG,eAAe,GAAG,IAAI,CAAC;CAC3D,CAAC;AAOF,eAAO,MAAM,eAAe,EAAE,aAAa,EAeF,CAAC;AAE1C,eAAO,MAAM,mBAAmB,EAAE,aAAa,EAA2D,CAAC;AAE3G,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,EAAE,MAAM,MAAM,EAAE,KAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAa9F,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { booleanRule } from "./boolean.js";
|
|
2
|
+
import { durationRule } from "./duration.js";
|
|
3
|
+
import { jsonRule } from "./json.js";
|
|
4
|
+
import { keyValueListRule, keyValueRule, listRule } from "./list.js";
|
|
5
|
+
import { portRule } from "./port.js";
|
|
6
|
+
import { emailRule, numberRule, stringRule } from "./basic.js";
|
|
7
|
+
import { urlRule } from "./url.js";
|
|
8
|
+
import { ipRule, versionRule } from "./dotted.js";
|
|
9
|
+
// ⚠️ Règle d’or :
|
|
10
|
+
// JSON avant list,
|
|
11
|
+
// duration avant number,
|
|
12
|
+
// boolean avant enum,
|
|
13
|
+
export const inferencePasses = [
|
|
14
|
+
jsonRule, // 10
|
|
15
|
+
keyValueListRule, // 9
|
|
16
|
+
keyValueRule, // 8
|
|
17
|
+
listRule, // 7
|
|
18
|
+
portRule, //7
|
|
19
|
+
durationRule, // 6
|
|
20
|
+
booleanRule, // 6
|
|
21
|
+
ipRule, // 5.5
|
|
22
|
+
versionRule, // 5
|
|
23
|
+
urlRule, // 5
|
|
24
|
+
emailRule, // 4
|
|
25
|
+
numberRule, // 3
|
|
26
|
+
stringRule, // 0 = fallback
|
|
27
|
+
].sort((a, b) => b.priority - a.priority);
|
|
28
|
+
export const listInferencePasses = [portRule, numberRule, emailRule, urlRule, stringRule];
|
|
29
|
+
export const matchesEnvKey = (name, keys) => {
|
|
30
|
+
for (const key of keys) {
|
|
31
|
+
if (name.toUpperCase().includes(key.toUpperCase())) {
|
|
32
|
+
return {
|
|
33
|
+
matched: true,
|
|
34
|
+
reason: `Env name contains key: ${key}`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
matched: false,
|
|
40
|
+
reason: "No hint in the Env name",
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/infer-rules/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,aAAa,EAAkC,MAAM,YAAY,CAAC;AAI3F,eAAO,MAAM,QAAQ,EAAE,aAiDtB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { matchesEnvKey } from "./index.js";
|
|
2
|
+
const JSON_KEYS_HIGH = ["JSON"];
|
|
3
|
+
const JSON_KEYS_LOW = ["_PAYLOAD", "_CONFIG", "_DATA", "_META"];
|
|
4
|
+
export const jsonRule = {
|
|
5
|
+
type: "json",
|
|
6
|
+
priority: 10,
|
|
7
|
+
threshold: 5,
|
|
8
|
+
tryInfer({ name, rawValue }) {
|
|
9
|
+
let parsed;
|
|
10
|
+
const reasons = [];
|
|
11
|
+
try {
|
|
12
|
+
parsed = JSON.parse(rawValue);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
let confidence = 0;
|
|
18
|
+
// si pas de {} ni de [], on se retrouve avec une valeur seule, genre "\"romain\"" ou "\"2\"". (avec des guillemets)
|
|
19
|
+
// Ce serait effectivement un json valie, mais peu de chance que ce soit _intentionnel_
|
|
20
|
+
// 🔥 structure JSON forte
|
|
21
|
+
if (rawValue.startsWith("{") || rawValue.startsWith("[")) {
|
|
22
|
+
confidence += 6;
|
|
23
|
+
reasons.push("JSON structure (+6)");
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
// JSON primitif : valide mais suspect
|
|
27
|
+
confidence += 2;
|
|
28
|
+
reasons.push("JSON primitive (+2)");
|
|
29
|
+
}
|
|
30
|
+
// 🔤 heuristiques sur le nom
|
|
31
|
+
const { matched: matchedHigh, reason: reasonHigh } = matchesEnvKey(name, JSON_KEYS_HIGH);
|
|
32
|
+
if (matchedHigh) {
|
|
33
|
+
confidence += 2;
|
|
34
|
+
reasons.push(`${reasonHigh} (+2)`);
|
|
35
|
+
}
|
|
36
|
+
const { matched: matchedLow, reason: reasonLow } = matchesEnvKey(name, JSON_KEYS_LOW);
|
|
37
|
+
if (matchedLow) {
|
|
38
|
+
confidence += 1;
|
|
39
|
+
reasons.push(`${reasonLow} (+1)`);
|
|
40
|
+
}
|
|
41
|
+
if (confidence < this.threshold)
|
|
42
|
+
return null;
|
|
43
|
+
return {
|
|
44
|
+
schema: `jsonSchema("${name}")`,
|
|
45
|
+
importedSchemas: ["jsonSchema"],
|
|
46
|
+
confidence,
|
|
47
|
+
reasons,
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/infer-rules/list.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAC;AAS1D,eAAO,MAAM,gBAAgB,EAAE,aAiC9B,CAAC;AAIF,eAAO,MAAM,YAAY,EAAE,aAwB1B,CAAC;AASF,eAAO,MAAM,QAAQ,EAAE,aAgGtB,CAAC"}
|