@malevich-studio/strapi-sdk-typescript 1.2.16 → 1.2.17
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.
- package/dist/cli.cjs +63 -39
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +63 -39
- package/dist/cli.mjs.map +1 -1
- package/dist/generator/attributes/relation.d.ts +2 -2
- package/dist/index.cjs +16 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.mjs +16 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -21440,17 +21440,22 @@ class Strapi {
|
|
|
21440
21440
|
log(data);
|
|
21441
21441
|
return data;
|
|
21442
21442
|
}
|
|
21443
|
-
|
|
21444
|
-
|
|
21445
|
-
|
|
21446
|
-
|
|
21447
|
-
|
|
21448
|
-
|
|
21449
|
-
|
|
21450
|
-
|
|
21451
|
-
.
|
|
21452
|
-
|
|
21453
|
-
|
|
21443
|
+
async can(uid, controller, action) {
|
|
21444
|
+
if (!this.permissions) {
|
|
21445
|
+
const response = await this.fetchData('users-permissions/permissions');
|
|
21446
|
+
this.permissions = response.permissions;
|
|
21447
|
+
}
|
|
21448
|
+
if (!this.permissions[uid]) {
|
|
21449
|
+
throw new Error(`Permissions for ${uid} not found!`);
|
|
21450
|
+
}
|
|
21451
|
+
if (!this.permissions[uid].controllers[controller]) {
|
|
21452
|
+
throw new Error(`Permissions for ${uid}.${controller} not found!`);
|
|
21453
|
+
}
|
|
21454
|
+
if (!this.permissions[uid].controllers[controller][action]) {
|
|
21455
|
+
throw new Error(`Permission for ${uid}.${controller}.${action} not found!`);
|
|
21456
|
+
}
|
|
21457
|
+
return this.permissions[uid].controllers[controller][action].enabled;
|
|
21458
|
+
}
|
|
21454
21459
|
}
|
|
21455
21460
|
|
|
21456
21461
|
var AttributeMode;
|
|
@@ -21523,32 +21528,6 @@ class BaseRelation extends Base {
|
|
|
21523
21528
|
}
|
|
21524
21529
|
}
|
|
21525
21530
|
|
|
21526
|
-
class Media extends BaseRelation {
|
|
21527
|
-
constructor(name, attribute) {
|
|
21528
|
-
super(name, attribute);
|
|
21529
|
-
this.name = name;
|
|
21530
|
-
this.attribute = attribute;
|
|
21531
|
-
}
|
|
21532
|
-
getType() {
|
|
21533
|
-
return this.attribute.multiple ? 'File[]' : 'File';
|
|
21534
|
-
}
|
|
21535
|
-
getInputType() {
|
|
21536
|
-
return 'number[]';
|
|
21537
|
-
}
|
|
21538
|
-
getPopulates() {
|
|
21539
|
-
return [{
|
|
21540
|
-
name: this.name,
|
|
21541
|
-
type: 'FileQuery',
|
|
21542
|
-
}];
|
|
21543
|
-
}
|
|
21544
|
-
getFilters() {
|
|
21545
|
-
return [{
|
|
21546
|
-
name: this.name,
|
|
21547
|
-
type: 'FileFilters',
|
|
21548
|
-
}];
|
|
21549
|
-
}
|
|
21550
|
-
}
|
|
21551
|
-
|
|
21552
21531
|
/**
|
|
21553
21532
|
* Returns the TypeScript interface name from a content type UID
|
|
21554
21533
|
* e.g. "api::article.article" => "Article"
|
|
@@ -21623,6 +21602,43 @@ class Relation extends BaseRelation {
|
|
|
21623
21602
|
}
|
|
21624
21603
|
}
|
|
21625
21604
|
|
|
21605
|
+
/**
|
|
21606
|
+
* Returns the TypeScript interface name from a component UID
|
|
21607
|
+
* e.g. "default.test-component" => "DefaultTestComponent"
|
|
21608
|
+
*/
|
|
21609
|
+
function getComponentName(uid) {
|
|
21610
|
+
return uid
|
|
21611
|
+
.split(/[\.\-]/)
|
|
21612
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
21613
|
+
.join('');
|
|
21614
|
+
}
|
|
21615
|
+
|
|
21616
|
+
class Media extends BaseRelation {
|
|
21617
|
+
constructor(name, attribute) {
|
|
21618
|
+
super(name, attribute);
|
|
21619
|
+
this.name = name;
|
|
21620
|
+
this.attribute = attribute;
|
|
21621
|
+
}
|
|
21622
|
+
getType() {
|
|
21623
|
+
return this.attribute.multiple ? 'File[]' : 'File';
|
|
21624
|
+
}
|
|
21625
|
+
getInputType() {
|
|
21626
|
+
return 'number[]';
|
|
21627
|
+
}
|
|
21628
|
+
getPopulates() {
|
|
21629
|
+
return [{
|
|
21630
|
+
name: this.name,
|
|
21631
|
+
type: 'FileQuery',
|
|
21632
|
+
}];
|
|
21633
|
+
}
|
|
21634
|
+
getFilters() {
|
|
21635
|
+
return [{
|
|
21636
|
+
name: this.name,
|
|
21637
|
+
type: 'FileFilters',
|
|
21638
|
+
}];
|
|
21639
|
+
}
|
|
21640
|
+
}
|
|
21641
|
+
|
|
21626
21642
|
class Enumeration extends Base {
|
|
21627
21643
|
constructor(name, attribute) {
|
|
21628
21644
|
super(name, attribute);
|
|
@@ -21932,6 +21948,14 @@ function generateMethodsCode(contentType) {
|
|
|
21932
21948
|
` return await this.delete<${modelName}>('${contentType.schema.pluralName}', id, params);`,
|
|
21933
21949
|
' }',
|
|
21934
21950
|
].join('\n'));
|
|
21951
|
+
console.log(contentType.uid);
|
|
21952
|
+
if (contentType.uid.startsWith('api::')) {
|
|
21953
|
+
methods.push([
|
|
21954
|
+
` public async can${getContentTypeName(contentType.schema.singularName)}(action: PermissionAction) {`,
|
|
21955
|
+
` return await this.can('${contentType.uid}', '${contentType.schema.singularName.replace(/^api::/, '')}', action);`,
|
|
21956
|
+
' }',
|
|
21957
|
+
].join('\n'));
|
|
21958
|
+
}
|
|
21935
21959
|
return methods;
|
|
21936
21960
|
}
|
|
21937
21961
|
/**
|
|
@@ -21985,7 +22009,7 @@ async function generateStrapiTypes(strapi) {
|
|
|
21985
22009
|
localizations: {
|
|
21986
22010
|
type: 'relation',
|
|
21987
22011
|
target: contentType.uid,
|
|
21988
|
-
relation:
|
|
22012
|
+
relation: AttributeRelation.OneToMany,
|
|
21989
22013
|
required: true,
|
|
21990
22014
|
},
|
|
21991
22015
|
} : {}),
|
|
@@ -21996,7 +22020,7 @@ async function generateStrapiTypes(strapi) {
|
|
|
21996
22020
|
allInterfaces.push(generateInputTypeCode(modelName, attributes));
|
|
21997
22021
|
}
|
|
21998
22022
|
const output = [
|
|
21999
|
-
'import {Strapi as StrapiBase, Query, Filters, FilterValue, RelationInput, DynamiczonePopulate, DynamiczoneComponent} from "@malevich-studio/strapi-sdk-typescript";',
|
|
22023
|
+
'import {Strapi as StrapiBase, Query, Filters, FilterValue, RelationInput, DynamiczonePopulate, DynamiczoneComponent, PermissionAction} from "@malevich-studio/strapi-sdk-typescript";',
|
|
22000
22024
|
'import {BlocksContent} from "@strapi/blocks-react-renderer";',
|
|
22001
22025
|
'',
|
|
22002
22026
|
'export default class Strapi extends StrapiBase {',
|