@deterministic-code/datasources-cli 0.1.16 → 0.1.17
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.
|
@@ -3,6 +3,7 @@ import { inferReferenceFieldTypes } from "@deterministic-code/datasources-code-g
|
|
|
3
3
|
import { createCasingStrategy } from "@deterministic-code/generators-common/casing-strategy";
|
|
4
4
|
import { identityColumns, isCollectionField, persistedColumnFields } from "@deterministic-code/generators-common/spec-types";
|
|
5
5
|
import { writeInclusionOf } from "@deterministic-code/datasources-code-generators/sql/common/write-inclusion";
|
|
6
|
+
const createZeroKind = (field) => field.isId === true || field.references !== void 0 || field.isNullable === true || field.defaultValue !== void 0 && field.defaultValue !== null ? void 0 : field.type === "boolean" ? "boolean" : field.type === "string" ? "string" : void 0;
|
|
6
7
|
const referenceOf = (references) => {
|
|
7
8
|
if (references === void 0) return void 0;
|
|
8
9
|
const [type, field] = [references].flat().join(".").split(".");
|
|
@@ -80,6 +81,12 @@ const planRepositories = (spec, dialect, settings) => {
|
|
|
80
81
|
createProperties: columns.filter(
|
|
81
82
|
(field) => writeInclusionOf(field, identityColumns(tableType, table), overlays.get(field.name)).includeInCreate
|
|
82
83
|
).map((field) => property(field.name)),
|
|
84
|
+
createZeros: columns.flatMap((field) => {
|
|
85
|
+
if (!writeInclusionOf(field, identityColumns(tableType, table), overlays.get(field.name)).includeInCreate)
|
|
86
|
+
return [];
|
|
87
|
+
const kind = createZeroKind(field);
|
|
88
|
+
return kind === void 0 ? [] : [{ name: property(field.name), kind }];
|
|
89
|
+
}),
|
|
83
90
|
updateProperties: columns.filter(
|
|
84
91
|
(field) => writeInclusionOf(field, identityColumns(tableType, table), overlays.get(field.name)).includeInUpdate
|
|
85
92
|
).map((field) => property(field.name)),
|
|
@@ -3,9 +3,17 @@ import { content } from "@deterministic-code/generators-common/generate-entry";
|
|
|
3
3
|
import { childField, children as childModels, isLinked, pluralSnake, registryFile, repositoryFile, rustIdent, rustModLine } from "./RepositoryModel.js";
|
|
4
4
|
import { dialectsOf, pad, quote, writeList } from "./writeLists.js";
|
|
5
5
|
const rustString = (value) => `"${quote(value)}"`;
|
|
6
|
-
const uses = (model) =>
|
|
7
|
-
|
|
6
|
+
const uses = (model) => {
|
|
7
|
+
const builder = dialectsOf(model).length === 0 ? "" : "CRUDRepositoryBuilder, ";
|
|
8
|
+
const value = model.createZeros.length === 0 ? "" : "Value, ";
|
|
9
|
+
return `use datasources::{Association, Connection, CRUDRepository, ${builder}CRUDRepositoryOptions, DictionaryMapper, Enrichment, EnrichmentPropertyType, ICRUDRepository, ReadonlyRepository, ReadonlyRepositoryMappingOptions, ${value}Result};
|
|
8
10
|
use std::sync::Arc;`;
|
|
11
|
+
};
|
|
12
|
+
const rustZeros = (zeros) => zeros.length === 0 ? "" : `.map(|repo| repo.with_create_zeros([
|
|
13
|
+
${zeros.map(
|
|
14
|
+
(zero) => zero.kind === "boolean" ? ` (${rustString(zero.name)}.into(), Value::from(false)),` : ` (${rustString(zero.name)}.into(), Value::from("")),`
|
|
15
|
+
).join("\n")}
|
|
16
|
+
].into_iter().collect()))`;
|
|
9
17
|
const rustFill = (model) => {
|
|
10
18
|
const mapping = model.propertyMappings.length === 0 ? "" : `options.property_mappings = Some(Arc::new(DictionaryMapper::new([
|
|
11
19
|
${model.propertyMappings.map((pair) => ` (${rustString(pair.from)}.into(), ${rustString(pair.to)}.into()),`).join("\n")}
|
|
@@ -191,7 +199,7 @@ const plain = (model, nested, casing) => `${uses(model)}
|
|
|
191
199
|
|
|
192
200
|
pub fn ${repoFn(model.specName, casing)}(connection: Arc<dyn Connection>) -> Result<CRUDRepository> {
|
|
193
201
|
${crudOptions(model)}
|
|
194
|
-
CRUDRepository::new(connection, options)
|
|
202
|
+
CRUDRepository::new(connection, options)${rustZeros(model.createZeros)}
|
|
195
203
|
}
|
|
196
204
|
|
|
197
205
|
${readonlyFn(model, nested, casing)}
|
|
@@ -218,7 +226,7 @@ impl ${type} {
|
|
|
218
226
|
pub fn new(connection: Arc<dyn Connection>) -> Result<Self> {
|
|
219
227
|
${pad(crudOptions(model), 4)}
|
|
220
228
|
${childLets(children, nested, casing)}
|
|
221
|
-
let mut repo = CRUDRepository::new(Arc::clone(&connection), options)?;
|
|
229
|
+
let mut repo = CRUDRepository::new(Arc::clone(&connection), options)${rustZeros(model.createZeros)}?;
|
|
222
230
|
${enrich}
|
|
223
231
|
Ok(Self { repo: Arc::new(repo), ${assign} })
|
|
224
232
|
}
|
|
@@ -10,6 +10,8 @@ const entityAndMapping = (model) => {
|
|
|
10
10
|
const tsOptions = (model) => `{ ${entityAndMapping(model)}ids: ${writeList("typescript", model.ids)}, createProperties: ${writeList("typescript", model.createProperties)}, updateProperties: ${writeList("typescript", model.updateProperties)}, readProperties: ${writeList("typescript", model.readProperties)} }`;
|
|
11
11
|
const tsReadonly = (model) => `{ ${entityAndMapping(model)}readProperties: ${writeList("typescript", model.readProperties)} }`;
|
|
12
12
|
const tsOptionsExpr = (model) => dialectsOf(model).length === 0 ? tsOptions(model) : "options(connection)";
|
|
13
|
+
const tsZeros = (model) => model.createZeros.length === 0 ? "" : ` this.createZeros = { ${model.createZeros.map((zero) => `${zero.name}: ${zero.kind === "boolean" ? "false" : '""'}`).join(", ")} };
|
|
14
|
+
`;
|
|
13
15
|
const tsBuilder = (name, model, write) => `const ${name} = (connection: IConnection) =>
|
|
14
16
|
new CRUDRepositoryBuilder<${model.typeName}>()
|
|
15
17
|
.add(${write(model)})${dialectsOf(model).map(([engine, planned]) => `
|
|
@@ -96,7 +98,7 @@ ${tsOptionsFn(model)}export class ${model.typeName}Repository extends CRUDReposi
|
|
|
96
98
|
${fields.length === 0 ? "" : `${fields.join("\n")}
|
|
97
99
|
`} constructor(connection: IConnection) {
|
|
98
100
|
super(connection, ${tsOptionsExpr(model)});
|
|
99
|
-
${wrap}${lines.length === 0 ? "" : `${lines.join("\n")}
|
|
101
|
+
${tsZeros(model)}${wrap}${lines.length === 0 ? "" : `${lines.join("\n")}
|
|
100
102
|
`} }
|
|
101
103
|
${createReadonly(model, casing)}
|
|
102
104
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deterministic-code/datasources-code-generators",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/generateSql.js",
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
"./sql/common/infer-reference-types": "./dist/sql/common/infer-reference-types.js"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@deterministic-code/datasources": "^0.1.
|
|
18
|
-
"@deterministic-code/datasources-mysql": "^0.1.
|
|
19
|
-
"@deterministic-code/datasources-oracle": "^0.1.
|
|
20
|
-
"@deterministic-code/datasources-postgres": "^0.1.
|
|
21
|
-
"@deterministic-code/datasources-sqlite": "^0.1.
|
|
22
|
-
"@deterministic-code/datasources-sqlserver": "^0.1.
|
|
17
|
+
"@deterministic-code/datasources": "^0.1.15",
|
|
18
|
+
"@deterministic-code/datasources-mysql": "^0.1.15",
|
|
19
|
+
"@deterministic-code/datasources-oracle": "^0.1.15",
|
|
20
|
+
"@deterministic-code/datasources-postgres": "^0.1.15",
|
|
21
|
+
"@deterministic-code/datasources-sqlite": "^0.1.15",
|
|
22
|
+
"@deterministic-code/datasources-sqlserver": "^0.1.15",
|
|
23
23
|
"@deterministic-code/deterministic-generators-common": "0.1.0",
|
|
24
24
|
"@deterministic-code/generators-common": "0.0.1",
|
|
25
25
|
"pluralize": "^8.0.0",
|
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.17",
|
|
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.17",
|
|
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",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"@deterministic-code/rust-generators": "0.0.1",
|
|
22
22
|
"@deterministic-code/generators-openapi": "0.0.1",
|
|
23
23
|
"@deterministic-code/patch-merger": "0.1.0",
|
|
24
|
-
"@deterministic-code/datasources": "^0.1.
|
|
25
|
-
"@deterministic-code/datasources-sqlite": "^0.1.
|
|
26
|
-
"@deterministic-code/datasources-mysql": "^0.1.
|
|
27
|
-
"@deterministic-code/datasources-postgres": "^0.1.
|
|
28
|
-
"@deterministic-code/datasources-sqlserver": "^0.1.
|
|
29
|
-
"@deterministic-code/datasources-oracle": "^0.1.
|
|
24
|
+
"@deterministic-code/datasources": "^0.1.15",
|
|
25
|
+
"@deterministic-code/datasources-sqlite": "^0.1.15",
|
|
26
|
+
"@deterministic-code/datasources-mysql": "^0.1.15",
|
|
27
|
+
"@deterministic-code/datasources-postgres": "^0.1.15",
|
|
28
|
+
"@deterministic-code/datasources-sqlserver": "^0.1.15",
|
|
29
|
+
"@deterministic-code/datasources-oracle": "^0.1.15",
|
|
30
30
|
"@inquirer/prompts": "^7.8.0",
|
|
31
31
|
"yaml": "^2.6.0",
|
|
32
32
|
"mustache": "^4.2.0",
|