elysia 2.0.0-beta.2 → 2.0.0-beta.21
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/dist/adapter/bun/index.d.ts +18 -2
- package/dist/adapter/bun/index.js +467 -110
- package/dist/adapter/bun/index.mjs +467 -112
- package/dist/adapter/types.d.ts +2 -21
- package/dist/adapter/utils.d.ts +14 -3
- package/dist/adapter/utils.js +146 -87
- package/dist/adapter/utils.mjs +148 -90
- package/dist/adapter/web-standard/handler.d.ts +1 -1
- package/dist/adapter/web-standard/handler.js +47 -36
- package/dist/adapter/web-standard/handler.mjs +48 -37
- package/dist/adapter/web-standard/index.js +2 -30
- package/dist/adapter/web-standard/index.mjs +2 -30
- package/dist/adapter/web-standard/utils.js +5 -18
- package/dist/adapter/web-standard/utils.mjs +5 -18
- package/dist/base.d.ts +99 -67
- package/dist/base.js +678 -510
- package/dist/base.mjs +682 -514
- package/dist/compile/aot-capture.d.ts +2 -13
- package/dist/compile/aot-capture.js +26 -69
- package/dist/compile/aot-capture.mjs +28 -67
- package/dist/compile/aot-emit.d.ts +9 -7
- package/dist/compile/aot-emit.js +42 -19
- package/dist/compile/aot-emit.mjs +42 -20
- package/dist/compile/aot.d.ts +17 -19
- package/dist/compile/aot.js +41 -51
- package/dist/compile/aot.mjs +39 -49
- package/dist/compile/handler/descriptor.d.ts +9 -12
- package/dist/compile/handler/descriptor.js +19 -44
- package/dist/compile/handler/descriptor.mjs +20 -42
- package/dist/compile/handler/frozen-validator.d.ts +5 -10
- package/dist/compile/handler/frozen-validator.js +55 -105
- package/dist/compile/handler/frozen-validator.mjs +53 -105
- package/dist/compile/handler/index.d.ts +7 -5
- package/dist/compile/handler/index.js +270 -111
- package/dist/compile/handler/index.mjs +270 -113
- package/dist/compile/handler/jit.d.ts +19 -17
- package/dist/compile/handler/jit.js +222 -149
- package/dist/compile/handler/jit.mjs +224 -152
- package/dist/compile/handler/params.d.ts +1 -4
- package/dist/compile/handler/params.js +10 -5
- package/dist/compile/handler/params.mjs +14 -8
- package/dist/compile/handler/reconstruct.d.ts +2 -2
- package/dist/compile/handler/reconstruct.js +6 -4
- package/dist/compile/handler/reconstruct.mjs +6 -4
- package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
- package/dist/compile/handler/static-clone-resolver.js +8 -0
- package/dist/compile/handler/static-clone-resolver.mjs +7 -0
- package/dist/compile/handler/utils.d.ts +22 -11
- package/dist/compile/handler/utils.js +159 -253
- package/dist/compile/handler/utils.mjs +155 -252
- package/dist/compile/jit-probe.d.ts +2 -2
- package/dist/compile/jit-probe.js +2 -3
- package/dist/compile/jit-probe.mjs +2 -3
- package/dist/compile/lexer.d.ts +7 -4
- package/dist/compile/lexer.js +268 -6
- package/dist/compile/lexer.mjs +268 -4
- package/dist/compile/utils.js +7 -4
- package/dist/compile/utils.mjs +7 -4
- package/dist/compiled.d.ts +0 -1
- package/dist/compiled.js +0 -1
- package/dist/compiled.mjs +0 -1
- package/dist/context.d.ts +14 -4
- package/dist/context.js +17 -32
- package/dist/context.mjs +19 -34
- package/dist/cookie/config.d.ts +7 -2
- package/dist/cookie/config.js +76 -16
- package/dist/cookie/config.mjs +77 -18
- package/dist/cookie/cookie.d.ts +1 -1
- package/dist/cookie/cookie.js +8 -10
- package/dist/cookie/cookie.mjs +8 -10
- package/dist/cookie/crypto.d.ts +8 -7
- package/dist/cookie/crypto.js +51 -40
- package/dist/cookie/crypto.mjs +51 -41
- package/dist/cookie/error.d.ts +1 -2
- package/dist/cookie/error.js +6 -4
- package/dist/cookie/error.mjs +6 -4
- package/dist/cookie/lib.js +7 -2
- package/dist/cookie/lib.mjs +7 -2
- package/dist/cookie/serialize.js +1 -1
- package/dist/cookie/serialize.mjs +1 -1
- package/dist/cookie/types.d.ts +10 -0
- package/dist/cookie/utils.d.ts +4 -8
- package/dist/cookie/utils.js +86 -52
- package/dist/cookie/utils.mjs +89 -54
- package/dist/error.d.ts +113 -103
- package/dist/error.js +181 -117
- package/dist/error.mjs +179 -118
- package/dist/generation.d.ts +2 -2
- package/dist/handler/error.d.ts +26 -15
- package/dist/handler/error.js +77 -96
- package/dist/handler/error.mjs +74 -97
- package/dist/handler/fetch.js +87 -108
- package/dist/handler/fetch.mjs +89 -110
- package/dist/handler/utils.d.ts +12 -6
- package/dist/handler/utils.js +84 -28
- package/dist/handler/utils.mjs +80 -28
- package/dist/index.d.ts +12 -12
- package/dist/index.js +2 -9
- package/dist/index.mjs +1 -1
- package/dist/memory.js +1 -1
- package/dist/memory.mjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/bun.d.ts +8 -1
- package/dist/plugin/aot/bun.js +16 -9
- package/dist/plugin/aot/bun.mjs +17 -10
- package/dist/plugin/aot/core.d.ts +52 -60
- package/dist/plugin/aot/core.js +208 -109
- package/dist/plugin/aot/core.mjs +205 -111
- package/dist/plugin/aot/esbuild.js +8 -5
- package/dist/plugin/aot/esbuild.mjs +9 -6
- package/dist/plugin/aot/hooks.d.ts +6 -17
- package/dist/plugin/aot/hooks.js +36 -14
- package/dist/plugin/aot/hooks.mjs +37 -16
- package/dist/plugin/aot/rspack-loader.d.ts +1 -5
- package/dist/plugin/aot/rspack-loader.js +1 -10
- package/dist/plugin/aot/rspack-loader.mjs +1 -10
- package/dist/plugin/aot/rspack.js +2 -5
- package/dist/plugin/aot/rspack.mjs +3 -6
- package/dist/plugin/aot/source.d.ts +6 -42
- package/dist/plugin/aot/source.js +71 -71
- package/dist/plugin/aot/source.mjs +72 -72
- package/dist/plugin/aot/treeshake.js +2 -6
- package/dist/plugin/aot/treeshake.mjs +2 -6
- package/dist/plugin/aot/unplugin.d.ts +1 -4
- package/dist/plugin/aot/unplugin.js +4 -13
- package/dist/plugin/aot/unplugin.mjs +4 -13
- package/dist/plugin/aot/vite.d.ts +2 -6
- package/dist/plugin/aot/worker.js +2 -2
- package/dist/plugin/aot/worker.mjs +2 -2
- package/dist/plugin/auto-head.js +1 -10
- package/dist/plugin/auto-head.mjs +1 -10
- package/dist/plugin/trace.d.ts +2 -1
- package/dist/route-table.d.ts +3 -0
- package/dist/route-table.js +16 -11
- package/dist/route-table.mjs +16 -11
- package/dist/schema-snapshot.d.ts +0 -4
- package/dist/schema-snapshot.js +32 -49
- package/dist/schema-snapshot.mjs +32 -49
- package/dist/sucrose.d.ts +6 -55
- package/dist/sucrose.js +103 -731
- package/dist/sucrose.mjs +102 -724
- package/dist/trace.d.ts +5 -8
- package/dist/trace.js +23 -134
- package/dist/trace.mjs +24 -135
- package/dist/type/bridge-live.d.ts +4 -2
- package/dist/type/bridge-live.js +6 -3
- package/dist/type/bridge-live.mjs +4 -2
- package/dist/type/bridge.d.ts +6 -4
- package/dist/type/bridge.js +17 -9
- package/dist/type/bridge.mjs +5 -3
- package/dist/type/coerce-plan.d.ts +5 -5
- package/dist/type/coerce-plan.js +41 -39
- package/dist/type/coerce-plan.mjs +43 -39
- package/dist/type/coerce.d.ts +3 -7
- package/dist/type/coerce.js +18 -75
- package/dist/type/coerce.mjs +19 -76
- package/dist/type/compat.d.ts +3 -0
- package/dist/type/compat.js +23 -14
- package/dist/type/compat.mjs +20 -10
- package/dist/type/elysia/array-buffer.d.ts +4 -1
- package/dist/type/elysia/array-buffer.js +17 -17
- package/dist/type/elysia/array-buffer.mjs +17 -17
- package/dist/type/elysia/array-string.js +2 -40
- package/dist/type/elysia/array-string.mjs +2 -39
- package/dist/type/elysia/array.js +5 -9
- package/dist/type/elysia/array.mjs +5 -9
- package/dist/type/elysia/boolean-string.js +2 -3
- package/dist/type/elysia/boolean-string.mjs +1 -1
- package/dist/type/elysia/boolean.js +3 -12
- package/dist/type/elysia/boolean.mjs +3 -11
- package/dist/type/elysia/cookie.d.ts +3 -4
- package/dist/type/elysia/cookie.js +5 -15
- package/dist/type/elysia/cookie.mjs +5 -15
- package/dist/type/elysia/date.js +13 -20
- package/dist/type/elysia/date.mjs +10 -16
- package/dist/type/elysia/file-type.d.ts +11 -4
- package/dist/type/elysia/file-type.js +17 -2
- package/dist/type/elysia/file-type.mjs +17 -3
- package/dist/type/elysia/file.d.ts +1 -3
- package/dist/type/elysia/file.js +11 -27
- package/dist/type/elysia/file.mjs +11 -12
- package/dist/type/elysia/files.js +7 -11
- package/dist/type/elysia/files.mjs +7 -10
- package/dist/type/elysia/form.js +2 -3
- package/dist/type/elysia/form.mjs +3 -3
- package/dist/type/elysia/integer-string.d.ts +1 -1
- package/dist/type/elysia/integer-string.js +4 -30
- package/dist/type/elysia/integer-string.mjs +5 -30
- package/dist/type/elysia/integer.js +3 -12
- package/dist/type/elysia/integer.mjs +3 -11
- package/dist/type/elysia/intersect.js +0 -5
- package/dist/type/elysia/intersect.mjs +0 -5
- package/dist/type/elysia/json-string.d.ts +7 -0
- package/dist/type/elysia/json-string.js +47 -0
- package/dist/type/elysia/json-string.mjs +46 -0
- package/dist/type/elysia/keep-config.d.ts +14 -0
- package/dist/type/elysia/keep-config.js +62 -0
- package/dist/type/elysia/keep-config.mjs +53 -0
- package/dist/type/elysia/maybe-empty.js +3 -4
- package/dist/type/elysia/maybe-empty.mjs +1 -1
- package/dist/type/elysia/nullable.js +2 -3
- package/dist/type/elysia/nullable.mjs +1 -1
- package/dist/type/elysia/number.d.ts +2 -1
- package/dist/type/elysia/number.js +19 -11
- package/dist/type/elysia/number.mjs +18 -10
- package/dist/type/elysia/numeric-enum.d.ts +1 -1
- package/dist/type/elysia/numeric-enum.js +4 -5
- package/dist/type/elysia/numeric-enum.mjs +3 -3
- package/dist/type/elysia/numeric.d.ts +4 -2
- package/dist/type/elysia/numeric.js +20 -17
- package/dist/type/elysia/numeric.mjs +19 -16
- package/dist/type/elysia/object-string.js +2 -37
- package/dist/type/elysia/object-string.mjs +2 -36
- package/dist/type/elysia/object.js +5 -9
- package/dist/type/elysia/object.mjs +5 -9
- package/dist/type/elysia/optional.js +8 -8
- package/dist/type/elysia/optional.mjs +7 -7
- package/dist/type/elysia/problem.d.ts +20 -0
- package/dist/type/elysia/problem.js +25 -0
- package/dist/type/elysia/problem.mjs +24 -0
- package/dist/type/elysia/string.js +4 -3
- package/dist/type/elysia/string.mjs +4 -2
- package/dist/type/elysia/uint8-array.d.ts +1 -1
- package/dist/type/elysia/uint8-array.js +5 -20
- package/dist/type/elysia/uint8-array.mjs +5 -19
- package/dist/type/elysia/union-enum.js +7 -8
- package/dist/type/elysia/union-enum.mjs +6 -6
- package/dist/type/elysia/union.js +0 -5
- package/dist/type/elysia/union.mjs +0 -5
- package/dist/type/elysia/utils.d.ts +2 -4
- package/dist/type/elysia/utils.js +10 -21
- package/dist/type/elysia/utils.mjs +7 -15
- package/dist/type/exports.d.ts +4 -2
- package/dist/type/exports.js +23 -2
- package/dist/type/exports.mjs +11 -2
- package/dist/type/index.d.ts +10 -2
- package/dist/type/index.js +62 -15
- package/dist/type/index.mjs +65 -11
- package/dist/type/shared.d.ts +3 -9
- package/dist/type/shared.js +44 -97
- package/dist/type/shared.mjs +43 -97
- package/dist/type/sync-require.d.ts +11 -0
- package/dist/type/sync-require.js +14 -0
- package/dist/type/sync-require.mjs +12 -0
- package/dist/type/typebox-system-lite.d.ts +2 -0
- package/dist/type/typebox-system-lite.js +34 -0
- package/dist/type/typebox-system-lite.mjs +3 -0
- package/dist/type/typebox-system-require.d.ts +7 -0
- package/dist/type/typebox-system-require.js +24 -0
- package/dist/type/typebox-system-require.mjs +23 -0
- package/dist/type/typebox-type-live.d.ts +11 -0
- package/dist/type/typebox-type-live.js +45 -0
- package/dist/type/typebox-type-live.mjs +20 -0
- package/dist/type/typebox-type.d.ts +34 -0
- package/dist/type/typebox-type.js +199 -0
- package/dist/type/typebox-type.mjs +86 -0
- package/dist/type/typebox-value-live.d.ts +11 -0
- package/dist/type/typebox-value-live.js +31 -0
- package/dist/type/typebox-value-live.mjs +13 -0
- package/dist/type/typebox-value-ops.d.ts +4 -0
- package/dist/type/typebox-value-ops.js +90 -0
- package/dist/type/typebox-value-ops.mjs +5 -0
- package/dist/type/typebox-value-require.d.ts +8 -0
- package/dist/type/typebox-value-require.js +28 -0
- package/dist/type/typebox-value-require.mjs +25 -0
- package/dist/type/typebox-value.d.ts +35 -0
- package/dist/type/typebox-value.js +161 -0
- package/dist/type/typebox-value.mjs +74 -0
- package/dist/type/utils.js +1 -10
- package/dist/type/utils.mjs +1 -10
- package/dist/type/validator/clean-safe.d.ts +2 -4
- package/dist/type/validator/clean-safe.js +15 -11
- package/dist/type/validator/clean-safe.mjs +16 -10
- package/dist/type/validator/custom-error.js +12 -16
- package/dist/type/validator/custom-error.mjs +11 -14
- package/dist/type/validator/default-precompute.d.ts +9 -1
- package/dist/type/validator/default-precompute.js +40 -77
- package/dist/type/validator/default-precompute.mjs +37 -74
- package/dist/type/validator/exact-mirror-live.d.ts +8 -0
- package/dist/type/validator/exact-mirror-live.js +22 -0
- package/dist/type/validator/exact-mirror-live.mjs +17 -0
- package/dist/type/validator/exact-mirror-require.d.ts +4 -0
- package/dist/type/validator/exact-mirror-require.js +11 -0
- package/dist/type/validator/exact-mirror-require.mjs +9 -0
- package/dist/type/validator/exact-mirror.js +8 -8
- package/dist/type/validator/exact-mirror.mjs +9 -8
- package/dist/type/validator/frozen-check.js +5 -6
- package/dist/type/validator/frozen-check.mjs +6 -7
- package/dist/type/validator/index.d.ts +1 -0
- package/dist/type/validator/index.js +169 -166
- package/dist/type/validator/index.mjs +162 -158
- package/dist/type/validator/string-codec-aot.d.ts +2 -1
- package/dist/type/validator/string-codec-aot.js +8 -2
- package/dist/type/validator/string-codec-aot.mjs +7 -2
- package/dist/type/validator/validator-cache.d.ts +5 -4
- package/dist/type/validator/validator-cache.js +41 -24
- package/dist/type/validator/validator-cache.mjs +40 -22
- package/dist/types.d.ts +263 -95
- package/dist/universal/constants.d.ts +2 -1
- package/dist/universal/constants.js +3 -1
- package/dist/universal/constants.mjs +2 -1
- package/dist/universal/env.js +2 -3
- package/dist/universal/env.mjs +2 -3
- package/dist/universal/file.d.ts +6 -4
- package/dist/universal/file.js +11 -16
- package/dist/universal/file.mjs +12 -16
- package/dist/universal/index.d.ts +2 -2
- package/dist/universal/is-production.d.ts +1 -2
- package/dist/universal/is-production.js +1 -3
- package/dist/universal/is-production.mjs +2 -3
- package/dist/universal/server.d.ts +0 -272
- package/dist/utils.d.ts +43 -7
- package/dist/utils.js +181 -126
- package/dist/utils.mjs +168 -126
- package/dist/validator/index.d.ts +1 -1
- package/dist/validator/index.js +17 -30
- package/dist/validator/index.mjs +18 -31
- package/dist/validator/route.js +2 -1
- package/dist/validator/route.mjs +2 -1
- package/dist/ws/context.d.ts +8 -1
- package/dist/ws/context.js +68 -44
- package/dist/ws/context.mjs +67 -44
- package/dist/ws/parser.js +10 -20
- package/dist/ws/parser.mjs +10 -20
- package/dist/ws/route.d.ts +2 -2
- package/dist/ws/route.js +249 -141
- package/dist/ws/route.mjs +254 -146
- package/dist/ws/types.d.ts +2 -2
- package/package.json +23 -49
- package/dist/compile/analysis-cache.d.ts +0 -6
- package/dist/compile/analysis-cache.js +0 -12
- package/dist/compile/analysis-cache.mjs +0 -11
- package/dist/cookie/index.d.ts +0 -7
- package/dist/cookie/index.js +0 -13
- package/dist/cookie/index.mjs +0 -7
- package/dist/handler/index.d.ts +0 -2
- package/dist/handler/index.js +0 -5
- package/dist/handler/index.mjs +0 -3
package/dist/validator/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { assignOwn } from "../utils.mjs";
|
|
2
|
+
import { Clone, Compile, HasCodec, Intersect, TypeBoxValidator, TypeBoxValidatorCache, applyCoercions } from "../type/bridge.mjs";
|
|
2
3
|
import { ValidationError } from "../error.mjs";
|
|
3
4
|
import { Capture, Compiled } from "../compile/aot.mjs";
|
|
4
5
|
import { isAsyncFunction } from "../compile/utils.mjs";
|
|
5
6
|
import { clearCoerceLeafCache, clearSharedReferenceCaches, nonAdditionalProperties } from "../type/shared.mjs";
|
|
6
|
-
import { isAsyncPredicate } from "../type/elysia/file-type.mjs";
|
|
7
7
|
import { hasProperty } from "../type/utils.mjs";
|
|
8
8
|
|
|
9
9
|
//#region src/validator/index.ts
|
|
@@ -34,11 +34,7 @@ var Validator = class Validator {
|
|
|
34
34
|
schemas: options.schemas.map((v) => Validator.reference(v, models))
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
if (
|
|
38
|
-
const message = "[Elysia] Compiled schema detected. Please pass t.Schema instead.";
|
|
39
|
-
if (Capture.isCapturing()) throw new Error(`${message} build plugin cannot serialize a pre-compiled schema.`);
|
|
40
|
-
console.warn(message);
|
|
41
|
-
}
|
|
37
|
+
if (schema != null && typeof schema.Check === "function" && "evaluateResult" in schema && !("~standard" in schema)) throw new Error("[Elysia] Compiled schema detected. Please pass t.Schema instead.");
|
|
42
38
|
let isIntersectable = false;
|
|
43
39
|
if (options?.schemas?.length) if ("~kind" in schema && options.schemas.every((v) => "~kind" in v || "~elyAcl" in v)) isIntersectable = true;
|
|
44
40
|
else return new MultiValidator(schema, options);
|
|
@@ -98,7 +94,6 @@ var Validator = class Validator {
|
|
|
98
94
|
clearSharedReferenceCaches();
|
|
99
95
|
}
|
|
100
96
|
};
|
|
101
|
-
const isCompiledSchema = (schema) => schema != null && typeof schema.Check === "function" && "buildResult" in schema;
|
|
102
97
|
const isSingleSchema = (schema) => "~kind" in schema || "~elyAcl" in schema || "~standard" in schema;
|
|
103
98
|
const toStatusBased = (schema) => isSingleSchema(schema) ? { 200: schema } : schema;
|
|
104
99
|
const isAsyncStandardSchema = (schema) => isAsyncFunction(schema["~standard"].validate);
|
|
@@ -142,7 +137,6 @@ var MultiValidator = class MultiValidator extends Validator {
|
|
|
142
137
|
#schemas;
|
|
143
138
|
#codecs;
|
|
144
139
|
#hasDefaults;
|
|
145
|
-
#tbSchemas;
|
|
146
140
|
#asyncMembers;
|
|
147
141
|
constructor(schema, options) {
|
|
148
142
|
super();
|
|
@@ -151,7 +145,6 @@ var MultiValidator = class MultiValidator extends Validator {
|
|
|
151
145
|
const schemas = [schema].concat(options.schemas);
|
|
152
146
|
const codecs = [];
|
|
153
147
|
const hasDefaults = [];
|
|
154
|
-
const tbSchemas = [];
|
|
155
148
|
const asyncMembers = [];
|
|
156
149
|
const shouldClose = options?.normalize === false;
|
|
157
150
|
const compileMember = (rawSchema, hd) => {
|
|
@@ -160,8 +153,7 @@ var MultiValidator = class MultiValidator extends Validator {
|
|
|
160
153
|
const compiled = Compile(coercedSchema);
|
|
161
154
|
codecs.push(HasCodec(coercedSchema));
|
|
162
155
|
hasDefaults.push(hd);
|
|
163
|
-
|
|
164
|
-
if (compiled.buildResult?.external?.variables?.some(isAsyncPredicate) ?? false) {
|
|
156
|
+
if (TypeBoxValidator.member(coercedSchema, compiled)) {
|
|
165
157
|
this.isAsync = true;
|
|
166
158
|
asyncMembers.push(Validator.create(rawSchema, {
|
|
167
159
|
coerces: options?.coerces,
|
|
@@ -187,7 +179,6 @@ var MultiValidator = class MultiValidator extends Validator {
|
|
|
187
179
|
if (isAsyncStandardSchema(schema)) this.isAsync = true;
|
|
188
180
|
codecs.push(false);
|
|
189
181
|
hasDefaults.push(false);
|
|
190
|
-
tbSchemas.push(null);
|
|
191
182
|
asyncMembers.push(null);
|
|
192
183
|
}
|
|
193
184
|
}
|
|
@@ -195,7 +186,6 @@ var MultiValidator = class MultiValidator extends Validator {
|
|
|
195
186
|
this.#schemas = schemas;
|
|
196
187
|
this.#codecs = codecs;
|
|
197
188
|
this.#hasDefaults = hasDefaults;
|
|
198
|
-
this.#tbSchemas = tbSchemas;
|
|
199
189
|
this.#asyncMembers = asyncMembers;
|
|
200
190
|
}
|
|
201
191
|
static #merge(snapshot, result) {
|
|
@@ -204,7 +194,7 @@ var MultiValidator = class MultiValidator extends Validator {
|
|
|
204
194
|
snapshot.push(...result);
|
|
205
195
|
return snapshot;
|
|
206
196
|
}
|
|
207
|
-
if (typeof snapshot === "object" && typeof result === "object") return
|
|
197
|
+
if (typeof snapshot === "object" && typeof result === "object") return assignOwn(snapshot, result);
|
|
208
198
|
throw new Error("Unable to merged value with different type");
|
|
209
199
|
}
|
|
210
200
|
static #syncStandard(schema, value) {
|
|
@@ -246,20 +236,6 @@ var MultiValidator = class MultiValidator extends Validator {
|
|
|
246
236
|
EncodeFrom(value) {
|
|
247
237
|
return this.From(value);
|
|
248
238
|
}
|
|
249
|
-
#fromTypeBox(compiled, index, value, type) {
|
|
250
|
-
let v = this.#cloneForMember(value);
|
|
251
|
-
if (this.#hasDefaults[index]) v = compiled.Default ? compiled.Default(v) : Default(this.#tbSchemas[index], v);
|
|
252
|
-
if (this.#codecs[index]) try {
|
|
253
|
-
return compiled.Clean(compiled.Decode(v));
|
|
254
|
-
} catch {
|
|
255
|
-
throw new ValidationError(type, value, () => compiled.Errors(value));
|
|
256
|
-
}
|
|
257
|
-
if (!compiled.Check(v)) throw new ValidationError(type, value, () => compiled.Errors(v));
|
|
258
|
-
return compiled.Clean(v);
|
|
259
|
-
}
|
|
260
|
-
#fromTypeBoxAsync(tbv, value, type) {
|
|
261
|
-
return tbv.FromAsync(this.#cloneForMember(value), type);
|
|
262
|
-
}
|
|
263
239
|
From(value, type, allowAsync = this.isAsync) {
|
|
264
240
|
return this.#fromLoop(value, 0, void 0, type, allowAsync);
|
|
265
241
|
}
|
|
@@ -282,9 +258,20 @@ var MultiValidator = class MultiValidator extends Validator {
|
|
|
282
258
|
const asyncTbv = this.#asyncMembers[i];
|
|
283
259
|
if (asyncTbv) {
|
|
284
260
|
if (!allowAsync) throw asyncStandardSchemaError();
|
|
285
|
-
return this.#
|
|
261
|
+
return asyncTbv.FromAsync(this.#cloneForMember(value), type).then((result) => this.#fromLoop(value, i + 1, MultiValidator.#merge(snapshot, result), type, allowAsync));
|
|
262
|
+
}
|
|
263
|
+
const compiled = validator;
|
|
264
|
+
let v = this.#cloneForMember(value);
|
|
265
|
+
if (this.#hasDefaults[i]) v = compiled.Default(v);
|
|
266
|
+
let memberValue;
|
|
267
|
+
if (this.#codecs[i]) try {
|
|
268
|
+
memberValue = compiled.Clean(compiled.Decode(v));
|
|
269
|
+
} catch {
|
|
270
|
+
throw new ValidationError(type, value, () => compiled.Errors(value));
|
|
286
271
|
}
|
|
287
|
-
|
|
272
|
+
else if (!compiled.Check(v)) throw new ValidationError(type, value, () => compiled.Errors(v));
|
|
273
|
+
else memberValue = compiled.Clean(v);
|
|
274
|
+
snapshot = MultiValidator.#merge(snapshot, memberValue);
|
|
288
275
|
}
|
|
289
276
|
return snapshot;
|
|
290
277
|
}
|
package/dist/validator/route.js
CHANGED
|
@@ -31,7 +31,8 @@ var RouteValidator = class {
|
|
|
31
31
|
const merge = pickMerge(mergeSchemas, slot);
|
|
32
32
|
if (!route[slot] && !merge?.length) continue;
|
|
33
33
|
const reference = require_validator_index.Validator.reference(route[slot] ?? merge[0], options?.models);
|
|
34
|
-
const
|
|
34
|
+
const tb = isTb(reference) ? reference : merge?.find(isTb);
|
|
35
|
+
const coerces = tb ? coerce(tb) : void 0;
|
|
35
36
|
this[slot] = require_validator_index.Validator.create(route[slot], {
|
|
36
37
|
...options,
|
|
37
38
|
slot,
|
package/dist/validator/route.mjs
CHANGED
|
@@ -30,7 +30,8 @@ var RouteValidator = class {
|
|
|
30
30
|
const merge = pickMerge(mergeSchemas, slot);
|
|
31
31
|
if (!route[slot] && !merge?.length) continue;
|
|
32
32
|
const reference = Validator.reference(route[slot] ?? merge[0], options?.models);
|
|
33
|
-
const
|
|
33
|
+
const tb = isTb(reference) ? reference : merge?.find(isTb);
|
|
34
|
+
const coerces = tb ? coerce(tb) : void 0;
|
|
34
35
|
this[slot] = Validator.create(route[slot], {
|
|
35
36
|
...options,
|
|
36
37
|
slot,
|
package/dist/ws/context.d.ts
CHANGED
|
@@ -11,12 +11,19 @@ interface WSConnectionData {
|
|
|
11
11
|
ping?: (elysia: ElysiaWS<any>, data: Buffer) => void | Promise<void>;
|
|
12
12
|
pong?: (elysia: ElysiaWS<any>, data: Buffer) => void | Promise<void>;
|
|
13
13
|
closeHandlerInvoked?: boolean;
|
|
14
|
+
/** in-flight `message` handlers, bounded by `MAX_INFLIGHT_MESSAGES` */
|
|
15
|
+
inflight?: number;
|
|
16
|
+
/** settles when an async `open` hook finished; dispatch chains onto it */
|
|
17
|
+
opening?: Promise<void>;
|
|
18
|
+
/** async socket lifecycle callbacks other than message/open */
|
|
19
|
+
settling?: number;
|
|
14
20
|
elysia?: ElysiaWS<any>;
|
|
15
21
|
context?: Record<string, unknown>;
|
|
16
22
|
resumeWaiters?: Set<() => void>;
|
|
17
23
|
validator?: WSResponseValidator;
|
|
18
24
|
defaultValidator?: WSValidatorLike;
|
|
19
25
|
}
|
|
26
|
+
declare function trackWSSettling(data: WSConnectionData, result: void | Promise<void>, onSettled?: () => void): void;
|
|
20
27
|
declare class ElysiaWS<Route extends RouteSchema = {}> {
|
|
21
28
|
#private;
|
|
22
29
|
raw: ServerWebSocket<WSConnectionData>;
|
|
@@ -46,4 +53,4 @@ declare class ElysiaWS<Route extends RouteSchema = {}> {
|
|
|
46
53
|
}
|
|
47
54
|
declare function isGeneratorObject(value: unknown): boolean;
|
|
48
55
|
//#endregion
|
|
49
|
-
export { ElysiaWS, WSConnectionData, isGeneratorObject };
|
|
56
|
+
export { ElysiaWS, WSConnectionData, isGeneratorObject, trackWSSettling };
|
package/dist/ws/context.js
CHANGED
|
@@ -3,10 +3,14 @@ const require_utils = require('../utils.js');
|
|
|
3
3
|
const require_error = require('../error.js');
|
|
4
4
|
|
|
5
5
|
//#region src/ws/context.ts
|
|
6
|
-
function
|
|
7
|
-
if (!
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
function trackWSSettling(data, result, onSettled) {
|
|
7
|
+
if (!(result instanceof Promise)) return;
|
|
8
|
+
data.settling = (data.settling ?? 0) + 1;
|
|
9
|
+
const release = () => {
|
|
10
|
+
data.settling--;
|
|
11
|
+
onSettled?.();
|
|
12
|
+
};
|
|
13
|
+
result.then(release, release);
|
|
10
14
|
}
|
|
11
15
|
function memoize(view, key, value) {
|
|
12
16
|
const self = view.raw.data.elysia ?? view;
|
|
@@ -24,6 +28,15 @@ var ElysiaWS = class {
|
|
|
24
28
|
this.raw = raw;
|
|
25
29
|
if (context) for (const key in context) {
|
|
26
30
|
if (key === "ws" || key === "body") continue;
|
|
31
|
+
if (key === "__proto__") {
|
|
32
|
+
Object.defineProperty(this, key, {
|
|
33
|
+
value: context[key],
|
|
34
|
+
writable: true,
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true
|
|
37
|
+
});
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
27
40
|
this[key] = context[key];
|
|
28
41
|
}
|
|
29
42
|
}
|
|
@@ -36,11 +49,11 @@ var ElysiaWS = class {
|
|
|
36
49
|
}
|
|
37
50
|
get ping() {
|
|
38
51
|
const self = this.raw.data.elysia ?? this;
|
|
39
|
-
return memoize(this, "ping", self.#
|
|
52
|
+
return memoize(this, "ping", self.#control.bind(self, "ping"));
|
|
40
53
|
}
|
|
41
54
|
get pong() {
|
|
42
55
|
const self = this.raw.data.elysia ?? this;
|
|
43
|
-
return memoize(this, "pong", self.#
|
|
56
|
+
return memoize(this, "pong", self.#control.bind(self, "pong"));
|
|
44
57
|
}
|
|
45
58
|
get publish() {
|
|
46
59
|
const self = this.raw.data.elysia ?? this;
|
|
@@ -62,58 +75,68 @@ var ElysiaWS = class {
|
|
|
62
75
|
get data() {
|
|
63
76
|
return this.raw.data;
|
|
64
77
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
71
|
-
if (typeof data === "object") return JSON.stringify(data);
|
|
72
|
-
return data;
|
|
73
|
-
}
|
|
74
|
-
#validatedOrError(data) {
|
|
78
|
+
/**
|
|
79
|
+
* Validate, redact and serialize an outbound value, or return the
|
|
80
|
+
* `ValidationError` the payload was refused with.
|
|
81
|
+
*/
|
|
82
|
+
#frame(data) {
|
|
75
83
|
const connectionData = this.raw.data;
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
const validators = connectionData?.validator;
|
|
85
|
+
const defaultValidator = connectionData?.defaultValidator;
|
|
86
|
+
const status = data instanceof require_error.ElysiaStatus ? data : void 0;
|
|
87
|
+
const v = validators && (status ? validators[status.status] : defaultValidator);
|
|
88
|
+
let value = status ? status.response : data;
|
|
89
|
+
if (v) {
|
|
90
|
+
const encode = v.EncodeFrom;
|
|
91
|
+
let redacted;
|
|
92
|
+
if (typeof encode === "function" && !v.hasCodec && !v.mayReturnPromise) try {
|
|
93
|
+
redacted = encode.call(v, value, "message");
|
|
94
|
+
} catch {}
|
|
95
|
+
if (redacted !== void 0) value = redacted;
|
|
96
|
+
else if (!v.Check(value)) return new require_error.ValidationError("message", value, v.Errors(value));
|
|
97
|
+
}
|
|
98
|
+
if (status) return JSON.stringify({
|
|
99
|
+
status: status.status,
|
|
100
|
+
error: value
|
|
101
|
+
});
|
|
102
|
+
if (value === void 0) return null;
|
|
103
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
104
|
+
return value;
|
|
81
105
|
}
|
|
82
106
|
#send(data, compress) {
|
|
83
107
|
if (data === void 0) return 0;
|
|
84
108
|
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) return this.raw.send(data, compress);
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
87
|
-
return this.raw.send(
|
|
88
|
-
}
|
|
89
|
-
#
|
|
90
|
-
if (data === void 0) return this.raw
|
|
91
|
-
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) return this.raw
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
94
|
-
return this.raw
|
|
95
|
-
}
|
|
96
|
-
#pong(data) {
|
|
97
|
-
if (data === void 0) return this.raw.pong();
|
|
98
|
-
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) return this.raw.pong(data);
|
|
99
|
-
const err = this.#validatedOrError(data);
|
|
100
|
-
if (err !== void 0) return this.raw.send(err);
|
|
101
|
-
return this.raw.pong(this.#prepare(data));
|
|
109
|
+
const frame = this.#frame(data);
|
|
110
|
+
if (frame instanceof require_error.ValidationError) return this.raw.send(frame.message);
|
|
111
|
+
return this.raw.send(frame, compress);
|
|
112
|
+
}
|
|
113
|
+
#control(kind, data) {
|
|
114
|
+
if (data === void 0) return this.raw[kind]();
|
|
115
|
+
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) return this.raw[kind](data);
|
|
116
|
+
const frame = this.#frame(data);
|
|
117
|
+
if (frame instanceof require_error.ValidationError) return this.raw.send(frame.message);
|
|
118
|
+
return this.raw[kind](frame);
|
|
102
119
|
}
|
|
103
120
|
#publish(topic, data, compress) {
|
|
104
121
|
if (data === void 0) return 0;
|
|
105
122
|
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) return this.raw.publish(topic, data, compress);
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
108
|
-
return this.raw.publish(topic,
|
|
123
|
+
const frame = this.#frame(data);
|
|
124
|
+
if (frame instanceof require_error.ValidationError) return this.raw.send(frame.message);
|
|
125
|
+
return this.raw.publish(topic, frame, compress);
|
|
109
126
|
}
|
|
110
127
|
#close(code, reason) {
|
|
111
128
|
const data = this.raw.data;
|
|
112
129
|
if (!data.closeHandlerInvoked && data.close) {
|
|
113
130
|
data.closeHandlerInvoked = true;
|
|
114
131
|
try {
|
|
115
|
-
const
|
|
116
|
-
|
|
132
|
+
const close = data.close;
|
|
133
|
+
const lifecycle = data["~lifecycleRun"];
|
|
134
|
+
const result = lifecycle ? lifecycle(close, this, code ?? 1e3, reason ?? "") : close(this, code ?? 1e3, reason ?? "");
|
|
135
|
+
if (result instanceof Promise) {
|
|
136
|
+
const closing = result.catch(() => {});
|
|
137
|
+
trackWSSettling(data, closing);
|
|
138
|
+
closing.then(() => this.raw.close(code, reason)).catch(() => this.raw.close(code, reason));
|
|
139
|
+
}
|
|
117
140
|
return;
|
|
118
141
|
} catch {}
|
|
119
142
|
}
|
|
@@ -149,4 +172,5 @@ function isGeneratorObject(value) {
|
|
|
149
172
|
|
|
150
173
|
//#endregion
|
|
151
174
|
exports.ElysiaWS = ElysiaWS;
|
|
152
|
-
exports.isGeneratorObject = isGeneratorObject;
|
|
175
|
+
exports.isGeneratorObject = isGeneratorObject;
|
|
176
|
+
exports.trackWSSettling = trackWSSettling;
|
package/dist/ws/context.mjs
CHANGED
|
@@ -2,10 +2,14 @@ import { requestId } from "../utils.mjs";
|
|
|
2
2
|
import { ElysiaStatus, ValidationError } from "../error.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/ws/context.ts
|
|
5
|
-
function
|
|
6
|
-
if (!
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
function trackWSSettling(data, result, onSettled) {
|
|
6
|
+
if (!(result instanceof Promise)) return;
|
|
7
|
+
data.settling = (data.settling ?? 0) + 1;
|
|
8
|
+
const release = () => {
|
|
9
|
+
data.settling--;
|
|
10
|
+
onSettled?.();
|
|
11
|
+
};
|
|
12
|
+
result.then(release, release);
|
|
9
13
|
}
|
|
10
14
|
function memoize(view, key, value) {
|
|
11
15
|
const self = view.raw.data.elysia ?? view;
|
|
@@ -23,6 +27,15 @@ var ElysiaWS = class {
|
|
|
23
27
|
this.raw = raw;
|
|
24
28
|
if (context) for (const key in context) {
|
|
25
29
|
if (key === "ws" || key === "body") continue;
|
|
30
|
+
if (key === "__proto__") {
|
|
31
|
+
Object.defineProperty(this, key, {
|
|
32
|
+
value: context[key],
|
|
33
|
+
writable: true,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true
|
|
36
|
+
});
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
26
39
|
this[key] = context[key];
|
|
27
40
|
}
|
|
28
41
|
}
|
|
@@ -35,11 +48,11 @@ var ElysiaWS = class {
|
|
|
35
48
|
}
|
|
36
49
|
get ping() {
|
|
37
50
|
const self = this.raw.data.elysia ?? this;
|
|
38
|
-
return memoize(this, "ping", self.#
|
|
51
|
+
return memoize(this, "ping", self.#control.bind(self, "ping"));
|
|
39
52
|
}
|
|
40
53
|
get pong() {
|
|
41
54
|
const self = this.raw.data.elysia ?? this;
|
|
42
|
-
return memoize(this, "pong", self.#
|
|
55
|
+
return memoize(this, "pong", self.#control.bind(self, "pong"));
|
|
43
56
|
}
|
|
44
57
|
get publish() {
|
|
45
58
|
const self = this.raw.data.elysia ?? this;
|
|
@@ -61,58 +74,68 @@ var ElysiaWS = class {
|
|
|
61
74
|
get data() {
|
|
62
75
|
return this.raw.data;
|
|
63
76
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
if (typeof data === "object") return JSON.stringify(data);
|
|
71
|
-
return data;
|
|
72
|
-
}
|
|
73
|
-
#validatedOrError(data) {
|
|
77
|
+
/**
|
|
78
|
+
* Validate, redact and serialize an outbound value, or return the
|
|
79
|
+
* `ValidationError` the payload was refused with.
|
|
80
|
+
*/
|
|
81
|
+
#frame(data) {
|
|
74
82
|
const connectionData = this.raw.data;
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
const validators = connectionData?.validator;
|
|
84
|
+
const defaultValidator = connectionData?.defaultValidator;
|
|
85
|
+
const status = data instanceof ElysiaStatus ? data : void 0;
|
|
86
|
+
const v = validators && (status ? validators[status.status] : defaultValidator);
|
|
87
|
+
let value = status ? status.response : data;
|
|
88
|
+
if (v) {
|
|
89
|
+
const encode = v.EncodeFrom;
|
|
90
|
+
let redacted;
|
|
91
|
+
if (typeof encode === "function" && !v.hasCodec && !v.mayReturnPromise) try {
|
|
92
|
+
redacted = encode.call(v, value, "message");
|
|
93
|
+
} catch {}
|
|
94
|
+
if (redacted !== void 0) value = redacted;
|
|
95
|
+
else if (!v.Check(value)) return new ValidationError("message", value, v.Errors(value));
|
|
96
|
+
}
|
|
97
|
+
if (status) return JSON.stringify({
|
|
98
|
+
status: status.status,
|
|
99
|
+
error: value
|
|
100
|
+
});
|
|
101
|
+
if (value === void 0) return null;
|
|
102
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
103
|
+
return value;
|
|
80
104
|
}
|
|
81
105
|
#send(data, compress) {
|
|
82
106
|
if (data === void 0) return 0;
|
|
83
107
|
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) return this.raw.send(data, compress);
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
86
|
-
return this.raw.send(
|
|
87
|
-
}
|
|
88
|
-
#
|
|
89
|
-
if (data === void 0) return this.raw
|
|
90
|
-
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) return this.raw
|
|
91
|
-
const
|
|
92
|
-
if (
|
|
93
|
-
return this.raw
|
|
94
|
-
}
|
|
95
|
-
#pong(data) {
|
|
96
|
-
if (data === void 0) return this.raw.pong();
|
|
97
|
-
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) return this.raw.pong(data);
|
|
98
|
-
const err = this.#validatedOrError(data);
|
|
99
|
-
if (err !== void 0) return this.raw.send(err);
|
|
100
|
-
return this.raw.pong(this.#prepare(data));
|
|
108
|
+
const frame = this.#frame(data);
|
|
109
|
+
if (frame instanceof ValidationError) return this.raw.send(frame.message);
|
|
110
|
+
return this.raw.send(frame, compress);
|
|
111
|
+
}
|
|
112
|
+
#control(kind, data) {
|
|
113
|
+
if (data === void 0) return this.raw[kind]();
|
|
114
|
+
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) return this.raw[kind](data);
|
|
115
|
+
const frame = this.#frame(data);
|
|
116
|
+
if (frame instanceof ValidationError) return this.raw.send(frame.message);
|
|
117
|
+
return this.raw[kind](frame);
|
|
101
118
|
}
|
|
102
119
|
#publish(topic, data, compress) {
|
|
103
120
|
if (data === void 0) return 0;
|
|
104
121
|
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) return this.raw.publish(topic, data, compress);
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
107
|
-
return this.raw.publish(topic,
|
|
122
|
+
const frame = this.#frame(data);
|
|
123
|
+
if (frame instanceof ValidationError) return this.raw.send(frame.message);
|
|
124
|
+
return this.raw.publish(topic, frame, compress);
|
|
108
125
|
}
|
|
109
126
|
#close(code, reason) {
|
|
110
127
|
const data = this.raw.data;
|
|
111
128
|
if (!data.closeHandlerInvoked && data.close) {
|
|
112
129
|
data.closeHandlerInvoked = true;
|
|
113
130
|
try {
|
|
114
|
-
const
|
|
115
|
-
|
|
131
|
+
const close = data.close;
|
|
132
|
+
const lifecycle = data["~lifecycleRun"];
|
|
133
|
+
const result = lifecycle ? lifecycle(close, this, code ?? 1e3, reason ?? "") : close(this, code ?? 1e3, reason ?? "");
|
|
134
|
+
if (result instanceof Promise) {
|
|
135
|
+
const closing = result.catch(() => {});
|
|
136
|
+
trackWSSettling(data, closing);
|
|
137
|
+
closing.then(() => this.raw.close(code, reason)).catch(() => this.raw.close(code, reason));
|
|
138
|
+
}
|
|
116
139
|
return;
|
|
117
140
|
} catch {}
|
|
118
141
|
}
|
|
@@ -147,4 +170,4 @@ function isGeneratorObject(value) {
|
|
|
147
170
|
}
|
|
148
171
|
|
|
149
172
|
//#endregion
|
|
150
|
-
export { ElysiaWS, isGeneratorObject };
|
|
173
|
+
export { ElysiaWS, isGeneratorObject, trackWSSettling };
|
package/dist/ws/parser.js
CHANGED
|
@@ -1,25 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
//#region src/ws/parser.ts
|
|
4
|
-
function isNumericString(s) {
|
|
5
|
-
if (s.length === 0) return false;
|
|
6
|
-
let sawDigit = false;
|
|
7
|
-
let sawDot = false;
|
|
8
|
-
for (let i = 0; i < s.length; i++) {
|
|
9
|
-
const c = s.charCodeAt(i);
|
|
10
|
-
if (i === 0 && (c === 43 || c === 45)) continue;
|
|
11
|
-
if (c >= 48 && c <= 57) {
|
|
12
|
-
sawDigit = true;
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
if (c === 46 && !sawDot) {
|
|
16
|
-
sawDot = true;
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
return sawDigit;
|
|
22
|
-
}
|
|
23
4
|
function defaultWSParse(message) {
|
|
24
5
|
if (typeof message !== "string") return message;
|
|
25
6
|
const start = message.charCodeAt(0);
|
|
@@ -28,7 +9,16 @@ function defaultWSParse(message) {
|
|
|
28
9
|
} catch {
|
|
29
10
|
return message;
|
|
30
11
|
}
|
|
31
|
-
|
|
12
|
+
let i = start === 43 || start === 45 ? 1 : 0;
|
|
13
|
+
let sawDigit = false;
|
|
14
|
+
let sawDot = false;
|
|
15
|
+
for (; i < message.length; i++) {
|
|
16
|
+
const c = message.charCodeAt(i);
|
|
17
|
+
if (c >= 48 && c <= 57) sawDigit = true;
|
|
18
|
+
else if (c === 46 && !sawDot) sawDot = true;
|
|
19
|
+
else break;
|
|
20
|
+
}
|
|
21
|
+
if (sawDigit && i === message.length) {
|
|
32
22
|
if (message.length < 16) return +message;
|
|
33
23
|
const n = +message;
|
|
34
24
|
if (message.length === 16 && String(n) === message) return n;
|
package/dist/ws/parser.mjs
CHANGED
|
@@ -1,23 +1,4 @@
|
|
|
1
1
|
//#region src/ws/parser.ts
|
|
2
|
-
function isNumericString(s) {
|
|
3
|
-
if (s.length === 0) return false;
|
|
4
|
-
let sawDigit = false;
|
|
5
|
-
let sawDot = false;
|
|
6
|
-
for (let i = 0; i < s.length; i++) {
|
|
7
|
-
const c = s.charCodeAt(i);
|
|
8
|
-
if (i === 0 && (c === 43 || c === 45)) continue;
|
|
9
|
-
if (c >= 48 && c <= 57) {
|
|
10
|
-
sawDigit = true;
|
|
11
|
-
continue;
|
|
12
|
-
}
|
|
13
|
-
if (c === 46 && !sawDot) {
|
|
14
|
-
sawDot = true;
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
return sawDigit;
|
|
20
|
-
}
|
|
21
2
|
function defaultWSParse(message) {
|
|
22
3
|
if (typeof message !== "string") return message;
|
|
23
4
|
const start = message.charCodeAt(0);
|
|
@@ -26,7 +7,16 @@ function defaultWSParse(message) {
|
|
|
26
7
|
} catch {
|
|
27
8
|
return message;
|
|
28
9
|
}
|
|
29
|
-
|
|
10
|
+
let i = start === 43 || start === 45 ? 1 : 0;
|
|
11
|
+
let sawDigit = false;
|
|
12
|
+
let sawDot = false;
|
|
13
|
+
for (; i < message.length; i++) {
|
|
14
|
+
const c = message.charCodeAt(i);
|
|
15
|
+
if (c >= 48 && c <= 57) sawDigit = true;
|
|
16
|
+
else if (c === 46 && !sawDot) sawDot = true;
|
|
17
|
+
else break;
|
|
18
|
+
}
|
|
19
|
+
if (sawDigit && i === message.length) {
|
|
30
20
|
if (message.length < 16) return +message;
|
|
31
21
|
const n = +message;
|
|
32
22
|
if (message.length === 16 && String(n) === message) return n;
|
package/dist/ws/route.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { InternalRoute } from "../types.js";
|
|
2
1
|
import { Context } from "../context.js";
|
|
2
|
+
import { InternalRoute } from "../types.js";
|
|
3
3
|
import { WSOptions, WSOptionsEntry, WebSocketHandler } from "./types.js";
|
|
4
4
|
import { AnyElysia } from "../base.js";
|
|
5
5
|
import { ElysiaWS, WSConnectionData } from "./context.js";
|
|
@@ -10,7 +10,7 @@ declare function drainWaiters(ws: ElysiaWS<any>): void;
|
|
|
10
10
|
declare function handleWSResponse(ws: ElysiaWS<any>, value: unknown, mapResponses: readonly AnyFn[]): Promise<void>;
|
|
11
11
|
declare function buildWSRoute(route: InternalRoute, app: AnyElysia): [fetch: (context: Context) => Promise<Response | undefined> | Response | undefined, options: Partial<WebSocketHandler<any>>];
|
|
12
12
|
declare function resolveWSOptions(entries: WSOptionsEntry[]): WSOptions | undefined;
|
|
13
|
-
declare function accumulateWSOptions(target: WSOptions, routeOptions: WSOptions
|
|
13
|
+
declare function accumulateWSOptions(target: WSOptions, routeOptions: WSOptions): void;
|
|
14
14
|
declare function buildGlobalWSHandler(): WebSocketHandler<WSConnectionData>;
|
|
15
15
|
//#endregion
|
|
16
16
|
export { accumulateWSOptions, buildGlobalWSHandler, buildWSRoute, drainWaiters, handleWSResponse, resolveWSOptions };
|