@gadgetinc/dateilager 0.8.9 → 0.8.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.
@@ -108,14 +108,16 @@ export declare class DateiLagerBinaryClient {
108
108
  constructor(options: DateiLagerBinaryClientOptions);
109
109
  /**
110
110
  * Update objects in a project based on the differences in a local directory.
111
- * @param project The id of the project.
112
- * @param directory The path of the directory to send updates from.
113
- * @param options Object of options.
114
- * @param options.timeout Number of milliseconds to wait before terminating the process.
115
- * @returns The latest project version or `null` if something went wrong.
111
+ * @param project The id of the project.
112
+ * @param directory The path of the directory to send updates from.
113
+ * @param options Object of options.
114
+ * @param options.timeout Number of milliseconds to wait before terminating the process.
115
+ * @param options.subpaths The paths to include when updating the FS.
116
+ * @returns The latest project version or `null` if something went wrong.
116
117
  */
117
118
  update(project: bigint, directory: string, options?: {
118
119
  timeout?: number;
120
+ subpaths?: string[];
119
121
  }): Promise<bigint | null>;
120
122
  /**
121
123
  * Rebuild the local filesystem.
@@ -125,6 +127,7 @@ export declare class DateiLagerBinaryClient {
125
127
  * @param options Object of options.
126
128
  * @param options.timeout Number of milliseconds to wait before terminating the process.
127
129
  * @param options.ignores The paths to ignore when rebuilding the FS.
130
+ * @param options.subpaths The paths to include when rebuilding the FS.
128
131
  * @param options.summarize Should produce the summary file after rebuilding.
129
132
  * @param options.cacheDir Path where the cache directory is mounted.
130
133
  * @param options.matchInclude Set fileMatch to true if the written files are matched by this glob pattern
@@ -134,6 +137,7 @@ export declare class DateiLagerBinaryClient {
134
137
  rebuild(project: bigint, to: bigint | null, directory: string, options?: {
135
138
  timeout?: number;
136
139
  ignores?: string[];
140
+ subpaths?: string[];
137
141
  summarize?: boolean;
138
142
  cacheDir?: string;
139
143
  matchInclude?: string;
@@ -145,6 +149,7 @@ export declare class DateiLagerBinaryClient {
145
149
  * @param from Where to start cleanup
146
150
  * @param options dict options passed
147
151
  * @param options.timeout timeout limit for the request
152
+ * @returns The number of records garbage collected
148
153
  */
149
154
  gcRandomProjects(sample: number, keep: number, from?: number, options?: {
150
155
  timeout?: number;
@@ -156,6 +161,7 @@ export declare class DateiLagerBinaryClient {
156
161
  * @param from Where to start cleanup
157
162
  * @param options dict options passed
158
163
  * @param options.timeout timeout limit for the request
164
+ * @returns The number of records garbage collected
159
165
  */
160
166
  gcProject(project: number, keep: number, from?: number, options?: {
161
167
  timeout?: number;
@@ -165,6 +171,7 @@ export declare class DateiLagerBinaryClient {
165
171
  * @param sample sample size of cleanup
166
172
  * @param options dict options passed
167
173
  * @param options.timeout timeout limit for the request
174
+ * @returns The number of records garbage collected
168
175
  */
169
176
  gcContents(sample: number, options?: {
170
177
  timeout?: number;
@@ -50,11 +50,12 @@ class DateiLagerBinaryClient {
50
50
  }
51
51
  /**
52
52
  * Update objects in a project based on the differences in a local directory.
53
- * @param project The id of the project.
54
- * @param directory The path of the directory to send updates from.
55
- * @param options Object of options.
56
- * @param options.timeout Number of milliseconds to wait before terminating the process.
57
- * @returns The latest project version or `null` if something went wrong.
53
+ * @param project The id of the project.
54
+ * @param directory The path of the directory to send updates from.
55
+ * @param options Object of options.
56
+ * @param options.timeout Number of milliseconds to wait before terminating the process.
57
+ * @param options.subpaths The paths to include when updating the FS.
58
+ * @returns The latest project version or `null` if something went wrong.
58
59
  */
59
60
  async update(project, directory, options) {
60
61
  return await (0, telemetry_1.trace)("dateilager-binary-client.update", {
@@ -64,6 +65,9 @@ class DateiLagerBinaryClient {
64
65
  },
65
66
  }, async () => {
66
67
  const args = ["--dir", String(directory), "--project", String(project)];
68
+ if (options?.subpaths) {
69
+ args.push(`--subpaths=${options.subpaths.join(",")}`);
70
+ }
67
71
  const result = await this._call("update", args, directory, options);
68
72
  if (result.stdout == "-1") {
69
73
  return null;
@@ -79,6 +83,7 @@ class DateiLagerBinaryClient {
79
83
  * @param options Object of options.
80
84
  * @param options.timeout Number of milliseconds to wait before terminating the process.
81
85
  * @param options.ignores The paths to ignore when rebuilding the FS.
86
+ * @param options.subpaths The paths to include when rebuilding the FS.
82
87
  * @param options.summarize Should produce the summary file after rebuilding.
83
88
  * @param options.cacheDir Path where the cache directory is mounted.
84
89
  * @param options.matchInclude Set fileMatch to true if the written files are matched by this glob pattern
@@ -113,6 +118,9 @@ class DateiLagerBinaryClient {
113
118
  if (options?.matchExclude) {
114
119
  args.push(`--matchexclude=${options.matchExclude}`);
115
120
  }
121
+ if (options?.subpaths) {
122
+ args.push(`--subpaths=${options.subpaths.join(",")}`);
123
+ }
116
124
  args.push("--project", String(project), "--dir", directory);
117
125
  const result = await this._call("rebuild", args, directory, options);
118
126
  const parsed = JSON.parse(result.stdout);
@@ -125,6 +133,7 @@ class DateiLagerBinaryClient {
125
133
  * @param from Where to start cleanup
126
134
  * @param options dict options passed
127
135
  * @param options.timeout timeout limit for the request
136
+ * @returns The number of records garbage collected
128
137
  */
129
138
  async gcRandomProjects(sample, keep, from, options) {
130
139
  return await (0, telemetry_1.trace)("dateilager-binary-client.gc", {
@@ -150,6 +159,7 @@ class DateiLagerBinaryClient {
150
159
  * @param from Where to start cleanup
151
160
  * @param options dict options passed
152
161
  * @param options.timeout timeout limit for the request
162
+ * @returns The number of records garbage collected
153
163
  */
154
164
  async gcProject(project, keep, from, options) {
155
165
  return await (0, telemetry_1.trace)("dateilager-binary-client.gc", {
@@ -172,6 +182,7 @@ class DateiLagerBinaryClient {
172
182
  * @param sample sample size of cleanup
173
183
  * @param options dict options passed
174
184
  * @param options.timeout timeout limit for the request
185
+ * @returns The number of records garbage collected
175
186
  */
176
187
  async gcContents(sample, options) {
177
188
  return await (0, telemetry_1.trace)("dateilager-binary-client.gc", {
@@ -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;AAmH7C;;;;GAIG;AACH,MAAa,sBAAsB;IAIjC;;OAEG;I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I,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"]}
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;QAM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e,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;AA9RD,wDA8RC","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 * @param options.subpaths The paths to include when updating the FS.\n * @returns The latest project version or `null` if something went wrong.\n */\n public async update(project: bigint, directory: string, options?: { timeout?: number; subpaths?: string[] }): 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 if (options?.subpaths) {\n args.push(`--subpaths=${options.subpaths.join(\",\")}`);\n }\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.subpaths The paths to include 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 subpaths?: 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 if (options?.subpaths) {\n args.push(`--subpaths=${options.subpaths.join(\",\")}`);\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 * @returns The number of records garbage collected\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 * @returns The number of records garbage collected\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 * @returns The number of records garbage collected\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"]}
@@ -141,6 +141,7 @@ class DateiLagerGrpcClient {
141
141
  path,
142
142
  ignores,
143
143
  isPrefix: true,
144
+ subpaths: [],
144
145
  },
145
146
  ],
146
147
  }, this._rpcOptions()));
@@ -180,7 +181,7 @@ class DateiLagerGrpcClient {
180
181
  "dl.to_version": String(to),
181
182
  },
182
183
  }, async () => {
183
- const call = this._client.getUnary({ project, fromVersion: from, toVersion: to, queries: [{ path, ignores, isPrefix: true }] }, this._rpcOptions());
184
+ const call = this._client.getUnary({ project, fromVersion: from, toVersion: to, queries: [{ path, ignores, isPrefix: true, subpaths: [] }] }, this._rpcOptions());
184
185
  return await call.response;
185
186
  });
186
187
  }
@@ -210,6 +211,7 @@ class DateiLagerGrpcClient {
210
211
  path,
211
212
  isPrefix: false,
212
213
  ignores: [],
214
+ subpaths: [],
213
215
  },
214
216
  ],
215
217
  }, this._rpcOptions());
@@ -1 +1 @@
1
- {"version":3,"file":"grpc-client.js","sourceRoot":"","sources":["../../src/grpc-client.ts"],"names":[],"mappings":";;;AACA,2CAA0E;AAE1E,4CAA8E;AAC9E,gEAA4D;AAC5D,0DAA+F;AAC/F,+BAAgD;AAChD,oDAAqD;AAErD,oDAA6C;AAC7C,2CAA2D;AA0C3D;;;;;GAKG;AACH,MAAa,oBAAoB;IAU/B;;;;OAIG;IACH,YAAmB,OAAoC;QAdvD,gBAAgB;QACC;;;;;WAAkB;QAEnC,gBAAgB;QACC;;;;;WAA0B;QAE3C,gBAAgB;QACC;;;;;WAA0C;QAQzD,MAAM,OAAO,GAAG,OAAO,OAAO,CAA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AAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC3C,OAAO,QAAQ,CAAC,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;QAC3D,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AAED,MAAM,OAAO,GAAG,IAAI,kBAAW,EAAE,CAAC;AAElC;;;;GAIG;AACH,SAAgB,aAAa,CAAC,OAAe;IAC3C,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAFD,sCAEC;AAED,MAAM,OAAO,GAAG,IAAI,kBAAW,EAAE,CAAC;AAElC;;;;GAIG;AACH,SAAgB,aAAa,CAAC,KAA6B;IACzD,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAFD,sCAEC","sourcesContent":["import type { ClientOptions } from \"@grpc/grpc-js\";\nimport { ChannelCredentials, credentials, Metadata } from \"@grpc/grpc-js\";\nimport type { Span } from \"@opentelemetry/api\";\nimport { context as contextAPI, trace as traceAPI } from \"@opentelemetry/api\";\nimport { GrpcTransport } from \"@protobuf-ts/grpc-transport\";\nimport { RpcError, type ClientStreamingCall, type RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport { TextDecoder, TextEncoder } from \"util\";\nimport { trace, tracer } from \"./internal/telemetry\";\nimport type { CloneToProjectResponse, GetUnaryResponse, Objekt, Project, UpdateRequest, UpdateResponse } from \"./pb/fs_pb\";\nimport { FsClient } from \"./pb/fs_pb.client\";\nimport { ProjectAlreadyExistsError } from \"./utils/errors\";\nexport type { Objekt, Project };\n\n/**\n * Options for {@link DateiLagerGrpcClient}.\n */\nexport interface DateiLagerGrpcClientOptions {\n /**\n * The address of the dateilager server.\n */\n server:\n | string\n | {\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 /**\n * The token that will be sent as authorization metadata to the dateilager server.\n */\n token: string | (() => Promise<string>);\n\n /**\n * Options that will be passed to the underlying grpc client constructor.\n * @see ClientOptions\n */\n grpcClientOptions?: ClientOptions;\n\n /**\n * Options that will be passed to every remote procedure call.\n * @see RpcOptions\n */\n rpcOptions?: RpcOptions | (() => RpcOptions | undefined);\n}\n\n/**\n * A client class for interacting with DateiLager's GRPC API.\n *\n * The DateiLager API surface area is as minimal as possible;\n * convenience functions, such as getObject, should be implemented within the client.\n */\nexport class DateiLagerGrpcClient {\n /** @internal */\n private readonly _client: FsClient;\n\n /** @internal */\n private readonly _transport: GrpcTransport;\n\n /** @internal */\n private readonly _rpcOptions: () => RpcOptions | undefined;\n\n /**\n * The library used to interact with GRPC creates connections lazily, this constructor will not\n * raise an error even if there is no service running at {@link DateiLagerGrpcClientOptions.server server}.\n * @param options Grpc client options.\n */\n public constructor(options: DateiLagerGrpcClientOptions) {\n const tokenFn = typeof options.token === \"string\" ? () => Promise.resolve(options.token as string) : options.token;\n\n this._transport = new GrpcTransport({\n host: typeof options.server === \"string\" ? options.server : `${options.server.host}:${options.server.port}`,\n channelCredentials: credentials.combineChannelCredentials(\n ChannelCredentials.createSsl(),\n credentials.createFromMetadataGenerator((_, callback) => {\n tokenFn()\n .then((token) => {\n const meta = new Metadata();\n meta.add(\"authorization\", `Bearer ${token}`);\n callback(null, meta);\n })\n .catch(callback);\n })\n ),\n clientOptions: {\n \"grpc.keepalive_time_ms\": 5_000,\n \"grpc.keepalive_timeout_ms\": 1_000,\n \"grpc.keepalive_permit_without_calls\": 1,\n ...options.grpcClientOptions,\n },\n });\n\n this._client = new FsClient(this._transport);\n\n this._rpcOptions = options.rpcOptions instanceof Function ? options.rpcOptions : () => options.rpcOptions as RpcOptions | undefined;\n }\n\n /**\n * Close the underlying GRPC client.\n */\n public close(): void {\n this._transport.close();\n }\n\n /**\n * Create a new project.\n * @param project The id of the project.\n * @param packPatterns The paths to pack.\n * @param template The id of the project to start from.\n */\n public async newProject(project: bigint, packPatterns: string[], template?: bigint): Promise<void> {\n try {\n await trace(\n \"dateilager-grpc-client.new-project\",\n {\n attributes: {\n \"dl.project\": String(project),\n \"dl.pack_patterns\": packPatterns,\n \"dl.template\": String(template),\n },\n },\n () => this._client.newProject({ id: project, packPatterns, template }, this._rpcOptions())\n );\n } catch (error) {\n if (error instanceof RpcError && error.code == \"ALREADY_EXISTS\") {\n throw new ProjectAlreadyExistsError(`project id ${project} already exists`);\n }\n throw error;\n }\n }\n\n /**\n * Delete a project.\n * @param project The id of the project.\n */\n public async deleteProject(project: bigint): Promise<void> {\n await trace(\n \"dateilager-grpc-client.delete-project\",\n {\n attributes: {\n \"dl.project\": String(project),\n },\n },\n () => this._client.deleteProject({ project }, this._rpcOptions())\n );\n }\n\n /**\n * List objects.\n * @param project The id of the project.\n * @param path The path to list objects under.\n * @param ignores The paths under {@link path} to ignore.\n * @param from The project version to start from.\n * @param to The project version to end at.\n * @returns A stream of objects.\n * @yields An object from the stream.\n * @example\n * for await (const object of client.listObjects(1n, \"\")) {\n * console.log(\"[listObjects] path: \" + object.path);\n * console.log(\"[listObjects] content:\\n\" + object.content);\n * }\n */\n public async *listObjects(\n project: bigint,\n path: string,\n ignores: string[] = [],\n from?: bigint,\n to?: bigint\n ): AsyncGenerator<Objekt, void> {\n const parentContext = contextAPI.active();\n const span = tracer.startSpan(\n \"dateilager-grpc-client.list-objects\",\n {\n attributes: {\n \"dl.project\": String(project),\n \"dl.path\": path,\n \"dl.ignores\": ignores,\n \"dl.from_version\": String(from),\n \"dl.to_version\": String(to),\n },\n },\n parentContext\n );\n\n try {\n const call = contextAPI.with(traceAPI.setSpan(parentContext, span), () =>\n this._client.get(\n {\n project,\n fromVersion: from,\n toVersion: to,\n queries: [\n {\n path,\n ignores,\n isPrefix: true,\n },\n ],\n },\n this._rpcOptions()\n )\n );\n\n for await (const response of call.responses) {\n if (response.object) {\n yield response.object;\n }\n }\n\n await call.status;\n } finally {\n span.end();\n }\n }\n\n /**\n * Get objects.\n * @param project The id of the project.\n * @param path The path to get objects under.\n * @param ignores The paths under {@link path} to ignore.\n * @param from The project version to start from.\n * @param to The project version to end at.\n * @returns All the objects under {@link path}.\n * @example\n * const response = await client.getObjects(1n, \"\");\n * for (const object of response.objects) {\n * console.log(\"[getObjects] path: \" + object.path);\n * console.log(\"[getObjects] content:\\n\" + object.content);\n * }\n */\n public async getObjects(project: bigint, path: string, ignores: string[] = [], from?: bigint, to?: bigint): Promise<GetUnaryResponse> {\n return await trace(\n \"dateilager-grpc-client.get-unary\",\n {\n attributes: {\n \"dl.project\": String(project),\n \"dl.path\": path,\n \"dl.ignores\": ignores,\n \"dl.from_version\": String(from),\n \"dl.to_version\": String(to),\n },\n },\n async () => {\n const call = this._client.getUnary(\n { project, fromVersion: from, toVersion: to, queries: [{ path, ignores, isPrefix: true }] },\n this._rpcOptions()\n );\n return await call.response;\n }\n );\n }\n\n /**\n * Get an object.\n * @param project The id of the project.\n * @param path The path of the object.\n * @param from The project version to start from.\n * @param to The project version to end at.\n * @returns The object at the given path or undefined if it does not exist.\n */\n public async getObject(project: bigint, path: string, from?: bigint, to?: bigint): Promise<Objekt | undefined> {\n return await trace(\n \"dateilager-grpc-client.get-object\",\n {\n attributes: {\n \"dl.project\": String(project),\n \"dl.path\": path,\n \"dl.from_version\": String(from),\n \"dl.to_version\": String(to),\n },\n },\n async () => {\n const call = this._client.get(\n {\n project,\n fromVersion: from,\n toVersion: to,\n queries: [\n {\n path,\n isPrefix: false,\n ignores: [],\n },\n ],\n },\n this._rpcOptions()\n );\n\n let object: Objekt | undefined;\n for await (const response of call.responses) {\n object = response.object;\n }\n\n await call.status;\n\n return object;\n }\n );\n }\n\n /**\n * Update objects.\n * @param project The id of the project.\n * @returns An {@link UpdateInputStream} to send objects to update.\n */\n public updateObjects(project: bigint): UpdateInputStream {\n const parentContext = contextAPI.active();\n const span = tracer.startSpan(\n \"dateilager-grpc-client.update-objects\",\n {\n attributes: {\n \"dl.project\": String(project),\n },\n },\n parentContext\n );\n\n const call = contextAPI.with(traceAPI.setSpan(parentContext, span), () => this._client.update(this._rpcOptions()));\n\n return new UpdateInputStream(project, call, span);\n }\n\n /**\n * Update an object.\n * @param project The id of the project.\n * @param obj The object to update.\n * @returns The latest project version or `null` if something went wrong.\n */\n public async updateObject(project: bigint, obj: Objekt): Promise<bigint | null> {\n const stream = this.updateObjects(project);\n await stream.send(obj);\n return await stream.complete();\n }\n\n /**\n * Rollback a project.\n * @param project The id of the project.\n * @param version The version to rollback to.\n */\n public async rollbackProject(project: bigint, version: bigint): Promise<void> {\n await this._client.rollback({ project, version }, this._rpcOptions());\n }\n\n /**\n * Snapshot the current state of the dateilager server.\n * @returns All the projects on the dateilager server.\n * @throws If the dateilager server's DL_ENV environment variable is PROD.\n * @see DateiLagerGrpcClient.resetToSnapshotInDevOrTests\n */\n public async snapshotInDevOrTests(): Promise<Project[]> {\n const call = await this._client.snapshot({}, this._rpcOptions());\n return call.response.projects;\n }\n\n /**\n * Reset the given projects to their respective versions and delete any remaining projects.\n * If no projects are provided, delete all projects.\n * @param projects The projects to reset.\n * @throws If the dateilager server's DL_ENV environment variable is PROD.\n * @see DateiLagerGrpcClient.snapshotInDevOrTests\n */\n public async resetToSnapshotInDevOrTests(projects: Project[]): Promise<void> {\n await this._client.reset({ projects }, this._rpcOptions());\n }\n\n /**\n * Clones the `source` projects changes (from `fromVersion` up to `toVersion`) to the `target` project.\n * This method assumes that it is always a one way clone from source to target, it does not take into account\n * the changes that have occurred in the `target` project.\n * @param source The source project.\n * @param target The target project.\n * @param version The version of the source project to clone up to.\n * @returns The new version number of the target project.\n */\n public async cloneToProject(source: bigint, target: bigint, version: bigint): Promise<CloneToProjectResponse> {\n return await trace(\n \"dateilager-grpc-client.clone-to-project\",\n {\n attributes: {\n \"dl.source\": String(source),\n \"dl.target\": String(target),\n \"dl.version\": String(version),\n },\n },\n async () => {\n const call = await this._client.cloneToProject({ source, target, version }, this._rpcOptions());\n return call.response;\n }\n );\n }\n\n /**\n * GC project.\n * @param project The project to GC.\n * @param keep The amount of versions since the latest that should be kept.\n * @param from The starting version to GC from.\n * @returns The amount of objects that were GC'd.\n */\n public async gcProject(project: bigint, keep: bigint, from?: bigint): Promise<bigint> {\n const call = await this._client.gcProject({\n project: project,\n keepVersions: keep,\n fromVersion: from,\n });\n return call.response.count;\n }\n\n /**\n * GC random projects.\n * @param sample The percentage of projects to sample from.\n * @param keep The amount of versions since the latest that should be kept.\n * @param from The starting version to GC from.\n * @returns The amount of objects that were GC'd.\n */\n public async gcRandomProjects(sample: number, keep: bigint, from?: bigint): Promise<bigint> {\n const call = await this._client.gcRandomProjects({\n sample: sample,\n keepVersions: keep,\n fromVersion: from,\n });\n return call.response.count;\n }\n\n /**\n * GC contents.\n * @param sample The percentage of projects to sample from.\n * @returns The amount of objects that were GC'd.\n */\n public async gcContents(sample: number): Promise<bigint> {\n const call = await this._client.gcContents({\n sample: sample,\n });\n return call.response.count;\n }\n}\n\n/**\n * Used to send a stream of objects to update.\n * @see DateiLagerGrpcClient.updateObjects\n */\nclass UpdateInputStream {\n /** @internal */\n private readonly _project: bigint;\n\n /** @internal */\n private readonly _call: ClientStreamingCall<UpdateRequest, UpdateResponse>;\n\n /** @internal */\n private readonly _span: Span;\n\n public constructor(project: bigint, call: ClientStreamingCall<UpdateRequest, UpdateResponse>, span: Span) {\n this._project = project;\n this._call = call;\n this._span = span;\n }\n\n /**\n * Send an object to update.\n * @param obj The object to update.\n */\n public async send(obj: Objekt): Promise<void> {\n try {\n await this._call.requests.send({\n project: this._project,\n object: obj,\n });\n } catch (err) {\n this._span.end();\n throw err;\n }\n }\n\n /**\n * Complete the update request.\n * @returns The latest project version or `null` if something went wrong.\n */\n public async complete(): Promise<bigint | null> {\n try {\n await this._call.requests.complete();\n const response = await this._call.response;\n return response.version != -1n ? response.version : null;\n } finally {\n this._span.end();\n }\n }\n}\n\nconst encoder = new TextEncoder();\n\n/**\n * Encode string object contents as an array of bytes.\n * @param content The string to encode.\n * @returns The encoded content as an array of bytes.\n */\nexport function encodeContent(content: string): Uint8Array {\n return encoder.encode(content);\n}\n\nconst decoder = new TextDecoder();\n\n/**\n * Decode an array of bytes as an object's string contents.\n * @param bytes The array of bytes to decode.\n * @returns The bytes decoded into a string.\n */\nexport function decodeContent(bytes: Uint8Array | undefined): string {\n return decoder.decode(bytes);\n}\n"]}
1
+ {"version":3,"file":"grpc-client.js","sourceRoot":"","sources":["../../src/grpc-client.ts"],"names":[],"mappings":";;;AACA,2CAA0E;AAE1E,4CAA8E;AAC9E,gEAA4D;AAC5D,0DAA+F;AAC/F,+BAAgD;AAChD,oDAAqD;AAErD,oDAA6C;AAC7C,2CAA2D;AA0C3D;;;;;GAKG;AACH,MAAa,oBAAoB;IAU/B;;;;OAIG;IACH,YAAmB,OAAoC;QAdvD,gBAAgB;QACC;;;;;WAAkB;QAEnC,gBAAgB;QACC;;;;;WAA0B;QAE3C,gBAAgB;QACC;;;;;WAA0C;QAQzD,MAAM,OAAO,GAAG,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,CAAC;QAEnH,IAAI,CAAC,UAAU,GAAG,IAAI,8BAAa,CAAC;YAClC,IAAI,EAAE,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE;YAC3G,kBAAkB,EAAE,qBAAW,CAAC,yBAAyB,CACvD,4BAAkB,CAAC,SAAS,EAAE,EAC9B,qBAAW,CAAC,2BAA2B,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE;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AAM,OAAO,GAAG,IAAI,kBAAW,EAAE,CAAC;AAElC;;;;GAIG;AACH,SAAgB,aAAa,CAAC,KAA6B;IACzD,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAFD,sCAEC","sourcesContent":["import type { ClientOptions } from \"@grpc/grpc-js\";\nimport { ChannelCredentials, credentials, Metadata } from \"@grpc/grpc-js\";\nimport type { Span } from \"@opentelemetry/api\";\nimport { context as contextAPI, trace as traceAPI } from \"@opentelemetry/api\";\nimport { GrpcTransport } from \"@protobuf-ts/grpc-transport\";\nimport { RpcError, type ClientStreamingCall, type RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport { TextDecoder, TextEncoder } from \"util\";\nimport { trace, tracer } from \"./internal/telemetry\";\nimport type { CloneToProjectResponse, GetUnaryResponse, Objekt, Project, UpdateRequest, UpdateResponse } from \"./pb/fs_pb\";\nimport { FsClient } from \"./pb/fs_pb.client\";\nimport { ProjectAlreadyExistsError } from \"./utils/errors\";\nexport type { Objekt, Project };\n\n/**\n * Options for {@link DateiLagerGrpcClient}.\n */\nexport interface DateiLagerGrpcClientOptions {\n /**\n * The address of the dateilager server.\n */\n server:\n | string\n | {\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 /**\n * The token that will be sent as authorization metadata to the dateilager server.\n */\n token: string | (() => Promise<string>);\n\n /**\n * Options that will be passed to the underlying grpc client constructor.\n * @see ClientOptions\n */\n grpcClientOptions?: ClientOptions;\n\n /**\n * Options that will be passed to every remote procedure call.\n * @see RpcOptions\n */\n rpcOptions?: RpcOptions | (() => RpcOptions | undefined);\n}\n\n/**\n * A client class for interacting with DateiLager's GRPC API.\n *\n * The DateiLager API surface area is as minimal as possible;\n * convenience functions, such as getObject, should be implemented within the client.\n */\nexport class DateiLagerGrpcClient {\n /** @internal */\n private readonly _client: FsClient;\n\n /** @internal */\n private readonly _transport: GrpcTransport;\n\n /** @internal */\n private readonly _rpcOptions: () => RpcOptions | undefined;\n\n /**\n * The library used to interact with GRPC creates connections lazily, this constructor will not\n * raise an error even if there is no service running at {@link DateiLagerGrpcClientOptions.server server}.\n * @param options Grpc client options.\n */\n public constructor(options: DateiLagerGrpcClientOptions) {\n const tokenFn = typeof options.token === \"string\" ? () => Promise.resolve(options.token as string) : options.token;\n\n this._transport = new GrpcTransport({\n host: typeof options.server === \"string\" ? options.server : `${options.server.host}:${options.server.port}`,\n channelCredentials: credentials.combineChannelCredentials(\n ChannelCredentials.createSsl(),\n credentials.createFromMetadataGenerator((_, callback) => {\n tokenFn()\n .then((token) => {\n const meta = new Metadata();\n meta.add(\"authorization\", `Bearer ${token}`);\n callback(null, meta);\n })\n .catch(callback);\n })\n ),\n clientOptions: {\n \"grpc.keepalive_time_ms\": 5_000,\n \"grpc.keepalive_timeout_ms\": 1_000,\n \"grpc.keepalive_permit_without_calls\": 1,\n ...options.grpcClientOptions,\n },\n });\n\n this._client = new FsClient(this._transport);\n\n this._rpcOptions = options.rpcOptions instanceof Function ? options.rpcOptions : () => options.rpcOptions as RpcOptions | undefined;\n }\n\n /**\n * Close the underlying GRPC client.\n */\n public close(): void {\n this._transport.close();\n }\n\n /**\n * Create a new project.\n * @param project The id of the project.\n * @param packPatterns The paths to pack.\n * @param template The id of the project to start from.\n */\n public async newProject(project: bigint, packPatterns: string[], template?: bigint): Promise<void> {\n try {\n await trace(\n \"dateilager-grpc-client.new-project\",\n {\n attributes: {\n \"dl.project\": String(project),\n \"dl.pack_patterns\": packPatterns,\n \"dl.template\": String(template),\n },\n },\n () => this._client.newProject({ id: project, packPatterns, template }, this._rpcOptions())\n );\n } catch (error) {\n if (error instanceof RpcError && error.code == \"ALREADY_EXISTS\") {\n throw new ProjectAlreadyExistsError(`project id ${project} already exists`);\n }\n throw error;\n }\n }\n\n /**\n * Delete a project.\n * @param project The id of the project.\n */\n public async deleteProject(project: bigint): Promise<void> {\n await trace(\n \"dateilager-grpc-client.delete-project\",\n {\n attributes: {\n \"dl.project\": String(project),\n },\n },\n () => this._client.deleteProject({ project }, this._rpcOptions())\n );\n }\n\n /**\n * List objects.\n * @param project The id of the project.\n * @param path The path to list objects under.\n * @param ignores The paths under {@link path} to ignore.\n * @param from The project version to start from.\n * @param to The project version to end at.\n * @returns A stream of objects.\n * @yields An object from the stream.\n * @example\n * for await (const object of client.listObjects(1n, \"\")) {\n * console.log(\"[listObjects] path: \" + object.path);\n * console.log(\"[listObjects] content:\\n\" + object.content);\n * }\n */\n public async *listObjects(\n project: bigint,\n path: string,\n ignores: string[] = [],\n from?: bigint,\n to?: bigint\n ): AsyncGenerator<Objekt, void> {\n const parentContext = contextAPI.active();\n const span = tracer.startSpan(\n \"dateilager-grpc-client.list-objects\",\n {\n attributes: {\n \"dl.project\": String(project),\n \"dl.path\": path,\n \"dl.ignores\": ignores,\n \"dl.from_version\": String(from),\n \"dl.to_version\": String(to),\n },\n },\n parentContext\n );\n\n try {\n const call = contextAPI.with(traceAPI.setSpan(parentContext, span), () =>\n this._client.get(\n {\n project,\n fromVersion: from,\n toVersion: to,\n queries: [\n {\n path,\n ignores,\n isPrefix: true,\n subpaths: [],\n },\n ],\n },\n this._rpcOptions()\n )\n );\n\n for await (const response of call.responses) {\n if (response.object) {\n yield response.object;\n }\n }\n\n await call.status;\n } finally {\n span.end();\n }\n }\n\n /**\n * Get objects.\n * @param project The id of the project.\n * @param path The path to get objects under.\n * @param ignores The paths under {@link path} to ignore.\n * @param from The project version to start from.\n * @param to The project version to end at.\n * @returns All the objects under {@link path}.\n * @example\n * const response = await client.getObjects(1n, \"\");\n * for (const object of response.objects) {\n * console.log(\"[getObjects] path: \" + object.path);\n * console.log(\"[getObjects] content:\\n\" + object.content);\n * }\n */\n public async getObjects(project: bigint, path: string, ignores: string[] = [], from?: bigint, to?: bigint): Promise<GetUnaryResponse> {\n return await trace(\n \"dateilager-grpc-client.get-unary\",\n {\n attributes: {\n \"dl.project\": String(project),\n \"dl.path\": path,\n \"dl.ignores\": ignores,\n \"dl.from_version\": String(from),\n \"dl.to_version\": String(to),\n },\n },\n async () => {\n const call = this._client.getUnary(\n { project, fromVersion: from, toVersion: to, queries: [{ path, ignores, isPrefix: true, subpaths: [] }] },\n this._rpcOptions()\n );\n return await call.response;\n }\n );\n }\n\n /**\n * Get an object.\n * @param project The id of the project.\n * @param path The path of the object.\n * @param from The project version to start from.\n * @param to The project version to end at.\n * @returns The object at the given path or undefined if it does not exist.\n */\n public async getObject(project: bigint, path: string, from?: bigint, to?: bigint): Promise<Objekt | undefined> {\n return await trace(\n \"dateilager-grpc-client.get-object\",\n {\n attributes: {\n \"dl.project\": String(project),\n \"dl.path\": path,\n \"dl.from_version\": String(from),\n \"dl.to_version\": String(to),\n },\n },\n async () => {\n const call = this._client.get(\n {\n project,\n fromVersion: from,\n toVersion: to,\n queries: [\n {\n path,\n isPrefix: false,\n ignores: [],\n subpaths: [],\n },\n ],\n },\n this._rpcOptions()\n );\n\n let object: Objekt | undefined;\n for await (const response of call.responses) {\n object = response.object;\n }\n\n await call.status;\n\n return object;\n }\n );\n }\n\n /**\n * Update objects.\n * @param project The id of the project.\n * @returns An {@link UpdateInputStream} to send objects to update.\n */\n public updateObjects(project: bigint): UpdateInputStream {\n const parentContext = contextAPI.active();\n const span = tracer.startSpan(\n \"dateilager-grpc-client.update-objects\",\n {\n attributes: {\n \"dl.project\": String(project),\n },\n },\n parentContext\n );\n\n const call = contextAPI.with(traceAPI.setSpan(parentContext, span), () => this._client.update(this._rpcOptions()));\n\n return new UpdateInputStream(project, call, span);\n }\n\n /**\n * Update an object.\n * @param project The id of the project.\n * @param obj The object to update.\n * @returns The latest project version or `null` if something went wrong.\n */\n public async updateObject(project: bigint, obj: Objekt): Promise<bigint | null> {\n const stream = this.updateObjects(project);\n await stream.send(obj);\n return await stream.complete();\n }\n\n /**\n * Rollback a project.\n * @param project The id of the project.\n * @param version The version to rollback to.\n */\n public async rollbackProject(project: bigint, version: bigint): Promise<void> {\n await this._client.rollback({ project, version }, this._rpcOptions());\n }\n\n /**\n * Snapshot the current state of the dateilager server.\n * @returns All the projects on the dateilager server.\n * @throws If the dateilager server's DL_ENV environment variable is PROD.\n * @see DateiLagerGrpcClient.resetToSnapshotInDevOrTests\n */\n public async snapshotInDevOrTests(): Promise<Project[]> {\n const call = await this._client.snapshot({}, this._rpcOptions());\n return call.response.projects;\n }\n\n /**\n * Reset the given projects to their respective versions and delete any remaining projects.\n * If no projects are provided, delete all projects.\n * @param projects The projects to reset.\n * @throws If the dateilager server's DL_ENV environment variable is PROD.\n * @see DateiLagerGrpcClient.snapshotInDevOrTests\n */\n public async resetToSnapshotInDevOrTests(projects: Project[]): Promise<void> {\n await this._client.reset({ projects }, this._rpcOptions());\n }\n\n /**\n * Clones the `source` projects changes (from `fromVersion` up to `toVersion`) to the `target` project.\n * This method assumes that it is always a one way clone from source to target, it does not take into account\n * the changes that have occurred in the `target` project.\n * @param source The source project.\n * @param target The target project.\n * @param version The version of the source project to clone up to.\n * @returns The new version number of the target project.\n */\n public async cloneToProject(source: bigint, target: bigint, version: bigint): Promise<CloneToProjectResponse> {\n return await trace(\n \"dateilager-grpc-client.clone-to-project\",\n {\n attributes: {\n \"dl.source\": String(source),\n \"dl.target\": String(target),\n \"dl.version\": String(version),\n },\n },\n async () => {\n const call = await this._client.cloneToProject({ source, target, version }, this._rpcOptions());\n return call.response;\n }\n );\n }\n\n /**\n * GC project.\n * @param project The project to GC.\n * @param keep The amount of versions since the latest that should be kept.\n * @param from The starting version to GC from.\n * @returns The amount of objects that were GC'd.\n */\n public async gcProject(project: bigint, keep: bigint, from?: bigint): Promise<bigint> {\n const call = await this._client.gcProject({\n project: project,\n keepVersions: keep,\n fromVersion: from,\n });\n return call.response.count;\n }\n\n /**\n * GC random projects.\n * @param sample The percentage of projects to sample from.\n * @param keep The amount of versions since the latest that should be kept.\n * @param from The starting version to GC from.\n * @returns The amount of objects that were GC'd.\n */\n public async gcRandomProjects(sample: number, keep: bigint, from?: bigint): Promise<bigint> {\n const call = await this._client.gcRandomProjects({\n sample: sample,\n keepVersions: keep,\n fromVersion: from,\n });\n return call.response.count;\n }\n\n /**\n * GC contents.\n * @param sample The percentage of projects to sample from.\n * @returns The amount of objects that were GC'd.\n */\n public async gcContents(sample: number): Promise<bigint> {\n const call = await this._client.gcContents({\n sample: sample,\n });\n return call.response.count;\n }\n}\n\n/**\n * Used to send a stream of objects to update.\n * @see DateiLagerGrpcClient.updateObjects\n */\nclass UpdateInputStream {\n /** @internal */\n private readonly _project: bigint;\n\n /** @internal */\n private readonly _call: ClientStreamingCall<UpdateRequest, UpdateResponse>;\n\n /** @internal */\n private readonly _span: Span;\n\n public constructor(project: bigint, call: ClientStreamingCall<UpdateRequest, UpdateResponse>, span: Span) {\n this._project = project;\n this._call = call;\n this._span = span;\n }\n\n /**\n * Send an object to update.\n * @param obj The object to update.\n */\n public async send(obj: Objekt): Promise<void> {\n try {\n await this._call.requests.send({\n project: this._project,\n object: obj,\n });\n } catch (err) {\n this._span.end();\n throw err;\n }\n }\n\n /**\n * Complete the update request.\n * @returns The latest project version or `null` if something went wrong.\n */\n public async complete(): Promise<bigint | null> {\n try {\n await this._call.requests.complete();\n const response = await this._call.response;\n return response.version != -1n ? response.version : null;\n } finally {\n this._span.end();\n }\n }\n}\n\nconst encoder = new TextEncoder();\n\n/**\n * Encode string object contents as an array of bytes.\n * @param content The string to encode.\n * @returns The encoded content as an array of bytes.\n */\nexport function encodeContent(content: string): Uint8Array {\n return encoder.encode(content);\n}\n\nconst decoder = new TextDecoder();\n\n/**\n * Decode an array of bytes as an object's string contents.\n * @param bytes The array of bytes to decode.\n * @returns The bytes decoded into a string.\n */\nexport function decodeContent(bytes: Uint8Array | undefined): string {\n return decoder.decode(bytes);\n}\n"]}
@@ -111,6 +111,10 @@ export interface ObjectQuery {
111
111
  * @generated from protobuf field: repeated string ignores = 4;
112
112
  */
113
113
  ignores: string[];
114
+ /**
115
+ * @generated from protobuf field: repeated string subpaths = 5;
116
+ */
117
+ subpaths: string[];
114
118
  }
115
119
  /**
116
120
  * @generated from protobuf message pb.GetRequest
@@ -401,7 +401,8 @@ class ObjectQuery$Type extends runtime_4.MessageType {
401
401
  super("pb.ObjectQuery", [
402
402
  { no: 1, name: "path", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
403
403
  { no: 2, name: "is_prefix", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
404
- { no: 4, name: "ignores", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ }
404
+ { no: 4, name: "ignores", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ },
405
+ { no: 5, name: "subpaths", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ }
405
406
  ]);
406
407
  }
407
408
  create(value) {
@@ -409,6 +410,7 @@ class ObjectQuery$Type extends runtime_4.MessageType {
409
410
  message.path = "";
410
411
  message.isPrefix = false;
411
412
  message.ignores = [];
413
+ message.subpaths = [];
412
414
  if (value !== undefined)
413
415
  (0, runtime_3.reflectionMergePartial)(this, message, value);
414
416
  return message;
@@ -427,6 +429,9 @@ class ObjectQuery$Type extends runtime_4.MessageType {
427
429
  case /* repeated string ignores */ 4:
428
430
  message.ignores.push(reader.string());
429
431
  break;
432
+ case /* repeated string subpaths */ 5:
433
+ message.subpaths.push(reader.string());
434
+ break;
430
435
  default:
431
436
  let u = options.readUnknownField;
432
437
  if (u === "throw")
@@ -448,6 +453,9 @@ class ObjectQuery$Type extends runtime_4.MessageType {
448
453
  /* repeated string ignores = 4; */
449
454
  for (let i = 0; i < message.ignores.length; i++)
450
455
  writer.tag(4, runtime_1.WireType.LengthDelimited).string(message.ignores[i]);
456
+ /* repeated string subpaths = 5; */
457
+ for (let i = 0; i < message.subpaths.length; i++)
458
+ writer.tag(5, runtime_1.WireType.LengthDelimited).string(message.subpaths[i]);
451
459
  let u = options.writeUnknownFields;
452
460
  if (u !== false)
453
461
  (u == true ? runtime_2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);