@nocobase/plugin-api-doc 0.13.0-alpha.1

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 (59) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +80 -0
  3. package/README.zh-CN.md +79 -0
  4. package/client.d.ts +2 -0
  5. package/client.js +1 -0
  6. package/dist/client/Document.d.ts +4 -0
  7. package/dist/client/index.d.ts +6 -0
  8. package/dist/client/index.js +48583 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.js +11 -0
  11. package/dist/locale/en-US.d.ts +2 -0
  12. package/dist/locale/en-US.js +5 -0
  13. package/dist/locale/index.d.ts +4 -0
  14. package/dist/locale/index.js +20 -0
  15. package/dist/locale/zh-CN.d.ts +6 -0
  16. package/dist/locale/zh-CN.js +9 -0
  17. package/dist/server/index.d.ts +1 -0
  18. package/dist/server/index.js +11 -0
  19. package/dist/server/server.d.ts +8 -0
  20. package/dist/server/server.js +51 -0
  21. package/dist/server/swagger/base-swagger.d.ts +49 -0
  22. package/dist/server/swagger/base-swagger.js +54 -0
  23. package/dist/server/swagger/collections/components/field-type-map.d.ts +22 -0
  24. package/dist/server/swagger/collections/components/field-type-map.js +34 -0
  25. package/dist/server/swagger/collections/components/index.d.ts +24 -0
  26. package/dist/server/swagger/collections/components/index.js +18 -0
  27. package/dist/server/swagger/collections/components/parameters.d.ts +5 -0
  28. package/dist/server/swagger/collections/components/parameters.js +173 -0
  29. package/dist/server/swagger/collections/components/schemas.d.ts +23 -0
  30. package/dist/server/swagger/collections/components/schemas.js +91 -0
  31. package/dist/server/swagger/collections/index.d.ts +31 -0
  32. package/dist/server/swagger/collections/index.js +22 -0
  33. package/dist/server/swagger/collections/paths/associations/index.d.ts +6 -0
  34. package/dist/server/swagger/collections/paths/associations/index.js +32 -0
  35. package/dist/server/swagger/collections/paths/associations/multiple-association.d.ts +6 -0
  36. package/dist/server/swagger/collections/paths/associations/multiple-association.js +106 -0
  37. package/dist/server/swagger/collections/paths/associations/single-association.d.ts +5 -0
  38. package/dist/server/swagger/collections/paths/associations/single-association.js +88 -0
  39. package/dist/server/swagger/collections/paths/collection.d.ts +201 -0
  40. package/dist/server/swagger/collections/paths/collection.js +333 -0
  41. package/dist/server/swagger/collections/paths/index.d.ts +4 -0
  42. package/dist/server/swagger/collections/paths/index.js +30 -0
  43. package/dist/server/swagger/collections/tags/index.d.ts +6 -0
  44. package/dist/server/swagger/collections/tags/index.js +26 -0
  45. package/dist/server/swagger/constants.d.ts +10 -0
  46. package/dist/server/swagger/constants.js +14 -0
  47. package/dist/server/swagger/helpers.d.ts +171 -0
  48. package/dist/server/swagger/helpers.js +111 -0
  49. package/dist/server/swagger/index.d.ts +48 -0
  50. package/dist/server/swagger/index.js +221 -0
  51. package/dist/server/swagger/loader.d.ts +4 -0
  52. package/dist/server/swagger/loader.js +54 -0
  53. package/dist/server/swagger/merge.d.ts +1 -0
  54. package/dist/server/swagger/merge.js +13 -0
  55. package/dist/swagger.d.ts +43 -0
  56. package/dist/swagger.js +46 -0
  57. package/package.json +24 -0
  58. package/server.d.ts +3 -0
  59. package/server.js +1 -0
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ var paths = require('./paths');
4
+ var components = require('./components');
5
+ var tags = require('./tags');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var paths__default = /*#__PURE__*/_interopDefault(paths);
10
+ var components__default = /*#__PURE__*/_interopDefault(components);
11
+ var tags__default = /*#__PURE__*/_interopDefault(tags);
12
+
13
+ function collectionToSwaggerObject(collection, options) {
14
+ return {
15
+ paths: paths__default.default(collection, options),
16
+ components: components__default.default(collection, options),
17
+ tags: tags__default.default(collection, options)
18
+ };
19
+ }
20
+ var collections_default = collectionToSwaggerObject;
21
+
22
+ module.exports = collections_default;
@@ -0,0 +1,6 @@
1
+ import { Collection, RelationField } from '@nocobase/database';
2
+ declare const _default: (collection: Collection) => {
3
+ [x: string]: object;
4
+ };
5
+ export default _default;
6
+ export declare function associationFields(collection: Collection): Array<RelationField>;
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var database = require('@nocobase/database');
6
+ var multipleAssociation = require('./multiple-association');
7
+ var singleAssociation = require('./single-association');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var multipleAssociation__default = /*#__PURE__*/_interopDefault(multipleAssociation);
12
+ var singleAssociation__default = /*#__PURE__*/_interopDefault(singleAssociation);
13
+
14
+ var associations_default = (collection) => {
15
+ return associationFields(collection).map((field) => {
16
+ if (field.type === "belongsToMany" || field.type === "hasMany") {
17
+ return multipleAssociation__default.default(collection, field);
18
+ }
19
+ return singleAssociation__default.default(collection, field);
20
+ }).reduce((obj, item) => {
21
+ return {
22
+ ...obj,
23
+ ...item
24
+ };
25
+ }, {});
26
+ };
27
+ function associationFields(collection) {
28
+ return Array.from(collection.fields.values()).filter((field) => field instanceof database.RelationField).filter((field) => field.name !== "createdBy" && field.name !== "updatedBy");
29
+ }
30
+
31
+ exports.associationFields = associationFields;
32
+ exports.default = associations_default;
@@ -0,0 +1,6 @@
1
+ import { BelongsToManyField, Collection, HasManyField } from '@nocobase/database';
2
+ export declare function appendCollectionIndexParams(apiDef: object): object;
3
+ declare const _default: (collection: Collection, relationField: HasManyField | BelongsToManyField) => {
4
+ [x: string]: object;
5
+ };
6
+ export default _default;
@@ -0,0 +1,106 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var collection = require('../collection');
6
+ var index = require('../index');
7
+
8
+ function appendCollectionIndexParams(apiDef) {
9
+ for (const action of Object.keys(apiDef)) {
10
+ const parameters = apiDef[action]["parameters"];
11
+ if (!parameters) {
12
+ apiDef[action]["parameters"] = [];
13
+ }
14
+ apiDef[action]["parameters"].unshift({
15
+ $ref: "#/components/parameters/collectionIndex"
16
+ });
17
+ }
18
+ return apiDef;
19
+ }
20
+ var multiple_association_default = (collection$1, relationField) => {
21
+ const options = {
22
+ collection: collection$1,
23
+ relationField
24
+ };
25
+ collection$1.db.getCollection(relationField.target);
26
+ const paths = {
27
+ [`/${collection$1.name}/{collectionIndex}/${relationField.name}:list`]: appendCollectionIndexParams(
28
+ collection.ListActionTemplate(options)
29
+ ),
30
+ [`/${collection$1.name}/{collectionIndex}/${relationField.name}:get`]: appendCollectionIndexParams(
31
+ collection.GetActionTemplate(options)
32
+ ),
33
+ [`/${collection$1.name}/{collectionIndex}/${relationField.name}:create`]: appendCollectionIndexParams(
34
+ collection.CreateActionTemplate(options)
35
+ ),
36
+ [`/${collection$1.name}/{collectionIndex}/${relationField.name}:update`]: appendCollectionIndexParams(
37
+ collection.UpdateActionTemplate(options)
38
+ ),
39
+ [`/${collection$1.name}/{collectionIndex}/${relationField.name}:destroy`]: appendCollectionIndexParams(
40
+ collection.DestroyActionTemplate(options)
41
+ ),
42
+ [`/${collection$1.name}/{collectionIndex}/${relationField.name}:set`]: appendCollectionIndexParams({
43
+ post: {
44
+ tags: [`${collection$1.name}.${relationField.name}`],
45
+ summary: "Set or reset associations",
46
+ parameters: [
47
+ {
48
+ $ref: "#/components/parameters/filterByTk"
49
+ },
50
+ {
51
+ $ref: "#/components/parameters/filterByTks"
52
+ }
53
+ ],
54
+ responses: {
55
+ "200": {
56
+ description: "OK"
57
+ }
58
+ }
59
+ }
60
+ }),
61
+ [`/${collection$1.name}/{collectionIndex}/${relationField.name}:remove`]: appendCollectionIndexParams({
62
+ post: {
63
+ tags: [`${collection$1.name}.${relationField.name}`],
64
+ summary: "Detach record",
65
+ parameters: [
66
+ {
67
+ $ref: "#/components/parameters/filterByTk"
68
+ },
69
+ {
70
+ $ref: "#/components/parameters/filterByTks"
71
+ }
72
+ ],
73
+ responses: {
74
+ "200": {
75
+ description: "OK"
76
+ }
77
+ }
78
+ }
79
+ }),
80
+ [`/${collection$1.name}/{collectionIndex}/${relationField.name}:toggle`]: appendCollectionIndexParams({
81
+ post: {
82
+ tags: [`${collection$1.name}.${relationField.name}`],
83
+ summary: "Attach or detach record",
84
+ parameters: [
85
+ {
86
+ $ref: "#/components/parameters/filterByTk"
87
+ }
88
+ ],
89
+ responses: {
90
+ "200": {
91
+ description: "OK"
92
+ }
93
+ }
94
+ }
95
+ })
96
+ };
97
+ if (index.hasSortField(collection$1)) {
98
+ paths[`/${collection$1.name}/{collectionIndex}/${relationField.name}:move`] = appendCollectionIndexParams(
99
+ collection.MoveActionTemplate(options)
100
+ );
101
+ }
102
+ return paths;
103
+ };
104
+
105
+ exports.appendCollectionIndexParams = appendCollectionIndexParams;
106
+ exports.default = multiple_association_default;
@@ -0,0 +1,5 @@
1
+ import { BelongsToField, Collection, HasOneField } from '@nocobase/database';
2
+ declare const _default: (collection: Collection, relationField: HasOneField | BelongsToField) => {
3
+ [x: string]: object;
4
+ };
5
+ export default _default;
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ var multipleAssociation = require('./multiple-association');
4
+ var collection = require('../collection');
5
+
6
+ function removeFilterByTkParams(apiDoc) {
7
+ for (const action of Object.values(apiDoc)) {
8
+ if (action.parameters) {
9
+ action.parameters = action.parameters.filter((param) => {
10
+ if (param.$ref) {
11
+ return param.$ref !== "#/components/parameters/filterByTk";
12
+ }
13
+ });
14
+ }
15
+ }
16
+ return apiDoc;
17
+ }
18
+ const parametersShouldRemove = [
19
+ "#/components/parameters/filterByTk",
20
+ "#/components/parameters/filter",
21
+ "#/components/parameters/sort"
22
+ ];
23
+ function filterSingleAssociationParams(apiDoc) {
24
+ for (const action of Object.values(apiDoc)) {
25
+ if (action.parameters) {
26
+ action.parameters = action.parameters.filter((param) => {
27
+ if (param.$ref) {
28
+ return !parametersShouldRemove.includes(param.$ref);
29
+ }
30
+ });
31
+ }
32
+ }
33
+ return apiDoc;
34
+ }
35
+ var single_association_default = (collection$1, relationField) => {
36
+ const options = {
37
+ collection: collection$1,
38
+ relationField
39
+ };
40
+ return {
41
+ [`/${collection$1.name}/{collectionIndex}/${relationField.name}:get`]: removeFilterByTkParams(
42
+ filterSingleAssociationParams(multipleAssociation.appendCollectionIndexParams(collection.GetActionTemplate(options)))
43
+ ),
44
+ [`/${collection$1.name}/{collectionIndex}/${relationField.name}:set`]: multipleAssociation.appendCollectionIndexParams({
45
+ post: {
46
+ tags: [`${collection$1.name}.${relationField.name}`],
47
+ summary: "Associate a record",
48
+ parameters: [
49
+ {
50
+ name: "tk",
51
+ in: "query",
52
+ description: "targetKey",
53
+ schema: {
54
+ type: "string"
55
+ }
56
+ }
57
+ ],
58
+ responses: {
59
+ "200": {
60
+ description: "OK"
61
+ }
62
+ }
63
+ }
64
+ }),
65
+ [`/${collection$1.name}/{collectionIndex}/${relationField.name}:remove`]: multipleAssociation.appendCollectionIndexParams({
66
+ post: {
67
+ tags: [`${collection$1.name}.${relationField.name}`],
68
+ summary: "Disassociate the relationship record",
69
+ responses: {
70
+ "200": {
71
+ description: "OK"
72
+ }
73
+ }
74
+ }
75
+ }),
76
+ [`/${collection$1.name}/{collectionIndex}/${relationField.name}:update`]: removeFilterByTkParams(
77
+ filterSingleAssociationParams(multipleAssociation.appendCollectionIndexParams(collection.UpdateActionTemplate(options)))
78
+ ),
79
+ [`/${collection$1.name}/{collectionIndex}/${relationField.name}:create`]: removeFilterByTkParams(
80
+ filterSingleAssociationParams(multipleAssociation.appendCollectionIndexParams(collection.CreateActionTemplate(options)))
81
+ ),
82
+ [`/${collection$1.name}/{collectionIndex}/${relationField.name}:destroy`]: removeFilterByTkParams(
83
+ filterSingleAssociationParams(multipleAssociation.appendCollectionIndexParams(collection.DestroyActionTemplate(options)))
84
+ )
85
+ };
86
+ };
87
+
88
+ module.exports = single_association_default;
@@ -0,0 +1,201 @@
1
+ import { Collection, RelationField } from '@nocobase/database';
2
+ type TemplateOptions = {
3
+ collection: Collection;
4
+ relationField?: RelationField;
5
+ };
6
+ export declare function relationTypeToString(field: RelationField): any;
7
+ export declare function ListActionTemplate({ collection, relationField }: TemplateOptions): {
8
+ get: {
9
+ tags: string[];
10
+ summary: string;
11
+ parameters: ({
12
+ name: string;
13
+ in: string;
14
+ description: string;
15
+ required: boolean;
16
+ schema: {
17
+ type: string;
18
+ };
19
+ $ref?: undefined;
20
+ } | {
21
+ $ref: string;
22
+ name?: undefined;
23
+ in?: undefined;
24
+ description?: undefined;
25
+ required?: undefined;
26
+ schema?: undefined;
27
+ })[];
28
+ responses: {
29
+ '200': {
30
+ description: string;
31
+ content: {
32
+ 'application/json': {
33
+ schema: {
34
+ type: string;
35
+ properties: {
36
+ data: {
37
+ type: string;
38
+ items: {
39
+ $ref: string;
40
+ };
41
+ };
42
+ meta: {
43
+ type: string;
44
+ properties: {
45
+ count: {
46
+ type: string;
47
+ description: string;
48
+ };
49
+ page: {
50
+ type: string;
51
+ description: string;
52
+ };
53
+ pageSize: {
54
+ type: string;
55
+ description: string;
56
+ };
57
+ totalPage: {
58
+ type: string;
59
+ description: string;
60
+ };
61
+ };
62
+ };
63
+ };
64
+ };
65
+ };
66
+ };
67
+ };
68
+ };
69
+ };
70
+ };
71
+ export declare function GetActionTemplate(options: TemplateOptions): {
72
+ get: {
73
+ tags: string[];
74
+ summary: string;
75
+ parameters: {
76
+ $ref: string;
77
+ }[];
78
+ responses: {
79
+ '200': {
80
+ description: string;
81
+ content: {
82
+ 'application/json': {
83
+ schema: {
84
+ type: string;
85
+ properties: {
86
+ data: {
87
+ $ref: string;
88
+ };
89
+ };
90
+ };
91
+ };
92
+ };
93
+ };
94
+ };
95
+ };
96
+ };
97
+ export declare function CreateActionTemplate(options: TemplateOptions): {
98
+ post: {
99
+ tags: string[];
100
+ summary: string;
101
+ parameters: {
102
+ $ref: string;
103
+ }[];
104
+ requestBody: {
105
+ content: {
106
+ 'application/json': {
107
+ schema: {
108
+ $ref: string;
109
+ };
110
+ };
111
+ };
112
+ };
113
+ responses: {
114
+ '200': {
115
+ description: string;
116
+ content: {
117
+ 'application/json': {
118
+ schema: {
119
+ type: string;
120
+ properties: {
121
+ data: {
122
+ $ref: string;
123
+ };
124
+ };
125
+ };
126
+ };
127
+ };
128
+ };
129
+ };
130
+ };
131
+ };
132
+ export declare function UpdateActionTemplate(options: TemplateOptions): {
133
+ post: {
134
+ tags: string[];
135
+ summary: string;
136
+ parameters: {
137
+ $ref: string;
138
+ }[];
139
+ requestBody: {
140
+ content: {
141
+ 'application/json': {
142
+ schema: {
143
+ $ref: string;
144
+ };
145
+ };
146
+ };
147
+ };
148
+ responses: {
149
+ '200': {
150
+ description: string;
151
+ content: {
152
+ 'application/json': {
153
+ schema: {
154
+ type: string;
155
+ properties: {
156
+ data: {
157
+ $ref: string;
158
+ };
159
+ };
160
+ };
161
+ };
162
+ };
163
+ };
164
+ };
165
+ };
166
+ };
167
+ export declare function DestroyActionTemplate(options: TemplateOptions): {
168
+ post: {
169
+ tags: string[];
170
+ summary: string;
171
+ parameters: {
172
+ $ref: string;
173
+ }[];
174
+ responses: {
175
+ '200': {
176
+ description: string;
177
+ };
178
+ };
179
+ };
180
+ };
181
+ export declare function MoveActionTemplate(options: TemplateOptions): {
182
+ post: {
183
+ tags: string[];
184
+ summary: string;
185
+ parameters: {
186
+ name: string;
187
+ in: string;
188
+ description: string;
189
+ schema: {
190
+ type: string;
191
+ };
192
+ }[];
193
+ responses: {
194
+ '200': {
195
+ description: string;
196
+ };
197
+ };
198
+ };
199
+ };
200
+ declare const _default: (collection: Collection) => any;
201
+ export default _default;