@appsemble/utils 0.20.45 → 0.21.1

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 (52) hide show
  1. package/README.md +3 -3
  2. package/api/components/schemas/ObjectRemapperDefinition.js +6 -504
  3. package/api/components/schemas/RequestActionDefinition.js +1 -1
  4. package/api/components/schemas/ScimPatchOp.d.ts +2 -0
  5. package/api/components/schemas/ScimPatchOp.js +47 -0
  6. package/api/components/schemas/ScimSecret.d.ts +2 -0
  7. package/api/components/schemas/ScimSecret.js +16 -0
  8. package/api/components/schemas/ScimUser.d.ts +2 -0
  9. package/api/components/schemas/ScimUser.js +60 -0
  10. package/api/components/schemas/index.d.ts +3 -0
  11. package/api/components/schemas/index.js +3 -0
  12. package/api/components/securitySchemes/index.d.ts +1 -0
  13. package/api/components/securitySchemes/index.js +1 -0
  14. package/api/components/securitySchemes/scim.d.ts +2 -0
  15. package/api/components/securitySchemes/scim.js +6 -0
  16. package/api/index.test.js +1 -1
  17. package/api/paths/appScimEndpoints.d.ts +2 -0
  18. package/api/paths/appScimEndpoints.js +260 -0
  19. package/api/paths/appScimSecrets.d.ts +2 -0
  20. package/api/paths/appScimSecrets.js +45 -0
  21. package/api/paths/index.js +4 -0
  22. package/appMessages.test.js +1 -1
  23. package/convertToCsv.js +1 -1
  24. package/iterApp.test.js +44 -48
  25. package/jsonschema.test.js +8 -8
  26. package/normalize.js +2 -2
  27. package/package.json +4 -4
  28. package/pem.js +3 -3
  29. package/reference-schemas/remappers/arrays.d.ts +2 -0
  30. package/reference-schemas/remappers/arrays.js +334 -0
  31. package/reference-schemas/remappers/conditionals.d.ts +2 -0
  32. package/reference-schemas/remappers/conditionals.js +93 -0
  33. package/reference-schemas/remappers/data.d.ts +2 -0
  34. package/reference-schemas/remappers/data.js +321 -0
  35. package/reference-schemas/remappers/dates.d.ts +2 -0
  36. package/reference-schemas/remappers/dates.js +38 -0
  37. package/reference-schemas/remappers/history.d.ts +2 -0
  38. package/reference-schemas/remappers/history.js +246 -0
  39. package/reference-schemas/remappers/index.d.ts +9 -0
  40. package/reference-schemas/remappers/index.js +10 -0
  41. package/reference-schemas/remappers/objects.d.ts +2 -0
  42. package/reference-schemas/remappers/objects.js +157 -0
  43. package/reference-schemas/remappers/randoms.d.ts +2 -0
  44. package/reference-schemas/remappers/randoms.js +35 -0
  45. package/reference-schemas/remappers/strings.d.ts +2 -0
  46. package/reference-schemas/remappers/strings.js +81 -0
  47. package/reference-schemas/remappers/unsorted.d.ts +2 -0
  48. package/reference-schemas/remappers/unsorted.js +71 -0
  49. package/remap.js +1 -1
  50. package/remap.test.js +8 -9
  51. package/string.js +2 -2
  52. package/vitest.config.d.ts +2 -0
@@ -161,7 +161,7 @@ describe('combineSchemas', () => {
161
161
  });
162
162
  describe('iterJSONSchema', () => {
163
163
  it('should handle properties', () => {
164
- const onSchema = import.meta.jest.fn();
164
+ const onSchema = vi.fn();
165
165
  const schema = {
166
166
  type: 'object',
167
167
  properties: {
@@ -174,7 +174,7 @@ describe('iterJSONSchema', () => {
174
174
  expect(onSchema).toHaveBeenCalledWith(schema.properties.foo);
175
175
  });
176
176
  it('should handle additionalProperties', () => {
177
- const onSchema = import.meta.jest.fn();
177
+ const onSchema = vi.fn();
178
178
  const schema = {
179
179
  type: 'object',
180
180
  additionalProperties: { description: 'foo' },
@@ -185,7 +185,7 @@ describe('iterJSONSchema', () => {
185
185
  expect(onSchema).toHaveBeenCalledWith(schema.additionalProperties);
186
186
  });
187
187
  it('should handle an items object', () => {
188
- const onSchema = import.meta.jest.fn();
188
+ const onSchema = vi.fn();
189
189
  const schema = {
190
190
  type: 'array',
191
191
  items: { description: 'foo' },
@@ -196,7 +196,7 @@ describe('iterJSONSchema', () => {
196
196
  expect(onSchema).toHaveBeenCalledWith(schema.items);
197
197
  });
198
198
  it('should handle an items array', () => {
199
- const onSchema = import.meta.jest.fn();
199
+ const onSchema = vi.fn();
200
200
  const schema = {
201
201
  type: 'array',
202
202
  items: [{ description: 'foo' }, { description: 'bar' }],
@@ -208,7 +208,7 @@ describe('iterJSONSchema', () => {
208
208
  expect(onSchema).toHaveBeenCalledWith(schema.items[1]);
209
209
  });
210
210
  it('should handle additionalItems', () => {
211
- const onSchema = import.meta.jest.fn();
211
+ const onSchema = vi.fn();
212
212
  const schema = {
213
213
  type: 'array',
214
214
  additionalItems: { description: 'foo' },
@@ -219,7 +219,7 @@ describe('iterJSONSchema', () => {
219
219
  expect(onSchema).toHaveBeenCalledWith(schema.additionalItems);
220
220
  });
221
221
  it('should handle anyOf', () => {
222
- const onSchema = import.meta.jest.fn();
222
+ const onSchema = vi.fn();
223
223
  const schema = {
224
224
  type: 'array',
225
225
  anyOf: [{ description: 'foo' }],
@@ -230,7 +230,7 @@ describe('iterJSONSchema', () => {
230
230
  expect(onSchema).toHaveBeenCalledWith(schema.anyOf[0]);
231
231
  });
232
232
  it('should handle oneOf', () => {
233
- const onSchema = import.meta.jest.fn();
233
+ const onSchema = vi.fn();
234
234
  const schema = {
235
235
  type: 'array',
236
236
  oneOf: [{ description: 'foo' }],
@@ -241,7 +241,7 @@ describe('iterJSONSchema', () => {
241
241
  expect(onSchema).toHaveBeenCalledWith(schema.oneOf[0]);
242
242
  });
243
243
  it('should handle allOf', () => {
244
- const onSchema = import.meta.jest.fn();
244
+ const onSchema = vi.fn();
245
245
  const schema = {
246
246
  type: 'array',
247
247
  allOf: [{ description: 'foo' }],
package/normalize.js CHANGED
@@ -14,11 +14,11 @@ export function normalize(input, stripTrailingHyphen = true) {
14
14
  const normalized = input
15
15
  // Normalize accents. https://stackoverflow.com/a/37511463/1154610
16
16
  .normalize('NFD')
17
- .replace(/[\u0300-\u036F]/g, '')
17
+ .replaceAll(/[\u0300-\u036F]/g, '')
18
18
  // Make it lower case.
19
19
  .toLowerCase()
20
20
  // Replace any non-alphanumeric with single hyphens them at the start.
21
- .replace(/[^\da-z]+/g, (match, index) => (index ? '-' : ''));
21
+ .replaceAll(/[^\da-z]+/g, (match, index) => (index ? '-' : ''));
22
22
  return stripTrailingHyphen ? normalized.replace(/-$/, '') : normalized;
23
23
  }
24
24
  //# sourceMappingURL=normalize.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appsemble/utils",
3
- "version": "0.20.45",
3
+ "version": "0.21.1",
4
4
  "description": "Utility functions used in Appsemble internally",
5
5
  "keywords": [
6
6
  "app",
@@ -28,10 +28,10 @@
28
28
  ],
29
29
  "scripts": {
30
30
  "prepack": "tsc --noEmit false",
31
- "test": "NODE_OPTIONS=--experimental-vm-modules jest"
31
+ "test": "vitest"
32
32
  },
33
33
  "dependencies": {
34
- "@appsemble/types": "0.20.45",
34
+ "@appsemble/types": "0.21.1",
35
35
  "axios": "^1.0.0",
36
36
  "cron-parser": "^4.0.0",
37
37
  "date-fns": "^2.0.0",
@@ -45,7 +45,7 @@
45
45
  "openapi-types": "^12.0.0",
46
46
  "parse-duration": "^1.0.0",
47
47
  "postcss": "^8.0.0",
48
- "type-fest": "^3.0.0"
48
+ "type-fest": "^4.0.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/langmap": "^0.0.1",
package/pem.js CHANGED
@@ -1,8 +1,8 @@
1
1
  export function stripPem(pem, removeNewlines = false) {
2
2
  return pem
3
- .replace(/^[\s-]*BEGIN [A-Z]+[\s-]*/g, '')
4
- .replace(/[\s-]*END [A-Z]+[\s-]*$/g, '')
5
- .replace(/\r?\n/g, removeNewlines ? '' : '\n')
3
+ .replaceAll(/^[\s-]*BEGIN [A-Z]+[\s-]*/g, '')
4
+ .replaceAll(/[\s-]*END [A-Z]+[\s-]*$/g, '')
5
+ .replaceAll(/\r?\n/g, removeNewlines ? '' : '\n')
6
6
  .trim();
7
7
  }
8
8
  export function wrapPem(pem, type) {
@@ -0,0 +1,2 @@
1
+ import { type OpenAPIV3 } from 'openapi-types';
2
+ export declare const arrayRemappers: Record<string, OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject>;
@@ -0,0 +1,334 @@
1
+ export const arrayRemappers = {
2
+ 'array.map': {
3
+ $ref: '#/components/schemas/RemapperDefinition',
4
+ description: `
5
+ The remapper goes through the given array and applies the given remappers on each individual item.
6
+ This can be very handy when sorting arrays by certain data. The remapper always returns an array.
7
+ Output can be an empty array if the supplied data isn’t an array.
8
+
9
+ For example, if you want to sort through a list of people and only get their occupations you can do
10
+ the following:
11
+
12
+ Input:
13
+
14
+ \`\`\`json
15
+ [
16
+ {
17
+ "name": "Peter",
18
+ "occupation": "Delivery driver"
19
+ },
20
+ {
21
+ "name": "Otto",
22
+ "occupation": "Scientist"
23
+ },
24
+ {
25
+ "name": "Harry",
26
+ "occupation": "CEO"
27
+ }
28
+ ]
29
+ \`\`\`
30
+
31
+ \`\`\`yaml
32
+ array.map:
33
+ object.omit:
34
+ - name
35
+ \`\`\`
36
+
37
+ Result:
38
+
39
+ \`\`\`json
40
+ [{ "occupation": "Delivery driver" }, { "occupation": "Scientist" }, { "occupation": "CEO" }]
41
+ \`\`\`
42
+
43
+ Another great use for \`array.map\` is to combine it with the \`if\` remapper and sort your arrays on
44
+ specific values.
45
+
46
+ Using the same input data from the previous example, look at how you can change the code to get
47
+ people from a specific occupation:
48
+
49
+ \`\`\`yaml
50
+ - array.map:
51
+ if:
52
+ condition: { equals: [{ prop: occupation }, Scientist] }
53
+ then:
54
+ object.from:
55
+ name:
56
+ prop: name
57
+ occupation:
58
+ prop: occupation
59
+ else: null
60
+ - null.strip: null
61
+ \`\`\`
62
+
63
+ Result:
64
+
65
+ \`\`\`json
66
+ [
67
+ {
68
+ "name": "Otto",
69
+ "occupation": "Scientist"
70
+ }
71
+ ]
72
+ \`\`\`
73
+
74
+ Because \`array.map\` returns an array, every item has to return something. This is why we have to
75
+ return the full object with the data we want in the \`then\` section. It’s also why we return \`null\`.
76
+ This results in an array consisting of \`null\` values and objects with actual data in them. To solve
77
+ this problem, we use the \`null.strip\` remapper to remove any null values which results in a clean
78
+ array.
79
+ `,
80
+ },
81
+ 'array.unique': {
82
+ $ref: '#/components/schemas/RemapperDefinition',
83
+ description: `
84
+ Filters out unique values from an array. The value Remapper is applied to each entry in the array
85
+ using its result to determine uniqueness.
86
+
87
+ If the value Remapper results in undefined or null, the entire entry is used for uniqueness.
88
+
89
+ If the input is not an array, the input is returned without any modifications.
90
+
91
+ Input:
92
+
93
+ \`\`\`json
94
+ [1, 1, 2, 3]
95
+ \`\`\`
96
+
97
+ \`\`\`yaml
98
+ array.unique: null
99
+ \`\`\`
100
+
101
+ Result:
102
+
103
+ \`\`\`json
104
+ [1, 2, 3]
105
+ \`\`\`
106
+
107
+ You can also check for more complex values in arrays. The remapper accepts remappers as well, so you
108
+ can also use entire objects to check for unique values.
109
+
110
+ For this example, we have the following extended data with some duplicate values:
111
+
112
+ \`\`\`json
113
+ [
114
+ {
115
+ "name": "Peter",
116
+ "occupation": "Delivery driver",
117
+ "age": 19
118
+ },
119
+ {
120
+ "name": "Peter",
121
+ "occupation": "Photographer",
122
+ "age": 19
123
+ },
124
+ {
125
+ "name": "Otto",
126
+ "occupation": "Scientist",
127
+ "age": 50
128
+ },
129
+ {
130
+ "name": "Harry",
131
+ "occupation": "CEO",
132
+ "age": 20
133
+ }
134
+ ]
135
+ \`\`\`
136
+
137
+ We can be fairly sure in this list of people the first two Peters are the same person but with a
138
+ different occupation. To get more complex unique values from here, we can do the following:
139
+
140
+ \`\`\`yaml
141
+ array.unique:
142
+ object.from:
143
+ name: { prop: name }
144
+ age: { prop: age }
145
+ \`\`\`
146
+
147
+ This then checks the array for unique values in both the \`name\` and \`age\` fields. The result of this
148
+ remapper is a filtered list:
149
+
150
+ \`\`\`json
151
+ [
152
+ {
153
+ "name": "Peter",
154
+ "occupation": "Delivery driver",
155
+ "age": 19
156
+ },
157
+ {
158
+ "name": "Otto",
159
+ "occupation": "Scientist",
160
+ "age": 50
161
+ },
162
+ {
163
+ "name": "Harry",
164
+ "occupation": "CEO",
165
+ "age": 20
166
+ }
167
+ ]
168
+ \`\`\`
169
+ `,
170
+ },
171
+ 'array.from': {
172
+ type: 'array',
173
+ items: {
174
+ $ref: '#/components/schemas/RemapperDefinition',
175
+ },
176
+ description: `
177
+ Creates a new array based on a provided array of remappers. This array can also consist of static
178
+ values.
179
+
180
+ For example:
181
+
182
+ \`\`\`yaml
183
+ array.from:
184
+ - Peter
185
+ - Otto
186
+ - Harry
187
+ \`\`\`
188
+
189
+ \`\`\`json
190
+ ["Peter", "Otto", "Harry"]
191
+ \`\`\`
192
+
193
+ This remapper can also be used to convert given data into an array.
194
+
195
+ Input:
196
+
197
+ \`\`\`json
198
+ {
199
+ "name": "Peter",
200
+ "occupation": "Delivery driver"
201
+ }
202
+ \`\`\`
203
+
204
+ \`\`\`yaml
205
+ array.from:
206
+ - root: null # Takes the data passed to this remapper, explained more in the 'Data' page
207
+ \`\`\`
208
+
209
+ Result:
210
+
211
+ \`\`\`json
212
+ [
213
+ {
214
+ "name": "Peter",
215
+ "occupation": "Delivery driver"
216
+ }
217
+ ]
218
+ \`\`\`
219
+ `,
220
+ },
221
+ 'array.append': {
222
+ type: 'array',
223
+ items: {
224
+ $ref: '#/components/schemas/RemapperDefinition',
225
+ },
226
+ description: `
227
+ Append new values to the end of an array. If the input is not an array an empty array is returned.
228
+
229
+ Using the array from the previous example, we can add a new object on top of it using this remapper:
230
+
231
+ \`\`\`yaml
232
+ array.append:
233
+ - object.from:
234
+ name: James
235
+ occupation: News reporter
236
+ \`\`\`
237
+
238
+ Result:
239
+
240
+ \`\`\`json
241
+ [
242
+ {
243
+ "name": "Peter",
244
+ "occupation": "Delivery driver"
245
+ },
246
+ {
247
+ "name": "Otto",
248
+ "occupation": "Scientist"
249
+ },
250
+ {
251
+ "name": "Harry",
252
+ "occupation": "CEO"
253
+ },
254
+ {
255
+ "name": "James",
256
+ "occupation": "News reporter"
257
+ }
258
+ ]
259
+ \`\`\`
260
+ `,
261
+ },
262
+ 'array.omit': {
263
+ type: 'array',
264
+ items: {
265
+ $ref: '#/components/schemas/RemapperDefinition',
266
+ },
267
+ description: `
268
+ Remove values from an array. The input is expected to be the index(es) of the items to be deleted.
269
+ Accepts an array of static or remapper values.
270
+
271
+ With the previous example we added a new person to the list of people, so now we can remove that
272
+ person. We already know the index of this person in the array is \`3\`, so it’s easy:
273
+
274
+ \`\`\`yaml
275
+ array.omit:
276
+ - 3
277
+ \`\`\`
278
+
279
+ Result:
280
+
281
+ \`\`\`json
282
+ [
283
+ {
284
+ "name": "Peter",
285
+ "occupation": "Delivery driver"
286
+ },
287
+ {
288
+ "name": "Otto",
289
+ "occupation": "Scientist"
290
+ },
291
+ {
292
+ "name": "Harry",
293
+ "occupation": "CEO"
294
+ }
295
+ ]
296
+ \`\`\`
297
+
298
+ However, usually we don’t know the exact index of the item we want to delete. Because the remapper
299
+ accepts remappers as input we can get the desired item’s ID from another source as well. Take the
300
+ following example:
301
+
302
+ In this example we assume the data from the previous example is passed to this table block using a
303
+ data loader’s emitting event called “people”. When the user clicks on one of the people in the
304
+ table, it gets the list of people again. Using the index of this person, and the \`array.omit\`
305
+ remapper, the person gets removed from the list.
306
+
307
+ \`\`\`yaml
308
+ type: table
309
+ version: 0.20.38
310
+ events:
311
+ listen:
312
+ data: people
313
+ parameters:
314
+ fields:
315
+ - label: Name
316
+ value: { prop: name }
317
+ onClick: removePerson
318
+ - label: Occupation
319
+ value: { prop: occupation }
320
+ actions:
321
+ removePerson:
322
+ type: resource.query
323
+ resource: citizensNYC
324
+ remapAfter:
325
+ array.omit:
326
+ - context: index # This gets the index of the item in the table, explained more in the 'Data' page.
327
+ onSuccess:
328
+ type: resource.update
329
+ resource: citizensNYC
330
+ \`\`\`
331
+ `,
332
+ },
333
+ };
334
+ //# sourceMappingURL=arrays.js.map
@@ -0,0 +1,2 @@
1
+ import { type OpenAPIV3 } from 'openapi-types';
2
+ export declare const conditionalRemappers: Record<string, OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject>;
@@ -0,0 +1,93 @@
1
+ export const conditionalRemappers = {
2
+ if: {
3
+ type: 'object',
4
+ description: `Check if condition results in a truthy value.
5
+
6
+ Returns value of then if condition is truthy, otherwise it returns the value of else.
7
+ `,
8
+ additionalProperties: false,
9
+ required: ['condition', 'then', 'else'],
10
+ properties: {
11
+ condition: {
12
+ $ref: '#/components/schemas/RemapperDefinition',
13
+ description: 'The condition to check.',
14
+ },
15
+ then: {
16
+ $ref: '#/components/schemas/RemapperDefinition',
17
+ description: 'This remapper is used if the condition returns true.',
18
+ },
19
+ else: {
20
+ $ref: '#/components/schemas/RemapperDefinition',
21
+ description: 'This remapper is used if the condition returns false.',
22
+ },
23
+ },
24
+ },
25
+ equals: {
26
+ type: 'array',
27
+ items: {
28
+ $ref: '#/components/schemas/RemapperDefinition',
29
+ },
30
+ description: `Compare all computed remapper values against each other.
31
+
32
+ Returns \`true\` if all entries are equal, otherwise \`false\`.
33
+ `,
34
+ },
35
+ gt: {
36
+ type: 'array',
37
+ description: `Compare the first computed remapper value with the second computed remapper value.
38
+
39
+ Returns \`true\` if the first entry is greater than the second entry.`,
40
+ minItems: 2,
41
+ maxItems: 2,
42
+ items: {
43
+ $ref: '#/components/schemas/RemapperDefinition',
44
+ },
45
+ },
46
+ lt: {
47
+ type: 'array',
48
+ description: `Compare the first computed remapper value with the second computed remapper value.
49
+
50
+ Returns \`true\` if the first entry is lesser than the second entry.`,
51
+ minItems: 2,
52
+ maxItems: 2,
53
+ items: {
54
+ $ref: '#/components/schemas/RemapperDefinition',
55
+ },
56
+ },
57
+ not: {
58
+ type: 'array',
59
+ items: {
60
+ $ref: '#/components/schemas/RemapperDefinition',
61
+ },
62
+ description: `Compare all computed remapper values against the first.
63
+
64
+ Returns \`false\` if all entries are equal to the first entry, otherwise \`true\`.
65
+
66
+ If only one remapper or none is passed, the remapper value gets computed and then inverted.
67
+ `,
68
+ },
69
+ match: {
70
+ type: 'array',
71
+ description: `Check if any case results in a truthy value.
72
+
73
+ Returns the value of the first case where the condition equals true, otherwise returns null.
74
+ `,
75
+ items: {
76
+ type: 'object',
77
+ additionalProperties: false,
78
+ required: ['case', 'value'],
79
+ description: '',
80
+ properties: {
81
+ case: {
82
+ $ref: '#/components/schemas/RemapperDefinition',
83
+ description: 'The condition to check.',
84
+ },
85
+ value: {
86
+ $ref: '#/components/schemas/RemapperDefinition',
87
+ description: 'This remapper is used if the case is true',
88
+ },
89
+ },
90
+ },
91
+ },
92
+ };
93
+ //# sourceMappingURL=conditionals.js.map
@@ -0,0 +1,2 @@
1
+ import { type OpenAPIV3 } from 'openapi-types';
2
+ export declare const dataRemappers: Record<string, OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject>;