@wener/common 2.0.3 → 2.0.5
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/lib/ai/qwen3vl/utils.js.map +1 -1
- package/lib/cn/ChineseResidentIdNo.js +1 -1
- package/lib/cn/ChineseResidentIdNo.js.map +1 -1
- package/lib/cn/Mod11.js +1 -1
- package/lib/cn/Mod11.js.map +1 -1
- package/lib/consola/formatLogObject.js +5 -5
- package/lib/consola/formatLogObject.js.map +1 -1
- package/lib/data/maybeNumber.js +1 -1
- package/lib/data/maybeNumber.js.map +1 -1
- package/lib/data/types.d.js.map +1 -1
- package/lib/dayjs/formatDuration.js.map +1 -1
- package/lib/dayjs/resolveRelativeTime.js +9 -80
- package/lib/dayjs/resolveRelativeTime.js.map +1 -1
- package/lib/drain3/Drain.js +356 -0
- package/lib/drain3/Drain.js.map +1 -0
- package/lib/drain3/LogCluster.js +38 -0
- package/lib/drain3/LogCluster.js.map +1 -0
- package/lib/drain3/Node.js +39 -0
- package/lib/drain3/Node.js.map +1 -0
- package/lib/drain3/TemplateMiner.js +204 -0
- package/lib/drain3/TemplateMiner.js.map +1 -0
- package/lib/drain3/index.js +31 -0
- package/lib/drain3/index.js.map +1 -0
- package/lib/drain3/persistence/FilePersistence.js +24 -0
- package/lib/drain3/persistence/FilePersistence.js.map +1 -0
- package/lib/drain3/persistence/MemoryPersistence.js +18 -0
- package/lib/drain3/persistence/MemoryPersistence.js.map +1 -0
- package/lib/drain3/persistence/PersistenceHandler.js +5 -0
- package/lib/drain3/persistence/PersistenceHandler.js.map +1 -0
- package/lib/drain3/types.js +7 -0
- package/lib/drain3/types.js.map +1 -0
- package/lib/fs/IFileSystem.d.js.map +1 -1
- package/lib/fs/createBrowserFileSystem.js +4 -2
- package/lib/fs/createBrowserFileSystem.js.map +1 -1
- package/lib/fs/createMemoryFileSystem.js +7 -6
- package/lib/fs/createMemoryFileSystem.js.map +1 -1
- package/lib/fs/createSandboxFileSystem.js.map +1 -1
- package/lib/fs/createWebDavFileSystem.js +22 -5
- package/lib/fs/createWebDavFileSystem.js.map +1 -1
- package/lib/fs/createWebFileSystem.js +225 -0
- package/lib/fs/createWebFileSystem.js.map +1 -0
- package/lib/fs/findMimeType.js +1 -1
- package/lib/fs/findMimeType.js.map +1 -1
- package/lib/fs/index.js +1 -1
- package/lib/fs/index.js.map +1 -1
- package/lib/fs/minio/createMinioFileSystem.js +974 -0
- package/lib/fs/minio/createMinioFileSystem.js.map +1 -0
- package/lib/fs/minio/index.js +2 -0
- package/lib/fs/minio/index.js.map +1 -0
- package/lib/fs/orpc/createContractClientFileSystem.js +3 -3
- package/lib/fs/orpc/createContractClientFileSystem.js.map +1 -1
- package/lib/fs/orpc/server/createFileSystemContractImpl.js.map +1 -1
- package/lib/fs/s3/createS3MiniFileSystem.js +116 -68
- package/lib/fs/s3/createS3MiniFileSystem.js.map +1 -1
- package/lib/fs/server/createDatabaseFileSystem.js +7 -7
- package/lib/fs/server/createDatabaseFileSystem.js.map +1 -1
- package/lib/fs/server/createNodeFileSystem.js +30 -5
- package/lib/fs/server/createNodeFileSystem.js.map +1 -1
- package/lib/fs/tests/runFileSystemTest.js +27 -26
- package/lib/fs/tests/runFileSystemTest.js.map +1 -1
- package/lib/fs/utils.js.map +1 -1
- package/lib/fs/webdav/index.js +2 -0
- package/lib/fs/webdav/index.js.map +1 -0
- package/lib/jsonschema/JsonSchema.js +5 -5
- package/lib/jsonschema/JsonSchema.js.map +1 -1
- package/lib/jsonschema/forEachJsonSchema.js +1 -1
- package/lib/jsonschema/forEachJsonSchema.js.map +1 -1
- package/lib/jsonschema/types.d.js.map +1 -1
- package/lib/meta/defineMetadata.js.map +1 -1
- package/lib/orpc/createOpenApiContractClient.js.map +1 -1
- package/lib/password/PHC.js +2 -2
- package/lib/password/PHC.js.map +1 -1
- package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -1
- package/lib/password/createBase64PasswordAlgorithm.js +1 -1
- package/lib/password/createBase64PasswordAlgorithm.js.map +1 -1
- package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -1
- package/lib/password/createPBKDF2PasswordAlgorithm.js +1 -1
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -1
- package/lib/password/createScryptPasswordAlgorithm.js +3 -3
- package/lib/password/createScryptPasswordAlgorithm.js.map +1 -1
- package/lib/resource/ListQuery.js.map +1 -1
- package/lib/resource/index.js.map +1 -1
- package/lib/s3/formatS3Url.js +2 -2
- package/lib/s3/formatS3Url.js.map +1 -1
- package/lib/s3/parseS3Url.js +1 -1
- package/lib/s3/parseS3Url.js.map +1 -1
- package/lib/schema/SchemaRegistry.js.map +1 -1
- package/lib/schema/TypeSchema.d.js.map +1 -1
- package/lib/schema/createSchemaData.js +4 -4
- package/lib/schema/createSchemaData.js.map +1 -1
- package/lib/schema/findJsonSchemaByPath.js.map +1 -1
- package/lib/schema/formatZodError.js +42 -44
- package/lib/schema/formatZodError.js.map +1 -1
- package/lib/schema/toJsonSchema.js +4 -4
- package/lib/schema/toJsonSchema.js.map +1 -1
- package/lib/schema/validate.js +1 -1
- package/lib/schema/validate.js.map +1 -1
- package/lib/utils/buildRedactorFormSchema.js +1 -1
- package/lib/utils/buildRedactorFormSchema.js.map +1 -1
- package/package.json +32 -13
- package/src/ai/qwen3vl/utils.ts +1 -1
- package/src/cn/ChineseResidentIdNo.ts +1 -1
- package/src/cn/Mod11.ts +1 -1
- package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +1 -1
- package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +0 -23
- package/src/cn/parseChineseNumber.test.ts +4 -4
- package/src/consola/formatLogObject.ts +6 -6
- package/src/data/maybeNumber.ts +1 -1
- package/src/data/parseSort.test.ts +0 -1
- package/src/data/types.d.ts +2 -2
- package/src/dayjs/formatDuration.ts +2 -2
- package/src/dayjs/resolveRelativeTime.ts +11 -14
- package/src/drain3/Drain.test.ts +378 -0
- package/src/drain3/Drain.ts +394 -0
- package/src/drain3/LogCluster.ts +46 -0
- package/src/drain3/Node.ts +53 -0
- package/src/drain3/TemplateMiner.ts +246 -0
- package/src/drain3/index.ts +36 -0
- package/src/drain3/persistence/FilePersistence.ts +24 -0
- package/src/drain3/persistence/MemoryPersistence.ts +23 -0
- package/src/drain3/persistence/PersistenceHandler.ts +19 -0
- package/src/drain3/types.ts +75 -0
- package/src/fs/IFileSystem.d.ts +1 -2
- package/src/fs/createBrowserFileSystem.ts +7 -5
- package/src/fs/createMemoryFileSystem.ts +9 -13
- package/src/fs/createSandboxFileSystem.ts +1 -1
- package/src/fs/createWebDavFileSystem.ts +28 -10
- package/src/fs/createWebFileSystem.ts +242 -0
- package/src/fs/findMimeType.ts +1 -4
- package/src/fs/index.ts +1 -1
- package/src/fs/minio/createMinioFileSystem.ts +1148 -0
- package/src/fs/minio/index.ts +1 -0
- package/src/fs/orpc/createContractClientFileSystem.ts +5 -5
- package/src/fs/orpc/server/createFileSystemContractImpl.ts +1 -1
- package/src/fs/s3/createS3MiniFileSystem.ts +119 -78
- package/src/fs/s3/s3fs.test.ts +441 -0
- package/src/fs/s3/s3mini.test.ts +2 -2
- package/src/fs/server/createDatabaseFileSystem.ts +7 -7
- package/src/fs/server/createNodeFileSystem.ts +32 -13
- package/src/fs/server/dbfs.test.ts +2 -1
- package/src/fs/tests/runFileSystemTest.ts +29 -28
- package/src/fs/utils.ts +1 -1
- package/src/fs/webdav/index.ts +1 -0
- package/src/jsonschema/JsonSchema.ts +5 -5
- package/src/jsonschema/forEachJsonSchema.ts +1 -1
- package/src/jsonschema/types.d.ts +1 -1
- package/src/meta/defineMetadata.ts +1 -1
- package/src/orpc/createOpenApiContractClient.ts +2 -2
- package/src/password/PHC.ts +3 -3
- package/src/password/createArgon2PasswordAlgorithm.ts +1 -1
- package/src/password/createBase64PasswordAlgorithm.ts +2 -2
- package/src/password/createBcryptPasswordAlgorithm.ts +4 -2
- package/src/password/createPBKDF2PasswordAlgorithm.ts +2 -2
- package/src/password/createScryptPasswordAlgorithm.ts +4 -4
- package/src/resource/ListQuery.ts +4 -1
- package/src/resource/index.ts +2 -2
- package/src/s3/formatS3Url.test.ts +1 -1
- package/src/s3/formatS3Url.ts +2 -2
- package/src/s3/parseS3Url.ts +1 -1
- package/src/schema/SchemaRegistry.ts +1 -1
- package/src/schema/TypeSchema.d.ts +6 -6
- package/src/schema/createSchemaData.ts +4 -4
- package/src/schema/findJsonSchemaByPath.ts +4 -4
- package/src/schema/formatZodError.test.ts +2 -1
- package/src/schema/formatZodError.ts +50 -62
- package/src/schema/toJsonSchema.ts +6 -6
- package/src/schema/validate.ts +1 -1
- package/src/utils/buildRedactorFormSchema.ts +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expect } from 'vitest';
|
|
2
2
|
import { FileSystemError, FileSystemErrorCode } from '../FileSystemError';
|
|
3
|
-
import type { IFileSystem } from '../IFileSystem';
|
|
3
|
+
import type { IFileSystem, IServerFileSystem } from '../IFileSystem';
|
|
4
4
|
|
|
5
5
|
export type RunFileSystemTestOptions = {
|
|
6
6
|
writableStream?: boolean;
|
|
@@ -10,7 +10,7 @@ export type RunFileSystemTestOptions = {
|
|
|
10
10
|
abort?: boolean;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export async function runFileSystemTest(fs: IFileSystem, options: RunFileSystemTestOptions = {}) {
|
|
13
|
+
export async function runFileSystemTest(fs: IFileSystem | IServerFileSystem, options: RunFileSystemTestOptions = {}) {
|
|
14
14
|
const { writableStream = true, readableStream = true, readStream = true, writeStream = true, abort = true } = options;
|
|
15
15
|
// should be implemented
|
|
16
16
|
const stat = await fs.stat('/README.txt');
|
|
@@ -65,21 +65,22 @@ export async function runFileSystemTest(fs: IFileSystem, options: RunFileSystemT
|
|
|
65
65
|
await expect(fs.writeFile('/', 'test')).rejects.toMatchObject({ code: FileSystemErrorCode.EINVAL });
|
|
66
66
|
|
|
67
67
|
// should support streaming operations
|
|
68
|
-
|
|
68
|
+
const serverFs = fs as IServerFileSystem;
|
|
69
|
+
if (readStream && 'createReadStream' in fs) {
|
|
69
70
|
await fs.writeFile('/stream.txt', 'Hello, World!');
|
|
70
71
|
|
|
71
72
|
// Test createReadStream
|
|
72
|
-
const
|
|
73
|
-
expect(
|
|
73
|
+
const readStreamObj = serverFs.createReadStream('/stream.txt');
|
|
74
|
+
expect(readStreamObj).toBeDefined();
|
|
74
75
|
|
|
75
76
|
const chunks: Buffer[] = [];
|
|
76
|
-
for await (const chunk of
|
|
77
|
+
for await (const chunk of readStreamObj) {
|
|
77
78
|
chunks.push(chunk);
|
|
78
79
|
}
|
|
79
80
|
expect(Buffer.concat(chunks).toString()).toBe('Hello, World!');
|
|
80
81
|
|
|
81
82
|
// Test createReadStream with range
|
|
82
|
-
const rangeStream =
|
|
83
|
+
const rangeStream = serverFs.createReadStream('/stream.txt', { range: { start: 0, end: 4 } });
|
|
83
84
|
const rangeChunks: Buffer[] = [];
|
|
84
85
|
for await (const chunk of rangeStream) {
|
|
85
86
|
rangeChunks.push(chunk);
|
|
@@ -87,37 +88,37 @@ export async function runFileSystemTest(fs: IFileSystem, options: RunFileSystemT
|
|
|
87
88
|
expect(Buffer.concat(rangeChunks).toString()).toBe('Hello');
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
if (writeStream && fs
|
|
91
|
+
if (writeStream && 'createWriteStream' in fs) {
|
|
91
92
|
// Test createWriteStream
|
|
92
|
-
const
|
|
93
|
-
expect(
|
|
93
|
+
const writeStreamObj = serverFs.createWriteStream('/write-test.txt');
|
|
94
|
+
expect(writeStreamObj).toBeDefined();
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
writeStreamObj.write('Test content');
|
|
97
|
+
writeStreamObj.end();
|
|
97
98
|
|
|
98
|
-
await new Promise((resolve) =>
|
|
99
|
+
await new Promise((resolve) => writeStreamObj.on('finish', resolve));
|
|
99
100
|
expect(await fs.readFile('/write-test.txt', { encoding: 'text' })).toBe('Test content');
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
// should support Web Streams API
|
|
103
|
-
if (readableStream) {
|
|
104
|
+
if (readableStream && fs.createReadableStream) {
|
|
104
105
|
await fs.writeFile('/webstream.txt', 'Web Stream Test');
|
|
105
106
|
|
|
106
107
|
// Test createReadableStream
|
|
107
|
-
const
|
|
108
|
-
expect(
|
|
108
|
+
const readableStreamObj = fs.createReadableStream('/webstream.txt');
|
|
109
|
+
expect(readableStreamObj).toBeDefined();
|
|
109
110
|
|
|
110
|
-
const reader =
|
|
111
|
+
const reader = readableStreamObj.getReader();
|
|
111
112
|
const { value } = await reader.read();
|
|
112
113
|
expect(value?.toString()).toBe('Web Stream Test');
|
|
113
114
|
}
|
|
114
115
|
|
|
115
|
-
if (writableStream) {
|
|
116
|
+
if (writableStream && fs.createWritableStream) {
|
|
116
117
|
// Test createWritableStream
|
|
117
|
-
const
|
|
118
|
-
expect(
|
|
118
|
+
const writableStreamObj = fs.createWritableStream('/web-write-test.txt');
|
|
119
|
+
expect(writableStreamObj).toBeDefined();
|
|
119
120
|
|
|
120
|
-
const writer =
|
|
121
|
+
const writer = writableStreamObj.getWriter();
|
|
121
122
|
await writer.write(Buffer.from('Web Stream Write Test'));
|
|
122
123
|
await writer.close();
|
|
123
124
|
|
|
@@ -125,30 +126,30 @@ export async function runFileSystemTest(fs: IFileSystem, options: RunFileSystemT
|
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
// should handle streaming errors
|
|
128
|
-
if (abort && readStream && fs
|
|
129
|
+
if (abort && readStream && 'createReadStream' in fs) {
|
|
129
130
|
const controller2 = new AbortController();
|
|
130
131
|
|
|
131
132
|
// Test read stream with abort
|
|
132
|
-
const
|
|
133
|
+
const readStreamObj = serverFs.createReadStream('/README.txt', { signal: controller2.signal });
|
|
133
134
|
controller2.abort();
|
|
134
135
|
|
|
135
136
|
await expect(
|
|
136
137
|
new Promise((_, reject) => {
|
|
137
|
-
|
|
138
|
+
readStreamObj.on('error', reject);
|
|
138
139
|
}),
|
|
139
140
|
).rejects.toThrow(Error);
|
|
140
141
|
}
|
|
141
142
|
|
|
142
|
-
if (abort && writeStream && fs
|
|
143
|
+
if (abort && writeStream && 'createWriteStream' in fs) {
|
|
143
144
|
// Test write stream with abort
|
|
144
145
|
const controller3 = new AbortController();
|
|
145
|
-
const
|
|
146
|
+
const writeStreamObj = serverFs.createWriteStream('/abort-test.txt', { signal: controller3.signal });
|
|
146
147
|
controller3.abort();
|
|
147
148
|
|
|
148
149
|
await expect(
|
|
149
150
|
new Promise((_, reject) => {
|
|
150
|
-
|
|
151
|
-
|
|
151
|
+
writeStreamObj.on('error', reject);
|
|
152
|
+
writeStreamObj.write('test');
|
|
152
153
|
}),
|
|
153
154
|
).rejects.toThrow(Error);
|
|
154
155
|
}
|
package/src/fs/utils.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { IFileStat, WritableData } from './IFileSystem';
|
|
|
4
4
|
export function resolveData(data: WritableData) {
|
|
5
5
|
let buf: Uint8Array;
|
|
6
6
|
if (typeof data === 'string') {
|
|
7
|
-
buf = ArrayBuffers.toUint8Array(ArrayBuffers.from(data, 'utf8'));
|
|
7
|
+
buf = ArrayBuffers.toUint8Array(ArrayBuffers.from(data, 'utf8') as BufferSource);
|
|
8
8
|
} else if (data instanceof ArrayBuffer) {
|
|
9
9
|
buf = new Uint8Array(data);
|
|
10
10
|
} else if (data instanceof Uint8Array) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createWebDavFileSystem } from '../createWebDavFileSystem';
|
|
@@ -72,7 +72,7 @@ function addSchema(
|
|
|
72
72
|
onConflict = (_, neo) => neo;
|
|
73
73
|
break;
|
|
74
74
|
case 'throw':
|
|
75
|
-
onConflict = (
|
|
75
|
+
onConflict = (_old, neo) => {
|
|
76
76
|
throw new Error(`Schema ${neo.$id} already exists`);
|
|
77
77
|
};
|
|
78
78
|
break;
|
|
@@ -119,8 +119,8 @@ function create<S>(schema: S, data?: any): TypeOfSchema<S> {
|
|
|
119
119
|
.with({ oneOf: P.nonNullable }, (schema) => {
|
|
120
120
|
return create(schema.oneOf[0]);
|
|
121
121
|
})
|
|
122
|
-
.with({ type: 'string' }, (
|
|
123
|
-
.with({ type: P.union('number', 'integer') }, (
|
|
122
|
+
.with({ type: 'string' }, (_schema) => '')
|
|
123
|
+
.with({ type: P.union('number', 'integer') }, (_schema) => 0)
|
|
124
124
|
.with({ type: 'object' }, (schema: JsonSchemaDef) => {
|
|
125
125
|
let out = validate({ schema, data: data ?? {}, mutate: true });
|
|
126
126
|
if (!out.success) {
|
|
@@ -141,8 +141,8 @@ function create<S>(schema: S, data?: any): TypeOfSchema<S> {
|
|
|
141
141
|
return out.data;
|
|
142
142
|
})
|
|
143
143
|
.with({ type: 'null' }, () => null)
|
|
144
|
-
.with({ type: 'boolean' }, (
|
|
145
|
-
.with({ type: 'array' }, (
|
|
144
|
+
.with({ type: 'boolean' }, (_schema) => false)
|
|
145
|
+
.with({ type: 'array' }, (_schema) => [])
|
|
146
146
|
.otherwise(() => {
|
|
147
147
|
return undefined;
|
|
148
148
|
});
|
|
@@ -9,7 +9,7 @@ export function forEachJsonSchema(js: JsonSchemaDef, cb: (js: JsonSchemaDef, ctx
|
|
|
9
9
|
_f: (js: JsonSchemaDef, ctx: VisitJsonSchemaContext) => void,
|
|
10
10
|
parent: JsonSchemaDef | undefined,
|
|
11
11
|
path: string[],
|
|
12
|
-
|
|
12
|
+
_k?: string,
|
|
13
13
|
) => {
|
|
14
14
|
if (!js) {
|
|
15
15
|
return;
|
|
@@ -30,7 +30,7 @@ export function createMetadataKey<T = never>(a: any, b?: any): MetadataKey<T> {
|
|
|
30
30
|
|
|
31
31
|
export function defineMetadata<T>(res: HasMetadata, key: MetadataKey<T>, opts: T): void;
|
|
32
32
|
export function defineMetadata<T>(key: MetadataKey<T>, items: Array<[HasMetadata, T]>): void;
|
|
33
|
-
export function defineMetadata<
|
|
33
|
+
export function defineMetadata<_T>(a: any, b: any, c?: any) {
|
|
34
34
|
if (Array.isArray(b)) {
|
|
35
35
|
const key = a;
|
|
36
36
|
const items = b;
|
|
@@ -43,8 +43,8 @@ export type CreateContractClientOptions = {
|
|
|
43
43
|
baseUrl?: string;
|
|
44
44
|
apiKey?: string;
|
|
45
45
|
headers?: Record<string, string> | Headers;
|
|
46
|
-
getApiKey?: () => string |
|
|
47
|
-
getHeaders?: (headers: Headers) => Headers |
|
|
46
|
+
getApiKey?: () => string | undefined;
|
|
47
|
+
getHeaders?: (headers: Headers) => Headers | undefined;
|
|
48
48
|
plugins?: StandardLinkPlugin<any>[];
|
|
49
49
|
fetch?: LinkFetchClientOptions<any>['fetch'];
|
|
50
50
|
batch?: BatchLinkPluginOptions<any> | boolean;
|
package/src/password/PHC.ts
CHANGED
|
@@ -99,7 +99,7 @@ export namespace PHC {
|
|
|
99
99
|
|
|
100
100
|
// Convert Numbers into Numeric Strings and Buffers into B64 encoded strings.
|
|
101
101
|
pk.forEach((k) => {
|
|
102
|
-
const value = opts.params
|
|
102
|
+
const value = opts.params?.[k];
|
|
103
103
|
if (typeof value === 'number') {
|
|
104
104
|
opts.params![k] = value.toString();
|
|
105
105
|
} else if (value instanceof Uint8Array) {
|
|
@@ -143,7 +143,7 @@ export namespace PHC {
|
|
|
143
143
|
return phcstr;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
interface DeserializeResult {
|
|
146
|
+
export interface DeserializeResult {
|
|
147
147
|
id: string;
|
|
148
148
|
version?: number;
|
|
149
149
|
params?: Record<string, string | number>;
|
|
@@ -223,7 +223,7 @@ export namespace PHC {
|
|
|
223
223
|
|
|
224
224
|
// Convert Decimal Strings into Numbers
|
|
225
225
|
Object.keys(params).forEach((k) => {
|
|
226
|
-
const value = params
|
|
226
|
+
const value = params?.[k];
|
|
227
227
|
if (typeof value === 'string' && decimalRegex.test(value)) {
|
|
228
228
|
params![k] = parseInt(value, 10);
|
|
229
229
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { maybeFunction, type MaybeFunction, type MaybePromise } from '@wener/utils';
|
|
2
|
-
import { Password } from './Password';
|
|
2
|
+
import type { Password } from './Password';
|
|
3
3
|
|
|
4
4
|
type Provide = {
|
|
5
5
|
hash: (password: string, options: { salt?: Buffer; raw?: boolean; type?: 0 | 1 | 2 }) => Promise<string>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ArrayBuffers } from '@wener/utils';
|
|
2
|
-
import { Password } from './Password';
|
|
2
|
+
import type { Password } from './Password';
|
|
3
3
|
|
|
4
4
|
export function createBase64PasswordAlgorithm({ id = 'base64' }: { id?: string } = {}): Password.PasswordAlgorithm {
|
|
5
5
|
return {
|
|
@@ -7,7 +7,7 @@ export function createBase64PasswordAlgorithm({ id = 'base64' }: { id?: string }
|
|
|
7
7
|
async hash(password: string) {
|
|
8
8
|
return `$${id}$$${ArrayBuffers.toBase64(password).replace(/=/g, '')}`;
|
|
9
9
|
},
|
|
10
|
-
async verify(password: string,
|
|
10
|
+
async verify(password: string, _hash: string, opts) {
|
|
11
11
|
return Boolean(opts.hash) && ArrayBuffers.toString(opts.hash!) === password;
|
|
12
12
|
},
|
|
13
13
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MaybePromise } from '@wener/utils';
|
|
2
|
-
import { Password } from './Password';
|
|
2
|
+
import type { Password } from './Password';
|
|
3
3
|
|
|
4
4
|
type ProviderType = () => MaybePromise<{
|
|
5
5
|
hash: (password: string, rounds: number | string) => Promise<string>;
|
|
@@ -9,7 +9,9 @@ type ProviderType = () => MaybePromise<{
|
|
|
9
9
|
export function createBcryptPasswordAlgorithm({
|
|
10
10
|
// provider = () => import('bcrypt').then((v) => v.default),
|
|
11
11
|
provider = () => import('bcryptjs').then((v) => v.default),
|
|
12
|
-
}: {
|
|
12
|
+
}: {
|
|
13
|
+
provider?: ProviderType;
|
|
14
|
+
} = {}): Password.PasswordAlgorithm {
|
|
13
15
|
// bcrypt or bcryptjs
|
|
14
16
|
return {
|
|
15
17
|
name: 'bcrypt',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Errors } from '@wener/utils';
|
|
2
|
-
import { Password } from './Password';
|
|
2
|
+
import type { Password } from './Password';
|
|
3
3
|
import { PHC } from './PHC';
|
|
4
4
|
|
|
5
5
|
export function createPBKDF2PasswordAlgorithm({
|
|
@@ -55,7 +55,7 @@ export function createPBKDF2PasswordAlgorithm({
|
|
|
55
55
|
key,
|
|
56
56
|
storedHash.length * 8,
|
|
57
57
|
);
|
|
58
|
-
return new Uint8Array(hash).every((v, i) => v === storedHash
|
|
58
|
+
return new Uint8Array(hash).every((v, i) => v === storedHash?.[i]);
|
|
59
59
|
},
|
|
60
60
|
};
|
|
61
61
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomBytes, scrypt, timingSafeEqual } from 'node:crypto';
|
|
2
2
|
import { Errors } from '@wener/utils';
|
|
3
|
-
import { Password } from './Password';
|
|
3
|
+
import type { Password } from './Password';
|
|
4
4
|
import { PHC } from './PHC';
|
|
5
5
|
|
|
6
6
|
export function createScryptPasswordAlgorithm(
|
|
@@ -14,7 +14,7 @@ export function createScryptPasswordAlgorithm(
|
|
|
14
14
|
} = {},
|
|
15
15
|
): Password.PasswordAlgorithm {
|
|
16
16
|
let id = options.id || 'scrypt';
|
|
17
|
-
options.cost ||=
|
|
17
|
+
options.cost ||= 2 ** 14;
|
|
18
18
|
options.blocksize ||= 8;
|
|
19
19
|
options.parallelism ||= 1;
|
|
20
20
|
options.saltlen ||= 16;
|
|
@@ -35,7 +35,7 @@ export function createScryptPasswordAlgorithm(
|
|
|
35
35
|
});
|
|
36
36
|
},
|
|
37
37
|
|
|
38
|
-
async verify(password: string,
|
|
38
|
+
async verify(password: string, _hash: string, opts): Promise<boolean> {
|
|
39
39
|
try {
|
|
40
40
|
const salt = Errors.BadRequest.require(opts.salt);
|
|
41
41
|
const storedHash = Errors.BadRequest.require(opts.hash);
|
|
@@ -53,7 +53,7 @@ export function createScryptPasswordAlgorithm(
|
|
|
53
53
|
resolve(isMatch);
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
|
-
} catch (
|
|
56
|
+
} catch (_error) {
|
|
57
57
|
return Promise.resolve(false);
|
|
58
58
|
}
|
|
59
59
|
},
|
|
@@ -25,7 +25,10 @@ export const ListQuerySchema = z.object({
|
|
|
25
25
|
deleted: z.coerce.boolean().optional(),
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
type ListQueryOverride =
|
|
28
|
+
type ListQueryOverride =
|
|
29
|
+
| ListQueryInput
|
|
30
|
+
| undefined
|
|
31
|
+
| ((input: ListQueryInput) => ListQueryInput | undefined | undefined);
|
|
29
32
|
|
|
30
33
|
export function resolveListQuery(target: ListQueryInput | undefined, ...args: ListQueryOverride[]): ListQuery {
|
|
31
34
|
let out = args.reduce((a: ListQueryInput, source) => {
|
package/src/resource/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export type { AnyResource } from './schema/AnyResourceSchema';
|
|
2
|
+
export type { Identifiable } from './Identifiable';
|
|
3
3
|
export { getTitleOfResource } from './getTitleOfResource';
|
|
4
4
|
export { type ListQueryInput, type ListQuery, resolveListQuery, ListQuerySchema } from './ListQuery';
|
|
@@ -216,7 +216,7 @@ describe('formatS3Url', () => {
|
|
|
216
216
|
endpoint: 's3.amazonaws.com',
|
|
217
217
|
bucket: 'a'.repeat(64),
|
|
218
218
|
};
|
|
219
|
-
expect(() => formatS3Url(options)).toThrow(
|
|
219
|
+
expect(() => formatS3Url(options)).toThrow(`Invalid bucket name: ${'a'.repeat(64)}`);
|
|
220
220
|
});
|
|
221
221
|
|
|
222
222
|
it('should handle valid bucket names with various formats', () => {
|
package/src/s3/formatS3Url.ts
CHANGED
|
@@ -31,7 +31,7 @@ export function formatS3Url(
|
|
|
31
31
|
} else {
|
|
32
32
|
url = new URL(`https://${ep}`);
|
|
33
33
|
}
|
|
34
|
-
} catch (
|
|
34
|
+
} catch (_error) {
|
|
35
35
|
throw new Error(`Invalid endpoint: ${ep}`);
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -58,7 +58,7 @@ export function formatS3Url(
|
|
|
58
58
|
|
|
59
59
|
if (port) {
|
|
60
60
|
const portNum = Number(port);
|
|
61
|
-
if (isNaN(portNum) || portNum < 1 || portNum > 65535) {
|
|
61
|
+
if (Number.isNaN(portNum) || portNum < 1 || portNum > 65535) {
|
|
62
62
|
throw new Error('Port must be a valid number between 1 and 65535');
|
|
63
63
|
}
|
|
64
64
|
url.port = String(portNum);
|
package/src/s3/parseS3Url.ts
CHANGED
|
@@ -10,23 +10,23 @@ import type { JsonSchemaDef } from '../jsonschema';
|
|
|
10
10
|
export type TypeSchema<I = unknown, O = I> = TSchema | z.ZodSchema<O, I> | JsonSchemaDef | StandardSchemaV1<I, O>;
|
|
11
11
|
|
|
12
12
|
export type SchemaOutput<S extends TypeSchema> =
|
|
13
|
-
S extends StandardSchemaV1<infer
|
|
13
|
+
S extends StandardSchemaV1<infer _I, infer O>
|
|
14
14
|
? O
|
|
15
|
-
: S extends z.ZodSchema<infer O, infer
|
|
15
|
+
: S extends z.ZodSchema<infer O, infer _I>
|
|
16
16
|
? O
|
|
17
17
|
: S extends TSchema
|
|
18
18
|
? TypeBoxStaticEncode<S>
|
|
19
|
-
: S extends JsonSchemaDef<infer
|
|
19
|
+
: S extends JsonSchemaDef<infer _I, infer O>
|
|
20
20
|
? O
|
|
21
21
|
: never;
|
|
22
22
|
|
|
23
23
|
export type SchemaInput<S extends TypeSchema> =
|
|
24
|
-
S extends StandardSchemaV1<infer I, infer
|
|
24
|
+
S extends StandardSchemaV1<infer I, infer _O>
|
|
25
25
|
? I
|
|
26
|
-
: S extends z.ZodSchema<infer
|
|
26
|
+
: S extends z.ZodSchema<infer _O, infer I>
|
|
27
27
|
? I
|
|
28
28
|
: S extends TSchema
|
|
29
29
|
? TypeBoxStaticDecode<S>
|
|
30
|
-
: S extends JsonSchemaDef<infer I, infer
|
|
30
|
+
: S extends JsonSchemaDef<infer I, infer _O>
|
|
31
31
|
? I
|
|
32
32
|
: never;
|
|
@@ -54,8 +54,8 @@ function _create(schema: JsonSchemaDef, options: CreateOptions, ctx: { required:
|
|
|
54
54
|
.with({ oneOf: P.nonNullable }, (schema) => {
|
|
55
55
|
return _create(schema.oneOf[0], options, { required: false });
|
|
56
56
|
})
|
|
57
|
-
.with({ type: 'string' }, (
|
|
58
|
-
.with({ type: P.union('number', 'integer') }, (
|
|
57
|
+
.with({ type: 'string' }, (_schema) => '')
|
|
58
|
+
.with({ type: P.union('number', 'integer') }, (_schema) => 0)
|
|
59
59
|
.with({ type: 'object' }, () => {
|
|
60
60
|
const out: Record<string, any> = {};
|
|
61
61
|
|
|
@@ -73,8 +73,8 @@ function _create(schema: JsonSchemaDef, options: CreateOptions, ctx: { required:
|
|
|
73
73
|
return out;
|
|
74
74
|
})
|
|
75
75
|
.with({ type: 'null' }, () => null)
|
|
76
|
-
.with({ type: 'boolean' }, (
|
|
77
|
-
.with({ type: 'array' }, (
|
|
76
|
+
.with({ type: 'boolean' }, (_schema) => false)
|
|
77
|
+
.with({ type: 'array' }, (_schema) => [])
|
|
78
78
|
.otherwise(() => {
|
|
79
79
|
return undefined;
|
|
80
80
|
});
|
|
@@ -14,10 +14,10 @@ export function findJsonSchemaByPath(schema: TypeSchema, objectPath: string) {
|
|
|
14
14
|
for (const segment of segments) {
|
|
15
15
|
// 检查当前 schema 是否是对象类型且有 properties
|
|
16
16
|
if (
|
|
17
|
-
currentSchema
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
currentSchema &&
|
|
18
|
+
typeof currentSchema === 'object' &&
|
|
19
|
+
currentSchema.properties &&
|
|
20
|
+
currentSchema.properties[segment]
|
|
21
21
|
) {
|
|
22
22
|
currentSchema = currentSchema.properties[segment];
|
|
23
23
|
continue;
|
|
@@ -181,10 +181,11 @@ describe('formatZodError', () => {
|
|
|
181
181
|
|
|
182
182
|
it('should use schema description when available', () => {
|
|
183
183
|
const schema = z.object({
|
|
184
|
-
name: z.string().describe('姓名'),
|
|
184
|
+
name: z.string().min(1).describe('姓名'),
|
|
185
185
|
email: z.string().email().describe('邮箱地址'),
|
|
186
186
|
});
|
|
187
187
|
|
|
188
|
+
// Use empty string for name (triggers min(1) error) and invalid email
|
|
188
189
|
const result = schema.safeParse({ name: '', email: 'invalid' });
|
|
189
190
|
expect(result.success).toBe(false);
|
|
190
191
|
if (!result.success) {
|