@docstack/client 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/attribute.js +406 -0
- package/lib/core/attribute.js.map +1 -0
- package/lib/core/class.d.ts +15 -16
- package/lib/core/class.js +761 -0
- package/lib/core/class.js.map +1 -0
- package/lib/core/crypto-engine/index.js +229 -0
- package/lib/core/crypto-engine/index.js.map +1 -0
- package/lib/core/crypto-engine/utils.js +88 -0
- package/lib/core/crypto-engine/utils.js.map +1 -0
- package/lib/core/datamodel/index.js +1308 -0
- package/lib/core/datamodel/index.js.map +1 -0
- package/lib/core/domain.d.ts +7 -8
- package/lib/core/domain.js +423 -0
- package/lib/core/domain.js.map +1 -0
- package/lib/core/index.js +520 -0
- package/lib/core/index.js.map +1 -0
- package/lib/core/job-engine/index.js +220 -0
- package/lib/core/job-engine/index.js.map +1 -0
- package/lib/core/policy-engine/index.js +232 -0
- package/lib/core/policy-engine/index.js.map +1 -0
- package/lib/core/query-engine/accumulators.js +258 -0
- package/lib/core/query-engine/accumulators.js.map +1 -0
- package/lib/core/query-engine/evaluator.js +179 -0
- package/lib/core/query-engine/evaluator.js.map +1 -0
- package/lib/core/query-engine/executor.js +405 -0
- package/lib/core/query-engine/executor.js.map +1 -0
- package/lib/core/query-engine/index.js +4 -0
- package/lib/core/query-engine/index.js.map +1 -0
- package/lib/core/query-engine/parser.js +515 -0
- package/lib/core/query-engine/parser.js.map +1 -0
- package/lib/core/query-engine/planner.js +330 -0
- package/lib/core/query-engine/planner.js.map +1 -0
- package/lib/core/stack.js +1817 -0
- package/lib/core/stack.js.map +1 -0
- package/lib/core/test-utils/docstack.js +222 -0
- package/lib/core/test-utils/docstack.js.map +1 -0
- package/lib/core/trigger/index.js +81 -0
- package/lib/core/trigger/index.js.map +1 -0
- package/lib/index.js +4 -8231
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +10 -4
- package/lib/plugins/pouchdb.js +368 -0
- package/lib/plugins/pouchdb.js.map +1 -0
- package/lib/utils/crypto/index.js +34 -0
- package/lib/utils/crypto/index.js.map +1 -0
- package/lib/utils/index.js +58 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/logger/index.js +20 -0
- package/lib/utils/logger/index.js.map +1 -0
- package/lib/utils/logger/transport.js +28 -0
- package/lib/utils/logger/transport.js.map +1 -0
- package/lib/workers/dataModel.js +48 -0
- package/lib/workers/dataModel.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
// import express, {Express} from 'express'
|
|
2
|
+
// import { static as exStatic } from 'express';
|
|
3
|
+
// import * as dotenv from "dotenv";
|
|
4
|
+
// import cors from "cors";
|
|
5
|
+
// dotenv.config({ path: './.env' })
|
|
6
|
+
import createlogger from "../utils/logger/index";
|
|
7
|
+
// import test from '../../../server/src//utils/dbManager/test';
|
|
8
|
+
// import { generateJwtKeys, generatePswKeys } from '../../../server/src/utils/crypto';
|
|
9
|
+
import ClientStack from './stack';
|
|
10
|
+
// import { login, JWTAuthPayload, setupAdminUser } from '../../../server/src//utils/auth';
|
|
11
|
+
// import memoryAdapter from "pouchdb-adapter-memory"
|
|
12
|
+
// import cookieParser from 'cookie-parser';
|
|
13
|
+
// import jwt from 'jsonwebtoken';
|
|
14
|
+
import Class from "./class";
|
|
15
|
+
import Domain from './domain';
|
|
16
|
+
import { Trigger } from "./trigger/index";
|
|
17
|
+
import { JobEngine } from "./job-engine/index";
|
|
18
|
+
// import AbstractClass from '../../shared/src//utils/stack/class';
|
|
19
|
+
import Attribute from './attribute';
|
|
20
|
+
// import { EventTarget } from 'node:events';
|
|
21
|
+
// let envPath = process.env.ENVFILE || "./.env";
|
|
22
|
+
// envPath = resolve(process.cwd(), envPath);
|
|
23
|
+
// dotenv.config({ path: envPath });
|
|
24
|
+
// [TODO] Implement DocStack.type in "remote" | "local"
|
|
25
|
+
// When is remote, open a websocket (socket.io) connection to given remote
|
|
26
|
+
// implement cases in each of stack methods (queries and doc creation)
|
|
27
|
+
// to actually send and receive messages
|
|
28
|
+
// [TODO][HARD] Think about authentication mechanism
|
|
29
|
+
// Probably support same rest authentication (jwtToken)
|
|
30
|
+
// but also api tokens
|
|
31
|
+
// Remote connection that require auth can be opened but
|
|
32
|
+
// cannot send or receive messages until authentication
|
|
33
|
+
/**
|
|
34
|
+
* The main entry point for the DocStack client library.
|
|
35
|
+
*
|
|
36
|
+
* DocStack manages multiple {@link ClientStack} instances and provides
|
|
37
|
+
* a unified interface for database operations, authentication, and
|
|
38
|
+
* class/attribute creation.
|
|
39
|
+
*
|
|
40
|
+
* The client emits a `ready` event when all stacks are initialized.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* // Initialize DocStack with a single database
|
|
45
|
+
* const docstack = new DocStack({ name: 'my-app' });
|
|
46
|
+
*
|
|
47
|
+
* // Wait for ready
|
|
48
|
+
* docstack.addEventListener('ready', async () => {
|
|
49
|
+
* const stack = docstack.getStack('my-app');
|
|
50
|
+
* const taskClass = await stack.getClass('Task');
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* // Initialize with credentials for automatic authentication
|
|
54
|
+
* const docstack = new DocStack({
|
|
55
|
+
* name: 'my-app',
|
|
56
|
+
* credentials: { username: 'admin', password: 'secret' }
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @extends EventTarget
|
|
61
|
+
*/
|
|
62
|
+
class DocStack extends EventTarget {
|
|
63
|
+
async addStack(config) {
|
|
64
|
+
let stack;
|
|
65
|
+
if (typeof config == "object" && config.name) {
|
|
66
|
+
stack = await ClientStack.create(`db-${config.name}`, {
|
|
67
|
+
// defaults to leveldb
|
|
68
|
+
// adapter: 'memory',
|
|
69
|
+
plugins: [
|
|
70
|
+
// https://www.npmjs.com/package/pouchdb-adapter-memory
|
|
71
|
+
// memoryAdapter
|
|
72
|
+
],
|
|
73
|
+
patches: config.patches,
|
|
74
|
+
credentials: config.credentials,
|
|
75
|
+
disableCryptoEngine: config.disableCryptoEngine,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else if (typeof config === "string") {
|
|
79
|
+
stack = await ClientStack.create(`db-${config}`, {
|
|
80
|
+
// defaults to leveldb
|
|
81
|
+
// adapter: 'memory',
|
|
82
|
+
plugins: [
|
|
83
|
+
// https://www.npmjs.com/package/pouchdb-adapter-memory
|
|
84
|
+
// memoryAdapter
|
|
85
|
+
]
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (stack) {
|
|
89
|
+
this.stacks.push(stack);
|
|
90
|
+
// let window_ = window as Window & typeof globalThis & {
|
|
91
|
+
// stacks: ClientStack[]
|
|
92
|
+
// }
|
|
93
|
+
// if (window_.stacks) {
|
|
94
|
+
// window_.stacks.push(stack)
|
|
95
|
+
// }
|
|
96
|
+
return stack;
|
|
97
|
+
}
|
|
98
|
+
// await setupAdminUser();
|
|
99
|
+
}
|
|
100
|
+
async resetAll() {
|
|
101
|
+
try {
|
|
102
|
+
for (const stack of this.stacks) {
|
|
103
|
+
await stack.reset();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
throw new Error(e);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Returns all initialized stacks.
|
|
112
|
+
* @returns Array of ClientStack instances
|
|
113
|
+
*/
|
|
114
|
+
getStacks() {
|
|
115
|
+
return this.stacks;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Authenticates a user on a specific stack.
|
|
119
|
+
*
|
|
120
|
+
* @param name - The stack name to authenticate against
|
|
121
|
+
* @param credentials - The user's login credentials
|
|
122
|
+
* @returns The authentication session proof
|
|
123
|
+
* @throws Error if the stack is not found
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const proof = await docstack.authenticateStack('my-app', {
|
|
128
|
+
* username: 'user@example.com',
|
|
129
|
+
* password: 'password123'
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
async authenticateStack(name, credentials) {
|
|
134
|
+
const stack = this.getStack(name);
|
|
135
|
+
if (!stack) {
|
|
136
|
+
throw new Error(`Stack '${name}' not found`);
|
|
137
|
+
}
|
|
138
|
+
return stack.authenticate(credentials);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Returns whether all stacks have been initialized.
|
|
142
|
+
* @returns `true` if ready, `false` otherwise
|
|
143
|
+
*/
|
|
144
|
+
getReadyState() {
|
|
145
|
+
return this.readyState;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Resets all stacks and re-initializes them.
|
|
149
|
+
* Useful for testing or clearing all data.
|
|
150
|
+
*/
|
|
151
|
+
async reset() {
|
|
152
|
+
try {
|
|
153
|
+
await this.resetAll();
|
|
154
|
+
await this.initStacks(this.config);
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
throw new Error(e);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Creates a new DocStack client instance.
|
|
162
|
+
* Initializes all configured stacks asynchronously.
|
|
163
|
+
* Listen for the `ready` event to know when initialization is complete.
|
|
164
|
+
*
|
|
165
|
+
* @param config - One or more stack configurations
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* const docstack = new DocStack(
|
|
170
|
+
* { name: 'primary-db' },
|
|
171
|
+
* { name: 'backup-db' }
|
|
172
|
+
* );
|
|
173
|
+
*
|
|
174
|
+
* docstack.addEventListener('ready', () => {
|
|
175
|
+
* console.log('All stacks ready!');
|
|
176
|
+
* });
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
constructor(...config) {
|
|
180
|
+
super();
|
|
181
|
+
/** Array of stack configurations used for initialization. */
|
|
182
|
+
this.config = [];
|
|
183
|
+
/** Array of all initialized ClientStack instances. */
|
|
184
|
+
this.stacks = [];
|
|
185
|
+
this.logger = createlogger().child({ module: "client" });
|
|
186
|
+
this.initStacks = async (configs) => {
|
|
187
|
+
// TODO: Consider changing to Promise.all for concurrency
|
|
188
|
+
for (const config of configs) {
|
|
189
|
+
const stack = await this.addStack(config);
|
|
190
|
+
}
|
|
191
|
+
this.readyState = true;
|
|
192
|
+
this.dispatchEvent(new CustomEvent("ready", {
|
|
193
|
+
detail: {
|
|
194
|
+
stacks: this.stacks
|
|
195
|
+
}
|
|
196
|
+
}));
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Gets a stack by its name or connection string.
|
|
200
|
+
*
|
|
201
|
+
* @param name - The stack name or connection identifier
|
|
202
|
+
* @returns The matching ClientStack, or `undefined` if not found
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const stack = docstack.getStack('my-app');
|
|
207
|
+
* if (stack) {
|
|
208
|
+
* const users = await stack.query('SELECT * FROM User');
|
|
209
|
+
* }
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
this.getStack = (name) => {
|
|
213
|
+
return this.stacks.find(s => s.name == name || s.connection == name);
|
|
214
|
+
};
|
|
215
|
+
this.clearConnection = async (conn) => {
|
|
216
|
+
const fnLogger = this.logger.child({ method: 'clearConnection' });
|
|
217
|
+
try {
|
|
218
|
+
// const conn = req.params.conn;
|
|
219
|
+
if (!conn) {
|
|
220
|
+
throw new Error("Connection name not provided");
|
|
221
|
+
}
|
|
222
|
+
await ClientStack.clear(conn);
|
|
223
|
+
fnLogger.info('Internal database cleared');
|
|
224
|
+
// return res.status(200).json({ success: true, message: 'Internal database cleared' });
|
|
225
|
+
}
|
|
226
|
+
catch (e) {
|
|
227
|
+
throw new Error(e);
|
|
228
|
+
// return res.status(500).json({ success: false, error: 'An error occurred' });
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Exports all documents from a stack.
|
|
233
|
+
*
|
|
234
|
+
* @param stackName - The name of the stack to export
|
|
235
|
+
* @returns All documents from the stack
|
|
236
|
+
* @throws Error if the stack is not found
|
|
237
|
+
*/
|
|
238
|
+
this.export = async (stackName) => {
|
|
239
|
+
const stack = this.getStack(stackName);
|
|
240
|
+
if (stack) {
|
|
241
|
+
const dump = await stack.dump();
|
|
242
|
+
return dump;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
throw new Error(`Did not find any stack for name '${stackName}'`);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Creates a new Class in the specified stack.
|
|
250
|
+
*
|
|
251
|
+
* @param stackName - The name of the stack to create the class in
|
|
252
|
+
* @param name - The class name
|
|
253
|
+
* @param config - Configuration with type and description
|
|
254
|
+
* @throws Error if the stack is not found
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* await docstack.createClass('my-app', 'Product', {
|
|
259
|
+
* type: 'class',
|
|
260
|
+
* description: 'Product catalog items'
|
|
261
|
+
* });
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
this.createClass = async (stackName, name, config) => {
|
|
265
|
+
const fnLogger = this.logger.child({ method: 'createClass' });
|
|
266
|
+
const stack = this.getStack(stackName);
|
|
267
|
+
if (!stack) {
|
|
268
|
+
throw new Error(`Stack '${stackName}' not found`);
|
|
269
|
+
}
|
|
270
|
+
const { type, description } = config;
|
|
271
|
+
fnLogger.info("Args", {
|
|
272
|
+
stackName, name, config
|
|
273
|
+
});
|
|
274
|
+
try {
|
|
275
|
+
const newClass = await Class.create(stack, name, "class", description, {});
|
|
276
|
+
fnLogger.info(`class '${name}' created successfully.`, { classModel: newClass.getModel() });
|
|
277
|
+
}
|
|
278
|
+
catch (e) {
|
|
279
|
+
throw new Error(`Error during class '${name}' creation. ${e}`);
|
|
280
|
+
}
|
|
281
|
+
fnLogger.info('Class created successfully');
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* Creates a new Attribute on a Class in the specified stack.
|
|
285
|
+
*
|
|
286
|
+
* @param stackName - The name of the stack containing the class
|
|
287
|
+
* @param className - The class to add the attribute to
|
|
288
|
+
* @param params - Attribute configuration
|
|
289
|
+
* @throws Error if the stack or class is not found
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```typescript
|
|
293
|
+
* await docstack.createAttribute('my-app', 'Product', {
|
|
294
|
+
* name: 'price',
|
|
295
|
+
* type: 'number',
|
|
296
|
+
* description: 'Product price in cents'
|
|
297
|
+
* });
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
this.createAttribute = async (stackName, className, params) => {
|
|
301
|
+
const fnLogger = this.logger.child({ method: 'createAttribute' });
|
|
302
|
+
const stack = this.getStack(stackName);
|
|
303
|
+
if (!stack) {
|
|
304
|
+
throw new Error(`Stack '${stackName}' not found`);
|
|
305
|
+
}
|
|
306
|
+
const { name, type, description, config } = params;
|
|
307
|
+
fnLogger.info(`Creating attribute for class '${className}' in stack '${stackName}'`, {
|
|
308
|
+
name, type, config
|
|
309
|
+
});
|
|
310
|
+
try {
|
|
311
|
+
// Loads the class object
|
|
312
|
+
let classObj = await stack.getClass(className);
|
|
313
|
+
if (classObj) {
|
|
314
|
+
let newAttribute = await Attribute.create(classObj, name, type, description, config);
|
|
315
|
+
fnLogger.info(`Attribute '${name}' added to class '${className}'`, { attributeModel: newAttribute.getModel() });
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
throw new Error(`Failed to retrieve Class '${className}'`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
catch (e) {
|
|
322
|
+
fnLogger.error(`Error during attribute '${name}' creation: ${e}`);
|
|
323
|
+
throw new Error(`Error during attribute '${name}' creation: ${e}`);
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
this.readyState = false;
|
|
327
|
+
const fnLogger = this.logger.child({ method: "constructor" });
|
|
328
|
+
/*
|
|
329
|
+
this.app.use(logRequest)
|
|
330
|
+
// Enable CORS for all routes
|
|
331
|
+
if (process.env.NODE_ENV === 'development') {
|
|
332
|
+
logger.info("Development environment. Enabling CORS for :8080");
|
|
333
|
+
this.app.use(cors({
|
|
334
|
+
origin: 'http://localhost:8080',
|
|
335
|
+
// Replace with the origin of webpack dev server
|
|
336
|
+
methods: ['GET', 'POST'],
|
|
337
|
+
credentials: true,
|
|
338
|
+
}));
|
|
339
|
+
}
|
|
340
|
+
*/
|
|
341
|
+
/*
|
|
342
|
+
// Use built-in middleware for parsing JSON and URL-encoded data
|
|
343
|
+
this.app.use(express.json());
|
|
344
|
+
this.app.use(express.urlencoded({ extended: true }));
|
|
345
|
+
this.app.use(cookieParser());
|
|
346
|
+
this.app.use((req, res, next) => {
|
|
347
|
+
if (!this.readyState) {
|
|
348
|
+
return res.status(503); // Service Unavailable.
|
|
349
|
+
}
|
|
350
|
+
// Server is ready to receive requests
|
|
351
|
+
next()
|
|
352
|
+
})
|
|
353
|
+
*/
|
|
354
|
+
/*
|
|
355
|
+
this.app.use('/api/private', (req, res, next) => {
|
|
356
|
+
const token = req.cookies.jwtToken
|
|
357
|
+
if (!token) {
|
|
358
|
+
logger.error("No token provided")
|
|
359
|
+
return res.status(403).json({
|
|
360
|
+
success: false,
|
|
361
|
+
message: 'No token provided',
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
const secretKey = process.env.JWT_PUBLIC_KEY;
|
|
365
|
+
if (!secretKey || secretKey === '') {
|
|
366
|
+
logger.error("No secret key found")
|
|
367
|
+
return res.status(500).json({
|
|
368
|
+
success: false,
|
|
369
|
+
message: 'No secret key found',
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
jwt.verify(token, secretKey, async (err, payload: JWTAuthPayload) => {
|
|
373
|
+
if (err) {
|
|
374
|
+
logger.error("Invalid token", err)
|
|
375
|
+
return res.status(403).json({
|
|
376
|
+
success: false,
|
|
377
|
+
message: 'Invalid token',
|
|
378
|
+
});
|
|
379
|
+
} else {
|
|
380
|
+
// Check whether the session is still valid
|
|
381
|
+
const { sessionId } = payload;
|
|
382
|
+
const UserSessionClass = await this.store.getClass("UserSession");
|
|
383
|
+
const sessionCards = await UserSessionClass.getCards({
|
|
384
|
+
sessionId: { $eq: sessionId },
|
|
385
|
+
sessionStatus: { $eq: "active" }
|
|
386
|
+
}, null, 0, 1);
|
|
387
|
+
if (sessionCards.length === 0) {
|
|
388
|
+
return res.status(403).json({
|
|
389
|
+
success: false,
|
|
390
|
+
message: 'Session expired',
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
// TODO: Consider passing the session card to the next middleware
|
|
394
|
+
next();
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
})
|
|
398
|
+
*/
|
|
399
|
+
// TODO: Serve the dashboard to a specific route, i.e.: admin
|
|
400
|
+
// this.app.use(exStatic('./dist'));
|
|
401
|
+
// TODO: Serve the static files from the build folder
|
|
402
|
+
// of the UI application
|
|
403
|
+
// this.app.get('*', (req, res) => {
|
|
404
|
+
// const templatePath = resolve(__dirname, './dist', 'index.html');
|
|
405
|
+
// res.sendFile(templatePath);
|
|
406
|
+
// });
|
|
407
|
+
/*
|
|
408
|
+
this.app.post('/login', async (req, res) => {
|
|
409
|
+
try {
|
|
410
|
+
const { username, password } = req.body;
|
|
411
|
+
const { responseCode, body, token } = await login(username, password);
|
|
412
|
+
// Append also the token to the response
|
|
413
|
+
let cookieOptions = {}
|
|
414
|
+
if (process.env.NODE_ENV === 'development') {
|
|
415
|
+
cookieOptions = { sameSite: 'None', secure: true, maxAge: 1000 * 60 * 15 };
|
|
416
|
+
logger.warn("Development mode: setting cookie options to SameSite=None; Secure=true for JWT token");
|
|
417
|
+
} else cookieOptions = { sameSite: 'Strict', httpOnly: true, maxAge: 1000 * 60 * 15 };
|
|
418
|
+
|
|
419
|
+
res.cookie('jwtToken', token, cookieOptions);
|
|
420
|
+
return res.status(responseCode).json(body);
|
|
421
|
+
} catch (error) {
|
|
422
|
+
console.error("Error during login", error);
|
|
423
|
+
return res.status(500).json({ success: false, error: 'An error occurred' });
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
*/
|
|
427
|
+
/*
|
|
428
|
+
this.app.get('/api/private/reset', async (req, res) => {
|
|
429
|
+
try {
|
|
430
|
+
await this.reset();
|
|
431
|
+
return res.status(200).json({ success: true, message: 'Internal database reset' });
|
|
432
|
+
} catch (e) {
|
|
433
|
+
return res.status(500).json({ success: false, error: 'An error occurred' });
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
*/
|
|
437
|
+
/*
|
|
438
|
+
this.app.get('/api/private/clear:conn', async (req, res) => {
|
|
439
|
+
try {
|
|
440
|
+
const conn = req.params.conn;
|
|
441
|
+
if (!conn) {
|
|
442
|
+
throw new Error("Connection name not provided");
|
|
443
|
+
}
|
|
444
|
+
await ClientStack.clear(conn);
|
|
445
|
+
return res.status(200).json({ success: true, message: 'Internal database cleared' });
|
|
446
|
+
} catch (e) {
|
|
447
|
+
logger.error("Error during database clear", e);
|
|
448
|
+
return res.status(500).json({ success: false, error: 'An error occurred' });
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
*/
|
|
452
|
+
/*
|
|
453
|
+
this.app.get('/api/private/test', (req, res) => {
|
|
454
|
+
return res.status(200).json({ message: 'Hello from the server! This is a private route' });
|
|
455
|
+
});
|
|
456
|
+
*/
|
|
457
|
+
/*
|
|
458
|
+
this.app.post('/api/private/create-class/:name', async (req, res) => {
|
|
459
|
+
const { name } = req.params;
|
|
460
|
+
const { type, description } = req.query;
|
|
461
|
+
logger.info("create-class - received request", {
|
|
462
|
+
params: req.params,
|
|
463
|
+
query: req.query
|
|
464
|
+
})
|
|
465
|
+
|
|
466
|
+
try {
|
|
467
|
+
const newClass = await Class.create(
|
|
468
|
+
this.store, name, type as string, description as string
|
|
469
|
+
);
|
|
470
|
+
logger.info("create-class", `class '${name}' created successfully.`,
|
|
471
|
+
{classModel: newClass.getModel()}
|
|
472
|
+
)
|
|
473
|
+
} catch (e) {
|
|
474
|
+
logger.error(`Error during class '${name} creation: ${e}`);
|
|
475
|
+
return res.status(500).json({ success: false, error: 'An error occurred' });
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
return res.status(200).json({ success: true, message: 'Class created successfully' });
|
|
479
|
+
})
|
|
480
|
+
*/
|
|
481
|
+
/*
|
|
482
|
+
this.app.put('/api/private/create-attribute/:name', async (req, res) => {
|
|
483
|
+
const className = req.params.name;
|
|
484
|
+
const { name, type, config } = req.body;
|
|
485
|
+
logger.info(`create-attribute - for class '${className}'`, {
|
|
486
|
+
name, type, config
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
try {
|
|
490
|
+
// Loads the class object
|
|
491
|
+
let classObj = await this.store.getClass(className);
|
|
492
|
+
let newAttribute = await Attribute.create(classObj, name, type, config);
|
|
493
|
+
logger.info(`create-attribute - Attribute '${name}' added to class '${className}'`,
|
|
494
|
+
{attributeModel: newAttribute.getModel()}
|
|
495
|
+
);
|
|
496
|
+
} catch (e) {
|
|
497
|
+
logger.error(`Error during attribute '${name}' creation: ${e}`)
|
|
498
|
+
}
|
|
499
|
+
})
|
|
500
|
+
*/
|
|
501
|
+
// const port = process.env.SERVER_PORT || 5000;
|
|
502
|
+
// const server = this.app.listen(port, () => logger.info(`Listening on port ${port}`));
|
|
503
|
+
// Procedure that should run once only
|
|
504
|
+
// can be considered "setup procedures"
|
|
505
|
+
//generatePswKeys()
|
|
506
|
+
// generateJwtKeys()
|
|
507
|
+
// Server "startup procedures"
|
|
508
|
+
// setTimeout(test, 1000)
|
|
509
|
+
this.initStacks(config);
|
|
510
|
+
this.addEventListener("ready", () => fnLogger.info("DocStack client successfully initialized"));
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Core exports from the DocStack client library.
|
|
515
|
+
*
|
|
516
|
+
* @module @docstack/client
|
|
517
|
+
*/
|
|
518
|
+
export { ClientStack, Trigger, Class, Attribute, Domain, JobEngine };
|
|
519
|
+
export { DocStack };
|
|
520
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,gDAAgD;AAChD,oCAAoC;AACpC,2BAA2B;AAC3B,oCAAoC;AACpC,OAAO,YAAY,MAAM,uBAAuB,CAAA;AAChD,gEAAgE;AAChE,uFAAuF;AACvF,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,2FAA2F;AAC3F,qDAAqD;AACrD,4CAA4C;AAC5C,kCAAkC;AAClC,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,mEAAmE;AACnE,OAAO,SAAS,MAAM,aAAa,CAAC;AAGpC,6CAA6C;AAE7C,iDAAiD;AACjD,6CAA6C;AAC7C,oCAAoC;AAGpC,uDAAuD;AACvD,0EAA0E;AAC1E,sEAAsE;AACtE,wCAAwC;AACxC,oDAAoD;AACpD,uDAAuD;AACvD,sBAAsB;AACtB,wDAAwD;AACxD,uDAAuD;AACvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,QAAS,SAAQ,WAAW;IAWtB,KAAK,CAAC,QAAQ,CAAC,MAAmB;QACtC,IAAI,KAA8B,CAAC;QACnC,IAAI,OAAO,MAAM,IAAI,QAAQ,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;YAC3C,KAAK,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,EAAE;gBAClD,sBAAsB;gBACtB,qBAAqB;gBACrB,OAAO,EAAE;gBACL,uDAAuD;gBACvD,gBAAgB;iBACnB;gBACD,OAAO,EAAE,M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