@builder.io/sdk 3.0.2-0 → 3.0.2-2

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,159 +1,177 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var builder_class_1 = require("./builder.class");
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ var builder_class_1 = require('./builder.class');
4
4
  describe('Builder', function () {
5
- test('trustedHosts', function () {
6
- expect(builder_class_1.Builder.isTrustedHost('localhost')).toBe(true);
7
- expect(builder_class_1.Builder.isTrustedHost('builder.io')).toBe(true);
8
- expect(builder_class_1.Builder.isTrustedHost('beta.builder.io')).toBe(true);
9
- expect(builder_class_1.Builder.isTrustedHost('qa.builder.io')).toBe(true);
10
- expect(builder_class_1.Builder.isTrustedHost('123-review-build.beta.builder.io')).toBe(true);
11
- });
12
- test('arbitrary builder.io subdomains', function () {
13
- expect(builder_class_1.Builder.isTrustedHost('cdn.builder.io')).toBe(false);
14
- expect(builder_class_1.Builder.isTrustedHost('foo.builder.io')).toBe(false);
15
- expect(builder_class_1.Builder.isTrustedHost('evildomainbeta.builder.io')).toBe(false);
16
- });
17
- test('add trusted host', function () {
18
- expect(builder_class_1.Builder.isTrustedHost('example.com')).toBe(false);
19
- builder_class_1.Builder.registerTrustedHost('example.com');
20
- expect(builder_class_1.Builder.isTrustedHost('example.com')).toBe(true);
21
- });
5
+ test('trustedHosts', function () {
6
+ expect(builder_class_1.Builder.isTrustedHost('localhost')).toBe(true);
7
+ expect(builder_class_1.Builder.isTrustedHost('builder.io')).toBe(true);
8
+ expect(builder_class_1.Builder.isTrustedHost('beta.builder.io')).toBe(true);
9
+ expect(builder_class_1.Builder.isTrustedHost('qa.builder.io')).toBe(true);
10
+ expect(builder_class_1.Builder.isTrustedHost('123-review-build.beta.builder.io')).toBe(true);
11
+ });
12
+ test('arbitrary builder.io subdomains', function () {
13
+ expect(builder_class_1.Builder.isTrustedHost('cdn.builder.io')).toBe(false);
14
+ expect(builder_class_1.Builder.isTrustedHost('foo.builder.io')).toBe(false);
15
+ expect(builder_class_1.Builder.isTrustedHost('evildomainbeta.builder.io')).toBe(false);
16
+ });
17
+ test('add trusted host', function () {
18
+ expect(builder_class_1.Builder.isTrustedHost('example.com')).toBe(false);
19
+ builder_class_1.Builder.registerTrustedHost('example.com');
20
+ expect(builder_class_1.Builder.isTrustedHost('example.com')).toBe(true);
21
+ });
22
22
  });
23
23
  describe('serializeIncludingFunctions', function () {
24
- test('serializes functions in inputs', function () {
25
- var input = {
26
- name: 'TestComponent',
27
- inputs: [
28
- {
29
- name: 'text',
30
- type: 'string',
31
- onChange: function (value) {
32
- return value.toUpperCase();
33
- },
34
- },
35
- ],
36
- };
37
- var result = builder_class_1.Builder['serializeIncludingFunctions'](input);
38
- expect(typeof result.inputs[0].onChange).toBe('string');
39
- expect(result.inputs[0].onChange).toContain('return value.toUpperCase()');
40
- });
41
- test('serializes arrow functions in inputs', function () {
42
- var input = {
43
- name: 'ArrowComponent',
44
- inputs: [
45
- {
46
- name: 'number',
47
- type: 'number',
48
- onChange: function (value) { return value * 2; },
49
- },
50
- ],
51
- };
52
- var result = builder_class_1.Builder['serializeIncludingFunctions'](input);
53
- expect(typeof result.inputs[0].onChange).toBe('string');
54
- expect(result.inputs[0].onChange).toContain('value * 2');
55
- });
56
- test('does not modify non-function properties', function () {
57
- var input = {
58
- name: 'MixedComponent',
59
- inputs: [
60
- {
61
- name: 'text',
62
- type: 'string',
63
- defaultValue: 'hello',
64
- },
65
- ],
66
- };
67
- var result = builder_class_1.Builder['serializeIncludingFunctions'](input);
68
- expect(result).toEqual(input);
69
- });
70
- test('handles multiple inputs with mixed properties', function () {
71
- var input = {
72
- name: 'ComplexComponent',
73
- inputs: [
74
- {
75
- name: 'text',
76
- type: 'string',
77
- onChange: function (value) { return value.trim(); },
78
- },
79
- {
80
- name: 'number',
81
- type: 'number',
82
- defaultValue: 42,
83
- },
84
- {
85
- name: 'options',
86
- type: 'string',
87
- onChange: function (value) {
88
- return value.map(function (v) { return v.toLowerCase(); });
89
- },
90
- },
91
- ],
92
- };
93
- var result = builder_class_1.Builder['serializeIncludingFunctions'](input);
94
- expect(typeof result.inputs[0].onChange).toBe('string');
95
- expect(result.inputs[0].onChange).toContain('value.trim()');
96
- expect(result.inputs[1]).toEqual(input.inputs[1]);
97
- expect(typeof result.inputs[2].onChange).toBe('string');
98
- expect(result.inputs[2].onChange).toContain('v.toLowerCase()');
99
- });
24
+ test('serializes functions in inputs', function () {
25
+ var input = {
26
+ name: 'TestComponent',
27
+ inputs: [
28
+ {
29
+ name: 'text',
30
+ type: 'string',
31
+ onChange: function (value) {
32
+ return value.toUpperCase();
33
+ },
34
+ },
35
+ ],
36
+ };
37
+ var result = builder_class_1.Builder['serializeIncludingFunctions'](input);
38
+ expect(typeof result.inputs[0].onChange).toBe('string');
39
+ expect(result.inputs[0].onChange).toContain('return value.toUpperCase()');
40
+ });
41
+ test('serializes arrow functions in inputs', function () {
42
+ var input = {
43
+ name: 'ArrowComponent',
44
+ inputs: [
45
+ {
46
+ name: 'number',
47
+ type: 'number',
48
+ onChange: function (value) {
49
+ return value * 2;
50
+ },
51
+ },
52
+ ],
53
+ };
54
+ var result = builder_class_1.Builder['serializeIncludingFunctions'](input);
55
+ expect(typeof result.inputs[0].onChange).toBe('string');
56
+ expect(result.inputs[0].onChange).toContain('value * 2');
57
+ });
58
+ test('does not modify non-function properties', function () {
59
+ var input = {
60
+ name: 'MixedComponent',
61
+ inputs: [
62
+ {
63
+ name: 'text',
64
+ type: 'string',
65
+ defaultValue: 'hello',
66
+ },
67
+ ],
68
+ };
69
+ var result = builder_class_1.Builder['serializeIncludingFunctions'](input);
70
+ expect(result).toEqual(input);
71
+ });
72
+ test('handles multiple inputs with mixed properties', function () {
73
+ var input = {
74
+ name: 'ComplexComponent',
75
+ inputs: [
76
+ {
77
+ name: 'text',
78
+ type: 'string',
79
+ onChange: function (value) {
80
+ return value.trim();
81
+ },
82
+ },
83
+ {
84
+ name: 'number',
85
+ type: 'number',
86
+ defaultValue: 42,
87
+ },
88
+ {
89
+ name: 'options',
90
+ type: 'string',
91
+ onChange: function (value) {
92
+ return value.map(function (v) {
93
+ return v.toLowerCase();
94
+ });
95
+ },
96
+ },
97
+ ],
98
+ };
99
+ var result = builder_class_1.Builder['serializeIncludingFunctions'](input);
100
+ expect(typeof result.inputs[0].onChange).toBe('string');
101
+ expect(result.inputs[0].onChange).toContain('value.trim()');
102
+ expect(result.inputs[1]).toEqual(input.inputs[1]);
103
+ expect(typeof result.inputs[2].onChange).toBe('string');
104
+ expect(result.inputs[2].onChange).toContain('v.toLowerCase()');
105
+ });
100
106
  });
101
107
  describe('prepareComponentSpecToSend', function () {
102
- test('removes class property and serializes functions in inputs', function () {
103
- var _a, _b;
104
- var input = {
105
- name: 'TestComponent',
106
- class: /** @class */ (function () {
107
- function TestClass() {
108
- }
109
- return TestClass;
110
- }()),
111
- inputs: [
112
- {
113
- name: 'text',
114
- type: 'string',
115
- onChange: function (value) {
116
- return value.toUpperCase();
117
- },
118
- },
119
- ],
120
- };
121
- var result = builder_class_1.Builder['prepareComponentSpecToSend'](input);
122
- expect(result.class).toBeUndefined();
123
- expect(typeof ((_a = result.inputs) === null || _a === void 0 ? void 0 : _a[0].onChange)).toBe('string');
124
- expect((_b = result.inputs) === null || _b === void 0 ? void 0 : _b[0].onChange).toContain('value.toUpperCase()');
125
- });
126
- test('preserves other properties', function () {
127
- var _a, _b, _c, _d, _e;
128
- var input = {
129
- name: 'ComplexComponent',
130
- class: /** @class */ (function () {
131
- function ComplexClass() {
132
- }
133
- return ComplexClass;
134
- }()),
135
- inputs: [
136
- {
137
- name: 'text',
138
- type: 'string',
139
- defaultValue: 'hello',
140
- onChange: function (value) { return value.trim(); },
141
- },
142
- {
143
- name: 'number',
144
- type: 'number',
145
- defaultValue: 42,
146
- },
147
- ],
148
- };
149
- var result = builder_class_1.Builder['prepareComponentSpecToSend'](input);
150
- expect(result.class).toBeUndefined();
151
- expect(result.name).toBe('ComplexComponent');
152
- expect((_a = result.inputs) === null || _a === void 0 ? void 0 : _a.length).toBe(2);
153
- expect(typeof ((_b = result.inputs) === null || _b === void 0 ? void 0 : _b[0].onChange)).toBe('string');
154
- expect((_c = result.inputs) === null || _c === void 0 ? void 0 : _c[0].onChange).toContain('value.trim()');
155
- expect((_d = result.inputs) === null || _d === void 0 ? void 0 : _d[0].defaultValue).toBe('hello');
156
- expect((_e = result.inputs) === null || _e === void 0 ? void 0 : _e[1]).toEqual(input.inputs[1]);
157
- });
108
+ test('removes class property and serializes functions in inputs', function () {
109
+ var _a, _b;
110
+ var input = {
111
+ name: 'TestComponent',
112
+ class: /** @class */ (function () {
113
+ function TestClass() {}
114
+ return TestClass;
115
+ })(),
116
+ inputs: [
117
+ {
118
+ name: 'text',
119
+ type: 'string',
120
+ onChange: function (value) {
121
+ return value.toUpperCase();
122
+ },
123
+ },
124
+ ],
125
+ };
126
+ var result = builder_class_1.Builder['prepareComponentSpecToSend'](input);
127
+ expect(result.class).toBeUndefined();
128
+ expect(typeof ((_a = result.inputs) === null || _a === void 0 ? void 0 : _a[0].onChange)).toBe(
129
+ 'string'
130
+ );
131
+ expect((_b = result.inputs) === null || _b === void 0 ? void 0 : _b[0].onChange).toContain(
132
+ 'value.toUpperCase()'
133
+ );
134
+ });
135
+ test('preserves other properties', function () {
136
+ var _a, _b, _c, _d, _e;
137
+ var input = {
138
+ name: 'ComplexComponent',
139
+ class: /** @class */ (function () {
140
+ function ComplexClass() {}
141
+ return ComplexClass;
142
+ })(),
143
+ inputs: [
144
+ {
145
+ name: 'text',
146
+ type: 'string',
147
+ defaultValue: 'hello',
148
+ onChange: function (value) {
149
+ return value.trim();
150
+ },
151
+ },
152
+ {
153
+ name: 'number',
154
+ type: 'number',
155
+ defaultValue: 42,
156
+ },
157
+ ],
158
+ };
159
+ var result = builder_class_1.Builder['prepareComponentSpecToSend'](input);
160
+ expect(result.class).toBeUndefined();
161
+ expect(result.name).toBe('ComplexComponent');
162
+ expect((_a = result.inputs) === null || _a === void 0 ? void 0 : _a.length).toBe(2);
163
+ expect(typeof ((_b = result.inputs) === null || _b === void 0 ? void 0 : _b[0].onChange)).toBe(
164
+ 'string'
165
+ );
166
+ expect((_c = result.inputs) === null || _c === void 0 ? void 0 : _c[0].onChange).toContain(
167
+ 'value.trim()'
168
+ );
169
+ expect((_d = result.inputs) === null || _d === void 0 ? void 0 : _d[0].defaultValue).toBe(
170
+ 'hello'
171
+ );
172
+ expect((_e = result.inputs) === null || _e === void 0 ? void 0 : _e[1]).toEqual(
173
+ input.inputs[1]
174
+ );
175
+ });
158
176
  });
159
- //# sourceMappingURL=builder.class.test.js.map
177
+ //# sourceMappingURL=builder.class.test.js.map