@deterministic-code/datasources-cli 0.1.7 → 0.1.8

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.
@@ -61,6 +61,9 @@ const applyMigrateUp = async (command, flags, deps, env = process.env) => {
61
61
  `migrate-up: provider ${provider} is not in backend.datasources (${dialects.join(", ") || "none"})`
62
62
  );
63
63
  const args = [
64
+ "--yes",
65
+ "--package",
66
+ "@deterministic-code/migraters",
64
67
  "migrate-up",
65
68
  "--provider",
66
69
  provider,
@@ -2,7 +2,16 @@ const migrateProviders = ["sqlite", "postgres", "mysql", "sqlserver", "oracle"];
2
2
  const sqlMigrateProviders = (names) => migrateProviders.filter((name) => names.includes(name));
3
3
  const migrateInitCommands = (dialects) => dialects.length === 0 ? [] : [
4
4
  { command: "npm", args: ["install", "@deterministic-code/migraters"] },
5
- { command: "npx", args: ["migrate-init", ...dialects.flatMap((name) => ["--dialect", name])] }
5
+ {
6
+ command: "npx",
7
+ args: [
8
+ "--yes",
9
+ "--package",
10
+ "@deterministic-code/migraters",
11
+ "migrate-init",
12
+ ...dialects.flatMap((name) => ["--dialect", name])
13
+ ]
14
+ }
6
15
  ];
7
16
  export {
8
17
  migrateInitCommands,
@@ -125,6 +125,12 @@ const isCsValueType = (csType) => {
125
125
  const t = csType.endsWith("?") ? csType.slice(0, -1) : csType;
126
126
  return CS_VALUE_TYPES.has(t.slice(t.lastIndexOf(".") + 1));
127
127
  };
128
+ const csLanguageDefault = (csType) => {
129
+ if (csType.endsWith("?") || isCsValueType(csType)) return void 0;
130
+ if (csType === "string") return '""';
131
+ if (csType === "byte[]") return "[]";
132
+ return "default!";
133
+ };
128
134
  const collectionDefaultExpr = (field) => {
129
135
  if (!field.isArray && field.isMap !== true) return void 0;
130
136
  if (field.isNullable && field.defaultValue === null) return void 0;
@@ -146,6 +152,7 @@ const nativeDefaultExpr = (specType, field) => {
146
152
  export {
147
153
  collectionDefaultExpr,
148
154
  convertSpecType,
155
+ csLanguageDefault,
149
156
  defaultValueConverter,
150
157
  isCsValueType,
151
158
  nativeDefaultExpr,
@@ -17,6 +17,7 @@ import {
17
17
  import {
18
18
  collectionDefaultExpr,
19
19
  convertSpecType,
20
+ csLanguageDefault,
20
21
  nativeDefaultExpr
21
22
  } from "./deterministic-type-converter.js";
22
23
  import { Emit } from "./emit.js";
@@ -41,7 +42,7 @@ class Generator extends Emit {
41
42
  const parent = classParent(table, "datasource", typesByName);
42
43
  const fields = declaredFields(table, "datasource", typesByName).map((f) => {
43
44
  const csType = csTypeFor(f, typesByName);
44
- const initializer = collectionDefaultExpr(f) ?? nativeDefaultExpr(fieldTypeOf(f, typesByName), f);
45
+ const initializer = collectionDefaultExpr(f) ?? nativeDefaultExpr(fieldTypeOf(f, typesByName), f) ?? csLanguageDefault(csType);
45
46
  return {
46
47
  ident: this.casing.convertFields(f.name),
47
48
  csType,
@@ -20,6 +20,7 @@ import {
20
20
  import {
21
21
  collectionDefaultExpr,
22
22
  convertSpecType,
23
+ csLanguageDefault,
23
24
  nativeDefaultExpr
24
25
  } from "./deterministic-type-converter.js";
25
26
  import { Emit } from "./emit.js";
@@ -61,7 +62,7 @@ class Generator extends Emit {
61
62
  const parent = classParent(view, "view", typesByName);
62
63
  const fields = declaredFields(view, "view", typesByName).map((f) => {
63
64
  const csType = this.csTypeFor(f, typesByName);
64
- const initializer = collectionDefaultExpr(f) ?? (f.kind === "primitive" ? nativeDefaultExpr(fieldTypeOf(f, typesByName), f) : void 0);
65
+ const initializer = collectionDefaultExpr(f) ?? (f.kind === "primitive" ? nativeDefaultExpr(fieldTypeOf(f, typesByName), f) : void 0) ?? csLanguageDefault(csType);
65
66
  return {
66
67
  ident: this.casing.convertFields(f.name),
67
68
  csType,
@@ -146,6 +146,14 @@ export const isCsValueType = (csType: string): boolean => {
146
146
  return CS_VALUE_TYPES.has(t.slice(t.lastIndexOf(".") + 1));
147
147
  };
148
148
 
149
+ /** Language zero for a non-nullable reference type. Value types stay uninitialized. */
150
+ export const csLanguageDefault = (csType: string): string | undefined => {
151
+ if (csType.endsWith("?") || isCsValueType(csType)) return undefined;
152
+ if (csType === "string") return '""';
153
+ if (csType === "byte[]") return "[]";
154
+ return "default!";
155
+ };
156
+
149
157
  export const collectionDefaultExpr = (field: {
150
158
  isArray: boolean;
151
159
  isMap?: boolean;
@@ -21,6 +21,7 @@ import {
21
21
  import {
22
22
  collectionDefaultExpr,
23
23
  convertSpecType,
24
+ csLanguageDefault,
24
25
  nativeDefaultExpr,
25
26
  } from "./deterministic-type-converter.ts";
26
27
  import { Emit } from "./emit.ts";
@@ -52,7 +53,9 @@ class Generator extends Emit {
52
53
  const fields = declaredFields(table, "datasource", typesByName).map((f) => {
53
54
  const csType = csTypeFor(f, typesByName);
54
55
  const initializer =
55
- collectionDefaultExpr(f) ?? nativeDefaultExpr(fieldTypeOf(f, typesByName), f);
56
+ collectionDefaultExpr(f) ??
57
+ nativeDefaultExpr(fieldTypeOf(f, typesByName), f) ??
58
+ csLanguageDefault(csType);
56
59
  return {
57
60
  ident: this.casing.convertFields(f.name),
58
61
  csType,
@@ -24,6 +24,7 @@ import {
24
24
  import {
25
25
  collectionDefaultExpr,
26
26
  convertSpecType,
27
+ csLanguageDefault,
27
28
  nativeDefaultExpr,
28
29
  } from "./deterministic-type-converter.ts";
29
30
  import { Emit } from "./emit.ts";
@@ -81,7 +82,8 @@ class Generator extends Emit {
81
82
  collectionDefaultExpr(f) ??
82
83
  (f.kind === "primitive"
83
84
  ? nativeDefaultExpr(fieldTypeOf(f, typesByName), f)
84
- : undefined);
85
+ : undefined) ??
86
+ csLanguageDefault(csType);
85
87
  return {
86
88
  ident: this.casing.convertFields(f.name),
87
89
  csType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deterministic-code/datasources-cli",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "datasources": "./bin/datasources.mjs"