@ms-cloudpack/data-bus 0.3.1 → 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.
package/README.md CHANGED
@@ -25,6 +25,23 @@ import { createDataBus } from '@ms-cloudpack/data-bus';
25
25
  export const bus = createDataBus();
26
26
  ```
27
27
 
28
+ ### Creating data paths
29
+
30
+ Data in the data bus is represented as a tree. Each node in the tree has a parent and children, and can contain data. To represent the expectations of what data is in each node, we define a data path object and reference it when publishing and subscribing to it. This ensures proper type safety.
31
+
32
+ The purpose of the `path` parameter is to define the path in the tree where the data lives. This is useful because you can subscribe to any branch of the tree and receive change notifications (via subscriptions or provider activations) for all nodes under that branch.
33
+
34
+ Example of defining a data path:
35
+
36
+ ```js
37
+ import z from 'zod';
38
+
39
+ const itemCountPath = createDataPath({
40
+ path: ['items', 'itemCount'],
41
+ type: z.number(),
42
+ });
43
+ ```
44
+
28
45
  ### Subscribing to data
29
46
 
30
47
  The data bus provides a method `subscribe` for consumers to subscribe to different types of data. As that data changes, consumers will be notified of changes. Any number of consumers can subscribe for the same data. Data is
@@ -32,7 +49,9 @@ hierarchical, so you can subscribe to a full branch, or to a leaf node within th
32
49
  string arrays.
33
50
 
34
51
  ```js
35
- const dispose = bus.subscribe(['produce', 'apples'], (data, path) => {
52
+ import { itemCountPath } from './dataPaths';
53
+
54
+ const dispose = bus.subscribe(itemCountPath, (count) => {
36
55
  console.log(`${data} (${path.join('/')})`);
37
56
  });
38
57
  ```
@@ -44,9 +63,12 @@ Callers can unsubscribe from data by calling the `dispose` function returned fro
44
63
  Data can be published using the `publish` api:
45
64
 
46
65
  ```js
47
- bus.publish(['produce', 'apples'], 42);
66
+ import { itemCountPath } from './dataPaths';
48
67
 
49
- // The subscriber will log "42 (produce/apples)"
68
+ bus.subscribe(itemCountPath, (count) => console.log(count));
69
+ bus.publish(itemCountPath, 42);
70
+
71
+ // The console will read: 42
50
72
  ```
51
73
 
52
74
  ### Using providers to produce data on demand
@@ -55,20 +77,26 @@ Providers can also be registered with the bus to provide data on demand, so that
55
77
  to be gathered unless it is being observed:
56
78
 
57
79
  ```js
58
- const intervals = {};
80
+ import { itemCountPath } from './dataPaths';
81
+
82
+ const intervalId;
59
83
 
60
84
  bus.addProvider({
61
- path: ['produce'],
62
- onActivate: (path) => {
85
+ path: itemCountPath,
86
+
87
+ // Called when activated.
88
+ onActivate: (itemCountPath) => {
63
89
  let counter = 0;
64
- interfaces[path.join('/')] = setInterval(() => {
65
- bus.publish(type, id, counter++);
90
+
91
+ intervalId = setInterval(() => {
92
+ bus.publish(itemCountPath, counter++);
66
93
  }, 1000);
67
94
  },
68
- onDeactivate: (path) => {
69
- const pathId = path.join('/');
70
- clearInterval(intervals[pathId]);
71
- delete intervals[pathId];
95
+
96
+ // Called when deactivated.
97
+ onDeactivate: (itemCountPath) => {
98
+ bus.publish(itemCountPath, 0);
99
+ clearInterval(intervalId);
72
100
  },
73
101
  });
74
102
  ```
@@ -83,7 +111,9 @@ redundantly.
83
111
  In some cases, we may need to simply read the data without subscribing. In this case, the `getData` api can be used:
84
112
 
85
113
  ```js
86
- const currentValue = bus.getData(['some-data-type', 'some-data-id']);
114
+ import { itemCountPath } from './dataPaths';
115
+
116
+ const currentValue = bus.getData(itemCountPath);
87
117
  ```
88
118
 
89
119
  ## Motivation
@@ -1 +1 @@
1
- {"version":3,"file":"createDataBus.d.ts","sourceRoot":"","sources":["../src/createDataBus.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGlD;;GAEG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAyCvC"}
1
+ {"version":3,"file":"createDataBus.d.ts","sourceRoot":"","sources":["../src/createDataBus.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAIlD;;GAEG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAmDvC"}
@@ -12,12 +12,17 @@ export function createDataBus() {
12
12
  };
13
13
  const disposables = [];
14
14
  const bus = {
15
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
- publish: (path, value) => publish(state, bus, path, value),
17
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
- getData: (path) => getData(state, path),
19
- subscribe: (path, change) => {
20
- const internalDispose = subscribe(state, bus, path, change);
15
+ publish(path, value) {
16
+ const publishPath = Array.isArray(path) ? path : path.path;
17
+ return publish(state, bus, publishPath, value);
18
+ },
19
+ getData(path) {
20
+ const publishPath = Array.isArray(path) ? path : path.path;
21
+ return getData(state, publishPath);
22
+ },
23
+ subscribe(path, change) {
24
+ const publishPath = Array.isArray(path) ? path : path.path;
25
+ const internalDispose = subscribe(state, bus, publishPath, change);
21
26
  const dispose = () => {
22
27
  const index = disposables.indexOf(dispose);
23
28
  if (index !== -1) {
@@ -28,8 +33,10 @@ export function createDataBus() {
28
33
  disposables.push(dispose);
29
34
  return dispose;
30
35
  },
31
- addProvider: (provider) => addProvider(state, provider),
32
- dispose: () => {
36
+ addProvider(provider) {
37
+ addProvider(state, provider);
38
+ },
39
+ dispose() {
33
40
  for (const dispose of disposables) {
34
41
  dispose();
35
42
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createDataBus.js","sourceRoot":"","sources":["../src/createDataBus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAO3C;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,KAAK,GAAiB;QAC1B,IAAI,EAAE,UAAU,EAAE;KACnB,CAAC;IAEF,MAAM,WAAW,GAAsB,EAAE,CAAC;IAC1C,MAAM,GAAG,GAAG;QACV,8DAA8D;QAC9D,OAAO,EAAE,CAAC,IAAc,EAAE,KAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC;QAEzE,8DAA8D;QAC9D,OAAO,EAAE,CAAc,IAAc,EAAE,EAAE,CAAC,OAAO,CAAQ,KAAK,EAAE,IAAI,CAAC;QAErE,SAAS,EAAE,CAAC,IAAc,EAAE,MAA6B,EAAE,EAAE;YAC3D,MAAM,eAAe,GAAG,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;YAE5D,MAAM,OAAO,GAAG,GAAG,EAAE;gBACnB,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAE3C,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;oBAChB,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;iBAC9B;gBAED,eAAe,EAAE,CAAC;YACpB,CAAC,CAAC;YAEF,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAE1B,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,WAAW,EAAE,CAAC,QAAyB,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC;QAExE,OAAO,EAAE,GAAG,EAAE;YACZ,KAAK,MAAM,OAAO,IAAI,WAAW,EAAE;gBACjC,OAAO,EAAE,CAAC;aACX;QACH,CAAC;KACF,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { addProvider } from './addProvider.js';\nimport { createNode } from './createNode.js';\nimport { getData } from './getData.js';\nimport { publish } from './publish.js';\nimport { subscribe } from './subscribe.js';\nimport type { DataBusChangeFunction } from './types/DataBusChangeFunction.js';\nimport type { DataBusProvider } from './types/DataBusProvider.js';\nimport type { DataBusState } from './types/DataBusState.js';\nimport type { DataBus } from './types/DataBus.js';\nimport type { DisposeFunction } from './types/DisposeFunction.js';\n\n/**\n * Creates a new data bus instance.\n */\nexport function createDataBus(): DataBus {\n const state: DataBusState = {\n root: createNode(),\n };\n\n const disposables: DisposeFunction[] = [];\n const bus = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n publish: (path: string[], value: any) => publish(state, bus, path, value),\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getData: <TData = any>(path: string[]) => getData<TData>(state, path),\n\n subscribe: (path: string[], change: DataBusChangeFunction) => {\n const internalDispose = subscribe(state, bus, path, change);\n\n const dispose = () => {\n const index = disposables.indexOf(dispose);\n\n if (index !== -1) {\n disposables.splice(index, 1);\n }\n\n internalDispose();\n };\n\n disposables.push(dispose);\n\n return dispose;\n },\n\n addProvider: (provider: DataBusProvider) => addProvider(state, provider),\n\n dispose: () => {\n for (const dispose of disposables) {\n dispose();\n }\n },\n };\n\n return bus;\n}\n"]}
1
+ {"version":3,"file":"createDataBus.js","sourceRoot":"","sources":["../src/createDataBus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAQ3C;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,KAAK,GAAiB;QAC1B,IAAI,EAAE,UAAU,EAAE;KACnB,CAAC;IAEF,MAAM,WAAW,GAAsB,EAAE,CAAC;IAE1C,MAAM,GAAG,GAAY;QACnB,OAAO,CAAQ,IAA4B,EAAE,KAAY;YACvD,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YAE3D,OAAO,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;QACjD,CAAC;QAED,OAAO,CAAQ,IAA4B;YACzC,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YAE3D,OAAO,OAAO,CAAQ,KAAK,EAAE,WAAW,CAAC,CAAC;QAC5C,CAAC;QAED,SAAS,CAAC,IAA4B,EAAE,MAA6B;YACnE,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YAC3D,MAAM,eAAe,GAAG,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;YAEnE,MAAM,OAAO,GAAG,GAAG,EAAE;gBACnB,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAE3C,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;oBAChB,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;iBAC9B;gBAED,eAAe,EAAE,CAAC;YACpB,CAAC,CAAC;YAEF,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAE1B,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,WAAW,CAAC,QAAyB;YACnC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC/B,CAAC;QAED,OAAO;YACL,KAAK,MAAM,OAAO,IAAI,WAAW,EAAE;gBACjC,OAAO,EAAE,CAAC;aACX;QACH,CAAC;KACF,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { addProvider } from './addProvider.js';\nimport { createNode } from './createNode.js';\nimport { getData } from './getData.js';\nimport { publish } from './publish.js';\nimport { subscribe } from './subscribe.js';\nimport type { DataBusChangeFunction } from './types/DataBusChangeFunction.js';\nimport type { DataBusProvider } from './types/DataBusProvider.js';\nimport type { DataBusState } from './types/DataBusState.js';\nimport type { DataBus } from './types/DataBus.js';\nimport type { DisposeFunction } from './types/DisposeFunction.js';\nimport type { DataBusPath } from './index.js';\n\n/**\n * Creates a new data bus instance.\n */\nexport function createDataBus(): DataBus {\n const state: DataBusState = {\n root: createNode(),\n };\n\n const disposables: DisposeFunction[] = [];\n\n const bus: DataBus = {\n publish<TData>(path: string[] | DataBusPath, value: TData) {\n const publishPath = Array.isArray(path) ? path : path.path;\n\n return publish(state, bus, publishPath, value);\n },\n\n getData<TData>(path: string[] | DataBusPath) {\n const publishPath = Array.isArray(path) ? path : path.path;\n\n return getData<TData>(state, publishPath);\n },\n\n subscribe(path: string[] | DataBusPath, change: DataBusChangeFunction) {\n const publishPath = Array.isArray(path) ? path : path.path;\n const internalDispose = subscribe(state, bus, publishPath, change);\n\n const dispose = () => {\n const index = disposables.indexOf(dispose);\n\n if (index !== -1) {\n disposables.splice(index, 1);\n }\n\n internalDispose();\n };\n\n disposables.push(dispose);\n\n return dispose;\n },\n\n addProvider(provider: DataBusProvider) {\n addProvider(state, provider);\n },\n\n dispose() {\n for (const dispose of disposables) {\n dispose();\n }\n },\n };\n\n return bus;\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type z from 'zod';
2
+ import type { DataBusPath } from './types/DataBusPath.js';
3
+ /**
4
+ * Helper to make source typing and paths joined in a structure.
5
+ */
6
+ export declare function createDataPath<TZodType extends z.ZodType>(options: {
7
+ path: string[];
8
+ type: TZodType;
9
+ }): DataBusPath<TZodType>;
10
+ //# sourceMappingURL=createDataPath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createDataPath.d.ts","sourceRoot":"","sources":["../src/createDataPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,SAAS,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE;IAClE,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC;CAChB,GAAG,WAAW,CAAC,QAAQ,CAAC,CAExB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Helper to make source typing and paths joined in a structure.
3
+ */
4
+ export function createDataPath(options) {
5
+ return options;
6
+ }
7
+ //# sourceMappingURL=createDataPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createDataPath.js","sourceRoot":"","sources":["../src/createDataPath.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,UAAU,cAAc,CAA6B,OAG1D;IACC,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type z from 'zod';\nimport type { DataBusPath } from './types/DataBusPath.js';\n\n/**\n * Helper to make source typing and paths joined in a structure.\n */\nexport function createDataPath<TZodType extends z.ZodType>(options: {\n path: string[];\n type: TZodType;\n}): DataBusPath<TZodType> {\n return options;\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- export { createDataBus } from './createDataBus.js';
2
1
  export type { DataBus } from './types/DataBus.js';
3
2
  export type { DataBusChangeFunction } from './types/DataBusChangeFunction.js';
4
3
  export type { DataBusNode } from './types/DataBusNode.js';
4
+ export type { DataBusPath } from './types/DataBusPath.js';
5
5
  export type { DataBusProvider } from './types/DataBusProvider.js';
6
6
  export type { DataBusState } from './types/DataBusState.js';
7
7
  export type { DisposeFunction } from './types/DisposeFunction.js';
8
+ export { createDataBus } from './createDataBus.js';
9
+ export { createDataPath } from './createDataPath.js';
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAC9E,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAC9E,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
package/lib/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { createDataBus } from './createDataBus.js';
2
+ export { createDataPath } from './createDataPath.js';
2
3
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { createDataBus } from './createDataBus.js';\nexport type { DataBus } from './types/DataBus.js';\nexport type { DataBusChangeFunction } from './types/DataBusChangeFunction.js';\nexport type { DataBusNode } from './types/DataBusNode.js';\nexport type { DataBusProvider } from './types/DataBusProvider.js';\nexport type { DataBusState } from './types/DataBusState.js';\nexport type { DisposeFunction } from './types/DisposeFunction.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export type { DataBus } from './types/DataBus.js';\nexport type { DataBusChangeFunction } from './types/DataBusChangeFunction.js';\nexport type { DataBusNode } from './types/DataBusNode.js';\nexport type { DataBusPath } from './types/DataBusPath.js';\nexport type { DataBusProvider } from './types/DataBusProvider.js';\nexport type { DataBusState } from './types/DataBusState.js';\nexport type { DisposeFunction } from './types/DisposeFunction.js';\n\nexport { createDataBus } from './createDataBus.js';\nexport { createDataPath } from './createDataPath.js';\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.36.1"
8
+ "packageVersion": "7.36.4"
9
9
  }
10
10
  ]
11
11
  }
@@ -1,10 +1,15 @@
1
1
  import type { DataBusChangeFunction } from './DataBusChangeFunction.js';
2
2
  import type { DisposeFunction } from './DisposeFunction.js';
3
3
  import type { DataBusProvider } from './DataBusProvider.js';
4
+ import type { DataBusPath } from './DataBusPath.js';
5
+ import type z from 'zod';
4
6
  export interface DataBus {
5
- publish: <TData = any>(path: string[], value: TData) => void;
6
- subscribe: <TData = any>(path: string[], callback: DataBusChangeFunction<TData>) => DisposeFunction;
7
- getData: <TData = any>(path: string[]) => TData | undefined;
7
+ publish<TData = any>(path: string[], value: TData): void;
8
+ publish<TZodData extends z.ZodType>(path: DataBusPath<TZodData>, value: z.infer<TZodData>): void;
9
+ subscribe<TData = any>(path: string[], callback: DataBusChangeFunction<TData>): DisposeFunction;
10
+ subscribe<TZodData extends z.ZodType>(path: DataBusPath<TZodData>, callback: DataBusChangeFunction<z.infer<TZodData>>): DisposeFunction;
11
+ getData<TData = any>(path: string[]): TData | undefined;
12
+ getData<TZodData extends z.ZodType = z.ZodAny>(path: DataBusPath<TZodData>): z.infer<TZodData> | undefined;
8
13
  addProvider: (provider: DataBusProvider) => void;
9
14
  dispose: () => void;
10
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DataBus.d.ts","sourceRoot":"","sources":["../../src/types/DataBus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,WAAW,OAAO;IAEtB,OAAO,EAAE,CAAC,KAAK,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAE7D,SAAS,EAAE,CAAC,KAAK,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,qBAAqB,CAAC,KAAK,CAAC,KAAK,eAAe,CAAC;IAEpG,OAAO,EAAE,CAAC,KAAK,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,KAAK,GAAG,SAAS,CAAC;IAC5D,WAAW,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;IACjD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB"}
1
+ {"version":3,"file":"DataBus.d.ts","sourceRoot":"","sources":["../../src/types/DataBus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,MAAM,WAAW,OAAO;IAEtB,OAAO,CAAC,KAAK,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACzD,OAAO,CAAC,QAAQ,SAAS,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;IAGjG,SAAS,CAAC,KAAK,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,qBAAqB,CAAC,KAAK,CAAC,GAAG,eAAe,CAAC;IAChG,SAAS,CAAC,QAAQ,SAAS,CAAC,CAAC,OAAO,EAClC,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAC,EAC3B,QAAQ,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GACjD,eAAe,CAAC;IAGnB,OAAO,CAAC,KAAK,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,GAAG,SAAS,CAAC;IACxD,OAAO,CAAC,QAAQ,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;IAE3G,WAAW,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;IAEjD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB"}
@@ -1 +1 @@
1
- {"version":3,"file":"DataBus.js","sourceRoot":"","sources":["../../src/types/DataBus.ts"],"names":[],"mappings":"","sourcesContent":["import type { DataBusChangeFunction } from './DataBusChangeFunction.js';\nimport type { DisposeFunction } from './DisposeFunction.js';\nimport type { DataBusProvider } from './DataBusProvider.js';\n\nexport interface DataBus {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n publish: <TData = any>(path: string[], value: TData) => void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n subscribe: <TData = any>(path: string[], callback: DataBusChangeFunction<TData>) => DisposeFunction;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getData: <TData = any>(path: string[]) => TData | undefined;\n addProvider: (provider: DataBusProvider) => void;\n dispose: () => void;\n}\n"]}
1
+ {"version":3,"file":"DataBus.js","sourceRoot":"","sources":["../../src/types/DataBus.ts"],"names":[],"mappings":"","sourcesContent":["import type { DataBusChangeFunction } from './DataBusChangeFunction.js';\nimport type { DisposeFunction } from './DisposeFunction.js';\nimport type { DataBusProvider } from './DataBusProvider.js';\nimport type { DataBusPath } from './DataBusPath.js';\nimport type z from 'zod';\nexport interface DataBus {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n publish<TData = any>(path: string[], value: TData): void;\n publish<TZodData extends z.ZodType>(path: DataBusPath<TZodData>, value: z.infer<TZodData>): void;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n subscribe<TData = any>(path: string[], callback: DataBusChangeFunction<TData>): DisposeFunction;\n subscribe<TZodData extends z.ZodType>(\n path: DataBusPath<TZodData>,\n callback: DataBusChangeFunction<z.infer<TZodData>>,\n ): DisposeFunction;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getData<TData = any>(path: string[]): TData | undefined;\n getData<TZodData extends z.ZodType = z.ZodAny>(path: DataBusPath<TZodData>): z.infer<TZodData> | undefined;\n\n addProvider: (provider: DataBusProvider) => void;\n\n dispose: () => void;\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import type z from 'zod';
2
+ export type DataBusPath<TZodData extends z.ZodType = z.ZodUnknown> = {
3
+ /**
4
+ * Path to the data within the databus tree.
5
+ */
6
+ path: string[];
7
+ /**
8
+ * The type of the data, represented by a zod schema.
9
+ */
10
+ type: TZodData;
11
+ };
12
+ //# sourceMappingURL=DataBusPath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataBusPath.d.ts","sourceRoot":"","sources":["../../src/types/DataBusPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,UAAU,IAAI;IACnE;;OAEG;IACH,IAAI,EAAE,MAAM,EAAE,CAAC;IAEf;;OAEG;IACH,IAAI,EAAE,QAAQ,CAAC;CAChB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=DataBusPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataBusPath.js","sourceRoot":"","sources":["../../src/types/DataBusPath.ts"],"names":[],"mappings":"","sourcesContent":["import type z from 'zod';\n\nexport type DataBusPath<TZodData extends z.ZodType = z.ZodUnknown> = {\n /**\n * Path to the data within the databus tree.\n */\n path: string[];\n\n /**\n * The type of the data, represented by a zod schema.\n */\n type: TZodData;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/data-bus",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "description": "A data bus implementation.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -8,6 +8,7 @@
8
8
  "sideEffects": false,
9
9
  "exports": {
10
10
  ".": {
11
+ "source": "./src/index.ts",
11
12
  "types": "./lib/index.d.ts",
12
13
  "import": "./lib/index.js"
13
14
  }
@@ -22,6 +23,9 @@
22
23
  "test:watch": "cloudpack-scripts test-watch",
23
24
  "test": "cloudpack-scripts test"
24
25
  },
26
+ "dependencies": {
27
+ "zod": "^3.21.4"
28
+ },
25
29
  "devDependencies": {
26
30
  "@ms-cloudpack/eslint-plugin-internal": "*",
27
31
  "@ms-cloudpack/scripts": "*"