@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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/lib/index.js +3 -0
  3. package/lib/index.js.map +1 -0
  4. package/lib/jsonschema/JsonSchema.js +180 -0
  5. package/lib/jsonschema/JsonSchema.js.map +1 -0
  6. package/lib/jsonschema/index.js +2 -0
  7. package/lib/jsonschema/index.js.map +1 -0
  8. package/lib/jsonschema/types.d.js +3 -0
  9. package/lib/jsonschema/types.d.js.map +1 -0
  10. package/lib/meta/defineInit.js +42 -0
  11. package/lib/meta/defineInit.js.map +1 -0
  12. package/lib/meta/defineMetadata.js +30 -0
  13. package/lib/meta/defineMetadata.js.map +1 -0
  14. package/lib/meta/index.js +3 -0
  15. package/lib/meta/index.js.map +1 -0
  16. package/lib/normalizePagination.js +14 -0
  17. package/lib/normalizePagination.js.map +1 -0
  18. package/lib/parseSort.js +91 -0
  19. package/lib/parseSort.js.map +1 -0
  20. package/lib/password/PHC.js +200 -0
  21. package/lib/password/PHC.js.map +1 -0
  22. package/lib/password/Password.js +83 -0
  23. package/lib/password/Password.js.map +1 -0
  24. package/lib/password/createArgon2PasswordAlgorithm.js +53 -0
  25. package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -0
  26. package/lib/password/createBase64PasswordAlgorithm.js +14 -0
  27. package/lib/password/createBase64PasswordAlgorithm.js.map +1 -0
  28. package/lib/password/createBcryptPasswordAlgorithm.js +20 -0
  29. package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -0
  30. package/lib/password/createPBKDF2PasswordAlgorithm.js +54 -0
  31. package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -0
  32. package/lib/password/createScryptPasswordAlgorithm.js +66 -0
  33. package/lib/password/createScryptPasswordAlgorithm.js.map +1 -0
  34. package/lib/password/index.js +6 -0
  35. package/lib/password/index.js.map +1 -0
  36. package/lib/password/server/index.js +2 -0
  37. package/lib/password/server/index.js.map +1 -0
  38. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +85 -0
  39. package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +1 -0
  40. package/package.json +56 -0
  41. package/src/index.ts +2 -0
  42. package/src/jsonschema/JsonSchema.test.ts +27 -0
  43. package/src/jsonschema/JsonSchema.ts +197 -0
  44. package/src/jsonschema/index.ts +2 -0
  45. package/src/jsonschema/types.d.ts +173 -0
  46. package/src/meta/defineInit.ts +68 -0
  47. package/src/meta/defineMetadata.test.ts +15 -0
  48. package/src/meta/defineMetadata.ts +57 -0
  49. package/src/meta/index.ts +3 -0
  50. package/src/normalizePagination.ts +25 -0
  51. package/src/parseSort.test.ts +41 -0
  52. package/src/parseSort.ts +115 -0
  53. package/src/password/PHC.test.ts +317 -0
  54. package/src/password/PHC.ts +247 -0
  55. package/src/password/Password.test.ts +58 -0
  56. package/src/password/Password.ts +113 -0
  57. package/src/password/createArgon2PasswordAlgorithm.ts +80 -0
  58. package/src/password/createBase64PasswordAlgorithm.ts +14 -0
  59. package/src/password/createBcryptPasswordAlgorithm.ts +30 -0
  60. package/src/password/createPBKDF2PasswordAlgorithm.ts +73 -0
  61. package/src/password/createScryptPasswordAlgorithm.ts +72 -0
  62. package/src/password/index.ts +5 -0
  63. package/src/password/server/index.ts +1 -0
  64. 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
+ }