camusdb 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -4
- package/dist/auth/rest-login-client.d.ts.map +1 -1
- package/dist/auth/rest-login-client.js +15 -1
- package/dist/auth/rest-login-client.js.map +1 -1
- package/dist/auth/token-provider.d.ts +14 -0
- package/dist/auth/token-provider.d.ts.map +1 -1
- package/dist/auth/token-provider.js +39 -11
- package/dist/auth/token-provider.js.map +1 -1
- package/dist/client.d.ts +24 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +78 -8
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +29 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +20 -0
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/json.d.ts.map +1 -1
- package/dist/json.js +42 -8
- package/dist/json.js.map +1 -1
- package/dist/own-record.d.ts +16 -0
- package/dist/own-record.d.ts.map +1 -0
- package/dist/own-record.js +18 -0
- package/dist/own-record.js.map +1 -0
- package/dist/query-stream.d.ts +4 -4
- package/dist/query-stream.js +4 -4
- package/dist/result-set.d.ts +4 -2
- package/dist/result-set.d.ts.map +1 -1
- package/dist/result-set.js +25 -8
- package/dist/result-set.js.map +1 -1
- package/dist/retry.d.ts +4 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +16 -4
- package/dist/retry.js.map +1 -1
- package/dist/runtime.js +2 -0
- package/dist/runtime.js.map +1 -1
- package/dist/sequence.d.ts +62 -0
- package/dist/sequence.d.ts.map +1 -0
- package/dist/sequence.js +70 -0
- package/dist/sequence.js.map +1 -0
- package/dist/sql-syntax.d.ts +21 -1
- package/dist/sql-syntax.d.ts.map +1 -1
- package/dist/sql-syntax.js +30 -1
- package/dist/sql-syntax.js.map +1 -1
- package/dist/statements.d.ts.map +1 -1
- package/dist/statements.js +5 -0
- package/dist/statements.js.map +1 -1
- package/dist/transport/grpc/batch-frames.d.ts +67 -0
- package/dist/transport/grpc/batch-frames.d.ts.map +1 -0
- package/dist/transport/grpc/batch-frames.js +111 -0
- package/dist/transport/grpc/batch-frames.js.map +1 -0
- package/dist/transport/grpc/batcher.d.ts +132 -3
- package/dist/transport/grpc/batcher.d.ts.map +1 -1
- package/dist/transport/grpc/batcher.js +389 -30
- package/dist/transport/grpc/batcher.js.map +1 -1
- package/dist/transport/grpc/grpc-transport.d.ts +8 -1
- package/dist/transport/grpc/grpc-transport.d.ts.map +1 -1
- package/dist/transport/grpc/grpc-transport.js +59 -8
- package/dist/transport/grpc/grpc-transport.js.map +1 -1
- package/dist/transport/grpc/messages.d.ts +18 -2
- package/dist/transport/grpc/messages.d.ts.map +1 -1
- package/dist/transport/grpc/messages.js +6 -0
- package/dist/transport/grpc/messages.js.map +1 -1
- package/dist/transport/grpc/proto.d.ts +1 -1
- package/dist/transport/grpc/proto.d.ts.map +1 -1
- package/dist/transport/grpc/proto.js.map +1 -1
- package/dist/transport/http.d.ts.map +1 -1
- package/dist/transport/http.js +5 -1
- package/dist/transport/http.js.map +1 -1
- package/dist/transport/ndjson-row-source.d.ts.map +1 -1
- package/dist/transport/ndjson-row-source.js +16 -3
- package/dist/transport/ndjson-row-source.js.map +1 -1
- package/dist/transport/rest-transport.d.ts.map +1 -1
- package/dist/transport/rest-transport.js +5 -2
- package/dist/transport/rest-transport.js.map +1 -1
- package/dist/transport/transport.d.ts +4 -3
- package/dist/transport/transport.d.ts.map +1 -1
- package/dist/transport/transport.js.map +1 -1
- package/dist/values/encode.d.ts.map +1 -1
- package/dist/values/encode.js +7 -2
- package/dist/values/encode.js.map +1 -1
- package/dist/values/typed.d.ts.map +1 -1
- package/dist/values/typed.js +22 -1
- package/dist/values/typed.js.map +1 -1
- package/dist/values/uuid.d.ts +7 -1
- package/dist/values/uuid.d.ts.map +1 -1
- package/dist/values/uuid.js +15 -6
- package/dist/values/uuid.js.map +1 -1
- package/package.json +1 -1
- package/proto/camus_sql.proto +39 -2
package/dist/retry.js
CHANGED
|
@@ -22,6 +22,8 @@ const RETRYABLE_CODES = new Set(['CADB0502', 'CADB0504', 'CADB0505']);
|
|
|
22
22
|
* would have committed on its second attempt.
|
|
23
23
|
*/
|
|
24
24
|
const RETRYABLE_MESSAGE_MARKERS = ['MustRetry', 'AlreadyLocked', 'commit returned Aborted'];
|
|
25
|
+
/** How far `isRetryable` walks a `cause` chain before it stops. */
|
|
26
|
+
const MAX_CAUSE_DEPTH = 16;
|
|
25
27
|
/**
|
|
26
28
|
* True when running the same work again may succeed.
|
|
27
29
|
*
|
|
@@ -31,9 +33,15 @@ const RETRYABLE_MESSAGE_MARKERS = ['MustRetry', 'AlreadyLocked', 'commit returne
|
|
|
31
33
|
* the same handle, which `CamusTransaction` does on its own.
|
|
32
34
|
*/
|
|
33
35
|
export function isRetryable(error) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
let current = error;
|
|
37
|
+
// A cause chain comes from outside the driver and can hold a cycle. The cap bounds the walk
|
|
38
|
+
// without a visited set; no real chain is anywhere near this deep.
|
|
39
|
+
for (let depth = 0; current != null && depth < MAX_CAUSE_DEPTH; depth++) {
|
|
40
|
+
const next = current.cause;
|
|
41
|
+
if (!CamusError.is(current)) {
|
|
42
|
+
current = next;
|
|
36
43
|
continue;
|
|
44
|
+
}
|
|
37
45
|
if (current.code === CamusErrorCode.FinalizeUnresolved)
|
|
38
46
|
return false;
|
|
39
47
|
if (RETRYABLE_CODES.has(current.code))
|
|
@@ -42,6 +50,7 @@ export function isRetryable(error) {
|
|
|
42
50
|
if (current.message.includes(marker))
|
|
43
51
|
return true;
|
|
44
52
|
}
|
|
53
|
+
current = next;
|
|
45
54
|
}
|
|
46
55
|
return false;
|
|
47
56
|
}
|
|
@@ -68,9 +77,12 @@ export async function withRetry(operation, options = {}) {
|
|
|
68
77
|
}
|
|
69
78
|
}
|
|
70
79
|
}
|
|
71
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* The back-off after attempt number `attempt`, in milliseconds. Exported so a caller can mirror the
|
|
82
|
+
* schedule. The first retry waits the documented 20 ms base, the second 40 ms, and so on.
|
|
83
|
+
*/
|
|
72
84
|
export function computeDelayMs(attempt) {
|
|
73
|
-
const base = Math.min(20 * 2 ** attempt, 400);
|
|
85
|
+
const base = Math.min(20 * 2 ** (attempt - 1), 400);
|
|
74
86
|
const jitter = base * 0.25 * (2 * Math.random() - 1);
|
|
75
87
|
return Math.max(1, base + jitter);
|
|
76
88
|
}
|
package/dist/retry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;GAOG;AAEH,oFAAoF;AACpF,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;AAEtE;;;;GAIG;AACH,MAAM,yBAAyB,GAAG,CAAC,WAAW,EAAE,eAAe,EAAE,yBAAyB,CAAC,CAAC;AAE5F;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;GAOG;AAEH,oFAAoF;AACpF,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;AAEtE;;;;GAIG;AACH,MAAM,yBAAyB,GA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IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/runtime.js
CHANGED
|
@@ -126,6 +126,8 @@ function transportKey(config, deployment) {
|
|
|
126
126
|
String(config.batch.channelPoolSize),
|
|
127
127
|
String(config.batch.coalescingThreshold),
|
|
128
128
|
String(config.batch.coalescingDelayMs),
|
|
129
|
+
String(config.batch.requestFrames),
|
|
130
|
+
String(config.batch.streamDrainTimeoutMs),
|
|
129
131
|
].join('|');
|
|
130
132
|
}
|
|
131
133
|
function isLoginClient(value) {
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpG,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE;;;;;;GAMG;AACH,MAAM,OAAO,aAAa;IACf,MAAM,CAAiB;IAEhC,iFAAiF;IACxE,IAAI,CAAoB;IAEjC,gGAAgG;IACvF,IAAI,CAAqB;IAElC,6EAA6E;IACpE,SAAS,CAAiB;IAEnC,8EAA8E;IACrE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AAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC;QACxC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC;QACtC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC;QAClC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC;KAC1C,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACd,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAQ,KAA0B,CAAC,KAAK,KAAK,UAAU;QACvD,OAAQ,KAA0B,CAAC,MAAM,KAAK,UAAU,CACzD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of CamusDB
|
|
3
|
+
*
|
|
4
|
+
* For the full copyright and license information, please view the LICENSE.txt
|
|
5
|
+
* file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The options of a `CREATE SEQUENCE`.
|
|
9
|
+
*
|
|
10
|
+
* A CamusDB sequence stores `int64` values only, has a positive increment, and never cycles. The
|
|
11
|
+
* server refuses `CYCLE` with `CADB0533`, because a wrapped counter would issue again the values
|
|
12
|
+
* that committed rows already hold, so there is no option for it here.
|
|
13
|
+
*/
|
|
14
|
+
export interface CamusSequenceOptions {
|
|
15
|
+
/** The first value `nextval` returns. The server default is the minimum. */
|
|
16
|
+
readonly startWith?: number | bigint | undefined;
|
|
17
|
+
/** The step between two values. It must be positive. The server default is 1. */
|
|
18
|
+
readonly incrementBy?: number | bigint | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The smallest value. Leave it out for the server default, 1. The statement never says
|
|
21
|
+
* `NO MINVALUE`, because the server reads that as the smallest 64-bit value, not as the default.
|
|
22
|
+
*/
|
|
23
|
+
readonly minValue?: number | bigint | undefined;
|
|
24
|
+
/** The largest value. Leave it out for the server default, the largest 64-bit value. */
|
|
25
|
+
readonly maxValue?: number | bigint | undefined;
|
|
26
|
+
/** Adds `IF NOT EXISTS`, so the statement does nothing when the sequence already exists. */
|
|
27
|
+
readonly ifNotExists?: boolean | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The statement that creates a sequence:
|
|
31
|
+
* `CREATE SEQUENCE [IF NOT EXISTS] name [START WITH …] [INCREMENT BY …] [MINVALUE …] [MAXVALUE …]`.
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* await client.executeDdl(createSequenceStatement('ticket_numbers', { startWith: 1000 }));
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @throws {TypeError} when the name cannot be delimited, when a value is not an integer, or when
|
|
38
|
+
* the increment is not positive.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createSequenceStatement(name: string, options?: CamusSequenceOptions): string;
|
|
41
|
+
/**
|
|
42
|
+
* The statement that drops a sequence: `DROP SEQUENCE [IF EXISTS] name`.
|
|
43
|
+
*
|
|
44
|
+
* @throws {TypeError} when the name cannot be delimited.
|
|
45
|
+
*/
|
|
46
|
+
export declare function dropSequenceStatement(name: string, options?: {
|
|
47
|
+
ifExists?: boolean;
|
|
48
|
+
}): string;
|
|
49
|
+
/**
|
|
50
|
+
* The expression that draws the next value of a sequence: `nextval('name')`. Use it in the value
|
|
51
|
+
* list of an `INSERT`, or as a column default. A column default needs parentheses:
|
|
52
|
+
* `DEFAULT (nextval('name'))`.
|
|
53
|
+
*
|
|
54
|
+
* The name is a string argument, not an identifier, so it is quoted as a literal. It must still be
|
|
55
|
+
* a name that a `CREATE SEQUENCE` can delimit.
|
|
56
|
+
*
|
|
57
|
+
* @throws {TypeError} when the name cannot be a sequence name.
|
|
58
|
+
*/
|
|
59
|
+
export declare function nextValueExpression(name: string): string;
|
|
60
|
+
/** The statement that draws one value: a `SELECT` with no `FROM`, which the server accepts. */
|
|
61
|
+
export declare function selectNextValueStatement(name: string): string;
|
|
62
|
+
//# sourceMappingURL=sequence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAEjD,iFAAiF;IACjF,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAEnD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAEhD,wFAAwF;IACxF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAEhD,4FAA4F;IAC5F,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC5C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,MAAM,CAqBhG;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,MAAM,CAEhG;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGxD;AAED,+FAA+F;AAC/F,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7D"}
|
package/dist/sequence.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of CamusDB
|
|
3
|
+
*
|
|
4
|
+
* For the full copyright and license information, please view the LICENSE.txt
|
|
5
|
+
* file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
import { delimitIdentifier, sqlLiteral, validateIdentifier } from './sql-syntax.js';
|
|
8
|
+
/**
|
|
9
|
+
* The statement that creates a sequence:
|
|
10
|
+
* `CREATE SEQUENCE [IF NOT EXISTS] name [START WITH …] [INCREMENT BY …] [MINVALUE …] [MAXVALUE …]`.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* await client.executeDdl(createSequenceStatement('ticket_numbers', { startWith: 1000 }));
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @throws {TypeError} when the name cannot be delimited, when a value is not an integer, or when
|
|
17
|
+
* the increment is not positive.
|
|
18
|
+
*/
|
|
19
|
+
export function createSequenceStatement(name, options = {}) {
|
|
20
|
+
let sql = `CREATE SEQUENCE ${options.ifNotExists === true ? 'IF NOT EXISTS ' : ''}${delimitIdentifier(name, 'name')}`;
|
|
21
|
+
if (options.startWith !== undefined)
|
|
22
|
+
sql += ` START WITH ${integer(options.startWith, 'startWith')}`;
|
|
23
|
+
if (options.incrementBy !== undefined) {
|
|
24
|
+
const increment = integer(options.incrementBy, 'incrementBy');
|
|
25
|
+
if (BigInt(increment) <= 0n) {
|
|
26
|
+
throw new TypeError(`A CamusDB sequence needs a positive increment; got ${increment} for sequence '${name}'.`);
|
|
27
|
+
}
|
|
28
|
+
sql += ` INCREMENT BY ${increment}`;
|
|
29
|
+
}
|
|
30
|
+
if (options.minValue !== undefined)
|
|
31
|
+
sql += ` MINVALUE ${integer(options.minValue, 'minValue')}`;
|
|
32
|
+
if (options.maxValue !== undefined)
|
|
33
|
+
sql += ` MAXVALUE ${integer(options.maxValue, 'maxValue')}`;
|
|
34
|
+
return sql;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The statement that drops a sequence: `DROP SEQUENCE [IF EXISTS] name`.
|
|
38
|
+
*
|
|
39
|
+
* @throws {TypeError} when the name cannot be delimited.
|
|
40
|
+
*/
|
|
41
|
+
export function dropSequenceStatement(name, options = {}) {
|
|
42
|
+
return `DROP SEQUENCE ${options.ifExists === true ? 'IF EXISTS ' : ''}${delimitIdentifier(name, 'name')}`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The expression that draws the next value of a sequence: `nextval('name')`. Use it in the value
|
|
46
|
+
* list of an `INSERT`, or as a column default. A column default needs parentheses:
|
|
47
|
+
* `DEFAULT (nextval('name'))`.
|
|
48
|
+
*
|
|
49
|
+
* The name is a string argument, not an identifier, so it is quoted as a literal. It must still be
|
|
50
|
+
* a name that a `CREATE SEQUENCE` can delimit.
|
|
51
|
+
*
|
|
52
|
+
* @throws {TypeError} when the name cannot be a sequence name.
|
|
53
|
+
*/
|
|
54
|
+
export function nextValueExpression(name) {
|
|
55
|
+
validateIdentifier(name, 'name');
|
|
56
|
+
return `nextval(${sqlLiteral(name, `sequence name '${name}'`)})`;
|
|
57
|
+
}
|
|
58
|
+
/** The statement that draws one value: a `SELECT` with no `FROM`, which the server accepts. */
|
|
59
|
+
export function selectNextValueStatement(name) {
|
|
60
|
+
return `SELECT ${nextValueExpression(name)}`;
|
|
61
|
+
}
|
|
62
|
+
function integer(value, option) {
|
|
63
|
+
if (typeof value === 'bigint')
|
|
64
|
+
return value.toString();
|
|
65
|
+
if (!Number.isSafeInteger(value)) {
|
|
66
|
+
throw new TypeError(`The sequence option '${option}' needs a safe integer or a bigint; got ${String(value)}.`);
|
|
67
|
+
}
|
|
68
|
+
return String(value);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=sequence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sequence.js","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AA6BpF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAY,EAAE,U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,IAAY;IAC9C,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACjC,OAAO,WAAW,UAAU,CAAC,IAAI,EAAE,kBAAkB,IAAI,GAAG,CAAC,GAAG,CAAC;AACnE,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,wBAAwB,CAAC,IAAY;IACnD,OAAO,UAAU,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;AAC/C,CAAC;AAED,SAAS,OAAO,CAAC,KAAsB,EAAE,MAAc;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IAEvD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,SAAS,CACjB,wBAAwB,MAAM,2CAA2C,MAAM,CAAC,KAAK,CAAC,GAAG,CAC1F,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
package/dist/sql-syntax.d.ts
CHANGED
|
@@ -34,8 +34,28 @@ export declare function validateSqlLiteral(value: string, target: string): void;
|
|
|
34
34
|
* out of its quoting.
|
|
35
35
|
*/
|
|
36
36
|
export declare function delimitIdentifier(identifier: string, parameterName: string): string;
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Refuses an identifier that cannot be delimited.
|
|
39
|
+
*
|
|
40
|
+
* A trailing backslash is refused for the reason `validateSqlLiteral` refuses one: CamusDB's lexer
|
|
41
|
+
* reads a backslash and the character after it as one unit, so the backslash would consume the
|
|
42
|
+
* closing backtick and the identifier would run into the text after it.
|
|
43
|
+
*/
|
|
38
44
|
export declare function validateIdentifier(identifier: string, parameterName: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* True when a string can serve as a database name.
|
|
47
|
+
*
|
|
48
|
+
* The name travels as a request field rather than as SQL text, so there is no injection to close
|
|
49
|
+
* here. What the test protects is the cache keys: the prepared-statement policy, the gRPC batcher,
|
|
50
|
+
* and the REST prepared-statement cache each join a database name and a statement with a newline,
|
|
51
|
+
* and each states that a database name holds no newline. A name that held one would make two
|
|
52
|
+
* distinct pairs collide on one key. Every control character is refused, not the newline alone,
|
|
53
|
+
* because none of them names a database.
|
|
54
|
+
*
|
|
55
|
+
* It reports a verdict rather than throwing, because the two call sites raise different error
|
|
56
|
+
* types: a configuration failure is a `CamusError`, and a bad argument is a `TypeError`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function isValidDatabaseName(database: string): boolean;
|
|
39
59
|
/**
|
|
40
60
|
* Refuses a name that is emitted into SQL as bare text and therefore cannot be escaped at all.
|
|
41
61
|
* Letters, digits, and `_ - . :` are allowed.
|
package/dist/sql-syntax.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-syntax.d.ts","sourceRoot":"","sources":["../src/sql-syntax.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AAEH;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAGhE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAoBtE;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAGnF;AAED
|
|
1
|
+
{"version":3,"file":"sql-syntax.d.ts","sourceRoot":"","sources":["../src/sql-syntax.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AAEH;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAGhE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAoBtE;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAGnF;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI,CAiBlF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAK7D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI,CAmB7F"}
|
package/dist/sql-syntax.js
CHANGED
|
@@ -53,7 +53,13 @@ export function delimitIdentifier(identifier, parameterName) {
|
|
|
53
53
|
validateIdentifier(identifier, parameterName);
|
|
54
54
|
return `\`${identifier}\``;
|
|
55
55
|
}
|
|
56
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Refuses an identifier that cannot be delimited.
|
|
58
|
+
*
|
|
59
|
+
* A trailing backslash is refused for the reason `validateSqlLiteral` refuses one: CamusDB's lexer
|
|
60
|
+
* reads a backslash and the character after it as one unit, so the backslash would consume the
|
|
61
|
+
* closing backtick and the identifier would run into the text after it.
|
|
62
|
+
*/
|
|
57
63
|
export function validateIdentifier(identifier, parameterName) {
|
|
58
64
|
if (identifier.trim().length === 0) {
|
|
59
65
|
throw new TypeError(`An identifier cannot be empty (${parameterName}).`);
|
|
@@ -61,6 +67,29 @@ export function validateIdentifier(identifier, parameterName) {
|
|
|
61
67
|
if (identifier.includes('`')) {
|
|
62
68
|
throw new TypeError(`The identifier '${identifier}' holds a backtick, which CamusDB cannot quote (${parameterName}).`);
|
|
63
69
|
}
|
|
70
|
+
if (identifier.endsWith('\\')) {
|
|
71
|
+
throw new TypeError(`The identifier '${identifier}' ends with a backslash (${parameterName}). CamusDB's lexer reads a ` +
|
|
72
|
+
'backslash and the character after it as one unit, so the backslash would consume the closing backtick.');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* True when a string can serve as a database name.
|
|
77
|
+
*
|
|
78
|
+
* The name travels as a request field rather than as SQL text, so there is no injection to close
|
|
79
|
+
* here. What the test protects is the cache keys: the prepared-statement policy, the gRPC batcher,
|
|
80
|
+
* and the REST prepared-statement cache each join a database name and a statement with a newline,
|
|
81
|
+
* and each states that a database name holds no newline. A name that held one would make two
|
|
82
|
+
* distinct pairs collide on one key. Every control character is refused, not the newline alone,
|
|
83
|
+
* because none of them names a database.
|
|
84
|
+
*
|
|
85
|
+
* It reports a verdict rather than throwing, because the two call sites raise different error
|
|
86
|
+
* types: a configuration failure is a `CamusError`, and a bad argument is a `TypeError`.
|
|
87
|
+
*/
|
|
88
|
+
export function isValidDatabaseName(database) {
|
|
89
|
+
if (database.trim().length === 0)
|
|
90
|
+
return false;
|
|
91
|
+
// eslint-disable-next-line no-control-regex -- the point of the test is to find these characters.
|
|
92
|
+
return !/[\u0000-\u001f\u007f]/.test(database);
|
|
64
93
|
}
|
|
65
94
|
/**
|
|
66
95
|
* Refuses a name that is emitted into SQL as bare text and therefore cannot be escaped at all.
|
package/dist/sql-syntax.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-syntax.js","sourceRoot":"","sources":["../src/sql-syntax.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,MAAc;IACtD,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAClC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;AAC5C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa,EAAE,MAAc;IAC9D,IAAI,KAA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gB;IAClD,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAE/C,kGAAkG;IAClG,OAAO,CAAC,uBAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,SAAiB,EAAE,aAAqB;IACrF,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,SAAS,CAAC,IAAI,aAAa,oBAAoB,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;QAC5B,MAAM,IAAI,SAAS,CACjB,IAAI,aAAa,QAAQ,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAwB,MAAM,CAAC,SAAS,CAAC,eAAe,CACrG,CAAC;IACJ,CAAC;IAED,KAAK,MAAM,SAAS,IAAI,IAAI,EAAE,CAAC;QAC7B,IAAI,qBAAqB,CAAC,IAAI,CAAC,SAAS,CAAC;YAAE,SAAS;QAEpD,MAAM,IAAI,SAAS,CACjB,IAAI,aAAa,0BAA0B,SAAS,gDAAgD;YAClG,iFAAiF,CACpF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/statements.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../src/statements.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../src/statements.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqEH,qDAAqD;AACrD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED,gEAAgE;AAChE,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED,yEAAyE;AACzE,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED,yEAAyE;AACzE,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEzD"}
|
package/dist/statements.js
CHANGED
|
@@ -43,6 +43,11 @@ const DDL_PREFIXES = [
|
|
|
43
43
|
'CREATE MATERIALIZED VIEW',
|
|
44
44
|
'DROP MATERIALIZED VIEW',
|
|
45
45
|
'ALTER MATERIALIZED VIEW',
|
|
46
|
+
// Sequences. ALTER SEQUENCE covers both the option form and RENAME TO. COMMENT ON SEQUENCE is
|
|
47
|
+
// absent, as COMMENT ON is for every other object: the data route handles it itself.
|
|
48
|
+
'CREATE SEQUENCE',
|
|
49
|
+
'DROP SEQUENCE',
|
|
50
|
+
'ALTER SEQUENCE',
|
|
46
51
|
];
|
|
47
52
|
const DML_PREFIXES = ['INSERT', 'UPDATE', 'DELETE'];
|
|
48
53
|
/**
|
package/dist/statements.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statements.js","sourceRoot":"","sources":["../src/statements.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;GAOG;AAEH;;;;;;;;;GASG;AACH,MAAM,YAAY,GAAG;IACnB,cAAc;IACd,YAAY;IACZ,aAAa;IACb,gGAAgG;IAChG,iGAAiG;IACjG,+CAA+C;IAC/C,UAAU;IACV,qBAAqB;IACrB,cAAc;IACd,YAAY;IACZ,6FAA6F;IAC7F,+FAA+F;IAC/F,6EAA6E;IAC7E,aAAa;IACb,wBAAwB;IACxB,WAAW;IACX,YAAY;IACZ,0BAA0B;IAC1B,wBAAwB;IACxB,yBAAyB;
|
|
1
|
+
{"version":3,"file":"statements.js","sourceRoot":"","sources":["../src/statements.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;GAOG;AAEH;;;;;;;;;GASG;AACH,MAAM,YAAY,GAAG;IACnB,cAAc;IACd,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AAI,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM;YAAE,SAAS;QAE7C,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;IAC5E,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of CamusDB
|
|
3
|
+
*
|
|
4
|
+
* For the full copyright and license information, please view the LICENSE.txt
|
|
5
|
+
* file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
import type { GrpcBatchExecuteRequest } from './messages.js';
|
|
8
|
+
/**
|
|
9
|
+
* The `BatchExecute` stream frame contract.
|
|
10
|
+
*
|
|
11
|
+
* A frame is one stream message that carries several complete operations, on the request side, or
|
|
12
|
+
* several complete responses, on the response side. The fixed cost of a stream message is then
|
|
13
|
+
* paid once per frame rather than once per operation or per row. A frame gives no atomicity and
|
|
14
|
+
* no ordering that the stream does not already give.
|
|
15
|
+
*
|
|
16
|
+
* The server keeps the same constants. The two must agree, as the two copies of `camus_sql.proto`
|
|
17
|
+
* must.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The response header a server writes when a stream opens to say that it reads request frames.
|
|
21
|
+
* The value is the highest contract version the server reads.
|
|
22
|
+
*
|
|
23
|
+
* A server built before frames writes nothing, and runs an unknown kind as a non-query. A client
|
|
24
|
+
* therefore waits for this announcement and never probes for it.
|
|
25
|
+
*/
|
|
26
|
+
export declare const FRAME_HEADER = "camusdb-batch-frames";
|
|
27
|
+
/**
|
|
28
|
+
* The request header a client writes when it opens a stream to say that it reads response frames.
|
|
29
|
+
* The value is the highest contract version the client reads.
|
|
30
|
+
*
|
|
31
|
+
* Without it, a server knows the client reads frames only once a request frame arrives. A single
|
|
32
|
+
* caller sends no request frame, so one large read would stay at one message per row. A server
|
|
33
|
+
* built before frames ignores the header.
|
|
34
|
+
*/
|
|
35
|
+
export declare const FRAME_ACCEPT_HEADER = "camusdb-batch-frames-accept";
|
|
36
|
+
/** The contract version this client writes, and the highest it reads. */
|
|
37
|
+
export declare const FRAME_VERSION = 1;
|
|
38
|
+
/** The most operations one frame carries. A server refuses the operations past it. */
|
|
39
|
+
export declare const FRAME_MAX_ITEMS = 256;
|
|
40
|
+
/**
|
|
41
|
+
* The most serialized operation bytes one frame carries.
|
|
42
|
+
*
|
|
43
|
+
* It sits far below the 4 MiB default message limit of gRPC, and on purpose. A message over the
|
|
44
|
+
* limit of the transport is refused before it is parsed, which resets the stream that every other
|
|
45
|
+
* operation shares. The sender must never build one. An operation larger than this budget on its
|
|
46
|
+
* own travels as a plain single message.
|
|
47
|
+
*/
|
|
48
|
+
export declare const FRAME_MAX_BYTES: number;
|
|
49
|
+
/**
|
|
50
|
+
* True when a header value announces a contract version this client writes.
|
|
51
|
+
*
|
|
52
|
+
* The whole value must be digits. `Number.parseInt` stops at the first character it cannot read,
|
|
53
|
+
* so it would read `1x` as version 1 and treat a header this client does not understand as an
|
|
54
|
+
* announcement.
|
|
55
|
+
*/
|
|
56
|
+
export declare function announcesFrames(value: string | undefined): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* An upper bound on the bytes one operation adds to a frame.
|
|
59
|
+
*
|
|
60
|
+
* `@grpc/proto-loader` builds a message as a plain object, which carries no serialized size. An
|
|
61
|
+
* exact figure costs a second serialization of every payload, and a large value now travels this
|
|
62
|
+
* path. The budget sits at a quarter of the message limit, so a generous estimate is the cheaper
|
|
63
|
+
* side of the trade: it fills a frame less than it could, and it never builds one the transport
|
|
64
|
+
* refuses.
|
|
65
|
+
*/
|
|
66
|
+
export declare function frameCost(request: GrpcBatchExecuteRequest): number;
|
|
67
|
+
//# sourceMappingURL=batch-frames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-frames.d.ts","sourceRoot":"","sources":["../../../src/transport/grpc/batch-frames.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAA6B,MAAM,eAAe,CAAC;AAExF;;;;;;;;;;GAUG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,yBAAyB,CAAC;AAEnD;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,gCAAgC,CAAC;AAEjE,yEAAyE;AACzE,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,sFAAsF;AACtF,eAAO,MAAM,eAAe,MAAM,CAAC;AAEnC;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,QAAc,CAAC;AAE3C;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAQlE;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,uBAAuB,GAAG,MAAM,CAElE"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of CamusDB
|
|
3
|
+
*
|
|
4
|
+
* For the full copyright and license information, please view the LICENSE.txt
|
|
5
|
+
* file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The `BatchExecute` stream frame contract.
|
|
9
|
+
*
|
|
10
|
+
* A frame is one stream message that carries several complete operations, on the request side, or
|
|
11
|
+
* several complete responses, on the response side. The fixed cost of a stream message is then
|
|
12
|
+
* paid once per frame rather than once per operation or per row. A frame gives no atomicity and
|
|
13
|
+
* no ordering that the stream does not already give.
|
|
14
|
+
*
|
|
15
|
+
* The server keeps the same constants. The two must agree, as the two copies of `camus_sql.proto`
|
|
16
|
+
* must.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* The response header a server writes when a stream opens to say that it reads request frames.
|
|
20
|
+
* The value is the highest contract version the server reads.
|
|
21
|
+
*
|
|
22
|
+
* A server built before frames writes nothing, and runs an unknown kind as a non-query. A client
|
|
23
|
+
* therefore waits for this announcement and never probes for it.
|
|
24
|
+
*/
|
|
25
|
+
export const FRAME_HEADER = 'camusdb-batch-frames';
|
|
26
|
+
/**
|
|
27
|
+
* The request header a client writes when it opens a stream to say that it reads response frames.
|
|
28
|
+
* The value is the highest contract version the client reads.
|
|
29
|
+
*
|
|
30
|
+
* Without it, a server knows the client reads frames only once a request frame arrives. A single
|
|
31
|
+
* caller sends no request frame, so one large read would stay at one message per row. A server
|
|
32
|
+
* built before frames ignores the header.
|
|
33
|
+
*/
|
|
34
|
+
export const FRAME_ACCEPT_HEADER = 'camusdb-batch-frames-accept';
|
|
35
|
+
/** The contract version this client writes, and the highest it reads. */
|
|
36
|
+
export const FRAME_VERSION = 1;
|
|
37
|
+
/** The most operations one frame carries. A server refuses the operations past it. */
|
|
38
|
+
export const FRAME_MAX_ITEMS = 256;
|
|
39
|
+
/**
|
|
40
|
+
* The most serialized operation bytes one frame carries.
|
|
41
|
+
*
|
|
42
|
+
* It sits far below the 4 MiB default message limit of gRPC, and on purpose. A message over the
|
|
43
|
+
* limit of the transport is refused before it is parsed, which resets the stream that every other
|
|
44
|
+
* operation shares. The sender must never build one. An operation larger than this budget on its
|
|
45
|
+
* own travels as a plain single message.
|
|
46
|
+
*/
|
|
47
|
+
export const FRAME_MAX_BYTES = 1024 * 1024;
|
|
48
|
+
/**
|
|
49
|
+
* True when a header value announces a contract version this client writes.
|
|
50
|
+
*
|
|
51
|
+
* The whole value must be digits. `Number.parseInt` stops at the first character it cannot read,
|
|
52
|
+
* so it would read `1x` as version 1 and treat a header this client does not understand as an
|
|
53
|
+
* announcement.
|
|
54
|
+
*/
|
|
55
|
+
export function announcesFrames(value) {
|
|
56
|
+
if (value === undefined)
|
|
57
|
+
return false;
|
|
58
|
+
const text = value.trim();
|
|
59
|
+
if (!/^\d+$/.test(text))
|
|
60
|
+
return false;
|
|
61
|
+
return Number(text) >= FRAME_VERSION;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* An upper bound on the bytes one operation adds to a frame.
|
|
65
|
+
*
|
|
66
|
+
* `@grpc/proto-loader` builds a message as a plain object, which carries no serialized size. An
|
|
67
|
+
* exact figure costs a second serialization of every payload, and a large value now travels this
|
|
68
|
+
* path. The budget sits at a quarter of the message limit, so a generous estimate is the cheaper
|
|
69
|
+
* side of the trade: it fills a frame less than it could, and it never builds one the transport
|
|
70
|
+
* refuses.
|
|
71
|
+
*/
|
|
72
|
+
export function frameCost(request) {
|
|
73
|
+
return ENVELOPE_BYTES + MESSAGE_BYTES + sqlRequestCost(request.request);
|
|
74
|
+
}
|
|
75
|
+
/** What a protobuf tag and a length prefix add around one nested message or one string. */
|
|
76
|
+
const ENVELOPE_BYTES = 8;
|
|
77
|
+
/** What a message of small scalar fields costs. Generous on purpose. */
|
|
78
|
+
const MESSAGE_BYTES = 32;
|
|
79
|
+
function sqlRequestCost(request) {
|
|
80
|
+
if (request === undefined)
|
|
81
|
+
return 0;
|
|
82
|
+
let cost = MESSAGE_BYTES + textCost(request.database) + textCost(request.sql);
|
|
83
|
+
if (request.parameters !== undefined) {
|
|
84
|
+
for (const [name, value] of Object.entries(request.parameters)) {
|
|
85
|
+
cost += MESSAGE_BYTES + textCost(name) + valueCost(value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (request.positionalParameters !== undefined) {
|
|
89
|
+
for (const value of request.positionalParameters)
|
|
90
|
+
cost += valueCost(value);
|
|
91
|
+
}
|
|
92
|
+
return cost;
|
|
93
|
+
}
|
|
94
|
+
function valueCost(value) {
|
|
95
|
+
let cost = MESSAGE_BYTES;
|
|
96
|
+
cost += textCost(value.stringValue);
|
|
97
|
+
cost += bytesCost(value.bytesValue);
|
|
98
|
+
cost += bytesCost(value.uuidValue);
|
|
99
|
+
if (value.arrayValue !== undefined) {
|
|
100
|
+
for (const item of value.arrayValue.items)
|
|
101
|
+
cost += valueCost(item);
|
|
102
|
+
}
|
|
103
|
+
return cost;
|
|
104
|
+
}
|
|
105
|
+
function textCost(text) {
|
|
106
|
+
return text === undefined ? 0 : ENVELOPE_BYTES + Buffer.byteLength(text, 'utf8');
|
|
107
|
+
}
|
|
108
|
+
function bytesCost(bytes) {
|
|
109
|
+
return bytes === undefined ? 0 : ENVELOPE_BYTES + bytes.length;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=batch-frames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-frames.js","sourceRoot":"","sources":["../../../src/transport/grpc/batch-frames.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;;GAUG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,sBAAsB,CAAC;AAEnD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,6BAA6B,CAAC;AAEjE,yEAAyE;AACzE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAE/B,sFAAsF;AACtF,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAC;AAEnC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,GAAG,IAAI,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAyB;IACvD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAEtC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAE1B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAEtC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC;AACvC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,OAAgC;IACxD,OAAO,cAAc,GAAG,aAAa,GAAG,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC1E,CAAC;AAED,2FAA2F;AAC3F,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB,wEA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