@ldsg/tables 0.3.9 → 0.3.11
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/constants.d.ts +3 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +10 -9
- package/dist/handler.d.ts +5 -7
- package/dist/handler.d.ts.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/instantiate-resource.d.ts +4 -4
- package/dist/instantiate-resource.js +1 -1
- package/dist/resource.d.ts +6 -4
- package/dist/resource.d.ts.map +1 -1
- package/dist/resource.js +9 -4
- package/dist/types/get-table-info.d.ts +3 -3
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/query-types.d.ts +69 -0
- package/dist/types/query-types.d.ts.map +1 -0
- package/dist/types/query-types.js +2 -0
- package/dist/types/specific-resource-settings.d.ts +1 -1
- package/dist/types/specific-resource-settings.d.ts.map +1 -1
- package/dist/utils/add-fields/constants.d.ts +1 -1
- package/dist/utils/add-fields/constants.js +17 -17
- package/dist/utils/add-fields/index.d.ts +11 -4
- package/dist/utils/add-fields/index.d.ts.map +1 -1
- package/dist/utils/add-fields/index.js +25 -24
- package/dist/utils/add-fields/utils/get-object-type-composer.d.ts +11 -7
- package/dist/utils/add-fields/utils/get-object-type-composer.d.ts.map +1 -1
- package/dist/utils/add-fields/utils/get-object-type-composer.js +18 -12
- package/dist/utils/add-fields/utils/index.d.ts +1 -1
- package/dist/utils/add-query-fields/index.d.ts +10 -0
- package/dist/utils/add-query-fields/index.d.ts.map +1 -0
- package/dist/utils/add-query-fields/index.js +26 -0
- package/dist/utils/add-query-fields/utils/create-resolvers.d.ts +21 -0
- package/dist/utils/add-query-fields/utils/create-resolvers.d.ts.map +1 -0
- package/dist/utils/add-query-fields/utils/create-resolvers.js +37 -0
- package/dist/utils/add-query-fields/utils/create-types.d.ts +10 -0
- package/dist/utils/add-query-fields/utils/create-types.d.ts.map +1 -0
- package/dist/utils/add-query-fields/utils/create-types.js +96 -0
- package/dist/utils/add-query-fields/utils/get-json-schema.d.ts +6 -0
- package/dist/utils/add-query-fields/utils/get-json-schema.d.ts.map +1 -0
- package/dist/utils/add-query-fields/utils/get-json-schema.js +52 -0
- package/dist/utils/add-query-fields/utils/map-table-info.d.ts +11 -0
- package/dist/utils/add-query-fields/utils/map-table-info.d.ts.map +1 -0
- package/dist/utils/add-query-fields/utils/map-table-info.js +32 -0
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/package.json +23 -18
package/dist/constants.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HandlerSpecificResourceSettings } from
|
|
2
|
-
import { ResourceDefinitionSpecificResourceSettings } from
|
|
3
|
-
import { GeneralResourceSettings } from
|
|
1
|
+
import { HandlerSpecificResourceSettings } from '@ldsg/handler';
|
|
2
|
+
import { ResourceDefinitionSpecificResourceSettings } from '@ldsg/resource-definition';
|
|
3
|
+
import { GeneralResourceSettings } from '@ldsg/types';
|
|
4
4
|
/**
|
|
5
5
|
* Instantiate Resource Handler General Resource Settings
|
|
6
6
|
* 实例化资源处理程序普通资源配置
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,0CAA0C,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;GAGG;AACH,eAAO,MAAM,sDAAsD,EAAE,uBAGpE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uDAAuD,EAAE,+BAOrE,CAAC;AAEF,eAAO,MAAM,6CAA6C,EAAE,uBAG3D,CAAC;AAEF,eAAO,MAAM,8CAA8C,EAAE,0CAE5D,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = exports.INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS = exports.INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS = void 0;
|
|
4
|
-
const application_1 = require("@ldsg/application");
|
|
5
4
|
/**
|
|
6
5
|
* Instantiate Resource Handler General Resource Settings
|
|
7
6
|
* 实例化资源处理程序普通资源配置
|
|
8
7
|
*/
|
|
9
8
|
exports.INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS = {
|
|
10
|
-
title:
|
|
11
|
-
description:
|
|
9
|
+
title: '表格组实例化资源处理程序',
|
|
10
|
+
description: ''
|
|
12
11
|
};
|
|
13
12
|
/**
|
|
14
13
|
* Instantiate Resource Handler Specific Resource Settings
|
|
@@ -19,12 +18,14 @@ exports.INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS = {
|
|
|
19
18
|
code: `export * from "@ldsg/tables";`,
|
|
20
19
|
dependencies: [
|
|
21
20
|
{
|
|
22
|
-
name:
|
|
23
|
-
}
|
|
24
|
-
]
|
|
21
|
+
name: '@ldsg/tables'
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
};
|
|
25
|
+
exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = {
|
|
26
|
+
title: '表格组资源定义',
|
|
27
|
+
description: ''
|
|
25
28
|
};
|
|
26
|
-
exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = { title: "表格组资源定义", description: "" };
|
|
27
29
|
exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = {
|
|
28
|
-
kind:
|
|
29
|
-
parentKind: application_1.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS.kind,
|
|
30
|
+
kind: 'tables'
|
|
30
31
|
};
|
package/dist/handler.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { Handler, HandlerExtendedResourceSettings } from
|
|
2
|
-
import { InstantiateResourceParams, InstantiateResourceRes } from
|
|
3
|
-
import { TablesResource } from
|
|
4
|
-
import { TablesSpecificResourceSettings } from
|
|
5
|
-
export declare const handler: Handler<
|
|
6
|
-
InstantiateResourceParams<HandlerExtendedResourceSettings<TablesSpecificResourceSettings>>
|
|
7
|
-
], InstantiateResourceRes<TablesResource>>;
|
|
1
|
+
import { Handler, HandlerExtendedResourceSettings } from '@ldsg/handler';
|
|
2
|
+
import { InstantiateResourceParams, InstantiateResourceRes } from '@ldsg/resource';
|
|
3
|
+
import { TablesResource } from './resource';
|
|
4
|
+
import { TablesSpecificResourceSettings } from './types';
|
|
5
|
+
export declare const handler: Handler<InstantiateResourceParams<HandlerExtendedResourceSettings<TablesSpecificResourceSettings>>, InstantiateResourceRes<TablesResource>>;
|
|
8
6
|
//# sourceMappingURL=handler.d.ts.map
|
package/dist/handler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAEnF,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,8BAA8B,EAAE,MAAM,SAAS,CAAC;AAEzD,eAAO,MAAM,OAAO,EAAE,OAAO,CAC3B,yBAAyB,CAAC,+BAA+B,CAAC,8BAA8B,CAAC,CAAC,EAC1F,sBAAsB,CAAC,cAAc,CAAC,CACjB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from './constants';
|
|
2
|
+
export * from './handler';
|
|
3
|
+
export * from './instantiate-resource';
|
|
4
|
+
export * from './resource';
|
|
5
|
+
export * from './types';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HandlerExtendedResourceSettings } from
|
|
2
|
-
import { InstantiateResource } from
|
|
3
|
-
import { TablesResource } from
|
|
4
|
-
import { TablesSpecificResourceSettings } from
|
|
1
|
+
import { HandlerExtendedResourceSettings } from '@ldsg/handler';
|
|
2
|
+
import { InstantiateResource } from '@ldsg/resource';
|
|
3
|
+
import { TablesResource } from './resource';
|
|
4
|
+
import { TablesSpecificResourceSettings } from './types';
|
|
5
5
|
export declare const instantiateResource: InstantiateResource<HandlerExtendedResourceSettings<TablesSpecificResourceSettings>, TablesResource>;
|
|
6
6
|
//# sourceMappingURL=instantiate-resource.d.ts.map
|
package/dist/resource.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { PlatformsParams } from
|
|
2
|
-
import { ModifyGraphQLSchema } from
|
|
3
|
-
import { Resource } from
|
|
4
|
-
import { TableInfo, TablesSpecificResourceSettings } from
|
|
1
|
+
import { PlatformsParams } from '@ldsg/field-type';
|
|
2
|
+
import { ModifyGraphQLSchema } from '@ldsg/graphql';
|
|
3
|
+
import { Resource } from '@ldsg/resource';
|
|
4
|
+
import { TableInfo, TablesSpecificResourceSettings } from './types';
|
|
5
|
+
import { MongooseModels } from './utils';
|
|
5
6
|
interface GetTableInfoListRes {
|
|
6
7
|
/**
|
|
7
8
|
* Table Info List
|
|
@@ -10,6 +11,7 @@ interface GetTableInfoListRes {
|
|
|
10
11
|
}
|
|
11
12
|
type GetTableInfoList = (params?: PlatformsParams) => GetTableInfoListRes;
|
|
12
13
|
export declare class TablesResource extends Resource<TablesSpecificResourceSettings> {
|
|
14
|
+
mongooseModels?: MongooseModels;
|
|
13
15
|
getTableInfoList: GetTableInfoList;
|
|
14
16
|
modifyGraphQLSchema: ModifyGraphQLSchema;
|
|
15
17
|
}
|
package/dist/resource.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAgB,SAAS,EAAE,8BAA8B,EAAE,MAAM,SAAS,CAAC;AAClF,OAAO,EAA6B,cAAc,EAAE,MAAM,SAAS,CAAC;AAEpE,UAAU,mBAAmB;IAC3B;;OAEG;IACH,aAAa,EAAE,SAAS,EAAE,CAAC;CAC5B;AAED,KAAK,gBAAgB,GAAG,CAAC,MAAM,CAAC,EAAE,eAAe,KAAK,mBAAmB,CAAC;AAE1E,qBAAa,cAAe,SAAQ,QAAQ,CAAC,8BAA8B,CAAC;IAC1E,cAAc,CAAC,EAAE,cAAc,CAAC;IAEhC,gBAAgB,EAAE,gBAAgB,CAoBhC;IAEF,mBAAmB,EAAE,mBAAmB,CAgBtC;CACH"}
|
package/dist/resource.js
CHANGED
|
@@ -13,7 +13,7 @@ class TablesResource extends resource_1.Resource {
|
|
|
13
13
|
this.getTableInfoList = (params) => {
|
|
14
14
|
const { id, getFilteredResources } = this;
|
|
15
15
|
const { resources } = getFilteredResources({
|
|
16
|
-
parentId: id
|
|
16
|
+
parentId: id
|
|
17
17
|
});
|
|
18
18
|
const mapRes = resources.map((resource) => {
|
|
19
19
|
var _a;
|
|
@@ -21,16 +21,21 @@ class TablesResource extends resource_1.Resource {
|
|
|
21
21
|
});
|
|
22
22
|
const tableInfoList = lodash_1.default.filter(mapRes, (value) => !lodash_1.default.isUndefined(value));
|
|
23
23
|
const res = {
|
|
24
|
-
tableInfoList
|
|
24
|
+
tableInfoList
|
|
25
25
|
};
|
|
26
26
|
return res;
|
|
27
27
|
};
|
|
28
28
|
this.modifyGraphQLSchema = (params) => {
|
|
29
29
|
const { schemaComposer } = params;
|
|
30
30
|
const { tableInfoList } = this.getTableInfoList();
|
|
31
|
-
(0, utils_1.addFields)({
|
|
31
|
+
const { mongooseModels } = (0, utils_1.addFields)({
|
|
32
|
+
tableInfoList,
|
|
33
|
+
schemaComposer
|
|
34
|
+
});
|
|
35
|
+
this.mongooseModels = mongooseModels;
|
|
36
|
+
(0, utils_1.addQueryFields)({
|
|
32
37
|
tableInfoList,
|
|
33
|
-
schemaComposer
|
|
38
|
+
schemaComposer
|
|
34
39
|
});
|
|
35
40
|
};
|
|
36
41
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PlatformsParams } from
|
|
2
|
-
import { ObjectInfo } from
|
|
3
|
-
import { GeneralResourceSettings } from
|
|
1
|
+
import { PlatformsParams } from '@ldsg/field-type';
|
|
2
|
+
import { ObjectInfo } from '@ldsg/object';
|
|
3
|
+
import { GeneralResourceSettings } from '@ldsg/types';
|
|
4
4
|
export interface TableInfo extends GeneralResourceSettings {
|
|
5
5
|
/**
|
|
6
6
|
* Table Name
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC"}
|
package/dist/types/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./get-table-info"), exports);
|
|
18
|
+
__exportStar(require("./query-types"), exports);
|
|
18
19
|
__exportStar(require("./specific-resource-settings"), exports);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { FieldInfo } from '@ldsg/object';
|
|
2
|
+
/**
|
|
3
|
+
* Object information with generated schemas
|
|
4
|
+
*/
|
|
5
|
+
export interface TableObjectInfo {
|
|
6
|
+
/**
|
|
7
|
+
* Object name
|
|
8
|
+
*/
|
|
9
|
+
name: string;
|
|
10
|
+
/**
|
|
11
|
+
* Object title
|
|
12
|
+
*/
|
|
13
|
+
title?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Object description
|
|
16
|
+
*/
|
|
17
|
+
description?: string;
|
|
18
|
+
/**
|
|
19
|
+
* List of field information
|
|
20
|
+
*/
|
|
21
|
+
fieldInfoList: FieldInfo[];
|
|
22
|
+
/**
|
|
23
|
+
* JSON Schema for the object
|
|
24
|
+
*/
|
|
25
|
+
jsonSchema: any;
|
|
26
|
+
/**
|
|
27
|
+
* Mongoose Schema (for reference)
|
|
28
|
+
*/
|
|
29
|
+
mongooseSchema?: any;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Lightweight table metadata
|
|
33
|
+
*/
|
|
34
|
+
export interface TableMetadata {
|
|
35
|
+
/**
|
|
36
|
+
* Table name
|
|
37
|
+
*/
|
|
38
|
+
name: string;
|
|
39
|
+
/**
|
|
40
|
+
* Human-readable table title
|
|
41
|
+
*/
|
|
42
|
+
title?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Optional table description
|
|
45
|
+
*/
|
|
46
|
+
description?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Detailed table information with schemas
|
|
50
|
+
*/
|
|
51
|
+
export interface TableDetail {
|
|
52
|
+
/**
|
|
53
|
+
* Table name
|
|
54
|
+
*/
|
|
55
|
+
name: string;
|
|
56
|
+
/**
|
|
57
|
+
* Human-readable table title
|
|
58
|
+
*/
|
|
59
|
+
title?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Optional table description
|
|
62
|
+
*/
|
|
63
|
+
description?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Object information
|
|
66
|
+
*/
|
|
67
|
+
objectInfo: TableObjectInfo;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=query-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-types.d.ts","sourceRoot":"","sources":["../../src/types/query-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,EAAE,SAAS,EAAE,CAAC;IAE3B;;OAEG;IACH,UAAU,EAAE,GAAG,CAAC;IAEhB;;OAEG;IACH,cAAc,CAAC,EAAE,GAAG,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,UAAU,EAAE,eAAe,CAAC;CAC7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specific-resource-settings.d.ts","sourceRoot":"","sources":["../../src/types/specific-resource-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"specific-resource-settings.d.ts","sourceRoot":"","sources":["../../src/types/specific-resource-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,WAAW,8BAA+B,SAAQ,wBAAwB;CAAG"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolverFactory } from
|
|
1
|
+
import { resolverFactory } from 'graphql-compose-mongoose';
|
|
2
2
|
export type ResolverFactoryKeyList = (keyof typeof resolverFactory)[];
|
|
3
3
|
export declare const MUTATION_RESOLVER_FACTORY_KEY_LIST: ResolverFactoryKeyList;
|
|
4
4
|
export declare const QUERY_RESOLVER_FACTORY_KEY_LIST: ResolverFactoryKeyList;
|
|
@@ -2,23 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QUERY_RESOLVER_FACTORY_KEY_LIST = exports.MUTATION_RESOLVER_FACTORY_KEY_LIST = void 0;
|
|
4
4
|
exports.MUTATION_RESOLVER_FACTORY_KEY_LIST = [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
'createOne',
|
|
6
|
+
'createMany',
|
|
7
|
+
'updateById',
|
|
8
|
+
'updateOne',
|
|
9
|
+
'updateMany',
|
|
10
|
+
'removeById',
|
|
11
|
+
'removeOne',
|
|
12
|
+
'removeMany'
|
|
13
13
|
];
|
|
14
14
|
exports.QUERY_RESOLVER_FACTORY_KEY_LIST = [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
'findById',
|
|
16
|
+
'findByIds',
|
|
17
|
+
'findOne',
|
|
18
|
+
'findMany',
|
|
19
|
+
'dataLoader',
|
|
20
|
+
'dataLoaderMany',
|
|
21
|
+
'count',
|
|
22
|
+
'connection',
|
|
23
|
+
'pagination'
|
|
24
24
|
];
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import { SchemaComposerParams } from
|
|
2
|
-
import
|
|
1
|
+
import { SchemaComposerParams } from '@ldsg/graphql';
|
|
2
|
+
import mongoose from 'mongoose';
|
|
3
|
+
import { TableInfo } from '../../types';
|
|
4
|
+
import { getObjectTC } from './utils';
|
|
5
|
+
export * from './constants';
|
|
6
|
+
export { getObjectTC };
|
|
3
7
|
interface AddFieldsParams extends SchemaComposerParams {
|
|
4
8
|
tableInfoList: TableInfo[];
|
|
5
9
|
}
|
|
6
|
-
type
|
|
10
|
+
export type MongooseModels = Record<string, mongoose.Model<any>>;
|
|
11
|
+
interface AddFieldsRes {
|
|
12
|
+
mongooseModels: MongooseModels;
|
|
13
|
+
}
|
|
14
|
+
type AddFields = (params: AddFieldsParams) => AddFieldsRes;
|
|
7
15
|
export declare const addFields: AddFields;
|
|
8
|
-
export {};
|
|
9
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/add-fields/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAGrD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/add-fields/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAGrD,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB,UAAU,eAAgB,SAAQ,oBAAoB;IACpD,aAAa,EAAE,SAAS,EAAE,CAAC;CAC5B;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAEjE,UAAU,YAAY;IACpB,cAAc,EAAE,cAAc,CAAC;CAChC;AAED,KAAK,SAAS,GAAG,CAAC,MAAM,EAAE,eAAe,KAAK,YAAY,CAAC;AAE3D,eAAO,MAAM,SAAS,EAAE,SAsBvB,CAAC"}
|
|
@@ -1,41 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
18
|
};
|
|
5
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.addFields = void 0;
|
|
7
|
-
const graphql_compose_mongoose_1 = require("graphql-compose-mongoose");
|
|
20
|
+
exports.addFields = exports.getObjectTC = void 0;
|
|
8
21
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
-
const constants_1 = require("./constants");
|
|
10
22
|
const utils_1 = require("./utils");
|
|
23
|
+
Object.defineProperty(exports, "getObjectTC", { enumerable: true, get: function () { return utils_1.getObjectTC; } });
|
|
24
|
+
__exportStar(require("./constants"), exports);
|
|
11
25
|
const addFields = (params) => {
|
|
12
26
|
const { schemaComposer, tableInfoList } = params;
|
|
13
|
-
const
|
|
14
|
-
const queryNewFields = {};
|
|
15
|
-
const resolverFactoryKeys = lodash_1.default.keys(graphql_compose_mongoose_1.resolverFactory);
|
|
16
|
-
/**
|
|
17
|
-
* TODO:如果 table name 重名就抛出异常
|
|
18
|
-
*/
|
|
27
|
+
const mongooseModels = {};
|
|
19
28
|
lodash_1.default.each(tableInfoList, (tableInfo) => {
|
|
20
29
|
const { title, description, name: tableName, objectInfo } = tableInfo;
|
|
21
|
-
const { objectTypeComposer } = (0, utils_1.
|
|
30
|
+
const { modelName, mongooseModel, objectTypeComposer } = (0, utils_1.getObjectTC)({
|
|
22
31
|
tableName,
|
|
23
32
|
objectInfo,
|
|
33
|
+
schemaComposer
|
|
24
34
|
});
|
|
25
|
-
|
|
26
|
-
var _a, _b, _c, _d;
|
|
27
|
-
const fieldName = lodash_1.default.camelCase(`${tableName}-${key}`);
|
|
28
|
-
if (constants_1.MUTATION_RESOLVER_FACTORY_KEY_LIST.includes(key)) {
|
|
29
|
-
mutationNewFields[fieldName] =
|
|
30
|
-
(_b = (_a = objectTypeComposer.mongooseResolvers)[key]) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
31
|
-
}
|
|
32
|
-
else if (constants_1.QUERY_RESOLVER_FACTORY_KEY_LIST.includes(key)) {
|
|
33
|
-
queryNewFields[fieldName] =
|
|
34
|
-
(_d = (_c = objectTypeComposer.mongooseResolvers)[key]) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
35
|
+
mongooseModels[modelName] = mongooseModel;
|
|
37
36
|
});
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const res = {
|
|
38
|
+
mongooseModels
|
|
39
|
+
};
|
|
40
|
+
return res;
|
|
40
41
|
};
|
|
41
42
|
exports.addFields = addFields;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import { ObjectInfo } from
|
|
2
|
-
import { ObjectTypeComposerWithMongooseResolvers } from
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { ObjectInfo } from '@ldsg/object';
|
|
2
|
+
import { ObjectTypeComposerWithMongooseResolvers } from 'graphql-compose-mongoose';
|
|
3
|
+
import { SchemaComposer } from 'graphql-compose';
|
|
4
|
+
import mongoose from 'mongoose';
|
|
5
|
+
interface GetObjectTCParams {
|
|
5
6
|
tableName: string;
|
|
6
7
|
objectInfo: ObjectInfo;
|
|
8
|
+
schemaComposer: SchemaComposer;
|
|
7
9
|
}
|
|
8
|
-
interface
|
|
10
|
+
interface GetObjectTCRes {
|
|
11
|
+
modelName: string;
|
|
12
|
+
mongooseModel: mongoose.Model<any>;
|
|
9
13
|
objectTypeComposer: ObjectTypeComposerWithMongooseResolvers<mongoose.Document<any, any, any>, any>;
|
|
10
14
|
}
|
|
11
|
-
type
|
|
12
|
-
export declare const
|
|
15
|
+
type GetObjectTC = (params: GetObjectTCParams) => GetObjectTCRes;
|
|
16
|
+
export declare const getObjectTC: GetObjectTC;
|
|
13
17
|
export {};
|
|
14
18
|
//# sourceMappingURL=get-object-type-composer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-object-type-composer.d.ts","sourceRoot":"","sources":["../../../../src/utils/add-fields/utils/get-object-type-composer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"get-object-type-composer.d.ts","sourceRoot":"","sources":["../../../../src/utils/add-fields/utils/get-object-type-composer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAmB,uCAAuC,EAAE,MAAM,0BAA0B,CAAC;AACpG,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,QAA8B,MAAM,UAAU,CAAC;AAEtD,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,UAAU,CAAC;IACvB,cAAc,EAAE,cAAc,CAAC;CAChC;AAED,UAAU,cAAc;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnC,kBAAkB,EAAE,uCAAuC,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;CACpG;AAED,KAAK,WAAW,GAAG,CAAC,MAAM,EAAE,iBAAiB,KAAK,cAAc,CAAC;AAEjE,eAAO,MAAM,WAAW,EAAE,WAgDzB,CAAC"}
|
|
@@ -3,30 +3,36 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getObjectTC = void 0;
|
|
7
7
|
const graphql_compose_mongoose_1 = require("graphql-compose-mongoose");
|
|
8
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
9
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
10
|
-
const
|
|
11
|
-
const { tableName, objectInfo } = params;
|
|
10
|
+
const getObjectTC = (params) => {
|
|
11
|
+
const { tableName, objectInfo, schemaComposer } = params;
|
|
12
12
|
const { fieldInfoList } = objectInfo;
|
|
13
13
|
const mongooseSchemaDefinition = {};
|
|
14
14
|
lodash_1.default.each(fieldInfoList, (fieldInfo) => {
|
|
15
|
-
const { name, typeInfo: { platformToTypeMap }
|
|
15
|
+
const { name, typeInfo: { platformToTypeMap } } = fieldInfo;
|
|
16
16
|
const { COMMON, MONGOOSE } = platformToTypeMap;
|
|
17
17
|
const type = MONGOOSE !== null && MONGOOSE !== void 0 ? MONGOOSE : COMMON;
|
|
18
|
-
|
|
18
|
+
const fieldName = lodash_1.default.camelCase(name);
|
|
19
|
+
mongooseSchemaDefinition[fieldName] = type;
|
|
20
|
+
});
|
|
21
|
+
const collectionName = lodash_1.default.snakeCase(tableName);
|
|
22
|
+
const mongooseSchema = new mongoose_1.default.Schema(mongooseSchemaDefinition, {
|
|
23
|
+
collection: collectionName
|
|
19
24
|
});
|
|
20
|
-
const mongooseSchema = new mongoose_1.default.Schema(mongooseSchemaDefinition);
|
|
21
25
|
const modelName = lodash_1.default.upperFirst(lodash_1.default.camelCase(tableName));
|
|
22
26
|
const mongooseModel = mongoose_1.default.model(modelName, mongooseSchema);
|
|
23
|
-
const customizationOptions = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
mongooseModel, customizationOptions);
|
|
27
|
+
const customizationOptions = {
|
|
28
|
+
schemaComposer: schemaComposer
|
|
29
|
+
};
|
|
30
|
+
const objectTypeComposer = (0, graphql_compose_mongoose_1.composeMongoose)(mongooseModel, customizationOptions);
|
|
27
31
|
const res = {
|
|
28
|
-
|
|
32
|
+
modelName,
|
|
33
|
+
mongooseModel,
|
|
34
|
+
objectTypeComposer
|
|
29
35
|
};
|
|
30
36
|
return res;
|
|
31
37
|
};
|
|
32
|
-
exports.
|
|
38
|
+
exports.getObjectTC = getObjectTC;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './get-object-type-composer';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SchemaComposerParams } from '@ldsg/graphql';
|
|
2
|
+
import { TableInfo } from '../../types';
|
|
3
|
+
export interface AddQueryFieldsParams extends SchemaComposerParams {
|
|
4
|
+
tableInfoList: TableInfo[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Adds `table` and `tables` query fields to the GraphQL schema
|
|
8
|
+
*/
|
|
9
|
+
export declare function addQueryFields(params: AddQueryFieldsParams): void;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/add-query-fields/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIxC,MAAM,WAAW,oBAAqB,SAAQ,oBAAoB;IAChE,aAAa,EAAE,SAAS,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAqBjE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addQueryFields = addQueryFields;
|
|
4
|
+
const create_types_1 = require("./utils/create-types");
|
|
5
|
+
const create_resolvers_1 = require("./utils/create-resolvers");
|
|
6
|
+
/**
|
|
7
|
+
* Adds `table` and `tables` query fields to the GraphQL schema
|
|
8
|
+
*/
|
|
9
|
+
function addQueryFields(params) {
|
|
10
|
+
const { schemaComposer, tableInfoList } = params;
|
|
11
|
+
const { Query } = schemaComposer;
|
|
12
|
+
// Create GraphQL types
|
|
13
|
+
const tableDetailTC = (0, create_types_1.createTableDetailTC)(schemaComposer);
|
|
14
|
+
const tableMetadataTC = (0, create_types_1.createTableMetadataTC)(schemaComposer);
|
|
15
|
+
// Add the types to the schema
|
|
16
|
+
schemaComposer.addSchemaMustHaveType(tableDetailTC);
|
|
17
|
+
schemaComposer.addSchemaMustHaveType(tableMetadataTC);
|
|
18
|
+
// Create resolvers
|
|
19
|
+
const tableResolver = (0, create_resolvers_1.createTableResolver)(tableInfoList);
|
|
20
|
+
const tablesResolver = (0, create_resolvers_1.createTablesResolver)(tableInfoList);
|
|
21
|
+
// Add fields to Query type
|
|
22
|
+
Query.addFields({
|
|
23
|
+
table: tableResolver,
|
|
24
|
+
tables: tablesResolver
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TableInfo } from '../../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a resolver definition for querying a single table by name
|
|
4
|
+
*/
|
|
5
|
+
export declare function createTableResolver(tableInfoList: TableInfo[]): {
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
args: {
|
|
9
|
+
name: string;
|
|
10
|
+
};
|
|
11
|
+
resolve: (_root: any, args: any) => Promise<import("../../../types").TableDetail>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Creates a resolver definition for querying all tables
|
|
15
|
+
*/
|
|
16
|
+
export declare function createTablesResolver(tableInfoList: TableInfo[]): {
|
|
17
|
+
name: string;
|
|
18
|
+
type: string;
|
|
19
|
+
resolve: () => Promise<import("../../../types").TableMetadata[]>;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=create-resolvers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-resolvers.d.ts","sourceRoot":"","sources":["../../../../src/utils/add-query-fields/utils/create-resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,SAAS,EAAE;;;;;;qBAOnC,GAAG,QAAQ,GAAG;EAWxC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,SAAS,EAAE;;;;EAQ9D"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTableResolver = createTableResolver;
|
|
4
|
+
exports.createTablesResolver = createTablesResolver;
|
|
5
|
+
const map_table_info_1 = require("./map-table-info");
|
|
6
|
+
/**
|
|
7
|
+
* Creates a resolver definition for querying a single table by name
|
|
8
|
+
*/
|
|
9
|
+
function createTableResolver(tableInfoList) {
|
|
10
|
+
return {
|
|
11
|
+
name: 'table',
|
|
12
|
+
type: 'TableDetail',
|
|
13
|
+
args: {
|
|
14
|
+
name: 'String!'
|
|
15
|
+
},
|
|
16
|
+
resolve: async (_root, args) => {
|
|
17
|
+
const { name } = args;
|
|
18
|
+
const tableInfo = tableInfoList.find((t) => t.name === name);
|
|
19
|
+
if (!tableInfo) {
|
|
20
|
+
throw new Error(`Table not found: ${name}`);
|
|
21
|
+
}
|
|
22
|
+
return (0, map_table_info_1.mapTableInfoToDetail)(tableInfo);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a resolver definition for querying all tables
|
|
28
|
+
*/
|
|
29
|
+
function createTablesResolver(tableInfoList) {
|
|
30
|
+
return {
|
|
31
|
+
name: 'tables',
|
|
32
|
+
type: '[TableMetadata!]!',
|
|
33
|
+
resolve: async () => {
|
|
34
|
+
return tableInfoList.map((t) => (0, map_table_info_1.mapTableInfoToMetadata)(t));
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ObjectTypeComposer, SchemaComposer } from 'graphql-compose';
|
|
2
|
+
/**
|
|
3
|
+
* Creates GraphQL type for TableMetadata
|
|
4
|
+
*/
|
|
5
|
+
export declare function createTableMetadataTC(schemaComposer: SchemaComposer): ObjectTypeComposer<any, any>;
|
|
6
|
+
/**
|
|
7
|
+
* Creates GraphQL type for TableDetail
|
|
8
|
+
*/
|
|
9
|
+
export declare function createTableDetailTC(schemaComposer: SchemaComposer): ObjectTypeComposer<any, any>;
|
|
10
|
+
//# sourceMappingURL=create-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-types.d.ts","sourceRoot":"","sources":["../../../../src/utils/add-query-fields/utils/create-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAyCrE;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,cAAc,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAsBlG;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,cAAc,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CA4BhG"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTableMetadataTC = createTableMetadataTC;
|
|
4
|
+
exports.createTableDetailTC = createTableDetailTC;
|
|
5
|
+
/**
|
|
6
|
+
* Creates GraphQL type for TableObjectInfo
|
|
7
|
+
*/
|
|
8
|
+
function createTableObjectInfoTC(schemaComposer) {
|
|
9
|
+
if (schemaComposer.has('TableObjectInfo')) {
|
|
10
|
+
return schemaComposer.getOTC('TableObjectInfo');
|
|
11
|
+
}
|
|
12
|
+
return schemaComposer.createObjectTC({
|
|
13
|
+
name: 'TableObjectInfo',
|
|
14
|
+
fields: {
|
|
15
|
+
name: {
|
|
16
|
+
type: 'String',
|
|
17
|
+
description: 'Object name'
|
|
18
|
+
},
|
|
19
|
+
title: {
|
|
20
|
+
type: 'String',
|
|
21
|
+
description: 'Object title'
|
|
22
|
+
},
|
|
23
|
+
description: {
|
|
24
|
+
type: 'String',
|
|
25
|
+
description: 'Object description'
|
|
26
|
+
},
|
|
27
|
+
fieldInfoList: {
|
|
28
|
+
type: 'JSON',
|
|
29
|
+
description: 'List of field information'
|
|
30
|
+
},
|
|
31
|
+
jsonSchema: {
|
|
32
|
+
type: 'JSON',
|
|
33
|
+
description: 'JSON Schema for the object'
|
|
34
|
+
},
|
|
35
|
+
mongooseSchema: {
|
|
36
|
+
type: 'JSON',
|
|
37
|
+
description: 'Mongoose Schema reference'
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates GraphQL type for TableMetadata
|
|
44
|
+
*/
|
|
45
|
+
function createTableMetadataTC(schemaComposer) {
|
|
46
|
+
if (schemaComposer.has('TableMetadata')) {
|
|
47
|
+
return schemaComposer.getOTC('TableMetadata');
|
|
48
|
+
}
|
|
49
|
+
return schemaComposer.createObjectTC({
|
|
50
|
+
name: 'TableMetadata',
|
|
51
|
+
fields: {
|
|
52
|
+
name: {
|
|
53
|
+
type: 'String!',
|
|
54
|
+
description: 'Table name'
|
|
55
|
+
},
|
|
56
|
+
title: {
|
|
57
|
+
type: 'String',
|
|
58
|
+
description: 'Human-readable table title'
|
|
59
|
+
},
|
|
60
|
+
description: {
|
|
61
|
+
type: 'String',
|
|
62
|
+
description: 'Optional table description'
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates GraphQL type for TableDetail
|
|
69
|
+
*/
|
|
70
|
+
function createTableDetailTC(schemaComposer) {
|
|
71
|
+
if (schemaComposer.has('TableDetail')) {
|
|
72
|
+
return schemaComposer.getOTC('TableDetail');
|
|
73
|
+
}
|
|
74
|
+
const tableObjectInfoTC = createTableObjectInfoTC(schemaComposer);
|
|
75
|
+
return schemaComposer.createObjectTC({
|
|
76
|
+
name: 'TableDetail',
|
|
77
|
+
fields: {
|
|
78
|
+
name: {
|
|
79
|
+
type: 'String!',
|
|
80
|
+
description: 'Table name'
|
|
81
|
+
},
|
|
82
|
+
title: {
|
|
83
|
+
type: 'String',
|
|
84
|
+
description: 'Human-readable table title'
|
|
85
|
+
},
|
|
86
|
+
description: {
|
|
87
|
+
type: 'String',
|
|
88
|
+
description: 'Optional table description'
|
|
89
|
+
},
|
|
90
|
+
objectInfo: {
|
|
91
|
+
type: tableObjectInfoTC,
|
|
92
|
+
description: 'Object information'
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-json-schema.d.ts","sourceRoot":"","sources":["../../../../src/utils/add-query-fields/utils/get-json-schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAsCzC;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,aAAa,EAAE,SAAS,EAAE,GAAG,GAAG,CAkB5E"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getJsonSchemaByFieldInfoList = getJsonSchemaByFieldInfoList;
|
|
4
|
+
const field_type_1 = require("@ldsg/field-type");
|
|
5
|
+
/**
|
|
6
|
+
* Generates JSON Schema for a field based on its type info
|
|
7
|
+
*/
|
|
8
|
+
function getJsonSchemaForField(fieldInfo) {
|
|
9
|
+
const { typeInfo } = fieldInfo;
|
|
10
|
+
const { platformToTypeMap } = typeInfo;
|
|
11
|
+
// Try to get JSON schema from platform-specific type map
|
|
12
|
+
const jsonSchema = platformToTypeMap[field_type_1.FieldTypeBasePlatform.JSON_SCHEMA];
|
|
13
|
+
if (jsonSchema) {
|
|
14
|
+
return jsonSchema;
|
|
15
|
+
}
|
|
16
|
+
// Fallback: generate basic schema based on common type
|
|
17
|
+
const commonType = platformToTypeMap[field_type_1.FieldTypeBasePlatform.COMMON];
|
|
18
|
+
if (!commonType) {
|
|
19
|
+
return {
|
|
20
|
+
type: 'string',
|
|
21
|
+
title: fieldInfo.title || fieldInfo.name
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
// Basic type mapping
|
|
25
|
+
const typeMap = {
|
|
26
|
+
string: { type: 'string', title: fieldInfo.title || fieldInfo.name },
|
|
27
|
+
number: { type: 'number', title: fieldInfo.title || fieldInfo.name },
|
|
28
|
+
boolean: { type: 'boolean', title: fieldInfo.title || fieldInfo.name },
|
|
29
|
+
array: { type: 'array', title: fieldInfo.title || fieldInfo.name },
|
|
30
|
+
object: { type: 'object', title: fieldInfo.title || fieldInfo.name }
|
|
31
|
+
};
|
|
32
|
+
return typeMap[commonType] || { type: 'string', title: fieldInfo.title || fieldInfo.name };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generates JSON Schema for an object from its field info list
|
|
36
|
+
*/
|
|
37
|
+
function getJsonSchemaByFieldInfoList(fieldInfoList) {
|
|
38
|
+
const properties = {};
|
|
39
|
+
const required = [];
|
|
40
|
+
fieldInfoList.forEach((fieldInfo) => {
|
|
41
|
+
const schema = getJsonSchemaForField(fieldInfo);
|
|
42
|
+
properties[fieldInfo.name] = schema;
|
|
43
|
+
// Add to required if field is mandatory
|
|
44
|
+
if (fieldInfo.required) {
|
|
45
|
+
required.push(fieldInfo.name);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
type: 'object',
|
|
50
|
+
properties
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TableInfo } from '../../../types';
|
|
2
|
+
import { TableDetail, TableMetadata } from '../../../types/query-types';
|
|
3
|
+
/**
|
|
4
|
+
* Maps TableInfo to TableMetadata (lightweight version without schemas)
|
|
5
|
+
*/
|
|
6
|
+
export declare function mapTableInfoToMetadata(tableInfo: TableInfo): TableMetadata;
|
|
7
|
+
/**
|
|
8
|
+
* Maps TableInfo to TableDetail (includes schemas)
|
|
9
|
+
*/
|
|
10
|
+
export declare function mapTableInfoToDetail(tableInfo: TableInfo): TableDetail;
|
|
11
|
+
//# sourceMappingURL=map-table-info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-table-info.d.ts","sourceRoot":"","sources":["../../../../src/utils/add-query-fields/utils/map-table-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAGxE;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,SAAS,GAAG,aAAa,CAM1E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,SAAS,GAAG,WAAW,CAetE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapTableInfoToMetadata = mapTableInfoToMetadata;
|
|
4
|
+
exports.mapTableInfoToDetail = mapTableInfoToDetail;
|
|
5
|
+
const get_json_schema_1 = require("./get-json-schema");
|
|
6
|
+
/**
|
|
7
|
+
* Maps TableInfo to TableMetadata (lightweight version without schemas)
|
|
8
|
+
*/
|
|
9
|
+
function mapTableInfoToMetadata(tableInfo) {
|
|
10
|
+
return {
|
|
11
|
+
name: tableInfo.name,
|
|
12
|
+
title: tableInfo.title,
|
|
13
|
+
description: tableInfo.description
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Maps TableInfo to TableDetail (includes schemas)
|
|
18
|
+
*/
|
|
19
|
+
function mapTableInfoToDetail(tableInfo) {
|
|
20
|
+
const { objectInfo } = tableInfo;
|
|
21
|
+
// Generate JSON schema for the object
|
|
22
|
+
const jsonSchema = (0, get_json_schema_1.getJsonSchemaByFieldInfoList)(objectInfo.fieldInfoList);
|
|
23
|
+
return {
|
|
24
|
+
name: tableInfo.name,
|
|
25
|
+
title: tableInfo.title,
|
|
26
|
+
description: tableInfo.description,
|
|
27
|
+
objectInfo: {
|
|
28
|
+
...objectInfo,
|
|
29
|
+
jsonSchema
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
|
package/dist/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,39 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldsg/tables",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.11",
|
|
4
4
|
"description": "",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "wanxger",
|
|
5
8
|
"main": "dist/index.js",
|
|
9
|
+
"types": "dist",
|
|
6
10
|
"files": [
|
|
7
11
|
"dist/"
|
|
8
12
|
],
|
|
9
|
-
"types": "dist",
|
|
10
|
-
"keywords": [],
|
|
11
|
-
"author": "wanxger",
|
|
12
|
-
"license": "MIT",
|
|
13
|
-
"publishConfig": {
|
|
14
|
-
"access": "public"
|
|
15
|
-
},
|
|
16
13
|
"dependencies": {
|
|
17
14
|
"graphql-compose-mongoose": "^10.0.0",
|
|
18
15
|
"lodash": "^4.17.21",
|
|
19
16
|
"mongoose": "^8.14.3",
|
|
20
|
-
"@ldsg/
|
|
21
|
-
"@ldsg/
|
|
22
|
-
"@ldsg/
|
|
17
|
+
"@ldsg/resource": "0.3.10",
|
|
18
|
+
"@ldsg/field-type": "0.3.10",
|
|
19
|
+
"@ldsg/handler": "0.3.10",
|
|
20
|
+
"@ldsg/resource-definition": "0.3.10"
|
|
23
21
|
},
|
|
24
22
|
"devDependencies": {
|
|
23
|
+
"@types/jest": "^29.5.2",
|
|
25
24
|
"@types/lodash": "^4.14.202",
|
|
26
25
|
"@types/supertest": "^6.0.0",
|
|
27
26
|
"graphql": "16.11.0",
|
|
28
27
|
"graphql-compose": "^9.1.0",
|
|
28
|
+
"jest": "^29.5.0",
|
|
29
29
|
"supertest": "^6.3.4",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"@ldsg/
|
|
34
|
-
"@ldsg/
|
|
35
|
-
"@ldsg/
|
|
36
|
-
"@ldsg/
|
|
30
|
+
"ts-jest": "^29.1.5",
|
|
31
|
+
"ts-node": "^10.9.2",
|
|
32
|
+
"typescript": "^5.8.3",
|
|
33
|
+
"@ldsg/application": "0.3.10",
|
|
34
|
+
"@ldsg/graphql": "0.3.11",
|
|
35
|
+
"@ldsg/object": "0.3.10",
|
|
36
|
+
"@ldsg/object-field": "0.3.10",
|
|
37
|
+
"@ldsg/workflow": "0.3.11",
|
|
38
|
+
"@ldsg/types": "0.3.10"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
37
42
|
},
|
|
38
43
|
"scripts": {
|
|
39
44
|
"build": "tsc --project tsconfig.build.json",
|