@ntcore-ts/client 1.0.0-beta.2

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.
Files changed (56) hide show
  1. package/README.md +51 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.esm.js +4845 -0
  5. package/dist/index.esm.js.map +1 -0
  6. package/dist/lib/client.d.ts +262 -0
  7. package/dist/lib/client.d.ts.map +1 -0
  8. package/dist/lib/index.d.ts +8 -0
  9. package/dist/lib/index.d.ts.map +1 -0
  10. package/dist/lib/pubsub/base-topic.d.ts +104 -0
  11. package/dist/lib/pubsub/base-topic.d.ts.map +1 -0
  12. package/dist/lib/pubsub/index.d.ts +6 -0
  13. package/dist/lib/pubsub/index.d.ts.map +1 -0
  14. package/dist/lib/pubsub/json-topic.d.ts +50 -0
  15. package/dist/lib/pubsub/json-topic.d.ts.map +1 -0
  16. package/dist/lib/pubsub/prefix-topic.d.ts +45 -0
  17. package/dist/lib/pubsub/prefix-topic.d.ts.map +1 -0
  18. package/dist/lib/pubsub/protobuf-schema-manager.d.ts +96 -0
  19. package/dist/lib/pubsub/protobuf-schema-manager.d.ts.map +1 -0
  20. package/dist/lib/pubsub/protobuf-topic.d.ts +126 -0
  21. package/dist/lib/pubsub/protobuf-topic.d.ts.map +1 -0
  22. package/dist/lib/pubsub/pubsub.d.ts +134 -0
  23. package/dist/lib/pubsub/pubsub.d.ts.map +1 -0
  24. package/dist/lib/pubsub/struct-topic.d.ts +40 -0
  25. package/dist/lib/pubsub/struct-topic.d.ts.map +1 -0
  26. package/dist/lib/pubsub/topic.d.ts +134 -0
  27. package/dist/lib/pubsub/topic.d.ts.map +1 -0
  28. package/dist/lib/socket/messenger.d.ts +104 -0
  29. package/dist/lib/socket/messenger.d.ts.map +1 -0
  30. package/dist/lib/socket/socket.d.ts +193 -0
  31. package/dist/lib/socket/socket.d.ts.map +1 -0
  32. package/dist/lib/struct/built-in-schemas.d.ts +21 -0
  33. package/dist/lib/struct/built-in-schemas.d.ts.map +1 -0
  34. package/dist/lib/struct/geometry.d.ts +129 -0
  35. package/dist/lib/struct/geometry.d.ts.map +1 -0
  36. package/dist/lib/struct/index.d.ts +5 -0
  37. package/dist/lib/struct/index.d.ts.map +1 -0
  38. package/dist/lib/struct/struct-codec.d.ts +14 -0
  39. package/dist/lib/struct/struct-codec.d.ts.map +1 -0
  40. package/dist/lib/struct/struct-descriptor.d.ts +60 -0
  41. package/dist/lib/struct/struct-descriptor.d.ts.map +1 -0
  42. package/dist/lib/struct/struct-parser.d.ts +28 -0
  43. package/dist/lib/struct/struct-parser.d.ts.map +1 -0
  44. package/dist/lib/struct/struct-schema-manager.d.ts +41 -0
  45. package/dist/lib/struct/struct-schema-manager.d.ts.map +1 -0
  46. package/dist/lib/types/index.d.ts +2 -0
  47. package/dist/lib/types/index.d.ts.map +1 -0
  48. package/dist/lib/types/schemas.d.ts +269 -0
  49. package/dist/lib/types/schemas.d.ts.map +1 -0
  50. package/dist/lib/types/types.d.ts +66 -0
  51. package/dist/lib/types/types.d.ts.map +1 -0
  52. package/dist/lib/util/logger.d.ts +60 -0
  53. package/dist/lib/util/logger.d.ts.map +1 -0
  54. package/dist/lib/util/util.d.ts +68 -0
  55. package/dist/lib/util/util.d.ts.map +1 -0
  56. package/package.json +64 -0
@@ -0,0 +1,104 @@
1
+ import type { NetworkTablesPrefixTopic } from './prefix-topic';
2
+ import type { PubSubClient } from './pubsub';
3
+ import type { NetworkTablesTopic } from './topic';
4
+ import type { AnnounceMessageParams, NetworkTablesTypes, PropertiesMessage, SubscribeOptions, TopicProperties } from '../types/types';
5
+ export type CallbackFn<T> = (value: T | null, params: AnnounceMessageParams) => void;
6
+ export declare abstract class NetworkTablesBaseTopic<T> {
7
+ protected abstract readonly type: 'regular' | 'prefix';
8
+ protected client: PubSubClient;
9
+ private _id?;
10
+ private readonly _name;
11
+ protected _lastChangedTime?: number;
12
+ protected _announceParams: AnnounceMessageParams | null;
13
+ private _subscribers;
14
+ isRegular(): this is NetworkTablesTopic<NetworkTablesTypes>;
15
+ isPrefix(): this is NetworkTablesPrefixTopic;
16
+ /**
17
+ * Gets the ID of the topic.
18
+ * @returns The ID of the topic.
19
+ */
20
+ get id(): number | undefined;
21
+ /**
22
+ * Gets the name of the topic.
23
+ * @returns The name of the topic.
24
+ */
25
+ get name(): string;
26
+ /**
27
+ * Gets the server time of the last value change.
28
+ * @returns The server time of the last value change.
29
+ */
30
+ get lastChangedTime(): number | undefined;
31
+ /**
32
+ * Whether the topic has been announced.
33
+ * @returns Whether the topic has been announced.
34
+ */
35
+ get announced(): boolean;
36
+ /**
37
+ * Gets the subscribers to the topic.
38
+ * @returns The subscribers to the topic.
39
+ */
40
+ get subscribers(): Map<number, {
41
+ callback: CallbackFn<T>;
42
+ options: SubscribeOptions;
43
+ }>;
44
+ /**
45
+ * Creates a new topic. This should only be done after the
46
+ * base NTCore client has been initialized.
47
+ * @param client - The client that owns the topic.
48
+ * @param name - The name of the topic.
49
+ */
50
+ constructor(client: PubSubClient, name: string);
51
+ /**
52
+ * Marks the topic as announced. This should only be called by the PubSubClient.
53
+ * @param params - The parameters of the announcement.
54
+ */
55
+ announce(params: AnnounceMessageParams): void;
56
+ /** Marks the topic as unannounced. This should only be called by the PubSubClient. */
57
+ unannounce(): void;
58
+ /**
59
+ * Creates a new subscriber.
60
+ * @param callback - The callback to call when the topic value changes.
61
+ * @param options - The options for the subscriber. `id` and `save` are not part of the public API;
62
+ * use {@link subscribeWithId} for reconnect internals.
63
+ * @returns The UID of the subscriber.
64
+ */
65
+ abstract subscribe(callback: CallbackFn<T>, options?: Omit<SubscribeOptions, 'prefix'>): number;
66
+ /**
67
+ * Creates a new subscriber, optionally reusing a subscription UID.
68
+ * @internal Used by resubscribeAll and tests. Not part of the public subscribe() signature.
69
+ * @param callback - The callback to call when the topic value changes.
70
+ * @param options - The options for the subscriber.
71
+ * @param id - The UID of the subscriber.
72
+ * @param save - Whether to save the subscriber.
73
+ * @returns The UID of the subscriber.
74
+ */
75
+ protected abstract subscribeWithId(callback: CallbackFn<T>, options?: Omit<SubscribeOptions, 'prefix'>, id?: number, save?: boolean): number;
76
+ /**
77
+ * Resubscribes all local subscribers.
78
+ * @param client - The client to resubscribe with.
79
+ */
80
+ abstract resubscribeAll(client: PubSubClient): void;
81
+ /**
82
+ * Removes a subscriber
83
+ * @param subuid - The UID of the subscriber.
84
+ * @param removeCallback - Whether to remove the callback. Leave this as true unless you know what you're doing.
85
+ */
86
+ unsubscribe(subuid: number, removeCallback?: boolean): void;
87
+ /**
88
+ * Removes all local subscribers.
89
+ */
90
+ unsubscribeAll(): void;
91
+ /**
92
+ * Strips client-only subscribe options (e.g. `immediateNotify`) before sending to the NT server.
93
+ * @param options - The subscriber options, possibly including client-only fields.
94
+ * @returns Protocol subscribe options.
95
+ */
96
+ protected toProtocolSubscribeOptions(options?: Omit<SubscribeOptions, 'prefix'>): Omit<SubscribeOptions, 'prefix' | 'immediateNotify'>;
97
+ /**
98
+ * Sets the properties of the topic.
99
+ * @param properties - Topic properties to update (e.g. `{ persistent: true, retained: true }`).
100
+ * @returns The server's response.
101
+ */
102
+ setProperties(properties?: TopicProperties): Promise<PropertiesMessage>;
103
+ }
104
+ //# sourceMappingURL=base-topic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-topic.d.ts","sourceRoot":"","sources":["../../../src/lib/pubsub/base-topic.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EAEjB,gBAAgB,EAChB,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,UAAU,CAAC,CAAC,IAA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AAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,EAC1C,EAAE,CAAC,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,OAAO,GACb,MAAM;IAET;;;OAGG;IACH,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAEnD;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,UAAO;IAWjD;;OAEG;IACH,cAAc;IAMd;;;;OAIG;IACH,SAAS,CAAC,0BAA0B,CAClC,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAM,GAC7C,IAAI,CAAC,gBAAgB,EAAE,QAAQ,GAAG,iBAAiB,CAAC;IAUvD;;;;OAIG;IACG,aAAa,CAAC,UAAU,GAAE,eAAoB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CASlF"}
@@ -0,0 +1,6 @@
1
+ export * from './prefix-topic';
2
+ export * from './topic';
3
+ export * from './struct-topic';
4
+ export * from './protobuf-topic';
5
+ export * from './json-topic';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/pubsub/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { NetworkTablesTopic } from './topic';
2
+ import type { PubSubClient } from './pubsub';
3
+ import type { z } from 'zod';
4
+ /** Options for {@link NetworkTablesJsonTopic} and `getJsonTopic`. */
5
+ export interface JsonTopicOptions<T extends object> {
6
+ validator?: z.ZodType<T>;
7
+ }
8
+ /**
9
+ * JSON topic: public value is a parsed object; wire format is a JSON string with type `'json'`.
10
+ */
11
+ export declare class NetworkTablesJsonTopic<T extends object> extends NetworkTablesTopic<string, T> {
12
+ private decodedValue;
13
+ private _validator?;
14
+ /**
15
+ * Creates a new JSON topic.
16
+ * @param client - The client that owns the topic.
17
+ * @param name - The name of the topic.
18
+ * @param defaultValue - The default public value of the topic.
19
+ * @param options - Optional runtime validator for parsed JSON.
20
+ */
21
+ constructor(client: PubSubClient, name: string, defaultValue?: T, options?: JsonTopicOptions<T>);
22
+ /**
23
+ * Applies options to this topic. Used when returning a cached topic from getJsonTopic.
24
+ * A later defaultValue is ignored once a value exists (matches createTopic).
25
+ * A later `validator` replaces any previous validator because the topic is a singleton.
26
+ * @param options - The options to apply.
27
+ */
28
+ applyOptions(options?: {
29
+ defaultValue?: T;
30
+ } & JsonTopicOptions<T>): void;
31
+ private maybeValidate;
32
+ /**
33
+ * Gets the parsed JSON value of the topic.
34
+ * @returns The parsed JSON object, or null if no value has been set.
35
+ */
36
+ getValue(): T | null;
37
+ /**
38
+ * Sets the JSON value of the topic. The value is serialized with JSON.stringify for the wire.
39
+ * @param value - The object to publish.
40
+ */
41
+ setValue(value: T): void;
42
+ /**
43
+ * Updates the value of the topic from the wire JSON string.
44
+ * This should only be called by the PubSubClient.
45
+ * @param value - The wire-format JSON string.
46
+ * @param lastChangedTime - The server time of the last value change.
47
+ */
48
+ updateValue(value: string, lastChangedTime: number): void;
49
+ }
50
+ //# sourceMappingURL=json-topic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-topic.d.ts","sourceRoot":"","sources":["../../../src/lib/pubsub/json-topic.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,qEAAqE;AACrE,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM;IAChD,SAAS,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;CAC1B;AAED;;GAEG;AACH,qBAAa,sBAAsB,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAC;IACzF,OAAO,CAAC,YAAY,CAAY;IAChC,OAAO,CAAC,UAAU,CAAC,CAAe;IAElC;;;;;;OAMG;gBACS,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAQ/F;;;;;OAKG;IACH,YAAY,CAAC,OAAO,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,CAAC,CAAA;KAAE,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI;IASxE,OAAO,CAAC,aAAa;IAIrB;;;OAGG;IACM,QAAQ,IAAI,CAAC,GAAG,IAAI;IAI7B;;;OAGG;IACM,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAYjC;;;;;OAKG;IACM,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,IAAI;CAQnE"}
@@ -0,0 +1,45 @@
1
+ import { NetworkTablesBaseTopic } from './base-topic';
2
+ import type { CallbackFn } from './base-topic';
3
+ import type { PubSubClient } from './pubsub';
4
+ import type { AnnounceMessageParams, NetworkTablesTypes, SubscribeOptions } from '../types/types';
5
+ export declare class NetworkTablesPrefixTopic extends NetworkTablesBaseTopic<NetworkTablesTypes> {
6
+ readonly type = "prefix";
7
+ private readonly _lastSubtopicValues;
8
+ /**
9
+ * Creates a new topic. This should only be done after the
10
+ * base NTCore client has been initialized.
11
+ * @param client - The client that owns the topic.
12
+ * @param name - The name of the topic.
13
+ */
14
+ constructor(client: PubSubClient, name: string);
15
+ /** */
16
+ /** */
17
+ /**
18
+ * Creates a new subscriber.
19
+ * @param callback - The callback to call when the topic value changes.
20
+ * @param options - The options for the subscriber. `immediateNotify` is client-side only
21
+ * and replays cached matching subtopic values (not sent to the NT server).
22
+ * @returns The UID of the subscriber.
23
+ */
24
+ subscribe(callback: CallbackFn<NetworkTablesTypes>, options?: Omit<SubscribeOptions, 'prefix'>): number;
25
+ /**
26
+ * Creates a new subscriber, optionally reusing a subscription UID.
27
+ * @internal Used by resubscribeAll. Does not honor `immediateNotify`.
28
+ * @param callback - The callback to call when the topic value changes.
29
+ * @param options - The options for the subscriber.
30
+ * @param id - The UID of the subscriber.
31
+ * @param save - Whether to save the subscriber.
32
+ * @returns The UID of the subscriber.
33
+ */
34
+ protected subscribeWithId(callback: CallbackFn<NetworkTablesTypes>, options?: Omit<SubscribeOptions, 'prefix'>, id?: number, save?: boolean): number;
35
+ resubscribeAll(client: PubSubClient): void;
36
+ /**
37
+ * Updates the value of a subtopic. Notifies all subscribers of the change.
38
+ * @param params - The params of the subtopic
39
+ * @param value - The value of the subtopic
40
+ * @param serverTime - The time the value was updated
41
+ */
42
+ updateValue(params: AnnounceMessageParams, value: NetworkTablesTypes | null, serverTime: number): void;
43
+ private notifySubscribers;
44
+ }
45
+ //# sourceMappingURL=prefix-topic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefix-topic.d.ts","sourceRoot":"","sources":["../../../src/lib/pubsub/prefix-topic.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAElB,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AAExB,qBAAa,wBAAyB,SAAQ,sBAAsB,CAAC,kBAAkB,CAAC;IACtF,QAAQ,CAAC,IAAI,YAAY;IACzB,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAGhC;IAEJ;;;;;OAKG;gBACS,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM;IAa9C,MAAM;IAEN,MAAM;IAEN;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,kBAAkB,CAAC,EAAE,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAM;IAmBlG;;;;;;;;OAQG;IACH,SAAS,CAAC,eAAe,CACvB,QAAQ,EAAE,UAAU,CAAC,kBAAkB,CAAC,EACxC,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAM,EAC9C,EAAE,CAAC,EAAE,MAAM,EACX,IAAI,UAAO;IA0Bb,cAAc,CAAC,MAAM,EAAE,YAAY;IASnC;;;;;OAKG;IACH,WAAW,CAAC,MAAM,EAAE,qBAAqB,EAAE,KAAK,EAAE,kBAAkB,GAAG,IAAI,EAAE,UAAU,EAAE,MAAM;IAgB/F,OAAO,CAAC,iBAAiB;CA2B1B"}
@@ -0,0 +1,96 @@
1
+ import 'protobufjs/ext/descriptor/index.js';
2
+ import type { PubSubClient } from './pubsub';
3
+ /**
4
+ * Manages protobuf schema fetching and caching from NetworkTables.
5
+ * Schemas are automatically cached from `/.schema/proto:*` topics using a prefix subscription.
6
+ */
7
+ export declare class ProtobufSchemaManager {
8
+ private readonly schemaCache;
9
+ private readonly registeredSchemas;
10
+ private readonly schemaPrefixTopic;
11
+ private readonly client;
12
+ private fileDescriptorProtoType;
13
+ constructor(client: PubSubClient);
14
+ /**
15
+ * Handles schema updates from the prefix topic subscription.
16
+ * Automatically decodes and caches all schema files that arrive.
17
+ * @param value - The value of the schema update (null when a topic is unannounced).
18
+ * @param params - The parameters of the announce message.
19
+ */
20
+ private handleSchemaUpdate;
21
+ /**
22
+ * Fetches a protobuf message type from the cache.
23
+ * Searches all loaded schemas in the cache to find one containing the requested message type.
24
+ * Returns null if the schema is not yet in cache (e.g. topic announced before schema topic arrived).
25
+ * @param messageName - The name of the protobuf message type (e.g., "frc.Pose2d").
26
+ * @returns The protobufjs Type, or null if not found in cache.
27
+ */
28
+ fetchMessageType(messageName: string): protobuf.Type | null;
29
+ /**
30
+ * Clears the schema cache.
31
+ */
32
+ clearCache(): void;
33
+ /**
34
+ * Gets the message name from a protobuf root.
35
+ * Auto-detects the first message type in the proto file.
36
+ * @param root - The protobuf root containing the schema.
37
+ * @returns The message name in format "package.MessageName" or "MessageName" if no package (no leading dot).
38
+ */
39
+ getMessageNameFromProto(root: protobuf.Namespace): string;
40
+ /**
41
+ * Recursively finds the first message type in a namespace.
42
+ * @param namespace - The namespace to search.
43
+ * @returns The first message type found, or null.
44
+ */
45
+ private findFirstMessage;
46
+ /**
47
+ * Registers a protobuf schema by loading a proto file and publishing it to NetworkTables.
48
+ * Node.js only — uses the filesystem. In the browser, use {@link registerSchemaFromSource} or
49
+ * {@link registerSchemaFromType} instead.
50
+ * @param protoFilePath - Path to the .proto file.
51
+ * @param messageName - Optional message name to use. If not provided, auto-detected from proto file.
52
+ * @returns A promise that resolves to the message name and schema root.
53
+ * @throws {Error} If called in a browser, or if the proto file cannot be loaded or schema cannot be registered.
54
+ */
55
+ registerSchema(protoFilePath: string, messageName?: string): Promise<{
56
+ messageName: string;
57
+ root: protobuf.Namespace;
58
+ }>;
59
+ /**
60
+ * Parses a `.proto` source string without publishing (no filesystem).
61
+ * @param protoSource - The contents of a .proto file.
62
+ * @returns The detected message name and resolved root.
63
+ */
64
+ parseSource(protoSource: string): {
65
+ messageName: string;
66
+ root: protobuf.Root;
67
+ };
68
+ registerSchemaFromSource(protoSource: string, filename?: string, messageName?: string): Promise<{
69
+ messageName: string;
70
+ root: protobuf.Namespace;
71
+ }>;
72
+ /**
73
+ * Registers a protobuf schema from a prebuilt protobufjs Type (no filesystem). Safe in the browser.
74
+ * @param messageType - A protobufjs Type used for encode/decode.
75
+ * @param filename - Optional filename used for the schema topic (defaults to the message name).
76
+ * @returns A promise that resolves to the message name and schema root.
77
+ */
78
+ registerSchemaFromType(messageType: protobuf.Type, filename?: string): Promise<{
79
+ messageName: string;
80
+ root: protobuf.Namespace;
81
+ }>;
82
+ /**
83
+ * Loads a root then publishes it, sharing in-flight protection by schema topic name.
84
+ */
85
+ private registerRootFromLoader;
86
+ /**
87
+ * Publishes an already-parsed root, sharing in-flight protection by schema topic name.
88
+ */
89
+ private publishRoot;
90
+ /**
91
+ * Encodes a FileDescriptorProto from a root, publishes the schema topic, and caches it.
92
+ * Must be called inside an in-flight operation.
93
+ */
94
+ private publishLoadedRoot;
95
+ }
96
+ //# sourceMappingURL=protobuf-schema-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protobuf-schema-manager.d.ts","sourceRoot":"","sources":["../../../src/lib/pubsub/protobuf-schema-manager.ts"],"names":[],"mappings":"AAEA,OAAO,oCAAoC,CAAC;AAkB5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAgB7C;;;GAGG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA8C;IAC1E,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA0B;IAC5D,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA2B;IAC7D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,uBAAuB,CAE7B;gBAEU,MAAM,EAAE,YAAY;IAWhC;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IA2B1B;;;;;;OAMG;IACH,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC,IAAI,GAAG,IAAI;IAc3D;;OAEG;IACH,UAAU;IAIV;;;;;OAKG;IACH,uBAAuB,CAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,GAAG,MAAM;IA4BzD;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAexB;;;;;;;;OAQG;IACG,cAAc,CAClB,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAA;KAAE,CAAC;IAqB7D;;;;OAIG;IACH,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAA;KAAE;IAaxE,wBAAwB,CAC5B,WAAW,EAAE,MAAM,EACnB,QAAQ,CAAC,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAA;KAAE,CAAC;IAO7D;;;;;OAKG;IACG,sBAAsB,CAC1B,WAAW,EAAE,QAAQ,CAAC,IAAI,EAC1B,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAA;KAAE,CAAC;IAO7D;;OAEG;YACW,sBAAsB;IAsBpC;;OAEG;YACW,WAAW;IAoBzB;;;OAGG;YACW,iBAAiB;CAgDhC"}
@@ -0,0 +1,126 @@
1
+ import { type AnnounceMessage, type AnnounceMessageParams, type TopicProperties } from '../types/types';
2
+ import { NetworkTablesTopic } from './topic';
3
+ import type { PubSubClient } from './pubsub';
4
+ import type { Type } from 'protobufjs';
5
+ import type { z } from 'zod';
6
+ /** Options for creating a protobuf topic. */
7
+ export interface ProtobufTopicOptions<T extends object> {
8
+ defaultValue?: T;
9
+ validator?: z.ZodType<T>;
10
+ /** Path to a .proto file. Node.js only (uses the filesystem). */
11
+ protoFilePath?: string;
12
+ /** Contents of a .proto file. Parsed in-memory; safe in the browser. */
13
+ protoSource?: string;
14
+ /** Prebuilt protobufjs Type. Safe in the browser. */
15
+ messageType?: Type;
16
+ }
17
+ export declare class NetworkTablesProtobufTopic<T extends object> extends NetworkTablesTopic<Uint8Array<ArrayBufferLike>, T> {
18
+ private decodedValue;
19
+ private _protobufMessageName?;
20
+ private _protobufMessageType;
21
+ private _validator?;
22
+ private _protoFilePath?;
23
+ private _protoSource?;
24
+ private _providedMessageType?;
25
+ private _messageTypeString?;
26
+ private _schemaRegistered;
27
+ /** Stored error when constructor's fire-and-forget loadProtoSchema fails; re-thrown by ensureMessageType. */
28
+ private _schemaLoadError;
29
+ /**
30
+ * Creates a new topic. This should only be done after the
31
+ * base NTCore client has been initialized.
32
+ * @param client - The client that owns the topic.
33
+ * @param name - The name of the topic.
34
+ * @param options - The options for the topic.
35
+ * @param options.defaultValue
36
+ * @param options.validator
37
+ * @param options.protoFilePath - Node.js only. Use protoSource or messageType in the browser.
38
+ * @param options.protoSource - In-memory .proto text. Safe in the browser.
39
+ * @param options.messageType - Prebuilt protobufjs Type. Safe in the browser.
40
+ */
41
+ constructor(client: PubSubClient, name: string, options?: ProtobufTopicOptions<T>);
42
+ /**
43
+ * Applies options to an existing protobuf topic.
44
+ * Used when returning a cached topic from getProtobufTopic so the returned
45
+ * instance has the requested validator, protoFilePath, and defaultValue.
46
+ * A later `validator` replaces any previous validator because the topic is a singleton.
47
+ * @param options - The options to apply.
48
+ */
49
+ applyOptions(options?: ProtobufTopicOptions<T>): void;
50
+ private normalizeMessageName;
51
+ private assertMessageTypeUnchanged;
52
+ /**
53
+ * Gets the value of the topic.
54
+ * @returns The value of the topic.
55
+ */
56
+ getValue(): T | null;
57
+ setValue(value: T): void;
58
+ /**
59
+ * Ensures the protobuf message type is available, fetching it if necessary.
60
+ * @returns The protobuf message type.
61
+ * @throws {Error} If schema loading failed in the constructor (protoFilePath), re-throws that error.
62
+ * @throws {Error} If the protobuf message type cannot be found in the schema cache.
63
+ */
64
+ private ensureMessageType;
65
+ /**
66
+ * Decodes a protobuf-encoded value to a typed object.
67
+ * @param value - The protobuf-encoded Uint8Array value.
68
+ * @returns The decoded protobuf object.
69
+ * @throws {Error} If the protobuf message type is not found in the schema cache.
70
+ * This can occur if decoding is attempted before the schema has been
71
+ * fetched from NetworkTables (e.g., value update arrives before
72
+ * announcement is processed or schema topic is received).
73
+ */
74
+ private decodeValue;
75
+ /**
76
+ * Encodes a typed object to a protobuf-encoded Uint8Array.
77
+ * @param value - The typed object to encode.
78
+ * @returns The protobuf-encoded Uint8Array.
79
+ * @throws {Error} If the protobuf message type is not found in the schema cache.
80
+ * This can occur if encoding is attempted before the schema has been
81
+ * loaded (e.g., setValue called before protoFilePath schema is loaded
82
+ * or before the topic announcement provides the message type).
83
+ */
84
+ private encodeValue;
85
+ /**
86
+ * Updates the value of the topic.
87
+ * This should only be called by the PubSubClient.
88
+ * @param value - The value to update.
89
+ * @param lastChangedTime - The server time of the last value change.
90
+ */
91
+ updateValue(value: Uint8Array<ArrayBufferLike>, lastChangedTime: number): void;
92
+ /**
93
+ * Marks the topic as announced. This should only be called by the PubSubClient.
94
+ * @param params - The parameters of the announcement.
95
+ */
96
+ announce(params: AnnounceMessageParams): void;
97
+ /**
98
+ * Fetches the protobuf schema for this topic.
99
+ * @param messageName - The protobuf message name.
100
+ */
101
+ private fetchProtobufSchema;
102
+ /**
103
+ * Loads a proto schema from a file path (Node.js only).
104
+ * @param protoFilePath - Path to the .proto file.
105
+ */
106
+ private loadProtoSchema;
107
+ /**
108
+ * Loads a proto schema from an in-memory source string.
109
+ * @param protoSource - Contents of a .proto file.
110
+ */
111
+ private loadProtoSource;
112
+ /**
113
+ * Applies a prebuilt protobufjs Type for encode/decode.
114
+ * @param messageType - The protobufjs Type.
115
+ */
116
+ private applyMessageType;
117
+ /**
118
+ * Publishes the topic.
119
+ * If a proto file path was provided, registers the schema first.
120
+ * @param properties - The properties to publish the topic with.
121
+ * @param id - The UID of the publisher. You must verify that the ID is not already in use.
122
+ * @returns A promise that resolves when the topic is published.
123
+ */
124
+ publish(properties?: TopicProperties, id?: number): Promise<AnnounceMessage | void>;
125
+ }
126
+ //# sourceMappingURL=protobuf-topic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protobuf-topic.d.ts","sourceRoot":"","sources":["../../../src/lib/pubsub/protobuf-topic.ts"],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AAE,oBAAoB,CAAC,CAAC,CAAC;IA4CjF;;;;;;OAMG;IACH,YAAY,CAAC,OAAO,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,IAAI;IAiDrD,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,0BAA0B;IAQlC;;;OAGG;IACM,QAAQ,IAAI,CAAC,GAAG,IAAI;IAIpB,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAajC;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAgBzB;;;;;;;;OAQG;IACH,OAAO,CAAC,WAAW;IAcnB;;;;;;;;OAQG;IACH,OAAO,CAAC,WAAW;IAMnB;;;;;OAKG;IACM,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,eAAe,CAAC,EAAE,eAAe,EAAE,MAAM;IAShF;;;OAGG;IACM,QAAQ,CAAC,MAAM,EAAE,qBAAqB;IA2B/C;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAO3B;;;OAGG;YACW,eAAe;IAgB7B;;;OAGG;YACW,eAAe;IAY7B;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAgBxB;;;;;;OAMG;IACY,OAAO,CAAC,UAAU,GAAE,eAAoB,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;CAkDvG"}
@@ -0,0 +1,134 @@
1
+ import { Messenger } from '../socket/messenger';
2
+ import { type AnnounceMessageParams, type NetworkTablesTypes } from '../types/types';
3
+ import { ProtobufSchemaManager } from './protobuf-schema-manager';
4
+ import { StructSchemaManager } from '../struct/struct-schema-manager';
5
+ import type { NetworkTablesBaseTopic } from './base-topic';
6
+ import type { NetworkTablesPrefixTopic } from './prefix-topic';
7
+ import type { NetworkTablesTopic } from './topic';
8
+ /** The client for the PubSub protocol. */
9
+ export declare class PubSubClient {
10
+ private readonly _messenger;
11
+ private readonly topics;
12
+ private readonly prefixTopics;
13
+ private readonly knownTopicParams;
14
+ /** Value updates that arrived before the topic announcement (topicId -> latest message). Flushed when announce arrives. */
15
+ private readonly pendingValueUpdates;
16
+ private readonly _protobufSchemaManager;
17
+ private readonly _structSchemaManager;
18
+ private static _instances;
19
+ private readonly inFlightOperations;
20
+ private _isCleaningUp;
21
+ private readonly beforeUnloadHandler;
22
+ get messenger(): Messenger;
23
+ get protobufSchemaManager(): ProtobufSchemaManager;
24
+ get structSchemaManager(): StructSchemaManager;
25
+ private constructor();
26
+ /**
27
+ * Gets the instance of the NetworkTables client.
28
+ * @param serverUrl - The URL of the server to connect to. This is not used after the first call.
29
+ * @returns The instance of the NetworkTables client.
30
+ */
31
+ static getInstance(serverUrl: string): PubSubClient;
32
+ /**
33
+ * Reinstantiates the client by resubscribing to all previously subscribed topics
34
+ * and republishing for all previously published topics.
35
+ * @param url - The URL of the server to connect to.
36
+ */
37
+ reinstantiate(url: string): void;
38
+ /**
39
+ * Registers a topic with this PubSubClient.
40
+ * @param topic - The topic to register
41
+ */
42
+ registerTopic<T>(topic: NetworkTablesBaseTopic<T>): void;
43
+ /**
44
+ * Called by the messenger when a topic is updated.
45
+ * @param message - The message data.
46
+ */
47
+ private onTopicUpdate;
48
+ /**
49
+ * Called by the messenger when a topic is announced.
50
+ * @param params - The announce message parameters.
51
+ */
52
+ private onTopicAnnounce;
53
+ /**
54
+ * Delivers a value update to the regular topic (if any) and all matching prefix topics.
55
+ */
56
+ private _deliverValueUpdate;
57
+ /**
58
+ * Called by the messenger when a topic is unannounced.
59
+ * @param params - The unannounce message parameters.
60
+ */
61
+ private onTopicUnannounce;
62
+ /**
63
+ * Called by the messenger when a topic's properties are updated.
64
+ * @param params - The properties message parameters.
65
+ */
66
+ private onTopicProperties;
67
+ /**
68
+ * Updates the value of a topic on the server.
69
+ * @param topic - The topic to update.
70
+ * @param value - The new value (wire format) to send.
71
+ */
72
+ updateServer<TWire extends NetworkTablesTypes, TPublic = TWire>(topic: NetworkTablesTopic<TWire, TPublic>, value: TWire): void;
73
+ /**
74
+ * Notifies all prefix topics that match the given topic name of a local value update.
75
+ * Called when a regular/protobuf topic's setValue() runs so prefix subscribers (e.g. "all topics" table) see locally published values.
76
+ */
77
+ notifyPrefixTopicsForLocalUpdate(params: AnnounceMessageParams, value: NetworkTablesTypes): void;
78
+ /**
79
+ * Gets the topic with the given ID.
80
+ * @param topicId - The ID of the topic to get.
81
+ * @returns The topic with the given ID, or null if no topic with that ID exists.
82
+ */
83
+ private getTopicFromId;
84
+ /**
85
+ * Gets the topic with the given name.
86
+ * @param topicName - The name of the topic to get.
87
+ * @returns The topic with the given name, or null if no topic with that name exists.
88
+ */
89
+ getTopicFromName<T extends NetworkTablesTypes>(topicName: string): NetworkTablesTopic<T> | null;
90
+ /**
91
+ * Gets the topic with the given name.
92
+ * @param topicName - The name of the topic to get.
93
+ * @returns The topic with the given name, or null if no topic with that name exists.
94
+ */
95
+ getPrefixTopicFromName(topicName: string): NetworkTablesPrefixTopic | null;
96
+ /**
97
+ * Gets the known announcement parameters for a topic.
98
+ * @param id - The ID of the topic.
99
+ * @returns The known announcement parameters for the topic, or undefined if the topic is not known.
100
+ */
101
+ getKnownTopicParams(id: number): {
102
+ name: string;
103
+ id: number;
104
+ type: string;
105
+ properties: {
106
+ persistent?: boolean | undefined;
107
+ retained?: boolean | undefined;
108
+ cached?: boolean | undefined;
109
+ };
110
+ pubuid?: number | undefined;
111
+ } | undefined;
112
+ /**
113
+ * Gets or creates an in-flight operation to prevent race conditions.
114
+ * If an operation with the same key is already in progress, returns the existing promise.
115
+ * Otherwise, creates a new operation and stores it.
116
+ * @param key - Unique key for the operation (e.g., "schema:/.schema/proto:filename" or "publish:/topic/name")
117
+ * @param operation - The async operation to execute
118
+ * @returns A promise that resolves to the operation result
119
+ * @throws Error if the client is cleaning up and no existing operation is found
120
+ */
121
+ getOrCreateInFlightOperation<T>(key: string, operation: () => Promise<T>): Promise<T>;
122
+ /**
123
+ * Cleans up the client by unsubscribing from all topics and stopping publishing for all topics.
124
+ * Prevents new in-flight operations from starting, but allows existing ones to complete naturally.
125
+ * The socket is closed immediately, which will cause any in-flight operations to fail.
126
+ */
127
+ cleanup(): void;
128
+ /**
129
+ * Removes this client, its messenger, and its socket from their singleton maps.
130
+ * Call after {@link cleanup} so a later getInstance creates a fresh client.
131
+ */
132
+ releaseInstance(): void;
133
+ }
134
+ //# sourceMappingURL=pubsub.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pubsub.d.ts","sourceRoot":"","sources":["../../../src/lib/pubsub/pubsub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAEL,KAAK,qBAAqB,EAE1B,KAAK,kBAAkB,EAGxB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,0CAA0C;AAC1C,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsD;IAC7E,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAwC;IAErE,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAqC;IACtE,2HAA2H;IAC3H,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAiC;IACrE,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAwB;IAC/D,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAsB;IAC3D,OAAO,CAAC,MAAM,CAAC,UAAU,CAAmC;IAE5D,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAuC;IAC1E,OAAO,CAAC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M,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IA6BrF;;;;OAIG;IACH,OAAO;IAmCP;;;OAGG;IACH,eAAe,IAAI,IAAI;CAQxB"}
@@ -0,0 +1,40 @@
1
+ import { type AnnounceMessage, type AnnounceMessageParams, type TopicProperties } from '../types/types';
2
+ import { NetworkTablesTopic } from './topic';
3
+ import type { PubSubClient } from './pubsub';
4
+ import type { z } from 'zod';
5
+ export declare class NetworkTablesStructTopic<T extends object | object[]> extends NetworkTablesTopic<Uint8Array, T> {
6
+ private decodedValue;
7
+ private _typeName;
8
+ private _isArray;
9
+ private _validator?;
10
+ private _descriptor;
11
+ /** When schema option build fails (e.g. nested not yet available), store and retry in ensureDescriptor. */
12
+ private _pendingSchema;
13
+ constructor(client: PubSubClient, name: string, options?: {
14
+ typeName?: string;
15
+ schema?: string;
16
+ defaultValue?: T;
17
+ validator?: z.ZodType<T>;
18
+ });
19
+ /**
20
+ * Applies options to this topic. Used when returning a cached topic from getStructTopic.
21
+ * A later `validator` replaces any previous validator because the topic is a singleton.
22
+ * @param options - The options to apply.
23
+ */
24
+ applyOptions(options?: {
25
+ typeName?: string;
26
+ schema?: string;
27
+ defaultValue?: T;
28
+ validator?: z.ZodType<T>;
29
+ }): void;
30
+ private ensureDescriptor;
31
+ private maybeValidate;
32
+ getValue(): T | null;
33
+ setValue(value: T): void;
34
+ private decodeValue;
35
+ private encodeValue;
36
+ updateValue(value: Uint8Array, lastChangedTime: number): void;
37
+ announce(params: AnnounceMessageParams): void;
38
+ publish(properties?: TopicProperties, id?: number): Promise<AnnounceMessage | void>;
39
+ }
40
+ //# sourceMappingURL=struct-topic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"struct-topic.d.ts","sourceRoot":"","sources":["../../../src/lib/pubsub/struct-topic.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAE1B,KAAK,eAAe,EACrB,MAAM,gBAA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