Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
877e301
fix(optional): remove optional args
macornwell Mar 14, 2025
3e10ee2
Merge branch 'add-custom-logging'
macornwell Mar 14, 2025
4cb1d4b
feat(ts): add support for ts configs
macornwell Mar 14, 2025
352c975
chore(fm): update functional models
macornwell Mar 19, 2025
22221cd
feat(logging): refactor logging so it has a better more usable interface
macornwell Mar 20, 2025
e831ac7
chore(version): bump version
macornwell Mar 20, 2025
650aa65
fix(trace): remove console.trace because the stack is useless
macornwell Mar 20, 2025
a3a1be7
feat(id): add a unique id for each log message
macornwell Mar 20, 2025
3fe4f44
chore(upgrade): update functional models
macornwell Mar 22, 2025
1b75e4e
feat(runtimeid): add runtimeId as part of constants. Add to default l…
macornwell Mar 22, 2025
60d187b
fix(deps): update deps
macornwell Mar 22, 2025
97149eb
feat(ids): add ability to get log ids
macornwell Mar 25, 2025
4b9711e
fix(cruds): fix model cruds model.create bug
macornwell Mar 25, 2025
e55ecd0
feat(env): add environment to the log message
macornwell Mar 26, 2025
aa4b7f3
fix(create): align more with the functional-models approach
macornwell Mar 27, 2025
f6d99ed
feat(logging): major logging API update
macornwell Apr 10, 2025
66abe80
chore(version): bump version
macornwell Apr 10, 2025
dea0b5d
fix(tests): fix tests
macornwell Apr 10, 2025
939676c
fix(context): fix log context not being delayed enough
macornwell Apr 10, 2025
a8dd2f2
fix(text): fix incorrect name
macornwell Apr 22, 2025
bf708e4
style(fix): fix styles
macornwell Apr 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@node-in-layers/core",
"type": "module",
"version": "1.2.9",
"version": "1.4.3",
"description": "The core library for the Node In Layers rapid web development framework.",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -82,7 +82,7 @@
"dependencies": {
"async-lock": "^1.4.1",
"axios": "^1.7.9",
"functional-models": "^3.0.12",
"functional-models": "^3.0.15",
"import-meta-resolve": "^4.1.0",
"lodash": "^4.17.21",
"loglevel": "^1.9.2",
Expand Down
1 change: 1 addition & 0 deletions src/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const loadSystem = async <TConfig extends Config = Config>(args: {
)

const layersServices = layersApp.services.create()
// @ts-ignore
const layersFeatures = layersApp.features.create({
...globals,
services: {
Expand Down
11 changes: 8 additions & 3 deletions src/globals/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import merge from 'lodash/merge.js'
import { v4 } from 'uuid'
import get from 'lodash/get.js'
import { isConfig, validateConfig } from '../libs.js'
import {
Expand All @@ -16,12 +17,14 @@ const name = CoreNamespace.globals
type GlobalsServicesProps = Readonly<{
environment: string
workingDirectory: string
runtimeId?: string
}>

type GlobalsServices<TConfig extends Config> = Readonly<{
loadConfig: () => Promise<TConfig>
getRootLogger: () => RootLogger
getConstants: () => {
runtimeId: string
workingDirectory: string
environment: string
}
Expand All @@ -41,13 +44,14 @@ const services = {
create: <TConfig extends Config>({
environment,
workingDirectory,
runtimeId,
}: GlobalsServicesProps): GlobalsServices<TConfig> => {
const getRootLogger = standardLogger

const _findConfigPath = async () => {
const nodeFS = await import('node:fs')
const nodePath = await import('node:path')
const extensions = ['mjs', 'js']
const extensions = ['mjs', 'js', 'mts', 'ts']
return extensions
.map(e => {
return nodePath.resolve(
Expand All @@ -64,7 +68,7 @@ const services = {
const fullPath = await _findConfigPath()
if (!fullPath) {
throw new Error(
`Could not find a config.${environment} for mjs, or js.`
`Could not find a config.${environment} for mts, ts, mjs, or js.`
)
}
const url = new URL(`file://${fullPath}`)
Expand All @@ -81,6 +85,7 @@ const services = {

const getConstants = () => {
return {
runtimeId: runtimeId || v4(),
workingDirectory,
environment,
}
Expand Down Expand Up @@ -122,7 +127,7 @@ const features = {

const commonGlobals = {
config,
log: ourServices.getRootLogger(),
rootLogger: ourServices.getRootLogger(),
constants: ourServices.getConstants(),
}
const globals: TGlobals = await config[CoreNamespace.root].apps.reduce(
Expand Down
74 changes: 74 additions & 0 deletions src/globals/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import merge from 'lodash/merge.js'
import get from 'lodash/get.js'
import omit from 'lodash/omit.js'
import { LogLevelNames, CrossLayerProps, Logger, LogId } from '../types.js'

const defaultGetFunctionWrapLogLevel = (layerName: string): LogLevelNames => {
switch (layerName) {
case 'features':
case 'entries':
return LogLevelNames.info
case 'services':
return LogLevelNames.trace
default:
return LogLevelNames.debug
}
}

/**
* Gets the cross layer props and combines it with information from the logger.
* Does this in a "smart" way.
*
* The result of this can be dumped directly into applyData.
*
* @param {Logger} logger
* @param {CrossLayerProps} crossLayerProps
*/
const combineLoggingProps = (
logger: Logger,
crossLayerProps?: CrossLayerProps
) => {
const loggingData = crossLayerProps?.logging || {}
const ids = loggingData.ids || []
const currentIds = logger.getIds()
const existingIds = currentIds.reduce(
(acc, obj) => {
return Object.keys(obj).reduce((accKeys, key) => {
return merge(accKeys, { [key]: key })
}, acc)
},
{} as Record<string, string>
)
const unique = ids.reduce(
(acc, passedIn) => {
const keys = Object.entries(passedIn)
const newKeys = keys
.filter(([, value]) => !(value in existingIds))
.map(([key, value]) => ({ [key]: value }))
if (newKeys.length > 0) {
return acc.concat(newKeys)
}
return acc
},
[] as readonly LogId[]
)

return merge(
{
ids: logger.getIds().concat(unique),
},
omit(loggingData, 'ids')
)
}

const isCrossLayerLoggingProps = (
maybe?: CrossLayerProps
): maybe is CrossLayerProps => {
return Boolean(get(maybe, 'logging.ids'))
}

export {
defaultGetFunctionWrapLogLevel,
combineLoggingProps,
isCrossLayerLoggingProps,
}
Loading