sonamu 0.0.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.
Files changed (60) hide show
  1. package/.pnp.cjs +15552 -0
  2. package/.pnp.loader.mjs +285 -0
  3. package/.vscode/extensions.json +6 -0
  4. package/.vscode/settings.json +9 -0
  5. package/.yarnrc.yml +5 -0
  6. package/dist/bin/cli.d.ts +2 -0
  7. package/dist/bin/cli.d.ts.map +1 -0
  8. package/dist/bin/cli.js +123 -0
  9. package/dist/bin/cli.js.map +1 -0
  10. package/dist/index.js +34 -0
  11. package/package.json +60 -0
  12. package/src/api/caster.ts +72 -0
  13. package/src/api/code-converters.ts +552 -0
  14. package/src/api/context.ts +20 -0
  15. package/src/api/decorators.ts +63 -0
  16. package/src/api/index.ts +5 -0
  17. package/src/api/init.ts +128 -0
  18. package/src/bin/cli.ts +115 -0
  19. package/src/database/base-model.ts +287 -0
  20. package/src/database/db.ts +95 -0
  21. package/src/database/knex-plugins/knex-on-duplicate-update.ts +41 -0
  22. package/src/database/upsert-builder.ts +231 -0
  23. package/src/exceptions/error-handler.ts +29 -0
  24. package/src/exceptions/so-exceptions.ts +91 -0
  25. package/src/index.ts +17 -0
  26. package/src/shared/web.shared.ts.txt +119 -0
  27. package/src/smd/migrator.ts +1462 -0
  28. package/src/smd/smd-manager.ts +141 -0
  29. package/src/smd/smd-utils.ts +266 -0
  30. package/src/smd/smd.ts +533 -0
  31. package/src/syncer/index.ts +1 -0
  32. package/src/syncer/syncer.ts +1283 -0
  33. package/src/templates/base-template.ts +19 -0
  34. package/src/templates/generated.template.ts +247 -0
  35. package/src/templates/generated_http.template.ts +114 -0
  36. package/src/templates/index.ts +1 -0
  37. package/src/templates/init_enums.template.ts +71 -0
  38. package/src/templates/init_generated.template.ts +44 -0
  39. package/src/templates/init_types.template.ts +38 -0
  40. package/src/templates/model.template.ts +168 -0
  41. package/src/templates/model_test.template.ts +39 -0
  42. package/src/templates/service.template.ts +263 -0
  43. package/src/templates/smd.template.ts +49 -0
  44. package/src/templates/view_enums_buttonset.template.ts +34 -0
  45. package/src/templates/view_enums_dropdown.template.ts +67 -0
  46. package/src/templates/view_enums_select.template.ts +60 -0
  47. package/src/templates/view_form.template.ts +397 -0
  48. package/src/templates/view_id_all_select.template.ts +34 -0
  49. package/src/templates/view_id_async_select.template.ts +113 -0
  50. package/src/templates/view_list.template.ts +652 -0
  51. package/src/templates/view_list_columns.template.ts +59 -0
  52. package/src/templates/view_search_input.template.ts +67 -0
  53. package/src/testing/fixture-manager.ts +271 -0
  54. package/src/types/types.ts +668 -0
  55. package/src/typings/knex.d.ts +24 -0
  56. package/src/utils/controller.ts +21 -0
  57. package/src/utils/lodash-able.ts +11 -0
  58. package/src/utils/model.ts +33 -0
  59. package/src/utils/utils.ts +28 -0
  60. package/tsconfig.json +47 -0
@@ -0,0 +1,285 @@
1
+ import { URL, fileURLToPath, pathToFileURL } from 'url';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import moduleExports, { Module } from 'module';
5
+
6
+ var PathType;
7
+ (function(PathType2) {
8
+ PathType2[PathType2["File"] = 0] = "File";
9
+ PathType2[PathType2["Portable"] = 1] = "Portable";
10
+ PathType2[PathType2["Native"] = 2] = "Native";
11
+ })(PathType || (PathType = {}));
12
+ const npath = Object.create(path);
13
+ const ppath = Object.create(path.posix);
14
+ npath.cwd = () => process.cwd();
15
+ ppath.cwd = () => toPortablePath(process.cwd());
16
+ ppath.resolve = (...segments) => {
17
+ if (segments.length > 0 && ppath.isAbsolute(segments[0])) {
18
+ return path.posix.resolve(...segments);
19
+ } else {
20
+ return path.posix.resolve(ppath.cwd(), ...segments);
21
+ }
22
+ };
23
+ const contains = function(pathUtils, from, to) {
24
+ from = pathUtils.normalize(from);
25
+ to = pathUtils.normalize(to);
26
+ if (from === to)
27
+ return `.`;
28
+ if (!from.endsWith(pathUtils.sep))
29
+ from = from + pathUtils.sep;
30
+ if (to.startsWith(from)) {
31
+ return to.slice(from.length);
32
+ } else {
33
+ return null;
34
+ }
35
+ };
36
+ npath.fromPortablePath = fromPortablePath;
37
+ npath.toPortablePath = toPortablePath;
38
+ npath.contains = (from, to) => contains(npath, from, to);
39
+ ppath.contains = (from, to) => contains(ppath, from, to);
40
+ const WINDOWS_PATH_REGEXP = /^([a-zA-Z]:.*)$/;
41
+ const UNC_WINDOWS_PATH_REGEXP = /^\/\/(\.\/)?(.*)$/;
42
+ const PORTABLE_PATH_REGEXP = /^\/([a-zA-Z]:.*)$/;
43
+ const UNC_PORTABLE_PATH_REGEXP = /^\/unc\/(\.dot\/)?(.*)$/;
44
+ function fromPortablePath(p) {
45
+ if (process.platform !== `win32`)
46
+ return p;
47
+ let portablePathMatch, uncPortablePathMatch;
48
+ if (portablePathMatch = p.match(PORTABLE_PATH_REGEXP))
49
+ p = portablePathMatch[1];
50
+ else if (uncPortablePathMatch = p.match(UNC_PORTABLE_PATH_REGEXP))
51
+ p = `\\\\${uncPortablePathMatch[1] ? `.\\` : ``}${uncPortablePathMatch[2]}`;
52
+ else
53
+ return p;
54
+ return p.replace(/\//g, `\\`);
55
+ }
56
+ function toPortablePath(p) {
57
+ if (process.platform !== `win32`)
58
+ return p;
59
+ p = p.replace(/\\/g, `/`);
60
+ let windowsPathMatch, uncWindowsPathMatch;
61
+ if (windowsPathMatch = p.match(WINDOWS_PATH_REGEXP))
62
+ p = `/${windowsPathMatch[1]}`;
63
+ else if (uncWindowsPathMatch = p.match(UNC_WINDOWS_PATH_REGEXP))
64
+ p = `/unc/${uncWindowsPathMatch[1] ? `.dot/` : ``}${uncWindowsPathMatch[2]}`;
65
+ return p;
66
+ }
67
+
68
+ const builtinModules = new Set(Module.builtinModules || Object.keys(process.binding(`natives`)));
69
+ const isBuiltinModule = (request) => request.startsWith(`node:`) || builtinModules.has(request);
70
+ function readPackageScope(checkPath) {
71
+ const rootSeparatorIndex = checkPath.indexOf(npath.sep);
72
+ let separatorIndex;
73
+ do {
74
+ separatorIndex = checkPath.lastIndexOf(npath.sep);
75
+ checkPath = checkPath.slice(0, separatorIndex);
76
+ if (checkPath.endsWith(`${npath.sep}node_modules`))
77
+ return false;
78
+ const pjson = readPackage(checkPath + npath.sep);
79
+ if (pjson) {
80
+ return {
81
+ data: pjson,
82
+ path: checkPath
83
+ };
84
+ }
85
+ } while (separatorIndex > rootSeparatorIndex);
86
+ return false;
87
+ }
88
+ function readPackage(requestPath) {
89
+ const jsonPath = npath.resolve(requestPath, `package.json`);
90
+ if (!fs.existsSync(jsonPath))
91
+ return null;
92
+ return JSON.parse(fs.readFileSync(jsonPath, `utf8`));
93
+ }
94
+
95
+ const [major, minor] = process.versions.node.split(`.`).map((value) => parseInt(value, 10));
96
+ const HAS_CONSOLIDATED_HOOKS = major > 16 || major === 16 && minor >= 12;
97
+ const HAS_UNFLAGGED_JSON_MODULES = major > 17 || major === 17 && minor >= 5 || major === 16 && minor >= 15;
98
+ const HAS_JSON_IMPORT_ASSERTION_REQUIREMENT = major > 17 || major === 17 && minor >= 1 || major === 16 && minor > 14;
99
+
100
+ async function tryReadFile(path2) {
101
+ try {
102
+ return await fs.promises.readFile(path2, `utf8`);
103
+ } catch (error) {
104
+ if (error.code === `ENOENT`)
105
+ return null;
106
+ throw error;
107
+ }
108
+ }
109
+ function tryParseURL(str, base) {
110
+ try {
111
+ return new URL(str, base);
112
+ } catch {
113
+ return null;
114
+ }
115
+ }
116
+ let entrypointPath = null;
117
+ function setEntrypointPath(file) {
118
+ entrypointPath = file;
119
+ }
120
+ function getFileFormat(filepath) {
121
+ var _a, _b;
122
+ const ext = path.extname(filepath);
123
+ switch (ext) {
124
+ case `.mjs`: {
125
+ return `module`;
126
+ }
127
+ case `.cjs`: {
128
+ return `commonjs`;
129
+ }
130
+ case `.wasm`: {
131
+ throw new Error(`Unknown file extension ".wasm" for ${filepath}`);
132
+ }
133
+ case `.json`: {
134
+ if (HAS_UNFLAGGED_JSON_MODULES)
135
+ return `json`;
136
+ throw new Error(`Unknown file extension ".json" for ${filepath}`);
137
+ }
138
+ case `.js`: {
139
+ const pkg = readPackageScope(filepath);
140
+ if (!pkg)
141
+ return `commonjs`;
142
+ return (_a = pkg.data.type) != null ? _a : `commonjs`;
143
+ }
144
+ default: {
145
+ if (entrypointPath !== filepath)
146
+ return null;
147
+ const pkg = readPackageScope(filepath);
148
+ if (!pkg)
149
+ return `commonjs`;
150
+ if (pkg.data.type === `module`)
151
+ return null;
152
+ return (_b = pkg.data.type) != null ? _b : `commonjs`;
153
+ }
154
+ }
155
+ }
156
+
157
+ async function getFormat$1(resolved, context, defaultGetFormat) {
158
+ const url = tryParseURL(resolved);
159
+ if ((url == null ? void 0 : url.protocol) !== `file:`)
160
+ return defaultGetFormat(resolved, context, defaultGetFormat);
161
+ const format = getFileFormat(fileURLToPath(url));
162
+ if (format) {
163
+ return {
164
+ format
165
+ };
166
+ }
167
+ return defaultGetFormat(resolved, context, defaultGetFormat);
168
+ }
169
+
170
+ async function getSource$1(urlString, context, defaultGetSource) {
171
+ const url = tryParseURL(urlString);
172
+ if ((url == null ? void 0 : url.protocol) !== `file:`)
173
+ return defaultGetSource(urlString, context, defaultGetSource);
174
+ return {
175
+ source: await fs.promises.readFile(fileURLToPath(url), `utf8`)
176
+ };
177
+ }
178
+
179
+ async function load$1(urlString, context, nextLoad) {
180
+ var _a;
181
+ const url = tryParseURL(urlString);
182
+ if ((url == null ? void 0 : url.protocol) !== `file:`)
183
+ return nextLoad(urlString, context, nextLoad);
184
+ const filePath = fileURLToPath(url);
185
+ const format = getFileFormat(filePath);
186
+ if (!format)
187
+ return nextLoad(urlString, context, nextLoad);
188
+ if (HAS_JSON_IMPORT_ASSERTION_REQUIREMENT && format === `json` && ((_a = context.importAssertions) == null ? void 0 : _a.type) !== `json`) {
189
+ const err = new TypeError(`[ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "${urlString}" needs an import assertion of type "json"`);
190
+ err.code = `ERR_IMPORT_ASSERTION_TYPE_MISSING`;
191
+ throw err;
192
+ }
193
+ return {
194
+ format,
195
+ source: await fs.promises.readFile(filePath, `utf8`),
196
+ shortCircuit: true
197
+ };
198
+ }
199
+
200
+ const pathRegExp = /^(?![a-zA-Z]:[\\/]|\\\\|\.{0,2}(?:\/|$))((?:node:)?(?:@[^/]+\/)?[^/]+)\/*(.*|)$/;
201
+ const isRelativeRegexp = /^\.{0,2}\//;
202
+ async function resolve$1(originalSpecifier, context, nextResolve) {
203
+ var _a;
204
+ const {findPnpApi} = moduleExports;
205
+ if (!findPnpApi || isBuiltinModule(originalSpecifier))
206
+ return nextResolve(originalSpecifier, context, nextResolve);
207
+ let specifier = originalSpecifier;
208
+ const url = tryParseURL(specifier, isRelativeRegexp.test(specifier) ? context.parentURL : void 0);
209
+ if (url) {
210
+ if (url.protocol !== `file:`)
211
+ return nextResolve(originalSpecifier, context, nextResolve);
212
+ specifier = fileURLToPath(url);
213
+ }
214
+ const {parentURL, conditions = []} = context;
215
+ const issuer = parentURL ? fileURLToPath(parentURL) : process.cwd();
216
+ const pnpapi = (_a = findPnpApi(issuer)) != null ? _a : url ? findPnpApi(specifier) : null;
217
+ if (!pnpapi)
218
+ return nextResolve(originalSpecifier, context, nextResolve);
219
+ const dependencyNameMatch = specifier.match(pathRegExp);
220
+ let allowLegacyResolve = false;
221
+ if (dependencyNameMatch) {
222
+ const [, dependencyName, subPath] = dependencyNameMatch;
223
+ if (subPath === ``) {
224
+ const resolved = pnpapi.resolveToUnqualified(`${dependencyName}/package.json`, issuer);
225
+ if (resolved) {
226
+ const content = await tryReadFile(resolved);
227
+ if (content) {
228
+ const pkg = JSON.parse(content);
229
+ allowLegacyResolve = pkg.exports == null;
230
+ }
231
+ }
232
+ }
233
+ }
234
+ const result = pnpapi.resolveRequest(specifier, issuer, {
235
+ conditions: new Set(conditions),
236
+ extensions: allowLegacyResolve ? void 0 : []
237
+ });
238
+ if (!result)
239
+ throw new Error(`Resolving '${specifier}' from '${issuer}' failed`);
240
+ const resultURL = pathToFileURL(result);
241
+ if (url) {
242
+ resultURL.search = url.search;
243
+ resultURL.hash = url.hash;
244
+ }
245
+ if (!parentURL)
246
+ setEntrypointPath(fileURLToPath(resultURL));
247
+ return {
248
+ url: resultURL.href,
249
+ shortCircuit: true
250
+ };
251
+ }
252
+
253
+ const binding = process.binding(`fs`);
254
+ const originalfstat = binding.fstat;
255
+ const ZIP_MASK = 4278190080;
256
+ const ZIP_MAGIC = 704643072;
257
+ binding.fstat = function(...args) {
258
+ const [fd, useBigint, req] = args;
259
+ if ((fd & ZIP_MASK) === ZIP_MAGIC && useBigint === false && req === void 0) {
260
+ try {
261
+ const stats = fs.fstatSync(fd);
262
+ return new Float64Array([
263
+ stats.dev,
264
+ stats.mode,
265
+ stats.nlink,
266
+ stats.uid,
267
+ stats.gid,
268
+ stats.rdev,
269
+ stats.blksize,
270
+ stats.ino,
271
+ stats.size,
272
+ stats.blocks
273
+ ]);
274
+ } catch {
275
+ }
276
+ }
277
+ return originalfstat.apply(this, args);
278
+ };
279
+
280
+ const resolve = resolve$1;
281
+ const getFormat = HAS_CONSOLIDATED_HOOKS ? void 0 : getFormat$1;
282
+ const getSource = HAS_CONSOLIDATED_HOOKS ? void 0 : getSource$1;
283
+ const load = HAS_CONSOLIDATED_HOOKS ? load$1 : void 0;
284
+
285
+ export { getFormat, getSource, load, resolve };
@@ -0,0 +1,6 @@
1
+ {
2
+ "recommendations": [
3
+ "arcanis.vscode-zipfs",
4
+ "esbenp.prettier-vscode"
5
+ ]
6
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "search.exclude": {
3
+ "**/.yarn": true,
4
+ "**/.pnp.*": true
5
+ },
6
+ "prettier.prettierPath": ".yarn/sdks/prettier/index.js",
7
+ "typescript.tsdk": ".yarn/sdks/typescript/lib",
8
+ "typescript.enablePromptUseWorkspaceTsdk": true
9
+ }
package/.yarnrc.yml ADDED
@@ -0,0 +1,5 @@
1
+ plugins:
2
+ - path: .yarn/plugins/yarn-up-all-plugin.cjs
3
+ spec: "https://github.com/e5mode/yarn-up-all/releases/download/1.1.0/index.js"
4
+
5
+ yarnPath: .yarn/releases/yarn-3.2.3.cjs
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/bin/cli.ts"],"names":[],"mappings":""}
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ /* Global Begin */
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ console.log(chalk_1.default.bgBlue(`BEGIN ${new Date()}`));
18
+ const dotenv_1 = __importDefault(require("dotenv"));
19
+ dotenv_1.default.config();
20
+ const path_1 = __importDefault(require("path"));
21
+ const base_model_1 = require("../database/base-model");
22
+ const db_1 = require("../database/db");
23
+ const smd_manager_1 = require("../smd/smd-manager");
24
+ const migrator_1 = require("../smd/migrator");
25
+ const syncer_1 = require("../syncer/syncer");
26
+ const fixture_manager_1 = require("../testing/fixture-manager");
27
+ let migrator;
28
+ let fixtureManager;
29
+ function bootstrap() {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ // appRootPath 셋업
32
+ const appRootPath = path_1.default.resolve(process.cwd(), "..");
33
+ syncer_1.Syncer.getInstance({
34
+ appRootPath,
35
+ });
36
+ yield db_1.DB.readKnexfile();
37
+ const [_0, _1, action, ...args] = process.argv;
38
+ switch (action) {
39
+ case "migrate":
40
+ yield migrate(args[0]);
41
+ break;
42
+ case "fixture":
43
+ yield fixture(args[0], args.slice(1));
44
+ break;
45
+ default:
46
+ throw new Error(`Unknown action ${action}`);
47
+ }
48
+ });
49
+ }
50
+ bootstrap().finally(() => __awaiter(void 0, void 0, void 0, function* () {
51
+ if (migrator) {
52
+ yield migrator.destroy();
53
+ }
54
+ if (fixtureManager) {
55
+ yield fixtureManager.destory();
56
+ }
57
+ yield base_model_1.BaseModel.destroy();
58
+ /* Global End */
59
+ console.log(chalk_1.default.bgBlue(`END ${new Date()}\n`));
60
+ }));
61
+ function migrate(subAction) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ yield smd_manager_1.SMDManager.autoload();
64
+ // migrator
65
+ migrator = new migrator_1.Migrator({
66
+ appRootPath: syncer_1.Syncer.getInstance().config.appRootPath,
67
+ knexfile: db_1.DB.getKnexfile(),
68
+ mode: "dev",
69
+ });
70
+ switch (subAction) {
71
+ case "run":
72
+ yield migrator.cleanUpDist();
73
+ yield migrator.run();
74
+ break;
75
+ case "rollback":
76
+ yield migrator.rollback();
77
+ break;
78
+ case "clear":
79
+ yield migrator.clearPendingList();
80
+ break;
81
+ case "reset":
82
+ yield migrator.resetAll();
83
+ break;
84
+ default:
85
+ throw new Error(`Unknown subAction - ${subAction}`);
86
+ }
87
+ });
88
+ }
89
+ function fixture(subAction, extras) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ yield smd_manager_1.SMDManager.autoload();
92
+ fixtureManager = new fixture_manager_1.FixtureManager();
93
+ switch (subAction) {
94
+ case "import":
95
+ if (!extras || Array.isArray(extras) === false || extras.length !== 2) {
96
+ throw new Error("Import 대상 smdId와 id가 필요합니다.");
97
+ }
98
+ const [smdId, idsString] = extras;
99
+ let ids = [];
100
+ if (idsString.includes(",")) {
101
+ ids = idsString
102
+ .split(",")
103
+ .map((idString) => Number(idString))
104
+ .filter((id) => Number.isNaN(id) === false);
105
+ }
106
+ else {
107
+ ids = [Number(idsString)];
108
+ }
109
+ if (smdId === undefined || idsString === undefined || ids.length === 0) {
110
+ throw new Error("잘못된 입력");
111
+ }
112
+ yield fixtureManager.importFixture(smdId, ids);
113
+ yield fixtureManager.sync();
114
+ break;
115
+ case "sync":
116
+ yield fixtureManager.sync();
117
+ break;
118
+ default:
119
+ throw new Error(`Unknown subAction - ${subAction}`);
120
+ }
121
+ });
122
+ }
123
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/bin/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,kBAAkB;AAClB,kDAA0B;AAC1B,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,SAAS,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;AAEjD,oDAA4B;AAC5B,gBAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,gDAAwB;AACxB,uDAAmD;AACnD,uCAAoC;AACpC,oDAAgD;AAChD,8CAA2C;AAC3C,6CAA0C;AAC1C,gEAA4D;AAE5D,IAAI,QAAkB,CAAC;AACvB,IAAI,cAA8B,CAAC;AAEnC,SAAe,SAAS;;QACtB,iBAAiB;QACjB,MAAM,WAAW,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;QACtD,eAAM,CAAC,WAAW,CAAC;YACjB,WAAW;SACZ,CAAC,CAAC;QACH,MAAM,OAAE,CAAC,YAAY,EAAE,CAAC;QAExB,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;QAC/C,QAAQ,MAAM,EAAE;YACd,KAAK,SAAS;gBACZ,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAAqB,CAAC,CAAC;gBAC3C,MAAM;YAC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C;gBAC5B,MAAM;YACR,KAAK,MAAM;gBACT,MAAM,cAAc,CAAC,IAAI,EAAE,CAAC;gBAC5B,MAAM;YACR;gBACE,MAAM,IAAI,KAAK,CAAC,uBAAuB,SAAS,EAAE,CAAC,CAAC;SACvD;IACH,CAAC;CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api/code-converters"), exports);
18
+ __exportStar(require("./api/context"), exports);
19
+ __exportStar(require("./api/decorators"), exports);
20
+ __exportStar(require("./api/init"), exports);
21
+ __exportStar(require("./database/base-model"), exports);
22
+ __exportStar(require("./database/db"), exports);
23
+ __exportStar(require("./database/upsert-builder"), exports);
24
+ __exportStar(require("./exceptions/error-handler"), exports);
25
+ __exportStar(require("./exceptions/so-exceptions"), exports);
26
+ __exportStar(require("./smd/smd-manager"), exports);
27
+ __exportStar(require("./smd/smd-utils"), exports);
28
+ __exportStar(require("./syncer/syncer"), exports);
29
+ __exportStar(require("./testing/fixture-manager"), exports);
30
+ __exportStar(require("./types/types"), exports);
31
+ __exportStar(require("./utils/controller"), exports);
32
+ __exportStar(require("./utils/model"), exports);
33
+ __exportStar(require("./utils/utils"), exports);
34
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "sonamu",
3
+ "version": "0.0.1",
4
+ "description": "Sonamu — TypeScript Fullstack API Framework",
5
+ "keywords": [
6
+ "typescript",
7
+ "framework",
8
+ "orm"
9
+ ],
10
+ "main": "dist/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "license": "MIT",
13
+ "author": {
14
+ "name": "Minsang Kim",
15
+ "email": "minsangk@me.com",
16
+ "url": "https://twitter.com/minsangk"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/ping-alive/sonamu.git"
21
+ },
22
+ "bin": "./dist/bin/cli.js",
23
+ "dependencies": {
24
+ "chalk": "^4.1.2",
25
+ "dotenv": "^16.0.2",
26
+ "fast-deep-equal": "^3.1.3",
27
+ "fastify": "^4.5.3",
28
+ "fs-extra": "^10.1.0",
29
+ "glob": "^8.0.3",
30
+ "inflection": "^1.13.2",
31
+ "knex": "^2.3.0",
32
+ "lodash": "^4.17.21",
33
+ "luxon": "^3.0.3",
34
+ "mysql2": "^2.3.3",
35
+ "prompts": "^2.4.2",
36
+ "qs": "^6.11.0",
37
+ "uuid": "^8.3.2",
38
+ "zod": "^3.18.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/fs-extra": "^9.0.13",
42
+ "@types/glob": "^8.0.0",
43
+ "@types/inflection": "^1.13.0",
44
+ "@types/jest": "^29.0.0",
45
+ "@types/lodash": "^4.14.184",
46
+ "@types/luxon": "^3.0.1",
47
+ "@types/node": "^18.7.15",
48
+ "@types/prettier": "^2.7.0",
49
+ "@types/prompts": "^2.0.14",
50
+ "@types/qs": "^6.9.7",
51
+ "@types/uuid": "^8.3.4",
52
+ "jest": "^29.0.2",
53
+ "nodemon": "^2.0.19",
54
+ "prettier": "^2.7.1",
55
+ "source-map-support": "^0.5.21",
56
+ "ts-jest": "^28.0.8",
57
+ "typescript": "^4.8.2"
58
+ },
59
+ "packageManager": "yarn@3.2.3"
60
+ }
@@ -0,0 +1,72 @@
1
+ import { z } from "zod";
2
+
3
+ // optional, nullable 무관하게 ZodNumber 체크
4
+ function isZodNumberAnyway(zodType: z.ZodType<any>) {
5
+ if (zodType instanceof z.ZodNumber) {
6
+ return true;
7
+ } else if (
8
+ zodType instanceof z.ZodNullable &&
9
+ zodType._def.innerType instanceof z.ZodNumber
10
+ ) {
11
+ return true;
12
+ } else if (
13
+ zodType instanceof z.ZodOptional &&
14
+ zodType._def.innerType instanceof z.ZodNumber
15
+ ) {
16
+ } else if (
17
+ zodType instanceof z.ZodOptional &&
18
+ zodType._def.innerType instanceof z.ZodOptional &&
19
+ zodType._type.def.innerType instanceof z.ZodNumber
20
+ ) {
21
+ return true;
22
+ }
23
+
24
+ return false;
25
+ }
26
+
27
+ // ZodType을 이용해 raw를 Type Coercing
28
+ export function caster(zodType: z.ZodType<any>, raw: any): any {
29
+ if (isZodNumberAnyway(zodType) && typeof raw === "string") {
30
+ // number
31
+ return Number(raw);
32
+ } else if (
33
+ zodType instanceof z.ZodUnion &&
34
+ zodType.options.some((opt: z.ZodType<any>) => isZodNumberAnyway(opt))
35
+ ) {
36
+ // zArrayable Number 케이스 처리
37
+ if (Array.isArray(raw)) {
38
+ const numType = zodType.options.find(
39
+ (opt: z.ZodType<any>) => opt instanceof z.ZodNumber
40
+ );
41
+ return raw.map((elem: any) => caster(numType, elem));
42
+ } else {
43
+ return Number(raw);
44
+ }
45
+ } else if (
46
+ zodType instanceof z.ZodBoolean &&
47
+ (raw === "true" || raw === "false")
48
+ ) {
49
+ // boolean
50
+ return raw === "true";
51
+ } else if (zodType instanceof z.ZodArray) {
52
+ // array
53
+ return raw.map((elem: any) => caster(zodType.element, elem));
54
+ } else if (zodType instanceof z.ZodObject && typeof raw === "object") {
55
+ // object
56
+ return Object.keys(raw).reduce((r, rawKey) => {
57
+ r[rawKey] = caster(zodType.shape[rawKey], raw[rawKey]);
58
+ return r;
59
+ }, {} as any);
60
+ } else if (zodType instanceof z.ZodOptional) {
61
+ return caster(zodType._def.innerType, raw);
62
+ } else {
63
+ // 나머지는 처리 안함
64
+ return raw;
65
+ }
66
+ }
67
+
68
+ export function fastifyCaster(schema: z.ZodObject<any>) {
69
+ return z.preprocess((raw: any) => {
70
+ return caster(schema, raw);
71
+ }, schema);
72
+ }