neo4j-driver-core
Version:
Internals of neo4j-driver
267 lines (266 loc) • 13.3 kB
TypeScript
/**
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Rule, Rules, GenericConstructor } from './mapping.highlevel';
import { VectorType } from './vector';
/**
* @property {function(rule: ?Rule)} asBoolean Create a {@link Rule} that validates the value is a Boolean.
*
* @property {function(rule: ?Rule)} asString Create a {@link Rule} that validates the value is a String.
*
* @property {function(rule: ?Rule & { isInteger?: boolean })} asNumber Create a {@link Rule} that validates the value is a {@link Number}.
*
* @property {function(rule: ?Rule & { acceptNumber?: boolean })} asBigInt Create a {@link Rule} that validates the value is a {@link BigInt}.
*
* @property {function(rule: ?Rule & { acceptNumber?: boolean })} asInteger Create a {@link Rule} that validates the value is an {@link Integer}.
*
* @property {function(rule: ?Rule)} asNode Create a {@link Rule} that validates the value is a {@link Node}.
*
* @property {function(rule: ?Rule)} asRelationship Create a {@link Rule} that validates the value is a {@link Relationship}.
*
* @property {function(rule: ?Rule)} asPath Create a {@link Rule} that validates the value is a {@link Path}.
*
* @property {function(rule: ?Rule)} asPoint Create a {@link Rule} that validates the value is a {@link Point}.
*
* @property {function(rule: ?Rule & { stringify?: boolean })} asDuration Create a {@link Rule} that validates the value is a {@link Duration}.
*
* @property {function(rule: ?Rule & { stringify?: boolean })} asLocalTime Create a {@link Rule} that validates the value is a {@link LocalTime}.
*
* @property {function(rule: ?Rule & { stringify?: boolean })} asTime Create a {@link Rule} that validates the value is a {@link Time}.
*
* @property {function(rule: ?Rule & { stringify?: boolean, jsNativeDate?: boolean })} asDate Create a {@link Rule} that validates the value is a {@link Date}.
*
* @property {function(rule: ?Rule & { stringify?: boolean, jsNativeDate?: boolean })} asLocalDateTime Create a {@link Rule} that validates the value is a {@link LocalDateTime}.
*
* @property {function(rule: ?Rule & { stringify?: boolean, jsNativeDate?: boolean })} asDateTime Create a {@link Rule} that validates the value is a {@link DateTime}.
*
* @property {function(rule: ?Rule & { apply?: Rule })} asList Create a {@link Rule} that validates the value is a List.
*
* @property {function(rule: ?Rule & { asTypedList?: boolean, dimension?: number, type?: VectorType })} asVector Create a {@link Rule} that validates the value is a {@link Vector}.
*
* @property {function(rule: ?Rule & { stringify?: boolean })} asUUID Create a {@link Rule} that validates the value is a {@link UUID}.
*
* @property {function(rules: Rules)} asObject Create a {@link Rule} for an object, allowing complex mapping of even nested results.
*/
export declare const rule: Readonly<{
/**
* Create a {@link Rule} that validates the value is a Boolean.
*
* @param {Rule | undefined} rule Configurations for the rule
* @returns {Rule} A new rule for the value
*/
asBoolean(rule?: Rule): Rule;
/**
* Create a {@link Rule} that validates the value is a String.
*
* Optionally takes a {@link Rule}, in which case the returned rule will keep all fields of the one provided.
*
* @param {Rule | undefined} rule Configurations for the rule
* @returns {Rule} A new rule for the value
*/
asString(rule?: Rule): Rule;
/**
* Create a {@link Rule} that validates the value is a {@link Number}.
*
* Optionally takes a {@link Rule}, in which case the returned rule will keep all fields of the one provided.
*
* @param {Rule & { isInteger?: boolean } | undefined} rule Configurations for the rule.
* If `isInteger` is set to true, the created validate function will allow Integer values through, and the conversion functions will ensure results are return as numbers while parameters are transmitted as integers.
* @returns {Rule} A new rule for the value
*/
asNumber(rule?: Rule & {
isInteger?: boolean;
}): Rule;
/**
* Create a {@link Rule} that validates the value is a {@link BigInt}.
*
* Optionally takes a {@link Rule}, in which case the returned rule will keep all fields of the one provided.
*
* @returns {Rule} A new rule for the value
*/
asBigInt(rule?: Rule & {
acceptNumber?: boolean;
}): Rule;
/**
* Create a {@link Rule} that validates the value is an {@link Integer}.
*
* Optionally takes a {@link Rule}, in which case the returned rule will keep all fields of the one provided.
*
* @param {Rule & { acceptNumber?: boolean } | undefined} rule Configurations for the rule, if `acceptNumber` is set to true, the created validate function will allow Numbers through and the conversion functions will turn Numbers into Integers.
* @returns {Rule} A new rule for the value
*/
asInteger(rule?: Rule & {
acceptNumber?: boolean;
}): Rule;
/**
* Create a {@link Rule} that validates the value is a {@link Node}.
*
* Optionally takes a {@link Rule}, in which case the returned rule will keep all fields of the one provided.
*
* @example
* const actingJobsRules: Rules = {
* // Converts the person node to a Person object in accordance with provided rules
* person: neo4j.rule.asNode({
* convert: (node: Node) => node.as(Person, personRules)
* }),
* // Returns the movie node as a Node
* movie: neo4j.rule.asNode({}),
* }
*
* @param {Rule | undefined} rule Configurations for the rule
* @returns {Rule} A new rule for the value
*/
asNode(rule?: Rule): Rule;
/**
* Create a {@link Rule} that validates the value is a {@link Relationship}.
*
* Optionally takes a {@link Rule}, in which case the returned rule will keep all fields of the one provided.
*
* @example
* const actingJobsRules: Rules = {
* // Converts the role relationship to a Role object in accordance with provided rules
* role: neo4j.rule.asRelationship({
* convert: (rel: Relationship) => rel.as(Role, roleRules)
* }),
* // Returns the employment relationship as a Relationship
* employment: neo4j.rule.asRelationship({}),
* }
*
* @param {Rule | undefined} rule Configurations for the rule.
* @returns {Rule} A new rule for the value
*/
asRelationship(rule?: Rule): Rule;
/**
* Create a {@link Rule} that validates the value is a {@link Path}
*
* Optionally takes a {@link Rule}, in which case the returned rule will keep all fields of the one provided.
*
* @param {Rule | undefined} rule Configurations for the rule
* @returns {Rule} A new rule for the value
*/
asPath(rule?: Rule): Rule;
/**
* Create a {@link Rule} that validates the value is a {@link Point}
*
* Optionally takes a {@link Rule}, in which case the returned rule will keep all fields of the one provided.
*
* @param {Rule | undefined} rule Configurations for the rule
* @returns {Rule} A new rule for the value
*/
asPoint(rule?: Rule): Rule;
/**
* Create a {@link Rule} that validates the value is a {@link Duration}
*
* Optionally takes a {@link Rule}, in which case the returned rule will keep all fields of the one provided.
*
* @param {Rule & { stringify?: boolean } | undefined} rule Configurations for the rule. If `stringify` is set, the returned rule will have `convert` and `parameterConversion` functions which automatically convert between strings in user code and {@link Duration}s in the database.
* @returns {Rule} A new rule for the value
*/
asDuration(rule?: Rule & {
stringify?: boolean;
}): Rule;
/**
* Create a {@link Rule} that validates the value is a {@link LocalTime}
*
* @param {Rule & { stringify?: boolean } | undefined} rule Configurations for the rule. If `stringify` is set, the returned rule will have `convert` and `parameterConversion` functions which automatically convert between strings in user code and {@link LocalTime}s in the database.
* @returns {Rule} A new rule for the value
*/
asLocalTime(rule?: Rule & {
stringify?: boolean;
}): Rule;
/**
* Create a {@link Rule} that validates the value is a {@link Time}
*
* @param {Rule & { stringify?: boolean } | undefined} rule Configurations for the rule. If `stringify` is set, the returned rule will have `convert` and `parameterConversion` functions which automatically convert between strings in user code and {@link Time}s in the database.
* @returns {Rule} A new rule for the value
*/
asTime(rule?: Rule & {
stringify?: boolean;
}): Rule;
/**
* Create a {@link Rule} that validates the value is a {@link Date}
*
* @param {Rule & { stringify?: boolean, jsNativeDate?: boolean } | undefined} rule Configurations for the rule. If `stringify`/`jsNativeDate` is set, the returned rule will have `convert` and `parameterConversion` functions which automatically convert between strings/JavaScript Dates in user code and {@link Date}s in the database.
* @returns {Rule} A new rule for the value
*/
asDate(rule?: Rule & {
stringify?: boolean;
jsNativeDate?: boolean;
}): Rule;
/**
* Create a {@link Rule} that validates the value is a {@link LocalDateTime}
*
* @param {Rule & { stringify?: boolean, jsNativeDate?: boolean } | undefined} rule Configurations for the rule. If `stringify`/`jsNativeDate` is set, the returned rule will have `convert` and `parameterConversion` functions which automatically convert between strings/JavaScript Dates in user code and {@link LocalDateTime}s in the database.
* @returns {Rule} A new rule for the value
*/
asLocalDateTime(rule?: Rule & {
stringify?: boolean;
jsNativeDate?: boolean;
}): Rule;
/**
* Create a {@link Rule} that validates the value is a {@link DateTime}
*
* @param {Rule & { stringify?: boolean, jsNativeDate?: boolean } | undefined} rule Configurations for the rule. If `stringify`/`jsNativeDate` is set, the returned rule will have `convert` and `parameterConversion` functions which automatically convert between strings/JavaScript Dates in user code and {@link DateTime}s in the database.
* @returns {Rule} A new rule for the value
*/
asDateTime(rule?: Rule & {
stringify?: boolean;
jsNativeDate?: boolean;
}): Rule;
/**
* Create a {@link Rule} that validates the value is a List.
*
* Optionally taking a rule for hydrating the contained values.
*
* @param {Rule & { apply?: Rule } | undefined} rule Configurations for the rule. Setting apply to a rule will apply that rule to all elements of the list.
* @returns {Rule} A new rule for the value
*/
asList(rule?: Rule & {
apply?: Rule;
}): Rule;
/**
* Create a {@link Rule} that validates the value is a {@link Vector}.
*
* @param {Rule & { asTypedList?: boolean, dimension?: number, type?: VectorType } | undefined} rule Configurations for the rule. Setting asTypedList will automatically convert between TypedList in user code and Vectors in the database.
* @returns {Rule} A new rule for the value
*/
asVector(rule?: Rule & {
asTypedList?: boolean;
dimension?: number;
type?: VectorType;
}): Rule;
/**
* Create a {@link Rule} that validates the value is a {@link UUID}.
*
* @param {Rule & { stringify?: boolean } | undefined} rule Configurations for the rule. Setting stringify will automatically convert between Strings in user code and UUIDs in the database.
* @returns {Rule} A new rule for the value
*/
asUUID(rule?: Rule & {
stringify?: boolean;
}): Rule;
/**
* Create a {@link Rule} for an object, allowing complex mapping of even nested results
*
* NOTE: When using this rule, object identifiers will be mapped according to any name mapping set with neo4j.RecordObjectMapping.translateIdentifiers.
*
* @param {Rules} rules rules for the fields of the object.
* @param {GenericConstructor} constructor The constructor function of the class to map to. The constructor must be callable with all arguments undefined.
* @returns {Rule} A new rule for the value
*/
asObject(constructorOrRules: GenericConstructor<Object> | Rules, rules?: Rules): Rule;
}>;