apache-iggy 0.10.0 → 0.10.1-edge.2

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.
Files changed (157) hide show
  1. package/README.md +248 -28
  2. package/dist/client/client.config.d.ts +2 -0
  3. package/dist/client/client.config.js +13 -2
  4. package/dist/client/client.config.test.js +15 -2
  5. package/dist/client/client.connection-string.js +13 -1
  6. package/dist/client/client.connection-string.test.js +43 -1
  7. package/dist/client/client.connection.d.ts +33 -135
  8. package/dist/client/client.connection.js +190 -453
  9. package/dist/client/client.connection.test.js +244 -669
  10. package/dist/client/client.d.ts +4 -35
  11. package/dist/client/client.js +8 -101
  12. package/dist/client/client.operation.d.ts +120 -0
  13. package/dist/client/client.operation.js +428 -0
  14. package/dist/client/client.operation.test.d.ts +2 -0
  15. package/dist/client/client.operation.test.js +285 -0
  16. package/dist/client/client.socket.d.ts +92 -209
  17. package/dist/client/client.socket.js +1205 -981
  18. package/dist/client/client.socket.test.js +4865 -679
  19. package/dist/client/client.type.d.ts +65 -22
  20. package/dist/client/index.d.ts +1 -0
  21. package/dist/client/index.js +1 -0
  22. package/dist/client.e2e.js +3 -5
  23. package/dist/e2e/resource-options.e2e.d.ts +2 -0
  24. package/dist/{wire/stream/purge-stream.command.js → e2e/resource-options.e2e.js} +12 -20
  25. package/dist/e2e/resource-options.suite.d.ts +15 -0
  26. package/dist/e2e/resource-options.suite.js +272 -0
  27. package/dist/e2e/tcp.cluster.e2e.js +1 -0
  28. package/dist/e2e/tcp.consumer-stream.e2e.js +4 -0
  29. package/dist/e2e/tcp.parallel.e2e.js +5 -6
  30. package/dist/e2e/tcp.stream.e2e.js +0 -3
  31. package/dist/e2e/tcp.system.e2e.js +10 -1
  32. package/dist/e2e/tcp.token.e2e.js +8 -2
  33. package/dist/e2e/tcp.topic.e2e.js +0 -3
  34. package/dist/e2e/tcp.user.e2e.js +46 -3
  35. package/dist/e2e/tls.system.e2e.js +21 -12
  36. package/dist/index.d.ts +2 -1
  37. package/dist/index.js +1 -1
  38. package/dist/stream/consumer-stream.js +97 -12
  39. package/dist/wire/cluster/cluster.type.d.ts +2 -2
  40. package/dist/wire/cluster/cluster.utils.d.ts +1 -0
  41. package/dist/wire/cluster/cluster.utils.js +4 -1
  42. package/dist/wire/command-set.d.ts +8 -8
  43. package/dist/wire/command-set.js +18 -9
  44. package/dist/wire/command.code.d.ts +3 -10
  45. package/dist/wire/command.code.js +9 -11
  46. package/dist/wire/command.utils.d.ts +3 -2
  47. package/dist/wire/command.utils.js +3 -2
  48. package/dist/wire/error.code.js +17 -1
  49. package/dist/wire/error.code.test.js +28 -1
  50. package/dist/wire/error.utils.d.ts +4 -2
  51. package/dist/wire/error.utils.js +6 -3
  52. package/dist/wire/identifier.utils.d.ts +2 -0
  53. package/dist/wire/identifier.utils.js +2 -0
  54. package/dist/wire/index.d.ts +1 -0
  55. package/dist/wire/index.js +1 -0
  56. package/dist/wire/message/header.type.d.ts +1 -1
  57. package/dist/wire/message/message-batch.test.js +11 -5
  58. package/dist/wire/message/message.utils.d.ts +0 -10
  59. package/dist/wire/message/message.utils.js +1 -22
  60. package/dist/wire/message/poll-messages.command.d.ts +12 -1
  61. package/dist/wire/message/poll-messages.command.js +64 -16
  62. package/dist/wire/message/poll-messages.command.test.js +143 -5
  63. package/dist/wire/message/poll.utils.d.ts +4 -0
  64. package/dist/wire/message/poll.utils.js +6 -1
  65. package/dist/wire/message/send-messages.command.d.ts +3 -3
  66. package/dist/wire/message/send-messages.command.js +103 -3
  67. package/dist/wire/message/send-messages.command.test.js +113 -2
  68. package/dist/wire/offset/delete-offset.command.d.ts +11 -4
  69. package/dist/wire/offset/delete-offset.command.js +1 -1
  70. package/dist/wire/offset/get-offset.command.d.ts +1 -1
  71. package/dist/wire/offset/offset-write.command.test.d.ts +2 -0
  72. package/dist/wire/offset/offset-write.command.test.js +43 -0
  73. package/dist/wire/offset/offset.utils.js +10 -6
  74. package/dist/wire/offset/store-offset.command.d.ts +10 -0
  75. package/dist/wire/offset/store-offset.command.js +1 -1
  76. package/dist/wire/options.utils.d.ts +46 -0
  77. package/dist/wire/options.utils.js +57 -0
  78. package/dist/wire/partition/partition-route.d.ts +12 -0
  79. package/dist/wire/partition/partition-route.js +40 -0
  80. package/dist/wire/partition/partition-route.test.d.ts +2 -0
  81. package/dist/wire/partition/partition-route.test.js +42 -0
  82. package/dist/wire/session/login-with-token.command.d.ts +2 -2
  83. package/dist/wire/session/login-with-token.command.js +7 -2
  84. package/dist/wire/session/login.command.d.ts +2 -2
  85. package/dist/wire/session/login.command.js +7 -2
  86. package/dist/wire/stream/create-stream.command.d.ts +5 -2
  87. package/dist/wire/stream/create-stream.command.js +20 -2
  88. package/dist/wire/stream/index.d.ts +1 -1
  89. package/dist/wire/stream/index.js +1 -1
  90. package/dist/wire/stream/stream-options.d.ts +77 -0
  91. package/dist/wire/stream/stream-options.js +101 -0
  92. package/dist/wire/stream/stream-options.test.d.ts +2 -0
  93. package/dist/wire/stream/stream-options.test.js +103 -0
  94. package/dist/wire/stream/stream.utils.d.ts +9 -0
  95. package/dist/wire/stream/stream.utils.js +17 -3
  96. package/dist/wire/stream/update-stream.command.d.ts +23 -5
  97. package/dist/wire/stream/update-stream.command.js +10 -17
  98. package/dist/wire/system/describe-options.command.d.ts +23 -6
  99. package/dist/wire/system/describe-options.command.js +21 -2
  100. package/dist/wire/system/get-stats.command.d.ts +17 -0
  101. package/dist/wire/system/get-stats.command.js +69 -16
  102. package/dist/wire/system/get-stats.command.test.d.ts +2 -0
  103. package/dist/wire/system/get-stats.command.test.js +97 -0
  104. package/dist/wire/system/index.d.ts +2 -0
  105. package/dist/wire/system/index.js +2 -0
  106. package/dist/wire/system/snapshot.command.d.ts +64 -0
  107. package/dist/wire/system/snapshot.command.js +76 -0
  108. package/dist/wire/system/snapshot.command.test.d.ts +2 -0
  109. package/dist/wire/system/snapshot.command.test.js +86 -0
  110. package/dist/wire/system/update-resource.command.d.ts +53 -0
  111. package/dist/wire/system/update-resource.command.js +130 -0
  112. package/dist/wire/system/update-resource.command.test.d.ts +2 -0
  113. package/dist/wire/system/update-resource.command.test.js +497 -0
  114. package/dist/wire/token/create-token.command.d.ts +1 -1
  115. package/dist/wire/token/create-token.command.js +1 -1
  116. package/dist/wire/token/create-token.command.test.js +6 -0
  117. package/dist/wire/topic/create-topic.command.d.ts +20 -12
  118. package/dist/wire/topic/create-topic.command.js +11 -4
  119. package/dist/wire/topic/index.d.ts +1 -2
  120. package/dist/wire/topic/index.js +1 -2
  121. package/dist/wire/topic/topic.utils.d.ts +14 -5
  122. package/dist/wire/topic/topic.utils.js +26 -11
  123. package/dist/wire/topic/topic.utils.test.js +13 -13
  124. package/dist/wire/topic/update-topic.command.d.ts +22 -15
  125. package/dist/wire/topic/update-topic.command.js +12 -34
  126. package/dist/wire/user/create-user.command.d.ts +12 -2
  127. package/dist/wire/user/create-user.command.js +7 -3
  128. package/dist/wire/user/index.d.ts +1 -0
  129. package/dist/wire/user/index.js +1 -0
  130. package/dist/wire/user/update-user.command.d.ts +25 -7
  131. package/dist/wire/user/update-user.command.js +18 -31
  132. package/dist/wire/user/user.utils.d.ts +2 -0
  133. package/dist/wire/user/user.utils.js +5 -3
  134. package/dist/wire/vsr/header.d.ts +23 -8
  135. package/dist/wire/vsr/header.js +32 -10
  136. package/dist/wire/vsr/header.test.js +5 -1
  137. package/dist/wire/vsr/index.d.ts +8 -2
  138. package/dist/wire/vsr/index.js +44 -11
  139. package/dist/wire/vsr/operation.d.ts +18 -6
  140. package/dist/wire/vsr/operation.js +46 -16
  141. package/dist/wire/vsr/operation.test.js +32 -8
  142. package/dist/wire/vsr/register.d.ts +10 -6
  143. package/dist/wire/vsr/register.js +24 -7
  144. package/dist/wire/vsr/register.test.js +28 -8
  145. package/dist/wire/vsr/reply.d.ts +4 -1
  146. package/dist/wire/vsr/reply.js +42 -7
  147. package/dist/wire/vsr/reply.test.js +11 -1
  148. package/dist/wire/vsr/session.d.ts +9 -10
  149. package/dist/wire/vsr/session.js +32 -23
  150. package/dist/wire/vsr/session.test.js +33 -7
  151. package/dist/wire/vsr/vsr.test.js +57 -6
  152. package/package.json +6 -7
  153. package/dist/wire/message/flush-unsaved-buffers.command.d.ts +0 -26
  154. package/dist/wire/message/flush-unsaved-buffers.command.js +0 -36
  155. package/dist/wire/stream/purge-stream.command.d.ts +0 -22
  156. package/dist/wire/topic/purge-topic.command.d.ts +0 -24
  157. package/dist/wire/topic/purge-topic.command.js +0 -39
@@ -0,0 +1,76 @@
1
+ // Licensed to the Apache Software Foundation (ASF) under one
2
+ // or more contributor license agreements. See the NOTICE file
3
+ // distributed with this work for additional information
4
+ // regarding copyright ownership. The ASF licenses this file
5
+ // to you under the Apache License, Version 2.0 (the
6
+ // "License"); you may not use this file except in compliance
7
+ // with the License. You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the License is distributed on an
13
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ // KIND, either express or implied. See the License for the
15
+ // specific language governing permissions and limitations
16
+ // under the License.
17
+ import { COMMAND_CODE } from '../command.code.js';
18
+ import { wrapCommand } from '../command.utils.js';
19
+ export const SnapshotCompression = {
20
+ Stored: 1,
21
+ Deflated: 2,
22
+ Bzip2: 3,
23
+ Zstd: 4,
24
+ Lzma: 5,
25
+ Xz: 6,
26
+ };
27
+ export const SystemSnapshotType = {
28
+ FilesystemOverview: 1,
29
+ ProcessList: 2,
30
+ ResourceUsage: 3,
31
+ Test: 4,
32
+ ServerLogs: 5,
33
+ ServerConfig: 6,
34
+ All: 100,
35
+ };
36
+ export const SNAPSHOT_COMPRESSION = SnapshotCompression;
37
+ export const SYSTEM_SNAPSHOT_TYPE = SystemSnapshotType;
38
+ const serializeSnapshot = (payload) => {
39
+ const compression = payload && payload.compression ? payload.compression : SnapshotCompression.Deflated;
40
+ const snapshotTypes = payload && payload.snapshotTypes ? payload.snapshotTypes : [SystemSnapshotType.All];
41
+ if (snapshotTypes.length > 255) {
42
+ throw new Error('snapshotTypes count cannot exceed 255');
43
+ }
44
+ if (snapshotTypes.length > 1 && snapshotTypes.includes(SystemSnapshotType.All)) {
45
+ throw new Error('SystemSnapshotType.All cannot be combined with specific snapshot types');
46
+ }
47
+ const buf = Buffer.allocUnsafe(2 + snapshotTypes.length);
48
+ buf.writeUInt8(compression, 0);
49
+ buf.writeUInt8(snapshotTypes.length, 1);
50
+ for (let i = 0; i < snapshotTypes.length; i++) {
51
+ buf.writeUInt8(snapshotTypes[i], 2 + i);
52
+ }
53
+ return buf;
54
+ };
55
+ export const SNAPSHOT = {
56
+ code: COMMAND_CODE.GetSnapshot,
57
+ serialize: serializeSnapshot,
58
+ deserialize: (r) => r.data
59
+ };
60
+ /**
61
+ * Captures and packages the current system state as a raw ZIP archive.
62
+ *
63
+ * @param options - Optional configuration for snapshot compression and section types.
64
+ * Defaults to Deflated compression and `SystemSnapshotType.All` (code 100), capturing all
65
+ * available diagnostic sections (filesystem overview, process list, resource usage, server
66
+ * logs, and server configuration) for complete debugging.
67
+ * @returns A Buffer containing the raw ZIP archive bytes.
68
+ *
69
+ * @remarks
70
+ * - Authentication is required, and the caller must have administrative permissions.
71
+ * - The server enforces a single-flight mutex guard: only one snapshot can be collected
72
+ * at a time across the cluster.
73
+ * - Subject to the client's default 30-second socket timeout budget.
74
+ */
75
+ export const snapshot = wrapCommand(SNAPSHOT);
76
+ //# sourceMappingURL=snapshot.command.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=snapshot.command.test.d.ts.map
@@ -0,0 +1,86 @@
1
+ // Licensed to the Apache Software Foundation (ASF) under one
2
+ // or more contributor license agreements. See the NOTICE file
3
+ // distributed with this work for additional information
4
+ // regarding copyright ownership. The ASF licenses this file
5
+ // to you under the Apache License, Version 2.0 (the
6
+ // "License"); you may not use this file except in compliance
7
+ // with the License. You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the License is distributed on an
13
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ // KIND, either express or implied. See the License for the
15
+ // specific language governing permissions and limitations
16
+ // under the License.
17
+ import { describe, it } from 'node:test';
18
+ import assert from 'node:assert/strict';
19
+ import { COMMAND_CODE } from '../command.code.js';
20
+ import { SNAPSHOT, SnapshotCompression, SystemSnapshotType, SNAPSHOT_COMPRESSION, SYSTEM_SNAPSHOT_TYPE } from './snapshot.command.js';
21
+ describe('SnapshotCommand', () => {
22
+ it('has correct command code', () => {
23
+ assert.equal(SNAPSHOT.code, COMMAND_CODE.GetSnapshot);
24
+ assert.equal(SNAPSHOT.code, 11);
25
+ });
26
+ describe('serialize', () => {
27
+ it('serializes default options (Deflated compression and All snapshot type)', () => {
28
+ const buf = SNAPSHOT.serialize();
29
+ assert.equal(buf.length, 3);
30
+ assert.equal(buf.readUInt8(0), SnapshotCompression.Deflated);
31
+ assert.equal(buf.readUInt8(1), 1);
32
+ assert.equal(buf.readUInt8(2), SystemSnapshotType.All);
33
+ });
34
+ it('serializes custom compression and snapshot types', () => {
35
+ const buf = SNAPSHOT.serialize({
36
+ compression: SnapshotCompression.Stored,
37
+ snapshotTypes: [
38
+ SystemSnapshotType.FilesystemOverview,
39
+ SystemSnapshotType.ServerLogs
40
+ ]
41
+ });
42
+ assert.equal(buf.length, 4);
43
+ assert.equal(buf.readUInt8(0), SnapshotCompression.Stored);
44
+ assert.equal(buf.readUInt8(1), 2);
45
+ assert.equal(buf.readUInt8(2), SystemSnapshotType.FilesystemOverview);
46
+ assert.equal(buf.readUInt8(3), SystemSnapshotType.ServerLogs);
47
+ });
48
+ it('serializes empty snapshot types', () => {
49
+ const buf = SNAPSHOT.serialize({
50
+ compression: SnapshotCompression.Bzip2,
51
+ snapshotTypes: []
52
+ });
53
+ assert.equal(buf.length, 2);
54
+ assert.equal(buf.readUInt8(0), SnapshotCompression.Bzip2);
55
+ assert.equal(buf.readUInt8(1), 0);
56
+ });
57
+ it('throws when snapshotTypes count exceeds 255', () => {
58
+ const oversizedTypes = new Array(256).fill(SystemSnapshotType.Test);
59
+ assert.throws(() => SNAPSHOT.serialize({ snapshotTypes: oversizedTypes }), /snapshotTypes count cannot exceed 255/);
60
+ });
61
+ it('throws when SystemSnapshotType.All is mixed with other types', () => {
62
+ assert.throws(() => SNAPSHOT.serialize({
63
+ snapshotTypes: [
64
+ SystemSnapshotType.All,
65
+ SystemSnapshotType.ProcessList
66
+ ]
67
+ }), /SystemSnapshotType\.All cannot be combined with specific snapshot types/);
68
+ });
69
+ it('supports backwards-compatible enum aliases', () => {
70
+ assert.equal(SNAPSHOT_COMPRESSION.Deflated, SnapshotCompression.Deflated);
71
+ assert.equal(SYSTEM_SNAPSHOT_TYPE.All, SystemSnapshotType.All);
72
+ });
73
+ });
74
+ describe('deserialize', () => {
75
+ it('returns raw payload buffer', () => {
76
+ const rawData = Buffer.from([0x50, 0x4B, 0x03, 0x04, 1, 2, 3]);
77
+ const res = SNAPSHOT.deserialize({
78
+ status: 0,
79
+ length: rawData.length,
80
+ data: rawData
81
+ });
82
+ assert.deepEqual(res, rawData);
83
+ });
84
+ });
85
+ });
86
+ //# sourceMappingURL=snapshot.command.test.js.map
@@ -0,0 +1,53 @@
1
+ import { type Id } from '../identifier.utils.js';
2
+ import { type OptionEntry } from '../options.utils.js';
3
+ import { OptionsScope } from './describe-options.command.js';
4
+ /** The resource an update patches, tagged by its options scope. */
5
+ export type ResourceTarget = {
6
+ scope: typeof OptionsScope.Topic;
7
+ streamId: Id;
8
+ topicId: Id;
9
+ } | {
10
+ scope: typeof OptionsScope.Stream;
11
+ streamId: Id;
12
+ } | {
13
+ scope: typeof OptionsScope.User;
14
+ userId: Id;
15
+ };
16
+ /**
17
+ * Parameters for the generic update: the keys to set, the keys to reset to
18
+ * their defaults. Every other key keeps its stored value.
19
+ *
20
+ * Typed keys are checked here with the category and in the order the server
21
+ * admits them. A patch carrying any raw entry or raw reset name gets only the
22
+ * structural checks, because the server catalog may know keys or flags this
23
+ * build does not, so the server decides the rest.
24
+ */
25
+ export type UpdateResource = {
26
+ target: ResourceTarget;
27
+ /** Keys set through typed fields. A later entry for a key wins */
28
+ options?: OptionEntry[];
29
+ /** Keys reset through typed members */
30
+ reset?: readonly string[];
31
+ /** Entries with no typed field. A typed entry of the same key wins */
32
+ rawOptions?: OptionEntry[];
33
+ /** Reset names with no typed member */
34
+ rawReset?: readonly string[];
35
+ };
36
+ /**
37
+ * Update resource command definition, the one update for streams, topics and
38
+ * users. Layout: `[scope:u8][identifiers][reset_count:u8][reset_key:name]*`
39
+ * followed by the options block running to the end of the payload. Reset
40
+ * names and set entries are both written in ascending name byte order.
41
+ */
42
+ export declare const UPDATE_RESOURCE: {
43
+ code: number;
44
+ serialize: ({ target, options, reset, rawOptions, rawReset }: UpdateResource) => Buffer<ArrayBuffer>;
45
+ deserialize: (r: import("../../index.js").CommandResponse) => boolean;
46
+ };
47
+ /**
48
+ * A typed column value as an option entry. Text no header value can carry
49
+ * travels as a bool, a kind the column never accepts, so the refusal is the
50
+ * column's own error on either side.
51
+ */
52
+ export declare const columnOption: (key: string, text: string) => OptionEntry;
53
+ //# sourceMappingURL=update-resource.command.d.ts.map
@@ -0,0 +1,130 @@
1
+ // Licensed to the Apache Software Foundation (ASF) under one
2
+ // or more contributor license agreements. See the NOTICE file
3
+ // distributed with this work for additional information
4
+ // regarding copyright ownership. The ASF licenses this file
5
+ // to you under the Apache License, Version 2.0 (the
6
+ // "License"); you may not use this file except in compliance
7
+ // with the License. You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the License is distributed on an
13
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ // KIND, either express or implied. See the License for the
15
+ // specific language governing permissions and limitations
16
+ // under the License.
17
+ import { deserializeVoidResponse } from '../../client/client.utils.js';
18
+ import { COMMAND_CODE } from '../command.code.js';
19
+ import { responseError } from '../error.utils.js';
20
+ import { serializeIdentifier } from '../identifier.utils.js';
21
+ import { uint8ToBuf } from '../number.utils.js';
22
+ import { HeaderKind } from '../message/header.type.js';
23
+ import { HeaderValue } from '../message/header.utils.js';
24
+ import { OPTION_CATALOG, dedupeOptions, serializeOptions, sortOptions } from '../options.utils.js';
25
+ import { OptionFlag, OptionsScope } from './describe-options.command.js';
26
+ const INVALID_COMMAND = 3;
27
+ const INVALID_USERNAME = 43;
28
+ const INVALID_USER_STATUS = 45;
29
+ const INVALID_STREAM_NAME = 1013;
30
+ const INVALID_TOPIC_NAME = 2014;
31
+ const UNSUPPORTED_OPTION_KEY = 4041;
32
+ const OPTION_NOT_UPDATABLE = 4103;
33
+ const OPTION_NOT_RESETTABLE = 4104;
34
+ const READ_ONLY_OPTION = 4105;
35
+ const MAX_NAME_LENGTH = 255;
36
+ const MAX_RESET_KEYS = 255;
37
+ const KEY_PREVIEW_LENGTH = 64;
38
+ const MIN_USERNAME_LENGTH = 3;
39
+ const MAX_USERNAME_LENGTH = 50;
40
+ /**
41
+ * Update resource command definition, the one update for streams, topics and
42
+ * users. Layout: `[scope:u8][identifiers][reset_count:u8][reset_key:name]*`
43
+ * followed by the options block running to the end of the payload. Reset
44
+ * names and set entries are both written in ascending name byte order.
45
+ */
46
+ export const UPDATE_RESOURCE = {
47
+ code: COMMAND_CODE.UpdateResource,
48
+ serialize: ({ target, options = [], reset = [], rawOptions = [], rawReset = [] }) => {
49
+ const set = sortOptions(dedupeOptions([...rawOptions, ...options]));
50
+ const resetKeys = [...new Set([...reset, ...rawReset])]
51
+ .sort((left, right) => Buffer.compare(Buffer.from(left), Buffer.from(right)));
52
+ checkPatch(target.scope, set, resetKeys, rawOptions.length > 0 || rawReset.length > 0);
53
+ const identifiers = target.scope === OptionsScope.Topic
54
+ ? [serializeIdentifier(target.streamId), serializeIdentifier(target.topicId)]
55
+ : [serializeIdentifier(target.scope === OptionsScope.Stream ? target.streamId : target.userId)];
56
+ return Buffer.concat([
57
+ uint8ToBuf(target.scope),
58
+ ...identifiers,
59
+ uint8ToBuf(resetKeys.length),
60
+ ...resetKeys.map((key) => {
61
+ const name = Buffer.from(key);
62
+ return Buffer.concat([uint8ToBuf(name.length), name]);
63
+ }),
64
+ serializeOptions(set)
65
+ ]);
66
+ },
67
+ deserialize: deserializeVoidResponse
68
+ };
69
+ /**
70
+ * A typed column value as an option entry. Text no header value can carry
71
+ * travels as a bool, a kind the column never accepts, so the refusal is the
72
+ * column's own error on either side.
73
+ */
74
+ export const columnOption = (key, text) => {
75
+ const length = Buffer.byteLength(text);
76
+ return {
77
+ key,
78
+ value: length >= 1 && length <= MAX_NAME_LENGTH ? HeaderValue.String(text) : HeaderValue.Bool(false)
79
+ };
80
+ };
81
+ /** Refuses a patch with the category and in the order the server admits it. */
82
+ const checkPatch = (scope, set, reset, raw) => {
83
+ const refuse = (code, detail) => {
84
+ throw responseError(COMMAND_CODE.UpdateResource, code, detail);
85
+ };
86
+ if (set.length === 0 && reset.length === 0)
87
+ refuse(INVALID_COMMAND, 'the update sets and resets nothing');
88
+ const conflict = reset.find((key) => set.some((entry) => entry.key === key));
89
+ if (conflict !== undefined)
90
+ refuse(INVALID_COMMAND, `key '${conflict}' is both set and reset`);
91
+ const nameLength = (key) => Buffer.byteLength(key);
92
+ // The catalog is far smaller than the count byte, so an overlong list always
93
+ // names a key admission would refuse.
94
+ const unwritable = reset.find((key) => nameLength(key) < 1 || nameLength(key) > MAX_NAME_LENGTH)
95
+ ?? (reset.length > MAX_RESET_KEYS
96
+ ? reset.find((key) => !OPTION_CATALOG.get(key)?.scopes.includes(scope))
97
+ : undefined);
98
+ if (unwritable !== undefined)
99
+ refuse(UNSUPPORTED_OPTION_KEY, `reset of '${unwritable.slice(0, KEY_PREVIEW_LENGTH)}'`);
100
+ if (raw)
101
+ return;
102
+ const keys = [...set.map((entry) => entry.key), ...reset];
103
+ const outOfScope = keys.find((key) => !OPTION_CATALOG.get(key)?.scopes.includes(scope));
104
+ if (outOfScope !== undefined)
105
+ refuse(UNSUPPORTED_OPTION_KEY, `key '${outOfScope}'`);
106
+ const first = (candidates, refused) => candidates.find((key) => {
107
+ const descriptor = OPTION_CATALOG.get(key);
108
+ return descriptor !== undefined && refused(descriptor);
109
+ });
110
+ const readOnly = first(keys, ({ flags, internal }) => internal || (flags & OptionFlag.ReadOnly) !== 0);
111
+ if (readOnly !== undefined)
112
+ refuse(READ_ONLY_OPTION, `key '${readOnly}'`);
113
+ const createOnly = first(keys, ({ flags }) => (flags & OptionFlag.Updatable) === 0);
114
+ if (createOnly !== undefined)
115
+ refuse(OPTION_NOT_UPDATABLE, `key '${createOnly}'`);
116
+ const fixed = first(reset, ({ flags }) => (flags & OptionFlag.Resettable) === 0);
117
+ if (fixed !== undefined)
118
+ refuse(OPTION_NOT_RESETTABLE, `reset of '${fixed}'`);
119
+ for (const { key, value } of set) {
120
+ const text = value.kind === HeaderKind.String ? value.value : undefined;
121
+ const length = text === undefined ? 0 : Buffer.byteLength(text);
122
+ if (key === 'name' && (length < 1 || length > MAX_NAME_LENGTH))
123
+ refuse(scope === OptionsScope.Topic ? INVALID_TOPIC_NAME : INVALID_STREAM_NAME, 'name');
124
+ if (key === 'username' && (length < MIN_USERNAME_LENGTH || length > MAX_USERNAME_LENGTH))
125
+ refuse(INVALID_USERNAME, 'username');
126
+ if (key === 'status' && text !== 'active' && text !== 'inactive')
127
+ refuse(INVALID_USER_STATUS, 'status');
128
+ }
129
+ };
130
+ //# sourceMappingURL=update-resource.command.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=update-resource.command.test.d.ts.map