@ldsg/tables 0.2.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.
Files changed (42) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +1 -0
  3. package/dist/constants.d.ts +13 -0
  4. package/dist/constants.d.ts.map +1 -0
  5. package/dist/constants.js +26 -0
  6. package/dist/handler.d.ts +8 -0
  7. package/dist/handler.d.ts.map +1 -0
  8. package/dist/handler.js +5 -0
  9. package/dist/index.d.ts +6 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +21 -0
  12. package/dist/instantiate-resource.d.ts +6 -0
  13. package/dist/instantiate-resource.d.ts.map +1 -0
  14. package/dist/instantiate-resource.js +13 -0
  15. package/dist/resource.d.ts +17 -0
  16. package/dist/resource.d.ts.map +1 -0
  17. package/dist/resource.js +38 -0
  18. package/dist/types/get-table-info.d.ts +15 -0
  19. package/dist/types/get-table-info.d.ts.map +1 -0
  20. package/dist/types/get-table-info.js +2 -0
  21. package/dist/types/index.d.ts +3 -0
  22. package/dist/types/index.d.ts.map +1 -0
  23. package/dist/types/index.js +18 -0
  24. package/dist/types/specific-resource-settings.d.ts +4 -0
  25. package/dist/types/specific-resource-settings.d.ts.map +1 -0
  26. package/dist/types/specific-resource-settings.js +2 -0
  27. package/dist/utils/add-fields/constants.d.ts +5 -0
  28. package/dist/utils/add-fields/constants.d.ts.map +1 -0
  29. package/dist/utils/add-fields/constants.js +24 -0
  30. package/dist/utils/add-fields/index.d.ts +9 -0
  31. package/dist/utils/add-fields/index.d.ts.map +1 -0
  32. package/dist/utils/add-fields/index.js +41 -0
  33. package/dist/utils/add-fields/utils/get-object-type-composer.d.ts +14 -0
  34. package/dist/utils/add-fields/utils/get-object-type-composer.d.ts.map +1 -0
  35. package/dist/utils/add-fields/utils/get-object-type-composer.js +32 -0
  36. package/dist/utils/add-fields/utils/index.d.ts +2 -0
  37. package/dist/utils/add-fields/utils/index.d.ts.map +1 -0
  38. package/dist/utils/add-fields/utils/index.js +17 -0
  39. package/dist/utils/index.d.ts +2 -0
  40. package/dist/utils/index.d.ts.map +1 -0
  41. package/dist/utils/index.js +17 -0
  42. package/package.json +42 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2014-present Sebastian McKenzie and other contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # LDSG Tables Resource
@@ -0,0 +1,13 @@
1
+ import { HandlerSpecificResourceSettings } from "@ldsg/handler";
2
+ import { ResourceDefinitionSpecificResourceSettings } from "@ldsg/resource-definition";
3
+ import { GeneralResourceSettings } from "@ldsg/types";
4
+ export declare const HANDLER_GENERAL_RESOURCE_SETTINGS: GeneralResourceSettings;
5
+ /**
6
+ * Handler Resource Settings
7
+ * 此类型资源的子级处理程序资源的配置
8
+ * 如无或为 undefined,则说明无需子级处理程序。
9
+ */
10
+ export declare const HANDLER_SPECIFIC_RESOURCE_SETTINGS: HandlerSpecificResourceSettings;
11
+ export declare const RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS: GeneralResourceSettings;
12
+ export declare const RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS: ResourceDefinitionSpecificResourceSettings;
13
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,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,eAAO,MAAM,iCAAiC,EAAE,uBAG/C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,EAAE,+BAQ9C,CAAC;AAEJ,eAAO,MAAM,6CAA6C,EAAE,uBACnB,CAAC;AAE1C,eAAO,MAAM,8CAA8C,EAAE,0CAI1D,CAAC"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = exports.HANDLER_SPECIFIC_RESOURCE_SETTINGS = exports.HANDLER_GENERAL_RESOURCE_SETTINGS = void 0;
4
+ const application_1 = require("@ldsg/application");
5
+ exports.HANDLER_GENERAL_RESOURCE_SETTINGS = {
6
+ title: "表格组类型资源处理程序",
7
+ description: "",
8
+ };
9
+ /**
10
+ * Handler Resource Settings
11
+ * 此类型资源的子级处理程序资源的配置
12
+ * 如无或为 undefined,则说明无需子级处理程序。
13
+ */
14
+ exports.HANDLER_SPECIFIC_RESOURCE_SETTINGS = {
15
+ code: `export * from "@ldsg/tables";`,
16
+ dependencies: [
17
+ {
18
+ name: "@ldsg/tables",
19
+ },
20
+ ],
21
+ };
22
+ exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = { title: "表格组类型资源定义", description: "" };
23
+ exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = {
24
+ kind: "tables",
25
+ parentKind: application_1.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS.kind,
26
+ };
@@ -0,0 +1,8 @@
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<[
6
+ InstantiateResourceParams<HandlerExtendedResourceSettings<TablesSpecificResourceSettings>>
7
+ ], InstantiateResourceRes<TablesResource>>;
8
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +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,EACL,yBAAyB,EACzB,sBAAsB,EACvB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,8BAA8B,EAAE,MAAM,SAAS,CAAC;AAEzD,eAAO,MAAM,OAAO,EAAE,OAAO,CAC3B;IACE,yBAAyB,CACvB,+BAA+B,CAAC,8BAA8B,CAAC,CAChE;CACF,EACD,sBAAsB,CAAC,cAAc,CAAC,CACjB,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = void 0;
4
+ const instantiate_resource_1 = require("./instantiate-resource");
5
+ exports.handler = instantiate_resource_1.instantiateResource;
@@ -0,0 +1,6 @@
1
+ export * from "./constants";
2
+ export * from "./handler";
3
+ export * from "./instantiate-resource";
4
+ export * from "./resource";
5
+ export * from "./types";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
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
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./constants"), exports);
18
+ __exportStar(require("./handler"), exports);
19
+ __exportStar(require("./instantiate-resource"), exports);
20
+ __exportStar(require("./resource"), exports);
21
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,6 @@
1
+ import { HandlerExtendedResourceSettings } from "@ldsg/handler";
2
+ import { InstantiateResource } from "@ldsg/resource";
3
+ import { TablesResource } from "./resource";
4
+ import { TablesSpecificResourceSettings } from "./types";
5
+ export declare const instantiateResource: InstantiateResource<HandlerExtendedResourceSettings<TablesSpecificResourceSettings>, TablesResource>;
6
+ //# sourceMappingURL=instantiate-resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instantiate-resource.d.ts","sourceRoot":"","sources":["../src/instantiate-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,8BAA8B,EAAE,MAAM,SAAS,CAAC;AAEzD,eAAO,MAAM,mBAAmB,EAAE,mBAAmB,CACnD,+BAA+B,CAAC,8BAA8B,CAAC,EAC/D,cAAc,CAWf,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.instantiateResource = void 0;
4
+ const resource_1 = require("./resource");
5
+ const instantiateResource = (params) => {
6
+ const { resourceConstructorParams } = params;
7
+ const resource = new resource_1.TablesResource(resourceConstructorParams);
8
+ const res = {
9
+ resource,
10
+ };
11
+ return res;
12
+ };
13
+ exports.instantiateResource = instantiateResource;
@@ -0,0 +1,17 @@
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
+ interface GetTableInfoListRes {
6
+ /**
7
+ * Table Info List
8
+ */
9
+ tableInfoList: TableInfo[];
10
+ }
11
+ type GetTableInfoList = (params?: PlatformsParams) => GetTableInfoListRes;
12
+ export declare class TablesResource extends Resource<TablesSpecificResourceSettings> {
13
+ getTableInfoList: GetTableInfoList;
14
+ modifyGraphQLSchema: ModifyGraphQLSchema;
15
+ }
16
+ export {};
17
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +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,EAEL,SAAS,EACT,8BAA8B,EAC/B,MAAM,SAAS,CAAC;AAGjB,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,gBAAgB,EAAE,gBAAgB,CAoBhC;IAEF,mBAAmB,EAAE,mBAAmB,CAStC;CACH"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TablesResource = void 0;
7
+ const resource_1 = require("@ldsg/resource");
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const utils_1 = require("./utils");
10
+ class TablesResource extends resource_1.Resource {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.getTableInfoList = (params) => {
14
+ const { id, getFilteredResources } = this;
15
+ const { resources } = getFilteredResources({
16
+ parentId: id,
17
+ });
18
+ const mapRes = resources.map((resource) => {
19
+ var _a;
20
+ return (_a = resource.getTableInfo) === null || _a === void 0 ? void 0 : _a.call(resource, params);
21
+ });
22
+ const tableInfoList = lodash_1.default.filter(mapRes, (value) => !lodash_1.default.isUndefined(value));
23
+ const res = {
24
+ tableInfoList,
25
+ };
26
+ return res;
27
+ };
28
+ this.modifyGraphQLSchema = (params) => {
29
+ const { schemaComposer } = params;
30
+ const { tableInfoList } = this.getTableInfoList();
31
+ (0, utils_1.addFields)({
32
+ tableInfoList,
33
+ schemaComposer,
34
+ });
35
+ };
36
+ }
37
+ }
38
+ exports.TablesResource = TablesResource;
@@ -0,0 +1,15 @@
1
+ import { PlatformsParams } from "@ldsg/field-type";
2
+ import { ObjectInfo } from "@ldsg/object";
3
+ import { GeneralResourceSettings } from "@ldsg/types";
4
+ export interface TableInfo extends GeneralResourceSettings {
5
+ /**
6
+ * Table Name
7
+ */
8
+ name: string;
9
+ /**
10
+ * Object Info
11
+ */
12
+ objectInfo: ObjectInfo;
13
+ }
14
+ export type GetTableInfo = (params?: PlatformsParams) => TableInfo;
15
+ //# sourceMappingURL=get-table-info.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-table-info.d.ts","sourceRoot":"","sources":["../../src/types/get-table-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,WAAW,SAAU,SAAQ,uBAAuB;IACxD;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,CAAC,EAAE,eAAe,KAAK,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export * from "./get-table-info";
2
+ export * from "./specific-resource-settings";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,18 @@
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
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./get-table-info"), exports);
18
+ __exportStar(require("./specific-resource-settings"), exports);
@@ -0,0 +1,4 @@
1
+ import { SpecificResourceSettings } from "@ldsg/types";
2
+ export interface TablesSpecificResourceSettings extends SpecificResourceSettings {
3
+ }
4
+ //# sourceMappingURL=specific-resource-settings.d.ts.map
@@ -0,0 +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,8BACf,SAAQ,wBAAwB;CAAG"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { resolverFactory } from "graphql-compose-mongoose";
2
+ export type ResolverFactoryKeyList = (keyof typeof resolverFactory)[];
3
+ export declare const MUTATION_RESOLVER_FACTORY_KEY_LIST: ResolverFactoryKeyList;
4
+ export declare const QUERY_RESOLVER_FACTORY_KEY_LIST: ResolverFactoryKeyList;
5
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/utils/add-fields/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,MAAM,MAAM,sBAAsB,GAAG,CAAC,MAAM,OAAO,eAAe,CAAC,EAAE,CAAC;AAEtE,eAAO,MAAM,kCAAkC,EAAE,sBAShD,CAAC;AAEF,eAAO,MAAM,+BAA+B,EAAE,sBAU7C,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QUERY_RESOLVER_FACTORY_KEY_LIST = exports.MUTATION_RESOLVER_FACTORY_KEY_LIST = void 0;
4
+ exports.MUTATION_RESOLVER_FACTORY_KEY_LIST = [
5
+ "createOne",
6
+ "createMany",
7
+ "updateById",
8
+ "updateOne",
9
+ "updateMany",
10
+ "removeById",
11
+ "removeOne",
12
+ "removeMany",
13
+ ];
14
+ exports.QUERY_RESOLVER_FACTORY_KEY_LIST = [
15
+ "findById",
16
+ "findByIds",
17
+ "findOne",
18
+ "findMany",
19
+ "dataLoader",
20
+ "dataLoaderMany",
21
+ "count",
22
+ "connection",
23
+ "pagination",
24
+ ];
@@ -0,0 +1,9 @@
1
+ import { SchemaComposerParams } from "@ldsg/graphql";
2
+ import { TableInfo } from "../../types";
3
+ interface AddFieldsParams extends SchemaComposerParams {
4
+ tableInfoList: TableInfo[];
5
+ }
6
+ type AddFields = (params: AddFieldsParams) => void;
7
+ export declare const addFields: AddFields;
8
+ export {};
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;AAQxC,UAAU,eAAgB,SAAQ,oBAAoB;IACpD,aAAa,EAAE,SAAS,EAAE,CAAC;CAC5B;AAED,KAAK,SAAS,GAAG,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,CAAC;AAEnD,eAAO,MAAM,SAAS,EAAE,SAmCvB,CAAC"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.addFields = void 0;
7
+ const graphql_compose_mongoose_1 = require("graphql-compose-mongoose");
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const constants_1 = require("./constants");
10
+ const utils_1 = require("./utils");
11
+ const addFields = (params) => {
12
+ const { schemaComposer, tableInfoList } = params;
13
+ const mutationNewFields = {};
14
+ const queryNewFields = {};
15
+ const resolverFactoryKeys = lodash_1.default.keys(graphql_compose_mongoose_1.resolverFactory);
16
+ /**
17
+ * TODO:如果 table name 重名就抛出异常
18
+ */
19
+ lodash_1.default.each(tableInfoList, (tableInfo) => {
20
+ const { title, description, name: tableName, objectInfo } = tableInfo;
21
+ const { objectTypeComposer } = (0, utils_1.getObjectTypeComposer)({
22
+ tableName,
23
+ objectInfo,
24
+ });
25
+ lodash_1.default.each(resolverFactoryKeys, (key) => {
26
+ const fieldName = lodash_1.default.camelCase(`${tableName}-${key}`);
27
+ if (constants_1.MUTATION_RESOLVER_FACTORY_KEY_LIST.includes(key)) {
28
+ mutationNewFields[fieldName] =
29
+ objectTypeComposer.mongooseResolvers[key];
30
+ }
31
+ else if (constants_1.QUERY_RESOLVER_FACTORY_KEY_LIST.includes(key)) {
32
+ queryNewFields[fieldName] = objectTypeComposer.mongooseResolvers[key];
33
+ }
34
+ else {
35
+ }
36
+ });
37
+ });
38
+ schemaComposer.Mutation.addFields(mutationNewFields);
39
+ schemaComposer.Query.addFields(queryNewFields);
40
+ };
41
+ exports.addFields = addFields;
@@ -0,0 +1,14 @@
1
+ import { ObjectInfo } from "@ldsg/object";
2
+ import { ObjectTypeComposerWithMongooseResolvers } from "graphql-compose-mongoose";
3
+ import mongoose from "mongoose";
4
+ interface GetObjectTypeComposerParams {
5
+ tableName: string;
6
+ objectInfo: ObjectInfo;
7
+ }
8
+ interface GetObjectTypeComposerRes {
9
+ objectTypeComposer: ObjectTypeComposerWithMongooseResolvers<mongoose.Document<any, any, any>, any>;
10
+ }
11
+ type GetObjectTypeComposer = (params: GetObjectTypeComposerParams) => GetObjectTypeComposerRes;
12
+ export declare const getObjectTypeComposer: GetObjectTypeComposer;
13
+ export {};
14
+ //# sourceMappingURL=get-object-type-composer.d.ts.map
@@ -0,0 +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,EAEL,uCAAuC,EACxC,MAAM,0BAA0B,CAAC;AAElC,OAAO,QAA8B,MAAM,UAAU,CAAC;AAEtD,UAAU,2BAA2B;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,UAAU,wBAAwB;IAChC,kBAAkB,EAAE,uCAAuC,CACzD,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAChC,GAAG,CACJ,CAAC;CACH;AAED,KAAK,qBAAqB,GAAG,CAC3B,MAAM,EAAE,2BAA2B,KAChC,wBAAwB,CAAC;AAE9B,eAAO,MAAM,qBAAqB,EAAE,qBAuCnC,CAAC"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getObjectTypeComposer = void 0;
7
+ const graphql_compose_mongoose_1 = require("graphql-compose-mongoose");
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const mongoose_1 = __importDefault(require("mongoose"));
10
+ const getObjectTypeComposer = (params) => {
11
+ const { tableName, objectInfo } = params;
12
+ const { fieldInfoList } = objectInfo;
13
+ const mongooseSchemaDefinition = {};
14
+ lodash_1.default.each(fieldInfoList, (fieldInfo) => {
15
+ const { name, typeInfo: { platformToTypeMap }, } = fieldInfo;
16
+ const { COMMON, MONGOOSE } = platformToTypeMap;
17
+ const type = MONGOOSE !== null && MONGOOSE !== void 0 ? MONGOOSE : COMMON;
18
+ mongooseSchemaDefinition[name] = type;
19
+ });
20
+ const mongooseSchema = new mongoose_1.default.Schema(mongooseSchemaDefinition);
21
+ const modelName = lodash_1.default.upperFirst(lodash_1.default.camelCase(tableName));
22
+ const mongooseModel = mongoose_1.default.model(modelName, mongooseSchema);
23
+ const customizationOptions = {};
24
+ const objectTypeComposer = (0, graphql_compose_mongoose_1.composeMongoose)(
25
+ // @ts-ignore
26
+ mongooseModel, customizationOptions);
27
+ const res = {
28
+ objectTypeComposer,
29
+ };
30
+ return res;
31
+ };
32
+ exports.getObjectTypeComposer = getObjectTypeComposer;
@@ -0,0 +1,2 @@
1
+ export * from "./get-object-type-composer";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/add-fields/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,17 @@
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
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./get-object-type-composer"), exports);
@@ -0,0 +1,2 @@
1
+ export * from "./add-fields";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -0,0 +1,17 @@
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
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./add-fields"), exports);
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@ldsg/tables",
3
+ "version": "0.2.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "files": [
7
+ "dist/"
8
+ ],
9
+ "types": "dist",
10
+ "keywords": [],
11
+ "author": "wanxger",
12
+ "license": "MIT",
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "dependencies": {
17
+ "graphql-compose-mongoose": "^10.0.0",
18
+ "lodash": "^4.17.21",
19
+ "mongoose": "^8.14.3",
20
+ "@ldsg/handler": "0.2.0",
21
+ "@ldsg/resource": "0.2.0",
22
+ "@ldsg/resource-definition": "0.2.0"
23
+ },
24
+ "devDependencies": {
25
+ "@types/lodash": "^4.14.202",
26
+ "@types/supertest": "^6.0.0",
27
+ "graphql": "16.11.0",
28
+ "graphql-compose": "^9.1.0",
29
+ "supertest": "^6.3.4",
30
+ "@ldsg/application": "0.2.0",
31
+ "@ldsg/graphql": "0.2.0",
32
+ "@ldsg/object": "0.2.0",
33
+ "@ldsg/field-type": "0.2.0",
34
+ "@ldsg/object-field": "0.2.0",
35
+ "@ldsg/types": "0.2.0",
36
+ "@ldsg/workflow": "0.2.0"
37
+ },
38
+ "scripts": {
39
+ "build": "pnpm clean && tsc --project tsconfig.build.json",
40
+ "clean": "rm -rf dist"
41
+ }
42
+ }