@ldsg/object 0.1.0-alpha.19 → 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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=unit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unit.d.ts","sourceRoot":"","sources":["../../src/__tests__/unit.ts"],"names":[],"mappings":""}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("@ldsg/constants");
4
+ const field_type_1 = require("@ldsg/field-type");
5
+ const handler_1 = require("@ldsg/handler");
6
+ const resource_1 = require("@ldsg/resource");
7
+ const resource_2 = require("../resource");
8
+ class MockObjectFieldResource extends resource_1.Resource {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.getFieldInfo = (params) => {
12
+ const { id, settings: { title, description, name, properties }, getResourcesFromSettings, } = this;
13
+ const { fieldTypeResource } = getResourcesFromSettings();
14
+ const { fieldTypeInfo } = fieldTypeResource.getFieldTypeInfo({
15
+ ...params,
16
+ fieldProperties: properties,
17
+ });
18
+ const fieldInfo = {
19
+ id,
20
+ title,
21
+ description,
22
+ name,
23
+ typeInfo: fieldTypeInfo,
24
+ };
25
+ const res = {
26
+ fieldInfo,
27
+ };
28
+ return res;
29
+ };
30
+ }
31
+ }
32
+ test("object", () => {
33
+ new handler_1.HandlerResource(field_type_1.stringFieldTypeHandlerResourceRecord);
34
+ new field_type_1.FieldTypeResource(field_type_1.stringFieldTypeResourceRecord);
35
+ const testObject = new resource_2.ObjectResource({
36
+ id: "test-object",
37
+ kind: "object",
38
+ parentId: constants_1.ROOT_RESOURCE_ID,
39
+ settings: {
40
+ title: "测试对象",
41
+ description: "",
42
+ name: "test",
43
+ },
44
+ });
45
+ new MockObjectFieldResource({
46
+ id: "test-object-test-1-object-field",
47
+ kind: "object_field",
48
+ parentId: "test-object",
49
+ settings: {
50
+ title: "测试对象测试1对象字段",
51
+ description: "",
52
+ name: "test1",
53
+ fieldTypeResourceId: field_type_1.stringFieldTypeResourceRecord.id,
54
+ properties: {
55
+ max: "10",
56
+ },
57
+ },
58
+ });
59
+ new MockObjectFieldResource({
60
+ id: "test-object-test-2-object-field",
61
+ kind: "object_field",
62
+ parentId: "test-object",
63
+ settings: {
64
+ title: "测试对象测试2对象字段",
65
+ description: "",
66
+ name: "test2",
67
+ fieldTypeResourceId: field_type_1.stringFieldTypeResourceRecord.id,
68
+ properties: {
69
+ max: "10",
70
+ },
71
+ },
72
+ });
73
+ new MockObjectFieldResource({
74
+ id: "test-object-test-3-object-field",
75
+ kind: "object_field",
76
+ parentId: "test-object",
77
+ settings: {
78
+ title: "测试对象测试3对象字段",
79
+ description: "",
80
+ name: "test3",
81
+ fieldTypeResourceId: field_type_1.stringFieldTypeResourceRecord.id,
82
+ properties: {
83
+ max: "10",
84
+ },
85
+ },
86
+ });
87
+ const getObjectInfoRes = testObject.getObjectInfo();
88
+ expect(getObjectInfoRes).toMatchSnapshot();
89
+ });
@@ -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,eAAO,MAAM,iCAAiC,EAAE,uBAG/C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,EAAE,+BAQ9C,CAAC;AAEJ,eAAO,MAAM,6CAA6C,EAAE,uBACpB,CAAC;AAEzC,eAAO,MAAM,8CAA8C,EAAE,0CAI1D,CAAC"}
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,uBACpB,CAAC;AAEzC,eAAO,MAAM,8CAA8C,EAAE,0CAI1D,CAAC"}
package/dist/constants.js CHANGED
@@ -1,6 +1,7 @@
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.HANDLER_SPECIFIC_RESOURCE_SETTINGS = exports.HANDLER_GENERAL_RESOURCE_SETTINGS = void 0;
4
+ const constants_1 = require("@ldsg/constants");
4
5
  exports.HANDLER_GENERAL_RESOURCE_SETTINGS = {
5
6
  title: "对象类型资源处理程序",
6
7
  description: "",
@@ -20,6 +21,6 @@ exports.HANDLER_SPECIFIC_RESOURCE_SETTINGS = {
20
21
  };
21
22
  exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = { title: "对象类型资源定义", description: "" };
22
23
  exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = {
23
- kind: "OBJECT",
24
- subKinds: [],
24
+ kind: "object",
25
+ parentKind: constants_1.ROOT_RESOURCE_KIND,
25
26
  };
@@ -1,5 +1,26 @@
1
+ import { PlatformsParams } from "@ldsg/field-type";
1
2
  import { Resource } from "@ldsg/resource";
2
- import { ObjectSpecificResourceSettings } from "./types";
3
+ import { GeneralResourceSettings } from "@ldsg/types";
4
+ import { FieldInfo, ObjectSpecificResourceSettings } from "./types";
5
+ export interface ObjectInfo extends GeneralResourceSettings {
6
+ /**
7
+ * Object Name
8
+ */
9
+ name: string;
10
+ /**
11
+ * Field Info List
12
+ */
13
+ fieldInfoList: FieldInfo[];
14
+ }
15
+ export interface GetObjectInfoRes {
16
+ /**
17
+ * Object Info
18
+ */
19
+ objectInfo: ObjectInfo;
20
+ }
21
+ type GetObjectInfo = (params?: PlatformsParams) => GetObjectInfoRes;
3
22
  export declare class ObjectResource extends Resource<ObjectSpecificResourceSettings> {
23
+ getObjectInfo: GetObjectInfo;
4
24
  }
25
+ export {};
5
26
  //# sourceMappingURL=resource.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,8BAA8B,EAAE,MAAM,SAAS,CAAC;AAEzD,qBAAa,cAAe,SAAQ,QAAQ,CAAC,8BAA8B,CAAC;CAAG"}
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,EACL,SAAS,EAET,8BAA8B,EAC/B,MAAM,SAAS,CAAC;AAEjB,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,CAmC1B;CACH"}
package/dist/resource.js CHANGED
@@ -1,7 +1,37 @@
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
  exports.ObjectResource = void 0;
4
7
  const resource_1 = require("@ldsg/resource");
8
+ const lodash_1 = __importDefault(require("lodash"));
5
9
  class ObjectResource extends resource_1.Resource {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.getObjectInfo = (params) => {
13
+ const { id, settings: { title, description, name }, getFilteredResources, } = this;
14
+ const { resources } = getFilteredResources({
15
+ parentId: id,
16
+ });
17
+ const mapRes = resources.map((resource) => {
18
+ var _a;
19
+ const fieldInfo = (_a = resource.getFieldInfo) === null || _a === void 0 ? void 0 : _a.call(resource, params);
20
+ return fieldInfo;
21
+ });
22
+ const filterRes = lodash_1.default.filter(mapRes, (value) => !lodash_1.default.isUndefined(value));
23
+ const fieldInfoList = lodash_1.default.map(filterRes, "fieldInfo");
24
+ const objectInfo = {
25
+ title,
26
+ description,
27
+ name,
28
+ fieldInfoList,
29
+ };
30
+ const res = {
31
+ objectInfo,
32
+ };
33
+ return res;
34
+ };
35
+ }
6
36
  }
7
37
  exports.ObjectResource = ObjectResource;
@@ -0,0 +1,22 @@
1
+ import { FieldTypeInfo, PlatformsParams } from "@ldsg/field-type";
2
+ import { GeneralResourceSettings } from "@ldsg/types";
3
+ export interface FieldInfo extends GeneralResourceSettings {
4
+ /**
5
+ * Field ID
6
+ */
7
+ id: string;
8
+ /**
9
+ * Field Name
10
+ */
11
+ name: string;
12
+ /**
13
+ * Field Type Info
14
+ */
15
+ typeInfo: FieldTypeInfo;
16
+ }
17
+ interface GetFieldInfoRes {
18
+ fieldInfo: FieldInfo;
19
+ }
20
+ export type GetFieldInfo = (params?: PlatformsParams) => GetFieldInfoRes;
21
+ export {};
22
+ //# sourceMappingURL=get-field-info.d.ts.map
@@ -0,0 +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;CACzB;AAED,UAAU,eAAe;IACvB,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,CAAC,EAAE,eAAe,KAAK,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,3 @@
1
+ export * from "./get-field-info";
1
2
  export * from "./specific-resource-settings";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC"}
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./get-field-info"), exports);
17
18
  __exportStar(require("./specific-resource-settings"), exports);
@@ -1,4 +1,8 @@
1
1
  import { SpecificResourceSettings } from "@ldsg/types";
2
2
  export interface ObjectSpecificResourceSettings extends SpecificResourceSettings {
3
+ /**
4
+ * Object Name
5
+ */
6
+ name: string;
3
7
  }
4
8
  //# sourceMappingURL=specific-resource-settings.d.ts.map
@@ -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,8BACf,SAAQ,wBAAwB;CAAG"}
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;IAChC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ldsg/object",
3
- "version": "0.1.0-alpha.19",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -14,16 +14,15 @@
14
14
  "access": "public"
15
15
  },
16
16
  "dependencies": {
17
- "graphql-yoga": "^5.13.4",
18
- "@ldsg/handler": "0.1.0-alpha.19",
19
- "@ldsg/resource": "0.1.0-alpha.19",
20
- "@ldsg/resource-definition": "0.1.0-alpha.19"
17
+ "lodash": "^4.17.21",
18
+ "@ldsg/handler": "0.2.0",
19
+ "@ldsg/resource": "0.2.0",
20
+ "@ldsg/resource-definition": "0.2.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@types/supertest": "^6.0.0",
24
- "supertest": "^6.3.4",
25
- "@ldsg/application": "0.1.0-alpha.19",
26
- "@ldsg/types": "0.1.0-alpha.19"
23
+ "@types/lodash": "^4.14.202",
24
+ "@ldsg/field-type": "0.2.0",
25
+ "@ldsg/types": "0.2.0"
27
26
  },
28
27
  "scripts": {
29
28
  "build": "pnpm clean && tsc --project tsconfig.build.json",
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=resource.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resource.spec.d.ts","sourceRoot":"","sources":["../src/resource.spec.ts"],"names":[],"mappings":""}
@@ -1,46 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const application_1 = require("@ldsg/application");
16
- const supertest_1 = __importDefault(require("supertest"));
17
- const resource_1 = require("./resource");
18
- test("application", () => __awaiter(void 0, void 0, void 0, function* () {
19
- const applicationResource = new application_1.ApplicationResource({
20
- id: "application",
21
- kind: "APPLICATION",
22
- parentId: "ROOT",
23
- settings: {
24
- title: "应用",
25
- description: "应用根资源",
26
- name: "测试应用",
27
- },
28
- });
29
- new resource_1.ObjectResource({
30
- id: "object",
31
- kind: "OBJECT",
32
- parentId: "application",
33
- settings: {
34
- title: "对象",
35
- description: "对象根资源",
36
- objectEndpoint: "/test-object",
37
- },
38
- });
39
- const app = yield applicationResource.createExpressApp();
40
- const response = yield (0, supertest_1.default)(app).get("/");
41
- expect(response.statusCode).toBe(200);
42
- expect(response.text).toBe("Hello, 测试应用!");
43
- const response2 = yield (0, supertest_1.default)(app).get("/test-object");
44
- expect(response2.statusCode).toBe(200);
45
- expect(response2.text).toMatchSnapshot();
46
- }));