@automate.ax/codec 0.86.2 → 0.87.1

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/dist/rpc.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import type { StandardRPCCustomJsonSerializer } from "@orpc/client/standard";
2
+ import * as z from "zod";
3
+ import { type Encodable } from "./index.js";
4
+ /** Opaque codec bytes carried through oRPC's native Blob transport. */
5
+ export declare class CodecEnvelope {
6
+ readonly blob: Blob;
7
+ /**
8
+ * Creates an opaque encoded value.
9
+ *
10
+ * @param blob - Msgpack bytes represented as a transport-safe Blob.
11
+ */
12
+ constructor(blob: Blob);
13
+ }
14
+ /** Schema for one opaque codec transport value. */
15
+ export declare const codecEnvelopeSchema: z.ZodCustom<CodecEnvelope, CodecEnvelope>;
16
+ /**
17
+ * Wraps already encoded codec bytes without decoding or re-encoding them.
18
+ *
19
+ * @param bytes - Exact persisted or freshly encoded codec bytes.
20
+ */
21
+ export declare function createCodecEnvelope(bytes: Uint8Array): CodecEnvelope;
22
+ /**
23
+ * Reads the exact codec bytes carried by an envelope.
24
+ *
25
+ * @param envelope - Opaque bytes received from oRPC.
26
+ */
27
+ export declare function readCodecEnvelope(envelope: CodecEnvelope): Promise<Uint8Array<ArrayBuffer>>;
28
+ /**
29
+ * Encodes one runtime value before it crosses an oRPC boundary.
30
+ *
31
+ * @param value - Codec-supported value to transport.
32
+ */
33
+ export declare function encodeCodecEnvelope(value: Encodable): Promise<CodecEnvelope>;
34
+ /**
35
+ * Decodes one runtime value after it crosses an oRPC boundary.
36
+ *
37
+ * @param envelope - Opaque bytes received from oRPC.
38
+ */
39
+ export declare function decodeCodecEnvelope(envelope: CodecEnvelope): Promise<Encodable>;
40
+ /** Symmetric oRPC serializer for opaque codec envelopes. */
41
+ export declare const codecEnvelopeSerializer: StandardRPCCustomJsonSerializer;
package/dist/rpc.js ADDED
@@ -0,0 +1,60 @@
1
+ import * as z from "zod";
2
+ import { decode, encode } from "./index.js";
3
+ /** Opaque codec bytes carried through oRPC's native Blob transport. */
4
+ export class CodecEnvelope {
5
+ blob;
6
+ /**
7
+ * Creates an opaque encoded value.
8
+ *
9
+ * @param blob - Msgpack bytes represented as a transport-safe Blob.
10
+ */
11
+ constructor(blob) {
12
+ this.blob = blob;
13
+ }
14
+ }
15
+ const BLOB_SCHEMA = z.instanceof(Blob);
16
+ /** Schema for one opaque codec transport value. */
17
+ export const codecEnvelopeSchema = z
18
+ .instanceof(CodecEnvelope)
19
+ .refine((envelope) => envelope.blob instanceof Blob, {
20
+ message: "Codec envelope must contain Blob bytes",
21
+ });
22
+ /**
23
+ * Wraps already encoded codec bytes without decoding or re-encoding them.
24
+ *
25
+ * @param bytes - Exact persisted or freshly encoded codec bytes.
26
+ */
27
+ export function createCodecEnvelope(bytes) {
28
+ return new CodecEnvelope(new Blob([Uint8Array.from(bytes)]));
29
+ }
30
+ /**
31
+ * Reads the exact codec bytes carried by an envelope.
32
+ *
33
+ * @param envelope - Opaque bytes received from oRPC.
34
+ */
35
+ export async function readCodecEnvelope(envelope) {
36
+ return new Uint8Array(await envelope.blob.arrayBuffer());
37
+ }
38
+ /**
39
+ * Encodes one runtime value before it crosses an oRPC boundary.
40
+ *
41
+ * @param value - Codec-supported value to transport.
42
+ */
43
+ export async function encodeCodecEnvelope(value) {
44
+ return createCodecEnvelope(await encode(value));
45
+ }
46
+ /**
47
+ * Decodes one runtime value after it crosses an oRPC boundary.
48
+ *
49
+ * @param envelope - Opaque bytes received from oRPC.
50
+ */
51
+ export async function decodeCodecEnvelope(envelope) {
52
+ return await decode(await readCodecEnvelope(envelope));
53
+ }
54
+ /** Symmetric oRPC serializer for opaque codec envelopes. */
55
+ export const codecEnvelopeSerializer = {
56
+ type: 21,
57
+ condition: (data) => data instanceof CodecEnvelope,
58
+ serialize: (data) => data.blob,
59
+ deserialize: (blob) => new CodecEnvelope(BLOB_SCHEMA.parse(blob)),
60
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automate.ax/codec",
3
- "version": "0.86.2",
3
+ "version": "0.87.1",
4
4
  "description": "Msgpack-based encoding helpers for Automate.ax runtime data.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -20,6 +20,7 @@
20
20
  "exports": {
21
21
  ".": "./src/index.ts",
22
22
  "./http": "./src/http.ts",
23
+ "./rpc": "./src/rpc.ts",
23
24
  "./*": "./src/*"
24
25
  },
25
26
  "cjs": false,
@@ -38,6 +39,11 @@
38
39
  "types": "./dist/http.d.ts",
39
40
  "default": "./dist/http.js"
40
41
  },
42
+ "./rpc": {
43
+ "bun": "./src/rpc.ts",
44
+ "types": "./dist/rpc.d.ts",
45
+ "default": "./dist/rpc.js"
46
+ },
41
47
  "./*": {
42
48
  "bun": "./src/*",
43
49
  "types": "./dist/*",
@@ -74,6 +80,7 @@
74
80
  "zshy": "^0.7.2"
75
81
  },
76
82
  "dependencies": {
83
+ "@orpc/client": "1.15.0",
77
84
  "@remix-run/multipart-parser": "^0.16.4",
78
85
  "@standard-schema/spec": "^1.1.0",
79
86
  "content-type": "^3.0.0",
package/src/rpc.ts ADDED
@@ -0,0 +1,66 @@
1
+ import type { StandardRPCCustomJsonSerializer } from "@orpc/client/standard"
2
+ import * as z from "zod"
3
+ import { decode, encode, type Encodable } from "./index"
4
+
5
+ /** Opaque codec bytes carried through oRPC's native Blob transport. */
6
+ export class CodecEnvelope {
7
+ /**
8
+ * Creates an opaque encoded value.
9
+ *
10
+ * @param blob - Msgpack bytes represented as a transport-safe Blob.
11
+ */
12
+ constructor(public readonly blob: Blob) {}
13
+ }
14
+
15
+ const BLOB_SCHEMA = z.instanceof(Blob)
16
+
17
+ /** Schema for one opaque codec transport value. */
18
+ export const codecEnvelopeSchema = z
19
+ .instanceof(CodecEnvelope)
20
+ .refine((envelope) => envelope.blob instanceof Blob, {
21
+ message: "Codec envelope must contain Blob bytes",
22
+ })
23
+
24
+ /**
25
+ * Wraps already encoded codec bytes without decoding or re-encoding them.
26
+ *
27
+ * @param bytes - Exact persisted or freshly encoded codec bytes.
28
+ */
29
+ export function createCodecEnvelope(bytes: Uint8Array) {
30
+ return new CodecEnvelope(new Blob([Uint8Array.from(bytes)]))
31
+ }
32
+
33
+ /**
34
+ * Reads the exact codec bytes carried by an envelope.
35
+ *
36
+ * @param envelope - Opaque bytes received from oRPC.
37
+ */
38
+ export async function readCodecEnvelope(envelope: CodecEnvelope) {
39
+ return new Uint8Array(await envelope.blob.arrayBuffer())
40
+ }
41
+
42
+ /**
43
+ * Encodes one runtime value before it crosses an oRPC boundary.
44
+ *
45
+ * @param value - Codec-supported value to transport.
46
+ */
47
+ export async function encodeCodecEnvelope(value: Encodable) {
48
+ return createCodecEnvelope(await encode(value))
49
+ }
50
+
51
+ /**
52
+ * Decodes one runtime value after it crosses an oRPC boundary.
53
+ *
54
+ * @param envelope - Opaque bytes received from oRPC.
55
+ */
56
+ export async function decodeCodecEnvelope(envelope: CodecEnvelope) {
57
+ return await decode(await readCodecEnvelope(envelope))
58
+ }
59
+
60
+ /** Symmetric oRPC serializer for opaque codec envelopes. */
61
+ export const codecEnvelopeSerializer: StandardRPCCustomJsonSerializer = {
62
+ type: 21,
63
+ condition: (data) => data instanceof CodecEnvelope,
64
+ serialize: (data) => data.blob,
65
+ deserialize: (blob) => new CodecEnvelope(BLOB_SCHEMA.parse(blob)),
66
+ }