@multiplatform.one/utils 0.1.21 → 5.0.0

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.
@@ -0,0 +1,84 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/wait.ts
2
+ var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);
3
+ var _pg = require('pg'); var _pg2 = _interopRequireDefault(_pg);
4
+ async function waitForApi(interval) {
5
+ try {
6
+ const res = await _axios2.default.get(
7
+ `http://localhost:${process.env.API_PORT || "5001"}/healthz`
8
+ );
9
+ if ((_optionalChain([res, 'optionalAccess', _ => _.status]) || 500) < 300) {
10
+ return;
11
+ }
12
+ } catch (err) {
13
+ }
14
+ await new Promise((resolve) => setTimeout(resolve, interval));
15
+ return waitForApi(interval);
16
+ }
17
+ async function waitForFrappe(interval) {
18
+ try {
19
+ const res = await _axios2.default.get(
20
+ `${process.env.FRAPPE_BASE_URL || "http://frappe.localhost"}/api/method/ping`
21
+ );
22
+ if ((_optionalChain([res, 'optionalAccess', _2 => _2.status]) || 500) < 300) {
23
+ return;
24
+ }
25
+ } catch (err) {
26
+ }
27
+ await new Promise((resolve) => setTimeout(resolve, interval));
28
+ return waitForFrappe(interval);
29
+ }
30
+ async function waitForPostgres(interval) {
31
+ const client = new _pg2.default.Client({
32
+ database: process.env.POSTGRES_DATABASE || "postgres",
33
+ host: process.env.POSTGRES_HOSTNAME || "localhost",
34
+ password: process.env.POSTGRES_PASSWORD || "postgres",
35
+ port: Number.parseInt(process.env.POSTGRES_PORT || "5432"),
36
+ user: process.env.POSTGRES_USERNAME || "postgres"
37
+ });
38
+ try {
39
+ await client.connect();
40
+ while (true) {
41
+ try {
42
+ await client.query("SELECT 1");
43
+ return;
44
+ } catch (error) {
45
+ }
46
+ await new Promise((resolve) => setTimeout(resolve, interval));
47
+ }
48
+ } finally {
49
+ await client.end();
50
+ }
51
+ }
52
+ async function waitForKeycloak(interval) {
53
+ try {
54
+ const res = await _axios2.default.get(
55
+ `${process.env.KEYCLOAK_BASE_URL || "http://localhost:8080"}/realms/master/.well-known/openid-configuration`
56
+ );
57
+ if ((_optionalChain([res, 'optionalAccess', _3 => _3.status]) || 500) < 300) {
58
+ return;
59
+ }
60
+ } catch (err) {
61
+ }
62
+ await new Promise((resolve) => setTimeout(resolve, interval));
63
+ return waitForKeycloak(interval);
64
+ }
65
+ function formatServiceList(services) {
66
+ if (services.length === 1) return services[0];
67
+ if (services.length === 2) return `${services[0]} and ${services[1]}`;
68
+ return `${services.slice(0, -1).join(", ")} and ${services[services.length - 1]}`;
69
+ }
70
+ var waitServices = [
71
+ "graphql",
72
+ "frappe",
73
+ "postgres",
74
+ "keycloak"
75
+ ];
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+ exports.waitForApi = waitForApi; exports.waitForFrappe = waitForFrappe; exports.waitForPostgres = waitForPostgres; exports.waitForKeycloak = waitForKeycloak; exports.formatServiceList = formatServiceList; exports.waitServices = waitServices;
package/lib/dev.cjs ADDED
@@ -0,0 +1,102 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
+
3
+
4
+
5
+
6
+
7
+
8
+ var _chunk55ZF3CTQcjs = require('./chunk-55ZF3CTQ.cjs');
9
+
10
+ // src/dev.ts
11
+ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
12
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
13
+ var logger = console;
14
+ function lookupTranspileModules(packageDirs, { log = true } = {}) {
15
+ const transpileModules = [
16
+ ...new Set(
17
+ [
18
+ .../* @__PURE__ */ new Set([
19
+ projectRoot,
20
+ _path2.default.resolve(projectRoot, "app"),
21
+ _path2.default.resolve(projectRoot, "packages", "ui"),
22
+ ...packageDirs || []
23
+ ])
24
+ ].map((packageDir) => {
25
+ try {
26
+ return JSON.parse(
27
+ _fs2.default.readFileSync(_path2.default.join(packageDir, "package.json"), "utf-8")
28
+ ).transpileModules || [];
29
+ } catch (err) {
30
+ if (log) logger.error(err);
31
+ return [];
32
+ }
33
+ })
34
+ )
35
+ ].flat();
36
+ if (log) logger.debug("transpileModules:", transpileModules.join(", "));
37
+ return transpileModules;
38
+ }
39
+ function lookupTamaguiModules(packageDirs, { log = true } = {}) {
40
+ const tamaguiModules = [
41
+ .../* @__PURE__ */ new Set([
42
+ "tamagui",
43
+ ...[
44
+ .../* @__PURE__ */ new Set([
45
+ projectRoot,
46
+ _path2.default.resolve(projectRoot, "app"),
47
+ _path2.default.resolve(projectRoot, "packages", "ui"),
48
+ ...packageDirs || []
49
+ ])
50
+ ].map((packageDir) => {
51
+ try {
52
+ return JSON.parse(
53
+ _fs2.default.readFileSync(_path2.default.join(packageDir, "package.json"), "utf-8")
54
+ ).tamaguiModules || [];
55
+ } catch (err) {
56
+ if (log) logger.error(err);
57
+ return [];
58
+ }
59
+ })
60
+ ])
61
+ ].flat();
62
+ if (log) logger.debug("tamaguiModules:", tamaguiModules.join(", "));
63
+ return tamaguiModules;
64
+ }
65
+ function resolveConfig(keys = []) {
66
+ return keys.reduce(
67
+ (acc, key) => {
68
+ if (process.env[key]) acc[key] = process.env[key];
69
+ return acc;
70
+ },
71
+ {}
72
+ );
73
+ }
74
+ var projectRoot = (() => {
75
+ const rootDir = _path2.default.parse(new URL(import.meta.url).pathname).root;
76
+ let projectRoot2 = _path2.default.dirname(new URL(import.meta.url).pathname);
77
+ while (projectRoot2 !== rootDir) {
78
+ const packageJsonPath = _path2.default.join(projectRoot2, "package.json");
79
+ const packageJsonExists = _fs2.default.existsSync(packageJsonPath) && _fs2.default.statSync(packageJsonPath).isFile();
80
+ if (packageJsonExists) {
81
+ const npmrcPath = _path2.default.join(projectRoot2, ".npmrc");
82
+ const nodeModulesPath = _path2.default.join(projectRoot2, "node_modules");
83
+ const npmrcExists = _fs2.default.existsSync(npmrcPath) && _fs2.default.statSync(npmrcPath).isFile();
84
+ const nodeModulesExists = _fs2.default.existsSync(nodeModulesPath) && _fs2.default.statSync(nodeModulesPath).isDirectory();
85
+ if (npmrcExists && nodeModulesExists) return projectRoot2;
86
+ }
87
+ projectRoot2 = _path2.default.dirname(projectRoot2);
88
+ }
89
+ return process.cwd();
90
+ })();
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+ exports.formatServiceList = _chunk55ZF3CTQcjs.formatServiceList; exports.lookupTamaguiModules = lookupTamaguiModules; exports.lookupTranspileModules = lookupTranspileModules; exports.projectRoot = projectRoot; exports.resolveConfig = resolveConfig; exports.waitForApi = _chunk55ZF3CTQcjs.waitForApi; exports.waitForFrappe = _chunk55ZF3CTQcjs.waitForFrappe; exports.waitForKeycloak = _chunk55ZF3CTQcjs.waitForKeycloak; exports.waitForPostgres = _chunk55ZF3CTQcjs.waitForPostgres; exports.waitServices = _chunk55ZF3CTQcjs.waitServices;
package/lib/index.cjs ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/index.ts
2
+ var index_default = {};
3
+
4
+
5
+ exports.default = index_default;
@@ -0,0 +1,98 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/meshConfig.ts
2
+ var meshConfig = {
3
+ sources: [
4
+ ...process.env.MESH_API === "1" ? [
5
+ {
6
+ name: "API",
7
+ handler: {
8
+ graphql: {
9
+ endpoint: `http://localhost:${process.env.API_PORT}/graphql`,
10
+ subscriptionsEndpoint: `ws://localhost:${process.env.API_PORT}/graphql`,
11
+ subscriptionsProtocol: "WS",
12
+ operationHeaders: {
13
+ Authorization: "{context.headers.Authorization}",
14
+ Cookie: "{context.headers.Cookie}"
15
+ }
16
+ }
17
+ },
18
+ transforms: [
19
+ {
20
+ prefix: {
21
+ mode: "wrap",
22
+ value: "API"
23
+ }
24
+ },
25
+ {
26
+ filterSchema: {
27
+ mode: "wrap",
28
+ filters: []
29
+ }
30
+ }
31
+ ]
32
+ }
33
+ ] : [],
34
+ ...process.env.MESH_FRAPPE === "1" ? [
35
+ {
36
+ name: "Frappe",
37
+ handler: {
38
+ graphql: {
39
+ endpoint: `${process.env.FRAPPE_BASE_URL}/api/method/graphql`,
40
+ subscriptionsEndpoint: `${process.env.FRAPPE_BASE_URL}/api/method/graphql`.replace(
41
+ /^https?/,
42
+ "ws"
43
+ ),
44
+ subscriptionsProtocol: "WS",
45
+ operationHeaders: {
46
+ Authorization: "{context.headers.Authorization}",
47
+ Cookie: "{context.headers.Cookie}"
48
+ }
49
+ }
50
+ },
51
+ transforms: [
52
+ {
53
+ prefix: {
54
+ mode: "wrap",
55
+ value: "Frappe"
56
+ }
57
+ },
58
+ {
59
+ filterSchema: {
60
+ mode: "wrap",
61
+ filters: ["Subscription.doc_events"]
62
+ }
63
+ }
64
+ ]
65
+ }
66
+ ] : []
67
+ ],
68
+ additionalEnvelopPlugins: "./envelopPlugins.js",
69
+ serve: {
70
+ browser: false
71
+ },
72
+ plugins: [
73
+ {
74
+ rateLimit: {
75
+ config: []
76
+ }
77
+ },
78
+ {
79
+ maxTokens: {
80
+ n: 1e3
81
+ }
82
+ },
83
+ {
84
+ maxDepth: {
85
+ n: 10
86
+ }
87
+ },
88
+ {
89
+ blockFieldSuggestions: {}
90
+ },
91
+ {
92
+ responseCache: {}
93
+ }
94
+ ]
95
+ };
96
+
97
+
98
+ exports.meshConfig = meshConfig;
package/lib/wait.cjs ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+ var _chunk55ZF3CTQcjs = require('./chunk-55ZF3CTQ.cjs');
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+ exports.formatServiceList = _chunk55ZF3CTQcjs.formatServiceList; exports.waitForApi = _chunk55ZF3CTQcjs.waitForApi; exports.waitForFrappe = _chunk55ZF3CTQcjs.waitForFrappe; exports.waitForKeycloak = _chunk55ZF3CTQcjs.waitForKeycloak; exports.waitForPostgres = _chunk55ZF3CTQcjs.waitForPostgres; exports.waitServices = _chunk55ZF3CTQcjs.waitServices;
package/package.json CHANGED
@@ -1,13 +1,10 @@
1
1
  {
2
2
  "name": "@multiplatform.one/utils",
3
- "version": "0.1.21",
3
+ "version": "5.0.0",
4
4
  "description": "utilities for multiplatform.one",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
- "keywords": [
8
- "multiplatform.one",
9
- "utils"
10
- ],
7
+ "keywords": ["multiplatform.one", "utils"],
11
8
  "homepage": "https://multiplatform.one",
12
9
  "bugs": {
13
10
  "url": "https://gitlab.com/bitspur/multiplatform.one/multiplatform.one/issues",
@@ -15,7 +12,7 @@
15
12
  },
16
13
  "license": "Apache-2.0",
17
14
  "author": "BitSpur <support@risserlabs.com> (https://risserlabs.com)",
18
- "main": "lib/index.js",
15
+ "main": "lib/index.cjs",
19
16
  "module": "lib/index.js",
20
17
  "source": "src/index.ts",
21
18
  "types": "types/index.d.ts",
@@ -24,12 +21,7 @@
24
21
  "build": "rm -rf lib types 2>/dev/null && tsc -b --emitDeclarationOnly && tsup",
25
22
  "test": "vitest run --coverage --coverage.provider=v8 --coverage.reporter=text --coverage.reporter=lcov --coverage.reporter=html"
26
23
  },
27
- "files": [
28
- "bin",
29
- "lib",
30
- "types",
31
- "src"
32
- ],
24
+ "files": ["bin", "lib", "types", "src"],
33
25
  "repository": {
34
26
  "type": "git",
35
27
  "url": "https://gitlab.com/bitspur/multiplatform.one/multiplatform.one"
@@ -52,15 +44,18 @@
52
44
  "exports": {
53
45
  ".": {
54
46
  "types": "./types/index.d.ts",
55
- "import": "./lib/index.js"
47
+ "import": "./lib/index.js",
48
+ "require": "./lib/index.cjs"
56
49
  },
57
50
  "./dev": {
58
51
  "types": "./types/dev.d.ts",
59
- "import": "./lib/dev.js"
52
+ "import": "./lib/dev.js",
53
+ "require": "./lib/dev.cjs"
60
54
  },
61
55
  "./meshConfig": {
62
56
  "types": "./types/meshConfig.d.ts",
63
- "import": "./lib/meshConfig.js"
57
+ "import": "./lib/meshConfig.js",
58
+ "require": "./lib/meshConfig.cjs"
64
59
  },
65
60
  "./package.json": "./package.json"
66
61
  }