sonamu 0.2.53 → 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.
@@ -356,6 +356,19 @@ function getZodTypeFromApiParamType(paramType, references) {
356
356
  return reference;
357
357
  case "union":
358
358
  const unionType = paramType;
359
+ if (unionType.types.length === 2 && unionType.types.some((type) => type === "null")) {
360
+ if (unionType.types[0] === "null") {
361
+ return getZodTypeFromApiParamType(
362
+ unionType.types[1],
363
+ references
364
+ ).nullable();
365
+ } else {
366
+ return getZodTypeFromApiParamType(
367
+ unionType.types[0],
368
+ references
369
+ ).nullable();
370
+ }
371
+ }
359
372
  return _zod.z.union(
360
373
  unionType.types.map(
361
374
  (type) => getZodTypeFromApiParamType(type, references)
@@ -3121,7 +3134,7 @@ var Syncer = class {
3121
3134
  const name = paramDec.name;
3122
3135
  const type = this.resolveTypeNode(paramDec.type);
3123
3136
  if (name === void 0) {
3124
- console.log({ name, type, paramDec });
3137
+ console.debug({ name, type, paramDec });
3125
3138
  }
3126
3139
  return {
3127
3140
  name: name.escapedText ? name.escapedText.toString() : `nonameAt${index}`,
@@ -3340,7 +3353,7 @@ var Syncer = class {
3340
3353
  await _fsextra2.default.writeJSON(this.checksumsPath, checksums, {
3341
3354
  spaces: 2
3342
3355
  });
3343
- console.debug("checksum saved", this.checksumsPath);
3356
+ console.log("checksum saved", this.checksumsPath);
3344
3357
  }
3345
3358
  async getChecksumOfFile(filePath) {
3346
3359
  return new Promise((resolve, reject) => {
@@ -3816,30 +3829,36 @@ var Syncer = class {
3816
3829
  const enumsKeys = Object.keys(enums).filter(
3817
3830
  (name) => name !== names.constant
3818
3831
  );
3819
- return keys.reduce((result, key) => {
3820
- const tpl = this.getTemplate(key);
3821
- if (key.startsWith("view_enums")) {
3822
- enumsKeys.map((componentId) => {
3823
- const { target: target2, path: p2 } = tpl.getTargetAndPath(names, componentId);
3824
- result[`${key}__${componentId}`] = _fsextra2.default.existsSync(
3825
- _path2.default.join(Sonamu.appRootPath, target2, p2)
3826
- );
3827
- });
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
+ }
3828
3858
  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
- }
3841
- return result;
3842
- }, {});
3859
+ },
3860
+ {}
3861
+ );
3843
3862
  }
3844
3863
  async getZodTypeById(zodTypeId) {
3845
3864
  const modulePath = EntityManager.getModulePath(zodTypeId);
@@ -3879,9 +3898,7 @@ var Syncer = class {
3879
3898
  const obj = await propNode.children.reduce(
3880
3899
  async (promise, childPropNode) => {
3881
3900
  const result = await promise;
3882
- result[childPropNode.prop.name] = await this.propNodeToZodType(
3883
- childPropNode
3884
- );
3901
+ result[childPropNode.prop.name] = await this.propNodeToZodType(childPropNode);
3885
3902
  return result;
3886
3903
  },
3887
3904
  {}
@@ -5008,7 +5025,7 @@ var EntityManagerClass = class {
5008
5025
  _glob2.default.glob(_path2.default.resolve(pathPattern), (_err, files) => {
5009
5026
  Promise.all(
5010
5027
  files.map(async (file) => {
5011
- this.register(JSON.parse(_fsextra2.default.readFileSync(file).toString()));
5028
+ await this.register(JSON.parse(_fsextra2.default.readFileSync(file).toString()));
5012
5029
  })
5013
5030
  ).then(() => {
5014
5031
  resolve("ok");
@@ -5025,15 +5042,17 @@ var EntityManagerClass = class {
5025
5042
  this.isAutoloaded = false;
5026
5043
  const sonamuPath = _path2.default.join(
5027
5044
  Sonamu.apiRootPath,
5028
- "dist/application/sonamu.generated.js"
5045
+ `dist/application/sonamu.generated.js?t=${Date.now()}`
5029
5046
  );
5030
- if (__require.cache[sonamuPath]) {
5047
+ if (_optionalChain([__require, 'optionalAccess', _87 => _87.cache]) && __require.cache[sonamuPath]) {
5031
5048
  delete __require.cache[sonamuPath];
5032
5049
  }
5033
- return this.autoload(doSilent);
5050
+ return await this.autoload(doSilent);
5034
5051
  }
5035
- register(json) {
5052
+ async register(json) {
5036
5053
  const entity = new Entity(json);
5054
+ await entity.registerModulePaths();
5055
+ entity.registerTableSpecs();
5037
5056
  this.entities.set(json.id, entity);
5038
5057
  }
5039
5058
  get(entityId) {
@@ -5166,8 +5185,6 @@ var Entity = class {
5166
5185
  fs: _inflection2.default.dasherize(_inflection2.default.underscore(id)).toLowerCase(),
5167
5186
  module: id
5168
5187
  };
5169
- this.registerModulePaths();
5170
- this.registerTableSpecs();
5171
5188
  }
5172
5189
  /*
5173
5190
  subset SELECT/JOIN/LOADER 결과 리턴
@@ -5313,7 +5330,7 @@ var Entity = class {
5313
5330
  const relSubsetQuery = relEntity.resolveSubsetQuery("", relFields);
5314
5331
  let manyJoin;
5315
5332
  if (isHasManyRelationProp(relation)) {
5316
- const fromCol = _nullishCoalesce(_optionalChain([relation, 'optionalAccess', _87 => _87.fromColumn]), () => ( "id"));
5333
+ const fromCol = _nullishCoalesce(_optionalChain([relation, 'optionalAccess', _88 => _88.fromColumn]), () => ( "id"));
5317
5334
  manyJoin = {
5318
5335
  fromTable: this.table,
5319
5336
  fromCol,
@@ -5485,7 +5502,7 @@ var Entity = class {
5485
5502
  return prop.name;
5486
5503
  }).filter(nonNullable);
5487
5504
  }
5488
- registerModulePaths() {
5505
+ async registerModulePaths() {
5489
5506
  const basePath = `${this.names.parentFs}`;
5490
5507
  EntityManager.setModulePath(`${this.id}BaseSchema`, `sonamu.generated`);
5491
5508
  if (Object.keys(this.subsets).length > 0) {
@@ -5511,15 +5528,14 @@ var Entity = class {
5511
5528
  );
5512
5529
  if (_fsextra2.default.existsSync(typesFileDistPath)) {
5513
5530
  const importPath = _path2.default.relative(__dirname, typesFileDistPath);
5514
- Promise.resolve().then(() => _interopRequireWildcard(require(importPath))).then((t) => {
5515
- this.types = Object.keys(t).reduce((result, key) => {
5516
- EntityManager.setModulePath(key, typesModulePath);
5517
- return {
5518
- ...result,
5519
- [key]: t[key]
5520
- };
5521
- }, {});
5522
- });
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
+ }, {});
5523
5539
  }
5524
5540
  }
5525
5541
  registerTableSpecs() {
@@ -6518,7 +6534,7 @@ ${onlyTs.map((f) => f.name).join("\n")}`
6518
6534
  const [, keyName, from, referencesTable, referencesField, onClause] = matched2;
6519
6535
  const [onUpdateFull, _onUpdate] = _nullishCoalesce((_nullishCoalesce(onClause, () => ( ""))).match(/ON UPDATE ([A-Z ]+)$/), () => ( []));
6520
6536
  const onUpdate = _nullishCoalesce(_onUpdate, () => ( "NO ACTION"));
6521
- const onDelete = _nullishCoalesce(_optionalChain([(_nullishCoalesce(onClause, () => ( ""))), 'access', _88 => _88.replace, 'call', _89 => _89(_nullishCoalesce(onUpdateFull, () => ( "")), ""), 'access', _90 => _90.match, 'call', _91 => _91(/ON DELETE ([A-Z ]+) /), 'optionalAccess', _92 => _92[1]]), () => ( "NO ACTION"));
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"));
6522
6538
  return {
6523
6539
  keyName,
6524
6540
  from,
@@ -7393,7 +7409,7 @@ var FixtureManagerClass = class {
7393
7409
  const targetDB = _knex2.default.call(void 0, Sonamu.dbConfig[targetDBName]);
7394
7410
  const { entityId, field, value, searchType } = searchOptions;
7395
7411
  const entity = EntityManager.get(entityId);
7396
- const column = _optionalChain([entity, 'access', _93 => _93.props, 'access', _94 => _94.find, 'call', _95 => _95((prop) => prop.name === field), 'optionalAccess', _96 => _96.type]) === "relation" ? `${field}_id` : field;
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;
7397
7413
  let query = sourceDB(entity.table);
7398
7414
  if (searchType === "equals") {
7399
7415
  query = query.where(column, value);
@@ -7465,7 +7481,7 @@ var FixtureManagerClass = class {
7465
7481
  prop,
7466
7482
  value: row[prop.name]
7467
7483
  };
7468
- const db = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _97 => _97._db]), () => ( BaseModel.getDB("w")));
7484
+ const db = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _98 => _98._db]), () => ( BaseModel.getDB("w")));
7469
7485
  if (isManyToManyRelationProp(prop)) {
7470
7486
  const relatedEntity = EntityManager.get(prop.with);
7471
7487
  const throughTable = prop.joinTable;
@@ -7484,7 +7500,7 @@ var FixtureManagerClass = class {
7484
7500
  );
7485
7501
  if (relatedProp) {
7486
7502
  const relatedRow = await db(relatedEntity.table).where("id", row.id).first();
7487
- record.columns[prop.name].value = _optionalChain([relatedRow, 'optionalAccess', _98 => _98.id]);
7503
+ record.columns[prop.name].value = _optionalChain([relatedRow, 'optionalAccess', _99 => _99.id]);
7488
7504
  }
7489
7505
  } else if (isRelationProp(prop)) {
7490
7506
  const relatedId = row[`${prop.name}_id`];
@@ -7492,7 +7508,7 @@ var FixtureManagerClass = class {
7492
7508
  if (relatedId) {
7493
7509
  record.belongsRecords.push(`${prop.with}#${relatedId}`);
7494
7510
  }
7495
- if (!_optionalChain([options, 'optionalAccess', _99 => _99.singleRecord]) && relatedId) {
7511
+ if (!_optionalChain([options, 'optionalAccess', _100 => _100.singleRecord]) && relatedId) {
7496
7512
  const relatedEntity = EntityManager.get(prop.with);
7497
7513
  const relatedRow = await db(relatedEntity.table).where("id", relatedId).first();
7498
7514
  if (relatedRow) {
@@ -7832,4 +7848,4 @@ var FixtureManager = new FixtureManagerClass();
7832
7848
 
7833
7849
 
7834
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;
7835
- //# sourceMappingURL=chunk-5UCV2JP3.js.map
7851
+ //# sourceMappingURL=chunk-YXILRRDT.js.map