@takeshape/util 11.45.5 → 11.47.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.
- package/dist/cjs/common/arrays.js +42 -0
- package/dist/cjs/common/assert.js +9 -0
- package/dist/cjs/common/async-noop.js +5 -0
- package/dist/cjs/common/billing.js +35 -0
- package/dist/cjs/common/clone.js +76 -0
- package/dist/cjs/common/delay.js +28 -0
- package/dist/cjs/common/draftjs-templates.js +131 -0
- package/dist/cjs/common/draftjs.js +807 -0
- package/dist/cjs/common/get-image-url.js +8 -0
- package/dist/cjs/common/highlight-code.js +33 -0
- package/dist/cjs/common/http.js +19 -0
- package/dist/cjs/common/index.js +50 -0
- package/dist/cjs/common/map.js +7 -0
- package/dist/cjs/common/memoize.js +13 -0
- package/dist/cjs/common/merge.js +64 -0
- package/dist/cjs/common/mime.js +68 -0
- package/dist/cjs/common/names.js +13 -0
- package/dist/cjs/common/naming.js +65 -0
- package/dist/cjs/common/path-to-string.js +10 -0
- package/dist/cjs/common/persisted-queries.js +4 -0
- package/dist/cjs/common/predicate.js +15 -0
- package/dist/cjs/common/set-in.js +13 -0
- package/dist/cjs/common/sets.js +19 -0
- package/dist/cjs/common/sleep.js +9 -0
- package/dist/cjs/common/sort-object.js +16 -0
- package/dist/cjs/common/strings.js +74 -0
- package/dist/cjs/common/templates.js +109 -0
- package/dist/cjs/common/timezone.js +606 -0
- package/dist/cjs/common/tracing.js +2 -0
- package/dist/cjs/common/types.js +63 -0
- package/dist/cjs/common/unix-to-iso.js +15 -0
- package/dist/cjs/common/urls.js +9 -0
- package/dist/cjs/common/validation.js +5 -0
- package/dist/cjs/common/value.js +8 -0
- package/dist/cjs/common/visit.js +60 -0
- package/dist/cjs/node/encryption.js +31 -0
- package/dist/cjs/node/gzip.js +10 -0
- package/dist/cjs/node/index.js +19 -0
- package/dist/cjs/node/search-params.js +23 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/common/arrays.js +33 -0
- package/dist/esm/common/assert.js +5 -0
- package/dist/esm/common/async-noop.js +2 -0
- package/dist/esm/common/billing.js +29 -0
- package/dist/esm/common/clone.js +71 -0
- package/dist/esm/common/delay.js +22 -0
- package/dist/esm/common/draftjs-templates.js +122 -0
- package/dist/esm/common/draftjs.js +792 -0
- package/{es → dist/esm/common}/get-image-url.js +2 -7
- package/dist/esm/common/highlight-code.js +26 -0
- package/dist/esm/common/http.js +15 -0
- package/dist/esm/common/index.js +34 -0
- package/{es → dist/esm/common}/map.js +2 -2
- package/dist/esm/common/memoize.js +6 -0
- package/dist/esm/common/merge.js +54 -0
- package/dist/esm/common/mime.js +60 -0
- package/dist/esm/common/names.js +9 -0
- package/dist/esm/common/naming.js +54 -0
- package/dist/esm/common/path-to-string.js +6 -0
- package/{es → dist/esm/common}/persisted-queries.js +1 -1
- package/{es → dist/esm/common}/predicate.js +4 -4
- package/dist/esm/common/set-in.js +7 -0
- package/dist/esm/common/sets.js +14 -0
- package/dist/esm/common/sleep.js +5 -0
- package/dist/esm/common/sort-object.js +12 -0
- package/dist/esm/common/strings.js +60 -0
- package/dist/esm/common/templates.js +95 -0
- package/dist/esm/common/timezone.js +602 -0
- package/dist/esm/common/tracing.js +1 -0
- package/dist/esm/common/types.js +50 -0
- package/dist/esm/common/unix-to-iso.js +9 -0
- package/dist/esm/common/urls.js +5 -0
- package/dist/esm/common/validation.js +2 -0
- package/dist/esm/common/value.js +4 -0
- package/dist/esm/common/visit.js +52 -0
- package/dist/esm/node/encryption.js +25 -0
- package/dist/esm/node/gzip.js +4 -0
- package/dist/esm/node/index.js +3 -0
- package/dist/esm/node/search-params.js +17 -0
- package/dist/esm/package.json +1 -0
- package/dist/tsconfig.types.tsbuildinfo +1 -0
- package/dist/{arrays.d.ts → types/common/arrays.d.ts} +0 -1
- package/dist/{assert.d.ts → types/common/assert.d.ts} +0 -1
- package/dist/{async-noop.d.ts → types/common/async-noop.d.ts} +0 -1
- package/dist/types/common/billing.d.ts +365 -0
- package/dist/{clone.d.ts → types/common/clone.d.ts} +0 -1
- package/dist/{delay.d.ts → types/common/delay.d.ts} +0 -1
- package/dist/{draftjs-templates.d.ts → types/common/draftjs-templates.d.ts} +1 -2
- package/dist/{draftjs.d.ts → types/common/draftjs.d.ts} +1 -2
- package/dist/{get-image-url.d.ts → types/common/get-image-url.d.ts} +0 -1
- package/dist/types/common/highlight-code.d.ts +14 -0
- package/dist/{http.d.ts → types/common/http.d.ts} +0 -1
- package/dist/types/common/index.d.ts +34 -0
- package/dist/{map.d.ts → types/common/map.d.ts} +0 -1
- package/dist/{memoize.d.ts → types/common/memoize.d.ts} +0 -1
- package/dist/{merge.d.ts → types/common/merge.d.ts} +0 -1
- package/dist/{mime.d.ts → types/common/mime.d.ts} +0 -1
- package/dist/{names.d.ts → types/common/names.d.ts} +0 -1
- package/dist/{naming.d.ts → types/common/naming.d.ts} +0 -1
- package/dist/{path-to-string.d.ts → types/common/path-to-string.d.ts} +0 -1
- package/dist/{persisted-queries.d.ts → types/common/persisted-queries.d.ts} +0 -1
- package/dist/{predicate.d.ts → types/common/predicate.d.ts} +0 -1
- package/dist/{set-in.d.ts → types/common/set-in.d.ts} +0 -1
- package/dist/{sets.d.ts → types/common/sets.d.ts} +0 -1
- package/dist/{sleep.d.ts → types/common/sleep.d.ts} +0 -1
- package/dist/{sort-object.d.ts → types/common/sort-object.d.ts} +0 -1
- package/dist/{strings.d.ts → types/common/strings.d.ts} +1 -2
- package/dist/{templates.d.ts → types/common/templates.d.ts} +1 -2
- package/dist/{timezone.d.ts → types/common/timezone.d.ts} +0 -1
- package/dist/{tracing.d.ts → types/common/tracing.d.ts} +1 -2
- package/dist/{types.d.ts → types/common/types.d.ts} +0 -1
- package/dist/{unix-to-iso.d.ts → types/common/unix-to-iso.d.ts} +0 -1
- package/dist/{urls.d.ts → types/common/urls.d.ts} +0 -1
- package/dist/{validation.d.ts → types/common/validation.d.ts} +0 -1
- package/dist/{value.d.ts → types/common/value.d.ts} +0 -1
- package/dist/{visit.d.ts → types/common/visit.d.ts} +0 -1
- package/dist/{encryption.d.ts → types/node/encryption.d.ts} +0 -1
- package/dist/{gzip.d.ts → types/node/gzip.d.ts} +1 -2
- package/dist/types/node/index.d.ts +3 -0
- package/dist/{search-params.d.ts → types/node/search-params.d.ts} +1 -2
- package/package.json +33 -21
- package/dist/arrays.d.ts.map +0 -1
- package/dist/arrays.js +0 -44
- package/dist/assert.d.ts.map +0 -1
- package/dist/assert.js +0 -11
- package/dist/async-noop.d.ts.map +0 -1
- package/dist/async-noop.js +0 -8
- package/dist/billing.d.ts +0 -366
- package/dist/billing.d.ts.map +0 -1
- package/dist/billing.js +0 -48
- package/dist/browser.d.ts +0 -2
- package/dist/browser.d.ts.map +0 -1
- package/dist/browser.js +0 -16
- package/dist/clone.d.ts.map +0 -1
- package/dist/clone.js +0 -101
- package/dist/common.d.ts +0 -32
- package/dist/common.d.ts.map +0 -1
- package/dist/common.js +0 -346
- package/dist/delay.d.ts.map +0 -1
- package/dist/delay.js +0 -34
- package/dist/draftjs-templates.d.ts.map +0 -1
- package/dist/draftjs-templates.js +0 -157
- package/dist/draftjs.d.ts.map +0 -1
- package/dist/draftjs.js +0 -836
- package/dist/encryption.d.ts.map +0 -1
- package/dist/encryption.js +0 -33
- package/dist/get-image-url.d.ts.map +0 -1
- package/dist/get-image-url.js +0 -15
- package/dist/gzip.d.ts.map +0 -1
- package/dist/gzip.js +0 -11
- package/dist/highlight-code.d.ts +0 -15
- package/dist/highlight-code.d.ts.map +0 -1
- package/dist/highlight-code.js +0 -35
- package/dist/http.d.ts.map +0 -1
- package/dist/http.js +0 -18
- package/dist/index.d.ts +0 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -60
- package/dist/map.d.ts.map +0 -1
- package/dist/map.js +0 -9
- package/dist/memoize.d.ts.map +0 -1
- package/dist/memoize.js +0 -13
- package/dist/merge.d.ts.map +0 -1
- package/dist/merge.js +0 -67
- package/dist/mime.d.ts.map +0 -1
- package/dist/mime.js +0 -37
- package/dist/names.d.ts.map +0 -1
- package/dist/names.js +0 -15
- package/dist/naming.d.ts.map +0 -1
- package/dist/naming.js +0 -91
- package/dist/path-to-string.d.ts.map +0 -1
- package/dist/path-to-string.js +0 -13
- package/dist/persisted-queries.d.ts.map +0 -1
- package/dist/persisted-queries.js +0 -7
- package/dist/predicate.d.ts.map +0 -1
- package/dist/predicate.js +0 -17
- package/dist/search-params.d.ts.map +0 -1
- package/dist/search-params.js +0 -25
- package/dist/set-in.d.ts.map +0 -1
- package/dist/set-in.js +0 -11
- package/dist/sets.d.ts.map +0 -1
- package/dist/sets.js +0 -21
- package/dist/sleep.d.ts.map +0 -1
- package/dist/sleep.js +0 -11
- package/dist/sort-object.d.ts.map +0 -1
- package/dist/sort-object.js +0 -21
- package/dist/strings.d.ts.map +0 -1
- package/dist/strings.js +0 -87
- package/dist/templates.d.ts.map +0 -1
- package/dist/templates.js +0 -120
- package/dist/timezone.d.ts.map +0 -1
- package/dist/timezone.js +0 -17
- package/dist/tracing.d.ts.map +0 -1
- package/dist/tracing.js +0 -5
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -92
- package/dist/unix-to-iso.d.ts.map +0 -1
- package/dist/unix-to-iso.js +0 -17
- package/dist/urls.d.ts.map +0 -1
- package/dist/urls.js +0 -11
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js +0 -8
- package/dist/value.d.ts.map +0 -1
- package/dist/value.js +0 -11
- package/dist/visit.d.ts.map +0 -1
- package/dist/visit.js +0 -61
- package/es/arrays.js +0 -33
- package/es/assert.js +0 -5
- package/es/async-noop.js +0 -2
- package/es/billing.js +0 -40
- package/es/browser.js +0 -1
- package/es/clone.js +0 -94
- package/es/common.js +0 -31
- package/es/delay.js +0 -26
- package/es/draftjs-templates.js +0 -147
- package/es/draftjs.js +0 -819
- package/es/encryption.js +0 -26
- package/es/gzip.js +0 -4
- package/es/highlight-code.js +0 -26
- package/es/http.js +0 -11
- package/es/index.js +0 -6
- package/es/memoize.js +0 -6
- package/es/merge.js +0 -58
- package/es/mime.js +0 -29
- package/es/names.js +0 -9
- package/es/naming.js +0 -78
- package/es/path-to-string.js +0 -6
- package/es/search-params.js +0 -17
- package/es/set-in.js +0 -6
- package/es/sets.js +0 -14
- package/es/sleep.js +0 -5
- package/es/sort-object.js +0 -14
- package/es/strings.js +0 -72
- package/es/templates.js +0 -105
- package/es/timezone.js +0 -10
- package/es/tracing.js +0 -1
- package/es/types.js +0 -80
- package/es/unix-to-iso.js +0 -9
- package/es/urls.js +0 -5
- package/es/validation.js +0 -2
- package/es/value.js +0 -4
- package/es/visit.js +0 -53
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { getImageUrl as imageUrl } from '@takeshape/routing';
|
|
2
2
|
export function getImageUrl(path, defaultImageConfig, imageBaseUrl, config) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
...config
|
|
6
|
-
}, {
|
|
7
|
-
baseUrl: imageBaseUrl
|
|
8
|
-
});
|
|
9
|
-
}
|
|
3
|
+
return imageUrl(path, { ...defaultImageConfig, ...config }, { baseUrl: imageBaseUrl });
|
|
4
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The intention is to move all this to the client package in the end, but right now it's here
|
|
3
|
+
* to be shared between the draftjs / mdx implementations, which span the client / server differently.
|
|
4
|
+
*/
|
|
5
|
+
import Prism from 'prismjs';
|
|
6
|
+
import 'prismjs/components/prism-javascript.js';
|
|
7
|
+
import 'prismjs/components/prism-markup.js';
|
|
8
|
+
import 'prismjs/components/prism-markup-templating.js';
|
|
9
|
+
import 'prismjs/components/prism-css.js';
|
|
10
|
+
import 'prismjs/components/prism-bash.js';
|
|
11
|
+
import 'prismjs/components/prism-django.js';
|
|
12
|
+
import 'prismjs/components/prism-twig.js';
|
|
13
|
+
import 'prismjs/components/prism-yaml.js';
|
|
14
|
+
import 'prismjs/components/prism-graphql.js';
|
|
15
|
+
import 'prismjs/components/prism-sass.js';
|
|
16
|
+
import 'prismjs/components/prism-scss.js';
|
|
17
|
+
import 'prismjs/components/prism-markdown.js';
|
|
18
|
+
import 'prismjs/components/prism-json.js';
|
|
19
|
+
import escape from 'lodash/escape.js';
|
|
20
|
+
export const highlightCode = (code, lang) => {
|
|
21
|
+
if (lang) {
|
|
22
|
+
const syntax = Prism.languages[lang];
|
|
23
|
+
return Prism.highlight(code, syntax, lang);
|
|
24
|
+
}
|
|
25
|
+
return escape(code);
|
|
26
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isBrowser } from 'browser-or-node';
|
|
2
|
+
export const getBasicAuthString = (basicAuth) => {
|
|
3
|
+
let authString = '';
|
|
4
|
+
if (basicAuth.username) {
|
|
5
|
+
authString += basicAuth.username;
|
|
6
|
+
}
|
|
7
|
+
authString += ':';
|
|
8
|
+
if (basicAuth.password) {
|
|
9
|
+
authString += basicAuth.password;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Not ideal, but this is used in service-providers which is imported into both the client and the api.
|
|
13
|
+
*/
|
|
14
|
+
return isBrowser ? window.btoa(authString) : Buffer.from(authString).toString('base64');
|
|
15
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export * from './arrays.js';
|
|
2
|
+
export * from './assert.js';
|
|
3
|
+
export * from './async-noop.js';
|
|
4
|
+
export * from './billing.js';
|
|
5
|
+
export * from './clone.js';
|
|
6
|
+
export * from './delay.js';
|
|
7
|
+
export * from './draftjs-templates.js';
|
|
8
|
+
export * from './draftjs.js';
|
|
9
|
+
export * from './get-image-url.js';
|
|
10
|
+
export * from './highlight-code.js';
|
|
11
|
+
export * from './http.js';
|
|
12
|
+
export * from './map.js';
|
|
13
|
+
export * from './memoize.js';
|
|
14
|
+
export * from './merge.js';
|
|
15
|
+
export * from './mime.js';
|
|
16
|
+
export * from './names.js';
|
|
17
|
+
export * from './naming.js';
|
|
18
|
+
export * from './path-to-string.js';
|
|
19
|
+
export * from './persisted-queries.js';
|
|
20
|
+
export * from './predicate.js';
|
|
21
|
+
export * from './set-in.js';
|
|
22
|
+
export * from './sets.js';
|
|
23
|
+
export * from './sleep.js';
|
|
24
|
+
export * from './sort-object.js';
|
|
25
|
+
export * from './strings.js';
|
|
26
|
+
export * from './templates.js';
|
|
27
|
+
export * from './timezone.js';
|
|
28
|
+
export * from './tracing.js';
|
|
29
|
+
export * from './types.js';
|
|
30
|
+
export * from './unix-to-iso.js';
|
|
31
|
+
export * from './urls.js';
|
|
32
|
+
export * from './validation.js';
|
|
33
|
+
export * from './value.js';
|
|
34
|
+
export * from './visit.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export function mapKeysToArray(map) {
|
|
2
|
-
|
|
3
|
-
}
|
|
2
|
+
return Array.from(map.keys());
|
|
3
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import difference from 'lodash/difference.js';
|
|
2
|
+
import isArray from 'lodash/isArray.js';
|
|
3
|
+
import isEqual from 'lodash/isEqual.js';
|
|
4
|
+
import isNull from 'lodash/isNull.js';
|
|
5
|
+
import merge from 'lodash/merge.js';
|
|
6
|
+
import mergeWith from 'lodash/mergeWith.js';
|
|
7
|
+
import omit from 'lodash/omit.js';
|
|
8
|
+
import union from 'lodash/union.js';
|
|
9
|
+
/**
|
|
10
|
+
* Lodash `mergeWith` customizer to concat arrays
|
|
11
|
+
*/
|
|
12
|
+
const arrayConcatCustomizer = (value, srcValue) => {
|
|
13
|
+
if (isArray(value)) {
|
|
14
|
+
return value.concat(srcValue);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Lodash `mergeWith` loaded with a customizer that concatenates arrays for a
|
|
19
|
+
* deeper merge.
|
|
20
|
+
*/
|
|
21
|
+
export function mergeWithArrayConcat(object, source) {
|
|
22
|
+
return mergeWith(object, source, arrayConcatCustomizer);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Lodash `mergeWith` customizer to merge arrays
|
|
26
|
+
*/
|
|
27
|
+
const arrayMergeCustomizer = (value, srcValue) => {
|
|
28
|
+
if (isArray(value) && isArray(srcValue)) {
|
|
29
|
+
return merge(value, srcValue).filter((val) => !isNull(val));
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Lodash `mergeWith` loaded with a customizer that merges arrays at the same
|
|
34
|
+
* object path. Array items set to `null` will be removed.
|
|
35
|
+
*/
|
|
36
|
+
export function mergeWithArrayMerge(object, source) {
|
|
37
|
+
return mergeWith(object, source, arrayMergeCustomizer);
|
|
38
|
+
}
|
|
39
|
+
export function rebaseObject(to, base, from) {
|
|
40
|
+
const fromKeys = Object.keys(from);
|
|
41
|
+
const removedKeys = difference(Object.keys(base), fromKeys);
|
|
42
|
+
const newObj = omit(to, removedKeys);
|
|
43
|
+
for (const key of fromKeys) {
|
|
44
|
+
if (!isEqual(base[key], from[key])) {
|
|
45
|
+
newObj[key] = from[key];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return newObj;
|
|
49
|
+
}
|
|
50
|
+
export function rebaseArray(to, base, from) {
|
|
51
|
+
const removed = difference(base, from);
|
|
52
|
+
const added = difference(from, base);
|
|
53
|
+
return union(difference(to, removed), added);
|
|
54
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import mime from 'mime-types';
|
|
2
|
+
const compressedMimeTypes = new Set([
|
|
3
|
+
'application/atom+xml',
|
|
4
|
+
'application/javascript',
|
|
5
|
+
'application/json',
|
|
6
|
+
'application/ld+json',
|
|
7
|
+
'application/manifest+json',
|
|
8
|
+
'application/rdf+xml',
|
|
9
|
+
'application/rss+xml',
|
|
10
|
+
'application/schema+json',
|
|
11
|
+
'application/vnd.geo+json',
|
|
12
|
+
'application/vnd.ms-fontobject',
|
|
13
|
+
'application/x-font-ttf',
|
|
14
|
+
'application/x-javascript',
|
|
15
|
+
'application/x-web-app-manifest+json',
|
|
16
|
+
'application/xhtml+xml',
|
|
17
|
+
'application/xml',
|
|
18
|
+
'font/eot',
|
|
19
|
+
'font/otf',
|
|
20
|
+
'font/opentype',
|
|
21
|
+
'image/bmp',
|
|
22
|
+
'image/svg+xml',
|
|
23
|
+
'image/vnd.microsoft.icon',
|
|
24
|
+
'image/x-icon',
|
|
25
|
+
'text/cache-manifest',
|
|
26
|
+
'text/css',
|
|
27
|
+
'text/html',
|
|
28
|
+
'text/javascript',
|
|
29
|
+
'text/plain',
|
|
30
|
+
'text/vcard',
|
|
31
|
+
'text/vnd.rim.location.xloc',
|
|
32
|
+
'text/vtt',
|
|
33
|
+
'text/x-component',
|
|
34
|
+
'text/x-cross-domain-policy',
|
|
35
|
+
'text/xml'
|
|
36
|
+
]);
|
|
37
|
+
// Application/octetstream
|
|
38
|
+
const DEFAULT_TYPE = mime.lookup('bin');
|
|
39
|
+
/**
|
|
40
|
+
* Gets the content type of the file, based on it's extension.
|
|
41
|
+
* @param {String} src Path to file fow which content type should be evaluated.
|
|
42
|
+
* @return {String} Returns string with content type and charset.
|
|
43
|
+
*/
|
|
44
|
+
export function contentType(src) {
|
|
45
|
+
let type = (mime.lookup(src) || DEFAULT_TYPE).replace('-', '');
|
|
46
|
+
const charset = mime.charset(type);
|
|
47
|
+
if (charset) {
|
|
48
|
+
type += `; charset=${charset}`;
|
|
49
|
+
}
|
|
50
|
+
return type;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Determines whether we should compress based on file extension
|
|
54
|
+
* @param {String} src Path to file fow which content type should be evaluated.
|
|
55
|
+
* @return {Boolean} Returns true if we should compress
|
|
56
|
+
*/
|
|
57
|
+
export function shouldCompress(src) {
|
|
58
|
+
const mimeType = mime.lookup(src);
|
|
59
|
+
return Boolean(mimeType && compressedMimeTypes.has(mimeType));
|
|
60
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import camelCase from 'lodash/camelCase.js';
|
|
2
|
+
import kebabCase from 'lodash/kebabCase.js';
|
|
3
|
+
export function prefixName(config, params, name) {
|
|
4
|
+
const { withVariant, withRegion, separator } = config;
|
|
5
|
+
const { appName, stage: { env, variant }, region } = params;
|
|
6
|
+
const parts = [appName, env];
|
|
7
|
+
if (withVariant && env !== 'prod' && variant) {
|
|
8
|
+
parts.push(variant);
|
|
9
|
+
}
|
|
10
|
+
if (withRegion) {
|
|
11
|
+
if (!region) {
|
|
12
|
+
throw new Error('Cannot provide a region prefix without a region in context');
|
|
13
|
+
}
|
|
14
|
+
parts.push(region);
|
|
15
|
+
}
|
|
16
|
+
if (name === '*') {
|
|
17
|
+
parts.push(name);
|
|
18
|
+
}
|
|
19
|
+
else if (config.case === 'kebabCase') {
|
|
20
|
+
parts.push(kebabCase(name));
|
|
21
|
+
}
|
|
22
|
+
else if (config.case === 'camelCase') {
|
|
23
|
+
parts.push(camelCase(name));
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
parts.push(name);
|
|
27
|
+
}
|
|
28
|
+
return parts.join(separator);
|
|
29
|
+
}
|
|
30
|
+
export function dynamoTableName(params, name) {
|
|
31
|
+
return prefixName({ withVariant: true, withRegion: false, separator: '--' }, params, name);
|
|
32
|
+
}
|
|
33
|
+
export const variantResourceName = prefixName.bind(null, {
|
|
34
|
+
withVariant: true,
|
|
35
|
+
withRegion: false,
|
|
36
|
+
separator: '--',
|
|
37
|
+
case: 'kebabCase'
|
|
38
|
+
});
|
|
39
|
+
export const sharedResourceName = prefixName.bind(null, {
|
|
40
|
+
withVariant: false,
|
|
41
|
+
withRegion: false,
|
|
42
|
+
separator: '--',
|
|
43
|
+
case: 'kebabCase'
|
|
44
|
+
});
|
|
45
|
+
export function variantBucketName(params, name) {
|
|
46
|
+
return prefixName({ withVariant: true, withRegion: true, separator: '--' }, params, name);
|
|
47
|
+
}
|
|
48
|
+
export function sharedBucketName(params, name) {
|
|
49
|
+
return prefixName({ withVariant: false, withRegion: true, separator: '--' }, params, name);
|
|
50
|
+
}
|
|
51
|
+
export const sharedTopicName = sharedResourceName;
|
|
52
|
+
export function keyName(params, name) {
|
|
53
|
+
return prefixName({ withVariant: true, withRegion: false, separator: '--' }, params, name);
|
|
54
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const PERSISTED_QUERY_NOT_FOUND_CODE = 'PERSISTED_QUERY_NOT_FOUND';
|
|
1
|
+
export const PERSISTED_QUERY_NOT_FOUND_CODE = 'PERSISTED_QUERY_NOT_FOUND';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export function not(predicate) {
|
|
2
|
-
|
|
2
|
+
return (value) => !predicate(value);
|
|
3
3
|
}
|
|
4
4
|
export function equals(a) {
|
|
5
|
-
|
|
5
|
+
return (b) => a === b;
|
|
6
6
|
}
|
|
7
7
|
export function falsy(obj) {
|
|
8
|
-
|
|
9
|
-
}
|
|
8
|
+
return !obj;
|
|
9
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import clone from 'lodash/fp/clone.js';
|
|
2
|
+
import curry from 'lodash/fp/curry.js';
|
|
3
|
+
import setWith from 'lodash/fp/setWith.js';
|
|
4
|
+
/**
|
|
5
|
+
* Same as lodash/set but does not mutate the arguments
|
|
6
|
+
*/
|
|
7
|
+
export const setIn = curry((obj, path, value) => setWith(clone, path, value, clone(obj)));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function addAll(set, iterable) {
|
|
2
|
+
for (const value of iterable) {
|
|
3
|
+
set.add(value);
|
|
4
|
+
}
|
|
5
|
+
return set;
|
|
6
|
+
}
|
|
7
|
+
export function mapSet(set, fn) {
|
|
8
|
+
const result = new Array(set.size);
|
|
9
|
+
let i = 0;
|
|
10
|
+
for (const value of set) {
|
|
11
|
+
result[i++] = fn(value);
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object key order is not guarenteed. This can be useful
|
|
3
|
+
* but should not be depended upon.
|
|
4
|
+
*/
|
|
5
|
+
export const sortObject = (obj) => {
|
|
6
|
+
// Convert object to array of key-value pairs
|
|
7
|
+
const arr = Object.entries(obj);
|
|
8
|
+
// Sort array by key
|
|
9
|
+
arr.sort(([key1], [key2]) => key1.localeCompare(key2));
|
|
10
|
+
// Convert array back to object
|
|
11
|
+
return Object.fromEntries(arr);
|
|
12
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isBrowser } from 'browser-or-node';
|
|
2
|
+
import _camelCase from 'lodash/camelCase.js';
|
|
3
|
+
import isEmpty from 'lodash/isEmpty.js';
|
|
4
|
+
import isString from 'lodash/isString.js';
|
|
5
|
+
import upperFirst from 'lodash/upperFirst.js';
|
|
6
|
+
import { ensureArray } from './arrays.js';
|
|
7
|
+
export const camelCase = _camelCase;
|
|
8
|
+
export function formatShapeName(str, options) {
|
|
9
|
+
const strings = ensureArray(str);
|
|
10
|
+
const shapeNameIndex = options?.shapeNameIndex ?? 0;
|
|
11
|
+
const shapeName = strings.at(shapeNameIndex);
|
|
12
|
+
// If the shapeNameIndex is incorrect, behave as normal
|
|
13
|
+
if (!shapeName) {
|
|
14
|
+
throw new Error(`Could not find a ShapeName at index '${shapeNameIndex}'`);
|
|
15
|
+
}
|
|
16
|
+
const prefix = strings.slice(0, Math.max(shapeNameIndex, 0));
|
|
17
|
+
const suffix = strings.slice(shapeNameIndex + 1);
|
|
18
|
+
let arr = [];
|
|
19
|
+
if (prefix) {
|
|
20
|
+
arr = [...arr, pascalCase(prefix)];
|
|
21
|
+
}
|
|
22
|
+
if (shapeName.length > 2 && shapeName.startsWith('TS') && shapeName.charAt(2) === shapeName.charAt(2).toUpperCase()) {
|
|
23
|
+
// Built-in shape, prefixed with `TS`
|
|
24
|
+
arr = [...arr, shapeName];
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
arr = [...arr, pascalCase(shapeName)];
|
|
28
|
+
}
|
|
29
|
+
if (suffix) {
|
|
30
|
+
arr = [...arr, pascalCase(suffix)];
|
|
31
|
+
}
|
|
32
|
+
return arr.join('');
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Optional config triggers a namespace-preserving behavior for built-in shapes starting with `TS`.
|
|
36
|
+
*/
|
|
37
|
+
export function pascalCase(str) {
|
|
38
|
+
return upperFirst(camelCase(str));
|
|
39
|
+
}
|
|
40
|
+
export function isUuid(str) {
|
|
41
|
+
return Boolean(/\w{8,}(-\w{4,}){3,}-\w{12,}/.exec(str));
|
|
42
|
+
}
|
|
43
|
+
export function isEmptyString(str) {
|
|
44
|
+
return isString(str) && isEmpty(str);
|
|
45
|
+
}
|
|
46
|
+
export function isIntegerLike(value) {
|
|
47
|
+
if (typeof value === 'number') {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return /^\d+$/.test(value);
|
|
51
|
+
}
|
|
52
|
+
export function encodePropertyName(value) {
|
|
53
|
+
return value.replace(/[^A-Za-z0-9]/g, (c) => `%${c.charCodeAt(0).toString(16)}`);
|
|
54
|
+
}
|
|
55
|
+
export function base64Encode(str) {
|
|
56
|
+
return isBrowser ? window.btoa(str) : Buffer.from(str).toString('base64');
|
|
57
|
+
}
|
|
58
|
+
export function base64Decode(str) {
|
|
59
|
+
return isBrowser ? window.atob(str) : Buffer.from(str, 'base64').toString();
|
|
60
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { getImageUrl } from '@takeshape/routing';
|
|
2
|
+
/*
|
|
3
|
+
* The intention is to move all this to the client package in the end, but right now it's here
|
|
4
|
+
* to be shared between the draftjs / mdx implementations, which span the client / server differently.
|
|
5
|
+
*/
|
|
6
|
+
import classnames from 'classnames';
|
|
7
|
+
import escape from 'lodash/escape.js';
|
|
8
|
+
import { highlightCode } from './highlight-code.js';
|
|
9
|
+
import { isRecord } from './types.js';
|
|
10
|
+
export function getApplyPrefix(prefix) {
|
|
11
|
+
return (className) => (className ? prefix + className : '');
|
|
12
|
+
}
|
|
13
|
+
export function attrs(obj) {
|
|
14
|
+
const attrStrings = [];
|
|
15
|
+
const attrNames = Object.keys(obj);
|
|
16
|
+
attrNames.sort();
|
|
17
|
+
for (const attrName of attrNames) {
|
|
18
|
+
const value = obj[attrName];
|
|
19
|
+
if (value) {
|
|
20
|
+
attrStrings.push(`${attrName}="${escape(value)}"`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return attrStrings.length ? ` ${attrStrings.join(' ')}` : '';
|
|
24
|
+
}
|
|
25
|
+
export function imageTemplate(applyPrefix, data) {
|
|
26
|
+
const { caption, credit, alignment, size, asset, imageParams } = data;
|
|
27
|
+
if (!asset) {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
const imageUrl = getImageUrl(asset.path, imageParams);
|
|
31
|
+
let figCaption = '';
|
|
32
|
+
if (caption || credit) {
|
|
33
|
+
const htmlCaption = caption ? `<span class="${applyPrefix('caption')}">${caption}</span>` : '';
|
|
34
|
+
const htmlCredit = credit ? `<span class="${applyPrefix('credit')}">${credit}</span>` : '';
|
|
35
|
+
figCaption = `<figcaption>${htmlCaption} ${htmlCredit}</figcaption>`;
|
|
36
|
+
}
|
|
37
|
+
const classes = classnames(applyPrefix(alignment), applyPrefix(size));
|
|
38
|
+
const classAttr = classes ? ` class="${classes}"` : '';
|
|
39
|
+
const imgAttrs = attrs({
|
|
40
|
+
alt: asset.description,
|
|
41
|
+
title: asset.title
|
|
42
|
+
});
|
|
43
|
+
let image = `<img${imgAttrs} src="${imageUrl}"/>`;
|
|
44
|
+
if (data.link?.url) {
|
|
45
|
+
const target = data.link.external ? ' target="blank" rel="noopener noreferrer"' : '';
|
|
46
|
+
image = `<a href="${data.link.url}"${target}>${image}</a>`;
|
|
47
|
+
}
|
|
48
|
+
return `<figure${classAttr}>${image}${figCaption}</figure>`;
|
|
49
|
+
}
|
|
50
|
+
function renderMdx(tag, attributes, data, children) {
|
|
51
|
+
const tagWithAttributes = `${tag} ${attributes.map((attr) => `${attr}="${escape(data[attr])}"`).join(' ')}`;
|
|
52
|
+
if (children) {
|
|
53
|
+
return `<${tagWithAttributes}>
|
|
54
|
+
${children.replace(/[\n\r]+$/, '')}
|
|
55
|
+
</${tag}>`;
|
|
56
|
+
}
|
|
57
|
+
return `<${tagWithAttributes}/>`;
|
|
58
|
+
}
|
|
59
|
+
export function imageTemplateMdx(applyPrefix, data) {
|
|
60
|
+
return renderMdx(applyPrefix('Image'), ['id', 'caption', 'credit', 'link', 'linkisexternal', 'alignment', 'size', 'src'], data);
|
|
61
|
+
}
|
|
62
|
+
export function oembedTemplate(applyPrefix, data) {
|
|
63
|
+
return `<div class="${applyPrefix('oembed')}">${data.html}</div>`;
|
|
64
|
+
}
|
|
65
|
+
export function oembedTemplateMdx(applyPrefix, data) {
|
|
66
|
+
return renderMdx(applyPrefix('Oembed'), ['url', 'author_name', 'author_url', 'width', 'height', 'type', 'cache_age', 'provider_name', 'version'], data, data.html);
|
|
67
|
+
}
|
|
68
|
+
export function codeTemplate(applyPrefix, data) {
|
|
69
|
+
const { text, lang } = data;
|
|
70
|
+
const code = highlightCode(text, lang);
|
|
71
|
+
const langClass = lang ? ` class="${applyPrefix(`language-${lang}`)}"` : '';
|
|
72
|
+
return `<pre><code${langClass}>${code}</code></pre>`;
|
|
73
|
+
}
|
|
74
|
+
export function jsonTemplate(template, context) {
|
|
75
|
+
const renderTemplate = (template) => {
|
|
76
|
+
return template.replace(/{{(\w+)}}/g, (_, name) => context[name] ?? '');
|
|
77
|
+
};
|
|
78
|
+
const transform = (obj) => {
|
|
79
|
+
if (Array.isArray(obj)) {
|
|
80
|
+
return obj.map(transform);
|
|
81
|
+
}
|
|
82
|
+
if (isRecord(obj)) {
|
|
83
|
+
const result = {};
|
|
84
|
+
for (const key of Object.keys(obj)) {
|
|
85
|
+
result[renderTemplate(key)] = transform(obj[key]);
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
if (typeof obj === 'string') {
|
|
90
|
+
return renderTemplate(obj);
|
|
91
|
+
}
|
|
92
|
+
return obj;
|
|
93
|
+
};
|
|
94
|
+
return transform(template);
|
|
95
|
+
}
|