kubernetes-fluent-client 1.9.0 → 2.0.0
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/dist/fluent/index.d.ts +1 -1
- package/dist/fluent/index.d.ts.map +1 -1
- package/dist/fluent/index.js +17 -3
- package/dist/fluent/index.test.js +28 -1
- package/dist/fluent/types.d.ts +29 -9
- package/dist/fluent/types.d.ts.map +1 -1
- package/dist/fluent/types.js +2 -0
- package/dist/fluent/watch.d.ts +70 -39
- package/dist/fluent/watch.d.ts.map +1 -1
- package/dist/fluent/watch.js +282 -107
- package/dist/fluent/watch.spec.d.ts +2 -0
- package/dist/fluent/watch.spec.d.ts.map +1 -0
- package/dist/fluent/watch.spec.js +221 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/package.json +10 -10
- package/src/fluent/index.test.ts +37 -2
- package/src/fluent/index.ts +24 -7
- package/src/fluent/types.ts +32 -11
- package/src/fluent/watch.spec.ts +264 -0
- package/src/fluent/watch.ts +313 -150
- package/src/index.ts +6 -2
package/dist/fluent/index.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ import { Filters, K8sInit } from "./types";
|
|
|
8
8
|
* @param filters - (optional) filter overrides, can also be chained
|
|
9
9
|
* @returns a fluent API for the model
|
|
10
10
|
*/
|
|
11
|
-
export declare function K8s<T extends GenericClass, K extends KubernetesObject = InstanceType<T>>(model: T, filters?: Filters): K8sInit<K>;
|
|
11
|
+
export declare function K8s<T extends GenericClass, K extends KubernetesObject = InstanceType<T>>(model: T, filters?: Filters): K8sInit<T, K>;
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fluent/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwB,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fluent/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwB,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAOjF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAsB,MAAM,SAAS,CAAC;AAI/D;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,gBAAgB,GAAG,YAAY,CAAC,CAAC,CAAC,EACtF,KAAK,EAAE,CAAC,EACR,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAmKf"}
|
package/dist/fluent/index.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.K8s = void 0;
|
|
6
6
|
const http_status_codes_1 = require("http-status-codes");
|
|
7
|
+
const fetch_1 = require("../fetch");
|
|
7
8
|
const kinds_1 = require("../kinds");
|
|
8
9
|
const utils_1 = require("./utils");
|
|
9
10
|
const watch_1 = require("./watch");
|
|
@@ -134,9 +135,22 @@ function K8s(model, filters = {}) {
|
|
|
134
135
|
* @inheritdoc
|
|
135
136
|
* @see {@link K8sInit.Watch}
|
|
136
137
|
*/
|
|
137
|
-
|
|
138
|
-
return
|
|
138
|
+
function Watch(callback, watchCfg) {
|
|
139
|
+
return new watch_1.Watcher(model, filters, callback, watchCfg);
|
|
139
140
|
}
|
|
140
|
-
|
|
141
|
+
/**
|
|
142
|
+
* @inheritdoc
|
|
143
|
+
* @see {@link K8sInit.Raw}
|
|
144
|
+
*/
|
|
145
|
+
async function Raw(url) {
|
|
146
|
+
const thing = await (0, utils_1.k8sCfg)("GET");
|
|
147
|
+
const { opts, serverUrl } = thing;
|
|
148
|
+
const resp = await (0, fetch_1.fetch)(`${serverUrl}${url}`, opts);
|
|
149
|
+
if (resp.ok) {
|
|
150
|
+
return resp.data;
|
|
151
|
+
}
|
|
152
|
+
throw resp;
|
|
153
|
+
}
|
|
154
|
+
return { InNamespace, Apply, Create, Patch, Raw, ...withFilters };
|
|
141
155
|
}
|
|
142
156
|
exports.K8s = K8s;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const globals_1 = require("@jest/globals");
|
|
4
|
-
const
|
|
4
|
+
const client_node_1 = require("@kubernetes/client-node");
|
|
5
5
|
const _1 = require(".");
|
|
6
|
+
const fetch_1 = require("../fetch");
|
|
7
|
+
const upstream_1 = require("../upstream");
|
|
6
8
|
const utils_1 = require("./utils");
|
|
7
9
|
// Setup mocks
|
|
8
10
|
globals_1.jest.mock("./utils");
|
|
11
|
+
globals_1.jest.mock("../fetch");
|
|
9
12
|
const generateFakePodManagedFields = (manager) => {
|
|
10
13
|
return [
|
|
11
14
|
{
|
|
@@ -49,6 +52,7 @@ const generateFakePodManagedFields = (manager) => {
|
|
|
49
52
|
managedFields: generateFakePodManagedFields("pepr"),
|
|
50
53
|
},
|
|
51
54
|
};
|
|
55
|
+
const mockedKubeCfg = globals_1.jest.mocked(utils_1.k8sCfg);
|
|
52
56
|
const mockedKubeExec = globals_1.jest.mocked(utils_1.k8sExec).mockResolvedValue(fakeResource);
|
|
53
57
|
(0, globals_1.beforeEach)(() => {
|
|
54
58
|
// Clear all instances and calls to constructor and all methods:
|
|
@@ -134,4 +138,27 @@ const generateFakePodManagedFields = (manager) => {
|
|
|
134
138
|
mockedKubeExec.mockRejectedValueOnce({ status: 500 }); // Internal Server Error on first call
|
|
135
139
|
await (0, globals_1.expect)((0, _1.K8s)(upstream_1.Pod).Delete("fakeResource")).rejects.toEqual(globals_1.expect.objectContaining({ status: 500 }));
|
|
136
140
|
});
|
|
141
|
+
(0, globals_1.it)("should create a raw api request", async () => {
|
|
142
|
+
mockedKubeCfg.mockReturnValue(new Promise(r => r({
|
|
143
|
+
serverUrl: "http://localhost:8080",
|
|
144
|
+
opts: {},
|
|
145
|
+
})));
|
|
146
|
+
const mockResp = {
|
|
147
|
+
kind: "APIVersions",
|
|
148
|
+
versions: ["v1"],
|
|
149
|
+
serverAddressByClientCIDRs: [
|
|
150
|
+
{
|
|
151
|
+
serverAddress: "172.27.0.3:6443",
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
};
|
|
155
|
+
globals_1.jest.mocked(fetch_1.fetch).mockResolvedValue({
|
|
156
|
+
ok: true,
|
|
157
|
+
data: mockResp,
|
|
158
|
+
status: 200,
|
|
159
|
+
statusText: "OK",
|
|
160
|
+
});
|
|
161
|
+
const result = await (0, _1.K8s)(client_node_1.V1APIGroup).Raw("/api");
|
|
162
|
+
(0, globals_1.expect)(result).toEqual(mockResp);
|
|
163
|
+
});
|
|
137
164
|
});
|
package/dist/fluent/types.d.ts
CHANGED
|
@@ -2,15 +2,17 @@ import { KubernetesListObject, KubernetesObject } from "@kubernetes/client-node"
|
|
|
2
2
|
import { Operation } from "fast-json-patch";
|
|
3
3
|
import type { PartialDeep } from "type-fest";
|
|
4
4
|
import { GenericClass, GroupVersionKind } from "../types";
|
|
5
|
-
import { WatchCfg, WatchController } from "./watch";
|
|
6
5
|
import { ApplyCfg } from "./apply";
|
|
6
|
+
import { WatchCfg, Watcher } from "./watch";
|
|
7
7
|
/**
|
|
8
8
|
* The Phase matched when using the K8s Watch API.
|
|
9
9
|
*/
|
|
10
10
|
export declare enum WatchPhase {
|
|
11
11
|
Added = "ADDED",
|
|
12
12
|
Modified = "MODIFIED",
|
|
13
|
-
Deleted = "DELETED"
|
|
13
|
+
Deleted = "DELETED",
|
|
14
|
+
Bookmark = "BOOKMARK",
|
|
15
|
+
Error = "ERROR"
|
|
14
16
|
}
|
|
15
17
|
export type FetchMethods = "GET" | "APPLY" | "POST" | "PUT" | "DELETE" | "PATCH" | "WATCH";
|
|
16
18
|
export interface Filters {
|
|
@@ -32,7 +34,7 @@ export type GetFunction<K extends KubernetesObject> = {
|
|
|
32
34
|
(): Promise<KubernetesListObject<K>>;
|
|
33
35
|
(name: string): Promise<K>;
|
|
34
36
|
};
|
|
35
|
-
export type K8sFilteredActions<K extends KubernetesObject> = {
|
|
37
|
+
export type K8sFilteredActions<T extends GenericClass, K extends KubernetesObject> = {
|
|
36
38
|
/**
|
|
37
39
|
* Get the resource or resources matching the filters.
|
|
38
40
|
* If no filters are specified, all resources will be returned.
|
|
@@ -52,7 +54,7 @@ export type K8sFilteredActions<K extends KubernetesObject> = {
|
|
|
52
54
|
* @param watchCfg - (optional) watch configuration
|
|
53
55
|
* @returns a watch controller
|
|
54
56
|
*/
|
|
55
|
-
Watch: (callback:
|
|
57
|
+
Watch: (callback: WatchAction<T>, watchCfg?: WatchCfg) => Watcher<T>;
|
|
56
58
|
};
|
|
57
59
|
export type K8sUnfilteredActions<K extends KubernetesObject> = {
|
|
58
60
|
/**
|
|
@@ -79,8 +81,26 @@ export type K8sUnfilteredActions<K extends KubernetesObject> = {
|
|
|
79
81
|
* @returns The patched resource
|
|
80
82
|
*/
|
|
81
83
|
Patch: (payload: Operation[]) => Promise<K>;
|
|
84
|
+
/**
|
|
85
|
+
* Perform a raw GET request to the Kubernetes API. This is useful for calling endpoints that are not supported by the fluent API.
|
|
86
|
+
* This command mirrors the `kubectl get --raw` command.
|
|
87
|
+
*
|
|
88
|
+
* E.g.
|
|
89
|
+
*
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { V1APIGroup } from "@kubernetes/client-node";
|
|
92
|
+
*
|
|
93
|
+
* K8s(V1APIGroup).Raw("/api")
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* will call the `/api` endpoint and is equivalent to `kubectl get --raw /api`.
|
|
97
|
+
*
|
|
98
|
+
* @param url the URL to call (e.g. /api)
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
Raw: (url: string) => Promise<K>;
|
|
82
102
|
};
|
|
83
|
-
export type K8sWithFilters<K extends KubernetesObject> = K8sFilteredActions<K> & {
|
|
103
|
+
export type K8sWithFilters<T extends GenericClass, K extends KubernetesObject> = K8sFilteredActions<T, K> & {
|
|
84
104
|
/**
|
|
85
105
|
* Filter the query by the given field.
|
|
86
106
|
* Note multiple calls to this method will result in an AND condition. e.g.
|
|
@@ -100,7 +120,7 @@ export type K8sWithFilters<K extends KubernetesObject> = K8sFilteredActions<K> &
|
|
|
100
120
|
* @param value - the field value
|
|
101
121
|
* @returns the fluent API
|
|
102
122
|
*/
|
|
103
|
-
WithField: <P extends Paths<K>>(key: P, value: string) => K8sWithFilters<K>;
|
|
123
|
+
WithField: <P extends Paths<K>>(key: P, value: string) => K8sWithFilters<T, K>;
|
|
104
124
|
/**
|
|
105
125
|
* Filter the query by the given label. If no value is specified, the label simply must exist.
|
|
106
126
|
* Note multiple calls to this method will result in an AND condition. e.g.
|
|
@@ -119,16 +139,16 @@ export type K8sWithFilters<K extends KubernetesObject> = K8sFilteredActions<K> &
|
|
|
119
139
|
* @param value - the label value
|
|
120
140
|
* @returns the fluent API
|
|
121
141
|
*/
|
|
122
|
-
WithLabel: (key: string, value?: string) => K8sWithFilters<K>;
|
|
142
|
+
WithLabel: (key: string, value?: string) => K8sWithFilters<T, K>;
|
|
123
143
|
};
|
|
124
|
-
export type K8sInit<K extends KubernetesObject> = K8sWithFilters<K> & K8sUnfilteredActions<K> & {
|
|
144
|
+
export type K8sInit<T extends GenericClass, K extends KubernetesObject> = K8sWithFilters<T, K> & K8sUnfilteredActions<K> & {
|
|
125
145
|
/**
|
|
126
146
|
* Set the namespace filter.
|
|
127
147
|
*
|
|
128
148
|
* @param namespace - the namespace to filter on
|
|
129
149
|
* @returns the fluent API
|
|
130
150
|
*/
|
|
131
|
-
InNamespace: (namespace: string) => K8sWithFilters<K>;
|
|
151
|
+
InNamespace: (namespace: string) => K8sWithFilters<T, K>;
|
|
132
152
|
};
|
|
133
153
|
export type WatchAction<T extends GenericClass, K extends KubernetesObject = InstanceType<T>> = (update: K, phase: WatchPhase) => Promise<void> | void;
|
|
134
154
|
type Join<K, P> = K extends string | number ? P extends string | number ? `${K}${"" extends P ? "" : "."}${P}` : never : never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/fluent/types.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/fluent/types.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAE5C;;GAEG;AACH,oBAAY,UAAU;IACpB,KAAK,UAAU;IACf,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;AAE3F,MAAM,WAAW,OAAO;IACtB,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,C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,GAAG,GAAG,GAAG,CAAC,EAAE,GACpC,KAAK,GACP,KAAK,CAAC;AAEV,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC7D,KAAK,GACL,CAAC,SAAS,MAAM,GACd;KACG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK;CACpF,CAAC,MAAM,CAAC,CAAC,GACV,EAAE,CAAC"}
|
package/dist/fluent/types.js
CHANGED
package/dist/fluent/watch.d.ts
CHANGED
|
@@ -1,52 +1,83 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { EventEmitter } from "events";
|
|
4
|
+
import { GenericClass } from "../types";
|
|
3
5
|
import { Filters, WatchAction } from "./types";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
export declare enum WatchEvent {
|
|
7
|
+
/** Watch is connected successfully */
|
|
8
|
+
CONNECT = "connect",
|
|
9
|
+
/** Network error occurs */
|
|
10
|
+
NETWORK_ERROR = "network_error",
|
|
11
|
+
/** Error decoding data or running the callback */
|
|
12
|
+
DATA_ERROR = "data_error",
|
|
13
|
+
/** Reconnect is called */
|
|
14
|
+
RECONNECT = "reconnect",
|
|
15
|
+
/** Retry limit is exceeded */
|
|
16
|
+
GIVE_UP = "give_up",
|
|
17
|
+
/** Abort is called */
|
|
18
|
+
ABORT = "abort",
|
|
19
|
+
/** Resync is called */
|
|
20
|
+
RESYNC = "resync",
|
|
21
|
+
/** Data is received and decoded */
|
|
22
|
+
DATA = "data",
|
|
23
|
+
/** Bookmark is received */
|
|
24
|
+
BOOKMARK = "bookmark",
|
|
25
|
+
/** ResourceVersion is updated */
|
|
26
|
+
RESOURCE_VERSION = "resource_version",
|
|
27
|
+
/** 410 (old resource version) occurs */
|
|
28
|
+
OLD_RESOURCE_VERSION = "old_resource_version",
|
|
29
|
+
/** A reconnect is already pending */
|
|
30
|
+
RECONNECT_PENDING = "reconnect_pending"
|
|
31
|
+
}
|
|
32
|
+
/** Configuration for the watch function. */
|
|
33
|
+
export type WatchCfg = {
|
|
34
|
+
/** The resource version to start the watch at, this will be updated on each event. */
|
|
35
|
+
resourceVersion?: string;
|
|
36
|
+
/** The maximum number of times to retry the watch, the retry count is reset on success. Unlimited retries if not specified. */
|
|
37
|
+
retryMax?: number;
|
|
38
|
+
/** The delay between retries in seconds. Defaults to 10 seconds. */
|
|
39
|
+
retryDelaySec?: number;
|
|
40
|
+
/** Amount of seconds to wait before a forced-resyncing of the watch list. Defaults to 300 (5 minutes). */
|
|
41
|
+
resyncIntervalSec?: number;
|
|
42
|
+
};
|
|
43
|
+
/** A wrapper around the Kubernetes watch API. */
|
|
44
|
+
export declare class Watcher<T extends GenericClass> {
|
|
45
|
+
#private;
|
|
8
46
|
/**
|
|
9
|
-
*
|
|
47
|
+
* Setup a Kubernetes watcher for the specified model and filters. The callback function will be called for each event received.
|
|
48
|
+
* The watch can be aborted by calling {@link Watcher.close} or by calling abort() on the AbortController returned by {@link Watcher.start}.
|
|
10
49
|
*
|
|
11
|
-
* @param reason optional reason for aborting the watch
|
|
12
|
-
*/
|
|
13
|
-
abort: (reason?: string) => void;
|
|
14
|
-
/**
|
|
15
|
-
* Get the AbortSignal for the watch.
|
|
16
50
|
*
|
|
17
|
-
* @
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*/
|
|
24
|
-
export type WatchCfg = {
|
|
25
|
-
/**
|
|
26
|
-
* The maximum number of times to retry the watch, the retry count is reset on success.
|
|
51
|
+
* Kubernetes API docs: {@link https://kubernetes.io/docs/reference/using-api/api-concepts/#efficient-detection-of-changes}
|
|
52
|
+
*
|
|
53
|
+
* @param model - the model to use for the API
|
|
54
|
+
* @param filters - (optional) filter overrides, can also be chained
|
|
55
|
+
* @param callback - the callback function to call when an event is received
|
|
56
|
+
* @param watchCfg - (optional) watch configuration
|
|
27
57
|
*/
|
|
28
|
-
|
|
58
|
+
constructor(model: T, filters: Filters, callback: WatchAction<T>, watchCfg?: WatchCfg);
|
|
29
59
|
/**
|
|
30
|
-
*
|
|
60
|
+
* Start the watch.
|
|
61
|
+
*
|
|
62
|
+
* @returns The AbortController for the watch.
|
|
31
63
|
*/
|
|
32
|
-
|
|
64
|
+
start(): Promise<AbortController>;
|
|
65
|
+
/** Close the watch. Also available on the AbortController returned by {@link Watcher.start}. */
|
|
66
|
+
close(): void;
|
|
33
67
|
/**
|
|
34
|
-
*
|
|
68
|
+
* Get a unique ID for the watch based on the model and filters.
|
|
69
|
+
* This is useful for caching the watch data or resource versions.
|
|
70
|
+
*
|
|
71
|
+
* @returns the watch ID
|
|
35
72
|
*/
|
|
36
|
-
|
|
73
|
+
get id(): string;
|
|
37
74
|
/**
|
|
38
|
-
*
|
|
75
|
+
* Subscribe to watch events. This is an EventEmitter that emits the following events:
|
|
76
|
+
*
|
|
77
|
+
* Use {@link WatchEvent} for the event names.
|
|
78
|
+
*
|
|
79
|
+
* @returns an EventEmitter
|
|
39
80
|
*/
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Execute a watch on the specified resource.
|
|
44
|
-
*
|
|
45
|
-
* @param model - the model to use for the API
|
|
46
|
-
* @param filters - (optional) filter overrides, can also be chained
|
|
47
|
-
* @param callback - the callback function to call when an event is received
|
|
48
|
-
* @param watchCfg - (optional) watch configuration
|
|
49
|
-
* @returns a WatchController to allow the watch to be aborted externally
|
|
50
|
-
*/
|
|
51
|
-
export declare function ExecWatch<T extends GenericClass>(model: T, filters: Filters, callback: WatchAction<T>, watchCfg?: WatchCfg): Promise<WatchController>;
|
|
81
|
+
get events(): EventEmitter;
|
|
82
|
+
}
|
|
52
83
|
//# sourceMappingURL=watch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/fluent/watch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/fluent/watch.ts"],"names":[],"mappings":";;AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAc,MAAM,SAAS,CAAC;AAG3D,oBAAY,UAAU;IACpB,sCAAsC;IACtC,OAAO,YAAY;IACnB,2BAA2B;IAC3B,aAAa,kBAAkB;IAC/B,kDAAkD;IAClD,UAAU,eAAe;IACzB,0BAA0B;IAC1B,SAAS,cAAc;IACvB,8BAA8B;IAC9B,OAAO,YAAY;IACnB,sBAAsB;IACtB,KAAK,UAAU;IACf,uBAAuB;IACvB,MAAM,WAAW;IACjB,mCAAmC;IACnC,IAAI,SAAS;IACb,2BAA2B;IAC3B,QAAQ,aAAa;IACrB,iCAAiC;IACjC,gBAAgB,qBAAqB;IACrC,wCAAwC;IACxC,oBAAoB,yBAAyB;IAC7C,qCAAqC;IACrC,iBAAiB,sBAAsB;CACxC;AAED,4CAA4C;AAC5C,MAAM,MAAM,QAAQ,GAAG;IACrB,sFAAsF;IACtF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,+HAA+H;IAC/H,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0GAA0G;IAC1G,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,iDAAiD;AACjD,qBAAa,OAAO,CAAC,CAAC,SAAS,YAAY;;IA6BzC;;;;;;;;;;;OAWG;gBACS,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