Skip to content

Commit 81304b8

Browse files
authored
Added exactOptionalPropertyTypes TS option (#77)
1 parent 8841d71 commit 81304b8

File tree

6 files changed

+143
-172
lines changed

6 files changed

+143
-172
lines changed

lib/directory.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,16 +500,16 @@ export class Directory<KeyIn = NativeValue, KeyOut = Buffer, ValIn = NativeValue
500500

501501
interface DirectoryLayerOpts {
502502
/** The prefix for directory metadata nodes. Defaults to '\xfe' */
503-
nodePrefix?: string | Buffer
503+
nodePrefix?: undefined | string | Buffer
504504
// We really actually want a NodeSubspace here, but we'll set the kv encoding
505505
// ourselves to make the API simpler.
506-
nodeSubspace?: SubspaceAny
507-
506+
nodeSubspace?: undefined | SubspaceAny
507+
508508
/** The prefix for content. Defaults to ''. */
509-
contentPrefix?: string | Buffer // Defaults to '', the root.
510-
contentSubspace?: SubspaceAny
509+
contentPrefix?: undefined | string | Buffer // Defaults to '', the root.
510+
contentSubspace?: undefined | SubspaceAny
511511

512-
allowManualPrefixes?: boolean // default false
512+
allowManualPrefixes?: undefined | boolean // default false
513513
}
514514

515515
export class DirectoryLayer {

lib/opts.g.ts

Lines changed: 111 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,51 @@
22
import {OptionData} from './opts'
33

44
export type NetworkOptions = {
5-
local_address?: string // DEPRECATED
6-
cluster_file?: string // DEPRECATED
7-
trace_enable?: string // path to output directory (or NULL for current working directory)
8-
trace_roll_size?: number // max size of a single trace output file
9-
trace_max_logs_size?: number // max total size of trace files
10-
trace_log_group?: string // value of the LogGroup attribute
11-
trace_format?: string // Format of trace files
12-
trace_clock_source?: string // Trace clock source
13-
trace_file_identifier?: string // The identifier that will be part of all trace file names
14-
trace_share_among_client_threads?: true
15-
trace_partial_file_suffix?: string // Append this suffix to partially written log files. When a log file is complete, it is renamed to remove the suffix. No separator is added between the file and the suffix. If you want to add a file extension, you should include the separator - e.g. '.tmp' instead of 'tmp' to add the 'tmp' extension.
16-
knob?: string // knob_name=knob_value
17-
TLS_plugin?: string // DEPRECATED
18-
TLS_cert_bytes?: Buffer // certificates
19-
TLS_cert_path?: string // file path
20-
TLS_key_bytes?: Buffer // key
21-
TLS_key_path?: string // file path
22-
TLS_verify_peers?: Buffer // verification pattern
23-
Buggify_enable?: true
24-
Buggify_disable?: true
25-
Buggify_section_activated_probability?: number // probability expressed as a percentage between 0 and 100
26-
Buggify_section_fired_probability?: number // probability expressed as a percentage between 0 and 100
27-
TLS_ca_bytes?: Buffer // ca bundle
28-
TLS_ca_path?: string // file path
29-
TLS_password?: string // key passphrase
30-
disable_multi_version_client_api?: true
31-
callbacks_on_external_threads?: true
32-
external_client_library?: string // path to client library
33-
external_client_directory?: string // path to directory containing client libraries
34-
disable_local_client?: true
35-
client_threads_per_version?: number // Number of client threads to be spawned. Each cluster will be serviced by a single client thread.
36-
future_version_client_library?: string // path to client library
37-
disable_client_statistics_logging?: true
38-
enable_slow_task_profiling?: true // DEPRECATED
39-
enable_run_loop_profiling?: true
40-
disable_client_bypass?: true
41-
client_buggify_enable?: true
42-
client_buggify_disable?: true
43-
client_buggify_section_activated_probability?: number // probability expressed as a percentage between 0 and 100
44-
client_buggify_section_fired_probability?: number // probability expressed as a percentage between 0 and 100
45-
distributed_client_tracer?: string // Distributed tracer type. Choose from none, log_file, or network_lossy
46-
client_tmp_dir?: string // Client directory for temporary files.
47-
supported_client_versions?: string // [release version],[source version],[protocol version];...
48-
external_client?: true
49-
external_client_transport_id?: number // Transport ID for the child connection
5+
local_address?: undefined | string // DEPRECATED
6+
cluster_file?: undefined | string // DEPRECATED
7+
trace_enable?: undefined | string // path to output directory (or NULL for current working directory)
8+
trace_roll_size?: undefined | number // max size of a single trace output file
9+
trace_max_logs_size?: undefined | number // max total size of trace files
10+
trace_log_group?: undefined | string // value of the LogGroup attribute
11+
trace_format?: undefined | string // Format of trace files
12+
trace_clock_source?: undefined | string // Trace clock source
13+
trace_file_identifier?: undefined | string // The identifier that will be part of all trace file names
14+
trace_share_among_client_threads?: undefined | true
15+
trace_partial_file_suffix?: undefined | string // Append this suffix to partially written log files. When a log file is complete, it is renamed to remove the suffix. No separator is added between the file and the suffix. If you want to add a file extension, you should include the separator - e.g. '.tmp' instead of 'tmp' to add the 'tmp' extension.
16+
knob?: undefined | string // knob_name=knob_value
17+
TLS_plugin?: undefined | string // DEPRECATED
18+
TLS_cert_bytes?: undefined | Buffer // certificates
19+
TLS_cert_path?: undefined | string // file path
20+
TLS_key_bytes?: undefined | Buffer // key
21+
TLS_key_path?: undefined | string // file path
22+
TLS_verify_peers?: undefined | Buffer // verification pattern
23+
Buggify_enable?: undefined | true
24+
Buggify_disable?: undefined | true
25+
Buggify_section_activated_probability?: undefined | number // probability expressed as a percentage between 0 and 100
26+
Buggify_section_fired_probability?: undefined | number // probability expressed as a percentage between 0 and 100
27+
TLS_ca_bytes?: undefined | Buffer // ca bundle
28+
TLS_ca_path?: undefined | string // file path
29+
TLS_password?: undefined | string // key passphrase
30+
disable_multi_version_client_api?: undefined | true
31+
callbacks_on_external_threads?: undefined | true
32+
external_client_library?: undefined | string // path to client library
33+
external_client_directory?: undefined | string // path to directory containing client libraries
34+
disable_local_client?: undefined | true
35+
client_threads_per_version?: undefined | number // Number of client threads to be spawned. Each cluster will be serviced by a single client thread.
36+
future_version_client_library?: undefined | string // path to client library
37+
disable_client_statistics_logging?: undefined | true
38+
enable_slow_task_profiling?: undefined | true // DEPRECATED
39+
enable_run_loop_profiling?: undefined | true
40+
disable_client_bypass?: undefined | true
41+
client_buggify_enable?: undefined | true
42+
client_buggify_disable?: undefined | true
43+
client_buggify_section_activated_probability?: undefined | number // probability expressed as a percentage between 0 and 100
44+
client_buggify_section_fired_probability?: undefined | number // probability expressed as a percentage between 0 and 100
45+
distributed_client_tracer?: undefined | string // Distributed tracer type. Choose from none, log_file, or network_lossy
46+
client_tmp_dir?: undefined | string // Client directory for temporary files.
47+
supported_client_versions?: undefined | string // [release version],[source version],[protocol version];...
48+
external_client?: undefined | true
49+
external_client_transport_id?: undefined | number // Transport ID for the child connection
5050
}
5151

5252
export enum NetworkOptionCode {
@@ -310,23 +310,23 @@ export enum NetworkOptionCode {
310310
}
311311

312312
export type DatabaseOptions = {
313-
location_cache_size?: number // Max location cache entries
314-
max_watches?: number // Max outstanding watches
315-
machine_id?: string // Hexadecimal ID
316-
datacenter_id?: string // Hexadecimal ID
317-
snapshot_ryw_enable?: true
318-
snapshot_ryw_disable?: true
319-
transaction_logging_max_field_length?: number // Maximum length of escaped key and value fields.
320-
transaction_timeout?: number // value in milliseconds of timeout
321-
transaction_retry_limit?: number // number of times to retry
322-
transaction_max_retry_delay?: number // value in milliseconds of maximum delay
323-
transaction_size_limit?: number // value in bytes
324-
transaction_causal_read_risky?: true
325-
transaction_include_port_in_address?: true
326-
transaction_automatic_idempotency?: true
327-
transaction_bypass_unreadable?: true
328-
use_config_database?: true
329-
test_causal_read_risky?: true
313+
location_cache_size?: undefined | number // Max location cache entries
314+
max_watches?: undefined | number // Max outstanding watches
315+
machine_id?: undefined | string // Hexadecimal ID
316+
datacenter_id?: undefined | string // Hexadecimal ID
317+
snapshot_ryw_enable?: undefined | true
318+
snapshot_ryw_disable?: undefined | true
319+
transaction_logging_max_field_length?: undefined | number // Maximum length of escaped key and value fields.
320+
transaction_timeout?: undefined | number // value in milliseconds of timeout
321+
transaction_retry_limit?: undefined | number // number of times to retry
322+
transaction_max_retry_delay?: undefined | number // value in milliseconds of maximum delay
323+
transaction_size_limit?: undefined | number // value in bytes
324+
transaction_causal_read_risky?: undefined | true
325+
transaction_include_port_in_address?: undefined | true
326+
transaction_automatic_idempotency?: undefined | true
327+
transaction_bypass_unreadable?: undefined | true
328+
use_config_database?: undefined | true
329+
test_causal_read_risky?: undefined | true
330330
}
331331

332332
export enum DatabaseOptionCode {
@@ -457,55 +457,55 @@ export enum DatabaseOptionCode {
457457
}
458458

459459
export type TransactionOptions = {
460-
causal_write_risky?: true
461-
causal_read_risky?: true
462-
causal_read_disable?: true
463-
include_port_in_address?: true
464-
next_write_no_write_conflict_range?: true
465-
commit_on_first_proxy?: true
466-
check_writes_enable?: true
467-
read_your_writes_disable?: true
468-
read_ahead_disable?: true // DEPRECATED
469-
durability_datacenter?: true
470-
durability_risky?: true
471-
durability_dev_null_is_web_scale?: true // DEPRECATED
472-
priority_system_immediate?: true
473-
priority_batch?: true
474-
initialize_new_database?: true
475-
access_system_keys?: true
476-
read_system_keys?: true
477-
raw_access?: true
478-
debug_dump?: true
479-
debug_retry_logging?: string // Optional transaction name
480-
transaction_logging_enable?: string // DEPRECATED
481-
debug_transaction_identifier?: string // String identifier to be used when tracing or profiling this transaction. The identifier must not exceed 100 characters.
482-
log_transaction?: true
483-
transaction_logging_max_field_length?: number // Maximum length of escaped key and value fields.
484-
server_request_tracing?: true
485-
timeout?: number // value in milliseconds of timeout
486-
retry_limit?: number // number of times to retry
487-
max_retry_delay?: number // value in milliseconds of maximum delay
488-
size_limit?: number // value in bytes
489-
idempotency_id?: string // Unique ID
490-
automatic_idempotency?: true
491-
snapshot_ryw_enable?: true
492-
snapshot_ryw_disable?: true
493-
lock_aware?: true
494-
used_during_commit_protection_disable?: true
495-
read_lock_aware?: true
496-
first_in_batch?: true
497-
use_provisional_proxies?: true
498-
report_conflicting_keys?: true
499-
special_key_space_relaxed?: true
500-
special_key_space_enable_writes?: true
501-
tag?: string // String identifier used to associated this transaction with a throttling group. Must not exceed 16 characters.
502-
auto_throttle_tag?: string // String identifier used to associated this transaction with a throttling group. Must not exceed 16 characters.
503-
span_parent?: Buffer // A byte string of length 16 used to associate the span of this transaction with a parent
504-
expensive_clear_cost_estimation_enable?: true
505-
bypass_unreadable?: true
506-
use_grv_cache?: true
507-
skip_grv_cache?: true
508-
authorization_token?: string // A JSON Web Token authorized to access data belonging to one or more tenants, indicated by 'tenants' claim of the token's payload.
460+
causal_write_risky?: undefined | true
461+
causal_read_risky?: undefined | true
462+
causal_read_disable?: undefined | true
463+
include_port_in_address?: undefined | true
464+
next_write_no_write_conflict_range?: undefined | true
465+
commit_on_first_proxy?: undefined | true
466+
check_writes_enable?: undefined | true
467+
read_your_writes_disable?: undefined | true
468+
read_ahead_disable?: undefined | true // DEPRECATED
469+
durability_datacenter?: undefined | true
470+
durability_risky?: undefined | true
471+
durability_dev_null_is_web_scale?: undefined | true // DEPRECATED
472+
priority_system_immediate?: undefined | true
473+
priority_batch?: undefined | true
474+
initialize_new_database?: undefined | true
475+
access_system_keys?: undefined | true
476+
read_system_keys?: undefined | true
477+
raw_access?: undefined | true
478+
debug_dump?: undefined | true
479+
debug_retry_logging?: undefined | string // Optional transaction name
480+
transaction_logging_enable?: undefined | string // DEPRECATED
481+
debug_transaction_identifier?: undefined | string // String identifier to be used when tracing or profiling this transaction. The identifier must not exceed 100 characters.
482+
log_transaction?: undefined | true
483+
transaction_logging_max_field_length?: undefined | number // Maximum length of escaped key and value fields.
484+
server_request_tracing?: undefined | true
485+
timeout?: undefined | number // value in milliseconds of timeout
486+
retry_limit?: undefined | number // number of times to retry
487+
max_retry_delay?: undefined | number // value in milliseconds of maximum delay
488+
size_limit?: undefined | number // value in bytes
489+
idempotency_id?: undefined | string // Unique ID
490+
automatic_idempotency?: undefined | true
491+
snapshot_ryw_enable?: undefined | true
492+
snapshot_ryw_disable?: undefined | true
493+
lock_aware?: undefined | true
494+
used_during_commit_protection_disable?: undefined | true
495+
read_lock_aware?: undefined | true
496+
first_in_batch?: undefined | true
497+
use_provisional_proxies?: undefined | true
498+
report_conflicting_keys?: undefined | true
499+
special_key_space_relaxed?: undefined | true
500+
special_key_space_enable_writes?: undefined | true
501+
tag?: undefined | string // String identifier used to associated this transaction with a throttling group. Must not exceed 16 characters.
502+
auto_throttle_tag?: undefined | string // String identifier used to associated this transaction with a throttling group. Must not exceed 16 characters.
503+
span_parent?: undefined | Buffer // A byte string of length 16 used to associate the span of this transaction with a parent
504+
expensive_clear_cost_estimation_enable?: undefined | true
505+
bypass_unreadable?: undefined | true
506+
use_grv_cache?: undefined | true
507+
skip_grv_cache?: undefined | true
508+
authorization_token?: undefined | string // A JSON Web Token authorized to access data belonging to one or more tenants, indicated by 'tenants' claim of the token's payload.
509509
}
510510

511511
export enum TransactionOptionCode {

lib/transaction.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ byteZero.writeUInt8(0, 0)
3939

4040
export interface RangeOptionsBatch {
4141
// defaults to Iterator for batch mode, WantAll for getRangeAll.
42-
streamingMode?: StreamingMode,
43-
limit?: number,
44-
reverse?: boolean,
42+
streamingMode?: undefined | StreamingMode,
43+
limit?: undefined | number,
44+
reverse?: undefined | boolean,
4545
}
4646

4747
export interface RangeOptions extends RangeOptionsBatch {
48-
targetBytes?: number,
48+
targetBytes?: undefined | number,
4949
}
5050

5151
export type KVList<Key, Value> = {
@@ -56,7 +56,7 @@ export type KVList<Key, Value> = {
5656
export {Watch}
5757

5858
export type WatchOptions = {
59-
throwAllErrors?: boolean
59+
throwAllErrors?: undefined | boolean
6060
}
6161

6262
// Polyfill for node < 10.0 to make asyncIterators work (getRange / getRangeBatch).
@@ -752,7 +752,15 @@ export default class Transaction<KeyIn = NativeValue, KeyOut = Buffer, ValIn = N
752752
*/
753753
async getVersionstampPrefixedValue(key: KeyIn): Promise<{stamp: Buffer, value?: ValOut} | null> {
754754
const val = await this._tn.get(this._keyEncoding.pack(key), this.isSnapshot)
755-
return val == null ? null
755+
756+
if (val == null) {
757+
return null;
758+
}
759+
760+
return val.length <= 10
761+
? {
762+
stamp: val
763+
}
756764
: {
757765
stamp: val.slice(0, 10),
758766

@@ -762,7 +770,7 @@ export default class Transaction<KeyIn = NativeValue, KeyOut = Buffer, ValIn = N
762770
// for the decoder and that can cause issues. We'll just return null
763771
// in that case - but, yeah, controversial. You might want some other
764772
// encoding or something. File an issue if this causes you grief.
765-
value: val.length > 10 ? this._valueEncoding.unpack(val.slice(10)) : undefined
773+
value: this._valueEncoding.unpack(val.slice(10))
766774
}
767775
}
768776

lib/transformer.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {asBuf, concat2, strInc, startsWith} from './util'
55
import {UnboundStamp} from './versionstamp'
66

77
export type Transformer<In, Out> = {
8-
name?: string, // For debugging.
8+
name?: undefined | string, // For debugging.
99

1010
// The tuple type supports embedding versionstamps, but the versionstamp
1111
// isn't known until the transaction has been committed.
@@ -54,11 +54,16 @@ export const prefixTransformer = <In, Out>(prefix: string | Buffer, inner: Trans
5454
if (inner.packUnboundVersionstamp) transformer.packUnboundVersionstamp = (val: In): UnboundStamp => {
5555
const innerVal = inner.packUnboundVersionstamp!(val)
5656

57-
return {
57+
const unboundStamp: UnboundStamp = {
5858
data: concat2(_prefix, innerVal.data),
59-
stampPos: _prefix.length + innerVal.stampPos,
60-
codePos: innerVal.codePos != null ? _prefix.length + innerVal.codePos : undefined,
59+
stampPos: _prefix.length + innerVal.stampPos
60+
};
61+
62+
if (innerVal.codePos != null) {
63+
unboundStamp.codePos = _prefix.length + innerVal.codePos;
6164
}
65+
66+
return unboundStamp;
6267
}
6368

6469
if (inner.bakeVersionstamp) transformer.bakeVersionstamp = inner.bakeVersionstamp.bind(inner)

scripts/gentsopts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ parseString(xml, (err, result) => {
6868
if (name.endsWith('Option')) {
6969
line(`export type ${name}s = {`)
7070
options.forEach(({name, type, paramDescription, deprecated}) => {
71-
output.write(` ${name}?: ${typeToTs(type)}`)
71+
output.write(` ${name}?: undefined | ${typeToTs(type)}`)
7272
if (deprecated) output.write(` ${comment} DEPRECATED`)
7373
else if (paramDescription) output.write(` ${comment} ${paramDescription}`)
7474
line()

0 commit comments

Comments
 (0)