Socket
Socket
Sign inDemoInstall

aca.ts

Package Overview
Dependencies
Maintainers
2
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aca.ts - npm Package Compare versions

Comparing version 0.0.91 to 0.0.92

35

dist/libs/api.js

@@ -67,3 +67,5 @@ "use strict";

}`;
return Cst.queries.map((v) => `${v}: ${v === '$' ? aggr() : query(v)}`).join(`,\n`);
return (tbl.kind === 'view' ? Cst.viewQueries : Cst.queries)
.map((v) => `${v}: ${v === '$' ? aggr() : query(v)}`)
.join(`,\n`);
};

@@ -125,5 +127,2 @@ const tblIter = (subTbls) => Object.keys(subTbls).reduce((_, v) => {

const tbl = tables[k];
if ('view' === tbl.kind) {
continue;
}
Object.assign(Att[tbl.jsName], {

@@ -246,5 +245,5 @@ dbName: tbl.dbName,

}
const TblType = (columns, uniques) => {
const TblType = (tbl, uniques) => {
const query = (Q) => {
const fields = Object.values(columns);
const fields = Object.values(tbl.columns);
switch (Q) {

@@ -276,3 +275,3 @@ case 'scalar':

? `$EnumFilter<${v.fieldType}, ${v.isNull}>`
: `$${v.fieldType === 'Date | string' ? 'Date' : titleCase(v.fieldType)}Filter<${v.isNull}>`} | ${v.fieldType} ${v.isNull ? ' | null' : ''}`}`)
: `$${v.fieldType === 'Date | string' ? 'Date' : titleCase(v.fieldType.endsWith(']') ? v.fieldType.slice(0, -2) : v.fieldType)}Filter<${v.isNull}>`} | ${v.fieldType} ${v.isNull ? ' | null' : ''}`}`)
].join('\n');

@@ -299,3 +298,3 @@ case 'select':

return `
count?: {[P in keyof scalar]?: number}
count?: {'*'?: number} & {[P in keyof scalar]?: number}
countDistinct?: {[P in keyof scalar]?: number}

@@ -494,3 +493,3 @@ ${fields.filter((v) => v.fieldType === 'number').length

where?: where
count?: {[P in keyof scalar]?: boolean}
count?: {'*'?: boolean} & {[P in keyof scalar]?: boolean}
countDistinct?: {[P in keyof scalar]?: boolean}

@@ -549,8 +548,12 @@ ${fields.filter((v) => v.fieldType === 'number').length

const uniqueWhere = `export type uniqueWhere =` +
uniques
.map((u) => `{
${u.map((v) => `${v}: ${columns[v].fieldType}`)}
(uniques?.length
? uniques
.map((u) => `{
${u.map((v) => `${v}: ${tbl.columns[v].fieldType}`)}
}`)
.join(' | ');
const queries = ['where', 'scalar', 'orderBy', 'select', 'aggregateReturning', 'insertInput', 'updateInput', ...Cst.queries]
.join(' | ')
: `{}`);
const queries = (tbl.kind === 'view'
? ['where', 'scalar', 'orderBy', 'select', 'aggregateReturning', ...Cst.viewQueries]
: ['where', 'scalar', 'orderBy', 'select', 'aggregateReturning', 'insertInput', 'updateInput', ...Cst.queries])
.map((v) => `export ${v === '$' ? 'namespace' : 'type'} ${v === 'delete' ? 'del' : v} ${v === '$' ? '' : '='} {

@@ -581,3 +584,3 @@ ${v === '$' ? aggr() : query(v)}

isEnum: col.type === 'enum' ? true : false,
fieldType: typeTbl.endsWith(']') && col.type !== 'enum' ? typeTbl.slice(0, -2) : typeTbl,
fieldType: typeTbl.endsWith(']') && col.type !== 'enum' && !['number[]', 'string[]', 'boolean[]', 'Date[]'].includes(typeTbl) ? typeTbl.slice(0, -2) : typeTbl,
required: col.optional === 'required' ? '' : '?',

@@ -646,3 +649,3 @@ isRelation: false,

export namespace ${key} {
${typeof tbl.kind === 'string' ? TblType(columns, tbl.uniques) : tblIter(tbl)}
${typeof tbl.kind === 'string' ? TblType({ kind: tbl.kind, columns }, tbl.uniques) : tblIter(tbl)}
}`;

@@ -649,0 +652,0 @@ };

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.argOpts = exports.queries = exports.aggregates = exports.ClientApiIndex = exports.ClientApi = exports.ServerIndex = exports.ServerServe = exports.ServerTsconfig = exports.ServerPackage = exports.ServerRPCIndex = exports.ServerRPCDir = exports.ApiIndex = exports.DefaultClientApiDir = exports.DefaultServerApiDir = exports.DefaultTsDir = exports.DefaultClientName = exports.DefaultServerName = exports.AcaOrmPropetty = exports.AcaMiscRemark = exports.AcaMiscRecordsDir = exports.AcaConfigSchema = exports.AcaMiscDir = exports.AcaTsconfig = exports.AcaExample = exports.AcaConfig = exports.AcaDir = exports.Pkg = exports.FrameworkClient = exports.ServerApiExport = exports.ClientApiExport = exports.Delimiter = void 0;
exports.argOpts = exports.viewQueries = exports.queries = exports.aggregates = exports.ClientApiIndex = exports.ClientApi = exports.ServerIndex = exports.ServerServe = exports.ServerTsconfig = exports.ServerPackage = exports.ServerRPCIndex = exports.ServerRPCDir = exports.ApiIndex = exports.DefaultClientApiDir = exports.DefaultServerApiDir = exports.DefaultTsDir = exports.DefaultClientName = exports.DefaultServerName = exports.AcaOrmPropetty = exports.AcaMiscRemark = exports.AcaMiscRecordsDir = exports.AcaConfigSchema = exports.AcaMiscDir = exports.AcaTsconfig = exports.AcaExample = exports.AcaConfig = exports.AcaDir = exports.Pkg = exports.FrameworkClient = exports.ServerApiExport = exports.ClientApiExport = exports.Delimiter = void 0;
exports.Delimiter = `_`;

@@ -54,2 +54,8 @@ exports.ClientApiExport = ['$RPC', '$Enum'];

];
exports.viewQueries = [
'findOne',
'findFirst',
'findMany',
'aggregate',
];
exports.argOpts = ['findFirst', 'findMany', 'deleteMany'].concat(exports.aggregates);

@@ -16,2 +16,6 @@ "use strict";

const foreigns = [];
if (tbls[jsName].kind === 'view' && tbls[jsName]['sql']) {
rtn.alter.push(`CREATE VIEW "${tbls[jsName].dbName}" AS ${tbls[jsName]['sql']}`);
return rtn;
}
if (tbls[jsName].dbName.length > sqlDiff.keyword.maxTblLen) {

@@ -51,5 +55,3 @@ throw new Error(`table ${tbls[jsName].dbName} length more than the ${sqlDiff.keyword.maxTblLen}`);

if (config.connectOption.driver === 'betterSqlite3') {
rtn.create.push(sqlDiff
.tbl(tbls[jsName].dbName)
.create(create.concat(foreigns).join(',\n')));
rtn.create.push(sqlDiff.tbl(tbls[jsName].dbName).create(create.concat(foreigns).join(',\n')));
rtn.alter.push(uniques.join(';\n\n'));

@@ -65,4 +67,5 @@ }

const sqlDiff = (0, sql_diff_1.default)(config.connectOption.driver);
if (tbls[jsName].kind === 'view')
return { remove: [``], alter: [] };
if (tbls[jsName].kind === 'view') {
return { remove: [`DROP VIEW IF EXISTS "${tbls[jsName].dbName}"`], alter: [] };
}
const rtn = { remove: [], alter: [] };

@@ -95,3 +98,3 @@ rtn.remove.push(sqlDiff.tbl(tbls[jsName].dbName).drop());

remove: [],
alter: [],
alter: []
};

@@ -117,5 +120,3 @@ for (const k in alter) {

}
constraint = sqlDiff
.tbl(tbl.dbName)
.constraint.foreign('ADD', v.props.foreign, relTbl);
constraint = sqlDiff.tbl(tbl.dbName).constraint.foreign('ADD', v.props.foreign, relTbl);
}

@@ -129,2 +130,3 @@ if (v.type.split('.').length === 1) {

notNull,
default: v.props.default
});

@@ -145,3 +147,3 @@ }

if (config.connectOption.driver === 'betterSqlite3') {
throw new Error("betterSqlite3 暂不支持修改外键");
throw new Error('betterSqlite3 暂不支持修改外键');
}

@@ -157,5 +159,3 @@ rtn.alter.push(constraint);

const relTbl = tbls[v.props.foreign.jsType?.split('.')[0]];
constraint = sqlDiff
.tbl(tbl.dbName)
.constraint.foreign('DROP', v.props.foreign, relTbl);
constraint = sqlDiff.tbl(tbl.dbName).constraint.foreign('DROP', v.props.foreign, relTbl);
}

@@ -171,3 +171,3 @@ if (v.props.unique) {

if (config.connectOption.driver === 'betterSqlite3') {
throw new Error("betterSqlite3 暂不支持修改外键");
throw new Error('betterSqlite3 暂不支持修改外键');
}

@@ -187,6 +187,3 @@ rtn.alter.push(constraint);

if (alterCol.map) {
rtn.alter.push(sqlDiff
.tbl(tbl.dbName)
.mutate.alter(alterCol.map.old)
.rename(alterCol.map.new));
rtn.alter.push(sqlDiff.tbl(tbl.dbName).mutate.alter(alterCol.map.old).rename(alterCol.map.new));
}

@@ -197,6 +194,8 @@ if (alterCol.optional) {

.mutate.alter(colName)
.notNull(({ required: 'SET', optional: 'DROP' }[alterCol.optional.new])));
.notNull({ required: 'SET', optional: 'DROP' }[alterCol.optional.new]));
}
if (alterCol.relation) {
if (!alterCol.relation.new.props.foreign && alterCol.relation.new.type.endsWith(']') && !alterCol.relation.isAlter) {
if (!alterCol.relation.new.props.foreign &&
alterCol.relation.new.type.endsWith(']') &&
!alterCol.relation.isAlter) {
const spt = alterCol.relation.new.props.jsType.split('.');

@@ -216,3 +215,5 @@ const relTblName = spt[0];

}
if (!alterCol.relation.old.props.foreign && alterCol.relation.old.type.endsWith(']') && !alterCol.relation.isAlter) {
if (!alterCol.relation.old.props.foreign &&
alterCol.relation.old.type.endsWith(']') &&
!alterCol.relation.isAlter) {
const spt = alterCol.relation.old.props.jsType.split('.');

@@ -224,5 +225,3 @@ const relTblName = spt[0];

const mapName = (0, common_1.MapTblName)(relTbl.dbName, relCol.dbName, tbl.dbName, alterCol.relation.old.dbName);
rtn.alter.push(sqlDiff
.tbl(mapName)
.drop());
rtn.alter.push(sqlDiff.tbl(mapName).drop());
}

@@ -238,6 +237,3 @@ }

if (alterCol.props.dbType) {
rtn.alter.push(sqlDiff
.tbl(tbl.dbName)
.mutate.alter(colName)
.type(alterCol.props.dbType.new));
rtn.alter.push(sqlDiff.tbl(tbl.dbName).mutate.alter(colName).type(alterCol.props.dbType.new));
}

@@ -253,6 +249,3 @@ if (alterCol.props.unique) {

if (alterCol.props.check) {
rtn.alter.push(sqlDiff
.tbl(tbl.dbName)
.mutate.alter(colName)
.check(alterCol.props.check.new));
rtn.alter.push(sqlDiff.tbl(tbl.dbName).mutate.alter(colName).check(alterCol.props.check.new));
}

@@ -262,13 +255,7 @@ if (alterCol.props.default !== undefined) {

alterCol.props.default.new = `''`;
rtn.alter.push(sqlDiff
.tbl(tbl.dbName)
.mutate.alter(colName)
.default(alterCol.props.default.new));
rtn.alter.push(sqlDiff.tbl(tbl.dbName).mutate.alter(colName).default(alterCol.props.default.new));
}
if (alterCol.props.createdAt) {
if (alterCol.props.createdAt.new) {
rtn.alter.push(sqlDiff
.tbl(tbl.dbName)
.mutate.alter(colName)
.default('CURRENT_TIMESTAMP'));
rtn.alter.push(sqlDiff.tbl(tbl.dbName).mutate.alter(colName).default('CURRENT_TIMESTAMP'));
rtn.alter.push(sqlDiff.tbl(tbl.dbName).mutate.alter(colName).notNull('DROP'));

@@ -282,6 +269,3 @@ }

if (alterCol.props.updatedAt.new) {
rtn.alter.push(sqlDiff
.tbl(tbl.dbName)
.mutate.alter(colName)
.default('CURRENT_TIMESTAMP'));
rtn.alter.push(sqlDiff.tbl(tbl.dbName).mutate.alter(colName).default('CURRENT_TIMESTAMP'));
rtn.alter.push(sqlDiff.tbl(tbl.dbName).mutate.alter(colName).notNull('DROP'));

@@ -295,15 +279,11 @@ }

if (config.connectOption.driver === 'betterSqlite3') {
throw new Error("betterSqlite3 暂不支持修改外键");
throw new Error('betterSqlite3 暂不支持修改外键');
}
if (alterCol.props.foreign.old) {
const relTbl = (tbls[alterCol.props.foreign.old.jsType?.split('.')[0]]);
rtn.alter.push(sqlDiff
.tbl(tbl.dbName)
.constraint.foreign('DROP', alterCol.props.foreign.old, relTbl));
const relTbl = tbls[alterCol.props.foreign.old.jsType?.split('.')[0]];
rtn.alter.push(sqlDiff.tbl(tbl.dbName).constraint.foreign('DROP', alterCol.props.foreign.old, relTbl));
}
if (alterCol.props.foreign.new) {
const relTbl = (tbls[alterCol.props.foreign.new.jsType?.split('.')[0]]);
rtn.alter.push(sqlDiff
.tbl(tbl.dbName)
.constraint.foreign('ADD', alterCol.props.foreign.new, relTbl));
const relTbl = tbls[alterCol.props.foreign.new.jsType?.split('.')[0]];
rtn.alter.push(sqlDiff.tbl(tbl.dbName).constraint.foreign('ADD', alterCol.props.foreign.new, relTbl));
}

@@ -361,3 +341,3 @@ }

alter: [],
mapTable: {},
mapTable: {}
};

@@ -374,5 +354,3 @@ const splits = colObj.type.match(/[\w\.]+/)[0].split('.');

const primaryKey = sqlDiff.keyword.stmt.primaryKey.toUpperCase();
const autoincrement = props.idType === 'autoincrement'
? sqlDiff.keyword.stmt.autoincrement.toUpperCase()
: '';
const autoincrement = props.idType === 'autoincrement' ? sqlDiff.keyword.stmt.autoincrement.toUpperCase() : '';
columnSql += `${dbType}${primaryKey}${autoincrement}`;

@@ -429,10 +407,6 @@ }

}
rtn.foreign.push(sqlDiff
.tbl(tblName)
.constraint.foreign('ADD', props.foreign, tbls[spt[0]]));
rtn.foreign.push(sqlDiff.tbl(tblName).constraint.foreign('ADD', props.foreign, tbls[spt[0]]));
}
if ('array' !== relCol.optional) {
rtn.unique.push(sqlDiff
.tbl(tblName)
.constraint.unique('ADD', colObj.props.foreign.keys));
rtn.unique.push(sqlDiff.tbl(tblName).constraint.unique('ADD', colObj.props.foreign.keys));
}

@@ -467,7 +441,5 @@ }

alter: [],
mapTable: {},
mapTable: {}
};
const addTbls = Object.keys(createArr
? createArr.reduce((_, v) => ((_[v.jsName] = v), _), {})
: flatTbls);
const addTbls = Object.keys(createArr ? createArr.reduce((_, v) => ((_[v.jsName] = v), _), {}) : flatTbls);
for (const v of addTbls) {

@@ -484,3 +456,3 @@ const sql = CreateTblSql(config, flatTbls, v);

total: tblCreate.create.length,
sqls: tblCreate.create.concat(tblCreate.alter).join(';\n\n'),
sqls: tblCreate.create.concat(tblCreate.alter).join(';\n\n')
};

@@ -496,3 +468,3 @@ }

alter: [],
remove: [],
remove: []
};

@@ -516,5 +488,23 @@ if ((0, common_1.notEmpty)(diff)) {

}
if (diff.alterView) {
for (const k in diff.alterView) {
const tbl = curr[k];
if (diff.alterView[k].map) {
if (currdb.config.connectOption.driver === 'betterSqlite3') {
rtn.alter.push(`DROP VIEW IF EXISTS "${diff.alterView[k].map['old']}"`);
rtn.alter.push(`CREATE VIEW "${diff.alterView[k].map['new']['name']}" AS ${diff.alterView[k].map['new']['sql']}`);
}
else {
rtn.alter.push(`ALTER VIEW "${diff.alterView[k].map['old']}" RENAME TO "${diff.alterView[k].map['new']['name']}"`);
}
}
if (diff.alterView[k]['sql']) {
rtn.alter.push(`DROP VIEW IF EXISTS "${diff.alterView[k]['sql']['old']}"`);
rtn.alter.push(`CREATE VIEW "${tbl.dbName}" AS ${diff.alterView[k]['sql']['new']}`);
}
}
}
}
return [...new Set([...rtn.create, ...rtn.alter, ...rtn.remove])].join(';\n');
return [...new Set([...rtn.remove, ...rtn.create, ...rtn.alter,])].join(';\n');
}
exports.DbDiffSqls = DbDiffSqls;

@@ -26,3 +26,3 @@ "use strict";

string: { jsType: 'string', dbType: stringType },
int: { jsType: 'number', dbType: 'int8' },
int: { jsType: 'number', dbType: 'int8' }
},

@@ -36,3 +36,3 @@ scalarType: {

boolean: { jsType: 'boolean', dbType: 'boolean' },
Date: { jsType: 'Date', dbType: 'timestamp' },
Date: { jsType: 'Date', dbType: 'timestamp' }
},

@@ -42,3 +42,3 @@ dbType: {

cuid: 'char(25)',
uuid: 'uuid',
uuid: 'uuid'
},

@@ -52,7 +52,7 @@ dbTypes: {

Date: ['timestamp', 'date', 'time', 'interval'],
string: [],
string: []
},
timestamp: {
create,
update: create,
update: create
},

@@ -87,3 +87,3 @@ stmt: {

...options,
database: 'postgres',
database: 'postgres'
});

@@ -93,4 +93,4 @@ await db.connect();

return db;
},
},
}
}
},

@@ -109,3 +109,3 @@ mssql: {

string: { jsType: 'string', dbType: stringType },
int: { jsType: 'number', dbType: 'int' },
int: { jsType: 'number', dbType: 'int' }
},

@@ -119,3 +119,3 @@ scalarType: {

boolean: { jsType: 'number', dbType: 'bit' },
Date: { jsType: 'Date', dbType: 'datetime' },
Date: { jsType: 'Date', dbType: 'datetime' }
},

@@ -125,3 +125,3 @@ dbType: {

cuid: 'char(25)',
uuid: 'char(36)',
uuid: 'char(36)'
},

@@ -135,7 +135,7 @@ dbTypes: {

Date: ['timestamp', 'date', 'time', 'interval'],
string: [],
string: []
},
timestamp: {
create,
update: create,
update: create
},

@@ -158,4 +158,4 @@ stmt: {

options: {
encrypt: false,
},
encrypt: false
}
};

@@ -170,8 +170,8 @@ opts.server = opts.host;

...opts,
database: 'master',
database: 'master'
});
}
return db;
},
},
}
}
},

@@ -188,3 +188,3 @@ mysql2: {

jsType: 'number',
dbType: 'int',
dbType: 'int'
},

@@ -194,3 +194,3 @@ cuid: { jsType: 'string', dbType: 'cuid' },

string: { jsType: 'string', dbType: 'varchar(200)' },
int: { jsType: 'number', dbType: 'int' },
int: { jsType: 'number', dbType: 'int' }
},

@@ -204,3 +204,3 @@ scalarType: {

boolean: { jsType: 'boolean', dbType: 'boolean' },
Date: { jsType: 'Date', dbType: 'timestamp' },
Date: { jsType: 'Date', dbType: 'timestamp' }
},

@@ -210,3 +210,3 @@ dbType: {

cuid: 'char(25)',
uuid: 'char(36)',
uuid: 'char(36)'
},

@@ -220,7 +220,7 @@ dbTypes: {

Date: ['timestamp', 'date', 'time', 'interval'],
string: [],
string: []
},
timestamp: {
create: create,
update: create,
update: create
},

@@ -246,8 +246,8 @@ stmt: {

...options,
database: undefined,
database: undefined
});
}
return db;
},
},
}
}
},

@@ -264,3 +264,3 @@ mysql: {

jsType: 'number',
dbType: 'int',
dbType: 'int'
},

@@ -270,3 +270,3 @@ cuid: { jsType: 'string', dbType: 'cuid' },

string: { jsType: 'string', dbType: 'varchar(200)' },
int: { jsType: 'number', dbType: 'int' },
int: { jsType: 'number', dbType: 'int' }
},

@@ -280,3 +280,3 @@ scalarType: {

boolean: { jsType: 'boolean', dbType: 'boolean' },
Date: { jsType: 'Date', dbType: 'timestamp' },
Date: { jsType: 'Date', dbType: 'timestamp' }
},

@@ -286,3 +286,3 @@ dbType: {

cuid: 'char(25)',
uuid: 'char(36)',
uuid: 'char(36)'
},

@@ -296,7 +296,7 @@ dbTypes: {

Date: ['timestamp', 'date', 'time', 'interval'],
string: [],
string: []
},
timestamp: {
create: create,
update: create,
update: create
},

@@ -324,3 +324,3 @@ stmt: {

...options,
database: undefined,
database: undefined
});

@@ -331,4 +331,4 @@ const conn = (0, util_1.promisify)((cb) => db.connect(cb));

return db;
},
},
}
}
},

@@ -345,3 +345,3 @@ betterSqlite3: {

jsType: 'number',
dbType: 'integer',
dbType: 'integer'
},

@@ -351,3 +351,3 @@ cuid: { jsType: 'string', dbType: 'cuid' },

string: { jsType: 'string', dbType: stringType },
int: { jsType: 'number', dbType: 'integer' },
int: { jsType: 'number', dbType: 'integer' }
},

@@ -361,3 +361,3 @@ scalarType: {

boolean: { jsType: 'boolean', dbType: 'integer' },
Date: { jsType: 'Date', dbType: 'timestamp' },
Date: { jsType: 'Date', dbType: 'timestamp' }
},

@@ -367,3 +367,3 @@ dbType: {

cuid: 'char(25)',
uuid: 'char(36)',
uuid: 'char(36)'
},

@@ -377,7 +377,7 @@ dbTypes: {

Date: ['timestamp', 'date', 'time'],
string: [],
string: []
},
timestamp: {
create,
update: create,
update: create
},

@@ -401,8 +401,8 @@ stmt: {

...options,
filename: undefined,
filename: undefined
})
: null;
},
},
},
}
}
}
};

@@ -421,3 +421,3 @@ function default_1(driver) {

return {
pg: ` SELECT * FROM pg_database WHERE datname = ${qPrefix}${dbName}${qName}`,
pg: ` SELECT * FROM pg_database WHERE datname = ${qPrefix}${dbName}${qName}`
}[driver];

@@ -430,3 +430,3 @@ },

AND tablename NOT LIKE 'sql_%'
ORDER BY tablename`,
ORDER BY tablename`
}[driver];

@@ -454,5 +454,5 @@ },

...option,
filename: undefined,
filename: undefined
});
},
}
},

@@ -465,3 +465,3 @@ tbl(table) {

pg: `select * from information_schema.columns
where table_schema = 'public' and table_name='${table}'`,
where table_schema = 'public' and table_name='${table}'`
}[driver];

@@ -483,3 +483,3 @@ },

const cols = columns
.map((v) => `ADD COLUMN ${qName}${v.name}${qName} ${v.dbType.toUpperCase()}${v.notNull ? ' NOT NULL' : ''}`)
.map((v) => `ADD COLUMN ${qName}${v.name}${qName} ${v.dbType.toUpperCase()}${v.notNull ? ' NOT NULL' : ''}${v.default !== undefined ? ` DEFAULT ${typeof v.default === 'string' ? v.default ? v.default : '' : v.default}` : ''}`)
.join(', ');

@@ -523,5 +523,3 @@ return `ALTER TABLE ${qPrefix}${table}${qName} ${cols}`;

}
return `ALTER TABLE ${qPrefix}${table}${qName} ALTER COLUMN ${qName}${column}${qName} ${value !== undefined
? `SET CHECK ${qValue}${value}${qValue}`
: 'DROP CHECK'}`;
return `ALTER TABLE ${qPrefix}${table}${qName} ALTER COLUMN ${qName}${column}${qName} ${value !== undefined ? `SET CHECK ${qValue}${value}${qValue}` : 'DROP CHECK'}`;
},

@@ -533,5 +531,5 @@ default(value) {

return `ALTER TABLE ${qPrefix}${table}${qName} ALTER COLUMN ${qName}${column}${qName} ${value !== undefined ? `SET DEFAULT ${value}` : 'DROP DEFAULT'}`;
},
}
};
},
}
},

@@ -550,3 +548,3 @@ constraint: {

JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
WHERE constraint_type = '${type}' AND tc.table_name = '${table}'`,
WHERE constraint_type = '${type}' AND tc.table_name = '${table}'`
}[driver];

@@ -571,5 +569,3 @@ },

const key = columns.join('_');
const quoteCols = `${columns
.map((v) => `${qName}${v}${qName}`)
.toString()}`;
const quoteCols = `${columns.map((v) => `${qName}${v}${qName}`).toString()}`;
if ('betterSqlite3' === driver) {

@@ -588,9 +584,6 @@ if (action === 'DROP') {

let quoteCols = `${qName}${columns}${qName}`;
quoteCols =
typeof columns === 'string' ? quoteCols : quoteCols.toString();
return `${action} INDEX ${qName}INDEX_${table}_${key}${qName}${action === 'CREATE'
? ` ON ${qName}${table}${qName} (${quoteCols})`
: ''}`;
},
},
quoteCols = typeof columns === 'string' ? quoteCols : quoteCols.toString();
return `${action} INDEX ${qName}INDEX_${table}_${key}${qName}${action === 'CREATE' ? ` ON ${qName}${table}${qName} (${quoteCols})` : ''}`;
}
}
};

@@ -611,5 +604,5 @@ },

async rename(column) { },
async alter(column) { },
async alter(column) { }
};
},
}
};

@@ -620,6 +613,6 @@ },

insert: (version, orm) => `\nINSERT INTO ${qPrefix}___ACA${qName} (${qName}version${qName}, ${qName}orm${qName}) VALUES (${qValue}${version}${qValue}, ${qValue}${orm || ''}${qValue});\n`,
select: `\nSELECT * FROM ${qPrefix}___ACA${qName};\n`,
},
select: `\nSELECT * FROM ${qPrefix}___ACA${qName};\n`
}
};
}
exports.default = default_1;

@@ -48,19 +48,37 @@ "use strict";

alter: {},
alterView: {}
};
const contains = Fluctuate(curr, prev, rtn);
contains.forEach((v) => {
if (curr[v].map !== prev[v].map && curr[v].dbName !== prev[v].dbName) {
if (curr[v].kind === 'view') {
if (curr[v].map !== prev[v].map && curr[v].dbName !== prev[v].dbName) {
rtn.alterView[v] = rtn.alterView[v] || {};
rtn.alterView[v].map = { new: {
name: curr[v].dbName,
sql: curr[v]['sql']
}, old: prev[v].dbName };
}
if (curr[v]['sql'] !== prev[v]['sql']) {
rtn.alterView[v] = rtn.alterView[v] || {};
rtn.alterView[v].sql = { new: curr[v]['sql'], old: prev[v].dbName };
}
if ((0, common_1.isEmpty)(rtn.alterView[v]))
delete rtn.alterView[v];
}
else {
if (curr[v].map !== prev[v].map && curr[v].dbName !== prev[v].dbName) {
rtn.alter[v] = rtn.alter[v] || {};
rtn.alter[v].map = { new: curr[v].dbName, old: prev[v].dbName };
}
rtn.alter[v] = rtn.alter[v] || {};
rtn.alter[v].map = { new: curr[v].dbName, old: prev[v].dbName };
rtn.alter[v]['columns'] = rtn.alter[v]['columns'] || {};
Column(rtn.alter[v]['columns'], curr[v]['columns'], prev[v]['columns']);
if ((0, common_1.isEmpty)(rtn.alter[v]['columns']))
delete rtn.alter[v]['columns'];
rtn.alter[v]['props'] = BlockProps(curr[v]['props'], prev[v]['props']);
if ((0, common_1.isEmpty)(rtn.alter[v]['props']))
delete rtn.alter[v]['props'];
if ((0, common_1.isEmpty)(rtn.alter[v]))
delete rtn.alter[v];
}
rtn.alter[v] = rtn.alter[v] || {};
rtn.alter[v]['columns'] = rtn.alter[v]['columns'] || {};
Column(rtn.alter[v]['columns'], curr[v]['columns'], prev[v]['columns']);
if ((0, common_1.isEmpty)(rtn.alter[v]['columns']))
delete rtn.alter[v]['columns'];
rtn.alter[v]['props'] = BlockProps(curr[v]['props'], prev[v]['props']);
if ((0, common_1.isEmpty)(rtn.alter[v]['props']))
delete rtn.alter[v]['props'];
if ((0, common_1.isEmpty)(rtn.alter[v]))
delete rtn.alter[v];
});

@@ -121,3 +139,3 @@ for (const k in rtn) {

'createdAt',
'updatedAt',
'updatedAt'
].forEach((v2) => {

@@ -128,3 +146,3 @@ colAlt[v].props = colAlt[v].props || {};

new: cCol.props[v2],
old: pCol.props[v2],
old: pCol.props[v2]
};

@@ -134,6 +152,7 @@ }

if (cCol.props.foreign || pCol.props.foreign) {
if (JSON.stringify(cCol.props.foreign?.references) !== JSON.stringify(pCol.props.foreign?.references)) {
if (JSON.stringify(cCol.props.foreign?.references) !==
JSON.stringify(pCol.props.foreign?.references)) {
colAlt[v].props.foreign = {
new: cCol.props.foreign,
old: pCol.props.foreign,
old: pCol.props.foreign
};

@@ -147,3 +166,3 @@ }

new: cCol.props.foreign,
old: pCol.props.foreign,
old: pCol.props.foreign
};

@@ -150,0 +169,0 @@ }

@@ -351,2 +351,9 @@ "use strict";

body.kind = 'view';
body['sql'] = props['view'];
body['uniques'] = [];
body['indexes'] = [];
if (props['id'])
(body['id'] = props['id']), body['uniques'].push(props['id']);
if (props['uniques'])
body['uniques'].push(...props['uniques']);
delete props['view'];

@@ -384,2 +391,7 @@ }

}
if (body.kind === 'view') {
col['props'] = props;
if (props['unique'])
body['uniques'].push([colKey]);
}
let init;

@@ -394,3 +406,3 @@ if (V2.initializer) {

const idType = col['type'].match(/^id(\[\w+\])?$/);
if (idType) {
if (idType && col['props']) {
col['props'].isId = true;

@@ -489,3 +501,2 @@ }

case 'view':
break;
case 'table':

@@ -492,0 +503,0 @@ const tbl = subModels[k];

{
"name": "aca.ts",
"version": "0.0.91",
"version": "0.0.92",
"description": "ACA.ts is a fullstack development toolkit, which can automatically synchronize database schema and generate database query APIs according to a typescript ORM document; Automatically generate the client access server APIs according to the server functions and database query APIs, so that the client code can be developed on the client.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -35,2 +35,11 @@ English | [中文文档](https://aca.ts.center/zh)

@$.view('select "user"."id" as "userid", "user"."name", "user"."married", "user"."age", "profile"."password" from "user" left join "profile" as "profile" on "user"."id" = "profile"."userId"')
class userProfile {
userid: id
@$_.unique name: string
married = false
age?: int
password?: string
}
export class post {

@@ -37,0 +46,0 @@ id: id

module.exports = `\n
/* eslint-disable @typescript-eslint/no-namespace */
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable @typescript-eslint/no-unused-expressions */
/* eslint-disable @typescript-eslint/no-redeclare */
/* eslint-disable @typescript-eslint/no-unused-vars */
// @ts-nocheck
type $EnumKeys = keyof $Enum

@@ -10,0 +5,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc