sonamu 0.4.12 → 0.4.14
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-ZLFDB43J.js → chunk-2WAC2GER.js} +147 -96
- package/dist/chunk-2WAC2GER.js.map +1 -0
- package/dist/{chunk-FKZK27YL.mjs → chunk-C3IPIF6O.mjs} +2 -2
- package/dist/{chunk-INTZUNZ6.js → chunk-EXHKSVTE.js} +7 -7
- package/dist/{chunk-LNZTU4JC.mjs → chunk-FCERKIIF.mjs} +104 -53
- package/dist/chunk-FCERKIIF.mjs.map +1 -0
- package/dist/{chunk-JQJTQQ7D.mjs → chunk-HGIBJYOU.mjs} +2 -2
- package/dist/{chunk-NPLUHS5L.mjs → chunk-JKSOJRQA.mjs} +2 -2
- package/dist/{chunk-FYLFH3Q6.js → chunk-OTKKFP3Y.js} +100 -100
- package/dist/{chunk-IEMX4VPN.js → chunk-UZ2IY5VE.js} +4 -4
- 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/caster.ts +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-FKZK27YL.mjs.map → chunk-C3IPIF6O.mjs.map} +0 -0
- package/dist/{chunk-INTZUNZ6.js.map → chunk-EXHKSVTE.js.map} +0 -0
- package/dist/{chunk-JQJTQQ7D.mjs.map → chunk-HGIBJYOU.mjs.map} +0 -0
- package/dist/{chunk-NPLUHS5L.mjs.map → chunk-JKSOJRQA.mjs.map} +0 -0
- package/dist/{chunk-FYLFH3Q6.js.map → chunk-OTKKFP3Y.js.map} +0 -0
- package/dist/{chunk-IEMX4VPN.js.map → chunk-UZ2IY5VE.js.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
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
isStringProp,
|
|
17
17
|
isTextProp,
|
|
18
18
|
isVirtualProp
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-FCERKIIF.mjs";
|
|
20
20
|
|
|
21
21
|
// src/entity/migrator.ts
|
|
22
22
|
import _ from "lodash";
|
|
@@ -1578,4 +1578,4 @@ export {
|
|
|
1578
1578
|
FixtureManagerClass,
|
|
1579
1579
|
FixtureManager
|
|
1580
1580
|
};
|
|
1581
|
-
//# sourceMappingURL=chunk-
|
|
1581
|
+
//# sourceMappingURL=chunk-C3IPIF6O.mjs.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunk2WAC2GERjs = require('./chunk-2WAC2GER.js');
|
|
6
6
|
|
|
7
7
|
// src/database/upsert-builder.ts
|
|
8
8
|
var _uuid = require('uuid');
|
|
@@ -20,7 +20,7 @@ async function batchUpdate(db, tableName, ids, rows, chunkSize = 50, trx = null)
|
|
|
20
20
|
};
|
|
21
21
|
if (trx) {
|
|
22
22
|
for (const chunk of chunks) {
|
|
23
|
-
await executeUpdate(chunk,
|
|
23
|
+
await executeUpdate(chunk, _chunk2WAC2GERjs.DB.toClient(trx));
|
|
24
24
|
}
|
|
25
25
|
} else {
|
|
26
26
|
await db.trx(async (newTrx) => {
|
|
@@ -87,7 +87,7 @@ var UpsertBuilder = class {
|
|
|
87
87
|
if (table === void 0) {
|
|
88
88
|
const tableSpec = (() => {
|
|
89
89
|
try {
|
|
90
|
-
return
|
|
90
|
+
return _chunk2WAC2GERjs.EntityManager.getTableSpec(tableName);
|
|
91
91
|
} catch (e) {
|
|
92
92
|
return null;
|
|
93
93
|
}
|
|
@@ -119,7 +119,7 @@ var UpsertBuilder = class {
|
|
|
119
119
|
return null;
|
|
120
120
|
}
|
|
121
121
|
return uniqueKeyArray.join("---delimiter--");
|
|
122
|
-
}).filter(
|
|
122
|
+
}).filter(_chunk2WAC2GERjs.nonNullable);
|
|
123
123
|
const uuid = (() => {
|
|
124
124
|
if (uniqueKeys.length > 0) {
|
|
125
125
|
for (const uniqueKey of uniqueKeys) {
|
|
@@ -180,7 +180,7 @@ var UpsertBuilder = class {
|
|
|
180
180
|
)) {
|
|
181
181
|
throw new Error(`${tableName} \uD574\uACB0\uB418\uC9C0 \uC54A\uC740 \uCC38\uC870\uAC00 \uC788\uC2B5\uB2C8\uB2E4.`);
|
|
182
182
|
}
|
|
183
|
-
const wdb =
|
|
183
|
+
const wdb = _chunk2WAC2GERjs.DB.toClient(_wdb);
|
|
184
184
|
const { references, refTables } = Array.from(this.tables).reduce(
|
|
185
185
|
(r, [, table2]) => {
|
|
186
186
|
const reference = Array.from(table2.references.values()).find(
|
|
@@ -264,7 +264,7 @@ var UpsertBuilder = class {
|
|
|
264
264
|
return row;
|
|
265
265
|
});
|
|
266
266
|
await batchUpdate(
|
|
267
|
-
|
|
267
|
+
_chunk2WAC2GERjs.DB.toClient(wdb),
|
|
268
268
|
tableName,
|
|
269
269
|
whereColumns,
|
|
270
270
|
rows,
|
|
@@ -277,4 +277,4 @@ var UpsertBuilder = class {
|
|
|
277
277
|
|
|
278
278
|
|
|
279
279
|
exports.isRefField = isRefField; exports.UpsertBuilder = UpsertBuilder;
|
|
280
|
-
//# sourceMappingURL=chunk-
|
|
280
|
+
//# sourceMappingURL=chunk-EXHKSVTE.js.map
|
|
@@ -564,6 +564,9 @@ function apiParamToTsCode(params, injectImportKeys) {
|
|
|
564
564
|
return `${param.name}${param.optional && !param.defaultDef ? "?" : ""}: ${apiParamTypeToTsType(param.type, injectImportKeys)}${param.defaultDef ? `= ${param.defaultDef}` : ""}`;
|
|
565
565
|
}).join(", ");
|
|
566
566
|
}
|
|
567
|
+
function apiParamToTsCodeAsObject(params, injectImportKeys) {
|
|
568
|
+
return `{ ${params.map((param) => `${param.name}${param.optional ? "?" : ""}: ${apiParamTypeToTsType(param.type, injectImportKeys)}${param.defaultDef ? `= ${param.defaultDef}` : ""}`).join(", ")} }`;
|
|
569
|
+
}
|
|
567
570
|
function apiParamTypeToTsType(paramType, injectImportKeys) {
|
|
568
571
|
if ([
|
|
569
572
|
"string",
|
|
@@ -778,13 +781,32 @@ function api(options = {}) {
|
|
|
778
781
|
modelName.replace(/Model$/, "").replace(/Frame$/, ""),
|
|
779
782
|
true
|
|
780
783
|
)}/${inflection.camelize(propertyKey, true)}`;
|
|
781
|
-
|
|
784
|
+
registeredApis.push({
|
|
782
785
|
modelName,
|
|
783
786
|
methodName,
|
|
784
787
|
path: options.path ?? defaultPath,
|
|
785
788
|
options
|
|
786
|
-
};
|
|
787
|
-
|
|
789
|
+
});
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
function stream(options) {
|
|
793
|
+
return function(target, propertyKey) {
|
|
794
|
+
const modelName = target.constructor.name.match(/(.+)Class$/)[1];
|
|
795
|
+
const methodName = propertyKey;
|
|
796
|
+
const defaultPath = `/${inflection.camelize(
|
|
797
|
+
modelName.replace(/Model$/, "").replace(/Frame$/, ""),
|
|
798
|
+
true
|
|
799
|
+
)}/${inflection.camelize(propertyKey, true)}`;
|
|
800
|
+
registeredApis.push({
|
|
801
|
+
modelName,
|
|
802
|
+
methodName,
|
|
803
|
+
path: options.path ?? defaultPath,
|
|
804
|
+
options: {
|
|
805
|
+
...options,
|
|
806
|
+
httpMethod: "GET"
|
|
807
|
+
},
|
|
808
|
+
streamOptions: options
|
|
809
|
+
});
|
|
788
810
|
};
|
|
789
811
|
}
|
|
790
812
|
|
|
@@ -967,7 +989,7 @@ function isZodNumberAnyway(zodType) {
|
|
|
967
989
|
} else if (zodType instanceof z3.ZodNullable && zodType._def.innerType instanceof z3.ZodNumber) {
|
|
968
990
|
return true;
|
|
969
991
|
} else if (zodType instanceof z3.ZodOptional && zodType._def.innerType instanceof z3.ZodNumber) {
|
|
970
|
-
} else if (zodType instanceof z3.ZodOptional && zodType._def
|
|
992
|
+
} else if (zodType instanceof z3.ZodOptional && zodType._def?.innerType instanceof z3.ZodOptional && zodType._type?.def?.innerType instanceof z3.ZodNumber) {
|
|
971
993
|
return true;
|
|
972
994
|
}
|
|
973
995
|
return false;
|
|
@@ -4030,7 +4052,7 @@ var Template__service = class extends Template {
|
|
|
4030
4052
|
`import { z } from 'zod';`,
|
|
4031
4053
|
`import qs from "qs";`,
|
|
4032
4054
|
`import useSWR, { SWRResponse } from "swr";`,
|
|
4033
|
-
`import { fetch, ListResult, SWRError, SwrOptions, handleConditional, swrPostFetcher } from '../sonamu.shared';`,
|
|
4055
|
+
`import { fetch, ListResult, SWRError, SwrOptions, handleConditional, swrPostFetcher, EventHandlers, SSEStreamOptions, useSSEStream } from '../sonamu.shared';`,
|
|
4034
4056
|
...hasAxiosProgressEvent ? [`import { AxiosProgressEvent } from 'axios';`] : []
|
|
4035
4057
|
]
|
|
4036
4058
|
};
|
|
@@ -4056,57 +4078,65 @@ var Template__service = class extends Template {
|
|
|
4056
4078
|
paramsWithoutContext,
|
|
4057
4079
|
importKeys
|
|
4058
4080
|
);
|
|
4081
|
+
const paramsDefAsObject = apiParamToTsCodeAsObject(
|
|
4082
|
+
paramsWithoutContext,
|
|
4083
|
+
importKeys
|
|
4084
|
+
);
|
|
4059
4085
|
const returnTypeDef = apiParamTypeToTsType(
|
|
4060
4086
|
unwrapPromiseOnce(api2.returnType),
|
|
4061
4087
|
importKeys
|
|
4062
4088
|
);
|
|
4063
4089
|
const payloadDef = `{ ${paramsWithoutContext.map((param) => param.name).join(", ")} }`;
|
|
4064
|
-
|
|
4065
|
-
|
|
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
|
-
|
|
4090
|
+
const apiBaseUrl = `${Sonamu.config.route.prefix}${api2.path}`;
|
|
4091
|
+
return [
|
|
4092
|
+
// 클라이언트별로 생성
|
|
4093
|
+
..._9.sortBy(
|
|
4094
|
+
api2.options.clients,
|
|
4095
|
+
(client) => client === "swr" ? 0 : 1
|
|
4096
|
+
).map((client) => {
|
|
4097
|
+
switch (client) {
|
|
4098
|
+
case "axios":
|
|
4099
|
+
return this.renderAxios(
|
|
4100
|
+
api2,
|
|
4101
|
+
apiBaseUrl,
|
|
4102
|
+
typeParamsDef,
|
|
4103
|
+
paramsDef,
|
|
4104
|
+
returnTypeDef,
|
|
4105
|
+
payloadDef
|
|
4106
|
+
);
|
|
4107
|
+
case "axios-multipart":
|
|
4108
|
+
return this.renderAxiosMultipart(
|
|
4109
|
+
api2,
|
|
4110
|
+
apiBaseUrl,
|
|
4111
|
+
typeParamsDef,
|
|
4112
|
+
paramsDef,
|
|
4113
|
+
returnTypeDef,
|
|
4114
|
+
paramsWithoutContext
|
|
4115
|
+
);
|
|
4116
|
+
case "swr":
|
|
4117
|
+
return this.renderSwr(
|
|
4118
|
+
api2,
|
|
4119
|
+
apiBaseUrl,
|
|
4120
|
+
typeParamsDef,
|
|
4121
|
+
paramsDef,
|
|
4122
|
+
returnTypeDef,
|
|
4123
|
+
payloadDef
|
|
4124
|
+
);
|
|
4125
|
+
case "window-fetch":
|
|
4126
|
+
return this.renderWindowFetch(
|
|
4127
|
+
api2,
|
|
4128
|
+
apiBaseUrl,
|
|
4129
|
+
typeParamsDef,
|
|
4130
|
+
paramsDef,
|
|
4131
|
+
payloadDef
|
|
4132
|
+
);
|
|
4133
|
+
default:
|
|
4134
|
+
return `// Not supported ${inflection4.camelize(client, true)} yet.`;
|
|
4135
|
+
}
|
|
4136
|
+
}),
|
|
4137
|
+
// 스트리밍인 경우
|
|
4138
|
+
...api2.streamOptions ? [this.renderStream(api2, apiBaseUrl, paramsDefAsObject)] : []
|
|
4139
|
+
].join("\n");
|
|
4110
4140
|
}).join("\n\n");
|
|
4111
4141
|
return `export namespace ${modelName.replace(/Model$/, "Service").replace(/Frame$/, "Service")} {
|
|
4112
4142
|
${methodCodes}
|
|
@@ -4187,6 +4217,23 @@ export async function ${api2.methodName}${typeParamsDef}(${paramsDef}): Promise<
|
|
|
4187
4217
|
}
|
|
4188
4218
|
`.trim();
|
|
4189
4219
|
}
|
|
4220
|
+
renderStream(api2, apiBaseUrl, paramsDefAsObject) {
|
|
4221
|
+
if (!api2.streamOptions) {
|
|
4222
|
+
return "// streamOptions not found";
|
|
4223
|
+
}
|
|
4224
|
+
const methodNameStream = api2.options.resourceName ? "use" + inflection4.camelize(api2.options.resourceName) : "use" + inflection4.camelize(api2.methodName);
|
|
4225
|
+
const methodNameStreamCamelized = inflection4.camelize(
|
|
4226
|
+
methodNameStream,
|
|
4227
|
+
true
|
|
4228
|
+
);
|
|
4229
|
+
const eventsTypeDef = zodTypeToTsTypeDef(api2.streamOptions.events);
|
|
4230
|
+
return ` export function ${methodNameStreamCamelized}(
|
|
4231
|
+
params: ${paramsDefAsObject},
|
|
4232
|
+
handlers: EventHandlers<${eventsTypeDef} & { end?: () => void }>,
|
|
4233
|
+
options: SSEStreamOptions) {
|
|
4234
|
+
return useSSEStream<${eventsTypeDef}>(\`${apiBaseUrl}\`, params, handlers, options);
|
|
4235
|
+
}`;
|
|
4236
|
+
}
|
|
4190
4237
|
};
|
|
4191
4238
|
|
|
4192
4239
|
// src/templates/view_form.template.ts
|
|
@@ -5298,9 +5345,10 @@ var Syncer = class {
|
|
|
5298
5345
|
}
|
|
5299
5346
|
async sync() {
|
|
5300
5347
|
const { targets } = Sonamu.config.sync;
|
|
5348
|
+
const currentDirname = __dirname.endsWith("/syncer") ? __dirname : path5.join(__dirname, "./syncer");
|
|
5301
5349
|
await Promise.all(
|
|
5302
5350
|
targets.map(async (target) => {
|
|
5303
|
-
const srcCodePath = path5.join(
|
|
5351
|
+
const srcCodePath = path5.join(currentDirname, `../shared/${target}.shared.ts.txt`).replace("/dist/", "/src/");
|
|
5304
5352
|
if (!fs2.existsSync(srcCodePath)) {
|
|
5305
5353
|
return;
|
|
5306
5354
|
}
|
|
@@ -5320,6 +5368,7 @@ var Syncer = class {
|
|
|
5320
5368
|
return;
|
|
5321
5369
|
}
|
|
5322
5370
|
fs2.writeFileSync(dstCodePath, fs2.readFileSync(srcCodePath));
|
|
5371
|
+
console.log(chalk.blue("shared.ts is synced"));
|
|
5323
5372
|
})
|
|
5324
5373
|
);
|
|
5325
5374
|
let currentChecksums = await this.getCurrentChecksums();
|
|
@@ -7527,12 +7576,14 @@ export {
|
|
|
7527
7576
|
propToZodTypeDef,
|
|
7528
7577
|
zodTypeToZodCode,
|
|
7529
7578
|
apiParamToTsCode,
|
|
7579
|
+
apiParamToTsCodeAsObject,
|
|
7530
7580
|
apiParamTypeToTsType,
|
|
7531
7581
|
unwrapPromiseOnce,
|
|
7532
7582
|
serializeZodType,
|
|
7533
7583
|
zodTypeToTsTypeDef,
|
|
7534
7584
|
registeredApis,
|
|
7535
7585
|
api,
|
|
7586
|
+
stream,
|
|
7536
7587
|
SoException,
|
|
7537
7588
|
isSoException,
|
|
7538
7589
|
BadRequestException,
|
|
@@ -7569,4 +7620,4 @@ export {
|
|
|
7569
7620
|
isTest,
|
|
7570
7621
|
Sonamu
|
|
7571
7622
|
};
|
|
7572
|
-
//# sourceMappingURL=chunk-
|
|
7623
|
+
//# sourceMappingURL=chunk-FCERKIIF.mjs.map
|