typeferry 0.6.0
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/README.md +88 -0
- package/dist/auth/client/cross-tab-sync.d.ts +21 -0
- package/dist/auth/client/cross-tab-sync.js +56 -0
- package/dist/auth/client/cross-tab-sync.js.map +1 -0
- package/dist/auth/client/index.d.ts +2 -0
- package/dist/auth/client/index.js +3 -0
- package/dist/auth/client/index.js.map +1 -0
- package/dist/auth/client/oauth/google-provider.d.ts +11 -0
- package/dist/auth/client/oauth/google-provider.js +11 -0
- package/dist/auth/client/oauth/google-provider.js.map +1 -0
- package/dist/auth/client/oauth/index.d.ts +4 -0
- package/dist/auth/client/oauth/index.js +3 -0
- package/dist/auth/client/oauth/index.js.map +1 -0
- package/dist/auth/client/oauth/use-google-login.d.ts +39 -0
- package/dist/auth/client/oauth/use-google-login.js +55 -0
- package/dist/auth/client/oauth/use-google-login.js.map +1 -0
- package/dist/auth/client/token-refresh.d.ts +21 -0
- package/dist/auth/client/token-refresh.js +212 -0
- package/dist/auth/client/token-refresh.js.map +1 -0
- package/dist/auth/index.d.ts +7 -0
- package/dist/auth/index.js +9 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/server/cookie-utils.d.ts +42 -0
- package/dist/auth/server/cookie-utils.js +91 -0
- package/dist/auth/server/cookie-utils.js.map +1 -0
- package/dist/auth/server/device-info.d.ts +23 -0
- package/dist/auth/server/device-info.js +52 -0
- package/dist/auth/server/device-info.js.map +1 -0
- package/dist/auth/server/index.d.ts +4 -0
- package/dist/auth/server/index.js +5 -0
- package/dist/auth/server/index.js.map +1 -0
- package/dist/auth/server/jwt-utils.d.ts +29 -0
- package/dist/auth/server/jwt-utils.js +53 -0
- package/dist/auth/server/jwt-utils.js.map +1 -0
- package/dist/auth/server/oauth/google.d.ts +31 -0
- package/dist/auth/server/oauth/google.js +40 -0
- package/dist/auth/server/oauth/google.js.map +1 -0
- package/dist/auth/server/oauth/index.d.ts +3 -0
- package/dist/auth/server/oauth/index.js +2 -0
- package/dist/auth/server/oauth/index.js.map +1 -0
- package/dist/auth/server/oauth/types.d.ts +37 -0
- package/dist/auth/server/oauth/types.js +2 -0
- package/dist/auth/server/oauth/types.js.map +1 -0
- package/dist/auth/server/session-manager.d.ts +46 -0
- package/dist/auth/server/session-manager.js +167 -0
- package/dist/auth/server/session-manager.js.map +1 -0
- package/dist/auth/types.d.ts +197 -0
- package/dist/auth/types.js +2 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/client/call-method-proxy.d.ts +2 -0
- package/dist/client/call-method-proxy.js +22 -0
- package/dist/client/call-method-proxy.js.map +1 -0
- package/dist/client/client-channel.d.ts +43 -0
- package/dist/client/client-channel.js +148 -0
- package/dist/client/client-channel.js.map +1 -0
- package/dist/client/client-http.d.ts +27 -0
- package/dist/client/client-http.js +106 -0
- package/dist/client/client-http.js.map +1 -0
- package/dist/client/client-socket.d.ts +85 -0
- package/dist/client/client-socket.js +317 -0
- package/dist/client/client-socket.js.map +1 -0
- package/dist/client/client.d.ts +149 -0
- package/dist/client/client.js +401 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/context-manager.d.ts +54 -0
- package/dist/client/context-manager.js +89 -0
- package/dist/client/context-manager.js.map +1 -0
- package/dist/client/idle-timer.d.ts +35 -0
- package/dist/client/idle-timer.js +101 -0
- package/dist/client/idle-timer.js.map +1 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +7 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/logger.d.ts +76 -0
- package/dist/client/logger.js +129 -0
- package/dist/client/logger.js.map +1 -0
- package/dist/client/visibility-manager.d.ts +62 -0
- package/dist/client/visibility-manager.js +177 -0
- package/dist/client/visibility-manager.js.map +1 -0
- package/dist/ejson/adjust-types-from-json-value.d.ts +1 -0
- package/dist/ejson/adjust-types-from-json-value.js +35 -0
- package/dist/ejson/adjust-types-from-json-value.js.map +1 -0
- package/dist/ejson/base64.d.ts +11 -0
- package/dist/ejson/base64.js +87 -0
- package/dist/ejson/base64.js.map +1 -0
- package/dist/ejson/built-in-converters.d.ts +1 -0
- package/dist/ejson/built-in-converters.js +137 -0
- package/dist/ejson/built-in-converters.js.map +1 -0
- package/dist/ejson/clone.d.ts +1 -0
- package/dist/ejson/clone.js +80 -0
- package/dist/ejson/clone.js.map +1 -0
- package/dist/ejson/custom-models.d.ts +38 -0
- package/dist/ejson/custom-models.js +76 -0
- package/dist/ejson/custom-models.js.map +1 -0
- package/dist/ejson/custom-types.d.ts +1 -0
- package/dist/ejson/custom-types.js +2 -0
- package/dist/ejson/custom-types.js.map +1 -0
- package/dist/ejson/equals.d.ts +1 -0
- package/dist/ejson/equals.js +117 -0
- package/dist/ejson/equals.js.map +1 -0
- package/dist/ejson/from-json-value.d.ts +1 -0
- package/dist/ejson/from-json-value.js +13 -0
- package/dist/ejson/from-json-value.js.map +1 -0
- package/dist/ejson/helpers/adjust-types-to-json-value.d.ts +1 -0
- package/dist/ejson/helpers/adjust-types-to-json-value.js +36 -0
- package/dist/ejson/helpers/adjust-types-to-json-value.js.map +1 -0
- package/dist/ejson/helpers/from-json-value-helper.d.ts +1 -0
- package/dist/ejson/helpers/from-json-value-helper.js +24 -0
- package/dist/ejson/helpers/from-json-value-helper.js.map +1 -0
- package/dist/ejson/helpers/to-json-value-helper.d.ts +1 -0
- package/dist/ejson/helpers/to-json-value-helper.js +15 -0
- package/dist/ejson/helpers/to-json-value-helper.js.map +1 -0
- package/dist/ejson/index.d.ts +27 -0
- package/dist/ejson/index.js +54 -0
- package/dist/ejson/index.js.map +1 -0
- package/dist/ejson/is-binary.d.ts +2 -0
- package/dist/ejson/is-binary.js +5 -0
- package/dist/ejson/is-binary.js.map +1 -0
- package/dist/ejson/parse.d.ts +6 -0
- package/dist/ejson/parse.js +12 -0
- package/dist/ejson/parse.js.map +1 -0
- package/dist/ejson/stable-stringify.d.ts +10 -0
- package/dist/ejson/stable-stringify.js +25 -0
- package/dist/ejson/stable-stringify.js.map +1 -0
- package/dist/ejson/stringify.d.ts +5 -0
- package/dist/ejson/stringify.js +15 -0
- package/dist/ejson/stringify.js.map +1 -0
- package/dist/ejson/to-json-value.d.ts +1 -0
- package/dist/ejson/to-json-value.js +17 -0
- package/dist/ejson/to-json-value.js.map +1 -0
- package/dist/ejson/utils.d.ts +18 -0
- package/dist/ejson/utils.js +43 -0
- package/dist/ejson/utils.js.map +1 -0
- package/dist/mongodb/change-streams.d.ts +31 -0
- package/dist/mongodb/change-streams.js +142 -0
- package/dist/mongodb/change-streams.js.map +1 -0
- package/dist/mongodb/client.d.ts +13 -0
- package/dist/mongodb/client.js +30 -0
- package/dist/mongodb/client.js.map +1 -0
- package/dist/mongodb/decorators/collection.d.ts +9 -0
- package/dist/mongodb/decorators/collection.js +26 -0
- package/dist/mongodb/decorators/collection.js.map +1 -0
- package/dist/mongodb/decorators/index.d.ts +4 -0
- package/dist/mongodb/decorators/index.js +5 -0
- package/dist/mongodb/decorators/index.js.map +1 -0
- package/dist/mongodb/decorators/metadata.d.ts +21 -0
- package/dist/mongodb/decorators/metadata.js +29 -0
- package/dist/mongodb/decorators/metadata.js.map +1 -0
- package/dist/mongodb/decorators/register.d.ts +3 -0
- package/dist/mongodb/decorators/register.js +10 -0
- package/dist/mongodb/decorators/register.js.map +1 -0
- package/dist/mongodb/decorators/watch.d.ts +4 -0
- package/dist/mongodb/decorators/watch.js +10 -0
- package/dist/mongodb/decorators/watch.js.map +1 -0
- package/dist/mongodb/filters.d.ts +20 -0
- package/dist/mongodb/filters.js +40 -0
- package/dist/mongodb/filters.js.map +1 -0
- package/dist/mongodb/find-one-or-create.d.ts +4 -0
- package/dist/mongodb/find-one-or-create.js +16 -0
- package/dist/mongodb/find-one-or-create.js.map +1 -0
- package/dist/mongodb/index.d.ts +10 -0
- package/dist/mongodb/index.js +11 -0
- package/dist/mongodb/index.js.map +1 -0
- package/dist/mongodb/live/client.d.ts +52 -0
- package/dist/mongodb/live/client.js +266 -0
- package/dist/mongodb/live/client.js.map +1 -0
- package/dist/mongodb/live/engine.d.ts +55 -0
- package/dist/mongodb/live/engine.js +440 -0
- package/dist/mongodb/live/engine.js.map +1 -0
- package/dist/mongodb/live/index.d.ts +5 -0
- package/dist/mongodb/live/index.js +6 -0
- package/dist/mongodb/live/index.js.map +1 -0
- package/dist/mongodb/live/observer.d.ts +58 -0
- package/dist/mongodb/live/observer.js +246 -0
- package/dist/mongodb/live/observer.js.map +1 -0
- package/dist/mongodb/live/publication.d.ts +4 -0
- package/dist/mongodb/live/publication.js +30 -0
- package/dist/mongodb/live/publication.js.map +1 -0
- package/dist/mongodb/live/source.d.ts +55 -0
- package/dist/mongodb/live/source.js +197 -0
- package/dist/mongodb/live/source.js.map +1 -0
- package/dist/mongodb/live/types.d.ts +266 -0
- package/dist/mongodb/live/types.js +29 -0
- package/dist/mongodb/live/types.js.map +1 -0
- package/dist/mongodb/live/window.d.ts +7 -0
- package/dist/mongodb/live/window.js +93 -0
- package/dist/mongodb/live/window.js.map +1 -0
- package/dist/mongodb/registry.d.ts +35 -0
- package/dist/mongodb/registry.js +129 -0
- package/dist/mongodb/registry.js.map +1 -0
- package/dist/mongodb/schema.d.ts +16 -0
- package/dist/mongodb/schema.js +43 -0
- package/dist/mongodb/schema.js.map +1 -0
- package/dist/mongodb/timestamps.d.ts +17 -0
- package/dist/mongodb/timestamps.js +27 -0
- package/dist/mongodb/timestamps.js.map +1 -0
- package/dist/mongodb/types.d.ts +120 -0
- package/dist/mongodb/types.js +10 -0
- package/dist/mongodb/types.js.map +1 -0
- package/dist/react/components/client-provider.d.ts +8 -0
- package/dist/react/components/client-provider.js +23 -0
- package/dist/react/components/client-provider.js.map +1 -0
- package/dist/react/components/index.d.ts +1 -0
- package/dist/react/components/index.js +2 -0
- package/dist/react/components/index.js.map +1 -0
- package/dist/react/hooks/index.d.ts +13 -0
- package/dist/react/hooks/index.js +14 -0
- package/dist/react/hooks/index.js.map +1 -0
- package/dist/react/hooks/use-auth.d.ts +4 -0
- package/dist/react/hooks/use-auth.js +35 -0
- package/dist/react/hooks/use-auth.js.map +1 -0
- package/dist/react/hooks/use-caller.d.ts +5 -0
- package/dist/react/hooks/use-caller.js +13 -0
- package/dist/react/hooks/use-caller.js.map +1 -0
- package/dist/react/hooks/use-channel.d.ts +1 -0
- package/dist/react/hooks/use-channel.js +7 -0
- package/dist/react/hooks/use-channel.js.map +1 -0
- package/dist/react/hooks/use-circuit-breaker.d.ts +6 -0
- package/dist/react/hooks/use-circuit-breaker.js +16 -0
- package/dist/react/hooks/use-circuit-breaker.js.map +1 -0
- package/dist/react/hooks/use-client.d.ts +3 -0
- package/dist/react/hooks/use-client.js +13 -0
- package/dist/react/hooks/use-client.js.map +1 -0
- package/dist/react/hooks/use-connection-state.d.ts +13 -0
- package/dist/react/hooks/use-connection-state.js +55 -0
- package/dist/react/hooks/use-connection-state.js.map +1 -0
- package/dist/react/hooks/use-creation.d.ts +5 -0
- package/dist/react/hooks/use-creation.js +17 -0
- package/dist/react/hooks/use-creation.js.map +1 -0
- package/dist/react/hooks/use-deps-change.d.ts +1 -0
- package/dist/react/hooks/use-deps-change.js +11 -0
- package/dist/react/hooks/use-deps-change.js.map +1 -0
- package/dist/react/hooks/use-local-event.d.ts +13 -0
- package/dist/react/hooks/use-local-event.js +32 -0
- package/dist/react/hooks/use-local-event.js.map +1 -0
- package/dist/react/hooks/use-method-refresh.d.ts +15 -0
- package/dist/react/hooks/use-method-refresh.js +48 -0
- package/dist/react/hooks/use-method-refresh.js.map +1 -0
- package/dist/react/hooks/use-method.d.ts +26 -0
- package/dist/react/hooks/use-method.js +161 -0
- package/dist/react/hooks/use-method.js.map +1 -0
- package/dist/react/hooks/use-mongodb-live-publication.d.ts +13 -0
- package/dist/react/hooks/use-mongodb-live-publication.js +26 -0
- package/dist/react/hooks/use-mongodb-live-publication.js.map +1 -0
- package/dist/react/hooks/use-object.d.ts +2 -0
- package/dist/react/hooks/use-object.js +22 -0
- package/dist/react/hooks/use-object.js.map +1 -0
- package/dist/react/hooks/use-subscribe.d.ts +8 -0
- package/dist/react/hooks/use-subscribe.js +49 -0
- package/dist/react/hooks/use-subscribe.js.map +1 -0
- package/dist/react/hooks/use-throttled-events.d.ts +7 -0
- package/dist/react/hooks/use-throttled-events.js +11 -0
- package/dist/react/hooks/use-throttled-events.js.map +1 -0
- package/dist/react/hooks/use-token-refresh.d.ts +13 -0
- package/dist/react/hooks/use-token-refresh.js +40 -0
- package/dist/react/hooks/use-token-refresh.js.map +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +3 -0
- package/dist/react/index.js.map +1 -0
- package/dist/server/client-node.d.ts +76 -0
- package/dist/server/client-node.js +159 -0
- package/dist/server/client-node.js.map +1 -0
- package/dist/server/create-method-proxy.d.ts +2 -0
- package/dist/server/create-method-proxy.js +16 -0
- package/dist/server/create-method-proxy.js.map +1 -0
- package/dist/server/decorators/cached.d.ts +37 -0
- package/dist/server/decorators/cached.js +65 -0
- package/dist/server/decorators/cached.js.map +1 -0
- package/dist/server/decorators/index.d.ts +14 -0
- package/dist/server/decorators/index.js +13 -0
- package/dist/server/decorators/index.js.map +1 -0
- package/dist/server/decorators/infer.d.ts +78 -0
- package/dist/server/decorators/infer.js +11 -0
- package/dist/server/decorators/infer.js.map +1 -0
- package/dist/server/decorators/metadata.d.ts +60 -0
- package/dist/server/decorators/metadata.js +77 -0
- package/dist/server/decorators/metadata.js.map +1 -0
- package/dist/server/decorators/method.d.ts +14 -0
- package/dist/server/decorators/method.js +25 -0
- package/dist/server/decorators/method.js.map +1 -0
- package/dist/server/decorators/namespace.d.ts +25 -0
- package/dist/server/decorators/namespace.js +34 -0
- package/dist/server/decorators/namespace.js.map +1 -0
- package/dist/server/decorators/protected.d.ts +36 -0
- package/dist/server/decorators/protected.js +61 -0
- package/dist/server/decorators/protected.js.map +1 -0
- package/dist/server/decorators/register.d.ts +25 -0
- package/dist/server/decorators/register.js +72 -0
- package/dist/server/decorators/register.js.map +1 -0
- package/dist/server/decorators/schema.d.ts +17 -0
- package/dist/server/decorators/schema.js +27 -0
- package/dist/server/decorators/schema.js.map +1 -0
- package/dist/server/decorators/use.d.ts +22 -0
- package/dist/server/decorators/use.js +32 -0
- package/dist/server/decorators/use.js.map +1 -0
- package/dist/server/default-methods.d.ts +8 -0
- package/dist/server/default-methods.js +8 -0
- package/dist/server/default-methods.js.map +1 -0
- package/dist/server/event.d.ts +42 -0
- package/dist/server/event.js +53 -0
- package/dist/server/event.js.map +1 -0
- package/dist/server/index.d.ts +10 -0
- package/dist/server/index.js +11 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/method.d.ts +95 -0
- package/dist/server/method.js +113 -0
- package/dist/server/method.js.map +1 -0
- package/dist/server/methods.d.ts +11 -0
- package/dist/server/methods.js +74 -0
- package/dist/server/methods.js.map +1 -0
- package/dist/server/request-types.d.ts +20 -0
- package/dist/server/request-types.js +8 -0
- package/dist/server/request-types.js.map +1 -0
- package/dist/server/room-registry.d.ts +28 -0
- package/dist/server/room-registry.js +83 -0
- package/dist/server/room-registry.js.map +1 -0
- package/dist/server/server-channel.d.ts +32 -0
- package/dist/server/server-channel.js +104 -0
- package/dist/server/server-channel.js.map +1 -0
- package/dist/server/server.d.ts +124 -0
- package/dist/server/server.js +243 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/transports/hono-rate-limit.d.ts +15 -0
- package/dist/server/transports/hono-rate-limit.js +36 -0
- package/dist/server/transports/hono-rate-limit.js.map +1 -0
- package/dist/server/transports/index.d.ts +4 -0
- package/dist/server/transports/index.js +5 -0
- package/dist/server/transports/index.js.map +1 -0
- package/dist/server/transports/node-hono-transport-contract.d.ts +16 -0
- package/dist/server/transports/node-hono-transport-contract.js +18 -0
- package/dist/server/transports/node-hono-transport-contract.js.map +1 -0
- package/dist/server/transports/node-hono-transport.d.ts +47 -0
- package/dist/server/transports/node-hono-transport.js +327 -0
- package/dist/server/transports/node-hono-transport.js.map +1 -0
- package/dist/server/transports/redis-transport.d.ts +34 -0
- package/dist/server/transports/redis-transport.js +84 -0
- package/dist/server/transports/redis-transport.js.map +1 -0
- package/dist/server/transports/websocket-transport.d.ts +42 -0
- package/dist/server/transports/websocket-transport.js +174 -0
- package/dist/server/transports/websocket-transport.js.map +1 -0
- package/dist/server/transports/ws-shared.d.ts +37 -0
- package/dist/server/transports/ws-shared.js +188 -0
- package/dist/server/transports/ws-shared.js.map +1 -0
- package/dist/server/typeferry-async-local-storage.d.ts +5 -0
- package/dist/server/typeferry-async-local-storage.js +6 -0
- package/dist/server/typeferry-async-local-storage.js.map +1 -0
- package/dist/server/types.d.ts +27 -0
- package/dist/server/types.js +11 -0
- package/dist/server/types.js.map +1 -0
- package/dist/utils/constants.d.ts +72 -0
- package/dist/utils/constants.js +79 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/environment.d.ts +8 -0
- package/dist/utils/environment.js +17 -0
- package/dist/utils/environment.js.map +1 -0
- package/dist/utils/errors.d.ts +26 -0
- package/dist/utils/errors.js +35 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/event-emitter.d.ts +37 -0
- package/dist/utils/event-emitter.js +104 -0
- package/dist/utils/event-emitter.js.map +1 -0
- package/dist/utils/events.d.ts +7 -0
- package/dist/utils/events.js +23 -0
- package/dist/utils/events.js.map +1 -0
- package/dist/utils/helpers.d.ts +14 -0
- package/dist/utils/helpers.js +40 -0
- package/dist/utils/helpers.js.map +1 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.js +12 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/intercept.d.ts +7 -0
- package/dist/utils/intercept.js +21 -0
- package/dist/utils/intercept.js.map +1 -0
- package/dist/utils/iterator.d.ts +9 -0
- package/dist/utils/iterator.js +28 -0
- package/dist/utils/iterator.js.map +1 -0
- package/dist/utils/lodash.d.ts +33 -0
- package/dist/utils/lodash.js +123 -0
- package/dist/utils/lodash.js.map +1 -0
- package/dist/utils/presentation.d.ts +19 -0
- package/dist/utils/presentation.js +25 -0
- package/dist/utils/presentation.js.map +1 -0
- package/dist/utils/promise.d.ts +6 -0
- package/dist/utils/promise.js +17 -0
- package/dist/utils/promise.js.map +1 -0
- package/dist/utils/protocol.d.ts +110 -0
- package/dist/utils/protocol.js +59 -0
- package/dist/utils/protocol.js.map +1 -0
- package/dist/utils/types.d.ts +23 -0
- package/dist/utils/types.js +2 -0
- package/dist/utils/types.js.map +1 -0
- package/package.json +187 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { RateLimiter } from 'limiter';
|
|
2
|
+
import { MessageType, Presentation, ServerEvents } from '../utils/index.js';
|
|
3
|
+
import EventEmitter2 from '../utils/event-emitter.js';
|
|
4
|
+
import { SocketState } from './types.js';
|
|
5
|
+
export class ClientNode extends EventEmitter2 {
|
|
6
|
+
uuid;
|
|
7
|
+
isAuthenticated = false;
|
|
8
|
+
meta = {};
|
|
9
|
+
context = {};
|
|
10
|
+
userId = null;
|
|
11
|
+
user = null;
|
|
12
|
+
socket;
|
|
13
|
+
/** Framework-agnostic request exposed by the Hono adapter. */
|
|
14
|
+
req;
|
|
15
|
+
/** Framework-agnostic response exposed by the Hono adapter. */
|
|
16
|
+
res;
|
|
17
|
+
isServer = false;
|
|
18
|
+
limiter;
|
|
19
|
+
server;
|
|
20
|
+
headers = {};
|
|
21
|
+
remoteAddress;
|
|
22
|
+
userAgent;
|
|
23
|
+
constructor(server, socket, req, res, limit) {
|
|
24
|
+
super();
|
|
25
|
+
this.server = server;
|
|
26
|
+
this.socket = socket;
|
|
27
|
+
this.req = req;
|
|
28
|
+
this.res = res;
|
|
29
|
+
if (limit) {
|
|
30
|
+
this.limiter = new RateLimiter(limit === true
|
|
31
|
+
? {
|
|
32
|
+
tokensPerInterval: 60,
|
|
33
|
+
interval: 60 * 1000,
|
|
34
|
+
}
|
|
35
|
+
: {
|
|
36
|
+
tokensPerInterval: limit.max,
|
|
37
|
+
interval: limit.interval,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
get authenticated() {
|
|
42
|
+
return this.isAuthenticated;
|
|
43
|
+
}
|
|
44
|
+
set authenticated(authenticated) {
|
|
45
|
+
this.isAuthenticated = authenticated;
|
|
46
|
+
}
|
|
47
|
+
get readyState() {
|
|
48
|
+
return this.socket?.readyState;
|
|
49
|
+
}
|
|
50
|
+
setId(uuid) {
|
|
51
|
+
this.uuid = uuid;
|
|
52
|
+
}
|
|
53
|
+
setContext(context) {
|
|
54
|
+
this.context = this.authenticated ? context : {};
|
|
55
|
+
this.setUserId();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Extracts tracking properties (headers, IP, user-agent) from a request.
|
|
59
|
+
* Accepts both Node `IncomingMessage` and the framework-agnostic `TypeFerryRequest`.
|
|
60
|
+
*/
|
|
61
|
+
setTrackingProperties(source) {
|
|
62
|
+
this.headers = (source.headers ?? {});
|
|
63
|
+
this.userAgent = source.headers?.['user-agent'] ?? '';
|
|
64
|
+
this.remoteAddress =
|
|
65
|
+
source.headers?.['x-forwarded-for'] ??
|
|
66
|
+
source.socket?.remoteAddress ??
|
|
67
|
+
source.ip ??
|
|
68
|
+
'';
|
|
69
|
+
}
|
|
70
|
+
// The user ID is used for authorizing the user's channel.
|
|
71
|
+
setUserId() {
|
|
72
|
+
if (!this.authenticated)
|
|
73
|
+
return;
|
|
74
|
+
const userId = this.context?.user?._id;
|
|
75
|
+
if (!userId) {
|
|
76
|
+
throw new Error('The auth function must return a user object with a valid "_id" property');
|
|
77
|
+
}
|
|
78
|
+
this.userId = String(this.context.user._id);
|
|
79
|
+
this.user = this.context.user;
|
|
80
|
+
this.server?.indexClientByUserId(this);
|
|
81
|
+
}
|
|
82
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
83
|
+
// WebSocket Message Emitters
|
|
84
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
85
|
+
/**
|
|
86
|
+
* Sends a push event to the client.
|
|
87
|
+
* Uses the wire protocol `{ t: "event", ... }` envelope.
|
|
88
|
+
*/
|
|
89
|
+
emitTypeFerryEvent(event, channel, params) {
|
|
90
|
+
this.sendTypeFerryEvent(event, channel, params);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Sends a push event and returns the native transport pressure.
|
|
94
|
+
*
|
|
95
|
+
* Live data delivery uses this result to avoid hiding slow consumers behind
|
|
96
|
+
* the WebSocket runtime's own queue.
|
|
97
|
+
*/
|
|
98
|
+
sendTypeFerryEvent(event, channel, params) {
|
|
99
|
+
if (!this.socket || this.socket.readyState !== SocketState.OPEN) {
|
|
100
|
+
return { accepted: false, bufferedBytes: this.bufferedBytes };
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
this.socket.send(Presentation.encode({
|
|
104
|
+
t: MessageType.EVENT,
|
|
105
|
+
uuid: Presentation.uuid(),
|
|
106
|
+
event,
|
|
107
|
+
channel,
|
|
108
|
+
params,
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return { accepted: false, bufferedBytes: this.bufferedBytes };
|
|
113
|
+
}
|
|
114
|
+
return { accepted: true, bufferedBytes: this.bufferedBytes };
|
|
115
|
+
}
|
|
116
|
+
/** Whether the transport exposes native queued-byte pressure. */
|
|
117
|
+
get supportsBufferedBytes() {
|
|
118
|
+
return typeof this.socket?.bufferedAmount === 'number';
|
|
119
|
+
}
|
|
120
|
+
/** Returns native bytes queued by the WebSocket runtime without sending. */
|
|
121
|
+
get bufferedBytes() {
|
|
122
|
+
try {
|
|
123
|
+
return this.socket?.bufferedAmount ?? 0;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Sends an error to the client.
|
|
131
|
+
*/
|
|
132
|
+
emitError(payload) {
|
|
133
|
+
if (!this.socket || this.socket.readyState !== SocketState.OPEN)
|
|
134
|
+
return;
|
|
135
|
+
this.socket.send(Presentation.encode(payload));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Sends authentication result to the client.
|
|
139
|
+
* Uses the wire protocol `{ t: "auth", ... }` envelope.
|
|
140
|
+
*/
|
|
141
|
+
emitAuthResult(authenticated) {
|
|
142
|
+
if (!this.socket || this.socket.readyState !== SocketState.OPEN)
|
|
143
|
+
return;
|
|
144
|
+
this.socket.send(Presentation.encode({ t: MessageType.AUTH, authenticated }));
|
|
145
|
+
}
|
|
146
|
+
/** Idempotency guard — prevents duplicate DISCONNECT events. */
|
|
147
|
+
closed = false;
|
|
148
|
+
close() {
|
|
149
|
+
if (this.closed)
|
|
150
|
+
return;
|
|
151
|
+
this.closed = true;
|
|
152
|
+
if (this.socket) {
|
|
153
|
+
this.socket.close();
|
|
154
|
+
}
|
|
155
|
+
this.emit(ServerEvents.DISCONNECT);
|
|
156
|
+
this.server.emit(ServerEvents.DISCONNECTION, this);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=client-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-node.js","sourceRoot":"","sources":["../../src/server/client-node.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function createMethodProxy(server, path = '') {
|
|
2
|
+
return new Proxy({}, {
|
|
3
|
+
get(_, prop) {
|
|
4
|
+
const newPath = path ? `${path}.${prop}` : prop;
|
|
5
|
+
return createMethodProxy(server, newPath);
|
|
6
|
+
},
|
|
7
|
+
set(_, prop, value) {
|
|
8
|
+
const propertyPath = path
|
|
9
|
+
? `${path}.${prop}`
|
|
10
|
+
: prop;
|
|
11
|
+
server.addMethod(propertyPath, value?.[0] ?? value, value?.[1]);
|
|
12
|
+
return true;
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=create-method-proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-method-proxy.js","sourceRoot":"","sources":["../../src/server/create-method-proxy.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,iBAAiB,CAAC,MAAc,EAAE,IAAI,GAAG,EAAE;IACzD,OAAO,IAAI,KAAK,CACd,EAAE,EACF;QACE,GAAG,CAAC,CAAC,EAAE,IAAI;YACT,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAc,EAAE,CAAC,CAAC,CAAE,IAAe,CAAA;YACrE,OAAO,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC3C,CAAC;QACD,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK;YAChB,MAAM,YAAY,GAAG,IAAI;gBACvB,CAAC,CAAC,GAAG,IAAI,IAAI,IAAc,EAAE;gBAC7B,CAAC,CAAE,IAAe,CAAA;YACpB,MAAM,CAAC,SAAS,CAAC,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;YAC/D,OAAO,IAAI,CAAA;QACb,CAAC;KACF,CACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Cached class/method decorator — enables result caching.
|
|
3
|
+
* @NoCache method decorator — disables caching for a specific method.
|
|
4
|
+
*
|
|
5
|
+
* @module typeferry/server/decorators/cached
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Enables result caching at the class or method level.
|
|
9
|
+
*
|
|
10
|
+
* When applied to a class, all methods inherit the cache setting.
|
|
11
|
+
* When applied to a method, it overrides/complements class-level settings.
|
|
12
|
+
*
|
|
13
|
+
* @param maxAge - Cache TTL in milliseconds (default: 60000)
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* @Namespace('analytics')
|
|
18
|
+
* @Cached(30_000)
|
|
19
|
+
* class AnalyticsMethods { ... }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function Cached(maxAge?: number): <T extends (abstract new (...args: unknown[]) => unknown) | ((...args: never[]) => unknown)>(target: T, context: ClassDecoratorContext | ClassMethodDecoratorContext) => T;
|
|
23
|
+
/**
|
|
24
|
+
* Disables caching for a specific method when the class has @Cached().
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* @Namespace('analytics')
|
|
29
|
+
* @Cached(30_000)
|
|
30
|
+
* class AnalyticsMethods {
|
|
31
|
+
* @Method()
|
|
32
|
+
* @NoCache()
|
|
33
|
+
* async realtime(client: ClientNode, params) { ... }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function NoCache(): <T extends (...args: never[]) => unknown>(target: T, context: ClassMethodDecoratorContext) => T;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Cached class/method decorator — enables result caching.
|
|
3
|
+
* @NoCache method decorator — disables caching for a specific method.
|
|
4
|
+
*
|
|
5
|
+
* @module typeferry/server/decorators/cached
|
|
6
|
+
*/
|
|
7
|
+
import { getOrCreateMethodMeta, getOrCreateNamespaceMeta, queueMethodUpdate, } from './metadata.js';
|
|
8
|
+
const DEFAULT_MAX_AGE = 60_000;
|
|
9
|
+
/**
|
|
10
|
+
* Enables result caching at the class or method level.
|
|
11
|
+
*
|
|
12
|
+
* When applied to a class, all methods inherit the cache setting.
|
|
13
|
+
* When applied to a method, it overrides/complements class-level settings.
|
|
14
|
+
*
|
|
15
|
+
* @param maxAge - Cache TTL in milliseconds (default: 60000)
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* @Namespace('analytics')
|
|
20
|
+
* @Cached(30_000)
|
|
21
|
+
* class AnalyticsMethods { ... }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function Cached(maxAge) {
|
|
25
|
+
return function (target, context) {
|
|
26
|
+
if (context.kind === 'class') {
|
|
27
|
+
const meta = getOrCreateNamespaceMeta(target);
|
|
28
|
+
meta.cached = true;
|
|
29
|
+
meta.maxAge = maxAge ?? DEFAULT_MAX_AGE;
|
|
30
|
+
return target;
|
|
31
|
+
}
|
|
32
|
+
const key = String(context.name);
|
|
33
|
+
queueMethodUpdate(Class => {
|
|
34
|
+
const meta = getOrCreateMethodMeta(Class, key);
|
|
35
|
+
meta.cached = true;
|
|
36
|
+
meta.maxAge = maxAge ?? DEFAULT_MAX_AGE;
|
|
37
|
+
});
|
|
38
|
+
return target;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Disables caching for a specific method when the class has @Cached().
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* @Namespace('analytics')
|
|
47
|
+
* @Cached(30_000)
|
|
48
|
+
* class AnalyticsMethods {
|
|
49
|
+
* @Method()
|
|
50
|
+
* @NoCache()
|
|
51
|
+
* async realtime(client: ClientNode, params) { ... }
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function NoCache() {
|
|
56
|
+
return function (target, context) {
|
|
57
|
+
const key = String(context.name);
|
|
58
|
+
queueMethodUpdate(Class => {
|
|
59
|
+
const meta = getOrCreateMethodMeta(Class, key);
|
|
60
|
+
meta.cached = false;
|
|
61
|
+
});
|
|
62
|
+
return target;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=cached.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cached.js","sourceRoot":"","sources":["../../../src/server/decorators/cached.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,YAAY,CAAA;AAEnB,MAAM,eAAe,GAAG,MAAM,CAAA;AAE9B;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,MAAM,CAAC,MAAe;IACpC,OAAO,UAKL,MAAS,EACT,OAA4D;QAE5D,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC7B,MAAM,IAAI,GAAG,wBAAwB,CACnC,MAAsD,CACvD,CAAA;YACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;YAClB,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,eAAe,CAAA;YACvC,OAAO,MAAM,CAAA;QACf,CAAC;QAED,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAEhC,iBAAiB,CAAC,KAAK,CAAC,EAAE;YACxB,MAAM,IAAI,GAAG,qBAAqB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;YAC9C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;YAClB,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,eAAe,CAAA;QACzC,CAAC,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,OAAO;IACrB,OAAO,UACL,MAAS,EACT,OAAoC;QAEpC,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAEhC,iBAAiB,CAAC,KAAK,CAAC,EAAE;YACxB,MAAM,IAAI,GAAG,qBAAqB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;YAC9C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACrB,CAAC,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeFerry decorator API — class/decorator-based alternative to the ns() builder.
|
|
3
|
+
*
|
|
4
|
+
* @module typeferry/server/decorators
|
|
5
|
+
*/
|
|
6
|
+
export { Cached, NoCache } from './cached.js';
|
|
7
|
+
export type { InferNamespace } from './infer.js';
|
|
8
|
+
export type { MethodMeta, NamespaceMeta } from './metadata.js';
|
|
9
|
+
export { Method } from './method.js';
|
|
10
|
+
export { Namespace } from './namespace.js';
|
|
11
|
+
export { Protected, Public } from './protected.js';
|
|
12
|
+
export { registerNamespace } from './register.js';
|
|
13
|
+
export { Schema } from './schema.js';
|
|
14
|
+
export { Use } from './use.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeFerry decorator API — class/decorator-based alternative to the ns() builder.
|
|
3
|
+
*
|
|
4
|
+
* @module typeferry/server/decorators
|
|
5
|
+
*/
|
|
6
|
+
export { Cached, NoCache } from './cached.js';
|
|
7
|
+
export { Method } from './method.js';
|
|
8
|
+
export { Namespace } from './namespace.js';
|
|
9
|
+
export { Protected, Public } from './protected.js';
|
|
10
|
+
export { registerNamespace } from './register.js';
|
|
11
|
+
export { Schema } from './schema.js';
|
|
12
|
+
export { Use } from './use.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/decorators/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAG1C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level utilities for extracting client-callable method types from
|
|
3
|
+
* decorator-based TypeFerry namespace classes.
|
|
4
|
+
*
|
|
5
|
+
* Bridges the gap between runtime decorator metadata and compile-time
|
|
6
|
+
* type inference, enabling autocomplete on `client.m.ai.generation.abort(...)`.
|
|
7
|
+
*
|
|
8
|
+
* @module typeferry/server/decorators/infer
|
|
9
|
+
*/
|
|
10
|
+
import type { ClientNode } from '../client-node.js';
|
|
11
|
+
import type { CallOptions } from '../../utils/index.js';
|
|
12
|
+
/**
|
|
13
|
+
* Extracts `{ params: P; result: R }` from a TypeFerry method signature.
|
|
14
|
+
*
|
|
15
|
+
* Uses tuple extraction on `Args` to distinguish 1-param from 2-param
|
|
16
|
+
* methods, avoiding function bivariance where `(a) => R` would incorrectly
|
|
17
|
+
* match `(a, b: infer P) => R`.
|
|
18
|
+
*/
|
|
19
|
+
type ExtractMethodSignature<T> = T extends (...args: infer Args) => Promise<infer R> ? Args extends [ClientNode, infer P] ? {
|
|
20
|
+
params: P;
|
|
21
|
+
result: R;
|
|
22
|
+
} : Args extends [ClientNode] ? {
|
|
23
|
+
params: undefined;
|
|
24
|
+
result: R;
|
|
25
|
+
} : never : never;
|
|
26
|
+
/**
|
|
27
|
+
* Maps class methods to client-callable signatures.
|
|
28
|
+
* Filters out non-TypeFerry methods (those without `ClientNode` first param).
|
|
29
|
+
*/
|
|
30
|
+
type MethodsOf<T> = {
|
|
31
|
+
[K in keyof T as ExtractMethodSignature<T[K]> extends never ? never : K]: ExtractMethodSignature<T[K]> extends {
|
|
32
|
+
params: infer P;
|
|
33
|
+
result: infer R;
|
|
34
|
+
} ? P extends undefined ? (options?: CallOptions) => Promise<R> : (params: P, options?: CallOptions) => Promise<R> : never;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Converts a dotted path string into a nested object type.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* PathToNested<'ai.generation', { abort: fn }>
|
|
42
|
+
* // → { ai: { generation: { abort: fn } } }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
type PathToNested<Path extends string, Value> = Path extends `${infer Head}.${infer Rest}` ? {
|
|
46
|
+
[K in Head]: PathToNested<Rest, Value>;
|
|
47
|
+
} : {
|
|
48
|
+
[K in Path]: Value;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Infers a client-side type map from a decorated TypeFerry namespace class.
|
|
52
|
+
*
|
|
53
|
+
* Extracts method signatures matching `(client: ClientNode, params: P) => Promise<R>`
|
|
54
|
+
* and wraps them in a nested object keyed by the dotted prefix.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* // Server class:
|
|
59
|
+
* \@Namespace('ai.generation')
|
|
60
|
+
* class AiGenerationMethods {
|
|
61
|
+
* async abort(client: ClientNode, params: \{ generationId: string \}): Promise<void> \{ ... \}
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* // Companion type (one line per class):
|
|
65
|
+
* export type AiGenerationApi = InferNamespace<AiGenerationMethods, 'ai.generation'>
|
|
66
|
+
* // → \{ ai: \{ generation: \{ abort: (params: \{ generationId: string \}, options?) => Promise<void> \} \} \}
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* Multiple namespaces compose via intersection:
|
|
70
|
+
* ```ts
|
|
71
|
+
* type AllAi = AiGenerationApi & AiMermaidApi & AiDeckApi
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @typeParam T - Class instance type (the decorated class)
|
|
75
|
+
* @typeParam Prefix - Dotted namespace prefix matching \@Namespace value
|
|
76
|
+
*/
|
|
77
|
+
export type InferNamespace<T, Prefix extends string> = Prefix extends '' ? MethodsOf<T> : PathToNested<Prefix, MethodsOf<T>>;
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level utilities for extracting client-callable method types from
|
|
3
|
+
* decorator-based TypeFerry namespace classes.
|
|
4
|
+
*
|
|
5
|
+
* Bridges the gap between runtime decorator metadata and compile-time
|
|
6
|
+
* type inference, enabling autocomplete on `client.m.ai.generation.abort(...)`.
|
|
7
|
+
*
|
|
8
|
+
* @module typeferry/server/decorators/infer
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=infer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer.js","sourceRoot":"","sources":["../../../src/server/decorators/infer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WeakMap-based metadata stores for TypeFerry decorator API.
|
|
3
|
+
*
|
|
4
|
+
* TC39 Stage 3 decorators don't have `reflect-metadata`, so we use WeakMaps
|
|
5
|
+
* keyed by class constructor (namespace) and class prototype (methods).
|
|
6
|
+
*
|
|
7
|
+
* Method decorators push updates to a pending queue instead of using
|
|
8
|
+
* `addInitializer` so metadata ownership stays explicit across classes defined
|
|
9
|
+
* in the same file. The @Namespace decorator flushes the queue after methods.
|
|
10
|
+
*
|
|
11
|
+
* @module typeferry/server/decorators/metadata
|
|
12
|
+
*/
|
|
13
|
+
import type { z } from 'zod';
|
|
14
|
+
import type { AnyFunction } from '../../utils/index.js';
|
|
15
|
+
/** Class-level metadata set by @Namespace, @Protected, @Cached */
|
|
16
|
+
export interface NamespaceMeta {
|
|
17
|
+
prefix: string;
|
|
18
|
+
protected: boolean;
|
|
19
|
+
cached: boolean;
|
|
20
|
+
maxAge: number;
|
|
21
|
+
}
|
|
22
|
+
/** Per-method metadata set by @Method, @Schema, @Use, @Public, @Cached, @NoCache */
|
|
23
|
+
export interface MethodMeta {
|
|
24
|
+
name: string;
|
|
25
|
+
schema?: z.ZodType;
|
|
26
|
+
middleware: AnyFunction[];
|
|
27
|
+
/** undefined = inherit from class */
|
|
28
|
+
protected?: boolean;
|
|
29
|
+
/** undefined = inherit from class */
|
|
30
|
+
cached?: boolean;
|
|
31
|
+
maxAge?: number;
|
|
32
|
+
}
|
|
33
|
+
/** Keyed by class constructor — stores namespace-level config */
|
|
34
|
+
export declare const NAMESPACE_META: WeakMap<object, NamespaceMeta>;
|
|
35
|
+
/** Keyed by class constructor — maps method property keys to their config */
|
|
36
|
+
export declare const METHOD_META: WeakMap<object, Map<string, MethodMeta>>;
|
|
37
|
+
/**
|
|
38
|
+
* Pending method metadata updates, flushed by @Namespace.
|
|
39
|
+
*
|
|
40
|
+
* Each entry is a function that receives the class constructor and applies
|
|
41
|
+
* its metadata. This avoids initializer ordering becoming shared state.
|
|
42
|
+
*/
|
|
43
|
+
export declare const PENDING_METHOD_UPDATES: Array<(Class: object) => void>;
|
|
44
|
+
/** Get or initialize namespace metadata for a class constructor */
|
|
45
|
+
export declare function getOrCreateNamespaceMeta(target: object): NamespaceMeta;
|
|
46
|
+
/** Get or initialize the method metadata map for a class constructor */
|
|
47
|
+
export declare function getOrCreateMethodMap(target: object): Map<string, MethodMeta>;
|
|
48
|
+
/** Get or initialize metadata for a specific method on a class */
|
|
49
|
+
export declare function getOrCreateMethodMeta(target: object, key: string): MethodMeta;
|
|
50
|
+
/**
|
|
51
|
+
* Queue a method-level metadata update to be flushed by @Namespace.
|
|
52
|
+
*
|
|
53
|
+
* @param updater - Receives the class constructor when flushed
|
|
54
|
+
*/
|
|
55
|
+
export declare function queueMethodUpdate(updater: (Class: object) => void): void;
|
|
56
|
+
/**
|
|
57
|
+
* Flush all pending method updates for the given class constructor.
|
|
58
|
+
* Called by @Namespace after all method decorators have run.
|
|
59
|
+
*/
|
|
60
|
+
export declare function flushPendingUpdates(Class: object): void;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WeakMap-based metadata stores for TypeFerry decorator API.
|
|
3
|
+
*
|
|
4
|
+
* TC39 Stage 3 decorators don't have `reflect-metadata`, so we use WeakMaps
|
|
5
|
+
* keyed by class constructor (namespace) and class prototype (methods).
|
|
6
|
+
*
|
|
7
|
+
* Method decorators push updates to a pending queue instead of using
|
|
8
|
+
* `addInitializer` so metadata ownership stays explicit across classes defined
|
|
9
|
+
* in the same file. The @Namespace decorator flushes the queue after methods.
|
|
10
|
+
*
|
|
11
|
+
* @module typeferry/server/decorators/metadata
|
|
12
|
+
*/
|
|
13
|
+
/** Keyed by class constructor — stores namespace-level config */
|
|
14
|
+
export const NAMESPACE_META = new WeakMap();
|
|
15
|
+
/** Keyed by class constructor — maps method property keys to their config */
|
|
16
|
+
export const METHOD_META = new WeakMap();
|
|
17
|
+
/**
|
|
18
|
+
* Pending method metadata updates, flushed by @Namespace.
|
|
19
|
+
*
|
|
20
|
+
* Each entry is a function that receives the class constructor and applies
|
|
21
|
+
* its metadata. This avoids initializer ordering becoming shared state.
|
|
22
|
+
*/
|
|
23
|
+
export const PENDING_METHOD_UPDATES = [];
|
|
24
|
+
const DEFAULT_NAMESPACE_META = {
|
|
25
|
+
prefix: '',
|
|
26
|
+
protected: false,
|
|
27
|
+
cached: false,
|
|
28
|
+
maxAge: 60_000,
|
|
29
|
+
};
|
|
30
|
+
/** Get or initialize namespace metadata for a class constructor */
|
|
31
|
+
export function getOrCreateNamespaceMeta(target) {
|
|
32
|
+
let meta = NAMESPACE_META.get(target);
|
|
33
|
+
if (!meta) {
|
|
34
|
+
meta = { ...DEFAULT_NAMESPACE_META };
|
|
35
|
+
NAMESPACE_META.set(target, meta);
|
|
36
|
+
}
|
|
37
|
+
return meta;
|
|
38
|
+
}
|
|
39
|
+
/** Get or initialize the method metadata map for a class constructor */
|
|
40
|
+
export function getOrCreateMethodMap(target) {
|
|
41
|
+
let map = METHOD_META.get(target);
|
|
42
|
+
if (!map) {
|
|
43
|
+
map = new Map();
|
|
44
|
+
METHOD_META.set(target, map);
|
|
45
|
+
}
|
|
46
|
+
return map;
|
|
47
|
+
}
|
|
48
|
+
/** Get or initialize metadata for a specific method on a class */
|
|
49
|
+
export function getOrCreateMethodMeta(target, key) {
|
|
50
|
+
const map = getOrCreateMethodMap(target);
|
|
51
|
+
let meta = map.get(key);
|
|
52
|
+
if (!meta) {
|
|
53
|
+
meta = { name: key, middleware: [] };
|
|
54
|
+
map.set(key, meta);
|
|
55
|
+
}
|
|
56
|
+
return meta;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Queue a method-level metadata update to be flushed by @Namespace.
|
|
60
|
+
*
|
|
61
|
+
* @param updater - Receives the class constructor when flushed
|
|
62
|
+
*/
|
|
63
|
+
export function queueMethodUpdate(updater) {
|
|
64
|
+
PENDING_METHOD_UPDATES.push(updater);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Flush all pending method updates for the given class constructor.
|
|
68
|
+
* Called by @Namespace after all method decorators have run.
|
|
69
|
+
*/
|
|
70
|
+
export function flushPendingUpdates(Class) {
|
|
71
|
+
while (PENDING_METHOD_UPDATES.length > 0) {
|
|
72
|
+
const updater = PENDING_METHOD_UPDATES.pop();
|
|
73
|
+
if (updater)
|
|
74
|
+
updater(Class);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/server/decorators/metadata.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA0BH,iEAAiE;AACjE,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,OAAO,EAAyB,CAAA;AAElE,6EAA6E;AAC7E,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,OAAO,EAAmC,CAAA;AAEzE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAmC,EAAE,CAAA;AAExE,MAAM,sBAAsB,GAAkB;IAC5C,MAAM,EAAE,EAAE;IACV,SAAS,EAAE,KAAK;IAChB,MAAM,EAAE,KAAK;IACb,MAAM,EAAE,MAAM;CACf,CAAA;AAED,mEAAmE;AACnE,MAAM,UAAU,wBAAwB,CAAC,MAAc;IACrD,IAAI,IAAI,GAAG,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACrC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,IAAI,GAAG,EAAE,GAAG,sBAAsB,EAAE,CAAA;QACpC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAClC,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,oBAAoB,CAAC,MAAc;IACjD,IAAI,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACjC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,GAAG,GAAG,IAAI,GAAG,EAAE,CAAA;QACf,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,qBAAqB,CAAC,MAAc,EAAE,GAAW;IAC/D,MAAM,GAAG,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAA;IACxC,IAAI,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACvB,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,IAAI,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,CAAA;QACpC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACpB,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgC;IAChE,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AACtC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,OAAO,sBAAsB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzC,MAAM,OAAO,GAAG,sBAAsB,CAAC,GAAG,EAAE,CAAA;QAC5C,IAAI,OAAO;YAAE,OAAO,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Method decorator — marks a class method as a TypeFerry RPC endpoint.
|
|
3
|
+
*
|
|
4
|
+
* Queues a metadata update that @Namespace flushes after all method decorators
|
|
5
|
+
* have run. A pending queue keeps initializer ordering explicit across classes.
|
|
6
|
+
*
|
|
7
|
+
* @module typeferry/server/decorators/method
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Marks a class method as a TypeFerry RPC method.
|
|
11
|
+
*
|
|
12
|
+
* @param name - Optional override for the RPC method name (defaults to property key)
|
|
13
|
+
*/
|
|
14
|
+
export declare function Method(name?: string): <T extends (...args: never[]) => unknown>(target: T, context: ClassMethodDecoratorContext) => T;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Method decorator — marks a class method as a TypeFerry RPC endpoint.
|
|
3
|
+
*
|
|
4
|
+
* Queues a metadata update that @Namespace flushes after all method decorators
|
|
5
|
+
* have run. A pending queue keeps initializer ordering explicit across classes.
|
|
6
|
+
*
|
|
7
|
+
* @module typeferry/server/decorators/method
|
|
8
|
+
*/
|
|
9
|
+
import { getOrCreateMethodMeta, queueMethodUpdate } from './metadata.js';
|
|
10
|
+
/**
|
|
11
|
+
* Marks a class method as a TypeFerry RPC method.
|
|
12
|
+
*
|
|
13
|
+
* @param name - Optional override for the RPC method name (defaults to property key)
|
|
14
|
+
*/
|
|
15
|
+
export function Method(name) {
|
|
16
|
+
return function (target, context) {
|
|
17
|
+
const key = String(context.name);
|
|
18
|
+
queueMethodUpdate(Class => {
|
|
19
|
+
const meta = getOrCreateMethodMeta(Class, key);
|
|
20
|
+
meta.name = name ?? key;
|
|
21
|
+
});
|
|
22
|
+
return target;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=method.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method.js","sourceRoot":"","sources":["../../../src/server/decorators/method.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAErE;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,IAAa;IAClC,OAAO,UACL,MAAS,EACT,OAAoC;QAEpC,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAEhC,iBAAiB,CAAC,KAAK,CAAC,EAAE;YACxB,MAAM,IAAI,GAAG,qBAAqB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;YAC9C,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,GAAG,CAAA;QACzB,CAAC,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Namespace class decorator — registers a class as a TypeFerry RPC namespace.
|
|
3
|
+
*
|
|
4
|
+
* All methods in the class are prefixed with `{prefix}.{methodName}`.
|
|
5
|
+
* Also flushes pending @Method metadata into the class's WeakMap entry.
|
|
6
|
+
*
|
|
7
|
+
* @module typeferry/server/decorators/namespace
|
|
8
|
+
*/
|
|
9
|
+
type ClassConstructor = abstract new (...args: unknown[]) => unknown;
|
|
10
|
+
/**
|
|
11
|
+
* Registers the decorated class as a TypeFerry namespace with the given prefix.
|
|
12
|
+
*
|
|
13
|
+
* Class decorators run after all method decorators, so we flush the pending
|
|
14
|
+
* update queue here — each queued updater receives this class constructor
|
|
15
|
+
* and writes its metadata into the class's WeakMap entry.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* @Namespace('boards')
|
|
20
|
+
* class BoardMethods { ... }
|
|
21
|
+
* // Methods register as: boards.get, boards.create, etc.
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function Namespace(prefix: string): <T extends ClassConstructor>(target: T, _context: ClassDecoratorContext) => T;
|
|
25
|
+
export {};
|