@carbonorm/carbonnode 3.6.7 → 3.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/api/C6Constants.d.ts +2 -0
- package/dist/api/orm/queryHelpers.d.ts +2 -0
- package/dist/api/types/ormInterfaces.d.ts +4 -1
- package/dist/index.cjs.js +121 -101
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +120 -102
- package/dist/index.esm.js.map +1 -1
- package/package.json +7 -2
- package/scripts/assets/handlebars/C6.ts.handlebars +9 -41
- package/scripts/generateRestBindings.cjs +1 -1
- package/scripts/generateRestBindings.ts +1 -1
- package/scripts/setup-git-hooks.mjs +77 -0
- package/scripts/test-hooks.sh +34 -0
- package/src/api/C6Constants.ts +1 -0
- package/src/api/executors/HttpExecutor.ts +5 -2
- package/src/api/handlers/ExpressHandler.ts +1 -1
- package/src/api/orm/builders/ConditionBuilder.ts +23 -1
- package/src/api/orm/queryHelpers.ts +16 -0
- package/src/api/types/ormInterfaces.ts +6 -2
|
@@ -795,9 +795,12 @@ export class HttpExecutor<
|
|
|
795
795
|
|
|
796
796
|
}
|
|
797
797
|
|
|
798
|
-
const
|
|
798
|
+
const ormKey = tableToFetch
|
|
799
|
+
.split('_')
|
|
800
|
+
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
|
|
801
|
+
.join('_');
|
|
799
802
|
|
|
800
|
-
const RestApi =
|
|
803
|
+
const RestApi = C6.ORM[ormKey] ?? new Error(`Fetch Dependencies could not fund table (${ormKey}) in the set ∉ [ ${Object.keys(C6.ORM).join(', ')} ]`);
|
|
801
804
|
|
|
802
805
|
console.log('%c Fetch Dependencies will select (' + tableToFetch + ') using GET request', 'color: #33ccff')
|
|
803
806
|
|
|
@@ -49,7 +49,7 @@ export function ExpressHandler({C6, mysqlPool}: { C6: iC6Object, mysqlPool: Pool
|
|
|
49
49
|
if (primary) {
|
|
50
50
|
payload[C6C.WHERE][primaryKeyName] = primary;
|
|
51
51
|
} else {
|
|
52
|
-
res.status(400).json({error: `Invalid request: ${method} requires a primary key.`});
|
|
52
|
+
res.status(400).json({error: `Invalid request: ${method} requires a primary key (${primaryKeyName}).`});
|
|
53
53
|
}
|
|
54
54
|
break;
|
|
55
55
|
case 'POST':
|
|
@@ -52,7 +52,16 @@ export abstract class ConditionBuilder<
|
|
|
52
52
|
C6C.IS, C6C.IS_NOT,
|
|
53
53
|
C6C.BETWEEN, 'NOT BETWEEN',
|
|
54
54
|
C6C.MATCH_AGAINST,
|
|
55
|
-
C6C.ST_DISTANCE_SPHERE
|
|
55
|
+
C6C.ST_DISTANCE_SPHERE,
|
|
56
|
+
// spatial predicates
|
|
57
|
+
C6C.ST_CONTAINS,
|
|
58
|
+
C6C.ST_INTERSECTS,
|
|
59
|
+
C6C.ST_WITHIN,
|
|
60
|
+
C6C.ST_CROSSES,
|
|
61
|
+
C6C.ST_DISJOINT,
|
|
62
|
+
C6C.ST_EQUALS,
|
|
63
|
+
C6C.ST_OVERLAPS,
|
|
64
|
+
C6C.ST_TOUCHES
|
|
56
65
|
]);
|
|
57
66
|
|
|
58
67
|
private isTableReference(val: any): boolean {
|
|
@@ -113,6 +122,19 @@ export abstract class ConditionBuilder<
|
|
|
113
122
|
const threshold = Array.isArray(value) ? value[0] : value;
|
|
114
123
|
return `ST_Distance_Sphere(${col1}, ${col2}) < ${this.addParam(params, '', threshold)}`;
|
|
115
124
|
}
|
|
125
|
+
if ([
|
|
126
|
+
C6C.ST_CONTAINS,
|
|
127
|
+
C6C.ST_INTERSECTS,
|
|
128
|
+
C6C.ST_WITHIN,
|
|
129
|
+
C6C.ST_CROSSES,
|
|
130
|
+
C6C.ST_DISJOINT,
|
|
131
|
+
C6C.ST_EQUALS,
|
|
132
|
+
C6C.ST_OVERLAPS,
|
|
133
|
+
C6C.ST_TOUCHES
|
|
134
|
+
].includes(column)) {
|
|
135
|
+
const [geom1, geom2] = op;
|
|
136
|
+
return `${column}(${geom1}, ${geom2})`;
|
|
137
|
+
}
|
|
116
138
|
}
|
|
117
139
|
|
|
118
140
|
const leftIsCol = this.isColumnRef(column);
|
|
@@ -16,3 +16,19 @@ export const fieldEq = (leftCol: string, rightCol: string, leftAlias: string, ri
|
|
|
16
16
|
// ST_Distance_Sphere for aliased fields
|
|
17
17
|
export const distSphere = (fromCol: string, toCol: string, fromAlias: string, toAlias: string): any[] =>
|
|
18
18
|
[C6C.ST_DISTANCE_SPHERE, F(fromCol, fromAlias), F(toCol, toAlias)];
|
|
19
|
+
|
|
20
|
+
// Build a bounding-box expression.
|
|
21
|
+
//
|
|
22
|
+
// Arguments must be provided in `(minLng, minLat, maxLng, maxLat)` order. The
|
|
23
|
+
// helper does not attempt to swap or validate coordinates; if a minimum value
|
|
24
|
+
// is greater than its corresponding maximum value, MySQL's `ST_MakeEnvelope`
|
|
25
|
+
// returns `NULL`.
|
|
26
|
+
export const bbox = (minLng: number, minLat: number, maxLng: number, maxLat: number): any[] =>
|
|
27
|
+
[C6C.ST_SRID, [C6C.ST_MAKEENVELOPE,
|
|
28
|
+
[C6C.ST_POINT, minLng, minLat],
|
|
29
|
+
[C6C.ST_POINT, maxLng, maxLat]], 4326];
|
|
30
|
+
|
|
31
|
+
// ST_Contains for map envelope/shape queries
|
|
32
|
+
export const stContains = (envelope: string, shape: string): any[] =>
|
|
33
|
+
[C6C.ST_CONTAINS, envelope, shape];
|
|
34
|
+
|
|
@@ -7,6 +7,7 @@ import {Modify} from "./modifyTypes";
|
|
|
7
7
|
import {JoinType, OrderDirection, SQLComparisonOperator, SQLFunction} from "./mysqlTypes";
|
|
8
8
|
import {CarbonReact} from "@carbonorm/carbonreact";
|
|
9
9
|
import {OrmGenerics} from "./ormGenerics";
|
|
10
|
+
import {restOrm} from "../restOrm";
|
|
10
11
|
|
|
11
12
|
export type iRestMethods = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
12
13
|
export const POST = 'POST';
|
|
@@ -255,8 +256,11 @@ export interface iC6Object<
|
|
|
255
256
|
[K in Extract<keyof RestTableInterfaces, string>]: C6RestfulModel<K, RestTableInterfaces[K], keyof RestTableInterfaces[K] & string>;
|
|
256
257
|
};
|
|
257
258
|
PREFIX: string;
|
|
258
|
-
|
|
259
|
-
|
|
259
|
+
ORM: {
|
|
260
|
+
[K in Extract<keyof RestTableInterfaces, string>]:
|
|
261
|
+
C6RestfulModel<K, RestTableInterfaces[K], keyof RestTableInterfaces[K] & string>
|
|
262
|
+
& ReturnType<typeof restOrm<OrmGenerics<any>>>
|
|
263
|
+
}[]
|
|
260
264
|
[key: string]: any;
|
|
261
265
|
}
|
|
262
266
|
|