@comapeo/map-server 1.0.0-pre.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/README.md +610 -0
- package/dist/context.d.ts +46 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +181 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +112 -0
- package/dist/lib/constants.d.ts +7 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +6 -0
- package/dist/lib/download-request.d.ts +17 -0
- package/dist/lib/download-request.d.ts.map +1 -0
- package/dist/lib/download-request.js +113 -0
- package/dist/lib/errors.d.ts +88 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +158 -0
- package/dist/lib/event-stream-response.d.ts +17 -0
- package/dist/lib/event-stream-response.d.ts.map +1 -0
- package/dist/lib/event-stream-response.js +39 -0
- package/dist/lib/event-target.d.ts +9 -0
- package/dist/lib/event-target.d.ts.map +1 -0
- package/dist/lib/event-target.js +4 -0
- package/dist/lib/fetch-api.d.ts +3 -0
- package/dist/lib/fetch-api.d.ts.map +1 -0
- package/dist/lib/fetch-api.js +16 -0
- package/dist/lib/map-share.d.ts +52 -0
- package/dist/lib/map-share.d.ts.map +1 -0
- package/dist/lib/map-share.js +142 -0
- package/dist/lib/secret-stream-fetch.d.ts +7 -0
- package/dist/lib/secret-stream-fetch.d.ts.map +1 -0
- package/dist/lib/secret-stream-fetch.js +34 -0
- package/dist/lib/self-evicting-map.d.ts +16 -0
- package/dist/lib/self-evicting-map.d.ts.map +1 -0
- package/dist/lib/self-evicting-map.js +29 -0
- package/dist/lib/state-update-event.d.ts +8 -0
- package/dist/lib/state-update-event.d.ts.map +1 -0
- package/dist/lib/state-update-event.js +10 -0
- package/dist/lib/utils.d.ts +32 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +96 -0
- package/dist/middlewares/localhost-only.d.ts +11 -0
- package/dist/middlewares/localhost-only.d.ts.map +1 -0
- package/dist/middlewares/localhost-only.js +10 -0
- package/dist/middlewares/parse-request.d.ts +11 -0
- package/dist/middlewares/parse-request.d.ts.map +1 -0
- package/dist/middlewares/parse-request.js +25 -0
- package/dist/routes/downloads.d.ts +15 -0
- package/dist/routes/downloads.d.ts.map +1 -0
- package/dist/routes/downloads.js +60 -0
- package/dist/routes/map-shares.d.ts +19 -0
- package/dist/routes/map-shares.d.ts.map +1 -0
- package/dist/routes/map-shares.js +192 -0
- package/dist/routes/maps.d.ts +6 -0
- package/dist/routes/maps.d.ts.map +1 -0
- package/dist/routes/maps.js +118 -0
- package/dist/routes/root.d.ts +6 -0
- package/dist/routes/root.d.ts.map +1 -0
- package/dist/routes/root.js +29 -0
- package/dist/types.d.ts +110 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +96 -0
- package/node_modules/@envelop/instrumentation/LICENSE +21 -0
- package/node_modules/@envelop/instrumentation/README.md +30 -0
- package/node_modules/@envelop/instrumentation/cjs/index.js +5 -0
- package/node_modules/@envelop/instrumentation/cjs/instrumentation.js +89 -0
- package/node_modules/@envelop/instrumentation/cjs/package.json +1 -0
- package/node_modules/@envelop/instrumentation/esm/index.js +2 -0
- package/node_modules/@envelop/instrumentation/esm/instrumentation.js +82 -0
- package/node_modules/@envelop/instrumentation/package.json +57 -0
- package/node_modules/@envelop/instrumentation/typings/index.d.cts +1 -0
- package/node_modules/@envelop/instrumentation/typings/index.d.ts +1 -0
- package/node_modules/@envelop/instrumentation/typings/instrumentation.d.cts +44 -0
- package/node_modules/@envelop/instrumentation/typings/instrumentation.d.ts +44 -0
- package/node_modules/@whatwg-node/disposablestack/cjs/AsyncDisposableStack.js +73 -0
- package/node_modules/@whatwg-node/disposablestack/cjs/DisposableStack.js +62 -0
- package/node_modules/@whatwg-node/disposablestack/cjs/SupressedError.js +16 -0
- package/node_modules/@whatwg-node/disposablestack/cjs/index.js +11 -0
- package/node_modules/@whatwg-node/disposablestack/cjs/package.json +1 -0
- package/node_modules/@whatwg-node/disposablestack/cjs/symbols.js +20 -0
- package/node_modules/@whatwg-node/disposablestack/cjs/utils.js +11 -0
- package/node_modules/@whatwg-node/disposablestack/esm/AsyncDisposableStack.js +69 -0
- package/node_modules/@whatwg-node/disposablestack/esm/DisposableStack.js +58 -0
- package/node_modules/@whatwg-node/disposablestack/esm/SupressedError.js +12 -0
- package/node_modules/@whatwg-node/disposablestack/esm/index.js +7 -0
- package/node_modules/@whatwg-node/disposablestack/esm/symbols.js +16 -0
- package/node_modules/@whatwg-node/disposablestack/esm/utils.js +7 -0
- package/node_modules/@whatwg-node/disposablestack/package.json +44 -0
- package/node_modules/@whatwg-node/disposablestack/typings/AsyncDisposableStack.d.cts +15 -0
- package/node_modules/@whatwg-node/disposablestack/typings/AsyncDisposableStack.d.ts +15 -0
- package/node_modules/@whatwg-node/disposablestack/typings/DisposableStack.d.cts +14 -0
- package/node_modules/@whatwg-node/disposablestack/typings/DisposableStack.d.ts +14 -0
- package/node_modules/@whatwg-node/disposablestack/typings/SupressedError.d.cts +5 -0
- package/node_modules/@whatwg-node/disposablestack/typings/SupressedError.d.ts +5 -0
- package/node_modules/@whatwg-node/disposablestack/typings/index.d.cts +4 -0
- package/node_modules/@whatwg-node/disposablestack/typings/index.d.ts +4 -0
- package/node_modules/@whatwg-node/disposablestack/typings/symbols.d.cts +5 -0
- package/node_modules/@whatwg-node/disposablestack/typings/symbols.d.ts +5 -0
- package/node_modules/@whatwg-node/disposablestack/typings/utils.d.cts +2 -0
- package/node_modules/@whatwg-node/disposablestack/typings/utils.d.ts +2 -0
- package/node_modules/@whatwg-node/promise-helpers/cjs/index.js +270 -0
- package/node_modules/@whatwg-node/promise-helpers/cjs/package.json +1 -0
- package/node_modules/@whatwg-node/promise-helpers/esm/index.js +257 -0
- package/node_modules/@whatwg-node/promise-helpers/package.json +43 -0
- package/node_modules/@whatwg-node/promise-helpers/typings/index.d.cts +31 -0
- package/node_modules/@whatwg-node/promise-helpers/typings/index.d.ts +31 -0
- package/node_modules/@whatwg-node/server/README.md +590 -0
- package/node_modules/@whatwg-node/server/cjs/createServerAdapter.js +368 -0
- package/node_modules/@whatwg-node/server/cjs/index.js +17 -0
- package/node_modules/@whatwg-node/server/cjs/package.json +1 -0
- package/node_modules/@whatwg-node/server/cjs/plugins/types.js +0 -0
- package/node_modules/@whatwg-node/server/cjs/plugins/useContentEncoding.js +73 -0
- package/node_modules/@whatwg-node/server/cjs/plugins/useCors.js +124 -0
- package/node_modules/@whatwg-node/server/cjs/plugins/useErrorHandling.js +52 -0
- package/node_modules/@whatwg-node/server/cjs/types.js +0 -0
- package/node_modules/@whatwg-node/server/cjs/utils.js +599 -0
- package/node_modules/@whatwg-node/server/cjs/uwebsockets.js +241 -0
- package/node_modules/@whatwg-node/server/esm/createServerAdapter.js +365 -0
- package/node_modules/@whatwg-node/server/esm/index.js +11 -0
- package/node_modules/@whatwg-node/server/esm/plugins/types.js +0 -0
- package/node_modules/@whatwg-node/server/esm/plugins/useContentEncoding.js +70 -0
- package/node_modules/@whatwg-node/server/esm/plugins/useCors.js +120 -0
- package/node_modules/@whatwg-node/server/esm/plugins/useErrorHandling.js +46 -0
- package/node_modules/@whatwg-node/server/esm/types.js +0 -0
- package/node_modules/@whatwg-node/server/esm/utils.js +588 -0
- package/node_modules/@whatwg-node/server/esm/uwebsockets.js +234 -0
- package/node_modules/@whatwg-node/server/package.json +46 -0
- package/node_modules/@whatwg-node/server/typings/createServerAdapter.d.cts +19 -0
- package/node_modules/@whatwg-node/server/typings/createServerAdapter.d.ts +19 -0
- package/node_modules/@whatwg-node/server/typings/index.d.cts +11 -0
- package/node_modules/@whatwg-node/server/typings/index.d.ts +11 -0
- package/node_modules/@whatwg-node/server/typings/plugins/types.d.cts +76 -0
- package/node_modules/@whatwg-node/server/typings/plugins/types.d.ts +76 -0
- package/node_modules/@whatwg-node/server/typings/plugins/useContentEncoding.d.cts +2 -0
- package/node_modules/@whatwg-node/server/typings/plugins/useContentEncoding.d.ts +2 -0
- package/node_modules/@whatwg-node/server/typings/plugins/useCors.d.cts +14 -0
- package/node_modules/@whatwg-node/server/typings/plugins/useCors.d.ts +14 -0
- package/node_modules/@whatwg-node/server/typings/plugins/useErrorHandling.d.cts +13 -0
- package/node_modules/@whatwg-node/server/typings/plugins/useErrorHandling.d.ts +13 -0
- package/node_modules/@whatwg-node/server/typings/types.d.cts +100 -0
- package/node_modules/@whatwg-node/server/typings/types.d.ts +100 -0
- package/node_modules/@whatwg-node/server/typings/utils.d.cts +42 -0
- package/node_modules/@whatwg-node/server/typings/utils.d.ts +42 -0
- package/node_modules/@whatwg-node/server/typings/uwebsockets.d.cts +32 -0
- package/node_modules/@whatwg-node/server/typings/uwebsockets.d.ts +32 -0
- package/node_modules/tslib/CopyrightNotice.txt +15 -0
- package/node_modules/tslib/LICENSE.txt +12 -0
- package/node_modules/tslib/README.md +164 -0
- package/node_modules/tslib/SECURITY.md +41 -0
- package/node_modules/tslib/modules/index.d.ts +38 -0
- package/node_modules/tslib/modules/index.js +70 -0
- package/node_modules/tslib/modules/package.json +3 -0
- package/node_modules/tslib/package.json +47 -0
- package/node_modules/tslib/tslib.d.ts +460 -0
- package/node_modules/tslib/tslib.es6.html +1 -0
- package/node_modules/tslib/tslib.es6.js +402 -0
- package/node_modules/tslib/tslib.es6.mjs +401 -0
- package/node_modules/tslib/tslib.html +1 -0
- package/node_modules/tslib/tslib.js +484 -0
- package/package.json +87 -0
- package/src/context.ts +203 -0
- package/src/index.ts +193 -0
- package/src/lib/constants.ts +6 -0
- package/src/lib/download-request.ts +142 -0
- package/src/lib/errors.ts +187 -0
- package/src/lib/event-stream-response.ts +57 -0
- package/src/lib/event-target.ts +11 -0
- package/src/lib/fetch-api.ts +18 -0
- package/src/lib/map-share.ts +185 -0
- package/src/lib/secret-stream-fetch.ts +42 -0
- package/src/lib/self-evicting-map.ts +35 -0
- package/src/lib/state-update-event.ts +14 -0
- package/src/lib/utils.ts +110 -0
- package/src/middlewares/localhost-only.ts +16 -0
- package/src/middlewares/parse-request.ts +34 -0
- package/src/routes/downloads.ts +92 -0
- package/src/routes/map-shares.ts +246 -0
- package/src/routes/maps.ts +146 -0
- package/src/routes/root.ts +37 -0
- package/src/types.ts +152 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { RequestLike } from 'itty-router';
|
|
2
|
+
import { Type as T, type Static } from 'typebox';
|
|
3
|
+
export declare const MapShareDeclineReason: T.TUnion<[T.TLiteral<"disk_full">, T.TLiteral<"user_rejected">, T.TString]>;
|
|
4
|
+
declare const MapShareStateUpdate: T.TUnion<[T.TObject<{
|
|
5
|
+
status: T.TLiteral<"pending">;
|
|
6
|
+
}>, T.TObject<{
|
|
7
|
+
status: T.TLiteral<"declined">;
|
|
8
|
+
reason: T.TUnion<[T.TLiteral<"disk_full">, T.TLiteral<"user_rejected">, T.TString]>;
|
|
9
|
+
}>, T.TObject<{
|
|
10
|
+
status: T.TLiteral<"downloading">;
|
|
11
|
+
bytesDownloaded: T.TNumber;
|
|
12
|
+
}>, T.TObject<{
|
|
13
|
+
status: T.TLiteral<"canceled">;
|
|
14
|
+
}>, T.TObject<{
|
|
15
|
+
status: T.TLiteral<"aborted">;
|
|
16
|
+
}>, T.TObject<{
|
|
17
|
+
status: T.TLiteral<"completed">;
|
|
18
|
+
}>, T.TObject<{
|
|
19
|
+
status: T.TLiteral<"error">;
|
|
20
|
+
error: T.TObject<{
|
|
21
|
+
message: T.TString;
|
|
22
|
+
code: T.TString;
|
|
23
|
+
}>;
|
|
24
|
+
}>]>;
|
|
25
|
+
export type MapShareStateUpdate = Static<typeof MapShareStateUpdate>;
|
|
26
|
+
export type MapShareStatus = Static<typeof MapShareStateUpdate>['status'];
|
|
27
|
+
export type DownloadStateUpdate = Extract<MapShareStateUpdate, {
|
|
28
|
+
status: 'downloading' | 'completed' | 'error' | 'canceled' | 'aborted';
|
|
29
|
+
}>;
|
|
30
|
+
export declare const MapShareUrls: T.TArray<T.TString>;
|
|
31
|
+
export declare const ShareId: T.TString;
|
|
32
|
+
export type ShareId = Static<typeof ShareId>;
|
|
33
|
+
export declare const EstimatedSizeBytes: T.TNumber;
|
|
34
|
+
declare const MapInfo: T.TObject<{
|
|
35
|
+
mapId: T.TString;
|
|
36
|
+
mapName: T.TString;
|
|
37
|
+
estimatedSizeBytes: T.TNumber;
|
|
38
|
+
bounds: T.TImmutable<T.TTuple<[T.TNumber, T.TNumber, T.TNumber, T.TNumber]>>;
|
|
39
|
+
minzoom: T.TNumber;
|
|
40
|
+
maxzoom: T.TNumber;
|
|
41
|
+
mapCreated: T.TNumber;
|
|
42
|
+
}>;
|
|
43
|
+
declare const MapShareBase: T.TIntersect<[T.TObject<{
|
|
44
|
+
receiverDeviceId: T.TString;
|
|
45
|
+
shareId: T.TString;
|
|
46
|
+
mapShareUrls: T.TArray<T.TString>;
|
|
47
|
+
mapShareCreated: T.TNumber;
|
|
48
|
+
}>, T.TObject<{
|
|
49
|
+
mapId: T.TString;
|
|
50
|
+
mapName: T.TString;
|
|
51
|
+
estimatedSizeBytes: T.TNumber;
|
|
52
|
+
bounds: T.TImmutable<T.TTuple<[T.TNumber, T.TNumber, T.TNumber, T.TNumber]>>;
|
|
53
|
+
minzoom: T.TNumber;
|
|
54
|
+
maxzoom: T.TNumber;
|
|
55
|
+
mapCreated: T.TNumber;
|
|
56
|
+
}>]>;
|
|
57
|
+
export declare const MapShareState: T.TIntersect<[T.TIntersect<[T.TObject<{
|
|
58
|
+
receiverDeviceId: T.TString;
|
|
59
|
+
shareId: T.TString;
|
|
60
|
+
mapShareUrls: T.TArray<T.TString>;
|
|
61
|
+
mapShareCreated: T.TNumber;
|
|
62
|
+
}>, T.TObject<{
|
|
63
|
+
mapId: T.TString;
|
|
64
|
+
mapName: T.TString;
|
|
65
|
+
estimatedSizeBytes: T.TNumber;
|
|
66
|
+
bounds: T.TImmutable<T.TTuple<[T.TNumber, T.TNumber, T.TNumber, T.TNumber]>>;
|
|
67
|
+
minzoom: T.TNumber;
|
|
68
|
+
maxzoom: T.TNumber;
|
|
69
|
+
mapCreated: T.TNumber;
|
|
70
|
+
}>]>, T.TUnion<[T.TObject<{
|
|
71
|
+
status: T.TLiteral<"pending">;
|
|
72
|
+
}>, T.TObject<{
|
|
73
|
+
status: T.TLiteral<"declined">;
|
|
74
|
+
reason: T.TUnion<[T.TLiteral<"disk_full">, T.TLiteral<"user_rejected">, T.TString]>;
|
|
75
|
+
}>, T.TObject<{
|
|
76
|
+
status: T.TLiteral<"downloading">;
|
|
77
|
+
bytesDownloaded: T.TNumber;
|
|
78
|
+
}>, T.TObject<{
|
|
79
|
+
status: T.TLiteral<"canceled">;
|
|
80
|
+
}>, T.TObject<{
|
|
81
|
+
status: T.TLiteral<"aborted">;
|
|
82
|
+
}>, T.TObject<{
|
|
83
|
+
status: T.TLiteral<"completed">;
|
|
84
|
+
}>, T.TObject<{
|
|
85
|
+
status: T.TLiteral<"error">;
|
|
86
|
+
error: T.TObject<{
|
|
87
|
+
message: T.TString;
|
|
88
|
+
code: T.TString;
|
|
89
|
+
}>;
|
|
90
|
+
}>]>]>;
|
|
91
|
+
export type MapShareState = DistributiveIntersection<Static<typeof MapShareBase>, Static<typeof MapShareStateUpdate>>;
|
|
92
|
+
export type MapInfo = Static<typeof MapInfo>;
|
|
93
|
+
export type FetchContext = {
|
|
94
|
+
isLocalhost?: boolean;
|
|
95
|
+
remoteDeviceId?: string;
|
|
96
|
+
};
|
|
97
|
+
export type DistributiveIntersection<Base, Union> = Union extends unknown ? Base & Union : never;
|
|
98
|
+
export type DistributeProperty<T, K extends keyof T> = T[K] extends infer V ? V extends T[K] ? {
|
|
99
|
+
[P in K]: V;
|
|
100
|
+
} & Omit<T, K> : never : never;
|
|
101
|
+
/**
|
|
102
|
+
* External router returned by create router functions. Ensures routers are
|
|
103
|
+
* called with the necessary fetch context
|
|
104
|
+
*/
|
|
105
|
+
export type RouterExternal = {
|
|
106
|
+
fetch: (request: RequestLike, context: FetchContext) => Promise<any>;
|
|
107
|
+
};
|
|
108
|
+
export type BBox = Readonly<[number, number, number, number]>;
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,IAAI,IAAI,CAAC,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAA;AAEhD,eAAO,MAAM,qBAAqB,6EAYhC,CAAA;AAEF,QAAA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;IAgDvB,CAAA;AAEF,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAA;AACpE,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC,QAAQ,CAAC,CAAA;AAEzE,MAAM,MAAM,mBAAmB,GAAG,OAAO,CACxC,mBAAmB,EACnB;IAAE,MAAM,EAAE,aAAa,GAAG,WAAW,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,CAAA;CAAE,CAC1E,CAAA;AAED,eAAO,MAAM,YAAY,qBAIvB,CAAA;AACF,eAAO,MAAM,OAAO,WAGlB,CAAA;AACF,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,OAAO,CAAC,CAAA;AAC5C,eAAO,MAAM,kBAAkB,WAE7B,CAAA;AAEF,QAAA,MAAM,OAAO;;;;;;;;EAcX,CAAA;AAEF,QAAA,MAAM,YAAY;;;;;;;;;;;;;IAYhB,CAAA;AAEF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAmD,CAAA;AAE7E,MAAM,MAAM,aAAa,GAAG,wBAAwB,CACnD,MAAM,CAAC,OAAO,YAAY,CAAC,EAC3B,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAClC,CAAA;AAED,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,OAAO,CAAC,CAAA;AAE5C,MAAM,MAAM,YAAY,GAAG;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,cAAc,CAAC,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,wBAAwB,CAAC,IAAI,EAAE,KAAK,IAAI,KAAK,SAAS,OAAO,GACtE,IAAI,GAAG,KAAK,GACZ,KAAK,CAAA;AAER,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,GACxE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GACb;KAAG,CAAC,IAAI,CAAC,GAAG,CAAC;CAAE,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAC5B,KAAK,GACN,KAAK,CAAA;AAER;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC5B,KAAK,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;CACpE,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Type as T } from 'typebox';
|
|
2
|
+
export const MapShareDeclineReason = T.Union([
|
|
3
|
+
T.Literal('disk_full', {
|
|
4
|
+
description: "The map share was declined because the receiver's disk is full",
|
|
5
|
+
}),
|
|
6
|
+
T.Literal('user_rejected', {
|
|
7
|
+
description: 'The map share was declined by the user',
|
|
8
|
+
}),
|
|
9
|
+
T.String({
|
|
10
|
+
minLength: 1,
|
|
11
|
+
description: 'Other reason for declining the map share',
|
|
12
|
+
}),
|
|
13
|
+
]);
|
|
14
|
+
const MapShareStateUpdate = T.Union([
|
|
15
|
+
T.Object({
|
|
16
|
+
status: T.Literal('pending', {
|
|
17
|
+
description: 'Map share is awaiting a response',
|
|
18
|
+
}),
|
|
19
|
+
}),
|
|
20
|
+
T.Object({
|
|
21
|
+
status: T.Literal('declined', {
|
|
22
|
+
description: 'Map share has been declined',
|
|
23
|
+
}),
|
|
24
|
+
reason: MapShareDeclineReason,
|
|
25
|
+
}),
|
|
26
|
+
T.Object({
|
|
27
|
+
status: T.Literal('downloading', {
|
|
28
|
+
description: 'Map share is currently being downloaded',
|
|
29
|
+
}),
|
|
30
|
+
bytesDownloaded: T.Number({
|
|
31
|
+
description: 'Total bytes downloaded so far (compare with estimatedSizeBytes for progress)',
|
|
32
|
+
}),
|
|
33
|
+
}),
|
|
34
|
+
T.Object({
|
|
35
|
+
status: T.Literal('canceled', {
|
|
36
|
+
description: 'Map share has been canceled (by the sharer)',
|
|
37
|
+
}),
|
|
38
|
+
}),
|
|
39
|
+
T.Object({
|
|
40
|
+
status: T.Literal('aborted', {
|
|
41
|
+
description: 'Map share download was aborted (by the receiver)',
|
|
42
|
+
}),
|
|
43
|
+
}),
|
|
44
|
+
T.Object({
|
|
45
|
+
status: T.Literal('completed', { description: 'Map has been downloaded' }),
|
|
46
|
+
}),
|
|
47
|
+
T.Object({
|
|
48
|
+
status: T.Literal('error', {
|
|
49
|
+
description: 'An error occurred while downloading',
|
|
50
|
+
}),
|
|
51
|
+
error: T.Object({
|
|
52
|
+
message: T.String({ description: 'Error message' }),
|
|
53
|
+
code: T.String({ description: 'Error code' }),
|
|
54
|
+
}, {
|
|
55
|
+
description: 'Error that occurred while receiving the map share',
|
|
56
|
+
}),
|
|
57
|
+
}),
|
|
58
|
+
]);
|
|
59
|
+
export const MapShareUrls = T.Array(T.String({ format: 'uri' }), {
|
|
60
|
+
minItems: 1,
|
|
61
|
+
description: 'List of map share URLs (for each network interface of the sharer)',
|
|
62
|
+
});
|
|
63
|
+
export const ShareId = T.String({
|
|
64
|
+
minLength: 1,
|
|
65
|
+
description: 'The ID of the map share',
|
|
66
|
+
});
|
|
67
|
+
export const EstimatedSizeBytes = T.Number({
|
|
68
|
+
description: 'Estimated size of the map data in bytes',
|
|
69
|
+
});
|
|
70
|
+
const MapInfo = T.Object({
|
|
71
|
+
mapId: T.String({ description: 'The ID of the map' }),
|
|
72
|
+
mapName: T.String({ description: 'The name of the map' }),
|
|
73
|
+
estimatedSizeBytes: EstimatedSizeBytes,
|
|
74
|
+
bounds: T.ReadonlyType(T.Tuple([T.Number(), T.Number(), T.Number(), T.Number()], {
|
|
75
|
+
description: 'The bounding box of the map data',
|
|
76
|
+
})),
|
|
77
|
+
minzoom: T.Number({ description: 'The minimum zoom level of the map data' }),
|
|
78
|
+
maxzoom: T.Number({ description: 'The maximum zoom level of the map data' }),
|
|
79
|
+
mapCreated: T.Number({
|
|
80
|
+
description: 'Timestamp (ms since epoch) when the map was created',
|
|
81
|
+
}),
|
|
82
|
+
});
|
|
83
|
+
const MapShareBase = T.Intersect([
|
|
84
|
+
T.Object({
|
|
85
|
+
receiverDeviceId: T.String({
|
|
86
|
+
description: 'The ID of the device that can receive the map share',
|
|
87
|
+
}),
|
|
88
|
+
shareId: ShareId,
|
|
89
|
+
mapShareUrls: MapShareUrls,
|
|
90
|
+
mapShareCreated: T.Number({
|
|
91
|
+
description: 'Timestamp (ms since epoch) when the map share was created',
|
|
92
|
+
}),
|
|
93
|
+
}),
|
|
94
|
+
MapInfo,
|
|
95
|
+
]);
|
|
96
|
+
export const MapShareState = T.Intersect([MapShareBase, MapShareStateUpdate]);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Dotan Simha
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
## `@envelop/instrumentation`
|
|
2
|
+
|
|
3
|
+
This package contains utility functions and types to ease the use of instrumentation accross
|
|
4
|
+
Envelop, Yoga, whatwg-node and Hive Gateway plugins.
|
|
5
|
+
|
|
6
|
+
> [!NOTE] Instrumentation are automatically composed together. This should only be used if the
|
|
7
|
+
> default ordering doesn't suit your needs (ie. instrumentation and hooks should be executed in
|
|
8
|
+
> different order)
|
|
9
|
+
|
|
10
|
+
## `composeInstrumentation(instrumentation: Instrumentation[]): Instrumentation`
|
|
11
|
+
|
|
12
|
+
This function composes all the instrumentation into one. The instrumentation will be called in the
|
|
13
|
+
same order as they are in the array (from top to bottom).
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { composeInstrumentation } from '@envelop/instrumentation'
|
|
17
|
+
|
|
18
|
+
// Extract instrumentation to compose from their plugins
|
|
19
|
+
const { instrumentation: instrumentation1, ...plugin1 } = usePlugin1()
|
|
20
|
+
const { instrumentation: instrumentation2, ...plugin2 } = usePlugin2()
|
|
21
|
+
|
|
22
|
+
const getEnveloped = envelop({
|
|
23
|
+
plugins: [
|
|
24
|
+
plugin1,
|
|
25
|
+
plugin2,
|
|
26
|
+
// Plugin instrumentation and plugin hooks will be executed in a different order
|
|
27
|
+
{ instrumentation: composeInstrumentation([instrumentation1, instrumentation2]) }
|
|
28
|
+
]
|
|
29
|
+
})
|
|
30
|
+
```
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getInstrumented = void 0;
|
|
4
|
+
exports.chain = chain;
|
|
5
|
+
exports.composeInstrumentation = composeInstrumentation;
|
|
6
|
+
exports.getInstrumentationAndPlugin = getInstrumentationAndPlugin;
|
|
7
|
+
const promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
|
8
|
+
/**
|
|
9
|
+
* Composes 2 instrumentations together into one instrumentation.
|
|
10
|
+
* The first one will be the outer call, the second one the inner call.
|
|
11
|
+
*/
|
|
12
|
+
function chain(first, next) {
|
|
13
|
+
const merged = { ...next, ...first };
|
|
14
|
+
for (const key of Object.keys(merged)) {
|
|
15
|
+
if (key in first && key in next) {
|
|
16
|
+
merged[key] = (payload, wrapped) => first[key](payload, () => next[key](payload, wrapped));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return merged;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Composes a list of instrumentation together into one instrumentation object.
|
|
23
|
+
* The order of execution will respect the order of the array,
|
|
24
|
+
* the first one being the outter most call, the last one the inner most call.
|
|
25
|
+
*/
|
|
26
|
+
function composeInstrumentation(instrumentation) {
|
|
27
|
+
return instrumentation.length > 0 ? instrumentation.reduce(chain) : undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Extract instrumentation from a list of plugins.
|
|
31
|
+
* It returns instrumentation found, and the list of plugins without their instrumentation.
|
|
32
|
+
*
|
|
33
|
+
* You can use this to easily customize the composition of the instrumentation if the default one
|
|
34
|
+
* doesn't suits your needs.
|
|
35
|
+
*/
|
|
36
|
+
function getInstrumentationAndPlugin(plugins) {
|
|
37
|
+
const pluginInstrumentation = [];
|
|
38
|
+
const newPlugins = [];
|
|
39
|
+
for (const { instrumentation, ...plugin } of plugins) {
|
|
40
|
+
if (instrumentation) {
|
|
41
|
+
pluginInstrumentation.push(instrumentation);
|
|
42
|
+
}
|
|
43
|
+
newPlugins.push(plugin);
|
|
44
|
+
}
|
|
45
|
+
return { pluginInstrumentation, plugins: newPlugins };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A helper to instrument a function.
|
|
49
|
+
*
|
|
50
|
+
* @param payload: The first argument that will be passed to the instrumentation on each function call
|
|
51
|
+
* @returns Function and Async Functions factories allowing to wrap a function with a given instrument.
|
|
52
|
+
*/
|
|
53
|
+
const getInstrumented = (payload) => ({
|
|
54
|
+
/**
|
|
55
|
+
* Wraps the `wrapped` function with the given `instrument` wrapper.
|
|
56
|
+
* @returns The wrapped function, or `undefined` if the instrument is `undefined`.
|
|
57
|
+
*/
|
|
58
|
+
fn(instrument, wrapped) {
|
|
59
|
+
if (!instrument) {
|
|
60
|
+
return wrapped;
|
|
61
|
+
}
|
|
62
|
+
return (...args) => {
|
|
63
|
+
let result;
|
|
64
|
+
instrument(payload, () => {
|
|
65
|
+
result = wrapped(...args);
|
|
66
|
+
});
|
|
67
|
+
return result;
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
/**
|
|
71
|
+
* Wraps the `wrapped` function with the given `instrument` wrapper.
|
|
72
|
+
* @returns The wrapped function, or `undefined` if the instrument is `undefined`.
|
|
73
|
+
*/
|
|
74
|
+
asyncFn(instrument, wrapped) {
|
|
75
|
+
if (!instrument) {
|
|
76
|
+
return wrapped;
|
|
77
|
+
}
|
|
78
|
+
return (...args) => {
|
|
79
|
+
let result;
|
|
80
|
+
return (0, promise_helpers_1.handleMaybePromise)(() => instrument(payload, () => {
|
|
81
|
+
result = wrapped(...args);
|
|
82
|
+
return (0, promise_helpers_1.isPromise)(result) ? result.then(() => undefined) : undefined;
|
|
83
|
+
}), () => {
|
|
84
|
+
return result;
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
exports.getInstrumented = getInstrumented;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { handleMaybePromise, isPromise } from '@whatwg-node/promise-helpers';
|
|
2
|
+
/**
|
|
3
|
+
* Composes 2 instrumentations together into one instrumentation.
|
|
4
|
+
* The first one will be the outer call, the second one the inner call.
|
|
5
|
+
*/
|
|
6
|
+
export function chain(first, next) {
|
|
7
|
+
const merged = { ...next, ...first };
|
|
8
|
+
for (const key of Object.keys(merged)) {
|
|
9
|
+
if (key in first && key in next) {
|
|
10
|
+
merged[key] = (payload, wrapped) => first[key](payload, () => next[key](payload, wrapped));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return merged;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Composes a list of instrumentation together into one instrumentation object.
|
|
17
|
+
* The order of execution will respect the order of the array,
|
|
18
|
+
* the first one being the outter most call, the last one the inner most call.
|
|
19
|
+
*/
|
|
20
|
+
export function composeInstrumentation(instrumentation) {
|
|
21
|
+
return instrumentation.length > 0 ? instrumentation.reduce(chain) : undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Extract instrumentation from a list of plugins.
|
|
25
|
+
* It returns instrumentation found, and the list of plugins without their instrumentation.
|
|
26
|
+
*
|
|
27
|
+
* You can use this to easily customize the composition of the instrumentation if the default one
|
|
28
|
+
* doesn't suits your needs.
|
|
29
|
+
*/
|
|
30
|
+
export function getInstrumentationAndPlugin(plugins) {
|
|
31
|
+
const pluginInstrumentation = [];
|
|
32
|
+
const newPlugins = [];
|
|
33
|
+
for (const { instrumentation, ...plugin } of plugins) {
|
|
34
|
+
if (instrumentation) {
|
|
35
|
+
pluginInstrumentation.push(instrumentation);
|
|
36
|
+
}
|
|
37
|
+
newPlugins.push(plugin);
|
|
38
|
+
}
|
|
39
|
+
return { pluginInstrumentation, plugins: newPlugins };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A helper to instrument a function.
|
|
43
|
+
*
|
|
44
|
+
* @param payload: The first argument that will be passed to the instrumentation on each function call
|
|
45
|
+
* @returns Function and Async Functions factories allowing to wrap a function with a given instrument.
|
|
46
|
+
*/
|
|
47
|
+
export const getInstrumented = (payload) => ({
|
|
48
|
+
/**
|
|
49
|
+
* Wraps the `wrapped` function with the given `instrument` wrapper.
|
|
50
|
+
* @returns The wrapped function, or `undefined` if the instrument is `undefined`.
|
|
51
|
+
*/
|
|
52
|
+
fn(instrument, wrapped) {
|
|
53
|
+
if (!instrument) {
|
|
54
|
+
return wrapped;
|
|
55
|
+
}
|
|
56
|
+
return (...args) => {
|
|
57
|
+
let result;
|
|
58
|
+
instrument(payload, () => {
|
|
59
|
+
result = wrapped(...args);
|
|
60
|
+
});
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* Wraps the `wrapped` function with the given `instrument` wrapper.
|
|
66
|
+
* @returns The wrapped function, or `undefined` if the instrument is `undefined`.
|
|
67
|
+
*/
|
|
68
|
+
asyncFn(instrument, wrapped) {
|
|
69
|
+
if (!instrument) {
|
|
70
|
+
return wrapped;
|
|
71
|
+
}
|
|
72
|
+
return (...args) => {
|
|
73
|
+
let result;
|
|
74
|
+
return handleMaybePromise(() => instrument(payload, () => {
|
|
75
|
+
result = wrapped(...args);
|
|
76
|
+
return isPromise(result) ? result.then(() => undefined) : undefined;
|
|
77
|
+
}), () => {
|
|
78
|
+
return result;
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@envelop/instrumentation",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@whatwg-node/promise-helpers": "^1.2.1",
|
|
7
|
+
"tslib": "^2.5.0"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/n1ru4l/envelop.git",
|
|
12
|
+
"directory": "packages/instrumentation"
|
|
13
|
+
},
|
|
14
|
+
"author": "Valentin Cocaud <v.cocaud@gmail.com>",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18.0.0"
|
|
18
|
+
},
|
|
19
|
+
"main": "cjs/index.js",
|
|
20
|
+
"module": "esm/index.js",
|
|
21
|
+
"typings": "typings/index.d.ts",
|
|
22
|
+
"typescript": {
|
|
23
|
+
"definition": "typings/index.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./typings/index.d.cts",
|
|
30
|
+
"default": "./cjs/index.js"
|
|
31
|
+
},
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./typings/index.d.ts",
|
|
34
|
+
"default": "./esm/index.js"
|
|
35
|
+
},
|
|
36
|
+
"default": {
|
|
37
|
+
"types": "./typings/index.d.ts",
|
|
38
|
+
"default": "./esm/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"./*": {
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./typings/*.d.cts",
|
|
44
|
+
"default": "./cjs/*.js"
|
|
45
|
+
},
|
|
46
|
+
"import": {
|
|
47
|
+
"types": "./typings/*.d.ts",
|
|
48
|
+
"default": "./esm/*.js"
|
|
49
|
+
},
|
|
50
|
+
"default": {
|
|
51
|
+
"types": "./typings/*.d.ts",
|
|
52
|
+
"default": "./esm/*.js"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"./package.json": "./package.json"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './instrumentation.cjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './instrumentation.js';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
2
|
+
export type GenericInstrumentation = Record<string, (payload: any, wrapped: () => MaybePromise<void>) => MaybePromise<void>>;
|
|
3
|
+
/**
|
|
4
|
+
* Composes 2 instrumentations together into one instrumentation.
|
|
5
|
+
* The first one will be the outer call, the second one the inner call.
|
|
6
|
+
*/
|
|
7
|
+
export declare function chain<First extends GenericInstrumentation, Next extends GenericInstrumentation>(first: First, next: Next): First & Next;
|
|
8
|
+
/**
|
|
9
|
+
* Composes a list of instrumentation together into one instrumentation object.
|
|
10
|
+
* The order of execution will respect the order of the array,
|
|
11
|
+
* the first one being the outter most call, the last one the inner most call.
|
|
12
|
+
*/
|
|
13
|
+
export declare function composeInstrumentation<T extends GenericInstrumentation>(instrumentation: T[]): T | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Extract instrumentation from a list of plugins.
|
|
16
|
+
* It returns instrumentation found, and the list of plugins without their instrumentation.
|
|
17
|
+
*
|
|
18
|
+
* You can use this to easily customize the composition of the instrumentation if the default one
|
|
19
|
+
* doesn't suits your needs.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getInstrumentationAndPlugin<T, P extends {
|
|
22
|
+
instrumentation?: T;
|
|
23
|
+
}>(plugins: P[]): {
|
|
24
|
+
pluginInstrumentation: T[];
|
|
25
|
+
plugins: Omit<P, 'instrumentation'>[];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A helper to instrument a function.
|
|
29
|
+
*
|
|
30
|
+
* @param payload: The first argument that will be passed to the instrumentation on each function call
|
|
31
|
+
* @returns Function and Async Functions factories allowing to wrap a function with a given instrument.
|
|
32
|
+
*/
|
|
33
|
+
export declare const getInstrumented: <TPayload>(payload: TPayload) => {
|
|
34
|
+
/**
|
|
35
|
+
* Wraps the `wrapped` function with the given `instrument` wrapper.
|
|
36
|
+
* @returns The wrapped function, or `undefined` if the instrument is `undefined`.
|
|
37
|
+
*/
|
|
38
|
+
fn<TResult, TArgs extends any[]>(instrument: ((payload: TPayload, wrapped: () => void) => void) | undefined, wrapped: (...args: TArgs) => TResult): (...args: TArgs) => TResult;
|
|
39
|
+
/**
|
|
40
|
+
* Wraps the `wrapped` function with the given `instrument` wrapper.
|
|
41
|
+
* @returns The wrapped function, or `undefined` if the instrument is `undefined`.
|
|
42
|
+
*/
|
|
43
|
+
asyncFn<TResult, TArgs_1 extends any[]>(instrument: ((payload: TPayload, wrapped: () => MaybePromise<void>) => MaybePromise<void>) | undefined, wrapped: (...args: TArgs_1) => MaybePromise<TResult>): (...args: TArgs_1) => MaybePromise<TResult>;
|
|
44
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
2
|
+
export type GenericInstrumentation = Record<string, (payload: any, wrapped: () => MaybePromise<void>) => MaybePromise<void>>;
|
|
3
|
+
/**
|
|
4
|
+
* Composes 2 instrumentations together into one instrumentation.
|
|
5
|
+
* The first one will be the outer call, the second one the inner call.
|
|
6
|
+
*/
|
|
7
|
+
export declare function chain<First extends GenericInstrumentation, Next extends GenericInstrumentation>(first: First, next: Next): First & Next;
|
|
8
|
+
/**
|
|
9
|
+
* Composes a list of instrumentation together into one instrumentation object.
|
|
10
|
+
* The order of execution will respect the order of the array,
|
|
11
|
+
* the first one being the outter most call, the last one the inner most call.
|
|
12
|
+
*/
|
|
13
|
+
export declare function composeInstrumentation<T extends GenericInstrumentation>(instrumentation: T[]): T | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Extract instrumentation from a list of plugins.
|
|
16
|
+
* It returns instrumentation found, and the list of plugins without their instrumentation.
|
|
17
|
+
*
|
|
18
|
+
* You can use this to easily customize the composition of the instrumentation if the default one
|
|
19
|
+
* doesn't suits your needs.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getInstrumentationAndPlugin<T, P extends {
|
|
22
|
+
instrumentation?: T;
|
|
23
|
+
}>(plugins: P[]): {
|
|
24
|
+
pluginInstrumentation: T[];
|
|
25
|
+
plugins: Omit<P, 'instrumentation'>[];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A helper to instrument a function.
|
|
29
|
+
*
|
|
30
|
+
* @param payload: The first argument that will be passed to the instrumentation on each function call
|
|
31
|
+
* @returns Function and Async Functions factories allowing to wrap a function with a given instrument.
|
|
32
|
+
*/
|
|
33
|
+
export declare const getInstrumented: <TPayload>(payload: TPayload) => {
|
|
34
|
+
/**
|
|
35
|
+
* Wraps the `wrapped` function with the given `instrument` wrapper.
|
|
36
|
+
* @returns The wrapped function, or `undefined` if the instrument is `undefined`.
|
|
37
|
+
*/
|
|
38
|
+
fn<TResult, TArgs extends any[]>(instrument: ((payload: TPayload, wrapped: () => void) => void) | undefined, wrapped: (...args: TArgs) => TResult): (...args: TArgs) => TResult;
|
|
39
|
+
/**
|
|
40
|
+
* Wraps the `wrapped` function with the given `instrument` wrapper.
|
|
41
|
+
* @returns The wrapped function, or `undefined` if the instrument is `undefined`.
|
|
42
|
+
*/
|
|
43
|
+
asyncFn<TResult, TArgs_1 extends any[]>(instrument: ((payload: TPayload, wrapped: () => MaybePromise<void>) => MaybePromise<void>) | undefined, wrapped: (...args: TArgs_1) => MaybePromise<TResult>): (...args: TArgs_1) => MaybePromise<TResult>;
|
|
44
|
+
};
|