sonamu 0.4.12 → 0.4.13
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/.pnp.cjs +5 -5
- package/dist/{base-model-BvVra-8f.d.mts → base-model-CEB0H0aO.d.mts} +1 -1
- package/dist/{base-model-Br6krkwK.d.ts → base-model-CrqDMYhI.d.ts} +1 -1
- package/dist/bin/cli.js +51 -51
- package/dist/bin/cli.mjs +2 -2
- package/dist/{chunk-FYLFH3Q6.js → chunk-CXAVBVKC.js} +100 -100
- package/dist/{chunk-JQJTQQ7D.mjs → chunk-DDJ7T4MA.mjs} +2 -2
- package/dist/{chunk-ZLFDB43J.js → chunk-DMJSNO2L.js} +104 -53
- package/dist/chunk-DMJSNO2L.js.map +1 -0
- package/dist/{chunk-INTZUNZ6.js → chunk-DYFCACHD.js} +7 -7
- package/dist/{chunk-IEMX4VPN.js → chunk-J6S43O7G.js} +4 -4
- package/dist/{chunk-FKZK27YL.mjs → chunk-NI37CY4T.mjs} +2 -2
- package/dist/{chunk-NPLUHS5L.mjs → chunk-NIFOTHBW.mjs} +2 -2
- package/dist/{chunk-LNZTU4JC.mjs → chunk-QJFHDCBN.mjs} +103 -52
- package/dist/chunk-QJFHDCBN.mjs.map +1 -0
- package/dist/database/drivers/knex/base-model.d.mts +2 -2
- package/dist/database/drivers/knex/base-model.d.ts +2 -2
- package/dist/database/drivers/knex/base-model.js +8 -8
- package/dist/database/drivers/knex/base-model.mjs +3 -3
- package/dist/database/drivers/kysely/base-model.d.mts +2 -2
- package/dist/database/drivers/kysely/base-model.d.ts +2 -2
- package/dist/database/drivers/kysely/base-model.js +9 -9
- package/dist/database/drivers/kysely/base-model.mjs +3 -3
- package/dist/index.d.mts +17 -4
- package/dist/index.d.ts +17 -4
- package/dist/index.js +13 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/api/code-converters.ts +7 -0
- package/src/api/decorators.ts +36 -4
- package/src/shared/web.shared.ts.txt +225 -0
- package/src/syncer/syncer.ts +7 -1
- package/src/templates/service.template.ts +50 -9
- package/dist/chunk-LNZTU4JC.mjs.map +0 -1
- package/dist/chunk-ZLFDB43J.js.map +0 -1
- package/dist/{chunk-FYLFH3Q6.js.map → chunk-CXAVBVKC.js.map} +0 -0
- package/dist/{chunk-JQJTQQ7D.mjs.map → chunk-DDJ7T4MA.mjs.map} +0 -0
- package/dist/{chunk-INTZUNZ6.js.map → chunk-DYFCACHD.js.map} +0 -0
- package/dist/{chunk-IEMX4VPN.js.map → chunk-J6S43O7G.js.map} +0 -0
- package/dist/{chunk-FKZK27YL.mjs.map → chunk-NI37CY4T.mjs.map} +0 -0
- package/dist/{chunk-NPLUHS5L.mjs.map → chunk-NIFOTHBW.mjs.map} +0 -0
- package/dist/{model-DWoinpJ7.d.mts → model-aFgomcdc.d.mts} +4 -4
- package/dist/{model-DWoinpJ7.d.ts → model-aFgomcdc.d.ts} +4 -4
|
@@ -566,6 +566,9 @@ function apiParamToTsCode(params, injectImportKeys) {
|
|
|
566
566
|
return `${param.name}${param.optional && !param.defaultDef ? "?" : ""}: ${apiParamTypeToTsType(param.type, injectImportKeys)}${param.defaultDef ? `= ${param.defaultDef}` : ""}`;
|
|
567
567
|
}).join(", ");
|
|
568
568
|
}
|
|
569
|
+
function apiParamToTsCodeAsObject(params, injectImportKeys) {
|
|
570
|
+
return `{ ${params.map((param) => `${param.name}${param.optional ? "?" : ""}: ${apiParamTypeToTsType(param.type, injectImportKeys)}${param.defaultDef ? `= ${param.defaultDef}` : ""}`).join(", ")} }`;
|
|
571
|
+
}
|
|
569
572
|
function apiParamTypeToTsType(paramType, injectImportKeys) {
|
|
570
573
|
if ([
|
|
571
574
|
"string",
|
|
@@ -780,13 +783,32 @@ function api(options = {}) {
|
|
|
780
783
|
modelName.replace(/Model$/, "").replace(/Frame$/, ""),
|
|
781
784
|
true
|
|
782
785
|
)}/${_inflection2.default.camelize(propertyKey, true)}`;
|
|
783
|
-
|
|
786
|
+
registeredApis.push({
|
|
784
787
|
modelName,
|
|
785
788
|
methodName,
|
|
786
789
|
path: _nullishCoalesce(options.path, () => ( defaultPath)),
|
|
787
790
|
options
|
|
788
|
-
};
|
|
789
|
-
|
|
791
|
+
});
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
function stream(options) {
|
|
795
|
+
return function(target, propertyKey) {
|
|
796
|
+
const modelName = target.constructor.name.match(/(.+)Class$/)[1];
|
|
797
|
+
const methodName = propertyKey;
|
|
798
|
+
const defaultPath = `/${_inflection2.default.camelize(
|
|
799
|
+
modelName.replace(/Model$/, "").replace(/Frame$/, ""),
|
|
800
|
+
true
|
|
801
|
+
)}/${_inflection2.default.camelize(propertyKey, true)}`;
|
|
802
|
+
registeredApis.push({
|
|
803
|
+
modelName,
|
|
804
|
+
methodName,
|
|
805
|
+
path: _nullishCoalesce(options.path, () => ( defaultPath)),
|
|
806
|
+
options: {
|
|
807
|
+
...options,
|
|
808
|
+
httpMethod: "GET"
|
|
809
|
+
},
|
|
810
|
+
streamOptions: options
|
|
811
|
+
});
|
|
790
812
|
};
|
|
791
813
|
}
|
|
792
814
|
|
|
@@ -4032,7 +4054,7 @@ var Template__service = class extends Template {
|
|
|
4032
4054
|
`import { z } from 'zod';`,
|
|
4033
4055
|
`import qs from "qs";`,
|
|
4034
4056
|
`import useSWR, { SWRResponse } from "swr";`,
|
|
4035
|
-
`import { fetch, ListResult, SWRError, SwrOptions, handleConditional, swrPostFetcher } from '../sonamu.shared';`,
|
|
4057
|
+
`import { fetch, ListResult, SWRError, SwrOptions, handleConditional, swrPostFetcher, EventHandlers, SSEStreamOptions, useSSEStream } from '../sonamu.shared';`,
|
|
4036
4058
|
...hasAxiosProgressEvent ? [`import { AxiosProgressEvent } from 'axios';`] : []
|
|
4037
4059
|
]
|
|
4038
4060
|
};
|
|
@@ -4058,57 +4080,65 @@ var Template__service = class extends Template {
|
|
|
4058
4080
|
paramsWithoutContext,
|
|
4059
4081
|
importKeys
|
|
4060
4082
|
);
|
|
4083
|
+
const paramsDefAsObject = apiParamToTsCodeAsObject(
|
|
4084
|
+
paramsWithoutContext,
|
|
4085
|
+
importKeys
|
|
4086
|
+
);
|
|
4061
4087
|
const returnTypeDef = apiParamTypeToTsType(
|
|
4062
4088
|
unwrapPromiseOnce(api2.returnType),
|
|
4063
4089
|
importKeys
|
|
4064
4090
|
);
|
|
4065
4091
|
const payloadDef = `{ ${paramsWithoutContext.map((param) => param.name).join(", ")} }`;
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4092
|
+
const apiBaseUrl = `${Sonamu.config.route.prefix}${api2.path}`;
|
|
4093
|
+
return [
|
|
4094
|
+
// 클라이언트별로 생성
|
|
4095
|
+
..._lodash2.default.sortBy(
|
|
4096
|
+
api2.options.clients,
|
|
4097
|
+
(client) => client === "swr" ? 0 : 1
|
|
4098
|
+
).map((client) => {
|
|
4099
|
+
switch (client) {
|
|
4100
|
+
case "axios":
|
|
4101
|
+
return this.renderAxios(
|
|
4102
|
+
api2,
|
|
4103
|
+
apiBaseUrl,
|
|
4104
|
+
typeParamsDef,
|
|
4105
|
+
paramsDef,
|
|
4106
|
+
returnTypeDef,
|
|
4107
|
+
payloadDef
|
|
4108
|
+
);
|
|
4109
|
+
case "axios-multipart":
|
|
4110
|
+
return this.renderAxiosMultipart(
|
|
4111
|
+
api2,
|
|
4112
|
+
apiBaseUrl,
|
|
4113
|
+
typeParamsDef,
|
|
4114
|
+
paramsDef,
|
|
4115
|
+
returnTypeDef,
|
|
4116
|
+
paramsWithoutContext
|
|
4117
|
+
);
|
|
4118
|
+
case "swr":
|
|
4119
|
+
return this.renderSwr(
|
|
4120
|
+
api2,
|
|
4121
|
+
apiBaseUrl,
|
|
4122
|
+
typeParamsDef,
|
|
4123
|
+
paramsDef,
|
|
4124
|
+
returnTypeDef,
|
|
4125
|
+
payloadDef
|
|
4126
|
+
);
|
|
4127
|
+
case "window-fetch":
|
|
4128
|
+
return this.renderWindowFetch(
|
|
4129
|
+
api2,
|
|
4130
|
+
apiBaseUrl,
|
|
4131
|
+
typeParamsDef,
|
|
4132
|
+
paramsDef,
|
|
4133
|
+
payloadDef
|
|
4134
|
+
);
|
|
4135
|
+
default:
|
|
4136
|
+
return `// Not supported ${_inflection2.default.camelize(client, true)} yet.`;
|
|
4137
|
+
}
|
|
4138
|
+
}),
|
|
4139
|
+
// 스트리밍인 경우
|
|
4140
|
+
...api2.streamOptions ? [this.renderStream(api2, apiBaseUrl, paramsDefAsObject)] : []
|
|
4141
|
+
].join("\n");
|
|
4112
4142
|
}).join("\n\n");
|
|
4113
4143
|
return `export namespace ${modelName.replace(/Model$/, "Service").replace(/Frame$/, "Service")} {
|
|
4114
4144
|
${methodCodes}
|
|
@@ -4189,6 +4219,23 @@ export async function ${api2.methodName}${typeParamsDef}(${paramsDef}): Promise<
|
|
|
4189
4219
|
}
|
|
4190
4220
|
`.trim();
|
|
4191
4221
|
}
|
|
4222
|
+
renderStream(api2, apiBaseUrl, paramsDefAsObject) {
|
|
4223
|
+
if (!api2.streamOptions) {
|
|
4224
|
+
return "// streamOptions not found";
|
|
4225
|
+
}
|
|
4226
|
+
const methodNameStream = api2.options.resourceName ? "use" + _inflection2.default.camelize(api2.options.resourceName) : "use" + _inflection2.default.camelize(api2.methodName);
|
|
4227
|
+
const methodNameStreamCamelized = _inflection2.default.camelize(
|
|
4228
|
+
methodNameStream,
|
|
4229
|
+
true
|
|
4230
|
+
);
|
|
4231
|
+
const eventsTypeDef = zodTypeToTsTypeDef(api2.streamOptions.events);
|
|
4232
|
+
return ` export function ${methodNameStreamCamelized}(
|
|
4233
|
+
params: ${paramsDefAsObject},
|
|
4234
|
+
handlers: EventHandlers<${eventsTypeDef} & { end?: () => void }>,
|
|
4235
|
+
options: SSEStreamOptions) {
|
|
4236
|
+
return useSSEStream<${eventsTypeDef}>(\`${apiBaseUrl}\`, params, handlers, options);
|
|
4237
|
+
}`;
|
|
4238
|
+
}
|
|
4192
4239
|
};
|
|
4193
4240
|
|
|
4194
4241
|
// src/templates/view_form.template.ts
|
|
@@ -5300,9 +5347,10 @@ var Syncer = (_class4 = class {
|
|
|
5300
5347
|
}
|
|
5301
5348
|
async sync() {
|
|
5302
5349
|
const { targets } = Sonamu.config.sync;
|
|
5350
|
+
const currentDirname = __dirname.endsWith("/syncer") ? __dirname : _path2.default.join(__dirname, "./syncer");
|
|
5303
5351
|
await Promise.all(
|
|
5304
5352
|
targets.map(async (target) => {
|
|
5305
|
-
const srcCodePath = _path2.default.join(
|
|
5353
|
+
const srcCodePath = _path2.default.join(currentDirname, `../shared/${target}.shared.ts.txt`).replace("/dist/", "/src/");
|
|
5306
5354
|
if (!_fsextra2.default.existsSync(srcCodePath)) {
|
|
5307
5355
|
return;
|
|
5308
5356
|
}
|
|
@@ -5322,6 +5370,7 @@ var Syncer = (_class4 = class {
|
|
|
5322
5370
|
return;
|
|
5323
5371
|
}
|
|
5324
5372
|
_fsextra2.default.writeFileSync(dstCodePath, _fsextra2.default.readFileSync(srcCodePath));
|
|
5373
|
+
console.log(_chalk2.default.blue("shared.ts is synced"));
|
|
5325
5374
|
})
|
|
5326
5375
|
);
|
|
5327
5376
|
let currentChecksums = await this.getCurrentChecksums();
|
|
@@ -7570,5 +7619,7 @@ var Entity = (_class7 = class {
|
|
|
7570
7619
|
|
|
7571
7620
|
|
|
7572
7621
|
|
|
7573
|
-
|
|
7574
|
-
|
|
7622
|
+
|
|
7623
|
+
|
|
7624
|
+
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.isKyselyError = isKyselyError; 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.apiParamToTsCodeAsObject = apiParamToTsCodeAsObject; exports.apiParamTypeToTsType = apiParamTypeToTsType; exports.unwrapPromiseOnce = unwrapPromiseOnce; exports.serializeZodType = serializeZodType; exports.zodTypeToTsTypeDef = zodTypeToTsTypeDef; exports.registeredApis = registeredApis; exports.api = api; exports.stream = stream; 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.hydrate = hydrate; exports.Entity = Entity; exports.EntityManager = EntityManager; exports.asArray = asArray; exports.objToMap = objToMap; exports.KnexClient = KnexClient; exports.KyselyClient = KyselyClient; exports.DBKnexClass = DBKnexClass; exports.DBKyselyClass = DBKyselyClass; exports.DB = DB; 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.Sonamu = Sonamu;
|
|
7625
|
+
//# sourceMappingURL=chunk-DMJSNO2L.js.map
|