modelence 0.14.1 → 0.15.2-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -59
- package/dist/{chunk-DIWBKGBL.js → chunk-3SPXJEOR.js} +2 -2
- package/dist/chunk-3SPXJEOR.js.map +1 -0
- package/dist/chunk-D6FY7A77.js +2 -0
- package/dist/chunk-D6FY7A77.js.map +1 -0
- package/dist/chunk-MF6PQMFH.js +3 -0
- package/dist/chunk-MF6PQMFH.js.map +1 -0
- package/dist/client.d.ts +154 -13
- package/dist/client.js +1 -1
- package/dist/client.js.map +1 -1
- package/dist/{index-CwdohC5n.d.ts → index-CLpVWWuj.d.ts} +6 -2
- package/dist/index.d.ts +2 -2
- package/dist/{package-2Z6OSR3A.js → package-O4GYADO2.js} +2 -2
- package/dist/{package-2Z6OSR3A.js.map → package-O4GYADO2.js.map} +1 -1
- package/dist/server.d.ts +41 -18
- package/dist/server.js +11 -11
- package/dist/server.js.map +1 -1
- package/dist/telemetry.js +1 -1
- package/dist/{types-CSQ5Qjb4.d.ts → types-Cm6x0ToB.d.ts} +12 -7
- package/dist/{types-BtENzxGq.d.ts → types-CoDMtVYU.d.ts} +77 -10
- package/dist/types.d.ts +3 -3
- package/package.json +1 -1
- package/dist/chunk-3S2FFBNS.js +0 -2
- package/dist/chunk-3S2FFBNS.js.map +0 -1
- package/dist/chunk-DIWBKGBL.js.map +0 -1
- package/dist/chunk-ZGSW7HE6.js +0 -3
- package/dist/chunk-ZGSW7HE6.js.map +0 -1
package/dist/telemetry.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{m as captureError,i as logDebug,k as logError,j as logInfo,l as startTransaction}from'./chunk-
|
|
1
|
+
export{m as captureError,i as logDebug,k as logError,j as logInfo,l as startTransaction}from'./chunk-3SPXJEOR.js';//# sourceMappingURL=telemetry.js.map
|
|
2
2
|
//# sourceMappingURL=telemetry.js.map
|
|
@@ -12,6 +12,7 @@ import { Document, ObjectId } from 'mongodb';
|
|
|
12
12
|
*/
|
|
13
13
|
type ConfigType = 'text' | 'string' | 'number' | 'boolean' | 'secret';
|
|
14
14
|
type ConfigKey = string;
|
|
15
|
+
type ValueType<T extends ConfigType = ConfigType> = T extends 'number' ? number : T extends 'string' ? string : T extends 'text' ? string : T extends 'boolean' ? boolean : T extends 'secret' ? string : never;
|
|
15
16
|
/**
|
|
16
17
|
* Defines a single configuration field within a module's `configSchema`.
|
|
17
18
|
*
|
|
@@ -24,17 +25,17 @@ type ConfigKey = string;
|
|
|
24
25
|
* }
|
|
25
26
|
* ```
|
|
26
27
|
*/
|
|
27
|
-
type ConfigParams = {
|
|
28
|
+
type ConfigParams<T extends ConfigType = ConfigType, IsPublic extends boolean = boolean> = {
|
|
28
29
|
/** The data type of this configuration value. */
|
|
29
|
-
type:
|
|
30
|
+
type: T;
|
|
30
31
|
/** The default value used when no value has been set. */
|
|
31
|
-
default: ValueType<
|
|
32
|
+
default: ValueType<T>;
|
|
32
33
|
/**
|
|
33
34
|
* Whether this config value is accessible on the client via `getConfig()` from `modelence/client`.
|
|
34
35
|
*
|
|
35
36
|
* Config values with `type: 'secret'` cannot be public.
|
|
36
37
|
*/
|
|
37
|
-
isPublic:
|
|
38
|
+
isPublic: IsPublic;
|
|
38
39
|
};
|
|
39
40
|
type AppConfig = {
|
|
40
41
|
key: ConfigKey;
|
|
@@ -69,7 +70,6 @@ type ConfigSchema = {
|
|
|
69
70
|
[key: string]: ConfigParams;
|
|
70
71
|
};
|
|
71
72
|
type Configs = Record<ConfigKey, AppConfig>;
|
|
72
|
-
type ValueType<T> = T extends 'number' ? number : T extends 'string' ? string : T extends 'text' ? string : T extends 'boolean' ? boolean : T extends 'secret' ? string : never;
|
|
73
73
|
|
|
74
74
|
interface UserEmail {
|
|
75
75
|
address: string;
|
|
@@ -147,7 +147,9 @@ type RoleDefinition = {
|
|
|
147
147
|
/** @internal */
|
|
148
148
|
permissions?: Permission[];
|
|
149
149
|
};
|
|
150
|
-
|
|
150
|
+
declare const SUPPORTED_OAUTH_PROVIDERS: readonly ["google", "github"];
|
|
151
|
+
type OAuthProvider = (typeof SUPPORTED_OAUTH_PROVIDERS)[number];
|
|
152
|
+
type AuthProvider = OAuthProvider | 'email';
|
|
151
153
|
type AuthSuccessProps = {
|
|
152
154
|
provider: AuthProvider;
|
|
153
155
|
user: User;
|
|
@@ -195,6 +197,9 @@ type SignupProps = UpdateProfileProps & {
|
|
|
195
197
|
password: string;
|
|
196
198
|
};
|
|
197
199
|
type Handler<T = unknown> = (args: Args, context: Context) => Promise<T> | T;
|
|
200
|
+
type AnyMethodShape = ((...args: any[]) => any) | {
|
|
201
|
+
handler: (...args: any[]) => any;
|
|
202
|
+
};
|
|
198
203
|
type MethodType = 'query' | 'mutation';
|
|
199
204
|
type MethodDefinition<T = unknown> = {
|
|
200
205
|
/** @internal */
|
|
@@ -271,4 +276,4 @@ interface WebsocketClientProvider {
|
|
|
271
276
|
}): void;
|
|
272
277
|
}
|
|
273
278
|
|
|
274
|
-
export { type
|
|
279
|
+
export { type AnyMethodShape as A, type ConfigSchema as C, type DefaultRoles as D, type Handler as H, type MethodDefinition as M, type OAuthProvider as O, type Permission as P, type RoleDefinition as R, ServerChannel as S, type UpdateProfileProps as U, type ValueType as V, type WebsocketServerProvider as W, type WebsocketClientProvider as a, type ConfigKey as b, type ConfigParams as c, type ConfigType as d, ClientChannel as e, type SignupProps as f, type AuthSuccessProps as g, type AuthErrorProps as h, type User as i, type AppConfig as j, type Session as k, type UserInfo as l, type Role as m, type Context as n, type ClientInfo as o, type ConnectionInfo as p, type Args as q, type MethodType as r, type Method as s, type Configs as t, type UserEmail as u, SUPPORTED_OAUTH_PROVIDERS as v, type AuthProvider as w };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import './index-
|
|
2
|
-
import {
|
|
1
|
+
import './index-CLpVWWuj.js';
|
|
2
|
+
import { n as Context } from './types-Cm6x0ToB.js';
|
|
3
3
|
import * as mongodb from 'mongodb';
|
|
4
|
-
import { WithId, IndexDescription, SearchIndexDescription, MongoClient, Collection, FilterOperators, Document, FindOptions, ObjectId, SortDirection, OptionalUnlessRequiredId, InsertOneResult, InsertManyResult, UpdateFilter, UpdateResult,
|
|
4
|
+
import { WithId, IndexDescription, SearchIndexDescription, MongoClient, Collection, FilterOperators, Document, FindOptions, ObjectId, SortDirection, OptionalUnlessRequiredId, ClientSession, InsertOneResult, InsertManyResult, UpdateFilter, UpdateResult, DeleteResult, FindOneAndUpdateOptions, FindOneAndDeleteOptions, WithoutId, FindOneAndReplaceOptions, ReplaceOptions, DistinctOptions, ChangeStreamOptions, ChangeStream, AggregateOptions, AggregationCursor, AnyBulkWriteOperation, BulkWriteResult } from 'mongodb';
|
|
5
5
|
import { z, ZodNumber, ZodArray } from 'zod';
|
|
6
6
|
import { Request, Response, NextFunction } from 'express';
|
|
7
7
|
|
|
@@ -127,6 +127,7 @@ type StrictRootFilterOperators<TSchema> = {
|
|
|
127
127
|
* @internal
|
|
128
128
|
*/
|
|
129
129
|
type ArrayElement<T> = T extends (infer E)[] ? E : never;
|
|
130
|
+
type Flatten<T> = T extends ReadonlyArray<infer E> ? E : T;
|
|
130
131
|
/**
|
|
131
132
|
* Helper type for $in/$nin that accepts any array/tuple where elements are assignable to T
|
|
132
133
|
* This solves the issue where TypeScript infers ['a', 'b'] as a tuple instead of ('a' | 'b')[]
|
|
@@ -430,14 +431,18 @@ declare class Store<TSchema extends ModelSchema, TMethods extends Record<string,
|
|
|
430
431
|
* @param document - The document to insert
|
|
431
432
|
* @returns The result of the insert operation
|
|
432
433
|
*/
|
|
433
|
-
insertOne(document: OptionalUnlessRequiredId<InferDocumentType<TSchema
|
|
434
|
+
insertOne(document: OptionalUnlessRequiredId<InferDocumentType<TSchema>>, options?: {
|
|
435
|
+
session?: ClientSession;
|
|
436
|
+
}): Promise<InsertOneResult>;
|
|
434
437
|
/**
|
|
435
438
|
* Inserts multiple documents
|
|
436
439
|
*
|
|
437
440
|
* @param documents - The documents to insert
|
|
438
441
|
* @returns The result of the insert operation
|
|
439
442
|
*/
|
|
440
|
-
insertMany(documents: OptionalUnlessRequiredId<InferDocumentType<TSchema>>[]
|
|
443
|
+
insertMany(documents: OptionalUnlessRequiredId<InferDocumentType<TSchema>>[], options?: {
|
|
444
|
+
session?: ClientSession;
|
|
445
|
+
}): Promise<InsertManyResult>;
|
|
441
446
|
/**
|
|
442
447
|
* Updates a single document
|
|
443
448
|
*
|
|
@@ -445,7 +450,9 @@ declare class Store<TSchema extends ModelSchema, TMethods extends Record<string,
|
|
|
445
450
|
* @param update - The update to apply to the document
|
|
446
451
|
* @returns The result of the update operation
|
|
447
452
|
*/
|
|
448
|
-
updateOne(selector: TypedFilter<this['_type']> | string | ObjectId, update: UpdateFilter<this['_type']
|
|
453
|
+
updateOne(selector: TypedFilter<this['_type']> | string | ObjectId, update: UpdateFilter<this['_type']>, options?: {
|
|
454
|
+
session?: ClientSession;
|
|
455
|
+
}): Promise<UpdateResult>;
|
|
449
456
|
/**
|
|
450
457
|
* Updates a single document, or inserts it if it doesn't exist
|
|
451
458
|
*
|
|
@@ -453,7 +460,9 @@ declare class Store<TSchema extends ModelSchema, TMethods extends Record<string,
|
|
|
453
460
|
* @param update - The MongoDB modifier to apply to the document
|
|
454
461
|
* @returns The result of the update operation
|
|
455
462
|
*/
|
|
456
|
-
upsertOne(selector: TypedFilter<this['_type']> | string | ObjectId, update: UpdateFilter<this['_type']
|
|
463
|
+
upsertOne(selector: TypedFilter<this['_type']> | string | ObjectId, update: UpdateFilter<this['_type']>, options?: {
|
|
464
|
+
session?: ClientSession;
|
|
465
|
+
}): Promise<UpdateResult>;
|
|
457
466
|
/**
|
|
458
467
|
* Updates multiple documents
|
|
459
468
|
*
|
|
@@ -471,21 +480,79 @@ declare class Store<TSchema extends ModelSchema, TMethods extends Record<string,
|
|
|
471
480
|
* @param update - The MongoDB modifier to apply to the documents
|
|
472
481
|
* @returns The result of the update operation
|
|
473
482
|
*/
|
|
474
|
-
upsertMany(selector: TypedFilter<this['_type']>, update: UpdateFilter<this['_type']
|
|
483
|
+
upsertMany(selector: TypedFilter<this['_type']>, update: UpdateFilter<this['_type']>, options?: {
|
|
484
|
+
session?: ClientSession;
|
|
485
|
+
}): Promise<UpdateResult>;
|
|
475
486
|
/**
|
|
476
487
|
* Deletes a single document
|
|
477
488
|
*
|
|
478
489
|
* @param selector - The selector to find the document to delete
|
|
479
490
|
* @returns The result of the delete operation
|
|
480
491
|
*/
|
|
481
|
-
deleteOne(selector: TypedFilter<this['_type']
|
|
492
|
+
deleteOne(selector: TypedFilter<this['_type']>, options?: {
|
|
493
|
+
session?: ClientSession;
|
|
494
|
+
}): Promise<DeleteResult>;
|
|
482
495
|
/**
|
|
483
496
|
* Deletes multiple documents
|
|
484
497
|
*
|
|
485
498
|
* @param selector - The selector to find the documents to delete
|
|
486
499
|
* @returns The result of the delete operation
|
|
487
500
|
*/
|
|
488
|
-
deleteMany(selector: TypedFilter<this['_type']
|
|
501
|
+
deleteMany(selector: TypedFilter<this['_type']>, options?: {
|
|
502
|
+
session?: ClientSession;
|
|
503
|
+
}): Promise<DeleteResult>;
|
|
504
|
+
/**
|
|
505
|
+
* Atomically finds a document and updates it, returning the document
|
|
506
|
+
*
|
|
507
|
+
* @param selector - The selector to find the document
|
|
508
|
+
* @param update - The update to apply
|
|
509
|
+
* @param options - Options including `returnDocument` ('before' or 'after'), `upsert`, `session`, etc.
|
|
510
|
+
* @returns The document (before or after update, depending on options), or null if not found
|
|
511
|
+
*/
|
|
512
|
+
findOneAndUpdate(selector: TypedFilter<this['_type']> | string | ObjectId, update: UpdateFilter<this['_type']>, options?: Omit<FindOneAndUpdateOptions, 'includeResultMetadata'>): Promise<this['_doc'] | null>;
|
|
513
|
+
/**
|
|
514
|
+
* Atomically finds a document and deletes it, returning the deleted document
|
|
515
|
+
*
|
|
516
|
+
* @param selector - The selector to find the document
|
|
517
|
+
* @param options - Options including `session`, `projection`, etc.
|
|
518
|
+
* @returns The deleted document, or null if not found
|
|
519
|
+
*/
|
|
520
|
+
findOneAndDelete(selector: TypedFilter<this['_type']> | string | ObjectId, options?: Omit<FindOneAndDeleteOptions, 'includeResultMetadata'>): Promise<this['_doc'] | null>;
|
|
521
|
+
/**
|
|
522
|
+
* Atomically finds a document and replaces it, returning the document
|
|
523
|
+
*
|
|
524
|
+
* @param selector - The selector to find the document
|
|
525
|
+
* @param replacement - The replacement document
|
|
526
|
+
* @param options - Options including `returnDocument` ('before' or 'after'), `upsert`, `session`, etc.
|
|
527
|
+
* @returns The document (before or after replacement, depending on options), or null if not found
|
|
528
|
+
*/
|
|
529
|
+
findOneAndReplace(selector: TypedFilter<this['_type']> | string | ObjectId, replacement: WithoutId<this['_type']>, options?: Omit<FindOneAndReplaceOptions, 'includeResultMetadata'>): Promise<this['_doc'] | null>;
|
|
530
|
+
/**
|
|
531
|
+
* Replaces a single document
|
|
532
|
+
*
|
|
533
|
+
* @param selector - The selector to find the document to replace
|
|
534
|
+
* @param replacement - The replacement document (must not contain update operators)
|
|
535
|
+
* @param options - Options including `upsert`, `session`, etc.
|
|
536
|
+
* @returns The result of the replace operation
|
|
537
|
+
*/
|
|
538
|
+
replaceOne(selector: TypedFilter<this['_type']> | string | ObjectId, replacement: WithoutId<this['_type']>, options?: ReplaceOptions): Promise<UpdateResult>;
|
|
539
|
+
/**
|
|
540
|
+
* Returns an array of distinct values for a field across the collection
|
|
541
|
+
*
|
|
542
|
+
* @param key - The field name (supports dot notation for nested fields)
|
|
543
|
+
* @param filter - Optional filter to narrow the documents
|
|
544
|
+
* @param options - Optional distinct options
|
|
545
|
+
* @returns An array of distinct values
|
|
546
|
+
*/
|
|
547
|
+
distinct<K extends keyof this['_rawDoc'] & string>(key: K, filter?: TypedFilter<this['_type']>, options?: DistinctOptions): Promise<Array<Flatten<this['_rawDoc'][K]>>>;
|
|
548
|
+
/**
|
|
549
|
+
* Opens a change stream on the collection to watch for real-time changes
|
|
550
|
+
*
|
|
551
|
+
* @param pipeline - Optional aggregation pipeline to filter/transform change events
|
|
552
|
+
* @param options - Optional change stream options
|
|
553
|
+
* @returns A ChangeStream instance
|
|
554
|
+
*/
|
|
555
|
+
watch(pipeline?: Document[], options?: ChangeStreamOptions): ChangeStream;
|
|
489
556
|
/**
|
|
490
557
|
* Aggregates documents using MongoDB's aggregation framework
|
|
491
558
|
*
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { A as AppServer, E as ExpressMiddleware, M as ModelenceConfig } from './index-
|
|
2
|
-
export {
|
|
3
|
-
export { B as BodyConfig, h as CronJob, C as CronJobInputParams, i as CronJobMetadata, g as EmailAttachment, c as EmailPayload, E as EmailProvider, k as ExpressHandler, H as HttpMethod, I as InferDocumentType, M as ModelSchema, a as RateLimitRule, b as RateLimitType, R as RouteDefinition, d as RouteHandler, j as RouteHandlers, e as RouteParams, f as RouteResponse, s as schema } from './types-
|
|
1
|
+
export { A as AppServer, a as AppServerInitOptions, E as ExpressMiddleware, M as ModelenceConfig } from './index-CLpVWWuj.js';
|
|
2
|
+
export { A as AnyMethodShape, j as AppConfig, q as Args, h as AuthErrorProps, w as AuthProvider, g as AuthSuccessProps, o as ClientInfo, b as ConfigKey, c as ConfigParams, C as ConfigSchema, d as ConfigType, t as Configs, p as ConnectionInfo, n as Context, D as DefaultRoles, H as Handler, s as Method, M as MethodDefinition, r as MethodType, O as OAuthProvider, P as Permission, m as Role, R as RoleDefinition, v as SUPPORTED_OAUTH_PROVIDERS, k as Session, f as SignupProps, U as UpdateProfileProps, i as User, u as UserEmail, l as UserInfo, V as ValueType, a as WebsocketClientProvider, W as WebsocketServerProvider } from './types-Cm6x0ToB.js';
|
|
3
|
+
export { B as BodyConfig, h as CronJob, C as CronJobInputParams, i as CronJobMetadata, g as EmailAttachment, c as EmailPayload, E as EmailProvider, k as ExpressHandler, H as HttpMethod, I as InferDocumentType, M as ModelSchema, a as RateLimitRule, b as RateLimitType, R as RouteDefinition, d as RouteHandler, j as RouteHandlers, e as RouteParams, f as RouteResponse, s as schema } from './types-CoDMtVYU.js';
|
|
4
4
|
import 'express';
|
|
5
5
|
import 'http';
|
|
6
6
|
import 'mongodb';
|
package/package.json
CHANGED
package/dist/chunk-3S2FFBNS.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function s(e){if(e instanceof Date)return {type:"date"};if(Array.isArray(e)){let n={};for(let r=0;r<e.length;r++){let t=e[r],o=s(t);o&&(n[r]=o);}return Object.keys(n).length>0?{type:"array",elements:n}:null}if(typeof e=="object"&&e!==null){let n={};for(let[r,t]of Object.entries(e)){let o=s(t);o&&(n[r]=o);}return Object.keys(n).length>0?{type:"object",props:n}:null}return null}function i(e,n){return n?n.type==="date"?new Date(e):n.type==="array"?e.map((r,t)=>i(r,n.elements[t])):n.type==="object"?Object.fromEntries(Object.entries(e).map(([r,t])=>[r,i(t,n.props[r])])):e:e}export{s as a,i as b};//# sourceMappingURL=chunk-3S2FFBNS.js.map
|
|
2
|
-
//# sourceMappingURL=chunk-3S2FFBNS.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/methods/serialize.ts"],"names":["getResponseTypeMap","result","elements","i","item","subTypeMap","props","key","value","reviveResponseTypes","data","typeMap","index"],"mappings":"AAAO,SAASA,EAAmBC,CAAAA,CAAiB,CAClD,GAAIA,CAAAA,YAAkB,KACpB,OAAO,CAAE,IAAA,CAAM,MAAO,EAGxB,GAAI,KAAA,CAAM,QAAQA,CAAM,CAAA,CAAG,CACzB,IAAMC,CAAAA,CAAoC,EAAC,CAC3C,QAASC,CAAAA,CAAI,CAAA,CAAGA,CAAAA,CAAIF,CAAAA,CAAO,OAAQE,CAAAA,EAAAA,CAAK,CACtC,IAAMC,CAAAA,CAAOH,EAAOE,CAAC,CAAA,CACfE,EAAaL,CAAAA,CAAmBI,CAAI,EACtCC,CAAAA,GACFH,CAAAA,CAASC,CAAC,CAAA,CAAIE,GAElB,CACA,OAAO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{\n return { type: 'date' };\n }\n\n if (Array.isArray(result)) {\n const elements: Record<string, unknown> = {};\n for (let i = 0; i < result.length; i++) {\n const item = result[i];\n const subTypeMap = getResponseTypeMap(item);\n if (subTypeMap) {\n elements[i] = subTypeMap;\n }\n }\n return Object.keys(elements).length > 0\n ? {\n type: 'array',\n elements,\n }\n : null;\n }\n\n if (typeof result === 'object' && result !== null) {\n const props: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(result)) {\n const subTypeMap = getResponseTypeMap(value);\n if (subTypeMap) {\n props[key] = subTypeMap;\n }\n }\n return Object.keys(props).length > 0\n ? {\n type: 'object',\n props,\n }\n : null;\n }\n\n return null;\n}\n\nexport function reviveResponseTypes<T = unknown>(data: T, typeMap?: Record<string, unknown>): T {\n if (!typeMap) {\n return data;\n }\n\n if (typeMap.type === 'date') {\n return new Date(data as string) as T;\n }\n\n if (typeMap.type === 'array') {\n return (data as unknown[]).map((item: unknown, index: number) =>\n reviveResponseTypes(item, (typeMap.elements as Record<string, unknown>[])[index])\n ) as T;\n }\n\n if (typeMap.type === 'object') {\n return Object.fromEntries(\n Object.entries(data as Record<string, unknown>).map(([key, value]) => [\n key,\n reviveResponseTypes(\n value,\n (typeMap.props as Record<string, unknown>)[key] as Record<string, unknown>\n ),\n ])\n ) as T;\n }\n\n return data;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config/server.ts","../src/app/loggerProcess.ts","../src/app/state.ts","../src/app/metrics.ts","../src/telemetry/index.ts"],"names":["configSchema","config","isInitialized","getConfig","key","getPublicConfigs","_","schema","loadConfigs","configs","type","value","getSchema","setSchema","isPublic","buffer","sequenceId","startLoggerProcess","_elasticCloudId","_elasticApiKey","originalStdoutWrite","process","originalStderrWrite","chunk","args","addToBuffer","loopSendLogs","timestamp","i","current","sendLogs","stdoutLogs","stderrLogs","log","logInfo","logError","metadata","markAppStarted","setMetadata","_metadata","getEnvironmentId","getAppAlias","getEnvironmentAlias","getTelemetryServiceName","isTelemetryEnabled","apm","logger","initMetrics","initElasticApm","elasticApmEndpoint","elasticCloudId","elasticApiKey","appAlias","environmentAlias","environmentId","serviceName","elasticApm","esTransport","ElasticsearchTransport","error","winston","getApm","isLoggerReady","getLogger","getLogLevel","defaultLoglevel","logDebug","message","startTransaction","name","context","transaction","result","endTime","captureError"],"mappings":"yIAEA,IAAIA,CAAAA,CAA6B,EAAC,CAC9BC,CAAAA,CAAuC,EAAC,CACxCC,CAAAA,CAAgB,KAAA,CAsCb,SAASC,EAAUC,CAAAA,CAAgB,CACxC,OAAOH,CAAAA,CAAOG,CAAG,CAAA,EAAG,KAAA,EAASJ,CAAAA,CAAaI,CAAG,GAAG,OAClD,CAEO,SAASC,CAAAA,EAAmB,CACjC,GAAI,CAACH,CAAAA,CACH,MAAM,IAAI,KAAA,CACR,0FACF,CAAA,CAGF,OAAO,MAAA,CAAO,WAAA,CACZ,MAAA,CAAO,OAAA,CAAQF,CAAY,CAAA,CACxB,MAAA,CAAO,CAAC,CAACM,EAAGC,CAAM,CAAA,GAAMA,CAAAA,CAAO,QAAQ,EACvC,GAAA,CAAI,CAAC,CAACH,CAAAA,CAAKG,CAAM,CAAA,GACT,CACLH,CAAAA,CACA,CACE,IAAAA,CAAAA,CACA,IAAA,CAAMG,CAAAA,CAAO,IAAA,CACb,MAAON,CAAAA,CAAOG,CAAG,CAAA,EAAG,KAAA,EAASG,CAAAA,CAAO,OACtC,CACF,CACD,CACL,CACF,CAEO,SAASC,CAAAA,CAAYC,EAAsB,CAChDA,CAAAA,CAAQ,OAAA,CAAQ,CAAC,CAAE,GAAA,CAAAL,CAAAA,CAAK,IAAA,CAAAM,CAAAA,CAAM,MAAAC,CAAM,CAAA,GAAM,CAGpC,CAFmBP,EAAI,WAAA,EAAY,CAAE,UAAA,CAAW,UAAU,GAEvC,CAACJ,CAAAA,CAAaI,CAAG,CAAA,GAKxCH,EAAOG,CAAG,CAAA,CAAI,CACZ,GAAA,CAAAA,CAAAA,CAC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,CAAAA,CAAaf,CAAAA,CAAc,CACzC,GAAI,CAACf,CAAAA,EAAmB,CAAG,CACzB,OAAA,CAAQ,KAAA,CAAMe,CAAK,CAAA,CACnB,MACF,CAEAE,CAAAA,EAAO,CAAE,YAAA,CAAaF,CAAK,EAC7B","file":"chunk-DIWBKGBL.js","sourcesContent":["import { AppConfig, ConfigKey, ConfigSchema } from './types';\n\nlet configSchema: ConfigSchema = {};\nlet config: Record<ConfigKey, AppConfig> = {};\nlet isInitialized = false;\n\n/**\n * @sidebarTitle getConfig (server)\n *\n * @param key - The configuration key to retrieve\n * @returns The configuration value (string, number, or boolean)\n *\n * @example\n * ```ts\n * import { getConfig } from 'modelence/server';\n *\n * // Get the site URL\n * const siteUrl = getConfig('_system.site.url');\n * ```\n *\n * Set via environment variable:\n * ```bash\n * MODELENCE_SITE_URL=https://myapp.com\n * ```\n *\n * @example\n * ```ts\n * import { getConfig } from 'modelence/server';\n *\n * // Get the current environment (e.g., 'development', 'staging', 'production')\n * const env = getConfig('_system.env');\n *\n * if (env === 'production') {\n * // Enable production features\n * }\n * ```\n *\n * Set via environment variable:\n * ```bash\n * MODELENCE_SITE_ENV=production\n * ```\n */\nexport function getConfig(key: ConfigKey) {\n return config[key]?.value ?? configSchema[key]?.default;\n}\n\nexport function getPublicConfigs() {\n if (!isInitialized) {\n throw new Error(\n 'Config is not initialized: an attempt was made to access configs before they were loaded'\n );\n }\n\n return Object.fromEntries(\n Object.entries(configSchema)\n .filter(([_, schema]) => schema.isPublic)\n .map(([key, schema]) => {\n return [\n key,\n {\n key,\n type: schema.type,\n value: config[key]?.value ?? schema.default,\n },\n ];\n })\n );\n}\n\nexport function loadConfigs(configs: AppConfig[]) {\n configs.forEach(({ key, type, value }) => {\n const isSystemConfig = key.toLowerCase().startsWith('_system.');\n\n if (!isSystemConfig && !configSchema[key]) {\n // Ignore unknown configs\n return;\n }\n\n config[key] = {\n key,\n type,\n value,\n };\n });\n\n isInitialized = true;\n}\n\nexport function getSchema() {\n return configSchema;\n}\n\nexport function setSchema(schema: ConfigSchema) {\n // TODO: more validation on the schema structure\n Object.entries(schema).forEach(([key, value]) => {\n const { type, isPublic } = value;\n\n if (type === 'secret' && isPublic) {\n throw new Error(`Config ${key} with type \"secret\" cannot be public`);\n }\n });\n\n configSchema = schema;\n}\n","// import { spawn } from 'child_process';\n// import { fileURLToPath } from 'url';\n// import { dirname, join } from 'path';\nimport { logInfo, logError } from '@/telemetry';\nimport process from 'process';\n\ntype LogEntry = { log: string; timestamp: Date | null; sequenceId?: number };\ntype LogBuffer = LogEntry[];\n\nconst buffer: { stdout: LogBuffer; stderr: LogBuffer } = {\n stdout: [{ log: '', timestamp: null }],\n stderr: [{ log: '', timestamp: null }],\n};\n\nlet sequenceId = 1;\n\nexport function startLoggerProcess({\n elasticCloudId: _elasticCloudId,\n elasticApiKey: _elasticApiKey,\n}: {\n elasticCloudId: string;\n elasticApiKey: string;\n}) {\n const originalStdoutWrite = process.stdout.write;\n const originalStderrWrite = process.stderr.write;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n process.stdout.write = function (chunk: string | Uint8Array, ...args: any[]) {\n addToBuffer(chunk.toString(), buffer.stdout);\n return originalStdoutWrite.call(process.stdout, chunk, ...args);\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n process.stderr.write = function (chunk: string | Uint8Array, ...args: any[]) {\n addToBuffer(chunk.toString(), buffer.stderr);\n return originalStderrWrite.call(process.stderr, chunk, ...args);\n };\n\n loopSendLogs();\n\n // const currentFilePath = fileURLToPath(import.meta.url);\n // const projectRoot = dirname(dirname(currentFilePath));\n // const loggerPath = join(projectRoot, 'bin', 'modelence-logger', 'index.js');\n // const logger = spawn(process.execPath, [loggerPath], {\n // env: {\n // NODE_ENV: process.env.NODE_ENV,\n // ELASTIC_CLOUD_ID: elasticCloudId,\n // ELASTIC_API_KEY: elasticApiKey\n // },\n // stdio: ['pipe', 'inherit', 'inherit'],\n // detached: true\n // });\n\n // const originalStdoutWrite = process.stdout.write;\n // const originalStderrWrite = process.stderr.write;\n\n // process.stdout.write = function(chunk: any, ...args: any[]) {\n // logger.stdin.write(chunk);\n // return originalStdoutWrite.apply(process.stdout, [chunk, ...args]);\n // };\n\n // process.stderr.write = function(chunk: any, ...args: any[]) {\n // logger.stdin.write(chunk);\n // return originalStderrWrite.apply(process.stderr, [chunk, ...args]);\n // };\n\n // process.on('exit', () => {\n // process.stdout.write = originalStdoutWrite;\n // process.stderr.write = originalStderrWrite;\n // });\n\n // logger.unref();\n}\n\nfunction addToBuffer(chunk: string, buffer: LogBuffer) {\n if (chunk.length === 0) {\n return;\n }\n\n const timestamp = new Date();\n\n for (let i = 0; i < chunk.length; i++) {\n const current = buffer[buffer.length - 1];\n if (!current.timestamp) {\n current.timestamp = timestamp;\n current.sequenceId = sequenceId++;\n }\n\n if (chunk[i] === '\\n') {\n buffer.push({ log: '', timestamp: null });\n } else {\n current.log += chunk[i];\n }\n }\n}\n\nasync function sendLogs() {\n const stdoutLogs = buffer.stdout.slice(0, -1);\n buffer.stdout = [buffer.stdout[buffer.stdout.length - 1]];\n\n const stderrLogs = buffer.stderr.slice(0, -1);\n buffer.stderr = [buffer.stderr[buffer.stderr.length - 1]];\n\n stdoutLogs.forEach(({ log, timestamp, sequenceId }: LogEntry) => {\n logInfo(log, { timestamp, source: 'console', sequenceId });\n });\n stderrLogs.forEach(({ log, timestamp, sequenceId }: LogEntry) => {\n logError(log, { timestamp, source: 'console', sequenceId });\n });\n}\n\nfunction loopSendLogs() {\n setTimeout(() => {\n sendLogs();\n loopSendLogs();\n }, 1000);\n}\n","type AppMetadata = {\n environmentId: string;\n appAlias: string;\n environmentAlias: string;\n telemetry: {\n isEnabled: boolean;\n serviceName: string;\n };\n};\n\nlet appStarted = false;\nlet metadata: AppMetadata | null = null;\n\nexport function markAppStarted() {\n appStarted = true;\n}\n\nexport function isAppStarted() {\n return appStarted;\n}\n\nexport function setMetadata(_metadata: AppMetadata) {\n metadata = Object.assign({}, metadata, _metadata);\n}\n\nexport function getEnvironmentId() {\n return metadata?.environmentId;\n}\n\nexport function getAppAlias() {\n return metadata?.appAlias;\n}\n\nexport function getEnvironmentAlias() {\n return metadata?.environmentAlias;\n}\n\nexport function getTelemetryServiceName() {\n return metadata?.telemetry?.serviceName;\n}\n\nexport function isTelemetryEnabled() {\n return Boolean(metadata?.telemetry?.isEnabled);\n}\n","import elasticApm from 'elastic-apm-node';\nimport winston from 'winston';\nimport { ElasticsearchTransport } from 'winston-elasticsearch';\n\nimport { getConfig } from '../config/server';\nimport { startLoggerProcess } from './loggerProcess';\nimport {\n getAppAlias,\n getEnvironmentAlias,\n getEnvironmentId,\n getTelemetryServiceName,\n isTelemetryEnabled,\n} from './state';\n\nlet isInitialized = false;\nlet apm: typeof elasticApm | null = null;\nlet logger: winston.Logger | null = null;\n\nexport const initMetrics = async () => {\n if (isInitialized) {\n throw new Error('Metrics are already initialized, duplicate \"initMetrics\" call received');\n }\n\n isInitialized = true;\n\n if (isTelemetryEnabled()) {\n await initElasticApm();\n }\n};\n\nasync function initElasticApm() {\n const elasticApmEndpoint = getConfig('_system.elastic.apmEndpoint') as string;\n const elasticCloudId = getConfig('_system.elastic.cloudId') as string;\n const elasticApiKey = getConfig('_system.elastic.apiKey') as string;\n\n const appAlias = getAppAlias() ?? 'unknown';\n const environmentAlias = getEnvironmentAlias() ?? 'unknown';\n const environmentId = getEnvironmentId() ?? 'unknown';\n const serviceName = getTelemetryServiceName();\n\n apm = elasticApm.start({\n serviceName,\n apiKey: elasticApiKey,\n serverUrl: elasticApmEndpoint,\n // environment: 'dev',\n transactionSampleRate: 1.0,\n centralConfig: false,\n globalLabels: {\n modelenceEnv: 'dev',\n appEnv: 'dev',\n environmentId,\n appAlias,\n environmentAlias,\n },\n // logLevel: 'debug'\n });\n\n const esTransport = new ElasticsearchTransport({\n apm,\n level: 'debug',\n clientOpts: {\n cloud: {\n id: elasticCloudId,\n },\n auth: {\n apiKey: elasticApiKey,\n },\n requestTimeout: 10000,\n tls: {\n rejectUnauthorized: false,\n },\n },\n bufferLimit: 1000,\n silent: false,\n });\n\n esTransport.on('error', (error) => {\n console.error('Elasticsearch Transport Error:', error);\n });\n\n logger = winston.createLogger({\n level: 'debug',\n defaultMeta: {\n serviceName,\n },\n format: winston.format.combine(winston.format.json()),\n transports: [\n // new winston.transports.Console(), // TODO: remove, just for debugging\n esTransport,\n ],\n });\n\n startLoggerProcess({\n elasticCloudId,\n elasticApiKey,\n });\n}\n\nexport function getApm() {\n if (!apm) {\n throw new Error('APM is not initialized');\n }\n return apm;\n}\n\nexport function isLoggerReady() {\n return logger !== null;\n}\n\nexport function getLogger() {\n if (!logger) {\n throw new Error('Logger is not initialized');\n }\n return logger;\n}\n","import { getLogger, getApm, isLoggerReady } from '@/app/metrics';\nimport { isTelemetryEnabled } from '@/app/state';\n\ntype LogLevel = 'error' | 'info' | 'debug' | '';\n\n/**\n * Gets the logging level for console logs based on the MODELENCE_LOG_LEVEL environment variable.\n *\n * @returns The log level ('error' | 'info' | 'debug' | '')\n *\n * Behavior:\n * - If MODELENCE_LOG_LEVEL is set, returns that value\n * - If telemetry is disabled and MODELENCE_LOG_LEVEL is not set, defaults to 'info'\n * - If telemetry is enabled and MODELENCE_LOG_LEVEL is not set, returns '' (no console logging)\n */\nfunction getLogLevel(): LogLevel {\n let defaultLoglevel: LogLevel = '';\n if (!isTelemetryEnabled()) {\n defaultLoglevel = 'info';\n }\n\n return (process.env.MODELENCE_LOG_LEVEL as LogLevel) || defaultLoglevel;\n}\n\nexport function logDebug(message: string, args: object) {\n if (isTelemetryEnabled() && isLoggerReady()) {\n getLogger().debug(message, args);\n }\n if (getLogLevel() === 'debug') {\n console.debug(message, args);\n }\n}\n\nexport function logInfo(message: string, args: object) {\n if (isTelemetryEnabled() && isLoggerReady()) {\n getLogger().info(message, args);\n }\n if (['debug', 'info'].includes(getLogLevel())) {\n console.info(message, args);\n }\n}\n\nexport function logError(message: string, args: object) {\n if (isTelemetryEnabled() && isLoggerReady()) {\n getLogger().error(message, args);\n }\n if (['debug', 'info', 'error'].includes(getLogLevel())) {\n console.error(message, args);\n }\n}\n\ninterface WrappedTransaction {\n end(result?: string, context?: Record<string, unknown>): void;\n setContext(context: Record<string, unknown>): void;\n}\n\nexport function startTransaction(\n type: 'method' | 'cron' | 'ai' | 'custom' | 'route',\n name: string,\n context?: Record<string, unknown>\n): WrappedTransaction {\n if (!isTelemetryEnabled()) {\n return {\n end: () => {\n // do nothing\n },\n setContext: () => {\n // do nothing\n },\n };\n }\n\n const apm = getApm();\n const transaction = apm.startTransaction(name, type);\n if (context) {\n apm.setCustomContext(context);\n }\n\n return {\n end: (\n result?: string,\n { endTime, context }: { endTime?: number; context?: Record<string, unknown> } = {}\n ) => {\n if (context) {\n apm.setCustomContext(context);\n }\n transaction.end(result, endTime);\n },\n setContext: (context: Record<string, unknown>) => {\n apm.setCustomContext(context);\n },\n };\n}\n\nexport function captureError(error: Error) {\n if (!isTelemetryEnabled()) {\n console.error(error);\n return;\n }\n\n getApm().captureError(error);\n}\n"]}
|
package/dist/chunk-ZGSW7HE6.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
var s="module",i="modelence",r="0.14.1",o="The Node.js Framework for Real-Time MongoDB Apps",n="dist/index.js",p="dist/global.d.ts",c={".":"./dist/index.js","./client":"./dist/client.js","./server":"./dist/server.js","./telemetry":"./dist/telemetry.js","./mongodb":"./dist/mongo.js","./types":{types:"./dist/types.d.ts",default:"./dist/types.js"}},d=["dist","dist/bin"],l={modelence:"./dist/bin/modelence.js"},a={build:"tsup",dev:"tsup --watch",format:'prettier --write "src/**/*.{ts,tsx,js,jsx,json,css,md}"',"format:check":'prettier --check "src/**/*.{ts,tsx,js,jsx,json,css,md}"',lint:"eslint src --ext .ts,.tsx --fix","lint:check":"eslint src --ext .ts,.tsx",prepublishOnly:"npm run build",test:"NODE_OPTIONS=--experimental-vm-modules jest","test:watch":"NODE_OPTIONS=--experimental-vm-modules jest --watch","test:coverage":"NODE_OPTIONS=--experimental-vm-modules jest --coverage",postversion:"git push && git push --tags",prepare:"cd ../.. && git config core.hooksPath .husky"},m={type:"git",url:"git+https://github.com/modelence/modelence.git"},y="Modelence",u="SEE LICENSE IN LICENSE",j={url:"https://github.com/modelence/modelence/issues"},g="https://modelence.com",h={"@types/archiver":"^6.0.3","@types/bcrypt":"^6.0.0","@types/cookie-parser":"^1.4.9","@types/express":"^5.0.0","@types/fs-extra":"^11.0.4","@types/jest":"^30.0.0","@types/node":"^22.5.1","@types/react":"^19.0.0","@types/react-dom":"^19.0.1","@types/socket.io":"^3.0.1","@typescript-eslint/eslint-plugin":"^8.17.0","@typescript-eslint/parser":"^8.17.0",eslint:"^9.37.0",husky:"^9.1.7",jest:"^30.2.0","lint-staged":"^16.2.7",prettier:"^3.6.2",react:"^19.0.0","react-dom":"^19.0.0","ts-jest":"^29.4.5","ts-node":"^10.9.2"},x={"@socket.io/mongo-adapter":"^0.4.0","@vitejs/plugin-react":"^4.3.4",archiver:"^7.0.1",bcrypt:"^6.0.0",commander:"^12.0.0","cookie-parser":"^1.4.7",dotenv:"^16.4.5","elastic-apm-node":"^4.15.0",express:"^4.21.0","fs-extra":"^11.2.0",jiti:"^2.4.2",mongodb:"^6.8.1",open:"^10.1.0","socket.io":"^4.8.1","socket.io-client":"^4.8.1",tsup:"^8.3.6",tsx:"^4.19.3",typescript:"^5.7.2",vite:"^6.0.3","vite-plugin-eslint":"^1.8.1",winston:"^3.15.0","winston-elasticsearch":"^0.19.0",zod:"^3.23.8",zustand:"^5.0.2"},v={react:">=18.0.0","react-dom":">=18.0.0"},b={type:s,name:i,version:r,description:o,main:n,types:p,exports:c,files:d,bin:l,scripts:a,"lint-staged":{"src/**/*.{ts,tsx,js,jsx,json,css,md}":"prettier --write"},repository:m,author:y,license:u,bugs:j,homepage:g,devDependencies:h,dependencies:x,peerDependencies:v};
|
|
2
|
-
export{s as a,i as b,r as c,o as d,n as e,p as f,c as g,d as h,l as i,a as j,m as k,y as l,u as m,j as n,g as o,h as p,x as q,v as r,b as s};//# sourceMappingURL=chunk-ZGSW7HE6.js.map
|
|
3
|
-
//# sourceMappingURL=chunk-ZGSW7HE6.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json"],"names":["type","name","version","description","main","types","exports","files","bin","scripts","repository","author","license","bugs","homepage","devDependencies","dependencies","peerDependencies","package_default"],"mappings":"AACE,IAAAA,CAAAA,CAAQ,QAAA,CACRC,CAAAA,CAAQ,WAAA,CACRC,CAAAA,CAAW,SACXC,CAAAA,CAAe,kDAAA,CACfC,CAAAA,CAAQ,eAAA,CACRC,CAAAA,CAAS,kBAAA,CACTC,EAAW,CACT,GAAA,CAAK,iBAAA,CACL,UAAA,CAAY,kBAAA,CACZ,UAAA,CAAY,kBAAA,CACZ,aAAA,CAAe,qBAAA,CACf,WAAA,CAAa,iBAAA,CACb,SAAA,CAAW,CACT,KAAA,CAAS,oBACT,OAAA,CAAW,iBACb,CACF,CAAA,CACAC,CAAAA,CAAS,CACP,MAAA,CACA,UACF,CAAA,CACAC,CAAAA,CAAO,CACL,SAAA,CAAa,yBACf,CAAA,CACAC,EAAW,CACT,KAAA,CAAS,MAAA,CACT,GAAA,CAAO,cAAA,CACP,MAAA,CAAU,yDAAA,CACV,cAAA,CAAgB,yDAAA,CAChB,IAAA,CAAQ,iCAAA,CACR,YAAA,CAAc,2BAAA,CACd,cAAA,CAAkB,gBAClB,IAAA,CAAQ,6CAAA,CACR,YAAA,CAAc,qDAAA,CACd,eAAA,CAAiB,wDAAA,CACjB,YAAe,6BAAA,CACf,OAAA,CAAW,8CACb,CAAA,CAIAC,CAAAA,CAAc,CACZ,KAAQ,KAAA,CACR,GAAA,CAAO,gDACT,CAAA,CACAC,CAAAA,CAAU,WAAA,CACVC,CAAAA,CAAW,wBAAA,CACXC,CAAAA,CAAQ,CACN,GAAA,CAAO,+CACT,CAAA,CACAC,CAAAA,CAAY,wBACZC,CAAAA,CAAmB,CACj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A,CAAAC,CAAAA,CACA,WAAA,CAAAC,CAAAA,CACA,IAAA,CAAAC,CAAAA,CACA,KAAA,CAAAC,CAAAA,CACA,QAAAC,CAAAA,CAWA,KAAA,CAAAC,CAAAA,CAIA,GAAA,CAAAC,CAAAA,CAGA,OAAA,CAAAC,CAAAA,CAcA,aAAA,CAAe,CACb,sCAAA,CAAwC,kBAC1C,CAAA,CACA,UAAA,CAAAC,CAAAA,CAIA,OAAAC,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,IAAA,CAAAC,CAAAA,CAGA,QAAA,CAAAC,CAAAA,CACA,eAAA,CAAAC,CAAAA,CAuBA,YAAA,CAAAC,CAAAA,CA0BA,gBAAA,CAAAC,CAIF","file":"chunk-ZGSW7HE6.js","sourcesContent":["{\n \"type\": \"module\",\n \"name\": \"modelence\",\n \"version\": \"0.14.1\",\n \"description\": \"The Node.js Framework for Real-Time MongoDB Apps\",\n \"main\": \"dist/index.js\",\n \"types\": \"dist/global.d.ts\",\n \"exports\": {\n \".\": \"./dist/index.js\",\n \"./client\": \"./dist/client.js\",\n \"./server\": \"./dist/server.js\",\n \"./telemetry\": \"./dist/telemetry.js\",\n \"./mongodb\": \"./dist/mongo.js\",\n \"./types\": {\n \"types\": \"./dist/types.d.ts\",\n \"default\": \"./dist/types.js\"\n }\n },\n \"files\": [\n \"dist\",\n \"dist/bin\"\n ],\n \"bin\": {\n \"modelence\": \"./dist/bin/modelence.js\"\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"format\": \"prettier --write \\\"src/**/*.{ts,tsx,js,jsx,json,css,md}\\\"\",\n \"format:check\": \"prettier --check \\\"src/**/*.{ts,tsx,js,jsx,json,css,md}\\\"\",\n \"lint\": \"eslint src --ext .ts,.tsx --fix\",\n \"lint:check\": \"eslint src --ext .ts,.tsx\",\n \"prepublishOnly\": \"npm run build\",\n \"test\": \"NODE_OPTIONS=--experimental-vm-modules jest\",\n \"test:watch\": \"NODE_OPTIONS=--experimental-vm-modules jest --watch\",\n \"test:coverage\": \"NODE_OPTIONS=--experimental-vm-modules jest --coverage\",\n \"postversion\": \"git push && git push --tags\",\n \"prepare\": \"cd ../.. && git config core.hooksPath .husky\"\n },\n \"lint-staged\": {\n \"src/**/*.{ts,tsx,js,jsx,json,css,md}\": \"prettier --write\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/modelence/modelence.git\"\n },\n \"author\": \"Modelence\",\n \"license\": \"SEE LICENSE IN LICENSE\",\n \"bugs\": {\n \"url\": \"https://github.com/modelence/modelence/issues\"\n },\n \"homepage\": \"https://modelence.com\",\n \"devDependencies\": {\n \"@types/archiver\": \"^6.0.3\",\n \"@types/bcrypt\": \"^6.0.0\",\n \"@types/cookie-parser\": \"^1.4.9\",\n \"@types/express\": \"^5.0.0\",\n \"@types/fs-extra\": \"^11.0.4\",\n \"@types/jest\": \"^30.0.0\",\n \"@types/node\": \"^22.5.1\",\n \"@types/react\": \"^19.0.0\",\n \"@types/react-dom\": \"^19.0.1\",\n \"@types/socket.io\": \"^3.0.1\",\n \"@typescript-eslint/eslint-plugin\": \"^8.17.0\",\n \"@typescript-eslint/parser\": \"^8.17.0\",\n \"eslint\": \"^9.37.0\",\n \"husky\": \"^9.1.7\",\n \"jest\": \"^30.2.0\",\n \"lint-staged\": \"^16.2.7\",\n \"prettier\": \"^3.6.2\",\n \"react\": \"^19.0.0\",\n \"react-dom\": \"^19.0.0\",\n \"ts-jest\": \"^29.4.5\",\n \"ts-node\": \"^10.9.2\"\n },\n \"dependencies\": {\n \"@socket.io/mongo-adapter\": \"^0.4.0\",\n \"@vitejs/plugin-react\": \"^4.3.4\",\n \"archiver\": \"^7.0.1\",\n \"bcrypt\": \"^6.0.0\",\n \"commander\": \"^12.0.0\",\n \"cookie-parser\": \"^1.4.7\",\n \"dotenv\": \"^16.4.5\",\n \"elastic-apm-node\": \"^4.15.0\",\n \"express\": \"^4.21.0\",\n \"fs-extra\": \"^11.2.0\",\n \"jiti\": \"^2.4.2\",\n \"mongodb\": \"^6.8.1\",\n \"open\": \"^10.1.0\",\n \"socket.io\": \"^4.8.1\",\n \"socket.io-client\": \"^4.8.1\",\n \"tsup\": \"^8.3.6\",\n \"tsx\": \"^4.19.3\",\n \"typescript\": \"^5.7.2\",\n \"vite\": \"^6.0.3\",\n \"vite-plugin-eslint\": \"^1.8.1\",\n \"winston\": \"^3.15.0\",\n \"winston-elasticsearch\": \"^0.19.0\",\n \"zod\": \"^3.23.8\",\n \"zustand\": \"^5.0.2\"\n },\n \"peerDependencies\": {\n \"react\": \">=18.0.0\",\n \"react-dom\": \">=18.0.0\"\n }\n}\n"]}
|