@gadgetinc/dateilager 0.7.9 → 0.7.11
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 +1 -1
- package/dist/cjs/binary-client.d.ts +2 -10
- package/dist/cjs/binary-client.js +3 -5
- package/dist/cjs/binary-client.js.map +1 -1
- package/dist/cjs/grpc-client.d.ts +16 -38
- package/dist/cjs/grpc-client.js +16 -36
- package/dist/cjs/grpc-client.js.map +1 -1
- package/dist/cjs/internal/telemetry.js +1 -1
- package/dist/cjs/internal/telemetry.js.map +1 -1
- package/dist/cjs/pb/fs_pb.client.js.map +1 -1
- package/dist/cjs/pb/fs_pb.js +3 -3
- package/dist/cjs/pb/fs_pb.js.map +1 -1
- package/dist/cjs/utils/errors.d.ts +3 -0
- package/dist/cjs/utils/errors.js +3 -0
- package/dist/cjs/utils/errors.js.map +1 -1
- package/dist/esm/binary-client.d.ts +2 -10
- package/dist/esm/binary-client.js +3 -5
- package/dist/esm/binary-client.js.map +1 -1
- package/dist/esm/grpc-client.d.ts +16 -38
- package/dist/esm/grpc-client.js +16 -36
- package/dist/esm/grpc-client.js.map +1 -1
- package/dist/esm/internal/telemetry.js +1 -1
- package/dist/esm/internal/telemetry.js.map +1 -1
- package/dist/esm/pb/fs_pb.client.js.map +1 -1
- package/dist/esm/pb/fs_pb.js +1 -1
- package/dist/esm/pb/fs_pb.js.map +1 -1
- package/dist/esm/utils/errors.d.ts +3 -0
- package/dist/esm/utils/errors.js +3 -0
- package/dist/esm/utils/errors.js.map +1 -1
- package/package.json +16 -16
package/README.md
CHANGED
|
@@ -25,38 +25,32 @@ export interface DateiLagerBinaryClientOptions {
|
|
|
25
25
|
token: string | (() => Promise<string>);
|
|
26
26
|
/**
|
|
27
27
|
* The path to the dateilager-client executable.
|
|
28
|
-
*
|
|
29
28
|
* @default "dateilager-client"
|
|
30
29
|
*/
|
|
31
30
|
command?: string;
|
|
32
31
|
/**
|
|
33
32
|
* The default number of milliseconds to wait before terminating any command.
|
|
34
|
-
*
|
|
35
33
|
* @default 0 No timeout.
|
|
36
34
|
*/
|
|
37
35
|
timeout?: number | {
|
|
38
36
|
/**
|
|
39
37
|
* The default number of milliseconds to wait before terminating the update command.
|
|
40
|
-
*
|
|
41
38
|
* @default 0 No timeout.
|
|
42
39
|
*/
|
|
43
40
|
update?: number;
|
|
44
41
|
/**
|
|
45
42
|
* The default number of milliseconds to wait before terminating the rebuild command.
|
|
46
|
-
*
|
|
47
43
|
* @default 0 No timeout.
|
|
48
44
|
*/
|
|
49
45
|
rebuild?: number;
|
|
50
46
|
/**
|
|
51
47
|
* The default number of milliseconds to wait before terminating the gc command.
|
|
52
|
-
*
|
|
53
48
|
* @default 0 No timeout.
|
|
54
49
|
*/
|
|
55
50
|
gc?: number;
|
|
56
51
|
};
|
|
57
52
|
/**
|
|
58
53
|
* Whether the dateilager binary client should enable tracing.
|
|
59
|
-
*
|
|
60
54
|
* @default false
|
|
61
55
|
*/
|
|
62
56
|
tracing?: boolean;
|
|
@@ -114,19 +108,17 @@ export declare class DateiLagerBinaryClient {
|
|
|
114
108
|
constructor(options: DateiLagerBinaryClientOptions);
|
|
115
109
|
/**
|
|
116
110
|
* Update objects in a project based on the differences in a local directory.
|
|
117
|
-
*
|
|
118
111
|
* @param project The id of the project.
|
|
119
112
|
* @param directory The path of the directory to send updates from.
|
|
120
113
|
* @param options Object of options.
|
|
121
114
|
* @param options.timeout Number of milliseconds to wait before terminating the process.
|
|
122
|
-
* @returns
|
|
115
|
+
* @returns The latest project version or `null` if something went wrong.
|
|
123
116
|
*/
|
|
124
117
|
update(project: bigint, directory: string, options?: {
|
|
125
118
|
timeout?: number;
|
|
126
119
|
}): Promise<bigint | null>;
|
|
127
120
|
/**
|
|
128
121
|
* Rebuild the local filesystem.
|
|
129
|
-
*
|
|
130
122
|
* @param project The id of the project.
|
|
131
123
|
* @param to The version of the project to rebuild the filesystem to.
|
|
132
124
|
* @param directory The path of the directory to rebuild the filesystem at.
|
|
@@ -137,7 +129,7 @@ export declare class DateiLagerBinaryClient {
|
|
|
137
129
|
* @param options.cacheDir Path where the cache directory is mounted.
|
|
138
130
|
* @param options.matchInclude Set fileMatch to true if the written files are matched by this glob pattern
|
|
139
131
|
* @param options.matchExclude Set fileMatch to false if the written files are matched by this glob pattern
|
|
140
|
-
* @returns
|
|
132
|
+
* @returns The latest project version or `null` if something went wrong.
|
|
141
133
|
*/
|
|
142
134
|
rebuild(project: bigint, to: bigint | null, directory: string, options?: {
|
|
143
135
|
timeout?: number;
|
|
@@ -50,12 +50,11 @@ class DateiLagerBinaryClient {
|
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Update objects in a project based on the differences in a local directory.
|
|
53
|
-
*
|
|
54
53
|
* @param project The id of the project.
|
|
55
54
|
* @param directory The path of the directory to send updates from.
|
|
56
55
|
* @param options Object of options.
|
|
57
56
|
* @param options.timeout Number of milliseconds to wait before terminating the process.
|
|
58
|
-
* @returns
|
|
57
|
+
* @returns The latest project version or `null` if something went wrong.
|
|
59
58
|
*/
|
|
60
59
|
async update(project, directory, options) {
|
|
61
60
|
return await (0, telemetry_1.trace)("dateilager-binary-client.update", {
|
|
@@ -74,7 +73,6 @@ class DateiLagerBinaryClient {
|
|
|
74
73
|
}
|
|
75
74
|
/**
|
|
76
75
|
* Rebuild the local filesystem.
|
|
77
|
-
*
|
|
78
76
|
* @param project The id of the project.
|
|
79
77
|
* @param to The version of the project to rebuild the filesystem to.
|
|
80
78
|
* @param directory The path of the directory to rebuild the filesystem at.
|
|
@@ -85,7 +83,7 @@ class DateiLagerBinaryClient {
|
|
|
85
83
|
* @param options.cacheDir Path where the cache directory is mounted.
|
|
86
84
|
* @param options.matchInclude Set fileMatch to true if the written files are matched by this glob pattern
|
|
87
85
|
* @param options.matchExclude Set fileMatch to false if the written files are matched by this glob pattern
|
|
88
|
-
* @returns
|
|
86
|
+
* @returns The latest project version or `null` if something went wrong.
|
|
89
87
|
*/
|
|
90
88
|
async rebuild(project, to, directory, options) {
|
|
91
89
|
return await (0, telemetry_1.trace)("dateilager-binary-client.rebuild", {
|
|
@@ -207,7 +205,7 @@ class DateiLagerBinaryClient {
|
|
|
207
205
|
}
|
|
208
206
|
const subprocess = (0, execa_1.default)(this._options.command, baseArgs.concat(args), {
|
|
209
207
|
cwd,
|
|
210
|
-
cleanup: false,
|
|
208
|
+
cleanup: false, // don't terminate this subprocess process eagerly when the parent process is terminated, which is execa's default behaviour. we use graceful shutdown gadget-side to give running operations a chance to complete, and we don't want to terminate them prematurely
|
|
211
209
|
env: { DL_TOKEN: await this._options.token() },
|
|
212
210
|
});
|
|
213
211
|
if (this._options.logger && subprocess.stderr) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binary-client.js","sourceRoot":"","sources":["../../src/binary-client.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA0D;AAE1D,kDAA0B;AAC1B,2DAA6B;AAC7B,wDAAgC;AAChC,oDAA6C;AAyH7C;;;;GAIG;AACH,MAAa,sBAAsB;IAIjC;;OAEG;IACH,YAAmB,OAAsC;QANzD,gBAAgB;QAChB;;;;;WAA0B;QAMxB,IAAI,CAAC,QAAQ,GAAG;YACd,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI;YACzB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,IAAI;YACjC,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY;YACzC,KAAK,EAAE,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAe,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK;YACzG,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,mBAAmB;YAC/C,OAAO,EACL,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ;gBACjC,CAAC,CAAC;oBACE,MAAM,EAAE,OAAO,CAAC,O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AC,EAAE;YACrE,GAAG;YACH,OAAO,EAAE,KAAK;YACd,GAAG,EAAE,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE;SAC/C,CAAC,CAAC;QAEH,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE;YAC7C,kBAAQ,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;gBAC9D,IAAI;oBACF,oDAAoD;oBACpD,6DAA6D;oBAC7D,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAKpD,CAAC;oBAEF,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;iBAC/C;gBAAC,OAAO,KAAK,EAAE;oBACd,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;iBAC1E;YACH,CAAC,CAAC,CAAC;SACJ;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CACF;AAnRD,wDAmRC","sourcesContent":["import { context, propagation } from \"@opentelemetry/api\";\nimport type { ExecaReturnValue } from \"execa\";\nimport execa from \"execa\";\nimport fs from \"fs/promises\";\nimport readline from \"readline\";\nimport { trace } from \"./internal/telemetry\";\n\n/**\n * Options for {@link DateiLagerBinaryClient}.\n */\nexport interface DateiLagerBinaryClientOptions {\n /**\n * The address of the dateilager server.\n */\n server: {\n /**\n * The host of the dateilager server.\n */\n host: string;\n\n /**\n * The port of the dateilager server.\n */\n port?: number;\n\n /**\n * The GRPC headless service hostname, used for load balancing across multiple servers.\n */\n headlessHost?: string;\n };\n\n /**\n * The token that will be sent as authorization metadata to the dateilager server.\n */\n token: string | (() => Promise<string>);\n\n /**\n * The path to the dateilager-client executable.\n *\n * @default \"dateilager-client\"\n */\n command?: string;\n\n /**\n * The default number of milliseconds to wait before terminating any command.\n *\n * @default 0 No timeout.\n */\n timeout?:\n | number\n | {\n /**\n * The default number of milliseconds to wait before terminating the update command.\n *\n * @default 0 No timeout.\n */\n update?: number;\n\n /**\n * The default number of milliseconds to wait before terminating the rebuild command.\n *\n * @default 0 No timeout.\n */\n rebuild?: number;\n\n /**\n * The default number of milliseconds to wait before terminating the gc command.\n *\n * @default 0 No timeout.\n */\n gc?: number;\n };\n\n /**\n * Whether the dateilager binary client should enable tracing.\n *\n * @default false\n */\n tracing?: boolean;\n\n /**\n * Logging configuration.\n */\n logger?: {\n /**\n * The log level to pass to the dateilager binary client.\n */\n level: \"debug\" | \"info\" | \"warn\" | \"error\";\n\n /**\n * The function that will be called when the dateilager binary client logs something.\n */\n log: (level: \"debug\" | \"info\" | \"warn\" | \"error\", msg: string, fields: Record<string, unknown>) => void;\n };\n}\n\n/**\n * The version of the filesystem after the call to rebuild.\n *\n * If a file pattern was included then patternDetected can be used to know if that filepattern was seen while rebuilding.\n */\nexport interface RebuildResult {\n /**\n * Filesystem version.\n */\n version: bigint;\n /**\n * Files updated by the rebuild operation.\n */\n count: number;\n /**\n * Whether or not the file match was detected.\n */\n fileMatch: boolean;\n}\n\n/**\n * The Result from calling the Dateilager Garbage Compiler\n */\nexport interface GCResult {\n /**\n * The number of records garbage collected\n */\n count: number;\n}\n\n/**\n * A version of the DateiLager client that uses the compiled binary client instead of the Javascript one.\n *\n * Useful for working directly with a real filesystem instead of in memory objects.\n */\nexport class DateiLagerBinaryClient {\n /** @internal */\n private readonly _options;\n\n /**\n * @param options An object with {@link DateiLagerBinaryClientOptions options}.\n */\n public constructor(options: DateiLagerBinaryClientOptions) {\n this._options = {\n host: options.server.host,\n port: options.server.port ?? 5051,\n headlessHost: options.server.headlessHost,\n token: typeof options.token === \"string\" ? () => Promise.resolve(options.token as string) : options.token,\n command: options.command ?? \"dateilager-client\",\n timeout:\n typeof options.timeout === \"number\"\n ? {\n update: options.timeout,\n rebuild: options.timeout,\n gc: options.timeout,\n }\n : {\n update: 0,\n rebuild: 0,\n gc: 0,\n ...options.timeout,\n },\n tracing: options.tracing ?? false,\n logger: options.logger,\n };\n }\n\n /**\n * Update objects in a project based on the differences in a local directory.\n *\n * @param project The id of the project.\n * @param directory The path of the directory to send updates from.\n * @param options Object of options.\n * @param options.timeout Number of milliseconds to wait before terminating the process.\n * @returns The latest project version or `null` if something went wrong.\n */\n public async update(project: bigint, directory: string, options?: { timeout?: number }): Promise<bigint | null> {\n return await trace(\n \"dateilager-binary-client.update\",\n {\n attributes: {\n \"dl.project\": String(project),\n \"dl.directory\": directory,\n },\n },\n async () => {\n const args = [\"--dir\", String(directory), \"--project\", String(project)];\n const result = await this._call(\"update\", args, directory, options);\n\n if (result.stdout == \"-1\") {\n return null;\n }\n\n return BigInt(result.stdout);\n }\n );\n }\n\n /**\n * Rebuild the local filesystem.\n *\n * @param project The id of the project.\n * @param to The version of the project to rebuild the filesystem to.\n * @param directory The path of the directory to rebuild the filesystem at.\n * @param options Object of options.\n * @param options.timeout Number of milliseconds to wait before terminating the process.\n * @param options.ignores The paths to ignore when rebuilding the FS.\n * @param options.summarize Should produce the summary file after rebuilding.\n * @param options.cacheDir Path where the cache directory is mounted.\n * @param options.matchInclude Set fileMatch to true if the written files are matched by this glob pattern\n * @param options.matchExclude Set fileMatch to false if the written files are matched by this glob pattern\n * @returns The latest project version or `null` if something went wrong.\n */\n public async rebuild(\n project: bigint,\n to: bigint | null,\n directory: string,\n options?: {\n timeout?: number;\n ignores?: string[];\n summarize?: boolean;\n cacheDir?: string;\n matchInclude?: string;\n matchExclude?: string;\n }\n ): Promise<RebuildResult> {\n return await trace(\n \"dateilager-binary-client.rebuild\",\n {\n attributes: {\n \"dl.project\": String(project),\n \"dl.to\": String(to),\n \"dl.directory\": directory,\n },\n },\n async () => {\n await fs.mkdir(directory, { recursive: true });\n\n const args = [\"--dir\", directory];\n if (to) {\n args.push(\"--to\", String(to));\n }\n\n if (options?.ignores) {\n args.push(\"--ignores\", options.ignores.join(\",\"));\n }\n\n if (options?.summarize === false) {\n args.push(\"--summarize=false\");\n }\n\n if (options?.cacheDir) {\n args.push(`--cachedir=${options.cacheDir}`);\n }\n\n if (options?.matchInclude) {\n args.push(`--matchinclude=${options.matchInclude}`);\n }\n\n if (options?.matchExclude) {\n args.push(`--matchexclude=${options.matchExclude}`);\n }\n\n args.push(\"--project\", String(project), \"--dir\", directory);\n const result = await this._call(\"rebuild\", args, directory, options);\n const parsed = JSON.parse(result.stdout) as { version: number; count: number; fileMatch: boolean };\n return { version: BigInt(parsed.version), count: parsed.count, fileMatch: parsed.fileMatch };\n }\n );\n }\n\n /**\n * @param sample sample size of cleanup\n * @param keep The amount of records to keep\n * @param from Where to start cleanup\n * @param options dict options passed\n * @param options.timeout timeout limit for the request\n */\n public async gcRandomProjects(sample: number, keep: number, from?: number, options?: { timeout?: number }): Promise<GCResult> {\n return await trace(\n \"dateilager-binary-client.gc\",\n {\n attributes: {\n \"db.mode\": \"random-projects\",\n \"dl.keep\": String(keep),\n \"dl.from\": String(from),\n \"dl.sample\": String(sample),\n },\n },\n async () => {\n const args = [\"--mode\", \"random-projects\", \"--keep\", String(keep), \"--sample\", String(sample)];\n\n if (from) args.push(\"--from\", String(from));\n\n const result = await this._call(\"gc\", args, undefined, options);\n const parsed = JSON.parse(result.stdout) as { count: number };\n return { count: parsed.count };\n }\n );\n }\n\n /**\n *\n * @param project The selected project to cleanup\n * @param keep The amount of records to keep\n * @param from Where to start cleanup\n * @param options dict options passed\n * @param options.timeout timeout limit for the request\n */\n public async gcProject(project: number, keep: number, from?: number, options?: { timeout?: number }): Promise<GCResult> {\n return await trace(\n \"dateilager-binary-client.gc\",\n {\n attributes: {\n \"db.mode\": \"project\",\n \"dl.keep\": String(keep),\n \"dl.from\": String(from),\n },\n },\n async () => {\n const args = [\"--mode\", \"project\", \"--keep\", String(keep), \"--project\", String(project)];\n\n if (from) args.push(\"--from\", String(from));\n\n const result = await this._call(\"gc\", args, undefined, options);\n const parsed = JSON.parse(result.stdout) as { count: number };\n return { count: parsed.count };\n }\n );\n }\n\n /**\n *\n * @param sample sample size of cleanup\n * @param options dict options passed\n * @param options.timeout timeout limit for the request\n */\n public async gcContents(sample: number, options?: { timeout?: number }): Promise<GCResult> {\n return await trace(\n \"dateilager-binary-client.gc\",\n {\n attributes: {\n \"db.mode\": \"contents\",\n \"dl.sample\": String(sample),\n },\n },\n async () => {\n const args = [\"--mode\", \"contents\", \"--sample\", String(sample)];\n\n const result = await this._call(\"gc\", args, undefined, options);\n const parsed = JSON.parse(result.stdout) as { count: number };\n return { count: parsed.count };\n }\n );\n }\n\n /** @internal */\n private async _call(\n method: \"update\" | \"rebuild\" | \"gc\",\n args: string[],\n cwd?: string,\n options?: { timeout?: number }\n ): Promise<ExecaReturnValue> {\n const baseArgs = [method, \"--host\", this._options.host, \"--port\", String(this._options.port), \"--log-encoding\", \"json\"];\n\n if (this._options.logger) {\n baseArgs.push(\"--log-level\", this._options.logger.level);\n }\n\n if (this._options.headlessHost) {\n baseArgs.push(\"--headless-host\", this._options.headlessHost);\n }\n\n const timeout = options?.timeout ?? this._options.timeout[method];\n baseArgs.push(\"--timeout\", String(timeout));\n\n if (this._options.tracing) {\n const carrier = {};\n propagation.inject(context.active(), carrier);\n const otelContext = JSON.stringify(carrier);\n\n baseArgs.push(\"--tracing\", \"--otel-context\", otelContext);\n }\n const subprocess = execa(this._options.command, baseArgs.concat(args), {\n cwd,\n cleanup: false, // don't terminate this subprocess process eagerly when the parent process is terminated, which is execa's default behaviour. we use graceful shutdown gadget-side to give running operations a chance to complete, and we don't want to terminate them prematurely\n env: { DL_TOKEN: await this._options.token() },\n });\n\n if (this._options.logger && subprocess.stderr) {\n readline.createInterface(subprocess.stderr).on(\"line\", (line) => {\n try {\n // we purposefully extract and ignore the `ts` field\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { level, msg, ts, ...fields } = JSON.parse(line) as {\n [key: string]: unknown;\n level: \"debug\" | \"info\" | \"warn\" | \"error\";\n msg: string;\n ts: string | number;\n };\n\n this._options.logger?.log(level, msg, fields);\n } catch (error) {\n this._options.logger?.log(\"warn\", \"failed to log line\", { error, line });\n }\n });\n }\n\n return subprocess;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"binary-client.js","sourceRoot":"","sources":["../../src/binary-client.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA0D;AAE1D,kDAA0B;AAC1B,2DAA6B;AAC7B,wDAAgC;AAChC,oDAA6C;AAmH7C;;;;GAIG;AACH,MAAa,sBAAsB;IAIjC;;OAEG;IACH,YAAmB,OAAsC;QANzD,gBAAgB;QACC;;;;;WAAS;QAMxB,IAAI,CAAC,QAAQ,GAAG;YACd,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI;YACzB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,IAAI;YACjC,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY;YACzC,KAAK,EAAE,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAe,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK;YACzG,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,mBAAmB;YAC/C,OAAO,EACL,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ;gBACjC,CAAC,CAAC;oBACE,MAAM,EAAE,OAAO,CAAC,OAAO;oBACvB,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,EAAE,EAAE,OAAO,CAAC,OAAO;iBACpB;gBACH,CAAC,CAAC;oBACE,MAAM,EAAE,CAAC;oBACT,OAAO,EAAE,CAAC;oBACV,EAAE,EAAE,CAAC;oBACL,GAAG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GAAG,EAAE,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE;SAC/C,CAAC,CAAC;QAEH,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC;YAC9C,kBAAQ,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;gBAC9D,IAAI,CAAC;oBACH,oDAAoD;oBACpD,6DAA6D;oBAC7D,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAKpD,CAAC;oBAEF,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;gBAChD,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC3E,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CACF;AAjRD,wDAiRC","sourcesContent":["import { context, propagation } from \"@opentelemetry/api\";\nimport type { ExecaReturnValue } from \"execa\";\nimport execa from \"execa\";\nimport fs from \"fs/promises\";\nimport readline from \"readline\";\nimport { trace } from \"./internal/telemetry\";\n\n/**\n * Options for {@link DateiLagerBinaryClient}.\n */\nexport interface DateiLagerBinaryClientOptions {\n /**\n * The address of the dateilager server.\n */\n server: {\n /**\n * The host of the dateilager server.\n */\n host: string;\n\n /**\n * The port of the dateilager server.\n */\n port?: number;\n\n /**\n * The GRPC headless service hostname, used for load balancing across multiple servers.\n */\n headlessHost?: string;\n };\n\n /**\n * The token that will be sent as authorization metadata to the dateilager server.\n */\n token: string | (() => Promise<string>);\n\n /**\n * The path to the dateilager-client executable.\n * @default \"dateilager-client\"\n */\n command?: string;\n\n /**\n * The default number of milliseconds to wait before terminating any command.\n * @default 0 No timeout.\n */\n timeout?:\n | number\n | {\n /**\n * The default number of milliseconds to wait before terminating the update command.\n * @default 0 No timeout.\n */\n update?: number;\n\n /**\n * The default number of milliseconds to wait before terminating the rebuild command.\n * @default 0 No timeout.\n */\n rebuild?: number;\n\n /**\n * The default number of milliseconds to wait before terminating the gc command.\n * @default 0 No timeout.\n */\n gc?: number;\n };\n\n /**\n * Whether the dateilager binary client should enable tracing.\n * @default false\n */\n tracing?: boolean;\n\n /**\n * Logging configuration.\n */\n logger?: {\n /**\n * The log level to pass to the dateilager binary client.\n */\n level: \"debug\" | \"info\" | \"warn\" | \"error\";\n\n /**\n * The function that will be called when the dateilager binary client logs something.\n */\n log: (level: \"debug\" | \"info\" | \"warn\" | \"error\", msg: string, fields: Record<string, unknown>) => void;\n };\n}\n\n/**\n * The version of the filesystem after the call to rebuild.\n *\n * If a file pattern was included then patternDetected can be used to know if that filepattern was seen while rebuilding.\n */\nexport interface RebuildResult {\n /**\n * Filesystem version.\n */\n version: bigint;\n /**\n * Files updated by the rebuild operation.\n */\n count: number;\n /**\n * Whether or not the file match was detected.\n */\n fileMatch: boolean;\n}\n\n/**\n * The Result from calling the Dateilager Garbage Compiler\n */\nexport interface GCResult {\n /**\n * The number of records garbage collected\n */\n count: number;\n}\n\n/**\n * A version of the DateiLager client that uses the compiled binary client instead of the Javascript one.\n *\n * Useful for working directly with a real filesystem instead of in memory objects.\n */\nexport class DateiLagerBinaryClient {\n /** @internal */\n private readonly _options;\n\n /**\n * @param options An object with {@link DateiLagerBinaryClientOptions options}.\n */\n public constructor(options: DateiLagerBinaryClientOptions) {\n this._options = {\n host: options.server.host,\n port: options.server.port ?? 5051,\n headlessHost: options.server.headlessHost,\n token: typeof options.token === \"string\" ? () => Promise.resolve(options.token as string) : options.token,\n command: options.command ?? \"dateilager-client\",\n timeout:\n typeof options.timeout === \"number\"\n ? {\n update: options.timeout,\n rebuild: options.timeout,\n gc: options.timeout,\n }\n : {\n update: 0,\n rebuild: 0,\n gc: 0,\n ...options.timeout,\n },\n tracing: options.tracing ?? false,\n logger: options.logger,\n };\n }\n\n /**\n * Update objects in a project based on the differences in a local directory.\n * @param project The id of the project.\n * @param directory The path of the directory to send updates from.\n * @param options Object of options.\n * @param options.timeout Number of milliseconds to wait before terminating the process.\n * @returns The latest project version or `null` if something went wrong.\n */\n public async update(project: bigint, directory: string, options?: { timeout?: number }): Promise<bigint | null> {\n return await trace(\n \"dateilager-binary-client.update\",\n {\n attributes: {\n \"dl.project\": String(project),\n \"dl.directory\": directory,\n },\n },\n async () => {\n const args = [\"--dir\", String(directory), \"--project\", String(project)];\n const result = await this._call(\"update\", args, directory, options);\n\n if (result.stdout == \"-1\") {\n return null;\n }\n\n return BigInt(result.stdout);\n }\n );\n }\n\n /**\n * Rebuild the local filesystem.\n * @param project The id of the project.\n * @param to The version of the project to rebuild the filesystem to.\n * @param directory The path of the directory to rebuild the filesystem at.\n * @param options Object of options.\n * @param options.timeout Number of milliseconds to wait before terminating the process.\n * @param options.ignores The paths to ignore when rebuilding the FS.\n * @param options.summarize Should produce the summary file after rebuilding.\n * @param options.cacheDir Path where the cache directory is mounted.\n * @param options.matchInclude Set fileMatch to true if the written files are matched by this glob pattern\n * @param options.matchExclude Set fileMatch to false if the written files are matched by this glob pattern\n * @returns The latest project version or `null` if something went wrong.\n */\n public async rebuild(\n project: bigint,\n to: bigint | null,\n directory: string,\n options?: {\n timeout?: number;\n ignores?: string[];\n summarize?: boolean;\n cacheDir?: string;\n matchInclude?: string;\n matchExclude?: string;\n }\n ): Promise<RebuildResult> {\n return await trace(\n \"dateilager-binary-client.rebuild\",\n {\n attributes: {\n \"dl.project\": String(project),\n \"dl.to\": String(to),\n \"dl.directory\": directory,\n },\n },\n async () => {\n await fs.mkdir(directory, { recursive: true });\n\n const args = [\"--dir\", directory];\n if (to) {\n args.push(\"--to\", String(to));\n }\n\n if (options?.ignores) {\n args.push(\"--ignores\", options.ignores.join(\",\"));\n }\n\n if (options?.summarize === false) {\n args.push(\"--summarize=false\");\n }\n\n if (options?.cacheDir) {\n args.push(`--cachedir=${options.cacheDir}`);\n }\n\n if (options?.matchInclude) {\n args.push(`--matchinclude=${options.matchInclude}`);\n }\n\n if (options?.matchExclude) {\n args.push(`--matchexclude=${options.matchExclude}`);\n }\n\n args.push(\"--project\", String(project), \"--dir\", directory);\n const result = await this._call(\"rebuild\", args, directory, options);\n const parsed = JSON.parse(result.stdout) as { version: number; count: number; fileMatch: boolean };\n return { version: BigInt(parsed.version), count: parsed.count, fileMatch: parsed.fileMatch };\n }\n );\n }\n\n /**\n * @param sample sample size of cleanup\n * @param keep The amount of records to keep\n * @param from Where to start cleanup\n * @param options dict options passed\n * @param options.timeout timeout limit for the request\n */\n public async gcRandomProjects(sample: number, keep: number, from?: number, options?: { timeout?: number }): Promise<GCResult> {\n return await trace(\n \"dateilager-binary-client.gc\",\n {\n attributes: {\n \"db.mode\": \"random-projects\",\n \"dl.keep\": String(keep),\n \"dl.from\": String(from),\n \"dl.sample\": String(sample),\n },\n },\n async () => {\n const args = [\"--mode\", \"random-projects\", \"--keep\", String(keep), \"--sample\", String(sample)];\n\n if (from) args.push(\"--from\", String(from));\n\n const result = await this._call(\"gc\", args, undefined, options);\n const parsed = JSON.parse(result.stdout) as { count: number };\n return { count: parsed.count };\n }\n );\n }\n\n /**\n *\n * @param project The selected project to cleanup\n * @param keep The amount of records to keep\n * @param from Where to start cleanup\n * @param options dict options passed\n * @param options.timeout timeout limit for the request\n */\n public async gcProject(project: number, keep: number, from?: number, options?: { timeout?: number }): Promise<GCResult> {\n return await trace(\n \"dateilager-binary-client.gc\",\n {\n attributes: {\n \"db.mode\": \"project\",\n \"dl.keep\": String(keep),\n \"dl.from\": String(from),\n },\n },\n async () => {\n const args = [\"--mode\", \"project\", \"--keep\", String(keep), \"--project\", String(project)];\n\n if (from) args.push(\"--from\", String(from));\n\n const result = await this._call(\"gc\", args, undefined, options);\n const parsed = JSON.parse(result.stdout) as { count: number };\n return { count: parsed.count };\n }\n );\n }\n\n /**\n *\n * @param sample sample size of cleanup\n * @param options dict options passed\n * @param options.timeout timeout limit for the request\n */\n public async gcContents(sample: number, options?: { timeout?: number }): Promise<GCResult> {\n return await trace(\n \"dateilager-binary-client.gc\",\n {\n attributes: {\n \"db.mode\": \"contents\",\n \"dl.sample\": String(sample),\n },\n },\n async () => {\n const args = [\"--mode\", \"contents\", \"--sample\", String(sample)];\n\n const result = await this._call(\"gc\", args, undefined, options);\n const parsed = JSON.parse(result.stdout) as { count: number };\n return { count: parsed.count };\n }\n );\n }\n\n /** @internal */\n private async _call(\n method: \"update\" | \"rebuild\" | \"gc\",\n args: string[],\n cwd?: string,\n options?: { timeout?: number }\n ): Promise<ExecaReturnValue> {\n const baseArgs = [method, \"--host\", this._options.host, \"--port\", String(this._options.port), \"--log-encoding\", \"json\"];\n\n if (this._options.logger) {\n baseArgs.push(\"--log-level\", this._options.logger.level);\n }\n\n if (this._options.headlessHost) {\n baseArgs.push(\"--headless-host\", this._options.headlessHost);\n }\n\n const timeout = options?.timeout ?? this._options.timeout[method];\n baseArgs.push(\"--timeout\", String(timeout));\n\n if (this._options.tracing) {\n const carrier = {};\n propagation.inject(context.active(), carrier);\n const otelContext = JSON.stringify(carrier);\n\n baseArgs.push(\"--tracing\", \"--otel-context\", otelContext);\n }\n const subprocess = execa(this._options.command, baseArgs.concat(args), {\n cwd,\n cleanup: false, // don't terminate this subprocess process eagerly when the parent process is terminated, which is execa's default behaviour. we use graceful shutdown gadget-side to give running operations a chance to complete, and we don't want to terminate them prematurely\n env: { DL_TOKEN: await this._options.token() },\n });\n\n if (this._options.logger && subprocess.stderr) {\n readline.createInterface(subprocess.stderr).on(\"line\", (line) => {\n try {\n // we purposefully extract and ignore the `ts` field\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { level, msg, ts, ...fields } = JSON.parse(line) as {\n [key: string]: unknown;\n level: \"debug\" | \"info\" | \"warn\" | \"error\";\n msg: string;\n ts: string | number;\n };\n\n this._options.logger?.log(level, msg, fields);\n } catch (error) {\n this._options.logger?.log(\"warn\", \"failed to log line\", { error, line });\n }\n });\n }\n\n return subprocess;\n }\n}\n"]}
|
|
@@ -26,13 +26,11 @@ export interface DateiLagerGrpcClientOptions {
|
|
|
26
26
|
token: string | (() => Promise<string>);
|
|
27
27
|
/**
|
|
28
28
|
* Options that will be passed to the underlying grpc client constructor.
|
|
29
|
-
*
|
|
30
29
|
* @see ClientOptions
|
|
31
30
|
*/
|
|
32
31
|
grpcClientOptions?: ClientOptions;
|
|
33
32
|
/**
|
|
34
33
|
* Options that will be passed to every remote procedure call.
|
|
35
|
-
*
|
|
36
34
|
* @see RpcOptions
|
|
37
35
|
*/
|
|
38
36
|
rpcOptions?: RpcOptions | (() => RpcOptions | undefined);
|
|
@@ -47,7 +45,6 @@ export declare class DateiLagerGrpcClient {
|
|
|
47
45
|
/**
|
|
48
46
|
* The library used to interact with GRPC creates connections lazily, this constructor will not
|
|
49
47
|
* raise an error even if there is no service running at {@link DateiLagerGrpcClientOptions.server server}.
|
|
50
|
-
*
|
|
51
48
|
* @param options Grpc client options.
|
|
52
49
|
*/
|
|
53
50
|
constructor(options: DateiLagerGrpcClientOptions);
|
|
@@ -57,7 +54,6 @@ export declare class DateiLagerGrpcClient {
|
|
|
57
54
|
close(): void;
|
|
58
55
|
/**
|
|
59
56
|
* Create a new project.
|
|
60
|
-
*
|
|
61
57
|
* @param project The id of the project.
|
|
62
58
|
* @param packPatterns The paths to pack.
|
|
63
59
|
* @param template The id of the project to start from.
|
|
@@ -65,19 +61,17 @@ export declare class DateiLagerGrpcClient {
|
|
|
65
61
|
newProject(project: bigint, packPatterns: string[], template?: bigint): Promise<void>;
|
|
66
62
|
/**
|
|
67
63
|
* Delete a project.
|
|
68
|
-
*
|
|
69
64
|
* @param project The id of the project.
|
|
70
65
|
*/
|
|
71
66
|
deleteProject(project: bigint): Promise<void>;
|
|
72
67
|
/**
|
|
73
68
|
* List objects.
|
|
74
|
-
*
|
|
75
|
-
* @param
|
|
76
|
-
* @param
|
|
77
|
-
* @param
|
|
78
|
-
* @param
|
|
79
|
-
* @
|
|
80
|
-
* @returns A stream of objects.
|
|
69
|
+
* @param project The id of the project.
|
|
70
|
+
* @param path The path to list objects under.
|
|
71
|
+
* @param ignores The paths under {@link path} to ignore.
|
|
72
|
+
* @param from The project version to start from.
|
|
73
|
+
* @param to The project version to end at.
|
|
74
|
+
* @returns A stream of objects.
|
|
81
75
|
* @yields An object from the stream.
|
|
82
76
|
* @example
|
|
83
77
|
* for await (const object of client.listObjects(1n, "")) {
|
|
@@ -88,13 +82,12 @@ export declare class DateiLagerGrpcClient {
|
|
|
88
82
|
listObjects(project: bigint, path: string, ignores?: string[], from?: bigint, to?: bigint): AsyncGenerator<Objekt, void>;
|
|
89
83
|
/**
|
|
90
84
|
* Get objects.
|
|
91
|
-
*
|
|
92
85
|
* @param project The id of the project.
|
|
93
86
|
* @param path The path to get objects under.
|
|
94
87
|
* @param ignores The paths under {@link path} to ignore.
|
|
95
88
|
* @param from The project version to start from.
|
|
96
89
|
* @param to The project version to end at.
|
|
97
|
-
* @returns
|
|
90
|
+
* @returns All the objects under {@link path}.
|
|
98
91
|
* @example
|
|
99
92
|
* const response = await client.getObjects(1n, "");
|
|
100
93
|
* for (const object of response.objects) {
|
|
@@ -105,39 +98,34 @@ export declare class DateiLagerGrpcClient {
|
|
|
105
98
|
getObjects(project: bigint, path: string, ignores?: string[], from?: bigint, to?: bigint): Promise<GetUnaryResponse>;
|
|
106
99
|
/**
|
|
107
100
|
* Get an object.
|
|
108
|
-
*
|
|
109
101
|
* @param project The id of the project.
|
|
110
102
|
* @param path The path of the object.
|
|
111
103
|
* @param from The project version to start from.
|
|
112
104
|
* @param to The project version to end at.
|
|
113
|
-
* @returns
|
|
105
|
+
* @returns The object at the given path or undefined if it does not exist.
|
|
114
106
|
*/
|
|
115
107
|
getObject(project: bigint, path: string, from?: bigint, to?: bigint): Promise<Objekt | undefined>;
|
|
116
108
|
/**
|
|
117
109
|
* Update objects.
|
|
118
|
-
*
|
|
119
110
|
* @param project The id of the project.
|
|
120
|
-
* @returns
|
|
111
|
+
* @returns An {@link UpdateInputStream} to send objects to update.
|
|
121
112
|
*/
|
|
122
113
|
updateObjects(project: bigint): UpdateInputStream;
|
|
123
114
|
/**
|
|
124
115
|
* Update an object.
|
|
125
|
-
*
|
|
126
116
|
* @param project The id of the project.
|
|
127
117
|
* @param obj The object to update.
|
|
128
|
-
* @returns
|
|
118
|
+
* @returns The latest project version or `null` if something went wrong.
|
|
129
119
|
*/
|
|
130
120
|
updateObject(project: bigint, obj: Objekt): Promise<bigint | null>;
|
|
131
121
|
/**
|
|
132
122
|
* Rollback a project.
|
|
133
|
-
*
|
|
134
123
|
* @param project The id of the project.
|
|
135
124
|
* @param version The version to rollback to.
|
|
136
125
|
*/
|
|
137
126
|
rollbackProject(project: bigint, version: bigint): Promise<void>;
|
|
138
127
|
/**
|
|
139
128
|
* Snapshot the current state of the dateilager server.
|
|
140
|
-
*
|
|
141
129
|
* @returns All the projects on the dateilager server.
|
|
142
130
|
* @throws If the dateilager server's DL_ENV environment variable is PROD.
|
|
143
131
|
* @see DateiLagerGrpcClient.resetToSnapshotInDevOrTests
|
|
@@ -146,7 +134,6 @@ export declare class DateiLagerGrpcClient {
|
|
|
146
134
|
/**
|
|
147
135
|
* Reset the given projects to their respective versions and delete any remaining projects.
|
|
148
136
|
* If no projects are provided, delete all projects.
|
|
149
|
-
*
|
|
150
137
|
* @param projects The projects to reset.
|
|
151
138
|
* @throws If the dateilager server's DL_ENV environment variable is PROD.
|
|
152
139
|
* @see DateiLagerGrpcClient.snapshotInDevOrTests
|
|
@@ -156,70 +143,61 @@ export declare class DateiLagerGrpcClient {
|
|
|
156
143
|
* Clones the `source` projects changes (from `fromVersion` up to `toVersion`) to the `target` project.
|
|
157
144
|
* This method assumes that it is always a one way clone from source to target, it does not take into account
|
|
158
145
|
* the changes that have occurred in the `target` project.
|
|
159
|
-
*
|
|
160
146
|
* @param source The source project.
|
|
161
147
|
* @param target The target project.
|
|
162
148
|
* @param version The version of the source project to clone up to.
|
|
163
|
-
* @returns
|
|
149
|
+
* @returns The new version number of the target project.
|
|
164
150
|
*/
|
|
165
151
|
cloneToProject(source: bigint, target: bigint, version: bigint): Promise<CloneToProjectResponse>;
|
|
166
152
|
/**
|
|
167
153
|
* GC project.
|
|
168
|
-
*
|
|
169
154
|
* @param project The project to GC.
|
|
170
155
|
* @param keep The amount of versions since the latest that should be kept.
|
|
171
156
|
* @param from The starting version to GC from.
|
|
172
|
-
* @returns
|
|
157
|
+
* @returns The amount of objects that were GC'd.
|
|
173
158
|
*/
|
|
174
159
|
gcProject(project: bigint, keep: bigint, from?: bigint): Promise<bigint>;
|
|
175
160
|
/**
|
|
176
161
|
* GC random projects.
|
|
177
|
-
*
|
|
178
162
|
* @param sample The percentage of projects to sample from.
|
|
179
163
|
* @param keep The amount of versions since the latest that should be kept.
|
|
180
164
|
* @param from The starting version to GC from.
|
|
181
|
-
* @returns
|
|
165
|
+
* @returns The amount of objects that were GC'd.
|
|
182
166
|
*/
|
|
183
167
|
gcRandomProjects(sample: number, keep: bigint, from?: bigint): Promise<bigint>;
|
|
184
168
|
/**
|
|
185
169
|
* GC contents.
|
|
186
|
-
*
|
|
187
170
|
* @param sample The percentage of projects to sample from.
|
|
188
|
-
* @returns
|
|
171
|
+
* @returns The amount of objects that were GC'd.
|
|
189
172
|
*/
|
|
190
173
|
gcContents(sample: number): Promise<bigint>;
|
|
191
174
|
}
|
|
192
175
|
/**
|
|
193
176
|
* Used to send a stream of objects to update.
|
|
194
|
-
*
|
|
195
177
|
* @see DateiLagerGrpcClient.updateObjects
|
|
196
178
|
*/
|
|
197
179
|
declare class UpdateInputStream {
|
|
198
180
|
constructor(project: bigint, call: ClientStreamingCall<UpdateRequest, UpdateResponse>, span: Span);
|
|
199
181
|
/**
|
|
200
182
|
* Send an object to update.
|
|
201
|
-
*
|
|
202
183
|
* @param obj The object to update.
|
|
203
184
|
*/
|
|
204
185
|
send(obj: Objekt): Promise<void>;
|
|
205
186
|
/**
|
|
206
187
|
* Complete the update request.
|
|
207
|
-
*
|
|
208
188
|
* @returns The latest project version or `null` if something went wrong.
|
|
209
189
|
*/
|
|
210
190
|
complete(): Promise<bigint | null>;
|
|
211
191
|
}
|
|
212
192
|
/**
|
|
213
193
|
* Encode string object contents as an array of bytes.
|
|
214
|
-
*
|
|
215
194
|
* @param content The string to encode.
|
|
216
|
-
* @returns
|
|
195
|
+
* @returns The encoded content as an array of bytes.
|
|
217
196
|
*/
|
|
218
197
|
export declare function encodeContent(content: string): Uint8Array;
|
|
219
198
|
/**
|
|
220
199
|
* Decode an array of bytes as an object's string contents.
|
|
221
|
-
*
|
|
222
200
|
* @param bytes The array of bytes to decode.
|
|
223
|
-
* @returns
|
|
201
|
+
* @returns The bytes decoded into a string.
|
|
224
202
|
*/
|
|
225
203
|
export declare function decodeContent(bytes: Uint8Array | undefined): string;
|
package/dist/cjs/grpc-client.js
CHANGED
|
@@ -19,7 +19,6 @@ class DateiLagerGrpcClient {
|
|
|
19
19
|
/**
|
|
20
20
|
* The library used to interact with GRPC creates connections lazily, this constructor will not
|
|
21
21
|
* raise an error even if there is no service running at {@link DateiLagerGrpcClientOptions.server server}.
|
|
22
|
-
*
|
|
23
22
|
* @param options Grpc client options.
|
|
24
23
|
*/
|
|
25
24
|
constructor(options) {
|
|
@@ -74,7 +73,6 @@ class DateiLagerGrpcClient {
|
|
|
74
73
|
}
|
|
75
74
|
/**
|
|
76
75
|
* Create a new project.
|
|
77
|
-
*
|
|
78
76
|
* @param project The id of the project.
|
|
79
77
|
* @param packPatterns The paths to pack.
|
|
80
78
|
* @param template The id of the project to start from.
|
|
@@ -98,7 +96,6 @@ class DateiLagerGrpcClient {
|
|
|
98
96
|
}
|
|
99
97
|
/**
|
|
100
98
|
* Delete a project.
|
|
101
|
-
*
|
|
102
99
|
* @param project The id of the project.
|
|
103
100
|
*/
|
|
104
101
|
async deleteProject(project) {
|
|
@@ -110,13 +107,12 @@ class DateiLagerGrpcClient {
|
|
|
110
107
|
}
|
|
111
108
|
/**
|
|
112
109
|
* List objects.
|
|
113
|
-
*
|
|
114
|
-
* @param
|
|
115
|
-
* @param
|
|
116
|
-
* @param
|
|
117
|
-
* @param
|
|
118
|
-
* @
|
|
119
|
-
* @returns A stream of objects.
|
|
110
|
+
* @param project The id of the project.
|
|
111
|
+
* @param path The path to list objects under.
|
|
112
|
+
* @param ignores The paths under {@link path} to ignore.
|
|
113
|
+
* @param from The project version to start from.
|
|
114
|
+
* @param to The project version to end at.
|
|
115
|
+
* @returns A stream of objects.
|
|
120
116
|
* @yields An object from the stream.
|
|
121
117
|
* @example
|
|
122
118
|
* for await (const object of client.listObjects(1n, "")) {
|
|
@@ -161,13 +157,12 @@ class DateiLagerGrpcClient {
|
|
|
161
157
|
}
|
|
162
158
|
/**
|
|
163
159
|
* Get objects.
|
|
164
|
-
*
|
|
165
160
|
* @param project The id of the project.
|
|
166
161
|
* @param path The path to get objects under.
|
|
167
162
|
* @param ignores The paths under {@link path} to ignore.
|
|
168
163
|
* @param from The project version to start from.
|
|
169
164
|
* @param to The project version to end at.
|
|
170
|
-
* @returns
|
|
165
|
+
* @returns All the objects under {@link path}.
|
|
171
166
|
* @example
|
|
172
167
|
* const response = await client.getObjects(1n, "");
|
|
173
168
|
* for (const object of response.objects) {
|
|
@@ -191,12 +186,11 @@ class DateiLagerGrpcClient {
|
|
|
191
186
|
}
|
|
192
187
|
/**
|
|
193
188
|
* Get an object.
|
|
194
|
-
*
|
|
195
189
|
* @param project The id of the project.
|
|
196
190
|
* @param path The path of the object.
|
|
197
191
|
* @param from The project version to start from.
|
|
198
192
|
* @param to The project version to end at.
|
|
199
|
-
* @returns
|
|
193
|
+
* @returns The object at the given path or undefined if it does not exist.
|
|
200
194
|
*/
|
|
201
195
|
async getObject(project, path, from, to) {
|
|
202
196
|
return await (0, telemetry_1.trace)("dateilager-grpc-client.get-object", {
|
|
@@ -229,9 +223,8 @@ class DateiLagerGrpcClient {
|
|
|
229
223
|
}
|
|
230
224
|
/**
|
|
231
225
|
* Update objects.
|
|
232
|
-
*
|
|
233
226
|
* @param project The id of the project.
|
|
234
|
-
* @returns
|
|
227
|
+
* @returns An {@link UpdateInputStream} to send objects to update.
|
|
235
228
|
*/
|
|
236
229
|
updateObjects(project) {
|
|
237
230
|
const parentContext = api_1.context.active();
|
|
@@ -245,10 +238,9 @@ class DateiLagerGrpcClient {
|
|
|
245
238
|
}
|
|
246
239
|
/**
|
|
247
240
|
* Update an object.
|
|
248
|
-
*
|
|
249
241
|
* @param project The id of the project.
|
|
250
242
|
* @param obj The object to update.
|
|
251
|
-
* @returns
|
|
243
|
+
* @returns The latest project version or `null` if something went wrong.
|
|
252
244
|
*/
|
|
253
245
|
async updateObject(project, obj) {
|
|
254
246
|
const stream = this.updateObjects(project);
|
|
@@ -257,7 +249,6 @@ class DateiLagerGrpcClient {
|
|
|
257
249
|
}
|
|
258
250
|
/**
|
|
259
251
|
* Rollback a project.
|
|
260
|
-
*
|
|
261
252
|
* @param project The id of the project.
|
|
262
253
|
* @param version The version to rollback to.
|
|
263
254
|
*/
|
|
@@ -266,7 +257,6 @@ class DateiLagerGrpcClient {
|
|
|
266
257
|
}
|
|
267
258
|
/**
|
|
268
259
|
* Snapshot the current state of the dateilager server.
|
|
269
|
-
*
|
|
270
260
|
* @returns All the projects on the dateilager server.
|
|
271
261
|
* @throws If the dateilager server's DL_ENV environment variable is PROD.
|
|
272
262
|
* @see DateiLagerGrpcClient.resetToSnapshotInDevOrTests
|
|
@@ -278,7 +268,6 @@ class DateiLagerGrpcClient {
|
|
|
278
268
|
/**
|
|
279
269
|
* Reset the given projects to their respective versions and delete any remaining projects.
|
|
280
270
|
* If no projects are provided, delete all projects.
|
|
281
|
-
*
|
|
282
271
|
* @param projects The projects to reset.
|
|
283
272
|
* @throws If the dateilager server's DL_ENV environment variable is PROD.
|
|
284
273
|
* @see DateiLagerGrpcClient.snapshotInDevOrTests
|
|
@@ -290,11 +279,10 @@ class DateiLagerGrpcClient {
|
|
|
290
279
|
* Clones the `source` projects changes (from `fromVersion` up to `toVersion`) to the `target` project.
|
|
291
280
|
* This method assumes that it is always a one way clone from source to target, it does not take into account
|
|
292
281
|
* the changes that have occurred in the `target` project.
|
|
293
|
-
*
|
|
294
282
|
* @param source The source project.
|
|
295
283
|
* @param target The target project.
|
|
296
284
|
* @param version The version of the source project to clone up to.
|
|
297
|
-
* @returns
|
|
285
|
+
* @returns The new version number of the target project.
|
|
298
286
|
*/
|
|
299
287
|
async cloneToProject(source, target, version) {
|
|
300
288
|
return await (0, telemetry_1.trace)("dateilager-grpc-client.clone-to-project", {
|
|
@@ -310,11 +298,10 @@ class DateiLagerGrpcClient {
|
|
|
310
298
|
}
|
|
311
299
|
/**
|
|
312
300
|
* GC project.
|
|
313
|
-
*
|
|
314
301
|
* @param project The project to GC.
|
|
315
302
|
* @param keep The amount of versions since the latest that should be kept.
|
|
316
303
|
* @param from The starting version to GC from.
|
|
317
|
-
* @returns
|
|
304
|
+
* @returns The amount of objects that were GC'd.
|
|
318
305
|
*/
|
|
319
306
|
async gcProject(project, keep, from) {
|
|
320
307
|
const call = await this._client.gcProject({
|
|
@@ -326,11 +313,10 @@ class DateiLagerGrpcClient {
|
|
|
326
313
|
}
|
|
327
314
|
/**
|
|
328
315
|
* GC random projects.
|
|
329
|
-
*
|
|
330
316
|
* @param sample The percentage of projects to sample from.
|
|
331
317
|
* @param keep The amount of versions since the latest that should be kept.
|
|
332
318
|
* @param from The starting version to GC from.
|
|
333
|
-
* @returns
|
|
319
|
+
* @returns The amount of objects that were GC'd.
|
|
334
320
|
*/
|
|
335
321
|
async gcRandomProjects(sample, keep, from) {
|
|
336
322
|
const call = await this._client.gcRandomProjects({
|
|
@@ -342,9 +328,8 @@ class DateiLagerGrpcClient {
|
|
|
342
328
|
}
|
|
343
329
|
/**
|
|
344
330
|
* GC contents.
|
|
345
|
-
*
|
|
346
331
|
* @param sample The percentage of projects to sample from.
|
|
347
|
-
* @returns
|
|
332
|
+
* @returns The amount of objects that were GC'd.
|
|
348
333
|
*/
|
|
349
334
|
async gcContents(sample) {
|
|
350
335
|
const call = await this._client.gcContents({
|
|
@@ -356,7 +341,6 @@ class DateiLagerGrpcClient {
|
|
|
356
341
|
exports.DateiLagerGrpcClient = DateiLagerGrpcClient;
|
|
357
342
|
/**
|
|
358
343
|
* Used to send a stream of objects to update.
|
|
359
|
-
*
|
|
360
344
|
* @see DateiLagerGrpcClient.updateObjects
|
|
361
345
|
*/
|
|
362
346
|
class UpdateInputStream {
|
|
@@ -388,7 +372,6 @@ class UpdateInputStream {
|
|
|
388
372
|
}
|
|
389
373
|
/**
|
|
390
374
|
* Send an object to update.
|
|
391
|
-
*
|
|
392
375
|
* @param obj The object to update.
|
|
393
376
|
*/
|
|
394
377
|
async send(obj) {
|
|
@@ -405,7 +388,6 @@ class UpdateInputStream {
|
|
|
405
388
|
}
|
|
406
389
|
/**
|
|
407
390
|
* Complete the update request.
|
|
408
|
-
*
|
|
409
391
|
* @returns The latest project version or `null` if something went wrong.
|
|
410
392
|
*/
|
|
411
393
|
async complete() {
|
|
@@ -422,9 +404,8 @@ class UpdateInputStream {
|
|
|
422
404
|
const encoder = new util_1.TextEncoder();
|
|
423
405
|
/**
|
|
424
406
|
* Encode string object contents as an array of bytes.
|
|
425
|
-
*
|
|
426
407
|
* @param content The string to encode.
|
|
427
|
-
* @returns
|
|
408
|
+
* @returns The encoded content as an array of bytes.
|
|
428
409
|
*/
|
|
429
410
|
function encodeContent(content) {
|
|
430
411
|
return encoder.encode(content);
|
|
@@ -433,9 +414,8 @@ exports.encodeContent = encodeContent;
|
|
|
433
414
|
const decoder = new util_1.TextDecoder();
|
|
434
415
|
/**
|
|
435
416
|
* Decode an array of bytes as an object's string contents.
|
|
436
|
-
*
|
|
437
417
|
* @param bytes The array of bytes to decode.
|
|
438
|
-
* @returns
|
|
418
|
+
* @returns The bytes decoded into a string.
|
|
439
419
|
*/
|
|
440
420
|
function decodeContent(bytes) {
|
|
441
421
|
return decoder.decode(bytes);
|