sonamu 0.2.54 → 0.3.1
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/dist/bin/cli.js +48 -48
- package/dist/bin/cli.mjs +1 -1
- package/dist/{chunk-L4KELCY7.mjs → chunk-MPXE4IHO.mjs} +49 -46
- package/dist/chunk-MPXE4IHO.mjs.map +1 -0
- package/dist/{chunk-JOHF7PK4.js → chunk-YXILRRDT.js} +55 -52
- package/dist/chunk-YXILRRDT.js.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/entity/entity-manager.ts +9 -5
- package/src/entity/entity.ts +9 -13
- package/src/syncer/syncer.ts +34 -29
- package/dist/chunk-JOHF7PK4.js.map +0 -1
- package/dist/chunk-L4KELCY7.mjs.map +0 -1
|
@@ -3134,7 +3134,7 @@ var Syncer = class {
|
|
|
3134
3134
|
const name = paramDec.name;
|
|
3135
3135
|
const type = this.resolveTypeNode(paramDec.type);
|
|
3136
3136
|
if (name === void 0) {
|
|
3137
|
-
console.
|
|
3137
|
+
console.debug({ name, type, paramDec });
|
|
3138
3138
|
}
|
|
3139
3139
|
return {
|
|
3140
3140
|
name: name.escapedText ? name.escapedText.toString() : `nonameAt${index}`,
|
|
@@ -3353,7 +3353,7 @@ var Syncer = class {
|
|
|
3353
3353
|
await _fsextra2.default.writeJSON(this.checksumsPath, checksums, {
|
|
3354
3354
|
spaces: 2
|
|
3355
3355
|
});
|
|
3356
|
-
console.
|
|
3356
|
+
console.log("checksum saved", this.checksumsPath);
|
|
3357
3357
|
}
|
|
3358
3358
|
async getChecksumOfFile(filePath) {
|
|
3359
3359
|
return new Promise((resolve, reject) => {
|
|
@@ -3829,30 +3829,36 @@ var Syncer = class {
|
|
|
3829
3829
|
const enumsKeys = Object.keys(enums).filter(
|
|
3830
3830
|
(name) => name !== names.constant
|
|
3831
3831
|
);
|
|
3832
|
-
return keys.reduce(
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3832
|
+
return keys.reduce(
|
|
3833
|
+
(result, key) => {
|
|
3834
|
+
const tpl = this.getTemplate(key);
|
|
3835
|
+
if (key.startsWith("view_enums")) {
|
|
3836
|
+
enumsKeys.map((componentId) => {
|
|
3837
|
+
const { target: target2, path: p2 } = tpl.getTargetAndPath(
|
|
3838
|
+
names,
|
|
3839
|
+
componentId
|
|
3840
|
+
);
|
|
3841
|
+
result[`${key}__${componentId}`] = _fsextra2.default.existsSync(
|
|
3842
|
+
_path2.default.join(Sonamu.appRootPath, target2, p2)
|
|
3843
|
+
);
|
|
3844
|
+
});
|
|
3845
|
+
return result;
|
|
3846
|
+
}
|
|
3847
|
+
const { target, path: p } = tpl.getTargetAndPath(names);
|
|
3848
|
+
const { targets } = Sonamu.config.sync;
|
|
3849
|
+
if (target.includes(":target")) {
|
|
3850
|
+
targets.map((t) => {
|
|
3851
|
+
result[`${key}__${t}`] = _fsextra2.default.existsSync(
|
|
3852
|
+
_path2.default.join(Sonamu.appRootPath, target.replace(":target", t), p)
|
|
3853
|
+
);
|
|
3854
|
+
});
|
|
3855
|
+
} else {
|
|
3856
|
+
result[key] = _fsextra2.default.existsSync(_path2.default.join(Sonamu.appRootPath, target, p));
|
|
3857
|
+
}
|
|
3841
3858
|
return result;
|
|
3842
|
-
}
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
if (target.includes(":target")) {
|
|
3846
|
-
targets.map((t) => {
|
|
3847
|
-
result[`${key}__${t}`] = _fsextra2.default.existsSync(
|
|
3848
|
-
_path2.default.join(Sonamu.appRootPath, target.replace(":target", t), p)
|
|
3849
|
-
);
|
|
3850
|
-
});
|
|
3851
|
-
} else {
|
|
3852
|
-
result[key] = _fsextra2.default.existsSync(_path2.default.join(Sonamu.appRootPath, target, p));
|
|
3853
|
-
}
|
|
3854
|
-
return result;
|
|
3855
|
-
}, {});
|
|
3859
|
+
},
|
|
3860
|
+
{}
|
|
3861
|
+
);
|
|
3856
3862
|
}
|
|
3857
3863
|
async getZodTypeById(zodTypeId) {
|
|
3858
3864
|
const modulePath = EntityManager.getModulePath(zodTypeId);
|
|
@@ -3892,9 +3898,7 @@ var Syncer = class {
|
|
|
3892
3898
|
const obj = await propNode.children.reduce(
|
|
3893
3899
|
async (promise, childPropNode) => {
|
|
3894
3900
|
const result = await promise;
|
|
3895
|
-
result[childPropNode.prop.name] = await this.propNodeToZodType(
|
|
3896
|
-
childPropNode
|
|
3897
|
-
);
|
|
3901
|
+
result[childPropNode.prop.name] = await this.propNodeToZodType(childPropNode);
|
|
3898
3902
|
return result;
|
|
3899
3903
|
},
|
|
3900
3904
|
{}
|
|
@@ -5021,7 +5025,7 @@ var EntityManagerClass = class {
|
|
|
5021
5025
|
_glob2.default.glob(_path2.default.resolve(pathPattern), (_err, files) => {
|
|
5022
5026
|
Promise.all(
|
|
5023
5027
|
files.map(async (file) => {
|
|
5024
|
-
this.register(JSON.parse(_fsextra2.default.readFileSync(file).toString()));
|
|
5028
|
+
await this.register(JSON.parse(_fsextra2.default.readFileSync(file).toString()));
|
|
5025
5029
|
})
|
|
5026
5030
|
).then(() => {
|
|
5027
5031
|
resolve("ok");
|
|
@@ -5038,15 +5042,17 @@ var EntityManagerClass = class {
|
|
|
5038
5042
|
this.isAutoloaded = false;
|
|
5039
5043
|
const sonamuPath = _path2.default.join(
|
|
5040
5044
|
Sonamu.apiRootPath,
|
|
5041
|
-
|
|
5045
|
+
`dist/application/sonamu.generated.js?t=${Date.now()}`
|
|
5042
5046
|
);
|
|
5043
|
-
if (__require.cache[sonamuPath]) {
|
|
5047
|
+
if (_optionalChain([__require, 'optionalAccess', _87 => _87.cache]) && __require.cache[sonamuPath]) {
|
|
5044
5048
|
delete __require.cache[sonamuPath];
|
|
5045
5049
|
}
|
|
5046
|
-
return this.autoload(doSilent);
|
|
5050
|
+
return await this.autoload(doSilent);
|
|
5047
5051
|
}
|
|
5048
|
-
register(json) {
|
|
5052
|
+
async register(json) {
|
|
5049
5053
|
const entity = new Entity(json);
|
|
5054
|
+
await entity.registerModulePaths();
|
|
5055
|
+
entity.registerTableSpecs();
|
|
5050
5056
|
this.entities.set(json.id, entity);
|
|
5051
5057
|
}
|
|
5052
5058
|
get(entityId) {
|
|
@@ -5179,8 +5185,6 @@ var Entity = class {
|
|
|
5179
5185
|
fs: _inflection2.default.dasherize(_inflection2.default.underscore(id)).toLowerCase(),
|
|
5180
5186
|
module: id
|
|
5181
5187
|
};
|
|
5182
|
-
this.registerModulePaths();
|
|
5183
|
-
this.registerTableSpecs();
|
|
5184
5188
|
}
|
|
5185
5189
|
/*
|
|
5186
5190
|
subset SELECT/JOIN/LOADER 결과 리턴
|
|
@@ -5326,7 +5330,7 @@ var Entity = class {
|
|
|
5326
5330
|
const relSubsetQuery = relEntity.resolveSubsetQuery("", relFields);
|
|
5327
5331
|
let manyJoin;
|
|
5328
5332
|
if (isHasManyRelationProp(relation)) {
|
|
5329
|
-
const fromCol = _nullishCoalesce(_optionalChain([relation, 'optionalAccess',
|
|
5333
|
+
const fromCol = _nullishCoalesce(_optionalChain([relation, 'optionalAccess', _88 => _88.fromColumn]), () => ( "id"));
|
|
5330
5334
|
manyJoin = {
|
|
5331
5335
|
fromTable: this.table,
|
|
5332
5336
|
fromCol,
|
|
@@ -5498,7 +5502,7 @@ var Entity = class {
|
|
|
5498
5502
|
return prop.name;
|
|
5499
5503
|
}).filter(nonNullable);
|
|
5500
5504
|
}
|
|
5501
|
-
registerModulePaths() {
|
|
5505
|
+
async registerModulePaths() {
|
|
5502
5506
|
const basePath = `${this.names.parentFs}`;
|
|
5503
5507
|
EntityManager.setModulePath(`${this.id}BaseSchema`, `sonamu.generated`);
|
|
5504
5508
|
if (Object.keys(this.subsets).length > 0) {
|
|
@@ -5524,15 +5528,14 @@ var Entity = class {
|
|
|
5524
5528
|
);
|
|
5525
5529
|
if (_fsextra2.default.existsSync(typesFileDistPath)) {
|
|
5526
5530
|
const importPath = _path2.default.relative(__dirname, typesFileDistPath);
|
|
5527
|
-
Promise.resolve().then(() => _interopRequireWildcard(require(importPath)))
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
});
|
|
5531
|
+
const t = await Promise.resolve().then(() => _interopRequireWildcard(require(importPath)));
|
|
5532
|
+
this.types = Object.keys(t).reduce((result, key) => {
|
|
5533
|
+
EntityManager.setModulePath(key, typesModulePath);
|
|
5534
|
+
return {
|
|
5535
|
+
...result,
|
|
5536
|
+
[key]: t[key]
|
|
5537
|
+
};
|
|
5538
|
+
}, {});
|
|
5536
5539
|
}
|
|
5537
5540
|
}
|
|
5538
5541
|
registerTableSpecs() {
|
|
@@ -6531,7 +6534,7 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
6531
6534
|
const [, keyName, from, referencesTable, referencesField, onClause] = matched2;
|
|
6532
6535
|
const [onUpdateFull, _onUpdate] = _nullishCoalesce((_nullishCoalesce(onClause, () => ( ""))).match(/ON UPDATE ([A-Z ]+)$/), () => ( []));
|
|
6533
6536
|
const onUpdate = _nullishCoalesce(_onUpdate, () => ( "NO ACTION"));
|
|
6534
|
-
const onDelete = _nullishCoalesce(_optionalChain([(_nullishCoalesce(onClause, () => ( ""))), 'access',
|
|
6537
|
+
const onDelete = _nullishCoalesce(_optionalChain([(_nullishCoalesce(onClause, () => ( ""))), 'access', _89 => _89.replace, 'call', _90 => _90(_nullishCoalesce(onUpdateFull, () => ( "")), ""), 'access', _91 => _91.match, 'call', _92 => _92(/ON DELETE ([A-Z ]+) /), 'optionalAccess', _93 => _93[1]]), () => ( "NO ACTION"));
|
|
6535
6538
|
return {
|
|
6536
6539
|
keyName,
|
|
6537
6540
|
from,
|
|
@@ -7406,7 +7409,7 @@ var FixtureManagerClass = class {
|
|
|
7406
7409
|
const targetDB = _knex2.default.call(void 0, Sonamu.dbConfig[targetDBName]);
|
|
7407
7410
|
const { entityId, field, value, searchType } = searchOptions;
|
|
7408
7411
|
const entity = EntityManager.get(entityId);
|
|
7409
|
-
const column = _optionalChain([entity, 'access',
|
|
7412
|
+
const column = _optionalChain([entity, 'access', _94 => _94.props, 'access', _95 => _95.find, 'call', _96 => _96((prop) => prop.name === field), 'optionalAccess', _97 => _97.type]) === "relation" ? `${field}_id` : field;
|
|
7410
7413
|
let query = sourceDB(entity.table);
|
|
7411
7414
|
if (searchType === "equals") {
|
|
7412
7415
|
query = query.where(column, value);
|
|
@@ -7478,7 +7481,7 @@ var FixtureManagerClass = class {
|
|
|
7478
7481
|
prop,
|
|
7479
7482
|
value: row[prop.name]
|
|
7480
7483
|
};
|
|
7481
|
-
const db = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
7484
|
+
const db = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _98 => _98._db]), () => ( BaseModel.getDB("w")));
|
|
7482
7485
|
if (isManyToManyRelationProp(prop)) {
|
|
7483
7486
|
const relatedEntity = EntityManager.get(prop.with);
|
|
7484
7487
|
const throughTable = prop.joinTable;
|
|
@@ -7497,7 +7500,7 @@ var FixtureManagerClass = class {
|
|
|
7497
7500
|
);
|
|
7498
7501
|
if (relatedProp) {
|
|
7499
7502
|
const relatedRow = await db(relatedEntity.table).where("id", row.id).first();
|
|
7500
|
-
record.columns[prop.name].value = _optionalChain([relatedRow, 'optionalAccess',
|
|
7503
|
+
record.columns[prop.name].value = _optionalChain([relatedRow, 'optionalAccess', _99 => _99.id]);
|
|
7501
7504
|
}
|
|
7502
7505
|
} else if (isRelationProp(prop)) {
|
|
7503
7506
|
const relatedId = row[`${prop.name}_id`];
|
|
@@ -7505,7 +7508,7 @@ var FixtureManagerClass = class {
|
|
|
7505
7508
|
if (relatedId) {
|
|
7506
7509
|
record.belongsRecords.push(`${prop.with}#${relatedId}`);
|
|
7507
7510
|
}
|
|
7508
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
7511
|
+
if (!_optionalChain([options, 'optionalAccess', _100 => _100.singleRecord]) && relatedId) {
|
|
7509
7512
|
const relatedEntity = EntityManager.get(prop.with);
|
|
7510
7513
|
const relatedRow = await db(relatedEntity.table).where("id", relatedId).first();
|
|
7511
7514
|
if (relatedRow) {
|
|
@@ -7845,4 +7848,4 @@ var FixtureManager = new FixtureManagerClass();
|
|
|
7845
7848
|
|
|
7846
7849
|
|
|
7847
7850
|
exports.SQLDateTimeString = SQLDateTimeString; exports.zArrayable = zArrayable; exports.isIntegerProp = isIntegerProp; exports.isBigIntegerProp = isBigIntegerProp; exports.isTextProp = isTextProp; exports.isStringProp = isStringProp; exports.isEnumProp = isEnumProp; exports.isFloatProp = isFloatProp; exports.isDoubleProp = isDoubleProp; exports.isDecimalProp = isDecimalProp; exports.isBooleanProp = isBooleanProp; exports.isDateProp = isDateProp; exports.isDateTimeProp = isDateTimeProp; exports.isTimeProp = isTimeProp; exports.isTimestampProp = isTimestampProp; exports.isJsonProp = isJsonProp; exports.isUuidProp = isUuidProp; exports.isVirtualProp = isVirtualProp; exports.isRelationProp = isRelationProp; exports.isOneToOneRelationProp = isOneToOneRelationProp; exports.isBelongsToOneRelationProp = isBelongsToOneRelationProp; exports.isHasManyRelationProp = isHasManyRelationProp; exports.isManyToManyRelationProp = isManyToManyRelationProp; exports.isCustomJoinClause = isCustomJoinClause; exports.SonamuQueryMode = SonamuQueryMode; exports.isKnexError = isKnexError; exports.ApiParamType = ApiParamType; exports.RenderingNode = RenderingNode; exports.TemplateOptions = TemplateOptions; exports.TemplateKey = TemplateKey; exports.GenerateOptions = GenerateOptions; exports.PathAndCode = PathAndCode; exports.getZodObjectFromApi = getZodObjectFromApi; exports.getZodObjectFromApiParams = getZodObjectFromApiParams; exports.getZodTypeFromApiParamType = getZodTypeFromApiParamType; exports.propNodeToZodTypeDef = propNodeToZodTypeDef; exports.getTextTypeLength = getTextTypeLength; exports.propToZodTypeDef = propToZodTypeDef; exports.zodTypeToZodCode = zodTypeToZodCode; exports.apiParamToTsCode = apiParamToTsCode; exports.apiParamTypeToTsType = apiParamTypeToTsType; exports.unwrapPromiseOnce = unwrapPromiseOnce; exports.serializeZodType = serializeZodType; exports.zodTypeToTsTypeDef = zodTypeToTsTypeDef; exports.registeredApis = registeredApis; exports.api = api; exports.SoException = SoException; exports.isSoException = isSoException; exports.BadRequestException = BadRequestException; exports.UnauthorizedException = UnauthorizedException; exports.NotFoundException = NotFoundException; exports.ServiceUnavailableException = ServiceUnavailableException; exports.InternalServerErrorException = InternalServerErrorException; exports.AlreadyProcessedException = AlreadyProcessedException; exports.DuplicateRowException = DuplicateRowException; exports.TargetNotFoundException = TargetNotFoundException; exports.globAsync = globAsync; exports.importMultiple = importMultiple; exports.findAppRootPath = findAppRootPath; exports.findApiRootPath = findApiRootPath; exports.nonNullable = nonNullable; exports.Entity = Entity; exports.EntityManager = EntityManager; exports.Syncer = Syncer; exports.isLocal = isLocal; exports.isRemote = isRemote; exports.isInDocker = isInDocker; exports.isDaemonServer = isDaemonServer; exports.isDevelopment = isDevelopment; exports.isStaging = isStaging; exports.isProduction = isProduction; exports.isTest = isTest; exports.DB = DB; exports.isRefField = isRefField; exports.UpsertBuilder = UpsertBuilder; exports.BaseModelClass = BaseModelClass; exports.BaseModel = BaseModel; exports.Sonamu = Sonamu; exports.Migrator = Migrator; exports.FixtureManagerClass = FixtureManagerClass; exports.FixtureManager = FixtureManager;
|
|
7848
|
-
//# sourceMappingURL=chunk-
|
|
7851
|
+
//# sourceMappingURL=chunk-YXILRRDT.js.map
|