@sentio/runtime 3.0.0-rc.7 → 3.0.0-rc.8
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/lib/{chunk-N3DTZ2BC.js → chunk-6MZJOWMH.js} +2 -2
- package/lib/{chunk-N3DTZ2BC.js.map → chunk-6MZJOWMH.js.map} +1 -1
- package/lib/{chunk-6XHWJ2VS.js → chunk-N3VEKOPD.js} +7 -2
- package/lib/chunk-N3VEKOPD.js.map +1 -0
- package/lib/{chunk-OFR7W4ZG.js → chunk-QHFSZVR5.js} +19 -13
- package/lib/{chunk-OFR7W4ZG.js.map → chunk-QHFSZVR5.js.map} +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +3 -3
- package/lib/{processor-CIR4erWa.d.ts → processor-CNHsQeJ6.d.ts} +4 -3
- package/lib/processor-runner.js +3 -12
- package/lib/processor-runner.js.map +1 -1
- package/lib/service-worker.js +2 -2
- package/lib/test-processor.test.d.ts +1 -1
- package/package.json +1 -1
- package/src/db-context.ts +1 -1
- package/src/plugin.ts +15 -4
- package/src/service-v3.ts +2 -3
- package/src/state.ts +4 -1
- package/lib/chunk-6XHWJ2VS.js.map +0 -1
package/lib/service-worker.js
CHANGED
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
require_cjs,
|
|
11
11
|
require_lib3 as require_lib,
|
|
12
12
|
require_lib4 as require_lib2
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-6MZJOWMH.js";
|
|
14
|
+
import "./chunk-QHFSZVR5.js";
|
|
15
15
|
import "./chunk-MV6JXS2P.js";
|
|
16
16
|
import {
|
|
17
17
|
__toESM
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as Plugin, D as DataBinding, a as ProcessResult, H as HandlerType } from './processor-
|
|
1
|
+
import { P as Plugin, D as DataBinding, a as ProcessResult, H as HandlerType } from './processor-CNHsQeJ6.js';
|
|
2
2
|
import { ProcessStreamResponse_Partitions, InitResponse, ProcessConfigResponse } from '@sentio/protos';
|
|
3
3
|
import 'rxjs';
|
|
4
4
|
import 'node:async_hooks';
|
package/package.json
CHANGED
package/src/db-context.ts
CHANGED
|
@@ -253,7 +253,7 @@ export class StoreContext extends AbstractStoreContext {
|
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
// for service
|
|
256
|
+
// for service v3
|
|
257
257
|
export class DataBindingContext extends AbstractStoreContext implements IDataBindingContext {
|
|
258
258
|
constructor(
|
|
259
259
|
readonly processId: number,
|
package/src/plugin.ts
CHANGED
|
@@ -8,9 +8,10 @@ import {
|
|
|
8
8
|
ProcessStreamResponse_Partitions,
|
|
9
9
|
ProcessStreamResponse_Partitions_Partition_SysValue,
|
|
10
10
|
StartRequest,
|
|
11
|
+
TemplateInstance,
|
|
11
12
|
UpdateTemplatesRequest
|
|
12
13
|
} from '@sentio/protos'
|
|
13
|
-
import {
|
|
14
|
+
import { IDataBindingContext, IStoreContext } from './db-context.js'
|
|
14
15
|
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
15
16
|
|
|
16
17
|
export abstract class Plugin {
|
|
@@ -65,7 +66,7 @@ export abstract class Plugin {
|
|
|
65
66
|
export class PluginManager {
|
|
66
67
|
static INSTANCE = new PluginManager()
|
|
67
68
|
|
|
68
|
-
dbContextLocalStorage = new AsyncLocalStorage<IStoreContext | undefined>()
|
|
69
|
+
dbContextLocalStorage = new AsyncLocalStorage<IDataBindingContext | IStoreContext | undefined>()
|
|
69
70
|
plugins: Plugin[] = []
|
|
70
71
|
typesToPlugin = new Map<HandlerType, Plugin>()
|
|
71
72
|
|
|
@@ -112,7 +113,7 @@ export class PluginManager {
|
|
|
112
113
|
processBinding(
|
|
113
114
|
request: DataBinding,
|
|
114
115
|
preparedData: PreparedData | undefined,
|
|
115
|
-
dbContext?: IStoreContext
|
|
116
|
+
dbContext?: IDataBindingContext | IStoreContext
|
|
116
117
|
): Promise<ProcessResult> {
|
|
117
118
|
const plugin = this.typesToPlugin.get(request.handlerType)
|
|
118
119
|
if (!plugin) {
|
|
@@ -134,7 +135,7 @@ export class PluginManager {
|
|
|
134
135
|
preprocessBinding(
|
|
135
136
|
request: DataBinding,
|
|
136
137
|
preprocessStore: { [k: string]: any },
|
|
137
|
-
dbContext?:
|
|
138
|
+
dbContext?: IDataBindingContext | IStoreContext
|
|
138
139
|
): Promise<PreprocessResult> {
|
|
139
140
|
const plugin = this.typesToPlugin.get(request.handlerType)
|
|
140
141
|
if (!plugin) {
|
|
@@ -152,4 +153,14 @@ export class PluginManager {
|
|
|
152
153
|
})
|
|
153
154
|
}
|
|
154
155
|
}
|
|
156
|
+
|
|
157
|
+
sendTemplateInstance(instance: TemplateInstance) {
|
|
158
|
+
// send template instance within the current db context
|
|
159
|
+
// this is only work in user handlers, when dbContextLocalStorage is set
|
|
160
|
+
// plugin.Configure does not have db context
|
|
161
|
+
const store = this.dbContextLocalStorage.getStore()
|
|
162
|
+
if (store && 'sendTemplateRequest' in store) {
|
|
163
|
+
store?.sendTemplateRequest([instance])
|
|
164
|
+
}
|
|
165
|
+
}
|
|
155
166
|
}
|
package/src/service-v3.ts
CHANGED
|
@@ -24,7 +24,6 @@ import { errorString } from './utils.js'
|
|
|
24
24
|
import { processMetrics } from './metrics.js'
|
|
25
25
|
import { recordRuntimeInfo } from './service.js'
|
|
26
26
|
import { DataBindingContext } from './db-context.js'
|
|
27
|
-
import { TemplateInstanceState } from './state.js'
|
|
28
27
|
import { freezeGlobalConfig } from './global-config.js'
|
|
29
28
|
import { ProcessorRuntimeOptions } from 'processor-runner-program.js'
|
|
30
29
|
|
|
@@ -182,7 +181,7 @@ export class ProcessorServiceImplV3 implements ProcessorV3ServiceImplementation
|
|
|
182
181
|
})
|
|
183
182
|
}
|
|
184
183
|
|
|
185
|
-
if (result.states?.configUpdated) {
|
|
184
|
+
/* if (result.states?.configUpdated) {
|
|
186
185
|
console.debug('sending tpl updates:')
|
|
187
186
|
subject.next({
|
|
188
187
|
processId,
|
|
@@ -190,7 +189,7 @@ export class ProcessorServiceImplV3 implements ProcessorV3ServiceImplementation
|
|
|
190
189
|
templates: TemplateInstanceState.INSTANCE.getValues()
|
|
191
190
|
}
|
|
192
191
|
})
|
|
193
|
-
}
|
|
192
|
+
}*/
|
|
194
193
|
|
|
195
194
|
console.debug('sending binding result', processId)
|
|
196
195
|
subject.next({
|
package/src/state.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TemplateInstance } from '@sentio/protos'
|
|
2
2
|
import { isMainThread, parentPort, threadId } from 'node:worker_threads'
|
|
3
|
+
import { PluginManager } from './plugin.js'
|
|
3
4
|
|
|
4
5
|
export class State {
|
|
5
6
|
stateMap = new Map<string, any>()
|
|
@@ -97,6 +98,8 @@ export class TemplateInstanceState extends ListStateStorage<TemplateInstance> {
|
|
|
97
98
|
// I'm worker thread, should notice the main thread
|
|
98
99
|
parentPort?.postMessage({ event: 'add_template_instance', value, from: threadId })
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
+
const ret = super.addValue(value)
|
|
102
|
+
PluginManager.INSTANCE.sendTemplateInstance(ret)
|
|
103
|
+
return ret
|
|
101
104
|
}
|
|
102
105
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/state.ts"],"sourcesContent":["import { TemplateInstance } from '@sentio/protos'\nimport { isMainThread, parentPort, threadId } from 'node:worker_threads'\n\nexport class State {\n stateMap = new Map<string, any>()\n\n static INSTANCE = new State()\n\n static reset() {\n State.INSTANCE = new State()\n }\n}\n\nexport abstract class StateStorage<T> {\n // TODO learn how to define single instance for all subclasses\n\n protected constructor() {\n //\n }\n\n abstract initValue(): T\n\n key(): string {\n return this.constructor.name\n }\n\n getOrRegister(): T {\n let metricState: T = State.INSTANCE.stateMap.get(this.key())\n if (!metricState) {\n metricState = this.initValue()\n State.INSTANCE.stateMap.set(this.key(), metricState)\n }\n return metricState\n }\n\n unregister(): T {\n const value = State.INSTANCE.stateMap.get(this.key())\n State.INSTANCE.stateMap.delete(this.key())\n return value\n }\n}\n\nexport abstract class MapStateStorage<T> extends StateStorage<Map<string, T>> {\n initValue() {\n return new Map<string, T>()\n }\n\n getValue(key: string): T | undefined {\n const m = this.getOrRegister()\n return m.get(key)\n }\n\n getValues(): T[] {\n const m = this.getOrRegister()\n return Array.from(m.values())\n }\n\n getOrSetValue(key: string, value: T): T {\n const m = this.getOrRegister()\n const oldValue = m.get(key)\n if (oldValue) {\n if (oldValue !== value) {\n console.warn(key, 'has been registered twice, use the previous one')\n }\n return oldValue\n }\n m.set(key, value)\n return value\n }\n}\n\nexport abstract class ListStateStorage<T> extends StateStorage<T[]> {\n initValue() {\n return []\n }\n\n getValues(): T[] {\n return this.getOrRegister()\n }\n\n addValue(value: T): T {\n const m = this.getOrRegister()\n m.push(value)\n return value\n }\n}\n\nexport class TemplateInstanceState extends ListStateStorage<TemplateInstance> {\n static INSTANCE = new TemplateInstanceState()\n\n constructor() {\n super()\n }\n\n override addValue(value: TemplateInstance): TemplateInstance {\n if (!isMainThread) {\n // I'm worker thread, should notice the main thread\n parentPort?.postMessage({ event: 'add_template_instance', value, from: threadId })\n }\n return super.addValue(value)\n }\n}\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":";;;AACA,SAAS,cAAc,YAAY,gBAAgB;AAE5C,IAAM,QAAN,MAAM,OAAM;AAAA,EACjB,WAAW,oBAAI,IAAiB;AAAA,EAEhC,OAAO,WAAW,IAAI,OAAM;AAAA,EAE5B,OAAO,QAAQ;AACb,WAAM,WAAW,IAAI,OAAM;AAAA,EAC7B;AACF;AAEO,IAAe,eAAf,MAA+B;AAAA;AAAA,EAG1B,cAAc;AAAA,EAExB;AAAA,EAIA,MAAc;AACZ,WAAO,KAAK,YAAY;AAAA,EAC1B;AAAA,EAEA,gBAAmB;AACjB,QAAI,cAAiB,MAAM,SAAS,SAAS,IAAI,KAAK,IAAI,CAAC;AAC3D,QAA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