iii-browser-sdk 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,145 @@
1
+ //#region src/stream.d.ts
2
+ /** Input for stream authentication. */
3
+ interface StreamAuthInput {
4
+ /** Request headers. */
5
+ headers: Record<string, string>;
6
+ /** Request path. */
7
+ path: string;
8
+ /** Query parameters. */
9
+ query_params: Record<string, string[]>;
10
+ /** Client address. */
11
+ addr: string;
12
+ }
13
+ /** Result of stream authentication. */
14
+ interface StreamAuthResult {
15
+ /** Arbitrary context passed to stream handlers after authentication. */
16
+ context?: any;
17
+ }
18
+ /** Context type extracted from {@link StreamAuthResult}. */
19
+ type StreamContext = StreamAuthResult['context'];
20
+ /** Event payload for stream join/leave events. */
21
+ interface StreamJoinLeaveEvent {
22
+ /** Unique subscription identifier. */
23
+ subscription_id: string;
24
+ /** Name of the stream. */
25
+ stream_name: string;
26
+ /** Group identifier. */
27
+ group_id: string;
28
+ /** Item identifier (if applicable). */
29
+ id?: string;
30
+ /** Auth context from {@link StreamAuthResult}. */
31
+ context?: StreamContext;
32
+ }
33
+ /** Result of a stream join request. */
34
+ interface StreamJoinResult {
35
+ /** Whether the join was unauthorized. */
36
+ unauthorized: boolean;
37
+ }
38
+ /** Input for retrieving a single stream item. */
39
+ type StreamGetInput = {
40
+ /** Name of the stream. */stream_name: string; /** Group identifier. */
41
+ group_id: string; /** Item identifier. */
42
+ item_id: string;
43
+ };
44
+ /** Input for setting a stream item. */
45
+ type StreamSetInput = {
46
+ /** Name of the stream. */stream_name: string; /** Group identifier. */
47
+ group_id: string; /** Item identifier. */
48
+ item_id: string; /** Data to store. */
49
+ data: any;
50
+ };
51
+ /** Input for deleting a stream item. */
52
+ type StreamDeleteInput = {
53
+ /** Name of the stream. */stream_name: string; /** Group identifier. */
54
+ group_id: string; /** Item identifier. */
55
+ item_id: string;
56
+ };
57
+ /** Input for listing all items in a stream group. */
58
+ type StreamListInput = {
59
+ /** Name of the stream. */stream_name: string; /** Group identifier. */
60
+ group_id: string;
61
+ };
62
+ /** Input for listing all groups in a stream. */
63
+ type StreamListGroupsInput = {
64
+ /** Name of the stream. */stream_name: string;
65
+ };
66
+ /** Result of a stream set operation. */
67
+ type StreamSetResult<TData> = {
68
+ /** Previous value (if it existed). */old_value?: TData; /** New value that was stored. */
69
+ new_value: TData;
70
+ };
71
+ /** Result of a stream update operation. */
72
+ type StreamUpdateResult<TData> = {
73
+ /** Previous value (if it existed). */old_value?: TData; /** New value after the update. */
74
+ new_value: TData;
75
+ };
76
+ /** Set a field at the given path to a value. */
77
+ type UpdateSet = {
78
+ type: 'set'; /** Dot-separated field path (e.g. `user.name`). */
79
+ path: string; /** Value to set. */
80
+ value: any;
81
+ };
82
+ /** Increment a numeric field by a given amount. */
83
+ type UpdateIncrement = {
84
+ type: 'increment'; /** Dot-separated field path. */
85
+ path: string; /** Amount to increment by. */
86
+ by: number;
87
+ };
88
+ /** Decrement a numeric field by a given amount. */
89
+ type UpdateDecrement = {
90
+ type: 'decrement'; /** Dot-separated field path. */
91
+ path: string; /** Amount to decrement by. */
92
+ by: number;
93
+ };
94
+ /** Remove a field at the given path. */
95
+ type UpdateRemove = {
96
+ type: 'remove'; /** Dot-separated field path. */
97
+ path: string;
98
+ };
99
+ /** Deep-merge an object into the field at the given path. */
100
+ type UpdateMerge = {
101
+ type: 'merge'; /** Dot-separated field path. */
102
+ path: string; /** Object to merge. */
103
+ value: any;
104
+ };
105
+ /** Result of a stream delete operation. */
106
+ type DeleteResult = {
107
+ /** Previous value (if it existed). */old_value?: any;
108
+ };
109
+ /**
110
+ * Union of all atomic update operations supported by streams.
111
+ *
112
+ * @see {@link UpdateSet}, {@link UpdateIncrement}, {@link UpdateDecrement},
113
+ * {@link UpdateRemove}, {@link UpdateMerge}
114
+ */
115
+ type UpdateOp = UpdateSet | UpdateIncrement | UpdateDecrement | UpdateRemove | UpdateMerge;
116
+ /** Input for atomically updating a stream item. */
117
+ type StreamUpdateInput = {
118
+ /** Name of the stream. */stream_name: string; /** Group identifier. */
119
+ group_id: string; /** Item identifier. */
120
+ item_id: string; /** Ordered list of update operations to apply atomically. */
121
+ ops: UpdateOp[];
122
+ };
123
+ /**
124
+ * Interface for custom stream implementations. Passed to `ISdk.createStream`
125
+ * to override the engine's built-in stream storage.
126
+ *
127
+ * @typeParam TData - Type of the data stored in the stream.
128
+ */
129
+ interface IStream<TData> {
130
+ /** Retrieve a single item by group and item ID. */
131
+ get(input: StreamGetInput): Promise<TData | null>;
132
+ /** Set (create or overwrite) a stream item. */
133
+ set(input: StreamSetInput): Promise<StreamSetResult<TData> | null>;
134
+ /** Delete a stream item. */
135
+ delete(input: StreamDeleteInput): Promise<DeleteResult>;
136
+ /** List all items in a group. */
137
+ list(input: StreamListInput): Promise<TData[]>;
138
+ /** List all group IDs in a stream. */
139
+ listGroups(input: StreamListGroupsInput): Promise<string[]>;
140
+ /** Apply atomic update operations to a stream item. */
141
+ update(input: StreamUpdateInput): Promise<StreamUpdateResult<TData> | null>;
142
+ }
143
+ //#endregion
144
+ export { UpdateIncrement as _, StreamContext as a, UpdateRemove as b, StreamJoinLeaveEvent as c, StreamListInput as d, StreamSetInput as f, UpdateDecrement as g, StreamUpdateResult as h, StreamAuthResult as i, StreamJoinResult as l, StreamUpdateInput as m, IStream as n, StreamDeleteInput as o, StreamSetResult as p, StreamAuthInput as r, StreamGetInput as s, DeleteResult as t, StreamListGroupsInput as u, UpdateMerge as v, UpdateSet as x, UpdateOp as y };
145
+ //# sourceMappingURL=stream-CCorhlLO.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-CCorhlLO.d.mts","names":[],"sources":["../src/stream.ts"],"mappings":";;UACiB,eAAA;EAAe;EAE9B,OAAA,EAAS,MAAA;EAIW;EAFpB,IAAA;EAFS;EAIT,YAAA,EAAc,MAAA;EAAd;EAEA,IAAA;AAAA;;UAIe,gBAAA;EAAA;EAGf,OAAA;AAAA;;KAIU,a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AK,QAAA;AAAA;;;;;;;UASU,OAAA;EApBsD;EAsBrE,GAAA,CAAI,KAAA,EAAO,cAAA,GAAiB,OAAA,CAAQ,KAAA;EAtB2D;EAwB/F,GAAA,CAAI,KAAA,EAAO,cAAA,GAAiB,OAAA,CAAQ,eAAA,CAAgB,KAAA;EArB1C;EAuBV,MAAA,CAAO,KAAA,EAAO,iBAAA,GAAoB,OAAA,CAAQ,YAAA;;EAE1C,IAAA,CAAK,KAAA,EAAO,eAAA,GAAkB,OAAA,CAAQ,KAAA;EAvBtC;EAyBA,UAAA,CAAW,KAAA,EAAO,qBAAA,GAAwB,OAAA;EArB1C;EAuBA,MAAA,CAAO,KAAA,EAAO,iBAAA,GAAoB,OAAA,CAAQ,kBAAA,CAAmB,KAAA;AAAA"}
File without changes
@@ -0,0 +1,2 @@
1
+ import { _ as UpdateIncrement, a as StreamContext, b as UpdateRemove, c as StreamJoinLeaveEvent, d as StreamListInput, f as StreamSetInput, g as UpdateDecrement, h as StreamUpdateResult, i as StreamAuthResult, l as StreamJoinResult, m as StreamUpdateInput, n as IStream, o as StreamDeleteInput, p as StreamSetResult, r as StreamAuthInput, s as StreamGetInput, t as DeleteResult, u as StreamListGroupsInput, v as UpdateMerge, x as UpdateSet, y as UpdateOp } from "./stream-B4Etd7Hp.cjs";
2
+ export { DeleteResult, IStream, StreamAuthInput, StreamAuthResult, StreamContext, StreamDeleteInput, StreamGetInput, StreamJoinLeaveEvent, StreamJoinResult, StreamListGroupsInput, StreamListInput, StreamSetInput, StreamSetResult, StreamUpdateInput, StreamUpdateResult, UpdateDecrement, UpdateIncrement, UpdateMerge, UpdateOp, UpdateRemove, UpdateSet };
@@ -0,0 +1,2 @@
1
+ import { _ as UpdateIncrement, a as StreamContext, b as UpdateRemove, c as StreamJoinLeaveEvent, d as StreamListInput, f as StreamSetInput, g as UpdateDecrement, h as StreamUpdateResult, i as StreamAuthResult, l as StreamJoinResult, m as StreamUpdateInput, n as IStream, o as StreamDeleteInput, p as StreamSetResult, r as StreamAuthInput, s as StreamGetInput, t as DeleteResult, u as StreamListGroupsInput, v as UpdateMerge, x as UpdateSet, y as UpdateOp } from "./stream-CCorhlLO.mjs";
2
+ export { DeleteResult, IStream, StreamAuthInput, StreamAuthResult, StreamContext, StreamDeleteInput, StreamGetInput, StreamJoinLeaveEvent, StreamJoinResult, StreamListGroupsInput, StreamListInput, StreamSetInput, StreamSetResult, StreamUpdateInput, StreamUpdateResult, UpdateDecrement, UpdateIncrement, UpdateMerge, UpdateOp, UpdateRemove, UpdateSet };
@@ -0,0 +1 @@
1
+ export { };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "iii-browser-sdk",
3
+ "version": "0.10.0",
4
+ "private": false,
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "main": "index.js",
9
+ "author": "III",
10
+ "license": "Apache-2.0",
11
+ "type": "module",
12
+ "description": "III SDK for the browser — no OpenTelemetry, no Node.js dependencies",
13
+ "keywords": [
14
+ "iii",
15
+ "sdk",
16
+ "browser",
17
+ "websocket"
18
+ ],
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.mjs",
23
+ "require": "./dist/index.cjs"
24
+ },
25
+ "./stream": {
26
+ "types": "./dist/stream.d.ts",
27
+ "import": "./dist/stream.mjs",
28
+ "require": "./dist/stream.cjs"
29
+ },
30
+ "./state": {
31
+ "types": "./dist/state.d.ts",
32
+ "import": "./dist/state.mjs",
33
+ "require": "./dist/state.cjs"
34
+ }
35
+ },
36
+ "devDependencies": {
37
+ "@types/ws": "^8.18.1",
38
+ "happy-dom": "^17.4.4",
39
+ "tsdown": "^0.21.4",
40
+ "typedoc": "^0.28.17",
41
+ "typescript": "^5.9.3",
42
+ "vitest": "^2.1.0",
43
+ "ws": "^8.18.3"
44
+ },
45
+ "scripts": {
46
+ "build": "tsdown",
47
+ "docs:json": "typedoc",
48
+ "test": "vitest run",
49
+ "test:watch": "vitest",
50
+ "test:integration": "vitest run --config vitest.integration.config.ts"
51
+ }
52
+ }
package/typedoc.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "entryPoints": ["src/index.ts", "src/stream.ts", "src/state.ts"],
3
+ "json": "api-docs.json",
4
+ "tsconfig": "tsconfig.json",
5
+ "excludePrivate": true,
6
+ "excludeInternal": true,
7
+ "excludeExternals": true
8
+ }
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from 'vitest/config'
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ environment: 'happy-dom',
7
+ testTimeout: 30000,
8
+ hookTimeout: 30000,
9
+ setupFiles: ['./tests/setup.ts'],
10
+ exclude: ['tests/integration/**'],
11
+ },
12
+ })
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from 'vitest/config'
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ testTimeout: 30000,
7
+ hookTimeout: 30000,
8
+ setupFiles: ['./tests/integration/setup.ts'],
9
+ include: ['tests/integration/**/*.test.ts'],
10
+ },
11
+ })