Skip to content

Commit 723efec

Browse files
committed
Inline util modules
1 parent 96c49f9 commit 723efec

File tree

12 files changed

+54
-72
lines changed

12 files changed

+54
-72
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ This driver uses semantic versioning:
4747
This brings these methods behavior in line with that of the `beginTransaction`
4848
and `executeTransaction` methods of `Database` objects.
4949

50+
- Moved `collectionToString` helper into `collection` module
51+
52+
- Moved `Dict` type into `connection` module
53+
54+
- Moved `Patch` type into `documents` module
55+
56+
- Moved `Errback` type into library internals
57+
58+
- Renamed `util/foxx-manifest` module to `foxx-manifest`
59+
5060
### Added
5161

5262
- Added `precaptureStackTraces` configuration option ([#599](https://github.com/arangodb/arangojs/issues/599))

src/aql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @packageDocumentation
1212
*/
1313
import { ArangoCollection, isArangoCollection } from "./collection";
14-
import { Dict } from "./util/types";
14+
import { Dict } from "./connection";
1515
import { isArangoView, View } from "./view";
1616

1717
/**

src/collection.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
DocumentSelector,
2222
Edge,
2323
EdgeData,
24+
Patch,
2425
_documentHandle,
2526
} from "./documents";
2627
import { isArangoError } from "./error";
@@ -43,7 +44,6 @@ import {
4344
} from "./indexes";
4445
import { Blob } from "./lib/blob";
4546
import { COLLECTION_NOT_FOUND, DOCUMENT_NOT_FOUND } from "./lib/codes";
46-
import { Patch } from "./util/types";
4747

4848
/**
4949
* Indicates whether the given value represents an {@link ArangoCollection}.
@@ -56,6 +56,20 @@ export function isArangoCollection(
5656
return Boolean(collection && collection.isArangoCollection);
5757
}
5858

59+
/**
60+
* Coerces the given collection name or {@link ArangoCollection} object to
61+
* a string representing the collection name.
62+
*
63+
* @param collection - Collection name or {@link ArangoCollection} object.
64+
*/
65+
export function collectionToString(
66+
collection: string | ArangoCollection
67+
): string {
68+
if (isArangoCollection(collection)) {
69+
return String(collection.name);
70+
} else return String(collection);
71+
}
72+
5973
/**
6074
* A marker interface identifying objects that can be used in AQL template
6175
* strings to create references to ArangoDB collections.

src/connection.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ import {
3333
const MIME_JSON = /\/(json|javascript)(\W|$)/;
3434
const LEADER_ENDPOINT_HEADER = "x-arango-endpoint";
3535

36+
/**
37+
* Generic type representing an object with values of a given value type.
38+
*
39+
* @param T - Type of the object's property values.
40+
*/
41+
export type Dict<T> = { [key: string]: T };
42+
3643
/**
3744
* Determines the behavior when multiple URLs are used:
3845
*
@@ -53,17 +60,13 @@ export type LoadBalancingStrategy = "NONE" | "ROUND_ROBIN" | "ONE_RANDOM";
5360
*
5461
* Header names should always be lowercase.
5562
*/
56-
export type Headers = {
57-
[key: string]: string;
58-
};
63+
export type Headers = Dict<string>;
5964

6065
/**
6166
* An arbitrary object with scalar values representing query string parameters
6267
* and their values.
6368
*/
64-
export type Params = {
65-
[key: string]: any;
66-
};
69+
export type Params = Dict<any>;
6770

6871
/**
6972
* Generic properties shared by all ArangoDB HTTP API responses.

src/cursor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* @packageDocumentation
99
*/
1010
import { LinkedList } from "x3-linkedlist";
11+
import { Dict } from "./connection";
1112
import { Database } from "./database";
12-
import { Dict } from "./util/types";
1313

1414
/**
1515
* Additional information about the cursor.

src/database.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
ArangoCollection,
2222
Collection,
2323
CollectionMetadata,
24+
collectionToString,
2425
CollectionType,
2526
CreateCollectionOptions,
2627
DocumentCollection,
@@ -31,11 +32,13 @@ import {
3132
ArangoResponseMetadata,
3233
Config,
3334
Connection,
35+
Dict,
3436
Headers,
3537
RequestOptions,
3638
} from "./connection";
3739
import { ArrayCursor, BatchedArrayCursor } from "./cursor";
3840
import { isArangoError } from "./error";
41+
import { FoxxManifest } from "./foxx-manifest";
3942
import {
4043
EdgeDefinitionOptions,
4144
Graph,
@@ -48,9 +51,6 @@ import { toForm } from "./lib/multipart";
4851
import { ArangojsResponse } from "./lib/request";
4952
import { Route } from "./route";
5053
import { Transaction } from "./transaction";
51-
import { collectionToString } from "./util/collectionToString";
52-
import { FoxxManifest } from "./util/foxx-manifest";
53-
import { Dict } from "./util/types";
5454
import {
5555
ArangoSearchView,
5656
ArangoSearchViewPropertiesOptions,

src/documents.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ export type Document<T extends object = any> = T &
6868
*/
6969
export type Edge<T extends object = any> = T & DocumentMetadata & EdgeMetadata;
7070

71+
/**
72+
* Type representing patch data for a given object type to represent a payload
73+
* ArangoDB can apply in a document PATCH request (i.e. a partial update).
74+
*
75+
* This differs from `Partial` in that it also applies itself to any nested
76+
* objects recursively.
77+
*/
78+
export type Patch<T = object> = { [K in keyof T]?: T[K] | Patch<T[K]> };
79+
7180
/**
7281
* An object with an ArangoDB document `_id` property.
7382
*

src/util/foxx-manifest.ts renamed to src/foxx-manifest.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
/**
22
* ```ts
3-
* import type { FoxxManifest } from "arangojs/util/foxx-manifest";
3+
* import type { FoxxManifest } from "arangojs/foxx-manifest";
44
* ```
55
*
6-
* The "util/foxx-manifest" module provides the Foxx manifest type for
7-
* TypeScript.
6+
* The "foxx-manifest" module provides the Foxx manifest type for TypeScript.
87
*
98
* Generated from {@link http://json.schemastore.org/foxx-manifest | JSON Schema}
109
* using `json-schema-to-typescript`.
1110
*
1211
* @packageDocumentation
1312
*/
1413

15-
import { Dict } from "./types";
14+
import { Dict } from "./connection";
1615

1716
/**
1817
* Schema for ArangoDB Foxx service manifests.

src/graph.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
import {
1616
ArangoCollection,
17+
collectionToString,
1718
DocumentCollection,
1819
EdgeCollection,
1920
isArangoCollection,
@@ -28,12 +29,11 @@ import {
2829
DocumentSelector,
2930
Edge,
3031
EdgeData,
32+
Patch,
3133
_documentHandle,
3234
} from "./documents";
3335
import { isArangoError } from "./error";
3436
import { DOCUMENT_NOT_FOUND, GRAPH_NOT_FOUND } from "./lib/codes";
35-
import { collectionToString } from "./util/collectionToString";
36-
import { Patch } from "./util/types";
3737

3838
/**
3939
* @internal

src/util/collectionToString.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)