esm ports

This commit is contained in:
Code 2025-01-23 07:22:43 +01:00
parent 4ed5ec432a
commit 3081cff065
352 changed files with 27615 additions and 22 deletions

7
packages/commons/dist/_glob.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
import { GlobOptions } from 'glob';
export declare const files: (cwd: any, glob: any, options?: any) => [];
export declare const filesEx: (cwd: any, glob: any, options?: GlobOptions) => [];
import { PATH_INFO } from '@/types_common.js';
export declare const forward_slash: (path: any) => any;
export declare const pathInfoEx: (src: string, altToken?: boolean, globOptions?: GlobOptions) => PATH_INFO;
export declare const pathInfo: (src: string, altToken?: boolean, cwd?: string) => PATH_INFO;

93
packages/commons/dist/_glob.js vendored Normal file
View File

@ -0,0 +1,93 @@
import * as path from 'path';
// import * as isGlob from 'is-glob'
// import * as fg from 'fast-glob'
import { glob, globSync, hasMagic } from 'glob';
import { REGEX_VAR, REGEX_VAR_ALT } from "@polymech/core/constants.js";
import { sync as exists } from '@polymech/fs/exists';
export const files = (cwd, glob, options) => globSync(glob, { ...{ dot: true, cwd, absolute: true, caseSensitiveMatch: false }, ...options || {} });
export const filesEx = (cwd, glob, options) => globSync(glob, { ...{ dot: true, cwd, absolute: true, caseSensitiveMatch: false }, ...options || {} });
import { substitute } from '@/variables.js';
import { isFile, isFolder, getExtensions } from '@/fs.js';
const globBase = require('glob-base');
export const forward_slash = (path) => {
const isExtendedLengthPath = /^\\\\\?\\/.test(path);
const hasNonAscii = /[^\u0000-\u0080]+/.test(path);
if (isExtendedLengthPath || hasNonAscii) {
return path;
}
return path.replace(/\\/g, '/');
};
export const pathInfoEx = (src, altToken = false, globOptions = {}) => {
const srcParts = path.parse(src);
let variables = {
PATH: src
};
variables.DIR = srcParts.dir;
variables.NAME = srcParts.name;
variables.FILE_NAME = srcParts.base;
variables.FILE_EXT = srcParts.ext.replace('.', '');
variables.PATH = src;
variables.IS_FILE = isFile(src);
variables.IS_FOLDER = isFolder(src);
variables.IS_EXPRESSION = src.match(altToken ? REGEX_VAR_ALT : REGEX_VAR) != null;
if (!variables.IS_FOLDER && !variables.IS_FILE) {
variables.IS_GLOB = hasMagic(substitute(altToken, srcParts.base, {}, false));
}
else {
variables.IS_GLOB = false;
}
if (variables.IS_GLOB) {
//important: use the forward slash since path.resolve will return backslashes on Windows
const glob_base = globBase(src);
variables.DIR = path.resolve(glob_base.base);
variables.FILE_NAME = glob_base.glob;
variables.GLOB = glob_base.glob;
variables.GLOB_EXTENSIONS = getExtensions(glob_base.glob);
globOptions = {
...globOptions,
cwd: globOptions.cwd ? path.join(globOptions.cwd, glob_base.base) : null
};
variables.FILES = glob.sync(glob_base.glob, globOptions);
}
else if (variables.IS_FILE && exists(src)) {
variables.FILES = [src];
}
return variables;
};
export const pathInfo = (src, altToken = false, cwd = null) => {
const srcParts = path.parse(src);
let variables = {
PATH: src
};
variables.DIR = srcParts.dir;
variables.NAME = srcParts.name;
variables.FILE_NAME = srcParts.base;
variables.FILE_EXT = srcParts.ext.replace('.', '');
variables.PATH = src;
variables.IS_FILE = isFile(src);
variables.IS_FOLDER = isFolder(src);
variables.IS_EXPRESSION = src.match(altToken ? REGEX_VAR_ALT : REGEX_VAR) != null;
if (!variables.IS_FOLDER && !variables.IS_FILE) {
variables.IS_GLOB = hasMagic(srcParts.base);
}
else {
variables.IS_GLOB = false;
}
if (variables.IS_GLOB) {
const glob_base = globBase(src);
variables.DIR = path.resolve(glob_base.base);
variables.FILE_NAME = glob_base.glob;
variables.GLOB = glob_base.glob;
variables.GLOB_EXTENSIONS = getExtensions(glob_base.glob);
variables.FILES = globSync(glob_base.glob, {
dot: true,
cwd: path.resolve(cwd || variables.DIR),
absolute: true
});
}
else if (variables.IS_FILE && exists(src)) {
variables.FILES = [src];
}
return variables;
};
//# sourceMappingURL=_glob.js.map

1
packages/commons/dist/_glob.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"_glob.js","sourceRoot":"","sources":["../src/_glob.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAA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AAA;AACpB,CAAC,CAAA"}

38
packages/commons/dist/config.d.ts vendored Normal file
View File

@ -0,0 +1,38 @@
export declare const API_PREFIX = "osr";
export declare const API_PREFIX_NEXT = "polymech";
export declare const HOME: (sub?: string) => string;
export declare const get_var: (key?: string) => string;
export declare const OSR_ROOT: (key?: string) => string;
export declare const OSR_SUB_DEFAULT: (key?: string) => string;
export declare const CONFIG_DEFAULT_PATH: (key?: string) => string;
export declare const OSR_TEMP: (key?: string) => string;
export declare const OSR_CACHE: (key?: string) => string;
export declare const OSR_PRIVATE: (key?: string) => string;
export declare const KB_ROOT: (key?: string) => string;
export declare const OSR_LIBRARY: (key?: string) => string;
export declare const OSR_LIBRARY_MACHINES: (key?: string) => string;
export declare const OSR_LIBRARY_DIRECTORY: (key?: string) => string;
export declare const PRODUCT_ROOT: (key?: string) => string;
export declare const OSR_CUSTOMER_DRIVE: (key?: string) => string;
export declare const OA_ROOT: (key?: string) => string;
export declare const OSR_USER_ASSETS: (key?: string) => string;
export declare const POLYMECH_ROOT: (key?: string) => string;
export declare const DEFAULT_ROOTS: {
OSR_ROOT: string;
OSR_TEMP: string;
PRODUCT_ROOT: string;
OA_ROOT: string;
KB_ROOT: string;
OSR_CACHE: string;
OSR_LIBRARY: string;
OSR_LIBRARY_MACHINES: string;
OSR_LIBRARY_DIRECTORY: string;
OSR_USER_ASSETS: string;
OSR_PRIVATE: string;
OSR_TEMPLATES: string;
OSR_CONTENT: string;
OSR_PROFILES: string;
OSR_CUSTOMER_DRIVE: string;
POLYMECH_ROOT: string;
};
export declare const CONFIG_DEFAULT: (key?: string) => string | false | object;

49
packages/commons/dist/config.js vendored Normal file
View File

@ -0,0 +1,49 @@
import * as env from 'env-var';
import { sync as read } from '@polymech/fs/read';
import { sync as exists } from '@polymech/fs/exists';
import * as path from 'path';
export const API_PREFIX = 'osr';
export const API_PREFIX_NEXT = 'polymech';
export const HOME = (sub = '') => path.join(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], sub);
export const get_var = (key = '') => env.get(key).asString() || env.get(key.replace(/-/g, '_')).asString() || env.get(key.replace(/_/g, '-')).asString();
export const OSR_ROOT = (key = 'OSR-ROOT') => get_var(key) || path.join(HOME('desktop'), API_PREFIX);
export const OSR_SUB_DEFAULT = (key = '') => get_var(key) || path.join(OSR_ROOT(), key);
export const CONFIG_DEFAULT_PATH = (key = 'OSR-CONFIG') => get_var(key) || path.join(HOME(`${API_PREFIX}`), '.config.json');
export const OSR_TEMP = (key = 'OSR-TEMP') => get_var(key) || OSR_SUB_DEFAULT(`.${API_PREFIX}/temp`);
export const OSR_CACHE = (key = 'OSR-CACHE') => get_var(key) || OSR_SUB_DEFAULT(`.${API_PREFIX}/cache`);
export const OSR_PRIVATE = (key = 'OSR-PRIVATE') => get_var(key);
export const KB_ROOT = (key = 'OSR-KB') => get_var(key);
export const OSR_LIBRARY = (key = 'OSR-LIBRARY') => get_var(key);
export const OSR_LIBRARY_MACHINES = (key = 'OSR-LIBRARY-MACHINES') => get_var(key);
export const OSR_LIBRARY_DIRECTORY = (key = 'OSR-LIBRARY-DIRECTORY') => get_var(key);
export const PRODUCT_ROOT = (key = 'PRODUCT-ROOT') => get_var(key);
export const OSR_CUSTOMER_DRIVE = (key = 'OSR-CUSTOMER-DRIVE') => get_var(key);
export const OA_ROOT = (key = 'OA-ROOT') => get_var(key);
export const OSR_USER_ASSETS = (key = 'OSR-USER-ASSETS') => get_var(key);
export const POLYMECH_ROOT = (key = 'POLYMECH-ROOT') => get_var(key) || path.join(HOME('desktop'), API_PREFIX_NEXT);
export const DEFAULT_ROOTS = {
OSR_ROOT: OSR_ROOT(),
OSR_TEMP: OSR_TEMP(),
PRODUCT_ROOT: PRODUCT_ROOT(),
OA_ROOT: OA_ROOT(),
KB_ROOT: KB_ROOT(),
OSR_CACHE: OSR_CACHE(),
OSR_LIBRARY: OSR_LIBRARY(),
OSR_LIBRARY_MACHINES: OSR_LIBRARY_MACHINES(),
OSR_LIBRARY_DIRECTORY: OSR_LIBRARY_DIRECTORY(),
OSR_USER_ASSETS: OSR_USER_ASSETS(),
OSR_PRIVATE: OSR_PRIVATE(),
OSR_TEMPLATES: path.join(OSR_SUB_DEFAULT('osr-templates')),
OSR_CONTENT: path.join(OSR_SUB_DEFAULT('osr-content')),
OSR_PROFILES: path.join(OSR_SUB_DEFAULT('osr-profiles')),
OSR_CUSTOMER_DRIVE: OSR_CUSTOMER_DRIVE(),
POLYMECH_ROOT: POLYMECH_ROOT()
};
export const CONFIG_DEFAULT = (key = 'OSR-CONFIG') => {
const cPath = path.resolve(CONFIG_DEFAULT_PATH(key));
if (exists(cPath)) {
return read(cPath, 'json');
}
return false;
};
//# sourceMappingURL=config.js.map

1
packages/commons/dist/config.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,IAAI,IAAI,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAA;AAC/B,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAA;AAEzC,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,GAAG,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAA;AAErH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAa,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,IAAI,GA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BAAqB,EAAE;IAC9C,eAAe,EAAE,eAAe,EAAE;IAClC,WAAW,EAAE,WAAW,EAAE;IAC1B,aAAa,EAAE,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;IAC1D,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;IACtD,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;IACxD,kBAAkB,EAAE,kBAAkB,EAAE;IACxC,aAAa,EAAE,aAAa,EAAE;CACjC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAc,YAAY,EAAE,EAAE;IACzD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC;IACrD,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE;QACf,OAAO,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;KAC9B;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAA"}

8
packages/commons/dist/constants.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
export declare const MODULE_NAME = "OSR-Commons";
export declare const PROFILE_FILE_NAME = ".osrl.json";
export declare const OA_LATEST = "${OSR_ROOT}/osr-directory/pp/${YYYY}_${MM}.json";
export declare const OA_LATEST_INVALID = "${OSR_ROOT}/osr-directory/pp/${YYYY}_${MM}_INVALID.json";
export declare const OA_LATEST_CENSORED = "${OSR_ROOT}/osr-directory/pp/${YYYY}_${MM}_CENSORED.json";
export declare const OA_LATEST_MERGED = "${OSR_ROOT}/osr-directory/pp/${YYYY}_${MM}_MERGED.json";
export declare const PP_BAZAR_LATEST_INDEX = "${OSR_ROOT}/pp-bazar/${YYYY}/${MM}/index.json";
export declare const PP_BAZAR_LATEST_INDEX_MERGED = "${OSR_ROOT}/pp-bazar/${YYYY}/${MM}/index_merged.json";

13
packages/commons/dist/constants.js vendored Normal file
View File

@ -0,0 +1,13 @@
export const MODULE_NAME = `OSR-Commons`;
export const PROFILE_FILE_NAME = `.osrl.json`;
////////////////////////////////////////
//
// OA Migration
export const OA_LATEST = '${OSR_ROOT}/osr-directory/pp/${YYYY}_${MM}.json';
export const OA_LATEST_INVALID = '${OSR_ROOT}/osr-directory/pp/${YYYY}_${MM}_INVALID.json';
export const OA_LATEST_CENSORED = '${OSR_ROOT}/osr-directory/pp/${YYYY}_${MM}_CENSORED.json';
export const OA_LATEST_MERGED = '${OSR_ROOT}/osr-directory/pp/${YYYY}_${MM}_MERGED.json';
// fecking bazar
export const PP_BAZAR_LATEST_INDEX = '${OSR_ROOT}/pp-bazar/${YYYY}/${MM}/index.json';
export const PP_BAZAR_LATEST_INDEX_MERGED = '${OSR_ROOT}/pp-bazar/${YYYY}/${MM}/index_merged.json';
//# sourceMappingURL=constants.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAA;AACxC,MAAM,CAAC,MAAM,iBAAiB,GAAG,YAAY,CAAA;AAC7C,wCAAwC;AACxC,EAAE;AACF,gBAAgB;AAEhB,MAAM,CAAC,MAAM,SAAS,GAAG,iDAAiD,CAAA;AAC1E,MAAM,CAAC,MAAM,iBAAiB,GAAG,yDAAyD,CAAA;AAC1F,MAAM,CAAC,MAAM,kBAAkB,GAAG,0DAA0D,CAAA;AAC5F,MAAM,CAAC,MAAM,gBAAgB,GAAG,wDAAwD,CAAA;AAExF,gBAAgB;AAChB,MAAM,CAAC,MAAM,qBAAqB,GAAG,+CAA+C,CAAA;AACpF,MAAM,CAAC,MAAM,4BAA4B,GAAG,sDAAsD,CAAA"}

7
packages/commons/dist/fs.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
export declare const GLOB_GROUP_PATTERN: RegExp;
export declare const UNC_REGEX: RegExp;
export declare const WIN32_PATH_REGEX: RegExp;
export declare const getExtensions: (glob: string) => any[];
export declare const isFile: (src: string) => boolean;
export declare const isFolder: (src: string) => boolean;
export declare const is_absolute: (fp: any) => boolean;

47
packages/commons/dist/fs.js vendored Normal file
View File

@ -0,0 +1,47 @@
import * as fs from 'fs';
// https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#namespaces
// https://github.com/isaacs/node-glob/blob/main/src/pattern.ts
export const GLOB_GROUP_PATTERN = /[!*+?@]\(.*\)/;
export const UNC_REGEX = /^[\\\/]{2,}[^\\\/]+[\\\/]+[^\\\/]+/;
export const WIN32_PATH_REGEX = /^([a-z]:)?[\\\/]/i;
import { is_windows } from './os.js';
const parseGlob = require('parse-glob');
export const getExtensions = (glob) => {
const match = glob.match(GLOB_GROUP_PATTERN);
if (match) {
return glob.substring((match.index || 0) + 2, glob.lastIndexOf(')')).split('|');
}
else {
return [parseGlob(glob).path.ext];
}
};
export const isFile = (src) => {
let srcIsFile = false;
try {
srcIsFile = fs.lstatSync(src).isFile();
}
catch (e) { }
return srcIsFile;
};
export const isFolder = (src) => {
let srcIsFolder = false;
try {
srcIsFolder = fs.lstatSync(src).isDirectory();
}
catch (e) { }
return srcIsFolder;
};
const is_relative_win32 = (fp) => !fp.test(UNC_REGEX) && !WIN32_PATH_REGEX.test(fp);
const is_absolute_posix = (fp) => fp.charAt(0) === '/';
const is_absolute_win32 = (fp) => {
if (/[a-z]/i.test(fp.charAt(0)) && fp.charAt(1) === ':' && fp.charAt(2) === '\\') {
return true;
}
// Microsoft Azure absolute filepath
if (fp.slice(0, 2) === '\\\\') {
return true;
}
return !is_relative_win32(fp);
};
export const is_absolute = (fp) => is_windows() ? is_absolute_win32(fp) : is_absolute_posix(fp);
//# sourceMappingURL=fs.js.map

1
packages/commons/dist/fs.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AAExB,kFA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,CAAC,CAAA;AAED,MAAM,iBAAiB,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACnF,MAAM,iBAAiB,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,CAAA;AACtD,MAAM,iBAAiB,GAAG,CAAC,EAAE,EAAE,EAAE;IAC7B,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE;QAC9E,OAAO,IAAI,CAAA;KACd;IACD,oCAAoC;IACpC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,EAAE;QAC3B,OAAO,IAAI,CAAC;KACf;IACD,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAA;AACjC,CAAC,CAAA;AACD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAAE,EAAE,EAAE,CAAE,UAAU,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAA"}

1
packages/commons/dist/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

2
packages/commons/dist/index.js vendored Normal file
View File

@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=index.js.map

1
packages/commons/dist/index.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}

2
packages/commons/dist/lib/fs.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
export declare const isFile: (src: string) => boolean;
export declare const isFolder: (src: string) => boolean;

18
packages/commons/dist/lib/fs.js vendored Normal file
View File

@ -0,0 +1,18 @@
import * as fs from 'fs';
export const isFile = (src) => {
let srcIsFile = false;
try {
srcIsFile = fs.lstatSync(src).isFile();
}
catch (e) { }
return srcIsFile;
};
export const isFolder = (src) => {
let srcIsFolder = false;
try {
srcIsFolder = fs.lstatSync(src).isDirectory();
}
catch (e) { }
return srcIsFolder;
};
//# sourceMappingURL=fs.js.map

1
packages/commons/dist/lib/fs.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/lib/fs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AAExB,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,EAAE;IAClC,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,IAAI;QACA,SAAS,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAA;KACzC;IAAC,OAAO,CAAC,EAAE,GAAG;IACf,OAAO,SAAS,CAAA;AACpB,CAAC,CAAA;AACD,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,EAAE;IACpC,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,IAAI;QACA,WAAW,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAA;KAChD;IAAC,OAAO,CAAC,EAAE,GAAG;IACf,OAAO,WAAW,CAAC;AACvB,CAAC,CAAA"}

2
packages/commons/dist/lib/index.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
export * from './strings.js';
export * from './fs.js';

3
packages/commons/dist/lib/index.js vendored Normal file
View File

@ -0,0 +1,3 @@
export * from './strings.js';
export * from './fs.js';
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA"}

View File

@ -0,0 +1,3 @@
export declare const regexExEmojis: RegExp;
export declare const regexExEmojis2: RegExp;
export declare const regexExEmojis3: RegExp;

7
packages/commons/dist/lib/strings.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
{"version":3,"file":"strings.js","sourceRoot":"","sources":["../../src/lib/strings.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,0mVAA0mV,CAAC;AAExoV,8CAA8C;AAC9C,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,MAAM,CAAC,ouYAAouY,EAAE,GAAG,CAAC,CAAA;AAEnxY,wBAAwB;AACxB,MAAM,CAAC,MAAM,cAAc,GAAG,62WAA62W,CAAC;AAE54W,MAAM,cAAc,GAAG,mYAAmY,CAAA"}

5
packages/commons/dist/logger.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
import { Logger } from "tslog";
export declare function createLogger(name: string, options?: any): Logger;
export declare const defaultLogger: Logger;
export { MODULE_NAME } from './constants.js';
export declare const logger: Logger;

15
packages/commons/dist/logger.js vendored Normal file
View File

@ -0,0 +1,15 @@
import { Logger } from "tslog";
export function createLogger(name, options) {
return new Logger({
name,
type: 'pretty',
...options,
});
}
export const defaultLogger = createLogger('DefaultLogger', {
minLevel: 1
});
import { MODULE_NAME } from './constants.js';
export { MODULE_NAME } from './constants.js';
export const logger = createLogger(MODULE_NAME, {});
//# sourceMappingURL=logger.js.map

1
packages/commons/dist/logger.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,OAAO,CAAA;AAE/C,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,OAAa;IACpD,OAAO,IAAI,MAAM,CAAC;QACd,IAAI;QACJ,IAAI,EAAE,QAAQ;QACd,GAAG,OAAO;KACb,CAAC,CAAA;AACN,CAAC;AACD,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAC,eAAe,EAAE;IACvD,QAAQ,EAAE,CAAC;CACd,CAAC,CAAA;AAEF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA"}

10
packages/commons/dist/os.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
export declare enum EPlatform {
Linux = "linux",
Windows = "win32",
OSX = "darwin"
}
export declare enum EArch {
x64 = "64",
x32 = "32"
}
export declare const is_windows: () => boolean;

13
packages/commons/dist/os.js vendored Normal file
View File

@ -0,0 +1,13 @@
export var EPlatform;
(function (EPlatform) {
EPlatform["Linux"] = "linux";
EPlatform["Windows"] = "win32";
EPlatform["OSX"] = "darwin";
})(EPlatform = EPlatform || (EPlatform = {}));
export var EArch;
(function (EArch) {
EArch["x64"] = "64";
EArch["x32"] = "32";
})(EArch = EArch || (EArch = {}));
export const is_windows = () => process && (process.platform === 'win32');
//# sourceMappingURL=os.js.map

1
packages/commons/dist/os.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"os.js","sourceRoot":"","sources":["../src/os.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,SAIX;AAJD,WAAY,SAAS;IACpB,4BAAe,CAAA;IACf,8BAAiB,CAAA;IACjB,2BAAc,CAAA;AACf,CAAC,EAJW,SAAS,GAAT,SAAS,KAAT,SAAS,QAIpB;AACD,MAAM,CAAN,IAAY,KAGX;AAHD,WAAY,KAAK;IAChB,mBAAU,CAAA;IACV,mBAAU,CAAA;AACX,CAAC,EAHW,KAAK,GAAL,KAAK,KAAL,KAAK,QAGhB;AACD,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAA"}

View File

@ -0,0 +1,56 @@
import { IDiscourseUploadImage } from './discourse.js';
export interface IDiscourseItemCommons {
forum?: string | boolean;
forumTitle?: string;
forumCategory?: number;
forumTags?: string | string[];
forumPostId?: number;
forumTopicId?: number;
forumUserId?: number;
forumUserName?: string;
forumPostHash?: string;
forumUploads?: Record<string, IDiscourseUploadImage>;
}
export interface IComponentConfig extends IDiscourseItemCommons {
cart_id?: string;
code: string;
price?: number;
cscartCats?: number[];
cscartId?: number;
vendorId?: number;
version?: string;
status?: string;
authors: IAuthor[];
replaced_by?: string;
alternatives?: string[];
flags?: number;
howto_categories?: string | string[];
sourceLanguage?: string;
last_sync_ts?: number;
download?: boolean;
edrawings?: string;
name: string;
showDimensions?: boolean;
showParts?: boolean;
slug: string;
score?: number;
Preview3d?: boolean;
keywords?: string;
meta_keywords?: string;
steps?: any;
/**
* @deprecated
*/
category: string;
product_dimensions?: string;
production?: IProduction;
}
export interface IAuthor {
name: string;
url: string;
}
export interface IProduction {
"fusion-folder": string;
"nc-folder": string;
cam: IAuthor[];
}

View File

@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=component.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../src/osr/component.ts"],"names":[],"mappings":""}

View File

@ -0,0 +1,15 @@
export interface IDiscourseUploadImage {
id: number;
url: string;
original_filename: string;
filesize: number;
width: number;
height: number;
thumbnail_width: number;
thumbnail_height: number;
extension: string;
short_url: string;
short_path: string;
retain_hours: any;
human_filesize: string;
}

View File

@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=discourse.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"discourse.js","sourceRoot":"","sources":["../../src/osr/discourse.ts"],"names":[],"mappings":""}

1
packages/commons/dist/paths.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

2
packages/commons/dist/paths.js vendored Normal file
View File

@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=paths.js.map

1
packages/commons/dist/paths.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":""}

19
packages/commons/dist/profile.d.ts vendored Normal file
View File

@ -0,0 +1,19 @@
interface EnvVariables {
[key: string]: string;
}
interface EnvConfig {
includes: string[];
variables: EnvVariables;
}
export interface IProfile {
includes: string[];
variables: EnvVariables;
env: {
[key: string]: EnvConfig;
};
}
export declare const resolveConfig: (config: any) => any;
export declare const parseProfile: (profilePath: string, profile: IProfile, options?: {
env: string;
}, rel?: string) => IProfile;
export {};

77
packages/commons/dist/profile.js vendored Normal file
View File

@ -0,0 +1,77 @@
import * as path from 'path';
import { REGEX_VAR } from "@polymech/core/constants.js";
import { sync as read } from '@polymech/fs/read';
import { sync as exists } from '@polymech/fs/exists';
import { isString } from '@polymech/core/types.js';
import { resolve, substitute } from './variables.js';
const _resolve = (config) => {
for (const key in config) {
if (config[key] && typeof config[key] == 'string') {
const resolved = substitute(false, config[key], config);
config[key] = resolved;
}
}
return config;
};
// @todo: Implement the function `resolveConfig`
export const resolveConfig = (config) => {
config = _resolve(config);
config = _resolve(config);
return config;
};
export const parseProfile = (profilePath, profile, options = { env: 'default' }, rel) => {
profilePath = path.resolve(resolve(profilePath, false, profile.variables));
if (!exists(profilePath)) {
return;
}
const _profile = read(profilePath, 'json') || { includes: [], variables: {} };
_profile.includes = _profile.includes || [];
_profile.variables = _profile.variables || {};
if (options.env && _profile.env && _profile.env[options.env] && _profile.env[options.env].includes) {
profile.includes = [
...profile.includes,
..._profile.includes,
..._profile.env[options.env].includes
];
}
else {
profile.includes = [
...profile.includes,
..._profile.includes
];
}
if (options.env && _profile.env && _profile.env[options.env] && _profile.env[options.env].variables) {
profile.variables = {
...profile.variables,
..._profile.variables,
..._profile.env[options.env].variables
};
}
for (const k in _profile.variables) {
if (isString(_profile.variables[k])) {
_profile.variables[k] = substitute(false, _profile.variables[k], profile.variables);
}
}
profile.variables = { ...profile.variables, ..._profile.variables, ..._profile.env[options.env]?.variables || {} };
for (const k in profile.variables) {
if (isString(profile.variables[k])) {
profile.variables[k] = substitute(false, profile.variables[k], profile.variables);
}
}
profile.includes = Array.from(new Set(profile.includes));
profile.includes = [
...profile.includes.map((i) => {
if (!path.isAbsolute(i) && rel && !i.match(REGEX_VAR)) {
return path.resolve(`${rel}/${i}`);
}
let ret = resolve(i, false, profile.variables);
ret = path.resolve(substitute(false, ret, profile.variables));
return ret;
})
];
profile.includes = profile.includes.filter((include) => include !== null &&
include !== '');
profile.includes = Array.from(new Set(profile.includes));
return profile;
};
//# sourceMappingURL=profile.js.map

1
packages/commons/dist/profile.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AACvD,OAAO,EAAE,IAAI,IAAI,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAoBpD,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,EAAE;IACxB,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE;QACtB,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,QAAQ,EAAE;YAC/C,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAA;YACvD,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAA;SACzB;KACJ;IACD,OAAO,MAAM,CAAC;AAClB,CAAC,C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,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;IACxD,OAAO,CAAC,QAAQ,GAAG;QACf,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YAC1B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;gBACnD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,CAAA;aACrC;YACD,IAAI,GAAG,GAAG,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;YAC9C,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;YAC7D,OAAO,GAAG,CAAA;QACd,CAAC,CAAC;KAAC,CAAA;IAEP,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CACnD,OAAO,KAAK,IAAI;QAChB,OAAO,KAAK,EAAE,CAAC,CAAA;IACnB,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;IACxD,OAAO,OAAO,CAAA;AAClB,CAAC,CAAA"}

23
packages/commons/dist/shemas/index.d.ts vendored Normal file
View File

@ -0,0 +1,23 @@
import * as CLI from 'yargs';
import { z, ZodTypeAny, ZodObject } from 'zod';
export * from './path.js';
export * from './zod_map.js';
export declare const generate_interfaces: (schemas: ZodObject<any>[], dst: string) => void;
export declare const enumerateHelpStrings: (schema: ZodTypeAny, path: string[], logger: any) => void;
export declare const yargsDefaults: (yargs: CLI.Argv) => any;
export declare const getInnerSchema: (schema: ZodTypeAny) => ZodTypeAny;
export declare const getInnerType: (type: ZodTypeAny) => any;
export declare const getDefaultValue: (schema: ZodTypeAny) => any;
export declare const getFieldDefaultValue: (schema: ZodTypeAny) => any | undefined;
export declare const getDescription: (schema: ZodTypeAny) => string | undefined;
export declare const toYargs: (yargs: CLI.Argv, zodSchema: ZodObject<any>, options?: {
onKey?: (yargs: CLI.Argv, key: string, options: any) => any;
}) => CLI.Argv;
export declare const WRITERS: {
'.json': (data: any, file: string, name: string, options: {}) => void;
};
export declare const writer: (file: string) => any;
export declare const write: (schemas: ZodObject<any>[], file: string, name: string, options: {}) => void;
export declare const combineValidatorsOr: (validators: z.ZodTypeAny[]) => z.ZodEffects<z.ZodString, string, string>;
export declare const combineValidatorsOrUsingZod: (validators: z.ZodTypeAny[]) => z.ZodTypeAny;
export declare const combineValidatorsOrUsingZod2: (validators: z.ZodTypeAny[]) => z.ZodTypeAny;

204
packages/commons/dist/shemas/index.js vendored Normal file
View File

@ -0,0 +1,204 @@
import * as path from 'path';
import { z, ZodObject, ZodEffects, ZodOptional, ZodDefault } from 'zod';
import { sync as writeFS } from '@polymech/fs/write';
import { zodToTs, printNode } from 'zod-to-ts';
import { zodToJsonSchema } from "zod-to-json-schema";
import { logger } from '@/logger.js';
export * from './path.js';
export * from './zod_map.js';
export const generate_interfaces = (schemas, dst) => {
const types = schemas.map(schema => `export interface ${schema.description || 'IOptions'} ${printNode(zodToTs(schema).node)}`);
writeFS(dst, types.join('\n'));
};
export const enumerateHelpStrings = (schema, path = [], logger) => {
if (schema instanceof ZodObject) {
for (const key in schema.shape) {
const nestedSchema = schema.shape[key];
enumerateHelpStrings(nestedSchema, [...path, key], logger);
}
}
else {
const description = schema._def.description;
if (description) {
logger.debug(`\t ${path.join('.')}: ${description}`);
}
}
};
export const yargsDefaults = (yargs) => yargs.parserConfiguration({ "camel-case-expansion": false });
export const getInnerSchema = (schema) => {
while (schema instanceof ZodEffects) {
schema = schema._def.schema;
}
return schema;
};
export const getInnerType = (type) => {
while (type instanceof ZodOptional) {
type = type._def.innerType;
}
while (type._def.typeName === 'ZodDefault' || type._def.typeName === 'ZodOptional') {
type = type._def.innerType;
}
return type._def.typeName;
};
export const getDefaultValue = (schema) => {
if (schema instanceof ZodDefault) {
return schema._def.defaultValue();
}
return undefined;
};
export const getFieldDefaultValue = (schema) => {
if (!schema) {
return undefined;
}
if (schema._def.typeName === 'ZodDefault') {
return schema._def.defaultValue();
}
if (schema instanceof ZodOptional) {
return getFieldDefaultValue(schema.unwrap());
}
if (schema instanceof ZodEffects) {
return getFieldDefaultValue(schema._def.schema);
}
if (typeof schema._def) {
return getFieldDefaultValue(schema._def.schema);
}
return undefined;
};
export const getDescription = (schema) => {
if (!schema) {
return undefined;
}
if (schema._def.description) {
return schema._def.description;
}
if (schema instanceof ZodOptional) {
return getDescription(schema.unwrap());
}
if (schema instanceof ZodEffects) {
return getDescription(schema._def.schema);
}
if (typeof schema._def) {
return getDescription(schema._def.schema);
}
return undefined;
};
export const toYargs = (yargs, zodSchema, options) => {
yargsDefaults(yargs);
try {
const shape = zodSchema.shape;
for (const key in shape) {
const zodField = shape[key];
const innerDef = getInnerSchema(zodField);
if (!innerDef) {
continue;
}
let type;
const inner_type = getInnerType(innerDef);
let descriptionExtra = '';
switch (inner_type) {
case 'ZodString':
type = 'string';
break;
case 'ZodBoolean':
type = 'boolean';
break;
case 'ZodNumber':
type = 'number';
break;
case 'ZodOptional':
case 'ZodEnum':
type = getInnerType(innerDef);
if (innerDef._def.typeName === 'ZodEnum') {
descriptionExtra = `\n\t ${innerDef._def.values.join(' \n\t ')}`;
}
break;
}
const defaultValue = getFieldDefaultValue(zodField);
let handled = false;
const args = {
type,
default: defaultValue,
describe: `${zodField._def.description || ''} ${descriptionExtra}`.trim()
};
if (options?.onKey) {
handled = options.onKey(yargs, key, args);
}
if (!handled) {
yargs.option(key, args);
}
}
return yargs;
}
catch (error) {
logger.error('Error processing schema:', error);
return yargs;
}
};
/////////////////////////////////////////////////////////
//
// Schema Writers
//
const extension = (file) => path.parse(file).ext;
const json = (data, file, name, options) => writeFS(file, data.map((s) => zodToJsonSchema(s, name)));
export const WRITERS = {
'.json': json
};
export const writer = (file) => WRITERS[extension(file)];
export const write = (schemas, file, name, options) => {
if (!WRITERS[extension(file)]) {
logger.error(`No writer found for file extension: ${extension(file)} : file: ${file}`);
return;
}
logger.debug(`Writing schema to ${file} : ${name}`);
try {
writer(file)(schemas, file, name, options);
}
catch (e) {
logger.trace(`Error writing schema to ${file} : ${name}`, e, e.stack, e.message);
}
};
////////////////////////////////////////////////////////////////////
//
// Schema Combinators
export const combineValidatorsOr = (validators) => {
return z.string().refine((value) => {
const errors = [];
const isValid = validators.some((validator) => {
try {
validator.parse(value);
return true;
}
catch (err) {
errors.push(err.errors);
return false;
}
});
if (!isValid) {
throw new z.ZodError(errors.flat());
}
return true;
}, 'Invalid value for all provided validators');
};
export const combineValidatorsOrUsingZod = (validators) => {
return validators.reduce((acc, validator) => acc.or(validator));
};
export const combineValidatorsOrUsingZod2 = (validators) => {
return validators.reduce((acc, validator) => {
return acc.or(validator).refine((value) => {
try {
acc.parse(value);
return true;
}
catch (errAcc) {
try {
validator.parse(value);
return true;
}
catch (errValidator) {
throw new z.ZodError([...errAcc.errors, ...errValidator.errors]);
}
}
});
});
};
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
export {};

22
packages/commons/dist/shemas/openapi.js vendored Normal file
View File

@ -0,0 +1,22 @@
export {};
/*
export const openapi = (data: ZodObject<any>[], file: string, name: string, options: {}) => {
const registry = new OpenAPIRegistry()
data.forEach((s) => registry.register(s.description, s))
const generator = new OpenApiGeneratorV3(registry.definitions)
const component = generator.generateComponents()
// const content = stringifyYAML(component)
return component
}
*/
/*
const yaml = (data: ZodObject<any>[], file: string, name: string, options: {}) => {
const registry = new OpenAPIRegistry()
data.forEach((s) => registry.register(s.description, s))
const generator = new OpenApiGeneratorV3(registry.definitions)
const component = generator.generateComponents()
logger.debug(`Writing schema to ${file} : ${name}`,component)
writeFS(file,stringifyYAML(component))
}
*/
//# sourceMappingURL=openapi.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"openapi.js","sourceRoot":"","sources":["../../src/shemas/openapi.ts"],"names":[],"mappings":";AAAA;;;;;;;;;EASE;AACF;;;;;;;;;EASE"}

30
packages/commons/dist/shemas/path.d.ts vendored Normal file
View File

@ -0,0 +1,30 @@
import { z, ZodTypeAny } from 'zod';
export declare enum E_PATH {
ENSURE_PATH_EXISTS = 1,
INVALID_INPUT = 2,
ENSURE_DIRECTORY_WRITABLE = 3,
ENSURE_FILE_IS_JSON = 4,
ENSURE_PATH_IS_ABSOLUTE = 5,
ENSURE_PATH_IS_RELATIVE = 6,
GET_PATH_INFO = 7
}
export declare const Transformers: Record<string, any>;
export declare const TransformersDescription: {
description: string;
fn: any;
}[];
export declare const extendSchema: (baseSchema: z.ZodObject<any>, extend: Record<string, any>) => z.ZodObject<Record<string, z.ZodTypeAny>, "strip", z.ZodTypeAny, {
[x: string]: any;
}, {
[x: string]: any;
}>;
export declare const ENSURE_DIRECTORY_WRITABLE: (inputPath: string, ctx: any, variables: Record<string, string>) => string;
export declare const IS_VALID_STRING: (inputPath: string) => boolean;
export declare const ENSURE_PATH_EXISTS: (inputPath: string, ctx: any, variables: Record<string, string>) => string;
export declare const test: () => z.ZodObject<Record<string, z.ZodTypeAny>, "strip", z.ZodTypeAny, {
[x: string]: any;
}, {
[x: string]: any;
}>;
export declare const Templates: Record<string, any>;
export declare const extend: (baseSchema: ZodTypeAny, template: any, variables?: Record<string, string>) => z.ZodTypeAny;

239
packages/commons/dist/shemas/path.js vendored Normal file
View File

@ -0,0 +1,239 @@
import { z } from 'zod';
import * as path from 'path';
import { accessSync, constants, lstatSync, existsSync } from 'fs';
import { isString } from '@polymech/core/primitives.js';
import { logger } from '@/logger.js';
import { sync as exists } from '@polymech/fs/exists';
import { sync as read } from '@polymech/fs/read';
import { DEFAULT_VARS, resolve, resolveVariables } from '@/variables.js';
import { getDescription } from '@/shemas/index.js';
import { isFile } from '@/lib/fs.js';
const DefaultPathSchemaBase = z.string().describe('Path to a file or directory');
const PathErrorMessages = {
INVALID_INPUT: 'INVALID_INPUT: ${inputPath}',
PATH_DOES_NOT_EXIST: 'Path does not exist ${inputPath} = ${resolvedPath}',
DIRECTORY_NOT_WRITABLE: 'Directory is not writable ${inputPath} = ${resolvedPath}',
NOT_A_DIRECTORY: 'Path is not a directory or does not exist ${inputPath} = ${resolvedPath}',
NOT_A_JSON_FILE: 'File is not a JSON file or does not exist ${inputPath} = ${resolvedPath}',
PATH_NOT_ABSOLUTE: 'Path is not absolute ${inputPath} = ${resolvedPath}',
PATH_NOT_RELATIVE: 'Path is not relative ${inputPath} = ${resolvedPath}',
};
export var E_PATH;
(function (E_PATH) {
E_PATH[E_PATH["ENSURE_PATH_EXISTS"] = 1] = "ENSURE_PATH_EXISTS";
E_PATH[E_PATH["INVALID_INPUT"] = 2] = "INVALID_INPUT";
E_PATH[E_PATH["ENSURE_DIRECTORY_WRITABLE"] = 3] = "ENSURE_DIRECTORY_WRITABLE";
E_PATH[E_PATH["ENSURE_FILE_IS_JSON"] = 4] = "ENSURE_FILE_IS_JSON";
E_PATH[E_PATH["ENSURE_PATH_IS_ABSOLUTE"] = 5] = "ENSURE_PATH_IS_ABSOLUTE";
E_PATH[E_PATH["ENSURE_PATH_IS_RELATIVE"] = 6] = "ENSURE_PATH_IS_RELATIVE";
E_PATH[E_PATH["GET_PATH_INFO"] = 7] = "GET_PATH_INFO";
})(E_PATH = E_PATH || (E_PATH = {}));
export const Transformers = {
resolve: (val, variables = {}) => {
if (!val) {
return null;
}
return {
resolved: path.resolve(resolve(val, false, variables)),
source: val
};
},
json: (val, variables = {}) => {
if (!val) {
return null;
}
const resolved = path.resolve(resolve(isString(val) ? val : val.source, false, variables));
return {
resolved,
source: val,
value: read(resolved, 'json')
};
},
string: (val, variables = {}) => {
if (!val) {
return null;
}
let src = isString(val) ? val : val.source;
src = resolve(src, false, variables);
const resolved = path.resolve(src);
if (!exists(resolved) || !isFile(resolved)) {
return {
resolved,
source: val,
value: null
};
}
else {
let value = null;
try {
value = read(resolved, 'string');
}
catch (e) {
logger.error('Failed to read file', { resolved, source: val, error: e.message });
}
return {
resolved,
source: val,
value
};
}
}
};
export const TransformersDescription = [
{
description: 'RESOLVE_PATH',
fn: Transformers.resolve
},
{
description: 'READ_JSON',
fn: Transformers.json
},
{
description: 'READ_STRING',
fn: Transformers.string
}
];
const extendType = (type, extend, variables = {}) => {
if (Array.isArray(extend.refine)) {
for (const refine of extend.refine) {
type = type.refine(refine);
}
}
else {
type = type.refine(extend.refine);
}
if (Array.isArray(extend.transform)) {
for (const transform of extend.transform) {
type = type.transform((val) => transform(val, variables));
}
}
else {
type = type.transform(extend.transform);
}
return type;
};
const extendTypeDescription = (type, extension, variables = {}) => {
const description = getDescription(type) || '';
let transformerDescriptions = 'Transformers:\n';
if (Array.isArray(extension.transform)) {
for (const transform of extension.transform) {
transformerDescriptions += transformerDescription(transform) + '\n';
}
}
else {
transformerDescriptions += transformerDescription(extension.transform) + '\n';
}
type = type.describe(description + '\n' + transformerDescriptions);
return type;
};
const transformerDescription = (fn) => {
const description = TransformersDescription.find((t) => t.fn === fn);
return description ? description.description : 'Unknown';
};
export const extendSchema = (baseSchema, extend) => {
const baseShape = baseSchema.shape;
const extendedShape = { ...baseShape };
for (const [key, refines] of Object.entries(extend)) {
if (!baseShape[key])
continue;
let fieldSchema = baseShape[key];
if (Array.isArray(refines.refine)) {
for (const refine of refines.refine) {
fieldSchema = fieldSchema.superRefine(refine);
}
}
else {
fieldSchema = fieldSchema.superRefine(refines);
}
if (Array.isArray(refines.transform)) {
for (const transform of refines.transform) {
fieldSchema = fieldSchema.transform((val) => transform(val));
}
}
else {
fieldSchema = fieldSchema.transform(refines.transform);
}
extendedShape[key] = fieldSchema;
}
return z.object(extendedShape);
};
export const ENSURE_DIRECTORY_WRITABLE = (inputPath, ctx, variables) => {
const resolvedPath = path.resolve(resolve(inputPath, false, variables));
const parts = path.parse(resolvedPath);
if (resolvedPath && existsSync(parts.dir) && lstatSync(parts.dir).isDirectory()) {
try {
accessSync(resolvedPath, constants.W_OK);
return resolvedPath;
}
catch (e) {
ctx.addIssue({
code: E_PATH.ENSURE_DIRECTORY_WRITABLE,
message: resolveVariables(PathErrorMessages.DIRECTORY_NOT_WRITABLE, false, { inputPath, resolvedPath })
});
return z.NEVER;
}
}
else {
ctx.addIssue({
code: E_PATH.ENSURE_DIRECTORY_WRITABLE,
message: resolveVariables(PathErrorMessages.NOT_A_DIRECTORY, false, { inputPath, resolvedPath })
});
return z.NEVER;
}
};
export const IS_VALID_STRING = (inputPath) => {
return isString(inputPath);
};
export const ENSURE_PATH_EXISTS = (inputPath, ctx, variables) => {
if (!inputPath || !ctx) {
return z.NEVER;
}
if (!isString(inputPath)) {
ctx.addIssue({
code: E_PATH.INVALID_INPUT,
message: resolveVariables(PathErrorMessages.INVALID_INPUT, false, {})
});
return z.NEVER;
}
const resolvedPath = path.resolve(resolve(inputPath, false, variables));
if (!exists(resolvedPath)) {
ctx.addIssue({
code: E_PATH.ENSURE_PATH_EXISTS,
message: resolveVariables(PathErrorMessages.PATH_DOES_NOT_EXIST, false, { inputPath, resolvedPath })
});
return z.NEVER;
}
return resolvedPath;
};
export const test = () => {
const BaseCompilerOptions = () => z.object({
root: DefaultPathSchemaBase.default(`${process.cwd()}`)
});
const ret = extendSchema(BaseCompilerOptions(), {
root: {
refine: [
(val, ctx) => ENSURE_DIRECTORY_WRITABLE(val, ctx, DEFAULT_VARS({ exampleVar: 'exampleValue' })),
(val, ctx) => ENSURE_PATH_EXISTS(val, ctx, DEFAULT_VARS({ exampleVar: 'exampleValue' }))
],
transform: [
(val) => path.resolve(resolve(val, false, DEFAULT_VARS({ exampleVar: 'exampleValue' })))
]
}
});
return ret;
};
export const Templates = {
json: {
refine: [IS_VALID_STRING, ENSURE_PATH_EXISTS],
transform: [Transformers.resolve, Transformers.json]
},
string: {
refine: [ENSURE_PATH_EXISTS],
transform: [Transformers.resolve, Transformers.string]
}
};
export const extend = (baseSchema, template, variables = {}) => {
const type = extendType(baseSchema, template, variables);
return extendTypeDescription(type, template, variables);
};
//# sourceMappingURL=path.js.map

File diff suppressed because one or more lines are too long

194
packages/commons/dist/shemas/types.d.ts vendored Normal file
View File

@ -0,0 +1,194 @@
export declare enum FLAG {
/**
* Instruct for no additional extra processing
* @constant
* @type int
*/
NONE = 0,
/**
* Will instruct the pre/post processor to base-64 decode or encode
* @constant
* @type int
*/
BASE_64 = 1,
/**
* Post/Pre process the value with a user function
* @constant
* @type int
*/
USE_FUNCTION = 2,
/**
* Replace variables with local scope's variables during the post/pre process
* @constant
* @type int
*/
REPLACE_VARIABLES = 4,
/**
* Replace variables with local scope's variables during the post/pre process but evaluate the whole string
* as Javascript
* @constant
* @type int
*/
REPLACE_VARIABLES_EVALUATED = 8,
/**
* Will instruct the pre/post processor to escpape evaluated or replaced variables or expressions
* @constant
* @type int
*/
ESCAPE = 16,
/**
* Will instruct the pre/post processor to replace block calls with oridinary vanilla script
* @constant
* @type int
*/
REPLACE_BLOCK_CALLS = 32,
/**
* Will instruct the pre/post processor to remove variable delimitters/placeholders from the final string
* @constant
* @type int
*/
REMOVE_DELIMTTERS = 64,
/**
* Will instruct the pre/post processor to remove "[" ,"]" , "(" , ")" , "{", "}" , "*" , "+" , "."
* @constant
* @type int
*/
ESCAPE_SPECIAL_CHARS = 128,
/**
* Will instruct the pre/post processor to use regular expressions over string substitution
* @constant
* @type int
*/
USE_REGEX = 256,
/**
* Will instruct the pre/post processor to use Filtrex (custom bison parser, needs xexpression) over string substitution
* @constant
* @type int
*/
USE_FILTREX = 512,
/**
* Cascade entry. There are cases where #USE_FUNCTION is not enough or we'd like to avoid further type checking.
* @constant
* @type int
*/
CASCADE = 1024,
/**
* Cascade entry. There are cases where #USE_FUNCTION is not enough or we'd like to avoid further type checking.
* @constant
* @type int
*/
EXPRESSION = 2048,
/**
* Dont parse anything
* @constant
* @type int
*/
DONT_PARSE = 4096,
/**
* Convert to hex
* @constant
* @type int
*/
TO_HEX = 8192,
/**
* Convert to hex
* @constant
* @type int
*/
REPLACE_HEX = 16384,
/**
* Wait for finish
* @constant
* @type int
*/
WAIT = 32768,
/**
* Wait for finish
* @constant
* @type int
*/
DONT_ESCAPE = 65536,
/**
* Flag to mark the maximum core bit mask, after here its user land
* @constant
* @type int
*/
END = 131072
}
export declare enum EType {
Number = "Number",
String = "String",
Boolean = "Boolean",
Date = "Date",
TimeStamp = "TimeStamp",
Duration = "Duration",
Url = "Url",
UrlScheme = "Url-Scheme",
Asset = "Asset",
Symbol = "Symbol",
Value = "Value",
Values = "Values",
Attribute = "Attribute",
Parameter = "Parameter",
Operation = "Operation",
ParameterOperation = "ParameterOperation",
Template = "Template",
Arguments = "Arguments"
}
export type TVector2D = [number, number];
export type TVector3D = [number, number, number];
export type TBBox = [TVector3D, TVector3D];
export type TQuaternion = [number, number, number, number];
export type TFlags = Record<string, bigint>;
export type TExpression = string | [string | RegExp, {
[key: string]: any;
}];
export type TOptions = {
flags?: TFlags | {
[key: string]: any;
};
};
export interface IUrlScheme {
url: string;
options?: {
[key: string]: any;
};
}
export interface IAsset {
urlScheme: IUrlScheme;
options?: {
[key: string]: any;
};
}
export type TSelector = TExpression | [TExpression, {
[key: string]: any;
}];
export interface ITypeInfo {
type: string;
symbol: bigint;
}
export interface IRef {
key: string | string;
struct: {
[key: string]: any;
};
}
export interface IAttribute {
type: ITypeInfo;
value: bigint;
}
export interface IParameter {
type: ITypeInfo;
value: bigint;
}
export interface IParameterOperation {
param1: bigint;
param2: bigint;
operation: bigint;
}
export type TTemplate = string | [ITypeInfo | TSelector, {
[key: string]: any;
}];
export type TArguments = {
[key: string]: any;
} | any[];

140
packages/commons/dist/shemas/types.js vendored Normal file
View File

@ -0,0 +1,140 @@
export var FLAG;
(function (FLAG) {
/**
* Instruct for no additional extra processing
* @constant
* @type int
*/
FLAG[FLAG["NONE"] = 0] = "NONE";
/**
* Will instruct the pre/post processor to base-64 decode or encode
* @constant
* @type int
*/
FLAG[FLAG["BASE_64"] = 1] = "BASE_64";
/**
* Post/Pre process the value with a user function
* @constant
* @type int
*/
FLAG[FLAG["USE_FUNCTION"] = 2] = "USE_FUNCTION";
/**
* Replace variables with local scope's variables during the post/pre process
* @constant
* @type int
*/
FLAG[FLAG["REPLACE_VARIABLES"] = 4] = "REPLACE_VARIABLES";
/**
* Replace variables with local scope's variables during the post/pre process but evaluate the whole string
* as Javascript
* @constant
* @type int
*/
FLAG[FLAG["REPLACE_VARIABLES_EVALUATED"] = 8] = "REPLACE_VARIABLES_EVALUATED";
/**
* Will instruct the pre/post processor to escpape evaluated or replaced variables or expressions
* @constant
* @type int
*/
FLAG[FLAG["ESCAPE"] = 16] = "ESCAPE";
/**
* Will instruct the pre/post processor to replace block calls with oridinary vanilla script
* @constant
* @type int
*/
FLAG[FLAG["REPLACE_BLOCK_CALLS"] = 32] = "REPLACE_BLOCK_CALLS";
/**
* Will instruct the pre/post processor to remove variable delimitters/placeholders from the final string
* @constant
* @type int
*/
FLAG[FLAG["REMOVE_DELIMTTERS"] = 64] = "REMOVE_DELIMTTERS";
/**
* Will instruct the pre/post processor to remove "[" ,"]" , "(" , ")" , "{", "}" , "*" , "+" , "."
* @constant
* @type int
*/
FLAG[FLAG["ESCAPE_SPECIAL_CHARS"] = 128] = "ESCAPE_SPECIAL_CHARS";
/**
* Will instruct the pre/post processor to use regular expressions over string substitution
* @constant
* @type int
*/
FLAG[FLAG["USE_REGEX"] = 256] = "USE_REGEX";
/**
* Will instruct the pre/post processor to use Filtrex (custom bison parser, needs xexpression) over string substitution
* @constant
* @type int
*/
FLAG[FLAG["USE_FILTREX"] = 512] = "USE_FILTREX";
/**
* Cascade entry. There are cases where #USE_FUNCTION is not enough or we'd like to avoid further type checking.
* @constant
* @type int
*/
FLAG[FLAG["CASCADE"] = 1024] = "CASCADE";
/**
* Cascade entry. There are cases where #USE_FUNCTION is not enough or we'd like to avoid further type checking.
* @constant
* @type int
*/
FLAG[FLAG["EXPRESSION"] = 2048] = "EXPRESSION";
/**
* Dont parse anything
* @constant
* @type int
*/
FLAG[FLAG["DONT_PARSE"] = 4096] = "DONT_PARSE";
/**
* Convert to hex
* @constant
* @type int
*/
FLAG[FLAG["TO_HEX"] = 8192] = "TO_HEX";
/**
* Convert to hex
* @constant
* @type int
*/
FLAG[FLAG["REPLACE_HEX"] = 16384] = "REPLACE_HEX";
/**
* Wait for finish
* @constant
* @type int
*/
FLAG[FLAG["WAIT"] = 32768] = "WAIT";
/**
* Wait for finish
* @constant
* @type int
*/
FLAG[FLAG["DONT_ESCAPE"] = 65536] = "DONT_ESCAPE";
/**
* Flag to mark the maximum core bit mask, after here its user land
* @constant
* @type int
*/
FLAG[FLAG["END"] = 131072] = "END";
})(FLAG = FLAG || (FLAG = {}));
export var EType;
(function (EType) {
EType["Number"] = "Number";
EType["String"] = "String";
EType["Boolean"] = "Boolean";
EType["Date"] = "Date";
EType["TimeStamp"] = "TimeStamp";
EType["Duration"] = "Duration";
EType["Url"] = "Url";
EType["UrlScheme"] = "Url-Scheme";
EType["Asset"] = "Asset";
EType["Symbol"] = "Symbol";
EType["Value"] = "Value";
EType["Values"] = "Values";
EType["Attribute"] = "Attribute";
EType["Parameter"] = "Parameter";
EType["Operation"] = "Operation";
EType["ParameterOperation"] = "ParameterOperation";
EType["Template"] = "Template";
EType["Arguments"] = "Arguments";
})(EType = EType || (EType = {}));
//# sourceMappingURL=types.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/shemas/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,IAoHX;AApHD,WAAY,IAAI;IACf;;;;OAIG;IACH,+BAAiB,CAAA;IACjB;;;;OAIG;IACH,qCAAoB,CAAA;IACpB;;;;OAIG;IACH,+CAAyB,CAAA;IACzB;;;;OAIG;IACH,yDAA8B,CAAA;IAC9B;;;;;OAKG;IACH,6EAAwC,CAAA;IACxC;;;;OAIG;IACH,oCAAmB,CAAA;IACnB;;;;OAIG;IACH,8DAAgC,CAAA;IAChC;;;;OAIG;IACH,0DAA8B,CAAA;IAC9B;;;;OAIG;IACH,iEAAiC,CAAA;IACjC;;;;OAIG;IACH,2CAAsB,CAAA;IACtB;;;;OAIG;IACH,+CAAwB,CAAA;IACxB;;;;OAIG;IACH,wCAAoB,CAAA;IACpB;;;;OAIG;IACH,8CAAuB,CAAA;IACvB;;;;OAIG;IACH,8CAAwB,CAAA;IACxB;;;;OAIG;IACH,sCAAoB,CAAA;IACpB;;;;OAIG;IACH,iDAAyB,CAAA;IACzB;;;;OAIG;IACH,mCAAkB,CAAA;IAClB;;;;OAIG;IACH,iDAAyB,CAAA;IACzB;;;;OAIG;IACH,kCAAiB,CAAA;AAClB,CAAC,EApHW,IAAI,GAAJ,IAAI,KAAJ,IAAI,QAoHf;AAED,MAAM,CAAN,IAAY,KAoBX;AApBD,WAAY,KAAK;IAEb,0BAAiB,CAAA;IACjB,0BAAiB,CAAA;IACjB,4BAAmB,CAAA;IACnB,sBAAa,CAAA;IACb,gCAAuB,CAAA;IACvB,8BAAqB,CAAA;IACrB,oBAAW,CAAA;IACX,iCAAwB,CAAA;IACxB,wBAAe,CAAA;IACf,0BAAiB,CAAA;IACjB,wBAAe,CAAA;IACf,0BAAiB,CAAA;IACjB,gCAAuB,CAAA;IACvB,gCAAuB,CAAA;IACvB,gCAAuB,CAAA;IACvB,kDAAyC,CAAA;IACzC,8BAAqB,CAAA;IACrB,gCAAuB,CAAA;AAC3B,CAAC,EApBW,KAAK,GAAL,KAAK,KAAL,KAAK,QAoBhB"}

1
packages/commons/dist/shemas/vfs.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

3
packages/commons/dist/shemas/vfs.js vendored Normal file
View File

@ -0,0 +1,3 @@
export {};
//import { zodToJsonSchema } from "zod-to-json-schema"
//# sourceMappingURL=vfs.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"vfs.js","sourceRoot":"","sources":["../../src/shemas/vfs.ts"],"names":[],"mappings":";AAAA,sDAAsD"}

View File

@ -0,0 +1,46 @@
import { ZodObject, ZodTypeAny } from 'zod';
/**
* Manages a collection of Zod schema properties
* and combines them into a single Zod object schema.
*
* @template MetaType The type of metadata you want to store for each field.
* Defaults to Record<string, unknown> if not provided.
*/
export declare class ZodMetaMap<MetaType = Record<string, unknown>> {
private fieldMap;
/**
* Adds a Zod schema under a specific key (property name),
* optionally attaching typed metadata.
*
* @param key - The name of the property in the root object.
* @param schema - The Zod schema for that property.
* @param metadata - Optional metadata object (type MetaType).
*/
add<T extends ZodTypeAny>(key: string, schema: T, metadata?: MetaType): this;
/**
* Builds and returns a root Zod object
* that combines all properties which were added.
*/
root(): ZodObject<Record<string, ZodTypeAny>>;
/**
* Retrieves the metadata for a specific key, if any.
*/
getMetadata(key: string): MetaType | undefined;
/**
* Static factory method: creates a SchemaMetaManager
* while letting you optionally specify the MetaType.
*
* Usage:
* const manager = SchemaMetaManager.create<MyFieldMeta>();
*/
static create<MT = Record<string, unknown>>(): ZodMetaMap<MT>;
/**
* Returns a basic UiSchema object that RJSF can use to render form controls.
*
* - Adds a top-level "ui:submitButtonOptions" (example).
* - For each field, we set `ui:title` (uppercase key),
* `ui:description` (from Zod's .describe() if available),
* and a naive placeholder from the default value (if parse(undefined) succeeds).
*/
getUISchema(): Record<string, unknown>;
}

102
packages/commons/dist/shemas/zod_map.js vendored Normal file
View File

@ -0,0 +1,102 @@
import { z } from 'zod';
/**
* Manages a collection of Zod schema properties
* and combines them into a single Zod object schema.
*
* @template MetaType The type of metadata you want to store for each field.
* Defaults to Record<string, unknown> if not provided.
*/
export class ZodMetaMap {
fieldMap = new Map();
/**
* Adds a Zod schema under a specific key (property name),
* optionally attaching typed metadata.
*
* @param key - The name of the property in the root object.
* @param schema - The Zod schema for that property.
* @param metadata - Optional metadata object (type MetaType).
*/
add(key, schema, metadata) {
this.fieldMap.set(key, { schema, metadata });
return this;
}
/**
* Builds and returns a root Zod object
* that combines all properties which were added.
*/
root() {
const shape = {};
for (const [key, { schema }] of this.fieldMap.entries()) {
shape[key] = schema;
}
return z.object(shape);
}
/**
* Retrieves the metadata for a specific key, if any.
*/
getMetadata(key) {
return this.fieldMap.get(key)?.metadata;
}
/**
* Static factory method: creates a SchemaMetaManager
* while letting you optionally specify the MetaType.
*
* Usage:
* const manager = SchemaMetaManager.create<MyFieldMeta>();
*/
static create() {
return new ZodMetaMap();
}
/**
* Returns a basic UiSchema object that RJSF can use to render form controls.
*
* - Adds a top-level "ui:submitButtonOptions" (example).
* - For each field, we set `ui:title` (uppercase key),
* `ui:description` (from Zod's .describe() if available),
* and a naive placeholder from the default value (if parse(undefined) succeeds).
*/
getUISchema() {
// Start with some top-level UI schema config (optional)
const uiSchema = {
'ui:submitButtonOptions': {
props: {
disabled: false,
className: 'btn btn-info',
},
norender: false,
submitText: 'Submit',
},
};
for (const [key, { schema }] of this.fieldMap.entries()) {
let fieldUi = {};
// Use the Zod description if available
// (Accessing `._def.description` is private/hacky, but commonly done.)
const sAny = schema;
if (sAny?._def?.description) {
fieldUi['ui:description'] = sAny._def.description;
}
// RJSF usually reads 'title' from JSON schema. But if you want
// to override it in UI schema, you can do so:
fieldUi['ui:title'] = key[0].toUpperCase() + key.substr(1).toLowerCase();
// If the Zod schema allows a default, we can parse(undefined) to get it.
try {
const defaultVal = schema.parse(undefined);
// There's no official 'ui:default' in RJSF, but you could do a placeholder:
fieldUi['ui:placeholder'] = defaultVal;
}
catch {
// no default
}
if (key == 'path') {
debugger;
}
fieldUi = {
...fieldUi,
...this.getMetadata(key),
};
uiSchema[key] = fieldUi;
}
return uiSchema;
}
}
//# sourceMappingURL=zod_map.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"zod_map.js","sourceRoot":"","sources":["../../src/shemas/zod_map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAyB,MAAM,KAAK,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM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AI,EAAE,IAAI,EAAE,WAAW,EAAE;gBACzB,OAAO,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;aACrD;YAED,+DAA+D;YAC/D,8CAA8C;YAC9C,OAAO,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;YAExE,yEAAyE;YACzE,IAAI;gBACA,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gBAC3C,4EAA4E;gBAC5E,OAAO,CAAC,gBAAgB,CAAC,GAAG,UAAU,CAAC;aAC1C;YAAC,MAAM;gBACJ,aAAa;aAChB;YACD,IAAG,GAAG,IAAE,MAAM,EAAC;gBACX,QAAQ,CAAA;aACX;YACD,OAAO,GAAG;gBACN,GAAG,OAAO;gBACV,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;aAC3B,CAAA;YACD,QAAQ,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;SAC3B;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ"}

264
packages/commons/dist/types.d.ts vendored Normal file
View File

@ -0,0 +1,264 @@
export interface IConvertedFileMeta {
photoData: Blob;
objectUrl: string;
name: string;
type: string;
}
export interface IUploadedFileMeta {
downloadUrl: string;
contentType?: string | null;
fullPath: string;
name: string;
type: string;
size: number;
timeCreated: string;
updated: string;
data: any;
}
export type IModerationStatus = 'draft' | 'awaiting-moderation' | 'rejected' | 'accepted';
export interface IModerable {
moderation: IModerationStatus;
_createdBy?: string;
_id?: string;
}
export type ISODateString = string;
export interface IUserState {
user?: IUser;
}
export interface IUser {
_authID: string;
_lastActive?: ISODateString;
userName: string;
displayName: string;
moderation: IModerationStatus;
verified: boolean;
badges?: IUserBadges;
coverImages: IUploadedFileMeta[] | IConvertedFileMeta[];
links: IExternalLink[];
userRoles?: string[];
about?: string | null;
DHSite_id?: number;
DHSite_mention_name?: string;
country?: string | null;
year?: ISODateString;
stats?: IUserStats;
/** keep a map of all howto ids that a user has voted as useful */
votedUsefulHowtos?: {
[howtoId: string]: boolean;
};
/** keep a map of all Research ids that a user has voted as useful */
votedUsefulResearch?: {
[researchId: string]: boolean;
};
notifications?: INotification[];
}
interface IUserBadges {
verified: boolean;
}
interface IExternalLink {
url: string;
label: 'email' | 'website' | 'discord' | 'bazar' | 'forum' | 'social media' | 'facebook' | 'instagram' | 'github' | 'linkedin' | 'map' | 'forum' | 'marketplace' | 'other' | 'other-2';
}
/**
* Track the ids and moderation status as summary for user stats
*/
interface IUserStats {
userCreatedHowtos: {
[id: string]: IModerationStatus;
};
userCreatedResearch: {
[id: string]: IModerationStatus;
};
userCreatedEvents: {
[id: string]: IModerationStatus;
};
}
export type IUserDB = IUser;
export interface INotification {
_id: string;
_created: string;
triggeredBy: {
displayName: string;
userId: string;
};
relevantUrl?: string;
type: NotificationType;
read: boolean;
}
export type NotificationType = 'new_comment' | 'howto_useful' | 'new_comment_research' | 'research_useful';
export type PlasticTypeLabel = 'pet' | 'hdpe' | 'pvc' | 'ldpe' | 'pp' | 'ps' | 'other';
export type MachineBuilderXpLabel = 'electronics' | 'machining' | 'welding' | 'assembling' | 'mould-making' | 'development';
export type WorkspaceType = 'shredder' | 'sheetpress' | 'extrusion' | 'injection' | 'mix' | 'machine shop' | 'service' | 'educational' | 'supplier' | '3dprint';
export type TOSR_User_Type = 'Precious Plastic' | 'OSR-Plastic' | 'Unknown' | 'User Contact' | 'Crawler' | 'Fablab' | 'OSE' | 'Meetup';
export interface IPlasticType {
label: PlasticTypeLabel;
number: string;
imageSrc?: string;
}
export interface IProfileType {
label: string;
imageSrc?: string;
cleanImageSrc?: string;
cleanImageVerifiedSrc?: string;
textLabel?: string;
}
export interface IWorkspaceType {
label: WorkspaceType;
imageSrc?: string;
textLabel?: string;
subText?: string;
}
export interface IMAchineBuilderXp {
label: MachineBuilderXpLabel;
}
export interface IOpeningHours {
day: string;
openFrom: string;
openTo: string;
}
/**
* PP users can have a bunch of custom meta fields depending on profile type
*/
export interface IUserPP extends IUser {
profileType: string;
workspaceType?: WorkspaceType | null;
mapPinDescription?: string | null;
openingHours?: IOpeningHours[];
collectedPlasticTypes?: PlasticTypeLabel[] | null;
machineBuilderXp?: IMAchineBuilderXp[] | null;
isExpert?: boolean | null;
isV4Member?: boolean | null;
}
export type IUserPPDB = IUserPP;
export interface IGeoLocation {
lng: number;
lat: number;
}
export interface IOA_UserDetail {
lastActive: Date;
profilePicUrl: string;
shortDescription: string;
heroImageUrl: string;
name: string;
profileUrl: string;
}
export interface IGeo_Administrative {
name: string;
description: string;
isoName: string;
order: number;
adminLevel: number;
isoCode: string;
wikidataId: string;
geonameId: number;
}
export interface IGeo_Informative {
name: string;
description: string;
order: number;
isoCode: string;
wikidataId: string;
geonameId: number;
}
export interface IGeo_LocalityInfo {
administrative: IGeo_Administrative[];
informative: IGeo_Informative[];
}
export interface IGeo {
latitude: number;
longitude: number;
continent: string;
lookupSource: string;
continentCode: string;
localityLanguageRequested: string;
city: string;
countryName: string;
postcode: string;
countryCode: string;
principalSubdivision: string;
principalSubdivisionCode: string;
plusCode: string;
locality: string;
localityInfo: IGeo_LocalityInfo;
}
export interface IUrl {
name: string;
url: string;
}
export interface IOA_Service {
welding: boolean;
assembling: boolean;
machining: boolean;
electronics: boolean;
molds: boolean;
}
export interface IImage {
url: string;
}
export interface IOSRUserData {
urls: IUrl[];
description: string;
services: IOA_Service[];
title: string;
images: IImage[];
jsError?: boolean;
}
export interface I_OSR_USER {
_created: Date;
location: IGeoLocation;
_modified: Date;
_id: string;
detail: IOA_UserDetail;
type: string;
_deleted: boolean;
moderation: string;
geo: IGeo;
data: IOSRUserData;
}
export interface I_USER_SHORT {
name: string;
email: string;
bazar: string;
web: string;
social: string;
censored: string;
lastActive: Date;
ig: string;
}
export type IProduct = {
slug: string;
name: string;
category: string;
code: string;
forum?: string;
forumCategory?: string;
version?: string;
cart_id?: string;
};
export interface IDiscourseUser {
id: number;
username: string;
name: string;
avatar_template: string;
active: boolean;
admin: boolean;
moderator: boolean;
last_seen_at: any;
last_emailed_at: string;
created_at: string;
last_seen_age: any;
last_emailed_age: number;
created_at_age: number;
trust_level: number;
manual_locked_trust_level: any;
flag_level: number;
title: any;
time_read: number;
staged: boolean;
days_visited: number;
posts_read_count: number;
topics_entered: number;
post_count: number;
}
export * from './osr/component.js';
export * from './types_kbot.js';

3
packages/commons/dist/types.js vendored Normal file
View File

@ -0,0 +1,3 @@
export * from './osr/component.js';
export * from './types_kbot.js';
//# sourceMappingURL=types.js.map

1
packages/commons/dist/types.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAyWE,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA"}

View File

@ -0,0 +1,6 @@
export interface IOptionsCache {
skip?: boolean;
clear?: boolean;
namespace?: string;
cacheRoot?: string;
}

2
packages/commons/dist/types_cache.js vendored Normal file
View File

@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=types_cache.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"types_cache.js","sourceRoot":"","sources":["../src/types_cache.ts"],"names":[],"mappings":""}

114
packages/commons/dist/types_common.d.ts vendored Normal file
View File

@ -0,0 +1,114 @@
export interface GeoPos {
lon: number;
lat: number;
}
export interface PATH_INFO {
DIR?: string;
NAME?: string;
FILE_NAME?: string;
FILE_EXT?: string;
PATH?: string;
IS_FILE?: boolean;
IS_FOLDER?: boolean;
IS_EXPRESSION?: boolean;
IS_GLOB?: boolean;
path: string;
GLOB: string;
GLOB_EXTENSIONS: string[];
FILES: string[];
}
export interface IDeeplConfig {
auth_key: string;
free_api: boolean;
}
export interface IIgConfig {
username: string;
password: string;
}
export interface ICsCartConfigMySQL {
host: string;
user: string;
database: string;
password: string;
}
export interface ICsCartConfig {
token: string;
url: string;
username: string;
siteUrl?: string;
timeout?: number;
language?: string;
userToken?: string;
mysql?: ICsCartConfigMySQL;
}
export interface IGiteaConfig {
token: string;
url: string;
}
export interface IDiscourseConfig {
host: string;
key: string;
username: string;
rateLimitConcurrency: number;
}
export interface IScaleserp {
key: string;
}
export interface IOSRConfig {
deepl: IDeeplConfig;
ig: IIgConfig;
cscart: ICsCartConfig;
discourse: IDiscourseConfig;
discourse_admin: IDiscourseConfig;
instagram: IIgConfig;
urls: any;
scaleserp?: IScaleserp;
gitea?: IGiteaConfig;
}
export interface SRC_VARIABLES {
SRC_PATH: string;
SRC_DIR: string;
SRC_NAME: string;
SRC_FILE_NAME: string;
SRC_FILE_EXT: string;
SRC_IS_FILE: boolean;
SRC_IS_FOLDER: boolean;
SRC_IS_EXPRESSION: boolean;
SRC_IS_GLOB: boolean;
SRC_GLOB: string;
SRC_GLOB_EXTENSIONS: string[];
SRC_FILES: string[];
}
export interface DST_VARIABLES {
DST_PATH: string;
DST_DIR: string;
DST_NAME: string;
DST_FILE_NAME: string;
DST_FILE_EXT: string;
DST_IS_FILE: boolean;
DST_IS_FOLDER: boolean;
DST_IS_EXPRESSION: boolean;
DST_IS_GLOB: boolean;
DST_GLOB: string;
DST_GLOB_EXTENSIONS: string[];
DST_FILES: string[];
}
export type PATH_VARIABLES = SRC_VARIABLES & DST_VARIABLES;
export interface IOptionsBase {
variables: PATH_VARIABLES;
}
export interface PATH_INFO {
DIR?: string;
FILE_EXT?: string;
FILE_NAME?: string;
FILES: string[];
GLOB_EXTENSIONS: string[];
GLOB: string;
IS_EXPRESSION?: boolean;
IS_FILE?: boolean;
IS_FOLDER?: boolean;
IS_GLOB?: boolean;
NAME?: string;
path: string;
PATH?: string;
}

2
packages/commons/dist/types_common.js vendored Normal file
View File

@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=types_common.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"types_common.js","sourceRoot":"","sources":["../src/types_common.ts"],"names":[],"mappings":""}

296
packages/commons/dist/types_gui.d.ts vendored Normal file
View File

@ -0,0 +1,296 @@
/**
* Flags to describe a block's execution behavior.
*
* @enum {integer} module=xide/types/RUN_FLAGS
* @memberOf module=xide/types
*/
export declare enum RUN_FLAGS {
/**
* The block can execute child blocks.
* @constant
* @type int
*/
CHILDREN = 32,
/**
* Block is waiting for a message => EXECUTION_STATE==RUNNING
* @constant
* @type int
*/
WAIT = 32768
}
/**
* Flags to describe a block's execution state.
*
* @enum {integer} module=xide/types/EXECUTION_STATE
* @memberOf module=xide/types
*/
export declare enum EXECUTION_STATE {
/**
* The block is doing nothing and also has done nothing. The is the default state
* @constant
* @type int
*/
NONE = 0,
/**
* The block is running.
* @constant
* @type int
*/
RUNNING = 1,
/**
* The block is an error state.
* @constant
* @type int
*/
ERROR = 2,
/**
* The block is in an paused state.
* @constant
* @type int
*/
PAUSED = 4,
/**
* The block is an finished state, ready to be cleared to "NONE" at the next frame.
* @constant
* @type int
*/
FINISH = 8,
/**
* The block is an stopped state, ready to be cleared to "NONE" at the next frame.
* @constant
* @type int
*/
STOPPED = 16,
/**
* The block has been launched once...
* @constant
* @type int
*/
ONCE = 2147483648,
/**
* Block will be reseted next frame
* @constant
* @type int
*/
RESET_NEXT_FRAME = 8388608,
/**
* Block is locked and so no further inputs can be activated.
* @constant
* @type int
*/
LOCKED = 536870912
}
export declare enum BLOCK_MODE {
NORMAL = 0,
UPDATE_WIDGET_PROPERTY = 1
}
/**
* Flags to describe a block's belonging to a standard signal.
* @enum {integer} module=xblox/types/BLOCK_OUTLET
* @memberOf module=xblox/types
*/
export declare enum BLOCK_OUTLET {
NONE = 0,
PROGRESS = 1,
ERROR = 2,
PAUSED = 4,
FINISH = 8,
STOPPED = 16
}
export declare enum EVENTS {
ON_RUN_BLOCK = "onRunBlock",
ON_RUN_BLOCK_FAILED = "onRunBlockFailed",
ON_RUN_BLOCK_SUCCESS = "onRunBlockSuccess",
ON_BLOCK_SELECTED = "onItemSelected",
ON_BLOCK_UNSELECTED = "onBlockUnSelected",
ON_BLOCK_EXPRESSION_FAILED = "onExpressionFailed",
ON_BUILD_BLOCK_INFO_LIST = "onBuildBlockInfoList",
ON_BUILD_BLOCK_INFO_LIST_END = "onBuildBlockInfoListEnd",
ON_BLOCK_PROPERTY_CHANGED = "onBlockPropertyChanged",
ON_SCOPE_CREATED = "onScopeCreated",
ON_VARIABLE_CHANGED = "onVariableChanged",
ON_CREATE_VARIABLE_CI = "onCreateVariableCI"
}
export declare enum BlockType {
AssignmentExpression = "AssignmentExpression",
ArrayExpression = "ArrayExpression",
BlockStatement = "BlockStatement",
BinaryExpression = "BinaryExpression",
BreakStatement = "BreakStatement",
CallExpression = "CallExpression",
CatchClause = "CatchClause",
ConditionalExpression = "ConditionalExpression",
ContinueStatement = "ContinueStatement",
DoWhileStatement = "DoWhileStatement",
DebuggerStatement = "DebuggerStatement",
EmptyStatement = "EmptyStatement",
ExpressionStatement = "ExpressionStatement",
ForStatement = "ForStatement",
ForInStatement = "ForInStatement",
FunctionDeclaration = "FunctionDeclaration",
FunctionExpression = "FunctionExpression",
Identifier = "Identifier",
IfStatement = "IfStatement",
Literal = "Literal",
LabeledStatement = "LabeledStatement",
LogicalExpression = "LogicalExpression",
MemberExpression = "MemberExpression",
NewExpression = "NewExpression",
ObjectExpression = "ObjectExpression",
Program = "Program",
Property = "Property",
ReturnStatement = "ReturnStatement",
SequenceExpression = "SequenceExpression",
SwitchStatement = "SwitchStatement",
SwitchCase = "SwitchCase",
ThisExpression = "ThisExpression",
ThrowStatement = "ThrowStatement",
TryStatement = "TryStatement",
UnaryExpression = "UnaryExpression",
UpdateExpression = "UpdateExpression",
VariableDeclaration = "VariableDeclaration",
VariableDeclarator = "VariableDeclarator",
WhileStatement = "WhileStatement",
WithStatement = "WithStatement"
}
/**
* Variable Flags
*
* @enum {int} VARIABLE_FLAGS
* @global
*/
export declare enum VARIABLE_FLAGS {
PUBLISH = 2,
PUBLISH_IF_SERVER = 4
}
export declare enum BLOCK_GROUPS {
VARIABLE = "DriverVariable",
BASIC_COMMAND = "DriverBasicCommand",
CONDITIONAL_COMMAND = "DriverConditionalCommand",
RESPONSE_VARIABLE = "DriverResponseVariable",
RESPONSE_BLOCKS = "conditionalProcess",
RESPONSE_VARIABLES = "processVariables",
BASIC_VARIABLES = "basicVariables"
}
export declare enum COMMAND_TYPES {
BASIC_COMMAND = "basic",
CONDITIONAL_COMMAND = "conditional",
INIT_COMMAND = "init"
}
export declare enum CIFLAG {
/**
* Instruct for no additional extra processing
* @constant
* @type int
*/
NONE = 0,
/**
* Will instruct the pre/post processor to base-64 decode or encode
* @constant
* @type int
*/
BASE_64 = 1,
/**
* Post/Pre process the value with a user function
* @constant
* @type int
*/
USE_FUNCTION = 2,
/**
* Replace variables with local scope's variables during the post/pre process
* @constant
* @type int
*/
REPLACE_VARIABLES = 4,
/**
* Replace variables with local scope's variables during the post/pre process but evaluate the whole string
* as Javascript
* @constant
* @type int
*/
REPLACE_VARIABLES_EVALUATED = 8,
/**
* Will instruct the pre/post processor to escpape evaluated or replaced variables or expressions
* @constant
* @type int
*/
ESCAPE = 16,
/**
* Will instruct the pre/post processor to replace block calls with oridinary vanilla script
* @constant
* @type int
*/
REPLACE_BLOCK_CALLS = 32,
/**
* Will instruct the pre/post processor to remove variable delimitters/placeholders from the final string
* @constant
* @type int
*/
REMOVE_DELIMTTERS = 64,
/**
* Will instruct the pre/post processor to remove "[" ,"]" , "(" , ")" , "{", "}" , "*" , "+" , "."
* @constant
* @type int
*/
ESCAPE_SPECIAL_CHARS = 128,
/**
* Will instruct the pre/post processor to use regular expressions over string substitution
* @constant
* @type int
*/
USE_REGEX = 256,
/**
* Will instruct the pre/post processor to use Filtrex (custom bison parser, needs xexpression) over string substitution
* @constant
* @type int
*/
USE_FILTREX = 512,
/**
* Cascade entry. There are cases where #USE_FUNCTION is not enough or we'd like to avoid further type checking.
* @constant
* @type int
*/
CASCADE = 1024,
/**
* Cascade entry. There are cases where #USE_FUNCTION is not enough or we'd like to avoid further type checking.
* @constant
* @type int
*/
EXPRESSION = 2048,
/**
* Dont parse anything
* @constant
* @type int
*/
DONT_PARSE = 4096,
/**
* Convert to hex
* @constant
* @type int
*/
TO_HEX = 8192,
/**
* Convert to hex
* @constant
* @type int
*/
REPLACE_HEX = 16384,
/**
* Wait for finish
* @constant
* @type int
*/
WAIT = 32768,
/**
* Wait for finish
* @constant
* @type int
*/
DONT_ESCAPE = 65536,
/**
* Flag to mark the maximum core bit mask, after here its user land
* @constant
* @type int
*/
END = 131072
}

314
packages/commons/dist/types_gui.js vendored Normal file
View File

@ -0,0 +1,314 @@
/**
* Flags to describe a block's execution behavior.
*
* @enum {integer} module=xide/types/RUN_FLAGS
* @memberOf module=xide/types
*/
export var RUN_FLAGS;
(function (RUN_FLAGS) {
/**
* The block can execute child blocks.
* @constant
* @type int
*/
RUN_FLAGS[RUN_FLAGS["CHILDREN"] = 32] = "CHILDREN";
/**
* Block is waiting for a message => EXECUTION_STATE==RUNNING
* @constant
* @type int
*/
RUN_FLAGS[RUN_FLAGS["WAIT"] = 32768] = "WAIT";
})(RUN_FLAGS = RUN_FLAGS || (RUN_FLAGS = {}));
;
/**
* Flags to describe a block's execution state.
*
* @enum {integer} module=xide/types/EXECUTION_STATE
* @memberOf module=xide/types
*/
export var EXECUTION_STATE;
(function (EXECUTION_STATE) {
/**
* The block is doing nothing and also has done nothing. The is the default state
* @constant
* @type int
*/
EXECUTION_STATE[EXECUTION_STATE["NONE"] = 0] = "NONE";
/**
* The block is running.
* @constant
* @type int
*/
EXECUTION_STATE[EXECUTION_STATE["RUNNING"] = 1] = "RUNNING";
/**
* The block is an error state.
* @constant
* @type int
*/
EXECUTION_STATE[EXECUTION_STATE["ERROR"] = 2] = "ERROR";
/**
* The block is in an paused state.
* @constant
* @type int
*/
EXECUTION_STATE[EXECUTION_STATE["PAUSED"] = 4] = "PAUSED";
/**
* The block is an finished state, ready to be cleared to "NONE" at the next frame.
* @constant
* @type int
*/
EXECUTION_STATE[EXECUTION_STATE["FINISH"] = 8] = "FINISH";
/**
* The block is an stopped state, ready to be cleared to "NONE" at the next frame.
* @constant
* @type int
*/
EXECUTION_STATE[EXECUTION_STATE["STOPPED"] = 16] = "STOPPED";
/**
* The block has been launched once...
* @constant
* @type int
*/
EXECUTION_STATE[EXECUTION_STATE["ONCE"] = 2147483648] = "ONCE";
/**
* Block will be reseted next frame
* @constant
* @type int
*/
EXECUTION_STATE[EXECUTION_STATE["RESET_NEXT_FRAME"] = 8388608] = "RESET_NEXT_FRAME";
/**
* Block is locked and so no further inputs can be activated.
* @constant
* @type int
*/
EXECUTION_STATE[EXECUTION_STATE["LOCKED"] = 536870912] = "LOCKED"; // Block is locked for utilisation in xblox
})(EXECUTION_STATE = EXECUTION_STATE || (EXECUTION_STATE = {}));
export var BLOCK_MODE;
(function (BLOCK_MODE) {
BLOCK_MODE[BLOCK_MODE["NORMAL"] = 0] = "NORMAL";
BLOCK_MODE[BLOCK_MODE["UPDATE_WIDGET_PROPERTY"] = 1] = "UPDATE_WIDGET_PROPERTY";
})(BLOCK_MODE = BLOCK_MODE || (BLOCK_MODE = {}));
;
/**
* Flags to describe a block's belonging to a standard signal.
* @enum {integer} module=xblox/types/BLOCK_OUTLET
* @memberOf module=xblox/types
*/
export var BLOCK_OUTLET;
(function (BLOCK_OUTLET) {
BLOCK_OUTLET[BLOCK_OUTLET["NONE"] = 0] = "NONE";
BLOCK_OUTLET[BLOCK_OUTLET["PROGRESS"] = 1] = "PROGRESS";
BLOCK_OUTLET[BLOCK_OUTLET["ERROR"] = 2] = "ERROR";
BLOCK_OUTLET[BLOCK_OUTLET["PAUSED"] = 4] = "PAUSED";
BLOCK_OUTLET[BLOCK_OUTLET["FINISH"] = 8] = "FINISH";
BLOCK_OUTLET[BLOCK_OUTLET["STOPPED"] = 16] = "STOPPED";
})(BLOCK_OUTLET = BLOCK_OUTLET || (BLOCK_OUTLET = {}));
;
export var EVENTS;
(function (EVENTS) {
EVENTS["ON_RUN_BLOCK"] = "onRunBlock";
EVENTS["ON_RUN_BLOCK_FAILED"] = "onRunBlockFailed";
EVENTS["ON_RUN_BLOCK_SUCCESS"] = "onRunBlockSuccess";
EVENTS["ON_BLOCK_SELECTED"] = "onItemSelected";
EVENTS["ON_BLOCK_UNSELECTED"] = "onBlockUnSelected";
EVENTS["ON_BLOCK_EXPRESSION_FAILED"] = "onExpressionFailed";
EVENTS["ON_BUILD_BLOCK_INFO_LIST"] = "onBuildBlockInfoList";
EVENTS["ON_BUILD_BLOCK_INFO_LIST_END"] = "onBuildBlockInfoListEnd";
EVENTS["ON_BLOCK_PROPERTY_CHANGED"] = "onBlockPropertyChanged";
EVENTS["ON_SCOPE_CREATED"] = "onScopeCreated";
EVENTS["ON_VARIABLE_CHANGED"] = "onVariableChanged";
EVENTS["ON_CREATE_VARIABLE_CI"] = "onCreateVariableCI";
})(EVENTS = EVENTS || (EVENTS = {}));
export var BlockType;
(function (BlockType) {
BlockType["AssignmentExpression"] = "AssignmentExpression";
BlockType["ArrayExpression"] = "ArrayExpression";
BlockType["BlockStatement"] = "BlockStatement";
BlockType["BinaryExpression"] = "BinaryExpression";
BlockType["BreakStatement"] = "BreakStatement";
BlockType["CallExpression"] = "CallExpression";
BlockType["CatchClause"] = "CatchClause";
BlockType["ConditionalExpression"] = "ConditionalExpression";
BlockType["ContinueStatement"] = "ContinueStatement";
BlockType["DoWhileStatement"] = "DoWhileStatement";
BlockType["DebuggerStatement"] = "DebuggerStatement";
BlockType["EmptyStatement"] = "EmptyStatement";
BlockType["ExpressionStatement"] = "ExpressionStatement";
BlockType["ForStatement"] = "ForStatement";
BlockType["ForInStatement"] = "ForInStatement";
BlockType["FunctionDeclaration"] = "FunctionDeclaration";
BlockType["FunctionExpression"] = "FunctionExpression";
BlockType["Identifier"] = "Identifier";
BlockType["IfStatement"] = "IfStatement";
BlockType["Literal"] = "Literal";
BlockType["LabeledStatement"] = "LabeledStatement";
BlockType["LogicalExpression"] = "LogicalExpression";
BlockType["MemberExpression"] = "MemberExpression";
BlockType["NewExpression"] = "NewExpression";
BlockType["ObjectExpression"] = "ObjectExpression";
BlockType["Program"] = "Program";
BlockType["Property"] = "Property";
BlockType["ReturnStatement"] = "ReturnStatement";
BlockType["SequenceExpression"] = "SequenceExpression";
BlockType["SwitchStatement"] = "SwitchStatement";
BlockType["SwitchCase"] = "SwitchCase";
BlockType["ThisExpression"] = "ThisExpression";
BlockType["ThrowStatement"] = "ThrowStatement";
BlockType["TryStatement"] = "TryStatement";
BlockType["UnaryExpression"] = "UnaryExpression";
BlockType["UpdateExpression"] = "UpdateExpression";
BlockType["VariableDeclaration"] = "VariableDeclaration";
BlockType["VariableDeclarator"] = "VariableDeclarator";
BlockType["WhileStatement"] = "WhileStatement";
BlockType["WithStatement"] = "WithStatement";
})(BlockType = BlockType || (BlockType = {}));
;
/**
* Variable Flags
*
* @enum {int} VARIABLE_FLAGS
* @global
*/
export var VARIABLE_FLAGS;
(function (VARIABLE_FLAGS) {
VARIABLE_FLAGS[VARIABLE_FLAGS["PUBLISH"] = 2] = "PUBLISH";
VARIABLE_FLAGS[VARIABLE_FLAGS["PUBLISH_IF_SERVER"] = 4] = "PUBLISH_IF_SERVER";
})(VARIABLE_FLAGS = VARIABLE_FLAGS || (VARIABLE_FLAGS = {}));
;
export var BLOCK_GROUPS;
(function (BLOCK_GROUPS) {
BLOCK_GROUPS["VARIABLE"] = "DriverVariable";
BLOCK_GROUPS["BASIC_COMMAND"] = "DriverBasicCommand";
BLOCK_GROUPS["CONDITIONAL_COMMAND"] = "DriverConditionalCommand";
BLOCK_GROUPS["RESPONSE_VARIABLE"] = "DriverResponseVariable";
BLOCK_GROUPS["RESPONSE_BLOCKS"] = "conditionalProcess";
BLOCK_GROUPS["RESPONSE_VARIABLES"] = "processVariables";
BLOCK_GROUPS["BASIC_VARIABLES"] = "basicVariables";
})(BLOCK_GROUPS = BLOCK_GROUPS || (BLOCK_GROUPS = {}));
;
export var COMMAND_TYPES;
(function (COMMAND_TYPES) {
COMMAND_TYPES["BASIC_COMMAND"] = "basic";
COMMAND_TYPES["CONDITIONAL_COMMAND"] = "conditional";
COMMAND_TYPES["INIT_COMMAND"] = "init";
})(COMMAND_TYPES = COMMAND_TYPES || (COMMAND_TYPES = {}));
;
export var CIFLAG;
(function (CIFLAG) {
/**
* Instruct for no additional extra processing
* @constant
* @type int
*/
CIFLAG[CIFLAG["NONE"] = 0] = "NONE";
/**
* Will instruct the pre/post processor to base-64 decode or encode
* @constant
* @type int
*/
CIFLAG[CIFLAG["BASE_64"] = 1] = "BASE_64";
/**
* Post/Pre process the value with a user function
* @constant
* @type int
*/
CIFLAG[CIFLAG["USE_FUNCTION"] = 2] = "USE_FUNCTION";
/**
* Replace variables with local scope's variables during the post/pre process
* @constant
* @type int
*/
CIFLAG[CIFLAG["REPLACE_VARIABLES"] = 4] = "REPLACE_VARIABLES";
/**
* Replace variables with local scope's variables during the post/pre process but evaluate the whole string
* as Javascript
* @constant
* @type int
*/
CIFLAG[CIFLAG["REPLACE_VARIABLES_EVALUATED"] = 8] = "REPLACE_VARIABLES_EVALUATED";
/**
* Will instruct the pre/post processor to escpape evaluated or replaced variables or expressions
* @constant
* @type int
*/
CIFLAG[CIFLAG["ESCAPE"] = 16] = "ESCAPE";
/**
* Will instruct the pre/post processor to replace block calls with oridinary vanilla script
* @constant
* @type int
*/
CIFLAG[CIFLAG["REPLACE_BLOCK_CALLS"] = 32] = "REPLACE_BLOCK_CALLS";
/**
* Will instruct the pre/post processor to remove variable delimitters/placeholders from the final string
* @constant
* @type int
*/
CIFLAG[CIFLAG["REMOVE_DELIMTTERS"] = 64] = "REMOVE_DELIMTTERS";
/**
* Will instruct the pre/post processor to remove "[" ,"]" , "(" , ")" , "{", "}" , "*" , "+" , "."
* @constant
* @type int
*/
CIFLAG[CIFLAG["ESCAPE_SPECIAL_CHARS"] = 128] = "ESCAPE_SPECIAL_CHARS";
/**
* Will instruct the pre/post processor to use regular expressions over string substitution
* @constant
* @type int
*/
CIFLAG[CIFLAG["USE_REGEX"] = 256] = "USE_REGEX";
/**
* Will instruct the pre/post processor to use Filtrex (custom bison parser, needs xexpression) over string substitution
* @constant
* @type int
*/
CIFLAG[CIFLAG["USE_FILTREX"] = 512] = "USE_FILTREX";
/**
* Cascade entry. There are cases where #USE_FUNCTION is not enough or we'd like to avoid further type checking.
* @constant
* @type int
*/
CIFLAG[CIFLAG["CASCADE"] = 1024] = "CASCADE";
/**
* Cascade entry. There are cases where #USE_FUNCTION is not enough or we'd like to avoid further type checking.
* @constant
* @type int
*/
CIFLAG[CIFLAG["EXPRESSION"] = 2048] = "EXPRESSION";
/**
* Dont parse anything
* @constant
* @type int
*/
CIFLAG[CIFLAG["DONT_PARSE"] = 4096] = "DONT_PARSE";
/**
* Convert to hex
* @constant
* @type int
*/
CIFLAG[CIFLAG["TO_HEX"] = 8192] = "TO_HEX";
/**
* Convert to hex
* @constant
* @type int
*/
CIFLAG[CIFLAG["REPLACE_HEX"] = 16384] = "REPLACE_HEX";
/**
* Wait for finish
* @constant
* @type int
*/
CIFLAG[CIFLAG["WAIT"] = 32768] = "WAIT";
/**
* Wait for finish
* @constant
* @type int
*/
CIFLAG[CIFLAG["DONT_ESCAPE"] = 65536] = "DONT_ESCAPE";
/**
* Flag to mark the maximum core bit mask, after here its user land
* @constant
* @type int
*/
CIFLAG[CIFLAG["END"] = 131072] = "END";
})(CIFLAG = CIFLAG || (CIFLAG = {}));
//# sourceMappingURL=types_gui.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"types_gui.js","sourceRoot":"","sources":["../src/types_gui.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAN,IAAY,SAaX;AAbD,WAAY,SAAS;IACjB;;;;OAIG;IACH,kDAAqB,CAAA;IACrB;;;;OAIG;IACH,6CAAkB,CAAA;AACtB,CAAC,EAbW,SAAS,GAAT,SAAS,KAAT,SAAS,QAapB;AAAA,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAN,IAAY,eAuDX;AAvDD,WAAY,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AACtC,CAAC,EARW,YAAY,GAAZ,YAAY,KAAZ,YAAY,QAQvB;AAAA,CAAC;AAEF,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACrB,wCAAuB,CAAA;IACvB,oDAAmC,CAAA;IACnC,sCAAqB,CAAA;AACzB,CAAC,EAJW,aAAa,GAAb,aAAa,KAAb,aAAa,QAIxB;AAAA,CAAC;AAEF,MAAM,CAAN,IAAY,MAoHX;AApHD,WAAY,MAAM;IACd;;;;OAIG;IACH,mCAAiB,CAAA;IACjB;;;;OAIG;IACH,yCAAoB,CAAA;IACpB;;;;OAIG;IACH,mDAAyB,CAAA;IACzB;;;;OAIG;IACH,6DAA8B,CAAA;IAC9B;;;;;OAKG;IACH,iFAAwC,CAAA;IACxC;;;;OAIG;IACH,wCAAmB,CAAA;IACnB;;;;OAIG;IACH,kEAAgC,CAAA;IAChC;;;;OAIG;IACH,8DAA8B,CAAA;IAC9B;;;;OAIG;IACH,qEAAiC,CAAA;IACjC;;;;OAIG;IACH,+CAAsB,CAAA;IACtB;;;;OAIG;IACH,mDAAwB,CAAA;IACxB;;;;OAIG;IACH,4CAAoB,CAAA;IACpB;;;;OAIG;IACH,kDAAuB,CAAA;IACvB;;;;OAIG;IACH,kDAAwB,CAAA;IACxB;;;;OAIG;IACH,0CAAoB,CAAA;IACpB;;;;OAIG;IACH,qDAAyB,CAAA;IACzB;;;;OAIG;IACH,uCAAkB,CAAA;IAClB;;;;OAIG;IACH,qDAAyB,CAAA;IACzB;;;;OAIG;IACH,sCAAiB,CAAA;AACrB,CAAC,EApHW,MAAM,GAAN,MAAM,KAAN,MAAM,QAoHjB"}

192
packages/commons/dist/types_kbot.d.ts vendored Normal file
View File

@ -0,0 +1,192 @@
export interface IKBotOptions {
/** Path to the project directory */
path?: string;
/** Description of the modifications to make to the project. Supports file paths. */
query?: string;
/** Optional output path for modified files */
output?: string | undefined;
/** Optional destination path for the result, will substitute ${MODEL} and ${ROUTER} in the path */
dst?: string | undefined;
/** Template (typescript) or path to use for processing, see https://git.polymech.io/polymech/ai-template-typescript */
template?: (("typescript") | string) | undefined;
/** Template root directory. When specified, templates are loaded with a prefix, eg: ${POLYMECH-ROOT}/ai-template-${options.template} */
templateRoot?: string;
/** List of template parts to disable. Addionally, tools categories can be disabled, eg: --disable=fs,git,interact,terminal,search,web,email,user */
disable?: string[];
/** List of specific tools to disable */
disableTools?: string[];
/** Glob patterns to match files for processing, comma separated, eg: src/*.tsx,src/*.ts */
glob?: string[] | undefined;
/** AI model to use for processing. Available models:

 OpenRouter models:

google/gemini-pro-1.5-exp | paid
meta-llama/llama-3.2-11b-vision-instruct:free | free
google/gemini-flash-1.5-exp | paid
google/gemini-flash-1.5-8b-exp | paid
microsoft/phi-3-medium-128k-instruct:free | free
microsoft/phi-3-mini-128k-instruct:free | free
google/gemini-2.0-flash-thinking-exp:free | free
google/gemini-2.0-flash-exp:free | free
meta-llama/llama-3.2-1b-instruct | paid
meta-llama/llama-3.2-3b-instruct | paid
meta-llama/llama-3.1-8b-instruct | paid
mistralai/mistral-7b-instruct | paid
mistralai/mistral-7b-instruct-v0.3 | paid
meta-llama/llama-3-8b-instruct | paid
amazon/nova-micro-v1 | paid
google/gemini-flash-1.5-8b | paid
mistralai/ministral-3b | paid
meta-llama/llama-3.2-11b-vision-instruct | paid
amazon/nova-lite-v1 | paid
google/gemini-flash-1.5 | paid
mistralai/ministral-8b | paid
microsoft/phi-3-mini-128k-instruct | paid
microsoft/phi-3.5-mini-128k-instruct | paid
meta-llama/llama-3.1-70b-instruct | paid
nvidia/llama-3.1-nemotron-70b-instruct | paid
deepseek/deepseek-chat | paid
cohere/command-r-08-2024 | paid
mistralai/mistral-nemo | paid
mistralai/pixtral-12b | paid
openai/gpt-4o-mini | paid
openai/gpt-4o-mini-2024-07-18 | paid
mistralai/mistral-7b-instruct-v0.1 | paid
ai21/jamba-1-5-mini | paid
mistralai/mistral-small | paid
qwen/qwen-2.5-72b-instruct | paid
meta-llama/llama-3-70b-instruct | paid
mistralai/mixtral-8x7b-instruct | paid
mistralai/mistral-tiny | paid
mistralai/codestral-mamba | paid
anthropic/claude-3-haiku:beta | paid
anthropic/claude-3-haiku | paid
nousresearch/hermes-3-llama-3.1-70b | paid
cohere/command-r-03-2024 | paid
cohere/command-r | paid
openai/gpt-3.5-turbo-0125 | paid
google/gemini-pro | paid
openai/gpt-3.5-turbo | paid
mistralai/mixtral-8x7b-instruct:nitro | paid
meta-llama/llama-3.1-405b-instruct | paid
amazon/nova-pro-v1 | paid
anthropic/claude-3.5-haiku:beta | paid
anthropic/claude-3.5-haiku | paid
anthropic/claude-3.5-haiku-20241022:beta | paid
anthropic/claude-3.5-haiku-20241022 | paid
microsoft/phi-3-medium-128k-instruct | paid
openai/gpt-3.5-turbo-1106 | paid
openai/gpt-3.5-turbo-0613 | paid
meta-llama/llama-3.2-90b-vision-instruct | paid
google/gemini-pro-1.5 | paid
mistralai/mixtral-8x22b-instruct | paid
mistralai/mistral-large | paid
mistralai/mistral-large-2407 | paid
mistralai/mistral-large-2411 | paid
mistralai/pixtral-large-2411 | paid
ai21/jamba-1-5-large | paid
x-ai/grok-2-1212 | paid
cohere/command-r-plus-08-2024 | paid
openai/gpt-4o | paid
openai/gpt-4o-2024-08-06 | paid
openai/gpt-4o-2024-11-20 | paid
mistralai/mistral-medium | paid
cohere/command-r-plus | paid
cohere/command-r-plus-04-2024 | paid
openai/gpt-3.5-turbo-16k | paid
anthropic/claude-3.5-sonnet:beta | paid
anthropic/claude-3.5-sonnet | paid
anthropic/claude-3-sonnet:beta | paid
anthropic/claude-3-sonnet | paid
anthropic/claude-3.5-sonnet-20240620:beta | paid
anthropic/claude-3.5-sonnet-20240620 | paid
openai/gpt-4o-2024-05-13 | paid
x-ai/grok-beta | paid
x-ai/grok-vision-beta | paid
openai/gpt-4o:extended | paid
openai/gpt-4-turbo | paid
openai/gpt-4-1106-preview | paid
openai/gpt-4-turbo-preview | paid
openai/o1 | paid
anthropic/claude-3-opus:beta | paid
anthropic/claude-3-opus | paid
openai/gpt-4 | paid
openai/gpt-4-0314 | paid
openai/gpt-4-32k-0314 | paid
openai/gpt-4-32k | paid

 OpenAI models:

gpt-4o-audio-preview-2024-10-01
gpt-4o-realtime-preview
gpt-4o-realtime-preview-2024-10-01
o1-mini-2024-09-12
dall-e-2
gpt-4-turbo
gpt-4-1106-preview
gpt-3.5-turbo
gpt-3.5-turbo-0125
gpt-3.5-turbo-instruct
gpt-4-1106-vision-preview
babbage-002
davinci-002
whisper-1
dall-e-3
gpt-4o-mini-2024-07-18
text-embedding-3-small
gpt-4o-mini
gpt-3.5-turbo-16k
gpt-4-0125-preview
gpt-4-turbo-preview
omni-moderation-latest
gpt-4o-2024-05-13
omni-moderation-2024-09-26
tts-1-hd-1106
chatgpt-4o-latest
gpt-4
gpt-4-0613
o1-mini
o1-preview
o1-preview-2024-09-12
tts-1-hd
gpt-4-vision-preview
text-embedding-ada-002
gpt-3.5-turbo-1106
gpt-4o-audio-preview
tts-1
tts-1-1106
gpt-3.5-turbo-instruct-0914
text-embedding-3-large
gpt-4o-realtime-preview-2024-12-17
gpt-4o-mini-realtime-preview
gpt-4o-mini-realtime-preview-2024-12-17
gpt-4o-2024-11-20
gpt-4o-audio-preview-2024-12-17
gpt-4o-mini-audio-preview
gpt-4o-2024-08-06
gpt-4o-mini-audio-preview-2024-12-17
gpt-4o
gpt-4-turbo-2024-04-09
-----
*/
model?: string;
/** Router to use: openai or openrouter */
router?: string;
/** Chat completion type - completion (without tools) or tools (with function calling) */
type?: "completion" | "tools";
/** Logging level for the application */
logLevel?: unknown;
/** Profile for constants */
profile?: string;
/** Environment (in profile) */
env?: string;
/** Configuration as JSON string or path to JSON file, eg: {"openrouter":{"key":"your-key"}} or path/to/config.json */
config?: string | undefined;
/** Write out as script */
dump?: string | undefined;
/** Path to preferences file */
preferences?: string;
/** Logging directory */
logs?: string;
}

2
packages/commons/dist/types_kbot.js vendored Normal file
View File

@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=types_kbot.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"types_kbot.js","sourceRoot":"","sources":["../src/types_kbot.ts"],"names":[],"mappings":""}

11
packages/commons/dist/uri.d.ts vendored Normal file
View File

@ -0,0 +1,11 @@
/// <reference types="node" resolution-mode="require"/>
import { URL } from 'url';
import * as path from 'path';
export interface IDownloadUrl {
urlParts: URL;
pathParts: path.ParsedPath;
filename: string;
path: string;
url: string;
}
export declare const parseForDownload: (url: string, dst: string) => IDownloadUrl;

23
packages/commons/dist/uri.js vendored Normal file
View File

@ -0,0 +1,23 @@
import { URL } from 'url';
import * as path from 'path';
const filenamify = require('filenamify');
const _sanitize = require("sanitize-filename");
const sanitize_ex = (f) => {
let str = filenamify(_sanitize(f)).replace(/[^\x00-\x7F]/g, "").replace('_', '');
return str;
};
export const parseForDownload = (url, dst) => {
const parsed = new URL(url);
const parts = path.parse(parsed.pathname);
const filename = sanitize_ex(decodeURI(parts.base));
const downloadPath = path.resolve(`${dst}/${filename}`);
const downloadUrl = parsed.origin + parsed.pathname;
return {
urlParts: parsed,
pathParts: parts,
filename: filename,
path: downloadPath,
url: downloadUrl
};
};
//# sourceMappingURL=uri.js.map

1
packages/commons/dist/uri.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"uri.js","sourceRoot":"","sources":["../src/uri.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,MAAM,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;AACxC,MAAM,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAA;AAE9C,MAAM,WAAW,GAAG,CAAC,CAAC,EAAE,EAAE;IACtB,IAAI,GAAG,GAAW,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACzF,OAAO,GAAG,CAAC;AACf,CAAC,CAAA;AAUD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAE,GAAW,EAAiB,EAAE;IAExE,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAEzC,MAAM,QAAQ,GAAG,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IACnD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,GAAG,IAAI,QAAQ,EAAE,CAAC,CAAA;IACvD,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAA;IAEnD,OAAO;QACH,QAAQ,EAAC,MAAM;QACf,SAAS,EAAE,KAAK;QAChB,QAAQ,EAAE,QAAQ;QAClB,IAAI,EAAE,YAAY;QAClB,GAAG,EAAE,WAAW;KACnB,CAAA;AACL,CAAC,CAAA"}

12
packages/commons/dist/variables.d.ts vendored Normal file
View File

@ -0,0 +1,12 @@
export declare const DATE_VARS: () => {
YYYY: number;
MM: number;
DD: number;
HH: number;
SS: number;
};
export declare const _substitute: (template: any, map: Record<string, any>, keep?: boolean, alt?: boolean) => any;
export declare const substitute: (alt: boolean, template: string, vars?: Record<string, any>, keep?: boolean) => any;
export declare const DEFAULT_VARS: (vars: any) => any;
export declare const resolveVariables: (_path: string, alt?: boolean, vars?: Record<string, string>) => any;
export declare const resolve: (_path: string, alt?: boolean, vars?: Record<string, string>) => any;

39
packages/commons/dist/variables.js vendored Normal file
View File

@ -0,0 +1,39 @@
import { REGEX_VAR, REGEX_VAR_ALT } from "@polymech/core/constants.js";
import { DEFAULT_ROOTS } from '@/config.js';
export const DATE_VARS = () => {
return {
YYYY: new Date(Date.now()).getFullYear(),
MM: new Date(Date.now()).getMonth() + 1,
DD: new Date(Date.now()).getDate(),
HH: new Date(Date.now()).getHours(),
SS: new Date(Date.now()).getSeconds()
};
};
export const _substitute = (template, map, keep = true, alt = false) => {
const transform = (k) => k || '';
return template.replace(alt ? REGEX_VAR_ALT : REGEX_VAR, (match, key, format) => {
if (map[key]) {
return transform(map[key]).toString();
}
else if (map[key.replace(/-/g, '_')]) {
return transform(map[key.replace(/-/g, '_')]).toString();
}
else if (keep) {
return "${" + key + "}";
}
else {
return "";
}
});
};
export const substitute = (alt, template, vars = {}, keep = true) => alt ? _substitute(template, vars, keep, alt) : _substitute(template, vars, keep, alt);
export const DEFAULT_VARS = (vars) => {
return {
...DEFAULT_ROOTS,
...DATE_VARS(),
...vars
};
};
export const resolveVariables = (_path, alt = false, vars = {}) => substitute(alt, _path, DEFAULT_VARS(vars));
export const resolve = (_path, alt = false, vars = {}) => resolveVariables(_path, alt, vars);
//# sourceMappingURL=variables.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"variables.js","sourceRoot":"","sources":["../src/variables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE;IAC1B,OAAO;QACH,IAAI,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE;QACxC,EAAE,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC;QACvC,EAAE,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE;QAClC,EAAE,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE;QACnC,EAAE,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,E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E;IACtC,OAAO;QACH,GAAG,aAAa;QAChB,GAAG,SAAS,EAAE;QACd,GAAG,IAAI;KACV,CAAA;AACL,CAAC,CAAA;AACD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAE,MAAe,KAAK,EAAE,OAA+B,EAAE,EAAE,EAAE,CACvG,UAAU,CAAC,GAAG,EAAE,KAAK,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC,CAAA;AAE9C,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAa,EAAE,MAAe,KAAK,EAAE,OAA+B,EAAE,EAAE,EAAE,CAC9F,gBAAgB,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA"}

View File

@ -6,18 +6,31 @@
"publishConfig": {
"access": "public"
},
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./variables": {
"import": "./dist/variables.js",
"require": "./dist/variables.cjs"
},
"./types": {
"import": "./dist/types.js",
"require": "./dist/types.cjs"
},
"./schemas": {
"import": "./dist/schemas/index.js",
"require": "./dist/schemas/index.cjs"
}
},
"licenses": [
{
"type": "BSD",
"url": "https://git.osr-plastic.org/osr-plastic/osr-core/blob/master/LICENSE"
}
],
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"main": "dist/index.js",
"repository": {
"type": "git",
@ -25,11 +38,16 @@
},
"types": "index.d.ts",
"dependencies": {
"@polymech/core": "workspace:*",
"@polymech/fs": "workspace:*",
"env-var": "^7.5.0",
"glob": "^10.4.1",
"tslog": "^3.3.3",
"tsup": "^8.3.5",
"yargs": "^17.7.2",
"zod": "^3.24.1",
"@polymech/fs": "workspace:*",
"@polymech/core": "workspace:*"
"zod-to-json-schema": "^3.24.1",
"zod-to-ts": "^1.2.0"
},
"devDependencies": {
"@eslint/js": "^9.18.0",

View File

@ -0,0 +1,96 @@
import * as path from 'path'
// import * as isGlob from 'is-glob'
// import * as fg from 'fast-glob'
import { glob, globSync, GlobOptions, hasMagic } from 'glob'
import { REGEX_VAR, REGEX_VAR_ALT } from "@polymech/core/constants.js"
import { sync as exists } from '@polymech/fs/exists'
export const files = (cwd, glob, options?: any) => globSync(glob, { ...{ dot: true, cwd, absolute: true, caseSensitiveMatch: false }, ...options || {} }) as []
export const filesEx = (cwd, glob, options?: GlobOptions) => globSync(glob, { ...{ dot: true, cwd, absolute: true, caseSensitiveMatch: false }, ...options || {} }) as []
import { substitute } from '@/variables.js'
import { isFile, isFolder, getExtensions } from '@/fs.js'
import { PATH_INFO } from '@/types_common.js'
const globBase = require('glob-base')
export const forward_slash = (path) => {
const isExtendedLengthPath = /^\\\\\?\\/.test(path)
const hasNonAscii = /[^\u0000-\u0080]+/.test(path)
if (isExtendedLengthPath || hasNonAscii) {
return path;
}
return path.replace(/\\/g, '/')
}
export const pathInfoEx = (src: string, altToken: boolean = false, globOptions: GlobOptions = {}): PATH_INFO => {
const srcParts = path.parse(src)
let variables: PATH_INFO = {
PATH: src
} as PATH_INFO
variables.DIR = srcParts.dir
variables.NAME = srcParts.name
variables.FILE_NAME = srcParts.base
variables.FILE_EXT = srcParts.ext.replace('.', '')
variables.PATH = src
variables.IS_FILE = isFile(src)
variables.IS_FOLDER = isFolder(src)
variables.IS_EXPRESSION = src.match(altToken ? REGEX_VAR_ALT : REGEX_VAR) != null
if (!variables.IS_FOLDER && !variables.IS_FILE) {
variables.IS_GLOB = hasMagic(substitute(altToken, srcParts.base, {}, false))
} else {
variables.IS_GLOB = false
}
if (variables.IS_GLOB) {
//important: use the forward slash since path.resolve will return backslashes on Windows
const glob_base = globBase(src)
variables.DIR = path.resolve(glob_base.base)
variables.FILE_NAME = glob_base.glob
variables.GLOB = glob_base.glob
variables.GLOB_EXTENSIONS = getExtensions(glob_base.glob)
globOptions = {
...globOptions,
cwd: globOptions.cwd ? path.join(globOptions.cwd as string, glob_base.base) : null
}
variables.FILES = glob.sync(glob_base.glob, globOptions) as []
} else if (variables.IS_FILE && exists(src)) {
variables.FILES = [src]
}
return variables
}
export const pathInfo = (src: string, altToken: boolean = false, cwd: string = null): PATH_INFO => {
const srcParts = path.parse(src)
let variables: PATH_INFO = {
PATH: src
} as PATH_INFO
variables.DIR = srcParts.dir
variables.NAME = srcParts.name
variables.FILE_NAME = srcParts.base
variables.FILE_EXT = srcParts.ext.replace('.', '')
variables.PATH = src
variables.IS_FILE = isFile(src)
variables.IS_FOLDER = isFolder(src)
variables.IS_EXPRESSION = src.match(altToken ? REGEX_VAR_ALT : REGEX_VAR) != null
if (!variables.IS_FOLDER && !variables.IS_FILE) {
variables.IS_GLOB = hasMagic(srcParts.base)
} else {
variables.IS_GLOB = false
}
if (variables.IS_GLOB) {
const glob_base = globBase(src)
variables.DIR = path.resolve(glob_base.base)
variables.FILE_NAME = glob_base.glob
variables.GLOB = glob_base.glob
variables.GLOB_EXTENSIONS = getExtensions(glob_base.glob)
variables.FILES = globSync(glob_base.glob, {
dot: true,
cwd: path.resolve(cwd || variables.DIR),
absolute: true
})
} else if (variables.IS_FILE && exists(src)) {
variables.FILES = [src]
}
return variables
}

View File

@ -0,0 +1,59 @@
import * as env from 'env-var'
import { sync as read } from '@polymech/fs/read'
import { sync as exists } from '@polymech/fs/exists'
import * as path from 'path'
export const API_PREFIX = 'osr'
export const API_PREFIX_NEXT = 'polymech'
export const HOME = (sub = '') => path.join(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], sub)
export const get_var = (key: string ='') => env.get(key).asString() || env.get(key.replace(/-/g, '_')).asString() || env.get(key.replace(/_/g, '-')).asString()
export const OSR_ROOT = (key: string = 'OSR-ROOT') => get_var(key) || path.join(HOME('desktop'), API_PREFIX)
export const OSR_SUB_DEFAULT = (key: string = '') => get_var(key) || path.join(OSR_ROOT(), key)
export const CONFIG_DEFAULT_PATH = (key: string = 'OSR-CONFIG') => get_var(key) || path.join(HOME(`${API_PREFIX}`), '.config.json')
export const OSR_TEMP = (key: string = 'OSR-TEMP') => get_var(key) || OSR_SUB_DEFAULT(`.${API_PREFIX}/temp`)
export const OSR_CACHE = (key: string = 'OSR-CACHE') => get_var(key) || OSR_SUB_DEFAULT(`.${API_PREFIX}/cache`)
export const OSR_PRIVATE = (key: string = 'OSR-PRIVATE') => get_var(key)
export const KB_ROOT = (key: string = 'OSR-KB') => get_var(key)
export const OSR_LIBRARY = (key: string = 'OSR-LIBRARY') => get_var(key)
export const OSR_LIBRARY_MACHINES = (key: string = 'OSR-LIBRARY-MACHINES') => get_var(key)
export const OSR_LIBRARY_DIRECTORY = (key: string = 'OSR-LIBRARY-DIRECTORY') => get_var(key)
export const PRODUCT_ROOT = (key: string = 'PRODUCT-ROOT') => get_var(key)
export const OSR_CUSTOMER_DRIVE = (key: string = 'OSR-CUSTOMER-DRIVE') => get_var(key)
export const OA_ROOT = (key: string = 'OA-ROOT') => get_var(key)
export const OSR_USER_ASSETS = (key: string = 'OSR-USER-ASSETS') => get_var(key)
export const POLYMECH_ROOT = (key: string = 'POLYMECH-ROOT') => get_var(key) || path.join(HOME('desktop'), API_PREFIX_NEXT)
export const DEFAULT_ROOTS = {
OSR_ROOT: OSR_ROOT(),
OSR_TEMP: OSR_TEMP(),
PRODUCT_ROOT: PRODUCT_ROOT(),
OA_ROOT: OA_ROOT(),
KB_ROOT: KB_ROOT(),
OSR_CACHE: OSR_CACHE(),
OSR_LIBRARY: OSR_LIBRARY(),
OSR_LIBRARY_MACHINES: OSR_LIBRARY_MACHINES(),
OSR_LIBRARY_DIRECTORY: OSR_LIBRARY_DIRECTORY(),
OSR_USER_ASSETS: OSR_USER_ASSETS(),
OSR_PRIVATE: OSR_PRIVATE(),
OSR_TEMPLATES: path.join(OSR_SUB_DEFAULT('osr-templates')),
OSR_CONTENT: path.join(OSR_SUB_DEFAULT('osr-content')),
OSR_PROFILES: path.join(OSR_SUB_DEFAULT('osr-profiles')),
OSR_CUSTOMER_DRIVE: OSR_CUSTOMER_DRIVE(),
POLYMECH_ROOT: POLYMECH_ROOT()
}
export const CONFIG_DEFAULT = (key: string = 'OSR-CONFIG') => {
const cPath = path.resolve(CONFIG_DEFAULT_PATH(key));
if (exists(cPath)) {
return read(cPath, 'json');
}
return false;
}

View File

@ -0,0 +1,14 @@
export const MODULE_NAME = `OSR-Commons`
export const PROFILE_FILE_NAME = `.osrl.json`
////////////////////////////////////////
//
// OA Migration
export const OA_LATEST = '${OSR_ROOT}/osr-directory/pp/${YYYY}_${MM}.json'
export const OA_LATEST_INVALID = '${OSR_ROOT}/osr-directory/pp/${YYYY}_${MM}_INVALID.json'
export const OA_LATEST_CENSORED = '${OSR_ROOT}/osr-directory/pp/${YYYY}_${MM}_CENSORED.json'
export const OA_LATEST_MERGED = '${OSR_ROOT}/osr-directory/pp/${YYYY}_${MM}_MERGED.json'
// fecking bazar
export const PP_BAZAR_LATEST_INDEX = '${OSR_ROOT}/pp-bazar/${YYYY}/${MM}/index.json'
export const PP_BAZAR_LATEST_INDEX_MERGED = '${OSR_ROOT}/pp-bazar/${YYYY}/${MM}/index_merged.json'

View File

@ -0,0 +1,50 @@
import * as fs from 'fs'
// https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#namespaces
// https://github.com/isaacs/node-glob/blob/main/src/pattern.ts
export const GLOB_GROUP_PATTERN = /[!*+?@]\(.*\)/
export const UNC_REGEX = /^[\\\/]{2,}[^\\\/]+[\\\/]+[^\\\/]+/
export const WIN32_PATH_REGEX = /^([a-z]:)?[\\\/]/i
import { is_windows } from './os.js'
const parseGlob = require('parse-glob')
export const getExtensions = (glob: string) => {
const match = glob.match(GLOB_GROUP_PATTERN);
if (match) {
return glob.substring((match.index || 0) + 2, glob.lastIndexOf(')')).split('|')
} else {
return [parseGlob(glob).path.ext]
}
}
export const isFile = (src: string) => {
let srcIsFile = false;
try {
srcIsFile = fs.lstatSync(src).isFile()
} catch (e) { }
return srcIsFile
}
export const isFolder = (src: string) => {
let srcIsFolder = false;
try {
srcIsFolder = fs.lstatSync(src).isDirectory()
} catch (e) { }
return srcIsFolder;
}
const is_relative_win32 = (fp) => !fp.test(UNC_REGEX) && !WIN32_PATH_REGEX.test(fp)
const is_absolute_posix = (fp) => fp.charAt(0) === '/'
const is_absolute_win32 = (fp) => {
if (/[a-z]/i.test(fp.charAt(0)) && fp.charAt(1) === ':' && fp.charAt(2) === '\\') {
return true
}
// Microsoft Azure absolute filepath
if (fp.slice(0, 2) === '\\\\') {
return true;
}
return !is_relative_win32(fp)
}
export const is_absolute = (fp) => is_windows() ? is_absolute_win32(fp) : is_absolute_posix(fp)

View File

@ -0,0 +1,16 @@
import * as fs from 'fs'
export const isFile = (src: string) => {
let srcIsFile = false;
try {
srcIsFile = fs.lstatSync(src).isFile()
} catch (e) { }
return srcIsFile
}
export const isFolder = (src: string) => {
let srcIsFolder = false;
try {
srcIsFolder = fs.lstatSync(src).isDirectory()
} catch (e) { }
return srcIsFolder;
}

View File

@ -0,0 +1,3 @@
export * from './strings.js'
export * from './fs.js'

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,17 @@
import { ISettingsParam, Logger } from "tslog"
export function createLogger(name: string, options?: any) {
return new Logger({
name,
type: 'pretty',
...options,
})
}
export const defaultLogger = createLogger('DefaultLogger', {
minLevel: 1
})
import { MODULE_NAME } from './constants.js'
export { MODULE_NAME } from './constants.js'
export const logger = createLogger(MODULE_NAME, {})

View File

@ -0,0 +1,10 @@
export enum EPlatform {
Linux = 'linux',
Windows = 'win32',
OSX = 'darwin'
}
export enum EArch {
x64 = '64',
x32 = '32'
}
export const is_windows = () => process && (process.platform === 'win32')

View File

@ -0,0 +1,102 @@
import { IDiscourseUploadImage } from './discourse.js'
export interface IDiscourseItemCommons {
// Discourse
forum?: string | boolean
// explicit forum title, otherwise #name will be used
forumTitle?: string
// linked Discourse category
forumCategory?: number
// Discourse tags
forumTags?: string | string[]
// Discourse post_id
forumPostId?: number
// Discourse topic_id
forumTopicId?: number
// Discourse owner id
forumUserId?: number
// Discourse owner username
forumUserName?: string
// last content hash
forumPostHash?: string
// map of Discourse uploads (internal uri > discourse upload uri)
forumUploads?: Record<string,IDiscourseUploadImage>
}
export interface IComponentConfig extends IDiscourseItemCommons {
//CS-Cart
cart_id?: string
code: string
price?: number
cscartCats?: number[]
cscartId?: number
vendorId?: number
//OSR internal
version?: string
status?: string
authors: IAuthor[]
// outdated and replaced by (using slug)
replaced_by?: string
// alternative components (using slug)
alternatives?: string[]
// internal processing flags
flags?: number
//related Discourse howto categories
howto_categories?: string | string[]
//content source language code (ISO)
sourceLanguage?: string
//last sync timestamp
last_sync_ts?: number
//OSR public
// explicit download url, otherwise default expression
download?: boolean
// explicit 3d preview url, otherwise default expression
edrawings?: string
// human readable title (used for Discourse and CSCart)
name: string
// content visibility features (used for Discourse and CSCart)
showDimensions?: boolean
showParts?: boolean
slug: string
score?: number
Preview3d?: boolean
keywords?: string
meta_keywords?: string
// kb
steps?: any
/**
* @deprecated
*/
category: string
product_dimensions?: string
production?: IProduction
}
export interface IAuthor {
name: string
url: string
}
export interface IProduction {
"fusion-folder": string
"nc-folder": string
cam: IAuthor[]
}

View File

@ -0,0 +1,15 @@
export interface IDiscourseUploadImage {
id: number
url: string
original_filename: string
filesize: number
width: number
height: number
thumbnail_width: number
thumbnail_height: number
extension: string
short_url: string
short_path: string
retain_hours: any
human_filesize: string
}

View File

View File

@ -0,0 +1,98 @@
import * as path from 'path'
import { REGEX_VAR } from "@polymech/core/constants.js"
import { sync as read } from '@polymech/fs/read'
import { sync as exists } from '@polymech/fs/exists'
import { isString } from '@polymech/core/types.js'
import { resolve, substitute } from './variables.js'
interface EnvVariables {
[key: string]: string
}
interface EnvConfig {
includes: string[]
variables: EnvVariables
}
export interface IProfile {
includes: string[]
variables: EnvVariables
env: {
[key: string]: EnvConfig
}
}
const _resolve = (config) => {
for (const key in config) {
if (config[key] && typeof config[key] == 'string') {
const resolved = substitute(false, config[key], config)
config[key] = resolved
}
}
return config;
}
// @todo: Implement the function `resolveConfig`
export const resolveConfig = (config) => {
config = _resolve(config)
config = _resolve(config)
return config
}
export const parseProfile = (profilePath: string, profile: IProfile, options: { env: string } = { env: 'default' }, rel?: string) => {
profilePath = path.resolve(resolve(profilePath, false, profile.variables))
if (!exists(profilePath as string)) {
return
}
const _profile = read(profilePath as string, 'json') as any || { includes: [], variables: {} } as IProfile
_profile.includes = _profile.includes || []
_profile.variables = _profile.variables || {}
if (options.env && _profile.env && _profile.env[options.env] && _profile.env[options.env].includes) {
profile.includes = [
...profile.includes,
..._profile.includes,
..._profile.env[options.env].includes
]
} else {
profile.includes = [
...profile.includes,
..._profile.includes
]
}
if (options.env && _profile.env && _profile.env[options.env] && _profile.env[options.env].variables) {
profile.variables = {
...profile.variables,
..._profile.variables,
..._profile.env[options.env].variables
}
}
for (const k in _profile.variables) {
if (isString(_profile.variables[k])) {
_profile.variables[k] = substitute(false, _profile.variables[k], profile.variables)
}
}
profile.variables = { ...profile.variables, ..._profile.variables, ..._profile.env[options.env]?.variables || {} }
for (const k in profile.variables) {
if (isString(profile.variables[k])) {
profile.variables[k] = substitute(false, profile.variables[k], profile.variables)
}
}
profile.includes = Array.from(new Set(profile.includes))
profile.includes = [
...profile.includes.map((i) => {
if (!path.isAbsolute(i) && rel && !i.match(REGEX_VAR)) {
return path.resolve(`${rel}/${i}`)
}
let ret = resolve(i, false, profile.variables)
ret = path.resolve(substitute(false, ret, profile.variables))
return ret
})]
profile.includes = profile.includes.filter((include) =>
include !== null &&
include !== '')
profile.includes = Array.from(new Set(profile.includes))
return profile
}

View File

@ -1,10 +1,13 @@
import * as path from 'node:path'
import * as path from 'path'
import * as CLI from 'yargs'
import { z, ZodTypeAny, ZodObject, ZodEffects, ZodOptional, ZodDefault } from 'zod'
import { sync as writeFS } from '@polymech/fs/write'
import { zodToTs, printNode } from 'zod-to-ts'
import { zodToJsonSchema } from "zod-to-json-schema"
import { logger } from '../logger'
import { logger } from '@/logger.js'
export * from './path.js'
export * from './zod_map.js'
type InnerType<T> = T extends ZodEffects<infer U> ? InnerType<U> : T
@ -14,7 +17,6 @@ type GetInnerType<T extends ZodTypeAny> = T extends ZodObject<any>
? InnerType<T>
: never;
export * from './path'
export const generate_interfaces = (schemas: ZodObject<any>[], dst: string) => {
const types = schemas.map(schema => `export interface ${schema.description || 'IOptions'} ${printNode(zodToTs(schema).node)}`)
@ -215,4 +217,4 @@ export const combineValidatorsOrUsingZod2 = (validators: z.ZodTypeAny[]) => {
})
})
}
export * from './zod_map'

View File

@ -2,18 +2,17 @@ import { z, ZodTypeAny } from 'zod'
import * as path from 'path'
import { accessSync, constants, lstatSync, existsSync } from 'fs'
import { isString } from '@polymech/'
import { isString } from '@polymech/core/primitives.js'
import { logger } from '../logger'
import { logger } from '@/logger.js'
import { sync as exists } from '@polymech/fs/exists'
import { sync as read } from '@polymech/fs/read'
import { DEFAULT_VARS, resolve, resolveVariables } from '../variables'
import { getDescription } from '../'
import { isFile } from '../lib/fs'
import { DEFAULT_VARS, resolve, resolveVariables } from '@/variables.js'
import { getDescription } from '@/shemas/index.js'
import { isFile } from '@/lib/fs.js'
type TResult = { resolved: string, source: string, value: unknown }
type TRefine = (src: string, ctx: any, variables: Record<string, string>) => string | z.ZodNever
@ -41,7 +40,7 @@ export enum E_PATH {
ENSURE_PATH_IS_RELATIVE,
GET_PATH_INFO
}
export const Transformers = {
export const Transformers:Record<string,any> = {
resolve: (val: string, variables: Record<string, string> = {}) => {
if (!val) {
return null
@ -238,7 +237,7 @@ export const test = () => {
return ret
}
export const Templates =
export const Templates:Record<string,any> =
{
json: {
refine: [IS_VALID_STRING, ENSURE_PATH_EXISTS],

View File

@ -0,0 +1,365 @@
export interface IConvertedFileMeta {
photoData: Blob
objectUrl: string
name: string
type: string
}
export interface IUploadedFileMeta {
downloadUrl: string
contentType?: string | null
fullPath: string
name: string
type: string
size: number
timeCreated: string
updated: string
data: any
}
// Types for moderation status
export type IModerationStatus =
| 'draft'
| 'awaiting-moderation'
| 'rejected'
| 'accepted'
export interface IModerable {
moderation: IModerationStatus
_createdBy?: string
_id?: string
}
export type ISODateString = string;
export interface IUserState {
user?: IUser
}
// IUser retains most of the fields from legacy users (omitting passwords),
// and has a few additional fields. Note 'email' is excluded
// _uid is unique/fixed identifier
// ALL USER INFO BELOW IS PUBLIC
export interface IUser {
// authID is additional id populated by firebase auth, required for some auth operations
_authID: string
_lastActive?: ISODateString
// userName is same as legacy 'mention_name', e.g. @my-name. It will also be the doc _id and
// firebase auth displayName property
userName: string
displayName: string
moderation: IModerationStatus
// note, user avatar url is taken direct from userName so no longer populated here
// avatar:string
verified: boolean
badges?: IUserBadges
// images will be in different formats if they are pending upload vs pulled from db
coverImages: IUploadedFileMeta[] | IConvertedFileMeta[]
links: IExternalLink[]
userRoles?: string[]
about?: string | null
DHSite_id?: number
DHSite_mention_name?: string
country?: string | null
// location?: ILocation | null
year?: ISODateString
stats?: IUserStats
/** keep a map of all howto ids that a user has voted as useful */
votedUsefulHowtos?: { [howtoId: string]: boolean }
/** keep a map of all Research ids that a user has voted as useful */
votedUsefulResearch?: { [researchId: string]: boolean }
notifications?: INotification[]
}
interface IUserBadges {
verified: boolean
}
interface IExternalLink {
url: string
label:
| 'email'
| 'website'
| 'discord'
| 'bazar'
| 'forum'
| 'social media'
| 'facebook'
| 'instagram'
| 'github'
| 'linkedin'
| 'map'
| 'forum'
| 'marketplace'
| 'other'
| 'other-2'
}
/**
* Track the ids and moderation status as summary for user stats
*/
interface IUserStats {
userCreatedHowtos: { [id: string]: IModerationStatus }
userCreatedResearch: { [id: string]: IModerationStatus }
userCreatedEvents: { [id: string]: IModerationStatus }
}
export type IUserDB = IUser;
export interface INotification {
_id: string
_created: string
triggeredBy: {
displayName: string
userId: string
}
relevantUrl?: string
type: NotificationType
read: boolean
}
export type NotificationType =
| 'new_comment'
| 'howto_useful'
| 'new_comment_research'
| 'research_useful'
export type PlasticTypeLabel =
| 'pet'
| 'hdpe'
| 'pvc'
| 'ldpe'
| 'pp'
| 'ps'
| 'other'
export type MachineBuilderXpLabel =
| 'electronics'
| 'machining'
| 'welding'
| 'assembling'
| 'mould-making'
| 'development'
export type WorkspaceType =
| 'shredder'
| 'sheetpress'
| 'extrusion'
| 'injection'
| 'mix'
| 'machine shop'
| 'service'
| 'educational'
| 'supplier'
| '3dprint'
export type TOSR_User_Type =
| 'Precious Plastic'
| 'OSR-Plastic'
| 'Unknown'
| 'User Contact'
| 'Crawler'
| 'Fablab'
| 'OSE'
| 'Meetup'
export interface IPlasticType {
label: PlasticTypeLabel
number: string
imageSrc?: string
}
export interface IProfileType {
label: string;
imageSrc?: string
cleanImageSrc?: string
cleanImageVerifiedSrc?: string
textLabel?: string
}
export interface IWorkspaceType {
label: WorkspaceType
imageSrc?: string
textLabel?: string
subText?: string
}
export interface IMAchineBuilderXp {
label: MachineBuilderXpLabel
}
export interface IOpeningHours {
day: string
openFrom: string
openTo: string
}
/**
* PP users can have a bunch of custom meta fields depending on profile type
*/
export interface IUserPP extends IUser {
profileType: string;
workspaceType?: WorkspaceType | null
mapPinDescription?: string | null
openingHours?: IOpeningHours[]
collectedPlasticTypes?: PlasticTypeLabel[] | null
machineBuilderXp?: IMAchineBuilderXp[] | null
isExpert?: boolean | null
isV4Member?: boolean | null
}
export type IUserPPDB = IUserPP;
///////////////////////////////////////////////////////////////////
//
// OSR Specific Namespace
export interface IGeoLocation {
lng: number;
lat: number;
}
export interface IOA_UserDetail {
lastActive: Date;
profilePicUrl: string;
shortDescription: string;
heroImageUrl: string;
name: string;
profileUrl: string;
}
export interface IGeo_Administrative {
name: string;
description: string;
isoName: string;
order: number;
adminLevel: number;
isoCode: string;
wikidataId: string;
geonameId: number;
}
export interface IGeo_Informative {
name: string;
description: string;
order: number;
isoCode: string;
wikidataId: string;
geonameId: number;
}
export interface IGeo_LocalityInfo {
administrative: IGeo_Administrative[];
informative: IGeo_Informative[];
}
export interface IGeo {
latitude: number;
longitude: number;
continent: string;
lookupSource: string;
continentCode: string;
localityLanguageRequested: string;
city: string;
countryName: string;
postcode: string;
countryCode: string;
principalSubdivision: string;
principalSubdivisionCode: string;
plusCode: string;
locality: string;
localityInfo: IGeo_LocalityInfo;
}
export interface IUrl {
name: string;
url: string;
}
export interface IOA_Service {
welding: boolean;
assembling: boolean;
machining: boolean;
electronics: boolean;
molds: boolean;
}
export interface IImage {
url: string;
}
export interface IOSRUserData {
urls: IUrl[];
description: string;
services: IOA_Service[];
title: string;
images: IImage[];
jsError?:boolean
}
export interface I_OSR_USER {
_created: Date;
location: IGeoLocation;
_modified: Date;
_id: string;
detail: IOA_UserDetail;
type: string;
_deleted: boolean;
moderation: string;
geo: IGeo;
data: IOSRUserData;
}
export interface I_USER_SHORT {
name: string;
email: string;
bazar: string;
web: string;
social: string;
censored: string;
lastActive: Date;
ig: string;
}
export type IProduct = {
slug: string;
name: string;
category: string;
code: string;
forum?: string;
forumCategory?: string;
version?: string;
cart_id?: string;
};
export interface IDiscourseUser {
id: number
username: string
name: string
avatar_template: string
active: boolean
admin: boolean
moderator: boolean
last_seen_at: any
last_emailed_at: string
created_at: string
last_seen_age: any
last_emailed_age: number
created_at_age: number
trust_level: number
manual_locked_trust_level: any
flag_level: number
title: any
time_read: number
staged: boolean
days_visited: number
posts_read_count: number
topics_entered: number
post_count: number
}
export * from './osr/component.js'
export * from './types_kbot.js'

View File

@ -0,0 +1,6 @@
export interface IOptionsCache {
skip?: boolean
clear?: boolean
namespace?: string
cacheRoot?: string
}

View File

@ -0,0 +1,129 @@
export interface GeoPos {
lon: number
lat: number
}
export interface PATH_INFO {
DIR?: string
NAME?: string
FILE_NAME?: string
FILE_EXT?: string
PATH?: string
IS_FILE?: boolean
IS_FOLDER?: boolean
IS_EXPRESSION?: boolean
IS_GLOB?: boolean
path: string
GLOB: string
GLOB_EXTENSIONS: string[]
FILES: string[]
}
export interface IDeeplConfig {
auth_key: string
free_api: boolean
}
export interface IIgConfig {
username: string
password: string
}
export interface ICsCartConfigMySQL {
host: string
user: string
database: string
password: string
}
export interface ICsCartConfig {
token: string
url: string
username: string
siteUrl?: string
timeout?: number
language?: string
userToken?: string
mysql?: ICsCartConfigMySQL
}
export interface IGiteaConfig {
token: string
url: string
}
export interface IDiscourseConfig {
host: string
key: string
username: string
rateLimitConcurrency: number
}
export interface IScaleserp {
key: string
}
export interface IOSRConfig {
deepl: IDeeplConfig
ig: IIgConfig
cscart: ICsCartConfig
discourse: IDiscourseConfig
discourse_admin: IDiscourseConfig
instagram: IIgConfig
urls: any
scaleserp?: IScaleserp
gitea?: IGiteaConfig
}
export interface SRC_VARIABLES {
SRC_PATH: string
SRC_DIR: string
SRC_NAME: string
SRC_FILE_NAME: string
SRC_FILE_EXT: string
SRC_IS_FILE: boolean
SRC_IS_FOLDER: boolean
SRC_IS_EXPRESSION: boolean
SRC_IS_GLOB: boolean
SRC_GLOB: string
SRC_GLOB_EXTENSIONS: string[]
SRC_FILES: string[]
}
export interface DST_VARIABLES {
DST_PATH: string
DST_DIR: string
DST_NAME: string
DST_FILE_NAME: string
DST_FILE_EXT: string
DST_IS_FILE: boolean
DST_IS_FOLDER: boolean
DST_IS_EXPRESSION: boolean
DST_IS_GLOB: boolean
DST_GLOB: string
DST_GLOB_EXTENSIONS: string[]
DST_FILES: string[]
}
export type PATH_VARIABLES = SRC_VARIABLES & DST_VARIABLES
export interface IOptionsBase {
variables: PATH_VARIABLES
}
export interface PATH_INFO {
DIR?: string
FILE_EXT?: string
FILE_NAME?: string
FILES: string[]
GLOB_EXTENSIONS: string[]
GLOB: string
IS_EXPRESSION?: boolean
IS_FILE?: boolean
IS_FOLDER?: boolean
IS_GLOB?: boolean
NAME?: string
path: string
PATH?: string
}

Some files were not shown because too many files have changed in this diff Show More