@ldsg/tables 0.3.32 → 0.3.34

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.
@@ -3,9 +3,25 @@ import { ObjectInfo } from "@ldsg/object";
3
3
  import { GeneralResourceSettings } from "@ldsg/types";
4
4
  export interface TableInfo extends GeneralResourceSettings {
5
5
  /**
6
- * Table Name
6
+ * Slug, used to derive name and collectionName
7
+ * kebab case
8
+ */
9
+ slug: string;
10
+ /**
11
+ * Table Name (derived from slug if slug is provided, otherwise from settings.name)
12
+ * camel case
7
13
  */
8
14
  name: string;
15
+ /**
16
+ * MongoDB collection name (derived from slug)
17
+ * snake case
18
+ */
19
+ collectionName: string;
20
+ /**
21
+ * mongoose model name (derived from slug)
22
+ * pascal case
23
+ */
24
+ modelName: string;
9
25
  /**
10
26
  * Object Info
11
27
  */
@@ -1 +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"}
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;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,CAAC,EAAE,eAAe,KAAK,SAAS,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/handle-table-info-list/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,UAAU,yBAA0B,SAAQ,oBAAoB;IAC9D,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,sBAAsB;IAC9B,cAAc,EAAE,cAAc,CAAC;CAChC;AAED,KAAK,mBAAmB,GAAG,CAAC,MAAM,EAAE,yBAAyB,KAAK,sBAAsB,CAAC;AAEzF,eAAO,MAAM,mBAAmB,EAAE,mBAsBjC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/handle-table-info-list/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,UAAU,yBAA0B,SAAQ,oBAAoB;IAC9D,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,sBAAsB;IAC9B,cAAc,EAAE,cAAc,CAAC;CAChC;AAED,KAAK,mBAAmB,GAAG,CAAC,MAAM,EAAE,yBAAyB,KAAK,sBAAsB,CAAC;AAEzF,eAAO,MAAM,mBAAmB,EAAE,mBAuBjC,CAAC"}
@@ -10,9 +10,10 @@ const handleTableInfoList = (params) => {
10
10
  const { schemaComposer, tableInfoList } = params;
11
11
  const mongooseModels = {};
12
12
  lodash_1.default.each(tableInfoList, (tableInfo) => {
13
- const { name: tableName, objectInfo } = tableInfo;
14
- const { modelName, mongooseModel } = (0, utils_1.getObjectTC)({
15
- tableName,
13
+ const { collectionName, modelName, objectInfo } = tableInfo;
14
+ const { mongooseModel } = (0, utils_1.getObjectTC)({
15
+ modelName,
16
+ collectionName,
16
17
  objectInfo,
17
18
  schemaComposer,
18
19
  });
@@ -3,7 +3,8 @@ import { SchemaComposer } from "graphql-compose";
3
3
  import { ObjectTypeComposerWithMongooseResolvers } from "graphql-compose-mongoose";
4
4
  import mongoose from "mongoose";
5
5
  interface GetObjectTCParams {
6
- tableName: string;
6
+ modelName: string;
7
+ collectionName: string;
7
8
  objectInfo: ObjectInfo;
8
9
  schemaComposer: SchemaComposer;
9
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"get-object-type-composer.d.ts","sourceRoot":"","sources":["../../../../src/utils/handle-table-info-list/utils/get-object-type-composer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAIL,uCAAuC,EAExC,MAAM,0BAA0B,CAAC;AAMlC,OAAO,QAA8B,MAAM,UAAU,CAAC;AAiBtD,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,CACzD,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAChC,GAAG,CACJ,CAAC;CACH;AAED,KAAK,WAAW,GAAG,CAAC,MAAM,EAAE,iBAAiB,KAAK,cAAc,CAAC;AAiCjE,eAAO,MAAM,WAAW,EAAE,WAkHzB,CAAC"}
1
+ {"version":3,"file":"get-object-type-composer.d.ts","sourceRoot":"","sources":["../../../../src/utils/handle-table-info-list/utils/get-object-type-composer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAIL,uCAAuC,EAExC,MAAM,0BAA0B,CAAC;AAMlC,OAAO,QAA8B,MAAM,UAAU,CAAC;AAiBtD,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,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,CACzD,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAChC,GAAG,CACJ,CAAC;CACH;AAED,KAAK,WAAW,GAAG,CAAC,MAAM,EAAE,iBAAiB,KAAK,cAAc,CAAC;AAoCjE,eAAO,MAAM,WAAW,EAAE,WA8GzB,CAAC"}
@@ -19,35 +19,34 @@ const countOpts = {
19
19
  };
20
20
  const buildNestedSchemaDefinition = (fieldInfoList, schemaDefinition) => {
21
21
  lodash_1.default.each(fieldInfoList, (fieldInfo) => {
22
- const { name, typeInfo: { platformToTypeMap }, fieldInfoList: nestedFieldInfoList, } = fieldInfo;
22
+ const { name, dbKey, typeInfo: { platformToTypeMap }, fieldInfoList: nestedFieldInfoList, } = fieldInfo;
23
23
  const { COMMON, MONGOOSE } = platformToTypeMap;
24
24
  const type = MONGOOSE !== null && MONGOOSE !== void 0 ? MONGOOSE : COMMON;
25
- const fieldName = lodash_1.default.camelCase(name);
26
- if ((type === null || type === void 0 ? void 0 : type.type) === "object" && nestedFieldInfoList) {
25
+ // `dbKey` is the MongoDB field key (snake_case)
26
+ // `name` is the Mongoose alias / GraphQL field name (camelCase)
27
+ const dbFieldName = dbKey;
28
+ const alias = name !== dbKey ? name : undefined;
29
+ if (((type === null || type === void 0 ? void 0 : type.type) === "object" || (type === null || type === void 0 ? void 0 : type.type) === "array") && nestedFieldInfoList) {
27
30
  const subDef = {};
28
31
  buildNestedSchemaDefinition(nestedFieldInfoList, subDef);
29
- schemaDefinition[fieldName] = new mongoose_1.default.Schema(subDef, { _id: false });
30
- }
31
- else if ((type === null || type === void 0 ? void 0 : type.type) === "array" && nestedFieldInfoList) {
32
- const subDef = {};
33
- buildNestedSchemaDefinition(nestedFieldInfoList, subDef);
34
- schemaDefinition[fieldName] = [new mongoose_1.default.Schema(subDef, { _id: false })];
32
+ const subSchema = new mongoose_1.default.Schema(subDef, { _id: false });
33
+ const value = type.type === "array" ? [subSchema] : subSchema;
34
+ schemaDefinition[dbFieldName] = { type: value, ...(alias ? { alias } : {}) };
35
35
  }
36
36
  else {
37
- schemaDefinition[fieldName] = type;
37
+ schemaDefinition[dbFieldName] =
38
+ alias && typeof type === "function" ? { type, alias } : alias ? { ...type, alias } : type;
38
39
  }
39
40
  });
40
41
  };
41
42
  const getObjectTC = (params) => {
42
- const { tableName, objectInfo, schemaComposer } = params;
43
+ const { modelName, collectionName, objectInfo, schemaComposer } = params;
43
44
  const { fieldInfoList } = objectInfo;
44
45
  const mongooseSchemaDefinition = {};
45
46
  buildNestedSchemaDefinition(fieldInfoList, mongooseSchemaDefinition);
46
- const collectionName = lodash_1.default.snakeCase(tableName);
47
47
  const mongooseSchema = new mongoose_1.default.Schema(mongooseSchemaDefinition, {
48
48
  collection: collectionName,
49
49
  });
50
- const modelName = tableName;
51
50
  const mongooseModel = mongoose_1.default.models[modelName]
52
51
  ? mongoose_1.default.model(modelName)
53
52
  : mongoose_1.default.model(modelName, mongooseSchema);
package/package.json CHANGED
@@ -1,24 +1,27 @@
1
1
  {
2
2
  "name": "@ldsg/tables",
3
- "version": "0.3.32",
3
+ "version": "0.3.34",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
7
7
  "author": "wanxger",
8
- "main": "dist/index.js",
9
- "types": "dist",
10
8
  "files": [
11
9
  "dist/"
12
10
  ],
11
+ "main": "dist/index.js",
12
+ "types": "dist",
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
13
16
  "dependencies": {
14
17
  "graphql-compose-mongoose": "10.1.0",
15
18
  "lodash": "^4.17.21",
16
19
  "mongoose": "^8.14.3",
17
20
  "zod": "^4.1.11",
18
- "@ldsg/field-type": "0.3.32",
19
- "@ldsg/resource": "0.3.32",
20
- "@ldsg/handler": "0.3.32",
21
- "@ldsg/resource-definition": "0.3.32"
21
+ "@ldsg/handler": "0.3.34",
22
+ "@ldsg/resource": "0.3.34",
23
+ "@ldsg/resource-definition": "0.3.34",
24
+ "@ldsg/field-type": "0.3.34"
22
25
  },
23
26
  "devDependencies": {
24
27
  "@types/jest": "^29.5.2",
@@ -33,15 +36,12 @@
33
36
  "ts-jest": "^29.1.5",
34
37
  "ts-node": "^10.9.2",
35
38
  "typescript": "^5.8.3",
36
- "@ldsg/application": "0.3.32",
37
- "@ldsg/graphql": "0.3.32",
38
- "@ldsg/object": "0.3.32",
39
- "@ldsg/object-field": "0.3.32",
40
- "@ldsg/types": "0.3.32",
41
- "@ldsg/workflow": "0.3.32"
42
- },
43
- "publishConfig": {
44
- "access": "public"
39
+ "@ldsg/application": "0.3.34",
40
+ "@ldsg/graphql": "0.3.34",
41
+ "@ldsg/object": "0.3.34",
42
+ "@ldsg/object-field": "0.3.34",
43
+ "@ldsg/types": "0.3.34",
44
+ "@ldsg/workflow": "0.3.34"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "tsc --project tsconfig.build.json",