@ldsg/object 0.3.31 → 0.3.33

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.
@@ -1,88 +1,93 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const constants_1 = require("@ldsg/constants");
4
7
  const field_type_1 = require("@ldsg/field-type");
5
8
  const handler_1 = require("@ldsg/handler");
6
9
  const resource_1 = require("@ldsg/resource");
10
+ const lodash_1 = __importDefault(require("lodash"));
7
11
  const resource_2 = require("../resource");
8
12
  class MockObjectFieldResource extends resource_1.Resource {
9
13
  constructor() {
10
14
  super(...arguments);
11
15
  this.getFieldInfo = (params) => {
12
- const { id, settings: { title, description, name, properties }, getResourcesFromSettings } = this;
16
+ const { id, settings: { title, description, slug, properties }, getResourcesFromSettings, } = this;
13
17
  const { fieldTypeResource } = getResourcesFromSettings();
14
18
  const { fieldTypeInfo } = fieldTypeResource.getFieldTypeInfo({
15
19
  ...params,
16
- fieldProperties: properties
20
+ fieldProperties: properties,
17
21
  });
18
22
  const fieldInfo = {
19
23
  id,
20
24
  title,
21
25
  description,
22
- name,
23
- typeInfo: fieldTypeInfo
26
+ name: lodash_1.default.camelCase(slug),
27
+ dbKey: lodash_1.default.snakeCase(slug),
28
+ typeInfo: fieldTypeInfo,
24
29
  };
25
30
  const res = {
26
- fieldInfo
31
+ fieldInfo,
27
32
  };
28
33
  return res;
29
34
  };
30
35
  }
31
36
  }
32
- test('object', () => {
37
+ test("object", () => {
33
38
  new handler_1.HandlerResource(field_type_1.stringFieldTypeHandlerResourceRecord);
34
39
  new field_type_1.FieldTypeResource(field_type_1.stringFieldTypeResourceRecord);
35
40
  const testObject = new resource_2.ObjectResource({
36
- id: 'test-object',
37
- kind: 'object',
41
+ id: "test-object",
42
+ kind: "object",
38
43
  parentId: constants_1.ROOT_RESOURCE_ID,
39
44
  settings: {
40
- title: '测试对象',
41
- description: '',
42
- name: 'test'
43
- }
45
+ title: "测试对象",
46
+ description: "",
47
+ slug: "test",
48
+ },
44
49
  });
45
50
  new MockObjectFieldResource({
46
- id: 'test-object-test-1-object-field',
47
- kind: 'object_field',
48
- parentId: 'test-object',
51
+ id: "test-object-test-1-object-field",
52
+ kind: "object_field",
53
+ parentId: "test-object",
49
54
  settings: {
50
- title: '测试对象测试1对象字段',
51
- description: '',
52
- name: 'test1',
55
+ title: "测试对象测试1对象字段",
56
+ description: "",
57
+ slug: "test1",
53
58
  fieldTypeResourceId: field_type_1.stringFieldTypeResourceRecord.id,
54
59
  properties: {
55
- max: '10'
56
- }
57
- }
60
+ max: "10",
61
+ },
62
+ },
58
63
  });
59
64
  new MockObjectFieldResource({
60
- id: 'test-object-test-2-object-field',
61
- kind: 'object_field',
62
- parentId: 'test-object',
65
+ id: "test-object-test-2-object-field",
66
+ kind: "object_field",
67
+ parentId: "test-object",
63
68
  settings: {
64
- title: '测试对象测试2对象字段',
65
- description: '',
66
- name: 'test2',
69
+ title: "测试对象测试2对象字段",
70
+ description: "",
71
+ slug: "test2",
67
72
  fieldTypeResourceId: field_type_1.stringFieldTypeResourceRecord.id,
68
73
  properties: {
69
- max: '10'
70
- }
71
- }
74
+ max: "10",
75
+ },
76
+ },
72
77
  });
73
78
  new MockObjectFieldResource({
74
- id: 'test-object-test-3-object-field',
75
- kind: 'object_field',
76
- parentId: 'test-object',
79
+ id: "test-object-test-3-object-field",
80
+ kind: "object_field",
81
+ parentId: "test-object",
77
82
  settings: {
78
- title: '测试对象测试3对象字段',
79
- description: '',
80
- name: 'test3',
83
+ title: "测试对象测试3对象字段",
84
+ description: "",
85
+ slug: "test3",
81
86
  fieldTypeResourceId: field_type_1.stringFieldTypeResourceRecord.id,
82
87
  properties: {
83
- max: '10'
84
- }
85
- }
88
+ max: "10",
89
+ },
90
+ },
86
91
  });
87
92
  const getObjectInfoRes = testObject.getObjectInfo();
88
93
  expect(getObjectInfoRes).toMatchSnapshot();
@@ -1,6 +1,6 @@
1
- import { HandlerSpecificResourceSettings } from '@ldsg/handler';
2
- import { ResourceDefinitionSpecificResourceSettings } from '@ldsg/resource-definition';
3
- import { GeneralResourceSettings } from '@ldsg/types';
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
  * 实例化资源处理程序普通资源配置
@@ -1 +1 @@
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"}
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,+BAQnE,CAAC;AAEJ,eAAO,MAAM,6CAA6C,EAAE,uBAG3D,CAAC;AAEF,eAAO,MAAM,8CAA8C,EAAE,0CAG1D,CAAC"}
package/dist/constants.js CHANGED
@@ -6,8 +6,8 @@ exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = exports.RESOURCE_DEFINI
6
6
  * 实例化资源处理程序普通资源配置
7
7
  */
8
8
  exports.INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS = {
9
- title: '对象实例化资源处理程序',
10
- description: ''
9
+ title: "对象实例化资源处理程序",
10
+ description: "",
11
11
  };
12
12
  /**
13
13
  * Instantiate Resource Handler Specific Resource Settings
@@ -18,14 +18,14 @@ exports.INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS = {
18
18
  code: `export * from "@ldsg/object";`,
19
19
  dependencies: [
20
20
  {
21
- name: '@ldsg/object'
22
- }
23
- ]
21
+ name: "@ldsg/object",
22
+ },
23
+ ],
24
24
  };
25
25
  exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = {
26
- title: '对象资源定义',
27
- description: ''
26
+ title: "对象资源定义",
27
+ description: "",
28
28
  };
29
29
  exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = {
30
- kind: 'object'
30
+ kind: "object",
31
31
  };
package/dist/handler.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { Handler, HandlerExtendedResourceSettings } from '@ldsg/handler';
2
- import { InstantiateResourceParams, InstantiateResourceRes } from '@ldsg/resource';
3
- import { ObjectResource } from './resource';
4
- import { ObjectSpecificResourceSettings } from './types';
1
+ import { Handler, HandlerExtendedResourceSettings } from "@ldsg/handler";
2
+ import { InstantiateResourceParams, InstantiateResourceRes } from "@ldsg/resource";
3
+ import { ObjectResource } from "./resource";
4
+ import { ObjectSpecificResourceSettings } from "./types";
5
5
  export declare const handler: Handler<InstantiateResourceParams<HandlerExtendedResourceSettings<ObjectSpecificResourceSettings>>, InstantiateResourceRes<ObjectResource>>;
6
6
  //# sourceMappingURL=handler.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from './constants';
2
- export * from './handler';
3
- export * from './instantiate-resource';
4
- export * from './resource';
5
- export * from './types';
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 '@ldsg/handler';
2
- import { InstantiateResource } from '@ldsg/resource';
3
- import { ObjectResource } from './resource';
4
- import { ObjectSpecificResourceSettings } from './types';
1
+ import { HandlerExtendedResourceSettings } from "@ldsg/handler";
2
+ import { InstantiateResource } from "@ldsg/resource";
3
+ import { ObjectResource } from "./resource";
4
+ import { ObjectSpecificResourceSettings } from "./types";
5
5
  export declare const instantiateResource: InstantiateResource<HandlerExtendedResourceSettings<ObjectSpecificResourceSettings>, ObjectResource>;
6
6
  //# sourceMappingURL=instantiate-resource.d.ts.map
@@ -6,7 +6,7 @@ const instantiateResource = (params) => {
6
6
  const { resourceConstructorParams } = params;
7
7
  const resource = new resource_1.ObjectResource(resourceConstructorParams);
8
8
  const res = {
9
- resource
9
+ resource,
10
10
  };
11
11
  return res;
12
12
  };
@@ -1,12 +1,18 @@
1
- import { PlatformsParams } from '@ldsg/field-type';
2
- import { Resource } from '@ldsg/resource';
3
- import { GeneralResourceSettings } from '@ldsg/types';
4
- import { FieldInfo, ObjectSpecificResourceSettings } from './types';
1
+ import { PlatformsParams } from "@ldsg/field-type";
2
+ import { Resource } from "@ldsg/resource";
3
+ import { GeneralResourceSettings } from "@ldsg/types";
4
+ import { FieldInfo, ObjectSpecificResourceSettings } from "./types";
5
5
  export interface ObjectInfo extends GeneralResourceSettings {
6
6
  /**
7
7
  * Object Name
8
+ * camel case
8
9
  */
9
10
  name: string;
11
+ /**
12
+ * Object Type Name
13
+ * pascal case
14
+ */
15
+ objectTypeName: string;
10
16
  /**
11
17
  * Field Info List
12
18
  */
@@ -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,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAgB,8BAA8B,EAAE,MAAM,SAAS,CAAC;AAElF,MAAM,WAAW,UAAW,SAAQ,uBAAuB;IACzD;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,aAAa,EAAE,SAAS,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,KAAK,aAAa,GAAG,CAAC,MAAM,CAAC,EAAE,eAAe,KAAK,gBAAgB,CAAC;AAEpE,qBAAa,cAAe,SAAQ,QAAQ,CAAC,8BAA8B,CAAC;IAC1E,aAAa,EAAE,aAAa,CAiC1B;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,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAgB,8BAA8B,EAAE,MAAM,SAAS,CAAC;AAElF,MAAM,WAAW,UAAW,SAAQ,uBAAuB;IACzD;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,aAAa,EAAE,SAAS,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,KAAK,aAAa,GAAG,CAAC,MAAM,CAAC,EAAE,eAAe,KAAK,gBAAgB,CAAC;AAEpE,qBAAa,cAAe,SAAQ,QAAQ,CAAC,8BAA8B,CAAC;IAC1E,aAAa,EAAE,aAAa,CAsC1B;CACH"}
package/dist/resource.js CHANGED
@@ -10,9 +10,11 @@ class ObjectResource extends resource_1.Resource {
10
10
  constructor() {
11
11
  super(...arguments);
12
12
  this.getObjectInfo = (params) => {
13
- const { id, settings: { title, description, name }, getFilteredResources } = this;
13
+ const { id, settings: { title, description, slug }, getFilteredResources, } = this;
14
+ const name = lodash_1.default.camelCase(slug);
15
+ const objectTypeName = lodash_1.default.upperFirst(lodash_1.default.camelCase(slug));
14
16
  const { resources } = getFilteredResources({
15
- parentId: id
17
+ parentId: id,
16
18
  });
17
19
  const mapRes = resources.map((resource) => {
18
20
  var _a;
@@ -20,15 +22,16 @@ class ObjectResource extends resource_1.Resource {
20
22
  return fieldInfo;
21
23
  });
22
24
  const filterRes = lodash_1.default.filter(mapRes, (value) => !lodash_1.default.isUndefined(value));
23
- const fieldInfoList = lodash_1.default.map(filterRes, 'fieldInfo');
25
+ const fieldInfoList = lodash_1.default.map(filterRes, "fieldInfo");
24
26
  const objectInfo = {
25
27
  title,
26
28
  description,
27
29
  name,
28
- fieldInfoList
30
+ objectTypeName,
31
+ fieldInfoList,
29
32
  };
30
33
  const res = {
31
- objectInfo
34
+ objectInfo,
32
35
  };
33
36
  return res;
34
37
  };
@@ -1,14 +1,20 @@
1
- import { FieldTypeInfo, PlatformsParams } from '@ldsg/field-type';
2
- import { GeneralResourceSettings } from '@ldsg/types';
1
+ import { FieldTypeInfo, PlatformsParams } from "@ldsg/field-type";
2
+ import { GeneralResourceSettings } from "@ldsg/types";
3
3
  export interface FieldInfo extends GeneralResourceSettings {
4
4
  /**
5
5
  * Field ID
6
6
  */
7
7
  id: string;
8
8
  /**
9
- * Field Name
9
+ * Field name (camelCase, e.g. "userId")
10
+ * Used as the GraphQL field name / Mongoose alias.
10
11
  */
11
12
  name: string;
13
+ /**
14
+ * Database field key (snake_case, e.g. "user_id")
15
+ * Used as the MongoDB document field key.
16
+ */
17
+ dbKey: string;
12
18
  /**
13
19
  * Field Type Info
14
20
  */
@@ -21,6 +27,6 @@ export interface FieldInfo extends GeneralResourceSettings {
21
27
  interface GetFieldInfoRes {
22
28
  fieldInfo: FieldInfo;
23
29
  }
24
- export type GetFieldInfo = (params?: PlatformsParams) => GetFieldInfoRes;
30
+ export type GetFieldInfo = (params?: PlatformsParams) => GetFieldInfoRes | undefined;
25
31
  export {};
26
32
  //# sourceMappingURL=get-field-info.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-field-info.d.ts","sourceRoot":"","sources":["../../src/types/get-field-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,WAAW,SAAU,SAAQ,uBAAuB;IACxD;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,QAAQ,EAAE,aAAa,CAAC;IAExB;;OAEG;IACH,aAAa,CAAC,EAAE,SAAS,EAAE,CAAC;CAC7B;AAED,UAAU,eAAe;IACvB,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,CAAC,EAAE,eAAe,KAAK,eAAe,CAAC"}
1
+ {"version":3,"file":"get-field-info.d.ts","sourceRoot":"","sources":["../../src/types/get-field-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,WAAW,SAAU,SAAQ,uBAAuB;IACxD;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,QAAQ,EAAE,aAAa,CAAC;IAExB;;OAEG;IACH,aAAa,CAAC,EAAE,SAAS,EAAE,CAAC;CAC7B;AAED,UAAU,eAAe;IACvB,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,CAAC,EAAE,eAAe,KAAK,eAAe,GAAG,SAAS,CAAC"}
@@ -1,3 +1,3 @@
1
- export * from './get-field-info';
2
- export * from './specific-resource-settings';
1
+ export * from "./get-field-info";
2
+ export * from "./specific-resource-settings";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,9 @@
1
- import { z } from 'zod';
1
+ import { z } from "zod";
2
2
  export declare const ObjectSpecificResourceSettingsSchema: z.ZodObject<{
3
- name: z.ZodString;
3
+ slug: z.ZodString;
4
4
  }, z.core.$catchall<z.ZodAny>>;
5
5
  export declare const SpecificResourceSettingsSchema: z.ZodObject<{
6
- name: z.ZodString;
6
+ slug: z.ZodString;
7
7
  }, z.core.$catchall<z.ZodAny>>;
8
8
  export type ObjectSpecificResourceSettings = z.infer<typeof ObjectSpecificResourceSettingsSchema>;
9
9
  //# sourceMappingURL=specific-resource-settings.d.ts.map
@@ -5,9 +5,9 @@ const zod_1 = require("zod");
5
5
  exports.ObjectSpecificResourceSettingsSchema = zod_1.z
6
6
  .object({
7
7
  /**
8
- * Object Name
8
+ * Object Slug
9
9
  */
10
- name: zod_1.z.string()
10
+ slug: zod_1.z.string(),
11
11
  })
12
12
  .catchall(zod_1.z.any());
13
13
  exports.SpecificResourceSettingsSchema = exports.ObjectSpecificResourceSettingsSchema;
package/package.json CHANGED
@@ -1,40 +1,44 @@
1
1
  {
2
2
  "name": "@ldsg/object",
3
- "version": "0.3.31",
3
+ "version": "0.3.33",
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
  "lodash": "^4.17.21",
15
18
  "zod": "^4.1.11",
16
- "@ldsg/constants": "0.3.31",
17
- "@ldsg/handler": "0.3.31",
18
- "@ldsg/resource": "0.3.31",
19
- "@ldsg/resource-definition": "0.3.31"
19
+ "@ldsg/constants": "0.3.33",
20
+ "@ldsg/handler": "0.3.33",
21
+ "@ldsg/resource": "0.3.33",
22
+ "@ldsg/resource-definition": "0.3.33"
20
23
  },
21
24
  "devDependencies": {
22
25
  "@types/jest": "^29.5.2",
23
26
  "@types/lodash": "^4.14.202",
24
27
  "jest": "^29.5.0",
28
+ "oxfmt": "latest",
29
+ "oxlint": "latest",
25
30
  "supertest": "^6.3.4",
26
31
  "ts-jest": "^29.1.5",
27
32
  "ts-node": "^10.9.2",
28
33
  "typescript": "^5.8.3",
29
- "@ldsg/field-type": "0.3.31",
30
- "@ldsg/types": "0.3.31"
31
- },
32
- "publishConfig": {
33
- "access": "public"
34
+ "@ldsg/field-type": "0.3.33",
35
+ "@ldsg/types": "0.3.33"
34
36
  },
35
37
  "scripts": {
36
38
  "build": "tsc --project tsconfig.build.json",
37
39
  "clean": "rm -rf dist",
40
+ "format": "oxfmt --write src/",
41
+ "lint": "oxlint src/",
38
42
  "test": "jest"
39
43
  }
40
44
  }