@deterministic-code/datasources-cli 0.1.15 → 0.1.16
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/wireRegister.js
CHANGED
|
@@ -22,12 +22,21 @@ pub mod repositories;
|
|
|
22
22
|
pub use repositories::${rustIdent(casing.convertFileName("repository_registry"))}::Repositories;
|
|
23
23
|
`;
|
|
24
24
|
};
|
|
25
|
-
const
|
|
26
|
-
|
|
25
|
+
const rustCargoLine = (cargo, name, line) => new RegExp(`^\\s*${name}\\s*=`, "m").test(cargo) ? void 0 : line;
|
|
26
|
+
const cargoWithCtor = (cargo) => {
|
|
27
|
+
const add = [
|
|
28
|
+
rustCargoLine(cargo, "ctor", 'ctor = "0.4"'),
|
|
29
|
+
rustCargoLine(cargo, "tokio", 'tokio = { version = "1", features = ["macros", "rt-multi-thread"] }')
|
|
30
|
+
].filter((line) => line !== void 0);
|
|
31
|
+
if (add.length === 0) return void 0;
|
|
32
|
+
const block = add.join("\n");
|
|
33
|
+
return cargo.includes("[dependencies]") ? cargo.replace("[dependencies]", `[dependencies]
|
|
34
|
+
${block}`) : `${cargo.trimEnd()}
|
|
27
35
|
|
|
28
36
|
[dependencies]
|
|
29
|
-
|
|
37
|
+
${block}
|
|
30
38
|
`;
|
|
39
|
+
};
|
|
31
40
|
const attached = (dialect, entry, entryPath, hook) => dialect === "typescript" ? entry.includes("datasources-register") ? void 0 : `import "${specFrom(entryPath, hook)}";
|
|
32
41
|
${entry}` : entry.includes("datasources_register") ? void 0 : `mod datasources_register;
|
|
33
42
|
use datasources_register::Repositories;
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { dirname, join } from "node:path";
|
|
2
2
|
import { catalog } from "./catalog.js";
|
|
3
|
+
const rustDriver = {
|
|
4
|
+
json: "JsonDriver",
|
|
5
|
+
memory: "MemoryDriver",
|
|
6
|
+
sqlite: "SqliteDriver",
|
|
7
|
+
xml: "XmlDriver",
|
|
8
|
+
yaml: "YamlDriver",
|
|
9
|
+
mysql: "MysqlDriver",
|
|
10
|
+
sqlserver: "SqlServerDriver",
|
|
11
|
+
postgres: "PostgresDriver",
|
|
12
|
+
oracle: "OracleDriver",
|
|
13
|
+
mongodb: "MongoDbDriver",
|
|
14
|
+
dynamodb: "DynamoDbDriver"
|
|
15
|
+
};
|
|
3
16
|
const optional = async (fs, path) => {
|
|
4
17
|
try {
|
|
5
18
|
return await fs.readFile(path);
|
|
@@ -15,10 +28,25 @@ const firstFile = async (fs, cwd, names) => {
|
|
|
15
28
|
}
|
|
16
29
|
return void 0;
|
|
17
30
|
};
|
|
18
|
-
const rustBindContents = (names) =>
|
|
19
|
-
|
|
20
|
-
const
|
|
31
|
+
const rustBindContents = (names) => `pub fn register() {
|
|
32
|
+
${names.map((name) => {
|
|
33
|
+
const crate = catalog[name].cargo.replaceAll("-", "_");
|
|
34
|
+
return ` datasources::register("${name}", std::sync::Arc::new(${crate}::${rustDriver[name]}));`;
|
|
35
|
+
}).join("\n")}
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
const withMod = (entry) => entry.includes("datasources_providers") ? entry : `mod datasources_providers;
|
|
21
39
|
${entry}`;
|
|
40
|
+
const withRegisterCall = (entry) => {
|
|
41
|
+
if (entry.includes("datasources_providers::register()")) return entry;
|
|
42
|
+
const main = /((?:async\s+)?fn\s+main\s*\([^)]*\)(?:\s*->\s*[^{]+)?\s*)\{(\s*)/;
|
|
43
|
+
return entry.replace(main, (_, sig, ws) => `${sig}{
|
|
44
|
+
datasources_providers::register();${ws === "" ? "\n" : ws}`);
|
|
45
|
+
};
|
|
46
|
+
const attachedProviders = (entry) => {
|
|
47
|
+
const next = withRegisterCall(withMod(entry));
|
|
48
|
+
return next === entry ? void 0 : next;
|
|
49
|
+
};
|
|
22
50
|
const wireRustProviders = async (cwd, names, dryRun, deps) => {
|
|
23
51
|
const entry = await firstFile(deps.fs, cwd, ["src/lib.rs", "src/main.rs", "lib.rs", "main.rs"]);
|
|
24
52
|
const bind = join(entry ? dirname(entry.path) : cwd, "datasources_providers.rs");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deterministic-code/datasources-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"datasources": "./bin/datasources.mjs"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@deterministic-code/datasources-code-generators": "0.1.
|
|
16
|
+
"@deterministic-code/datasources-code-generators": "0.1.16",
|
|
17
17
|
"@deterministic-code/generators-common": "0.0.1",
|
|
18
18
|
"@deterministic-code/deterministic-generators-common": "0.1.0",
|
|
19
19
|
"@deterministic-code/typescript-generators": "0.0.1",
|