@net-mesh/sdk 0.19.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.
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Identity + Token surface — ed25519 keypair, signed permission
3
+ * tokens, and a local token cache. Pure compute; the network-side
4
+ * wiring (mesh auth on `subscribeChannel`) lands in a later stage.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { Identity, TokenScope } from '@net-mesh/sdk';
9
+ *
10
+ * // Generate once, persist the bytes, reload on subsequent runs.
11
+ * const id = Identity.generate();
12
+ * const seed = id.toBytes();
13
+ * const reloaded = Identity.fromBytes(seed);
14
+ *
15
+ * // Issue a subscribe grant.
16
+ * const subscriber = Identity.generate();
17
+ * const token = id.issueToken({
18
+ * subject: subscriber.entityId,
19
+ * scope: ['subscribe'],
20
+ * channel: 'sensors/temp',
21
+ * ttlSeconds: 300,
22
+ * });
23
+ *
24
+ * // Subscriber installs; signature is verified at install time.
25
+ * subscriber.installToken(token);
26
+ * ```
27
+ */
28
+ import { Identity as NapiIdentity } from '@net-mesh/core';
29
+ /** Discrete permissions a token can authorize. */
30
+ export type TokenScope = 'publish' | 'subscribe' | 'admin' | 'delegate';
31
+ /**
32
+ * Base class for identity-layer errors (malformed seed / subject /
33
+ * channel name). Not thrown for token-validity issues — those are
34
+ * `TokenError`.
35
+ */
36
+ export declare class IdentityError extends Error {
37
+ constructor(message: string);
38
+ }
39
+ /**
40
+ * Token-layer error. `kind` is a stable discriminator for programmatic
41
+ * dispatch (`if (e.kind === 'expired')`) that doesn't rely on the
42
+ * message string.
43
+ */
44
+ export type TokenErrorKind = 'invalid_signature' | 'not_yet_valid' | 'expired' | 'delegation_exhausted' | 'delegation_not_allowed' | 'not_authorized' | 'invalid_format';
45
+ export declare class TokenError extends Error {
46
+ readonly kind: TokenErrorKind;
47
+ constructor(kind: TokenErrorKind, message?: string);
48
+ }
49
+ /**
50
+ * A signed, delegatable permission token. Construct via
51
+ * `Identity.issueToken` (locally) or `Token.parse` (from wire bytes).
52
+ *
53
+ * The wire form is 169 bytes: issuer (32) + subject (32) + scope (4)
54
+ * + channel hash (8, canonical 64-bit) + issuer generation (4) +
55
+ * not-before (8) + not-after (8) + delegation depth (1) + nonce (8)
56
+ * + ed25519 signature (64). Matches `PermissionToken::WIRE_SIZE` in
57
+ * the Rust core.
58
+ */
59
+ export declare class Token {
60
+ /** Raw serialized bytes. Safe to send over the wire. */
61
+ readonly bytes: Buffer;
62
+ readonly issuer: Buffer;
63
+ readonly subject: Buffer;
64
+ readonly scope: ReadonlySet<TokenScope>;
65
+ /**
66
+ * Canonical 64-bit hash of the channel name this token authorizes
67
+ * (combine with `wildcard` scope for cross-channel grants). Compare
68
+ * against `channelHash(name)` to check whether a token applies to a
69
+ * named channel.
70
+ */
71
+ readonly channelHash: bigint;
72
+ readonly notBefore: Date;
73
+ readonly notAfter: Date;
74
+ readonly delegationDepth: number;
75
+ readonly nonce: bigint;
76
+ private constructor();
77
+ /** Parse a serialized token. Throws `TokenError { kind: 'invalid_format' }` on bad bytes. */
78
+ static parse(bytes: Buffer): Token;
79
+ /** Verify the ed25519 signature. Does NOT check time bounds — use `isExpired()` for that. */
80
+ verify(): boolean;
81
+ /** `true` if the token's `notAfter` has passed. */
82
+ isExpired(): boolean;
83
+ /** Same instance — provided so callers can treat `Token` as a union with the serialized buffer. */
84
+ toBuffer(): Buffer;
85
+ }
86
+ /** Options for `Identity.issueToken`. */
87
+ export interface IssueTokenOptions {
88
+ /** 32-byte entity id of the grantee. */
89
+ subject: Buffer;
90
+ /** Scopes granted; union of `'publish' | 'subscribe' | 'admin' | 'delegate'`. */
91
+ scope: readonly TokenScope[];
92
+ /** Channel name. Hashed to u64 canonical; the wire-side fast-path
93
+ * hint is the low 16 bits of that hash. */
94
+ channel: string;
95
+ /** Validity window in seconds. Pick a short TTL + re-issue instead of building a revocation list. */
96
+ ttlSeconds: number;
97
+ /** How many times the grantee can re-delegate. Default 0 (forbidden). */
98
+ delegationDepth?: number;
99
+ }
100
+ /**
101
+ * Caller-owned identity bundle. Cheap to carry around; token cache
102
+ * entries are runtime-only and don't serialize.
103
+ */
104
+ export declare class Identity {
105
+ private readonly inner;
106
+ private constructor();
107
+ /** Generate a fresh ed25519 identity. Persist via `toBytes()` to keep `nodeId` stable across restarts. */
108
+ static generate(): Identity;
109
+ /** Load from a caller-owned 32-byte ed25519 seed. */
110
+ static fromSeed(seed: Buffer): Identity;
111
+ /** Alias for `fromSeed` — the persisted form IS the 32-byte seed. */
112
+ static fromBytes(bytes: Buffer): Identity;
113
+ /** Wrap an existing NAPI `Identity` handle — escape hatch for builder code. */
114
+ static fromNapi(inner: NapiIdentity): Identity;
115
+ /** The underlying NAPI handle. Used by the mesh builder to bind this identity to a `MeshNode`. */
116
+ toNapi(): NapiIdentity;
117
+ /** Serialize as the 32-byte ed25519 seed. Treat as secret material. */
118
+ toBytes(): Buffer;
119
+ /** Ed25519 public key. 32 bytes. */
120
+ get entityId(): Buffer;
121
+ /** Derived 64-bit origin hash used in packet headers. */
122
+ get originHash(): bigint;
123
+ /** Derived 64-bit node id used for routing / addressing. */
124
+ get nodeId(): bigint;
125
+ /** Sign arbitrary bytes. Returns 64-byte ed25519 signature. */
126
+ sign(message: Buffer): Buffer;
127
+ /** Issue a scoped token to another entity. */
128
+ issueToken(opts: IssueTokenOptions): Token;
129
+ /** Install a token this node received. Throws `TokenError` on bad signature or malformed bytes. */
130
+ installToken(token: Token | Buffer): void;
131
+ /** Look up a cached token. Returns `null` when no exact-channel entry is cached. */
132
+ lookupToken(subject: Buffer, channel: string): Token | null;
133
+ /** Number of cached tokens. Testing aid. */
134
+ get tokenCacheLen(): number;
135
+ }
136
+ /**
137
+ * Hash a channel name to its canonical 64-bit substrate identifier.
138
+ * Compare against `token.channelHash` to check whether a token
139
+ * applies to a named channel without trial-decoding. The per-packet
140
+ * wire `NetHeader` fast-path hint is the low 16 bits of this value.
141
+ */
142
+ export declare function channelHash(channel: string): bigint;
143
+ /**
144
+ * Delegate a token to a new subject. The parent token must include
145
+ * `'delegate'` in its scope and have `delegationDepth > 0`; the
146
+ * signer must be the subject of the parent token. `restrictedScope`
147
+ * is intersected with the parent's scope.
148
+ */
149
+ export declare function delegateToken(signer: Identity, parent: Token | Buffer, newSubject: Buffer, restrictedScope: readonly TokenScope[]): Token;
@@ -0,0 +1,264 @@
1
+ "use strict";
2
+ /**
3
+ * Identity + Token surface — ed25519 keypair, signed permission
4
+ * tokens, and a local token cache. Pure compute; the network-side
5
+ * wiring (mesh auth on `subscribeChannel`) lands in a later stage.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { Identity, TokenScope } from '@net-mesh/sdk';
10
+ *
11
+ * // Generate once, persist the bytes, reload on subsequent runs.
12
+ * const id = Identity.generate();
13
+ * const seed = id.toBytes();
14
+ * const reloaded = Identity.fromBytes(seed);
15
+ *
16
+ * // Issue a subscribe grant.
17
+ * const subscriber = Identity.generate();
18
+ * const token = id.issueToken({
19
+ * subject: subscriber.entityId,
20
+ * scope: ['subscribe'],
21
+ * channel: 'sensors/temp',
22
+ * ttlSeconds: 300,
23
+ * });
24
+ *
25
+ * // Subscriber installs; signature is verified at install time.
26
+ * subscriber.installToken(token);
27
+ * ```
28
+ */
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.Identity = exports.Token = exports.TokenError = exports.IdentityError = void 0;
31
+ exports.channelHash = channelHash;
32
+ exports.delegateToken = delegateToken;
33
+ const core_1 = require("@net-mesh/core");
34
+ const VALID_SCOPES = new Set([
35
+ 'publish',
36
+ 'subscribe',
37
+ 'admin',
38
+ 'delegate',
39
+ ]);
40
+ // ----------------------------------------------------------------------------
41
+ // Errors — prefix dispatch mirrors the mesh / channel pattern.
42
+ // ----------------------------------------------------------------------------
43
+ /**
44
+ * Base class for identity-layer errors (malformed seed / subject /
45
+ * channel name). Not thrown for token-validity issues — those are
46
+ * `TokenError`.
47
+ */
48
+ class IdentityError extends Error {
49
+ constructor(message) {
50
+ super(message);
51
+ this.name = 'IdentityError';
52
+ Object.setPrototypeOf(this, IdentityError.prototype);
53
+ }
54
+ }
55
+ exports.IdentityError = IdentityError;
56
+ class TokenError extends Error {
57
+ kind;
58
+ constructor(kind, message) {
59
+ super(message ?? `token ${kind.replace(/_/g, ' ')}`);
60
+ this.name = 'TokenError';
61
+ this.kind = kind;
62
+ Object.setPrototypeOf(this, TokenError.prototype);
63
+ }
64
+ }
65
+ exports.TokenError = TokenError;
66
+ function toIdentityError(e) {
67
+ const msg = e?.message ?? String(e);
68
+ if (msg.startsWith('token:')) {
69
+ const kind = msg.slice('token:'.length).trim();
70
+ // Unknown kind → treat as invalid_format defensively so the type is sound.
71
+ const known = new Set([
72
+ 'invalid_signature',
73
+ 'not_yet_valid',
74
+ 'expired',
75
+ 'delegation_exhausted',
76
+ 'delegation_not_allowed',
77
+ 'not_authorized',
78
+ 'invalid_format',
79
+ ]);
80
+ throw new TokenError(known.has(kind) ? kind : 'invalid_format', msg);
81
+ }
82
+ if (msg.startsWith('identity:')) {
83
+ throw new IdentityError(msg.slice('identity:'.length).trim());
84
+ }
85
+ throw e;
86
+ }
87
+ function runMapped(fn) {
88
+ try {
89
+ return fn();
90
+ }
91
+ catch (e) {
92
+ toIdentityError(e);
93
+ }
94
+ }
95
+ // ----------------------------------------------------------------------------
96
+ // Token — parsed, typed view over a serialized PermissionToken buffer.
97
+ // ----------------------------------------------------------------------------
98
+ /**
99
+ * A signed, delegatable permission token. Construct via
100
+ * `Identity.issueToken` (locally) or `Token.parse` (from wire bytes).
101
+ *
102
+ * The wire form is 169 bytes: issuer (32) + subject (32) + scope (4)
103
+ * + channel hash (8, canonical 64-bit) + issuer generation (4) +
104
+ * not-before (8) + not-after (8) + delegation depth (1) + nonce (8)
105
+ * + ed25519 signature (64). Matches `PermissionToken::WIRE_SIZE` in
106
+ * the Rust core.
107
+ */
108
+ class Token {
109
+ /** Raw serialized bytes. Safe to send over the wire. */
110
+ bytes;
111
+ issuer;
112
+ subject;
113
+ scope;
114
+ /**
115
+ * Canonical 64-bit hash of the channel name this token authorizes
116
+ * (combine with `wildcard` scope for cross-channel grants). Compare
117
+ * against `channelHash(name)` to check whether a token applies to a
118
+ * named channel.
119
+ */
120
+ channelHash;
121
+ notBefore;
122
+ notAfter;
123
+ delegationDepth;
124
+ nonce;
125
+ constructor(bytes, info) {
126
+ this.bytes = bytes;
127
+ this.issuer = info.issuer;
128
+ this.subject = info.subject;
129
+ this.scope = info.scope;
130
+ this.channelHash = info.channelHash;
131
+ this.notBefore = info.notBefore;
132
+ this.notAfter = info.notAfter;
133
+ this.delegationDepth = info.delegationDepth;
134
+ this.nonce = info.nonce;
135
+ }
136
+ /** Parse a serialized token. Throws `TokenError { kind: 'invalid_format' }` on bad bytes. */
137
+ static parse(bytes) {
138
+ return new Token(bytes, parseTokenBytes(bytes));
139
+ }
140
+ /** Verify the ed25519 signature. Does NOT check time bounds — use `isExpired()` for that. */
141
+ verify() {
142
+ return runMapped(() => (0, core_1.verifyToken)(this.bytes));
143
+ }
144
+ /** `true` if the token's `notAfter` has passed. */
145
+ isExpired() {
146
+ return runMapped(() => (0, core_1.tokenIsExpired)(this.bytes));
147
+ }
148
+ /** Same instance — provided so callers can treat `Token` as a union with the serialized buffer. */
149
+ toBuffer() {
150
+ return this.bytes;
151
+ }
152
+ }
153
+ exports.Token = Token;
154
+ function parseTokenBytes(bytes) {
155
+ const info = runMapped(() => (0, core_1.parseToken)(bytes));
156
+ return {
157
+ issuer: info.issuer,
158
+ subject: info.subject,
159
+ scope: new Set(info.scope),
160
+ channelHash: info.channelHash,
161
+ notBefore: new Date(Number(info.notBefore) * 1000),
162
+ notAfter: new Date(Number(info.notAfter) * 1000),
163
+ delegationDepth: info.delegationDepth,
164
+ nonce: info.nonce,
165
+ };
166
+ }
167
+ /**
168
+ * Caller-owned identity bundle. Cheap to carry around; token cache
169
+ * entries are runtime-only and don't serialize.
170
+ */
171
+ class Identity {
172
+ inner;
173
+ constructor(inner) {
174
+ this.inner = inner;
175
+ }
176
+ /** Generate a fresh ed25519 identity. Persist via `toBytes()` to keep `nodeId` stable across restarts. */
177
+ static generate() {
178
+ return new Identity(core_1.Identity.generate());
179
+ }
180
+ /** Load from a caller-owned 32-byte ed25519 seed. */
181
+ static fromSeed(seed) {
182
+ return new Identity(runMapped(() => core_1.Identity.fromSeed(seed)));
183
+ }
184
+ /** Alias for `fromSeed` — the persisted form IS the 32-byte seed. */
185
+ static fromBytes(bytes) {
186
+ return new Identity(runMapped(() => core_1.Identity.fromBytes(bytes)));
187
+ }
188
+ /** Wrap an existing NAPI `Identity` handle — escape hatch for builder code. */
189
+ static fromNapi(inner) {
190
+ return new Identity(inner);
191
+ }
192
+ /** The underlying NAPI handle. Used by the mesh builder to bind this identity to a `MeshNode`. */
193
+ toNapi() {
194
+ return this.inner;
195
+ }
196
+ /** Serialize as the 32-byte ed25519 seed. Treat as secret material. */
197
+ toBytes() {
198
+ return this.inner.toBytes();
199
+ }
200
+ /** Ed25519 public key. 32 bytes. */
201
+ get entityId() {
202
+ return this.inner.entityId;
203
+ }
204
+ /** Derived 64-bit origin hash used in packet headers. */
205
+ get originHash() {
206
+ return this.inner.originHash;
207
+ }
208
+ /** Derived 64-bit node id used for routing / addressing. */
209
+ get nodeId() {
210
+ return this.inner.nodeId;
211
+ }
212
+ /** Sign arbitrary bytes. Returns 64-byte ed25519 signature. */
213
+ sign(message) {
214
+ return this.inner.sign(message);
215
+ }
216
+ /** Issue a scoped token to another entity. */
217
+ issueToken(opts) {
218
+ for (const s of opts.scope) {
219
+ if (!VALID_SCOPES.has(s)) {
220
+ throw new IdentityError(`unknown scope ${JSON.stringify(s)}`);
221
+ }
222
+ }
223
+ const bytes = runMapped(() => this.inner.issueToken(opts.subject, Array.from(opts.scope), opts.channel, opts.ttlSeconds, opts.delegationDepth ?? 0));
224
+ return Token.parse(bytes);
225
+ }
226
+ /** Install a token this node received. Throws `TokenError` on bad signature or malformed bytes. */
227
+ installToken(token) {
228
+ const bytes = token instanceof Token ? token.bytes : token;
229
+ runMapped(() => this.inner.installToken(bytes));
230
+ }
231
+ /** Look up a cached token. Returns `null` when no exact-channel entry is cached. */
232
+ lookupToken(subject, channel) {
233
+ const bytes = runMapped(() => this.inner.lookupToken(subject, channel));
234
+ return bytes == null ? null : Token.parse(bytes);
235
+ }
236
+ /** Number of cached tokens. Testing aid. */
237
+ get tokenCacheLen() {
238
+ return this.inner.tokenCacheLen;
239
+ }
240
+ }
241
+ exports.Identity = Identity;
242
+ // ----------------------------------------------------------------------------
243
+ // Free-function helpers.
244
+ // ----------------------------------------------------------------------------
245
+ /**
246
+ * Hash a channel name to its canonical 64-bit substrate identifier.
247
+ * Compare against `token.channelHash` to check whether a token
248
+ * applies to a named channel without trial-decoding. The per-packet
249
+ * wire `NetHeader` fast-path hint is the low 16 bits of this value.
250
+ */
251
+ function channelHash(channel) {
252
+ return runMapped(() => (0, core_1.channelHash)(channel));
253
+ }
254
+ /**
255
+ * Delegate a token to a new subject. The parent token must include
256
+ * `'delegate'` in its scope and have `delegationDepth > 0`; the
257
+ * signer must be the subject of the parent token. `restrictedScope`
258
+ * is intersected with the parent's scope.
259
+ */
260
+ function delegateToken(signer, parent, newSubject, restrictedScope) {
261
+ const parentBytes = parent instanceof Token ? parent.bytes : parent;
262
+ const childBytes = runMapped(() => (0, core_1.delegateToken)(signer.toNapi(), parentBytes, newSubject, Array.from(restrictedScope)));
263
+ return Token.parse(childBytes);
264
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @net-mesh/sdk — Ergonomic TypeScript SDK for the Net mesh network.
3
+ *
4
+ * @example
5
+ * ```typescript
6
+ * import { NetNode } from '@net-mesh/sdk';
7
+ *
8
+ * const node = await NetNode.create({ shards: 4 });
9
+ *
10
+ * // Emit events
11
+ * node.emit({ token: 'hello', index: 0 });
12
+ * node.emitRaw('{"token": "world"}');
13
+ *
14
+ * // Subscribe to a stream
15
+ * for await (const event of node.subscribe()) {
16
+ * console.log(event.raw);
17
+ * }
18
+ *
19
+ * // Typed channels
20
+ * const temps = node.channel<{ celsius: number }>('sensors/temperature');
21
+ * temps.publish({ celsius: 22.5 });
22
+ *
23
+ * await node.shutdown();
24
+ * ```
25
+ *
26
+ * @packageDocumentation
27
+ */
28
+ export { NetNode } from './node';
29
+ export { EventStream, TypedEventStream } from './stream';
30
+ export { TypedChannel } from './channel';
31
+ export { MeshNode, BackpressureError, NotConnectedError, ChannelError, ChannelAuthError, } from './mesh';
32
+ export type { MeshNodeConfig, MeshStream, StreamConfig, StreamStats, Reliability, Visibility, OnFailure, ChannelConfig, PublishConfig, PublishReport, SubscribeOptions, } from './mesh';
33
+ export { Redex, RedexFile, NetDb, TasksAdapter, MemoriesAdapter, TaskStatus, TasksOrderBy, MemoriesOrderBy, CortexError, NetDbError, RedexError, } from './cortex';
34
+ export type { RedexOptions, RedexFileConfig, RedexEvent, SnapshotAndWatch, Task, Memory, TaskFilter, MemoryFilter, NetDbOpenConfig, NetDbBundle, CortexSnapshot, } from './cortex';
35
+ export { Identity, Token, IdentityError, TokenError, channelHash, delegateToken, } from './identity';
36
+ export type { TokenScope, TokenErrorKind, IssueTokenOptions } from './identity';
37
+ export type { CapabilitySet, CapabilityFilter, CapabilityLimits, Hardware, Software, SoftwarePair, GpuInfo, GpuVendor, Accelerator, AcceleratorKind, ModelCapability, ToolCapability, Modality, ScopeFilter, } from './capabilities';
38
+ export { SCOPE_TENANT_PREFIX, SCOPE_REGION_PREFIX, SCOPE_SUBNET_LOCAL, withTenantScope, withRegionScope, withSubnetLocalScope, } from './capabilities';
39
+ export type { TaxonomyAxis, TagKey, AxisSeparator, Tag, PredicateNode, PredicateWire, Predicate, CapabilitySetWire, MetadataChange, CapabilitySetDiff, StandardPlacement, PlacementCandidate, PlacementFilterFn, RegisteredPlacementFilter, } from './capability-enhancements';
40
+ export { TAXONOMY_AXES, RESERVED_PREFIXES, RPC_WHERE_HEADER, tagKey, tagToString, tagFromString, tagFromUserString, startsWithReservedPrefix, p, predicateToWire, predicateFromWire, predicateToRpcHeader, predicateFromRpcHeader, whereHeader, diffCapabilities, emptyCapabilities, requireTag, requireAxisValue, withMetadata, StandardPlacementBuilder, standardPlacement, placementFilterFromFn, evaluatePredicate, evaluatePredicateWithTrace, predicateDebugReport, predicateDebugReportFromWire, redactMetadataKeys, renderDebugReport, } from './capability-enhancements';
41
+ export type { ClauseTrace, ClauseStats, PredicateDebugReport, EvalContextWire, } from './capability-enhancements';
42
+ export type { AxisEntry, AxisSchema, KeyEntry, KeyShape, KeyShapeKind, SchemaError, ValidationReport, ValidationWarning, ValueType, } from './capability-schema';
43
+ export { AXIS_SCHEMA, METADATA_RESERVED_KEYS, METADATA_RESERVED_PREFIXES, METADATA_SOFT_CAP_BYTES, isReportClean, isReportValid, validateCapabilities, } from './capability-schema';
44
+ export { subnetId, GLOBAL_SUBNET } from './subnets';
45
+ export type { SubnetId, SubnetRule, SubnetPolicy } from './subnets';
46
+ export { DaemonRuntime, DaemonHandle, DaemonError, MigrationHandle, MigrationError, } from './compute';
47
+ export type { CausalEvent, MeshDaemon, DaemonFactory, DaemonHostConfig, DaemonStats, MigrationPhase, MigrationOptions, MigrationErrorKind, } from './compute';
48
+ export { DisposableMeshQueryRunner, InMemoryChainReader, MeshQuery, MeshQueryRunner, MeshQueryStream, QueryBuilder, parseMeshDbErrorKind, } from './meshdb';
49
+ export type { AggregateResult, CachePolicy, ExecuteOptions, GroupKey, JoinedRow, LineageEntry, MeshDbPredicate, ParsedMeshDbError, ResultRow, WindowBoundary, } from './meshdb';
50
+ export { MeshOsDaemonSdk, MeshOsDaemonHandle, MeshOsSdkError } from './meshos';
51
+ export type { MeshOsDaemon, MeshOsConfig, MeshOsDaemonSdkOptions, DaemonControl, DaemonHealth, CapabilityAdvert, MaintenanceState, MetadataView, PeerSnapshot, } from './meshos';
52
+ export { ReplicaGroup, ForkGroup, StandbyGroup, GroupError } from './groups';
53
+ export type { GroupErrorKind, GroupStrategy, GroupHealth, GroupMemberInfo, GroupHostConfig, ForkRecord, RequestContext, ReplicaGroupConfig, ForkGroupConfig, StandbyGroupConfig, } from './groups';
54
+ export { RedisStreamDedup } from './redis-dedup';
55
+ export type { NetNodeConfig, Transport, Receipt, PollRequest, PollResponseData, Stats, SubscribeOpts, StoredEvent, } from './types';
package/dist/index.js ADDED
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ /**
3
+ * @net-mesh/sdk — Ergonomic TypeScript SDK for the Net mesh network.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * import { NetNode } from '@net-mesh/sdk';
8
+ *
9
+ * const node = await NetNode.create({ shards: 4 });
10
+ *
11
+ * // Emit events
12
+ * node.emit({ token: 'hello', index: 0 });
13
+ * node.emitRaw('{"token": "world"}');
14
+ *
15
+ * // Subscribe to a stream
16
+ * for await (const event of node.subscribe()) {
17
+ * console.log(event.raw);
18
+ * }
19
+ *
20
+ * // Typed channels
21
+ * const temps = node.channel<{ celsius: number }>('sensors/temperature');
22
+ * temps.publish({ celsius: 22.5 });
23
+ *
24
+ * await node.shutdown();
25
+ * ```
26
+ *
27
+ * @packageDocumentation
28
+ */
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.standardPlacement = exports.StandardPlacementBuilder = exports.withMetadata = exports.requireAxisValue = exports.requireTag = exports.emptyCapabilities = exports.diffCapabilities = exports.whereHeader = exports.predicateFromRpcHeader = exports.predicateToRpcHeader = exports.predicateFromWire = exports.predicateToWire = exports.p = exports.startsWithReservedPrefix = exports.tagFromUserString = exports.tagFromString = exports.tagToString = exports.tagKey = exports.RPC_WHERE_HEADER = exports.RESERVED_PREFIXES = exports.TAXONOMY_AXES = exports.withSubnetLocalScope = exports.withRegionScope = exports.withTenantScope = exports.SCOPE_SUBNET_LOCAL = exports.SCOPE_REGION_PREFIX = exports.SCOPE_TENANT_PREFIX = exports.delegateToken = exports.channelHash = exports.TokenError = exports.IdentityError = exports.Token = exports.Identity = exports.RedexError = exports.NetDbError = exports.CortexError = exports.MemoriesAdapter = exports.TasksAdapter = exports.NetDb = exports.RedexFile = exports.Redex = exports.ChannelAuthError = exports.ChannelError = exports.NotConnectedError = exports.BackpressureError = exports.MeshNode = exports.TypedChannel = exports.TypedEventStream = exports.EventStream = exports.NetNode = void 0;
31
+ exports.RedisStreamDedup = exports.GroupError = exports.StandbyGroup = exports.ForkGroup = exports.ReplicaGroup = exports.MeshOsSdkError = exports.MeshOsDaemonHandle = exports.MeshOsDaemonSdk = exports.parseMeshDbErrorKind = exports.QueryBuilder = exports.MeshQueryStream = exports.MeshQueryRunner = exports.MeshQuery = exports.InMemoryChainReader = exports.DisposableMeshQueryRunner = exports.MigrationError = exports.MigrationHandle = exports.DaemonError = exports.DaemonHandle = exports.DaemonRuntime = exports.GLOBAL_SUBNET = exports.subnetId = exports.validateCapabilities = exports.isReportValid = exports.isReportClean = exports.METADATA_SOFT_CAP_BYTES = exports.METADATA_RESERVED_PREFIXES = exports.METADATA_RESERVED_KEYS = exports.AXIS_SCHEMA = exports.renderDebugReport = exports.redactMetadataKeys = exports.predicateDebugReportFromWire = exports.predicateDebugReport = exports.evaluatePredicateWithTrace = exports.evaluatePredicate = exports.placementFilterFromFn = void 0;
32
+ // Main handle.
33
+ var node_1 = require("./node");
34
+ Object.defineProperty(exports, "NetNode", { enumerable: true, get: function () { return node_1.NetNode; } });
35
+ // Streaming.
36
+ var stream_1 = require("./stream");
37
+ Object.defineProperty(exports, "EventStream", { enumerable: true, get: function () { return stream_1.EventStream; } });
38
+ Object.defineProperty(exports, "TypedEventStream", { enumerable: true, get: function () { return stream_1.TypedEventStream; } });
39
+ // Typed channels.
40
+ var channel_1 = require("./channel");
41
+ Object.defineProperty(exports, "TypedChannel", { enumerable: true, get: function () { return channel_1.TypedChannel; } });
42
+ // Mesh + streams.
43
+ var mesh_1 = require("./mesh");
44
+ Object.defineProperty(exports, "MeshNode", { enumerable: true, get: function () { return mesh_1.MeshNode; } });
45
+ Object.defineProperty(exports, "BackpressureError", { enumerable: true, get: function () { return mesh_1.BackpressureError; } });
46
+ Object.defineProperty(exports, "NotConnectedError", { enumerable: true, get: function () { return mesh_1.NotConnectedError; } });
47
+ Object.defineProperty(exports, "ChannelError", { enumerable: true, get: function () { return mesh_1.ChannelError; } });
48
+ Object.defineProperty(exports, "ChannelAuthError", { enumerable: true, get: function () { return mesh_1.ChannelAuthError; } });
49
+ // CortEX + NetDb (event-sourced state with reactive watches).
50
+ var cortex_1 = require("./cortex");
51
+ Object.defineProperty(exports, "Redex", { enumerable: true, get: function () { return cortex_1.Redex; } });
52
+ Object.defineProperty(exports, "RedexFile", { enumerable: true, get: function () { return cortex_1.RedexFile; } });
53
+ Object.defineProperty(exports, "NetDb", { enumerable: true, get: function () { return cortex_1.NetDb; } });
54
+ Object.defineProperty(exports, "TasksAdapter", { enumerable: true, get: function () { return cortex_1.TasksAdapter; } });
55
+ Object.defineProperty(exports, "MemoriesAdapter", { enumerable: true, get: function () { return cortex_1.MemoriesAdapter; } });
56
+ Object.defineProperty(exports, "CortexError", { enumerable: true, get: function () { return cortex_1.CortexError; } });
57
+ Object.defineProperty(exports, "NetDbError", { enumerable: true, get: function () { return cortex_1.NetDbError; } });
58
+ Object.defineProperty(exports, "RedexError", { enumerable: true, get: function () { return cortex_1.RedexError; } });
59
+ // Identity + tokens (security surface).
60
+ var identity_1 = require("./identity");
61
+ Object.defineProperty(exports, "Identity", { enumerable: true, get: function () { return identity_1.Identity; } });
62
+ Object.defineProperty(exports, "Token", { enumerable: true, get: function () { return identity_1.Token; } });
63
+ Object.defineProperty(exports, "IdentityError", { enumerable: true, get: function () { return identity_1.IdentityError; } });
64
+ Object.defineProperty(exports, "TokenError", { enumerable: true, get: function () { return identity_1.TokenError; } });
65
+ Object.defineProperty(exports, "channelHash", { enumerable: true, get: function () { return identity_1.channelHash; } });
66
+ Object.defineProperty(exports, "delegateToken", { enumerable: true, get: function () { return identity_1.delegateToken; } });
67
+ var capabilities_1 = require("./capabilities");
68
+ Object.defineProperty(exports, "SCOPE_TENANT_PREFIX", { enumerable: true, get: function () { return capabilities_1.SCOPE_TENANT_PREFIX; } });
69
+ Object.defineProperty(exports, "SCOPE_REGION_PREFIX", { enumerable: true, get: function () { return capabilities_1.SCOPE_REGION_PREFIX; } });
70
+ Object.defineProperty(exports, "SCOPE_SUBNET_LOCAL", { enumerable: true, get: function () { return capabilities_1.SCOPE_SUBNET_LOCAL; } });
71
+ Object.defineProperty(exports, "withTenantScope", { enumerable: true, get: function () { return capabilities_1.withTenantScope; } });
72
+ Object.defineProperty(exports, "withRegionScope", { enumerable: true, get: function () { return capabilities_1.withRegionScope; } });
73
+ Object.defineProperty(exports, "withSubnetLocalScope", { enumerable: true, get: function () { return capabilities_1.withSubnetLocalScope; } });
74
+ var capability_enhancements_1 = require("./capability-enhancements");
75
+ Object.defineProperty(exports, "TAXONOMY_AXES", { enumerable: true, get: function () { return capability_enhancements_1.TAXONOMY_AXES; } });
76
+ Object.defineProperty(exports, "RESERVED_PREFIXES", { enumerable: true, get: function () { return capability_enhancements_1.RESERVED_PREFIXES; } });
77
+ Object.defineProperty(exports, "RPC_WHERE_HEADER", { enumerable: true, get: function () { return capability_enhancements_1.RPC_WHERE_HEADER; } });
78
+ Object.defineProperty(exports, "tagKey", { enumerable: true, get: function () { return capability_enhancements_1.tagKey; } });
79
+ Object.defineProperty(exports, "tagToString", { enumerable: true, get: function () { return capability_enhancements_1.tagToString; } });
80
+ Object.defineProperty(exports, "tagFromString", { enumerable: true, get: function () { return capability_enhancements_1.tagFromString; } });
81
+ Object.defineProperty(exports, "tagFromUserString", { enumerable: true, get: function () { return capability_enhancements_1.tagFromUserString; } });
82
+ Object.defineProperty(exports, "startsWithReservedPrefix", { enumerable: true, get: function () { return capability_enhancements_1.startsWithReservedPrefix; } });
83
+ Object.defineProperty(exports, "p", { enumerable: true, get: function () { return capability_enhancements_1.p; } });
84
+ Object.defineProperty(exports, "predicateToWire", { enumerable: true, get: function () { return capability_enhancements_1.predicateToWire; } });
85
+ Object.defineProperty(exports, "predicateFromWire", { enumerable: true, get: function () { return capability_enhancements_1.predicateFromWire; } });
86
+ Object.defineProperty(exports, "predicateToRpcHeader", { enumerable: true, get: function () { return capability_enhancements_1.predicateToRpcHeader; } });
87
+ Object.defineProperty(exports, "predicateFromRpcHeader", { enumerable: true, get: function () { return capability_enhancements_1.predicateFromRpcHeader; } });
88
+ Object.defineProperty(exports, "whereHeader", { enumerable: true, get: function () { return capability_enhancements_1.whereHeader; } });
89
+ Object.defineProperty(exports, "diffCapabilities", { enumerable: true, get: function () { return capability_enhancements_1.diffCapabilities; } });
90
+ Object.defineProperty(exports, "emptyCapabilities", { enumerable: true, get: function () { return capability_enhancements_1.emptyCapabilities; } });
91
+ Object.defineProperty(exports, "requireTag", { enumerable: true, get: function () { return capability_enhancements_1.requireTag; } });
92
+ Object.defineProperty(exports, "requireAxisValue", { enumerable: true, get: function () { return capability_enhancements_1.requireAxisValue; } });
93
+ Object.defineProperty(exports, "withMetadata", { enumerable: true, get: function () { return capability_enhancements_1.withMetadata; } });
94
+ Object.defineProperty(exports, "StandardPlacementBuilder", { enumerable: true, get: function () { return capability_enhancements_1.StandardPlacementBuilder; } });
95
+ Object.defineProperty(exports, "standardPlacement", { enumerable: true, get: function () { return capability_enhancements_1.standardPlacement; } });
96
+ Object.defineProperty(exports, "placementFilterFromFn", { enumerable: true, get: function () { return capability_enhancements_1.placementFilterFromFn; } });
97
+ Object.defineProperty(exports, "evaluatePredicate", { enumerable: true, get: function () { return capability_enhancements_1.evaluatePredicate; } });
98
+ Object.defineProperty(exports, "evaluatePredicateWithTrace", { enumerable: true, get: function () { return capability_enhancements_1.evaluatePredicateWithTrace; } });
99
+ Object.defineProperty(exports, "predicateDebugReport", { enumerable: true, get: function () { return capability_enhancements_1.predicateDebugReport; } });
100
+ Object.defineProperty(exports, "predicateDebugReportFromWire", { enumerable: true, get: function () { return capability_enhancements_1.predicateDebugReportFromWire; } });
101
+ Object.defineProperty(exports, "redactMetadataKeys", { enumerable: true, get: function () { return capability_enhancements_1.redactMetadataKeys; } });
102
+ Object.defineProperty(exports, "renderDebugReport", { enumerable: true, get: function () { return capability_enhancements_1.renderDebugReport; } });
103
+ var capability_schema_1 = require("./capability-schema");
104
+ Object.defineProperty(exports, "AXIS_SCHEMA", { enumerable: true, get: function () { return capability_schema_1.AXIS_SCHEMA; } });
105
+ Object.defineProperty(exports, "METADATA_RESERVED_KEYS", { enumerable: true, get: function () { return capability_schema_1.METADATA_RESERVED_KEYS; } });
106
+ Object.defineProperty(exports, "METADATA_RESERVED_PREFIXES", { enumerable: true, get: function () { return capability_schema_1.METADATA_RESERVED_PREFIXES; } });
107
+ Object.defineProperty(exports, "METADATA_SOFT_CAP_BYTES", { enumerable: true, get: function () { return capability_schema_1.METADATA_SOFT_CAP_BYTES; } });
108
+ Object.defineProperty(exports, "isReportClean", { enumerable: true, get: function () { return capability_schema_1.isReportClean; } });
109
+ Object.defineProperty(exports, "isReportValid", { enumerable: true, get: function () { return capability_schema_1.isReportValid; } });
110
+ Object.defineProperty(exports, "validateCapabilities", { enumerable: true, get: function () { return capability_schema_1.validateCapabilities; } });
111
+ // Subnets (visibility enforcement).
112
+ var subnets_1 = require("./subnets");
113
+ Object.defineProperty(exports, "subnetId", { enumerable: true, get: function () { return subnets_1.subnetId; } });
114
+ Object.defineProperty(exports, "GLOBAL_SUBNET", { enumerable: true, get: function () { return subnets_1.GLOBAL_SUBNET; } });
115
+ // Compute (daemons + migration — Stage 3 + 4).
116
+ var compute_1 = require("./compute");
117
+ Object.defineProperty(exports, "DaemonRuntime", { enumerable: true, get: function () { return compute_1.DaemonRuntime; } });
118
+ Object.defineProperty(exports, "DaemonHandle", { enumerable: true, get: function () { return compute_1.DaemonHandle; } });
119
+ Object.defineProperty(exports, "DaemonError", { enumerable: true, get: function () { return compute_1.DaemonError; } });
120
+ Object.defineProperty(exports, "MigrationHandle", { enumerable: true, get: function () { return compute_1.MigrationHandle; } });
121
+ Object.defineProperty(exports, "MigrationError", { enumerable: true, get: function () { return compute_1.MigrationError; } });
122
+ // MeshDB (causal-chain query layer).
123
+ var meshdb_1 = require("./meshdb");
124
+ Object.defineProperty(exports, "DisposableMeshQueryRunner", { enumerable: true, get: function () { return meshdb_1.DisposableMeshQueryRunner; } });
125
+ Object.defineProperty(exports, "InMemoryChainReader", { enumerable: true, get: function () { return meshdb_1.InMemoryChainReader; } });
126
+ Object.defineProperty(exports, "MeshQuery", { enumerable: true, get: function () { return meshdb_1.MeshQuery; } });
127
+ Object.defineProperty(exports, "MeshQueryRunner", { enumerable: true, get: function () { return meshdb_1.MeshQueryRunner; } });
128
+ Object.defineProperty(exports, "MeshQueryStream", { enumerable: true, get: function () { return meshdb_1.MeshQueryStream; } });
129
+ Object.defineProperty(exports, "QueryBuilder", { enumerable: true, get: function () { return meshdb_1.QueryBuilder; } });
130
+ Object.defineProperty(exports, "parseMeshDbErrorKind", { enumerable: true, get: function () { return meshdb_1.parseMeshDbErrorKind; } });
131
+ // MeshOS (daemon-author SDK over the MeshOS supervisor).
132
+ var meshos_1 = require("./meshos");
133
+ Object.defineProperty(exports, "MeshOsDaemonSdk", { enumerable: true, get: function () { return meshos_1.MeshOsDaemonSdk; } });
134
+ Object.defineProperty(exports, "MeshOsDaemonHandle", { enumerable: true, get: function () { return meshos_1.MeshOsDaemonHandle; } });
135
+ Object.defineProperty(exports, "MeshOsSdkError", { enumerable: true, get: function () { return meshos_1.MeshOsSdkError; } });
136
+ // Groups (HA / scaling overlays — Stage 2 of SDK_GROUPS_SURFACE_PLAN).
137
+ var groups_1 = require("./groups");
138
+ Object.defineProperty(exports, "ReplicaGroup", { enumerable: true, get: function () { return groups_1.ReplicaGroup; } });
139
+ Object.defineProperty(exports, "ForkGroup", { enumerable: true, get: function () { return groups_1.ForkGroup; } });
140
+ Object.defineProperty(exports, "StandbyGroup", { enumerable: true, get: function () { return groups_1.StandbyGroup; } });
141
+ Object.defineProperty(exports, "GroupError", { enumerable: true, get: function () { return groups_1.GroupError; } });
142
+ // Redis Streams consumer-side dedup helper.
143
+ // NAPI re-export so users can `import { RedisStreamDedup } from
144
+ // '@net-mesh/sdk'` instead of reaching into the underlying NAPI
145
+ // module directly.
146
+ var redis_dedup_1 = require("./redis-dedup");
147
+ Object.defineProperty(exports, "RedisStreamDedup", { enumerable: true, get: function () { return redis_dedup_1.RedisStreamDedup; } });