@ldsg/tables 0.3.10 → 0.3.17

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 (34) hide show
  1. package/dist/resource.d.ts +2 -0
  2. package/dist/resource.d.ts.map +1 -1
  3. package/dist/resource.js +6 -1
  4. package/dist/types/index.d.ts +1 -0
  5. package/dist/types/index.d.ts.map +1 -1
  6. package/dist/types/index.js +1 -0
  7. package/dist/types/query-types.d.ts +69 -0
  8. package/dist/types/query-types.d.ts.map +1 -0
  9. package/dist/types/query-types.js +2 -0
  10. package/dist/utils/add-fields/index.d.ts +8 -1
  11. package/dist/utils/add-fields/index.d.ts.map +1 -1
  12. package/dist/utils/add-fields/index.js +11 -23
  13. package/dist/utils/add-fields/utils/get-object-type-composer.d.ts +8 -4
  14. package/dist/utils/add-fields/utils/get-object-type-composer.d.ts.map +1 -1
  15. package/dist/utils/add-fields/utils/get-object-type-composer.js +16 -10
  16. package/dist/utils/add-query-fields/index.d.ts +10 -0
  17. package/dist/utils/add-query-fields/index.d.ts.map +1 -0
  18. package/dist/utils/add-query-fields/index.js +26 -0
  19. package/dist/utils/add-query-fields/utils/create-resolvers.d.ts +21 -0
  20. package/dist/utils/add-query-fields/utils/create-resolvers.d.ts.map +1 -0
  21. package/dist/utils/add-query-fields/utils/create-resolvers.js +37 -0
  22. package/dist/utils/add-query-fields/utils/create-types.d.ts +10 -0
  23. package/dist/utils/add-query-fields/utils/create-types.d.ts.map +1 -0
  24. package/dist/utils/add-query-fields/utils/create-types.js +96 -0
  25. package/dist/utils/add-query-fields/utils/get-json-schema.d.ts +6 -0
  26. package/dist/utils/add-query-fields/utils/get-json-schema.d.ts.map +1 -0
  27. package/dist/utils/add-query-fields/utils/get-json-schema.js +52 -0
  28. package/dist/utils/add-query-fields/utils/map-table-info.d.ts +11 -0
  29. package/dist/utils/add-query-fields/utils/map-table-info.d.ts.map +1 -0
  30. package/dist/utils/add-query-fields/utils/map-table-info.js +32 -0
  31. package/dist/utils/index.d.ts +1 -0
  32. package/dist/utils/index.d.ts.map +1 -1
  33. package/dist/utils/index.js +1 -0
  34. package/package.json +11 -11
@@ -2,6 +2,7 @@ import { PlatformsParams } from '@ldsg/field-type';
2
2
  import { ModifyGraphQLSchema } from '@ldsg/graphql';
3
3
  import { Resource } from '@ldsg/resource';
4
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
  }
@@ -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,EAAgB,SAAS,EAAE,8BAA8B,EAAE,MAAM,SAAS,CAAC;AAGlF,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"}
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
@@ -28,7 +28,12 @@ class TablesResource extends resource_1.Resource {
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
38
  schemaComposer
34
39
  });
@@ -1,3 +1,4 @@
1
1
  export * from './get-table-info';
2
+ export * from './query-types';
2
3
  export * from './specific-resource-settings';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -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"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +1,16 @@
1
1
  import { SchemaComposerParams } from '@ldsg/graphql';
2
+ import mongoose from 'mongoose';
2
3
  import { TableInfo } from '../../types';
4
+ import { getObjectTC } from './utils';
3
5
  export * from './constants';
6
+ export { getObjectTC };
4
7
  interface AddFieldsParams extends SchemaComposerParams {
5
8
  tableInfoList: TableInfo[];
6
9
  }
7
- type AddFields = (params: AddFieldsParams) => void;
10
+ export type MongooseModels = Record<string, mongoose.Model<any>>;
11
+ interface AddFieldsRes {
12
+ mongooseModels: MongooseModels;
13
+ }
14
+ type AddFields = (params: AddFieldsParams) => AddFieldsRes;
8
15
  export declare const addFields: AddFields;
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;AAQxC,cAAc,aAAa,CAAC;AAE5B,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,SAiCvB,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"}
@@ -17,38 +17,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.addFields = void 0;
21
- const graphql_compose_mongoose_1 = require("graphql-compose-mongoose");
20
+ exports.addFields = exports.getObjectTC = void 0;
22
21
  const lodash_1 = __importDefault(require("lodash"));
23
- const constants_1 = require("./constants");
24
22
  const utils_1 = require("./utils");
23
+ Object.defineProperty(exports, "getObjectTC", { enumerable: true, get: function () { return utils_1.getObjectTC; } });
25
24
  __exportStar(require("./constants"), exports);
26
25
  const addFields = (params) => {
27
26
  const { schemaComposer, tableInfoList } = params;
28
- const mutationNewFields = {};
29
- const queryNewFields = {};
30
- const resolverFactoryKeys = lodash_1.default.keys(graphql_compose_mongoose_1.resolverFactory);
31
- /**
32
- * TODO:如果 table name 重名就抛出异常
33
- */
27
+ const mongooseModels = {};
34
28
  lodash_1.default.each(tableInfoList, (tableInfo) => {
35
29
  const { title, description, name: tableName, objectInfo } = tableInfo;
36
- const { objectTypeComposer } = (0, utils_1.getObjectTypeComposer)({
30
+ const { modelName, mongooseModel, objectTypeComposer } = (0, utils_1.getObjectTC)({
37
31
  tableName,
38
- objectInfo
39
- });
40
- lodash_1.default.each(resolverFactoryKeys, (key) => {
41
- var _a, _b, _c, _d;
42
- const fieldName = lodash_1.default.camelCase(`${tableName}-${key}`);
43
- if (constants_1.MUTATION_RESOLVER_FACTORY_KEY_LIST.includes(key)) {
44
- mutationNewFields[fieldName] = (_b = (_a = objectTypeComposer.mongooseResolvers)[key]) === null || _b === void 0 ? void 0 : _b.call(_a);
45
- }
46
- else if (constants_1.QUERY_RESOLVER_FACTORY_KEY_LIST.includes(key)) {
47
- queryNewFields[fieldName] = (_d = (_c = objectTypeComposer.mongooseResolvers)[key]) === null || _d === void 0 ? void 0 : _d.call(_c);
48
- }
32
+ objectInfo,
33
+ schemaComposer
49
34
  });
35
+ mongooseModels[modelName] = mongooseModel;
50
36
  });
51
- schemaComposer.Mutation.addFields(mutationNewFields);
52
- schemaComposer.Query.addFields(queryNewFields);
37
+ const res = {
38
+ mongooseModels
39
+ };
40
+ return res;
53
41
  };
54
42
  exports.addFields = addFields;
@@ -1,14 +1,18 @@
1
1
  import { ObjectInfo } from '@ldsg/object';
2
2
  import { ObjectTypeComposerWithMongooseResolvers } from 'graphql-compose-mongoose';
3
+ import { SchemaComposer } from 'graphql-compose';
3
4
  import mongoose from 'mongoose';
4
- interface GetObjectTypeComposerParams {
5
+ interface GetObjectTCParams {
5
6
  tableName: string;
6
7
  objectInfo: ObjectInfo;
8
+ schemaComposer: SchemaComposer;
7
9
  }
8
- interface GetObjectTypeComposerRes {
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 GetObjectTypeComposer = (params: GetObjectTypeComposerParams) => GetObjectTypeComposerRes;
12
- export declare const getObjectTypeComposer: GetObjectTypeComposer;
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,EAAmB,uCAAuC,EAAE,MAAM,0BAA0B,CAAC;AAEpG,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,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;CACpG;AAED,KAAK,qBAAqB,GAAG,CAAC,MAAM,EAAE,2BAA2B,KAAK,wBAAwB,CAAC;AAE/F,eAAO,MAAM,qBAAqB,EAAE,qBAuCnC,CAAC"}
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.getObjectTypeComposer = void 0;
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 getObjectTypeComposer = (params) => {
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
15
  const { name, typeInfo: { platformToTypeMap } } = fieldInfo;
16
16
  const { COMMON, MONGOOSE } = platformToTypeMap;
17
17
  const type = MONGOOSE !== null && MONGOOSE !== void 0 ? MONGOOSE : COMMON;
18
- mongooseSchemaDefinition[name] = type;
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
- const objectTypeComposer = (0, graphql_compose_mongoose_1.composeMongoose)(
25
- // @ts-ignore
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 = {
32
+ modelName,
33
+ mongooseModel,
28
34
  objectTypeComposer
29
35
  };
30
36
  return res;
31
37
  };
32
- exports.getObjectTypeComposer = getObjectTypeComposer;
38
+ exports.getObjectTC = getObjectTC;
@@ -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,6 @@
1
+ import { FieldInfo } from '@ldsg/object';
2
+ /**
3
+ * Generates JSON Schema for an object from its field info list
4
+ */
5
+ export declare function getJsonSchemaByFieldInfoList(fieldInfoList: FieldInfo[]): any;
6
+ //# sourceMappingURL=get-json-schema.d.ts.map
@@ -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
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './add-fields';
2
+ export * from './add-query-fields';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./add-fields"), exports);
18
+ __exportStar(require("./add-query-fields"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ldsg/tables",
3
- "version": "0.3.10",
3
+ "version": "0.3.17",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -14,9 +14,10 @@
14
14
  "graphql-compose-mongoose": "^10.0.0",
15
15
  "lodash": "^4.17.21",
16
16
  "mongoose": "^8.14.3",
17
- "@ldsg/handler": "0.3.10",
18
- "@ldsg/resource": "0.3.10",
19
- "@ldsg/resource-definition": "0.3.10"
17
+ "@ldsg/field-type": "0.3.17",
18
+ "@ldsg/resource": "0.3.17",
19
+ "@ldsg/handler": "0.3.17",
20
+ "@ldsg/resource-definition": "0.3.17"
20
21
  },
21
22
  "devDependencies": {
22
23
  "@types/jest": "^29.5.2",
@@ -29,13 +30,12 @@
29
30
  "ts-jest": "^29.1.5",
30
31
  "ts-node": "^10.9.2",
31
32
  "typescript": "^5.8.3",
32
- "@ldsg/application": "0.3.10",
33
- "@ldsg/field-type": "0.3.10",
34
- "@ldsg/graphql": "0.3.10",
35
- "@ldsg/object": "0.3.10",
36
- "@ldsg/object-field": "0.3.10",
37
- "@ldsg/types": "0.3.10",
38
- "@ldsg/workflow": "0.3.10"
33
+ "@ldsg/application": "0.3.17",
34
+ "@ldsg/graphql": "0.3.17",
35
+ "@ldsg/object-field": "0.3.17",
36
+ "@ldsg/workflow": "0.3.17",
37
+ "@ldsg/object": "0.3.17",
38
+ "@ldsg/types": "0.3.17"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"