@gadgetinc/dateilager 0.1.0-rc.1
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 -0
- package/dist/cjs/binary-client.d.ts +89 -0
- package/dist/cjs/binary-client.js +125 -0
- package/dist/cjs/binary-client.js.map +1 -0
- package/dist/cjs/grpc-client.d.ts +163 -0
- package/dist/cjs/grpc-client.js +320 -0
- package/dist/cjs/grpc-client.js.map +1 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/internal/telemetry.d.ts +1 -0
- package/dist/cjs/internal/telemetry.js +30 -0
- package/dist/cjs/internal/telemetry.js.map +1 -0
- package/dist/cjs/pb/fs_pb.client.d.ts +113 -0
- package/dist/cjs/pb/fs_pb.client.js +101 -0
- package/dist/cjs/pb/fs_pb.client.js.map +1 -0
- package/dist/cjs/pb/fs_pb.d.ts +494 -0
- package/dist/cjs/pb/fs_pb.js +1082 -0
- package/dist/cjs/pb/fs_pb.js.map +1 -0
- package/dist/esm/binary-client.d.ts +89 -0
- package/dist/esm/binary-client.js +118 -0
- package/dist/esm/binary-client.js.map +1 -0
- package/dist/esm/grpc-client.d.ts +163 -0
- package/dist/esm/grpc-client.js +314 -0
- package/dist/esm/grpc-client.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/telemetry.d.ts +1 -0
- package/dist/esm/internal/telemetry.js +26 -0
- package/dist/esm/internal/telemetry.js.map +1 -0
- package/dist/esm/pb/fs_pb.client.d.ts +113 -0
- package/dist/esm/pb/fs_pb.client.js +97 -0
- package/dist/esm/pb/fs_pb.client.js.map +1 -0
- package/dist/esm/pb/fs_pb.d.ts +494 -0
- package/dist/esm/pb/fs_pb.js +1079 -0
- package/dist/esm/pb/fs_pb.js.map +1 -0
- package/package.json +59 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# DateiLager JS Client
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for {@link DateiLagerBinaryClient}.
|
|
3
|
+
*/
|
|
4
|
+
export interface DateiLagerBinaryClientOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The address of the dateilager server.
|
|
7
|
+
*/
|
|
8
|
+
server: string | {
|
|
9
|
+
/**
|
|
10
|
+
* The host of the dateilager server.
|
|
11
|
+
*/
|
|
12
|
+
host: string;
|
|
13
|
+
/**
|
|
14
|
+
* The port of the dateilager server.
|
|
15
|
+
*/
|
|
16
|
+
port: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The token that will be sent as authorization metadata to the dateilager server.
|
|
20
|
+
*/
|
|
21
|
+
token: string | (() => Promise<string>);
|
|
22
|
+
/**
|
|
23
|
+
* The path to the dateilager-client executable.
|
|
24
|
+
*
|
|
25
|
+
* @default "dateilager-client"
|
|
26
|
+
*/
|
|
27
|
+
command?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The default number of milliseconds to wait before terminating the process.
|
|
30
|
+
*
|
|
31
|
+
* @default Infinity
|
|
32
|
+
*/
|
|
33
|
+
timeout?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the dateilager binary client should enable tracing.
|
|
36
|
+
*
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
tracing?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Logging configuration.
|
|
42
|
+
*/
|
|
43
|
+
logger?: {
|
|
44
|
+
/**
|
|
45
|
+
* The log level to pass to the dateilager binary client.
|
|
46
|
+
*/
|
|
47
|
+
level: "debug" | "info" | "warn" | "error";
|
|
48
|
+
/**
|
|
49
|
+
* The function that will be called when the dateilager binary client logs something.
|
|
50
|
+
*/
|
|
51
|
+
log: (level: "debug" | "info" | "warn" | "error", msg: string, fields: Record<string, unknown>) => void;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A version of the DateiLager client that uses the compiled binary client instead of the Javascript one.
|
|
56
|
+
*
|
|
57
|
+
* Useful for working directly with a real filesystem instead of in memory objects.
|
|
58
|
+
*/
|
|
59
|
+
export declare class DateiLagerBinaryClient {
|
|
60
|
+
/**
|
|
61
|
+
* @param options An object with {@link DateiLagerBinaryClientOptions options}.
|
|
62
|
+
*/
|
|
63
|
+
constructor(options: DateiLagerBinaryClientOptions);
|
|
64
|
+
/**
|
|
65
|
+
* Update objects in a project based on the differences in a local directory.
|
|
66
|
+
*
|
|
67
|
+
* @param project The id of the project.
|
|
68
|
+
* @param directory The path of the directory to send updates from.
|
|
69
|
+
* @param options Object of options.
|
|
70
|
+
* @param options.timeout Number of milliseconds to wait before terminating the process.
|
|
71
|
+
* @returns The latest project id or `null` if the latest version was already checked out.
|
|
72
|
+
*/
|
|
73
|
+
update(project: bigint, directory: string, options?: {
|
|
74
|
+
timeout: number;
|
|
75
|
+
}): Promise<bigint | null>;
|
|
76
|
+
/**
|
|
77
|
+
* Rebuild the local filesystem.
|
|
78
|
+
*
|
|
79
|
+
* @param project The id of the project.
|
|
80
|
+
* @param to The version of the project to rebuild the filesystem to.
|
|
81
|
+
* @param directory The path of the directory to rebuild the filesystem at.
|
|
82
|
+
* @param options Object of options.
|
|
83
|
+
* @param options.timeout Number of milliseconds to wait before terminating the process.
|
|
84
|
+
* @returns The latest project id or `null` if the latest version was already checked out.
|
|
85
|
+
*/
|
|
86
|
+
rebuild(project: bigint, to: bigint | null, directory: string, options?: {
|
|
87
|
+
timeout: number;
|
|
88
|
+
}): Promise<bigint | null>;
|
|
89
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DateiLagerBinaryClient = void 0;
|
|
7
|
+
const api_1 = require("@opentelemetry/api");
|
|
8
|
+
const execa_1 = __importDefault(require("execa"));
|
|
9
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
10
|
+
const readline_1 = __importDefault(require("readline"));
|
|
11
|
+
const telemetry_1 = require("./internal/telemetry");
|
|
12
|
+
/**
|
|
13
|
+
* A version of the DateiLager client that uses the compiled binary client instead of the Javascript one.
|
|
14
|
+
*
|
|
15
|
+
* Useful for working directly with a real filesystem instead of in memory objects.
|
|
16
|
+
*/
|
|
17
|
+
class DateiLagerBinaryClient {
|
|
18
|
+
/**
|
|
19
|
+
* @param options An object with {@link DateiLagerBinaryClientOptions options}.
|
|
20
|
+
*/
|
|
21
|
+
constructor(options) {
|
|
22
|
+
/** @internal */
|
|
23
|
+
Object.defineProperty(this, "_options", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
this._options = {
|
|
30
|
+
server: typeof options.server === "string" ? options.server : `${options.server.host}:${options.server.port}`,
|
|
31
|
+
token: typeof options.token === "string" ? () => Promise.resolve(options.token) : options.token,
|
|
32
|
+
command: options.command ?? "dateilager-client",
|
|
33
|
+
timeout: options.timeout ?? Infinity,
|
|
34
|
+
tracing: options.tracing ?? false,
|
|
35
|
+
logger: options.logger,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Update objects in a project based on the differences in a local directory.
|
|
40
|
+
*
|
|
41
|
+
* @param project The id of the project.
|
|
42
|
+
* @param directory The path of the directory to send updates from.
|
|
43
|
+
* @param options Object of options.
|
|
44
|
+
* @param options.timeout Number of milliseconds to wait before terminating the process.
|
|
45
|
+
* @returns The latest project id or `null` if the latest version was already checked out.
|
|
46
|
+
*/
|
|
47
|
+
async update(project, directory, options) {
|
|
48
|
+
return await (0, telemetry_1.trace)("dateilager-binary-client.update", {
|
|
49
|
+
attributes: {
|
|
50
|
+
"dl.project": String(project),
|
|
51
|
+
"dl.directory": directory,
|
|
52
|
+
},
|
|
53
|
+
}, async () => {
|
|
54
|
+
const result = await this._call("update", project, directory, ["-dir", directory], options);
|
|
55
|
+
if (result.stdout == "-1") {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return BigInt(result.stdout);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Rebuild the local filesystem.
|
|
63
|
+
*
|
|
64
|
+
* @param project The id of the project.
|
|
65
|
+
* @param to The version of the project to rebuild the filesystem to.
|
|
66
|
+
* @param directory The path of the directory to rebuild the filesystem at.
|
|
67
|
+
* @param options Object of options.
|
|
68
|
+
* @param options.timeout Number of milliseconds to wait before terminating the process.
|
|
69
|
+
* @returns The latest project id or `null` if the latest version was already checked out.
|
|
70
|
+
*/
|
|
71
|
+
async rebuild(project, to, directory, options) {
|
|
72
|
+
return await (0, telemetry_1.trace)("dateilager-binary-client.rebuild", {
|
|
73
|
+
attributes: {
|
|
74
|
+
"dl.project": String(project),
|
|
75
|
+
"dl.to": String(to),
|
|
76
|
+
"dl.directory": directory,
|
|
77
|
+
},
|
|
78
|
+
}, async () => {
|
|
79
|
+
await promises_1.default.mkdir(directory, { recursive: true });
|
|
80
|
+
const args = ["-dir", directory];
|
|
81
|
+
if (to) {
|
|
82
|
+
args.push("-to", String(to));
|
|
83
|
+
}
|
|
84
|
+
const result = await this._call("rebuild", project, directory, args, options);
|
|
85
|
+
if (result.stdout == "-1") {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
return BigInt(result.stdout);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/** @internal */
|
|
92
|
+
async _call(method, project, cwd, args, options) {
|
|
93
|
+
const baseArgs = [method, "-project", String(project), "-server", this._options.server, "-encoding", "json"];
|
|
94
|
+
if (this._options.logger) {
|
|
95
|
+
baseArgs.push("-log", this._options.logger.level);
|
|
96
|
+
}
|
|
97
|
+
if (this._options.tracing) {
|
|
98
|
+
const carrier = {};
|
|
99
|
+
api_1.propagation.inject(api_1.context.active(), carrier);
|
|
100
|
+
const otelContext = JSON.stringify(carrier);
|
|
101
|
+
baseArgs.push("-tracing", "-otel-context", otelContext);
|
|
102
|
+
}
|
|
103
|
+
const subprocess = (0, execa_1.default)(this._options.command, baseArgs.concat(args), {
|
|
104
|
+
cwd,
|
|
105
|
+
timeout: options?.timeout ?? this._options.timeout,
|
|
106
|
+
env: { DL_TOKEN: await this._options.token() },
|
|
107
|
+
});
|
|
108
|
+
if (this._options.logger && subprocess.stderr) {
|
|
109
|
+
readline_1.default.createInterface(subprocess.stderr).on("line", (line) => {
|
|
110
|
+
try {
|
|
111
|
+
// we purposefully extract and ignore the `ts` field
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
113
|
+
const { level, msg, ts, ...fields } = JSON.parse(line);
|
|
114
|
+
this._options.logger?.log(level, msg, fields);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
this._options.logger?.log("warn", "failed to log line", { error, line });
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return subprocess;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.DateiLagerBinaryClient = DateiLagerBinaryClient;
|
|
125
|
+
//# sourceMappingURL=binary-client.js.map
|
|
@@ -0,0 +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;AAiE7C;;;;GAIG;AACH,MAAa,sBAAsB;IAIjC;;OAEG;IACH,YAAmB,OAAsC;QANzD,gBAAgB;QAChB;;;;;WAA0B;QAMxB,IAAI,CAAC,QAAQ,GAAG;YACd,MAAM,EAAE,OAAO,OAAO,CAAC,MAAM,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","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 | 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 * 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 the process.\n *\n * @default Infinity\n */\n timeout?: number;\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 * 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 server: typeof options.server === \"string\" ? options.server : `${options.server.host}:${options.server.port}`,\n token: typeof options.token === \"string\" ? () => Promise.resolve(options.token as string) : options.token,\n command: options.command ?? \"dateilager-client\",\n timeout: options.timeout ?? Infinity,\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 id or `null` if the latest version was already checked out.\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 result = await this._call(\"update\", project, directory, [\"-dir\", 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 * @returns The latest project id or `null` if the latest version was already checked out.\n */\n public async rebuild(project: bigint, to: bigint | null, directory: string, options?: { timeout: number }): Promise<bigint | null> {\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 const result = await this._call(\"rebuild\", project, directory, args, options);\n if (result.stdout == \"-1\") {\n return null;\n }\n\n return BigInt(result.stdout);\n }\n );\n }\n\n /** @internal */\n private async _call(\n method: \"update\" | \"rebuild\",\n project: bigint,\n cwd: string,\n args: string[],\n options?: { timeout: number }\n ): Promise<ExecaReturnValue> {\n const baseArgs = [method, \"-project\", String(project), \"-server\", this._options.server, \"-encoding\", \"json\"];\n\n if (this._options.logger) {\n baseArgs.push(\"-log\", this._options.logger.level);\n }\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\n const subprocess = execa(this._options.command, baseArgs.concat(args), {\n cwd,\n timeout: options?.timeout ?? this._options.timeout,\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"]}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { ClientOptions } from "@grpc/grpc-js";
|
|
2
|
+
import type { Span } from "@opentelemetry/api";
|
|
3
|
+
import type { ClientStreamingCall, RpcOptions } from "@protobuf-ts/runtime-rpc";
|
|
4
|
+
import type { Objekt, Project, UpdateRequest, UpdateResponse } from "./pb/fs_pb";
|
|
5
|
+
/**
|
|
6
|
+
* Options for {@link DateiLagerGrpcClient}.
|
|
7
|
+
*/
|
|
8
|
+
export interface DateiLagerGrpcClientOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The address of the dateilager server.
|
|
11
|
+
*/
|
|
12
|
+
server: string | {
|
|
13
|
+
/**
|
|
14
|
+
* The host of the dateilager server.
|
|
15
|
+
*/
|
|
16
|
+
host: string;
|
|
17
|
+
/**
|
|
18
|
+
* The port of the dateilager server.
|
|
19
|
+
*/
|
|
20
|
+
port: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The token that will be sent as authorization metadata to the dateilager server.
|
|
24
|
+
*/
|
|
25
|
+
token: string | (() => Promise<string>);
|
|
26
|
+
/**
|
|
27
|
+
* Options that will be passed to the underlying grpc client constructor.
|
|
28
|
+
*
|
|
29
|
+
* @see ClientOptions
|
|
30
|
+
*/
|
|
31
|
+
grpcClientOptions?: ClientOptions;
|
|
32
|
+
/**
|
|
33
|
+
* Options that will be passed to every remote procedure call.
|
|
34
|
+
*
|
|
35
|
+
* @see RpcOptions
|
|
36
|
+
*/
|
|
37
|
+
rpcOptions?: RpcOptions | (() => RpcOptions | undefined);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A client class for interacting with DateiLager's GRPC API.
|
|
41
|
+
*
|
|
42
|
+
* The DateiLager API surface area is as minimal as possible;
|
|
43
|
+
* convenience functions, such as getObject, should be implemented within the client.
|
|
44
|
+
*/
|
|
45
|
+
export declare class DateiLagerGrpcClient {
|
|
46
|
+
/**
|
|
47
|
+
* The library used to interact with GRPC creates connections lazily, this constructor will not
|
|
48
|
+
* raise an error even if there is no service running at {@link DateiLagerGrpcClientOptions.server server}.
|
|
49
|
+
*
|
|
50
|
+
* @param options Grpc client options.
|
|
51
|
+
*/
|
|
52
|
+
constructor(options: DateiLagerGrpcClientOptions);
|
|
53
|
+
/**
|
|
54
|
+
* Close the underlying GRPC client.
|
|
55
|
+
*/
|
|
56
|
+
close(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Create a new project.
|
|
59
|
+
*
|
|
60
|
+
* @param project The id of the project.
|
|
61
|
+
* @param packPatterns The paths to pack.
|
|
62
|
+
* @param template The id of the project to start from.
|
|
63
|
+
*/
|
|
64
|
+
newProject(project: bigint, packPatterns: string[], template?: bigint): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Delete a project.
|
|
67
|
+
*
|
|
68
|
+
* @param project The id of the project.
|
|
69
|
+
*/
|
|
70
|
+
deleteProject(project: bigint): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* List objects.
|
|
73
|
+
*
|
|
74
|
+
* @param project The id of the project.
|
|
75
|
+
* @param path The path to list objects under.
|
|
76
|
+
* @param ignores The paths under {@link path} to ignore.
|
|
77
|
+
* @param from The project version to start from.
|
|
78
|
+
* @param to The project version to end at.
|
|
79
|
+
* @returns A stream of objects.
|
|
80
|
+
* @yields An object from the stream.
|
|
81
|
+
* @example
|
|
82
|
+
* for await (const object of client.listObjects(1n, "")) {
|
|
83
|
+
* console.log("[listObjects] path: " + object.path);
|
|
84
|
+
* console.log("[listObjects] content:\n" + object.content);
|
|
85
|
+
* }
|
|
86
|
+
*/
|
|
87
|
+
listObjects(project: bigint, path: string, ignores?: string[], from?: bigint, to?: bigint): AsyncGenerator<Objekt, void>;
|
|
88
|
+
/**
|
|
89
|
+
* Get an object.
|
|
90
|
+
*
|
|
91
|
+
* @param project The id of the project.
|
|
92
|
+
* @param path The path of the object.
|
|
93
|
+
* @returns The object at the given path or undefined if it does not exist.
|
|
94
|
+
*/
|
|
95
|
+
getObject(project: bigint, path: string): Promise<Objekt | undefined>;
|
|
96
|
+
/**
|
|
97
|
+
* Update objects.
|
|
98
|
+
*
|
|
99
|
+
* @param project The id of the project.
|
|
100
|
+
* @returns An {@link UpdateInputStream} to send objects to update.
|
|
101
|
+
*/
|
|
102
|
+
updateObjects(project: bigint): UpdateInputStream;
|
|
103
|
+
/**
|
|
104
|
+
* Update an object.
|
|
105
|
+
*
|
|
106
|
+
* @param project The id of the project.
|
|
107
|
+
* @param obj The object to update.
|
|
108
|
+
* @returns The new project version.
|
|
109
|
+
*/
|
|
110
|
+
updateObject(project: bigint, obj: Objekt): Promise<bigint | null>;
|
|
111
|
+
/**
|
|
112
|
+
* Snapshot the current state of the dateilager server.
|
|
113
|
+
*
|
|
114
|
+
* @returns All the projects on the dateilager server.
|
|
115
|
+
* @throws If the dateilager server's DL_ENV environment variable is PROD.
|
|
116
|
+
* @see DateiLagerGrpcClient.resetToSnapshotInDevOrTests
|
|
117
|
+
*/
|
|
118
|
+
snapshotInDevOrTests(): Promise<Project[]>;
|
|
119
|
+
/**
|
|
120
|
+
* Reset the given projects to their respective versions and delete any remaining projects.
|
|
121
|
+
* If no projects are provided, delete all projects.
|
|
122
|
+
*
|
|
123
|
+
* @param projects The projects to reset.
|
|
124
|
+
* @throws If the dateilager server's DL_ENV environment variable is PROD.
|
|
125
|
+
* @see DateiLagerGrpcClient.snapshotInDevOrTests
|
|
126
|
+
*/
|
|
127
|
+
resetToSnapshotInDevOrTests(projects: Project[]): Promise<void>;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Used to send a stream of objects to update.
|
|
131
|
+
*
|
|
132
|
+
* @see DateiLagerGrpcClient.updateObjects
|
|
133
|
+
*/
|
|
134
|
+
declare class UpdateInputStream {
|
|
135
|
+
constructor(project: bigint, call: ClientStreamingCall<UpdateRequest, UpdateResponse>, span: Span);
|
|
136
|
+
/**
|
|
137
|
+
* Send an object to update.
|
|
138
|
+
*
|
|
139
|
+
* @param obj The object to update.
|
|
140
|
+
*/
|
|
141
|
+
send(obj: Objekt): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* Complete the update request.
|
|
144
|
+
*
|
|
145
|
+
* @returns The new project version.
|
|
146
|
+
*/
|
|
147
|
+
complete(): Promise<bigint | null>;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Encode string object contents as an array of bytes.
|
|
151
|
+
*
|
|
152
|
+
* @param content The string to encode.
|
|
153
|
+
* @returns The encoded content as an array of bytes.
|
|
154
|
+
*/
|
|
155
|
+
export declare function encodeContent(content: string): Uint8Array;
|
|
156
|
+
/**
|
|
157
|
+
* Decode an array of bytes as an object's string contents.
|
|
158
|
+
*
|
|
159
|
+
* @param bytes The array of bytes to decode.
|
|
160
|
+
* @returns The bytes decoded into a string.
|
|
161
|
+
*/
|
|
162
|
+
export declare function decodeContent(bytes: Uint8Array | undefined): string;
|
|
163
|
+
export {};
|