@wener/common 2.0.2 → 2.0.3
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/index.js +2 -0
- package/lib/ai/qwen3vl/index.js.map +1 -0
- package/lib/ai/qwen3vl/utils.js +31 -0
- package/lib/ai/qwen3vl/utils.js.map +1 -0
- package/lib/ai/vision/DocLayoutElementTypeSchema.js +28 -0
- package/lib/ai/vision/DocLayoutElementTypeSchema.js.map +1 -0
- package/lib/ai/vision/ImageAnnotationSchema.js +50 -0
- package/lib/ai/vision/ImageAnnotationSchema.js.map +1 -0
- package/lib/ai/vision/index.js +3 -0
- package/lib/ai/vision/index.js.map +1 -0
- package/lib/ai/vision/resolveImageAnnotation.js +105 -0
- package/lib/ai/vision/resolveImageAnnotation.js.map +1 -0
- package/lib/cn/ChineseResidentIdNo.js +21 -14
- package/lib/cn/ChineseResidentIdNo.js.map +1 -0
- package/lib/cn/ChineseResidentIdNo.test.js +1 -1
- package/lib/cn/DivisionCode.js +30 -25
- package/lib/cn/DivisionCode.js.map +1 -0
- package/lib/cn/DivisionCode.test.js +1 -1
- package/lib/cn/Mod11.js +38 -81
- package/lib/cn/Mod11.js.map +1 -0
- package/lib/cn/Mod31.js +41 -90
- package/lib/cn/Mod31.js.map +1 -0
- package/lib/cn/UnifiedSocialCreditCode.js +43 -34
- package/lib/cn/UnifiedSocialCreditCode.js.map +1 -0
- package/lib/cn/UnifiedSocialCreditCode.test.js +1 -1
- package/lib/cn/formatChineseAmount.js +77 -0
- package/lib/cn/formatChineseAmount.js.map +1 -0
- package/lib/cn/index.js +7 -1
- package/lib/cn/index.js.map +1 -0
- package/lib/cn/parseChineseNumber.js +94 -0
- package/lib/cn/parseChineseNumber.js.map +1 -0
- package/lib/cn/parseChineseNumber.test.js +278 -0
- package/lib/cn/pinyin/cartesianProduct.js +22 -0
- package/lib/cn/pinyin/cartesianProduct.js.map +1 -0
- package/lib/cn/pinyin/cartesianProduct.test.js +179 -0
- package/lib/cn/pinyin/data.json +23573 -0
- package/lib/cn/pinyin/loader.js +14 -0
- package/lib/cn/pinyin/loader.js.map +1 -0
- package/lib/cn/pinyin/preload.js +3 -0
- package/lib/cn/pinyin/preload.js.map +1 -0
- package/lib/cn/pinyin/toPinyin.test.js +167 -0
- package/lib/cn/pinyin/toPinyinPure.js +33 -0
- package/lib/cn/pinyin/toPinyinPure.js.map +1 -0
- package/lib/cn/pinyin/transform.js +14 -0
- package/lib/cn/pinyin/transform.js.map +1 -0
- package/lib/cn/types.d.js +2 -0
- package/lib/cn/types.d.js.map +1 -0
- package/lib/consola/createStandardConsolaReporter.js +6 -6
- package/lib/consola/createStandardConsolaReporter.js.map +1 -0
- package/lib/consola/formatLogObject.js +65 -145
- package/lib/consola/formatLogObject.js.map +1 -0
- package/lib/consola/formatLogObject.test.js +184 -0
- package/lib/consola/index.js +1 -0
- package/lib/consola/index.js.map +1 -0
- package/lib/data/formatSort.js +6 -5
- package/lib/data/formatSort.js.map +1 -0
- package/lib/data/index.js +1 -0
- package/lib/data/index.js.map +1 -0
- package/lib/data/maybeNumber.js +5 -7
- package/lib/data/maybeNumber.js.map +1 -0
- package/lib/data/parseSort.js +22 -28
- package/lib/data/parseSort.js.map +1 -0
- package/lib/data/resolvePagination.js +13 -17
- package/lib/data/resolvePagination.js.map +1 -0
- package/lib/data/types.d.js +2 -0
- package/lib/data/types.d.js.map +1 -0
- package/lib/dayjs/dayjs.js +21 -19
- package/lib/dayjs/dayjs.js.map +1 -0
- package/lib/dayjs/formatDuration.js +15 -14
- package/lib/dayjs/formatDuration.js.map +1 -0
- package/lib/dayjs/index.js +2 -0
- package/lib/dayjs/index.js.map +1 -0
- package/lib/dayjs/parseDuration.js +5 -8
- package/lib/dayjs/parseDuration.js.map +1 -0
- package/lib/dayjs/parseRelativeTime.js +90 -0
- package/lib/dayjs/parseRelativeTime.js.map +1 -0
- package/lib/dayjs/parseRelativeTime.test.js +247 -0
- package/lib/dayjs/resolveRelativeTime.js +158 -0
- package/lib/dayjs/resolveRelativeTime.js.map +1 -0
- package/lib/dayjs/resolveRelativeTime.test.js +310 -0
- package/lib/decimal/index.js +1 -0
- package/lib/decimal/index.js.map +1 -0
- package/lib/decimal/parseDecimal.js +3 -1
- package/lib/decimal/parseDecimal.js.map +1 -0
- package/lib/emittery/emitter.js +10 -0
- package/lib/emittery/emitter.js.map +1 -0
- package/lib/emittery/index.js +2 -0
- package/lib/emittery/index.js.map +1 -0
- package/lib/foundation/schema/SexType.js +5 -3
- package/lib/foundation/schema/SexType.js.map +1 -0
- package/lib/foundation/schema/index.js +1 -0
- package/lib/foundation/schema/index.js.map +1 -0
- package/lib/foundation/schema/parseSexType.js +1 -0
- package/lib/foundation/schema/parseSexType.js.map +1 -0
- package/lib/foundation/schema/types.js +4 -2
- package/lib/foundation/schema/types.js.map +1 -0
- package/lib/fs/FileSystemError.js +23 -0
- package/lib/fs/FileSystemError.js.map +1 -0
- package/lib/fs/IFileSystem.d.js +3 -0
- package/lib/fs/IFileSystem.d.js.map +1 -0
- package/lib/fs/MemoryFileSystem.test.js +188 -0
- package/lib/fs/createBrowserFileSystem.js +248 -0
- package/lib/fs/createBrowserFileSystem.js.map +1 -0
- package/lib/fs/createMemoryFileSystem.js +516 -0
- package/lib/fs/createMemoryFileSystem.js.map +1 -0
- package/lib/fs/createSandboxFileSystem.js +108 -0
- package/lib/fs/createSandboxFileSystem.js.map +1 -0
- package/lib/fs/createWebDavFileSystem.js +137 -0
- package/lib/fs/createWebDavFileSystem.js.map +1 -0
- package/lib/fs/findMimeType.js +17 -0
- package/lib/fs/findMimeType.js.map +1 -0
- package/lib/fs/index.js +8 -0
- package/lib/fs/index.js.map +1 -0
- package/lib/fs/orpc/FileSystemContract.js +93 -0
- package/lib/fs/orpc/FileSystemContract.js.map +1 -0
- package/lib/fs/orpc/createContractClientFileSystem.js +93 -0
- package/lib/fs/orpc/createContractClientFileSystem.js.map +1 -0
- package/lib/fs/orpc/index.js +3 -0
- package/lib/fs/orpc/index.js.map +1 -0
- package/lib/fs/orpc/server/createFileSystemContractImpl.js +63 -0
- package/lib/fs/orpc/server/createFileSystemContractImpl.js.map +1 -0
- package/lib/fs/orpc/server/index.js +2 -0
- package/lib/fs/orpc/server/index.js.map +1 -0
- package/lib/fs/s3/createS3MiniFileSystem.js +705 -0
- package/lib/fs/s3/createS3MiniFileSystem.js.map +1 -0
- package/lib/fs/s3/index.js +2 -0
- package/lib/fs/s3/index.js.map +1 -0
- package/lib/fs/s3/s3mini.test.js +584 -0
- package/lib/fs/scandir.js +59 -0
- package/lib/fs/scandir.js.map +1 -0
- package/lib/fs/server/createDatabaseFileSystem.js +750 -0
- package/lib/fs/server/createDatabaseFileSystem.js.map +1 -0
- package/lib/fs/server/createNodeFileSystem.js +401 -0
- package/lib/fs/server/createNodeFileSystem.js.map +1 -0
- package/lib/fs/server/dbfs.test.js +221 -0
- package/lib/fs/server/index.js +2 -0
- package/lib/fs/server/index.js.map +1 -0
- package/lib/fs/server/loadTestDatabase.js +127 -0
- package/lib/fs/server/loadTestDatabase.js.map +1 -0
- package/lib/fs/tests/runFileSystemTest.js +318 -0
- package/lib/fs/tests/runFileSystemTest.js.map +1 -0
- package/lib/fs/types.js +27 -0
- package/lib/fs/types.js.map +1 -0
- package/lib/fs/utils/getFileUrl.js +35 -0
- package/lib/fs/utils/getFileUrl.js.map +1 -0
- package/lib/fs/utils.js +22 -0
- package/lib/fs/utils.js.map +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -0
- package/lib/jsonschema/JsonSchema.js +146 -172
- package/lib/jsonschema/JsonSchema.js.map +1 -0
- package/lib/jsonschema/forEachJsonSchema.js +44 -0
- package/lib/jsonschema/forEachJsonSchema.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 +2 -0
- package/lib/jsonschema/types.d.js.map +1 -0
- package/lib/meta/defineFileType.js +20 -103
- package/lib/meta/defineFileType.js.map +1 -0
- package/lib/meta/defineInit.js +31 -250
- package/lib/meta/defineInit.js.map +1 -0
- package/lib/meta/defineMetadata.js +24 -140
- package/lib/meta/defineMetadata.js.map +1 -0
- package/lib/meta/index.js +1 -0
- package/lib/meta/index.js.map +1 -0
- package/lib/orpc/createOpenApiContractClient.js +27 -0
- package/lib/orpc/createOpenApiContractClient.js.map +1 -0
- package/lib/orpc/createRpcContractClient.js +34 -0
- package/lib/orpc/createRpcContractClient.js.map +1 -0
- package/lib/orpc/index.js +3 -0
- package/lib/orpc/index.js.map +1 -0
- package/lib/orpc/resolveLinkPlugins.js +28 -0
- package/lib/orpc/resolveLinkPlugins.js.map +1 -0
- package/lib/password/PHC.js +63 -87
- package/lib/password/PHC.js.map +1 -0
- package/lib/password/PHC.test.js +11 -3
- package/lib/password/Password.js +29 -294
- package/lib/password/Password.js.map +1 -0
- package/lib/password/Password.test.js +35 -22
- package/lib/password/createArgon2PasswordAlgorithm.js +35 -191
- package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -0
- package/lib/password/createBase64PasswordAlgorithm.js +8 -141
- package/lib/password/createBase64PasswordAlgorithm.js.map +1 -0
- package/lib/password/createBcryptPasswordAlgorithm.js +13 -168
- package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -0
- package/lib/password/createPBKDF2PasswordAlgorithm.js +46 -228
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -0
- package/lib/password/createScryptPasswordAlgorithm.js +55 -211
- package/lib/password/createScryptPasswordAlgorithm.js.map +1 -0
- package/lib/password/index.js +1 -0
- package/lib/password/index.js.map +1 -0
- package/lib/password/server/index.js +1 -0
- package/lib/password/server/index.js.map +1 -0
- package/lib/resource/Identifiable.js +2 -0
- package/lib/resource/Identifiable.js.map +1 -0
- package/lib/resource/ListQuery.js +21 -93
- package/lib/resource/ListQuery.js.map +1 -0
- package/lib/resource/getTitleOfResource.js +3 -5
- package/lib/resource/getTitleOfResource.js.map +1 -0
- package/lib/resource/index.js +1 -0
- package/lib/resource/index.js.map +1 -0
- package/lib/resource/schema/AnyResourceSchema.js +2 -1
- package/lib/resource/schema/AnyResourceSchema.js.map +1 -0
- package/lib/resource/schema/BaseResourceSchema.js +2 -1
- package/lib/resource/schema/BaseResourceSchema.js.map +1 -0
- package/lib/resource/schema/ResourceActionType.js +6 -4
- package/lib/resource/schema/ResourceActionType.js.map +1 -0
- package/lib/resource/schema/ResourceStatus.js +5 -3
- package/lib/resource/schema/ResourceStatus.js.map +1 -0
- package/lib/resource/schema/ResourceType.js +5 -3
- package/lib/resource/schema/ResourceType.js.map +1 -0
- package/lib/resource/schema/index.js +1 -0
- package/lib/resource/schema/index.js.map +1 -0
- package/lib/resource/schema/types.js +16 -20
- package/lib/resource/schema/types.js.map +1 -0
- package/lib/s3/formatS3Url.js +65 -0
- package/lib/s3/formatS3Url.js.map +1 -0
- package/lib/s3/formatS3Url.test.js +262 -0
- package/lib/s3/index.js +3 -0
- package/lib/s3/index.js.map +1 -0
- package/lib/s3/parseS3Url.js +65 -0
- package/lib/s3/parseS3Url.js.map +1 -0
- package/lib/s3/parseS3Url.test.js +270 -0
- package/lib/schema/SchemaRegistry.js +38 -38
- package/lib/schema/SchemaRegistry.js.map +1 -0
- package/lib/schema/TypeSchema.d.js +2 -0
- package/lib/schema/TypeSchema.d.js.map +1 -0
- package/lib/schema/createSchemaData.js +26 -125
- package/lib/schema/createSchemaData.js.map +1 -0
- package/lib/schema/findJsonSchemaByPath.js +13 -36
- package/lib/schema/findJsonSchemaByPath.js.map +1 -0
- package/lib/schema/formatZodError.js +140 -0
- package/lib/schema/formatZodError.js.map +1 -0
- package/lib/schema/formatZodError.test.js +196 -0
- package/lib/schema/getSchemaCache.js +5 -5
- package/lib/schema/getSchemaCache.js.map +1 -0
- package/lib/schema/getSchemaOptions.js +8 -11
- package/lib/schema/getSchemaOptions.js.map +1 -0
- package/lib/schema/index.js +2 -1
- package/lib/schema/index.js.map +1 -0
- package/lib/schema/toJsonSchema.js +47 -290
- package/lib/schema/toJsonSchema.js.map +1 -0
- package/lib/schema/validate.js +33 -45
- package/lib/schema/validate.js.map +1 -0
- package/lib/tools/generateSchema.js +39 -197
- package/lib/tools/generateSchema.js.map +1 -0
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +55 -143
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +1 -0
- package/lib/utils/buildBaseUrl.js +13 -0
- package/lib/utils/buildBaseUrl.js.map +1 -0
- package/lib/utils/buildRedactorFormSchema.js +59 -0
- package/lib/utils/buildRedactorFormSchema.js.map +1 -0
- package/lib/utils/getEstimateProcessTime.js +12 -11
- package/lib/utils/getEstimateProcessTime.js.map +1 -0
- package/lib/utils/index.js +3 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/resolveFeatureOptions.js +12 -0
- package/lib/utils/resolveFeatureOptions.js.map +1 -0
- package/package.json +61 -13
- package/src/ai/qwen3vl/index.ts +1 -0
- package/src/ai/qwen3vl/utils.ts +36 -0
- package/src/ai/vision/DocLayoutElementTypeSchema.ts +30 -0
- package/src/ai/vision/ImageAnnotationSchema.ts +60 -0
- package/src/ai/vision/index.ts +2 -0
- package/src/ai/vision/resolveImageAnnotation.ts +135 -0
- package/src/cn/ChineseResidentIdNo.test.ts +1 -1
- package/src/cn/ChineseResidentIdNo.ts +8 -0
- package/src/cn/DivisionCode.test.ts +1 -1
- package/src/cn/DivisionCode.ts +8 -0
- package/src/cn/UnifiedSocialCreditCode.test.ts +1 -1
- package/src/cn/UnifiedSocialCreditCode.ts +15 -0
- package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +23 -0
- package/src/cn/formatChineseAmount.ts +61 -0
- package/src/cn/index.ts +7 -1
- package/src/cn/parseChineseNumber.test.ts +159 -0
- package/src/cn/parseChineseNumber.ts +97 -0
- package/src/cn/pinyin/cartesianProduct.test.ts +64 -0
- package/src/cn/pinyin/cartesianProduct.ts +24 -0
- package/src/cn/pinyin/data.json +23573 -0
- package/src/cn/pinyin/loader.ts +12 -0
- package/src/cn/pinyin/preload.ts +3 -0
- package/src/cn/pinyin/toPinyin.test.ts +12 -0
- package/src/cn/pinyin/toPinyinPure.ts +43 -0
- package/src/cn/pinyin/transform.ts +12 -0
- package/src/consola/formatLogObject.test.ts +27 -0
- package/src/consola/formatLogObject.ts +34 -6
- package/src/dayjs/dayjs.ts +18 -18
- package/src/dayjs/index.ts +3 -1
- package/src/dayjs/parseRelativeTime.test.ts +185 -0
- package/src/dayjs/parseRelativeTime.ts +115 -0
- package/src/dayjs/resolveRelativeTime.test.ts +357 -0
- package/src/dayjs/resolveRelativeTime.ts +167 -0
- package/src/emittery/emitter.ts +9 -0
- package/src/emittery/index.ts +1 -0
- package/src/fs/FileSystemError.ts +26 -0
- package/src/fs/IFileSystem.d.ts +102 -0
- package/src/fs/MemoryFileSystem.test.ts +37 -0
- package/src/fs/createBrowserFileSystem.ts +291 -0
- package/src/fs/createMemoryFileSystem.ts +604 -0
- package/src/fs/createSandboxFileSystem.ts +136 -0
- package/src/fs/createWebDavFileSystem.ts +172 -0
- package/src/fs/findMimeType.ts +23 -0
- package/src/fs/index.ts +8 -0
- package/src/fs/orpc/FileSystemContract.ts +92 -0
- package/src/fs/orpc/createContractClientFileSystem.ts +115 -0
- package/src/fs/orpc/index.ts +2 -0
- package/src/fs/orpc/server/createFileSystemContractImpl.ts +64 -0
- package/src/fs/orpc/server/index.ts +1 -0
- package/src/fs/s3/createS3MiniFileSystem.ts +830 -0
- package/src/fs/s3/index.ts +1 -0
- package/src/fs/s3/s3mini.test.ts +264 -0
- package/src/fs/scandir.ts +75 -0
- package/src/fs/server/createDatabaseFileSystem.ts +668 -0
- package/src/fs/server/createNodeFileSystem.ts +499 -0
- package/src/fs/server/dbfs.test.ts +47 -0
- package/src/fs/server/index.ts +1 -0
- package/src/fs/server/loadTestDatabase.ts +131 -0
- package/src/fs/tests/runFileSystemTest.ts +288 -0
- package/src/fs/types.ts +29 -0
- package/src/fs/utils/getFileUrl.ts +44 -0
- package/src/fs/utils.ts +23 -0
- package/src/jsonschema/JsonSchema.ts +118 -110
- package/src/jsonschema/forEachJsonSchema.ts +50 -0
- package/src/jsonschema/index.ts +1 -0
- package/src/orpc/createOpenApiContractClient.ts +52 -0
- package/src/orpc/createRpcContractClient.ts +50 -0
- package/src/orpc/index.ts +2 -0
- package/src/orpc/resolveLinkPlugins.ts +29 -0
- package/src/password/PHC.ts +3 -3
- package/src/password/Password.test.ts +1 -1
- package/src/password/createPBKDF2PasswordAlgorithm.ts +2 -2
- package/src/resource/schema/AnyResourceSchema.ts +16 -2
- package/src/s3/formatS3Url.test.ts +254 -0
- package/src/s3/formatS3Url.ts +84 -0
- package/src/s3/index.ts +2 -0
- package/src/s3/parseS3Url.test.ts +258 -0
- package/src/s3/parseS3Url.ts +88 -0
- package/src/schema/SchemaRegistry.ts +35 -33
- package/src/schema/formatZodError.test.ts +196 -0
- package/src/schema/formatZodError.ts +151 -0
- package/src/schema/getSchemaOptions.ts +2 -2
- package/src/schema/index.ts +1 -1
- package/src/utils/buildBaseUrl.ts +12 -0
- package/src/utils/buildRedactorFormSchema.ts +85 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/resolveFeatureOptions.ts +14 -0
- package/src/cn/ChineseResidentIdNo.mod.ts +0 -7
- package/src/cn/DivisionCode.mod.ts +0 -7
- package/src/cn/UnifiedSocialCreditCode.mod.ts +0 -7
- package/src/cn/mod.ts +0 -3
- package/src/schema/SchemaRegistry.mod.ts +0 -1
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import quarterOfYear from "dayjs/plugin/quarterOfYear";
|
|
3
|
+
import weekOfYear from "dayjs/plugin/weekOfYear";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { resolveRelativeTime } from "./resolveRelativeTime.js";
|
|
6
|
+
dayjs.extend(quarterOfYear);
|
|
7
|
+
dayjs.extend(weekOfYear);
|
|
8
|
+
describe("resolveRelativeTime", function () {
|
|
9
|
+
var fixedDate = new Date("2024-03-15T14:30:45.123Z");
|
|
10
|
+
describe("basic cases", function () {
|
|
11
|
+
it("should handle \"now\"", function () {
|
|
12
|
+
var result = resolveRelativeTime("now", fixedDate);
|
|
13
|
+
expect(result).toEqual(fixedDate);
|
|
14
|
+
});
|
|
15
|
+
it("should handle \"now\" without reference date", function () {
|
|
16
|
+
var result = resolveRelativeTime("now", undefined);
|
|
17
|
+
expect(result).toBeInstanceOf(Date);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe("subtraction operations", function () {
|
|
21
|
+
it("should subtract seconds", function () {
|
|
22
|
+
var result = resolveRelativeTime("now-30s", fixedDate);
|
|
23
|
+
var expected = dayjs(fixedDate).subtract(30, "second").toDate();
|
|
24
|
+
expect(result).toEqual(expected);
|
|
25
|
+
});
|
|
26
|
+
it("should subtract minutes", function () {
|
|
27
|
+
var result = resolveRelativeTime("now-15m", fixedDate);
|
|
28
|
+
var expected = dayjs(fixedDate).subtract(15, "minute").toDate();
|
|
29
|
+
expect(result).toEqual(expected);
|
|
30
|
+
});
|
|
31
|
+
it("should subtract hours", function () {
|
|
32
|
+
var result = resolveRelativeTime("now-2h", fixedDate);
|
|
33
|
+
var expected = dayjs(fixedDate).subtract(2, "hour").toDate();
|
|
34
|
+
expect(result).toEqual(expected);
|
|
35
|
+
});
|
|
36
|
+
it("should subtract days", function () {
|
|
37
|
+
var result = resolveRelativeTime("now-7d", fixedDate);
|
|
38
|
+
var expected = dayjs(fixedDate).subtract(7, "day").toDate();
|
|
39
|
+
expect(result).toEqual(expected);
|
|
40
|
+
});
|
|
41
|
+
it("should subtract weeks", function () {
|
|
42
|
+
var result = resolveRelativeTime("now-2w", fixedDate);
|
|
43
|
+
var expected = dayjs(fixedDate).subtract(2, "week").toDate();
|
|
44
|
+
expect(result).toEqual(expected);
|
|
45
|
+
});
|
|
46
|
+
it("should subtract months", function () {
|
|
47
|
+
var result = resolveRelativeTime("now-1M", fixedDate);
|
|
48
|
+
var expected = dayjs(fixedDate).subtract(1, "month").toDate();
|
|
49
|
+
expect(result).toEqual(expected);
|
|
50
|
+
});
|
|
51
|
+
it("should subtract quarters", function () {
|
|
52
|
+
var result = resolveRelativeTime("now-1Q", fixedDate);
|
|
53
|
+
var expected = dayjs(fixedDate).subtract(1, "quarter").toDate();
|
|
54
|
+
expect(result).toEqual(expected);
|
|
55
|
+
});
|
|
56
|
+
it("should subtract years", function () {
|
|
57
|
+
var result = resolveRelativeTime("now-1y", fixedDate);
|
|
58
|
+
var expected = dayjs(fixedDate).subtract(1, "year").toDate();
|
|
59
|
+
expect(result).toEqual(expected);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
describe("addition operations", function () {
|
|
63
|
+
it("should add seconds", function () {
|
|
64
|
+
var result = resolveRelativeTime("now+30s", fixedDate);
|
|
65
|
+
var expected = dayjs(fixedDate).add(30, "second").toDate();
|
|
66
|
+
expect(result).toEqual(expected);
|
|
67
|
+
});
|
|
68
|
+
it("should add minutes", function () {
|
|
69
|
+
var result = resolveRelativeTime("now+15m", fixedDate);
|
|
70
|
+
var expected = dayjs(fixedDate).add(15, "minute").toDate();
|
|
71
|
+
expect(result).toEqual(expected);
|
|
72
|
+
});
|
|
73
|
+
it("should add hours", function () {
|
|
74
|
+
var result = resolveRelativeTime("now+3h", fixedDate);
|
|
75
|
+
var expected = dayjs(fixedDate).add(3, "hour").toDate();
|
|
76
|
+
expect(result).toEqual(expected);
|
|
77
|
+
});
|
|
78
|
+
it("should add days", function () {
|
|
79
|
+
var result = resolveRelativeTime("now+5d", fixedDate);
|
|
80
|
+
var expected = dayjs(fixedDate).add(5, "day").toDate();
|
|
81
|
+
expect(result).toEqual(expected);
|
|
82
|
+
});
|
|
83
|
+
it("should add weeks", function () {
|
|
84
|
+
var result = resolveRelativeTime("now+2w", fixedDate);
|
|
85
|
+
var expected = dayjs(fixedDate).add(2, "week").toDate();
|
|
86
|
+
expect(result).toEqual(expected);
|
|
87
|
+
});
|
|
88
|
+
it("should add months", function () {
|
|
89
|
+
var result = resolveRelativeTime("now+2M", fixedDate);
|
|
90
|
+
var expected = dayjs(fixedDate).add(2, "month").toDate();
|
|
91
|
+
expect(result).toEqual(expected);
|
|
92
|
+
});
|
|
93
|
+
it("should add quarters", function () {
|
|
94
|
+
var result = resolveRelativeTime("now+1Q", fixedDate);
|
|
95
|
+
var expected = dayjs(fixedDate).add(1, "quarter").toDate();
|
|
96
|
+
expect(result).toEqual(expected);
|
|
97
|
+
});
|
|
98
|
+
it("should add years", function () {
|
|
99
|
+
var result = resolveRelativeTime("now+1y", fixedDate);
|
|
100
|
+
var expected = dayjs(fixedDate).add(1, "year").toDate();
|
|
101
|
+
expect(result).toEqual(expected);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe("truncation operations", function () {
|
|
105
|
+
it("should truncate to start of second", function () {
|
|
106
|
+
var result = resolveRelativeTime("now/s", fixedDate);
|
|
107
|
+
var expected = dayjs(fixedDate).startOf("second").toDate();
|
|
108
|
+
expect(result).toEqual(expected);
|
|
109
|
+
});
|
|
110
|
+
it("should truncate to start of minute", function () {
|
|
111
|
+
var result = resolveRelativeTime("now/m", fixedDate);
|
|
112
|
+
var expected = dayjs(fixedDate).startOf("minute").toDate();
|
|
113
|
+
expect(result).toEqual(expected);
|
|
114
|
+
});
|
|
115
|
+
it("should truncate to start of hour", function () {
|
|
116
|
+
var result = resolveRelativeTime("now/h", fixedDate);
|
|
117
|
+
var expected = dayjs(fixedDate).startOf("hour").toDate();
|
|
118
|
+
expect(result).toEqual(expected);
|
|
119
|
+
});
|
|
120
|
+
it("should truncate to start of day", function () {
|
|
121
|
+
var result = resolveRelativeTime("now/d", fixedDate);
|
|
122
|
+
var expected = dayjs(fixedDate).startOf("day").toDate();
|
|
123
|
+
expect(result).toEqual(expected);
|
|
124
|
+
});
|
|
125
|
+
it("should truncate to start of week", function () {
|
|
126
|
+
var result = resolveRelativeTime("now/w", fixedDate);
|
|
127
|
+
var expected = dayjs(fixedDate).startOf("week").toDate();
|
|
128
|
+
expect(result).toEqual(expected);
|
|
129
|
+
});
|
|
130
|
+
it("should truncate to start of month", function () {
|
|
131
|
+
var result = resolveRelativeTime("now/M", fixedDate);
|
|
132
|
+
var expected = dayjs(fixedDate).startOf("month").toDate();
|
|
133
|
+
expect(result).toEqual(expected);
|
|
134
|
+
});
|
|
135
|
+
it("should truncate to start of quarter", function () {
|
|
136
|
+
var result = resolveRelativeTime("now/Q", fixedDate);
|
|
137
|
+
var expected = dayjs(fixedDate).startOf("quarter").toDate();
|
|
138
|
+
expect(result).toEqual(expected);
|
|
139
|
+
});
|
|
140
|
+
it("should truncate to start of year", function () {
|
|
141
|
+
var result = resolveRelativeTime("now/y", fixedDate);
|
|
142
|
+
var expected = dayjs(fixedDate).startOf("year").toDate();
|
|
143
|
+
expect(result).toEqual(expected);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
describe("endOf truncation operations (backslash)", function () {
|
|
147
|
+
it("should truncate to end of second", function () {
|
|
148
|
+
var result = resolveRelativeTime("now\\s", fixedDate);
|
|
149
|
+
var expected = dayjs(fixedDate).endOf("second").toDate();
|
|
150
|
+
expect(result).toEqual(expected);
|
|
151
|
+
});
|
|
152
|
+
it("should truncate to end of minute", function () {
|
|
153
|
+
var result = resolveRelativeTime("now\\m", fixedDate);
|
|
154
|
+
var expected = dayjs(fixedDate).endOf("minute").toDate();
|
|
155
|
+
expect(result).toEqual(expected);
|
|
156
|
+
});
|
|
157
|
+
it("should truncate to end of hour", function () {
|
|
158
|
+
var result = resolveRelativeTime("now\\h", fixedDate);
|
|
159
|
+
var expected = dayjs(fixedDate).endOf("hour").toDate();
|
|
160
|
+
expect(result).toEqual(expected);
|
|
161
|
+
});
|
|
162
|
+
it("should truncate to end of day", function () {
|
|
163
|
+
var result = resolveRelativeTime("now\\d", fixedDate);
|
|
164
|
+
var expected = dayjs(fixedDate).endOf("day").toDate();
|
|
165
|
+
expect(result).toEqual(expected);
|
|
166
|
+
});
|
|
167
|
+
it("should truncate to end of week", function () {
|
|
168
|
+
var result = resolveRelativeTime("now\\w", fixedDate);
|
|
169
|
+
var expected = dayjs(fixedDate).endOf("week").toDate();
|
|
170
|
+
expect(result).toEqual(expected);
|
|
171
|
+
});
|
|
172
|
+
it("should truncate to end of month", function () {
|
|
173
|
+
var result = resolveRelativeTime("now\\M", fixedDate);
|
|
174
|
+
var expected = dayjs(fixedDate).endOf("month").toDate();
|
|
175
|
+
expect(result).toEqual(expected);
|
|
176
|
+
});
|
|
177
|
+
it("should truncate to end of quarter", function () {
|
|
178
|
+
var result = resolveRelativeTime("now\\Q", fixedDate);
|
|
179
|
+
var expected = dayjs(fixedDate).endOf("quarter").toDate();
|
|
180
|
+
expect(result).toEqual(expected);
|
|
181
|
+
});
|
|
182
|
+
it("should truncate to end of year", function () {
|
|
183
|
+
var result = resolveRelativeTime("now\\y", fixedDate);
|
|
184
|
+
var expected = dayjs(fixedDate).endOf("year").toDate();
|
|
185
|
+
expect(result).toEqual(expected);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
describe("complex combinations", function () {
|
|
189
|
+
it("should handle \"now-1M/M\" (start of previous month)", function () {
|
|
190
|
+
var result = resolveRelativeTime("now-1M/M", fixedDate);
|
|
191
|
+
var expected = dayjs(fixedDate).subtract(1, "month").startOf("month").toDate();
|
|
192
|
+
expect(result).toEqual(expected);
|
|
193
|
+
});
|
|
194
|
+
it("should handle \"now/d+1d-1s\" (end of current day)", function () {
|
|
195
|
+
var result = resolveRelativeTime("now/d+1d-1s", fixedDate);
|
|
196
|
+
var expected = dayjs(fixedDate).startOf("day").add(1, "day").subtract(1, "second").toDate();
|
|
197
|
+
expect(result).toEqual(expected);
|
|
198
|
+
});
|
|
199
|
+
it("should handle multiple operations \"now-1w+2d-3h\"", function () {
|
|
200
|
+
var result = resolveRelativeTime("now-1w+2d-3h", fixedDate);
|
|
201
|
+
var expected = dayjs(fixedDate).subtract(1, "week").add(2, "day").subtract(3, "hour").toDate();
|
|
202
|
+
expect(result).toEqual(expected);
|
|
203
|
+
});
|
|
204
|
+
it("should handle \"now-1M\\M\" (end of previous month)", function () {
|
|
205
|
+
var result = resolveRelativeTime("now-1M\\M", fixedDate);
|
|
206
|
+
var expected = dayjs(fixedDate).subtract(1, "month").endOf("month").toDate();
|
|
207
|
+
expect(result).toEqual(expected);
|
|
208
|
+
});
|
|
209
|
+
it("should handle \"now\\d\" vs \"now/d+1d-1s\" (both end of current day)", function () {
|
|
210
|
+
var resultBackslash = resolveRelativeTime("now\\d", fixedDate);
|
|
211
|
+
var resultAlternative = resolveRelativeTime("now/d+1d-1s", fixedDate);
|
|
212
|
+
var expectedBackslash = dayjs(fixedDate).endOf("day").toDate();
|
|
213
|
+
var expectedAlternative = dayjs(fixedDate).startOf("day").add(1, "day").subtract(1, "second").toDate();
|
|
214
|
+
expect(resultBackslash).toEqual(expectedBackslash);
|
|
215
|
+
expect(resultAlternative).toEqual(expectedAlternative);
|
|
216
|
+
// Note: endOf gives millisecond precision (.999), while alternative gives second precision (.000)
|
|
217
|
+
// Both represent end of day, but endOf is more precise
|
|
218
|
+
expect(resultBackslash.getTime()).toBeGreaterThan(resultAlternative.getTime());
|
|
219
|
+
});
|
|
220
|
+
it("should handle \"now-1y\\y\" (end of previous year)", function () {
|
|
221
|
+
var result = resolveRelativeTime("now-1y\\y", fixedDate);
|
|
222
|
+
var expected = dayjs(fixedDate).subtract(1, "year").endOf("year").toDate();
|
|
223
|
+
expect(result).toEqual(expected);
|
|
224
|
+
});
|
|
225
|
+
it("should handle \"now/y+6M\" (middle of current year)", function () {
|
|
226
|
+
var result = resolveRelativeTime("now/y+6M", fixedDate);
|
|
227
|
+
var expected = dayjs(fixedDate).startOf("year").add(6, "month").toDate();
|
|
228
|
+
expect(result).toEqual(expected);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
describe("error cases", function () {
|
|
232
|
+
it("should throw error for invalid format", function () {
|
|
233
|
+
expect(function () {
|
|
234
|
+
return resolveRelativeTime("invalid", fixedDate);
|
|
235
|
+
}).toThrow("Invalid");
|
|
236
|
+
});
|
|
237
|
+
it("should throw error for non-now start", function () {
|
|
238
|
+
expect(function () {
|
|
239
|
+
return resolveRelativeTime("then-1h", fixedDate);
|
|
240
|
+
}).toThrow("Invalid");
|
|
241
|
+
});
|
|
242
|
+
it("should throw error for invalid time unit", function () {
|
|
243
|
+
expect(function () {
|
|
244
|
+
return resolveRelativeTime("now-1x", fixedDate);
|
|
245
|
+
}).toThrow("Invalid time operand");
|
|
246
|
+
});
|
|
247
|
+
it("should throw error for invalid operator", function () {
|
|
248
|
+
expect(function () {
|
|
249
|
+
return resolveRelativeTime("now*1h", fixedDate);
|
|
250
|
+
}).toThrow("Invalid relative time format");
|
|
251
|
+
});
|
|
252
|
+
it("should throw error for invalid truncation unit", function () {
|
|
253
|
+
expect(function () {
|
|
254
|
+
return resolveRelativeTime("now/z", fixedDate);
|
|
255
|
+
}).toThrow();
|
|
256
|
+
});
|
|
257
|
+
it("should throw error for incomplete operation", function () {
|
|
258
|
+
expect(function () {
|
|
259
|
+
return resolveRelativeTime("now-", fixedDate);
|
|
260
|
+
}).toThrow("Invalid relative time format");
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
describe("Grafana examples from comments", function () {
|
|
264
|
+
it("should handle \"now-24h\" (last 24 hours)", function () {
|
|
265
|
+
var result = resolveRelativeTime("now-24h", fixedDate);
|
|
266
|
+
var expected = dayjs(fixedDate).subtract(24, "hour").toDate();
|
|
267
|
+
expect(result).toEqual(expected);
|
|
268
|
+
});
|
|
269
|
+
it("should handle \"now/M\" (start of current month)", function () {
|
|
270
|
+
var result = resolveRelativeTime("now/M", fixedDate);
|
|
271
|
+
var expected = dayjs(fixedDate).startOf("month").toDate();
|
|
272
|
+
expect(result).toEqual(expected);
|
|
273
|
+
});
|
|
274
|
+
it("should handle \"now-7d\" (last 7 days)", function () {
|
|
275
|
+
var result = resolveRelativeTime("now-7d", fixedDate);
|
|
276
|
+
var expected = dayjs(fixedDate).subtract(7, "day").toDate();
|
|
277
|
+
expect(result).toEqual(expected);
|
|
278
|
+
});
|
|
279
|
+
it("should handle \"now/y\" (start of current year)", function () {
|
|
280
|
+
var result = resolveRelativeTime("now/y", fixedDate);
|
|
281
|
+
var expected = dayjs(fixedDate).startOf("year").toDate();
|
|
282
|
+
expect(result).toEqual(expected);
|
|
283
|
+
});
|
|
284
|
+
it("should handle \"now/w\" (start of current week)", function () {
|
|
285
|
+
var result = resolveRelativeTime("now/w", fixedDate);
|
|
286
|
+
var expected = dayjs(fixedDate).startOf("week").toDate();
|
|
287
|
+
expect(result).toEqual(expected);
|
|
288
|
+
});
|
|
289
|
+
it("should handle \"now\\d\" (end of current day)", function () {
|
|
290
|
+
var result = resolveRelativeTime("now\\d", fixedDate);
|
|
291
|
+
var expected = dayjs(fixedDate).endOf("day").toDate();
|
|
292
|
+
expect(result).toEqual(expected);
|
|
293
|
+
});
|
|
294
|
+
it("should handle \"now\\M\" (end of current month)", function () {
|
|
295
|
+
var result = resolveRelativeTime("now\\M", fixedDate);
|
|
296
|
+
var expected = dayjs(fixedDate).endOf("month").toDate();
|
|
297
|
+
expect(result).toEqual(expected);
|
|
298
|
+
});
|
|
299
|
+
it("should handle \"now\\w\" (end of current week)", function () {
|
|
300
|
+
var result = resolveRelativeTime("now\\w", fixedDate);
|
|
301
|
+
var expected = dayjs(fixedDate).endOf("week").toDate();
|
|
302
|
+
expect(result).toEqual(expected);
|
|
303
|
+
});
|
|
304
|
+
it("should handle \"now\\y\" (end of current year)", function () {
|
|
305
|
+
var result = resolveRelativeTime("now\\y", fixedDate);
|
|
306
|
+
var expected = dayjs(fixedDate).endOf("year").toDate();
|
|
307
|
+
expect(result).toEqual(expected);
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
});
|
package/lib/decimal/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/decimal/index.ts"],"sourcesContent":["export { parseDecimal } from './parseDecimal';\n"],"names":["parseDecimal"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Decimal from
|
|
1
|
+
import Decimal from "decimal.js";
|
|
2
2
|
export function parseDecimal(v) {
|
|
3
3
|
switch(v){
|
|
4
4
|
case '':
|
|
@@ -11,3 +11,5 @@ export function parseDecimal(v) {
|
|
|
11
11
|
}
|
|
12
12
|
return new Decimal(v);
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=parseDecimal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/decimal/parseDecimal.ts"],"sourcesContent":["import Decimal from 'decimal.js';\n\nexport function parseDecimal(v: string | number | Decimal): Decimal;\nexport function parseDecimal(v: string | number | Decimal | undefined | null): Decimal | undefined;\nexport function parseDecimal(v: string | number | Decimal | undefined | null): Decimal | undefined {\n\tswitch (v) {\n\t\tcase '':\n\t\tcase undefined:\n\t\tcase null:\n\t\t\treturn undefined;\n\t}\n\tif (Decimal.isDecimal(v)) {\n\t\treturn v;\n\t}\n\treturn new Decimal(v);\n}\n"],"names":["Decimal","parseDecimal","v","undefined","isDecimal"],"mappings":"AAAA,OAAOA,aAAa,aAAa;AAIjC,OAAO,SAASC,aAAaC,CAA+C;IAC3E,OAAQA;QACP,KAAK;QACL,KAAKC;QACL,KAAK;YACJ,OAAOA;IACT;IACA,IAAIH,QAAQI,SAAS,CAACF,IAAI;QACzB,OAAOA;IACR;IACA,OAAO,IAAIF,QAAQE;AACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/emittery/emitter.ts"],"sourcesContent":["import Emittery, { type EventName } from 'emittery';\n\nexport function createEmitter<EventData = Record<EventName, any>>(name: string) {\n\treturn new Emittery<EventData>({\n\t\tdebug: {\n\t\t\tname,\n\t\t},\n\t});\n}\n"],"names":["Emittery","createEmitter","name","debug"],"mappings":"AAAA,OAAOA,cAAkC,WAAW;AAEpD,OAAO,SAASC,cAAkDC,IAAY;IAC7E,OAAO,IAAIF,SAAoB;QAC9BG,OAAO;YACND;QACD;IACD;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/emittery/index.ts"],"sourcesContent":["export { createEmitter } from './emitter';\n"],"names":["createEmitter"],"mappings":"AAAA,SAASA,aAAa,QAAQ,YAAY"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
2
|
// Sex 指的是生理性别/生物性别,通常由出生时的生物特征决定
|
|
3
|
-
export
|
|
3
|
+
export const SexType = Object.freeze({
|
|
4
4
|
__proto__: null,
|
|
5
5
|
Male: 'Male',
|
|
6
6
|
Female: 'Female'
|
|
7
7
|
});
|
|
8
|
-
export
|
|
8
|
+
export const SexTypeSchema = z.union([
|
|
9
9
|
//
|
|
10
10
|
z.literal(SexType.Male).describe('男'),
|
|
11
11
|
z.literal(SexType.Female).describe('女')
|
|
12
12
|
]).describe('性别').meta({
|
|
13
13
|
title: 'SexType'
|
|
14
14
|
});
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=SexType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/foundation/schema/SexType.ts"],"sourcesContent":["import { z } from 'zod/v4';\nimport type { EnumValues } from '../../resource/schema';\n\n// Sex 指的是生理性别/生物性别,通常由出生时的生物特征决定\nexport const SexType = Object.freeze({\n\t__proto__: null,\n\tMale: 'Male',\n\tFemale: 'Female',\n});\nexport type SexType = EnumValues<typeof SexType>;\n\nexport const SexTypeSchema = z\n\t.union([\n\t\t//\n\t\tz.literal(SexType.Male).describe('男'),\n\t\tz.literal(SexType.Female).describe('女'),\n\t])\n\t.describe('性别')\n\t.meta({\n\t\ttitle: 'SexType',\n\t});\n"],"names":["z","SexType","Object","freeze","__proto__","Male","Female","SexTypeSchema","union","literal","describe","meta","title"],"mappings":"AAAA,SAASA,CAAC,QAAQ,SAAS;AAG3B,iCAAiC;AACjC,OAAO,MAAMC,UAAUC,OAAOC,MAAM,CAAC;IACpCC,WAAW;IACXC,MAAM;IACNC,QAAQ;AACT,GAAG;AAGH,OAAO,MAAMC,gBAAgBP,EAC3BQ,KAAK,CAAC;IACN,EAAE;IACFR,EAAES,OAAO,CAACR,QAAQI,IAAI,EAAEK,QAAQ,CAAC;IACjCV,EAAES,OAAO,CAACR,QAAQK,MAAM,EAAEI,QAAQ,CAAC;CACnC,EACAA,QAAQ,CAAC,MACTC,IAAI,CAAC;IACLC,OAAO;AACR,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/foundation/schema/index.ts"],"sourcesContent":["export { SexType, SexTypeSchema } from './SexType';\n"],"names":["SexType","SexTypeSchema"],"mappings":"AAAA,SAASA,OAAO,EAAEC,aAAa,QAAQ,YAAY"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/foundation/schema/parseSexType.ts"],"sourcesContent":["import { SexType } from './SexType';\n\nexport function parseSexType(s: string | null | undefined): undefined | SexType {\n\tif (!s) return undefined;\n\n\tswitch (s.toLowerCase()) {\n\t\tcase '♂':\n\t\tcase '男':\n\t\tcase 'male':\n\t\tcase 'man':\n\t\t\treturn SexType.Male;\n\t\tcase '♀':\n\t\tcase '女':\n\t\tcase 'female':\n\t\tcase 'woman':\n\t\t\treturn SexType.Female;\n\t}\n\treturn undefined;\n}\n"],"names":["SexType","parseSexType","s","undefined","toLowerCase","Male","Female"],"mappings":"AAAA,SAASA,OAAO,QAAQ,YAAY;AAEpC,OAAO,SAASC,aAAaC,CAA4B;IACxD,IAAI,CAACA,GAAG,OAAOC;IAEf,OAAQD,EAAEE,WAAW;QACpB,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;YACJ,OAAOJ,QAAQK,IAAI;QACpB,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;YACJ,OAAOL,QAAQM,MAAM;IACvB;IACA,OAAOH;AACR"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import z from
|
|
2
|
-
export
|
|
1
|
+
import z from "zod/v4";
|
|
2
|
+
export const CoordinatesSchema = z.object({
|
|
3
3
|
latitude: z.number().min(-90).max(90).describe('纬度'),
|
|
4
4
|
longitude: z.number().min(-180).max(180).describe('经度')
|
|
5
5
|
}).describe('坐标信息');
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/foundation/schema/types.ts"],"sourcesContent":["import z from 'zod/v4';\n\nexport const CoordinatesSchema = z\n\t.object({\n\t\tlatitude: z.number().min(-90).max(90).describe('纬度'),\n\t\tlongitude: z.number().min(-180).max(180).describe('经度'),\n\t})\n\t.describe('坐标信息');\n"],"names":["z","CoordinatesSchema","object","latitude","number","min","max","describe","longitude"],"mappings":"AAAA,OAAOA,OAAO,SAAS;AAEvB,OAAO,MAAMC,oBAAoBD,EAC/BE,MAAM,CAAC;IACPC,UAAUH,EAAEI,MAAM,GAAGC,GAAG,CAAC,CAAC,IAAIC,GAAG,CAAC,IAAIC,QAAQ,CAAC;IAC/CC,WAAWR,EAAEI,MAAM,GAAGC,GAAG,CAAC,CAAC,KAAKC,GAAG,CAAC,KAAKC,QAAQ,CAAC;AACnD,GACCA,QAAQ,CAAC,QAAQ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const FileSystemErrorCode = {
|
|
2
|
+
ENOENT: 'ENOENT',
|
|
3
|
+
ENOTDIR: 'ENOTDIR',
|
|
4
|
+
EEXIST: 'EEXIST',
|
|
5
|
+
EISDIR: 'EISDIR',
|
|
6
|
+
ENOTEMPTY: 'ENOTEMPTY',
|
|
7
|
+
EACCES: 'EACCES',
|
|
8
|
+
EPERM: 'EPERM',
|
|
9
|
+
EINVAL: 'EINVAL'
|
|
10
|
+
};
|
|
11
|
+
export class FileSystemError extends Error {
|
|
12
|
+
code;
|
|
13
|
+
constructor(message, code){
|
|
14
|
+
super(message), this.code = code;
|
|
15
|
+
this.name = 'FileSystemError';
|
|
16
|
+
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
17
|
+
if (Error.captureStackTrace) {
|
|
18
|
+
Error.captureStackTrace(this, FileSystemError);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=FileSystemError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fs/FileSystemError.ts"],"sourcesContent":["export const FileSystemErrorCode = {\n\tENOENT: 'ENOENT',\n\tENOTDIR: 'ENOTDIR',\n\tEEXIST: 'EEXIST',\n\tEISDIR: 'EISDIR',\n\tENOTEMPTY: 'ENOTEMPTY',\n\tEACCES: 'EACCES',\n\tEPERM: 'EPERM',\n\tEINVAL: 'EINVAL',\n} as const;\n\nexport type FileSystemErrorCode = (typeof FileSystemErrorCode)[keyof typeof FileSystemErrorCode];\n\nexport class FileSystemError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly code: FileSystemErrorCode | string,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'FileSystemError';\n\t\t// Maintains proper stack trace for where our error was thrown (only available on V8)\n\t\tif (Error.captureStackTrace) {\n\t\t\tError.captureStackTrace(this, FileSystemError);\n\t\t}\n\t}\n}\n"],"names":["FileSystemErrorCode","ENOENT","ENOTDIR","EEXIST","EISDIR","ENOTEMPTY","EACCES","EPERM","EINVAL","FileSystemError","Error","message","code","name","captureStackTrace"],"mappings":"AAAA,OAAO,MAAMA,sBAAsB;IAClCC,QAAQ;IACRC,SAAS;IACTC,QAAQ;IACRC,QAAQ;IACRC,WAAW;IACXC,QAAQ;IACRC,OAAO;IACPC,QAAQ;AACT,EAAW;AAIX,OAAO,MAAMC,wBAAwBC;;IACpC,YACCC,OAAe,EACf,AAAgBC,IAAkC,CACjD;QACD,KAAK,CAACD,eAFUC,OAAAA;QAGhB,IAAI,CAACC,IAAI,GAAG;QACZ,qFAAqF;QACrF,IAAIH,MAAMI,iBAAiB,EAAE;YAC5BJ,MAAMI,iBAAiB,CAAC,IAAI,EAAEL;QAC/B;IACD;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fs/IFileSystem.d.ts"],"sourcesContent":["import type { FileKind, FileUrlOptions } from './types';\n\n// Base operation options\ntype OperationOptions = {\n\tsignal?: AbortSignal;\n};\n\n// Directory operations\nexport type ReaddirOptions = OperationOptions & {\n\tglob?: string;\n\trecursive?: boolean;\n\tdepth?: number;\n\tkind?: FileKind;\n\thidden?: boolean;\n};\nexport type MkdirOptions = OperationOptions & {\n\trecursive?: boolean;\n};\n// File operations\nexport type ReadFileOptions = OperationOptions & {\n\tencoding?: 'text' | 'binary';\n\tonDownloadProgress?: (e: { loaded: number; total: number }) => void;\n};\nexport type WriteFileOptions = OperationOptions & {\n\toverwrite?: boolean;\n\tonUploadProgress?: (e: { loaded: number; total: number }) => void;\n};\nexport type RenameOptions = OperationOptions & {\n\toverwrite?: boolean;\n};\nexport type RmOptions = OperationOptions & {\n\trecursive?: boolean;\n\tforce?: boolean;\n};\nexport type CopyOptions = OperationOptions & {\n\toverwrite?: boolean;\n\tshallow?: boolean;\n};\nexport type CreateReadStreamOptions = OperationOptions & {\n\trange?: { start: number; end?: number };\n\tsignal?: AbortSignal;\n};\nexport type CreateWriteStreamOptions = OperationOptions & {\n\toverwrite?: boolean;\n};\nexport type StatOptions = OperationOptions & {};\n\ntype WritableData = string | ArrayBuffer | ArrayBufferView | ReadableStream;\n\n/**\n * Universal file system interface (browser & server compatible)\n */\nexport type IFileSystem = {\n\treaddir(dir: string, options?: ReaddirOptions): Promise<IFileStat[]>;\n\tstat(entry: string, options?: StatOptions): Promise<IFileStat>;\n\tmkdir(path: string, options?: MkdirOptions): Promise<void>;\n\treadFile(path: string, options?: ReadFileOptions & { encoding: 'text' }): Promise<string>;\n\treadFile(path: string, options?: ReadFileOptions): Promise<Uint8Array>;\n\twriteFile(path: string, data: WritableData, options?: WriteFileOptions): Promise<void>;\n\trm(path: string, options?: RmOptions): Promise<void>;\n\trename(oldPath: string, newPath: string, options?: RenameOptions): Promise<void>;\n\texists(path: string): Promise<boolean>;\n\tcopy(src: string, dest: string, options?: CopyOptions): Promise<void>;\n\n\tgetUrl?(path: IFileStat | string, options?: FileUrlOptions): string | undefined;\n\n\tcreateReadableStream?(path: string, options?: CreateReadStreamOptions): ReadableStream;\n\tcreateWritableStream?(path: string, options?: CreateWriteStreamOptions): WritableStream;\n};\n\n/**\n * Server/Node.js specific file system interface with stream support\n */\nexport type IServerFileSystem = IFileSystem & {\n\tcreateReadStream(path: string, options?: CreateReadStreamOptions): import('node:stream').Readable;\n\tcreateWriteStream(path: string, options?: CreateWriteStreamOptions): import('node:stream').Writable;\n\twriteFile(\n\t\tpath: string,\n\t\tdata: WritableData | Buffer | import('node:stream').Readable,\n\t\toptions?: WriteFileOptions,\n\t): Promise<void>;\n};\n\nexport type IFileStat = {\n\t/**\n\t * parent path\n\t */\n\tdirectory: string;\n\t/**\n\t * full path\n\t */\n\tpath: string;\n\t/**\n\t * basename\n\t */\n\tname: string;\n\tkind: 'directory' | 'file';\n\tmtime: number;\n\tmeta: Record<string, any>;\n\tsize: number;\n};\n\n"],"names":[],"mappings":"AAmFA,WAiBE"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
}
|
|
6
|
+
catch (error) {
|
|
7
|
+
reject(error);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (info.done) {
|
|
11
|
+
resolve(value);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
Promise.resolve(value).then(_next, _throw);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _async_to_generator(fn) {
|
|
18
|
+
return function () {
|
|
19
|
+
var self = this, args = arguments;
|
|
20
|
+
return new Promise(function (resolve, reject) {
|
|
21
|
+
var gen = fn.apply(self, args);
|
|
22
|
+
function _next(value) {
|
|
23
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
24
|
+
}
|
|
25
|
+
function _throw(err) {
|
|
26
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
27
|
+
}
|
|
28
|
+
_next(undefined);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function _ts_generator(thisArg, body) {
|
|
33
|
+
var f, y, t, _ = {
|
|
34
|
+
label: 0,
|
|
35
|
+
sent: function () {
|
|
36
|
+
if (t[0] & 1)
|
|
37
|
+
throw t[1];
|
|
38
|
+
return t[1];
|
|
39
|
+
},
|
|
40
|
+
trys: [],
|
|
41
|
+
ops: []
|
|
42
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
43
|
+
return d(g, "next", {
|
|
44
|
+
value: verb(0)
|
|
45
|
+
}), d(g, "throw", {
|
|
46
|
+
value: verb(1)
|
|
47
|
+
}), d(g, "return", {
|
|
48
|
+
value: verb(2)
|
|
49
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
50
|
+
value: function () {
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
}), g;
|
|
54
|
+
function verb(n) {
|
|
55
|
+
return function (v) {
|
|
56
|
+
return step([
|
|
57
|
+
n,
|
|
58
|
+
v
|
|
59
|
+
]);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function step(op) {
|
|
63
|
+
if (f)
|
|
64
|
+
throw new TypeError("Generator is already executing.");
|
|
65
|
+
while (g && (g = 0, op[0] && (_ = 0)), _)
|
|
66
|
+
try {
|
|
67
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
|
68
|
+
return t;
|
|
69
|
+
if (y = 0, t)
|
|
70
|
+
op = [
|
|
71
|
+
op[0] & 2,
|
|
72
|
+
t.value
|
|
73
|
+
];
|
|
74
|
+
switch (op[0]) {
|
|
75
|
+
case 0:
|
|
76
|
+
case 1:
|
|
77
|
+
t = op;
|
|
78
|
+
break;
|
|
79
|
+
case 4:
|
|
80
|
+
_.label++;
|
|
81
|
+
return {
|
|
82
|
+
value: op[1],
|
|
83
|
+
done: false
|
|
84
|
+
};
|
|
85
|
+
case 5:
|
|
86
|
+
_.label++;
|
|
87
|
+
y = op[1];
|
|
88
|
+
op = [
|
|
89
|
+
0
|
|
90
|
+
];
|
|
91
|
+
continue;
|
|
92
|
+
case 7:
|
|
93
|
+
op = _.ops.pop();
|
|
94
|
+
_.trys.pop();
|
|
95
|
+
continue;
|
|
96
|
+
default:
|
|
97
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
98
|
+
_ = 0;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
102
|
+
_.label = op[1];
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
106
|
+
_.label = t[1];
|
|
107
|
+
t = op;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
if (t && _.label < t[2]) {
|
|
111
|
+
_.label = t[2];
|
|
112
|
+
_.ops.push(op);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
if (t[2])
|
|
116
|
+
_.ops.pop();
|
|
117
|
+
_.trys.pop();
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
op = body.call(thisArg, _);
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
op = [
|
|
124
|
+
6,
|
|
125
|
+
e
|
|
126
|
+
];
|
|
127
|
+
y = 0;
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
f = t = 0;
|
|
131
|
+
}
|
|
132
|
+
if (op[0] & 5)
|
|
133
|
+
throw op[1];
|
|
134
|
+
return {
|
|
135
|
+
value: op[0] ? op[1] : void 0,
|
|
136
|
+
done: true
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
import { beforeEach, describe, test } from "vitest";
|
|
141
|
+
import { createMemoryFileSystem } from "./createMemoryFileSystem.js";
|
|
142
|
+
import { runFileSystemTest } from "./tests/runFileSystemTest.js";
|
|
143
|
+
describe("MemoryFileSystem", function () {
|
|
144
|
+
var fs;
|
|
145
|
+
beforeEach(function () {
|
|
146
|
+
fs = createMemoryFileSystem({
|
|
147
|
+
root: {
|
|
148
|
+
path: "/",
|
|
149
|
+
directory: "",
|
|
150
|
+
name: "",
|
|
151
|
+
kind: "directory",
|
|
152
|
+
meta: {},
|
|
153
|
+
mtime: Date.now(),
|
|
154
|
+
size: 0,
|
|
155
|
+
children: [
|
|
156
|
+
{
|
|
157
|
+
path: "/README.txt",
|
|
158
|
+
directory: "/",
|
|
159
|
+
name: "README.txt",
|
|
160
|
+
kind: "file",
|
|
161
|
+
content: "Hello",
|
|
162
|
+
size: 5,
|
|
163
|
+
meta: {},
|
|
164
|
+
mtime: Date.now()
|
|
165
|
+
}
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
test("common tests", function () {
|
|
171
|
+
return _async_to_generator(function () {
|
|
172
|
+
return _ts_generator(this, function (_state) {
|
|
173
|
+
switch (_state.label) {
|
|
174
|
+
case 0:
|
|
175
|
+
return [
|
|
176
|
+
4,
|
|
177
|
+
runFileSystemTest(fs)
|
|
178
|
+
];
|
|
179
|
+
case 1:
|
|
180
|
+
_state.sent();
|
|
181
|
+
return [
|
|
182
|
+
2
|
|
183
|
+
];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
})();
|
|
187
|
+
});
|
|
188
|
+
});
|