@carbonorm/carbonnode 2.0.33 → 3.0.0
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/dist/api/carbonSqlExecutor.d.ts +17 -0
- package/dist/api/interfaces/ormInterfaces.d.ts +22 -1
- package/dist/api/rest/Blog_Categories.d.ts +37 -0
- package/dist/api/rest/Blog_Categories.test.d.ts +11 -0
- package/dist/api/rest/Blog_Images.d.ts +37 -0
- package/dist/api/rest/Blog_Images.test.d.ts +15 -0
- package/dist/api/rest/Blog_Post_Categories.d.ts +37 -0
- package/dist/api/rest/Blog_Post_Categories.test.d.ts +13 -0
- package/dist/api/rest/Blog_Post_Tags.d.ts +37 -0
- package/dist/api/rest/Blog_Post_Tags.test.d.ts +13 -0
- package/dist/api/rest/Blog_Posts.d.ts +37 -0
- package/dist/api/rest/Blog_Posts.test.d.ts +21 -0
- package/dist/api/rest/Blog_Tags.d.ts +37 -0
- package/dist/api/rest/Blog_Tags.test.d.ts +11 -0
- package/dist/api/rest/C6.d.ts +1000 -0
- package/dist/api/rest/Cache.d.ts +37 -0
- package/dist/api/rest/Cache.test.d.ts +12 -0
- package/dist/api/rest/Cities.d.ts +37 -0
- package/dist/api/rest/Cities.test.d.ts +17 -0
- package/dist/api/rest/Counties.d.ts +37 -0
- package/dist/api/rest/Counties.test.d.ts +18 -0
- package/dist/api/rest/Countries.d.ts +37 -0
- package/dist/api/rest/Countries.test.d.ts +24 -0
- package/dist/api/rest/Geometries.d.ts +37 -0
- package/dist/api/rest/Geometries.test.d.ts +16 -0
- package/dist/api/rest/Images.d.ts +37 -0
- package/dist/api/rest/Images.test.d.ts +16 -0
- package/dist/api/rest/Land_Section_Info.d.ts +37 -0
- package/dist/api/rest/Land_Section_Info.test.d.ts +15 -0
- package/dist/api/rest/Neighborhoods.d.ts +37 -0
- package/dist/api/rest/Neighborhoods.test.d.ts +12 -0
- package/dist/api/rest/Parcel_Building_Details.d.ts +37 -0
- package/dist/api/rest/Parcel_Building_Details.test.d.ts +40 -0
- package/dist/api/rest/Parcel_Neighborhoods.d.ts +37 -0
- package/dist/api/rest/Parcel_Neighborhoods.test.d.ts +15 -0
- package/dist/api/rest/Parcel_Owners.d.ts +37 -0
- package/dist/api/rest/Parcel_Owners.test.d.ts +23 -0
- package/dist/api/rest/Parcel_Sales.d.ts +37 -0
- package/dist/api/rest/Parcel_Sales.test.d.ts +19 -0
- package/dist/api/rest/Parcel_Tax_History.d.ts +37 -0
- package/dist/api/rest/Parcel_Tax_History.test.d.ts +24 -0
- package/dist/api/rest/Parcels.d.ts +37 -0
- package/dist/api/rest/Parcels.test.d.ts +42 -0
- package/dist/api/rest/Payment_Charge_Logs.d.ts +37 -0
- package/dist/api/rest/Payment_Charge_Logs.test.d.ts +17 -0
- package/dist/api/rest/Payment_Subscriptions.d.ts +37 -0
- package/dist/api/rest/Payment_Subscriptions.test.d.ts +20 -0
- package/dist/api/rest/Property_Units.d.ts +37 -0
- package/dist/api/rest/Property_Units.test.d.ts +55 -0
- package/dist/api/rest/Sources.d.ts +37 -0
- package/dist/api/rest/Sources.test.d.ts +17 -0
- package/dist/api/rest/States.d.ts +37 -0
- package/dist/api/rest/States.test.d.ts +20 -0
- package/dist/api/rest/Tax_Districts.d.ts +37 -0
- package/dist/api/rest/Tax_Districts.test.d.ts +12 -0
- package/dist/api/rest/Users.d.ts +37 -0
- package/dist/api/rest/Users.test.d.ts +14 -0
- package/dist/api/rest/Valuation_Reports.d.ts +37 -0
- package/dist/api/rest/Valuation_Reports.test.d.ts +36 -0
- package/dist/api/rest/Zip_Codes.d.ts +37 -0
- package/dist/api/rest/Zip_Codes.test.d.ts +15 -0
- package/dist/api/restRequest.d.ts +44 -21
- package/dist/index.cjs.js +903 -558
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.js +899 -557
- package/dist/index.esm.js.map +1 -1
- package/dist/variables/getEnvVar.d.ts +1 -0
- package/dist/variables/isNode.d.ts +2 -0
- package/dist/variables/isTest.d.ts +1 -1
- package/dist/variables/toastOptions.d.ts +2 -2
- package/package.json +23 -12
- package/scripts/assets/handlebars/C6.ts.handlebars +5 -1
- package/scripts/generateRestBindings.cjs +89 -23
- package/scripts/generateRestBindings.ts +100 -27
- package/src/api/carbonSqlExecutor.ts +279 -0
- package/src/api/interfaces/ormInterfaces.ts +9 -1
- package/src/api/restRequest.ts +164 -19
- package/src/index.ts +4 -0
- package/src/variables/getEnvVar.ts +15 -0
- package/src/variables/isLocal.ts +3 -6
- package/src/variables/isNode.ts +3 -0
- package/src/variables/isTest.ts +4 -16
- package/src/variables/isVerbose.ts +2 -6
package/src/api/restRequest.ts
CHANGED
|
@@ -2,8 +2,10 @@ import axiosInstance from "api/axiosInstance";
|
|
|
2
2
|
import convertForRequestBody from "api/convertForRequestBody";
|
|
3
3
|
import {iC6RestfulModel, iConstraint, iDynamicApiImport} from "api/interfaces/ormInterfaces";
|
|
4
4
|
import {AxiosInstance, AxiosPromise, AxiosResponse} from "axios";
|
|
5
|
+
import {Pool} from "mysql2/promise";
|
|
5
6
|
|
|
6
7
|
import {toast} from "react-toastify";
|
|
8
|
+
import isNode from 'variables/isNode'; // simple check: `typeof window==='undefined'`
|
|
7
9
|
import isLocal from "variables/isLocal";
|
|
8
10
|
import isTest from "variables/isTest";
|
|
9
11
|
import isVerbose from "variables/isVerbose";
|
|
@@ -267,23 +269,116 @@ export const DELETE = 'DELETE';
|
|
|
267
269
|
|
|
268
270
|
export type iRestMethods = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
269
271
|
|
|
272
|
+
// ========================
|
|
273
|
+
// 🔧 SQL Operator & Helpers
|
|
274
|
+
// ========================
|
|
275
|
+
|
|
276
|
+
export type SQLFunction =
|
|
277
|
+
| 'COUNT'
|
|
278
|
+
| 'GROUP_CONCAT'
|
|
279
|
+
| 'MAX'
|
|
280
|
+
| 'MIN'
|
|
281
|
+
| 'SUM'
|
|
282
|
+
| 'DISTINCT';
|
|
283
|
+
|
|
284
|
+
export type SQLComparisonOperator =
|
|
285
|
+
| '='
|
|
286
|
+
| '!='
|
|
287
|
+
| '<'
|
|
288
|
+
| '<='
|
|
289
|
+
| '>'
|
|
290
|
+
| '>='
|
|
291
|
+
| 'IN'
|
|
292
|
+
| 'NOT IN'
|
|
293
|
+
| 'LIKE'
|
|
294
|
+
| 'IS NULL'
|
|
295
|
+
| 'IS NOT NULL'
|
|
296
|
+
| 'BETWEEN'
|
|
297
|
+
| 'LESS_THAN'
|
|
298
|
+
| 'GREATER_THAN';
|
|
299
|
+
|
|
300
|
+
export type JoinType = 'INNER' | 'LEFT_OUTER' | 'RIGHT_OUTER';
|
|
301
|
+
|
|
302
|
+
export type OrderDirection = 'ASC' | 'DESC';
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
// ========================
|
|
306
|
+
// 📦 SELECT
|
|
307
|
+
// ========================
|
|
308
|
+
|
|
309
|
+
export type SubSelect<T = any> = {
|
|
310
|
+
subSelect: true;
|
|
311
|
+
table: string; // could be enum’d to known table names
|
|
312
|
+
args: RequestGetPutDeleteBody<T>;
|
|
313
|
+
alias: string;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
export type SelectField<T = any> =
|
|
317
|
+
| keyof T
|
|
318
|
+
| [keyof T, 'AS', string]
|
|
319
|
+
| [SQLFunction, keyof T]
|
|
320
|
+
| [SQLFunction, keyof T, string] // With alias
|
|
321
|
+
| SubSelect<T>; // Fully nested sub-select
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
// ========================
|
|
325
|
+
// 🧠 WHERE (Recursive)
|
|
326
|
+
// ========================
|
|
327
|
+
|
|
328
|
+
export type WhereClause<T = any> =
|
|
329
|
+
| Partial<T>
|
|
330
|
+
| LogicalGroup<T>
|
|
331
|
+
| ComparisonClause<T>;
|
|
332
|
+
|
|
333
|
+
export type LogicalGroup<T = any> = {
|
|
334
|
+
[logicalGroup: string]: Array<WhereClause<T>>;
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
export type ComparisonClause<T = any> = [keyof T, SQLComparisonOperator, any];
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
// ========================
|
|
341
|
+
// 🔗 JOIN
|
|
342
|
+
// ========================
|
|
343
|
+
|
|
344
|
+
export type JoinTableCondition<T = any> =
|
|
345
|
+
| Partial<T>
|
|
346
|
+
| WhereClause<T>[]
|
|
347
|
+
| ComparisonClause<T>[];
|
|
348
|
+
|
|
349
|
+
export type JoinClause<T = any> = {
|
|
350
|
+
[table: string]: JoinTableCondition<T>;
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
export type Join<T = any> = {
|
|
354
|
+
[K in JoinType]?: JoinClause<T>;
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
// ========================
|
|
359
|
+
// 📄 PAGINATION
|
|
360
|
+
// ========================
|
|
361
|
+
|
|
362
|
+
export type Pagination<T = any> = {
|
|
363
|
+
PAGE?: number;
|
|
364
|
+
LIMIT?: number | null;
|
|
365
|
+
ORDER?: Partial<Record<keyof T, OrderDirection>>;
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
// ========================
|
|
370
|
+
// 🌐 MAIN API TYPE
|
|
371
|
+
// ========================
|
|
372
|
+
|
|
373
|
+
export type RequestGetPutDeleteBody<T = any> = {
|
|
374
|
+
SELECT?: SelectField<T>[];
|
|
375
|
+
UPDATE?: Partial<T>;
|
|
376
|
+
DELETE?: boolean;
|
|
377
|
+
WHERE?: WhereClause<T>;
|
|
378
|
+
JOIN?: Join<T>;
|
|
379
|
+
PAGINATION?: Pagination<T>;
|
|
380
|
+
};
|
|
270
381
|
|
|
271
|
-
//wip
|
|
272
|
-
export type RequestGetPutDeleteBody = {
|
|
273
|
-
SELECT?: any,
|
|
274
|
-
UPDATE?: any,
|
|
275
|
-
DELETE?: any,
|
|
276
|
-
WHERE?: any,
|
|
277
|
-
JOIN?: {
|
|
278
|
-
LEFT?: any,
|
|
279
|
-
RIGHT?: any,
|
|
280
|
-
INNER?: any,
|
|
281
|
-
},
|
|
282
|
-
PAGINATION?: {
|
|
283
|
-
PAGE?: number,
|
|
284
|
-
LIMIT?: number,
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
382
|
|
|
288
383
|
export type RequestQueryBody<RestTableInterfaces extends { [key: string]: any }> =
|
|
289
384
|
iAPI<RestTableInterfaces>
|
|
@@ -350,6 +445,7 @@ interface iRest<CustomAndRequiredFields extends { [key: string]: any }, RestTabl
|
|
|
350
445
|
C6: iC6Object,
|
|
351
446
|
axios?: AxiosInstance,
|
|
352
447
|
restURL?: string,
|
|
448
|
+
mysqlPool?: Pool;
|
|
353
449
|
withCredentials?: boolean,
|
|
354
450
|
tableName: RestShortTableNames | RestShortTableNames[],
|
|
355
451
|
requestMethod: iRestMethods,
|
|
@@ -389,6 +485,7 @@ export default function restRequest<
|
|
|
389
485
|
C6,
|
|
390
486
|
axios = axiosInstance,
|
|
391
487
|
restURL = '/rest/',
|
|
488
|
+
mysqlPool,
|
|
392
489
|
withCredentials = true,
|
|
393
490
|
tableName,
|
|
394
491
|
requestMethod = GET,
|
|
@@ -423,7 +520,7 @@ export default function restRequest<
|
|
|
423
520
|
|
|
424
521
|
}
|
|
425
522
|
|
|
426
|
-
return (request: iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields = {} as iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields) => {
|
|
523
|
+
return async (request: iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields = {} as iAPI<Modify<RestTableInterfaces, RequestTableOverrides>> & CustomAndRequiredFields) => {
|
|
427
524
|
|
|
428
525
|
console.groupCollapsed('%c API: (' + requestMethod + ') Request for (' + operatingTable + ')', 'color: #0c0')
|
|
429
526
|
|
|
@@ -480,7 +577,7 @@ export default function restRequest<
|
|
|
480
577
|
}
|
|
481
578
|
|
|
482
579
|
// this could return itself with a new page number, or undefined if the end is reached
|
|
483
|
-
function apiRequest(): apiReturn<ResponseDataType
|
|
580
|
+
async function apiRequest(): Promise<apiReturn<ResponseDataType>> {
|
|
484
581
|
|
|
485
582
|
request.cacheResults ??= (C6.GET === requestMethod)
|
|
486
583
|
|
|
@@ -663,6 +760,54 @@ export default function restRequest<
|
|
|
663
760
|
|
|
664
761
|
}
|
|
665
762
|
|
|
763
|
+
// this is node check is for react bundlers to skip this import all together
|
|
764
|
+
if (isNode && mysqlPool) {
|
|
765
|
+
const { CarbonSqlExecutor } = await import('./carbonSqlExecutor');
|
|
766
|
+
const engine = new CarbonSqlExecutor(mysqlPool, C6);
|
|
767
|
+
switch (requestMethod) {
|
|
768
|
+
case GET:
|
|
769
|
+
return engine
|
|
770
|
+
.select(tableName, undefined, request)
|
|
771
|
+
.then((rows) => {
|
|
772
|
+
// mirror the front‐end shape
|
|
773
|
+
const serverResponse: iGetC6RestResponse<typeof rows> = {
|
|
774
|
+
rest: rows,
|
|
775
|
+
session: undefined,
|
|
776
|
+
sql: true,
|
|
777
|
+
};
|
|
778
|
+
return serverResponse;
|
|
779
|
+
}) as apiReturn<ResponseDataType>;
|
|
780
|
+
|
|
781
|
+
case POST:
|
|
782
|
+
return engine
|
|
783
|
+
.insert(tableName, request)
|
|
784
|
+
.then((created) => ({
|
|
785
|
+
rest: created,
|
|
786
|
+
})) as apiReturn<ResponseDataType>;
|
|
787
|
+
|
|
788
|
+
case PUT:
|
|
789
|
+
return engine
|
|
790
|
+
.update(tableName, undefined, request)
|
|
791
|
+
.then((updatedResult) => ({
|
|
792
|
+
rest: updatedResult,
|
|
793
|
+
rowCount: (updatedResult as any).affectedRows ?? 0,
|
|
794
|
+
})) as apiReturn<ResponseDataType>;
|
|
795
|
+
|
|
796
|
+
case DELETE:
|
|
797
|
+
return engine
|
|
798
|
+
.delete(tableName, undefined, request)
|
|
799
|
+
.then((deletedResult) => ({
|
|
800
|
+
rest: deletedResult,
|
|
801
|
+
rowCount: (deletedResult as any).affectedRows ?? 0,
|
|
802
|
+
deleted: true,
|
|
803
|
+
})) as apiReturn<ResponseDataType>;
|
|
804
|
+
|
|
805
|
+
default:
|
|
806
|
+
throw new Error(`Unsupported method: ${requestMethod}`);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
|
|
666
811
|
// A part of me exists that wants to remove this, but it's a good feature
|
|
667
812
|
// this allows developers the ability to cache requests based on primary key
|
|
668
813
|
// for tables like `photos` this can be a huge performance boost
|
|
@@ -1139,7 +1284,7 @@ export default function restRequest<
|
|
|
1139
1284
|
|
|
1140
1285
|
}
|
|
1141
1286
|
|
|
1142
|
-
return apiRequest()
|
|
1287
|
+
return await apiRequest()
|
|
1143
1288
|
|
|
1144
1289
|
}
|
|
1145
1290
|
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
export * from "./api/C6Constants";
|
|
6
6
|
export { default as axiosInstance } from "./api/axiosInstance";
|
|
7
7
|
export * from "./api/axiosInstance";
|
|
8
|
+
export * from "./api/carbonSqlExecutor";
|
|
8
9
|
export { default as convertForRequestBody } from "./api/convertForRequestBody";
|
|
9
10
|
export * from "./api/convertForRequestBody";
|
|
10
11
|
export { default as restRequest } from "./api/restRequest";
|
|
@@ -12,8 +13,11 @@ export * from "./api/restRequest";
|
|
|
12
13
|
export { default as timeout } from "./api/timeout";
|
|
13
14
|
export * from "./api/timeout";
|
|
14
15
|
export * from "./api/interfaces/ormInterfaces";
|
|
16
|
+
export * from "./variables/getEnvVar";
|
|
15
17
|
export { default as isLocal } from "./variables/isLocal";
|
|
16
18
|
export * from "./variables/isLocal";
|
|
19
|
+
export { default as isNode } from "./variables/isNode";
|
|
20
|
+
export * from "./variables/isNode";
|
|
17
21
|
export { default as isTest } from "./variables/isTest";
|
|
18
22
|
export * from "./variables/isTest";
|
|
19
23
|
export { default as isVerbose } from "./variables/isVerbose";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function getEnvVar(key: string, fallback = ''): string {
|
|
2
|
+
// Vite-style injection
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
if (typeof import.meta !== 'undefined' && import.meta.env && key in import.meta.env) {
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
return import.meta.env[key];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Node or SSR
|
|
10
|
+
if (typeof process !== 'undefined' && process.env && key in process.env) {
|
|
11
|
+
return process.env[key]!;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return fallback;
|
|
15
|
+
}
|
package/src/variables/isLocal.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
typeof process !== 'undefined' && process.env && process.env.NODE_ENV
|
|
3
|
-
? process.env.NODE_ENV
|
|
4
|
-
: // @ts-ignore
|
|
5
|
-
import.meta?.env?.MODE || import.meta?.env?.NODE_ENV;
|
|
1
|
+
import {getEnvVar} from "./getEnvVar";
|
|
6
2
|
|
|
7
|
-
|
|
3
|
+
|
|
4
|
+
const isDevelopment = getEnvVar('NODE_ENV', '') === 'development';
|
|
8
5
|
|
|
9
6
|
export default isDevelopment;
|
package/src/variables/isTest.ts
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
|
+
import {getEnvVar} from "./getEnvVar";
|
|
1
2
|
|
|
2
|
-
const isTest =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
(
|
|
6
|
-
process.env.JEST_WORKER_ID !== undefined ||
|
|
7
|
-
process.env.NODE_ENV === 'test' ||
|
|
8
|
-
process.env.REACT_APP_TEST === 'true'
|
|
9
|
-
) ||
|
|
10
|
-
// Vite-only branch
|
|
11
|
-
typeof import.meta !== 'undefined' &&
|
|
12
|
-
(
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
import.meta?.env?.MODE === 'test' ||
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
import.meta?.env?.VITE_TEST === 'true'
|
|
17
|
-
);
|
|
3
|
+
const isTest = getEnvVar('JEST_WORKER_ID') || getEnvVar('NODE_ENV') === 'test'
|
|
4
|
+
|| getEnvVar('REACT_APP_TEST') === 'true' || getEnvVar('VITE_TEST') === 'true'
|
|
5
|
+
|| getEnvVar('MODE') === 'test' || getEnvVar('VITE_TEST_MODE') === 'true';
|
|
18
6
|
|
|
19
7
|
export default isTest;
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
+
import {getEnvVar} from "./getEnvVar";
|
|
1
2
|
|
|
2
|
-
const envVerbose =
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import.meta?.env?.VITE_VERBOSE ?? // Vite-style
|
|
5
|
-
process?.env?.REACT_APP_VERBOSE ?? // CRA-style
|
|
6
|
-
process?.env?.VERBOSE ?? // Fallback (e.g., Node.js, or other bundlers)
|
|
7
|
-
'';
|
|
3
|
+
const envVerbose = getEnvVar('VERBOSE') || getEnvVar('REACT_APP_VERBOSE') || getEnvVar('VITE_VERBOSE') || ''
|
|
8
4
|
|
|
9
5
|
const isVerbose = ['true', '1', 'yes', 'on'].includes(envVerbose.toLowerCase());
|
|
10
6
|
|