@datagrok-libraries/utils 0.0.4 → 0.0.8

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 (42) hide show
  1. package/package.json +7 -3
  2. package/src/bit-array.d.ts +82 -0
  3. package/src/bit-array.d.ts.map +1 -0
  4. package/src/bit-array.js +666 -0
  5. package/src/bit-array.ts +767 -0
  6. package/src/operations.d.ts +66 -0
  7. package/src/operations.d.ts.map +1 -0
  8. package/src/operations.js +144 -0
  9. package/src/operations.ts +160 -0
  10. package/src/reduce-dimensionality.d.ts +38 -0
  11. package/src/reduce-dimensionality.d.ts.map +1 -0
  12. package/src/reduce-dimensionality.js +233 -0
  13. package/src/reduce-dimensionality.ts +278 -0
  14. package/src/sequence-encoder.d.ts +59 -0
  15. package/src/sequence-encoder.d.ts.map +1 -0
  16. package/src/sequence-encoder.js +117 -0
  17. package/src/sequence-encoder.ts +132 -0
  18. package/src/spe.d.ts +68 -0
  19. package/src/spe.d.ts.map +1 -0
  20. package/src/spe.js +151 -0
  21. package/src/spe.ts +172 -0
  22. package/src/string-measure.d.ts +33 -0
  23. package/src/string-measure.d.ts.map +1 -0
  24. package/src/string-measure.js +46 -0
  25. package/src/string-measure.ts +54 -0
  26. package/src/string-utils.d.ts +2 -0
  27. package/src/string-utils.d.ts.map +1 -0
  28. package/src/string-utils.js +9 -0
  29. package/src/string-utils.ts +8 -0
  30. package/src/table-validation.d.ts +2 -0
  31. package/src/table-validation.d.ts.map +1 -0
  32. package/src/table-validation.js +47 -0
  33. package/src/table-validation.ts +67 -0
  34. package/src/test-utils.d.ts +11 -0
  35. package/src/test-utils.d.ts.map +1 -0
  36. package/src/test-utils.js +81 -0
  37. package/src/test-utils.ts +97 -0
  38. package/src/type_declarations.d.ts +56 -0
  39. package/src/type_declarations.d.ts.map +1 -0
  40. package/src/type_declarations.js +37 -0
  41. package/src/type_declarations.ts +54 -0
  42. package/tsconfig.json +2 -2
@@ -0,0 +1,97 @@
1
+ import * as path from "path";
2
+ import * as os from "os";
3
+ import * as fs from "fs";
4
+ // @ts-ignore
5
+ import * as yaml from 'js-yaml';
6
+ const fetch = require('node-fetch');
7
+
8
+ export async function getToken(url: string, key: string) {
9
+ let response = await fetch(`${url}/users/login/dev/${key}`, {method: 'POST'});
10
+ let json = await response.json();
11
+ if (json.isSuccess == true)
12
+ return json.token;
13
+ else
14
+ throw 'Unable to login to server. Check your dev key';
15
+ }
16
+
17
+ export async function getWebUrl(url: string, token: string) {
18
+ let response = await fetch(`${url}/admin/plugins/admin/settings`, {headers: {Authorization: token}});
19
+ let json = await response.json();
20
+ return json.settings.webRoot;
21
+ }
22
+
23
+ const grokDir = path.join(os.homedir(), '.grok');
24
+ const confPath = path.join(grokDir, 'config.yaml');
25
+
26
+ function mapURL(conf: Config): Indexable {
27
+ let urls: Indexable = {};
28
+ for (let server in conf.servers) {
29
+ urls[conf['servers'][server]['url']] = conf['servers'][server];
30
+ }
31
+ return urls;
32
+ }
33
+
34
+ export function getDevKey(hostKey: string): {url: string, key: string} {
35
+ let config = yaml.load(fs.readFileSync(confPath, 'utf8')) as any;
36
+ let host = hostKey == '' ? config.default : hostKey;
37
+ host = host.trim();
38
+ let urls = mapURL(config);
39
+ let key = '';
40
+ let url = '';
41
+ try {
42
+ let url = new URL(host).href;
43
+ if (url.endsWith('/')) url = url.slice(0, -1);
44
+ if (url in urls) key = config['servers'][urls[url]]['key'];
45
+ } catch (error) {
46
+ if (config['servers'][host] == null)
47
+ throw `Unknown server alias. Please add it to ${confPath}`;
48
+ url = config['servers'][host]['url'];
49
+ key = config['servers'][host]['key'];
50
+ }
51
+ return {url, key};
52
+ }
53
+
54
+ export async function getBrowserPage(puppeteer: any): Promise<{browser: any, page: any}> {
55
+ let url:string = process.env.HOST ?? '';
56
+ let cfg = getDevKey(url);
57
+ url = cfg.url;
58
+
59
+ let key = cfg.key;
60
+ let token = await getToken(url, key);
61
+ url = await getWebUrl(url, token);
62
+ console.log(`Using web root: ${url}`);
63
+
64
+ let browser = await puppeteer.launch({
65
+ args: ['--disable-dev-shm-usage', '--disable-features=site-per-process'],
66
+ ignoreHTTPSErrors: true,
67
+ });
68
+
69
+ let page = await browser.newPage();
70
+ await page.goto(`${url}/oauth/`);
71
+ await page.setCookie({name: 'auth', value: token});
72
+ await page.evaluate((token: any) => {
73
+ window.localStorage.setItem('auth', token);
74
+ }, token);
75
+ await page.goto(url);
76
+ try {
77
+ await page.waitForSelector('.grok-preloader');
78
+ console.log('got preloader');
79
+ await page.waitForFunction(() => document.querySelector('.grok-preloader') == null, {timeout: 100000});
80
+ } catch (error) {
81
+ throw error;
82
+ }
83
+ return {browser, page};
84
+ }
85
+
86
+
87
+ interface Config {
88
+ servers: {
89
+ [alias: string]: {
90
+ url: string,
91
+ key: string
92
+ }
93
+ },
94
+ default: string,
95
+ }
96
+
97
+ interface Indexable { [key: string]: any }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Denotes a vector of floating poit values.
3
+ *
4
+ * @export
5
+ * @class Vector
6
+ * @extends {Float32Array}
7
+ */
8
+ export declare class Vector extends Float32Array {
9
+ }
10
+ /**
11
+ * Denotes a two-dimensional matrix.
12
+ *
13
+ * @export
14
+ * @class Matrix
15
+ * @extends {Array<Vector>}
16
+ */
17
+ export declare class Matrix extends Array<Vector> {
18
+ }
19
+ /**
20
+ * Denotes cartesian coordinates.
21
+ *
22
+ * @export
23
+ * @class Coordinates
24
+ * @extends {Matrix}
25
+ */
26
+ export declare class Coordinates extends Matrix {
27
+ }
28
+ /**
29
+ * Denotes an array of arbitrary-typed vectors.
30
+ *
31
+ * @export
32
+ * @class Vectors
33
+ * @extends {Array<any>}
34
+ */
35
+ export declare class Vectors extends Array<any> {
36
+ }
37
+ /**
38
+ * Denotes a dictionary containing function options.
39
+ *
40
+ * @export
41
+ * @type Options
42
+ */
43
+ export declare type Options = {
44
+ [name: string]: any;
45
+ };
46
+ /**
47
+ * Denotes custom distance metric between the two given vectors.
48
+ *
49
+ * @export
50
+ * @type DistanceMetric
51
+ * @param {any} v1 The first vector.
52
+ * @param {any} v2 The second vector.
53
+ * @return {number} Distance between these two vectors.
54
+ */
55
+ export declare type DistanceMetric = (v1: any, v2: any) => (number);
56
+ //# sourceMappingURL=type_declarations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type_declarations.d.ts","sourceRoot":"","sources":["type_declarations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,MAAO,SAAQ,YAAY;CAAG;AAE3C;;;;;;GAMG;AACH,qBAAa,MAAO,SAAQ,KAAK,CAAC,MAAM,CAAC;CAAG;AAE5C;;;;;;GAMG;AACH,qBAAa,WAAY,SAAQ,MAAM;CAAG;AAE1C;;;;;;GAMG;AACH,qBAAa,OAAQ,SAAQ,KAAK,CAAC,GAAG,CAAC;CAAG;AAE1C;;;;;GAKG;AACH,oBAAY,OAAO,GAAG;IAAC,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,CAAC;AAE5C;;;;;;;;GAQG;AACF,oBAAY,cAAc,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Denotes a vector of floating poit values.
3
+ *
4
+ * @export
5
+ * @class Vector
6
+ * @extends {Float32Array}
7
+ */
8
+ export class Vector extends Float32Array {
9
+ }
10
+ /**
11
+ * Denotes a two-dimensional matrix.
12
+ *
13
+ * @export
14
+ * @class Matrix
15
+ * @extends {Array<Vector>}
16
+ */
17
+ export class Matrix extends Array {
18
+ }
19
+ /**
20
+ * Denotes cartesian coordinates.
21
+ *
22
+ * @export
23
+ * @class Coordinates
24
+ * @extends {Matrix}
25
+ */
26
+ export class Coordinates extends Matrix {
27
+ }
28
+ /**
29
+ * Denotes an array of arbitrary-typed vectors.
30
+ *
31
+ * @export
32
+ * @class Vectors
33
+ * @extends {Array<any>}
34
+ */
35
+ export class Vectors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a vector of floating poit values.
3
+ *
4
+ * @export
5
+ * @class Vector
6
+ * @extends {Float32Array}
7
+ */
8
+ export class Vector extends Float32Array {}
9
+
10
+ /**
11
+ * Denotes a two-dimensional matrix.
12
+ *
13
+ * @export
14
+ * @class Matrix
15
+ * @extends {Array<Vector>}
16
+ */
17
+ export class Matrix extends Array<Vector> {}
18
+
19
+ /**
20
+ * Denotes cartesian coordinates.
21
+ *
22
+ * @export
23
+ * @class Coordinates
24
+ * @extends {Matrix}
25
+ */
26
+ export class Coordinates extends Matrix {}
27
+
28
+ /**
29
+ * Denotes an array of arbitrary-typed vectors.
30
+ *
31
+ * @export
32
+ * @class Vectors
33
+ * @extends {Array<any>}
34
+ */
35
+ export class Vectors extends Array<any> {}
36
+
37
+ /**
38
+ * Denotes a dictionary containing function options.
39
+ *
40
+ * @export
41
+ * @type Options
42
+ */
43
+ export type Options = {[name: string]: any};
44
+
45
+ /**
46
+ * Denotes custom distance metric between the two given vectors.
47
+ *
48
+ * @export
49
+ * @type DistanceMetric
50
+ * @param {any} v1 The first vector.
51
+ * @param {any} v2 The second vector.
52
+ * @return {number} Distance between these two vectors.
53
+ */
54
+ export type DistanceMetric = (v1: any, v2: any) => (number);
package/tsconfig.json CHANGED
@@ -10,8 +10,8 @@
10
10
  // "allowJs": true, /* Allow javascript files to be compiled. */
11
11
  // "checkJs": true, /* Report errors in .js files. */
12
12
  // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
13
- // "declaration": true, /* Generates corresponding '.d.ts' file. */
14
- // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
13
+ "declaration": true, /* Generates corresponding '.d.ts' file. */
14
+ "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15
15
  // "sourceMap": true, /* Generates corresponding '.map' file. */
16
16
  // "outFile": "./", /* Concatenate and emit output to single file. */
17
17
  // "outDir": "./", /* Redirect output structure to the directory. */