@versori/run 0.5.5 → 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.
- package/esm/src/interpreter/durable/compilers/durableworkflow.d.ts.map +1 -1
- package/esm/src/interpreter/durable/compilers/durableworkflow.js +46 -29
- package/esm/src/interpreter/vanilla/compilers/durableworkflow.d.ts.map +1 -1
- package/esm/src/interpreter/vanilla/compilers/durableworkflow.js +33 -16
- package/esm/src/kv/memory/MemoryKeyValue.d.ts.map +1 -1
- package/esm/src/kv/memory/MemoryKeyValue.js +70 -19
- package/esm/src/kv/nats/NatsKeyValue.d.ts.map +1 -1
- package/esm/src/kv/nats/NatsKeyValue.js +77 -23
- package/esm/src/kv/sdk/SDKKeyValue.d.ts.map +1 -1
- package/esm/src/kv/sdk/SDKKeyValue.js +103 -38
- package/package.json +1 -1
- package/script/src/interpreter/durable/compilers/durableworkflow.d.ts.map +1 -1
- package/script/src/interpreter/durable/compilers/durableworkflow.js +46 -29
- package/script/src/interpreter/vanilla/compilers/durableworkflow.d.ts.map +1 -1
- package/script/src/interpreter/vanilla/compilers/durableworkflow.js +33 -16
- package/script/src/kv/memory/MemoryKeyValue.d.ts.map +1 -1
- package/script/src/kv/memory/MemoryKeyValue.js +73 -19
- package/script/src/kv/nats/NatsKeyValue.d.ts.map +1 -1
- package/script/src/kv/nats/NatsKeyValue.js +80 -23
- package/script/src/kv/sdk/SDKKeyValue.d.ts.map +1 -1
- package/script/src/kv/sdk/SDKKeyValue.js +106 -38
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durableworkflow.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/durableworkflow.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"durableworkflow.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/durableworkflow.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAW,WAAW,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EACH,mBAAmB,EACnB,sBAAsB,EACzB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAgB,sBAAsB,CAClC,GAAG,EAAE,sBAAsB,EAC3B,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,WAAW,GACpB,UAAU,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC,CA2G9C;AAED,eAAO,MAAM,uBAAuB,EAAE,eAAe,CAAC,mBAAmB,EAAE,sBAAsB,CAIhG,CAAC"}
|
|
@@ -40,42 +40,59 @@ export function compileDurableWorkflow(ctx, trigger, signal) {
|
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
42
42
|
for (const wf of wfs.workflows) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
await ctx.tracer.startActiveSpan(`durableworkflow-${trigger.id}`, async (span) => {
|
|
44
|
+
span.setAttribute('task.id', trigger.id);
|
|
45
|
+
span.setAttribute('task.type', 'durableworkflow');
|
|
46
|
+
span.setAttribute('execution.id', wf.metadata?.executionId ?? '');
|
|
47
|
+
if (wf.metadata?.activationId) {
|
|
48
|
+
span.setAttribute('activation.id', wf.metadata.activationId);
|
|
49
|
+
}
|
|
47
50
|
try {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
const payload = wf.payload ? atob(wf.payload) : '{}';
|
|
52
|
+
const data = JSON.parse(payload);
|
|
53
|
+
let activation;
|
|
54
|
+
if (wf.metadata?.activationId) {
|
|
55
|
+
try {
|
|
56
|
+
const { data } = await ctx.platformApi.getActivation({
|
|
57
|
+
path: {
|
|
58
|
+
activation_id: wf.metadata.activationId,
|
|
59
|
+
organisation_id: ctx.organisationId,
|
|
60
|
+
environment_id: Deno.env.get(envVarEnvId) || 'development',
|
|
61
|
+
},
|
|
62
|
+
throwOnError: true,
|
|
63
|
+
});
|
|
64
|
+
activation = data;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
ctx.log.error('Failed to get activation', { error });
|
|
68
|
+
throw new Error('Failed to get activation');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const newContext = ctx.contextProvider.createWithExecutionId(activation, data, wf.metadata?.executionId ?? ulid().toString(), {
|
|
72
|
+
workflow: wf,
|
|
73
|
+
onSuccess: (completedContext) => {
|
|
74
|
+
// locked status means we own the workflow and it's not completed yet
|
|
75
|
+
if (wf.status !== 'locked') {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
ctx.queueProvider.complete({
|
|
79
|
+
id: wf.id,
|
|
80
|
+
output: btoa(JSON.stringify(completedContext.data)),
|
|
81
|
+
status: 'completed',
|
|
82
|
+
});
|
|
53
83
|
},
|
|
54
|
-
throwOnError: true,
|
|
55
84
|
});
|
|
56
|
-
|
|
85
|
+
consecutiveErrors = 0;
|
|
86
|
+
subscriber.next(newContext);
|
|
57
87
|
}
|
|
58
88
|
catch (error) {
|
|
59
|
-
|
|
60
|
-
|
|
89
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
90
|
+
ctx.log.error('Error processing workflow', { error });
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
span.end();
|
|
61
94
|
}
|
|
62
|
-
}
|
|
63
|
-
const newContext = ctx.contextProvider.createWithExecutionId(activation, data, wf.metadata?.executionId ?? ulid().toString(), {
|
|
64
|
-
workflow: wf,
|
|
65
|
-
onSuccess: (completedContext) => {
|
|
66
|
-
// locked status means we own the workflow and it's not completed yet
|
|
67
|
-
if (wf.status !== 'locked') {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
ctx.queueProvider.complete({
|
|
71
|
-
id: wf.id,
|
|
72
|
-
output: btoa(JSON.stringify(completedContext.data)),
|
|
73
|
-
status: 'completed',
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
95
|
});
|
|
77
|
-
consecutiveErrors = 0;
|
|
78
|
-
subscriber.next(newContext);
|
|
79
96
|
}
|
|
80
97
|
}
|
|
81
98
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durableworkflow.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/vanilla/compilers/durableworkflow.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"durableworkflow.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/vanilla/compilers/durableworkflow.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EACH,mBAAmB,EACnB,sBAAsB,EACzB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAqB,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,wBAAgB,sBAAsB,CAClC,GAAG,EAAE,sBAAsB,EAC3B,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,WAAW,GACpB,UAAU,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CA6FjD;AAED,eAAO,MAAM,uBAAuB,EAAE,eAAe,CAAC,mBAAmB,EAAE,sBAAsB,CAIhG,CAAC"}
|
|
@@ -40,24 +40,41 @@ export function compileDurableWorkflow(ctx, trigger, signal) {
|
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
42
42
|
for (const wf of wfs.workflows) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
await ctx.tracer.startActiveSpan(`durableworkflow-${trigger.id}`, (span) => {
|
|
44
|
+
span.setAttribute('task.id', trigger.id);
|
|
45
|
+
span.setAttribute('task.type', 'durableworkflow');
|
|
46
|
+
span.setAttribute('execution.id', wf.metadata?.executionId ?? '');
|
|
47
|
+
if (wf.metadata?.activationId) {
|
|
48
|
+
span.setAttribute('activation.id', wf.metadata.activationId);
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const payload = wf.payload ? atob(wf.payload) : '{}';
|
|
52
|
+
const data = JSON.parse(payload);
|
|
53
|
+
const newContext = ctx.contextProvider.createWithExecutionId(VanillaActivation, data, wf.metadata?.executionId ?? ulid().toString(), {
|
|
54
|
+
workflow: wf,
|
|
55
|
+
onSuccess: (completedContext) => {
|
|
56
|
+
// locked status means we own the workflow and it's not completed yet
|
|
57
|
+
if (wf.status !== 'locked') {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
ctx.queueProvider.complete({
|
|
61
|
+
id: wf.id,
|
|
62
|
+
output: btoa(JSON.stringify(completedContext.data)),
|
|
63
|
+
status: 'completed',
|
|
64
|
+
});
|
|
65
|
+
},
|
|
56
66
|
});
|
|
57
|
-
|
|
67
|
+
consecutiveErrors = 0;
|
|
68
|
+
subscriber.next(newContext);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
72
|
+
ctx.log.error('Error processing workflow', { error });
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
span.end();
|
|
76
|
+
}
|
|
58
77
|
});
|
|
59
|
-
consecutiveErrors = 0;
|
|
60
|
-
subscriber.next(newContext);
|
|
61
78
|
}
|
|
62
79
|
}
|
|
63
80
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryKeyValue.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/memory/MemoryKeyValue.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EACH,eAAe,EACf,aAAa,EACb,cAAc,EACjB,MAAM,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"file":"MemoryKeyValue.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/memory/MemoryKeyValue.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EACH,eAAe,EACf,aAAa,EACb,cAAc,EACjB,MAAM,uCAAuC,CAAC;AAK/C,qBAAa,cAAe,YAAW,QAAQ;IAC3C,OAAO,CAAC,KAAK,CAAmC;IAE1C,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IA0B/E,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBvD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBnD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAYxE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC;CAWpD"}
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* use of this software will be governed by the Apache License, Version 2.0.
|
|
12
12
|
*/
|
|
13
13
|
import { KVNotFoundError } from '../KVNotFoundError.js';
|
|
14
|
+
import opentelemetry from '@opentelemetry/api';
|
|
15
|
+
const tracer = opentelemetry.trace.getTracer('versori-run-kv');
|
|
14
16
|
export class MemoryKeyValue {
|
|
15
17
|
constructor() {
|
|
16
18
|
Object.defineProperty(this, "store", {
|
|
@@ -20,30 +22,79 @@ export class MemoryKeyValue {
|
|
|
20
22
|
value: new Map()
|
|
21
23
|
});
|
|
22
24
|
}
|
|
23
|
-
get(key, options) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
async get(key, options) {
|
|
26
|
+
return await tracer.startActiveSpan('kv.get', (span) => {
|
|
27
|
+
const keyStr = key instanceof Array ? key.join('.') : key;
|
|
28
|
+
span.setAttribute('kv.key', keyStr);
|
|
29
|
+
try {
|
|
30
|
+
const raw = this.store.get(keyStr);
|
|
31
|
+
if (typeof raw === 'undefined') {
|
|
32
|
+
if (options?.throwOnNotFound) {
|
|
33
|
+
throw new KVNotFoundError(keyStr);
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return raw;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
span.end();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
32
47
|
}
|
|
33
|
-
set(key, value) {
|
|
34
|
-
|
|
35
|
-
|
|
48
|
+
async set(key, value) {
|
|
49
|
+
return await tracer.startActiveSpan('kv.set', (span) => {
|
|
50
|
+
const keyStr = key instanceof Array ? key.join('.') : key;
|
|
51
|
+
span.setAttribute('kv.key', keyStr);
|
|
52
|
+
try {
|
|
53
|
+
this.store.set(keyStr, value);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
span.end();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
36
63
|
}
|
|
37
|
-
delete(key) {
|
|
38
|
-
|
|
39
|
-
|
|
64
|
+
async delete(key) {
|
|
65
|
+
return await tracer.startActiveSpan('kv.delete', (span) => {
|
|
66
|
+
const keyStr = key instanceof Array ? key.join('.') : key;
|
|
67
|
+
span.setAttribute('kv.key', keyStr);
|
|
68
|
+
try {
|
|
69
|
+
this.store.delete(keyStr);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
span.end();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
40
79
|
}
|
|
41
80
|
list(prefix, options) {
|
|
42
|
-
|
|
43
|
-
|
|
81
|
+
return tracer.startActiveSpan('kv.list', (span) => {
|
|
82
|
+
span.setAttribute('kv.prefix', prefix.join('.'));
|
|
83
|
+
console.log('Listing not implemented', prefix, options);
|
|
84
|
+
const err = new Error('Listing not implemented');
|
|
85
|
+
span.recordException(err);
|
|
86
|
+
span.end();
|
|
87
|
+
return Promise.reject(err);
|
|
88
|
+
});
|
|
44
89
|
}
|
|
45
90
|
count(prefix) {
|
|
46
|
-
|
|
47
|
-
|
|
91
|
+
return tracer.startActiveSpan('kv.count', (span) => {
|
|
92
|
+
span.setAttribute('kv.prefix', prefix.join('.'));
|
|
93
|
+
console.log('Count not implemented', prefix);
|
|
94
|
+
const err = new Error('Count not implemented');
|
|
95
|
+
span.recordException(err);
|
|
96
|
+
span.end();
|
|
97
|
+
return Promise.reject(err);
|
|
98
|
+
});
|
|
48
99
|
}
|
|
49
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NatsKeyValue.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/nats/NatsKeyValue.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,EAAE,EAAW,MAAM,mDAAmD,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EACH,eAAe,EACf,aAAa,EACb,cAAc,EACjB,MAAM,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"file":"NatsKeyValue.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/nats/NatsKeyValue.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,EAAE,EAAW,MAAM,mDAAmD,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EACH,eAAe,EACf,aAAa,EACb,cAAc,EACjB,MAAM,uCAAuC,CAAC;AAK/C,qBAAa,YAAa,YAAW,QAAQ;IAC7B,OAAO,CAAC,QAAQ,CAAC,EAAE;IAAM,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAA/B,EAAE,EAAE,EAAE,EAAmB,MAAM,EAAE,MAAM;IAE9D,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,GAAE,UAAU,CAAC,CAAC,CAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAqCnF,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBvD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBnD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAYxE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC;IAYjD,OAAO,CAAC,WAAW;CAGtB"}
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* use of this software will be governed by the Apache License, Version 2.0.
|
|
12
12
|
*/
|
|
13
13
|
import { KVNotFoundError } from '../KVNotFoundError.js';
|
|
14
|
+
import opentelemetry from '@opentelemetry/api';
|
|
15
|
+
const tracer = opentelemetry.trace.getTracer('versori-run-kv');
|
|
14
16
|
export class NatsKeyValue {
|
|
15
17
|
constructor(kv, prefix) {
|
|
16
18
|
Object.defineProperty(this, "kv", {
|
|
@@ -27,39 +29,91 @@ export class NatsKeyValue {
|
|
|
27
29
|
});
|
|
28
30
|
}
|
|
29
31
|
async get(key, options = {}) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
return await tracer.startActiveSpan('kv.get', async (span) => {
|
|
33
|
+
const keyStr = key instanceof Array ? key.join('.') : key;
|
|
34
|
+
span.setAttribute('kv.key', keyStr);
|
|
35
|
+
try {
|
|
36
|
+
let entry;
|
|
37
|
+
try {
|
|
38
|
+
entry = await this.kv.get(this.generateKey(keyStr));
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
42
|
+
console.error('Unknown error reading from KV store', error);
|
|
43
|
+
throw new Error('Unknown error reading from KV store');
|
|
44
|
+
}
|
|
45
|
+
if (!entry || ['DEL', 'PURGE'].includes(entry.operation)) {
|
|
46
|
+
if (options.throwOnNotFound) {
|
|
47
|
+
throw new KVNotFoundError(keyStr);
|
|
48
|
+
}
|
|
49
|
+
else if (typeof options.defaultValue !== 'undefined') {
|
|
50
|
+
return options.defaultValue;
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
return entry.json();
|
|
41
55
|
}
|
|
42
|
-
|
|
43
|
-
|
|
56
|
+
catch (error) {
|
|
57
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
58
|
+
throw error;
|
|
44
59
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
60
|
+
finally {
|
|
61
|
+
span.end();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
48
64
|
}
|
|
49
65
|
async set(key, value) {
|
|
50
|
-
|
|
51
|
-
|
|
66
|
+
return await tracer.startActiveSpan('kv.set', async (span) => {
|
|
67
|
+
const keyStr = key instanceof Array ? key.join('.') : key;
|
|
68
|
+
span.setAttribute('kv.key', keyStr);
|
|
69
|
+
try {
|
|
70
|
+
const payload = JSON.stringify(value);
|
|
71
|
+
await this.kv.put(this.generateKey(keyStr), payload);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
span.end();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
52
81
|
}
|
|
53
82
|
async delete(key) {
|
|
54
|
-
await
|
|
83
|
+
return await tracer.startActiveSpan('kv.delete', async (span) => {
|
|
84
|
+
const keyStr = key instanceof Array ? key.join('.') : key;
|
|
85
|
+
span.setAttribute('kv.key', keyStr);
|
|
86
|
+
try {
|
|
87
|
+
await this.kv.delete(this.generateKey(keyStr));
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
span.end();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
55
97
|
}
|
|
56
98
|
list(prefix, options) {
|
|
57
|
-
|
|
58
|
-
|
|
99
|
+
return tracer.startActiveSpan('kv.list', (span) => {
|
|
100
|
+
span.setAttribute('kv.prefix', prefix.join('.'));
|
|
101
|
+
console.log('Listing not implemented', prefix, options);
|
|
102
|
+
const err = new Error('Listing not implemented');
|
|
103
|
+
span.recordException(err);
|
|
104
|
+
span.end();
|
|
105
|
+
return Promise.reject(err);
|
|
106
|
+
});
|
|
59
107
|
}
|
|
60
108
|
count(prefix) {
|
|
61
|
-
|
|
62
|
-
|
|
109
|
+
return tracer.startActiveSpan('kv.count', (span) => {
|
|
110
|
+
span.setAttribute('kv.prefix', prefix.join('.'));
|
|
111
|
+
console.log('Count not implemented', prefix);
|
|
112
|
+
const err = new Error('Count not implemented');
|
|
113
|
+
span.recordException(err);
|
|
114
|
+
span.end();
|
|
115
|
+
return Promise.reject(err);
|
|
116
|
+
});
|
|
63
117
|
}
|
|
64
118
|
generateKey(key) {
|
|
65
119
|
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;
|
|
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;AAKtD,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;IAuCnF,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBvD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,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"}
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { KvOperationsService } from '../../dsl/http/versori/kvapi/services/KvOperationsService.js';
|
|
14
14
|
import { QueryOperationsService } from '../../dsl/http/versori/kvapi/services/QueryOperationsService.js';
|
|
15
|
+
import opentelemetry from '@opentelemetry/api';
|
|
16
|
+
const tracer = opentelemetry.trace.getTracer('versori-run-kv');
|
|
15
17
|
export class SDKKeyValue {
|
|
16
18
|
constructor(store, prefix) {
|
|
17
19
|
Object.defineProperty(this, "store", {
|
|
@@ -28,59 +30,122 @@ export class SDKKeyValue {
|
|
|
28
30
|
});
|
|
29
31
|
}
|
|
30
32
|
async get(key, options = {}) {
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
return await tracer.startActiveSpan('kv.get', async (span) => {
|
|
34
|
+
const keyStr = key instanceof Array ? key.join('/') : key;
|
|
35
|
+
span.setAttribute('kv.key', keyStr);
|
|
36
|
+
span.setAttribute('kv.store_id', this.store.id);
|
|
37
|
+
try {
|
|
38
|
+
const k = this.generateKey(keyStr);
|
|
39
|
+
const entry = await KvOperationsService.getKv(this.store.id, k);
|
|
40
|
+
if (entry.value === undefined) {
|
|
41
|
+
if (options.throwOnNotFound) {
|
|
42
|
+
throw new Error('Key not found');
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
37
45
|
}
|
|
38
|
-
return
|
|
46
|
+
return JSON.parse(String(entry.value));
|
|
39
47
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (options.throwOnNotFound && error instanceof Error &&
|
|
50
|
+
error.message === 'Key not found') {
|
|
51
|
+
throw new Error('Key not found');
|
|
52
|
+
}
|
|
53
|
+
else if (!options.throwOnNotFound) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
57
|
+
console.error('Unknown error reading from KV store', error);
|
|
58
|
+
throw new Error('Unknown error reading from KV store');
|
|
46
59
|
}
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
finally {
|
|
61
|
+
span.end();
|
|
49
62
|
}
|
|
50
|
-
|
|
51
|
-
throw new Error('Unknown error reading from KV store');
|
|
52
|
-
}
|
|
63
|
+
});
|
|
53
64
|
}
|
|
54
65
|
async set(key, value) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
return await tracer.startActiveSpan('kv.set', async (span) => {
|
|
67
|
+
const keyStr = key instanceof Array ? key.join('/') : key;
|
|
68
|
+
span.setAttribute('kv.key', keyStr);
|
|
69
|
+
span.setAttribute('kv.store_id', this.store.id);
|
|
70
|
+
try {
|
|
71
|
+
const payload = JSON.stringify(value);
|
|
72
|
+
const k = this.generateKey(keyStr);
|
|
73
|
+
await KvOperationsService.setKv(this.store.id, k, {
|
|
74
|
+
value: payload,
|
|
75
|
+
options: {},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
span.end();
|
|
84
|
+
}
|
|
60
85
|
});
|
|
61
86
|
}
|
|
62
87
|
async delete(key) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
88
|
+
return await tracer.startActiveSpan('kv.delete', async (span) => {
|
|
89
|
+
const keyStr = key instanceof Array ? key.join('/') : key;
|
|
90
|
+
span.setAttribute('kv.key', keyStr);
|
|
91
|
+
span.setAttribute('kv.store_id', this.store.id);
|
|
92
|
+
try {
|
|
93
|
+
const k = this.generateKey(keyStr);
|
|
94
|
+
await KvOperationsService.deleteKv(this.store.id, k, {
|
|
95
|
+
options: {},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
span.end();
|
|
104
|
+
}
|
|
66
105
|
});
|
|
67
106
|
}
|
|
68
107
|
async count(prefix) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
108
|
+
return await tracer.startActiveSpan('kv.count', async (span) => {
|
|
109
|
+
span.setAttribute('kv.prefix', prefix.join('/'));
|
|
110
|
+
span.setAttribute('kv.store_id', this.store.id);
|
|
111
|
+
try {
|
|
112
|
+
const k = this.generateKey(prefix).split('/');
|
|
113
|
+
return await QueryOperationsService.countKv(this.store.id, {
|
|
114
|
+
selector: {
|
|
115
|
+
prefix: k,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
span.end();
|
|
125
|
+
}
|
|
74
126
|
});
|
|
75
127
|
}
|
|
76
128
|
async list(prefix, options) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
129
|
+
return await tracer.startActiveSpan('kv.list', async (span) => {
|
|
130
|
+
span.setAttribute('kv.prefix', prefix.join('/'));
|
|
131
|
+
span.setAttribute('kv.store_id', this.store.id);
|
|
132
|
+
try {
|
|
133
|
+
const k = this.generateKey(prefix).split('/');
|
|
134
|
+
return await QueryOperationsService.listKv(this.store.id, {
|
|
135
|
+
selector: {
|
|
136
|
+
prefix: k,
|
|
137
|
+
...options?.selector,
|
|
138
|
+
},
|
|
139
|
+
options: options?.options,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
span.end();
|
|
148
|
+
}
|
|
84
149
|
});
|
|
85
150
|
}
|
|
86
151
|
generateKey(key) {
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durableworkflow.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/durableworkflow.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"durableworkflow.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/durableworkflow.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAW,WAAW,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EACH,mBAAmB,EACnB,sBAAsB,EACzB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAgB,sBAAsB,CAClC,GAAG,EAAE,sBAAsB,EAC3B,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,WAAW,GACpB,UAAU,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC,CA2G9C;AAED,eAAO,MAAM,uBAAuB,EAAE,eAAe,CAAC,mBAAmB,EAAE,sBAAsB,CAIhG,CAAC"}
|
|
@@ -44,42 +44,59 @@ function compileDurableWorkflow(ctx, trigger, signal) {
|
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
46
46
|
for (const wf of wfs.workflows) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
await ctx.tracer.startActiveSpan(`durableworkflow-${trigger.id}`, async (span) => {
|
|
48
|
+
span.setAttribute('task.id', trigger.id);
|
|
49
|
+
span.setAttribute('task.type', 'durableworkflow');
|
|
50
|
+
span.setAttribute('execution.id', wf.metadata?.executionId ?? '');
|
|
51
|
+
if (wf.metadata?.activationId) {
|
|
52
|
+
span.setAttribute('activation.id', wf.metadata.activationId);
|
|
53
|
+
}
|
|
51
54
|
try {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const payload = wf.payload ? atob(wf.payload) : '{}';
|
|
56
|
+
const data = JSON.parse(payload);
|
|
57
|
+
let activation;
|
|
58
|
+
if (wf.metadata?.activationId) {
|
|
59
|
+
try {
|
|
60
|
+
const { data } = await ctx.platformApi.getActivation({
|
|
61
|
+
path: {
|
|
62
|
+
activation_id: wf.metadata.activationId,
|
|
63
|
+
organisation_id: ctx.organisationId,
|
|
64
|
+
environment_id: Deno.env.get(constants_js_1.envVarEnvId) || 'development',
|
|
65
|
+
},
|
|
66
|
+
throwOnError: true,
|
|
67
|
+
});
|
|
68
|
+
activation = data;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
ctx.log.error('Failed to get activation', { error });
|
|
72
|
+
throw new Error('Failed to get activation');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const newContext = ctx.contextProvider.createWithExecutionId(activation, data, wf.metadata?.executionId ?? (0, mod_js_1.ulid)().toString(), {
|
|
76
|
+
workflow: wf,
|
|
77
|
+
onSuccess: (completedContext) => {
|
|
78
|
+
// locked status means we own the workflow and it's not completed yet
|
|
79
|
+
if (wf.status !== 'locked') {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
ctx.queueProvider.complete({
|
|
83
|
+
id: wf.id,
|
|
84
|
+
output: btoa(JSON.stringify(completedContext.data)),
|
|
85
|
+
status: 'completed',
|
|
86
|
+
});
|
|
57
87
|
},
|
|
58
|
-
throwOnError: true,
|
|
59
88
|
});
|
|
60
|
-
|
|
89
|
+
consecutiveErrors = 0;
|
|
90
|
+
subscriber.next(newContext);
|
|
61
91
|
}
|
|
62
92
|
catch (error) {
|
|
63
|
-
|
|
64
|
-
|
|
93
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
94
|
+
ctx.log.error('Error processing workflow', { error });
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
span.end();
|
|
65
98
|
}
|
|
66
|
-
}
|
|
67
|
-
const newContext = ctx.contextProvider.createWithExecutionId(activation, data, wf.metadata?.executionId ?? (0, mod_js_1.ulid)().toString(), {
|
|
68
|
-
workflow: wf,
|
|
69
|
-
onSuccess: (completedContext) => {
|
|
70
|
-
// locked status means we own the workflow and it's not completed yet
|
|
71
|
-
if (wf.status !== 'locked') {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
ctx.queueProvider.complete({
|
|
75
|
-
id: wf.id,
|
|
76
|
-
output: btoa(JSON.stringify(completedContext.data)),
|
|
77
|
-
status: 'completed',
|
|
78
|
-
});
|
|
79
|
-
},
|
|
80
99
|
});
|
|
81
|
-
consecutiveErrors = 0;
|
|
82
|
-
subscriber.next(newContext);
|
|
83
100
|
}
|
|
84
101
|
}
|
|
85
102
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durableworkflow.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/vanilla/compilers/durableworkflow.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"durableworkflow.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/vanilla/compilers/durableworkflow.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EACH,mBAAmB,EACnB,sBAAsB,EACzB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAqB,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,wBAAgB,sBAAsB,CAClC,GAAG,EAAE,sBAAsB,EAC3B,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,WAAW,GACpB,UAAU,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CA6FjD;AAED,eAAO,MAAM,uBAAuB,EAAE,eAAe,CAAC,mBAAmB,EAAE,sBAAsB,CAIhG,CAAC"}
|
|
@@ -44,24 +44,41 @@ function compileDurableWorkflow(ctx, trigger, signal) {
|
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
46
46
|
for (const wf of wfs.workflows) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
await ctx.tracer.startActiveSpan(`durableworkflow-${trigger.id}`, (span) => {
|
|
48
|
+
span.setAttribute('task.id', trigger.id);
|
|
49
|
+
span.setAttribute('task.type', 'durableworkflow');
|
|
50
|
+
span.setAttribute('execution.id', wf.metadata?.executionId ?? '');
|
|
51
|
+
if (wf.metadata?.activationId) {
|
|
52
|
+
span.setAttribute('activation.id', wf.metadata.activationId);
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const payload = wf.payload ? atob(wf.payload) : '{}';
|
|
56
|
+
const data = JSON.parse(payload);
|
|
57
|
+
const newContext = ctx.contextProvider.createWithExecutionId(ObservableCompiler_js_1.VanillaActivation, data, wf.metadata?.executionId ?? (0, mod_js_1.ulid)().toString(), {
|
|
58
|
+
workflow: wf,
|
|
59
|
+
onSuccess: (completedContext) => {
|
|
60
|
+
// locked status means we own the workflow and it's not completed yet
|
|
61
|
+
if (wf.status !== 'locked') {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
ctx.queueProvider.complete({
|
|
65
|
+
id: wf.id,
|
|
66
|
+
output: btoa(JSON.stringify(completedContext.data)),
|
|
67
|
+
status: 'completed',
|
|
68
|
+
});
|
|
69
|
+
},
|
|
60
70
|
});
|
|
61
|
-
|
|
71
|
+
consecutiveErrors = 0;
|
|
72
|
+
subscriber.next(newContext);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
76
|
+
ctx.log.error('Error processing workflow', { error });
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
span.end();
|
|
80
|
+
}
|
|
62
81
|
});
|
|
63
|
-
consecutiveErrors = 0;
|
|
64
|
-
subscriber.next(newContext);
|
|
65
82
|
}
|
|
66
83
|
}
|
|
67
84
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryKeyValue.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/memory/MemoryKeyValue.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EACH,eAAe,EACf,aAAa,EACb,cAAc,EACjB,MAAM,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"file":"MemoryKeyValue.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/memory/MemoryKeyValue.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EACH,eAAe,EACf,aAAa,EACb,cAAc,EACjB,MAAM,uCAAuC,CAAC;AAK/C,qBAAa,cAAe,YAAW,QAAQ;IAC3C,OAAO,CAAC,KAAK,CAAmC;IAE1C,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IA0B/E,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBvD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBnD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAYxE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC;CAWpD"}
|
|
@@ -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.MemoryKeyValue = 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 MemoryKeyValue {
|
|
18
23
|
constructor() {
|
|
19
24
|
Object.defineProperty(this, "store", {
|
|
@@ -23,31 +28,80 @@ class MemoryKeyValue {
|
|
|
23
28
|
value: new Map()
|
|
24
29
|
});
|
|
25
30
|
}
|
|
26
|
-
get(key, options) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
async get(key, options) {
|
|
32
|
+
return await tracer.startActiveSpan('kv.get', (span) => {
|
|
33
|
+
const keyStr = key instanceof Array ? key.join('.') : key;
|
|
34
|
+
span.setAttribute('kv.key', keyStr);
|
|
35
|
+
try {
|
|
36
|
+
const raw = this.store.get(keyStr);
|
|
37
|
+
if (typeof raw === 'undefined') {
|
|
38
|
+
if (options?.throwOnNotFound) {
|
|
39
|
+
throw new KVNotFoundError_js_1.KVNotFoundError(keyStr);
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return raw;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
span.end();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
35
53
|
}
|
|
36
|
-
set(key, value) {
|
|
37
|
-
|
|
38
|
-
|
|
54
|
+
async set(key, value) {
|
|
55
|
+
return await tracer.startActiveSpan('kv.set', (span) => {
|
|
56
|
+
const keyStr = key instanceof Array ? key.join('.') : key;
|
|
57
|
+
span.setAttribute('kv.key', keyStr);
|
|
58
|
+
try {
|
|
59
|
+
this.store.set(keyStr, value);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
span.end();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
39
69
|
}
|
|
40
|
-
delete(key) {
|
|
41
|
-
|
|
42
|
-
|
|
70
|
+
async delete(key) {
|
|
71
|
+
return await tracer.startActiveSpan('kv.delete', (span) => {
|
|
72
|
+
const keyStr = key instanceof Array ? key.join('.') : key;
|
|
73
|
+
span.setAttribute('kv.key', keyStr);
|
|
74
|
+
try {
|
|
75
|
+
this.store.delete(keyStr);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
span.end();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
43
85
|
}
|
|
44
86
|
list(prefix, options) {
|
|
45
|
-
|
|
46
|
-
|
|
87
|
+
return tracer.startActiveSpan('kv.list', (span) => {
|
|
88
|
+
span.setAttribute('kv.prefix', prefix.join('.'));
|
|
89
|
+
console.log('Listing not implemented', prefix, options);
|
|
90
|
+
const err = new Error('Listing not implemented');
|
|
91
|
+
span.recordException(err);
|
|
92
|
+
span.end();
|
|
93
|
+
return Promise.reject(err);
|
|
94
|
+
});
|
|
47
95
|
}
|
|
48
96
|
count(prefix) {
|
|
49
|
-
|
|
50
|
-
|
|
97
|
+
return tracer.startActiveSpan('kv.count', (span) => {
|
|
98
|
+
span.setAttribute('kv.prefix', prefix.join('.'));
|
|
99
|
+
console.log('Count not implemented', prefix);
|
|
100
|
+
const err = new Error('Count not implemented');
|
|
101
|
+
span.recordException(err);
|
|
102
|
+
span.end();
|
|
103
|
+
return Promise.reject(err);
|
|
104
|
+
});
|
|
51
105
|
}
|
|
52
106
|
}
|
|
53
107
|
exports.MemoryKeyValue = MemoryKeyValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NatsKeyValue.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/nats/NatsKeyValue.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,EAAE,EAAW,MAAM,mDAAmD,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EACH,eAAe,EACf,aAAa,EACb,cAAc,EACjB,MAAM,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"file":"NatsKeyValue.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/nats/NatsKeyValue.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,EAAE,EAAW,MAAM,mDAAmD,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EACH,eAAe,EACf,aAAa,EACb,cAAc,EACjB,MAAM,uCAAuC,CAAC;AAK/C,qBAAa,YAAa,YAAW,QAAQ;IAC7B,OAAO,CAAC,QAAQ,CAAC,EAAE;IAAM,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAA/B,EAAE,EAAE,EAAE,EAAmB,MAAM,EAAE,MAAM;IAE9D,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,GAAE,UAAU,CAAC,CAAC,CAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAqCnF,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBvD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBnD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAYxE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC;IAYjD,OAAO,CAAC,WAAW;CAGtB"}
|
|
@@ -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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
46
|
-
|
|
62
|
+
catch (error) {
|
|
63
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
64
|
+
throw error;
|
|
47
65
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
66
|
+
finally {
|
|
67
|
+
span.end();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
51
70
|
}
|
|
52
71
|
async set(key, value) {
|
|
53
|
-
|
|
54
|
-
|
|
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
|
|
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
|
-
|
|
61
|
-
|
|
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
|
-
|
|
65
|
-
|
|
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;
|
|
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;AAKtD,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;IAuCnF,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBvD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,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
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
52
|
+
return JSON.parse(String(entry.value));
|
|
42
53
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
51
|
-
|
|
66
|
+
finally {
|
|
67
|
+
span.end();
|
|
52
68
|
}
|
|
53
|
-
|
|
54
|
-
throw new Error('Unknown error reading from KV store');
|
|
55
|
-
}
|
|
69
|
+
});
|
|
56
70
|
}
|
|
57
71
|
async set(key, value) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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) {
|