UNPKG

neo4j-driver-core

Version:
324 lines (323 loc) 15.3 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); var mapping_highlevel_1 = require("./mapping.highlevel"); var mapping_rulesfactories_1 = require("./mapping.rulesfactories"); /** * Class Decorator Factory that enables the Neo4j Driver to map result records to this class * * @returns {Function} Class Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function mappedClass() { return function (_, context) { mapping_highlevel_1.rulesRegistry[context.name] = context.metadata; }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a boolean. * * @param {Rule} config Configurations for the rule * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function booleanProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asBoolean(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a string. * * @param {Rule} config Configurations for the rule * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function stringProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asString(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a number. * * @param {Rule & { isInteger?: boolean }} config 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 {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function numberProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asNumber(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a BigInt. * * @param {Rule & { acceptNumber?: boolean }} config Configurations for the rule, if `acceptNumber` is set to true, the created validate function will allow Numbers through and the convert function will turn Numbers into BigInts. * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function bigIntProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asBigInt(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to an Integer. * * @param {Rule & { acceptNumber?: boolean }} config Configurations for the rule, if `acceptNumber` is set to true, the created validate function will allow Numbers through and the convert function will turn Numbers into BigInts. * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function integerProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asInteger(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a Node. * * @param {Rule} config Configurations for the rule * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function nodeProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asNode(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a Relationship. * * @param {Rule} config Configurations for the rule. * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function relationshipProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asRelationship(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a Path. * * @param {Rule} config Configurations for the rule. * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function pathProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asPath(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a Point. * * @param {Rule} config Configurations for the rule. * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function pointProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asPoint(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a Duration. * * @param {Rule & { stringify?: boolean }} config Configurations for the rule. If `stringify` is set, the applied rule will have `convert` and `parameterConversion` functions which automatically convert between strings in user code and {@link Duration}s in the database. * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function durationProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asDuration(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a LocalTime * * @param {Rule & { stringify?: boolean }} config Configurations for the rule. If `stringify` is set, the applied rule will have `convert` and `parameterConversion` functions which automatically convert between strings in user code and {@link LocalTime}s in the database. * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function localTimeProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asLocalTime(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a Time * * @param {Rule & { stringify?: boolean }} config Configurations for the rule. If `stringify` is set, the applied rule will have `convert` and `parameterConversion` functions which automatically convert between strings in user code and {@link Time}s in the database. * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function timeProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asTime(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a Date * * @param {Rule & { stringify?: boolean, jsNativeDate?: boolean }} config Configurations for the rule. If `stringify`/`jsNativeDate` is set, the applied 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 {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function dateProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asDate(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a LocalDateTIme * * @param {Rule & { stringify?: boolean, jsNativeDate?: boolean }} config Configurations for the rule. If `stringify`/`jsNativeDate` is set, the applied 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 {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function localDateTimeProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asLocalDateTime(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a DateTIme * * @param {Rule & { stringify?: boolean, jsNativeDate?: boolean }} config Configurations for the rule. If `stringify`/`jsNativeDate` is set, the applied 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 {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function dateTimeProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asDateTime(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a List * * @param {Rule & { apply?: Rule }} config Configurations for the rule. Setting apply to a rule will apply that rule to all elements of the list. * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function listProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asList(__assign({ apply: __assign({}, context.metadata[context.name]) }, config)); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a Vector * * @param {Rule & { asTypedList?: boolean, dimension?: number, type?: VectorType }} config Configurations for the rule. Setting asTypedList will automatically convert between TypedList in user code and Vectors in the database. * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function vectorProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asVector(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to a UUID * * @param {Rule & { stringify?: boolean } | undefined} config Configurations for the rule. Setting stringify will automatically convert between Strings in user code and UUIDs in the database. * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function uuidProperty(config) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asUUID(config); }; } /** * Property Decorator Factory that enables the Neo4j Driver to map this property to 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. * @param {Rule & { asTypedList?: boolean, dimension?: number, type?: VectorType }} config Configurations for the rule. Setting asTypedList will automatically convert between TypedList in user code and Vectors in the database. * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function objectProperty(constructorOrRules, rules) { return function (_, context) { context.metadata[context.name] = mapping_rulesfactories_1.rule.asObject(constructorOrRules, rules); }; } /** * Property Decorator Factory that sets this property to optional. * NOTE: Should be put above a type decorator. * * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function optionalProperty() { return function (_, context) { context.metadata[context.name] = __assign({ optional: true }, context.metadata[context.name]); }; } /** * Property Decorator Factory that sets a custom parameter name to map this property to. * NOTE: Should be put above a type decorator. * * @param {string} name * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function mapPropertyFromName(name) { return function (_, context) { context.metadata[context.name] = __assign({ from: name }, context.metadata[context.name]); }; } /** * Property Decorator Factory that sets the Neo4j Driver to convert this property to another type. * NOTE: Should be put above a type decorator of type Node or Relationship. * * @param {any} type * @returns {Function} Property Decorator * @experimental Object Mapping Decorators are in preview and may change in minor releases. */ function convertPropertyToType(type) { return function (_, context) { context.metadata[context.name] = __assign({ convert: function (node) { return node.as(type); } }, context.metadata[context.name]); }; } var forExport = { booleanProperty: booleanProperty, stringProperty: stringProperty, numberProperty: numberProperty, bigIntProperty: bigIntProperty, integerProperty: integerProperty, nodeProperty: nodeProperty, relationshipProperty: relationshipProperty, pathProperty: pathProperty, pointProperty: pointProperty, durationProperty: durationProperty, localTimeProperty: localTimeProperty, timeProperty: timeProperty, dateProperty: dateProperty, localDateTimeProperty: localDateTimeProperty, dateTimeProperty: dateTimeProperty, listProperty: listProperty, vectorProperty: vectorProperty, uuidProperty: uuidProperty, objectProperty: objectProperty, optionalProperty: optionalProperty, mapPropertyFromName: mapPropertyFromName, convertPropertyToType: convertPropertyToType, mappedClass: mappedClass }; exports.default = forExport;