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,34 @@
|
|
|
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
|
+
import { flushPendingUpdates, getOrCreateNamespaceMeta } from './metadata.js';
|
|
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 function Namespace(prefix) {
|
|
25
|
+
return function (target, _context) {
|
|
26
|
+
const meta = getOrCreateNamespaceMeta(target);
|
|
27
|
+
meta.prefix = prefix;
|
|
28
|
+
// Flush all pending method-level metadata updates (@Method, @Schema,
|
|
29
|
+
// @Use, @Protected, @Cached, etc.) into this class's WeakMap entries.
|
|
30
|
+
flushPendingUpdates(target);
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=namespace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespace.js","sourceRoot":"","sources":["../../../src/server/decorators/namespace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAI1E;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CAAC,MAAc;IACtC,OAAO,UACL,MAAS,EACT,QAA+B;QAE/B,MAAM,IAAI,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAA;QAC7C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QAEpB,qEAAqE;QACrE,sEAAsE;QACtE,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAE3B,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Protected class decorator — sets `protected: true` as default for all methods.
|
|
3
|
+
* @Public method decorator — overrides class-level @Protected for a specific method.
|
|
4
|
+
*
|
|
5
|
+
* @module typeferry/server/decorators/protected
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Sets `protected: true` as default for all methods in the class.
|
|
9
|
+
* Individual methods can override with @Public().
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* @Namespace('boards')
|
|
14
|
+
* @Protected()
|
|
15
|
+
* class BoardMethods {
|
|
16
|
+
* // All methods here require authentication by default
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function Protected(): <T>(target: T, context: ClassDecoratorContext | ClassMethodDecoratorContext) => T;
|
|
21
|
+
/**
|
|
22
|
+
* Overrides class-level @Protected() for a specific method, making it public.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* @Namespace('boards')
|
|
27
|
+
* @Protected()
|
|
28
|
+
* class BoardMethods {
|
|
29
|
+
* @Method()
|
|
30
|
+
* @Public()
|
|
31
|
+
* async listPublic(client: ClientNode, params) { ... }
|
|
32
|
+
* // This method does NOT require authentication
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function Public(): <T extends (...args: never[]) => unknown>(target: T, context: ClassMethodDecoratorContext) => T;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Protected class decorator — sets `protected: true` as default for all methods.
|
|
3
|
+
* @Public method decorator — overrides class-level @Protected for a specific method.
|
|
4
|
+
*
|
|
5
|
+
* @module typeferry/server/decorators/protected
|
|
6
|
+
*/
|
|
7
|
+
import { getOrCreateMethodMeta, getOrCreateNamespaceMeta, queueMethodUpdate, } from './metadata.js';
|
|
8
|
+
/**
|
|
9
|
+
* Sets `protected: true` as default for all methods in the class.
|
|
10
|
+
* Individual methods can override with @Public().
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* @Namespace('boards')
|
|
15
|
+
* @Protected()
|
|
16
|
+
* class BoardMethods {
|
|
17
|
+
* // All methods here require authentication by default
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function Protected() {
|
|
22
|
+
return function (target, context) {
|
|
23
|
+
if (context.kind === 'class') {
|
|
24
|
+
const meta = getOrCreateNamespaceMeta(target);
|
|
25
|
+
meta.protected = true;
|
|
26
|
+
return target;
|
|
27
|
+
}
|
|
28
|
+
const key = String(context.name);
|
|
29
|
+
queueMethodUpdate(Class => {
|
|
30
|
+
const meta = getOrCreateMethodMeta(Class, key);
|
|
31
|
+
meta.protected = true;
|
|
32
|
+
});
|
|
33
|
+
return target;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Overrides class-level @Protected() for a specific method, making it public.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* @Namespace('boards')
|
|
42
|
+
* @Protected()
|
|
43
|
+
* class BoardMethods {
|
|
44
|
+
* @Method()
|
|
45
|
+
* @Public()
|
|
46
|
+
* async listPublic(client: ClientNode, params) { ... }
|
|
47
|
+
* // This method does NOT require authentication
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export function Public() {
|
|
52
|
+
return function (target, context) {
|
|
53
|
+
const key = String(context.name);
|
|
54
|
+
queueMethodUpdate(Class => {
|
|
55
|
+
const meta = getOrCreateMethodMeta(Class, key);
|
|
56
|
+
meta.protected = false;
|
|
57
|
+
});
|
|
58
|
+
return target;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=protected.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protected.js","sourceRoot":"","sources":["../../../src/server/decorators/protected.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,UACL,MAAS,EACT,OAA4D;QAE5D,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC7B,MAAM,IAAI,GAAG,wBAAwB,CAAC,MAAgB,CAAC,CAAA;YACvD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;YACrB,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,SAAS,GAAG,IAAI,CAAA;QACvB,CAAC,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,MAAM;IACpB,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,SAAS,GAAG,KAAK,CAAA;QACxB,CAAC,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers a decorator-based namespace class with TypeFerry.
|
|
3
|
+
*
|
|
4
|
+
* Reads WeakMap metadata from @Namespace, @Method, @Schema, @Use, @Protected,
|
|
5
|
+
* @Cached decorators and calls `global.TypeFerry.addMethod()` for each method.
|
|
6
|
+
*
|
|
7
|
+
* @module typeferry/server/decorators/register
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Registers all decorated methods on a namespace class with TypeFerry.
|
|
11
|
+
*
|
|
12
|
+
* Creates a singleton instance, reads class/method metadata, wraps each method
|
|
13
|
+
* to inject `ClientNode` as the first argument, and calls `global.TypeFerry.addMethod()`.
|
|
14
|
+
*
|
|
15
|
+
* @param Class - A class decorated with @Namespace and containing @Method members
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { registerNamespace } from 'typeferry/server/decorators'
|
|
20
|
+
* import { BoardMethods } from './boards.js'
|
|
21
|
+
*
|
|
22
|
+
* registerNamespace(BoardMethods)
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function registerNamespace(Class: new (...args: never[]) => unknown): void;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers a decorator-based namespace class with TypeFerry.
|
|
3
|
+
*
|
|
4
|
+
* Reads WeakMap metadata from @Namespace, @Method, @Schema, @Use, @Protected,
|
|
5
|
+
* @Cached decorators and calls `global.TypeFerry.addMethod()` for each method.
|
|
6
|
+
*
|
|
7
|
+
* @module typeferry/server/decorators/register
|
|
8
|
+
*/
|
|
9
|
+
import { METHOD_META, NAMESPACE_META } from './metadata.js';
|
|
10
|
+
/** Build a full method name from namespace prefix and method name */
|
|
11
|
+
function buildFullName(nsMeta, meta) {
|
|
12
|
+
return nsMeta.prefix ? `${nsMeta.prefix}.${meta.name}` : meta.name;
|
|
13
|
+
}
|
|
14
|
+
/** Merge class-level and method-level options into MethodOptions */
|
|
15
|
+
function buildOptions(nsMeta, meta) {
|
|
16
|
+
const isProtected = meta.protected ?? nsMeta.protected;
|
|
17
|
+
const isCached = meta.cached ?? nsMeta.cached;
|
|
18
|
+
const maxAge = meta.maxAge ?? (isCached ? nsMeta.maxAge : undefined);
|
|
19
|
+
return {
|
|
20
|
+
protected: isProtected,
|
|
21
|
+
middleware: meta.middleware.length > 0 ? meta.middleware : undefined,
|
|
22
|
+
schema: meta.schema,
|
|
23
|
+
cache: isCached || undefined,
|
|
24
|
+
maxAge,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Wrap a decorator-style method (explicit client param) into TypeFerry's
|
|
29
|
+
* `this`-based ClientNode binding.
|
|
30
|
+
*/
|
|
31
|
+
function wrapMethod(boundFn) {
|
|
32
|
+
return function (params) {
|
|
33
|
+
return boundFn(this, params);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Registers all decorated methods on a namespace class with TypeFerry.
|
|
38
|
+
*
|
|
39
|
+
* Creates a singleton instance, reads class/method metadata, wraps each method
|
|
40
|
+
* to inject `ClientNode` as the first argument, and calls `global.TypeFerry.addMethod()`.
|
|
41
|
+
*
|
|
42
|
+
* @param Class - A class decorated with @Namespace and containing @Method members
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { registerNamespace } from 'typeferry/server/decorators'
|
|
47
|
+
* import { BoardMethods } from './boards.js'
|
|
48
|
+
*
|
|
49
|
+
* registerNamespace(BoardMethods)
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export function registerNamespace(Class) {
|
|
53
|
+
const nsMeta = NAMESPACE_META.get(Class);
|
|
54
|
+
if (!nsMeta) {
|
|
55
|
+
throw new Error(`Class "${Class.name}" is missing @Namespace decorator. ` +
|
|
56
|
+
'Add @Namespace(prefix) to register it as a TypeFerry namespace.');
|
|
57
|
+
}
|
|
58
|
+
// Instantiate to get bound method references for TypeFerry registration
|
|
59
|
+
const instance = new Class();
|
|
60
|
+
const methodsMap = METHOD_META.get(Class);
|
|
61
|
+
if (!methodsMap?.size) {
|
|
62
|
+
throw new Error(`Namespace "${nsMeta.prefix}" (${Class.name}) has no @Method-decorated members.`);
|
|
63
|
+
}
|
|
64
|
+
for (const [propertyKey, meta] of methodsMap) {
|
|
65
|
+
const originalFn = instance[propertyKey];
|
|
66
|
+
if (typeof originalFn !== 'function') {
|
|
67
|
+
throw new Error(`"${propertyKey}" on ${Class.name} is not a function — cannot register as TypeFerry method.`);
|
|
68
|
+
}
|
|
69
|
+
global.TypeFerry.addMethod(buildFullName(nsMeta, meta), wrapMethod(originalFn.bind(instance)), buildOptions(nsMeta, meta));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../../src/server/decorators/register.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAExD,qEAAqE;AACrE,SAAS,aAAa,CAAC,MAAqB,EAAE,IAAgB;IAC5D,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAA;AACpE,CAAC;AAED,oEAAoE;AACpE,SAAS,YAAY,CAAC,MAAqB,EAAE,IAAgB;IAC3D,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,CAAA;IACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAA;IAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAEpE,OAAO;QACL,SAAS,EAAE,WAAW;QACtB,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;QACpE,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,KAAK,EAAE,QAAQ,IAAI,SAAS;QAC5B,MAAM;KACP,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,UAAU,CACjB,OAAyD;IAEzD,OAAO,UAA4B,MAAM;QACvC,OAAO,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAC9B,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAwC;IAExC,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACxC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,UAAU,KAAK,CAAC,IAAI,qCAAqC;YACvD,iEAAiE,CACpE,CAAA;IACH,CAAC;IAED,wEAAwE;IACxE,MAAM,QAAQ,GAAG,IAAK,KAA2C,EAAE,CAAA;IAEnE,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACzC,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,cAAc,MAAM,CAAC,MAAM,MAAM,KAAK,CAAC,IAAI,qCAAqC,CACjF,CAAA;IACH,CAAC;IAED,KAAK,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC;QAC7C,MAAM,UAAU,GAAG,QAAQ,CAAC,WAAW,CAG3B,CAAA;QAEZ,IAAI,OAAO,UAAU,KAAK,UAAU,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CACb,IAAI,WAAW,QAAQ,KAAK,CAAC,IAAI,2DAA2D,CAC7F,CAAA;QACH,CAAC;QAED,MAAM,CAAC,SAAS,CAAC,SAAS,CACxB,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,EAC3B,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EACrC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAC3B,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Schema decorator — attaches a Zod validation schema to a TypeFerry method.
|
|
3
|
+
*
|
|
4
|
+
* @module typeferry/server/decorators/schema
|
|
5
|
+
*/
|
|
6
|
+
import type { z } from 'zod';
|
|
7
|
+
/**
|
|
8
|
+
* Attaches a Zod schema for input validation on the decorated method.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* @Method()
|
|
13
|
+
* @Schema(z.object({ boardId: z.string(), name: z.string().min(1) }))
|
|
14
|
+
* async create(client: ClientNode, params: CreateParams) { ... }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function Schema(schema: z.ZodType): <T extends (...args: never[]) => unknown>(target: T, context: ClassMethodDecoratorContext) => T;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Schema decorator — attaches a Zod validation schema to a TypeFerry method.
|
|
3
|
+
*
|
|
4
|
+
* @module typeferry/server/decorators/schema
|
|
5
|
+
*/
|
|
6
|
+
import { getOrCreateMethodMeta, queueMethodUpdate } from './metadata.js';
|
|
7
|
+
/**
|
|
8
|
+
* Attaches a Zod schema for input validation on the decorated method.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* @Method()
|
|
13
|
+
* @Schema(z.object({ boardId: z.string(), name: z.string().min(1) }))
|
|
14
|
+
* async create(client: ClientNode, params: CreateParams) { ... }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export function Schema(schema) {
|
|
18
|
+
return function (target, context) {
|
|
19
|
+
const key = String(context.name);
|
|
20
|
+
queueMethodUpdate(Class => {
|
|
21
|
+
const meta = getOrCreateMethodMeta(Class, key);
|
|
22
|
+
meta.schema = schema;
|
|
23
|
+
});
|
|
24
|
+
return target;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/server/decorators/schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAErE;;;;;;;;;GASG;AACH,MAAM,UAAU,MAAM,CAAC,MAAiB;IACtC,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,MAAM,CAAA;QACtB,CAAC,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Use decorator — attaches middleware functions to a TypeFerry method.
|
|
3
|
+
*
|
|
4
|
+
* Multiple @Use() decorators stack. TC39 decorators evaluate bottom-to-top,
|
|
5
|
+
* so the pending queue receives entries in reverse order. @Namespace flushes
|
|
6
|
+
* them with `.pop()`, restoring the visual order (top @Use runs first).
|
|
7
|
+
*
|
|
8
|
+
* @module typeferry/server/decorators/use
|
|
9
|
+
*/
|
|
10
|
+
import type { AnyFunction } from '../../utils/index.js';
|
|
11
|
+
/**
|
|
12
|
+
* Attaches middleware functions to the decorated method.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* @Method()
|
|
17
|
+
* @Schema(z.object({ boardId: z.string() }))
|
|
18
|
+
* @Use(withBoardPermissionLevel(Permission.Read))
|
|
19
|
+
* async get(client: ClientNode, { boardId, board }: GetBoardParams) { ... }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function Use(...middleware: AnyFunction[]): <T extends (...args: never[]) => unknown>(target: T, context: ClassMethodDecoratorContext) => T;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Use decorator — attaches middleware functions to a TypeFerry method.
|
|
3
|
+
*
|
|
4
|
+
* Multiple @Use() decorators stack. TC39 decorators evaluate bottom-to-top,
|
|
5
|
+
* so the pending queue receives entries in reverse order. @Namespace flushes
|
|
6
|
+
* them with `.pop()`, restoring the visual order (top @Use runs first).
|
|
7
|
+
*
|
|
8
|
+
* @module typeferry/server/decorators/use
|
|
9
|
+
*/
|
|
10
|
+
import { getOrCreateMethodMeta, queueMethodUpdate } from './metadata.js';
|
|
11
|
+
/**
|
|
12
|
+
* Attaches middleware functions to the decorated method.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* @Method()
|
|
17
|
+
* @Schema(z.object({ boardId: z.string() }))
|
|
18
|
+
* @Use(withBoardPermissionLevel(Permission.Read))
|
|
19
|
+
* async get(client: ClientNode, { boardId, board }: GetBoardParams) { ... }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function Use(...middleware) {
|
|
23
|
+
return function (target, context) {
|
|
24
|
+
const key = String(context.name);
|
|
25
|
+
queueMethodUpdate(Class => {
|
|
26
|
+
const meta = getOrCreateMethodMeta(Class, key);
|
|
27
|
+
meta.middleware.push(...middleware);
|
|
28
|
+
});
|
|
29
|
+
return target;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=use.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use.js","sourceRoot":"","sources":["../../../src/server/decorators/use.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAErE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,GAAG,CAAC,GAAG,UAAyB;IAC9C,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,UAAU,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAA;QACrC,CAAC,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { Method } from './method.js';
|
|
3
|
+
import type { Server } from './server.js';
|
|
4
|
+
type MethodBuilder<Schema extends z.ZodUndefined | z.ZodObject<any> = z.ZodUndefined, Result = any> = (server: Server, name: string) => Method<Schema, Result>;
|
|
5
|
+
export declare const DefaultMethods: {
|
|
6
|
+
[key: string]: MethodBuilder;
|
|
7
|
+
};
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Methods } from '../utils/index.js';
|
|
2
|
+
import { rpcLogout, rpcOff, rpcOn } from './methods.js';
|
|
3
|
+
export const DefaultMethods = {
|
|
4
|
+
[Methods.RPC_ON]: rpcOn,
|
|
5
|
+
[Methods.RPC_OFF]: rpcOff,
|
|
6
|
+
[Methods.RPC_LOGOUT]: rpcLogout,
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=default-methods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-methods.js","sourceRoot":"","sources":["../../src/server/default-methods.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAQpD,MAAM,CAAC,MAAM,cAAc,GAEvB;IACF,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK;IACvB,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM;IACzB,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,SAAS;CAChC,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ClientNode } from './client-node.js';
|
|
2
|
+
import type { Server } from './server.js';
|
|
3
|
+
import type { ServerChannel } from './server-channel.js';
|
|
4
|
+
export type EventOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Requires authentication to subscribe to this event.
|
|
7
|
+
*/
|
|
8
|
+
protected?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Only allow user to subscribe to this event on his own channel. Automatically makes the event protected.
|
|
11
|
+
*/
|
|
12
|
+
user?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* This overrides the `user` flag.
|
|
15
|
+
*/
|
|
16
|
+
shouldSubscribe?: (client: ClientNode, eventName: string, channel: string) => Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* This will propagate the event to other instances when running node in a cluster.
|
|
19
|
+
*/
|
|
20
|
+
cluster?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* When true, excludes the originating client from receiving the event.
|
|
23
|
+
* Requires `params.uuid` to identify the originator.
|
|
24
|
+
*/
|
|
25
|
+
excludeOriginator?: boolean;
|
|
26
|
+
};
|
|
27
|
+
export declare class Event {
|
|
28
|
+
uuid: string;
|
|
29
|
+
name: string;
|
|
30
|
+
isProtected: boolean;
|
|
31
|
+
channel: ServerChannel;
|
|
32
|
+
server: Server;
|
|
33
|
+
cluster: boolean;
|
|
34
|
+
excludeOriginator: boolean;
|
|
35
|
+
shouldSubscribe: (client: ClientNode, eventName: string, channel: string) => Promise<boolean>;
|
|
36
|
+
constructor(name: string, server: Server, channel: ServerChannel, opts?: EventOptions);
|
|
37
|
+
/**
|
|
38
|
+
* Encodes the event with the wire protocol `t` field so propagate()
|
|
39
|
+
* can forward the payload directly without re-encoding.
|
|
40
|
+
*/
|
|
41
|
+
handler(channel: ServerChannel, params: Record<string, string>): void;
|
|
42
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { MessageType, Presentation } from '../utils/index.js';
|
|
2
|
+
export class Event {
|
|
3
|
+
uuid;
|
|
4
|
+
name;
|
|
5
|
+
isProtected;
|
|
6
|
+
channel;
|
|
7
|
+
server;
|
|
8
|
+
cluster;
|
|
9
|
+
excludeOriginator;
|
|
10
|
+
shouldSubscribe = async () => true;
|
|
11
|
+
constructor(name, server, channel, opts) {
|
|
12
|
+
this.uuid = Presentation.uuid();
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.server = server;
|
|
15
|
+
this.channel = channel;
|
|
16
|
+
this.isProtected = opts?.protected ?? false;
|
|
17
|
+
if (opts?.user) {
|
|
18
|
+
this.isProtected = true;
|
|
19
|
+
this.shouldSubscribe = async function (client, event, channel) {
|
|
20
|
+
if (!client.userId)
|
|
21
|
+
return false;
|
|
22
|
+
return channel === client.userId.toString();
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (opts?.shouldSubscribe) {
|
|
26
|
+
this.shouldSubscribe = opts.shouldSubscribe;
|
|
27
|
+
}
|
|
28
|
+
this.cluster = Boolean(opts?.cluster);
|
|
29
|
+
this.excludeOriginator = Boolean(opts?.excludeOriginator);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Encodes the event with the wire protocol `t` field so propagate()
|
|
33
|
+
* can forward the payload directly without re-encoding.
|
|
34
|
+
*/
|
|
35
|
+
handler(channel, params) {
|
|
36
|
+
const payload = Presentation.encode({
|
|
37
|
+
t: MessageType.EVENT,
|
|
38
|
+
uuid: Presentation.uuid(),
|
|
39
|
+
event: this.name,
|
|
40
|
+
channel: channel.channelName,
|
|
41
|
+
params,
|
|
42
|
+
});
|
|
43
|
+
const excludeUuid = this.excludeOriginator ? params.uuid : undefined;
|
|
44
|
+
if (this.cluster && this.server?.redisTransport?.pub) {
|
|
45
|
+
this.server.redisTransport
|
|
46
|
+
.publish(this.name, channel.channelName, payload, excludeUuid)
|
|
47
|
+
.catch(console.error);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
channel.propagate(this.name, payload, excludeUuid);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/server/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAqCpD,MAAM,OAAO,KAAK;IAChB,IAAI,CAAQ;IACZ,IAAI,CAAQ;IACZ,WAAW,CAAS;IACpB,OAAO,CAAe;IACtB,MAAM,CAAQ;IACd,OAAO,CAAS;IAChB,iBAAiB,CAAS;IAE1B,eAAe,GAIS,KAAK,IAAI,EAAE,CAAC,IAAI,CAAA;IAExC,YACE,IAAY,EACZ,MAAc,EACd,OAAsB,EACtB,IAAmB;QAEnB,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,CAAA;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QAEtB,IAAI,CAAC,WAAW,GAAG,IAAI,EAAE,SAAS,IAAI,KAAK,CAAA;QAE3C,IAAI,IAAI,EAAE,IAAI,EAAE,CAAC;YACf,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;YAEvB,IAAI,CAAC,eAAe,GAAG,KAAK,WAAW,MAAM,EAAE,KAAK,EAAE,OAAO;gBAC3D,IAAI,CAAC,MAAM,CAAC,MAAM;oBAAE,OAAO,KAAK,CAAA;gBAEhC,OAAO,OAAO,KAAK,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAA;YAC7C,CAAC,CAAA;QACH,CAAC;QAED,IAAI,IAAI,EAAE,eAAe,EAAE,CAAC;YAC1B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAA;QAC7C,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QACrC,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA;IAC3D,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,OAAsB,EAAE,MAA8B;QAC5D,MAAM,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC;YAClC,CAAC,EAAE,WAAW,CAAC,KAAK;YACpB,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE;YACzB,KAAK,EAAE,IAAI,CAAC,IAAI;YAChB,OAAO,EAAE,OAAO,CAAC,WAAW;YAC5B,MAAM;SACP,CAAC,CAAA;QAEF,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;QAEpE,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,CAAC;YACrD,IAAI,CAAC,MAAM,CAAC,cAAc;iBACvB,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,EAAE,WAAW,CAAC;iBAC7D,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YAEvB,OAAM;QACR,CAAC;QAED,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;IACpD,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './typeferry-async-local-storage.js';
|
|
2
|
+
export * from './client-node.js';
|
|
3
|
+
export * from './default-methods.js';
|
|
4
|
+
export * from './event.js';
|
|
5
|
+
export * from './method.js';
|
|
6
|
+
export * from './methods.js';
|
|
7
|
+
export * from './server.js';
|
|
8
|
+
export * from './server-channel.js';
|
|
9
|
+
export * from './transports/index.js';
|
|
10
|
+
export * from './types.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './typeferry-async-local-storage.js';
|
|
2
|
+
export * from './client-node.js';
|
|
3
|
+
export * from './default-methods.js';
|
|
4
|
+
export * from './event.js';
|
|
5
|
+
export * from './method.js';
|
|
6
|
+
export * from './methods.js';
|
|
7
|
+
export * from './server.js';
|
|
8
|
+
export * from './server-channel.js';
|
|
9
|
+
export * from './transports/index.js';
|
|
10
|
+
export * from './types.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAA;AAC/C,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,kBAAkB,CAAA;AAChC,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { AnyFunction, MethodParams as MethodParameters } from '../utils/index.js';
|
|
3
|
+
import type { ClientNode } from './client-node.js';
|
|
4
|
+
import type { Server } from './server.js';
|
|
5
|
+
/**
|
|
6
|
+
* Function signature for TypeFerry RPC methods.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam T - The type of the method parameters
|
|
9
|
+
* @typeParam R - The return type of the method
|
|
10
|
+
*/
|
|
11
|
+
export type MethodFunction<T = any, R = any> = (this: ClientNode, parameters?: MethodParameters<T>) => Promise<R> | R;
|
|
12
|
+
/**
|
|
13
|
+
* Configuration options for TypeFerry RPC methods.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam Schema - A Zod schema type for input validation
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* TypeFerry.addMethod(
|
|
20
|
+
* 'user.create',
|
|
21
|
+
* async ({ email, name }) => { ... },
|
|
22
|
+
* {
|
|
23
|
+
* protected: true,
|
|
24
|
+
* schema: z.object({
|
|
25
|
+
* email: z.string().email(),
|
|
26
|
+
* name: z.string().min(1),
|
|
27
|
+
* }),
|
|
28
|
+
* }
|
|
29
|
+
* )
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export interface MethodOptions<Schema extends z.ZodType = z.ZodType> {
|
|
33
|
+
/** Enable result caching for this method */
|
|
34
|
+
cache?: boolean;
|
|
35
|
+
/** Cache TTL in milliseconds (default: 60000) */
|
|
36
|
+
maxAge?: number;
|
|
37
|
+
/** Require authentication to call this method */
|
|
38
|
+
protected?: boolean;
|
|
39
|
+
/** Middleware functions to run before the method handler */
|
|
40
|
+
middleware?: AnyFunction[];
|
|
41
|
+
/** Zod schema for input validation and type inference */
|
|
42
|
+
schema?: Schema;
|
|
43
|
+
/**
|
|
44
|
+
* Redact parameters, results, and errors from method telemetry.
|
|
45
|
+
*
|
|
46
|
+
* Use this for RPCs whose payloads contain credentials, authorization
|
|
47
|
+
* scopes, private query arguments, or other data that must not reach
|
|
48
|
+
* METHOD_EXECUTION/METHOD_ERROR observers.
|
|
49
|
+
*/
|
|
50
|
+
sensitive?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/** Stable marker used when sensitive method telemetry is intentionally hidden. */
|
|
53
|
+
export declare const REDACTED_METHOD_TELEMETRY: "[REDACTED]";
|
|
54
|
+
/** Returns a method telemetry field with the configured sensitivity applied. */
|
|
55
|
+
export declare function redactMethodTelemetry(method: Pick<Method<z.ZodType, unknown>, 'isSensitive'>, value: unknown): unknown;
|
|
56
|
+
/**
|
|
57
|
+
* Represents a registered TypeFerry RPC method with validation and middleware support.
|
|
58
|
+
*
|
|
59
|
+
* Methods are the core RPC primitives in TypeFerry. Each method can have:
|
|
60
|
+
* - Input validation via Zod schemas
|
|
61
|
+
* - Middleware chain for authentication/authorization
|
|
62
|
+
* - Result caching with configurable TTL
|
|
63
|
+
* - Execution time tracking
|
|
64
|
+
*
|
|
65
|
+
* @typeParam Schema - The Zod schema type for input validation
|
|
66
|
+
* @typeParam Result - The return type of the method
|
|
67
|
+
*/
|
|
68
|
+
export declare class Method<Schema extends z.ZodType, Result> {
|
|
69
|
+
uuid: string;
|
|
70
|
+
fn: MethodFunction;
|
|
71
|
+
isProtected: boolean;
|
|
72
|
+
isSensitive: boolean;
|
|
73
|
+
middleware: AnyFunction[];
|
|
74
|
+
schema: z.ZodSchema | null;
|
|
75
|
+
name: string;
|
|
76
|
+
server: Server;
|
|
77
|
+
constructor(server: Server, name: string, fn: MethodFunction<z.input<Schema> | any, Result>, opts: MethodOptions<Schema>);
|
|
78
|
+
/**
|
|
79
|
+
* Executes the middleware chain, passing params through each middleware.
|
|
80
|
+
* Each middleware can transform or augment the params before passing to the next.
|
|
81
|
+
*/
|
|
82
|
+
runMiddleware(parameters: MethodParameters, node?: ClientNode): Promise<MethodParameters>;
|
|
83
|
+
/**
|
|
84
|
+
* Executes the method with validation, middleware, and timing.
|
|
85
|
+
*
|
|
86
|
+
* Execution flow:
|
|
87
|
+
* 1. Validate params against Zod schema (if provided)
|
|
88
|
+
* 2. Run middleware chain
|
|
89
|
+
* 3. Execute method handler
|
|
90
|
+
* 4. Emit execution event with timing data
|
|
91
|
+
*
|
|
92
|
+
* @throws {SchemaValidationError} When params fail Zod validation
|
|
93
|
+
*/
|
|
94
|
+
exec(parameters: MethodParameters, node?: ClientNode): Promise<Result>;
|
|
95
|
+
}
|