Skip to content

Commit

Permalink
Extracts protonode as a separated library from protolib
Browse files Browse the repository at this point in the history
  • Loading branch information
ap0k4 committed Jul 7, 2024
1 parent d039668 commit 8abae4e
Show file tree
Hide file tree
Showing 72 changed files with 96 additions and 81 deletions.
2 changes: 2 additions & 0 deletions apps/admin-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"pino-http": "9.0.0",
"pino-pretty": "10.3.1",
"pm2": "^5.3.0",
"protobase": "*",
"protolib": "*",
"protonode": "*",
"subleveldown": "^6.0.1",
"ts-morph": "20.0.0",
"ts-node": "10.9.1",
Expand Down
3 changes: 1 addition & 2 deletions apps/admin-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import { getBaseConfig, getConfigWithoutSecrets } from '../../../packages/app/Ba
// get config vars
dotenv.config({ path: '../../.env' });
global.defaultRoute = '/adminapi/v1'
import { getServiceToken } from 'protolib/api/lib/serviceToken'
import { getServiceToken, getApp, getMQTTClient } from 'protonode'
setConfig(getBaseConfig("admin-api", process, getServiceToken()))
import { getApp, getMQTTClient } from 'protolib/api'
import adminModules from 'protolib/adminapi'
require('events').EventEmitter.defaultMaxListeners = 100;

Expand Down
2 changes: 1 addition & 1 deletion apps/admin-api/src/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import { getLogger } from 'protobase';
import { getBaseConfig } from '../../../packages/app/BaseConfig'
import { getServiceToken } from 'protolib/api/lib/serviceToken'
import { getServiceToken } from 'protonode'
import http from 'http';
import httpProxy from 'http-proxy';
import { join } from 'path';
Expand Down
3 changes: 1 addition & 2 deletions apps/api/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getApp, getMQTTClient } from 'protolib/api'
import { getApp, getMQTTClient, getServiceToken } from 'protonode'
import { getLogger, getConfig } from 'protobase';
import { getServiceToken } from 'protolib/api/lib/serviceToken'
import { getConfigWithoutSecrets } from 'app/BaseConfig'
import BundleContext from 'app/bundles/apiContext'
import { generateEvent } from 'protolib/bundles/events/eventsLibrary';
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/cmd/addUser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import dotenv from 'dotenv'
dotenv.config({ path: path.join(__dirname, "..", "..", "..", "..", ".env") });
import { hash } from 'protolib/api';
import { hash } from 'protonode';
import { getDB } from 'app/bundles/storageProviders'
import { CmdRegisterSchema} from 'protolib/schema';
import moment from 'moment';
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ moduleAlias.addAliases({

import dotenv from 'dotenv'
dotenv.config({ path: '../../.env' });
import { getServiceToken } from 'protolib/api/lib/serviceToken'
import { getServiceToken } from 'protonode'
import { setConfig, getLogger } from 'protobase';
import { getBaseConfig } from 'app/BaseConfig'
setConfig(getBaseConfig('api', process, getServiceToken()))
Expand Down
1 change: 0 additions & 1 deletion docs/protolib.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
Protolib is one of the main packages of Protofy. It contains the main components and functions to create a web or app with Protofy. Inside Protolib you'll have the following subpackages:

- `protolib`: Here you will find UI related components and functions.
- `protolib/api`: Utilities and abstractions for API services, not working on client side at this moment
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"prod": "NODE_ENV=production pm2 start ecosystem.config.js --no-daemon",
"prod-service": "NODE_ENV=production pm2 start ecosystem.config.js && yarn monit",
"add-user": "yarn workspace api add-user",
"build": "yarn workspaces foreach --all run build",
"build": "yarn workspaces foreach -t --all run build",
"package": "yarn workspaces foreach --all run clean && yarn prepare-dev",
"package-fast": "yarn workspaces foreach --all --exclude electron-app run package",
"status": "pm2 status",
Expand Down
4 changes: 2 additions & 2 deletions packages/app/bundles/storageProviders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { leveldbProvider } from 'protolib/api/lib/db';
import { leveldbProvider } from 'protonode';

export { leveldbProvider } from 'protolib/api/lib/db';
export { leveldbProvider } from 'protonode';
// DEFAULTS
export const getDB = leveldbProvider.getDB;
export const connectDB = leveldbProvider.connectDB;
1 change: 1 addition & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"handlebars": "4.7.8",
"moment": "2.29.4",
"mrmime": "1.0.1",
"protonode": "*",
"react-data-table-component": "^7.5.4",
"react-data-table-component-extensions": "^1.6.0",
"react-native-safe-area-context": "4.10.4",
Expand Down
1 change: 0 additions & 1 deletion packages/protoflow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"immer": "9.0.5",
"lucide-react": "0.279.0",
"prettier": "^2.8.1",
"protolib": "0.0.1",
"react": "~18.2.0",
"react-color": "2.19.3",
"react-select": "5.7.0",
Expand Down
5 changes: 2 additions & 3 deletions packages/protolib/src/adminapi/auth.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@

import { LoginSchema, RegisterSchema, LoginRequest, RegisterRequest } from '../schema';
import { getInitialData } from 'app/initialData'
import { handler, checkPassword, hash, genToken, getApp, getSessionContext } from 'protolib/api'
import { handler, checkPassword, hash, genToken, getApp, getSessionContext, getServiceToken } from 'protonode'
import { connectDB, getDB } from 'app/bundles/storageProviders';
import { getServiceToken } from 'protolib/api/lib/serviceToken'
import moment from 'moment';
import { generateEvent } from "../bundles/events/eventsLibrary";
import { getLogger } from 'protobase';
import { UserModel } from '../bundles/users';
import {SiteConfig} from 'app/conf'
import { getDBOptions } from '../api';
import { getDBOptions } from 'protonode';

const logger = getLogger()

Expand Down
2 changes: 1 addition & 1 deletion packages/protolib/src/adminapi/databases.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import * as path from 'path';
import * as fs from 'fs';
import { handler, getApp} from 'protolib/api'
import { handler, getApp} from 'protonode'
import { getDB } from 'app/bundles/storageProviders'
import { getLogger } from 'protobase';

Expand Down
6 changes: 2 additions & 4 deletions packages/protolib/src/adminapi/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
import { promises as fs } from 'fs';
import { constants } from 'fs';
import path from 'path';
import { getApp } from 'protolib/api';
import {getServiceToken} from 'protolib/api/lib/serviceToken'
import { getApp, getServiceToken } from 'protonode';
import multer from 'multer';
import fsExtra from 'fs-extra';
import syncFs from 'fs'
import { v4 as uuidv4 } from 'uuid';
import {generateEvent} from '../bundles/events/eventsLibrary'
import { getRoot, handler } from '../api';
import { getRoot, handler } from 'protonode';
import { getLogger } from 'protobase';
import archiver from 'archiver';

Expand Down
2 changes: 1 addition & 1 deletion packages/protolib/src/adminapi/templates.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs';
import {templates} from 'app/templates'
import { handler, getApp} from 'protolib/api'
import { handler, getApp} from 'protonode'
import { connectDB } from 'app/bundles/storageProviders'
import { getLogger } from 'protobase';

Expand Down
1 change: 0 additions & 1 deletion packages/protolib/src/api/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { handler } from '../../api'
import { handler } from 'protonode'
const MAX_TOKENS = 4096

export function AiAssistantsAPI(app, context) {
Expand Down
4 changes: 2 additions & 2 deletions packages/protolib/src/bundles/apis/api.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { APIModel } from ".";
import { getSourceFile, addImportToSourceFile, ImportType, addObjectLiteralProperty, getDefinition, AutoAPI, getRoot, removeFileWithImports, addFeature, removeFeature, hasFeature } from '../../api'
import { getSourceFile, addImportToSourceFile, ImportType, addObjectLiteralProperty, getDefinition, AutoAPI, getRoot, removeFileWithImports, addFeature, removeFeature, hasFeature } from 'protonode'
import { promises as fs } from 'fs';
import * as fsSync from 'fs';
import * as fspath from 'path';
import { API } from 'protobase'
import { getServiceToken } from "../../api/lib/serviceToken";
import { getServiceToken } from "protonode";
import { ObjectModel } from '../objects/objectsSchemas'

const APIDir = (root) => fspath.join(root, "/packages/app/bundles/custom/apis/")
Expand Down
2 changes: 1 addition & 1 deletion packages/protolib/src/bundles/apis/context/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getServiceToken as getServiceToken_} from '../../../api/lib/serviceToken'
import { getServiceToken as getServiceToken_} from 'protonode'
import { API, getLogger } from "protobase";

const logger = getLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ use the chat if in doubt
*/

import { Objects } from "app/bundles/objects";
import { AutoAPI } from "protolib/api";
import { AutoAPI, getServiceToken } from "protonode";
import { API, Protofy, getLogger } from "protobase";
import { Application } from "express";
import {GoogleSheetClient} from 'protolib/bundles/google/googleSheetClient'
import fsPath from "path";
import { getServiceToken } from "protolib/api/lib/serviceToken";

const root = fsPath.join(process.cwd(), '..', '..')
const logger = getLogger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ use the chat if in doubt
*/

import { Objects } from "app/bundles/objects";
import { AutoAPI } from "protolib/api";
import { AutoAPI, getAuth } from "protonode";
import { API, Protofy, getLogger } from "protobase";
import { Application } from "express";
import { getAuth } from "protolib/api";
import fs from "fs";
import fsPath from "path";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Objects } from "app/bundles/objects";
import { AutoAPI } from 'protolib/api'
import { AutoAPI, getAuth } from 'protonode'
import { API, Protofy, getLogger } from "protobase";
import { Application } from 'express';
import { getAuth } from "protolib/api";
import fs from 'fs'
import path from "path";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ the session argument is a session object, with the following shape:
use the chat if in doubt
*/

import { getAuth } from "protolib/api";
import { getAuth } from "protonode";
import { API, Protofy, getLogger } from "protobase";
import { Application } from 'express';
import fs from 'fs'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ the session argument is a session object, with the following shape:
use the chat if in doubt
*/

import { getAuth } from "protolib/api";
import { getAuth } from "protonode";
import { API, Protofy, getLogger } from "protobase";
import { Application } from 'express';
import fs from 'fs'
Expand Down
2 changes: 1 addition & 1 deletion packages/protolib/src/bundles/databases/databasesAPI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { handler, AutoAPI, getRoot, closeDBS} from '../../api'
import { handler, AutoAPI, getRoot, closeDBS} from 'protonode'
import { connectDB, getDB } from 'app/bundles/storageProviders';
import * as fs from 'fs'
import * as path from 'path'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProtoModel, Protofy, AutoModel, Schema, z } from "protobase";
import { SessionDataType } from "../../api";
import { SessionDataType } from "protonode";

export const DatabaseEntrySchema = Schema.object({
key: z.string(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeviceBoardModel } from ".";
import { AutoAPI } from '../../../api'
import { AutoAPI } from 'protonode'

const initialData = {
"Protofy ESP32 devBoard": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeviceDefinitionModel } from ".";
import { AutoAPI } from '../../../api'
import { AutoAPI } from 'protonode'
import { API } from 'protobase'
import { DevicesModel } from "../devices";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeviceSdkModel } from ".";
import { AutoAPI } from '../../../api'
import { AutoAPI } from 'protonode'

const initialData = {
"1": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeviceCoreModel } from ".";
import { AutoAPI } from '../../../api'
import { AutoAPI } from 'protonode'
import { API } from 'protobase'

const initialData = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getServiceToken } from "../../../../api/lib/serviceToken";
import { getServiceToken } from "protonode";
import { API } from "protobase";

export const deviceAction = async (device, subsystem, action, value?, cb?, errorCb?) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getServiceToken } from "../../../../api/lib/serviceToken";
import { getServiceToken } from "protonode";
import { API } from "protobase";

export const deviceMonitor = async (device, subsystem, monitor) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/protolib/src/bundles/devices/devices/devicesAPI.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { API } from "protobase";
import { DevicesModel } from ".";
import { AutoAPI, handler } from '../../../api'
import { AutoAPI, handler, getServiceToken } from 'protonode'
import { getDB } from 'app/bundles/storageProviders'
import { getServiceToken } from "../../../api/lib/serviceToken";
import { generateEvent } from "../../events/eventsLibrary";
import { getLogger } from 'protobase';
import moment from 'moment';
Expand Down
2 changes: 1 addition & 1 deletion packages/protolib/src/bundles/events/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getServiceToken } from '../../../api/lib/serviceToken'
import { getServiceToken } from 'protonode'
import { generateEvent } from "../eventsLibrary"

export const onEvent = (mqtt, context, cb, path?, from?) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/protolib/src/bundles/events/eventsAPI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventModel } from ".";
import { AutoAPI, getDBOptions } from '../../api'
import { AutoAPI, getDBOptions } from 'protonode'
import {connectDB} from "app/bundles/storageProviders";


Expand Down
2 changes: 1 addition & 1 deletion packages/protolib/src/bundles/events/eventsSchemas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moment from "moment";
import { SessionDataType } from "../../api";
import { SessionDataType } from "protonode";
import { ProtoModel, z, Protofy, BaseSchema} from "protobase";

export const BaseEventSchema = z.object(Protofy("schema", {
Expand Down
2 changes: 1 addition & 1 deletion packages/protolib/src/bundles/files/intents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { usePrompt, promptCmd } from '../../context/PromptAtom';
import { useInterval, useUpdateEffect } from 'usehooks-ts';
import Flows from '../../adminpanel/features/components/Flows';
import { getFlowsCustomComponents } from 'app/bundles/masks'
import { getDefinition, toSourceFile } from '../../api/lib/code'
import { getDefinition, toSourceFile } from 'protonode/dist/lib/code'
import { ArrowFunction } from 'ts-morph';
import parserTypeScript from "prettier/parser-typescript.js";
import prettier from "prettier/standalone.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/protolib/src/bundles/fsm/FSMApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getSourceFile, addImportToSourceFile, ImportType, addObjectLiteralProperty, getDefinition, AutoAPI, getRoot, removeFileWithImports, addFeature, removeFeature, hasFeature } from '../../api'
import { getSourceFile, addImportToSourceFile, ImportType, addObjectLiteralProperty, getDefinition, AutoAPI, getRoot, removeFileWithImports, addFeature, removeFeature, hasFeature } from 'protonode'
import { promises as fs } from 'fs';
import * as fsSync from 'fs';
import * as fspath from 'path';
Expand Down
2 changes: 1 addition & 1 deletion packages/protolib/src/bundles/groups/groupsAPI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GroupModel } from "./";
import { AutoAPI } from '../../api'
import { AutoAPI } from 'protonode'

const initialData = {
admin: {"name": "admin", "workspaces": ["admin", "editor"], "admin": true},
Expand Down
2 changes: 1 addition & 1 deletion packages/protolib/src/bundles/keys/keysAPI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { KeyModel } from "./";
import { AutoAPI } from '../../api'
import { AutoAPI } from 'protonode'


export const KeysAPI = AutoAPI({
Expand Down
2 changes: 1 addition & 1 deletion packages/protolib/src/bundles/logs/logsAPI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { handler } from '../../api'
import { handler } from 'protonode'

export const LogsAPI = (app, context) => {
app.get('/adminapi/v1/logs', handler(async (req, res, session) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/protolib/src/bundles/objects/objectsAPI.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ObjectModel } from ".";
import { getImport, getSourceFile, extractChainCalls, addImportToSourceFile, ImportType, addObjectLiteralProperty, getDefinition, AutoAPI, getRoot, removeFileWithImports } from '../../api'
import { getImport, getSourceFile, extractChainCalls, addImportToSourceFile, ImportType, addObjectLiteralProperty, getDefinition, AutoAPI, getRoot, removeFileWithImports } from 'protonode'
import { promises as fs } from 'fs';
import * as fspath from 'path';
import { ObjectLiteralExpression, PropertyAssignment } from 'ts-morph';
import { getServiceToken } from '../../api/lib/serviceToken'
import { getServiceToken } from 'protonode'
import { API } from 'protobase'
import { APIModel } from '../apis/APISchemas'
import { PageModel } from '../pages/pagesSchemas'
Expand Down
2 changes: 1 addition & 1 deletion packages/protolib/src/bundles/objects/objectsSchemas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProtoModel, z } from "protobase";
import { SessionDataType } from "../../api";
import { SessionDataType } from "protonode";

export const BaseObjectSchema = z.object({
id: z.string().search().id().generate((obj) => obj.name.charAt(0).toUpperCase() + obj.name.slice(1) + 'Model').hidden(),
Expand Down
4 changes: 2 additions & 2 deletions packages/protolib/src/bundles/pages/pagesAPI.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { PageModel } from ".";
import { getSourceFile, getDefinition, AutoAPI, getRoot, addFeature, hasFeature, removeFeature } from '../../api'
import { getSourceFile, getDefinition, AutoAPI, getRoot, addFeature, hasFeature, removeFeature } from 'protonode'
import { promises as fs } from 'fs';
import * as syncFs from 'fs';
import * as fspath from 'path';
import { ArrayLiteralExpression } from 'ts-morph';
import { getServiceToken } from '../../api/lib/serviceToken'
import { getServiceToken } from 'protonode'
import { API } from 'protobase'
import { ObjectModel } from "../objects/objectsSchemas";

Expand Down
2 changes: 1 addition & 1 deletion packages/protolib/src/bundles/pages/pagesSchemas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProtoModel, Schema, optional, z } from 'protobase'
import { SessionDataType } from "../../api";
import { SessionDataType } from "protonode";

export const PageSchema = Schema.object({
name: z.string().search().id(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Node, NodeParams, getFieldValue, Button } from 'protoflow';
import { Mail } from 'lucide-react';
import { useColorFromPalette } from 'protoflow/src/diagram/Theme'
// import { sendMailWithResend } from 'protolib/api/lib/mail';
// import { sendMailWithResend } from 'protonode';

const SendMailResend = (node: any = {}, nodeData = {}) => {
const color = useColorFromPalette(9)
Expand Down
Loading

0 comments on commit 8abae4e

Please sign in to comment.