@versori/run 0.5.4 → 0.5.6

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 (31) hide show
  1. package/esm/src/interpreter/durable/compilers/durableworkflow.d.ts.map +1 -1
  2. package/esm/src/interpreter/durable/compilers/durableworkflow.js +46 -29
  3. package/esm/src/interpreter/vanilla/ObservableCompiler.d.ts +0 -2
  4. package/esm/src/interpreter/vanilla/ObservableCompiler.d.ts.map +1 -1
  5. package/esm/src/interpreter/vanilla/VanillaInterpreter.d.ts +1 -3
  6. package/esm/src/interpreter/vanilla/VanillaInterpreter.d.ts.map +1 -1
  7. package/esm/src/interpreter/vanilla/VanillaInterpreter.js +4 -12
  8. package/esm/src/interpreter/vanilla/compilers/durableworkflow.d.ts.map +1 -1
  9. package/esm/src/interpreter/vanilla/compilers/durableworkflow.js +28 -30
  10. package/esm/src/kv/memory/MemoryKeyValue.d.ts.map +1 -1
  11. package/esm/src/kv/memory/MemoryKeyValue.js +70 -19
  12. package/esm/src/kv/nats/NatsKeyValue.d.ts.map +1 -1
  13. package/esm/src/kv/nats/NatsKeyValue.js +77 -23
  14. package/esm/src/kv/sdk/SDKKeyValue.d.ts.map +1 -1
  15. package/esm/src/kv/sdk/SDKKeyValue.js +103 -38
  16. package/package.json +1 -1
  17. package/script/src/interpreter/durable/compilers/durableworkflow.d.ts.map +1 -1
  18. package/script/src/interpreter/durable/compilers/durableworkflow.js +46 -29
  19. package/script/src/interpreter/vanilla/ObservableCompiler.d.ts +0 -2
  20. package/script/src/interpreter/vanilla/ObservableCompiler.d.ts.map +1 -1
  21. package/script/src/interpreter/vanilla/VanillaInterpreter.d.ts +1 -3
  22. package/script/src/interpreter/vanilla/VanillaInterpreter.d.ts.map +1 -1
  23. package/script/src/interpreter/vanilla/VanillaInterpreter.js +4 -12
  24. package/script/src/interpreter/vanilla/compilers/durableworkflow.d.ts.map +1 -1
  25. package/script/src/interpreter/vanilla/compilers/durableworkflow.js +28 -30
  26. package/script/src/kv/memory/MemoryKeyValue.d.ts.map +1 -1
  27. package/script/src/kv/memory/MemoryKeyValue.js +73 -19
  28. package/script/src/kv/nats/NatsKeyValue.d.ts.map +1 -1
  29. package/script/src/kv/nats/NatsKeyValue.js +80 -23
  30. package/script/src/kv/sdk/SDKKeyValue.d.ts.map +1 -1
  31. package/script/src/kv/sdk/SDKKeyValue.js +106 -38
@@ -11,9 +11,14 @@
11
11
  * As of the Change Date, in accordance with the Business Source License,
12
12
  * use of this software will be governed by the Apache License, Version 2.0.
13
13
  */
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
14
17
  Object.defineProperty(exports, "__esModule", { value: true });
15
18
  exports.NatsKeyValue = void 0;
16
19
  const KVNotFoundError_js_1 = require("../KVNotFoundError.js");
20
+ const api_1 = __importDefault(require("@opentelemetry/api"));
21
+ const tracer = api_1.default.trace.getTracer('versori-run-kv');
17
22
  class NatsKeyValue {
18
23
  constructor(kv, prefix) {
19
24
  Object.defineProperty(this, "kv", {
@@ -30,39 +35,91 @@ class NatsKeyValue {
30
35
  });
31
36
  }
32
37
  async get(key, options = {}) {
33
- let entry;
34
- try {
35
- entry = await this.kv.get(this.generateKey(key instanceof Array ? key.join('.') : key));
36
- }
37
- catch (error) {
38
- console.error('Unknown error reading from KV store', error);
39
- throw new Error('Unknown error reading from KV store');
40
- }
41
- if (!entry || ['DEL', 'PURGE'].includes(entry.operation)) {
42
- if (options.throwOnNotFound) {
43
- throw new KVNotFoundError_js_1.KVNotFoundError(key instanceof Array ? key.join('.') : key);
38
+ return await tracer.startActiveSpan('kv.get', async (span) => {
39
+ const keyStr = key instanceof Array ? key.join('.') : key;
40
+ span.setAttribute('kv.key', keyStr);
41
+ try {
42
+ let entry;
43
+ try {
44
+ entry = await this.kv.get(this.generateKey(keyStr));
45
+ }
46
+ catch (error) {
47
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
48
+ console.error('Unknown error reading from KV store', error);
49
+ throw new Error('Unknown error reading from KV store');
50
+ }
51
+ if (!entry || ['DEL', 'PURGE'].includes(entry.operation)) {
52
+ if (options.throwOnNotFound) {
53
+ throw new KVNotFoundError_js_1.KVNotFoundError(keyStr);
54
+ }
55
+ else if (typeof options.defaultValue !== 'undefined') {
56
+ return options.defaultValue;
57
+ }
58
+ return undefined;
59
+ }
60
+ return entry.json();
44
61
  }
45
- else if (typeof options.defaultValue !== 'undefined') {
46
- return options.defaultValue;
62
+ catch (error) {
63
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
64
+ throw error;
47
65
  }
48
- return undefined;
49
- }
50
- return entry.json();
66
+ finally {
67
+ span.end();
68
+ }
69
+ });
51
70
  }
52
71
  async set(key, value) {
53
- const payload = JSON.stringify(value);
54
- await this.kv.put(this.generateKey(key instanceof Array ? key.join('.') : key), payload);
72
+ return await tracer.startActiveSpan('kv.set', async (span) => {
73
+ const keyStr = key instanceof Array ? key.join('.') : key;
74
+ span.setAttribute('kv.key', keyStr);
75
+ try {
76
+ const payload = JSON.stringify(value);
77
+ await this.kv.put(this.generateKey(keyStr), payload);
78
+ }
79
+ catch (error) {
80
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
81
+ throw error;
82
+ }
83
+ finally {
84
+ span.end();
85
+ }
86
+ });
55
87
  }
56
88
  async delete(key) {
57
- await this.kv.delete(this.generateKey(key instanceof Array ? key.join('.') : key));
89
+ return await tracer.startActiveSpan('kv.delete', async (span) => {
90
+ const keyStr = key instanceof Array ? key.join('.') : key;
91
+ span.setAttribute('kv.key', keyStr);
92
+ try {
93
+ await this.kv.delete(this.generateKey(keyStr));
94
+ }
95
+ catch (error) {
96
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
97
+ throw error;
98
+ }
99
+ finally {
100
+ span.end();
101
+ }
102
+ });
58
103
  }
59
104
  list(prefix, options) {
60
- console.log('Listing not implemented', prefix, options);
61
- return Promise.reject(new Error('Listing not implemented'));
105
+ return tracer.startActiveSpan('kv.list', (span) => {
106
+ span.setAttribute('kv.prefix', prefix.join('.'));
107
+ console.log('Listing not implemented', prefix, options);
108
+ const err = new Error('Listing not implemented');
109
+ span.recordException(err);
110
+ span.end();
111
+ return Promise.reject(err);
112
+ });
62
113
  }
63
114
  count(prefix) {
64
- console.log('Count not implemented', prefix);
65
- return Promise.reject(new Error('Count not implemented'));
115
+ return tracer.startActiveSpan('kv.count', (span) => {
116
+ span.setAttribute('kv.prefix', prefix.join('.'));
117
+ console.log('Count not implemented', prefix);
118
+ const err = new Error('Count not implemented');
119
+ span.recordException(err);
120
+ span.end();
121
+ return Promise.reject(err);
122
+ });
66
123
  }
67
124
  generateKey(key) {
68
125
  return `${this.prefix}.${key instanceof Array ? key.join('.') : key}`;
@@ -1 +1 @@
1
- {"version":3,"file":"SDKKeyValue.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/sdk/SDKKeyValue.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,wDAAwD,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,4DAA4D,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,sDAAsD,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,uDAAuD,CAAC;AAGvF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEtD,qBAAa,WAAY,YAAW,QAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK;IAAuB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAnD,KAAK,EAAE,mBAAmB,EAAmB,MAAM,EAAE,MAAM;IAElF,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,GAAE,UAAU,CAAC,CAAC,CAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IA8BnF,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EA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C,IAAI,CAAC;IAqB7C,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC;IAsBjD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAwB9E,OAAO,CAAC,WAAW;CAGtB"}
@@ -11,10 +11,15 @@
11
11
  * As of the Change Date, in accordance with the Business Source License,
12
12
  * use of this software will be governed by the Apache License, Version 2.0.
13
13
  */
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
14
17
  Object.defineProperty(exports, "__esModule", { value: true });
15
18
  exports.SDKKeyValue = void 0;
16
19
  const KvOperationsService_js_1 = require("../../dsl/http/versori/kvapi/services/KvOperationsService.js");
17
20
  const QueryOperationsService_js_1 = require("../../dsl/http/versori/kvapi/services/QueryOperationsService.js");
21
+ const api_1 = __importDefault(require("@opentelemetry/api"));
22
+ const tracer = api_1.default.trace.getTracer('versori-run-kv');
18
23
  class SDKKeyValue {
19
24
  constructor(store, prefix) {
20
25
  Object.defineProperty(this, "store", {
@@ -31,59 +36,122 @@ class SDKKeyValue {
31
36
  });
32
37
  }
33
38
  async get(key, options = {}) {
34
- try {
35
- const k = this.generateKey(key instanceof Array ? key.join('/') : key);
36
- const entry = await KvOperationsService_js_1.KvOperationsService.getKv(this.store.id, k);
37
- if (entry.value === undefined) {
38
- if (options.throwOnNotFound) {
39
- throw new Error('Key not found');
39
+ return await tracer.startActiveSpan('kv.get', async (span) => {
40
+ const keyStr = key instanceof Array ? key.join('/') : key;
41
+ span.setAttribute('kv.key', keyStr);
42
+ span.setAttribute('kv.store_id', this.store.id);
43
+ try {
44
+ const k = this.generateKey(keyStr);
45
+ const entry = await KvOperationsService_js_1.KvOperationsService.getKv(this.store.id, k);
46
+ if (entry.value === undefined) {
47
+ if (options.throwOnNotFound) {
48
+ throw new Error('Key not found');
49
+ }
50
+ return undefined;
40
51
  }
41
- return undefined;
52
+ return JSON.parse(String(entry.value));
42
53
  }
43
- return JSON.parse(String(entry.value));
44
- }
45
- catch (error) {
46
- if (options.throwOnNotFound && error instanceof Error &&
47
- error.message === 'Key not found') {
48
- throw new Error('Key not found');
54
+ catch (error) {
55
+ if (options.throwOnNotFound && error instanceof Error &&
56
+ error.message === 'Key not found') {
57
+ throw new Error('Key not found');
58
+ }
59
+ else if (!options.throwOnNotFound) {
60
+ return undefined;
61
+ }
62
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
63
+ console.error('Unknown error reading from KV store', error);
64
+ throw new Error('Unknown error reading from KV store');
49
65
  }
50
- else if (!options.throwOnNotFound) {
51
- return undefined;
66
+ finally {
67
+ span.end();
52
68
  }
53
- console.error('Unknown error reading from KV store', error);
54
- throw new Error('Unknown error reading from KV store');
55
- }
69
+ });
56
70
  }
57
71
  async set(key, value) {
58
- const payload = JSON.stringify(value);
59
- const k = this.generateKey(key instanceof Array ? key.join('/') : key);
60
- await KvOperationsService_js_1.KvOperationsService.setKv(this.store.id, k, {
61
- value: payload,
62
- options: {},
72
+ return await tracer.startActiveSpan('kv.set', async (span) => {
73
+ const keyStr = key instanceof Array ? key.join('/') : key;
74
+ span.setAttribute('kv.key', keyStr);
75
+ span.setAttribute('kv.store_id', this.store.id);
76
+ try {
77
+ const payload = JSON.stringify(value);
78
+ const k = this.generateKey(keyStr);
79
+ await KvOperationsService_js_1.KvOperationsService.setKv(this.store.id, k, {
80
+ value: payload,
81
+ options: {},
82
+ });
83
+ }
84
+ catch (error) {
85
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
86
+ throw error;
87
+ }
88
+ finally {
89
+ span.end();
90
+ }
63
91
  });
64
92
  }
65
93
  async delete(key) {
66
- const k = this.generateKey(key instanceof Array ? key.join('/') : key);
67
- await KvOperationsService_js_1.KvOperationsService.deleteKv(this.store.id, k, {
68
- options: {},
94
+ return await tracer.startActiveSpan('kv.delete', async (span) => {
95
+ const keyStr = key instanceof Array ? key.join('/') : key;
96
+ span.setAttribute('kv.key', keyStr);
97
+ span.setAttribute('kv.store_id', this.store.id);
98
+ try {
99
+ const k = this.generateKey(keyStr);
100
+ await KvOperationsService_js_1.KvOperationsService.deleteKv(this.store.id, k, {
101
+ options: {},
102
+ });
103
+ }
104
+ catch (error) {
105
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
106
+ throw error;
107
+ }
108
+ finally {
109
+ span.end();
110
+ }
69
111
  });
70
112
  }
71
113
  async count(prefix) {
72
- const k = this.generateKey(prefix).split('/');
73
- return await QueryOperationsService_js_1.QueryOperationsService.countKv(this.store.id, {
74
- selector: {
75
- prefix: k,
76
- },
114
+ return await tracer.startActiveSpan('kv.count', async (span) => {
115
+ span.setAttribute('kv.prefix', prefix.join('/'));
116
+ span.setAttribute('kv.store_id', this.store.id);
117
+ try {
118
+ const k = this.generateKey(prefix).split('/');
119
+ return await QueryOperationsService_js_1.QueryOperationsService.countKv(this.store.id, {
120
+ selector: {
121
+ prefix: k,
122
+ },
123
+ });
124
+ }
125
+ catch (error) {
126
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
127
+ throw error;
128
+ }
129
+ finally {
130
+ span.end();
131
+ }
77
132
  });
78
133
  }
79
134
  async list(prefix, options) {
80
- const k = this.generateKey(prefix).split('/');
81
- return await QueryOperationsService_js_1.QueryOperationsService.listKv(this.store.id, {
82
- selector: {
83
- prefix: k,
84
- ...options?.selector,
85
- },
86
- options: options?.options,
135
+ return await tracer.startActiveSpan('kv.list', async (span) => {
136
+ span.setAttribute('kv.prefix', prefix.join('/'));
137
+ span.setAttribute('kv.store_id', this.store.id);
138
+ try {
139
+ const k = this.generateKey(prefix).split('/');
140
+ return await QueryOperationsService_js_1.QueryOperationsService.listKv(this.store.id, {
141
+ selector: {
142
+ prefix: k,
143
+ ...options?.selector,
144
+ },
145
+ options: options?.options,
146
+ });
147
+ }
148
+ catch (error) {
149
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
150
+ throw error;
151
+ }
152
+ finally {
153
+ span.end();
154
+ }
87
155
  });
88
156
  }
89
157
  generateKey(key) {