mock-fried 1.0.0
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/README.md +229 -0
- package/dist/module.d.mts +125 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +160 -0
- package/dist/runtime/components/ApiExplorer.d.vue.ts +7 -0
- package/dist/runtime/components/ApiExplorer.vue +168 -0
- package/dist/runtime/components/ApiExplorer.vue.d.ts +7 -0
- package/dist/runtime/components/EndpointCard.d.vue.ts +24 -0
- package/dist/runtime/components/EndpointCard.vue +173 -0
- package/dist/runtime/components/EndpointCard.vue.d.ts +24 -0
- package/dist/runtime/components/ResponseViewer.d.vue.ts +16 -0
- package/dist/runtime/components/ResponseViewer.vue +78 -0
- package/dist/runtime/components/ResponseViewer.vue.d.ts +16 -0
- package/dist/runtime/components/RpcMethodCard.d.vue.ts +20 -0
- package/dist/runtime/components/RpcMethodCard.vue +129 -0
- package/dist/runtime/components/RpcMethodCard.vue.d.ts +20 -0
- package/dist/runtime/composables/index.d.ts +1 -0
- package/dist/runtime/composables/index.js +1 -0
- package/dist/runtime/composables/useApi.d.ts +19 -0
- package/dist/runtime/composables/useApi.js +5 -0
- package/dist/runtime/plugin.d.ts +7 -0
- package/dist/runtime/plugin.js +75 -0
- package/dist/runtime/server/handlers/openapi.d.ts +2 -0
- package/dist/runtime/server/handlers/openapi.js +346 -0
- package/dist/runtime/server/handlers/rpc.d.ts +7 -0
- package/dist/runtime/server/handlers/rpc.js +140 -0
- package/dist/runtime/server/handlers/schema.d.ts +7 -0
- package/dist/runtime/server/handlers/schema.js +190 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/server/utils/client-parser.d.ts +13 -0
- package/dist/runtime/server/utils/client-parser.js +272 -0
- package/dist/runtime/server/utils/mock/client-generator.d.ts +108 -0
- package/dist/runtime/server/utils/mock/client-generator.js +346 -0
- package/dist/runtime/server/utils/mock/index.d.ts +9 -0
- package/dist/runtime/server/utils/mock/index.js +38 -0
- package/dist/runtime/server/utils/mock/openapi-generator.d.ts +4 -0
- package/dist/runtime/server/utils/mock/openapi-generator.js +118 -0
- package/dist/runtime/server/utils/mock/pagination/cursor-manager.d.ts +38 -0
- package/dist/runtime/server/utils/mock/pagination/cursor-manager.js +129 -0
- package/dist/runtime/server/utils/mock/pagination/index.d.ts +8 -0
- package/dist/runtime/server/utils/mock/pagination/index.js +18 -0
- package/dist/runtime/server/utils/mock/pagination/page-manager.d.ts +41 -0
- package/dist/runtime/server/utils/mock/pagination/page-manager.js +96 -0
- package/dist/runtime/server/utils/mock/pagination/snapshot-store.d.ts +64 -0
- package/dist/runtime/server/utils/mock/pagination/snapshot-store.js +125 -0
- package/dist/runtime/server/utils/mock/pagination/types.d.ts +141 -0
- package/dist/runtime/server/utils/mock/pagination/types.js +14 -0
- package/dist/runtime/server/utils/mock/proto-generator.d.ts +12 -0
- package/dist/runtime/server/utils/mock/proto-generator.js +67 -0
- package/dist/runtime/server/utils/mock/shared.d.ts +69 -0
- package/dist/runtime/server/utils/mock/shared.js +150 -0
- package/dist/runtime/server/utils/mock-generator.d.ts +9 -0
- package/dist/runtime/server/utils/mock-generator.js +30 -0
- package/dist/types.d.mts +9 -0
- package/package.json +73 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
export function hashString(str) {
|
|
2
|
+
let hash = 0;
|
|
3
|
+
for (let i = 0; i < str.length; i++) {
|
|
4
|
+
const char = str.charCodeAt(i);
|
|
5
|
+
hash = (hash << 5) - hash + char;
|
|
6
|
+
hash = hash & hash;
|
|
7
|
+
}
|
|
8
|
+
return Math.abs(hash);
|
|
9
|
+
}
|
|
10
|
+
export function seededRandom(seed) {
|
|
11
|
+
let currentSeed = seed;
|
|
12
|
+
return () => {
|
|
13
|
+
currentSeed = currentSeed * 1103515245 + 12345 & 2147483647;
|
|
14
|
+
return currentSeed / 2147483647;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export class SeededRandom {
|
|
18
|
+
seed;
|
|
19
|
+
constructor(seed) {
|
|
20
|
+
this.seed = typeof seed === "string" ? hashString(seed) : seed;
|
|
21
|
+
}
|
|
22
|
+
next() {
|
|
23
|
+
this.seed = this.seed * 1103515245 + 12345 & 2147483647;
|
|
24
|
+
return this.seed / 2147483647;
|
|
25
|
+
}
|
|
26
|
+
nextInt(min, max) {
|
|
27
|
+
return Math.floor(this.next() * (max - min + 1)) + min;
|
|
28
|
+
}
|
|
29
|
+
pick(array) {
|
|
30
|
+
return array[this.nextInt(0, array.length - 1)];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 주어진 확률로 true 반환
|
|
34
|
+
*/
|
|
35
|
+
chance(probability) {
|
|
36
|
+
return this.next() < probability;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* UUID v4 형식 문자열 생성 (결정론적)
|
|
40
|
+
*/
|
|
41
|
+
uuid() {
|
|
42
|
+
const hex = "0123456789abcdef";
|
|
43
|
+
let uuid = "";
|
|
44
|
+
for (let i = 0; i < 36; i++) {
|
|
45
|
+
if (i === 8 || i === 13 || i === 18 || i === 23) {
|
|
46
|
+
uuid += "-";
|
|
47
|
+
} else if (i === 14) {
|
|
48
|
+
uuid += "4";
|
|
49
|
+
} else if (i === 19) {
|
|
50
|
+
uuid += hex[this.nextInt(8, 11)];
|
|
51
|
+
} else {
|
|
52
|
+
uuid += hex[this.nextInt(0, 15)];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return uuid;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* ULID 형식 문자열 생성 (결정론적)
|
|
59
|
+
* 26자리 Base32 인코딩 (Crockford's Base32)
|
|
60
|
+
*/
|
|
61
|
+
ulid() {
|
|
62
|
+
const ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
63
|
+
let timestamp = "";
|
|
64
|
+
for (let i = 0; i < 10; i++) {
|
|
65
|
+
timestamp += ENCODING[this.nextInt(0, 31)];
|
|
66
|
+
}
|
|
67
|
+
let random = "";
|
|
68
|
+
for (let i = 0; i < 16; i++) {
|
|
69
|
+
random += ENCODING[this.nextInt(0, 31)];
|
|
70
|
+
}
|
|
71
|
+
return timestamp + random;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* NanoID 형식 문자열 생성 (결정론적, 21자리)
|
|
75
|
+
*/
|
|
76
|
+
nanoid(size = 21) {
|
|
77
|
+
const ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-";
|
|
78
|
+
let id = "";
|
|
79
|
+
for (let i = 0; i < size; i++) {
|
|
80
|
+
id += ALPHABET[this.nextInt(0, ALPHABET.length - 1)];
|
|
81
|
+
}
|
|
82
|
+
return id;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 짧은 해시 ID 생성 (결정론적, 8자리)
|
|
86
|
+
*/
|
|
87
|
+
hashId(size = 8) {
|
|
88
|
+
const hex = "0123456789abcdef";
|
|
89
|
+
let id = "";
|
|
90
|
+
for (let i = 0; i < size; i++) {
|
|
91
|
+
id += hex[this.nextInt(0, 15)];
|
|
92
|
+
}
|
|
93
|
+
return id;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
export function generateId(prefix, seed) {
|
|
97
|
+
const rng = new SeededRandom(seed);
|
|
98
|
+
return `${prefix}-${rng.uuid().slice(0, 8)}`;
|
|
99
|
+
}
|
|
100
|
+
export function generateSnapshotId() {
|
|
101
|
+
return `snap-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
102
|
+
}
|
|
103
|
+
export const DEFAULT_ID_CONFIG = {
|
|
104
|
+
fieldPatterns: ["id", "uuid", "key", "_id"],
|
|
105
|
+
fieldSuffixes: ["_id", "Id", "_key", "Key", "_uuid", "Uuid"],
|
|
106
|
+
format: "uuid",
|
|
107
|
+
// 기본 포맷: uuid
|
|
108
|
+
prefix: "id-",
|
|
109
|
+
fieldOverrides: {}
|
|
110
|
+
};
|
|
111
|
+
export function isIdField(fieldName, config = DEFAULT_ID_CONFIG) {
|
|
112
|
+
const patterns = config.fieldPatterns ?? DEFAULT_ID_CONFIG.fieldPatterns;
|
|
113
|
+
const suffixes = config.fieldSuffixes ?? DEFAULT_ID_CONFIG.fieldSuffixes;
|
|
114
|
+
if (patterns.includes(fieldName)) return true;
|
|
115
|
+
if (suffixes.some((suffix) => fieldName.endsWith(suffix))) return true;
|
|
116
|
+
if (config.fieldOverrides?.[fieldName]) return true;
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
export function generateIdValue(fieldName, index, seed, config = DEFAULT_ID_CONFIG) {
|
|
120
|
+
const rng = new SeededRandom(`${seed}-${fieldName}-${index}`);
|
|
121
|
+
const override = config.fieldOverrides?.[fieldName];
|
|
122
|
+
if (override) {
|
|
123
|
+
const fieldConfig = typeof override === "string" ? { format: override } : override;
|
|
124
|
+
if (fieldConfig.fixedValue !== void 0) {
|
|
125
|
+
return fieldConfig.fixedValue;
|
|
126
|
+
}
|
|
127
|
+
return generateByFormat(fieldConfig.format, index, rng, fieldConfig.prefix);
|
|
128
|
+
}
|
|
129
|
+
const format = config.format ?? DEFAULT_ID_CONFIG.format;
|
|
130
|
+
const prefix = config.prefix ?? DEFAULT_ID_CONFIG.prefix;
|
|
131
|
+
return generateByFormat(format, index, rng, prefix);
|
|
132
|
+
}
|
|
133
|
+
export function generateByFormat(format, index, rng, prefix) {
|
|
134
|
+
switch (format) {
|
|
135
|
+
case "sequential":
|
|
136
|
+
return `${prefix ?? "id-"}${index + 1}`;
|
|
137
|
+
case "numeric":
|
|
138
|
+
return index + 1;
|
|
139
|
+
case "uuid":
|
|
140
|
+
return rng.uuid();
|
|
141
|
+
case "ulid":
|
|
142
|
+
return rng.ulid();
|
|
143
|
+
case "nanoid":
|
|
144
|
+
return rng.nanoid();
|
|
145
|
+
case "hash":
|
|
146
|
+
return rng.hashId();
|
|
147
|
+
default:
|
|
148
|
+
return rng.uuid();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock 데이터 생성 유틸리티
|
|
3
|
+
*
|
|
4
|
+
* @deprecated 직접 import 대신 'mock/' 모듈에서 import 하세요.
|
|
5
|
+
* 예: import { SchemaMockGenerator } from './mock'
|
|
6
|
+
*
|
|
7
|
+
* 이 파일은 하위 호환성을 위해 유지됩니다.
|
|
8
|
+
*/
|
|
9
|
+
export { hashString, seededRandom, SeededRandom, generateId, generateSnapshotId, DEFAULT_ID_CONFIG, isIdField, generateIdValue, generateByFormat, generateMockValueForProtoField, generateMockMessage, deriveSeedFromRequest, generateMockFromSchema, inferValueByFieldName, generateValueByType, inferTypeFromFieldName, SchemaMockGenerator, extractDataModelName, type ResponseTypeInfo, type CursorPayload, type PaginationSnapshot, type PagePaginationOptions, type PagePaginationResult, type CursorPaginationOptions, type CursorPaginationResult, type PaginationConfig, type CursorConfig, DEFAULT_PAGINATION_CONFIG, DEFAULT_CURSOR_CONFIG, SnapshotStore, getSnapshotStore, resetSnapshotStore, CursorPaginationManager, encodeCursor, decodeCursor, isCursorExpired, PagePaginationManager, } from './mock/index.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export {
|
|
2
|
+
hashString,
|
|
3
|
+
seededRandom,
|
|
4
|
+
SeededRandom,
|
|
5
|
+
generateId,
|
|
6
|
+
generateSnapshotId,
|
|
7
|
+
DEFAULT_ID_CONFIG,
|
|
8
|
+
isIdField,
|
|
9
|
+
generateIdValue,
|
|
10
|
+
generateByFormat,
|
|
11
|
+
generateMockValueForProtoField,
|
|
12
|
+
generateMockMessage,
|
|
13
|
+
deriveSeedFromRequest,
|
|
14
|
+
generateMockFromSchema,
|
|
15
|
+
inferValueByFieldName,
|
|
16
|
+
generateValueByType,
|
|
17
|
+
inferTypeFromFieldName,
|
|
18
|
+
SchemaMockGenerator,
|
|
19
|
+
extractDataModelName,
|
|
20
|
+
DEFAULT_PAGINATION_CONFIG,
|
|
21
|
+
DEFAULT_CURSOR_CONFIG,
|
|
22
|
+
SnapshotStore,
|
|
23
|
+
getSnapshotStore,
|
|
24
|
+
resetSnapshotStore,
|
|
25
|
+
CursorPaginationManager,
|
|
26
|
+
encodeCursor,
|
|
27
|
+
decodeCursor,
|
|
28
|
+
isCursorExpired,
|
|
29
|
+
PagePaginationManager
|
|
30
|
+
} from "./mock/index.js";
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
2
|
+
|
|
3
|
+
import type { default as Module } from './module.mjs'
|
|
4
|
+
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
|
+
|
|
7
|
+
export { default } from './module.mjs'
|
|
8
|
+
|
|
9
|
+
export { type MockModuleOptions, type OpenApiClientConfig } from './module.mjs'
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mock-fried",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Nuxt3 Mock API Module - OpenAPI & Protobuf RPC Mock Server",
|
|
5
|
+
"repository": "your-org/mock-fried",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"packageManager": "yarn@4.12.0",
|
|
9
|
+
"workspaces": [
|
|
10
|
+
"playground-openapi",
|
|
11
|
+
"playground-proto",
|
|
12
|
+
"packages/*"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/types.d.mts",
|
|
17
|
+
"import": "./dist/module.mjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"main": "./dist/module.mjs",
|
|
21
|
+
"typesVersions": {
|
|
22
|
+
"*": {
|
|
23
|
+
".": [
|
|
24
|
+
"./dist/types.d.mts"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"prepack": "nuxt-module-build build",
|
|
33
|
+
"dev": "yarn dev:prepare && nuxi dev playground-openapi",
|
|
34
|
+
"dev:openapi": "yarn dev:prepare && nuxi dev playground-openapi",
|
|
35
|
+
"dev:proto": "yarn dev:prepare:proto && nuxi dev playground-proto",
|
|
36
|
+
"dev:build": "nuxi build playground-openapi",
|
|
37
|
+
"dev:build:proto": "nuxi build playground-proto",
|
|
38
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground-openapi",
|
|
39
|
+
"dev:prepare:proto": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground-proto",
|
|
40
|
+
"release": "yarn lint && yarn test && yarn prepack && changelogen --release && yarn npm publish && git push --follow-tags",
|
|
41
|
+
"lint": "eslint .",
|
|
42
|
+
"lint:fix": "eslint . --fix",
|
|
43
|
+
"format": "prettier --write .",
|
|
44
|
+
"format:check": "prettier --check .",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"test:watch": "vitest watch",
|
|
47
|
+
"test:types": "vue-tsc --noEmit && cd playground-openapi && vue-tsc --noEmit"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@grpc/grpc-js": "^1.12.0",
|
|
51
|
+
"@grpc/proto-loader": "^0.7.13",
|
|
52
|
+
"@nuxt/kit": "^4.2.2",
|
|
53
|
+
"js-yaml": "^4.1.0",
|
|
54
|
+
"openapi-backend": "^5.10.6",
|
|
55
|
+
"pathe": "^2.0.2"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@nuxt/devtools": "^3.1.1",
|
|
59
|
+
"@nuxt/eslint-config": "^1.12.1",
|
|
60
|
+
"@nuxt/module-builder": "^1.0.2",
|
|
61
|
+
"@nuxt/schema": "^4.2.2",
|
|
62
|
+
"@nuxt/test-utils": "^3.21.0",
|
|
63
|
+
"@types/js-yaml": "^4.0.9",
|
|
64
|
+
"@types/node": "latest",
|
|
65
|
+
"changelogen": "^0.6.2",
|
|
66
|
+
"eslint": "^9.39.2",
|
|
67
|
+
"nuxt": "^4.2.2",
|
|
68
|
+
"prettier": "^3.5.3",
|
|
69
|
+
"typescript": "~5.9.3",
|
|
70
|
+
"vitest": "^4.0.16",
|
|
71
|
+
"vue-tsc": "^3.2.1"
|
|
72
|
+
}
|
|
73
|
+
}
|