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
package/dist/index.d.mts
CHANGED
|
@@ -862,7 +862,7 @@ declare class Entity {
|
|
|
862
862
|
fieldExprsToPropNodes(fieldExprs: string[], entity?: Entity): EntityPropNode[];
|
|
863
863
|
getFieldExprs(prefix?: string, maxDepth?: number, froms?: string[]): string[];
|
|
864
864
|
getTableColumns(): string[];
|
|
865
|
-
registerModulePaths(): void
|
|
865
|
+
registerModulePaths(): Promise<void>;
|
|
866
866
|
registerTableSpecs(): void;
|
|
867
867
|
toJson(): EntityJson;
|
|
868
868
|
save(): Promise<void>;
|
|
@@ -896,7 +896,7 @@ declare class EntityManagerClass {
|
|
|
896
896
|
isAutoloaded: boolean;
|
|
897
897
|
autoload(doSilent?: boolean): Promise<unknown>;
|
|
898
898
|
reload(doSilent?: boolean): Promise<unknown>;
|
|
899
|
-
register(json: EntityJson): void
|
|
899
|
+
register(json: EntityJson): Promise<void>;
|
|
900
900
|
get(entityId: string): Entity;
|
|
901
901
|
exists(entityId: string): boolean;
|
|
902
902
|
getAllIds(): string[];
|
package/dist/index.d.ts
CHANGED
|
@@ -862,7 +862,7 @@ declare class Entity {
|
|
|
862
862
|
fieldExprsToPropNodes(fieldExprs: string[], entity?: Entity): EntityPropNode[];
|
|
863
863
|
getFieldExprs(prefix?: string, maxDepth?: number, froms?: string[]): string[];
|
|
864
864
|
getTableColumns(): string[];
|
|
865
|
-
registerModulePaths(): void
|
|
865
|
+
registerModulePaths(): Promise<void>;
|
|
866
866
|
registerTableSpecs(): void;
|
|
867
867
|
toJson(): EntityJson;
|
|
868
868
|
save(): Promise<void>;
|
|
@@ -896,7 +896,7 @@ declare class EntityManagerClass {
|
|
|
896
896
|
isAutoloaded: boolean;
|
|
897
897
|
autoload(doSilent?: boolean): Promise<unknown>;
|
|
898
898
|
reload(doSilent?: boolean): Promise<unknown>;
|
|
899
|
-
register(json: EntityJson): void
|
|
899
|
+
register(json: EntityJson): Promise<void>;
|
|
900
900
|
get(entityId: string): Entity;
|
|
901
901
|
exists(entityId: string): boolean;
|
|
902
902
|
getAllIds(): string[];
|
package/dist/index.js
CHANGED
|
@@ -80,13 +80,13 @@
|
|
|
80
80
|
|
|
81
81
|
|
|
82
82
|
|
|
83
|
-
var
|
|
83
|
+
var _chunkYXILRRDTjs = require('./chunk-YXILRRDT.js');
|
|
84
84
|
|
|
85
85
|
// src/exceptions/error-handler.ts
|
|
86
86
|
function setupErrorHandler(server) {
|
|
87
87
|
server.setErrorHandler((error, request, reply) => {
|
|
88
88
|
_nullishCoalesce(error.statusCode, () => ( (error.statusCode = 400)));
|
|
89
|
-
if (
|
|
89
|
+
if (_chunkYXILRRDTjs.isSoException.call(void 0, error) && error.payload && Array.isArray(error.payload)) {
|
|
90
90
|
const issues = error.payload;
|
|
91
91
|
const [issue] = issues;
|
|
92
92
|
const message = `${issue.message} (${issue.path.join("/")})`;
|
|
@@ -423,5 +423,5 @@ function unique(columns) {
|
|
|
423
423
|
|
|
424
424
|
|
|
425
425
|
|
|
426
|
-
exports.AlreadyProcessedException =
|
|
426
|
+
exports.AlreadyProcessedException = _chunkYXILRRDTjs.AlreadyProcessedException; exports.ApiParamType = _chunkYXILRRDTjs.ApiParamType; exports.BadRequestException = _chunkYXILRRDTjs.BadRequestException; exports.BaseModel = _chunkYXILRRDTjs.BaseModel; exports.BaseModelClass = _chunkYXILRRDTjs.BaseModelClass; exports.DB = _chunkYXILRRDTjs.DB; exports.DuplicateRowException = _chunkYXILRRDTjs.DuplicateRowException; exports.Entity = _chunkYXILRRDTjs.Entity; exports.EntityManager = _chunkYXILRRDTjs.EntityManager; exports.FixtureManager = _chunkYXILRRDTjs.FixtureManager; exports.FixtureManagerClass = _chunkYXILRRDTjs.FixtureManagerClass; exports.GenerateOptions = _chunkYXILRRDTjs.GenerateOptions; exports.InternalServerErrorException = _chunkYXILRRDTjs.InternalServerErrorException; exports.Migrator = _chunkYXILRRDTjs.Migrator; exports.NotFoundException = _chunkYXILRRDTjs.NotFoundException; exports.PathAndCode = _chunkYXILRRDTjs.PathAndCode; exports.RenderingNode = _chunkYXILRRDTjs.RenderingNode; exports.SQLDateTimeString = _chunkYXILRRDTjs.SQLDateTimeString; exports.ServiceUnavailableException = _chunkYXILRRDTjs.ServiceUnavailableException; exports.SoException = _chunkYXILRRDTjs.SoException; exports.Sonamu = _chunkYXILRRDTjs.Sonamu; exports.SonamuQueryMode = _chunkYXILRRDTjs.SonamuQueryMode; exports.Syncer = _chunkYXILRRDTjs.Syncer; exports.TargetNotFoundException = _chunkYXILRRDTjs.TargetNotFoundException; exports.TemplateKey = _chunkYXILRRDTjs.TemplateKey; exports.TemplateOptions = _chunkYXILRRDTjs.TemplateOptions; exports.UnauthorizedException = _chunkYXILRRDTjs.UnauthorizedException; exports.UpsertBuilder = _chunkYXILRRDTjs.UpsertBuilder; exports.api = _chunkYXILRRDTjs.api; exports.apiParamToTsCode = _chunkYXILRRDTjs.apiParamToTsCode; exports.apiParamTypeToTsType = _chunkYXILRRDTjs.apiParamTypeToTsType; exports.asArray = asArray; exports.findApiRootPath = _chunkYXILRRDTjs.findApiRootPath; exports.findAppRootPath = _chunkYXILRRDTjs.findAppRootPath; exports.getTextTypeLength = _chunkYXILRRDTjs.getTextTypeLength; exports.getZodObjectFromApi = _chunkYXILRRDTjs.getZodObjectFromApi; exports.getZodObjectFromApiParams = _chunkYXILRRDTjs.getZodObjectFromApiParams; exports.getZodTypeFromApiParamType = _chunkYXILRRDTjs.getZodTypeFromApiParamType; exports.globAsync = _chunkYXILRRDTjs.globAsync; exports.i = i; exports.importMultiple = _chunkYXILRRDTjs.importMultiple; exports.isBelongsToOneRelationProp = _chunkYXILRRDTjs.isBelongsToOneRelationProp; exports.isBigIntegerProp = _chunkYXILRRDTjs.isBigIntegerProp; exports.isBooleanProp = _chunkYXILRRDTjs.isBooleanProp; exports.isCustomJoinClause = _chunkYXILRRDTjs.isCustomJoinClause; exports.isDaemonServer = _chunkYXILRRDTjs.isDaemonServer; exports.isDateProp = _chunkYXILRRDTjs.isDateProp; exports.isDateTimeProp = _chunkYXILRRDTjs.isDateTimeProp; exports.isDecimalProp = _chunkYXILRRDTjs.isDecimalProp; exports.isDevelopment = _chunkYXILRRDTjs.isDevelopment; exports.isDoubleProp = _chunkYXILRRDTjs.isDoubleProp; exports.isEnumProp = _chunkYXILRRDTjs.isEnumProp; exports.isFloatProp = _chunkYXILRRDTjs.isFloatProp; exports.isHasManyRelationProp = _chunkYXILRRDTjs.isHasManyRelationProp; exports.isInDocker = _chunkYXILRRDTjs.isInDocker; exports.isIntegerProp = _chunkYXILRRDTjs.isIntegerProp; exports.isJsonProp = _chunkYXILRRDTjs.isJsonProp; exports.isKnexError = _chunkYXILRRDTjs.isKnexError; exports.isLocal = _chunkYXILRRDTjs.isLocal; exports.isManyToManyRelationProp = _chunkYXILRRDTjs.isManyToManyRelationProp; exports.isOneToOneRelationProp = _chunkYXILRRDTjs.isOneToOneRelationProp; exports.isProduction = _chunkYXILRRDTjs.isProduction; exports.isRefField = _chunkYXILRRDTjs.isRefField; exports.isRelationProp = _chunkYXILRRDTjs.isRelationProp; exports.isRemote = _chunkYXILRRDTjs.isRemote; exports.isSoException = _chunkYXILRRDTjs.isSoException; exports.isStaging = _chunkYXILRRDTjs.isStaging; exports.isStringProp = _chunkYXILRRDTjs.isStringProp; exports.isTest = _chunkYXILRRDTjs.isTest; exports.isTextProp = _chunkYXILRRDTjs.isTextProp; exports.isTimeProp = _chunkYXILRRDTjs.isTimeProp; exports.isTimestampProp = _chunkYXILRRDTjs.isTimestampProp; exports.isUuidProp = _chunkYXILRRDTjs.isUuidProp; exports.isVirtualProp = _chunkYXILRRDTjs.isVirtualProp; exports.nonNullable = _chunkYXILRRDTjs.nonNullable; exports.objToMap = objToMap; exports.p = p; exports.propNodeToZodTypeDef = _chunkYXILRRDTjs.propNodeToZodTypeDef; exports.propToZodTypeDef = _chunkYXILRRDTjs.propToZodTypeDef; exports.registeredApis = _chunkYXILRRDTjs.registeredApis; exports.serializeZodType = _chunkYXILRRDTjs.serializeZodType; exports.setupErrorHandler = setupErrorHandler; exports.unwrapPromiseOnce = _chunkYXILRRDTjs.unwrapPromiseOnce; exports.zArrayable = _chunkYXILRRDTjs.zArrayable; exports.zodTypeToTsTypeDef = _chunkYXILRRDTjs.zodTypeToTsTypeDef; exports.zodTypeToZodCode = _chunkYXILRRDTjs.zodTypeToZodCode;
|
|
427
427
|
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -44,7 +44,7 @@ class EntityManagerClass {
|
|
|
44
44
|
glob.glob(path.resolve(pathPattern!), (_err, files) => {
|
|
45
45
|
Promise.all(
|
|
46
46
|
files.map(async (file) => {
|
|
47
|
-
this.register(JSON.parse(fs.readFileSync(file).toString()));
|
|
47
|
+
await this.register(JSON.parse(fs.readFileSync(file).toString()));
|
|
48
48
|
})
|
|
49
49
|
).then(() => {
|
|
50
50
|
resolve("ok");
|
|
@@ -63,18 +63,22 @@ class EntityManagerClass {
|
|
|
63
63
|
|
|
64
64
|
const sonamuPath = path.join(
|
|
65
65
|
Sonamu.apiRootPath,
|
|
66
|
-
|
|
66
|
+
`dist/application/sonamu.generated.js?t=${Date.now()}`
|
|
67
67
|
);
|
|
68
|
-
|
|
68
|
+
// CJS
|
|
69
|
+
if (require?.cache && require.cache[sonamuPath]) {
|
|
69
70
|
delete require.cache[sonamuPath];
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
return this.autoload(doSilent);
|
|
73
|
+
return await this.autoload(doSilent);
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
register(json: EntityJson): void {
|
|
76
|
+
async register(json: EntityJson): Promise<void> {
|
|
76
77
|
const entity = new Entity(json);
|
|
78
|
+
await entity.registerModulePaths();
|
|
79
|
+
entity.registerTableSpecs();
|
|
77
80
|
this.entities.set(json.id, entity);
|
|
81
|
+
// console.debug(chalk.cyan(`register :: ${entity.id}`));
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
get(entityId: string): Entity {
|
package/src/entity/entity.ts
CHANGED
|
@@ -133,9 +133,6 @@ export class Entity {
|
|
|
133
133
|
fs: inflection.dasherize(inflection.underscore(id)).toLowerCase(),
|
|
134
134
|
module: id,
|
|
135
135
|
};
|
|
136
|
-
|
|
137
|
-
this.registerModulePaths();
|
|
138
|
-
this.registerTableSpecs();
|
|
139
136
|
}
|
|
140
137
|
|
|
141
138
|
/*
|
|
@@ -544,7 +541,7 @@ export class Entity {
|
|
|
544
541
|
.filter(nonNullable);
|
|
545
542
|
}
|
|
546
543
|
|
|
547
|
-
registerModulePaths() {
|
|
544
|
+
async registerModulePaths() {
|
|
548
545
|
const basePath = `${this.names.parentFs}`;
|
|
549
546
|
|
|
550
547
|
// base-scheme
|
|
@@ -579,15 +576,14 @@ export class Entity {
|
|
|
579
576
|
|
|
580
577
|
if (fs.existsSync(typesFileDistPath)) {
|
|
581
578
|
const importPath = path.relative(__dirname, typesFileDistPath);
|
|
582
|
-
import(importPath)
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
});
|
|
579
|
+
const t = await import(importPath);
|
|
580
|
+
this.types = Object.keys(t).reduce((result, key) => {
|
|
581
|
+
EntityManager.setModulePath(key, typesModulePath);
|
|
582
|
+
return {
|
|
583
|
+
...result,
|
|
584
|
+
[key]: t[key],
|
|
585
|
+
};
|
|
586
|
+
}, {});
|
|
591
587
|
}
|
|
592
588
|
}
|
|
593
589
|
|
package/src/syncer/syncer.ts
CHANGED
|
@@ -397,7 +397,7 @@ export class Syncer {
|
|
|
397
397
|
await fs.writeJSON(this.checksumsPath, checksums, {
|
|
398
398
|
spaces: 2,
|
|
399
399
|
});
|
|
400
|
-
console.
|
|
400
|
+
console.log("checksum saved", this.checksumsPath);
|
|
401
401
|
}
|
|
402
402
|
|
|
403
403
|
async getChecksumOfFile(filePath: string): Promise<string> {
|
|
@@ -658,7 +658,7 @@ export class Syncer {
|
|
|
658
658
|
const type = this.resolveTypeNode(paramDec.type);
|
|
659
659
|
|
|
660
660
|
if (name === undefined) {
|
|
661
|
-
console.
|
|
661
|
+
console.debug({ name, type, paramDec });
|
|
662
662
|
}
|
|
663
663
|
|
|
664
664
|
return {
|
|
@@ -1023,32 +1023,38 @@ export class Syncer {
|
|
|
1023
1023
|
(name) => name !== names.constant
|
|
1024
1024
|
);
|
|
1025
1025
|
|
|
1026
|
-
return keys.reduce(
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1026
|
+
return keys.reduce(
|
|
1027
|
+
(result, key) => {
|
|
1028
|
+
const tpl = this.getTemplate(key);
|
|
1029
|
+
if (key.startsWith("view_enums")) {
|
|
1030
|
+
enumsKeys.map((componentId) => {
|
|
1031
|
+
const { target, path: p } = tpl.getTargetAndPath(
|
|
1032
|
+
names,
|
|
1033
|
+
componentId
|
|
1034
|
+
);
|
|
1035
|
+
result[`${key}__${componentId}`] = fs.existsSync(
|
|
1036
|
+
path.join(Sonamu.appRootPath, target, p)
|
|
1037
|
+
);
|
|
1038
|
+
});
|
|
1039
|
+
return result;
|
|
1040
|
+
}
|
|
1037
1041
|
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1042
|
+
const { target, path: p } = tpl.getTargetAndPath(names);
|
|
1043
|
+
const { targets } = Sonamu.config.sync;
|
|
1044
|
+
if (target.includes(":target")) {
|
|
1045
|
+
targets.map((t) => {
|
|
1046
|
+
result[`${key}__${t}`] = fs.existsSync(
|
|
1047
|
+
path.join(Sonamu.appRootPath, target.replace(":target", t), p)
|
|
1048
|
+
);
|
|
1049
|
+
});
|
|
1050
|
+
} else {
|
|
1051
|
+
result[key] = fs.existsSync(path.join(Sonamu.appRootPath, target, p));
|
|
1052
|
+
}
|
|
1049
1053
|
|
|
1050
|
-
|
|
1051
|
-
|
|
1054
|
+
return result;
|
|
1055
|
+
},
|
|
1056
|
+
{} as Record<`${TemplateKey}${string}`, boolean>
|
|
1057
|
+
);
|
|
1052
1058
|
}
|
|
1053
1059
|
|
|
1054
1060
|
async getZodTypeById(zodTypeId: string): Promise<z.ZodTypeAny> {
|
|
@@ -1093,9 +1099,8 @@ export class Syncer {
|
|
|
1093
1099
|
const obj = await propNode.children.reduce(
|
|
1094
1100
|
async (promise, childPropNode) => {
|
|
1095
1101
|
const result = await promise;
|
|
1096
|
-
result[childPropNode.prop!.name] =
|
|
1097
|
-
childPropNode
|
|
1098
|
-
);
|
|
1102
|
+
result[childPropNode.prop!.name] =
|
|
1103
|
+
await this.propNodeToZodType(childPropNode);
|
|
1099
1104
|
return result;
|
|
1100
1105
|
},
|
|
1101
1106
|
{} as any
|