@labacacia/nps-sdk 1.0.0-alpha.6 → 1.0.0-alpha.7
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/CHANGELOG.cn.md +115 -0
- package/CHANGELOG.md +124 -0
- package/README.cn.md +3 -1
- package/README.md +3 -1
- package/dist/core/anchor-cache.d.ts +42 -0
- package/dist/core/anchor-cache.d.ts.map +1 -0
- package/dist/core/anchor-cache.js +104 -0
- package/dist/core/anchor-cache.js.map +1 -0
- package/dist/core/cache.d.ts +14 -0
- package/dist/core/cache.d.ts.map +1 -0
- package/dist/core/cache.js +80 -0
- package/dist/core/cache.js.map +1 -0
- package/dist/core/canonical-json.d.ts +12 -0
- package/dist/core/canonical-json.d.ts.map +1 -0
- package/dist/core/canonical-json.js +44 -0
- package/dist/core/canonical-json.js.map +1 -0
- package/dist/core/codec.d.ts +32 -0
- package/dist/core/codec.d.ts.map +1 -0
- package/dist/core/codec.js +119 -0
- package/dist/core/codec.js.map +1 -0
- package/dist/core/codecs/index.d.ts +4 -0
- package/dist/core/codecs/index.d.ts.map +1 -0
- package/{src/core/codecs/index.ts → dist/core/codecs/index.js} +1 -0
- package/dist/core/codecs/index.js.map +1 -0
- package/dist/core/codecs/ncp-codec.d.ts +39 -0
- package/dist/core/codecs/ncp-codec.d.ts.map +1 -0
- package/dist/core/codecs/ncp-codec.js +93 -0
- package/dist/core/codecs/ncp-codec.js.map +1 -0
- package/dist/core/codecs/tier1-json-codec.d.ts +10 -0
- package/dist/core/codecs/tier1-json-codec.d.ts.map +1 -0
- package/{src/core/codecs/tier1-json-codec.ts → dist/core/codecs/tier1-json-codec.js} +11 -16
- package/dist/core/codecs/tier1-json-codec.js.map +1 -0
- package/dist/core/codecs/tier2-msgpack-codec.d.ts +10 -0
- package/dist/core/codecs/tier2-msgpack-codec.d.ts.map +1 -0
- package/{src/core/codecs/tier2-msgpack-codec.ts → dist/core/codecs/tier2-msgpack-codec.js} +10 -14
- package/dist/core/codecs/tier2-msgpack-codec.js.map +1 -0
- package/dist/core/crypto-provider.d.ts +31 -0
- package/dist/core/crypto-provider.d.ts.map +1 -0
- package/dist/core/crypto-provider.js +10 -0
- package/dist/core/crypto-provider.js.map +1 -0
- package/dist/core/exceptions.d.ts +27 -0
- package/dist/core/exceptions.d.ts.map +1 -0
- package/dist/core/exceptions.js +52 -0
- package/dist/core/exceptions.js.map +1 -0
- package/dist/core/frame-header.d.ts +87 -0
- package/dist/core/frame-header.d.ts.map +1 -0
- package/dist/core/frame-header.js +185 -0
- package/dist/core/frame-header.js.map +1 -0
- package/dist/core/frame-registry.d.ts +35 -0
- package/dist/core/frame-registry.d.ts.map +1 -0
- package/dist/core/frame-registry.js +63 -0
- package/dist/core/frame-registry.js.map +1 -0
- package/dist/core/frames.d.ts +81 -0
- package/dist/core/frames.d.ts.map +1 -0
- package/dist/core/frames.js +154 -0
- package/dist/core/frames.js.map +1 -0
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.d.ts.map +1 -0
- package/{src/core/index.ts → dist/core/index.js} +3 -23
- package/dist/core/index.js.map +1 -0
- package/dist/core/registry.d.ts +11 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +17 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/status-codes.d.ts +29 -0
- package/dist/core/status-codes.d.ts.map +1 -0
- package/dist/core/status-codes.js +39 -0
- package/dist/core/status-codes.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/{src/index.ts → dist/index.js} +1 -1
- package/dist/index.js.map +1 -0
- package/dist/ncp/frames/anchor-frame.d.ts +29 -0
- package/dist/ncp/frames/anchor-frame.d.ts.map +1 -0
- package/dist/ncp/frames/anchor-frame.js +54 -0
- package/dist/ncp/frames/anchor-frame.js.map +1 -0
- package/dist/ncp/frames/caps-frame.d.ts +29 -0
- package/dist/ncp/frames/caps-frame.d.ts.map +1 -0
- package/dist/ncp/frames/caps-frame.js +29 -0
- package/dist/ncp/frames/caps-frame.js.map +1 -0
- package/dist/ncp/frames/diff-frame.d.ts +32 -0
- package/dist/ncp/frames/diff-frame.d.ts.map +1 -0
- package/dist/ncp/frames/diff-frame.js +37 -0
- package/dist/ncp/frames/diff-frame.js.map +1 -0
- package/dist/ncp/frames/error-frame.d.ts +16 -0
- package/dist/ncp/frames/error-frame.d.ts.map +1 -0
- package/dist/ncp/frames/error-frame.js +13 -0
- package/dist/ncp/frames/error-frame.js.map +1 -0
- package/dist/ncp/frames/hello-frame.d.ts +21 -0
- package/dist/ncp/frames/hello-frame.d.ts.map +1 -0
- package/dist/ncp/frames/hello-frame.js +25 -0
- package/dist/ncp/frames/hello-frame.js.map +1 -0
- package/dist/ncp/frames/stream-frame.d.ts +16 -0
- package/dist/ncp/frames/stream-frame.d.ts.map +1 -0
- package/dist/ncp/frames/stream-frame.js +18 -0
- package/dist/ncp/frames/stream-frame.js.map +1 -0
- package/dist/ncp/frames.d.ts +94 -0
- package/dist/ncp/frames.d.ts.map +1 -0
- package/dist/ncp/frames.js +192 -0
- package/dist/ncp/frames.js.map +1 -0
- package/dist/ncp/handshake.d.ts +30 -0
- package/dist/ncp/handshake.d.ts.map +1 -0
- package/dist/ncp/handshake.js +80 -0
- package/dist/ncp/handshake.js.map +1 -0
- package/dist/ncp/index.d.ts +12 -0
- package/dist/ncp/index.d.ts.map +1 -0
- package/{src/ncp/index.ts → dist/ncp/index.js} +1 -0
- package/dist/ncp/index.js.map +1 -0
- package/dist/ncp/ncp-error-codes.d.ts +23 -0
- package/dist/ncp/ncp-error-codes.d.ts.map +1 -0
- package/dist/ncp/ncp-error-codes.js +34 -0
- package/dist/ncp/ncp-error-codes.js.map +1 -0
- package/dist/ncp/ncp-patch-format.d.ts +7 -0
- package/dist/ncp/ncp-patch-format.d.ts.map +1 -0
- package/dist/ncp/ncp-patch-format.js +13 -0
- package/dist/ncp/ncp-patch-format.js.map +1 -0
- package/dist/ncp/preamble.d.ts +47 -0
- package/dist/ncp/preamble.d.ts.map +1 -0
- package/dist/ncp/preamble.js +74 -0
- package/dist/ncp/preamble.js.map +1 -0
- package/dist/ncp/registry.d.ts +3 -0
- package/dist/ncp/registry.d.ts.map +1 -0
- package/dist/ncp/registry.js +13 -0
- package/dist/ncp/registry.js.map +1 -0
- package/dist/ncp/stream-manager.d.ts +57 -0
- package/dist/ncp/stream-manager.d.ts.map +1 -0
- package/dist/ncp/stream-manager.js +163 -0
- package/dist/ncp/stream-manager.js.map +1 -0
- package/dist/ndp/dns-txt.d.ts +35 -0
- package/dist/ndp/dns-txt.d.ts.map +1 -0
- package/dist/ndp/dns-txt.js +67 -0
- package/dist/ndp/dns-txt.js.map +1 -0
- package/dist/ndp/frames.d.ts +56 -0
- package/dist/ndp/frames.d.ts.map +1 -0
- package/dist/ndp/frames.js +87 -0
- package/dist/ndp/frames.js.map +1 -0
- package/dist/ndp/index.d.ts +6 -0
- package/dist/ndp/index.d.ts.map +1 -0
- package/{src/ndp/index.ts → dist/ndp/index.js} +1 -1
- package/dist/ndp/index.js.map +1 -0
- package/dist/ndp/ndp-registry.d.ts +13 -0
- package/dist/ndp/ndp-registry.d.ts.map +1 -0
- package/dist/ndp/ndp-registry.js +104 -0
- package/dist/ndp/ndp-registry.js.map +1 -0
- package/dist/ndp/registry.d.ts +3 -0
- package/dist/ndp/registry.d.ts.map +1 -0
- package/dist/ndp/registry.js +10 -0
- package/dist/ndp/registry.js.map +1 -0
- package/dist/ndp/validator.d.ts +18 -0
- package/dist/ndp/validator.d.ts.map +1 -0
- package/dist/ndp/validator.js +48 -0
- package/dist/ndp/validator.js.map +1 -0
- package/dist/nip/acme/client.d.ts +31 -0
- package/dist/nip/acme/client.d.ts.map +1 -0
- package/dist/nip/acme/client.js +136 -0
- package/dist/nip/acme/client.js.map +1 -0
- package/dist/nip/acme/index.d.ts +6 -0
- package/dist/nip/acme/index.d.ts.map +1 -0
- package/{src/nip/acme/index.ts → dist/nip/acme/index.js} +1 -1
- package/dist/nip/acme/index.js.map +1 -0
- package/dist/nip/acme/jws.d.ts +31 -0
- package/dist/nip/acme/jws.d.ts.map +1 -0
- package/dist/nip/acme/jws.js +76 -0
- package/dist/nip/acme/jws.js.map +1 -0
- package/dist/nip/acme/messages.d.ts +71 -0
- package/dist/nip/acme/messages.d.ts.map +1 -0
- package/dist/nip/acme/messages.js +4 -0
- package/dist/nip/acme/messages.js.map +1 -0
- package/dist/nip/acme/server.d.ts +41 -0
- package/dist/nip/acme/server.d.ts.map +1 -0
- package/dist/nip/acme/server.js +458 -0
- package/dist/nip/acme/server.js.map +1 -0
- package/dist/nip/acme/wire.d.ts +19 -0
- package/dist/nip/acme/wire.d.ts.map +1 -0
- package/dist/nip/acme/wire.js +21 -0
- package/dist/nip/acme/wire.js.map +1 -0
- package/dist/nip/assurance-level.d.ts +19 -0
- package/dist/nip/assurance-level.d.ts.map +1 -0
- package/dist/nip/assurance-level.js +38 -0
- package/dist/nip/assurance-level.js.map +1 -0
- package/dist/nip/cert-format.d.ts +5 -0
- package/dist/nip/cert-format.d.ts.map +1 -0
- package/dist/nip/cert-format.js +6 -0
- package/dist/nip/cert-format.js.map +1 -0
- package/dist/nip/error-codes.d.ts +25 -0
- package/dist/nip/error-codes.d.ts.map +1 -0
- package/{src/nip/error-codes.ts → dist/nip/error-codes.js} +19 -25
- package/dist/nip/error-codes.js.map +1 -0
- package/dist/nip/frames.d.ts +53 -0
- package/dist/nip/frames.d.ts.map +1 -0
- package/dist/nip/frames.js +106 -0
- package/dist/nip/frames.js.map +1 -0
- package/dist/nip/identity.d.ts +18 -0
- package/dist/nip/identity.d.ts.map +1 -0
- package/dist/nip/identity.js +94 -0
- package/dist/nip/identity.js.map +1 -0
- package/dist/nip/index.d.ts +11 -0
- package/dist/nip/index.d.ts.map +1 -0
- package/{src/nip/index.ts → dist/nip/index.js} +3 -2
- package/dist/nip/index.js.map +1 -0
- package/dist/nip/registry.d.ts +3 -0
- package/dist/nip/registry.d.ts.map +1 -0
- package/dist/nip/registry.js +10 -0
- package/dist/nip/registry.js.map +1 -0
- package/dist/nip/reputation-client.d.ts +116 -0
- package/dist/nip/reputation-client.d.ts.map +1 -0
- package/dist/nip/reputation-client.js +261 -0
- package/dist/nip/reputation-client.js.map +1 -0
- package/dist/nip/verifier.d.ts +23 -0
- package/dist/nip/verifier.d.ts.map +1 -0
- package/dist/nip/verifier.js +90 -0
- package/dist/nip/verifier.js.map +1 -0
- package/dist/nip/x509/builder.d.ts +35 -0
- package/dist/nip/x509/builder.d.ts.map +1 -0
- package/dist/nip/x509/builder.js +59 -0
- package/dist/nip/x509/builder.js.map +1 -0
- package/dist/nip/x509/index.d.ts +4 -0
- package/dist/nip/x509/index.d.ts.map +1 -0
- package/{src/nip/x509/index.ts → dist/nip/x509/index.js} +1 -1
- package/dist/nip/x509/index.js.map +1 -0
- package/dist/nip/x509/oids.d.ts +16 -0
- package/dist/nip/x509/oids.d.ts.map +1 -0
- package/{src/nip/x509/oids.ts → dist/nip/x509/oids.js} +5 -10
- package/dist/nip/x509/oids.js.map +1 -0
- package/dist/nip/x509/verifier.d.ts +26 -0
- package/dist/nip/x509/verifier.d.ts.map +1 -0
- package/dist/nip/x509/verifier.js +171 -0
- package/dist/nip/x509/verifier.js.map +1 -0
- package/dist/nop/client.d.ts +34 -0
- package/dist/nop/client.d.ts.map +1 -0
- package/dist/nop/client.js +90 -0
- package/dist/nop/client.js.map +1 -0
- package/dist/nop/frames.d.ts +65 -0
- package/dist/nop/frames.d.ts.map +1 -0
- package/dist/nop/frames.js +148 -0
- package/dist/nop/frames.js.map +1 -0
- package/dist/nop/index.d.ts +5 -0
- package/dist/nop/index.d.ts.map +1 -0
- package/{src/nop/index.ts → dist/nop/index.js} +1 -1
- package/dist/nop/index.js.map +1 -0
- package/dist/nop/models.d.ts +58 -0
- package/dist/nop/models.d.ts.map +1 -0
- package/dist/nop/models.js +50 -0
- package/dist/nop/models.js.map +1 -0
- package/dist/nop/nop-types.d.ts +136 -0
- package/dist/nop/nop-types.d.ts.map +1 -0
- package/dist/nop/nop-types.js +44 -0
- package/dist/nop/nop-types.js.map +1 -0
- package/dist/nop/registry.d.ts +3 -0
- package/dist/nop/registry.d.ts.map +1 -0
- package/dist/nop/registry.js +11 -0
- package/dist/nop/registry.js.map +1 -0
- package/dist/nwp/anchor-client.d.ts +109 -0
- package/dist/nwp/anchor-client.d.ts.map +1 -0
- package/dist/nwp/anchor-client.js +279 -0
- package/dist/nwp/anchor-client.js.map +1 -0
- package/dist/nwp/client.d.ts +22 -0
- package/dist/nwp/client.d.ts.map +1 -0
- package/dist/nwp/client.js +101 -0
- package/dist/nwp/client.js.map +1 -0
- package/dist/nwp/frames.d.ts +46 -0
- package/dist/nwp/frames.d.ts.map +1 -0
- package/dist/nwp/frames.js +81 -0
- package/dist/nwp/frames.js.map +1 -0
- package/dist/nwp/index.d.ts +5 -0
- package/dist/nwp/index.d.ts.map +1 -0
- package/{src/nwp/index.ts → dist/nwp/index.js} +2 -1
- package/dist/nwp/index.js.map +1 -0
- package/dist/nwp/registry.d.ts +3 -0
- package/dist/nwp/registry.d.ts.map +1 -0
- package/dist/nwp/registry.js +9 -0
- package/dist/nwp/registry.js.map +1 -0
- package/dist/setup.d.ts +10 -0
- package/dist/setup.d.ts.map +1 -0
- package/{src/setup.ts → dist/setup.js} +13 -16
- package/dist/setup.js.map +1 -0
- package/package.json +12 -1
- package/CONTRIBUTING.cn.md +0 -35
- package/CONTRIBUTING.md +0 -35
- package/nip-ca-server/Dockerfile +0 -27
- package/nip-ca-server/README.md +0 -45
- package/nip-ca-server/db/001_init.sql +0 -25
- package/nip-ca-server/docker-compose.yml +0 -29
- package/nip-ca-server/package.json +0 -23
- package/nip-ca-server/src/ca.ts +0 -155
- package/nip-ca-server/src/db.ts +0 -104
- package/nip-ca-server/src/index.ts +0 -157
- package/nip-ca-server/tsconfig.json +0 -13
- package/src/core/anchor-cache.ts +0 -129
- package/src/core/cache.ts +0 -93
- package/src/core/canonical-json.ts +0 -50
- package/src/core/codec.ts +0 -158
- package/src/core/codecs/ncp-codec.ts +0 -170
- package/src/core/crypto-provider.ts +0 -47
- package/src/core/exceptions.ts +0 -57
- package/src/core/frame-header.ts +0 -282
- package/src/core/frame-registry.ts +0 -91
- package/src/core/frames.ts +0 -184
- package/src/core/registry.ts +0 -28
- package/src/core/status-codes.ts +0 -47
- package/src/ncp/frames/anchor-frame.ts +0 -87
- package/src/ncp/frames/caps-frame.ts +0 -59
- package/src/ncp/frames/diff-frame.ts +0 -69
- package/src/ncp/frames/error-frame.ts +0 -26
- package/src/ncp/frames/hello-frame.ts +0 -50
- package/src/ncp/frames/stream-frame.ts +0 -35
- package/src/ncp/frames.ts +0 -251
- package/src/ncp/handshake.ts +0 -95
- package/src/ncp/ncp-error-codes.ts +0 -36
- package/src/ncp/ncp-patch-format.ts +0 -16
- package/src/ncp/preamble.ts +0 -79
- package/src/ncp/registry.ts +0 -15
- package/src/ncp/stream-manager.ts +0 -212
- package/src/ndp/dns-txt.ts +0 -86
- package/src/ndp/frames.ts +0 -124
- package/src/ndp/ndp-registry.ts +0 -116
- package/src/ndp/registry.ts +0 -12
- package/src/ndp/validator.ts +0 -64
- package/src/nip/acme/client.ts +0 -185
- package/src/nip/acme/jws.ts +0 -109
- package/src/nip/acme/messages.ts +0 -85
- package/src/nip/acme/server.ts +0 -480
- package/src/nip/acme/wire.ts +0 -24
- package/src/nip/assurance-level.ts +0 -40
- package/src/nip/cert-format.ts +0 -9
- package/src/nip/frames.ts +0 -138
- package/src/nip/identity.ts +0 -113
- package/src/nip/registry.ts +0 -12
- package/src/nip/verifier.ts +0 -122
- package/src/nip/x509/builder.ts +0 -91
- package/src/nip/x509/verifier.ts +0 -214
- package/src/nop/client.ts +0 -103
- package/src/nop/frames.ts +0 -181
- package/src/nop/models.ts +0 -79
- package/src/nop/nop-types.ts +0 -208
- package/src/nop/registry.ts +0 -13
- package/src/nwp/client.ts +0 -114
- package/src/nwp/frames.ts +0 -116
- package/src/nwp/registry.ts +0 -11
- package/tests/_rfc0002-keys.ts +0 -57
- package/tests/core/anchor-cache.test.ts +0 -242
- package/tests/core/codec.test.ts +0 -205
- package/tests/core/frame-registry.test.ts +0 -46
- package/tests/core.test.ts +0 -327
- package/tests/ncp/diff-binary-bitset.test.ts +0 -107
- package/tests/ncp/e2e-enc-reject.test.ts +0 -93
- package/tests/ncp/err-error-frame.test.ts +0 -152
- package/tests/ncp/frames.test.ts +0 -359
- package/tests/ncp/framing.test.ts +0 -233
- package/tests/ncp/hello-frame.test.ts +0 -122
- package/tests/ncp/inline-anchor.test.ts +0 -88
- package/tests/ncp/preamble.test.ts +0 -93
- package/tests/ncp/security.test.ts +0 -184
- package/tests/ncp/stream-window.test.ts +0 -167
- package/tests/ncp/stream.test.ts +0 -242
- package/tests/ncp/version-negotiation.test.ts +0 -123
- package/tests/ndp.test.ts +0 -377
- package/tests/nip-acme-agent01.test.ts +0 -192
- package/tests/nip-x509.test.ts +0 -280
- package/tests/nip.test.ts +0 -184
- package/tests/nop.test.ts +0 -344
- package/tests/nwp.test.ts +0 -237
- package/tsconfig.json +0 -20
- package/tsup.config.ts +0 -20
- package/vitest.config.ts +0 -10
package/tests/nop.test.ts
DELETED
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
// Copyright 2026 INNO LOTUS PTY LTD
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
5
|
-
import {
|
|
6
|
-
TaskState, TaskPriority, BackoffStrategy, AggregateStrategy,
|
|
7
|
-
computeDelayMs,
|
|
8
|
-
} from "../src/nop/models.js";
|
|
9
|
-
import { TaskFrame, DelegateFrame, SyncFrame, AlignStreamFrame } from "../src/nop/frames.js";
|
|
10
|
-
import { NopClient, NopTaskStatus } from "../src/nop/client.js";
|
|
11
|
-
import { createFullRegistry } from "../src/setup.js";
|
|
12
|
-
import { NpsFrameCodec } from "../src/core/index.js";
|
|
13
|
-
|
|
14
|
-
// ── computeDelayMs ────────────────────────────────────────────────────────────
|
|
15
|
-
|
|
16
|
-
describe("computeDelayMs", () => {
|
|
17
|
-
it("FIXED strategy ignores attempt", () => {
|
|
18
|
-
const p = { maxRetries: 3, backoff: BackoffStrategy.FIXED, baseDelayMs: 500 };
|
|
19
|
-
expect(computeDelayMs(p, 0)).toBe(500);
|
|
20
|
-
expect(computeDelayMs(p, 5)).toBe(500);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("LINEAR scales with attempt", () => {
|
|
24
|
-
const p = { maxRetries: 3, backoff: BackoffStrategy.LINEAR, baseDelayMs: 1000 };
|
|
25
|
-
expect(computeDelayMs(p, 0)).toBe(1000);
|
|
26
|
-
expect(computeDelayMs(p, 2)).toBe(3000);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("EXPONENTIAL doubles each attempt", () => {
|
|
30
|
-
const p = { maxRetries: 5, backoff: BackoffStrategy.EXPONENTIAL, baseDelayMs: 1000 };
|
|
31
|
-
expect(computeDelayMs(p, 0)).toBe(1000);
|
|
32
|
-
expect(computeDelayMs(p, 1)).toBe(2000);
|
|
33
|
-
expect(computeDelayMs(p, 3)).toBe(8000);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("caps at maxDelayMs", () => {
|
|
37
|
-
const p = { maxRetries: 5, backoff: BackoffStrategy.EXPONENTIAL, baseDelayMs: 1000, maxDelayMs: 5000 };
|
|
38
|
-
expect(computeDelayMs(p, 10)).toBe(5000);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("defaults base=1000 cap=30000", () => {
|
|
42
|
-
const p = { maxRetries: 3, backoff: BackoffStrategy.FIXED };
|
|
43
|
-
expect(computeDelayMs(p, 0)).toBe(1000);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// ── TaskFrame ─────────────────────────────────────────────────────────────────
|
|
48
|
-
|
|
49
|
-
describe("TaskFrame", () => {
|
|
50
|
-
const dag = { nodes: [{ id: "n1", action: "search", agent: "urn:nps:node:a:1" }], edges: [] };
|
|
51
|
-
|
|
52
|
-
it("round-trips via toDict / fromDict", () => {
|
|
53
|
-
const f = new TaskFrame(
|
|
54
|
-
"task-1", dag, 5000, "https://cb.example.com/hook",
|
|
55
|
-
{ sessionKey: "sk-1", traceId: "tr-1" }, TaskPriority.HIGH, 1,
|
|
56
|
-
);
|
|
57
|
-
const back = TaskFrame.fromDict(f.toDict());
|
|
58
|
-
expect(back.taskId).toBe("task-1");
|
|
59
|
-
expect(back.timeoutMs).toBe(5000);
|
|
60
|
-
expect(back.callbackUrl).toBe("https://cb.example.com/hook");
|
|
61
|
-
expect(back.priority).toBe(TaskPriority.HIGH);
|
|
62
|
-
expect(back.depth).toBe(1);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("optional fields default to undefined", () => {
|
|
66
|
-
const f = new TaskFrame("t2", dag);
|
|
67
|
-
const back = TaskFrame.fromDict(f.toDict());
|
|
68
|
-
expect(back.timeoutMs).toBeUndefined();
|
|
69
|
-
expect(back.callbackUrl).toBeUndefined();
|
|
70
|
-
expect(back.priority).toBeUndefined();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("codec round-trip (MsgPack)", () => {
|
|
74
|
-
const registry = createFullRegistry();
|
|
75
|
-
const codec = new NpsFrameCodec(registry);
|
|
76
|
-
const f = new TaskFrame("t3", dag);
|
|
77
|
-
const back = codec.decode(codec.encode(f)) as TaskFrame;
|
|
78
|
-
expect(back).toBeInstanceOf(TaskFrame);
|
|
79
|
-
expect(back.taskId).toBe("t3");
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// ── DelegateFrame ─────────────────────────────────────────────────────────────
|
|
84
|
-
|
|
85
|
-
describe("DelegateFrame", () => {
|
|
86
|
-
it("round-trips via toDict / fromDict", () => {
|
|
87
|
-
const f = new DelegateFrame(
|
|
88
|
-
"task-1", "sub-1", "classify", "urn:nps:node:a:1",
|
|
89
|
-
{ text: "hello" }, { model: "gpt-4" }, "idem-x",
|
|
90
|
-
);
|
|
91
|
-
const back = DelegateFrame.fromDict(f.toDict());
|
|
92
|
-
expect(back.subtaskId).toBe("sub-1");
|
|
93
|
-
expect(back.action).toBe("classify");
|
|
94
|
-
expect(back.inputs?.["text"]).toBe("hello");
|
|
95
|
-
expect(back.params?.["model"]).toBe("gpt-4");
|
|
96
|
-
expect(back.idempotencyKey).toBe("idem-x");
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("optional fields default to undefined", () => {
|
|
100
|
-
const f = new DelegateFrame("t1", "s1", "act", "urn:nps:node:a:1");
|
|
101
|
-
const back = DelegateFrame.fromDict(f.toDict());
|
|
102
|
-
expect(back.inputs).toBeUndefined();
|
|
103
|
-
expect(back.params).toBeUndefined();
|
|
104
|
-
expect(back.idempotencyKey).toBeUndefined();
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// ── SyncFrame ─────────────────────────────────────────────────────────────────
|
|
109
|
-
|
|
110
|
-
describe("SyncFrame", () => {
|
|
111
|
-
it("round-trips via toDict / fromDict", () => {
|
|
112
|
-
const f = new SyncFrame(
|
|
113
|
-
"task-1", "sync-1", ["sub-a", "sub-b"], 1,
|
|
114
|
-
AggregateStrategy.FASTEST_K, 3000,
|
|
115
|
-
);
|
|
116
|
-
const back = SyncFrame.fromDict(f.toDict());
|
|
117
|
-
expect(back.syncId).toBe("sync-1");
|
|
118
|
-
expect(back.waitFor).toEqual(["sub-a", "sub-b"]);
|
|
119
|
-
expect(back.minRequired).toBe(1);
|
|
120
|
-
expect(back.aggregate).toBe(AggregateStrategy.FASTEST_K);
|
|
121
|
-
expect(back.timeoutMs).toBe(3000);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("defaults minRequired=0 and aggregate=merge", () => {
|
|
125
|
-
const f = new SyncFrame("t1", "s1", ["a"]);
|
|
126
|
-
const back = SyncFrame.fromDict(f.toDict());
|
|
127
|
-
expect(back.minRequired).toBe(0);
|
|
128
|
-
expect(back.aggregate).toBe("merge");
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// ── AlignStreamFrame ──────────────────────────────────────────────────────────
|
|
133
|
-
|
|
134
|
-
describe("AlignStreamFrame", () => {
|
|
135
|
-
it("round-trips via toDict / fromDict with error", () => {
|
|
136
|
-
const f = new AlignStreamFrame(
|
|
137
|
-
"stream-1", "task-1", "sub-1", 3, true, "urn:nps:node:a:1",
|
|
138
|
-
{ score: 0.9 }, { errorCode: "NOP-DELEGATE-FAILED", message: "timeout" }, 10,
|
|
139
|
-
);
|
|
140
|
-
const back = AlignStreamFrame.fromDict(f.toDict());
|
|
141
|
-
expect(back.streamId).toBe("stream-1");
|
|
142
|
-
expect(back.seq).toBe(3);
|
|
143
|
-
expect(back.isFinal).toBe(true);
|
|
144
|
-
expect(back.senderNid).toBe("urn:nps:node:a:1");
|
|
145
|
-
expect(back.error?.errorCode).toBe("NOP-DELEGATE-FAILED");
|
|
146
|
-
expect(back.error?.message).toBe("timeout");
|
|
147
|
-
expect(back.windowSize).toBe(10);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it("handles null error field", () => {
|
|
151
|
-
const f = new AlignStreamFrame("s1", "t1", "st1", 0, false, "urn:nps:node:a:1");
|
|
152
|
-
const back = AlignStreamFrame.fromDict(f.toDict());
|
|
153
|
-
expect(back.error).toBeUndefined();
|
|
154
|
-
expect(back.data).toBeUndefined();
|
|
155
|
-
expect(back.windowSize).toBeUndefined();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("error without message is preserved", () => {
|
|
159
|
-
const f = new AlignStreamFrame(
|
|
160
|
-
"s1", "t1", "st1", 0, true, "urn:nps:node:a:1",
|
|
161
|
-
undefined, { errorCode: "NOP-TASK-FAILED" },
|
|
162
|
-
);
|
|
163
|
-
const back = AlignStreamFrame.fromDict(f.toDict());
|
|
164
|
-
expect(back.error?.errorCode).toBe("NOP-TASK-FAILED");
|
|
165
|
-
expect(back.error?.message).toBeUndefined();
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
// ── NopTaskStatus ─────────────────────────────────────────────────────────────
|
|
170
|
-
|
|
171
|
-
describe("NopTaskStatus", () => {
|
|
172
|
-
const makeStatus = (state: string, extras: Record<string, unknown> = {}) =>
|
|
173
|
-
new NopTaskStatus({ task_id: "t-1", state, ...extras });
|
|
174
|
-
|
|
175
|
-
it("taskId and state getters", () => {
|
|
176
|
-
const s = makeStatus("running");
|
|
177
|
-
expect(s.taskId).toBe("t-1");
|
|
178
|
-
expect(s.state).toBe(TaskState.RUNNING);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("isTerminal: COMPLETED / FAILED / CANCELLED are terminal", () => {
|
|
182
|
-
expect(makeStatus("completed").isTerminal).toBe(true);
|
|
183
|
-
expect(makeStatus("failed").isTerminal).toBe(true);
|
|
184
|
-
expect(makeStatus("cancelled").isTerminal).toBe(true);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it("isTerminal: running / pending are not terminal", () => {
|
|
188
|
-
expect(makeStatus("running").isTerminal).toBe(false);
|
|
189
|
-
expect(makeStatus("pending").isTerminal).toBe(false);
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it("aggregatedResult, errorCode, errorMessage", () => {
|
|
193
|
-
const s = makeStatus("failed", {
|
|
194
|
-
aggregated_result: { items: [] },
|
|
195
|
-
error_code: "NOP-TASK-FAILED",
|
|
196
|
-
error_message: "Agent timeout",
|
|
197
|
-
});
|
|
198
|
-
expect(s.aggregatedResult).toEqual({ items: [] });
|
|
199
|
-
expect(s.errorCode).toBe("NOP-TASK-FAILED");
|
|
200
|
-
expect(s.errorMessage).toBe("Agent timeout");
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it("errorCode / errorMessage undefined when null", () => {
|
|
204
|
-
const s = makeStatus("completed", { error_code: null, error_message: null });
|
|
205
|
-
expect(s.errorCode).toBeUndefined();
|
|
206
|
-
expect(s.errorMessage).toBeUndefined();
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it("nodeResults defaults to empty object", () => {
|
|
210
|
-
const s = makeStatus("running");
|
|
211
|
-
expect(s.nodeResults).toEqual({});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it("nodeResults when present", () => {
|
|
215
|
-
const s = makeStatus("completed", { node_results: { n1: { out: 42 } } });
|
|
216
|
-
expect(s.nodeResults["n1"]).toEqual({ out: 42 });
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("raw returns underlying dict", () => {
|
|
220
|
-
const s = makeStatus("pending");
|
|
221
|
-
expect(s.raw["task_id"]).toBe("t-1");
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it("toString format", () => {
|
|
225
|
-
const s = makeStatus("running");
|
|
226
|
-
expect(s.toString()).toContain("t-1");
|
|
227
|
-
expect(s.toString()).toContain("running");
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
// ── NopClient ─────────────────────────────────────────────────────────────────
|
|
232
|
-
|
|
233
|
-
describe("NopClient", () => {
|
|
234
|
-
const dag = { nodes: [{ id: "n1", action: "act", agent: "urn:nps:node:a:1" }], edges: [] };
|
|
235
|
-
|
|
236
|
-
beforeEach(() => { vi.restoreAllMocks(); });
|
|
237
|
-
|
|
238
|
-
it("submit — returns taskId on 201", async () => {
|
|
239
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({
|
|
240
|
-
ok: true,
|
|
241
|
-
json: () => Promise.resolve({ task_id: "new-task-1" }),
|
|
242
|
-
}));
|
|
243
|
-
const client = new NopClient("http://nop.test");
|
|
244
|
-
const id = await client.submit(new TaskFrame("t1", dag));
|
|
245
|
-
expect(id).toBe("new-task-1");
|
|
246
|
-
expect(vi.mocked(fetch)).toHaveBeenCalledWith(
|
|
247
|
-
"http://nop.test/task",
|
|
248
|
-
expect.objectContaining({ method: "POST" }),
|
|
249
|
-
);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it("submit — throws on non-2xx", async () => {
|
|
253
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: false, status: 400 }));
|
|
254
|
-
const client = new NopClient("http://nop.test");
|
|
255
|
-
await expect(client.submit(new TaskFrame("t1", dag))).rejects.toThrow("400");
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
it("getStatus — returns NopTaskStatus", async () => {
|
|
259
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({
|
|
260
|
-
ok: true,
|
|
261
|
-
json: () => Promise.resolve({ task_id: "t1", state: "running" }),
|
|
262
|
-
}));
|
|
263
|
-
const client = new NopClient("http://nop.test");
|
|
264
|
-
const status = await client.getStatus("t1");
|
|
265
|
-
expect(status).toBeInstanceOf(NopTaskStatus);
|
|
266
|
-
expect(status.state).toBe(TaskState.RUNNING);
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it("getStatus — throws on non-2xx", async () => {
|
|
270
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: false, status: 404 }));
|
|
271
|
-
const client = new NopClient("http://nop.test");
|
|
272
|
-
await expect(client.getStatus("missing")).rejects.toThrow("404");
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it("cancel — resolves on 200", async () => {
|
|
276
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: true }));
|
|
277
|
-
const client = new NopClient("http://nop.test");
|
|
278
|
-
await expect(client.cancel("t1")).resolves.toBeUndefined();
|
|
279
|
-
expect(vi.mocked(fetch)).toHaveBeenCalledWith(
|
|
280
|
-
"http://nop.test/task/t1/cancel",
|
|
281
|
-
expect.objectContaining({ method: "POST" }),
|
|
282
|
-
);
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
it("cancel — throws on non-2xx", async () => {
|
|
286
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: false, status: 409 }));
|
|
287
|
-
const client = new NopClient("http://nop.test");
|
|
288
|
-
await expect(client.cancel("t1")).rejects.toThrow("409");
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
it("wait — returns immediately when terminal on first poll", async () => {
|
|
292
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({
|
|
293
|
-
ok: true,
|
|
294
|
-
json: () => Promise.resolve({ task_id: "t1", state: "completed" }),
|
|
295
|
-
}));
|
|
296
|
-
const client = new NopClient("http://nop.test");
|
|
297
|
-
const status = await client.wait("t1", { pollIntervalMs: 100, timeoutMs: 5000 });
|
|
298
|
-
expect(status.isTerminal).toBe(true);
|
|
299
|
-
expect(vi.mocked(fetch)).toHaveBeenCalledTimes(1);
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
it("wait — polls until terminal", async () => {
|
|
303
|
-
vi.useFakeTimers();
|
|
304
|
-
let call = 0;
|
|
305
|
-
vi.stubGlobal("fetch", vi.fn().mockImplementation(() => {
|
|
306
|
-
const state = call++ < 2 ? "running" : "completed";
|
|
307
|
-
return Promise.resolve({
|
|
308
|
-
ok: true,
|
|
309
|
-
json: () => Promise.resolve({ task_id: "t1", state }),
|
|
310
|
-
});
|
|
311
|
-
}));
|
|
312
|
-
const client = new NopClient("http://nop.test");
|
|
313
|
-
const waitP = client.wait("t1", { pollIntervalMs: 100, timeoutMs: 10_000 });
|
|
314
|
-
// Advance through the polling intervals
|
|
315
|
-
await vi.runAllTimersAsync();
|
|
316
|
-
const status = await waitP;
|
|
317
|
-
expect(status.state).toBe(TaskState.COMPLETED);
|
|
318
|
-
vi.useRealTimers();
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
it("wait — throws on timeout", async () => {
|
|
322
|
-
vi.useFakeTimers();
|
|
323
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({
|
|
324
|
-
ok: true,
|
|
325
|
-
json: () => Promise.resolve({ task_id: "t1", state: "running" }),
|
|
326
|
-
}));
|
|
327
|
-
const client = new NopClient("http://nop.test");
|
|
328
|
-
const waitP = client.wait("t1", { pollIntervalMs: 50, timeoutMs: 100 });
|
|
329
|
-
const assertion = expect(waitP).rejects.toThrow("did not complete");
|
|
330
|
-
await vi.runAllTimersAsync();
|
|
331
|
-
await assertion;
|
|
332
|
-
vi.useRealTimers();
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
it("trailing slash stripped from baseUrl", async () => {
|
|
336
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: true }));
|
|
337
|
-
const client = new NopClient("http://nop.test/");
|
|
338
|
-
await client.cancel("t1");
|
|
339
|
-
expect(vi.mocked(fetch)).toHaveBeenCalledWith(
|
|
340
|
-
"http://nop.test/task/t1/cancel",
|
|
341
|
-
expect.anything(),
|
|
342
|
-
);
|
|
343
|
-
});
|
|
344
|
-
});
|
package/tests/nwp.test.ts
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
// Copyright 2026 INNO LOTUS PTY LTD
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
5
|
-
import { QueryFrame, ActionFrame, asyncActionResponseFromDict } from "../src/nwp/frames.js";
|
|
6
|
-
import { NwpClient } from "../src/nwp/client.js";
|
|
7
|
-
import { createDefaultRegistry } from "../src/setup.js";
|
|
8
|
-
import { NpsFrameCodec, EncodingTier } from "../src/core/index.js";
|
|
9
|
-
import { AnchorFrame, CapsFrame, StreamFrame } from "../src/ncp/frames.js";
|
|
10
|
-
|
|
11
|
-
// ── QueryFrame ────────────────────────────────────────────────────────────────
|
|
12
|
-
|
|
13
|
-
describe("QueryFrame", () => {
|
|
14
|
-
it("round-trips via toDict / fromDict", () => {
|
|
15
|
-
const f = new QueryFrame(
|
|
16
|
-
"sha256:" + "a".repeat(64),
|
|
17
|
-
{ name: { $eq: "Alice" } },
|
|
18
|
-
10,
|
|
19
|
-
0,
|
|
20
|
-
[{ field: "name", dir: "asc" }],
|
|
21
|
-
["id", "name"],
|
|
22
|
-
{ vector: [0.1, 0.2], topK: 5 },
|
|
23
|
-
2,
|
|
24
|
-
);
|
|
25
|
-
const back = QueryFrame.fromDict(f.toDict());
|
|
26
|
-
expect(back.anchorRef).toBe(f.anchorRef);
|
|
27
|
-
expect(back.limit).toBe(10);
|
|
28
|
-
expect(back.offset).toBe(0);
|
|
29
|
-
expect(back.orderBy?.[0]?.field).toBe("name");
|
|
30
|
-
expect(back.fields?.[1]).toBe("name");
|
|
31
|
-
expect(back.vectorSearch?.topK).toBe(5);
|
|
32
|
-
expect(back.depth).toBe(2);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("handles all-optional constructor (empty query)", () => {
|
|
36
|
-
const f = new QueryFrame();
|
|
37
|
-
const back = QueryFrame.fromDict(f.toDict());
|
|
38
|
-
expect(back.anchorRef).toBeUndefined();
|
|
39
|
-
expect(back.limit).toBeUndefined();
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// ── ActionFrame ───────────────────────────────────────────────────────────────
|
|
44
|
-
|
|
45
|
-
describe("ActionFrame", () => {
|
|
46
|
-
it("round-trips via toDict / fromDict", () => {
|
|
47
|
-
const f = new ActionFrame(
|
|
48
|
-
"search",
|
|
49
|
-
{ q: "test" },
|
|
50
|
-
true,
|
|
51
|
-
"idem-key-1",
|
|
52
|
-
5000,
|
|
53
|
-
);
|
|
54
|
-
const back = ActionFrame.fromDict(f.toDict());
|
|
55
|
-
expect(back.actionId).toBe("search");
|
|
56
|
-
expect(back.params?.["q"]).toBe("test");
|
|
57
|
-
expect(back.async_).toBe(true);
|
|
58
|
-
expect(back.idempotencyKey).toBe("idem-key-1");
|
|
59
|
-
expect(back.timeoutMs).toBe(5000);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("defaults async to false when not provided", () => {
|
|
63
|
-
const f = new ActionFrame("do-thing");
|
|
64
|
-
const back = ActionFrame.fromDict(f.toDict());
|
|
65
|
-
expect(back.async_).toBeFalsy();
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// ── asyncActionResponseFromDict ───────────────────────────────────────────────
|
|
70
|
-
|
|
71
|
-
describe("asyncActionResponseFromDict", () => {
|
|
72
|
-
it("parses full response", () => {
|
|
73
|
-
const r = asyncActionResponseFromDict({ task_id: "t1", status: "accepted", poll_url: "/poll/t1" });
|
|
74
|
-
expect(r.taskId).toBe("t1");
|
|
75
|
-
expect(r.status).toBe("accepted");
|
|
76
|
-
expect(r.pollUrl).toBe("/poll/t1");
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("omits pollUrl when null", () => {
|
|
80
|
-
const r = asyncActionResponseFromDict({ task_id: "t2", status: "accepted", poll_url: null });
|
|
81
|
-
expect(r.pollUrl).toBeUndefined();
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
// ── NwpClient ─────────────────────────────────────────────────────────────────
|
|
86
|
-
|
|
87
|
-
describe("NwpClient", () => {
|
|
88
|
-
const registry = createDefaultRegistry();
|
|
89
|
-
const codec = new NpsFrameCodec(registry);
|
|
90
|
-
const aid = "sha256:" + "b".repeat(64);
|
|
91
|
-
const schema = { fields: [{ name: "id", type: "uint64" }] };
|
|
92
|
-
|
|
93
|
-
beforeEach(() => { vi.restoreAllMocks(); });
|
|
94
|
-
|
|
95
|
-
it("sendAnchor — POSTs and resolves on 200", async () => {
|
|
96
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: true }));
|
|
97
|
-
const client = new NwpClient("http://node.test");
|
|
98
|
-
await expect(client.sendAnchor(new AnchorFrame(aid, schema))).resolves.toBeUndefined();
|
|
99
|
-
expect(vi.mocked(fetch)).toHaveBeenCalledWith(
|
|
100
|
-
"http://node.test/anchor",
|
|
101
|
-
expect.objectContaining({ method: "POST" }),
|
|
102
|
-
);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("sendAnchor — throws on non-2xx", async () => {
|
|
106
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: false, status: 503 }));
|
|
107
|
-
const client = new NwpClient("http://node.test");
|
|
108
|
-
await expect(client.sendAnchor(new AnchorFrame(aid, schema))).rejects.toThrow("503");
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("query — decodes CapsFrame response", async () => {
|
|
112
|
-
const capsFrame = new CapsFrame(aid, 1, [{ id: 42 }]);
|
|
113
|
-
const wire = codec.encode(capsFrame);
|
|
114
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({
|
|
115
|
-
ok: true,
|
|
116
|
-
arrayBuffer: () => Promise.resolve(wire.buffer),
|
|
117
|
-
}));
|
|
118
|
-
const client = new NwpClient("http://node.test");
|
|
119
|
-
const result = await client.query(new QueryFrame(aid));
|
|
120
|
-
expect(result).toBeInstanceOf(CapsFrame);
|
|
121
|
-
expect(result.count).toBe(1);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("query — throws when response is not CapsFrame", async () => {
|
|
125
|
-
const anchorFrame = new AnchorFrame(aid, schema);
|
|
126
|
-
const wire = codec.encode(anchorFrame);
|
|
127
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({
|
|
128
|
-
ok: true,
|
|
129
|
-
arrayBuffer: () => Promise.resolve(wire.buffer),
|
|
130
|
-
}));
|
|
131
|
-
const client = new NwpClient("http://node.test");
|
|
132
|
-
await expect(client.query(new QueryFrame(aid))).rejects.toThrow(TypeError);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it("query — throws on non-2xx", async () => {
|
|
136
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: false, status: 404 }));
|
|
137
|
-
const client = new NwpClient("http://node.test");
|
|
138
|
-
await expect(client.query(new QueryFrame(aid))).rejects.toThrow("404");
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("invoke — sync NPS frame response", async () => {
|
|
142
|
-
const capsFrame = new CapsFrame(aid, 0, []);
|
|
143
|
-
const wire = codec.encode(capsFrame);
|
|
144
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({
|
|
145
|
-
ok: true,
|
|
146
|
-
headers: { get: () => "application/x-nps-frame" },
|
|
147
|
-
arrayBuffer: () => Promise.resolve(wire.buffer),
|
|
148
|
-
}));
|
|
149
|
-
const client = new NwpClient("http://node.test");
|
|
150
|
-
const result = await client.invoke(new ActionFrame("list"));
|
|
151
|
-
expect(result).toBeInstanceOf(CapsFrame);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("invoke — async response returns AsyncActionResponse", async () => {
|
|
155
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({
|
|
156
|
-
ok: true,
|
|
157
|
-
json: () => Promise.resolve({ task_id: "t99", status: "queued" }),
|
|
158
|
-
}));
|
|
159
|
-
const client = new NwpClient("http://node.test");
|
|
160
|
-
const result = await client.invoke(new ActionFrame("heavy", {}, true)) as { taskId: string };
|
|
161
|
-
expect(result.taskId).toBe("t99");
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it("invoke — sync JSON response", async () => {
|
|
165
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({
|
|
166
|
-
ok: true,
|
|
167
|
-
headers: { get: () => "application/json" },
|
|
168
|
-
json: () => Promise.resolve({ result: "ok" }),
|
|
169
|
-
}));
|
|
170
|
-
const client = new NwpClient("http://node.test");
|
|
171
|
-
const result = await client.invoke(new ActionFrame("ping")) as { result: string };
|
|
172
|
-
expect(result.result).toBe("ok");
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it("invoke — throws on non-2xx", async () => {
|
|
176
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: false, status: 500 }));
|
|
177
|
-
const client = new NwpClient("http://node.test");
|
|
178
|
-
await expect(client.invoke(new ActionFrame("ping"))).rejects.toThrow("500");
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("stream — yields StreamFrames and stops at isLast", async () => {
|
|
182
|
-
const s0 = new StreamFrame("s1", 0, false, [{ id: 1 }]);
|
|
183
|
-
const s1 = new StreamFrame("s1", 1, true, [{ id: 2 }]);
|
|
184
|
-
const w0 = codec.encode(s0);
|
|
185
|
-
const w1 = codec.encode(s1);
|
|
186
|
-
|
|
187
|
-
async function* mockBody() { yield w0; yield w1; }
|
|
188
|
-
|
|
189
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: true, body: mockBody() }));
|
|
190
|
-
const client = new NwpClient("http://node.test");
|
|
191
|
-
const frames: StreamFrame[] = [];
|
|
192
|
-
for await (const f of client.stream(new QueryFrame(aid))) {
|
|
193
|
-
frames.push(f);
|
|
194
|
-
}
|
|
195
|
-
expect(frames).toHaveLength(2);
|
|
196
|
-
expect(frames[0]!.seq).toBe(0);
|
|
197
|
-
expect(frames[1]!.isLast).toBe(true);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it("stream — throws when chunk is not a StreamFrame", async () => {
|
|
201
|
-
const anchor = new AnchorFrame(aid, schema);
|
|
202
|
-
const wire = codec.encode(anchor);
|
|
203
|
-
async function* mockBody() { yield wire; }
|
|
204
|
-
|
|
205
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: true, body: mockBody() }));
|
|
206
|
-
const client = new NwpClient("http://node.test");
|
|
207
|
-
await expect(async () => {
|
|
208
|
-
for await (const _ of client.stream(new QueryFrame(aid))) { /* consume */ }
|
|
209
|
-
}).rejects.toThrow(TypeError);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("stream — returns immediately when body is null", async () => {
|
|
213
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: true, body: null }));
|
|
214
|
-
const client = new NwpClient("http://node.test");
|
|
215
|
-
const frames: StreamFrame[] = [];
|
|
216
|
-
for await (const f of client.stream(new QueryFrame(aid))) frames.push(f);
|
|
217
|
-
expect(frames).toHaveLength(0);
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it("stream — throws on non-2xx", async () => {
|
|
221
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: false, status: 400 }));
|
|
222
|
-
const client = new NwpClient("http://node.test");
|
|
223
|
-
await expect(async () => {
|
|
224
|
-
for await (const _ of client.stream(new QueryFrame(aid))) { /* consume */ }
|
|
225
|
-
}).rejects.toThrow("400");
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it("trailing slash stripped from baseUrl", async () => {
|
|
229
|
-
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: true }));
|
|
230
|
-
const client = new NwpClient("http://node.test/");
|
|
231
|
-
await client.sendAnchor(new AnchorFrame(aid, schema));
|
|
232
|
-
expect(vi.mocked(fetch)).toHaveBeenCalledWith(
|
|
233
|
-
"http://node.test/anchor",
|
|
234
|
-
expect.anything(),
|
|
235
|
-
);
|
|
236
|
-
});
|
|
237
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"strict": true,
|
|
4
|
-
"target": "ES2022",
|
|
5
|
-
"module": "NodeNext",
|
|
6
|
-
"moduleResolution": "NodeNext",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"sourceMap": true,
|
|
10
|
-
"outDir": "dist",
|
|
11
|
-
"rootDir": "src",
|
|
12
|
-
"esModuleInterop": true,
|
|
13
|
-
"skipLibCheck": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true,
|
|
15
|
-
"resolveJsonModule": true,
|
|
16
|
-
"isolatedModules": true
|
|
17
|
-
},
|
|
18
|
-
"include": ["src/**/*.ts"],
|
|
19
|
-
"exclude": ["node_modules", "dist", "tests"]
|
|
20
|
-
}
|
package/tsup.config.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "tsup";
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
entry: {
|
|
5
|
-
index: "src/index.ts",
|
|
6
|
-
"core/index": "src/core/index.ts",
|
|
7
|
-
"ncp/index": "src/ncp/index.ts",
|
|
8
|
-
"nwp/index": "src/nwp/index.ts",
|
|
9
|
-
"nip/index": "src/nip/index.ts",
|
|
10
|
-
"ndp/index": "src/ndp/index.ts",
|
|
11
|
-
"nop/index": "src/nop/index.ts",
|
|
12
|
-
},
|
|
13
|
-
format: ["esm", "cjs"],
|
|
14
|
-
dts: true,
|
|
15
|
-
sourcemap: true,
|
|
16
|
-
clean: true,
|
|
17
|
-
splitting: false,
|
|
18
|
-
treeshake: true,
|
|
19
|
-
target: "es2022",
|
|
20
|
-
});
|
package/vitest.config.ts
DELETED