@parsrun/service 0.1.29 → 0.1.30
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/client.d.ts +30 -3
- package/dist/client.js +1 -0
- package/dist/client.js.map +1 -1
- package/dist/define.d.ts +29 -6
- package/dist/define.js.map +1 -1
- package/dist/events/index.d.ts +95 -15
- package/dist/events/index.js.map +1 -1
- package/dist/{handler-CmiDUWZv.d.ts → handler-eCIZLODd.d.ts} +45 -3
- package/dist/{index-CVOAoJjZ.d.ts → index-reEpIe1R.d.ts} +82 -11
- package/dist/index.d.ts +53 -9
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/resilience/index.d.ts +76 -9
- package/dist/resilience/index.js +1 -0
- package/dist/resilience/index.js.map +1 -1
- package/dist/rpc/index.d.ts +3 -3
- package/dist/rpc/index.js +1 -0
- package/dist/rpc/index.js.map +1 -1
- package/dist/serialization/index.d.ts +27 -2
- package/dist/serialization/index.js.map +1 -1
- package/dist/{server-DFE8n2Sx.d.ts → server-BB9AbnkP.d.ts} +50 -6
- package/dist/tracing/index.d.ts +94 -15
- package/dist/tracing/index.js.map +1 -1
- package/dist/transports/cloudflare/index.d.ts +72 -10
- package/dist/transports/cloudflare/index.js.map +1 -1
- package/dist/{types-n4LLSPQU.d.ts → types-DHZaZwAt.d.ts} +51 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/serialization/index.ts"],"sourcesContent":["/**\n * @parsrun/service - Serialization\n * JSON and MessagePack serializers\n */\n\n// ============================================================================\n// SERIALIZER INTERFACE\n// ============================================================================\n\n/**\n * Serializer interface for encoding/decoding data\n */\nexport interface Serializer {\n /** Encode data to string or buffer */\n encode(data: unknown): string | ArrayBuffer;\n /** Decode string or buffer to data */\n decode(raw: string | ArrayBuffer): unknown;\n /** Content type for HTTP headers */\n contentType: string;\n}\n\n// ============================================================================\n// JSON SERIALIZER\n// ============================================================================\n\n/**\n * JSON serializer (default)\n */\nexport const jsonSerializer: Serializer = {\n encode(data: unknown): string {\n return JSON.stringify(data);\n },\n\n decode(raw: string | ArrayBuffer): unknown {\n if (raw instanceof ArrayBuffer) {\n const decoder = new TextDecoder();\n return JSON.parse(decoder.decode(raw));\n }\n return JSON.parse(raw);\n },\n\n contentType: \"application/json\",\n};\n\n// ============================================================================\n// MESSAGEPACK SERIALIZER (Lightweight implementation)\n// ============================================================================\n\n/**\n * Lightweight MessagePack encoder\n * Supports: null, boolean, number, string, array, object\n */\nfunction msgpackEncode(value: unknown): Uint8Array {\n const parts: Uint8Array[] = [];\n\n function encode(val: unknown): void {\n if (val === null || val === undefined) {\n parts.push(new Uint8Array([0xc0])); // nil\n return;\n }\n\n if (typeof val === \"boolean\") {\n parts.push(new Uint8Array([val ? 0xc3 : 0xc2]));\n return;\n }\n\n if (typeof val === \"number\") {\n if (Number.isInteger(val)) {\n if (val >= 0 && val <= 127) {\n // positive fixint\n parts.push(new Uint8Array([val]));\n } else if (val < 0 && val >= -32) {\n // negative fixint\n parts.push(new Uint8Array([val & 0xff]));\n } else if (val >= 0 && val <= 0xff) {\n // uint8\n parts.push(new Uint8Array([0xcc, val]));\n } else if (val >= 0 && val <= 0xffff) {\n // uint16\n parts.push(new Uint8Array([0xcd, (val >> 8) & 0xff, val & 0xff]));\n } else if (val >= 0 && val <= 0xffffffff) {\n // uint32\n parts.push(\n new Uint8Array([\n 0xce,\n (val >> 24) & 0xff,\n (val >> 16) & 0xff,\n (val >> 8) & 0xff,\n val & 0xff,\n ])\n );\n } else if (val >= -128 && val <= 127) {\n // int8\n parts.push(new Uint8Array([0xd0, val & 0xff]));\n } else if (val >= -32768 && val <= 32767) {\n // int16\n parts.push(new Uint8Array([0xd1, (val >> 8) & 0xff, val & 0xff]));\n } else if (val >= -2147483648 && val <= 2147483647) {\n // int32\n parts.push(\n new Uint8Array([\n 0xd2,\n (val >> 24) & 0xff,\n (val >> 16) & 0xff,\n (val >> 8) & 0xff,\n val & 0xff,\n ])\n );\n } else {\n // Fall back to float64 for large integers\n const buffer = new ArrayBuffer(9);\n const view = new DataView(buffer);\n view.setUint8(0, 0xcb);\n view.setFloat64(1, val, false);\n parts.push(new Uint8Array(buffer));\n }\n } else {\n // float64\n const buffer = new ArrayBuffer(9);\n const view = new DataView(buffer);\n view.setUint8(0, 0xcb);\n view.setFloat64(1, val, false);\n parts.push(new Uint8Array(buffer));\n }\n return;\n }\n\n if (typeof val === \"string\") {\n const encoded = new TextEncoder().encode(val);\n const len = encoded.length;\n\n if (len <= 31) {\n // fixstr\n parts.push(new Uint8Array([0xa0 | len]));\n } else if (len <= 0xff) {\n // str8\n parts.push(new Uint8Array([0xd9, len]));\n } else if (len <= 0xffff) {\n // str16\n parts.push(new Uint8Array([0xda, (len >> 8) & 0xff, len & 0xff]));\n } else {\n // str32\n parts.push(\n new Uint8Array([\n 0xdb,\n (len >> 24) & 0xff,\n (len >> 16) & 0xff,\n (len >> 8) & 0xff,\n len & 0xff,\n ])\n );\n }\n parts.push(encoded);\n return;\n }\n\n if (Array.isArray(val)) {\n const len = val.length;\n\n if (len <= 15) {\n // fixarray\n parts.push(new Uint8Array([0x90 | len]));\n } else if (len <= 0xffff) {\n // array16\n parts.push(new Uint8Array([0xdc, (len >> 8) & 0xff, len & 0xff]));\n } else {\n // array32\n parts.push(\n new Uint8Array([\n 0xdd,\n (len >> 24) & 0xff,\n (len >> 16) & 0xff,\n (len >> 8) & 0xff,\n len & 0xff,\n ])\n );\n }\n\n for (const item of val) {\n encode(item);\n }\n return;\n }\n\n if (typeof val === \"object\") {\n const keys = Object.keys(val as object);\n const len = keys.length;\n\n if (len <= 15) {\n // fixmap\n parts.push(new Uint8Array([0x80 | len]));\n } else if (len <= 0xffff) {\n // map16\n parts.push(new Uint8Array([0xde, (len >> 8) & 0xff, len & 0xff]));\n } else {\n // map32\n parts.push(\n new Uint8Array([\n 0xdf,\n (len >> 24) & 0xff,\n (len >> 16) & 0xff,\n (len >> 8) & 0xff,\n len & 0xff,\n ])\n );\n }\n\n for (const key of keys) {\n encode(key);\n encode((val as Record<string, unknown>)[key]);\n }\n return;\n }\n\n // Unsupported type - encode as null\n parts.push(new Uint8Array([0xc0]));\n }\n\n encode(value);\n\n // Merge all parts\n const totalLength = parts.reduce((sum, p) => sum + p.length, 0);\n const result = new Uint8Array(totalLength);\n let offset = 0;\n for (const part of parts) {\n result.set(part, offset);\n offset += part.length;\n }\n\n return result;\n}\n\n/**\n * Lightweight MessagePack decoder\n */\nfunction msgpackDecode(buffer: Uint8Array): unknown {\n let offset = 0;\n\n function decode(): unknown {\n if (offset >= buffer.length) {\n throw new Error(\"Unexpected end of buffer\");\n }\n\n const byte = buffer[offset++]!;\n\n // Positive fixint (0x00 - 0x7f)\n if (byte <= 0x7f) {\n return byte;\n }\n\n // Negative fixint (0xe0 - 0xff)\n if (byte >= 0xe0) {\n return byte - 256;\n }\n\n // Fixmap (0x80 - 0x8f)\n if (byte >= 0x80 && byte <= 0x8f) {\n const len = byte - 0x80;\n const result: Record<string, unknown> = {};\n for (let i = 0; i < len; i++) {\n const key = decode() as string;\n result[key] = decode();\n }\n return result;\n }\n\n // Fixarray (0x90 - 0x9f)\n if (byte >= 0x90 && byte <= 0x9f) {\n const len = byte - 0x90;\n const result: unknown[] = [];\n for (let i = 0; i < len; i++) {\n result.push(decode());\n }\n return result;\n }\n\n // Fixstr (0xa0 - 0xbf)\n if (byte >= 0xa0 && byte <= 0xbf) {\n const len = byte - 0xa0;\n const str = new TextDecoder().decode(buffer.subarray(offset, offset + len));\n offset += len;\n return str;\n }\n\n switch (byte) {\n case 0xc0: // nil\n return null;\n case 0xc2: // false\n return false;\n case 0xc3: // true\n return true;\n\n case 0xcc: // uint8\n return buffer[offset++];\n case 0xcd: // uint16\n return (buffer[offset++]! << 8) | buffer[offset++]!;\n case 0xce: // uint32\n return (\n ((buffer[offset++]! << 24) >>> 0) +\n (buffer[offset++]! << 16) +\n (buffer[offset++]! << 8) +\n buffer[offset++]!\n );\n\n case 0xd0: // int8\n {\n const val = buffer[offset++]!;\n return val > 127 ? val - 256 : val;\n }\n case 0xd1: // int16\n {\n const val = (buffer[offset++]! << 8) | buffer[offset++]!;\n return val > 32767 ? val - 65536 : val;\n }\n case 0xd2: // int32\n {\n const val =\n (buffer[offset++]! << 24) |\n (buffer[offset++]! << 16) |\n (buffer[offset++]! << 8) |\n buffer[offset++]!;\n return val;\n }\n\n case 0xcb: // float64\n {\n const view = new DataView(buffer.buffer, buffer.byteOffset + offset, 8);\n offset += 8;\n return view.getFloat64(0, false);\n }\n\n case 0xd9: // str8\n {\n const len = buffer[offset++]!;\n const str = new TextDecoder().decode(buffer.subarray(offset, offset + len));\n offset += len;\n return str;\n }\n case 0xda: // str16\n {\n const len = (buffer[offset++]! << 8) | buffer[offset++]!;\n const str = new TextDecoder().decode(buffer.subarray(offset, offset + len));\n offset += len;\n return str;\n }\n case 0xdb: // str32\n {\n const len =\n (buffer[offset++]! << 24) |\n (buffer[offset++]! << 16) |\n (buffer[offset++]! << 8) |\n buffer[offset++]!;\n const str = new TextDecoder().decode(buffer.subarray(offset, offset + len));\n offset += len;\n return str;\n }\n\n case 0xdc: // array16\n {\n const len = (buffer[offset++]! << 8) | buffer[offset++]!;\n const result: unknown[] = [];\n for (let i = 0; i < len; i++) {\n result.push(decode());\n }\n return result;\n }\n case 0xdd: // array32\n {\n const len =\n (buffer[offset++]! << 24) |\n (buffer[offset++]! << 16) |\n (buffer[offset++]! << 8) |\n buffer[offset++]!;\n const result: unknown[] = [];\n for (let i = 0; i < len; i++) {\n result.push(decode());\n }\n return result;\n }\n\n case 0xde: // map16\n {\n const len = (buffer[offset++]! << 8) | buffer[offset++]!;\n const result: Record<string, unknown> = {};\n for (let i = 0; i < len; i++) {\n const key = decode() as string;\n result[key] = decode();\n }\n return result;\n }\n case 0xdf: // map32\n {\n const len =\n (buffer[offset++]! << 24) |\n (buffer[offset++]! << 16) |\n (buffer[offset++]! << 8) |\n buffer[offset++]!;\n const result: Record<string, unknown> = {};\n for (let i = 0; i < len; i++) {\n const key = decode() as string;\n result[key] = decode();\n }\n return result;\n }\n\n default:\n throw new Error(`Unknown MessagePack type: 0x${byte.toString(16)}`);\n }\n }\n\n return decode();\n}\n\n/**\n * MessagePack serializer\n */\nexport const msgpackSerializer: Serializer = {\n encode(data: unknown): ArrayBuffer {\n const encoded = msgpackEncode(data);\n // Create a new ArrayBuffer with the exact bytes from the Uint8Array\n const buffer = new ArrayBuffer(encoded.byteLength);\n new Uint8Array(buffer).set(encoded);\n return buffer;\n },\n\n decode(raw: string | ArrayBuffer): unknown {\n if (typeof raw === \"string\") {\n // If string is passed, assume it's base64 encoded\n const binary = atob(raw);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return msgpackDecode(bytes);\n }\n return msgpackDecode(new Uint8Array(raw));\n },\n\n contentType: \"application/msgpack\",\n};\n\n// ============================================================================\n// SERIALIZER FACTORY\n// ============================================================================\n\n/**\n * Get serializer by format name\n */\nexport function getSerializer(format: \"json\" | \"msgpack\"): Serializer {\n switch (format) {\n case \"json\":\n return jsonSerializer;\n case \"msgpack\":\n return msgpackSerializer;\n default:\n return jsonSerializer;\n }\n}\n\n/**\n * Create a custom serializer\n */\nexport function createSerializer(options: {\n encode: (data: unknown) => string | ArrayBuffer;\n decode: (raw: string | ArrayBuffer) => unknown;\n contentType: string;\n}): Serializer {\n return options;\n}\n"],"mappings":";AA4BO,IAAM,iBAA6B;AAAA,EACxC,OAAO,MAAuB;AAC5B,WAAO,KAAK,UAAU,IAAI;AAAA,EAC5B;AAAA,EAEA,OAAO,KAAoC;AACzC,QAAI,eAAe,aAAa;AAC9B,YAAM,UAAU,IAAI,YAAY;AAChC,aAAO,KAAK,MAAM,QAAQ,OAAO,GAAG,CAAC;AAAA,IACvC;AACA,WAAO,KAAK,MAAM,GAAG;AAAA,EACvB;AAAA,EAEA,aAAa;AACf;AAUA,SA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AO;AAChB;AAKO,IAAM,oBAAgC;AAAA,EAC3C,OAAO,MAA4B;AACjC,UAAM,UAAU,cAAc,IAAI;AAElC,UAAM,SAAS,IAAI,YAAY,QAAQ,UAAU;AACjD,QAAI,WAAW,MAAM,EAAE,IAAI,OAAO;AAClC,WAAO;AAAA,EACT;AAAA,EAEA,OAAO,KAAoC;AACzC,QAAI,OAAO,QAAQ,UAAU;AAE3B,YAAM,SAAS,KAAK,GAAG;AACvB,YAAM,QAAQ,IAAI,WAAW,OAAO,MAAM;AAC1C,eAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,cAAM,CAAC,IAAI,OAAO,WAAW,CAAC;AAAA,MAChC;AACA,aAAO,cAAc,KAAK;AAAA,IAC5B;AACA,WAAO,cAAc,IAAI,WAAW,GAAG,CAAC;AAAA,EAC1C;AAAA,EAEA,aAAa;AACf;AASO,SAAS,cAAc,QAAwC;AACpE,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAKO,SAAS,iBAAiB,SAIlB;AACb,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/serialization/index.ts"],"sourcesContent":["/**\n * @parsrun/service - Serialization\n * JSON and MessagePack serializers\n */\n\n// ============================================================================\n// SERIALIZER INTERFACE\n// ============================================================================\n\n/**\n * Serializer interface for encoding/decoding data\n */\nexport interface Serializer {\n /** Encode data to string or buffer */\n encode(data: unknown): string | ArrayBuffer;\n /** Decode string or buffer to data */\n decode(raw: string | ArrayBuffer): unknown;\n /** Content type for HTTP headers */\n contentType: string;\n}\n\n// ============================================================================\n// JSON SERIALIZER\n// ============================================================================\n\n/**\n * JSON serializer (default)\n */\nexport const jsonSerializer: Serializer = {\n encode(data: unknown): string {\n return JSON.stringify(data);\n },\n\n decode(raw: string | ArrayBuffer): unknown {\n if (raw instanceof ArrayBuffer) {\n const decoder = new TextDecoder();\n return JSON.parse(decoder.decode(raw));\n }\n return JSON.parse(raw);\n },\n\n contentType: \"application/json\",\n};\n\n// ============================================================================\n// MESSAGEPACK SERIALIZER (Lightweight implementation)\n// ============================================================================\n\n/**\n * Lightweight MessagePack encoder\n * Supports: null, boolean, number, string, array, object\n */\nfunction msgpackEncode(value: unknown): Uint8Array {\n const parts: Uint8Array[] = [];\n\n function encode(val: unknown): void {\n if (val === null || val === undefined) {\n parts.push(new Uint8Array([0xc0])); // nil\n return;\n }\n\n if (typeof val === \"boolean\") {\n parts.push(new Uint8Array([val ? 0xc3 : 0xc2]));\n return;\n }\n\n if (typeof val === \"number\") {\n if (Number.isInteger(val)) {\n if (val >= 0 && val <= 127) {\n // positive fixint\n parts.push(new Uint8Array([val]));\n } else if (val < 0 && val >= -32) {\n // negative fixint\n parts.push(new Uint8Array([val & 0xff]));\n } else if (val >= 0 && val <= 0xff) {\n // uint8\n parts.push(new Uint8Array([0xcc, val]));\n } else if (val >= 0 && val <= 0xffff) {\n // uint16\n parts.push(new Uint8Array([0xcd, (val >> 8) & 0xff, val & 0xff]));\n } else if (val >= 0 && val <= 0xffffffff) {\n // uint32\n parts.push(\n new Uint8Array([\n 0xce,\n (val >> 24) & 0xff,\n (val >> 16) & 0xff,\n (val >> 8) & 0xff,\n val & 0xff,\n ])\n );\n } else if (val >= -128 && val <= 127) {\n // int8\n parts.push(new Uint8Array([0xd0, val & 0xff]));\n } else if (val >= -32768 && val <= 32767) {\n // int16\n parts.push(new Uint8Array([0xd1, (val >> 8) & 0xff, val & 0xff]));\n } else if (val >= -2147483648 && val <= 2147483647) {\n // int32\n parts.push(\n new Uint8Array([\n 0xd2,\n (val >> 24) & 0xff,\n (val >> 16) & 0xff,\n (val >> 8) & 0xff,\n val & 0xff,\n ])\n );\n } else {\n // Fall back to float64 for large integers\n const buffer = new ArrayBuffer(9);\n const view = new DataView(buffer);\n view.setUint8(0, 0xcb);\n view.setFloat64(1, val, false);\n parts.push(new Uint8Array(buffer));\n }\n } else {\n // float64\n const buffer = new ArrayBuffer(9);\n const view = new DataView(buffer);\n view.setUint8(0, 0xcb);\n view.setFloat64(1, val, false);\n parts.push(new Uint8Array(buffer));\n }\n return;\n }\n\n if (typeof val === \"string\") {\n const encoded = new TextEncoder().encode(val);\n const len = encoded.length;\n\n if (len <= 31) {\n // fixstr\n parts.push(new Uint8Array([0xa0 | len]));\n } else if (len <= 0xff) {\n // str8\n parts.push(new Uint8Array([0xd9, len]));\n } else if (len <= 0xffff) {\n // str16\n parts.push(new Uint8Array([0xda, (len >> 8) & 0xff, len & 0xff]));\n } else {\n // str32\n parts.push(\n new Uint8Array([\n 0xdb,\n (len >> 24) & 0xff,\n (len >> 16) & 0xff,\n (len >> 8) & 0xff,\n len & 0xff,\n ])\n );\n }\n parts.push(encoded);\n return;\n }\n\n if (Array.isArray(val)) {\n const len = val.length;\n\n if (len <= 15) {\n // fixarray\n parts.push(new Uint8Array([0x90 | len]));\n } else if (len <= 0xffff) {\n // array16\n parts.push(new Uint8Array([0xdc, (len >> 8) & 0xff, len & 0xff]));\n } else {\n // array32\n parts.push(\n new Uint8Array([\n 0xdd,\n (len >> 24) & 0xff,\n (len >> 16) & 0xff,\n (len >> 8) & 0xff,\n len & 0xff,\n ])\n );\n }\n\n for (const item of val) {\n encode(item);\n }\n return;\n }\n\n if (typeof val === \"object\") {\n const keys = Object.keys(val as object);\n const len = keys.length;\n\n if (len <= 15) {\n // fixmap\n parts.push(new Uint8Array([0x80 | len]));\n } else if (len <= 0xffff) {\n // map16\n parts.push(new Uint8Array([0xde, (len >> 8) & 0xff, len & 0xff]));\n } else {\n // map32\n parts.push(\n new Uint8Array([\n 0xdf,\n (len >> 24) & 0xff,\n (len >> 16) & 0xff,\n (len >> 8) & 0xff,\n len & 0xff,\n ])\n );\n }\n\n for (const key of keys) {\n encode(key);\n encode((val as Record<string, unknown>)[key]);\n }\n return;\n }\n\n // Unsupported type - encode as null\n parts.push(new Uint8Array([0xc0]));\n }\n\n encode(value);\n\n // Merge all parts\n const totalLength = parts.reduce((sum, p) => sum + p.length, 0);\n const result = new Uint8Array(totalLength);\n let offset = 0;\n for (const part of parts) {\n result.set(part, offset);\n offset += part.length;\n }\n\n return result;\n}\n\n/**\n * Lightweight MessagePack decoder\n */\nfunction msgpackDecode(buffer: Uint8Array): unknown {\n let offset = 0;\n\n function decode(): unknown {\n if (offset >= buffer.length) {\n throw new Error(\"Unexpected end of buffer\");\n }\n\n const byte = buffer[offset++]!;\n\n // Positive fixint (0x00 - 0x7f)\n if (byte <= 0x7f) {\n return byte;\n }\n\n // Negative fixint (0xe0 - 0xff)\n if (byte >= 0xe0) {\n return byte - 256;\n }\n\n // Fixmap (0x80 - 0x8f)\n if (byte >= 0x80 && byte <= 0x8f) {\n const len = byte - 0x80;\n const result: Record<string, unknown> = {};\n for (let i = 0; i < len; i++) {\n const key = decode() as string;\n result[key] = decode();\n }\n return result;\n }\n\n // Fixarray (0x90 - 0x9f)\n if (byte >= 0x90 && byte <= 0x9f) {\n const len = byte - 0x90;\n const result: unknown[] = [];\n for (let i = 0; i < len; i++) {\n result.push(decode());\n }\n return result;\n }\n\n // Fixstr (0xa0 - 0xbf)\n if (byte >= 0xa0 && byte <= 0xbf) {\n const len = byte - 0xa0;\n const str = new TextDecoder().decode(buffer.subarray(offset, offset + len));\n offset += len;\n return str;\n }\n\n switch (byte) {\n case 0xc0: // nil\n return null;\n case 0xc2: // false\n return false;\n case 0xc3: // true\n return true;\n\n case 0xcc: // uint8\n return buffer[offset++];\n case 0xcd: // uint16\n return (buffer[offset++]! << 8) | buffer[offset++]!;\n case 0xce: // uint32\n return (\n ((buffer[offset++]! << 24) >>> 0) +\n (buffer[offset++]! << 16) +\n (buffer[offset++]! << 8) +\n buffer[offset++]!\n );\n\n case 0xd0: // int8\n {\n const val = buffer[offset++]!;\n return val > 127 ? val - 256 : val;\n }\n case 0xd1: // int16\n {\n const val = (buffer[offset++]! << 8) | buffer[offset++]!;\n return val > 32767 ? val - 65536 : val;\n }\n case 0xd2: // int32\n {\n const val =\n (buffer[offset++]! << 24) |\n (buffer[offset++]! << 16) |\n (buffer[offset++]! << 8) |\n buffer[offset++]!;\n return val;\n }\n\n case 0xcb: // float64\n {\n const view = new DataView(buffer.buffer, buffer.byteOffset + offset, 8);\n offset += 8;\n return view.getFloat64(0, false);\n }\n\n case 0xd9: // str8\n {\n const len = buffer[offset++]!;\n const str = new TextDecoder().decode(buffer.subarray(offset, offset + len));\n offset += len;\n return str;\n }\n case 0xda: // str16\n {\n const len = (buffer[offset++]! << 8) | buffer[offset++]!;\n const str = new TextDecoder().decode(buffer.subarray(offset, offset + len));\n offset += len;\n return str;\n }\n case 0xdb: // str32\n {\n const len =\n (buffer[offset++]! << 24) |\n (buffer[offset++]! << 16) |\n (buffer[offset++]! << 8) |\n buffer[offset++]!;\n const str = new TextDecoder().decode(buffer.subarray(offset, offset + len));\n offset += len;\n return str;\n }\n\n case 0xdc: // array16\n {\n const len = (buffer[offset++]! << 8) | buffer[offset++]!;\n const result: unknown[] = [];\n for (let i = 0; i < len; i++) {\n result.push(decode());\n }\n return result;\n }\n case 0xdd: // array32\n {\n const len =\n (buffer[offset++]! << 24) |\n (buffer[offset++]! << 16) |\n (buffer[offset++]! << 8) |\n buffer[offset++]!;\n const result: unknown[] = [];\n for (let i = 0; i < len; i++) {\n result.push(decode());\n }\n return result;\n }\n\n case 0xde: // map16\n {\n const len = (buffer[offset++]! << 8) | buffer[offset++]!;\n const result: Record<string, unknown> = {};\n for (let i = 0; i < len; i++) {\n const key = decode() as string;\n result[key] = decode();\n }\n return result;\n }\n case 0xdf: // map32\n {\n const len =\n (buffer[offset++]! << 24) |\n (buffer[offset++]! << 16) |\n (buffer[offset++]! << 8) |\n buffer[offset++]!;\n const result: Record<string, unknown> = {};\n for (let i = 0; i < len; i++) {\n const key = decode() as string;\n result[key] = decode();\n }\n return result;\n }\n\n default:\n throw new Error(`Unknown MessagePack type: 0x${byte.toString(16)}`);\n }\n }\n\n return decode();\n}\n\n/**\n * MessagePack serializer\n */\nexport const msgpackSerializer: Serializer = {\n encode(data: unknown): ArrayBuffer {\n const encoded = msgpackEncode(data);\n // Create a new ArrayBuffer with the exact bytes from the Uint8Array\n const buffer = new ArrayBuffer(encoded.byteLength);\n new Uint8Array(buffer).set(encoded);\n return buffer;\n },\n\n decode(raw: string | ArrayBuffer): unknown {\n if (typeof raw === \"string\") {\n // If string is passed, assume it's base64 encoded\n const binary = atob(raw);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return msgpackDecode(bytes);\n }\n return msgpackDecode(new Uint8Array(raw));\n },\n\n contentType: \"application/msgpack\",\n};\n\n// ============================================================================\n// SERIALIZER FACTORY\n// ============================================================================\n\n/**\n * Get a serializer by format name.\n *\n * @param format - The serialization format (\"json\" or \"msgpack\")\n * @returns The corresponding serializer instance\n *\n * @example\n * ```typescript\n * const serializer = getSerializer('json');\n * const encoded = serializer.encode({ foo: 'bar' });\n * const decoded = serializer.decode(encoded);\n * ```\n */\nexport function getSerializer(format: \"json\" | \"msgpack\"): Serializer {\n switch (format) {\n case \"json\":\n return jsonSerializer;\n case \"msgpack\":\n return msgpackSerializer;\n default:\n return jsonSerializer;\n }\n}\n\n/**\n * Create a custom serializer with provided encode/decode functions.\n *\n * @param options - Serializer configuration\n * @param options.encode - Function to encode data to string or ArrayBuffer\n * @param options.decode - Function to decode string or ArrayBuffer to data\n * @param options.contentType - HTTP content type for the serialization format\n * @returns A custom serializer instance\n *\n * @example\n * ```typescript\n * const customSerializer = createSerializer({\n * encode: (data) => btoa(JSON.stringify(data)),\n * decode: (raw) => JSON.parse(atob(raw as string)),\n * contentType: 'application/x-custom',\n * });\n * ```\n */\nexport function createSerializer(options: {\n encode: (data: unknown) => string | ArrayBuffer;\n decode: (raw: string | ArrayBuffer) => unknown;\n contentType: string;\n}): Serializer {\n return options;\n}\n"],"mappings":";AA4BO,IAAM,iBAA6B;AAAA,EACx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Q;AACjB,cAAM,SAAkC,CAAC;AACzC,iBAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC5B,gBAAM,MAAM,OAAO;AACnB,iBAAO,GAAG,IAAI,OAAO;AAAA,QACvB;AACA,eAAO;AAAA,MACT;AAAA,MAEF;AACE,cAAM,IAAI,MAAM,+BAA+B,KAAK,SAAS,EAAE,CAAC,EAAE;AAAA,IACtE;AAAA,EACF;AAEA,SAAO,OAAO;AAChB;AAKO,IAAM,oBAAgC;AAAA,EAC3C,OAAO,MAA4B;AACjC,UAAM,UAAU,cAAc,IAAI;AAElC,UAAM,SAAS,IAAI,YAAY,QAAQ,UAAU;AACjD,QAAI,WAAW,MAAM,EAAE,IAAI,OAAO;AAClC,WAAO;AAAA,EACT;AAAA,EAEA,OAAO,KAAoC;AACzC,QAAI,OAAO,QAAQ,UAAU;AAE3B,YAAM,SAAS,KAAK,GAAG;AACvB,YAAM,QAAQ,IAAI,WAAW,OAAO,MAAM;AAC1C,eAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,cAAM,CAAC,IAAI,OAAO,WAAW,CAAC;AAAA,MAChC;AACA,aAAO,cAAc,KAAK;AAAA,IAC5B;AACA,WAAO,cAAc,IAAI,WAAW,GAAG,CAAC;AAAA,EAC1C;AAAA,EAEA,aAAa;AACf;AAmBO,SAAS,cAAc,QAAwC;AACpE,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAoBO,SAAS,iBAAiB,SAIlB;AACb,SAAO;AACT;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Logger } from '@parsrun/core';
|
|
2
|
-
import { b as ServiceDefinition, m as TraceContext, f as RpcRequest, g as RpcResponse } from './types-
|
|
2
|
+
import { b as ServiceDefinition, m as TraceContext, f as RpcRequest, g as RpcResponse } from './types-DHZaZwAt.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @parsrun/service - RPC Server
|
|
@@ -36,6 +36,9 @@ type RpcHandlers = {
|
|
|
36
36
|
queries?: Record<string, RpcHandler>;
|
|
37
37
|
mutations?: Record<string, RpcHandler>;
|
|
38
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* Options for creating an RPC server.
|
|
41
|
+
*/
|
|
39
42
|
interface RpcServerOptions {
|
|
40
43
|
/** Service definition */
|
|
41
44
|
definition: ServiceDefinition;
|
|
@@ -49,7 +52,13 @@ interface RpcServerOptions {
|
|
|
49
52
|
middleware?: RpcMiddleware[];
|
|
50
53
|
}
|
|
51
54
|
/**
|
|
52
|
-
* RPC middleware function
|
|
55
|
+
* RPC middleware function for request processing.
|
|
56
|
+
* Middleware can intercept, modify, or handle requests before/after handlers.
|
|
57
|
+
*
|
|
58
|
+
* @param request - The incoming RPC request
|
|
59
|
+
* @param context - Handler context with logger and metadata
|
|
60
|
+
* @param next - Function to call the next middleware or handler
|
|
61
|
+
* @returns Promise resolving to the handler result
|
|
53
62
|
*/
|
|
54
63
|
type RpcMiddleware = (request: RpcRequest, context: RpcHandlerContext, next: () => Promise<unknown>) => Promise<unknown>;
|
|
55
64
|
/**
|
|
@@ -87,19 +96,54 @@ declare class RpcServer {
|
|
|
87
96
|
};
|
|
88
97
|
}
|
|
89
98
|
/**
|
|
90
|
-
* Create an RPC server
|
|
99
|
+
* Create an RPC server for handling incoming requests.
|
|
100
|
+
*
|
|
101
|
+
* @param options - Server configuration options
|
|
102
|
+
* @returns A new RPC server instance
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const server = createRpcServer({
|
|
107
|
+
* definition: paymentsService,
|
|
108
|
+
* handlers: {
|
|
109
|
+
* queries: {
|
|
110
|
+
* getSubscription: async (input, ctx) => {
|
|
111
|
+
* return { status: 'active', plan: 'pro' };
|
|
112
|
+
* },
|
|
113
|
+
* },
|
|
114
|
+
* },
|
|
115
|
+
* middleware: [loggingMiddleware()],
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
91
118
|
*/
|
|
92
119
|
declare function createRpcServer(options: RpcServerOptions): RpcServer;
|
|
93
120
|
/**
|
|
94
|
-
*
|
|
121
|
+
* Create logging middleware for RPC requests.
|
|
122
|
+
* Logs request start and completion with input keys.
|
|
123
|
+
*
|
|
124
|
+
* @returns RPC middleware that logs requests
|
|
95
125
|
*/
|
|
96
126
|
declare function loggingMiddleware(): RpcMiddleware;
|
|
97
127
|
/**
|
|
98
|
-
*
|
|
128
|
+
* Create validation middleware for RPC request inputs.
|
|
129
|
+
* Applies validators to request inputs by method name.
|
|
130
|
+
*
|
|
131
|
+
* @param validators - Map of method names to validation functions
|
|
132
|
+
* @returns RPC middleware that validates inputs
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const middleware = validationMiddleware({
|
|
137
|
+
* createUser: (input) => validateUserInput(input),
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
99
140
|
*/
|
|
100
141
|
declare function validationMiddleware(validators: Record<string, (input: unknown) => unknown>): RpcMiddleware;
|
|
101
142
|
/**
|
|
102
|
-
*
|
|
143
|
+
* Create tenant context middleware.
|
|
144
|
+
* Extracts tenant ID from request metadata and adds it to the logger context.
|
|
145
|
+
*
|
|
146
|
+
* @returns RPC middleware that enriches logger with tenant context
|
|
103
147
|
*/
|
|
104
148
|
declare function tenantMiddleware(): RpcMiddleware;
|
|
105
149
|
|
package/dist/tracing/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as TraceContext, o as SpanKind, q as SpanAttributeValue, n as Span, p as SpanStatus, T as TracingConfig } from '../types-
|
|
1
|
+
import { m as TraceContext, o as SpanKind, q as SpanAttributeValue, n as Span, p as SpanStatus, T as TracingConfig } from '../types-DHZaZwAt.js';
|
|
2
2
|
import { Logger } from '@parsrun/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -83,11 +83,21 @@ declare class TraceContextManager {
|
|
|
83
83
|
*/
|
|
84
84
|
clear(): void;
|
|
85
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Sampling configuration for tracing.
|
|
88
|
+
* - "always": Sample all traces
|
|
89
|
+
* - "never": Never sample traces
|
|
90
|
+
* - { ratio: number }: Sample a percentage of traces (0-1)
|
|
91
|
+
*/
|
|
86
92
|
type Sampler = "always" | "never" | {
|
|
87
93
|
ratio: number;
|
|
88
94
|
};
|
|
89
95
|
/**
|
|
90
|
-
* Determine if a trace should be sampled
|
|
96
|
+
* Determine if a trace should be sampled based on the sampler configuration.
|
|
97
|
+
*
|
|
98
|
+
* @param sampler - Sampling configuration
|
|
99
|
+
* @param traceId - Optional trace ID for deterministic sampling
|
|
100
|
+
* @returns Whether the trace should be sampled
|
|
91
101
|
*/
|
|
92
102
|
declare function shouldSample(sampler: Sampler, traceId?: string): boolean;
|
|
93
103
|
|
|
@@ -96,6 +106,9 @@ declare function shouldSample(sampler: Sampler, traceId?: string): boolean;
|
|
|
96
106
|
* Span creation and management
|
|
97
107
|
*/
|
|
98
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Options for creating a span.
|
|
111
|
+
*/
|
|
99
112
|
interface SpanOptions {
|
|
100
113
|
/** Span name */
|
|
101
114
|
name: string;
|
|
@@ -109,7 +122,10 @@ interface SpanOptions {
|
|
|
109
122
|
startTime?: number;
|
|
110
123
|
}
|
|
111
124
|
/**
|
|
112
|
-
* Create a new span
|
|
125
|
+
* Create a new span for tracing an operation.
|
|
126
|
+
*
|
|
127
|
+
* @param options - Span configuration options
|
|
128
|
+
* @returns A new span instance
|
|
113
129
|
*/
|
|
114
130
|
declare function createSpan(options: SpanOptions): Span;
|
|
115
131
|
/**
|
|
@@ -159,15 +175,24 @@ declare class SpanManager {
|
|
|
159
175
|
clear(): void;
|
|
160
176
|
}
|
|
161
177
|
/**
|
|
162
|
-
* Calculate span duration in milliseconds
|
|
178
|
+
* Calculate span duration in milliseconds.
|
|
179
|
+
*
|
|
180
|
+
* @param span - The span to measure
|
|
181
|
+
* @returns Duration in milliseconds, or undefined if not ended
|
|
163
182
|
*/
|
|
164
183
|
declare function getSpanDuration(span: Span): number | undefined;
|
|
165
184
|
/**
|
|
166
|
-
* Check if span is completed
|
|
185
|
+
* Check if a span is completed (has an end time).
|
|
186
|
+
*
|
|
187
|
+
* @param span - The span to check
|
|
188
|
+
* @returns True if the span has been ended
|
|
167
189
|
*/
|
|
168
190
|
declare function isSpanCompleted(span: Span): boolean;
|
|
169
191
|
/**
|
|
170
|
-
*
|
|
192
|
+
* Convert a span to a simplified object for logging.
|
|
193
|
+
*
|
|
194
|
+
* @param span - The span to convert
|
|
195
|
+
* @returns A plain object representation of the span
|
|
171
196
|
*/
|
|
172
197
|
declare function spanToLogObject(span: Span): Record<string, unknown>;
|
|
173
198
|
/**
|
|
@@ -204,18 +229,28 @@ declare const SpanAttributes: {
|
|
|
204
229
|
* Console and OTLP exporters for spans
|
|
205
230
|
*/
|
|
206
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Interface for span exporters.
|
|
234
|
+
* Exporters receive completed spans and send them to a backend.
|
|
235
|
+
*/
|
|
207
236
|
interface SpanExporter {
|
|
208
237
|
/** Exporter name */
|
|
209
238
|
readonly name: string;
|
|
210
|
-
/** Export spans */
|
|
239
|
+
/** Export spans to the backend */
|
|
211
240
|
export(spans: Span[]): Promise<void>;
|
|
212
|
-
/** Shutdown exporter */
|
|
241
|
+
/** Shutdown exporter and flush pending spans */
|
|
213
242
|
shutdown(): Promise<void>;
|
|
214
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Base options for span exporters.
|
|
246
|
+
*/
|
|
215
247
|
interface ExporterOptions {
|
|
216
248
|
/** Logger */
|
|
217
249
|
logger?: Logger;
|
|
218
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Options for the console exporter.
|
|
253
|
+
*/
|
|
219
254
|
interface ConsoleExporterOptions extends ExporterOptions {
|
|
220
255
|
/** Pretty print (default: true in dev) */
|
|
221
256
|
pretty?: boolean;
|
|
@@ -225,7 +260,8 @@ interface ConsoleExporterOptions extends ExporterOptions {
|
|
|
225
260
|
includeEvents?: boolean;
|
|
226
261
|
}
|
|
227
262
|
/**
|
|
228
|
-
* Console exporter for development
|
|
263
|
+
* Console exporter for development and debugging.
|
|
264
|
+
* Outputs spans to the console with optional pretty formatting.
|
|
229
265
|
*/
|
|
230
266
|
declare class ConsoleExporter implements SpanExporter {
|
|
231
267
|
readonly name = "console";
|
|
@@ -238,9 +274,15 @@ declare class ConsoleExporter implements SpanExporter {
|
|
|
238
274
|
shutdown(): Promise<void>;
|
|
239
275
|
}
|
|
240
276
|
/**
|
|
241
|
-
* Create a console exporter
|
|
277
|
+
* Create a console exporter for local development.
|
|
278
|
+
*
|
|
279
|
+
* @param options - Exporter configuration options
|
|
280
|
+
* @returns A new console exporter instance
|
|
242
281
|
*/
|
|
243
282
|
declare function createConsoleExporter(options?: ConsoleExporterOptions): ConsoleExporter;
|
|
283
|
+
/**
|
|
284
|
+
* Options for the OTLP exporter.
|
|
285
|
+
*/
|
|
244
286
|
interface OtlpExporterOptions extends ExporterOptions {
|
|
245
287
|
/** OTLP endpoint URL */
|
|
246
288
|
endpoint: string;
|
|
@@ -258,7 +300,8 @@ interface OtlpExporterOptions extends ExporterOptions {
|
|
|
258
300
|
flushInterval?: number;
|
|
259
301
|
}
|
|
260
302
|
/**
|
|
261
|
-
* OTLP exporter for production tracing
|
|
303
|
+
* OTLP exporter for production tracing.
|
|
304
|
+
* Sends spans to an OpenTelemetry-compatible backend via HTTP.
|
|
262
305
|
*/
|
|
263
306
|
declare class OtlpExporter implements SpanExporter {
|
|
264
307
|
readonly name = "otlp";
|
|
@@ -282,7 +325,18 @@ declare class OtlpExporter implements SpanExporter {
|
|
|
282
325
|
shutdown(): Promise<void>;
|
|
283
326
|
}
|
|
284
327
|
/**
|
|
285
|
-
* Create an OTLP exporter
|
|
328
|
+
* Create an OTLP exporter for production tracing.
|
|
329
|
+
*
|
|
330
|
+
* @param options - Exporter configuration options
|
|
331
|
+
* @returns A new OTLP exporter instance
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```typescript
|
|
335
|
+
* const exporter = createOtlpExporter({
|
|
336
|
+
* endpoint: 'https://otel-collector.example.com:4318',
|
|
337
|
+
* serviceName: 'payments',
|
|
338
|
+
* });
|
|
339
|
+
* ```
|
|
286
340
|
*/
|
|
287
341
|
declare function createOtlpExporter(options: OtlpExporterOptions): OtlpExporter;
|
|
288
342
|
|
|
@@ -291,6 +345,9 @@ declare function createOtlpExporter(options: OtlpExporterOptions): OtlpExporter;
|
|
|
291
345
|
* High-level tracing API
|
|
292
346
|
*/
|
|
293
347
|
|
|
348
|
+
/**
|
|
349
|
+
* Options for creating a tracer.
|
|
350
|
+
*/
|
|
294
351
|
interface TracerOptions {
|
|
295
352
|
/** Service name */
|
|
296
353
|
serviceName: string;
|
|
@@ -370,7 +427,21 @@ declare class Tracer {
|
|
|
370
427
|
shutdown(): Promise<void>;
|
|
371
428
|
}
|
|
372
429
|
/**
|
|
373
|
-
* Create a tracer
|
|
430
|
+
* Create a tracer for distributed tracing.
|
|
431
|
+
*
|
|
432
|
+
* @param options - Tracer configuration options
|
|
433
|
+
* @returns A new tracer instance
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* ```typescript
|
|
437
|
+
* const tracer = createTracer({
|
|
438
|
+
* serviceName: 'payments',
|
|
439
|
+
* config: { sampler: { ratio: 0.1 } },
|
|
440
|
+
* });
|
|
441
|
+
* await tracer.trace('processPayment', async (span) => {
|
|
442
|
+
* // Processing logic
|
|
443
|
+
* });
|
|
444
|
+
* ```
|
|
374
445
|
*/
|
|
375
446
|
declare function createTracer(options: TracerOptions): Tracer;
|
|
376
447
|
/**
|
|
@@ -386,11 +457,19 @@ declare function setGlobalTracer(tracer: Tracer): void;
|
|
|
386
457
|
*/
|
|
387
458
|
declare function resetGlobalTracer(): void;
|
|
388
459
|
/**
|
|
389
|
-
* Create HTTP server tracing middleware
|
|
460
|
+
* Create HTTP server tracing middleware.
|
|
461
|
+
* Automatically creates spans for incoming HTTP requests.
|
|
462
|
+
*
|
|
463
|
+
* @param tracer - The tracer instance to use
|
|
464
|
+
* @returns Middleware function for HTTP frameworks
|
|
390
465
|
*/
|
|
391
466
|
declare function createTracingMiddleware(tracer: Tracer): (request: Request, next: () => Promise<Response>) => Promise<Response>;
|
|
392
467
|
/**
|
|
393
|
-
* Create RPC tracing helpers
|
|
468
|
+
* Create RPC tracing helpers for instrumenting RPC calls.
|
|
469
|
+
* Provides methods to trace outgoing calls and incoming handlers.
|
|
470
|
+
*
|
|
471
|
+
* @param tracer - The tracer instance to use
|
|
472
|
+
* @returns Object with traceCall and traceHandler methods
|
|
394
473
|
*/
|
|
395
474
|
declare function createRpcTracing(tracer: Tracer): {
|
|
396
475
|
/**
|