@appsemble/utils 0.30.1 → 0.30.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.
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.30.1/config/assets/logo.svg) Appsemble Utilities
1
+ # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.30.2/config/assets/logo.svg) Appsemble Utilities
2
2
 
3
3
  > Internal utility functions used across multiple Appsemble projects.
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/@appsemble/utils)](https://www.npmjs.com/package/@appsemble/utils)
6
- [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.30.1/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.30.1)
6
+ [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.30.2/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.30.2)
7
7
  [![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://prettier.io)
8
8
 
9
9
  ## Table of Contents
@@ -26,5 +26,5 @@ not guaranteed.
26
26
 
27
27
  ## License
28
28
 
29
- [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.30.1/LICENSE.md) ©
29
+ [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.30.2/LICENSE.md) ©
30
30
  [Appsemble](https://appsemble.com)
@@ -83,6 +83,10 @@ instructed to contact the app owner to get permissions.
83
83
  theme: {
84
84
  $ref: '#/components/schemas/Theme',
85
85
  },
86
+ badgeCount: {
87
+ $ref: '#/components/schemas/RemapperDefinition',
88
+ description: 'A Remapper that resolves to a number to be visibile in the side-menu.',
89
+ },
86
90
  },
87
91
  };
88
92
  //# sourceMappingURL=BasePageDefinition.js.map
@@ -0,0 +1,2 @@
1
+ import { type OpenAPIV3 } from 'openapi-types';
2
+ export declare const PageActionsDefinition: OpenAPIV3.NonArraySchemaObject;
@@ -1,4 +1,4 @@
1
- export const TabsPageActionsDefinition = {
1
+ export const PageActionsDefinition = {
2
2
  type: 'object',
3
3
  description: 'Action fired on page events',
4
4
  additionalProperties: false,
@@ -9,4 +9,4 @@ export const TabsPageActionsDefinition = {
9
9
  },
10
10
  },
11
11
  };
12
- //# sourceMappingURL=TabsPageActionsDefinition.js.map
12
+ //# sourceMappingURL=PageActionsDefinition.js.map
@@ -18,6 +18,9 @@ the list.
18
18
  $ref: '#/components/schemas/BlockDefinition',
19
19
  },
20
20
  },
21
+ actions: {
22
+ $ref: '#/components/schemas/PageActionsDefinition',
23
+ },
21
24
  },
22
25
  });
23
26
  //# sourceMappingURL=PageDefinition.js.map
@@ -39,7 +39,7 @@ export const TabsPageDefinition = extendJSONSchema(BasePageDefinition, {
39
39
  },
40
40
  },
41
41
  actions: {
42
- $ref: '#/components/schemas/TabsPageActionsDefinition',
42
+ $ref: '#/components/schemas/PageActionsDefinition',
43
43
  },
44
44
  },
45
45
  });
@@ -136,8 +136,8 @@ export * from './AppMemberPropertiesPatchActionDefinition.js';
136
136
  export * from './AppMemberRoleUpdateActionDefinition.js';
137
137
  export * from './LoopPageDefinition.js';
138
138
  export * from './LoopPageActionsDefinition.js';
139
- export * from './TabsPageActionsDefinition.js';
140
139
  export * from './AppMembersDefinition.js';
141
140
  export * from './AppMemberPropertyDefinition.js';
142
141
  export * from './GroupMember.js';
143
142
  export * from './AppAccount.js';
143
+ export * from './PageActionsDefinition.js';
@@ -136,9 +136,9 @@ export * from './AppMemberPropertiesPatchActionDefinition.js';
136
136
  export * from './AppMemberRoleUpdateActionDefinition.js';
137
137
  export * from './LoopPageDefinition.js';
138
138
  export * from './LoopPageActionsDefinition.js';
139
- export * from './TabsPageActionsDefinition.js';
140
139
  export * from './AppMembersDefinition.js';
141
140
  export * from './AppMemberPropertyDefinition.js';
142
141
  export * from './GroupMember.js';
143
142
  export * from './AppAccount.js';
143
+ export * from './PageActionsDefinition.js';
144
144
  //# sourceMappingURL=index.js.map
package/authorization.js CHANGED
@@ -27,7 +27,7 @@ function checkAppPermissions(acquiredPermissions, requiredPermissions) {
27
27
  }
28
28
  export function getAppInheritedRoles(appSecurityDefinition, roles, accumulatedRoles = []) {
29
29
  var _a;
30
- if (!appSecurityDefinition) {
30
+ if (!appSecurityDefinition || !roles) {
31
31
  return [];
32
32
  }
33
33
  for (const role of roles) {
package/examples.js CHANGED
@@ -33,6 +33,11 @@ export const examples = {
33
33
  result: {},
34
34
  skip: true,
35
35
  },
36
+ type: {
37
+ input: [1, 2, 3],
38
+ remapper: { type: null },
39
+ result: 'array',
40
+ },
36
41
  array: {
37
42
  input: ['a', 'b', 'c'],
38
43
  remapper: {
@@ -112,6 +117,30 @@ export const examples = {
112
117
  },
113
118
  ],
114
119
  },
120
+ 'array.filter': {
121
+ input: [
122
+ {
123
+ name: 'Peter',
124
+ },
125
+ {
126
+ name: 'Louis',
127
+ },
128
+ {
129
+ name: 'Brian',
130
+ },
131
+ ],
132
+ remapper: {
133
+ 'array.filter': {
134
+ equals: [
135
+ {
136
+ prop: 'name',
137
+ },
138
+ 'Louis',
139
+ ],
140
+ },
141
+ },
142
+ result: [{ name: 'Louis' }],
143
+ },
115
144
  'array.find': {
116
145
  input: [
117
146
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appsemble/utils",
3
- "version": "0.30.1",
3
+ "version": "0.30.2",
4
4
  "description": "Utility functions used in Appsemble internally",
5
5
  "keywords": [
6
6
  "app",
@@ -37,7 +37,7 @@
37
37
  "test": "vitest"
38
38
  },
39
39
  "dependencies": {
40
- "@appsemble/types": "0.30.1",
40
+ "@appsemble/types": "0.30.2",
41
41
  "axios": "^1.0.0",
42
42
  "cron-parser": "^4.0.0",
43
43
  "date-fns": "^2.0.0",
@@ -100,6 +100,37 @@ remapper is a filtered list:
100
100
  "age": 20
101
101
  }
102
102
  ]
103
+ \`\`\`
104
+ `,
105
+ },
106
+ 'array.filter': {
107
+ $ref: '#/components/schemas/RemapperDefinition',
108
+ description: `
109
+ Filters out values based on the input conditions provided.
110
+
111
+ For example:
112
+
113
+ ${schemaExample('array.filter')}
114
+
115
+ Example of how it can be used to filter a number array.
116
+
117
+ Input:
118
+
119
+ \`\`\`json
120
+ [1,2,1,3,4,1,5]
121
+ \`\`\`
122
+
123
+ \`\`\`yaml
124
+ array.filter:
125
+ equals:
126
+ - array: item
127
+ - 1
128
+ \`\`\`
129
+
130
+ Result:
131
+
132
+ \`\`\`json
133
+ [1,1,1]
103
134
  \`\`\`
104
135
  `,
105
136
  },
@@ -145,6 +145,24 @@ object will be checked. The result looks like this:
145
145
  },
146
146
  ],
147
147
  },
148
+ type: {
149
+ enum: [null],
150
+ description: `Returns the type of the input object
151
+
152
+ For example, with the following input value:
153
+ \`\`\`json
154
+ [0, 5, 7, 8]
155
+ \`\`\`
156
+ \`\`\`yaml
157
+ type: null
158
+ \`\`\`
159
+
160
+ The result will be:
161
+ \`\`\`json
162
+ "array"
163
+ \`\`\`
164
+ `,
165
+ },
148
166
  log: {
149
167
  enum: ['info', 'warn', 'error'],
150
168
  description: `Logs in the browser's console and returns the incoming data and the remapper function's context.
package/remap.js CHANGED
@@ -194,6 +194,16 @@ const mapperImplementations = {
194
194
  }
195
195
  return result;
196
196
  },
197
+ type(args, input) {
198
+ // eslint-disable-next-line eqeqeq
199
+ if (input === null) {
200
+ return null;
201
+ }
202
+ if (Array.isArray(input)) {
203
+ return 'array';
204
+ }
205
+ return typeof input;
206
+ },
197
207
  'array.map': (mapper, input, context) => {
198
208
  var _a;
199
209
  return (_a = input === null || input === void 0 ? void 0 : input.map((item, index) => remap(mapper, item, {
@@ -221,6 +231,19 @@ const mapperImplementations = {
221
231
  });
222
232
  },
223
233
  array: (prop, input, context) => { var _a; return (_a = context.array) === null || _a === void 0 ? void 0 : _a[prop]; },
234
+ 'array.filter'(mapper, input, context) {
235
+ if (!Array.isArray(input)) {
236
+ console.error(`${input} is not an array!`);
237
+ return null;
238
+ }
239
+ return input === null || input === void 0 ? void 0 : input.filter((item, index) => {
240
+ const remapped = remap(mapper, item, {
241
+ ...context,
242
+ array: { index, length: input.length, item },
243
+ });
244
+ return remapped;
245
+ });
246
+ },
224
247
  'array.find'(mapper, input, context) {
225
248
  var _a;
226
249
  if (!Array.isArray(input)) {
package/remap.test.js CHANGED
@@ -723,6 +723,43 @@ describe('object.assign', () => {
723
723
  },
724
724
  });
725
725
  });
726
+ describe('type', () => {
727
+ runTests({
728
+ 'input array, type remapper test': {
729
+ input: [
730
+ { firstName: 'John', lastName: 'Doe' },
731
+ { firstName: 'Jane', lastName: 'Smith' },
732
+ ],
733
+ mappers: { type: null },
734
+ expected: 'array',
735
+ },
736
+ 'input object, type remapper test': {
737
+ input: { firstName: 'John', lastName: 'Doe' },
738
+ mappers: { type: null },
739
+ expected: 'object',
740
+ },
741
+ 'input number, type remapper test': {
742
+ input: 1,
743
+ mappers: { type: null },
744
+ expected: 'number',
745
+ },
746
+ 'input string, type remapper test': {
747
+ input: 'I am a string',
748
+ mappers: { type: null },
749
+ expected: 'string',
750
+ },
751
+ 'null input type remapper test': {
752
+ input: null,
753
+ mappers: { type: null },
754
+ expected: null,
755
+ },
756
+ 'undefined input type remapper test': {
757
+ input: undefined,
758
+ mappers: { type: null },
759
+ expected: 'undefined',
760
+ },
761
+ });
762
+ });
726
763
  describe('array.map', () => {
727
764
  runTests({
728
765
  'apply remappers to each array item': {
@@ -877,6 +914,40 @@ describe('array', () => {
877
914
  },
878
915
  });
879
916
  });
917
+ describe('array.filter', () => {
918
+ runTests({
919
+ 'return a new array containing the object with specified value from array': {
920
+ input: [{ name: 'Craig' }, { name: 'Joey' }, { name: 'Stuart' }],
921
+ mappers: [{ 'array.filter': { equals: [{ prop: 'name' }, 'Craig'] } }],
922
+ expected: [{ name: 'Craig' }],
923
+ },
924
+ 'return a new array containing the 2 objects with specified value from array': {
925
+ input: [{ name: 'Craig' }, { name: 'Joey' }, { name: 'Stuart' }, { name: 'Craig' }],
926
+ mappers: [{ 'array.filter': { equals: [{ prop: 'name' }, 'Craig'] } }],
927
+ expected: [{ name: 'Craig' }, { name: 'Craig' }],
928
+ },
929
+ 'return a new array containing a single value when the array does not include objects': {
930
+ input: ['Craig', 'Joey', 'Stuart'],
931
+ mappers: [{ 'array.filter': { equals: [{ array: 'item' }, 'Craig'] } }],
932
+ expected: ['Craig'],
933
+ },
934
+ 'return an empty array when condition doesn’t match anything': {
935
+ input: ['Craig', 'Joey', 'Stuart'],
936
+ mappers: [{ 'array.filter': { equals: [{ array: 'item' }, 'Peter'] } }],
937
+ expected: [],
938
+ },
939
+ 'it should filter arrays with mixed content type(string)': {
940
+ input: ['Craig', 5, 'Joey', 7, 'Stuart'],
941
+ mappers: [{ 'array.filter': { equals: [{ array: 'item' }, 'Stuart'] } }],
942
+ expected: ['Stuart'],
943
+ },
944
+ 'it should filter arrays with mixed content type based on type of the item': {
945
+ input: ['Craig', 5, 'Joey', 7, 'Stuart'],
946
+ mappers: [{ 'array.filter': { equals: [{ type: { array: 'item' } }, 'number'] } }],
947
+ expected: [5, 7],
948
+ },
949
+ });
950
+ });
880
951
  describe('array.find', () => {
881
952
  runTests({
882
953
  'return object with specified value from array': {
@@ -1,2 +0,0 @@
1
- import { type OpenAPIV3 } from 'openapi-types';
2
- export declare const TabsPageActionsDefinition: OpenAPIV3.NonArraySchemaObject;