Skip to content

Commit 5d24bb5

Browse files
committed
closes #132
Enabled cyclic dependencies in type mapping to support true bidirectional relationships
1 parent 82c31df commit 5d24bb5

File tree

13 files changed

+1121
-952
lines changed

13 files changed

+1121
-952
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ const map = orange.map(x => ({
9494
})).map(x => ({
9595
orderLine: x.orderLine.map(({ hasMany }) => ({
9696
packages: hasMany(x.package).by('lineId')
97-
}))
98-
})).map(x => ({
97+
})),
9998
order: x.order.map(v => ({
10099
customer: v.references(x.customer).by('customerId'),
101100
lines: v.hasMany(x.orderLine).by('orderId'),
@@ -200,8 +199,7 @@ const map = orange.map(x => ({
200199
})).map(x => ({
201200
orderLine: x.orderLine.map(({ hasMany }) => ({
202201
packages: hasMany(x.package).by('lineId')
203-
}))
204-
})).map(x => ({
202+
})),
205203
order: x.order.map(({ hasOne, hasMany, references }) => ({
206204
customer: references(x.customer).by('customerId'),
207205
deliveryAddress: hasOne(x.deliveryAddress).by('orderId'),

dist/index.browser.mjs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4218,13 +4218,13 @@ function requireNewColumn () {
42184218

42194219
c.groupSum = (context, ...rest) => aggregateGroup.apply(null, [context, 'sum', c, table, ...rest]);
42204220
c.groupAvg = (context, ...rest) => aggregateGroup.apply(null, [context, 'avg', c, table, ...rest]);
4221-
c.groupMin = (context, ...rest) => aggregateGroup.apply(null, [context, 'min', c, table, ...rest]);
4222-
c.groupMax = (context, ...rest) => aggregateGroup.apply(null, [context, 'max', c, table, ...rest]);
4221+
c.groupMin = (context, ...rest) => aggregateGroup.apply(null, [context, 'min', c, table, false, ...rest]);
4222+
c.groupMax = (context, ...rest) => aggregateGroup.apply(null, [context, 'max', c, table, false, ...rest]);
42234223
c.groupCount = (context, ...rest) => aggregateGroup.apply(null, [context, 'count', c, table, false, ...rest]);
42244224
c.sum = (context, ...rest) => aggregate.apply(null, [context, 'sum', c, table, ...rest]);
42254225
c.avg = (context, ...rest) => aggregate.apply(null, [context, 'avg', c, table, ...rest]);
4226-
c.min = (context, ...rest) => aggregate.apply(null, [context, 'min', c, table, ...rest]);
4227-
c.max = (context, ...rest) => aggregate.apply(null, [context, 'max', c, table, ...rest]);
4226+
c.min = (context, ...rest) => aggregate.apply(null, [context, 'min', c, table, false, ...rest]);
4227+
c.max = (context, ...rest) => aggregate.apply(null, [context, 'max', c, table, false, ...rest]);
42284228
c.count = (context, ...rest) => aggregate.apply(null, [context, 'count', c, table, false, ...rest]);
42294229

42304230
function self(context) {
@@ -9415,13 +9415,13 @@ function requireRelatedColumn () {
94159415

94169416
c.groupSum = (context, ...rest) => aggregateGroup.apply(null, [context, 'sum', column, relations, ...rest]);
94179417
c.groupAvg = (context, ...rest) => aggregateGroup.apply(null, [context, 'avg', column, relations, ...rest]);
9418-
c.groupMin = (context, ...rest) => aggregateGroup.apply(null, [context, 'min', column, relations, ...rest]);
9419-
c.groupMax = (context, ...rest) => aggregateGroup.apply(null, [context, 'max', column, relations, ...rest]);
9418+
c.groupMin = (context, ...rest) => aggregateGroup.apply(null, [context, 'min', column, relations, false, ...rest]);
9419+
c.groupMax = (context, ...rest) => aggregateGroup.apply(null, [context, 'max', column, relations, false, ...rest]);
94209420
c.groupCount = (context, ...rest) => aggregateGroup.apply(null, [context, 'count', column, relations, false, ...rest]);
94219421
c.sum = (context, ...rest) => aggregate.apply(null, [context, 'sum', column, relations, ...rest]);
94229422
c.avg = (context, ...rest) => aggregate.apply(null, [context, 'avg', column, relations, ...rest]);
9423-
c.min = (context, ...rest) => aggregate.apply(null, [context, 'min', column, relations, ...rest]);
9424-
c.max = (context, ...rest) => aggregate.apply(null, [context, 'max', column, relations, ...rest]);
9423+
c.min = (context, ...rest) => aggregate.apply(null, [context, 'min', column, relations, false, ...rest]);
9424+
c.max = (context, ...rest) => aggregate.apply(null, [context, 'max', column, relations, false, ...rest]);
94259425
c.count = (context, ...rest) => aggregate.apply(null, [context, 'count', column, relations, false, ...rest]);
94269426
c.self = (context, ...rest) => childColumn.apply(null, [context, column, relations, ...rest]);
94279427

@@ -14799,6 +14799,7 @@ function requireIndexBrowser () {
1479914799
connectViaPool.commit = requireCommit();
1480014800
connectViaPool.rollback = requireRollback();
1480114801
connectViaPool.end = requirePools().end;
14802+
connectViaPool.close = connectViaPool.end;
1480214803
connectViaPool.log = requireLog().registerLogger;
1480314804
connectViaPool.on = requireLog().on;
1480414805
connectViaPool.off = requireLog().off;

dist/index.mjs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4219,13 +4219,13 @@ function requireNewColumn () {
42194219

42204220
c.groupSum = (context, ...rest) => aggregateGroup.apply(null, [context, 'sum', c, table, ...rest]);
42214221
c.groupAvg = (context, ...rest) => aggregateGroup.apply(null, [context, 'avg', c, table, ...rest]);
4222-
c.groupMin = (context, ...rest) => aggregateGroup.apply(null, [context, 'min', c, table, ...rest]);
4223-
c.groupMax = (context, ...rest) => aggregateGroup.apply(null, [context, 'max', c, table, ...rest]);
4222+
c.groupMin = (context, ...rest) => aggregateGroup.apply(null, [context, 'min', c, table, false, ...rest]);
4223+
c.groupMax = (context, ...rest) => aggregateGroup.apply(null, [context, 'max', c, table, false, ...rest]);
42244224
c.groupCount = (context, ...rest) => aggregateGroup.apply(null, [context, 'count', c, table, false, ...rest]);
42254225
c.sum = (context, ...rest) => aggregate.apply(null, [context, 'sum', c, table, ...rest]);
42264226
c.avg = (context, ...rest) => aggregate.apply(null, [context, 'avg', c, table, ...rest]);
4227-
c.min = (context, ...rest) => aggregate.apply(null, [context, 'min', c, table, ...rest]);
4228-
c.max = (context, ...rest) => aggregate.apply(null, [context, 'max', c, table, ...rest]);
4227+
c.min = (context, ...rest) => aggregate.apply(null, [context, 'min', c, table, false, ...rest]);
4228+
c.max = (context, ...rest) => aggregate.apply(null, [context, 'max', c, table, false, ...rest]);
42294229
c.count = (context, ...rest) => aggregate.apply(null, [context, 'count', c, table, false, ...rest]);
42304230

42314231
function self(context) {
@@ -9416,13 +9416,13 @@ function requireRelatedColumn () {
94169416

94179417
c.groupSum = (context, ...rest) => aggregateGroup.apply(null, [context, 'sum', column, relations, ...rest]);
94189418
c.groupAvg = (context, ...rest) => aggregateGroup.apply(null, [context, 'avg', column, relations, ...rest]);
9419-
c.groupMin = (context, ...rest) => aggregateGroup.apply(null, [context, 'min', column, relations, ...rest]);
9420-
c.groupMax = (context, ...rest) => aggregateGroup.apply(null, [context, 'max', column, relations, ...rest]);
9419+
c.groupMin = (context, ...rest) => aggregateGroup.apply(null, [context, 'min', column, relations, false, ...rest]);
9420+
c.groupMax = (context, ...rest) => aggregateGroup.apply(null, [context, 'max', column, relations, false, ...rest]);
94219421
c.groupCount = (context, ...rest) => aggregateGroup.apply(null, [context, 'count', column, relations, false, ...rest]);
94229422
c.sum = (context, ...rest) => aggregate.apply(null, [context, 'sum', column, relations, ...rest]);
94239423
c.avg = (context, ...rest) => aggregate.apply(null, [context, 'avg', column, relations, ...rest]);
9424-
c.min = (context, ...rest) => aggregate.apply(null, [context, 'min', column, relations, ...rest]);
9425-
c.max = (context, ...rest) => aggregate.apply(null, [context, 'max', column, relations, ...rest]);
9424+
c.min = (context, ...rest) => aggregate.apply(null, [context, 'min', column, relations, false, ...rest]);
9425+
c.max = (context, ...rest) => aggregate.apply(null, [context, 'max', column, relations, false, ...rest]);
94269426
c.count = (context, ...rest) => aggregate.apply(null, [context, 'count', column, relations, false, ...rest]);
94279427
c.self = (context, ...rest) => childColumn.apply(null, [context, column, relations, ...rest]);
94289428

@@ -20520,6 +20520,7 @@ function requireSrc () {
2052020520
connectViaPool.commit = requireCommit();
2052120521
connectViaPool.rollback = requireRollback();
2052220522
connectViaPool.end = requirePools().end;
20523+
connectViaPool.close = connectViaPool.end;
2052320524
connectViaPool.log = requireLog().registerLogger;
2052420525
connectViaPool.on = requireLog().on;
2052520526
connectViaPool.off = requireLog().off;

docs/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## Changelog
2+
__4.7.10__
3+
Enabled cyclic dependencies in type mapping to support true bidirectional relationships. See [#132](https://github.com/alfateam/orange-orm/issues/132)
24
__4.7.9__
35
Bugfix: MsSql: Validation failed for parameter '0'. Value must be between -2147483648 and 2147483647, inclusive. See [#131](https://github.com/alfateam/orange-orm/issues/131)
46
__4.7.8__

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "orange-orm",
3-
"version": "4.7.9",
3+
"version": "4.7.10",
44
"main": "./src/index.js",
55
"module": "./dist/index.mjs",
66
"browser": "./dist/index.browser.mjs",

src/index.d.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import type { RequestHandler } from 'express';
44
import type { D1Database } from '@cloudflare/workers-types';
55
import type { ConnectionConfiguration } from 'tedious';
66
import type { PoolAttributes } from 'oracledb';
7-
import type { AllowedDbMap, DbMapper, MappedDbDef } from './map';
7+
import type { AllowedDbMap, DbMapper, MappedDbDef, MergeProperties } from './map';
8+
import type { Filter as MapFilter, RawFilter as MapRawFilter, Pool as MapPool, PoolOptions as MapPoolOptions } from './map2';
89

910
declare function r(config: r.Config): unknown;
1011

@@ -26,12 +27,12 @@ declare namespace r {
2627
function off(type: 'query', cb: (e: QueryEvent) => void): void;
2728
function map<V extends AllowedDbMap<V>>(
2829
fn: (mapper: DbMapper<{}>) => V
29-
): MappedDbDef<V>;
30+
): MappedDbDef<MergeProperties<V, V>>;
3031
function createPatch(original: any[], modified: any[]): JsonPatch;
3132
function createPatch(original: any, modified: any): JsonPatch;
3233

3334
type JsonPatch = Array<{
34-
op: "add" | "remove" | "replace" | "copy" | "move" | "test";
35+
op: 'add' | 'remove' | 'replace' | 'copy' | 'move' | 'test';
3536
path: string;
3637
value?: any;
3738
from?: string;
@@ -48,13 +49,8 @@ declare namespace r {
4849
result: []
4950
}
5051

51-
export interface Pool {
52-
end(): Promise<void>;
53-
}
54-
55-
export interface PoolOptions {
56-
size?: number;
57-
}
52+
export type Pool = MapPool;
53+
export type PoolOptions = MapPoolOptions;
5854

5955
export interface Join {
6056
by(...columns: string[]): JoinBy;
@@ -65,8 +61,8 @@ declare namespace r {
6561
}
6662

6763
export abstract class JoinRelation {
68-
columns: ColumnDef[];
69-
childTable: Table;
64+
columns: ColumnDef[];
65+
childTable: Table;
7066
}
7167

7268
export interface Table {
@@ -155,17 +151,10 @@ declare namespace r {
155151
as(dbName: string): ColumnNotNullOf<T>;
156152
}
157153

158-
var filter: Filter;
159-
export interface RawFilter {
160-
sql: string | (() => string);
161-
parameters?: any[];
162-
}
154+
const filter: Filter;
163155

164-
export interface Filter extends RawFilter {
165-
and(filter: Filter, ...filters: Filter[]): Filter;
166-
or(filter: Filter, ...filters: Filter[]): Filter;
167-
not(): Filter;
168-
}
156+
export type RawFilter = MapRawFilter;
157+
export type Filter = MapFilter;
169158

170159
export type Concurrency = 'optimistic' | 'skipOnConflict' | 'overwrite';
171160

@@ -223,11 +212,11 @@ declare namespace r {
223212
*/
224213
iEqual(value: string | null): Filter;
225214
/**
226-
* ignore case, postgres only
215+
* ignore case, postgres only
227216
* */
228217
iEq(value: string | null): Filter;
229218
/**
230-
* ignore case, postgres only
219+
* ignore case, postgres only
231220
*/
232221
iEq(value: string | null): Filter;
233222
}

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ connectViaPool.filter = require('./emptyFilter');
2828
connectViaPool.commit = require('./table/commit');
2929
connectViaPool.rollback = require('./table/rollback');
3030
connectViaPool.end = require('./pools').end;
31+
connectViaPool.close = connectViaPool.end;
3132
connectViaPool.log = require('./table/log').registerLogger;
3233
connectViaPool.on = require('./table/log').on;
3334
connectViaPool.off = require('./table/log').off;

src/indexBrowser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ connectViaPool.filter = require('./emptyFilter');
1414
connectViaPool.commit = require('./table/commit');
1515
connectViaPool.rollback = require('./table/rollback');
1616
connectViaPool.end = require('./pools').end;
17+
connectViaPool.close = connectViaPool.end;
1718
connectViaPool.log = require('./table/log').registerLogger;
1819
connectViaPool.on = require('./table/log').on;
1920
connectViaPool.off = require('./table/log').off;

0 commit comments

Comments
 (0)