iii-sdk 0.3.0 → 0.4.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.
Files changed (44) hide show
  1. package/dist/index.cjs +190 -3
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +2 -2
  4. package/dist/index.d.mts +2 -2
  5. package/dist/index.mjs +188 -4
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/{otel-worker-gauges-CHooGOLC.mjs → otel-worker-gauges-Dqf47JXh.mjs} +24 -2
  8. package/dist/{otel-worker-gauges-CHooGOLC.mjs.map → otel-worker-gauges-Dqf47JXh.mjs.map} +1 -1
  9. package/dist/{otel-worker-gauges-CLZyxI1P.cjs → otel-worker-gauges-wK5b_eLY.cjs} +35 -1
  10. package/dist/{otel-worker-gauges-CLZyxI1P.cjs.map → otel-worker-gauges-wK5b_eLY.cjs.map} +1 -1
  11. package/dist/state.cjs.map +1 -1
  12. package/dist/state.d.cts +1 -1
  13. package/dist/state.d.cts.map +1 -1
  14. package/dist/state.d.mts +1 -1
  15. package/dist/state.d.mts.map +1 -1
  16. package/dist/state.mjs.map +1 -1
  17. package/dist/stream-BEp3rjfm.d.cts.map +1 -1
  18. package/dist/stream-Bzpo5JNV.d.mts.map +1 -1
  19. package/dist/telemetry.cjs +1 -1
  20. package/dist/telemetry.d.cts +1 -8
  21. package/dist/telemetry.d.cts.map +1 -1
  22. package/dist/telemetry.d.mts +1 -8
  23. package/dist/telemetry.d.mts.map +1 -1
  24. package/dist/telemetry.mjs +1 -1
  25. package/dist/{iii-BeqS2Gj2.d.cts → utils-00Nf7BPL.d.cts} +99 -9
  26. package/dist/utils-00Nf7BPL.d.cts.map +1 -0
  27. package/dist/{iii-ZNKF-Npp.d.mts → utils-DGk5SQIG.d.mts} +99 -9
  28. package/dist/utils-DGk5SQIG.d.mts.map +1 -0
  29. package/package.json +1 -1
  30. package/dist/iii-BeqS2Gj2.d.cts.map +0 -1
  31. package/dist/iii-ZNKF-Npp.d.mts.map +0 -1
  32. package/tests/api-triggers.test.ts +0 -163
  33. package/tests/bridge.test.ts +0 -84
  34. package/tests/exports.test.ts +0 -37
  35. package/tests/fetch-instrumentation.test.ts +0 -623
  36. package/tests/fixtures/config-test.yaml +0 -66
  37. package/tests/healthcheck.test.ts +0 -52
  38. package/tests/kv-server.test.ts +0 -82
  39. package/tests/otel-defaults.test.ts +0 -268
  40. package/tests/pubsub.test.ts +0 -117
  41. package/tests/setup.ts +0 -13
  42. package/tests/state.test.ts +0 -152
  43. package/tests/stream.test.ts +0 -216
  44. package/tests/utils.ts +0 -74
@@ -1,216 +0,0 @@
1
- import { beforeEach, describe, expect, it } from 'vitest'
2
- import { iii, sleep } from './utils'
3
- import type { StreamSetInput, StreamSetResult } from '../src/stream'
4
-
5
- type TestData = {
6
- name?: string
7
- value: number
8
- updated?: boolean
9
- }
10
-
11
- describe('Stream Operations', () => {
12
- const testStreamName = 'test-stream'
13
- const testGroupId = 'test-group'
14
- const testItemId = 'test-item'
15
-
16
- beforeEach(async () => {
17
- await iii
18
- .call('stream::delete', {
19
- stream_name: testStreamName,
20
- group_id: testGroupId,
21
- item_id: testItemId,
22
- })
23
- .catch(() => void 0)
24
- })
25
-
26
- describe('stream::set', () => {
27
- it('should set a new stream item', async () => {
28
- const testData = {
29
- name: 'Test Item',
30
- value: 42,
31
- metadata: { created: new Date().toISOString() },
32
- }
33
-
34
- const result = await iii.call<StreamSetInput, StreamSetResult<TestData>>('stream::set', {
35
- stream_name: testStreamName,
36
- group_id: testGroupId,
37
- item_id: testItemId,
38
- data: testData,
39
- })
40
-
41
- expect(result).toBeDefined()
42
- expect(result).toEqual({ old_value: null, new_value: testData })
43
- })
44
-
45
- it('should overwrite an existing stream item', async () => {
46
- const initialData: TestData = { value: 1 }
47
- const updatedData: TestData = { value: 2, updated: true }
48
-
49
- await iii.call('stream::set', {
50
- stream_name: testStreamName,
51
- group_id: testGroupId,
52
- item_id: testItemId,
53
- data: initialData,
54
- })
55
-
56
- const result: StreamSetResult<TestData> = await iii.call('stream::set', {
57
- stream_name: testStreamName,
58
- group_id: testGroupId,
59
- item_id: testItemId,
60
- data: updatedData,
61
- })
62
-
63
- expect(result.old_value).toEqual(initialData)
64
- expect(result.new_value).toEqual(updatedData)
65
- })
66
- })
67
-
68
- describe('stream::get', () => {
69
- it('should get an existing stream item', async () => {
70
- const testData: TestData = { name: 'Test', value: 100 }
71
-
72
- await iii.call('stream::set', {
73
- stream_name: testStreamName,
74
- group_id: testGroupId,
75
- item_id: testItemId,
76
- data: testData,
77
- })
78
-
79
- const result: TestData = await iii.call('stream::get', {
80
- stream_name: testStreamName,
81
- group_id: testGroupId,
82
- item_id: testItemId,
83
- })
84
-
85
- expect(result).toBeDefined()
86
- expect(result).toEqual(testData)
87
- })
88
-
89
- it('should return null for non-existent item', async () => {
90
- const result = await iii.call('stream::get', {
91
- stream_name: testStreamName,
92
- group_id: testGroupId,
93
- item_id: 'non-existent-item',
94
- })
95
-
96
- expect(result).toBeUndefined()
97
- })
98
- })
99
-
100
- describe('stream::delete', () => {
101
- it('should delete an existing stream item', async () => {
102
- await iii.call('stream::set', {
103
- stream_name: testStreamName,
104
- group_id: testGroupId,
105
- item_id: testItemId,
106
- data: { test: true },
107
- })
108
-
109
- await iii.call('stream::delete', {
110
- stream_name: testStreamName,
111
- group_id: testGroupId,
112
- item_id: testItemId,
113
- })
114
-
115
- const result = await iii.call('stream::get', {
116
- stream_name: testStreamName,
117
- group_id: testGroupId,
118
- item_id: testItemId,
119
- })
120
-
121
- expect(result).toBeUndefined()
122
- })
123
-
124
- it('should handle deleting non-existent item gracefully', async () => {
125
- await expect(
126
- iii.call('stream::delete', {
127
- stream_name: testStreamName,
128
- group_id: testGroupId,
129
- item_id: 'non-existent',
130
- }),
131
- ).resolves.not.toThrow()
132
- })
133
- })
134
-
135
- describe('stream::list', () => {
136
- it('should get all items in a group', async () => {
137
- type TestDataWithId = TestData & { id: string }
138
-
139
- const groupId = `stream-${Date.now()}`
140
- const items: TestDataWithId[] = [
141
- { id: 'stream-item1', value: 1 },
142
- { id: 'stream-item2', value: 2 },
143
- { id: 'stream-item3', value: 3 },
144
- ]
145
-
146
- // Set multiple items
147
- for (const item of items) {
148
- await iii.call('stream::set', {
149
- stream_name: testStreamName,
150
- group_id: groupId,
151
- item_id: item.id,
152
- data: item,
153
- })
154
- }
155
-
156
- const result: TestDataWithId[] = await iii.call('stream::list', {
157
- stream_name: testStreamName,
158
- group_id: groupId,
159
- })
160
- const sort = (a: TestDataWithId, b: TestDataWithId) => a.id.localeCompare(b.id)
161
-
162
- expect(Array.isArray(result)).toBe(true)
163
- expect(result.length).toBeGreaterThanOrEqual(items.length)
164
- expect(result.sort(sort)).toEqual(items.sort(sort))
165
- })
166
- })
167
-
168
- describe('stream custom operations', () => {
169
- it('should perform a custom operation on a stream item', async () => {
170
- const testStreamName = `test-stream-${Date.now()}`
171
- const state: Map<string, TestData> = new Map()
172
-
173
- iii.createStream(testStreamName, {
174
- get: async input => state.get(`${input.group_id}::${input.item_id}`),
175
- set: async input => {
176
- const key = `${input.group_id}::${input.item_id}`
177
- const oldValue = state.get(key)
178
- state.set(key, input.data)
179
-
180
- return { old_value: oldValue, new_value: input.data }
181
- },
182
- delete: async input => {
183
- const oldValue = state.get(`${input.group_id}::${input.item_id}`)
184
- state.delete(`${input.group_id}::${input.item_id}`)
185
- return { old_value: oldValue }
186
- },
187
- list: async input => {
188
- return Array.from(state.keys())
189
- .filter(key => key.startsWith(`${input.group_id}::`))
190
- .map(key => state.get(key))
191
- },
192
- listGroups: async () => Array.from(state.keys()),
193
- update: async () => {
194
- throw new Error('Not implemented')
195
- },
196
- })
197
-
198
- await sleep(1_000)
199
-
200
- const testData: TestData = { name: 'Test', value: 100 }
201
- const getArgs = {
202
- stream_name: testStreamName,
203
- group_id: testGroupId,
204
- item_id: testItemId,
205
- }
206
-
207
- await iii.call('stream::set', { ...getArgs, data: testData })
208
-
209
- expect(state.get(`${testGroupId}::${testItemId}`)).toEqual(testData)
210
-
211
- await expect(iii.call('stream::get', getArgs)).resolves.toEqual(testData)
212
- await iii.call('stream::delete', getArgs)
213
- await expect(iii.call('stream::get', getArgs)).resolves.toEqual(undefined)
214
- })
215
- })
216
- })
package/tests/utils.ts DELETED
@@ -1,74 +0,0 @@
1
- // import { iii } from 'iii-sdk'
2
- import { init, Logger } from '../src/index'
3
-
4
- const ENGINE_WS_URL = process.env.III_BRIDGE_URL ?? 'ws://localhost:49199'
5
- const ENGINE_HTTP_URL = process.env.III_HTTP_URL ?? 'http://localhost:3199'
6
- const RETRY_LIMIT = 100
7
- const DELAY_MS = 100
8
-
9
- export const engineWsUrl = ENGINE_WS_URL
10
- export const engineHttpUrl = ENGINE_HTTP_URL
11
-
12
- export const iii = init(engineWsUrl, {
13
- otel: {
14
- serviceName: 'iii-tests',
15
- serviceVersion: '0.0.1',
16
- reconnectionConfig: {
17
- maxRetries: 3,
18
- initialDelayMs: 100,
19
- maxDelayMs: 1000,
20
- },
21
- },
22
- reconnectionConfig: {
23
- maxRetries: 3,
24
- initialDelayMs: 100,
25
- maxDelayMs: 1000,
26
- },
27
- })
28
-
29
- // Standalone logger for test utilities — no trace context needed
30
- export const logger = new Logger()
31
-
32
- export async function httpRequest(
33
- method: string,
34
- path: string,
35
- // biome-ignore lint/suspicious/noExplicitAny: any is fine here
36
- body?: any,
37
- // biome-ignore lint/suspicious/noExplicitAny: any is fine here
38
- ): Promise<{ status: number; data: any }> {
39
- const url = `${engineHttpUrl}${path}`
40
- const options: RequestInit = { method, headers: { 'Content-Type': 'application/json' } }
41
-
42
- if (body) {
43
- options.body = JSON.stringify(body)
44
- }
45
-
46
- const response = await fetch(url, options)
47
- const data = await response.json().catch(() => ({}))
48
-
49
- return { status: response.status, data }
50
- }
51
-
52
- export function sleep(duration: number): Promise<void> {
53
- return new Promise(resolve => {
54
- setTimeout(() => resolve(), duration)
55
- })
56
- }
57
-
58
- export async function execute<T>(operation: () => Promise<T>): Promise<T> {
59
- let currentAttempt = 0
60
-
61
- while (true) {
62
- try {
63
- return await operation()
64
- } catch (err) {
65
- currentAttempt++
66
-
67
- if (currentAttempt >= RETRY_LIMIT) {
68
- throw err
69
- }
70
-
71
- await sleep(DELAY_MS)
72
- }
73
- }
74
- }