@fluidframework/tool-utils 2.0.0-internal.3.0.1 → 2.0.0-internal.3.1.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/.eslintrc.js +19 -23
- package/.mocharc.js +2 -2
- package/api-extractor.json +2 -2
- package/dist/fluidToolRC.d.ts.map +1 -1
- package/dist/fluidToolRC.js.map +1 -1
- package/dist/httpHelpers.d.ts.map +1 -1
- package/dist/httpHelpers.js +6 -2
- package/dist/httpHelpers.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/odspTokenManager.d.ts.map +1 -1
- package/dist/odspTokenManager.js +5 -2
- package/dist/odspTokenManager.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/snapshotNormalizer.d.ts.map +1 -1
- package/dist/snapshotNormalizer.js +13 -10
- package/dist/snapshotNormalizer.js.map +1 -1
- package/lib/fluidToolRC.d.ts.map +1 -1
- package/lib/fluidToolRC.js.map +1 -1
- package/lib/httpHelpers.d.ts.map +1 -1
- package/lib/httpHelpers.js +6 -2
- package/lib/httpHelpers.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/odspTokenManager.d.ts.map +1 -1
- package/lib/odspTokenManager.js +5 -2
- package/lib/odspTokenManager.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/snapshotNormalizer.d.ts.map +1 -1
- package/lib/snapshotNormalizer.js +14 -11
- package/lib/snapshotNormalizer.js.map +1 -1
- package/package.json +103 -102
- package/prettier.config.cjs +1 -1
- package/src/fluidToolRC.ts +36 -36
- package/src/httpHelpers.ts +58 -44
- package/src/index.ts +5 -1
- package/src/odspTokenManager.ts +301 -309
- package/src/packageVersion.ts +1 -1
- package/src/snapshotNormalizer.ts +178 -171
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +10 -16
package/src/fluidToolRC.ts
CHANGED
|
@@ -11,54 +11,54 @@ import { lock } from "proper-lockfile";
|
|
|
11
11
|
import { IOdspTokens } from "@fluidframework/odsp-doclib-utils";
|
|
12
12
|
|
|
13
13
|
export interface IAsyncCache<TKey, TValue> {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
get(key: TKey): Promise<TValue | undefined>;
|
|
15
|
+
save(key: TKey, value: TValue): Promise<void>;
|
|
16
|
+
lock<T>(callback: () => Promise<T>): Promise<T>;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export interface IResources {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
tokens?: {
|
|
21
|
+
version?: number;
|
|
22
|
+
data: {
|
|
23
|
+
[key: string]: {
|
|
24
|
+
storage?: IOdspTokens;
|
|
25
|
+
push?: IOdspTokens;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const getRCFileName = () => path.join(os.homedir(), ".fluidtoolrc");
|
|
32
32
|
|
|
33
33
|
export async function loadRC(): Promise<IResources> {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
const readFile = util.promisify(fs.readFile);
|
|
35
|
+
const exists = util.promisify(fs.exists);
|
|
36
|
+
const fileName = getRCFileName();
|
|
37
|
+
if (await exists(fileName)) {
|
|
38
|
+
const buf = await readFile(fileName);
|
|
39
|
+
try {
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
41
|
+
return JSON.parse(buf.toString("utf8"));
|
|
42
|
+
} catch (e) {
|
|
43
|
+
// Nothing
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return {};
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
export async function saveRC(rc: IResources) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
const writeFile = util.promisify(fs.writeFile);
|
|
51
|
+
const content = JSON.stringify(rc, undefined, 2);
|
|
52
|
+
return writeFile(getRCFileName(), Buffer.from(content, "utf8"));
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export async function lockRC() {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
57
|
+
return lock(getRCFileName(), {
|
|
58
|
+
retries: {
|
|
59
|
+
forever: true,
|
|
60
|
+
},
|
|
61
|
+
stale: 60000,
|
|
62
|
+
realpath: false,
|
|
63
|
+
});
|
|
64
64
|
}
|
package/src/httpHelpers.ts
CHANGED
|
@@ -7,53 +7,67 @@ import http from "http";
|
|
|
7
7
|
import { Socket } from "net";
|
|
8
8
|
|
|
9
9
|
export interface ITrackedHttpServer {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
readonly server: http.Server;
|
|
11
|
+
readonly sockets: Set<Socket>;
|
|
12
|
+
fullyClose(): void;
|
|
13
13
|
}
|
|
14
|
-
export function createTrackedServer(
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
export function createTrackedServer(
|
|
15
|
+
port: number,
|
|
16
|
+
requestListener: http.RequestListener,
|
|
17
|
+
): ITrackedHttpServer {
|
|
18
|
+
const server = http.createServer(requestListener).listen(port);
|
|
19
|
+
const sockets = new Set<Socket>();
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
server.on("connection", (socket) => {
|
|
22
|
+
sockets.add(socket);
|
|
23
|
+
socket.on("close", () => sockets.delete(socket));
|
|
24
|
+
});
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
return {
|
|
27
|
+
server,
|
|
28
|
+
sockets,
|
|
29
|
+
fullyClose() {
|
|
30
|
+
server.close();
|
|
31
|
+
sockets.forEach((socket) => socket.destroy());
|
|
32
|
+
},
|
|
33
|
+
};
|
|
29
34
|
}
|
|
30
|
-
export type OnceListenerHandler<T> = (
|
|
35
|
+
export type OnceListenerHandler<T> = (
|
|
36
|
+
req: http.IncomingMessage,
|
|
37
|
+
res: http.ServerResponse,
|
|
38
|
+
) => Promise<T>;
|
|
31
39
|
export type OnceListenerResult<T> = Promise<() => Promise<T>>;
|
|
32
|
-
export const serverListenAndHandle = async <T>(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
export const serverListenAndHandle = async <T>(
|
|
41
|
+
port: number,
|
|
42
|
+
handler: OnceListenerHandler<T>,
|
|
43
|
+
): OnceListenerResult<T> =>
|
|
44
|
+
// eslint-disable-next-line promise/param-names
|
|
45
|
+
new Promise((outerResolve, outerReject) => {
|
|
46
|
+
// eslint-disable-next-line promise/param-names
|
|
47
|
+
const innerP = new Promise<T>((innerResolve, innerReject) => {
|
|
48
|
+
const httpServer = createTrackedServer(port, (req, res) => {
|
|
49
|
+
// ignore favicon
|
|
50
|
+
if (req.url === "/favicon.ico") {
|
|
51
|
+
res.writeHead(200, { "Content-Type": "image/x-icon" });
|
|
52
|
+
res.end();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
handler(req, res)
|
|
56
|
+
.finally(() => httpServer.fullyClose())
|
|
57
|
+
.then(
|
|
58
|
+
(result) => innerResolve(result),
|
|
59
|
+
(error) => innerReject(error),
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
outerResolve(async () => innerP);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
52
65
|
|
|
53
|
-
export const endResponse = async (response: http.ServerResponse): Promise<void> =>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
66
|
+
export const endResponse = async (response: http.ServerResponse): Promise<void> =>
|
|
67
|
+
new Promise((resolve, reject) => {
|
|
68
|
+
try {
|
|
69
|
+
response.end(resolve);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
reject(error);
|
|
72
|
+
}
|
|
73
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -11,4 +11,8 @@ export {
|
|
|
11
11
|
OdspTokenManager,
|
|
12
12
|
odspTokensCache,
|
|
13
13
|
} from "./odspTokenManager";
|
|
14
|
-
export {
|
|
14
|
+
export {
|
|
15
|
+
gcBlobPrefix,
|
|
16
|
+
getNormalizedSnapshot,
|
|
17
|
+
ISnapshotNormalizerConfig,
|
|
18
|
+
} from "./snapshotNormalizer";
|