@malevich-studio/strapi-sdk-typescript 1.0.3 → 1.0.5

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 (48) hide show
  1. package/dist/cli.cjs +22278 -0
  2. package/dist/cli.cjs.map +1 -0
  3. package/dist/cli.d.ts +0 -1
  4. package/dist/cli.mjs +22258 -0
  5. package/dist/cli.mjs.map +1 -0
  6. package/dist/generate-strapi-types.d.ts +1 -1
  7. package/dist/generator/attributes/base-relation.d.ts +2 -1
  8. package/dist/generator/attributes/blocks.d.ts +2 -1
  9. package/dist/generator/attributes/boolean.d.ts +2 -1
  10. package/dist/generator/attributes/component.d.ts +2 -2
  11. package/dist/generator/attributes/date-time.d.ts +2 -1
  12. package/dist/generator/attributes/enumeration.d.ts +2 -1
  13. package/dist/generator/attributes/index.d.ts +2 -1
  14. package/dist/generator/attributes/json.d.ts +3 -2
  15. package/dist/generator/attributes/media.d.ts +3 -2
  16. package/dist/generator/attributes/number.d.ts +2 -1
  17. package/dist/generator/attributes/relation.d.ts +2 -2
  18. package/dist/generator/attributes/string.d.ts +2 -1
  19. package/dist/generator/index.d.ts +5 -0
  20. package/dist/index.cjs +21309 -0
  21. package/dist/index.cjs.map +1 -0
  22. package/dist/{main.d.ts → index.d.ts} +55 -7
  23. package/dist/index.mjs +21307 -0
  24. package/dist/index.mjs.map +1 -0
  25. package/dist/test.cjs +114 -0
  26. package/dist/test.cjs.map +1 -0
  27. package/dist/test.d.ts +1 -0
  28. package/dist/test.mjs +112 -0
  29. package/dist/test.mjs.map +1 -0
  30. package/package.json +27 -8
  31. package/dist/cli.js +0 -10
  32. package/dist/generate-strapi-types.js +0 -205
  33. package/dist/generator/attributes/base-relation.js +0 -56
  34. package/dist/generator/attributes/base.js +0 -53
  35. package/dist/generator/attributes/blocks.js +0 -29
  36. package/dist/generator/attributes/boolean.js +0 -17
  37. package/dist/generator/attributes/component.js +0 -36
  38. package/dist/generator/attributes/date-time.js +0 -17
  39. package/dist/generator/attributes/enumeration.js +0 -17
  40. package/dist/generator/attributes/index.js +0 -40
  41. package/dist/generator/attributes/json.js +0 -20
  42. package/dist/generator/attributes/media.js +0 -29
  43. package/dist/generator/attributes/number.js +0 -17
  44. package/dist/generator/attributes/relation.js +0 -66
  45. package/dist/generator/attributes/string.js +0 -17
  46. package/dist/generator/utils/get-component-name.js +0 -13
  47. package/dist/generator/utils/get-content-type-name.js +0 -18
  48. package/dist/main.js +0 -67
@@ -1,29 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const base_1 = __importDefault(require("./base"));
7
- class Blocks extends base_1.default {
8
- constructor(name, attribute) {
9
- super(name, attribute);
10
- this.name = name;
11
- this.attribute = attribute;
12
- }
13
- getType() {
14
- return 'BlocksContent';
15
- }
16
- getImports() {
17
- return [
18
- ...super.getImports(),
19
- 'import {BlocksContent} from "@strapi/blocks-react-renderer";',
20
- ];
21
- }
22
- getPackages() {
23
- return [
24
- ...super.getPackages(),
25
- '@strapi/blocks-react-renderer',
26
- ];
27
- }
28
- }
29
- exports.default = Blocks;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const base_1 = __importDefault(require("./base"));
7
- class Boolean extends base_1.default {
8
- constructor(name, attribute) {
9
- super(name, attribute);
10
- this.name = name;
11
- this.attribute = attribute;
12
- }
13
- getType() {
14
- return 'boolean';
15
- }
16
- }
17
- exports.default = Boolean;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const get_component_name_1 = require("../utils/get-component-name");
7
- const base_relation_1 = __importDefault(require("./base-relation"));
8
- class Component extends base_relation_1.default {
9
- constructor(name, attribute) {
10
- super(name, attribute);
11
- this.name = name;
12
- this.attribute = attribute;
13
- }
14
- getType() {
15
- const componentName = (0, get_component_name_1.getComponentName)(this.attribute.component);
16
- return this.attribute.repeatable ? `${componentName}[]` : componentName;
17
- }
18
- getInputType() {
19
- return `${(0, get_component_name_1.getComponentName)(this.attribute.component)}Input`;
20
- }
21
- getPopulates() {
22
- return [{
23
- name: this.name,
24
- type: `${(0, get_component_name_1.getComponentName)(this.attribute.component)}Query`,
25
- }];
26
- }
27
- getFilters() {
28
- return [
29
- // {
30
- // name: this.name,
31
- // type: `${getComponentName(this.attribute.component)}Filters`,
32
- // }
33
- ];
34
- }
35
- }
36
- exports.default = Component;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const base_1 = __importDefault(require("./base"));
7
- class DateTime extends base_1.default {
8
- constructor(name, attribute) {
9
- super(name, attribute);
10
- this.name = name;
11
- this.attribute = attribute;
12
- }
13
- getType() {
14
- return 'string';
15
- }
16
- }
17
- exports.default = DateTime;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const base_1 = __importDefault(require("./base"));
7
- class Enumeration extends base_1.default {
8
- constructor(name, attribute) {
9
- super(name, attribute);
10
- this.name = name;
11
- this.attribute = attribute;
12
- }
13
- getType() {
14
- return `'${this.attribute.enum.join('\' | \'')}'`;
15
- }
16
- }
17
- exports.default = Enumeration;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = getAttributeGenerator;
7
- const string_1 = __importDefault(require("./string"));
8
- const number_1 = __importDefault(require("./number"));
9
- const media_1 = __importDefault(require("./media"));
10
- const relation_1 = __importDefault(require("./relation"));
11
- const enumeration_1 = __importDefault(require("./enumeration"));
12
- const date_time_1 = __importDefault(require("./date-time"));
13
- const component_1 = __importDefault(require("./component"));
14
- const blocks_1 = __importDefault(require("./blocks"));
15
- const json_1 = __importDefault(require("./json"));
16
- const boolean_1 = __importDefault(require("./boolean"));
17
- const types = {
18
- 'string': string_1.default,
19
- 'text': string_1.default,
20
- 'password': string_1.default,
21
- 'email': string_1.default,
22
- 'integer': number_1.default,
23
- 'biginteger': number_1.default,
24
- 'decimal': number_1.default,
25
- 'float': number_1.default,
26
- 'boolean': boolean_1.default,
27
- 'media': media_1.default,
28
- 'relation': relation_1.default,
29
- 'enumeration': enumeration_1.default,
30
- 'datetime': date_time_1.default,
31
- 'component': component_1.default,
32
- 'blocks': blocks_1.default,
33
- 'json': json_1.default,
34
- };
35
- function getAttributeGenerator(name, attribute) {
36
- if (!types[attribute.type]) {
37
- throw new Error(`Attribute type "${attribute.type}" is not defined`);
38
- }
39
- return new types[attribute.type](name, attribute);
40
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const base_1 = __importDefault(require("./base"));
7
- class Json extends base_1.default {
8
- constructor(name, attribute) {
9
- super(name, attribute);
10
- this.name = name;
11
- this.attribute = attribute;
12
- }
13
- getType() {
14
- return 'object';
15
- }
16
- getFilters() {
17
- return [];
18
- }
19
- }
20
- exports.default = Json;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const base_relation_1 = __importDefault(require("./base-relation"));
7
- class Media extends base_relation_1.default {
8
- constructor(name, attribute) {
9
- super(name, attribute);
10
- this.name = name;
11
- this.attribute = attribute;
12
- }
13
- getType() {
14
- return this.attribute.multiple ? 'File[]' : 'File';
15
- }
16
- getPopulates() {
17
- return [{
18
- name: this.name,
19
- type: 'FileQuery',
20
- }];
21
- }
22
- getFilters() {
23
- return [{
24
- name: this.name,
25
- type: 'FileFilters',
26
- }];
27
- }
28
- }
29
- exports.default = Media;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const base_1 = __importDefault(require("./base"));
7
- class Number extends base_1.default {
8
- constructor(name, attribute) {
9
- super(name, attribute);
10
- this.name = name;
11
- this.attribute = attribute;
12
- }
13
- getType() {
14
- return 'number';
15
- }
16
- }
17
- exports.default = Number;
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AttributeRelation = void 0;
7
- const get_content_type_name_1 = require("../utils/get-content-type-name");
8
- const base_relation_1 = __importDefault(require("./base-relation"));
9
- var AttributeRelation;
10
- (function (AttributeRelation) {
11
- AttributeRelation["MorphToMany"] = "morphToMany";
12
- AttributeRelation["ManyToOne"] = "manyToOne";
13
- AttributeRelation["ManyToMany"] = "manyToMany";
14
- AttributeRelation["OneToMany"] = "oneToMany";
15
- AttributeRelation["OneToOne"] = "oneToOne";
16
- })(AttributeRelation || (exports.AttributeRelation = AttributeRelation = {}));
17
- class Relation extends base_relation_1.default {
18
- constructor(name, attribute) {
19
- super(name, attribute);
20
- this.name = name;
21
- this.attribute = attribute;
22
- }
23
- getType() {
24
- if (this.attribute.relation === AttributeRelation.MorphToMany) {
25
- return 'any';
26
- }
27
- const ContentTypeName = (0, get_content_type_name_1.getContentTypeName)(this.attribute.target);
28
- switch (this.attribute.relation) {
29
- case AttributeRelation.ManyToMany:
30
- case AttributeRelation.OneToMany:
31
- return `${ContentTypeName}[]`;
32
- case AttributeRelation.ManyToOne:
33
- case AttributeRelation.OneToOne:
34
- default:
35
- return ContentTypeName;
36
- }
37
- }
38
- getInputType() {
39
- return 'RelationInput';
40
- }
41
- getPopulates() {
42
- if (this.attribute.relation === AttributeRelation.MorphToMany) {
43
- return [];
44
- }
45
- return [{
46
- name: this.name,
47
- type: `${(0, get_content_type_name_1.getContentTypeName)(this.attribute.target)}Query`,
48
- }];
49
- }
50
- getFilters() {
51
- if (this.attribute.relation === AttributeRelation.MorphToMany) {
52
- return [];
53
- }
54
- return [{
55
- name: this.name,
56
- type: `${(0, get_content_type_name_1.getContentTypeName)(this.attribute.target)}Filters`,
57
- }];
58
- }
59
- getImports() {
60
- return [
61
- ...super.getImports(),
62
- 'import {RelationInput} from "@strapi/blocks-react-renderer";',
63
- ];
64
- }
65
- }
66
- exports.default = Relation;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const base_1 = __importDefault(require("./base"));
7
- class String extends base_1.default {
8
- constructor(name, attribute) {
9
- super(name, attribute);
10
- this.name = name;
11
- this.attribute = attribute;
12
- }
13
- getType() {
14
- return 'string';
15
- }
16
- }
17
- exports.default = String;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getComponentName = getComponentName;
4
- /**
5
- * Returns the TypeScript interface name from a component UID
6
- * e.g. "default.test-component" => "DefaultTestComponent"
7
- */
8
- function getComponentName(uid) {
9
- return uid
10
- .split(/[\.\-]/)
11
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
12
- .join('');
13
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getContentTypeName = getContentTypeName;
4
- /**
5
- * Returns the TypeScript interface name from a content type UID
6
- * e.g. "api::article.article" => "Article"
7
- */
8
- function getContentTypeName(uid) {
9
- // Usually, UIDs look like "api::<api-name>.<model-name>"
10
- // We'll split at "::" and then take the part after the dot.
11
- const namePart = uid.split('::')[1] || uid;
12
- const modelName = namePart.split('.')[1] || namePart;
13
- // Convert to PascalCase
14
- return modelName
15
- .split('-')
16
- .map((s) => s.charAt(0).toUpperCase() + s.slice(1))
17
- .join('');
18
- }
package/dist/main.js DELETED
@@ -1,67 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Strapi = void 0;
7
- const qs_1 = __importDefault(require("qs"));
8
- class Strapi {
9
- constructor(url, token) {
10
- this.url = url;
11
- this.token = token;
12
- }
13
- async request(endpoint, data = {}, params = {}) {
14
- const baseUrl = `${this.url}/api/`;
15
- const queryString = params.method === 'GET' ? qs_1.default.stringify(data) : '';
16
- const url = queryString ? `${baseUrl}${endpoint}?${queryString}` : `${baseUrl}${endpoint}`;
17
- const response = await fetch(url, {
18
- headers: {
19
- Authorization: `Bearer ${this.token}`,
20
- 'Content-Type': 'application/json',
21
- },
22
- cache: 'no-store',
23
- ...(params.method && !['GET', 'DELETE'].includes(params.method) ? {
24
- body: JSON.stringify({
25
- data,
26
- })
27
- } : {}),
28
- ...params
29
- });
30
- console.log(response);
31
- if (!response.ok) {
32
- throw new Error(`Помилка запиту до Strapi: ${response.status} ${response.statusText}`);
33
- }
34
- return (await response.json());
35
- }
36
- async getDocuments(endpoint, data, params = {}) {
37
- return await this.request(endpoint, data, {
38
- method: 'GET',
39
- ...params,
40
- });
41
- }
42
- async getDocument(endpoint, data, params = {}) {
43
- return await this.request(endpoint, data, {
44
- method: 'GET',
45
- ...params,
46
- });
47
- }
48
- async create(endpoint, data, params = {}) {
49
- return await this.request(endpoint, data, {
50
- method: 'POST',
51
- ...params,
52
- });
53
- }
54
- async update(endpoint, id, data, params = {}) {
55
- return await this.request(`${endpoint}/${id}`, data, {
56
- method: 'PUT',
57
- ...params,
58
- });
59
- }
60
- async delete(endpoint, id, params = {}) {
61
- return await this.request(`${endpoint}/${id}`, {}, {
62
- method: 'DELETE',
63
- ...params,
64
- });
65
- }
66
- }
67
- exports.Strapi = Strapi;