@hediet/linkrpc-infra 0.0.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.
@@ -0,0 +1,68 @@
1
+ import { jsonDocumentEditSchema } from "../json-document/index.js";
2
+ import { array, discriminatedUnion, enum as enum$1, lazy, literal, number, object, optional, record, string, unknown } from "zod/mini";
3
+ import { defineInterface, requestType } from "@hediet/linkrpc";
4
+ //#region src/logging/index.ts
5
+ const logLevelSchema = enum$1([
6
+ "trace",
7
+ "debug",
8
+ "info",
9
+ "warn",
10
+ "error",
11
+ "off"
12
+ ]);
13
+ const logErrorSchema = object({
14
+ name: optional(string()),
15
+ message: string(),
16
+ stack: optional(string())
17
+ });
18
+ const logEntrySchema = lazy(() => object({
19
+ timestamp: string(),
20
+ level: enum$1([
21
+ "trace",
22
+ "debug",
23
+ "info",
24
+ "warn",
25
+ "error"
26
+ ]),
27
+ message: string(),
28
+ attributes: optional(record(string(), unknown())),
29
+ entries: optional(array(logEntrySchema)),
30
+ durationMs: optional(number()),
31
+ error: optional(logErrorSchema)
32
+ }));
33
+ const logDocumentSchema = object({
34
+ schemaVersion: literal(1),
35
+ service: string(),
36
+ startedAt: string(),
37
+ state: record(string(), unknown()),
38
+ entries: array(logEntrySchema)
39
+ });
40
+ const logStreamEventSchema = discriminatedUnion("type", [object({
41
+ type: literal("snapshot"),
42
+ revision: number(),
43
+ document: logDocumentSchema
44
+ }), object({
45
+ type: literal("patch"),
46
+ revision: number(),
47
+ edits: array(jsonDocumentEditSchema)
48
+ })]);
49
+ /**
50
+ * Standard structured-log protocol. Implementations choose their own storage,
51
+ * retention, and sinks; this definition specifies only the LinkRPC wire API.
52
+ */
53
+ const loggingInterface = defineInterface({
54
+ id: "linkrpc.logging",
55
+ description: "Structured service logs exposed as a revisioned JSON document stream. watchLog emits a snapshot first and then patches in revision order. Clients that observe a revision gap must resynchronize with getLogSnapshot."
56
+ }, {
57
+ getLogLevel: requestType(object({}), object({ level: logLevelSchema })),
58
+ getLogSnapshot: requestType(object({}), object({
59
+ revision: number(),
60
+ document: logDocumentSchema
61
+ })),
62
+ setLogLevel: requestType(object({ level: logLevelSchema }), object({})),
63
+ watchLog: requestType(object({}), object({})).withStream({ server: logStreamEventSchema })
64
+ });
65
+ //#endregion
66
+ export { logDocumentSchema, logEntrySchema, logLevelSchema, logStreamEventSchema, loggingInterface };
67
+
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["zEnum"],"sources":["../../src/logging/index.ts"],"sourcesContent":["import {\n array,\n discriminatedUnion,\n enum as zEnum,\n lazy,\n literal,\n number,\n object,\n optional,\n record,\n string,\n unknown,\n} from 'zod/mini';\nimport type { output as zInfer } from 'zod/v4/core';\nimport { defineInterface, requestType, type Schema } from '@hediet/linkrpc';\nimport { jsonDocumentEditSchema } from '../json-document/index';\n\nexport const logLevelSchema = zEnum(['trace', 'debug', 'info', 'warn', 'error', 'off']);\nexport type LogLevel = zInfer<typeof logLevelSchema>;\nexport type EmittedLogLevel = Exclude<LogLevel, 'off'>;\n\nexport interface LogError {\n readonly name?: string;\n readonly message: string;\n readonly stack?: string;\n}\n\nexport interface LogEntry {\n readonly timestamp: string;\n readonly level: EmittedLogLevel;\n readonly message: string;\n readonly attributes?: Readonly<Record<string, unknown>>;\n readonly entries?: readonly LogEntry[];\n readonly durationMs?: number;\n readonly error?: LogError;\n}\n\nexport interface LogDocument {\n readonly schemaVersion: 1;\n readonly service: string;\n readonly startedAt: string;\n readonly state: Readonly<Record<string, unknown>>;\n readonly entries: readonly LogEntry[];\n}\n\nconst logErrorSchema = object({\n name: optional(string()),\n message: string(),\n stack: optional(string()),\n});\n\nexport const logEntrySchema: Schema<LogEntry> = lazy(() =>\n object({\n timestamp: string(),\n level: zEnum(['trace', 'debug', 'info', 'warn', 'error']),\n message: string(),\n attributes: optional(record(string(), unknown())),\n entries: optional(array(logEntrySchema)),\n durationMs: optional(number()),\n error: optional(logErrorSchema),\n }),\n);\n\nexport const logDocumentSchema: Schema<LogDocument> = object({\n schemaVersion: literal(1),\n service: string(),\n startedAt: string(),\n state: record(string(), unknown()),\n entries: array(logEntrySchema),\n});\n\nexport const logStreamEventSchema = discriminatedUnion('type', [\n object({\n type: literal('snapshot'),\n revision: number(),\n document: logDocumentSchema,\n }),\n object({\n type: literal('patch'),\n revision: number(),\n edits: array(jsonDocumentEditSchema),\n }),\n]);\n\nexport type LogStreamEvent = zInfer<typeof logStreamEventSchema>;\n\n/**\n * Standard structured-log protocol. Implementations choose their own storage,\n * retention, and sinks; this definition specifies only the LinkRPC wire API.\n */\nexport const loggingInterface = defineInterface(\n {\n id: 'linkrpc.logging',\n description:\n 'Structured service logs exposed as a revisioned JSON document stream. '\n + 'watchLog emits a snapshot first and then patches in revision order. '\n + 'Clients that observe a revision gap must resynchronize with getLogSnapshot.',\n },\n {\n getLogLevel: requestType(object({}), object({ level: logLevelSchema })),\n getLogSnapshot: requestType(\n object({}),\n object({ revision: number(), document: logDocumentSchema }),\n ),\n setLogLevel: requestType(object({ level: logLevelSchema }), object({})),\n watchLog: requestType(object({}), object({})).withStream({\n server: logStreamEventSchema,\n }),\n },\n);\n"],"mappings":";;;;AAiBA,MAAa,iBAAiBA,OAAM;CAAC;CAAS;CAAS;CAAQ;CAAQ;CAAS;AAAK,CAAC;AA4BtF,MAAM,iBAAiB,OAAO;CAC1B,MAAM,SAAS,OAAO,CAAC;CACvB,SAAS,OAAO;CAChB,OAAO,SAAS,OAAO,CAAC;AAC5B,CAAC;AAED,MAAa,iBAAmC,WAC5C,OAAO;CACH,WAAW,OAAO;CAClB,OAAOA,OAAM;EAAC;EAAS;EAAS;EAAQ;EAAQ;CAAO,CAAC;CACxD,SAAS,OAAO;CAChB,YAAY,SAAS,OAAO,OAAO,GAAG,QAAQ,CAAC,CAAC;CAChD,SAAS,SAAS,MAAM,cAAc,CAAC;CACvC,YAAY,SAAS,OAAO,CAAC;CAC7B,OAAO,SAAS,cAAc;AAClC,CAAC,CACL;AAEA,MAAa,oBAAyC,OAAO;CACzD,eAAe,QAAQ,CAAC;CACxB,SAAS,OAAO;CAChB,WAAW,OAAO;CAClB,OAAO,OAAO,OAAO,GAAG,QAAQ,CAAC;CACjC,SAAS,MAAM,cAAc;AACjC,CAAC;AAED,MAAa,uBAAuB,mBAAmB,QAAQ,CAC3D,OAAO;CACH,MAAM,QAAQ,UAAU;CACxB,UAAU,OAAO;CACjB,UAAU;AACd,CAAC,GACD,OAAO;CACH,MAAM,QAAQ,OAAO;CACrB,UAAU,OAAO;CACjB,OAAO,MAAM,sBAAsB;AACvC,CAAC,CACL,CAAC;;;;;AAQD,MAAa,mBAAmB,gBAC5B;CACI,IAAI;CACJ,aACI;AAGR,GACA;CACI,aAAa,YAAY,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,eAAe,CAAC,CAAC;CACtE,gBAAgB,YACZ,OAAO,CAAC,CAAC,GACT,OAAO;EAAE,UAAU,OAAO;EAAG,UAAU;CAAkB,CAAC,CAC9D;CACA,aAAa,YAAY,OAAO,EAAE,OAAO,eAAe,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CACtE,UAAU,YAAY,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EACrD,QAAQ,qBACZ,CAAC;AACL,CACJ"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@hediet/linkrpc-infra",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/hediet/linkrpc.git",
9
+ "directory": "typescript/packages/linkrpc-infra"
10
+ },
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": "./dist/index.js",
14
+ "./inspection": "./dist/inspection/index.js",
15
+ "./json-document": "./dist/json-document/index.js",
16
+ "./json-rpc": "./dist/json-rpc/index.js",
17
+ "./logging": "./dist/logging/index.js",
18
+ "./package.json": "./package.json"
19
+ },
20
+ "files": [
21
+ "dist/"
22
+ ],
23
+ "sideEffects": false,
24
+ "peerDependencies": {
25
+ "zod": "^4.4.3",
26
+ "@hediet/linkrpc": "0.0.1"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^20.0.0",
30
+ "tsdown": "^0.22.3",
31
+ "typescript": "^6.0.3",
32
+ "vitest": "^3.0.0",
33
+ "vscode-json-languageserver": "1.3.4",
34
+ "zod": "^4.4.3",
35
+ "@hediet/linkrpc": "0.0.1"
36
+ },
37
+ "scripts": {
38
+ "build": "tsdown",
39
+ "test": "vitest --run",
40
+ "test:interop": "vitest --run test/protocols/protocolInterop.live.test.ts",
41
+ "test:generated-interop": "vitest --run test/protocols/contracts/contracts.test.ts test/protocols/generatedInterop.crossLanguage.test.ts test/protocols/protocolInterop.live.test.ts",
42
+ "test:watch": "vitest"
43
+ }
44
+ }