ormbridge 0.7.0 → 0.8.0
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 +1 -0
- package/dist/cliRunner.js +7 -5
- package/dist/cliRunner.js.map +1 -1
- package/dist/config.d.ts +6 -3
- package/dist/config.js +3 -3
- package/dist/config.js.map +1 -1
- package/dist/emitters/sequelize.d.ts +35 -0
- package/dist/emitters/sequelize.js +1276 -0
- package/dist/emitters/sequelize.js.map +1 -0
- package/dist/formats.d.ts +6 -5
- package/dist/formats.js +38 -4
- package/dist/formats.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/io.js +29 -1
- package/dist/io.js.map +1 -1
- package/dist/parsers/sequelize.d.ts +15 -0
- package/dist/parsers/sequelize.js +906 -0
- package/dist/parsers/sequelize.js.map +1 -0
- package/dist/parsers/sequelizeAssociations.d.ts +45 -0
- package/dist/parsers/sequelizeAssociations.js +449 -0
- package/dist/parsers/sequelizeAssociations.js.map +1 -0
- package/dist/parsers/sequelizeCollect.d.ts +33 -0
- package/dist/parsers/sequelizeCollect.js +1298 -0
- package/dist/parsers/sequelizeCollect.js.map +1 -0
- package/dist/parsers/sequelizeInflection.d.ts +14 -0
- package/dist/parsers/sequelizeInflection.js +451 -0
- package/dist/parsers/sequelizeInflection.js.map +1 -0
- package/dist/parsers/sequelizeModel.d.ts +185 -0
- package/dist/parsers/sequelizeModel.js +2 -0
- package/dist/parsers/sequelizeModel.js.map +1 -0
- package/dist/parsers/sequelizeTypes.d.ts +24 -0
- package/dist/parsers/sequelizeTypes.js +248 -0
- package/dist/parsers/sequelizeTypes.js.map +1 -0
- package/dist/styles.d.ts +17 -0
- package/dist/styles.js +40 -0
- package/dist/styles.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type { SyntaxNode, TsValue } from './typescriptSyntax.js';
|
|
2
|
+
/** One parsed source file. */
|
|
3
|
+
export interface FileInfo {
|
|
4
|
+
path: string;
|
|
5
|
+
/** Short name used in warnings. */
|
|
6
|
+
label: string;
|
|
7
|
+
root: SyntaxNode;
|
|
8
|
+
/** Every `const name = <value>` in the file, so `sequelize.define('X', attributes)` can be followed. */
|
|
9
|
+
consts: Map<string, SyntaxNode>;
|
|
10
|
+
}
|
|
11
|
+
/** A node together with the file it was read from, for lookups that may leave the file. */
|
|
12
|
+
export interface Located {
|
|
13
|
+
file: FileInfo;
|
|
14
|
+
node: SyntaxNode;
|
|
15
|
+
}
|
|
16
|
+
export type TimestampKind = 'createdAt' | 'updatedAt' | 'deletedAt';
|
|
17
|
+
/** Where a column comes from: written in the model, or added by Sequelize itself. */
|
|
18
|
+
export type AttributeOrigin = 'declared' | 'id' | 'timestamp' | 'foreignKey';
|
|
19
|
+
/** One attribute of a model: everything `sequelize.define('X', { attribute: { ... } })` can say about a column. */
|
|
20
|
+
export interface RawAttribute {
|
|
21
|
+
/** The attribute (property) name; the column name is `field`, or derived from it. */
|
|
22
|
+
name: string;
|
|
23
|
+
origin: AttributeOrigin;
|
|
24
|
+
/** The data type expression as written (`DataTypes.STRING(100)`). */
|
|
25
|
+
type?: TsValue;
|
|
26
|
+
/** The TypeScript type of a decorated property, used when `@Column` names no data type. */
|
|
27
|
+
tsType?: string;
|
|
28
|
+
/** True when the TypeScript annotation allows null or the property is optional. */
|
|
29
|
+
tsNullable?: boolean;
|
|
30
|
+
allowNull?: boolean;
|
|
31
|
+
primaryKey?: boolean;
|
|
32
|
+
autoIncrement?: boolean;
|
|
33
|
+
/** `unique: true` (no name) or `unique: 'name'` / `unique: { name }`. */
|
|
34
|
+
unique?: {
|
|
35
|
+
name?: string;
|
|
36
|
+
};
|
|
37
|
+
defaultValue?: TsValue;
|
|
38
|
+
references?: {
|
|
39
|
+
model?: TsValue;
|
|
40
|
+
key?: string;
|
|
41
|
+
};
|
|
42
|
+
onDelete?: string;
|
|
43
|
+
onUpdate?: string;
|
|
44
|
+
field?: string;
|
|
45
|
+
comment?: string;
|
|
46
|
+
/** Values from the older `{ type: DataTypes.ENUM, values: [...] }` spelling. */
|
|
47
|
+
enumValues?: string[];
|
|
48
|
+
/** True when the attribute declares `get` or `set`. */
|
|
49
|
+
hasAccessor?: boolean;
|
|
50
|
+
timestamp?: TimestampKind;
|
|
51
|
+
/** The foreign key an association added or completed (or a `references` the attribute declares). */
|
|
52
|
+
link?: AttributeLink;
|
|
53
|
+
}
|
|
54
|
+
/** A foreign key on an attribute, resolved against the models of the project. */
|
|
55
|
+
export interface AttributeLink {
|
|
56
|
+
/** The referenced model; undefined when it is not part of the input. */
|
|
57
|
+
target: RawModel | undefined;
|
|
58
|
+
/** The referenced model's name as the source wrote it (also used for the stub model). */
|
|
59
|
+
targetName: string;
|
|
60
|
+
/** Attribute of the target the key points at (its primary key unless `targetKey` / `sourceKey` says otherwise). */
|
|
61
|
+
keyAttribute: string | undefined;
|
|
62
|
+
/** Column of the target when the reference named a column instead of an attribute. */
|
|
63
|
+
keyColumn?: string;
|
|
64
|
+
onDelete?: string;
|
|
65
|
+
onUpdate?: string;
|
|
66
|
+
/** False for `constraints: false`, which creates no foreign key in the database. */
|
|
67
|
+
constraint: boolean;
|
|
68
|
+
}
|
|
69
|
+
export interface RawIndexField {
|
|
70
|
+
/** Attribute or column name. */
|
|
71
|
+
name: string;
|
|
72
|
+
order?: 'asc' | 'desc';
|
|
73
|
+
length?: number;
|
|
74
|
+
operator?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface RawIndex {
|
|
77
|
+
fields: RawIndexField[];
|
|
78
|
+
unique: boolean;
|
|
79
|
+
name?: string;
|
|
80
|
+
using?: string;
|
|
81
|
+
/** `FULLTEXT` or `SPATIAL` (`UNIQUE` is folded into `unique`). */
|
|
82
|
+
type?: string;
|
|
83
|
+
/** True for a partial index (`where`); the IR cannot hold the predicate. */
|
|
84
|
+
isPartial: boolean;
|
|
85
|
+
/** True when a field is a `Sequelize.literal(...)` or another expression rather than a column. */
|
|
86
|
+
hasExpression: boolean;
|
|
87
|
+
}
|
|
88
|
+
export type AssociationKind = 'hasMany' | 'hasOne' | 'belongsTo' | 'belongsToMany';
|
|
89
|
+
/** A foreign key option: the attribute name, plus whatever the option object says about the column. */
|
|
90
|
+
export interface AssociationKey {
|
|
91
|
+
name?: string;
|
|
92
|
+
/** Allow-null, column name, unique and the other attribute settings of `{ name, allowNull, field }`. */
|
|
93
|
+
attribute: RawAttribute;
|
|
94
|
+
}
|
|
95
|
+
/** The options of one association call (or decorator). */
|
|
96
|
+
export interface AssociationOptions {
|
|
97
|
+
as?: string;
|
|
98
|
+
/** The foreign key as written: a name, or an attribute definition (`{ name, allowNull, field }`). */
|
|
99
|
+
foreignKey?: AssociationKey;
|
|
100
|
+
otherKey?: AssociationKey;
|
|
101
|
+
sourceKey?: string;
|
|
102
|
+
targetKey?: string;
|
|
103
|
+
onDelete?: string;
|
|
104
|
+
onUpdate?: string;
|
|
105
|
+
/** `constraints: false` */
|
|
106
|
+
constraints?: boolean;
|
|
107
|
+
/** `through` for `belongsToMany`: a join table name or a reference to a model. */
|
|
108
|
+
through?: {
|
|
109
|
+
table?: string;
|
|
110
|
+
model?: string;
|
|
111
|
+
unique?: boolean;
|
|
112
|
+
};
|
|
113
|
+
/** `scope`, `inverse` and other options this reader does not model. */
|
|
114
|
+
unsupported: string[];
|
|
115
|
+
}
|
|
116
|
+
/** An association call that was found in the source, before the model names are resolved. */
|
|
117
|
+
export interface RawAssociation {
|
|
118
|
+
kind: AssociationKind;
|
|
119
|
+
file: FileInfo;
|
|
120
|
+
/** The model the call was made on, as written (`User`, `this`, `models.User`). */
|
|
121
|
+
source: string;
|
|
122
|
+
/** The class a `this` receiver stands for, when the call is inside a class or `X.associate = ...`. */
|
|
123
|
+
enclosing: string | undefined;
|
|
124
|
+
/** The target model as written (`models.Post`, `Post`). */
|
|
125
|
+
target: string;
|
|
126
|
+
options: AssociationOptions;
|
|
127
|
+
/** For decorators: the property the decorator is on, which is the default alias. */
|
|
128
|
+
propertyName?: string;
|
|
129
|
+
/** For decorators: the model the property belongs to (resolved without a receiver). */
|
|
130
|
+
owner?: RawModel;
|
|
131
|
+
/** Text identifying the call in warnings, for example `Post.belongsTo(User)`. */
|
|
132
|
+
label: string;
|
|
133
|
+
}
|
|
134
|
+
export interface ModelOptions {
|
|
135
|
+
tableName?: string;
|
|
136
|
+
freezeTableName: boolean;
|
|
137
|
+
timestamps: boolean;
|
|
138
|
+
paranoid: boolean;
|
|
139
|
+
underscored: boolean;
|
|
140
|
+
schema?: string;
|
|
141
|
+
/** Names of the timestamp columns; false disables the column. */
|
|
142
|
+
createdAt: string | false;
|
|
143
|
+
updatedAt: string | false;
|
|
144
|
+
deletedAt: string | false;
|
|
145
|
+
/** `version: true` / `version: 'name'` adds an integer column. */
|
|
146
|
+
version?: string;
|
|
147
|
+
/** `name: { singular, plural }`, which replaces the inflected model name. */
|
|
148
|
+
nameSingular?: string;
|
|
149
|
+
namePlural?: string;
|
|
150
|
+
}
|
|
151
|
+
/** Defaults a `new Sequelize(..., { define: { ... } })` call gives every model. */
|
|
152
|
+
export type ModelOptionDefaults = Partial<Pick<ModelOptions, 'freezeTableName' | 'timestamps' | 'paranoid' | 'underscored' | 'schema' | 'createdAt' | 'updatedAt' | 'deletedAt'>>;
|
|
153
|
+
export type ModelStyle = 'define' | 'init' | 'decorators';
|
|
154
|
+
export interface RawModel {
|
|
155
|
+
file: FileInfo;
|
|
156
|
+
style: ModelStyle;
|
|
157
|
+
/** The Sequelize model name (`modelName`, the first argument of `define`, or the class name). */
|
|
158
|
+
modelName: string;
|
|
159
|
+
/** Variable and class names the source uses for the model. */
|
|
160
|
+
aliases: string[];
|
|
161
|
+
attributes: RawAttribute[];
|
|
162
|
+
/** The model options as written, read once the project defaults are known. */
|
|
163
|
+
optionEntries: Map<string, SyntaxNode>;
|
|
164
|
+
/** Options that decorators contribute (`@CreatedAt` renames the timestamp column, and so on). */
|
|
165
|
+
decoratorOptions: Partial<ModelOptions>;
|
|
166
|
+
indexes: RawIndex[];
|
|
167
|
+
/** sequelize-typescript `@ForeignKey(() => Model)`: attribute name -> model name. */
|
|
168
|
+
foreignKeyHints: Map<string, string>;
|
|
169
|
+
/** Names of the attributes that declare getters or setters. */
|
|
170
|
+
accessors: string[];
|
|
171
|
+
/** Unsupported features seen on the model (hooks, scopes, ...), reported once. */
|
|
172
|
+
unsupported: string[];
|
|
173
|
+
/** Text identifying the model in warnings, for example `user.js: model "User"`. */
|
|
174
|
+
location: string;
|
|
175
|
+
}
|
|
176
|
+
export interface Project {
|
|
177
|
+
files: FileInfo[];
|
|
178
|
+
models: RawModel[];
|
|
179
|
+
associations: RawAssociation[];
|
|
180
|
+
/** Constants of every file, for lookups across files (an imported attribute set). */
|
|
181
|
+
sharedConsts: Map<string, Located[]>;
|
|
182
|
+
/** The first `new Sequelize(..., { define })` found. */
|
|
183
|
+
defaults: ModelOptionDefaults;
|
|
184
|
+
warnings: string[];
|
|
185
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sequelizeModel.js","sourceRoot":"","sources":["../../src/parsers/sequelizeModel.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { IrRangeSubtype, IrScalarType } from '../ir.js';
|
|
2
|
+
import type { TsValue } from './typescriptSyntax.js';
|
|
3
|
+
/** A Sequelize `DataTypes` expression reduced to what the IR can hold. */
|
|
4
|
+
export interface ResolvedDataType {
|
|
5
|
+
type: IrScalarType;
|
|
6
|
+
maxLength?: number;
|
|
7
|
+
maxDigits?: number;
|
|
8
|
+
decimalPlaces?: number;
|
|
9
|
+
/** Values of an `ENUM` column. */
|
|
10
|
+
enumValues?: string[];
|
|
11
|
+
/** Dimensions of an `ARRAY` column; `type` then describes the innermost element. */
|
|
12
|
+
arrayDepth?: number;
|
|
13
|
+
rangeOf?: IrRangeSubtype;
|
|
14
|
+
unsupportedType?: string;
|
|
15
|
+
/** True for `DataTypes.VIRTUAL`, which has no database column. */
|
|
16
|
+
isVirtual?: boolean;
|
|
17
|
+
/** An approximation made while reading the type, to be reported with the field's location. */
|
|
18
|
+
note?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Reads a `DataTypes` expression (`DataTypes.STRING(100)`, `DataType.INTEGER`, `STRING`, ...).
|
|
22
|
+
* Returns undefined when the expression is not a Sequelize data type at all.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveDataType(value: TsValue): ResolvedDataType | undefined;
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/** Sequelize's default length for `STRING` and `CHAR` (VARCHAR(255)). */
|
|
2
|
+
const DEFAULT_STRING_LENGTH = 255;
|
|
3
|
+
const SIMPLE_TYPES = {
|
|
4
|
+
TEXT: 'text',
|
|
5
|
+
CITEXT: 'text',
|
|
6
|
+
TINYINT: 'int',
|
|
7
|
+
SMALLINT: 'int',
|
|
8
|
+
MEDIUMINT: 'int',
|
|
9
|
+
INTEGER: 'int',
|
|
10
|
+
NUMBER: 'int',
|
|
11
|
+
BIGINT: 'bigInt',
|
|
12
|
+
FLOAT: 'float',
|
|
13
|
+
REAL: 'float',
|
|
14
|
+
DOUBLE: 'float',
|
|
15
|
+
BOOLEAN: 'boolean',
|
|
16
|
+
DATE: 'dateTime',
|
|
17
|
+
DATEONLY: 'date',
|
|
18
|
+
TIME: 'time',
|
|
19
|
+
NOW: 'dateTime',
|
|
20
|
+
UUID: 'uuid',
|
|
21
|
+
UUIDV1: 'uuid',
|
|
22
|
+
UUIDV4: 'uuid',
|
|
23
|
+
JSON: 'json',
|
|
24
|
+
JSONB: 'json',
|
|
25
|
+
BLOB: 'bytes',
|
|
26
|
+
HSTORE: 'hstore',
|
|
27
|
+
INET: 'ipAddress',
|
|
28
|
+
};
|
|
29
|
+
/** Types the IR has no scalar for; the value is the SQL type they create. */
|
|
30
|
+
const UNSUPPORTED_TYPES = {
|
|
31
|
+
GEOMETRY: 'geometry',
|
|
32
|
+
GEOGRAPHY: 'geography',
|
|
33
|
+
CIDR: 'cidr',
|
|
34
|
+
MACADDR: 'macaddr',
|
|
35
|
+
TSVECTOR: 'tsvector',
|
|
36
|
+
};
|
|
37
|
+
const STRUCTURED_TYPES = new Set([
|
|
38
|
+
'STRING',
|
|
39
|
+
'CHAR',
|
|
40
|
+
'DECIMAL',
|
|
41
|
+
'NUMERIC',
|
|
42
|
+
'ENUM',
|
|
43
|
+
'ARRAY',
|
|
44
|
+
'RANGE',
|
|
45
|
+
'VIRTUAL',
|
|
46
|
+
]);
|
|
47
|
+
const RANGE_SUBTYPES = {
|
|
48
|
+
INTEGER: 'int',
|
|
49
|
+
BIGINT: 'bigInt',
|
|
50
|
+
DECIMAL: 'decimal',
|
|
51
|
+
NUMERIC: 'decimal',
|
|
52
|
+
DATE: 'dateTime',
|
|
53
|
+
DATEONLY: 'date',
|
|
54
|
+
};
|
|
55
|
+
function isTypeName(name) {
|
|
56
|
+
return (SIMPLE_TYPES[name] !== undefined ||
|
|
57
|
+
UNSUPPORTED_TYPES[name] !== undefined ||
|
|
58
|
+
STRUCTURED_TYPES.has(name));
|
|
59
|
+
}
|
|
60
|
+
/** Reads the arguments of `DECIMAL(10,2).UNSIGNED`, which the evaluator keeps as a single name. */
|
|
61
|
+
function argumentsFromText(text) {
|
|
62
|
+
const args = [];
|
|
63
|
+
for (const piece of text.split(',')) {
|
|
64
|
+
const trimmed = piece.trim();
|
|
65
|
+
if (trimmed === '') {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const quoted = /^(['"`])(.*)\1$/.exec(trimmed);
|
|
69
|
+
if (quoted !== null) {
|
|
70
|
+
args.push({ kind: 'string', value: quoted[2] ?? '' });
|
|
71
|
+
}
|
|
72
|
+
else if (/^-?\d+(\.\d+)?$/.test(trimmed)) {
|
|
73
|
+
args.push({ kind: 'number', value: Number(trimmed) });
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
args.push({ kind: 'name', value: trimmed });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return args;
|
|
80
|
+
}
|
|
81
|
+
/** Splits `DataTypes.INTEGER.UNSIGNED` into the type and its modifiers, skipping the namespace. */
|
|
82
|
+
function splitDottedName(dotted) {
|
|
83
|
+
const parts = dotted.split('.');
|
|
84
|
+
const index = parts.findIndex(isTypeName);
|
|
85
|
+
const base = parts[index];
|
|
86
|
+
if (index < 0 || base === undefined) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
return { base, modifiers: parts.slice(index + 1) };
|
|
90
|
+
}
|
|
91
|
+
function toTypeExpression(value) {
|
|
92
|
+
if (value.kind === 'call') {
|
|
93
|
+
const split = splitDottedName(value.callee);
|
|
94
|
+
return split === undefined ? undefined : { ...split, args: value.args };
|
|
95
|
+
}
|
|
96
|
+
if (value.kind !== 'name') {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
const open = value.value.indexOf('(');
|
|
100
|
+
if (open < 0) {
|
|
101
|
+
const split = splitDottedName(value.value);
|
|
102
|
+
return split === undefined ? undefined : { ...split, args: [] };
|
|
103
|
+
}
|
|
104
|
+
// `DataTypes.DECIMAL(10, 2).UNSIGNED`: a call followed by a member access.
|
|
105
|
+
const close = value.value.lastIndexOf(')');
|
|
106
|
+
const head = splitDottedName(value.value.slice(0, open));
|
|
107
|
+
if (head === undefined || close < open) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
const trailing = value.value
|
|
111
|
+
.slice(close + 1)
|
|
112
|
+
.split('.')
|
|
113
|
+
.filter((part) => part !== '');
|
|
114
|
+
return {
|
|
115
|
+
base: head.base,
|
|
116
|
+
args: argumentsFromText(value.value.slice(open + 1, close)),
|
|
117
|
+
modifiers: [...head.modifiers, ...trailing],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function numberAt(args, index) {
|
|
121
|
+
const value = args[index];
|
|
122
|
+
return value !== undefined && value.kind === 'number'
|
|
123
|
+
? value.value
|
|
124
|
+
: undefined;
|
|
125
|
+
}
|
|
126
|
+
function optionsOf(args) {
|
|
127
|
+
const first = args[0];
|
|
128
|
+
return first !== undefined && first.kind === 'object'
|
|
129
|
+
? first.properties
|
|
130
|
+
: undefined;
|
|
131
|
+
}
|
|
132
|
+
function numberProperty(properties, key) {
|
|
133
|
+
const value = properties?.[key];
|
|
134
|
+
return value !== undefined && value.kind === 'number'
|
|
135
|
+
? value.value
|
|
136
|
+
: undefined;
|
|
137
|
+
}
|
|
138
|
+
function enumValuesOf(args) {
|
|
139
|
+
const first = args[0];
|
|
140
|
+
const list = args.length === 1 && first !== undefined && first.kind === 'array'
|
|
141
|
+
? first.items
|
|
142
|
+
: args.length === 1 && first !== undefined && first.kind === 'object'
|
|
143
|
+
? valuesProperty(first.properties)
|
|
144
|
+
: args;
|
|
145
|
+
const values = [];
|
|
146
|
+
for (const item of list) {
|
|
147
|
+
if (item.kind !== 'string') {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
values.push(item.value);
|
|
151
|
+
}
|
|
152
|
+
return values;
|
|
153
|
+
}
|
|
154
|
+
function valuesProperty(properties) {
|
|
155
|
+
const values = properties['values'];
|
|
156
|
+
return values !== undefined && values.kind === 'array' ? values.items : [];
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Reads a `DataTypes` expression (`DataTypes.STRING(100)`, `DataType.INTEGER`, `STRING`, ...).
|
|
160
|
+
* Returns undefined when the expression is not a Sequelize data type at all.
|
|
161
|
+
*/
|
|
162
|
+
export function resolveDataType(value) {
|
|
163
|
+
const expression = toTypeExpression(value);
|
|
164
|
+
if (expression === undefined) {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
const { base, args, modifiers } = expression;
|
|
168
|
+
const options = optionsOf(args);
|
|
169
|
+
switch (base) {
|
|
170
|
+
case 'STRING':
|
|
171
|
+
case 'CHAR': {
|
|
172
|
+
const length = numberAt(args, 0) ??
|
|
173
|
+
numberProperty(options, 'length') ??
|
|
174
|
+
DEFAULT_STRING_LENGTH;
|
|
175
|
+
const binaryFlag = options?.['binary'];
|
|
176
|
+
const isBinary = modifiers.includes('BINARY') ||
|
|
177
|
+
(binaryFlag !== undefined &&
|
|
178
|
+
binaryFlag.kind === 'bool' &&
|
|
179
|
+
binaryFlag.value) ||
|
|
180
|
+
(args[1] !== undefined && args[1].kind === 'bool' && args[1].value);
|
|
181
|
+
return isBinary
|
|
182
|
+
? { type: 'bytes', maxLength: length }
|
|
183
|
+
: { type: 'string', maxLength: length };
|
|
184
|
+
}
|
|
185
|
+
case 'DECIMAL':
|
|
186
|
+
case 'NUMERIC': {
|
|
187
|
+
const precision = numberAt(args, 0) ?? numberProperty(options, 'precision');
|
|
188
|
+
const scale = numberAt(args, 1) ?? numberProperty(options, 'scale');
|
|
189
|
+
return {
|
|
190
|
+
type: 'decimal',
|
|
191
|
+
...(precision === undefined ? {} : { maxDigits: precision }),
|
|
192
|
+
...(scale === undefined ? {} : { decimalPlaces: scale }),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
case 'ENUM': {
|
|
196
|
+
const values = enumValuesOf(args);
|
|
197
|
+
if (values === undefined) {
|
|
198
|
+
return {
|
|
199
|
+
type: 'string',
|
|
200
|
+
maxLength: DEFAULT_STRING_LENGTH,
|
|
201
|
+
note: 'the ENUM values are not all string literals, so the column was read as a plain string',
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
return { type: 'string', enumValues: values };
|
|
205
|
+
}
|
|
206
|
+
case 'ARRAY': {
|
|
207
|
+
const inner = args[0];
|
|
208
|
+
const element = inner === undefined ? undefined : resolveDataType(inner);
|
|
209
|
+
if (element === undefined) {
|
|
210
|
+
return {
|
|
211
|
+
type: 'unsupported',
|
|
212
|
+
unsupportedType: 'array',
|
|
213
|
+
note: 'the ARRAY element type could not be determined',
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return { ...element, arrayDepth: (element.arrayDepth ?? 0) + 1 };
|
|
217
|
+
}
|
|
218
|
+
case 'RANGE': {
|
|
219
|
+
const inner = args[0];
|
|
220
|
+
const subtype = inner === undefined ? undefined : resolveDataType(inner);
|
|
221
|
+
const innerBase = inner === undefined ? undefined : toTypeExpression(inner)?.base;
|
|
222
|
+
const rangeOf = innerBase === undefined ? undefined : RANGE_SUBTYPES[innerBase];
|
|
223
|
+
if (subtype === undefined || rangeOf === undefined) {
|
|
224
|
+
return {
|
|
225
|
+
type: 'unsupported',
|
|
226
|
+
unsupportedType: 'range',
|
|
227
|
+
note: 'the RANGE element type is not one of INTEGER, BIGINT, DECIMAL, DATE or DATEONLY',
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
return { type: 'range', rangeOf };
|
|
231
|
+
}
|
|
232
|
+
case 'VIRTUAL':
|
|
233
|
+
return { type: 'unsupported', isVirtual: true };
|
|
234
|
+
default:
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
const simple = SIMPLE_TYPES[base];
|
|
238
|
+
if (simple !== undefined) {
|
|
239
|
+
return { type: simple };
|
|
240
|
+
}
|
|
241
|
+
const unsupported = UNSUPPORTED_TYPES[base];
|
|
242
|
+
return {
|
|
243
|
+
type: 'unsupported',
|
|
244
|
+
unsupportedType: unsupported ?? base.toLowerCase(),
|
|
245
|
+
note: `DataTypes.${base} has no equivalent in the shared model`,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=sequelizeTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sequelizeTypes.js","sourceRoot":"","sources":["../../src/parsers/sequelizeTypes.ts"],"names":[],"mappings":"AAqBA,yEAAyE;AACzE,MAAM,qBAAqB,GAAW,GAAG,CAAC;AAE1C,MAAM,YAAY,GAA2C;IAC3D,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,MAAM;IACd,OAAO,EAAE,KAAK;IACd,QAAQ,EAAE,KAAK;IACf,SAAS,EAAE,KAAK;IAChB,OAA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K,SAAS,EAAE,CAAC;gBACnD,OAAO;oBACL,IAAI,EAAE,aAAa;oBACnB,eAAe,EAAE,OAAO;oBACxB,IAAI,EAAE,iFAAiF;iBACxF,CAAC;YACJ,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;QACpC,CAAC;QACD,KAAK,SAAS;YACZ,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;QAClD;YACE,MAAM;IACV,CAAC;IAED,MAAM,MAAM,GAA6B,YAAY,CAAC,IAAI,CAAC,CAAC;IAC5D,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC1B,CAAC;IACD,MAAM,WAAW,GAAuB,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAChE,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,eAAe,EAAE,WAAW,IAAI,IAAI,CAAC,WAAW,EAAE;QAClD,IAAI,EAAE,aAAa,IAAI,wCAAwC;KAChE,CAAC;AACJ,CAAC"}
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type SequelizeStyle } from './emitters/sequelize.js';
|
|
2
|
+
import { type SqlAlchemyStyle } from './emitters/sqlalchemy.js';
|
|
3
|
+
import { type Result } from './result.js';
|
|
4
|
+
/** Every value `--style` accepts; which ones apply depends on the target format. */
|
|
5
|
+
export type OutputStyle = SqlAlchemyStyle | SequelizeStyle;
|
|
6
|
+
/** Every style of every format, in the order the help lists them. */
|
|
7
|
+
export declare const OUTPUT_STYLES: readonly OutputStyle[];
|
|
8
|
+
/** True when a value is a style of some format. */
|
|
9
|
+
export declare function isOutputStyle(value: string): value is OutputStyle;
|
|
10
|
+
/** The styles a target format accepts, or undefined when the format has none. */
|
|
11
|
+
export declare function stylesOf(format: string): readonly OutputStyle[] | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Checks a `--style` value against the target format. A format with styles accepts only its own
|
|
14
|
+
* (`sqlalchemy`, `sqlmodel` for SQLAlchemy; `init`, `define` for Sequelize). Any other format
|
|
15
|
+
* ignores the option, so it accepts every known style but still rejects values nobody knows.
|
|
16
|
+
*/
|
|
17
|
+
export declare function checkStyle(format: string, value: string, label?: string): Result<OutputStyle>;
|
package/dist/styles.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { SEQUELIZE_STYLES } from './emitters/sequelize.js';
|
|
2
|
+
import { SQLALCHEMY_STYLES, } from './emitters/sqlalchemy.js';
|
|
3
|
+
import { err, ok } from './result.js';
|
|
4
|
+
/** The output styles of the formats that have any, by format name. */
|
|
5
|
+
const STYLES_BY_FORMAT = {
|
|
6
|
+
sqlalchemy: SQLALCHEMY_STYLES,
|
|
7
|
+
sequelize: SEQUELIZE_STYLES,
|
|
8
|
+
};
|
|
9
|
+
/** Every style of every format, in the order the help lists them. */
|
|
10
|
+
export const OUTPUT_STYLES = [
|
|
11
|
+
...SQLALCHEMY_STYLES,
|
|
12
|
+
...SEQUELIZE_STYLES,
|
|
13
|
+
];
|
|
14
|
+
/** True when a value is a style of some format. */
|
|
15
|
+
export function isOutputStyle(value) {
|
|
16
|
+
return OUTPUT_STYLES.includes(value);
|
|
17
|
+
}
|
|
18
|
+
/** The styles a target format accepts, or undefined when the format has none. */
|
|
19
|
+
export function stylesOf(format) {
|
|
20
|
+
return STYLES_BY_FORMAT[format];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Checks a `--style` value against the target format. A format with styles accepts only its own
|
|
24
|
+
* (`sqlalchemy`, `sqlmodel` for SQLAlchemy; `init`, `define` for Sequelize). Any other format
|
|
25
|
+
* ignores the option, so it accepts every known style but still rejects values nobody knows.
|
|
26
|
+
*/
|
|
27
|
+
export function checkStyle(format, value, label = '--style value') {
|
|
28
|
+
const own = stylesOf(format);
|
|
29
|
+
if (own !== undefined) {
|
|
30
|
+
return own.includes(value)
|
|
31
|
+
? ok(value)
|
|
32
|
+
: err('INVALID_OPTION', `Invalid ${label} "${value}" for the ${format} format. Expected one of: ${own.join(', ')}.`);
|
|
33
|
+
}
|
|
34
|
+
return isOutputStyle(value)
|
|
35
|
+
? ok(value)
|
|
36
|
+
: err('INVALID_OPTION', `Invalid ${label} "${value}". Expected one of: ${OUTPUT_STYLES.join(', ')} (${Object.entries(STYLES_BY_FORMAT)
|
|
37
|
+
.map(([name, styles]) => `${styles.join(', ')} for ${name}`)
|
|
38
|
+
.join('; ')}).`);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAuB,MAAM,yBAAyB,CAAC;AAChF,OAAO,EACL,iBAAiB,GAElB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,GAAG,EAAE,EAAE,EAAe,MAAM,aAAa,CAAC;AAKnD,sEAAsE;AACtE,MAAM,gBAAgB,GAAqD;IACzE,UAAU,EAAE,iBAAiB;IAC7B,SAAS,EAAE,gBAAgB;CAC5B,CAAC;AAEF,qEAAqE;AACrE,MAAM,CAAC,MAAM,aAAa,GAA2B;IACnD,GAAG,iBAAiB;IACpB,GAAG,gBAAgB;CACpB,CAAC;AAEF,mDAAmD;AACnD,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAQ,aAAmC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC9D,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,QAAQ,CAAC,MAAc;IACrC,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACxB,MAAc,EACd,KAAa,EACb,QAAgB,eAAe;IAE/B,MAAM,GAAG,GAAuC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjE,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,GAAG,CAAC,QAAQ,CAAC,KAAoB,CAAC;YACvC,CAAC,CAAC,EAAE,CAAC,KAAoB,CAAC;YAC1B,CAAC,CAAC,GAAG,CACD,gBAAgB,EAChB,WAAW,KAAK,KAAK,KAAK,aAAa,MAAM,6BAA6B,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC5F,CAAC;IACR,CAAC;IACD,OAAO,aAAa,CAAC,KAAK,CAAC;QACzB,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC;QACX,CAAC,CAAC,GAAG,CACD,gBAAgB,EAChB,WAAW,KAAK,KAAK,KAAK,uBAAuB,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,OAAO,CAC1F,gBAAgB,CACjB;aACE,GAAG,CACF,CAAC,CAAC,IAAI,EAAE,MAAM,CAAmC,EAAE,EAAE,CACnD,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CACrC;aACA,IAAI,CAAC,IAAI,CAAC,IAAI,CAClB,CAAC;AACR,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ormbridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Convert ORM models between frameworks and languages (Django, Prisma, TypeORM, Doctrine, Laravel). Define your data model once and share typed schemas across your stack.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Richard McQuiston",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"python",
|
|
54
54
|
"typeorm",
|
|
55
55
|
"drizzle",
|
|
56
|
+
"sequelize",
|
|
56
57
|
"graphene",
|
|
57
58
|
"doctrine",
|
|
58
59
|
"laravel",
|