@teambit/schema 1.0.167 → 1.0.169

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,6 +1,6 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@1.0.167/dist/schema.composition.js';
2
- import * as compositions_1 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@1.0.167/dist/mock/button/button.composition.js';
3
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@1.0.167/dist/schema.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@1.0.169/dist/schema.composition.js';
2
+ import * as compositions_1 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@1.0.169/dist/mock/button/button.composition.js';
3
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_schema@1.0.169/dist/schema.docs.mdx';
4
4
 
5
5
  export const compositions = [compositions_0, compositions_1];
6
6
  export const overview = [overview_0];
@@ -131,3 +131,71 @@ export function genericFunction<T>(a: T) {
131
131
  }
132
132
 
133
133
  export const gfnc2 = genericFunction<string>('');
134
+
135
+ export function LogMethod(message: string) {
136
+ return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
137
+ const originalMethod = descriptor.value;
138
+ descriptor.value = function (...args: any[]) {
139
+ console.log(`Logging: ${message}`);
140
+ return originalMethod.apply(this, args);
141
+ };
142
+ };
143
+ }
144
+
145
+ export function CustomClassDecorator(config: {
146
+ name: string;
147
+ description: string;
148
+ fn?: () => string;
149
+ class?: ClassSomething;
150
+ arr?: [
151
+ string,
152
+ number,
153
+ boolean,
154
+ boolean,
155
+ number | undefined,
156
+ (a: string) => void,
157
+ { a: string; b: number },
158
+ ClassSomething
159
+ ];
160
+ }) {
161
+ return function (target: any) {
162
+ console.log(`Class ${config.name} - ${config.description}`);
163
+ };
164
+ }
165
+
166
+ @CustomClassDecorator({ name: 'ExampleClass2', description: 'This is an example class 2' })
167
+ export class ExampleDecoratorOne {
168
+ @LogMethod('This is a log message')
169
+ exampleMethod() {
170
+ // Method logic
171
+ }
172
+ }
173
+
174
+ export function ValidateArgs(config: { type: string; required: boolean }) {
175
+ return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
176
+ const originalMethod = descriptor.value;
177
+ descriptor.value = function (...args: any[]) {
178
+ if (args[0] && typeof args[0] !== config.type) {
179
+ throw new Error('Invalid argument type');
180
+ }
181
+ if (config.required && !args[0]) {
182
+ throw new Error('Argument is required');
183
+ }
184
+ return originalMethod.apply(this, args);
185
+ };
186
+ };
187
+ }
188
+
189
+ @CustomClassDecorator({
190
+ name: 'ExampleClass',
191
+ description: 'This is an example class',
192
+ fn: () => 'hi',
193
+ class: new ClassSomething('dsa'),
194
+ arr: ['hi', 5, true, false, undefined, () => {}, { a: 'hi', b: 5 }, new ClassSomething('dsa')],
195
+ })
196
+ export class ExampleDecoratorTwo {
197
+ @ValidateArgs({ type: 'string', required: true })
198
+ exampleMethod(input: string) {
199
+ // Method logic
200
+ }
201
+ }