@wener/common 1.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.
- package/LICENSE +21 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -0
- package/lib/jsonschema/JsonSchema.js +180 -0
- package/lib/jsonschema/JsonSchema.js.map +1 -0
- package/lib/jsonschema/index.js +2 -0
- package/lib/jsonschema/index.js.map +1 -0
- package/lib/jsonschema/types.d.js +3 -0
- package/lib/jsonschema/types.d.js.map +1 -0
- package/lib/meta/defineInit.js +42 -0
- package/lib/meta/defineInit.js.map +1 -0
- package/lib/meta/defineMetadata.js +30 -0
- package/lib/meta/defineMetadata.js.map +1 -0
- package/lib/meta/index.js +3 -0
- package/lib/meta/index.js.map +1 -0
- package/lib/normalizePagination.js +14 -0
- package/lib/normalizePagination.js.map +1 -0
- package/lib/parseSort.js +91 -0
- package/lib/parseSort.js.map +1 -0
- package/lib/password/PHC.js +200 -0
- package/lib/password/PHC.js.map +1 -0
- package/lib/password/Password.js +83 -0
- package/lib/password/Password.js.map +1 -0
- package/lib/password/createArgon2PasswordAlgorithm.js +53 -0
- package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -0
- package/lib/password/createBase64PasswordAlgorithm.js +14 -0
- package/lib/password/createBase64PasswordAlgorithm.js.map +1 -0
- package/lib/password/createBcryptPasswordAlgorithm.js +20 -0
- package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -0
- package/lib/password/createPBKDF2PasswordAlgorithm.js +54 -0
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -0
- package/lib/password/createScryptPasswordAlgorithm.js +66 -0
- package/lib/password/createScryptPasswordAlgorithm.js.map +1 -0
- package/lib/password/index.js +6 -0
- package/lib/password/index.js.map +1 -0
- package/lib/password/server/index.js +2 -0
- package/lib/password/server/index.js.map +1 -0
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +85 -0
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +1 -0
- package/package.json +56 -0
- package/src/index.ts +2 -0
- package/src/jsonschema/JsonSchema.test.ts +27 -0
- package/src/jsonschema/JsonSchema.ts +197 -0
- package/src/jsonschema/index.ts +2 -0
- package/src/jsonschema/types.d.ts +173 -0
- package/src/meta/defineInit.ts +68 -0
- package/src/meta/defineMetadata.test.ts +15 -0
- package/src/meta/defineMetadata.ts +57 -0
- package/src/meta/index.ts +3 -0
- package/src/normalizePagination.ts +25 -0
- package/src/parseSort.test.ts +41 -0
- package/src/parseSort.ts +115 -0
- package/src/password/PHC.test.ts +317 -0
- package/src/password/PHC.ts +247 -0
- package/src/password/Password.test.ts +58 -0
- package/src/password/Password.ts +113 -0
- package/src/password/createArgon2PasswordAlgorithm.ts +80 -0
- package/src/password/createBase64PasswordAlgorithm.ts +14 -0
- package/src/password/createBcryptPasswordAlgorithm.ts +30 -0
- package/src/password/createPBKDF2PasswordAlgorithm.ts +73 -0
- package/src/password/createScryptPasswordAlgorithm.ts +72 -0
- package/src/password/index.ts +5 -0
- package/src/password/server/index.ts +1 -0
- package/src/tools/renderJsonSchemaToMarkdownDoc.ts +93 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { TObject, TSchema } from '@sinclair/typebox';
|
|
2
|
+
|
|
3
|
+
export function renderJsonSchemaToMarkdownDoc(rootSchema: any) {
|
|
4
|
+
// markdown
|
|
5
|
+
const out: string[] = [];
|
|
6
|
+
const all = new Set();
|
|
7
|
+
const pending: TSchema[] = [];
|
|
8
|
+
|
|
9
|
+
const addObject = (o: TSchema) => {
|
|
10
|
+
if (all.has(o.$id)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
all.add(o.$id);
|
|
14
|
+
pending.push(o);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const writeObjectProps = (T: TObject, { prefix = '' }: { prefix?: string } = {}) => {
|
|
18
|
+
if (!T?.properties) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
for (const [name, schema] of Object.entries(T.properties)) {
|
|
22
|
+
let typ = schema.$id || schema.type;
|
|
23
|
+
|
|
24
|
+
if (typ === 'array') {
|
|
25
|
+
typ = `${schema.items.$id || schema.items.type}[]`;
|
|
26
|
+
if (schema.items.$id) {
|
|
27
|
+
addObject(schema.items);
|
|
28
|
+
}
|
|
29
|
+
} else if (schema.$id) {
|
|
30
|
+
addObject(schema);
|
|
31
|
+
}
|
|
32
|
+
if (!typ) {
|
|
33
|
+
if ('anyOf' in schema) {
|
|
34
|
+
typ = 'enum';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
out.push(`| ${prefix}${name} | ${typ} | ${schema.title || schema.description || ''} |`);
|
|
39
|
+
|
|
40
|
+
if (typ === 'object') {
|
|
41
|
+
writeObjectProps(schema as TObject, { prefix: `${prefix}${name}.` });
|
|
42
|
+
} else if (schema.type === 'array') {
|
|
43
|
+
if (schema.items.type === 'object' && !schema.items.$id) {
|
|
44
|
+
writeObjectProps(schema.items as TObject, { prefix: `${prefix}${name}[].` });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const writeObject = (T: TObject) => {
|
|
50
|
+
out.push(`### ${T.title || T.$id}`);
|
|
51
|
+
out.push(`
|
|
52
|
+
| $id | 名字 |
|
|
53
|
+
| --- | --- |
|
|
54
|
+
| ${T.$id || ''} | ${T.title || ''} |
|
|
55
|
+
`);
|
|
56
|
+
if (T.description) {
|
|
57
|
+
out.push('');
|
|
58
|
+
out.push(`> ${T.description}`);
|
|
59
|
+
out.push('');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
out.push(`| 名字 | 类型 | 说明 |`);
|
|
63
|
+
out.push(`| --- | --- | --- |`);
|
|
64
|
+
|
|
65
|
+
writeObjectProps(T);
|
|
66
|
+
|
|
67
|
+
out.push('');
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
writeObject(rootSchema);
|
|
71
|
+
|
|
72
|
+
for (const schema of pending) {
|
|
73
|
+
if (schema.type === 'object') {
|
|
74
|
+
writeObject(schema as TObject);
|
|
75
|
+
} else if ('anyOf' in schema) {
|
|
76
|
+
out.push(`### ${schema.$id || schema.title}`);
|
|
77
|
+
out.push(`
|
|
78
|
+
| $id | 名字 |
|
|
79
|
+
| --- | --- |
|
|
80
|
+
| ${schema.$id || ''} | ${schema.title || ''} |
|
|
81
|
+
`);
|
|
82
|
+
|
|
83
|
+
out.push(`| 值 | 说明 |`);
|
|
84
|
+
out.push(`| --- | --- |`);
|
|
85
|
+
for (const item of schema.anyOf) {
|
|
86
|
+
out.push(`| ${item.const} | ${item.title || item.description || ''} |`);
|
|
87
|
+
}
|
|
88
|
+
out.push('');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return out.join('\n');
|
|
93
|
+
}
|