drizzle-kit 0.24.0-6386ea9 → 0.24.0-8d86512
Sign up to get free protection for your applications and to get access to all the features.
- package/api.d.mts +10 -0
- package/api.d.ts +10 -0
- package/api.js +116 -59
- package/api.mjs +116 -59
- package/bin.cjs +414 -742
- package/package.json +4 -3
- package/utils.js +2 -1
- package/utils.mjs +2 -1
package/bin.cjs
CHANGED
@@ -5687,11 +5687,30 @@ var init_mysqlSchema = __esm({
|
|
5687
5687
|
}
|
5688
5688
|
});
|
5689
5689
|
|
5690
|
+
// src/extensions/vector.ts
|
5691
|
+
var vectorOps;
|
5692
|
+
var init_vector = __esm({
|
5693
|
+
"src/extensions/vector.ts"() {
|
5694
|
+
"use strict";
|
5695
|
+
vectorOps = [
|
5696
|
+
"vector_l2_ops",
|
5697
|
+
"vector_ip_ops",
|
5698
|
+
"vector_cosine_ops",
|
5699
|
+
"vector_l1_ops",
|
5700
|
+
"bit_hamming_ops",
|
5701
|
+
"bit_jaccard_ops",
|
5702
|
+
"halfvec_l2_ops",
|
5703
|
+
"sparsevec_l2_ops"
|
5704
|
+
];
|
5705
|
+
}
|
5706
|
+
});
|
5707
|
+
|
5690
5708
|
// src/serializer/pgSchema.ts
|
5691
5709
|
var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, sequenceSchema, sequenceSquashed, columnV7, column2, columnSquashed, tableV32, compositePK2, uniqueConstraint2, tableV42, tableV5, tableV6, tableV7, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaInternalV6, pgSchemaExternal, pgSchemaInternalV7, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashedV6, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchemaV6, pgSchemaV7, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
|
5692
5710
|
var init_pgSchema = __esm({
|
5693
5711
|
"src/serializer/pgSchema.ts"() {
|
5694
5712
|
"use strict";
|
5713
|
+
init_vector();
|
5695
5714
|
init_global();
|
5696
5715
|
init_lib();
|
5697
5716
|
indexV2 = objectType({
|
@@ -5938,7 +5957,8 @@ var init_pgSchema = __esm({
|
|
5938
5957
|
objectType({
|
5939
5958
|
isArray: booleanType().optional(),
|
5940
5959
|
dimensions: numberType().optional(),
|
5941
|
-
rawType: stringType().optional()
|
5960
|
+
rawType: stringType().optional(),
|
5961
|
+
isDefaultAnExpression: booleanType().optional()
|
5942
5962
|
}).optional()
|
5943
5963
|
)
|
5944
5964
|
}).optional()
|
@@ -6076,7 +6096,7 @@ var init_pgSchema = __esm({
|
|
6076
6096
|
squashIdx: (idx) => {
|
6077
6097
|
index2.parse(idx);
|
6078
6098
|
return `${idx.name};${idx.columns.map(
|
6079
|
-
(c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass}`
|
6099
|
+
(c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass && vectorOps.includes(c.opclass) ? c.opclass : ""}`
|
6080
6100
|
).join(",,")};${idx.isUnique};${idx.concurrently};${idx.method};${idx.where};${JSON.stringify(idx.with)}`;
|
6081
6101
|
},
|
6082
6102
|
unsquashIdx: (input) => {
|
@@ -11372,7 +11392,7 @@ var init_cli = __esm({
|
|
11372
11392
|
extensionsFilters: literalType("postgis").array().optional(),
|
11373
11393
|
introspectCasing: casing,
|
11374
11394
|
breakpoints: booleanType().optional().default(true),
|
11375
|
-
|
11395
|
+
migrations: objectType({
|
11376
11396
|
prefix: prefix.optional().default("index")
|
11377
11397
|
}).optional()
|
11378
11398
|
}).passthrough();
|
@@ -17510,7 +17530,7 @@ var init_utils4 = __esm({
|
|
17510
17530
|
credentials: parsed2.data,
|
17511
17531
|
tablesFilter,
|
17512
17532
|
schemasFilter,
|
17513
|
-
prefix: ((_a = config.
|
17533
|
+
prefix: ((_a = config.migrations) == null ? void 0 : _a.prefix) || "index"
|
17514
17534
|
};
|
17515
17535
|
}
|
17516
17536
|
if (dialect7 === "mysql") {
|
@@ -17527,7 +17547,7 @@ var init_utils4 = __esm({
|
|
17527
17547
|
credentials: parsed2.data,
|
17528
17548
|
tablesFilter,
|
17529
17549
|
schemasFilter,
|
17530
|
-
prefix: ((_b = config.
|
17550
|
+
prefix: ((_b = config.migrations) == null ? void 0 : _b.prefix) || "index"
|
17531
17551
|
};
|
17532
17552
|
}
|
17533
17553
|
if (dialect7 === "sqlite") {
|
@@ -17544,7 +17564,7 @@ var init_utils4 = __esm({
|
|
17544
17564
|
credentials: parsed2.data,
|
17545
17565
|
tablesFilter,
|
17546
17566
|
schemasFilter,
|
17547
|
-
prefix: ((_c = config.
|
17567
|
+
prefix: ((_c = config.migrations) == null ? void 0 : _c.prefix) || "index"
|
17548
17568
|
};
|
17549
17569
|
}
|
17550
17570
|
assertUnreachable(dialect7);
|
@@ -18372,24 +18392,6 @@ var init_pgImports = __esm({
|
|
18372
18392
|
}
|
18373
18393
|
});
|
18374
18394
|
|
18375
|
-
// src/extensions/vector.ts
|
18376
|
-
var vectorOps;
|
18377
|
-
var init_vector = __esm({
|
18378
|
-
"src/extensions/vector.ts"() {
|
18379
|
-
"use strict";
|
18380
|
-
vectorOps = [
|
18381
|
-
"vector_l2_ops",
|
18382
|
-
"vector_ip_ops",
|
18383
|
-
"vector_cosine_ops",
|
18384
|
-
"vector_l1_ops",
|
18385
|
-
"bit_hamming_ops",
|
18386
|
-
"bit_jaccard_ops",
|
18387
|
-
"halfvec_l2_ops",
|
18388
|
-
"sparsevec_l2_ops"
|
18389
|
-
];
|
18390
|
-
}
|
18391
|
-
});
|
18392
|
-
|
18393
18395
|
// src/serializer/pgSerializer.ts
|
18394
18396
|
var pgSerializer_exports = {};
|
18395
18397
|
__export(pgSerializer_exports, {
|
@@ -18433,7 +18435,7 @@ function buildArrayString(array, sqlType) {
|
|
18433
18435
|
}).join(",");
|
18434
18436
|
return `{${values}}`;
|
18435
18437
|
}
|
18436
|
-
var import_drizzle_orm5, import_pg_core2, import_pg_core3, dialect5, indexName2, generatePgSnapshot, trimChar, fromDatabase2, columnToDefault, defaultForColumn;
|
18438
|
+
var import_drizzle_orm5, import_pg_core2, import_pg_core3, dialect5, indexName2, generatePgSnapshot, trimChar, fromDatabase2, columnToDefault, columnEnumNameToDefault, defaultForColumn;
|
18437
18439
|
var init_pgSerializer = __esm({
|
18438
18440
|
"src/serializer/pgSerializer.ts"() {
|
18439
18441
|
"use strict";
|
@@ -18908,7 +18910,7 @@ ${withStyle.errorWarning(
|
|
18908
18910
|
WHEN 'int2'::regtype THEN 'smallserial'
|
18909
18911
|
END
|
18910
18912
|
ELSE format_type(a.atttypid, a.atttypmod)
|
18911
|
-
END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name,
|
18913
|
+
END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, ns.nspname as type_schema,
|
18912
18914
|
pg_get_serial_sequence('"${tableSchema}"."${tableName}"', a.attname)::regclass as seq_name, INFORMATION_SCHEMA.COLUMNS.column_name,
|
18913
18915
|
INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt,
|
18914
18916
|
INFORMATION_SCHEMA.COLUMNS.udt_name as enum_name,
|
@@ -18919,6 +18921,7 @@ ${withStyle.errorWarning(
|
|
18919
18921
|
INFORMATION_SCHEMA.COLUMNS.identity_cycle
|
18920
18922
|
FROM pg_attribute a
|
18921
18923
|
JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
|
18924
|
+
JOIN pg_type t ON t.oid = a.atttypid LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
|
18922
18925
|
WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}' and INFORMATION_SCHEMA.COLUMNS.table_schema = '${tableSchema}'
|
18923
18926
|
AND a.attnum > 0
|
18924
18927
|
AND NOT a.attisdropped
|
@@ -18938,30 +18941,42 @@ ${withStyle.errorWarning(
|
|
18938
18941
|
}
|
18939
18942
|
const tableForeignKeys = await db.query(
|
18940
18943
|
`SELECT
|
18941
|
-
|
18942
|
-
|
18943
|
-
|
18944
|
-
|
18945
|
-
|
18946
|
-
|
18947
|
-
|
18948
|
-
|
18949
|
-
|
18950
|
-
|
18951
|
-
|
18952
|
-
|
18953
|
-
|
18954
|
-
|
18955
|
-
|
18956
|
-
|
18957
|
-
|
18958
|
-
|
18959
|
-
|
18960
|
-
|
18961
|
-
|
18962
|
-
|
18963
|
-
|
18964
|
-
|
18944
|
+
con.contype AS constraint_type,
|
18945
|
+
nsp.nspname AS constraint_schema,
|
18946
|
+
con.conname AS constraint_name,
|
18947
|
+
rel.relname AS table_name,
|
18948
|
+
att.attname AS column_name,
|
18949
|
+
fnsp.nspname AS foreign_table_schema,
|
18950
|
+
frel.relname AS foreign_table_name,
|
18951
|
+
fatt.attname AS foreign_column_name,
|
18952
|
+
CASE con.confupdtype
|
18953
|
+
WHEN 'a' THEN 'NO ACTION'
|
18954
|
+
WHEN 'r' THEN 'RESTRICT'
|
18955
|
+
WHEN 'n' THEN 'SET NULL'
|
18956
|
+
WHEN 'c' THEN 'CASCADE'
|
18957
|
+
WHEN 'd' THEN 'SET DEFAULT'
|
18958
|
+
END AS update_rule,
|
18959
|
+
CASE con.confdeltype
|
18960
|
+
WHEN 'a' THEN 'NO ACTION'
|
18961
|
+
WHEN 'r' THEN 'RESTRICT'
|
18962
|
+
WHEN 'n' THEN 'SET NULL'
|
18963
|
+
WHEN 'c' THEN 'CASCADE'
|
18964
|
+
WHEN 'd' THEN 'SET DEFAULT'
|
18965
|
+
END AS delete_rule
|
18966
|
+
FROM
|
18967
|
+
pg_catalog.pg_constraint con
|
18968
|
+
JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
|
18969
|
+
JOIN pg_catalog.pg_namespace nsp ON nsp.oid = con.connamespace
|
18970
|
+
LEFT JOIN pg_catalog.pg_attribute att ON att.attnum = ANY (con.conkey)
|
18971
|
+
AND att.attrelid = con.conrelid
|
18972
|
+
LEFT JOIN pg_catalog.pg_class frel ON frel.oid = con.confrelid
|
18973
|
+
LEFT JOIN pg_catalog.pg_namespace fnsp ON fnsp.oid = frel.relnamespace
|
18974
|
+
LEFT JOIN pg_catalog.pg_attribute fatt ON fatt.attnum = ANY (con.confkey)
|
18975
|
+
AND fatt.attrelid = con.confrelid
|
18976
|
+
WHERE
|
18977
|
+
nsp.nspname = '${tableSchema}'
|
18978
|
+
AND rel.relname = '${tableName}'
|
18979
|
+
AND con.contype IN ('f');`
|
18965
18980
|
);
|
18966
18981
|
foreignKeysCount += tableForeignKeys.length;
|
18967
18982
|
if (progressCallback) {
|
@@ -19019,6 +19034,7 @@ ${withStyle.errorWarning(
|
|
19019
19034
|
const columnDimensions = columnResponse.array_dimensions;
|
19020
19035
|
const enumType2 = columnResponse.enum_name;
|
19021
19036
|
let columnType = columnResponse.data_type;
|
19037
|
+
const typeSchema = columnResponse.type_schema;
|
19022
19038
|
const isGenerated = columnResponse.is_generated === "ALWAYS";
|
19023
19039
|
const generationExpression = columnResponse.generation_expression;
|
19024
19040
|
const isIdentity = columnResponse.is_identity === "YES";
|
@@ -19050,6 +19066,25 @@ ${withStyle.errorWarning(
|
|
19050
19066
|
};
|
19051
19067
|
}
|
19052
19068
|
const defaultValue = defaultForColumn(columnResponse);
|
19069
|
+
if (defaultValue === "NULL") {
|
19070
|
+
if (typeof internals.tables[tableName] === "undefined") {
|
19071
|
+
internals.tables[tableName] = {
|
19072
|
+
columns: {
|
19073
|
+
[columnName]: {
|
19074
|
+
isDefaultAnExpression: true
|
19075
|
+
}
|
19076
|
+
}
|
19077
|
+
};
|
19078
|
+
} else {
|
19079
|
+
if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
|
19080
|
+
internals.tables[tableName].columns[columnName] = {
|
19081
|
+
isDefaultAnExpression: true
|
19082
|
+
};
|
19083
|
+
} else {
|
19084
|
+
internals.tables[tableName].columns[columnName].isDefaultAnExpression = true;
|
19085
|
+
}
|
19086
|
+
}
|
19087
|
+
}
|
19053
19088
|
const isSerial = columnType === "serial";
|
19054
19089
|
let columnTypeMapped = columnType;
|
19055
19090
|
if (columnTypeMapped.startsWith("numeric(")) {
|
@@ -19095,7 +19130,7 @@ ${withStyle.errorWarning(
|
|
19095
19130
|
// filter vectors, but in future we should filter any extension that was installed by user
|
19096
19131
|
columnAdditionalDT === "USER-DEFINED" && !["vector", "geometry"].includes(enumType2) ? enumType2 : columnTypeMapped
|
19097
19132
|
),
|
19098
|
-
typeSchema: enumsToReturn[`${
|
19133
|
+
typeSchema: enumsToReturn[`${typeSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${typeSchema}.${enumType2}`].schema : void 0,
|
19099
19134
|
primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
|
19100
19135
|
// default: isSerial ? undefined : defaultValue,
|
19101
19136
|
notNull: columnResponse.is_nullable === "NO",
|
@@ -19270,11 +19305,11 @@ ${withStyle.errorWarning(
|
|
19270
19305
|
columnToDefault = {
|
19271
19306
|
"numeric(": "::numeric",
|
19272
19307
|
// text: "::text",
|
19273
|
-
|
19308
|
+
"character varying": "::character varying",
|
19274
19309
|
// "double precision": "::double precision",
|
19275
19310
|
// "time with time zone": "::time with time zone",
|
19276
19311
|
"time without time zone": "::time without time zone",
|
19277
|
-
//
|
19312
|
+
// 'timestamp with time zone': '::timestamp with time zone',
|
19278
19313
|
"timestamp without time zone": "::timestamp without time zone",
|
19279
19314
|
"timestamp(": "::timestamp without time zone",
|
19280
19315
|
// date: "::date",
|
@@ -19288,6 +19323,12 @@ ${withStyle.errorWarning(
|
|
19288
19323
|
// json: "::json",
|
19289
19324
|
"character(": "::bpchar"
|
19290
19325
|
};
|
19326
|
+
columnEnumNameToDefault = {
|
19327
|
+
timestamptz: "::timestamp with time zone",
|
19328
|
+
timestmap: "::time without time zone",
|
19329
|
+
time: "::time without time zone",
|
19330
|
+
timetz: "::time with time zone"
|
19331
|
+
};
|
19291
19332
|
defaultForColumn = (column7) => {
|
19292
19333
|
if (column7.column_default === null) {
|
19293
19334
|
return void 0;
|
@@ -19296,19 +19337,33 @@ ${withStyle.errorWarning(
|
|
19296
19337
|
return void 0;
|
19297
19338
|
}
|
19298
19339
|
const hasDifferentDefaultCast = Object.keys(columnToDefault).find((it) => column7.data_type.startsWith(it));
|
19340
|
+
const hasDifferentDefaultCastForEnum = Object.keys(columnEnumNameToDefault).find(
|
19341
|
+
(it) => column7.enum_name.startsWith(it)
|
19342
|
+
);
|
19299
19343
|
const columnDefaultAsString = column7.column_default.toString();
|
19300
|
-
|
19344
|
+
const endsWithEnumName = columnDefaultAsString.endsWith(
|
19345
|
+
hasDifferentDefaultCastForEnum ? columnEnumNameToDefault[hasDifferentDefaultCastForEnum] : column7.data_type
|
19346
|
+
);
|
19347
|
+
const endsWithTypeName = columnDefaultAsString.endsWith(
|
19301
19348
|
hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : column7.data_type
|
19302
|
-
)
|
19349
|
+
);
|
19350
|
+
if (endsWithTypeName || endsWithEnumName) {
|
19303
19351
|
const nonPrefixPart = column7.column_default.length - (hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column7.data_type}`).length - 1;
|
19304
|
-
|
19352
|
+
let rt = column7.column_default.toString().substring(0, nonPrefixPart + 1);
|
19305
19353
|
if (/^-?[\d.]+(?:e-?\d+)?$/.test(rt) && !column7.data_type.startsWith("numeric")) {
|
19306
19354
|
return Number(rt);
|
19307
19355
|
} else if (column7.data_type === "json" || column7.data_type === "jsonb") {
|
19356
|
+
if (rt.startsWith("'")) {
|
19357
|
+
rt = rt.slice(1, -1);
|
19358
|
+
}
|
19308
19359
|
const jsonWithoutSpaces = JSON.stringify(JSON.parse(rt));
|
19309
19360
|
return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column7.data_type}`}`;
|
19310
19361
|
} else if (column7.data_type === "boolean") {
|
19311
19362
|
return column7.column_default === "true";
|
19363
|
+
} else if (rt === "NULL") {
|
19364
|
+
return `NULL`;
|
19365
|
+
} else if (rt.startsWith("'") && rt.endsWith("'")) {
|
19366
|
+
return rt;
|
19312
19367
|
} else {
|
19313
19368
|
return `'${rt}'`;
|
19314
19369
|
}
|
@@ -19317,8 +19372,10 @@ ${withStyle.errorWarning(
|
|
19317
19372
|
return Number(columnDefaultAsString);
|
19318
19373
|
} else if (column7.data_type === "boolean") {
|
19319
19374
|
return column7.column_default === "true";
|
19375
|
+
} else if (columnDefaultAsString === "NULL") {
|
19376
|
+
return `NULL`;
|
19320
19377
|
} else {
|
19321
|
-
return `${columnDefaultAsString}`;
|
19378
|
+
return `${columnDefaultAsString.replace(/\\/g, "`\\")}`;
|
19322
19379
|
}
|
19323
19380
|
}
|
19324
19381
|
};
|
@@ -74154,7 +74211,7 @@ var init_pgIntrospect = __esm({
|
|
74154
74211
|
});
|
74155
74212
|
|
74156
74213
|
// src/introspect-sqlite.ts
|
74157
|
-
var sqliteImportsList, indexName3, objToStatement2, relations, withCasing, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, column4, createTableColumns, createTableIndexes, createTableUniques, createTablePKs, createTableFKs;
|
74214
|
+
var sqliteImportsList, indexName3, objToStatement2, relations, escapeColumnKey, withCasing, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, column4, createTableColumns, createTableIndexes, createTableUniques, createTablePKs, createTableFKs;
|
74158
74215
|
var init_introspect_sqlite = __esm({
|
74159
74216
|
"src/introspect-sqlite.ts"() {
|
74160
74217
|
"use strict";
|
@@ -74181,12 +74238,18 @@ var init_introspect_sqlite = __esm({
|
|
74181
74238
|
return statement;
|
74182
74239
|
};
|
74183
74240
|
relations = /* @__PURE__ */ new Set();
|
74241
|
+
escapeColumnKey = (value) => {
|
74242
|
+
if (/^(?![a-zA-Z_$][a-zA-Z0-9_$]*$).+$/.test(value)) {
|
74243
|
+
return `"${value}"`;
|
74244
|
+
}
|
74245
|
+
return value;
|
74246
|
+
};
|
74184
74247
|
withCasing = (value, casing2) => {
|
74185
|
-
if (
|
74186
|
-
return value;
|
74248
|
+
if (casing2 === "preserve") {
|
74249
|
+
return escapeColumnKey(value);
|
74187
74250
|
}
|
74188
74251
|
if (casing2 === "camel") {
|
74189
|
-
return value.camelCase();
|
74252
|
+
return escapeColumnKey(value.camelCase());
|
74190
74253
|
}
|
74191
74254
|
return value;
|
74192
74255
|
};
|
@@ -75184,7 +75247,7 @@ var require_pluralize = __commonJS({
|
|
75184
75247
|
});
|
75185
75248
|
|
75186
75249
|
// src/introspect-mysql.ts
|
75187
|
-
var mysqlImportsList, objToStatement22, timeConfig, binaryConfig, importsPatch, relations2, prepareCasing, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, mapColumnDefaultForJson, column5, createTableColumns2, createTableIndexes2, createTableUniques2, createTablePKs2, createTableFKs2;
|
75250
|
+
var mysqlImportsList, objToStatement22, timeConfig, binaryConfig, importsPatch, relations2, escapeColumnKey2, prepareCasing, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, mapColumnDefaultForJson, column5, createTableColumns2, createTableIndexes2, createTableUniques2, createTablePKs2, createTableFKs2;
|
75188
75251
|
var init_introspect_mysql = __esm({
|
75189
75252
|
"src/introspect-mysql.ts"() {
|
75190
75253
|
"use strict";
|
@@ -75255,14 +75318,20 @@ var init_introspect_mysql = __esm({
|
|
75255
75318
|
"timestamp without time zone": "timestamp"
|
75256
75319
|
};
|
75257
75320
|
relations2 = /* @__PURE__ */ new Set();
|
75321
|
+
escapeColumnKey2 = (value) => {
|
75322
|
+
if (/^(?![a-zA-Z_$][a-zA-Z0-9_$]*$).+$/.test(value)) {
|
75323
|
+
return `"${value}"`;
|
75324
|
+
}
|
75325
|
+
return value;
|
75326
|
+
};
|
75258
75327
|
prepareCasing = (casing2) => (value) => {
|
75259
|
-
if (
|
75260
|
-
return value;
|
75328
|
+
if (casing2 === "preserve") {
|
75329
|
+
return escapeColumnKey2(value);
|
75261
75330
|
}
|
75262
75331
|
if (casing2 === "camel") {
|
75263
|
-
return value.camelCase();
|
75332
|
+
return escapeColumnKey2(value.camelCase());
|
75264
75333
|
}
|
75265
|
-
return value;
|
75334
|
+
return escapeColumnKey2(value);
|
75266
75335
|
};
|
75267
75336
|
schemaToTypeScript2 = (schema5, casing2) => {
|
75268
75337
|
const withCasing4 = prepareCasing(casing2);
|
@@ -75728,7 +75797,7 @@ import { sql } from "drizzle-orm"
|
|
75728
75797
|
});
|
75729
75798
|
|
75730
75799
|
// src/introspect-pg.ts
|
75731
|
-
var import_drizzle_orm8, import_relations, pgImportsList,
|
75800
|
+
var import_drizzle_orm8, import_relations, pgImportsList, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, mapColumnDefault3, importsPatch2, relations3, escapeColumnKey3, withCasing2, paramNameFor, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableUniques3, createTableFKs3;
|
75732
75801
|
var init_introspect_pg = __esm({
|
75733
75802
|
"src/introspect-pg.ts"() {
|
75734
75803
|
"use strict";
|
@@ -75772,16 +75841,6 @@ var init_introspect_pg = __esm({
|
|
75772
75841
|
"line",
|
75773
75842
|
"geometry"
|
75774
75843
|
]);
|
75775
|
-
objToStatement23 = (json) => {
|
75776
|
-
json = Object.fromEntries(Object.entries(json).filter((it) => it[1]));
|
75777
|
-
const keys = Object.keys(json);
|
75778
|
-
if (keys.length === 0)
|
75779
|
-
return;
|
75780
|
-
let statement = "{ ";
|
75781
|
-
statement += keys.map((it) => `${it}: "${json[it]}"`).join(", ");
|
75782
|
-
statement += " }";
|
75783
|
-
return statement;
|
75784
|
-
};
|
75785
75844
|
timeConfig2 = (json) => {
|
75786
75845
|
json = Object.fromEntries(Object.entries(json).filter((it) => it[1]));
|
75787
75846
|
const keys = Object.keys(json);
|
@@ -75841,6 +75900,12 @@ var init_introspect_pg = __esm({
|
|
75841
75900
|
statement += " }";
|
75842
75901
|
return statement;
|
75843
75902
|
};
|
75903
|
+
mapColumnDefault3 = (defaultValue, isExpression) => {
|
75904
|
+
if (isExpression) {
|
75905
|
+
return `sql\`${defaultValue}\``;
|
75906
|
+
}
|
75907
|
+
return defaultValue;
|
75908
|
+
};
|
75844
75909
|
importsPatch2 = {
|
75845
75910
|
"double precision": "doublePrecision",
|
75846
75911
|
"timestamp without time zone": "timestamp",
|
@@ -75849,12 +75914,18 @@ var init_introspect_pg = __esm({
|
|
75849
75914
|
"time with time zone": "time"
|
75850
75915
|
};
|
75851
75916
|
relations3 = /* @__PURE__ */ new Set();
|
75917
|
+
escapeColumnKey3 = (value) => {
|
75918
|
+
if (/^(?![a-zA-Z_$][a-zA-Z0-9_$]*$).+$/.test(value)) {
|
75919
|
+
return `"${value}"`;
|
75920
|
+
}
|
75921
|
+
return value;
|
75922
|
+
};
|
75852
75923
|
withCasing2 = (value, casing2) => {
|
75853
75924
|
if (casing2 === "preserve") {
|
75854
|
-
return value;
|
75925
|
+
return escapeColumnKey3(value);
|
75855
75926
|
}
|
75856
75927
|
if (casing2 === "camel") {
|
75857
|
-
return value.camelCase();
|
75928
|
+
return escapeColumnKey3(value.camelCase());
|
75858
75929
|
}
|
75859
75930
|
assertUnreachable(casing2);
|
75860
75931
|
};
|
@@ -75874,7 +75945,13 @@ var init_introspect_pg = __esm({
|
|
75874
75945
|
return [it[0], withCasing2(it[1], casing2)];
|
75875
75946
|
})
|
75876
75947
|
);
|
75877
|
-
const enumTypes =
|
75948
|
+
const enumTypes = Object.values(schema5.enums).reduce(
|
75949
|
+
(acc, cur) => {
|
75950
|
+
acc.add(`${cur.schema}.${cur.name}`);
|
75951
|
+
return acc;
|
75952
|
+
},
|
75953
|
+
/* @__PURE__ */ new Set()
|
75954
|
+
);
|
75878
75955
|
const imports = Object.values(schema5.tables).reduce(
|
75879
75956
|
(res, it) => {
|
75880
75957
|
const idxImports = Object.values(it.indexes).map((idx) => idx.isUnique ? "uniqueIndex" : "index");
|
@@ -75895,9 +75972,6 @@ var init_introspect_pg = __esm({
|
|
75895
75972
|
res.pg.push(...fkImpots);
|
75896
75973
|
res.pg.push(...pkImports);
|
75897
75974
|
res.pg.push(...uniqueImports);
|
75898
|
-
if (enumTypes.size > 0) {
|
75899
|
-
res.pg.push("pgEnum");
|
75900
|
-
}
|
75901
75975
|
const columnImports = Object.values(it.columns).map((col) => {
|
75902
75976
|
let patched = importsPatch2[col.type] || col.type;
|
75903
75977
|
patched = patched.startsWith("varchar(") ? "varchar" : patched;
|
@@ -75916,6 +75990,13 @@ var init_introspect_pg = __esm({
|
|
75916
75990
|
},
|
75917
75991
|
{ pg: [] }
|
75918
75992
|
);
|
75993
|
+
Object.values(schema5.enums).forEach((it) => {
|
75994
|
+
if (it.schema && it.schema !== "public" && it.schema !== "") {
|
75995
|
+
imports.pg.push("pgSchema");
|
75996
|
+
} else if (it.schema === "public") {
|
75997
|
+
imports.pg.push("pgEnum");
|
75998
|
+
}
|
75999
|
+
});
|
75919
76000
|
const enumStatements = Object.values(schema5.enums).map((it) => {
|
75920
76001
|
const enumSchema3 = schemas[it.schema];
|
75921
76002
|
const paramName = paramNameFor(it.name, enumSchema3);
|
@@ -75944,10 +76025,7 @@ var init_introspect_pg = __esm({
|
|
75944
76025
|
schema5.internal
|
75945
76026
|
);
|
75946
76027
|
statement += "}";
|
75947
|
-
|
75948
|
-
return it.columnsFrom.length > 1 || isSelf3(it);
|
75949
|
-
});
|
75950
|
-
if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
|
76028
|
+
if (Object.keys(table4.indexes).length > 0 || Object.values(table4.foreignKeys).length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
|
75951
76029
|
statement += ",\n";
|
75952
76030
|
statement += "(table) => {\n";
|
75953
76031
|
statement += " return {\n";
|
@@ -75956,7 +76034,7 @@ var init_introspect_pg = __esm({
|
|
75956
76034
|
Object.values(table4.indexes),
|
75957
76035
|
casing2
|
75958
76036
|
);
|
75959
|
-
statement += createTableFKs3(Object.values(
|
76037
|
+
statement += createTableFKs3(Object.values(table4.foreignKeys), schemas, casing2);
|
75960
76038
|
statement += createTablePKs3(
|
75961
76039
|
Object.values(table4.compositePrimaryKeys),
|
75962
76040
|
casing2
|
@@ -75998,9 +76076,18 @@ var init_introspect_pg = __esm({
|
|
75998
76076
|
isSelf3 = (fk4) => {
|
75999
76077
|
return fk4.tableFrom === fk4.tableTo;
|
76000
76078
|
};
|
76001
|
-
column6 = (tableName, type, name, enumTypes, casing2, defaultValue, internals) => {
|
76002
|
-
var _a;
|
76079
|
+
column6 = (tableName, type, name, enumTypes, typeSchema, casing2, defaultValue, internals) => {
|
76080
|
+
var _a, _b, _c;
|
76081
|
+
const isExpression = ((_b = (_a = internals == null ? void 0 : internals.tables[tableName]) == null ? void 0 : _a.columns[name]) == null ? void 0 : _b.isDefaultAnExpression) ?? false;
|
76003
76082
|
const lowered = type.toLowerCase();
|
76083
|
+
if (enumTypes.has(`${typeSchema}.${type}`)) {
|
76084
|
+
let out = `${withCasing2(name, casing2)}: ${withCasing2(
|
76085
|
+
paramNameFor(type, typeSchema),
|
76086
|
+
casing2
|
76087
|
+
)}("${name}")`;
|
76088
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76089
|
+
return out;
|
76090
|
+
}
|
76004
76091
|
if (lowered.startsWith("serial")) {
|
76005
76092
|
return `${withCasing2(name, casing2)}: serial("${name}")`;
|
76006
76093
|
}
|
@@ -76015,34 +76102,34 @@ var init_introspect_pg = __esm({
|
|
76015
76102
|
}
|
76016
76103
|
if (lowered.startsWith("integer")) {
|
76017
76104
|
let out = `${withCasing2(name, casing2)}: integer("${name}")`;
|
76018
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76105
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76019
76106
|
return out;
|
76020
76107
|
}
|
76021
76108
|
if (lowered.startsWith("smallint")) {
|
76022
76109
|
let out = `${withCasing2(name, casing2)}: smallint("${name}")`;
|
76023
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76110
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76024
76111
|
return out;
|
76025
76112
|
}
|
76026
76113
|
if (lowered.startsWith("bigint")) {
|
76027
76114
|
let out = `// You can use { mode: "bigint" } if numbers are exceeding js number limitations
|
76028
76115
|
`;
|
76029
76116
|
out += `${withCasing2(name, casing2)}: bigint("${name}", { mode: "number" })`;
|
76030
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76117
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76031
76118
|
return out;
|
76032
76119
|
}
|
76033
76120
|
if (lowered.startsWith("boolean")) {
|
76034
76121
|
let out = `${withCasing2(name, casing2)}: boolean("${name}")`;
|
76035
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76122
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76036
76123
|
return out;
|
76037
76124
|
}
|
76038
76125
|
if (lowered.startsWith("double precision")) {
|
76039
76126
|
let out = `${withCasing2(name, casing2)}: doublePrecision("${name}")`;
|
76040
|
-
out += defaultValue ? `.default(${defaultValue})` : "";
|
76127
|
+
out += defaultValue ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76041
76128
|
return out;
|
76042
76129
|
}
|
76043
76130
|
if (lowered.startsWith("real")) {
|
76044
76131
|
let out = `${withCasing2(name, casing2)}: real("${name}")`;
|
76045
|
-
out += defaultValue ? `.default(${defaultValue})` : "";
|
76132
|
+
out += defaultValue ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76046
76133
|
return out;
|
76047
76134
|
}
|
76048
76135
|
if (lowered.startsWith("uuid")) {
|
@@ -76058,7 +76145,7 @@ var init_introspect_pg = __esm({
|
|
76058
76145
|
}
|
76059
76146
|
let out = params ? `${withCasing2(name, casing2)}: numeric("${name}", ${timeConfig2(params)})` : `${withCasing2(name, casing2)}: numeric("${name}")`;
|
76060
76147
|
defaultValue = defaultValue ? defaultValue.startsWith(`'`) && defaultValue.endsWith(`'`) ? defaultValue.substring(1, defaultValue.length - 1) : defaultValue : void 0;
|
76061
|
-
out += defaultValue ? `.default('${defaultValue}')` : "";
|
76148
|
+
out += defaultValue ? `.default('${mapColumnDefault3(defaultValue, isExpression)}')` : "";
|
76062
76149
|
return out;
|
76063
76150
|
}
|
76064
76151
|
if (lowered.startsWith("timestamp")) {
|
@@ -76073,7 +76160,7 @@ var init_introspect_pg = __esm({
|
|
76073
76160
|
mode: "'string'"
|
76074
76161
|
});
|
76075
76162
|
let out = params ? `${withCasing2(name, casing2)}: timestamp("${name}", ${params})` : `${withCasing2(name, casing2)}: timestamp("${name}")`;
|
76076
|
-
defaultValue = defaultValue === "now()"
|
76163
|
+
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue === "CURRENT_TIMESTAMP" ? ".default(sql`CURRENT_TIMESTAMP`)" : defaultValue ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76077
76164
|
out += defaultValue;
|
76078
76165
|
return out;
|
76079
76166
|
}
|
@@ -76085,14 +76172,14 @@ var init_introspect_pg = __esm({
|
|
76085
76172
|
precision = precision ? precision : null;
|
76086
76173
|
const params = timeConfig2({ precision, withTimezone });
|
76087
76174
|
let out = params ? `${withCasing2(name, casing2)}: time("${name}", ${params})` : `${withCasing2(name, casing2)}: time("${name}")`;
|
76088
|
-
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${defaultValue})` : "";
|
76175
|
+
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76089
76176
|
out += defaultValue;
|
76090
76177
|
return out;
|
76091
76178
|
}
|
76092
76179
|
if (lowered.startsWith("interval")) {
|
76093
76180
|
const params = intervalConfig(lowered);
|
76094
76181
|
let out = params ? `${withCasing2(name, casing2)}: interval("${name}", ${params})` : `${withCasing2(name, casing2)}: interval("${name}")`;
|
76095
|
-
out += defaultValue ? `.default(${defaultValue})` : "";
|
76182
|
+
out += defaultValue ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76096
76183
|
return out;
|
76097
76184
|
}
|
76098
76185
|
if (lowered === "date") {
|
@@ -76122,22 +76209,22 @@ var init_introspect_pg = __esm({
|
|
76122
76209
|
}
|
76123
76210
|
if (lowered.startsWith("inet")) {
|
76124
76211
|
let out = `${withCasing2(name, casing2)}: inet("${name}")`;
|
76125
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76212
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76126
76213
|
return out;
|
76127
76214
|
}
|
76128
76215
|
if (lowered.startsWith("cidr")) {
|
76129
76216
|
let out = `${withCasing2(name, casing2)}: cidr("${name}")`;
|
76130
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76217
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76131
76218
|
return out;
|
76132
76219
|
}
|
76133
76220
|
if (lowered.startsWith("macaddr")) {
|
76134
76221
|
let out = `${withCasing2(name, casing2)}: macaddr("${name}")`;
|
76135
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76222
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76136
76223
|
return out;
|
76137
76224
|
}
|
76138
76225
|
if (lowered.startsWith("macaddr8")) {
|
76139
76226
|
let out = `${withCasing2(name, casing2)}: macaddr8("${name}")`;
|
76140
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76227
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76141
76228
|
return out;
|
76142
76229
|
}
|
76143
76230
|
if (lowered.startsWith("varchar")) {
|
@@ -76154,17 +76241,17 @@ var init_introspect_pg = __esm({
|
|
76154
76241
|
} else {
|
76155
76242
|
out = `${withCasing2(name, casing2)}: varchar("${name}")`;
|
76156
76243
|
}
|
76157
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76244
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76158
76245
|
return out;
|
76159
76246
|
}
|
76160
76247
|
if (lowered.startsWith("point")) {
|
76161
76248
|
let out = `${withCasing2(name, casing2)}: point("${name}")`;
|
76162
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76249
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76163
76250
|
return out;
|
76164
76251
|
}
|
76165
76252
|
if (lowered.startsWith("line")) {
|
76166
76253
|
let out = `${withCasing2(name, casing2)}: point("${name}")`;
|
76167
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76254
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76168
76255
|
return out;
|
76169
76256
|
}
|
76170
76257
|
if (lowered.startsWith("geometry")) {
|
@@ -76182,7 +76269,7 @@ var init_introspect_pg = __esm({
|
|
76182
76269
|
} else {
|
76183
76270
|
out = `${withCasing2(name, casing2)}: geometry("${name}")`;
|
76184
76271
|
}
|
76185
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76272
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76186
76273
|
if (isGeoUnknown) {
|
76187
76274
|
let unknown2 = `// TODO: failed to parse geometry type because found more than 2 options inside geometry function '${type}'
|
76188
76275
|
// Introspect is currently supporting only type and srid options
|
@@ -76206,7 +76293,7 @@ var init_introspect_pg = __esm({
|
|
76206
76293
|
} else {
|
76207
76294
|
out = `${withCasing2(name, casing2)}: vector("${name}")`;
|
76208
76295
|
}
|
76209
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76296
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76210
76297
|
return out;
|
76211
76298
|
}
|
76212
76299
|
if (lowered.startsWith("char")) {
|
@@ -76222,28 +76309,20 @@ var init_introspect_pg = __esm({
|
|
76222
76309
|
} else {
|
76223
76310
|
out = `${withCasing2(name, casing2)}: char("${name}")`;
|
76224
76311
|
}
|
76225
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76312
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76226
76313
|
return out;
|
76227
76314
|
}
|
76228
|
-
const columnInternals = (
|
76315
|
+
const columnInternals = (_c = internals == null ? void 0 : internals.tables[tableName]) == null ? void 0 : _c.columns[name];
|
76229
76316
|
if (typeof columnInternals !== "undefined") {
|
76230
76317
|
if (columnInternals.isArray && columnInternals.rawType && enumTypes.has(columnInternals.rawType)) {
|
76231
76318
|
let out = `${withCasing2(columnInternals.rawType, casing2)}: ${withCasing2(
|
76232
76319
|
columnInternals.rawType,
|
76233
76320
|
casing2
|
76234
76321
|
)}("${name}")`;
|
76235
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76322
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault3(defaultValue, isExpression)})` : "";
|
76236
76323
|
return out;
|
76237
76324
|
}
|
76238
76325
|
}
|
76239
|
-
if (enumTypes.has(type)) {
|
76240
|
-
let out = `${withCasing2(name, casing2)}: ${withCasing2(
|
76241
|
-
type,
|
76242
|
-
casing2
|
76243
|
-
)}("${name}")`;
|
76244
|
-
out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
|
76245
|
-
return out;
|
76246
|
-
}
|
76247
76326
|
let unknown = `// TODO: failed to parse database type '${type}'
|
76248
76327
|
`;
|
76249
76328
|
unknown += ` ${withCasing2(name, casing2)}: unknown("${name}")`;
|
@@ -76276,6 +76355,7 @@ var init_introspect_pg = __esm({
|
|
76276
76355
|
it.type,
|
76277
76356
|
it.name,
|
76278
76357
|
enumTypes,
|
76358
|
+
it.typeSchema ?? "public",
|
76279
76359
|
casing2,
|
76280
76360
|
it.default,
|
76281
76361
|
internals
|
@@ -76317,29 +76397,6 @@ var init_introspect_pg = __esm({
|
|
76317
76397
|
}
|
76318
76398
|
statement += it.identity ? generateIdentityParams(it.identity) : "";
|
76319
76399
|
statement += it.generated ? `.generatedAlwaysAs(sql\`${it.generated.as}\`)` : "";
|
76320
|
-
const fks2 = fkByColumnName[it.name];
|
76321
|
-
if (fks2) {
|
76322
|
-
const fksStatement = fks2.map((it2) => {
|
76323
|
-
const onDelete = it2.onDelete && it2.onDelete !== "no action" ? it2.onDelete : null;
|
76324
|
-
const onUpdate = it2.onUpdate && it2.onUpdate !== "no action" ? it2.onUpdate : null;
|
76325
|
-
const params = { onDelete, onUpdate };
|
76326
|
-
const typeSuffix = isCyclic3(it2) ? ": AnyPgColumn" : "";
|
76327
|
-
const paramsStr = objToStatement23(params);
|
76328
|
-
const tableSchema = schemas[it2.schemaTo || ""];
|
76329
|
-
const paramName = paramNameFor(it2.tableTo, tableSchema);
|
76330
|
-
if (paramsStr) {
|
76331
|
-
return `.references(()${typeSuffix} => ${withCasing2(
|
76332
|
-
paramName,
|
76333
|
-
casing2
|
76334
|
-
)}.${withCasing2(it2.columnsTo[0], casing2)}, ${paramsStr} )`;
|
76335
|
-
}
|
76336
|
-
return `.references(()${typeSuffix} => ${withCasing2(
|
76337
|
-
paramName,
|
76338
|
-
casing2
|
76339
|
-
)}.${withCasing2(it2.columnsTo[0], casing2)})`;
|
76340
|
-
}).join("");
|
76341
|
-
statement += fksStatement;
|
76342
|
-
}
|
76343
76400
|
statement += ",\n";
|
76344
76401
|
});
|
76345
76402
|
return statement;
|
@@ -76363,7 +76420,7 @@ var init_introspect_pg = __esm({
|
|
76363
76420
|
if (it2.isExpression) {
|
76364
76421
|
return `sql\`${it2.expression}\``;
|
76365
76422
|
} else {
|
76366
|
-
return `table.${withCasing2(it2.expression, casing2)}${it2.opclass && vectorOps.includes(it2.opclass) ? `.op("${it2.opclass}")` : ""}`;
|
76423
|
+
return `table.${withCasing2(it2.expression, casing2)}${it2.asc ? ".asc()" : ".desc()"}${it2.nulls === "first" ? ".nullsFirst()" : ".nullsLast()"}${it2.opclass && vectorOps.includes(it2.opclass) ? `.op("${it2.opclass}")` : ""}`;
|
76367
76424
|
}
|
76368
76425
|
}).join(", ")})`;
|
76369
76426
|
statement += it.where ? `.where(sql\`${it.where}\`)` : "";
|
@@ -80519,7 +80576,7 @@ var init_studio2 = __esm({
|
|
80519
80576
|
}
|
80520
80577
|
});
|
80521
80578
|
|
80522
|
-
// ../node_modules/.pnpm/@drizzle-team+brocli@0.
|
80579
|
+
// ../node_modules/.pnpm/@drizzle-team+brocli@0.8.2/node_modules/@drizzle-team/brocli/index.js
|
80523
80580
|
var __create2 = Object.create;
|
80524
80581
|
var __defProp2 = Object.defineProperty;
|
80525
80582
|
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
@@ -80966,299 +81023,130 @@ var require_shell_quote = __commonJS2({
|
|
80966
81023
|
}
|
80967
81024
|
});
|
80968
81025
|
var BroCliError = class extends Error {
|
80969
|
-
constructor(message
|
81026
|
+
constructor(message) {
|
80970
81027
|
const errPrefix = "BroCli error: ";
|
80971
81028
|
super(message === void 0 ? message : `${errPrefix}${message}`);
|
80972
|
-
this.event = event;
|
80973
81029
|
}
|
80974
81030
|
};
|
80975
81031
|
var import_clone = __toESM2(require_clone(), 1);
|
80976
|
-
var
|
80977
|
-
|
80978
|
-
|
80979
|
-
|
80980
|
-
|
80981
|
-
|
80982
|
-
|
80983
|
-
|
80984
|
-
|
80985
|
-
|
80986
|
-
|
80987
|
-
|
80988
|
-
|
80989
|
-
|
80990
|
-
|
80991
|
-
|
80992
|
-
|
80993
|
-
|
80994
|
-
|
80995
|
-
|
80996
|
-
|
80997
|
-
|
80998
|
-
|
80999
|
-
|
81000
|
-
|
81001
|
-
}
|
81002
|
-
|
81003
|
-
|
81004
|
-
|
81005
|
-
|
81006
|
-
|
81007
|
-
|
81008
|
-
|
81009
|
-
|
81010
|
-
result = "string";
|
81011
|
-
break;
|
81012
|
-
}
|
81013
|
-
case "positional": {
|
81014
|
-
result = `${option.isRequired ? "<" : "["}${option.enumVals ? option.enumVals.join("|") : option.name}${option.isRequired ? ">" : "]"}`;
|
81015
|
-
break;
|
81016
|
-
}
|
81017
|
-
}
|
81018
|
-
if (option.isRequired && option.type !== "positional")
|
81019
|
-
result = "!" + result.length ? " " : "" + result;
|
81020
|
-
return result;
|
81021
|
-
};
|
81022
|
-
var defaultEventHandler = async (event) => {
|
81023
|
-
var _a;
|
81024
|
-
switch (event.type) {
|
81025
|
-
case "command_help": {
|
81026
|
-
const command2 = event.command;
|
81027
|
-
const commandName = getCommandNameWithParents(command2);
|
81028
|
-
const cliName = event.name;
|
81029
|
-
const desc = command2.desc ?? command2.shortDesc;
|
81030
|
-
const subs = (_a = command2.subcommands) == null ? void 0 : _a.filter((s2) => !s2.hidden);
|
81031
|
-
const subcommands = subs && subs.length ? subs : void 0;
|
81032
|
-
if (desc !== void 0) {
|
81033
|
-
console.log(`
|
81034
|
-
${desc}`);
|
81035
|
-
}
|
81036
|
-
const opts = Object.values(command2.options ?? {}).filter(
|
81037
|
-
(opt) => !opt.config.isHidden
|
81038
|
-
);
|
81039
|
-
const positionals = opts.filter((opt) => opt.config.type === "positional");
|
81040
|
-
const options = opts.filter((opt) => opt.config.type !== "positional");
|
81041
|
-
console.log("\nUsage:");
|
81042
|
-
if (command2.handler) {
|
81043
|
-
console.log(
|
81044
|
-
` ${cliName ? cliName + " " : ""}${commandName}${positionals.length ? " " + positionals.map(({ config: p2 }) => getOptionTypeText(p2)).join(" ") : ""} [flags]`
|
81045
|
-
);
|
81046
|
-
} else
|
81047
|
-
console.log(` ${cliName ? cliName + " " : ""}${commandName} [command]`);
|
81048
|
-
if (command2.aliases) {
|
81049
|
-
console.log(`
|
81050
|
-
Aliases:`);
|
81051
|
-
console.log(` ${[command2.name, ...command2.aliases].join(", ")}`);
|
81052
|
-
}
|
81053
|
-
if (subcommands) {
|
81054
|
-
console.log("\nAvailable Commands:");
|
81055
|
-
const padding = 3;
|
81056
|
-
const maxLength = subcommands.reduce((p2, e2) => e2.name.length > p2 ? e2.name.length : p2, 0);
|
81057
|
-
const paddedLength = maxLength + padding;
|
81058
|
-
const preDescPad = 2 + paddedLength;
|
81059
|
-
const data = subcommands.map(
|
81060
|
-
(s2) => ` ${s2.name.padEnd(paddedLength)}${(() => {
|
81061
|
-
const description = s2.shortDesc ?? s2.desc;
|
81062
|
-
if (!(description == null ? void 0 : description.length))
|
81063
|
-
return "";
|
81064
|
-
const split = description.split("\n");
|
81065
|
-
const first = split.shift();
|
81066
|
-
const final = [first, ...split.map((s22) => "".padEnd(preDescPad) + s22)].join("\n");
|
81067
|
-
return final;
|
81068
|
-
})()}`
|
81069
|
-
).join("\n");
|
81070
|
-
console.log(data);
|
81071
|
-
}
|
81072
|
-
if (options.length) {
|
81073
|
-
const aliasLength = options.reduce((p2, e2) => {
|
81074
|
-
const currentLength = e2.config.aliases.reduce((pa, a) => pa + a.length, 0) + (e2.config.aliases.length - 1) * 2 + 1;
|
81075
|
-
return currentLength > p2 ? currentLength : p2;
|
81076
|
-
}, 0);
|
81077
|
-
const paddedAliasLength = aliasLength > 0 ? aliasLength + 1 : 0;
|
81078
|
-
const nameLength = options.reduce((p2, e2) => {
|
81079
|
-
const typeLen = getOptionTypeText(e2.config).length;
|
81080
|
-
const length = typeLen > 0 ? e2.config.name.length + 1 + typeLen : e2.config.name.length;
|
81081
|
-
return length > p2 ? length : p2;
|
81082
|
-
}, 0) + 3;
|
81083
|
-
const preDescPad = paddedAliasLength + nameLength + 2;
|
81084
|
-
const data = options.map(
|
81085
|
-
({ config: opt }) => ` ${`${opt.aliases.length ? opt.aliases.join(", ") + "," : ""}`.padEnd(paddedAliasLength)}${`${opt.name}${(() => {
|
81086
|
-
const typeText = getOptionTypeText(opt);
|
81087
|
-
return typeText.length ? " " + typeText : "";
|
81088
|
-
})()}`.padEnd(nameLength)}${(() => {
|
81089
|
-
var _a2;
|
81090
|
-
if (!((_a2 = opt.description) == null ? void 0 : _a2.length)) {
|
81091
|
-
return opt.default !== void 0 ? `default: ${JSON.stringify(opt.default)}` : "";
|
81092
|
-
}
|
81093
|
-
const split = opt.description.split("\n");
|
81094
|
-
const first = split.shift();
|
81095
|
-
const def = opt.default !== void 0 ? ` (default: ${JSON.stringify(opt.default)})` : "";
|
81096
|
-
const final = [first, ...split.map((s2) => "".padEnd(preDescPad) + s2)].join("\n") + def;
|
81097
|
-
return final;
|
81098
|
-
})()}`
|
81099
|
-
).join("\n");
|
81100
|
-
console.log("\nFlags:");
|
81101
|
-
console.log(data);
|
81102
|
-
}
|
81103
|
-
console.log("\nGlobal flags:");
|
81104
|
-
console.log(` -h, --help help for ${commandName}`);
|
81105
|
-
console.log(` -v, --version version${cliName ? ` for ${cliName}` : ""}`);
|
81106
|
-
if (subcommands) {
|
81107
|
-
console.log(
|
81108
|
-
`
|
81109
|
-
Use "${cliName ? cliName + " " : ""}${commandName} [command] --help" for more information about a command.
|
81110
|
-
`
|
81111
|
-
);
|
81112
|
-
}
|
81113
|
-
return true;
|
81114
|
-
}
|
81115
|
-
case "global_help": {
|
81116
|
-
const cliName = event.name;
|
81117
|
-
const desc = event.description;
|
81118
|
-
const commands = event.commands.filter((c) => !c.hidden);
|
81119
|
-
if (desc !== void 0) {
|
81120
|
-
console.log(`${desc}
|
81121
|
-
`);
|
81122
|
-
}
|
81123
|
-
console.log("Usage:");
|
81124
|
-
console.log(` ${cliName ? cliName + " " : ""}[command]`);
|
81125
|
-
if (commands.length) {
|
81126
|
-
console.log("\nAvailable Commands:");
|
81127
|
-
const padding = 3;
|
81128
|
-
const maxLength = commands.reduce((p2, e2) => e2.name.length > p2 ? e2.name.length : p2, 0);
|
81129
|
-
const paddedLength = maxLength + padding;
|
81130
|
-
const data = commands.map(
|
81131
|
-
(\u0441) => ` ${\u0441.name.padEnd(paddedLength)}${(() => {
|
81132
|
-
const desc2 = \u0441.shortDesc ?? \u0441.desc;
|
81133
|
-
if (!(desc2 == null ? void 0 : desc2.length))
|
81134
|
-
return "";
|
81135
|
-
const split = desc2.split("\n");
|
81136
|
-
const first = split.shift();
|
81137
|
-
const final = [first, ...split.map((s2) => "".padEnd(paddedLength + 2) + s2)].join("\n");
|
81138
|
-
return final;
|
81139
|
-
})()}`
|
81140
|
-
).join("\n");
|
81141
|
-
console.log(data);
|
81142
|
-
} else {
|
81143
|
-
console.log("\nNo available commands.");
|
81144
|
-
}
|
81145
|
-
console.log("\nFlags:");
|
81146
|
-
console.log(` -h, --help help${cliName ? ` for ${cliName}` : ""}`);
|
81147
|
-
console.log(` -v, --version version${cliName ? ` for ${cliName}` : ""}`);
|
81148
|
-
console.log("\n");
|
81149
|
-
return true;
|
81150
|
-
}
|
81151
|
-
case "version": {
|
81152
|
-
return true;
|
81153
|
-
}
|
81154
|
-
case "error": {
|
81155
|
-
let msg;
|
81156
|
-
switch (event.violation) {
|
81157
|
-
case "above_max": {
|
81158
|
-
const matchedName = event.offender.namePart;
|
81159
|
-
const data = event.offender.dataPart;
|
81160
|
-
const option = event.option;
|
81161
|
-
const max = option.maxVal;
|
81162
|
-
msg = `Invalid value: number type argument '${matchedName}' expects maximal value of ${max} as an input, got: ${data}`;
|
81163
|
-
break;
|
81164
|
-
}
|
81165
|
-
case "below_min": {
|
81166
|
-
const matchedName = event.offender.namePart;
|
81167
|
-
const data = event.offender.dataPart;
|
81168
|
-
const option = event.option;
|
81169
|
-
const min = option.minVal;
|
81170
|
-
msg = `Invalid value: number type argument '${matchedName}' expects minimal value of ${min} as an input, got: ${data}`;
|
81171
|
-
break;
|
81172
|
-
}
|
81173
|
-
case "expected_int": {
|
81174
|
-
const matchedName = event.offender.namePart;
|
81175
|
-
const data = event.offender.dataPart;
|
81176
|
-
msg = `Invalid value: number type argument '${matchedName}' expects an integer as an input, got: ${data}`;
|
81177
|
-
break;
|
81178
|
-
}
|
81179
|
-
case "invalid_boolean_syntax": {
|
81180
|
-
const matchedName = event.offender.namePart;
|
81181
|
-
const data = event.offender.dataPart;
|
81182
|
-
msg = `Invalid syntax: boolean type argument '${matchedName}' must have it's value passed in the following formats: ${matchedName}=<value> | ${matchedName} <value> | ${matchedName}.
|
81183
|
-
Allowed values: true, false, 0, 1`;
|
81184
|
-
break;
|
81185
|
-
}
|
81186
|
-
case "invalid_string_syntax": {
|
81187
|
-
const matchedName = event.offender.namePart;
|
81188
|
-
msg = `Invalid syntax: string type argument '${matchedName}' must have it's value passed in the following formats: ${matchedName}=<value> | ${matchedName} <value>`;
|
81189
|
-
break;
|
81190
|
-
}
|
81191
|
-
case "invalid_number_syntax": {
|
81192
|
-
const matchedName = event.offender.namePart;
|
81193
|
-
msg = `Invalid syntax: number type argument '${matchedName}' must have it's value passed in the following formats: ${matchedName}=<value> | ${matchedName} <value>`;
|
81194
|
-
break;
|
81195
|
-
}
|
81196
|
-
case "invalid_number_value": {
|
81197
|
-
const matchedName = event.offender.namePart;
|
81198
|
-
const data = event.offender.dataPart;
|
81199
|
-
msg = `Invalid value: number type argument '${matchedName}' expects a number as an input, got: ${data}`;
|
81200
|
-
break;
|
81201
|
-
}
|
81202
|
-
case "enum_violation": {
|
81203
|
-
const matchedName = event.offender.namePart;
|
81204
|
-
const data = event.offender.dataPart;
|
81205
|
-
const option = event.option;
|
81206
|
-
const values = option.enumVals;
|
81207
|
-
msg = option.type === "positional" ? `Invalid value: value for the positional argument '${option.name}' must be either one of the following: ${values.join(", ")}; Received: ${data}` : `Invalid value: value for the argument '${matchedName}' must be either one of the following: ${values.join(", ")}; Received: ${data}`;
|
81208
|
-
break;
|
81209
|
-
}
|
81210
|
-
case "unknown_command_error": {
|
81211
|
-
const msg2 = `Unknown command: '${event.offender}'.
|
81212
|
-
Type '--help' to get help on the cli.`;
|
81213
|
-
console.error(msg2);
|
81214
|
-
return true;
|
81215
|
-
}
|
81216
|
-
case "unknown_subcommand_error": {
|
81217
|
-
const cName = getCommandNameWithParents(event.command);
|
81218
|
-
const msg2 = `Unknown command: ${cName} ${event.offender}.
|
81219
|
-
Type '${cName} --help' to get the help on command.`;
|
81220
|
-
console.error(msg2);
|
81221
|
-
return true;
|
81222
|
-
}
|
81223
|
-
case "missing_args_error": {
|
81224
|
-
const missingOpts = event.missing;
|
81225
|
-
msg = `Command '${command.name}' is missing following required options: ${missingOpts.map((opt) => {
|
81226
|
-
const name = opt.shift();
|
81227
|
-
const aliases = opt;
|
81228
|
-
if (aliases.length)
|
81229
|
-
return `${name} [${aliases.join(", ")}]`;
|
81230
|
-
return name;
|
81231
|
-
}).join(", ")}`;
|
81232
|
-
break;
|
81233
|
-
}
|
81234
|
-
case "unrecognized_args_error": {
|
81235
|
-
const { command: command2, unrecognized } = event;
|
81236
|
-
msg = `Unrecognized options for command '${command2.name}': ${unrecognized.join(", ")}`;
|
81237
|
-
break;
|
81238
|
-
}
|
81239
|
-
case "unknown_error": {
|
81240
|
-
const e2 = event.error;
|
81241
|
-
console.error(typeof e2 === "object" && e2 !== null && "message" in e2 ? e2.message : e2);
|
81242
|
-
return true;
|
81243
|
-
}
|
81244
|
-
}
|
81245
|
-
console.error(msg);
|
81246
|
-
return true;
|
81247
|
-
}
|
81032
|
+
var import_shell_quote = __toESM2(require_shell_quote(), 1);
|
81033
|
+
var defaultTheme = (calledFor) => {
|
81034
|
+
if (Array.isArray(calledFor)) {
|
81035
|
+
const cmds = calledFor.filter((cmd) => !cmd.hidden);
|
81036
|
+
const tableCmds = cmds.map((cmd) => ({
|
81037
|
+
name: cmd.name,
|
81038
|
+
aliases: cmd.aliases ? cmd.aliases.join(", ") : "-",
|
81039
|
+
description: cmd.description ?? "-"
|
81040
|
+
}));
|
81041
|
+
console.log(`Here's the list of all available commands:`);
|
81042
|
+
console.table(tableCmds);
|
81043
|
+
console.log(
|
81044
|
+
"To read the details about any particular command type: [commandName] --help"
|
81045
|
+
);
|
81046
|
+
} else {
|
81047
|
+
const options = calledFor.options ? Object.values(calledFor.options).filter((opt) => {
|
81048
|
+
var _a;
|
81049
|
+
return !((_a = opt.config) == null ? void 0 : _a.isHidden);
|
81050
|
+
}).map(
|
81051
|
+
({ config: opt }) => ({
|
81052
|
+
name: opt.name,
|
81053
|
+
aliases: opt.aliases.length ? `${opt.aliases.join(", ")}` : "-",
|
81054
|
+
description: opt.description ?? "-",
|
81055
|
+
type: opt.type,
|
81056
|
+
required: opt.isRequired ? "\u2713" : "\u2717"
|
81057
|
+
})
|
81058
|
+
) : void 0;
|
81059
|
+
console.log(
|
81060
|
+
`Command: ${calledFor.name}${calledFor.aliases ? ` [${calledFor.aliases.join(", ")}]` : ""}${calledFor.description ? ` - ${calledFor.description}` : ""}`
|
81061
|
+
);
|
81062
|
+
if (!(options == null ? void 0 : options.length))
|
81063
|
+
return;
|
81064
|
+
console.log("\nOptions:");
|
81065
|
+
console.table(options);
|
81248
81066
|
}
|
81249
|
-
return false;
|
81250
81067
|
};
|
81251
|
-
var eventHandlerWrapper = (customEventHandler) => async (event) => await customEventHandler(event) ? true : await defaultEventHandler(event);
|
81252
|
-
var import_shell_quote = __toESM2(require_shell_quote(), 1);
|
81253
81068
|
function isInt(value) {
|
81254
81069
|
return value === Math.floor(value);
|
81255
81070
|
}
|
81256
|
-
var
|
81071
|
+
var unknownCommand = (caller) => {
|
81072
|
+
const msg = `Unknown command: '${caller}'.
|
81073
|
+
Type '--help' to get help on the cli.`;
|
81074
|
+
return new Error(msg);
|
81075
|
+
};
|
81076
|
+
var unknownSubcommand = (command2, caller) => {
|
81077
|
+
const name = getCommandNameRecursive(command2);
|
81078
|
+
const msg = `Unknown command: ${name} ${caller}.
|
81079
|
+
Type '${name} --help' to get the help on command.`;
|
81080
|
+
new Error(
|
81081
|
+
msg
|
81082
|
+
);
|
81083
|
+
return new Error(msg);
|
81084
|
+
};
|
81085
|
+
var missingRequired = (command2, missingOpts) => {
|
81086
|
+
const msg = `Command '${command2.name}' is missing following required options: ${missingOpts.map((opt) => {
|
81087
|
+
const name = opt.shift();
|
81088
|
+
const aliases = opt;
|
81089
|
+
if (aliases.length)
|
81090
|
+
return `${name} [${aliases.join(", ")}]`;
|
81091
|
+
return name;
|
81092
|
+
}).join(", ")}`;
|
81093
|
+
return new Error(msg);
|
81094
|
+
};
|
81095
|
+
var unrecognizedOptions = (command2, unrecognizedArgs) => {
|
81096
|
+
const msg = `Unrecognized options for command '${command2.name}': ${unrecognizedArgs.join(", ")}`;
|
81097
|
+
return new Error(msg);
|
81098
|
+
};
|
81099
|
+
var invalidBooleanSyntax = (matchedName) => {
|
81100
|
+
return new Error(
|
81101
|
+
`Invalid syntax: boolean type argument '${matchedName}' must have it's value passed in the following formats: ${matchedName}=<value> | ${matchedName} <value> | ${matchedName}.
|
81102
|
+
Allowed values: true, false, 0, 1`
|
81103
|
+
);
|
81104
|
+
};
|
81105
|
+
var invalidStringSyntax = (matchedName) => {
|
81106
|
+
return new Error(
|
81107
|
+
`Invalid syntax: string type argument '${matchedName}' must have it's value passed in the following formats: ${matchedName}=<value> | ${matchedName} <value>`
|
81108
|
+
);
|
81109
|
+
};
|
81110
|
+
var enumViolation = (matchedName, data, values) => {
|
81111
|
+
return new Error(
|
81112
|
+
`Invalid value: value for the argument '${matchedName}' must be either one of the following: ${values.join(", ")}; Received: ${data}`
|
81113
|
+
);
|
81114
|
+
};
|
81115
|
+
var enumViolationPos = (matchedName, data, values) => {
|
81116
|
+
return new Error(
|
81117
|
+
`Invalid value: value for the argument '${matchedName}' must be either one of the following: ${values.join(", ")}; Received: ${data}`
|
81118
|
+
);
|
81119
|
+
};
|
81120
|
+
var invalidNumberSyntax = (matchedName) => {
|
81121
|
+
return new Error(
|
81122
|
+
`Invalid syntax: number type argument '${matchedName}' must have it's value passed in the following formats: ${matchedName}=<value> | ${matchedName} <value>`
|
81123
|
+
);
|
81124
|
+
};
|
81125
|
+
var invalidNumberValue = (matchedName, data) => {
|
81126
|
+
return new Error(
|
81127
|
+
`Invalid value: number type argument '${matchedName}' expects a number as an input, got: ${data}`
|
81128
|
+
);
|
81129
|
+
};
|
81130
|
+
var invalidInteger = (matchedName, data) => {
|
81131
|
+
return new Error(
|
81132
|
+
`Invalid value: number type argument '${matchedName}' expects an integer as an input, got: ${data}`
|
81133
|
+
);
|
81134
|
+
};
|
81135
|
+
var belowMin = (matchedName, data, min) => {
|
81136
|
+
return new Error(
|
81137
|
+
`Invalid value: number type argument '${matchedName}' expects minimal value of ${min} as an input, got: ${data}`
|
81138
|
+
);
|
81139
|
+
};
|
81140
|
+
var aboveMax = (matchedName, data, max) => {
|
81141
|
+
return new Error(
|
81142
|
+
`Invalid value: number type argument '${matchedName}' expects maximal value of ${max} as an input, got: ${data}`
|
81143
|
+
);
|
81144
|
+
};
|
81257
81145
|
var generatePrefix = (name) => name.startsWith("-") ? name : name.length > 1 ? `--${name}` : `-${name}`;
|
81258
81146
|
var validateOptions = (config) => {
|
81259
81147
|
const cloned = (0, import_clone.default)(config);
|
81260
81148
|
const entries = [];
|
81261
|
-
const storedNames =
|
81149
|
+
const storedNames = {};
|
81262
81150
|
const cfgEntries = Object.entries(cloned);
|
81263
81151
|
for (const [key, value] of cfgEntries) {
|
81264
81152
|
const cfg = value._.config;
|
@@ -81268,13 +81156,13 @@ var validateOptions = (config) => {
|
|
81268
81156
|
continue;
|
81269
81157
|
if (cfg.name.includes("=")) {
|
81270
81158
|
throw new BroCliError(
|
81271
|
-
`Can't define option
|
81159
|
+
`Can't define option ${cfg.name} - option names and aliases cannot contain '='!`
|
81272
81160
|
);
|
81273
81161
|
}
|
81274
81162
|
for (const alias of cfg.aliases) {
|
81275
81163
|
if (alias.includes("=")) {
|
81276
81164
|
throw new BroCliError(
|
81277
|
-
`Can't define option
|
81165
|
+
`Can't define option ${cfg.name} - option names and aliases cannot contain '='!`
|
81278
81166
|
);
|
81279
81167
|
}
|
81280
81168
|
}
|
@@ -81292,33 +81180,33 @@ var validateOptions = (config) => {
|
|
81292
81180
|
for (const name of allNames) {
|
81293
81181
|
const match2 = reservedNames.find((n) => n === name);
|
81294
81182
|
if (match2)
|
81295
|
-
throw new BroCliError(`Can't define option
|
81183
|
+
throw new BroCliError(`Can't define option ${cfg.name} - name '${match2}' is reserved!`);
|
81296
81184
|
}
|
81297
|
-
|
81185
|
+
const storageVals = Object.values(storedNames);
|
81186
|
+
for (const storage2 of storageVals) {
|
81298
81187
|
const nameOccupier = storage2.find((e2) => e2 === cfg.name);
|
81299
81188
|
if (!nameOccupier)
|
81300
81189
|
continue;
|
81301
81190
|
throw new BroCliError(
|
81302
|
-
`Can't define option '${cfg.name}'
|
81191
|
+
`Can't define option '${cfg.name}': name is already in use by option '${storage2[0]}'!`
|
81303
81192
|
);
|
81304
81193
|
}
|
81305
81194
|
for (const alias of cfg.aliases) {
|
81306
|
-
for (const storage2 of
|
81195
|
+
for (const storage2 of storageVals) {
|
81307
81196
|
const nameOccupier = storage2.find((e2) => e2 === alias);
|
81308
81197
|
if (!nameOccupier)
|
81309
81198
|
continue;
|
81310
81199
|
throw new BroCliError(
|
81311
|
-
`Can't define option '${cfg.name}'
|
81200
|
+
`Can't define option '${cfg.name}': alias '${alias}' is already in use by option '${storage2[0]}'!`
|
81312
81201
|
);
|
81313
81202
|
}
|
81314
81203
|
}
|
81315
|
-
|
81316
|
-
storedNames.
|
81317
|
-
|
81318
|
-
if (currentNames.findIndex((e2) => e2 === name) === idx)
|
81204
|
+
storedNames[cfg.name] = [cfg.name, ...cfg.aliases];
|
81205
|
+
storedNames[cfg.name].forEach((name, idx) => {
|
81206
|
+
if (storedNames[cfg.name].findIndex((e2) => e2 === name) === idx)
|
81319
81207
|
return;
|
81320
81208
|
throw new BroCliError(
|
81321
|
-
`Can't define option '${cfg.name}'
|
81209
|
+
`Can't define option '${cfg.name}': duplicate aliases '${name}'!`
|
81322
81210
|
);
|
81323
81211
|
});
|
81324
81212
|
entries.push([key, { config: cfg, $output: void 0 }]);
|
@@ -81339,17 +81227,14 @@ var command = (command2) => {
|
|
81339
81227
|
`Can't define command '${cmd.name}' - command can't have subcommands and positional args at the same time!`
|
81340
81228
|
);
|
81341
81229
|
}
|
81342
|
-
if (!command2.handler && !command2.subcommands) {
|
81343
|
-
throw new BroCliError(
|
81344
|
-
`Can't define command '${cmd.name}' - command without subcommands must have a handler present!`
|
81345
|
-
);
|
81346
|
-
}
|
81347
81230
|
const processedOptions = command2.options ? validateOptions(command2.options) : void 0;
|
81348
81231
|
cmd.options = processedOptions;
|
81349
81232
|
cmd.name = cmd.name ?? ((_a = cmd.aliases) == null ? void 0 : _a.shift());
|
81350
81233
|
if (!cmd.name)
|
81351
81234
|
throw new BroCliError(`Can't define command without name!`);
|
81352
81235
|
cmd.aliases = ((_b = cmd.aliases) == null ? void 0 : _b.length) ? cmd.aliases : void 0;
|
81236
|
+
if (!cmd.handler)
|
81237
|
+
throw new BroCliError(`Can't define command '${cmd.name}' - command must have a handler!`);
|
81353
81238
|
if (cmd.name.startsWith("-")) {
|
81354
81239
|
throw new BroCliError(`Can't define command '${cmd.name}' - command name can't start with '-'!`);
|
81355
81240
|
}
|
@@ -81379,7 +81264,7 @@ var command = (command2) => {
|
|
81379
81264
|
}
|
81380
81265
|
return cmd;
|
81381
81266
|
};
|
81382
|
-
var getCommandInner = (commands, candidates, args
|
81267
|
+
var getCommandInner = (commands, candidates, args) => {
|
81383
81268
|
const { data: arg, originalIndex: index4 } = candidates.shift();
|
81384
81269
|
const command2 = commands.find((c) => {
|
81385
81270
|
const names = c.aliases ? [c.name, ...c.aliases] : [c.name];
|
@@ -81400,20 +81285,12 @@ var getCommandInner = (commands, candidates, args, cliName, cliDescription) => {
|
|
81400
81285
|
};
|
81401
81286
|
}
|
81402
81287
|
const newCandidates = candidates.map((c) => ({ data: c.data, originalIndex: c.originalIndex - 1 }));
|
81403
|
-
const subcommand = getCommandInner(command2.subcommands, newCandidates, newArgs
|
81404
|
-
if (!subcommand.command)
|
81405
|
-
throw
|
81406
|
-
type: "error",
|
81407
|
-
violation: "unknown_subcommand_error",
|
81408
|
-
name: cliName,
|
81409
|
-
description: cliDescription,
|
81410
|
-
command: command2,
|
81411
|
-
offender: candidates[0].data
|
81412
|
-
});
|
81413
|
-
}
|
81288
|
+
const subcommand = getCommandInner(command2.subcommands, newCandidates, newArgs);
|
81289
|
+
if (!subcommand.command)
|
81290
|
+
throw unknownSubcommand(command2, candidates[0].data);
|
81414
81291
|
return subcommand;
|
81415
81292
|
};
|
81416
|
-
var getCommand = (commands, args
|
81293
|
+
var getCommand = (commands, args) => {
|
81417
81294
|
var _a;
|
81418
81295
|
const candidates = [];
|
81419
81296
|
for (let i2 = 0; i2 < args.length; ++i2) {
|
@@ -81447,23 +81324,15 @@ var getCommand = (commands, args, cliName, cliDescription) => {
|
|
81447
81324
|
args: removeByIndex(args, firstCandidate.originalIndex)
|
81448
81325
|
};
|
81449
81326
|
}
|
81450
|
-
const { command: command2, args: argsRes } = getCommandInner(commands, candidates, args
|
81451
|
-
if (!command2)
|
81452
|
-
throw
|
81453
|
-
type: "error",
|
81454
|
-
violation: "unknown_command_error",
|
81455
|
-
commands,
|
81456
|
-
name: cliName,
|
81457
|
-
description: cliDescription,
|
81458
|
-
offender: firstCandidate.data
|
81459
|
-
});
|
81460
|
-
}
|
81327
|
+
const { command: command2, args: argsRes } = getCommandInner(commands, candidates, args);
|
81328
|
+
if (!command2)
|
81329
|
+
throw unknownCommand(firstCandidate.data);
|
81461
81330
|
return {
|
81462
81331
|
command: command2,
|
81463
81332
|
args: argsRes
|
81464
81333
|
};
|
81465
81334
|
};
|
81466
|
-
var parseArg = (
|
81335
|
+
var parseArg = (options, positionals, arg, nextArg) => {
|
81467
81336
|
let data = void 0;
|
81468
81337
|
const argSplit = arg.split("=");
|
81469
81338
|
const hasEq = arg.includes("=");
|
@@ -81484,18 +81353,8 @@ var parseArg = (command2, options, positionals, arg, nextArg, cliName, cliDescri
|
|
81484
81353
|
if (!positionals.length)
|
81485
81354
|
return {};
|
81486
81355
|
const pos = positionals.shift();
|
81487
|
-
if (pos[1].enumVals && !pos[1].enumVals.find((val2) => val2 ===
|
81488
|
-
throw
|
81489
|
-
type: "error",
|
81490
|
-
name: cliName,
|
81491
|
-
description: cliDescription,
|
81492
|
-
violation: "enum_violation",
|
81493
|
-
command: command2,
|
81494
|
-
option: pos[1],
|
81495
|
-
offender: {
|
81496
|
-
dataPart: arg
|
81497
|
-
}
|
81498
|
-
});
|
81356
|
+
if (pos[1].enumVals && !pos[1].enumVals.find((val2) => val2 === dataPart)) {
|
81357
|
+
throw enumViolationPos(pos[1].name, arg, pos[1].enumVals);
|
81499
81358
|
}
|
81500
81359
|
data = arg;
|
81501
81360
|
return {
|
@@ -81530,126 +81389,32 @@ var parseArg = (command2, options, positionals, arg, nextArg, cliName, cliDescri
|
|
81530
81389
|
skipNext = false;
|
81531
81390
|
return true;
|
81532
81391
|
}
|
81533
|
-
throw
|
81534
|
-
type: "error",
|
81535
|
-
name: cliName,
|
81536
|
-
description: cliDescription,
|
81537
|
-
violation: "invalid_boolean_syntax",
|
81538
|
-
option: opt,
|
81539
|
-
command: command2,
|
81540
|
-
offender: {
|
81541
|
-
namePart,
|
81542
|
-
dataPart
|
81543
|
-
}
|
81544
|
-
});
|
81392
|
+
throw invalidBooleanSyntax(match2);
|
81545
81393
|
} else {
|
81546
81394
|
const match2 = names.find((name) => name === namePart);
|
81547
81395
|
if (!match2)
|
81548
81396
|
return false;
|
81549
81397
|
if (opt.type === "string") {
|
81550
|
-
if (!hasEq && nextArg === void 0)
|
81551
|
-
throw
|
81552
|
-
type: "error",
|
81553
|
-
name: cliName,
|
81554
|
-
description: cliDescription,
|
81555
|
-
violation: "invalid_string_syntax",
|
81556
|
-
option: opt,
|
81557
|
-
command: command2,
|
81558
|
-
offender: {
|
81559
|
-
namePart,
|
81560
|
-
dataPart
|
81561
|
-
}
|
81562
|
-
});
|
81563
|
-
}
|
81398
|
+
if (!hasEq && nextArg === void 0)
|
81399
|
+
throw invalidStringSyntax(match2);
|
81564
81400
|
if (opt.enumVals && !opt.enumVals.find((val2) => val2 === dataPart)) {
|
81565
|
-
throw
|
81566
|
-
type: "error",
|
81567
|
-
name: cliName,
|
81568
|
-
description: cliDescription,
|
81569
|
-
violation: "enum_violation",
|
81570
|
-
option: opt,
|
81571
|
-
command: command2,
|
81572
|
-
offender: {
|
81573
|
-
namePart,
|
81574
|
-
dataPart
|
81575
|
-
}
|
81576
|
-
});
|
81401
|
+
throw enumViolation(match2, dataPart, opt.enumVals);
|
81577
81402
|
}
|
81578
81403
|
data = dataPart;
|
81579
81404
|
return true;
|
81580
81405
|
}
|
81581
|
-
if (!hasEq && nextArg === void 0)
|
81582
|
-
throw
|
81583
|
-
type: "error",
|
81584
|
-
name: cliName,
|
81585
|
-
description: cliDescription,
|
81586
|
-
violation: "invalid_number_syntax",
|
81587
|
-
option: opt,
|
81588
|
-
command: command2,
|
81589
|
-
offender: {
|
81590
|
-
namePart,
|
81591
|
-
dataPart
|
81592
|
-
}
|
81593
|
-
});
|
81594
|
-
}
|
81406
|
+
if (!hasEq && nextArg === void 0)
|
81407
|
+
throw invalidNumberSyntax(match2);
|
81595
81408
|
const numData = Number(dataPart);
|
81596
|
-
if (isNaN(numData))
|
81597
|
-
throw
|
81598
|
-
|
81599
|
-
|
81600
|
-
|
81601
|
-
|
81602
|
-
|
81603
|
-
|
81604
|
-
|
81605
|
-
namePart,
|
81606
|
-
dataPart
|
81607
|
-
}
|
81608
|
-
});
|
81609
|
-
}
|
81610
|
-
if (opt.isInt && !isInt(numData)) {
|
81611
|
-
throw new BroCliError(void 0, {
|
81612
|
-
type: "error",
|
81613
|
-
name: cliName,
|
81614
|
-
description: cliDescription,
|
81615
|
-
violation: "expected_int",
|
81616
|
-
option: opt,
|
81617
|
-
command: command2,
|
81618
|
-
offender: {
|
81619
|
-
namePart,
|
81620
|
-
dataPart
|
81621
|
-
}
|
81622
|
-
});
|
81623
|
-
}
|
81624
|
-
if (opt.minVal !== void 0 && numData < opt.minVal) {
|
81625
|
-
throw new BroCliError(void 0, {
|
81626
|
-
type: "error",
|
81627
|
-
name: cliName,
|
81628
|
-
description: cliDescription,
|
81629
|
-
violation: "below_min",
|
81630
|
-
option: opt,
|
81631
|
-
command: command2,
|
81632
|
-
offender: {
|
81633
|
-
namePart,
|
81634
|
-
dataPart
|
81635
|
-
}
|
81636
|
-
});
|
81637
|
-
}
|
81638
|
-
if (opt.maxVal !== void 0 && numData > opt.maxVal) {
|
81639
|
-
throw new BroCliError(void 0, {
|
81640
|
-
type: "error",
|
81641
|
-
name: cliName,
|
81642
|
-
description: cliDescription,
|
81643
|
-
violation: "above_max",
|
81644
|
-
option: opt,
|
81645
|
-
command: command2,
|
81646
|
-
offender: {
|
81647
|
-
namePart,
|
81648
|
-
dataPart
|
81649
|
-
}
|
81650
|
-
});
|
81651
|
-
}
|
81652
|
-
data = numData;
|
81409
|
+
if (isNaN(numData))
|
81410
|
+
throw invalidNumberValue(match2, dataPart);
|
81411
|
+
if (opt.isInt && !isInt(numData))
|
81412
|
+
throw invalidInteger(match2, dataPart);
|
81413
|
+
if (opt.minVal !== void 0 && numData < opt.minVal)
|
81414
|
+
throw belowMin(match2, dataPart, opt.minVal);
|
81415
|
+
if (opt.maxVal !== void 0 && numData > opt.maxVal)
|
81416
|
+
throw aboveMax(match2, dataPart, opt.maxVal);
|
81417
|
+
data = dataPart;
|
81653
81418
|
return true;
|
81654
81419
|
}
|
81655
81420
|
});
|
@@ -81660,7 +81425,7 @@ var parseArg = (command2, options, positionals, arg, nextArg, cliName, cliDescri
|
|
81660
81425
|
option: option == null ? void 0 : option[1]
|
81661
81426
|
};
|
81662
81427
|
};
|
81663
|
-
var parseOptions = (command2, args,
|
81428
|
+
var parseOptions = (command2, args, omitKeysOfUndefinedOptions) => {
|
81664
81429
|
const options = command2.options;
|
81665
81430
|
const optEntries = Object.entries(options ?? {}).map(
|
81666
81431
|
(opt) => [opt[0], opt[1].config]
|
@@ -81680,16 +81445,16 @@ var parseOptions = (command2, args, cliName, cliDescription, omitKeysOfUndefined
|
|
81680
81445
|
skipNext,
|
81681
81446
|
isHelp,
|
81682
81447
|
isVersion
|
81683
|
-
} = parseArg(
|
81448
|
+
} = parseArg(nonPositionalEntries, positionalEntries, arg, nextArg);
|
81684
81449
|
if (!option)
|
81685
81450
|
unrecognizedArgsArr.push(arg.split("=")[0]);
|
81686
81451
|
if (skipNext)
|
81687
81452
|
++i2;
|
81453
|
+
result[name] = data;
|
81688
81454
|
if (isHelp)
|
81689
81455
|
return "help";
|
81690
81456
|
if (isVersion)
|
81691
81457
|
return "version";
|
81692
|
-
result[name] = data;
|
81693
81458
|
}
|
81694
81459
|
for (const [optKey, option] of optEntries) {
|
81695
81460
|
const data = result[optKey] ?? option.default;
|
@@ -81702,29 +81467,19 @@ var parseOptions = (command2, args, cliName, cliDescription, omitKeysOfUndefined
|
|
81702
81467
|
if (option.isRequired && result[optKey] === void 0)
|
81703
81468
|
missingRequiredArr.push([option.name, ...option.aliases]);
|
81704
81469
|
}
|
81705
|
-
if (missingRequiredArr.length)
|
81706
|
-
throw
|
81707
|
-
|
81708
|
-
|
81709
|
-
|
81710
|
-
description: cliDescription,
|
81711
|
-
command: command2,
|
81712
|
-
missing: missingRequiredArr
|
81713
|
-
});
|
81714
|
-
}
|
81715
|
-
if (unrecognizedArgsArr.length) {
|
81716
|
-
throw new BroCliError(void 0, {
|
81717
|
-
type: "error",
|
81718
|
-
violation: "unrecognized_args_error",
|
81719
|
-
name: cliName,
|
81720
|
-
description: cliDescription,
|
81721
|
-
command: command2,
|
81722
|
-
unrecognized: unrecognizedArgsArr
|
81723
|
-
});
|
81724
|
-
}
|
81725
|
-
return Object.keys(result).length ? result : void 0;
|
81470
|
+
if (missingRequiredArr.length)
|
81471
|
+
throw missingRequired(command2, missingRequiredArr);
|
81472
|
+
if (unrecognizedArgsArr.length)
|
81473
|
+
throw unrecognizedOptions(command2, unrecognizedArgsArr);
|
81474
|
+
return result;
|
81726
81475
|
};
|
81727
|
-
var
|
81476
|
+
var executeOrLog = async (target) => {
|
81477
|
+
if (!target || typeof target === "string")
|
81478
|
+
console.log(target);
|
81479
|
+
else
|
81480
|
+
await target();
|
81481
|
+
};
|
81482
|
+
var getCommandNameRecursive = (command2) => command2.parent ? `${getCommandNameRecursive(command2.parent)} ${command2.name}` : command2.name;
|
81728
81483
|
var validateCommands = (commands, parent) => {
|
81729
81484
|
const storedNames = {};
|
81730
81485
|
for (const cmd of commands) {
|
@@ -81733,8 +81488,8 @@ var validateCommands = (commands, parent) => {
|
|
81733
81488
|
const nameOccupier = storage2.find((e2) => e2 === cmd.name);
|
81734
81489
|
if (!nameOccupier)
|
81735
81490
|
continue;
|
81736
|
-
throw new
|
81737
|
-
`Can't define command '${
|
81491
|
+
throw new Error(
|
81492
|
+
`Can't define command '${getCommandNameRecursive(cmd)}': name is already in use by command '${parent ? `${getCommandNameRecursive(parent)} ` : ""}${storage2[0]}'!`
|
81738
81493
|
);
|
81739
81494
|
}
|
81740
81495
|
if (cmd.aliases) {
|
@@ -81743,8 +81498,8 @@ var validateCommands = (commands, parent) => {
|
|
81743
81498
|
const nameOccupier = storage2.find((e2) => e2 === alias);
|
81744
81499
|
if (!nameOccupier)
|
81745
81500
|
continue;
|
81746
|
-
throw new
|
81747
|
-
`Can't define command '${
|
81501
|
+
throw new Error(
|
81502
|
+
`Can't define command '${getCommandNameRecursive(cmd)}': alias '${alias}' is already in use by command '${parent ? `${getCommandNameRecursive(parent)} ` : ""}${storage2[0]}'!`
|
81748
81503
|
);
|
81749
81504
|
}
|
81750
81505
|
}
|
@@ -81756,135 +81511,53 @@ var validateCommands = (commands, parent) => {
|
|
81756
81511
|
return commands;
|
81757
81512
|
};
|
81758
81513
|
var removeByIndex = (arr, idx) => [...arr.slice(0, idx), ...arr.slice(idx + 1, arr.length)];
|
81759
|
-
var
|
81514
|
+
var help = async (command2, commands, helpHandler) => typeof command2 === "object" ? command2.help !== void 0 ? await executeOrLog(command2.help) : await helpHandler(command2) : await helpHandler(commands);
|
81515
|
+
var rawCli = async (commands, config) => {
|
81760
81516
|
var _a, _b;
|
81761
|
-
const
|
81517
|
+
const processedCmds = validateCommands(commands);
|
81762
81518
|
const argSource = (config == null ? void 0 : config.argSource) ?? process.argv;
|
81763
81519
|
const version3 = config == null ? void 0 : config.version;
|
81764
|
-
const
|
81520
|
+
const helpHandler = (config == null ? void 0 : config.help) ?? defaultTheme;
|
81765
81521
|
const omitKeysOfUndefinedOptions = (config == null ? void 0 : config.omitKeysOfUndefinedOptions) ?? false;
|
81766
|
-
|
81767
|
-
|
81522
|
+
let args = argSource.slice(2, argSource.length);
|
81523
|
+
if (!args.length)
|
81524
|
+
return await helpHandler(processedCmds);
|
81525
|
+
const helpIndex = args.findIndex((arg) => arg === "--help" || arg === "-h");
|
81526
|
+
if (helpIndex !== -1 && (helpIndex > 0 ? ((_a = args[helpIndex - 1]) == null ? void 0 : _a.startsWith("-")) && !args[helpIndex - 1].includes("=") ? false : true : true)) {
|
81527
|
+
const command3 = getCommand(processedCmds, args).command;
|
81528
|
+
return help(command3, processedCmds, helpHandler);
|
81529
|
+
}
|
81530
|
+
const versionIndex = args.findIndex((arg) => arg === "--version" || arg === "-v");
|
81531
|
+
if (versionIndex !== -1 && (versionIndex > 0 ? ((_b = args[versionIndex - 1]) == null ? void 0 : _b.startsWith("-")) ? false : true : true)) {
|
81532
|
+
return await executeOrLog(version3);
|
81533
|
+
}
|
81534
|
+
const { command: command2, args: newArgs } = getCommand(processedCmds, args);
|
81535
|
+
if (!command2)
|
81536
|
+
return helpHandler(processedCmds);
|
81537
|
+
if (command2 === "help") {
|
81538
|
+
const { command: helpCommand } = getCommand(processedCmds, newArgs);
|
81539
|
+
return help(helpCommand, processedCmds, helpHandler);
|
81540
|
+
}
|
81541
|
+
const optionResult = parseOptions(command2, newArgs, omitKeysOfUndefinedOptions);
|
81542
|
+
if (optionResult === "help")
|
81543
|
+
return await help(command2, commands, helpHandler);
|
81544
|
+
if (optionResult === "version")
|
81545
|
+
return await executeOrLog(version3);
|
81546
|
+
if (optionResult) {
|
81547
|
+
if (config == null ? void 0 : config.hook)
|
81548
|
+
await config.hook("pre", command2);
|
81549
|
+
await command2.handler(command2.transform ? await command2.transform(optionResult) : optionResult);
|
81550
|
+
if (config == null ? void 0 : config.hook)
|
81551
|
+
await config.hook("post", command2);
|
81552
|
+
}
|
81553
|
+
return void 0;
|
81554
|
+
};
|
81555
|
+
var run = async (commands, config) => {
|
81768
81556
|
try {
|
81769
|
-
|
81770
|
-
let args = argSource.slice(2, argSource.length);
|
81771
|
-
if (!args.length) {
|
81772
|
-
return help !== void 0 ? await executeOrLog(help) : await eventHandler({
|
81773
|
-
type: "global_help",
|
81774
|
-
description: cliDescription,
|
81775
|
-
name: cliName,
|
81776
|
-
commands: processedCmds
|
81777
|
-
});
|
81778
|
-
}
|
81779
|
-
const helpIndex = args.findIndex((arg) => arg === "--help" || arg === "-h");
|
81780
|
-
if (helpIndex !== -1 && (helpIndex > 0 ? ((_a = args[helpIndex - 1]) == null ? void 0 : _a.startsWith("-")) && !args[helpIndex - 1].includes("=") ? false : true : true)) {
|
81781
|
-
const command3 = getCommand(processedCmds, args, cliName, cliDescription).command;
|
81782
|
-
if (typeof command3 === "object") {
|
81783
|
-
return command3.help !== void 0 ? await executeOrLog(command3.help) : await eventHandler({
|
81784
|
-
type: "command_help",
|
81785
|
-
description: cliDescription,
|
81786
|
-
name: cliName,
|
81787
|
-
command: command3
|
81788
|
-
});
|
81789
|
-
} else {
|
81790
|
-
return help !== void 0 ? await executeOrLog(help) : await eventHandler({
|
81791
|
-
type: "global_help",
|
81792
|
-
description: cliDescription,
|
81793
|
-
name: cliName,
|
81794
|
-
commands: processedCmds
|
81795
|
-
});
|
81796
|
-
}
|
81797
|
-
}
|
81798
|
-
const versionIndex = args.findIndex((arg) => arg === "--version" || arg === "-v");
|
81799
|
-
if (versionIndex !== -1 && (versionIndex > 0 ? ((_b = args[versionIndex - 1]) == null ? void 0 : _b.startsWith("-")) ? false : true : true)) {
|
81800
|
-
return version3 !== void 0 ? await executeOrLog(version3) : await eventHandler({
|
81801
|
-
type: "version",
|
81802
|
-
name: cliName,
|
81803
|
-
description: cliDescription
|
81804
|
-
});
|
81805
|
-
}
|
81806
|
-
const { command: command2, args: newArgs } = getCommand(processedCmds, args, cliName, cliDescription);
|
81807
|
-
if (!command2) {
|
81808
|
-
return help !== void 0 ? await executeOrLog(help) : await eventHandler({
|
81809
|
-
type: "global_help",
|
81810
|
-
description: cliDescription,
|
81811
|
-
name: cliName,
|
81812
|
-
commands: processedCmds
|
81813
|
-
});
|
81814
|
-
}
|
81815
|
-
if (command2 === "help") {
|
81816
|
-
let helpCommand;
|
81817
|
-
let newestArgs = newArgs;
|
81818
|
-
do {
|
81819
|
-
const res = getCommand(processedCmds, newestArgs, cliName, cliDescription);
|
81820
|
-
helpCommand = res.command;
|
81821
|
-
newestArgs = res.args;
|
81822
|
-
} while (helpCommand === "help");
|
81823
|
-
return helpCommand ? helpCommand.help !== void 0 ? await executeOrLog(helpCommand.help) : await eventHandler({
|
81824
|
-
type: "command_help",
|
81825
|
-
description: cliDescription,
|
81826
|
-
name: cliName,
|
81827
|
-
command: helpCommand
|
81828
|
-
}) : help !== void 0 ? await executeOrLog(help) : await eventHandler({
|
81829
|
-
type: "global_help",
|
81830
|
-
description: cliDescription,
|
81831
|
-
name: cliName,
|
81832
|
-
commands: processedCmds
|
81833
|
-
});
|
81834
|
-
}
|
81835
|
-
const optionResult = parseOptions(command2, newArgs, cliName, cliDescription, omitKeysOfUndefinedOptions);
|
81836
|
-
if (optionResult === "help") {
|
81837
|
-
return command2.help !== void 0 ? await executeOrLog(command2.help) : await eventHandler({
|
81838
|
-
type: "command_help",
|
81839
|
-
description: cliDescription,
|
81840
|
-
name: cliName,
|
81841
|
-
command: command2
|
81842
|
-
});
|
81843
|
-
}
|
81844
|
-
if (optionResult === "version") {
|
81845
|
-
return version3 !== void 0 ? await executeOrLog(version3) : await eventHandler({
|
81846
|
-
type: "version",
|
81847
|
-
name: cliName,
|
81848
|
-
description: cliDescription
|
81849
|
-
});
|
81850
|
-
}
|
81851
|
-
if (command2.handler) {
|
81852
|
-
if (config == null ? void 0 : config.hook)
|
81853
|
-
await config.hook("before", command2);
|
81854
|
-
await command2.handler(command2.transform ? await command2.transform(optionResult) : optionResult);
|
81855
|
-
if (config == null ? void 0 : config.hook)
|
81856
|
-
await config.hook("after", command2);
|
81857
|
-
return;
|
81858
|
-
} else {
|
81859
|
-
return command2.help !== void 0 ? await executeOrLog(command2.help) : await eventHandler({
|
81860
|
-
type: "command_help",
|
81861
|
-
description: cliDescription,
|
81862
|
-
name: cliName,
|
81863
|
-
command: command2
|
81864
|
-
});
|
81865
|
-
}
|
81557
|
+
await rawCli(commands, config);
|
81866
81558
|
} catch (e2) {
|
81867
|
-
|
81868
|
-
|
81869
|
-
await eventHandler(e2.event);
|
81870
|
-
else {
|
81871
|
-
if (!(config == null ? void 0 : config.noExit))
|
81872
|
-
console.error(e2.message);
|
81873
|
-
else
|
81874
|
-
return e2.message;
|
81875
|
-
}
|
81876
|
-
} else {
|
81877
|
-
await eventHandler({
|
81878
|
-
type: "error",
|
81879
|
-
violation: "unknown_error",
|
81880
|
-
name: cliName,
|
81881
|
-
description: cliDescription,
|
81882
|
-
error: e2
|
81883
|
-
});
|
81884
|
-
}
|
81885
|
-
if (!(config == null ? void 0 : config.noExit))
|
81886
|
-
process.exit(1);
|
81887
|
-
return;
|
81559
|
+
console.error(typeof e2 === "object" && e2 !== null && "message" in e2 ? e2.message : e2);
|
81560
|
+
process.exit(1);
|
81888
81561
|
}
|
81889
81562
|
};
|
81890
81563
|
var OptionBuilderBase = class _OptionBuilderBase {
|
@@ -81962,7 +81635,7 @@ var OptionBuilderBase = class _OptionBuilderBase {
|
|
81962
81635
|
max(value) {
|
81963
81636
|
const config = this.config();
|
81964
81637
|
const minVal = config.minVal;
|
81965
|
-
if (minVal !== void 0 && minVal
|
81638
|
+
if (minVal !== void 0 && minVal < value) {
|
81966
81639
|
throw new BroCliError("Unable to define option's max value to be lower than min value!");
|
81967
81640
|
}
|
81968
81641
|
return new _OptionBuilderBase({ ...config, maxVal: value });
|
@@ -83786,7 +83459,7 @@ init_utils2();
|
|
83786
83459
|
var version2 = async () => {
|
83787
83460
|
const { npmVersion } = await ormCoreVersions();
|
83788
83461
|
const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
|
83789
|
-
const envVersion = "0.24.0-
|
83462
|
+
const envVersion = "0.24.0-8d86512";
|
83790
83463
|
const kitVersion = envVersion ? `v${envVersion}` : "--";
|
83791
83464
|
const versions = `drizzle-kit: ${kitVersion}
|
83792
83465
|
${ormVersion}`;
|
@@ -83821,7 +83494,6 @@ var legacy = [
|
|
83821
83494
|
legacyCommand("check:sqlite", "check")
|
83822
83495
|
];
|
83823
83496
|
run([generate, migrate, pull, push, studio, up, check, drop, ...legacy], {
|
83824
|
-
name: "drizzle-kit",
|
83825
83497
|
version: version2
|
83826
83498
|
});
|
83827
83499
|
/*! Bundled license information:
|