Skip to content

Introduce Result, Record and Graph types mapping #1248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 35 commits into
base: 6.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5c45b0c
Introduce Result, Record and Graph types mappping
bigmontz Nov 8, 2023
0a93a37
Add global registry
bigmontz Nov 8, 2023
918989f
sync deno
bigmontz Nov 8, 2023
d731611
Merge branch '5.0' into 5.x-high-level-hydration
MaxAake Jan 31, 2025
4e8ac68
conflict resolution fix
MaxAake Jan 31, 2025
d71a19c
Documentation additions, import fixes and result.as fix
MaxAake Mar 10, 2025
cf7521d
deno sync
MaxAake Mar 10, 2025
009dd42
mapper undef check
MaxAake Mar 10, 2025
777c392
deno sync
MaxAake Mar 10, 2025
561456d
initialize mapper and add namemapping
MaxAake Mar 11, 2025
26f4e47
deny sync
MaxAake Mar 11, 2025
7ddb87e
improved name mappers
MaxAake Mar 12, 2025
65d2c56
deno sync
MaxAake Mar 12, 2025
f2c8d42
simplify name translations
MaxAake Mar 14, 2025
3ce02e6
deno sync
MaxAake Mar 14, 2025
281c5cd
name mapping documentation
MaxAake Mar 17, 2025
3116c63
deno sync
MaxAake Mar 17, 2025
11a74c4
example test and fix to convention namecheck
MaxAake Mar 17, 2025
0a83829
license header
MaxAake Mar 17, 2025
6af3a90
unit tests for mapping
MaxAake Mar 18, 2025
b8b037e
integration test expansion
MaxAake Mar 24, 2025
28df189
small doc changes and renaming hydrated
MaxAake Mar 26, 2025
eafc641
remove global exports of mapping functions
MaxAake Mar 26, 2025
b407c47
hydrated renamed in examples testing
MaxAake Mar 28, 2025
5ec4d1f
Refactored Results
MaxAake Apr 1, 2025
fba3a09
deno sync
MaxAake Apr 1, 2025
d97edde
renaming and exporting fix
MaxAake Apr 10, 2025
2d1c162
deno
MaxAake Apr 10, 2025
0c37551
small naming conventions refactor
MaxAake Apr 15, 2025
022b03a
deno sync
MaxAake Apr 15, 2025
9cdcc62
rename the mapping object for clarity
MaxAake Apr 16, 2025
509d020
improved ROM object documentation
MaxAake Apr 22, 2025
00a68ea
deno sync
MaxAake Apr 22, 2025
433aea0
rename rulefactory object, introduce mapping decorators
MaxAake Jul 8, 2025
5ac8467
deno sync
MaxAake Jul 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"private": true,
"type": "module",
"devDependencies": {
"@types/node": "^24.0.10",
"husky": "^8.0.3",
"lerna": "^4.0.0",
"lint-staged": "^14.0.0",
Expand Down Expand Up @@ -40,7 +41,7 @@
"scripts": {
"clean": "lerna clean -y && lerna run clean",
"build": "lerna bootstrap --ci",
"set_version::deno": "lerna run set_version --scope neo4j-driver-deno --stream -- ",
"set_version::deno": "lerna run set_version --scope neo4j-driver-deno --stream -- ",
"build::deno": "lerna run build --scope neo4j-driver-deno --stream -- ",
"build::notci": "lerna bootstrap",
"docs": "lerna run docs --stream --concurrency 1",
Expand Down
49 changes: 49 additions & 0 deletions packages/core/src/graph-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
import Integer from './integer'
import { stringify } from './json'
import { Rules, GenericConstructor, as } from './mapping.highlevel'

type StandardDate = Date
/**
Expand Down Expand Up @@ -82,6 +83,22 @@ class Node<T extends NumberOrInteger = Integer, P extends Properties = Propertie
this.elementId = _valueOrGetDefault(elementId, () => identity.toString())
}

/**
* Hydrates an object of a given type with the properties of the node
*
* @param {GenericConstructor<T> | Rules} constructorOrRules Contructor for the desired type or {@link Rules} for the hydration
* @param {Rules} [rules] {@link Rules} for the hydration
* @returns {T}
*/
as <T extends {} = Object>(rules: Rules): T
as <T extends {} = Object>(genericConstructor: GenericConstructor<T>): T
as <T extends {} = Object>(genericConstructor: GenericConstructor<T>, rules?: Rules): T
as <T extends {} = Object>(constructorOrRules: GenericConstructor<T> | Rules, rules?: Rules): T {
return as({
get: (key) => this.properties[key]
}, constructorOrRules, rules)
}

/**
* @ignore
*/
Expand Down Expand Up @@ -199,6 +216,22 @@ class Relationship<T extends NumberOrInteger = Integer, P extends Properties = P
this.endNodeElementId = _valueOrGetDefault(endNodeElementId, () => end.toString())
}

/**
* Hydrates an object of a given type with the properties of the relationship
*
* @param {GenericConstructor<T> | Rules} constructorOrRules Contructor for the desired type or {@link Rules} for the hydration
* @param {Rules} [rules] {@link Rules} for the hydration
* @returns {T}
*/
as <T extends {} = Object>(rules: Rules): T
as <T extends {} = Object>(genericConstructor: GenericConstructor<T>): T
as <T extends {} = Object>(genericConstructor: GenericConstructor<T>, rules?: Rules): T
as <T extends {} = Object>(constructorOrRules: GenericConstructor<T> | Rules, rules?: Rules): T {
return as({
get: (key) => this.properties[key]
}, constructorOrRules, rules)
}

/**
* @ignore
*/
Expand Down Expand Up @@ -320,6 +353,22 @@ class UnboundRelationship<T extends NumberOrInteger = Integer, P extends Propert
)
}

/**
* Hydrates an object of a given type with the properties of the relationship
*
* @param {GenericConstructor<T> | Rules} constructorOrRules Contructor for the desired type or {@link Rules} for the hydration
* @param {Rules} [rules] {@link Rules} for the hydration
* @returns {T}
*/
as <T extends {} = Object>(rules: Rules): T
as <T extends {} = Object>(genericConstructor: GenericConstructor<T>): T
as <T extends {} = Object>(genericConstructor: GenericConstructor<T>, rules?: Rules): T
as <T extends {} = Object>(constructorOrRules: GenericConstructor<T> | Rules, rules?: Rules): T {
return as({
get: (key) => this.properties[key]
}, constructorOrRules, rules)
}

/**
* @ignore
*/
Expand Down
23 changes: 19 additions & 4 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import NotificationFilter, {
notificationFilterMinimumSeverityLevel,
NotificationFilterMinimumSeverityLevel
} from './notification-filter'
import Result, { QueryResult, ResultObserver } from './result'
import Result, { MappedQueryResult, QueryResult, ResultObserver } from './result'
import EagerResult from './result-eager'
import ConnectionProvider, { Releasable } from './connection-provider'
import Connection from './connection'
Expand All @@ -101,6 +101,10 @@ import * as json from './json'
import resultTransformers, { ResultTransformer } from './result-transformers'
import ClientCertificate, { clientCertificateProviders, ClientCertificateProvider, ClientCertificateProviders, RotatingClientCertificateProvider, resolveCertificateProvider } from './client-certificate'
import * as internal from './internal' // todo: removed afterwards
import { StandardCase } from './mapping.nameconventions'
import { Rule, Rules, RecordObjectMapping } from './mapping.highlevel'
import { rule } from './mapping.rulesfactories'
import mappingDecorators from './mapping.decorators'

/**
* Object containing string constants representing predefined {@link Neo4jError} codes.
Expand Down Expand Up @@ -186,7 +190,11 @@ const forExport = {
notificationFilterDisabledClassification,
notificationFilterMinimumSeverityLevel,
clientCertificateProviders,
resolveCertificateProvider
resolveCertificateProvider,
rule,
mappingDecorators,
RecordObjectMapping,
StandardCase
}

export {
Expand Down Expand Up @@ -263,14 +271,19 @@ export {
notificationFilterDisabledClassification,
notificationFilterMinimumSeverityLevel,
clientCertificateProviders,
resolveCertificateProvider
resolveCertificateProvider,
rule,
mappingDecorators,
RecordObjectMapping,
StandardCase
}

export type {
StandardDate,
NumberOrInteger,
NotificationPosition,
QueryResult,
MappedQueryResult,
ResultObserver,
TransactionConfig,
BookmarkManager,
Expand All @@ -294,7 +307,9 @@ export type {
ClientCertificate,
ClientCertificateProvider,
ClientCertificateProviders,
RotatingClientCertificateProvider
RotatingClientCertificateProvider,
Rule,
Rules
}

export default forExport
3 changes: 2 additions & 1 deletion packages/core/src/internal/observers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import Record from '../record'
import { GenericResultObserver } from '../result'
import ResultSummary from '../result-summary'

interface StreamObserver {
Expand Down Expand Up @@ -115,7 +116,7 @@ export interface ResultStreamObserver extends StreamObserver {
* @param {function(metadata: Object)} observer.onCompleted - Handle stream tail, the summary.
* @param {function(error: Object)} observer.onError - Handle errors, should always be provided.
*/
subscribe: (observer: ResultObserver) => void
subscribe: (observer: GenericResultObserver<any>) => void
}

export class CompletedObserver implements ResultStreamObserver {
Expand Down
Loading