@an5/orm 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -83
- package/dist/an5Metadata.d.ts +10 -0
- package/dist/an5Metadata.js +93 -0
- package/dist/an5Orm.d.ts +95 -3
- package/dist/an5Orm.js +808 -512
- package/dist/config.d.ts +2 -0
- package/dist/config.js +24 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +16 -0
- package/dist/generator/src/code-generator.d.ts +1 -0
- package/dist/generator/src/code-generator.js +44 -20
- package/dist/generator/src/dotnet-generator.d.ts +2 -0
- package/dist/generator/src/dotnet-generator.js +332 -6
- package/dist/generator/src/index.js +18 -2
- package/dist/generator/src/metadata-generator.d.ts +4 -1
- package/dist/generator/src/metadata-generator.js +22 -8
- package/dist/generator/src/python-generator.d.ts +10 -0
- package/dist/generator/src/python-generator.js +242 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +23 -8
- package/dist/logger.d.ts +53 -0
- package/dist/logger.js +117 -0
- package/dist/metadata.d.ts +24 -0
- package/dist/metadata.js +15 -0
- package/dist/migration-core.d.ts +87 -0
- package/dist/migration-core.js +692 -0
- package/dist/sql-utils.d.ts +31 -0
- package/dist/sql-utils.js +290 -0
- package/generator/src/code-generator.ts +45 -20
- package/generator/src/dotnet-generator.ts +344 -6
- package/generator/src/golang-generator.ts +1242 -0
- package/generator/src/index.ts +8 -1
- package/generator/src/metadata-generator.ts +29 -12
- package/generator/src/python-generator.ts +314 -4
- package/package.json +12 -10
- package/dist/cleanup.d.ts +0 -2
- package/dist/cleanup.js +0 -120
- package/dist/cli.js +0 -64
- package/dist/migrate.d.ts +0 -11
- package/dist/migrate.js +0 -301
- package/dist/pull.d.ts +0 -2
- package/dist/pull.js +0 -339
- package/dist/push.d.ts +0 -2
- package/dist/push.js +0 -281
- package/dist/seed.d.ts +0 -2
- package/dist/seed.js +0 -401
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core metadata types for AN5 ORM.
|
|
3
|
+
* These types are owned by the core package (@an5/orm) so that the ORM never
|
|
4
|
+
* has to import from generated client artifacts. Generated clients import
|
|
5
|
+
* these types from @an5/orm instead.
|
|
6
|
+
*/
|
|
7
|
+
export interface RelationDef {
|
|
8
|
+
modelName: string;
|
|
9
|
+
relationType: "many" | "one";
|
|
10
|
+
foreignKey: string;
|
|
11
|
+
localKey: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ModelFieldMeta {
|
|
14
|
+
ts: string;
|
|
15
|
+
sql: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface An5Metadata {
|
|
19
|
+
modelToTable: Record<string, string>;
|
|
20
|
+
relationMap: Record<string, Record<string, RelationDef>>;
|
|
21
|
+
modelFields: Record<string, Record<string, ModelFieldMeta>>;
|
|
22
|
+
}
|
|
23
|
+
export declare const DEFAULT_METADATA: An5Metadata;
|
|
24
|
+
//# sourceMappingURL=metadata.d.ts.map
|
package/dist/metadata.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Core metadata types for AN5 ORM.
|
|
4
|
+
* These types are owned by the core package (@an5/orm) so that the ORM never
|
|
5
|
+
* has to import from generated client artifacts. Generated clients import
|
|
6
|
+
* these types from @an5/orm instead.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DEFAULT_METADATA = void 0;
|
|
10
|
+
exports.DEFAULT_METADATA = {
|
|
11
|
+
modelToTable: {},
|
|
12
|
+
relationMap: {},
|
|
13
|
+
modelFields: {},
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=metadata.js.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export interface SchemaField {
|
|
2
|
+
name: string;
|
|
3
|
+
sqlType: string;
|
|
4
|
+
isOptional: boolean;
|
|
5
|
+
isId: boolean;
|
|
6
|
+
isUnique: boolean;
|
|
7
|
+
uniqueName?: string | undefined;
|
|
8
|
+
defaultValue?: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
export interface SchemaIndexDefinition {
|
|
11
|
+
fields: string[];
|
|
12
|
+
name?: string;
|
|
13
|
+
includeFields?: string[];
|
|
14
|
+
filter?: string;
|
|
15
|
+
options?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface SchemaModel {
|
|
18
|
+
name: string;
|
|
19
|
+
tableName: string;
|
|
20
|
+
fields: SchemaField[];
|
|
21
|
+
compoundUniques: Array<string[] | SchemaIndexDefinition>;
|
|
22
|
+
indexes: Array<string[] | SchemaIndexDefinition>;
|
|
23
|
+
}
|
|
24
|
+
export interface DbColumn {
|
|
25
|
+
columnName: string;
|
|
26
|
+
dataType: string;
|
|
27
|
+
maxLength?: number;
|
|
28
|
+
precision?: number;
|
|
29
|
+
scale?: number;
|
|
30
|
+
isNullable: boolean;
|
|
31
|
+
isPrimaryKey: boolean;
|
|
32
|
+
isIdentity: boolean;
|
|
33
|
+
defaultValue?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface MigrationOp {
|
|
36
|
+
type: 'CREATE_TABLE' | 'ADD_COLUMN' | 'DROP_COLUMN' | 'ALTER_COLUMN' | 'ADD_INDEX' | 'ADD_UNIQUE' | 'DROP_INDEX' | 'DROP_UNIQUE' | 'DROP_TABLE';
|
|
37
|
+
table: string;
|
|
38
|
+
column?: string;
|
|
39
|
+
details?: string;
|
|
40
|
+
sql?: string;
|
|
41
|
+
previousSqlType?: string;
|
|
42
|
+
previousNullable?: boolean;
|
|
43
|
+
riskWarnings?: string[];
|
|
44
|
+
preflightSql?: string[];
|
|
45
|
+
}
|
|
46
|
+
export interface TableArtifacts {
|
|
47
|
+
indexes?: string[];
|
|
48
|
+
uniqueConstraints?: string[];
|
|
49
|
+
}
|
|
50
|
+
export interface MigrationSections {
|
|
51
|
+
preflight: string;
|
|
52
|
+
up: string;
|
|
53
|
+
down: string;
|
|
54
|
+
hasDown: boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface AppliedMigrationRef {
|
|
57
|
+
id: string;
|
|
58
|
+
}
|
|
59
|
+
export interface MigrationCommandOptions {
|
|
60
|
+
dryRun: boolean;
|
|
61
|
+
rest: string[];
|
|
62
|
+
}
|
|
63
|
+
export declare function parseSqlType(raw: string): string;
|
|
64
|
+
export declare function formatDbColumnSqlType(column: DbColumn): string;
|
|
65
|
+
export declare function mapDefault(val: string): string;
|
|
66
|
+
export declare function safeIdentifierName(raw: string): string;
|
|
67
|
+
export declare function quoteTableName(raw: string): string;
|
|
68
|
+
export declare function tableIdentityName(raw: string): string;
|
|
69
|
+
export declare function buildAlterColumnWarnings(previousSqlType: string, nextSqlType: string, previousNullable: boolean, nextNullable: boolean): string[];
|
|
70
|
+
export declare function buildAlterColumnPreflightSql(tableName: string, columnName: string, previousSqlType: string, nextSqlType: string, previousNullable: boolean, nextNullable: boolean): string[];
|
|
71
|
+
export declare function buildAddColumnPreflightSql(tableName: string, field: SchemaField): string[];
|
|
72
|
+
export declare function buildUniqueConstraintPreflightSql(tableName: string, fields: string[]): string[];
|
|
73
|
+
export declare function parseSchemaText(text: string): SchemaModel[];
|
|
74
|
+
export declare function buildCreateTableSql(model: SchemaModel): string;
|
|
75
|
+
export declare function buildIndexDiff(model: SchemaModel, artifacts: TableArtifacts, ops: MigrationOp[]): void;
|
|
76
|
+
export declare function generateColumnDiff(model: SchemaModel, dbColumns: DbColumn[], ops: MigrationOp[]): void;
|
|
77
|
+
export declare function generateDiff(schemaModels: SchemaModel[], dbTables: string[], introspectTable: (tableName: string) => Promise<DbColumn[]>, introspectArtifacts?: (tableName: string) => Promise<TableArtifacts>): Promise<MigrationOp[]>;
|
|
78
|
+
export declare function buildMigrationFile(timestamp: string, ops: MigrationOp[]): string;
|
|
79
|
+
export declare function buildDownMigrationSql(ops: MigrationOp[]): string;
|
|
80
|
+
export declare function parseMigrationSections(sql: string): MigrationSections;
|
|
81
|
+
export declare function splitSqlBatches(sql: string): string[];
|
|
82
|
+
export declare function parseRollbackSelection(args: string[], applied: AppliedMigrationRef[]): {
|
|
83
|
+
count: number;
|
|
84
|
+
label: string;
|
|
85
|
+
};
|
|
86
|
+
export declare function parseMigrationCommandOptions(args: string[]): MigrationCommandOptions;
|
|
87
|
+
//# sourceMappingURL=migration-core.d.ts.map
|