sonamu 0.2.46 → 0.2.47
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.js.map +1 -1
- package/dist/{chunk-77XBF27L.js → chunk-5VT5JTY4.js} +185 -186
- package/dist/chunk-5VT5JTY4.js.map +1 -0
- package/dist/index.d.ts +24 -2
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/bin/cli.ts +1 -1
- package/src/entity/entity.ts +5 -0
- package/src/exceptions/so-exceptions.ts +27 -9
- package/src/index.ts +1 -0
- package/src/syncer/syncer.ts +32 -45
- package/src/templates/entity.template.ts +27 -25
- package/src/types/types.ts +4 -0
- package/dist/chunk-77XBF27L.js.map +0 -1
|
@@ -156,7 +156,11 @@ var TemplateOptions = _zod.z.object({
|
|
|
156
156
|
entityId: _zod.z.string(),
|
|
157
157
|
parentId: _zod.z.string().optional(),
|
|
158
158
|
title: _zod.z.string(),
|
|
159
|
-
table: _zod.z.string().optional()
|
|
159
|
+
table: _zod.z.string().optional(),
|
|
160
|
+
props: _zod.z.array(_zod.z.object({})).optional(),
|
|
161
|
+
indexes: _zod.z.array(_zod.z.object({})).optional(),
|
|
162
|
+
subsets: _zod.z.object({}).optional(),
|
|
163
|
+
enums: _zod.z.object({}).optional()
|
|
160
164
|
}),
|
|
161
165
|
init_types: _zod.z.object({
|
|
162
166
|
entityId: _zod.z.string()
|
|
@@ -802,21 +806,21 @@ var InternalServerErrorException = class extends SoException {
|
|
|
802
806
|
};
|
|
803
807
|
var AlreadyProcessedException = class extends SoException {
|
|
804
808
|
constructor(message = "Already Processed", payload) {
|
|
805
|
-
super(
|
|
809
|
+
super(541, message, payload);
|
|
806
810
|
this.message = message;
|
|
807
811
|
this.payload = payload;
|
|
808
812
|
}
|
|
809
813
|
};
|
|
810
814
|
var DuplicateRowException = class extends SoException {
|
|
811
815
|
constructor(message = "Duplicate Row", payload) {
|
|
812
|
-
super(
|
|
816
|
+
super(542, message, payload);
|
|
813
817
|
this.message = message;
|
|
814
818
|
this.payload = payload;
|
|
815
819
|
}
|
|
816
820
|
};
|
|
817
821
|
var TargetNotFoundException = class extends SoException {
|
|
818
822
|
constructor(message = "Target Not Found", payload) {
|
|
819
|
-
super(
|
|
823
|
+
super(520, message, payload);
|
|
820
824
|
this.message = message;
|
|
821
825
|
this.payload = payload;
|
|
822
826
|
}
|
|
@@ -874,15 +878,11 @@ function nonNullable(value) {
|
|
|
874
878
|
return value !== null && value !== void 0;
|
|
875
879
|
}
|
|
876
880
|
|
|
877
|
-
// src/entity/entity-manager.ts
|
|
878
|
-
var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
881
|
// src/entity/entity.ts
|
|
884
882
|
var _lodash = require('lodash'); var _lodash2 = _interopRequireDefault(_lodash);
|
|
885
883
|
|
|
884
|
+
// src/entity/entity-manager.ts
|
|
885
|
+
var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);
|
|
886
886
|
|
|
887
887
|
|
|
888
888
|
|
|
@@ -1251,7 +1251,7 @@ var Template__entity = class extends Template {
|
|
|
1251
1251
|
title: _nullishCoalesce(title, () => ( entityId)),
|
|
1252
1252
|
parentId,
|
|
1253
1253
|
table: _nullishCoalesce(table, () => ( names.fsPlural.replace(/\-/g, "_"))),
|
|
1254
|
-
props: [
|
|
1254
|
+
props: _optionalChain([options, 'access', _61 => _61.props, 'optionalAccess', _62 => _62.length]) ? options.props : [
|
|
1255
1255
|
{ name: "id", type: "integer", unsigned: true, desc: "ID" },
|
|
1256
1256
|
...parent ? [
|
|
1257
1257
|
{
|
|
@@ -1271,20 +1271,20 @@ var Template__entity = class extends Template {
|
|
|
1271
1271
|
dbDefault: "CURRENT_TIMESTAMP"
|
|
1272
1272
|
}
|
|
1273
1273
|
],
|
|
1274
|
-
indexes: [],
|
|
1275
|
-
subsets: {
|
|
1274
|
+
indexes: [..._nullishCoalesce(options.indexes, () => ( []))],
|
|
1275
|
+
subsets: _nullishCoalesce(options.subsets, () => ( {
|
|
1276
1276
|
...parentId ? {} : {
|
|
1277
1277
|
A: ["id", "created_at"]
|
|
1278
1278
|
}
|
|
1279
|
-
},
|
|
1280
|
-
enums: {
|
|
1279
|
+
})),
|
|
1280
|
+
enums: _nullishCoalesce(options.enums, () => ( {
|
|
1281
1281
|
...parentId ? {} : {
|
|
1282
1282
|
[`${names.capital}OrderBy`]: {
|
|
1283
1283
|
"id-desc": "ID\uCD5C\uC2E0\uC21C"
|
|
1284
1284
|
},
|
|
1285
1285
|
[`${names.capital}SearchField`]: { id: "ID" }
|
|
1286
1286
|
}
|
|
1287
|
-
}
|
|
1287
|
+
}))
|
|
1288
1288
|
}).trim(),
|
|
1289
1289
|
importKeys: []
|
|
1290
1290
|
};
|
|
@@ -1342,7 +1342,7 @@ var Template__view_list = class extends Template {
|
|
|
1342
1342
|
return `<>{/* object ${colName} */}</>`;
|
|
1343
1343
|
case "object-pick":
|
|
1344
1344
|
const pickedChild = col.children.find(
|
|
1345
|
-
(child) => child.name === _optionalChain([col, 'access',
|
|
1345
|
+
(child) => child.name === _optionalChain([col, 'access', _63 => _63.config, 'optionalAccess', _64 => _64.picked])
|
|
1346
1346
|
);
|
|
1347
1347
|
if (!pickedChild) {
|
|
1348
1348
|
throw new Error(`object-pick \uC120\uD0DD \uC2E4\uD328 (\uC624\uBE0C\uC81D\uD2B8: ${col.name})`);
|
|
@@ -1456,13 +1456,13 @@ var Template__view_list = class extends Template {
|
|
|
1456
1456
|
orderBy: "id-desc",
|
|
1457
1457
|
search: "title"
|
|
1458
1458
|
};
|
|
1459
|
-
const orderByZodType = _optionalChain([columns, 'access',
|
|
1459
|
+
const orderByZodType = _optionalChain([columns, 'access', _65 => _65.find, 'call', _66 => _66(
|
|
1460
1460
|
(col) => col.name === "orderBy"
|
|
1461
|
-
), 'optionalAccess',
|
|
1461
|
+
), 'optionalAccess', _67 => _67.zodType]);
|
|
1462
1462
|
if (orderByZodType && orderByZodType instanceof _zod.z.ZodEnum) {
|
|
1463
1463
|
def.orderBy = Object.keys(orderByZodType.Enum)[0];
|
|
1464
1464
|
}
|
|
1465
|
-
const searchZodType = _optionalChain([columns, 'access',
|
|
1465
|
+
const searchZodType = _optionalChain([columns, 'access', _68 => _68.find, 'call', _69 => _69((col) => col.name === "search"), 'optionalAccess', _70 => _70.zodType]);
|
|
1466
1466
|
if (searchZodType && searchZodType instanceof _zod.z.ZodEnum) {
|
|
1467
1467
|
def.search = Object.keys(searchZodType.Enum)[0];
|
|
1468
1468
|
}
|
|
@@ -1475,7 +1475,7 @@ var Template__view_list = class extends Template {
|
|
|
1475
1475
|
const propCandidate = entity.props.find((p) => p.name === col.name);
|
|
1476
1476
|
return {
|
|
1477
1477
|
name: col.name,
|
|
1478
|
-
label: _nullishCoalesce(_optionalChain([propCandidate, 'optionalAccess',
|
|
1478
|
+
label: _nullishCoalesce(_optionalChain([propCandidate, 'optionalAccess', _71 => _71.desc]), () => ( col.label)),
|
|
1479
1479
|
tc: `(row) => ${this.renderColumn(entityId, col, names)}`
|
|
1480
1480
|
};
|
|
1481
1481
|
});
|
|
@@ -1814,7 +1814,7 @@ var Template__model = class extends Template {
|
|
|
1814
1814
|
const names = EntityManager.getNamesFromId(entityId);
|
|
1815
1815
|
const entity = EntityManager.get(entityId);
|
|
1816
1816
|
const vlTpl = new Template__view_list();
|
|
1817
|
-
if (_optionalChain([listParamsNode, 'optionalAccess',
|
|
1817
|
+
if (_optionalChain([listParamsNode, 'optionalAccess', _72 => _72.children]) === void 0) {
|
|
1818
1818
|
throw new Error(`listParamsNode\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4. ${entityId}`);
|
|
1819
1819
|
}
|
|
1820
1820
|
const def = vlTpl.getDefault(listParamsNode.children);
|
|
@@ -2328,7 +2328,7 @@ var Template__view_form = class extends Template {
|
|
|
2328
2328
|
const propCandidate = entity.props.find(
|
|
2329
2329
|
(prop) => prop.name === col.name
|
|
2330
2330
|
);
|
|
2331
|
-
col.label = _nullishCoalesce(_optionalChain([propCandidate, 'optionalAccess',
|
|
2331
|
+
col.label = _nullishCoalesce(_optionalChain([propCandidate, 'optionalAccess', _73 => _73.desc]), () => ( col.label));
|
|
2332
2332
|
return col;
|
|
2333
2333
|
});
|
|
2334
2334
|
const defaultValue = this.resolveDefaultValue(columns);
|
|
@@ -3123,7 +3123,7 @@ var Syncer = class {
|
|
|
3123
3123
|
name: name.escapedText ? name.escapedText.toString() : `nonameAt${index}`,
|
|
3124
3124
|
type,
|
|
3125
3125
|
optional: paramDec.optional === true,
|
|
3126
|
-
defaultDef: _optionalChain([paramDec, 'optionalAccess',
|
|
3126
|
+
defaultDef: _optionalChain([paramDec, 'optionalAccess', _74 => _74.defaultDef])
|
|
3127
3127
|
};
|
|
3128
3128
|
};
|
|
3129
3129
|
}
|
|
@@ -3431,7 +3431,7 @@ var Syncer = class {
|
|
|
3431
3431
|
return extendedApis;
|
|
3432
3432
|
}
|
|
3433
3433
|
resolveTypeNode(typeNode) {
|
|
3434
|
-
switch (_optionalChain([typeNode, 'optionalAccess',
|
|
3434
|
+
switch (_optionalChain([typeNode, 'optionalAccess', _75 => _75.kind])) {
|
|
3435
3435
|
case _typescript2.default.SyntaxKind.AnyKeyword:
|
|
3436
3436
|
return "any";
|
|
3437
3437
|
case _typescript2.default.SyntaxKind.UnknownKeyword:
|
|
@@ -3507,7 +3507,7 @@ var Syncer = class {
|
|
|
3507
3507
|
return {
|
|
3508
3508
|
t: "ref",
|
|
3509
3509
|
id: typeNode.typeName.escapedText.toString(),
|
|
3510
|
-
args: _optionalChain([typeNode, 'access',
|
|
3510
|
+
args: _optionalChain([typeNode, 'access', _76 => _76.typeArguments, 'optionalAccess', _77 => _77.map, 'call', _78 => _78(
|
|
3511
3511
|
(typeArg) => this.resolveTypeNode(typeArg)
|
|
3512
3512
|
)])
|
|
3513
3513
|
};
|
|
@@ -3812,36 +3812,30 @@ var Syncer = class {
|
|
|
3812
3812
|
const enumsKeys = Object.keys(enums).filter(
|
|
3813
3813
|
(name) => name !== names.constant
|
|
3814
3814
|
);
|
|
3815
|
-
return keys.reduce(
|
|
3816
|
-
(
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
result[`${key}__${componentId}`] = _fsextra2.default.existsSync(
|
|
3825
|
-
_path2.default.join(Sonamu.appRootPath, target2, p2)
|
|
3826
|
-
);
|
|
3827
|
-
});
|
|
3828
|
-
return result;
|
|
3829
|
-
}
|
|
3830
|
-
const { target, path: p } = tpl.getTargetAndPath(names);
|
|
3831
|
-
const { targets } = Sonamu.config.sync;
|
|
3832
|
-
if (target.includes(":target")) {
|
|
3833
|
-
targets.map((t) => {
|
|
3834
|
-
result[`${key}__${t}`] = _fsextra2.default.existsSync(
|
|
3835
|
-
_path2.default.join(Sonamu.appRootPath, target.replace(":target", t), p)
|
|
3836
|
-
);
|
|
3837
|
-
});
|
|
3838
|
-
} else {
|
|
3839
|
-
result[key] = _fsextra2.default.existsSync(_path2.default.join(Sonamu.appRootPath, target, p));
|
|
3840
|
-
}
|
|
3815
|
+
return keys.reduce((result, key) => {
|
|
3816
|
+
const tpl = this.getTemplate(key);
|
|
3817
|
+
if (key.startsWith("view_enums")) {
|
|
3818
|
+
enumsKeys.map((componentId) => {
|
|
3819
|
+
const { target: target2, path: p2 } = tpl.getTargetAndPath(names, componentId);
|
|
3820
|
+
result[`${key}__${componentId}`] = _fsextra2.default.existsSync(
|
|
3821
|
+
_path2.default.join(Sonamu.appRootPath, target2, p2)
|
|
3822
|
+
);
|
|
3823
|
+
});
|
|
3841
3824
|
return result;
|
|
3842
|
-
}
|
|
3843
|
-
{}
|
|
3844
|
-
|
|
3825
|
+
}
|
|
3826
|
+
const { target, path: p } = tpl.getTargetAndPath(names);
|
|
3827
|
+
const { targets } = Sonamu.config.sync;
|
|
3828
|
+
if (target.includes(":target")) {
|
|
3829
|
+
targets.map((t) => {
|
|
3830
|
+
result[`${key}__${t}`] = _fsextra2.default.existsSync(
|
|
3831
|
+
_path2.default.join(Sonamu.appRootPath, target.replace(":target", t), p)
|
|
3832
|
+
);
|
|
3833
|
+
});
|
|
3834
|
+
} else {
|
|
3835
|
+
result[key] = _fsextra2.default.existsSync(_path2.default.join(Sonamu.appRootPath, target, p));
|
|
3836
|
+
}
|
|
3837
|
+
return result;
|
|
3838
|
+
}, {});
|
|
3845
3839
|
}
|
|
3846
3840
|
async getZodTypeById(zodTypeId) {
|
|
3847
3841
|
const modulePath = EntityManager.getModulePath(zodTypeId);
|
|
@@ -3881,12 +3875,14 @@ var Syncer = class {
|
|
|
3881
3875
|
const obj = await propNode.children.reduce(
|
|
3882
3876
|
async (promise, childPropNode) => {
|
|
3883
3877
|
const result = await promise;
|
|
3884
|
-
result[childPropNode.prop.name] = await this.propNodeToZodType(
|
|
3878
|
+
result[childPropNode.prop.name] = await this.propNodeToZodType(
|
|
3879
|
+
childPropNode
|
|
3880
|
+
);
|
|
3885
3881
|
return result;
|
|
3886
3882
|
},
|
|
3887
3883
|
{}
|
|
3888
3884
|
);
|
|
3889
|
-
if (_optionalChain([propNode, 'access',
|
|
3885
|
+
if (_optionalChain([propNode, 'access', _79 => _79.prop, 'optionalAccess', _80 => _80.nullable]) === true) {
|
|
3890
3886
|
return _zod.z.object(obj).nullable();
|
|
3891
3887
|
} else {
|
|
3892
3888
|
return _zod.z.object(obj);
|
|
@@ -4083,21 +4079,16 @@ var Syncer = class {
|
|
|
4083
4079
|
});
|
|
4084
4080
|
return columnsNode;
|
|
4085
4081
|
}
|
|
4086
|
-
async createEntity(
|
|
4087
|
-
if (!/^[A-Z][a-zA-Z0-9]*$/.test(entityId)) {
|
|
4082
|
+
async createEntity(form) {
|
|
4083
|
+
if (!/^[A-Z][a-zA-Z0-9]*$/.test(form.entityId)) {
|
|
4088
4084
|
throw new BadRequestException("entityId\uB294 CamelCase \uD615\uC2DD\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4.");
|
|
4089
4085
|
}
|
|
4090
|
-
await this.generateTemplate("entity",
|
|
4091
|
-
entityId,
|
|
4092
|
-
parentId,
|
|
4093
|
-
table,
|
|
4094
|
-
title
|
|
4095
|
-
});
|
|
4086
|
+
await this.generateTemplate("entity", form);
|
|
4096
4087
|
await EntityManager.reload();
|
|
4097
4088
|
await this.actionGenerateSchemas();
|
|
4098
|
-
if (parentId === void 0) {
|
|
4089
|
+
if (form.parentId === void 0) {
|
|
4099
4090
|
await this.generateTemplate("init_types", {
|
|
4100
|
-
entityId
|
|
4091
|
+
entityId: form.entityId
|
|
4101
4092
|
});
|
|
4102
4093
|
}
|
|
4103
4094
|
}
|
|
@@ -4302,7 +4293,7 @@ var UpsertBuilder = class {
|
|
|
4302
4293
|
this.tables.set(tableName, {
|
|
4303
4294
|
references: /* @__PURE__ */ new Set(),
|
|
4304
4295
|
rows: [],
|
|
4305
|
-
uniqueIndexes: _nullishCoalesce(_optionalChain([tableSpec, 'optionalAccess',
|
|
4296
|
+
uniqueIndexes: _nullishCoalesce(_optionalChain([tableSpec, 'optionalAccess', _81 => _81.uniqueIndexes]), () => ( [])),
|
|
4306
4297
|
uniquesMap: /* @__PURE__ */ new Map()
|
|
4307
4298
|
});
|
|
4308
4299
|
}
|
|
@@ -4716,7 +4707,7 @@ var BaseModelClass = class {
|
|
|
4716
4707
|
_chalk2.default.blue(countQuery.toQuery().toString())
|
|
4717
4708
|
);
|
|
4718
4709
|
}
|
|
4719
|
-
return _nullishCoalesce(_optionalChain([countRow, 'optionalAccess',
|
|
4710
|
+
return _nullishCoalesce(_optionalChain([countRow, 'optionalAccess', _82 => _82.total]), () => ( 0));
|
|
4720
4711
|
})();
|
|
4721
4712
|
const rows = await (async () => {
|
|
4722
4713
|
if (queryMode === "count") {
|
|
@@ -4969,8 +4960,125 @@ var SonamuClass = class {
|
|
|
4969
4960
|
};
|
|
4970
4961
|
var Sonamu = new SonamuClass();
|
|
4971
4962
|
|
|
4963
|
+
// src/entity/entity-manager.ts
|
|
4964
|
+
|
|
4965
|
+
var EntityManagerClass = class {
|
|
4966
|
+
constructor() {
|
|
4967
|
+
this.entities = /* @__PURE__ */ new Map();
|
|
4968
|
+
this.modulePaths = /* @__PURE__ */ new Map();
|
|
4969
|
+
this.tableSpecs = /* @__PURE__ */ new Map();
|
|
4970
|
+
this.isAutoloaded = false;
|
|
4971
|
+
}
|
|
4972
|
+
// 경로 전달받아 모든 entity.json 파일 로드
|
|
4973
|
+
async autoload(doSilent = false) {
|
|
4974
|
+
if (this.isAutoloaded) {
|
|
4975
|
+
return;
|
|
4976
|
+
}
|
|
4977
|
+
const pathPattern = _path2.default.join(
|
|
4978
|
+
Sonamu.apiRootPath,
|
|
4979
|
+
"/src/application/**/*.entity.json"
|
|
4980
|
+
);
|
|
4981
|
+
!doSilent && console.log(_chalk2.default.yellow(`autoload ${pathPattern}`));
|
|
4982
|
+
return new Promise((resolve) => {
|
|
4983
|
+
_glob2.default.glob(_path2.default.resolve(pathPattern), (_err, files) => {
|
|
4984
|
+
Promise.all(
|
|
4985
|
+
files.map(async (file) => {
|
|
4986
|
+
this.register(JSON.parse(_fsextra2.default.readFileSync(file).toString()));
|
|
4987
|
+
})
|
|
4988
|
+
).then(() => {
|
|
4989
|
+
resolve("ok");
|
|
4990
|
+
this.isAutoloaded = true;
|
|
4991
|
+
});
|
|
4992
|
+
});
|
|
4993
|
+
});
|
|
4994
|
+
}
|
|
4995
|
+
async reload(doSilent = false) {
|
|
4996
|
+
console.log("reload");
|
|
4997
|
+
this.entities.clear();
|
|
4998
|
+
this.modulePaths.clear();
|
|
4999
|
+
this.tableSpecs.clear();
|
|
5000
|
+
this.isAutoloaded = false;
|
|
5001
|
+
const sonamuPath = _path2.default.join(
|
|
5002
|
+
Sonamu.apiRootPath,
|
|
5003
|
+
"dist/application/sonamu.generated.js"
|
|
5004
|
+
);
|
|
5005
|
+
if (__require.cache[sonamuPath]) {
|
|
5006
|
+
delete __require.cache[sonamuPath];
|
|
5007
|
+
}
|
|
5008
|
+
return this.autoload(doSilent);
|
|
5009
|
+
}
|
|
5010
|
+
register(json) {
|
|
5011
|
+
const entity = new Entity(json);
|
|
5012
|
+
this.entities.set(json.id, entity);
|
|
5013
|
+
}
|
|
5014
|
+
get(entityId) {
|
|
5015
|
+
const entity = this.entities.get(entityId);
|
|
5016
|
+
if (entity === void 0) {
|
|
5017
|
+
throw new Error(`\uC874\uC7AC\uD558\uC9C0 \uC54A\uB294 Entity \uC694\uCCAD ${entityId}`);
|
|
5018
|
+
}
|
|
5019
|
+
return entity;
|
|
5020
|
+
}
|
|
5021
|
+
exists(entityId) {
|
|
5022
|
+
const entity = this.entities.get(entityId);
|
|
5023
|
+
return entity !== void 0;
|
|
5024
|
+
}
|
|
5025
|
+
getAllIds() {
|
|
5026
|
+
return Array.from(EntityManager.entities.keys());
|
|
5027
|
+
}
|
|
5028
|
+
getAllParentIds() {
|
|
5029
|
+
return this.getAllIds().filter((entityId) => {
|
|
5030
|
+
const entity = this.get(entityId);
|
|
5031
|
+
return entity.parentId === void 0;
|
|
5032
|
+
});
|
|
5033
|
+
}
|
|
5034
|
+
getChildrenIds(parentId) {
|
|
5035
|
+
return this.getAllIds().filter((entityId) => {
|
|
5036
|
+
const entity = this.get(entityId);
|
|
5037
|
+
return entity.parentId === parentId;
|
|
5038
|
+
});
|
|
5039
|
+
}
|
|
5040
|
+
setModulePath(key, modulePath) {
|
|
5041
|
+
this.modulePaths.set(key, modulePath);
|
|
5042
|
+
}
|
|
5043
|
+
getModulePath(key) {
|
|
5044
|
+
const modulePath = this.modulePaths.get(key);
|
|
5045
|
+
if (modulePath === void 0) {
|
|
5046
|
+
throw new Error(`\uC874\uC7AC\uD558\uC9C0 \uC54A\uB294 \uBAA8\uB4C8 \uD328\uC2A4 \uC694\uCCAD ${key}`);
|
|
5047
|
+
}
|
|
5048
|
+
return modulePath;
|
|
5049
|
+
}
|
|
5050
|
+
setTableSpec(tableSpec) {
|
|
5051
|
+
this.tableSpecs.set(tableSpec.name, tableSpec);
|
|
5052
|
+
}
|
|
5053
|
+
getTableSpec(key) {
|
|
5054
|
+
const tableSpec = this.tableSpecs.get(key);
|
|
5055
|
+
if (tableSpec === void 0) {
|
|
5056
|
+
throw new Error(`\uC874\uC7AC\uD558\uC9C0 \uC54A\uB294 \uD14C\uC774\uBE14 \uC2A4\uD399 \uC694\uCCAD ${key}`);
|
|
5057
|
+
}
|
|
5058
|
+
return tableSpec;
|
|
5059
|
+
}
|
|
5060
|
+
getNamesFromId(entityId) {
|
|
5061
|
+
const pluralized = _inflection2.default.pluralize(entityId) === entityId ? `${entityId}List` : _inflection2.default.pluralize(entityId);
|
|
5062
|
+
return {
|
|
5063
|
+
fs: _inflection2.default.dasherize(_inflection2.default.underscore(entityId)).toLowerCase(),
|
|
5064
|
+
fsPlural: _inflection2.default.dasherize(_inflection2.default.underscore(pluralized)).toLowerCase(),
|
|
5065
|
+
camel: _inflection2.default.camelize(entityId, true),
|
|
5066
|
+
camelPlural: _inflection2.default.camelize(pluralized, true),
|
|
5067
|
+
capital: entityId,
|
|
5068
|
+
capitalPlural: pluralized,
|
|
5069
|
+
upper: entityId.toUpperCase(),
|
|
5070
|
+
constant: _inflection2.default.underscore(entityId).toUpperCase()
|
|
5071
|
+
};
|
|
5072
|
+
}
|
|
5073
|
+
};
|
|
5074
|
+
var EntityManager = new EntityManagerClass();
|
|
5075
|
+
|
|
4972
5076
|
// src/entity/entity.ts
|
|
4973
5077
|
|
|
5078
|
+
|
|
5079
|
+
|
|
5080
|
+
|
|
5081
|
+
|
|
4974
5082
|
var Entity = class {
|
|
4975
5083
|
constructor({
|
|
4976
5084
|
id,
|
|
@@ -5180,7 +5288,7 @@ var Entity = class {
|
|
|
5180
5288
|
const relSubsetQuery = relEntity.resolveSubsetQuery("", relFields);
|
|
5181
5289
|
let manyJoin;
|
|
5182
5290
|
if (isHasManyRelationProp(relation)) {
|
|
5183
|
-
const fromCol = _nullishCoalesce(_optionalChain([relation, 'optionalAccess',
|
|
5291
|
+
const fromCol = _nullishCoalesce(_optionalChain([relation, 'optionalAccess', _83 => _83.fromColumn]), () => ( "id"));
|
|
5184
5292
|
manyJoin = {
|
|
5185
5293
|
fromTable: this.table,
|
|
5186
5294
|
fromCol,
|
|
@@ -5577,6 +5685,9 @@ var Entity = class {
|
|
|
5577
5685
|
}
|
|
5578
5686
|
}
|
|
5579
5687
|
}
|
|
5688
|
+
EntityManager.get(this.id).indexes.map((index) => {
|
|
5689
|
+
index.columns = index.columns.filter((col) => col !== oldName);
|
|
5690
|
+
});
|
|
5580
5691
|
this.props.splice(at, 1);
|
|
5581
5692
|
await Promise.all(entities.map(async (entity) => entity.save()));
|
|
5582
5693
|
}
|
|
@@ -5607,119 +5718,6 @@ var Entity = class {
|
|
|
5607
5718
|
}
|
|
5608
5719
|
};
|
|
5609
5720
|
|
|
5610
|
-
// src/entity/entity-manager.ts
|
|
5611
|
-
|
|
5612
|
-
var EntityManagerClass = class {
|
|
5613
|
-
constructor() {
|
|
5614
|
-
this.entities = /* @__PURE__ */ new Map();
|
|
5615
|
-
this.modulePaths = /* @__PURE__ */ new Map();
|
|
5616
|
-
this.tableSpecs = /* @__PURE__ */ new Map();
|
|
5617
|
-
this.isAutoloaded = false;
|
|
5618
|
-
}
|
|
5619
|
-
// 경로 전달받아 모든 entity.json 파일 로드
|
|
5620
|
-
async autoload(doSilent = false) {
|
|
5621
|
-
if (this.isAutoloaded) {
|
|
5622
|
-
return;
|
|
5623
|
-
}
|
|
5624
|
-
const pathPattern = _path2.default.join(
|
|
5625
|
-
Sonamu.apiRootPath,
|
|
5626
|
-
"/src/application/**/*.entity.json"
|
|
5627
|
-
);
|
|
5628
|
-
!doSilent && console.log(_chalk2.default.yellow(`autoload ${pathPattern}`));
|
|
5629
|
-
return new Promise((resolve) => {
|
|
5630
|
-
_glob2.default.glob(_path2.default.resolve(pathPattern), (_err, files) => {
|
|
5631
|
-
Promise.all(
|
|
5632
|
-
files.map(async (file) => {
|
|
5633
|
-
this.register(JSON.parse(_fsextra2.default.readFileSync(file).toString()));
|
|
5634
|
-
})
|
|
5635
|
-
).then(() => {
|
|
5636
|
-
resolve("ok");
|
|
5637
|
-
this.isAutoloaded = true;
|
|
5638
|
-
});
|
|
5639
|
-
});
|
|
5640
|
-
});
|
|
5641
|
-
}
|
|
5642
|
-
async reload(doSilent = false) {
|
|
5643
|
-
console.log("reload");
|
|
5644
|
-
this.entities.clear();
|
|
5645
|
-
this.modulePaths.clear();
|
|
5646
|
-
this.tableSpecs.clear();
|
|
5647
|
-
this.isAutoloaded = false;
|
|
5648
|
-
const sonamuPath = _path2.default.join(
|
|
5649
|
-
Sonamu.apiRootPath,
|
|
5650
|
-
"dist/application/sonamu.generated.js"
|
|
5651
|
-
);
|
|
5652
|
-
if (__require.cache[sonamuPath]) {
|
|
5653
|
-
delete __require.cache[sonamuPath];
|
|
5654
|
-
}
|
|
5655
|
-
return this.autoload(doSilent);
|
|
5656
|
-
}
|
|
5657
|
-
register(json) {
|
|
5658
|
-
const entity = new Entity(json);
|
|
5659
|
-
this.entities.set(json.id, entity);
|
|
5660
|
-
}
|
|
5661
|
-
get(entityId) {
|
|
5662
|
-
const entity = this.entities.get(entityId);
|
|
5663
|
-
if (entity === void 0) {
|
|
5664
|
-
throw new Error(`\uC874\uC7AC\uD558\uC9C0 \uC54A\uB294 Entity \uC694\uCCAD ${entityId}`);
|
|
5665
|
-
}
|
|
5666
|
-
return entity;
|
|
5667
|
-
}
|
|
5668
|
-
exists(entityId) {
|
|
5669
|
-
const entity = this.entities.get(entityId);
|
|
5670
|
-
return entity !== void 0;
|
|
5671
|
-
}
|
|
5672
|
-
getAllIds() {
|
|
5673
|
-
return Array.from(EntityManager.entities.keys());
|
|
5674
|
-
}
|
|
5675
|
-
getAllParentIds() {
|
|
5676
|
-
return this.getAllIds().filter((entityId) => {
|
|
5677
|
-
const entity = this.get(entityId);
|
|
5678
|
-
return entity.parentId === void 0;
|
|
5679
|
-
});
|
|
5680
|
-
}
|
|
5681
|
-
getChildrenIds(parentId) {
|
|
5682
|
-
return this.getAllIds().filter((entityId) => {
|
|
5683
|
-
const entity = this.get(entityId);
|
|
5684
|
-
return entity.parentId === parentId;
|
|
5685
|
-
});
|
|
5686
|
-
}
|
|
5687
|
-
setModulePath(key, modulePath) {
|
|
5688
|
-
this.modulePaths.set(key, modulePath);
|
|
5689
|
-
}
|
|
5690
|
-
getModulePath(key) {
|
|
5691
|
-
const modulePath = this.modulePaths.get(key);
|
|
5692
|
-
if (modulePath === void 0) {
|
|
5693
|
-
throw new Error(`\uC874\uC7AC\uD558\uC9C0 \uC54A\uB294 \uBAA8\uB4C8 \uD328\uC2A4 \uC694\uCCAD ${key}`);
|
|
5694
|
-
}
|
|
5695
|
-
return modulePath;
|
|
5696
|
-
}
|
|
5697
|
-
setTableSpec(tableSpec) {
|
|
5698
|
-
this.tableSpecs.set(tableSpec.name, tableSpec);
|
|
5699
|
-
}
|
|
5700
|
-
getTableSpec(key) {
|
|
5701
|
-
const tableSpec = this.tableSpecs.get(key);
|
|
5702
|
-
if (tableSpec === void 0) {
|
|
5703
|
-
throw new Error(`\uC874\uC7AC\uD558\uC9C0 \uC54A\uB294 \uD14C\uC774\uBE14 \uC2A4\uD399 \uC694\uCCAD ${key}`);
|
|
5704
|
-
}
|
|
5705
|
-
return tableSpec;
|
|
5706
|
-
}
|
|
5707
|
-
getNamesFromId(entityId) {
|
|
5708
|
-
const pluralized = _inflection2.default.pluralize(entityId) === entityId ? `${entityId}List` : _inflection2.default.pluralize(entityId);
|
|
5709
|
-
return {
|
|
5710
|
-
fs: _inflection2.default.dasherize(_inflection2.default.underscore(entityId)).toLowerCase(),
|
|
5711
|
-
fsPlural: _inflection2.default.dasherize(_inflection2.default.underscore(pluralized)).toLowerCase(),
|
|
5712
|
-
camel: _inflection2.default.camelize(entityId, true),
|
|
5713
|
-
camelPlural: _inflection2.default.camelize(pluralized, true),
|
|
5714
|
-
capital: entityId,
|
|
5715
|
-
capitalPlural: pluralized,
|
|
5716
|
-
upper: entityId.toUpperCase(),
|
|
5717
|
-
constant: _inflection2.default.underscore(entityId).toUpperCase()
|
|
5718
|
-
};
|
|
5719
|
-
}
|
|
5720
|
-
};
|
|
5721
|
-
var EntityManager = new EntityManagerClass();
|
|
5722
|
-
|
|
5723
5721
|
// src/entity/migrator.ts
|
|
5724
5722
|
|
|
5725
5723
|
|
|
@@ -6495,7 +6493,7 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
6495
6493
|
const [, keyName, from, referencesTable, referencesField, onClause] = matched2;
|
|
6496
6494
|
const [onUpdateFull, _onUpdate] = _nullishCoalesce((_nullishCoalesce(onClause, () => ( ""))).match(/ON UPDATE ([A-Z ]+)$/), () => ( []));
|
|
6497
6495
|
const onUpdate = _nullishCoalesce(_onUpdate, () => ( "NO ACTION"));
|
|
6498
|
-
const onDelete = _nullishCoalesce(_optionalChain([(_nullishCoalesce(onClause, () => ( ""))), 'access',
|
|
6496
|
+
const onDelete = _nullishCoalesce(_optionalChain([(_nullishCoalesce(onClause, () => ( ""))), 'access', _84 => _84.replace, 'call', _85 => _85(_nullishCoalesce(onUpdateFull, () => ( "")), ""), 'access', _86 => _86.match, 'call', _87 => _87(/ON DELETE ([A-Z ]+) /), 'optionalAccess', _88 => _88[1]]), () => ( "NO ACTION"));
|
|
6499
6497
|
return {
|
|
6500
6498
|
keyName,
|
|
6501
6499
|
from,
|
|
@@ -7443,5 +7441,6 @@ var FixtureManager = new FixtureManagerClass();
|
|
|
7443
7441
|
|
|
7444
7442
|
|
|
7445
7443
|
|
|
7446
|
-
|
|
7447
|
-
|
|
7444
|
+
|
|
7445
|
+
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;
|
|
7446
|
+
//# sourceMappingURL=chunk-5VT5JTY4.js.map
|