@c15t/backend 1.0.5 → 1.2.0-canary.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/.turbo/turbo-build.log +33 -39
- package/.turbo/turbo-fmt.log +3 -3
- package/.turbo/turbo-test.log +531 -0
- package/coverage/coverage-final.json +84 -0
- package/coverage/coverage-summary.json +85 -0
- package/coverage/html/backend/index.html +116 -0
- package/coverage/html/backend/rslib.config.ts.html +415 -0
- package/coverage/html/backend/src/contracts/consent/index.html +161 -0
- package/coverage/html/backend/src/contracts/consent/index.ts.html +112 -0
- package/coverage/html/backend/src/contracts/consent/post.contract.ts.html +559 -0
- package/coverage/html/backend/src/contracts/consent/show-banner.contract.ts.html +220 -0
- package/coverage/html/backend/src/contracts/consent/verify.contract.ts.html +463 -0
- package/coverage/html/backend/src/contracts/index.html +116 -0
- package/coverage/html/backend/src/contracts/index.ts.html +139 -0
- package/coverage/html/backend/src/contracts/meta/index.html +131 -0
- package/coverage/html/backend/src/contracts/meta/index.ts.html +100 -0
- package/coverage/html/backend/src/contracts/meta/status.contract.ts.html +196 -0
- package/coverage/html/backend/src/contracts/shared/index.html +116 -0
- package/coverage/html/backend/src/contracts/shared/jurisdiction.schema.ts.html +175 -0
- package/coverage/html/backend/src/core.ts.html +1624 -0
- package/coverage/html/backend/src/handlers/consent/index.html +161 -0
- package/coverage/html/backend/src/handlers/consent/index.ts.html +112 -0
- package/coverage/html/backend/src/handlers/consent/post.handler.ts.html +889 -0
- package/coverage/html/backend/src/handlers/consent/show-banner.handler.ts.html +535 -0
- package/coverage/html/backend/src/handlers/consent/verify.handler.ts.html +1000 -0
- package/coverage/html/backend/src/handlers/meta/index.html +131 -0
- package/coverage/html/backend/src/handlers/meta/index.ts.html +100 -0
- package/coverage/html/backend/src/handlers/meta/status.handler.ts.html +226 -0
- package/coverage/html/backend/src/index.html +161 -0
- package/coverage/html/backend/src/init.ts.html +1018 -0
- package/coverage/html/backend/src/pkgs/api-router/hooks/index.html +116 -0
- package/coverage/html/backend/src/pkgs/api-router/hooks/processor.ts.html +544 -0
- package/coverage/html/backend/src/pkgs/api-router/index.html +116 -0
- package/coverage/html/backend/src/pkgs/api-router/telemetry.ts.html +334 -0
- package/coverage/html/backend/src/pkgs/api-router/utils/cors.ts.html +304 -0
- package/coverage/html/backend/src/pkgs/api-router/utils/index.html +131 -0
- package/coverage/html/backend/src/pkgs/api-router/utils/ip.ts.html +361 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/field-factory.ts.html +709 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/id-generator.ts.html +256 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/index.html +161 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/superjson-utils.ts.html +136 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/zod-fields.ts.html +496 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/create-hooks.ts.html +349 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/index.html +176 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/update-hooks.ts.html +358 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/update-many-hooks.ts.html +613 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/utils.ts.html +538 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/with-hooks-factory.ts.html +289 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapter-factory.ts.html +289 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.ts.html +2203 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/drizzle-adapter/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/dialect.ts.html +670 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/index.html +131 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/kysely-adapter.ts.html +3634 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/tests/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.ts.html +1417 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/memory-adapter/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/memory-adapter/memory-adapter.ts.html +2071 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/prisma-adapter/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/prisma-adapter/prisma-adapter.ts.html +1834 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/test.ts.html +316 -0
- package/coverage/html/backend/src/pkgs/db-adapters/index.html +131 -0
- package/coverage/html/backend/src/pkgs/db-adapters/utils.ts.html +238 -0
- package/coverage/html/backend/src/pkgs/migrations/get-migration.ts.html +343 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/get-schema.ts.html +217 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/index.html +146 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/process-fields.ts.html +280 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/process-tables.ts.html +289 -0
- package/coverage/html/backend/src/pkgs/migrations/index.html +176 -0
- package/coverage/html/backend/src/pkgs/migrations/migration-builders.ts.html +595 -0
- package/coverage/html/backend/src/pkgs/migrations/migration-execution.ts.html +301 -0
- package/coverage/html/backend/src/pkgs/migrations/schema-comparison.ts.html +694 -0
- package/coverage/html/backend/src/pkgs/migrations/type-mapping.ts.html +817 -0
- package/coverage/html/backend/src/pkgs/results/core/error-class.ts.html +976 -0
- package/coverage/html/backend/src/pkgs/results/core/error-codes.ts.html +703 -0
- package/coverage/html/backend/src/pkgs/results/core/index.html +146 -0
- package/coverage/html/backend/src/pkgs/results/core/tracing.ts.html +280 -0
- package/coverage/html/backend/src/pkgs/results/create-telemetry-options.ts.html +271 -0
- package/coverage/html/backend/src/pkgs/results/index.html +131 -0
- package/coverage/html/backend/src/pkgs/results/orpc-error-handler.ts.html +496 -0
- package/coverage/html/backend/src/pkgs/results/results/index.html +131 -0
- package/coverage/html/backend/src/pkgs/results/results/recovery-utils.ts.html +628 -0
- package/coverage/html/backend/src/pkgs/results/results/result-helpers.ts.html +1234 -0
- package/coverage/html/backend/src/pkgs/utils/env.ts.html +337 -0
- package/coverage/html/backend/src/pkgs/utils/index.html +146 -0
- package/coverage/html/backend/src/pkgs/utils/logger.ts.html +199 -0
- package/coverage/html/backend/src/pkgs/utils/url.ts.html +400 -0
- package/coverage/html/backend/src/router.ts.html +109 -0
- package/coverage/html/backend/src/schema/audit-log/index.html +146 -0
- package/coverage/html/backend/src/schema/audit-log/registry.ts.html +436 -0
- package/coverage/html/backend/src/schema/audit-log/schema.ts.html +223 -0
- package/coverage/html/backend/src/schema/audit-log/table.ts.html +640 -0
- package/coverage/html/backend/src/schema/consent/index.html +146 -0
- package/coverage/html/backend/src/schema/consent/registry.ts.html +616 -0
- package/coverage/html/backend/src/schema/consent/schema.ts.html +238 -0
- package/coverage/html/backend/src/schema/consent/table.ts.html +748 -0
- package/coverage/html/backend/src/schema/consent-policy/index.html +146 -0
- package/coverage/html/backend/src/schema/consent-policy/registry.ts.html +1063 -0
- package/coverage/html/backend/src/schema/consent-policy/schema.ts.html +265 -0
- package/coverage/html/backend/src/schema/consent-policy/table.ts.html +535 -0
- package/coverage/html/backend/src/schema/consent-purpose/index.html +146 -0
- package/coverage/html/backend/src/schema/consent-purpose/registry.ts.html +589 -0
- package/coverage/html/backend/src/schema/consent-purpose/schema.ts.html +259 -0
- package/coverage/html/backend/src/schema/consent-purpose/table.ts.html +547 -0
- package/coverage/html/backend/src/schema/consent-record/index.html +131 -0
- package/coverage/html/backend/src/schema/consent-record/schema.ts.html +211 -0
- package/coverage/html/backend/src/schema/consent-record/table.ts.html +457 -0
- package/coverage/html/backend/src/schema/create-registry.ts.html +148 -0
- package/coverage/html/backend/src/schema/definition.ts.html +685 -0
- package/coverage/html/backend/src/schema/domain/index.html +146 -0
- package/coverage/html/backend/src/schema/domain/registry.ts.html +973 -0
- package/coverage/html/backend/src/schema/domain/schema.ts.html +214 -0
- package/coverage/html/backend/src/schema/domain/table.ts.html +496 -0
- package/coverage/html/backend/src/schema/index.html +146 -0
- package/coverage/html/backend/src/schema/schemas.ts.html +166 -0
- package/coverage/html/backend/src/schema/subject/index.html +146 -0
- package/coverage/html/backend/src/schema/subject/registry.ts.html +973 -0
- package/coverage/html/backend/src/schema/subject/schema.ts.html +208 -0
- package/coverage/html/backend/src/schema/subject/table.ts.html +499 -0
- package/coverage/html/backend/src/server.ts.html +475 -0
- package/coverage/html/backend/src/testing/contract-testing.ts.html +1348 -0
- package/coverage/html/backend/src/testing/index.html +116 -0
- package/coverage/html/base.css +224 -0
- package/coverage/html/block-navigation.js +87 -0
- package/coverage/html/favicon.png +0 -0
- package/coverage/html/index.html +626 -0
- package/coverage/html/prettify.css +1 -0
- package/coverage/html/prettify.js +2 -0
- package/coverage/html/sort-arrow-sprite.png +0 -0
- package/coverage/html/sorter.js +196 -0
- package/dist/contracts/consent/index.d.ts +401 -0
- package/dist/contracts/consent/index.d.ts.map +1 -0
- package/dist/contracts/consent/index.test.d.ts +2 -0
- package/dist/contracts/consent/index.test.d.ts.map +1 -0
- package/dist/contracts/consent/post.contract.d.ts +212 -0
- package/dist/contracts/consent/post.contract.d.ts.map +1 -0
- package/dist/contracts/consent/post.contract.test.d.ts +2 -0
- package/dist/contracts/consent/post.contract.test.d.ts.map +1 -0
- package/dist/contracts/consent/show-banner.contract.d.ts +45 -0
- package/dist/contracts/consent/show-banner.contract.d.ts.map +1 -0
- package/dist/contracts/consent/show-banner.contract.test.d.ts +2 -0
- package/dist/contracts/consent/show-banner.contract.test.d.ts.map +1 -0
- package/dist/contracts/consent/verify.contract.d.ts +147 -0
- package/dist/contracts/consent/verify.contract.d.ts.map +1 -0
- package/dist/contracts/consent/verify.contract.test.d.ts +2 -0
- package/dist/contracts/consent/verify.contract.test.d.ts.map +1 -0
- package/dist/contracts/index.d.ts +963 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/meta/index.d.ts +78 -0
- package/dist/contracts/meta/index.d.ts.map +1 -0
- package/dist/contracts/meta/index.test.d.ts +2 -0
- package/dist/contracts/meta/index.test.d.ts.map +1 -0
- package/dist/contracts/meta/status.contract.d.ts +77 -0
- package/dist/contracts/meta/status.contract.d.ts.map +1 -0
- package/dist/contracts/meta/status.contract.test.d.ts +2 -0
- package/dist/contracts/meta/status.contract.test.d.ts.map +1 -0
- package/dist/contracts/shared/jurisdiction.schema.d.ts +24 -0
- package/dist/contracts/shared/jurisdiction.schema.d.ts.map +1 -0
- package/dist/core.cjs +3584 -0
- package/dist/core.d.ts +533 -76
- package/dist/core.d.ts.map +1 -1
- package/dist/{index.js → core.js} +1163 -1286
- package/dist/handlers/consent/index.d.ts +401 -0
- package/dist/handlers/consent/index.d.ts.map +1 -0
- package/dist/handlers/consent/post.handler.d.ts +234 -0
- package/dist/handlers/consent/post.handler.d.ts.map +1 -0
- package/dist/handlers/consent/show-banner.handler.d.ts +57 -0
- package/dist/handlers/consent/show-banner.handler.d.ts.map +1 -0
- package/dist/handlers/consent/show-banner.handler.test.d.ts +2 -0
- package/dist/handlers/consent/show-banner.handler.test.d.ts.map +1 -0
- package/dist/handlers/consent/verify.handler.d.ts +169 -0
- package/dist/handlers/consent/verify.handler.d.ts.map +1 -0
- package/dist/handlers/meta/index.d.ts +78 -0
- package/dist/handlers/meta/index.d.ts.map +1 -0
- package/dist/handlers/meta/status.handler.d.ts +76 -0
- package/dist/handlers/meta/status.handler.d.ts.map +1 -0
- package/dist/init.d.ts.map +1 -1
- package/dist/pkgs/api-router/hooks/processor.d.ts.map +1 -1
- package/dist/pkgs/api-router/types/router-props.d.ts +1 -1
- package/dist/pkgs/api-router/types/router-props.d.ts.map +1 -1
- package/dist/pkgs/api-router/utils/cors.d.ts +1 -1
- package/dist/pkgs/api-router/utils/cors.d.ts.map +1 -1
- package/dist/pkgs/data-model/fields/field-types.d.ts +1 -1
- package/dist/pkgs/data-model/fields/zod-fields.d.ts +32 -32
- package/dist/pkgs/data-model/index.cjs +1433 -1799
- package/dist/pkgs/data-model/index.js +20 -385
- package/dist/pkgs/data-model/schema/index.cjs +1402 -1768
- package/dist/pkgs/data-model/schema/index.js +20 -385
- package/dist/pkgs/db-adapters/adapter-factory.d.ts +2 -2
- package/dist/pkgs/db-adapters/adapter-factory.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.d.ts +4 -4
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/index.cjs +19 -151
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/index.js +19 -151
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/dialect.d.ts +1 -1
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.cjs +17 -149
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.js +17 -149
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.d.ts +2 -2
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/adapters/memory-adapter/index.cjs +17 -149
- package/dist/pkgs/db-adapters/adapters/memory-adapter/index.js +17 -149
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.cjs +19 -151
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.js +19 -151
- package/dist/pkgs/db-adapters/index.cjs +31 -153
- package/dist/pkgs/db-adapters/index.js +31 -153
- package/dist/pkgs/migrations/get-schema/get-schema.d.ts +2 -2
- package/dist/pkgs/migrations/get-schema/index.d.ts +1 -1
- package/dist/pkgs/migrations/index.cjs +30 -153
- package/dist/pkgs/migrations/index.js +30 -153
- package/dist/pkgs/migrations/schema-comparison.d.ts.map +1 -1
- package/dist/pkgs/results/core/error-class.d.ts +23 -21
- package/dist/pkgs/results/core/error-class.d.ts.map +1 -1
- package/dist/pkgs/results/index.cjs +17 -150
- package/dist/pkgs/results/index.d.ts +0 -3
- package/dist/pkgs/results/index.d.ts.map +1 -1
- package/dist/pkgs/results/index.js +17 -138
- package/dist/pkgs/results/orpc-error-handler.d.ts +65 -0
- package/dist/pkgs/results/orpc-error-handler.d.ts.map +1 -0
- package/dist/pkgs/results/types.d.ts +7 -7
- package/dist/pkgs/results/types.d.ts.map +1 -1
- package/dist/pkgs/types/context.d.ts +15 -4
- package/dist/pkgs/types/context.d.ts.map +1 -1
- package/dist/pkgs/types/endpoints.d.ts +3 -4
- package/dist/pkgs/types/endpoints.d.ts.map +1 -1
- package/dist/pkgs/types/options.d.ts +2 -3
- package/dist/pkgs/types/options.d.ts.map +1 -1
- package/dist/pkgs/types/plugins.d.ts +2 -3
- package/dist/pkgs/types/plugins.d.ts.map +1 -1
- package/dist/pkgs/utils/index.d.ts +1 -0
- package/dist/pkgs/utils/index.d.ts.map +1 -1
- package/dist/pkgs/utils/logger.d.ts +16 -0
- package/dist/pkgs/utils/logger.d.ts.map +1 -0
- package/dist/router.cjs +1213 -0
- package/dist/router.d.ts +480 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +1169 -0
- package/dist/schema/audit-log/table.d.ts +1 -1
- package/dist/schema/consent/table.d.ts +1 -1
- package/dist/schema/consent-policy/registry.d.ts +12 -12
- package/dist/schema/consent-policy/schema.d.ts +6 -6
- package/dist/schema/consent-policy/table.d.ts +7 -7
- package/dist/schema/consent-purpose/registry.d.ts +6 -6
- package/dist/schema/consent-purpose/schema.d.ts +6 -6
- package/dist/schema/consent-purpose/table.d.ts +7 -7
- package/dist/schema/consent-record/table.d.ts +1 -1
- package/dist/schema/create-registry.d.ts +32 -32
- package/dist/schema/definition.d.ts +19 -19
- package/dist/schema/domain/registry.d.ts +10 -10
- package/dist/schema/domain/schema.d.ts +5 -5
- package/dist/schema/domain/table.d.ts +6 -6
- package/dist/schema/index.cjs +1409 -1775
- package/dist/schema/index.js +20 -385
- package/dist/schema/schemas.d.ts +19 -19
- package/dist/schema/subject/registry.d.ts +4 -4
- package/dist/schema/subject/schema.d.ts +2 -2
- package/dist/schema/subject/table.d.ts +3 -3
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/testing/contract-testing.d.ts +37 -0
- package/dist/testing/contract-testing.d.ts.map +1 -0
- package/dist/types/context.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/options.d.ts +33 -2
- package/dist/types/options.d.ts.map +1 -1
- package/dist/types/plugins.d.ts +3 -4
- package/dist/types/plugins.d.ts.map +1 -1
- package/package.json +22 -30
- package/rslib.config.ts +2 -5
- package/src/contracts/consent/index.test.ts +5 -0
- package/src/contracts/consent/index.ts +9 -0
- package/src/contracts/consent/post.contract.test.ts +526 -0
- package/src/contracts/consent/post.contract.ts +160 -0
- package/src/contracts/consent/show-banner.contract.test.ts +214 -0
- package/src/contracts/consent/show-banner.contract.ts +45 -0
- package/src/contracts/consent/verify.contract.test.ts +185 -0
- package/src/contracts/consent/verify.contract.ts +126 -0
- package/src/contracts/index.ts +18 -0
- package/src/contracts/meta/index.test.ts +5 -0
- package/src/contracts/meta/index.ts +5 -0
- package/src/contracts/meta/status.contract.test.ts +338 -0
- package/src/contracts/meta/status.contract.ts +37 -0
- package/src/contracts/shared/jurisdiction.schema.ts +30 -0
- package/src/core.ts +451 -159
- package/src/handlers/consent/index.ts +9 -0
- package/src/handlers/consent/post.handler.ts +273 -0
- package/src/handlers/consent/show-banner.handler.test.ts +148 -0
- package/src/handlers/consent/show-banner.handler.ts +150 -0
- package/src/handlers/consent/verify.handler.ts +305 -0
- package/src/handlers/meta/index.ts +5 -0
- package/src/handlers/meta/status.handler.ts +47 -0
- package/src/init.ts +8 -5
- package/src/pkgs/api-router/hooks/__tests__/processor.test.ts +6 -0
- package/src/pkgs/api-router/hooks/processor.ts +2 -0
- package/src/pkgs/api-router/types/router-props.ts +1 -1
- package/src/pkgs/api-router/utils/cors.ts +1 -1
- package/src/pkgs/data-model/fields/field-types.ts +1 -1
- package/src/pkgs/data-model/fields/id-generator.ts +1 -1
- package/src/pkgs/db-adapters/README.md +3 -3
- package/src/pkgs/db-adapters/adapter-factory.ts +8 -4
- package/src/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.ts +13 -13
- package/src/pkgs/db-adapters/adapters/kysely-adapter/dialect.ts +1 -1
- package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/postgres.test.ts +1 -1
- package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/sqlite.test.ts +1 -1
- package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.ts +2 -2
- package/src/pkgs/migrations/get-migration.ts +3 -3
- package/src/pkgs/migrations/get-schema/get-schema.ts +2 -2
- package/src/pkgs/migrations/get-schema/index.ts +1 -1
- package/src/pkgs/migrations/migration-builders.ts +2 -2
- package/src/pkgs/migrations/migration-execution.ts +2 -2
- package/src/pkgs/migrations/schema-comparison.ts +5 -4
- package/src/pkgs/results/__tests__/error-class.test.ts +8 -7
- package/src/pkgs/results/core/error-class.ts +31 -43
- package/src/pkgs/results/index.ts +0 -10
- package/src/pkgs/results/orpc-error-handler.ts +137 -0
- package/src/pkgs/results/types.ts +8 -7
- package/src/pkgs/types/context.ts +18 -4
- package/src/pkgs/types/endpoints.ts +3 -5
- package/src/pkgs/types/options.ts +2 -3
- package/src/pkgs/types/plugins.ts +2 -3
- package/src/pkgs/utils/index.ts +1 -0
- package/src/pkgs/utils/logger.ts +38 -0
- package/src/router.ts +8 -0
- package/src/schema/audit-log/table.ts +1 -1
- package/src/schema/consent/table.ts +1 -1
- package/src/schema/consent-policy/table.ts +1 -1
- package/src/schema/consent-purpose/table.ts +1 -1
- package/src/schema/consent-record/table.ts +1 -1
- package/src/schema/definition.ts +2 -2
- package/src/schema/domain/table.ts +1 -1
- package/src/schema/subject/table.ts +1 -1
- package/src/server.ts +130 -0
- package/src/testing/contract-testing.ts +437 -0
- package/src/types/context.ts +1 -1
- package/src/types/index.ts +2 -2
- package/src/types/options.ts +38 -2
- package/src/types/plugins.ts +3 -4
- package/dist/index.cjs +0 -3701
- package/dist/index.d.ts +0 -11
- package/dist/index.d.ts.map +0 -1
- package/dist/init.test.d.ts +0 -2
- package/dist/init.test.d.ts.map +0 -1
- package/dist/integrations/cloudflare.cjs +0 -312
- package/dist/integrations/cloudflare.d.ts +0 -32
- package/dist/integrations/cloudflare.d.ts.map +0 -1
- package/dist/integrations/cloudflare.js +0 -278
- package/dist/integrations/next.cjs +0 -276
- package/dist/integrations/next.d.ts +0 -68
- package/dist/integrations/next.d.ts.map +0 -1
- package/dist/integrations/next.js +0 -239
- package/dist/integrations/node.cjs +0 -257
- package/dist/integrations/node.d.ts +0 -29
- package/dist/integrations/node.d.ts.map +0 -1
- package/dist/integrations/node.js +0 -223
- package/dist/pkgs/api-router/index.d.ts +0 -9
- package/dist/pkgs/api-router/index.d.ts.map +0 -1
- package/dist/pkgs/api-router/utils/define-route.d.ts +0 -87
- package/dist/pkgs/api-router/utils/define-route.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/console-formatter.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/console-formatter.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/integration.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/integration.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/log-levels.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/log-levels.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/logger-factory.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/logger-factory.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/result-logging.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/result-logging.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/types.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/types.test.d.ts.map +0 -1
- package/dist/pkgs/logger/console-formatter.d.ts +0 -56
- package/dist/pkgs/logger/console-formatter.d.ts.map +0 -1
- package/dist/pkgs/logger/index.cjs +0 -240
- package/dist/pkgs/logger/index.d.ts +0 -35
- package/dist/pkgs/logger/index.d.ts.map +0 -1
- package/dist/pkgs/logger/index.js +0 -185
- package/dist/pkgs/logger/log-levels.d.ts +0 -29
- package/dist/pkgs/logger/log-levels.d.ts.map +0 -1
- package/dist/pkgs/logger/logger-factory.d.ts +0 -42
- package/dist/pkgs/logger/logger-factory.d.ts.map +0 -1
- package/dist/pkgs/logger/result-logging.d.ts +0 -71
- package/dist/pkgs/logger/result-logging.d.ts.map +0 -1
- package/dist/pkgs/logger/telemetry.d.ts +0 -14
- package/dist/pkgs/logger/telemetry.d.ts.map +0 -1
- package/dist/pkgs/logger/types.d.ts +0 -121
- package/dist/pkgs/logger/types.d.ts.map +0 -1
- package/dist/pkgs/results/__tests__/retrieval-pipeline.test.d.ts +0 -2
- package/dist/pkgs/results/__tests__/retrieval-pipeline.test.d.ts.map +0 -1
- package/dist/pkgs/results/__tests__/validation-pipeline.test.d.ts +0 -2
- package/dist/pkgs/results/__tests__/validation-pipeline.test.d.ts.map +0 -1
- package/dist/pkgs/results/h3-integration.d.ts +0 -52
- package/dist/pkgs/results/h3-integration.d.ts.map +0 -1
- package/dist/pkgs/results/pipeline/retrieval-pipeline.d.ts +0 -101
- package/dist/pkgs/results/pipeline/retrieval-pipeline.d.ts.map +0 -1
- package/dist/pkgs/results/pipeline/validation-pipeline.d.ts +0 -89
- package/dist/pkgs/results/pipeline/validation-pipeline.d.ts.map +0 -1
- package/dist/response-types.d.ts +0 -19
- package/dist/response-types.d.ts.map +0 -1
- package/dist/routes/__test__/index.test.d.ts +0 -17
- package/dist/routes/__test__/index.test.d.ts.map +0 -1
- package/dist/routes/__test__/set-consent.test.d.ts +0 -2
- package/dist/routes/__test__/set-consent.test.d.ts.map +0 -1
- package/dist/routes/__test__/show-consent-banner.test.d.ts +0 -2
- package/dist/routes/__test__/show-consent-banner.test.d.ts.map +0 -1
- package/dist/routes/__test__/status.test.d.ts +0 -2
- package/dist/routes/__test__/status.test.d.ts.map +0 -1
- package/dist/routes/__test__/verify-consent.test.d.ts +0 -2
- package/dist/routes/__test__/verify-consent.test.d.ts.map +0 -1
- package/dist/routes/index.d.ts +0 -3
- package/dist/routes/index.d.ts.map +0 -1
- package/dist/routes/set-consent.d.ts +0 -89
- package/dist/routes/set-consent.d.ts.map +0 -1
- package/dist/routes/show-consent-banner.d.ts +0 -15
- package/dist/routes/show-consent-banner.d.ts.map +0 -1
- package/dist/routes/status.d.ts +0 -44
- package/dist/routes/status.d.ts.map +0 -1
- package/dist/routes/types.d.ts +0 -7
- package/dist/routes/types.d.ts.map +0 -1
- package/dist/routes/verify-consent.d.ts +0 -38
- package/dist/routes/verify-consent.d.ts.map +0 -1
- package/src/docs/ADVANCED_JSON_HANDLING.md +0 -99
- package/src/docs/neverthrow.md +0 -171
- package/src/index.ts +0 -34
- package/src/init.test.ts +0 -219
- package/src/integrations/cloudflare.ts +0 -269
- package/src/integrations/next.ts +0 -204
- package/src/integrations/node.ts +0 -141
- package/src/pkgs/api-router/index.ts +0 -148
- package/src/pkgs/api-router/types/h3.d.ts +0 -42
- package/src/pkgs/api-router/utils/define-route.ts +0 -410
- package/src/pkgs/logger/README.md +0 -213
- package/src/pkgs/logger/__tests__/console-formatter.test.ts +0 -67
- package/src/pkgs/logger/__tests__/integration.test.ts +0 -184
- package/src/pkgs/logger/__tests__/log-levels.test.ts +0 -77
- package/src/pkgs/logger/__tests__/logger-factory.test.ts +0 -156
- package/src/pkgs/logger/__tests__/result-logging.test.ts +0 -209
- package/src/pkgs/logger/__tests__/types.test.ts +0 -94
- package/src/pkgs/logger/console-formatter.ts +0 -75
- package/src/pkgs/logger/doc.md +0 -569
- package/src/pkgs/logger/index.ts +0 -59
- package/src/pkgs/logger/log-levels.ts +0 -46
- package/src/pkgs/logger/logger-factory.ts +0 -121
- package/src/pkgs/logger/result-logging.ts +0 -134
- package/src/pkgs/logger/telemetry.ts +0 -96
- package/src/pkgs/logger/types.ts +0 -138
- package/src/pkgs/results/__tests__/retrieval-pipeline.test.ts +0 -157
- package/src/pkgs/results/__tests__/validation-pipeline.test.ts +0 -151
- package/src/pkgs/results/h3-integration.ts +0 -142
- package/src/pkgs/results/pipeline/retrieval-pipeline.ts +0 -188
- package/src/pkgs/results/pipeline/validation-pipeline.ts +0 -164
- package/src/plugins/.keep +0 -0
- package/src/response-types.ts +0 -29
- package/src/routes/__test__/index.test.ts +0 -112
- package/src/routes/__test__/set-consent.test.ts +0 -242
- package/src/routes/__test__/show-consent-banner.test.ts +0 -98
- package/src/routes/__test__/status.test.ts +0 -64
- package/src/routes/__test__/verify-consent.test.ts +0 -266
- package/src/routes/index.ts +0 -12
- package/src/routes/set-consent.ts +0 -249
- package/src/routes/show-consent-banner.ts +0 -131
- package/src/routes/status.ts +0 -61
- package/src/routes/types.ts +0 -7
- package/src/routes/verify-consent.ts +0 -206
package/src/pkgs/logger/doc.md
DELETED
|
@@ -1,569 +0,0 @@
|
|
|
1
|
-
## Overview
|
|
2
|
-
|
|
3
|
-
The DoubleTie Logger is a lightweight, flexible logging utility designed for Node.js and TypeScript applications. It provides structured logging capabilities with configurable log levels, color-coded console output, and special utilities for error handling with the Result pattern.
|
|
4
|
-
|
|
5
|
-
This documentation provides comprehensive guidance on setting up, configuring, and using the DoubleTie Logger in your applications.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
Install the DoubleTie Logger package using your preferred package manager:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
# Using npm
|
|
13
|
-
npm install @doubletie/logger
|
|
14
|
-
|
|
15
|
-
# Using pnpm
|
|
16
|
-
pnpm add @doubletie/logger
|
|
17
|
-
|
|
18
|
-
# Using yarn
|
|
19
|
-
yarn add @doubletie/logger
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Getting Started
|
|
23
|
-
|
|
24
|
-
### Basic Usage
|
|
25
|
-
|
|
26
|
-
Create a logger instance and start logging messages:
|
|
27
|
-
|
|
28
|
-
```typescript
|
|
29
|
-
import { createLogger } from '@doubletie/logger';
|
|
30
|
-
|
|
31
|
-
// Create a logger with default settings (logs errors only)
|
|
32
|
-
const logger = createLogger();
|
|
33
|
-
|
|
34
|
-
// Log messages at different severity levels
|
|
35
|
-
logger.error('An error occurred while processing the request');
|
|
36
|
-
logger.warn('User session is about to expire');
|
|
37
|
-
logger.info('Application started successfully');
|
|
38
|
-
logger.debug('Connection details:', { host: 'example.com', port: 8080 });
|
|
39
|
-
logger.success('Data was saved successfully');
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### Log Levels
|
|
43
|
-
|
|
44
|
-
The logger supports five log levels, in order of decreasing severity:
|
|
45
|
-
|
|
46
|
-
1. **error** - Critical issues that require immediate attention
|
|
47
|
-
2. **warn** - Potential problems that don't prevent the application from working
|
|
48
|
-
3. **info** - General information about application operation
|
|
49
|
-
4. **success** - Successful operations (treated as info level when using custom handlers)
|
|
50
|
-
5. **debug** - Detailed information useful for debugging
|
|
51
|
-
|
|
52
|
-
By default, the logger is configured to show only error messages. You can change this by specifying a different log level during creation.
|
|
53
|
-
|
|
54
|
-
### Configuring Log Levels
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
import { createLogger } from '@doubletie/logger';
|
|
58
|
-
|
|
59
|
-
// Create a logger that shows warnings and errors
|
|
60
|
-
const warnLogger = createLogger({ level: 'warn' });
|
|
61
|
-
|
|
62
|
-
// Create a logger that shows all messages
|
|
63
|
-
const verboseLogger = createLogger({ level: 'debug' });
|
|
64
|
-
|
|
65
|
-
// With 'warn' level, these will be logged
|
|
66
|
-
warnLogger.error('Database connection failed');
|
|
67
|
-
warnLogger.warn('Deprecated function called');
|
|
68
|
-
|
|
69
|
-
// These will be suppressed with 'warn' level
|
|
70
|
-
warnLogger.info('User profile updated');
|
|
71
|
-
warnLogger.debug('Query parameters:', { id: 123 });
|
|
72
|
-
|
|
73
|
-
// With 'debug' level, all messages will be shown
|
|
74
|
-
verboseLogger.error('Critical error');
|
|
75
|
-
verboseLogger.warn('Warning message');
|
|
76
|
-
verboseLogger.info('Information message');
|
|
77
|
-
verboseLogger.debug('Debug details');
|
|
78
|
-
verboseLogger.success('Operation successful');
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### Customizing App Name
|
|
82
|
-
|
|
83
|
-
You can customize the application name that appears in the log messages:
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
import { createLogger } from '@doubletie/logger';
|
|
87
|
-
|
|
88
|
-
// Create a logger with a custom application name
|
|
89
|
-
const logger = createLogger({ appName: 'my-app' });
|
|
90
|
-
|
|
91
|
-
// Logs will show "[my-app]" instead of the default
|
|
92
|
-
logger.info('Application started');
|
|
93
|
-
// Output: 2023-03-15T12:34:56.789Z INFO [my-app]: Application started
|
|
94
|
-
|
|
95
|
-
// You can combine with other options
|
|
96
|
-
const appLogger = createLogger({
|
|
97
|
-
level: 'debug',
|
|
98
|
-
appName: 'payment-service'
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
appLogger.debug('Processing payment intent');
|
|
102
|
-
// Output: 2023-03-15T12:34:56.789Z DEBUG [payment-service]: Processing payment intent
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Disabling Logging
|
|
106
|
-
|
|
107
|
-
For scenarios where you need to temporarily disable all logging:
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
const logger = createLogger({ disabled: true });
|
|
111
|
-
|
|
112
|
-
// None of these messages will be logged
|
|
113
|
-
logger.error('This is hidden');
|
|
114
|
-
logger.warn('Also hidden');
|
|
115
|
-
logger.info('Hidden too');
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
This is useful for testing environments or when you want to conditionally enable/disable logging based on environment variables.
|
|
119
|
-
|
|
120
|
-
## Advanced Features
|
|
121
|
-
|
|
122
|
-
### Custom Log Handlers
|
|
123
|
-
|
|
124
|
-
You can provide your own log handler function to direct logs to a custom destination:
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
127
|
-
import { createLogger } from '@doubletie/logger';
|
|
128
|
-
|
|
129
|
-
// Create a logger with a custom log handler
|
|
130
|
-
const logger = createLogger({
|
|
131
|
-
level: 'info',
|
|
132
|
-
log: (level, message, ...args) => {
|
|
133
|
-
// Send to an external logging service
|
|
134
|
-
externalLoggingService.log({
|
|
135
|
-
level,
|
|
136
|
-
message,
|
|
137
|
-
timestamp: new Date().toISOString(),
|
|
138
|
-
data: args.length > 0 ? args[0] : undefined,
|
|
139
|
-
app: 'my-application',
|
|
140
|
-
environment: process.env.NODE_ENV
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// You could also write logs to a file
|
|
144
|
-
fs.appendFileSync(
|
|
145
|
-
`./logs/${level}.log`,
|
|
146
|
-
`${new Date().toISOString()} - ${message} - ${JSON.stringify(args)}\n`
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
// Now logs will be sent to your custom destinations
|
|
152
|
-
logger.info('User authentication successful', { userId: '12345' });
|
|
153
|
-
logger.error('Payment failed', { orderId: 'ORD-789', reason: 'Insufficient funds' });
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
### Using Existing Logger Instances
|
|
157
|
-
|
|
158
|
-
The `createLogger` function is flexible and can accept either configuration options or an existing logger instance:
|
|
159
|
-
|
|
160
|
-
```typescript
|
|
161
|
-
import { createLogger, Logger } from '@doubletie/logger';
|
|
162
|
-
|
|
163
|
-
// Create a base logger
|
|
164
|
-
const baseLogger = createLogger({ level: 'warn' });
|
|
165
|
-
|
|
166
|
-
// Function that can accept an optional logger
|
|
167
|
-
function initializeDatabase(config: { connectionString: string, logger?: Logger }) {
|
|
168
|
-
// If a logger is provided, use it; otherwise create a new one
|
|
169
|
-
const dbLogger = createLogger(config.logger);
|
|
170
|
-
|
|
171
|
-
dbLogger.info('Initializing database connection');
|
|
172
|
-
|
|
173
|
-
// Database initialization code...
|
|
174
|
-
|
|
175
|
-
dbLogger.success('Database connected successfully');
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Pass the existing logger
|
|
179
|
-
initializeDatabase({
|
|
180
|
-
connectionString: 'postgres://localhost:5432/mydb',
|
|
181
|
-
logger: baseLogger
|
|
182
|
-
});
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
This pattern is particularly useful for dependency injection and for ensuring consistent logging throughout an application.
|
|
186
|
-
|
|
187
|
-
### Structured Logging with Additional Data
|
|
188
|
-
|
|
189
|
-
All logger methods accept additional arguments that can be used for structured logging:
|
|
190
|
-
|
|
191
|
-
```typescript
|
|
192
|
-
// Log with contextual data
|
|
193
|
-
logger.info('User profile updated', {
|
|
194
|
-
userId: 'user123',
|
|
195
|
-
changes: ['email', 'preferences'],
|
|
196
|
-
source: 'web'
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
// Log performance metrics
|
|
200
|
-
logger.debug('Query execution completed', {
|
|
201
|
-
duration: 125, // ms
|
|
202
|
-
recordsReturned: 42,
|
|
203
|
-
cacheHit: false
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// Log errors with details
|
|
207
|
-
logger.error('Payment processing failed', {
|
|
208
|
-
orderId: 'ORD-123456',
|
|
209
|
-
amount: 99.99,
|
|
210
|
-
currency: 'USD',
|
|
211
|
-
errorCode: 'INSUFFICIENT_FUNDS'
|
|
212
|
-
});
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
## Error Handling with Result Types
|
|
216
|
-
|
|
217
|
-
The logger package includes special utilities for handling errors with [neverthrow](https://github.com/supermacro/neverthrow)'s Result and ResultAsync types, allowing you to log errors without interrupting the error handling flow.
|
|
218
|
-
|
|
219
|
-
### Logging Errors from Result
|
|
220
|
-
|
|
221
|
-
```typescript
|
|
222
|
-
import { logError } from '@doubletie/logger';
|
|
223
|
-
import { Result, err, ok } from 'neverthrow';
|
|
224
|
-
import type { BaseError } from '@doubletie/logger';
|
|
225
|
-
|
|
226
|
-
// Create a function that returns a Result
|
|
227
|
-
function validateUser(data: unknown): Result<User, BaseError> {
|
|
228
|
-
if (!data || typeof data !== 'object') {
|
|
229
|
-
return err({
|
|
230
|
-
message: 'Invalid user data',
|
|
231
|
-
code: 'INVALID_USER_DATA',
|
|
232
|
-
data
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// Validation logic...
|
|
237
|
-
|
|
238
|
-
return ok({ id: '123', name: 'John Doe' });
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// Use the validation function and log any errors
|
|
242
|
-
function processUserData(data: unknown) {
|
|
243
|
-
const logger = createLogger();
|
|
244
|
-
|
|
245
|
-
// Log errors but continue the Result flow
|
|
246
|
-
const result = logError(
|
|
247
|
-
validateUser(data),
|
|
248
|
-
logger,
|
|
249
|
-
'User validation error:'
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
// Continue processing with the Result
|
|
253
|
-
return result.match(
|
|
254
|
-
(user) => {
|
|
255
|
-
// Handle valid user
|
|
256
|
-
logger.info('Processing user', { id: user.id });
|
|
257
|
-
return user;
|
|
258
|
-
},
|
|
259
|
-
(error) => {
|
|
260
|
-
// Handle error (already logged)
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
### Logging Errors from ResultAsync
|
|
268
|
-
|
|
269
|
-
```typescript
|
|
270
|
-
import { logErrorAsync } from '@doubletie/logger';
|
|
271
|
-
import { ResultAsync } from 'neverthrow';
|
|
272
|
-
|
|
273
|
-
// Function that returns a ResultAsync
|
|
274
|
-
async function fetchUserData(userId: string): ResultAsync<UserData, BaseError> {
|
|
275
|
-
// Fetch implementation...
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// Log async errors
|
|
279
|
-
async function getUserProfile(userId: string) {
|
|
280
|
-
const logger = createLogger();
|
|
281
|
-
|
|
282
|
-
// Log errors but continue the ResultAsync flow
|
|
283
|
-
const resultAsync = logErrorAsync(
|
|
284
|
-
fetchUserData(userId),
|
|
285
|
-
logger,
|
|
286
|
-
'Error fetching user data:'
|
|
287
|
-
);
|
|
288
|
-
|
|
289
|
-
// Process the ResultAsync
|
|
290
|
-
return await resultAsync.match(
|
|
291
|
-
(userData) => {
|
|
292
|
-
logger.info('User data retrieved successfully');
|
|
293
|
-
return constructUserProfile(userData);
|
|
294
|
-
},
|
|
295
|
-
(error) => {
|
|
296
|
-
// Error already logged by logErrorAsync
|
|
297
|
-
return createDefaultProfile(userId);
|
|
298
|
-
}
|
|
299
|
-
);
|
|
300
|
-
}
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
## API Reference
|
|
304
|
-
|
|
305
|
-
### Types
|
|
306
|
-
|
|
307
|
-
#### `LogLevel`
|
|
308
|
-
|
|
309
|
-
```typescript
|
|
310
|
-
type LogLevel = 'info' | 'success' | 'warn' | 'error' | 'debug';
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
The available log severity levels.
|
|
314
|
-
|
|
315
|
-
#### `LoggerOptions`
|
|
316
|
-
|
|
317
|
-
```typescript
|
|
318
|
-
interface LoggerOptions {
|
|
319
|
-
/**
|
|
320
|
-
* Whether logging is disabled.
|
|
321
|
-
*/
|
|
322
|
-
disabled?: boolean;
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* The minimum log level to publish.
|
|
326
|
-
* Only logs with this level or higher severity will be published.
|
|
327
|
-
* Note that 'success' is treated as 'info' when using custom log handlers.
|
|
328
|
-
*/
|
|
329
|
-
level?: Exclude<LogLevel, 'success'>;
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Custom log handler function.
|
|
333
|
-
* When provided, this function will be called instead of console methods.
|
|
334
|
-
*/
|
|
335
|
-
log?: (
|
|
336
|
-
level: Exclude<LogLevel, 'success'>,
|
|
337
|
-
message: string,
|
|
338
|
-
...args: unknown[]
|
|
339
|
-
) => void;
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Custom application name to display in log messages.
|
|
343
|
-
* When provided, this will override the default app name in the log format.
|
|
344
|
-
*
|
|
345
|
-
* @default '🪢 doubletie'
|
|
346
|
-
*/
|
|
347
|
-
appName?: string;
|
|
348
|
-
}
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
#### `Logger`
|
|
352
|
-
|
|
353
|
-
```typescript
|
|
354
|
-
type Logger = Record<LogLevel, (message: string, ...args: unknown[]) => void>;
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
The logger interface with methods for each log level.
|
|
358
|
-
|
|
359
|
-
#### `BaseError`
|
|
360
|
-
|
|
361
|
-
```typescript
|
|
362
|
-
interface BaseError {
|
|
363
|
-
/** The error message */
|
|
364
|
-
message: string;
|
|
365
|
-
|
|
366
|
-
/** Optional error code */
|
|
367
|
-
code?: string | number;
|
|
368
|
-
|
|
369
|
-
/** Optional HTTP status code */
|
|
370
|
-
status?: number;
|
|
371
|
-
|
|
372
|
-
/** Optional additional error data */
|
|
373
|
-
data?: Record<string, unknown>;
|
|
374
|
-
|
|
375
|
-
/** Optional error category */
|
|
376
|
-
category?: string;
|
|
377
|
-
|
|
378
|
-
/** Error stack trace */
|
|
379
|
-
stack?: string;
|
|
380
|
-
}
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
The base interface for errors used with the logger.
|
|
384
|
-
|
|
385
|
-
### Functions
|
|
386
|
-
|
|
387
|
-
#### `createLogger`
|
|
388
|
-
|
|
389
|
-
```typescript
|
|
390
|
-
function createLogger(options?: LoggerOptions | Logger): Logger;
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
Creates a configured logger instance with methods for each log level.
|
|
394
|
-
|
|
395
|
-
- If passed an existing Logger instance, it will return that instance unchanged.
|
|
396
|
-
- If passed LoggerOptions, it will create a new logger with those options.
|
|
397
|
-
- If called with no arguments, it creates a logger with default settings (error level only).
|
|
398
|
-
|
|
399
|
-
#### `shouldPublishLog`
|
|
400
|
-
|
|
401
|
-
```typescript
|
|
402
|
-
function shouldPublishLog(currentLogLevel: LogLevel, logLevel: LogLevel): boolean;
|
|
403
|
-
```
|
|
404
|
-
|
|
405
|
-
Determines if a log message should be published based on configured log level.
|
|
406
|
-
|
|
407
|
-
- `currentLogLevel`: The configured threshold log level
|
|
408
|
-
- `logLevel`: The level of the message being evaluated
|
|
409
|
-
- Returns: Boolean indicating whether the message should be published
|
|
410
|
-
|
|
411
|
-
#### `logError`
|
|
412
|
-
|
|
413
|
-
```typescript
|
|
414
|
-
function logError<ValueType, ErrorType extends BaseError>(
|
|
415
|
-
result: Result<ValueType, ErrorType>,
|
|
416
|
-
logger: { error: (message: string, ...args: unknown[]) => void },
|
|
417
|
-
messagePrefix?: string
|
|
418
|
-
): Result<ValueType, ErrorType>;
|
|
419
|
-
```
|
|
420
|
-
|
|
421
|
-
Logs any errors in a Result without changing the Result.
|
|
422
|
-
|
|
423
|
-
- `result`: The Result to check for errors
|
|
424
|
-
- `logger`: An object with an error method for logging
|
|
425
|
-
- `messagePrefix`: Optional prefix for the error message
|
|
426
|
-
- Returns: The original Result unchanged
|
|
427
|
-
|
|
428
|
-
#### `logErrorAsync`
|
|
429
|
-
|
|
430
|
-
```typescript
|
|
431
|
-
function logErrorAsync<ValueType, ErrorType extends BaseError>(
|
|
432
|
-
resultAsync: ResultAsync<ValueType, ErrorType>,
|
|
433
|
-
logger: { error: (message: string, ...args: unknown[]) => void },
|
|
434
|
-
messagePrefix?: string
|
|
435
|
-
): ResultAsync<ValueType, ErrorType>;
|
|
436
|
-
```
|
|
437
|
-
|
|
438
|
-
Logs any errors in a ResultAsync without changing the ResultAsync.
|
|
439
|
-
|
|
440
|
-
- `resultAsync`: The ResultAsync to check for errors
|
|
441
|
-
- `logger`: An object with an error method for logging
|
|
442
|
-
- `messagePrefix`: Optional prefix for the error message
|
|
443
|
-
- Returns: The original ResultAsync unchanged
|
|
444
|
-
|
|
445
|
-
## Best Practices
|
|
446
|
-
|
|
447
|
-
### 1. Configure Log Levels by Environment
|
|
448
|
-
|
|
449
|
-
Adjust your log levels based on the environment:
|
|
450
|
-
|
|
451
|
-
```typescript
|
|
452
|
-
const logLevel = process.env.NODE_ENV === 'production'
|
|
453
|
-
? 'error' // Only log errors in production
|
|
454
|
-
: process.env.NODE_ENV === 'test'
|
|
455
|
-
? 'warn' // Log warnings and errors in test
|
|
456
|
-
: 'debug'; // Log everything in development
|
|
457
|
-
|
|
458
|
-
const logger = createLogger({ level: logLevel });
|
|
459
|
-
```
|
|
460
|
-
|
|
461
|
-
### 2. Use Structured Logging
|
|
462
|
-
|
|
463
|
-
Always include structured data as objects rather than string concatenation:
|
|
464
|
-
|
|
465
|
-
```typescript
|
|
466
|
-
// Instead of this:
|
|
467
|
-
logger.info(`User ${userId} logged in from ${ipAddress} at ${timestamp}`);
|
|
468
|
-
|
|
469
|
-
// Do this:
|
|
470
|
-
logger.info('User logged in', {
|
|
471
|
-
userId,
|
|
472
|
-
ipAddress,
|
|
473
|
-
timestamp: new Date().toISOString()
|
|
474
|
-
});
|
|
475
|
-
```
|
|
476
|
-
|
|
477
|
-
This makes logs easier to parse, filter, and analyze.
|
|
478
|
-
|
|
479
|
-
### 3. Create Domain-Specific Loggers
|
|
480
|
-
|
|
481
|
-
Create specialized loggers for different components of your application:
|
|
482
|
-
|
|
483
|
-
```typescript
|
|
484
|
-
// Database logger
|
|
485
|
-
const dbLogger = createLogger({
|
|
486
|
-
level: 'info',
|
|
487
|
-
log: (level, message, ...args) => {
|
|
488
|
-
const baseLogger = createLogger();
|
|
489
|
-
baseLogger[level](`[DATABASE] ${message}`, ...args);
|
|
490
|
-
}
|
|
491
|
-
});
|
|
492
|
-
|
|
493
|
-
// API logger
|
|
494
|
-
const apiLogger = createLogger({
|
|
495
|
-
level: 'debug',
|
|
496
|
-
log: (level, message, ...args) => {
|
|
497
|
-
const baseLogger = createLogger();
|
|
498
|
-
baseLogger[level](`[API] ${message}`, ...args);
|
|
499
|
-
}
|
|
500
|
-
});
|
|
501
|
-
```
|
|
502
|
-
|
|
503
|
-
### 4. Avoid Logging Sensitive Information
|
|
504
|
-
|
|
505
|
-
Never log passwords, authentication tokens, or personally identifiable information:
|
|
506
|
-
|
|
507
|
-
```typescript
|
|
508
|
-
// BAD: Logging sensitive data
|
|
509
|
-
logger.debug('User credentials', {
|
|
510
|
-
username: 'john.doe',
|
|
511
|
-
password: 'secret123' // Don't log passwords!
|
|
512
|
-
});
|
|
513
|
-
|
|
514
|
-
// GOOD: Redact sensitive information
|
|
515
|
-
logger.debug('Login attempt', {
|
|
516
|
-
username: 'john.doe',
|
|
517
|
-
passwordProvided: true,
|
|
518
|
-
timestamp: new Date().toISOString()
|
|
519
|
-
});
|
|
520
|
-
```
|
|
521
|
-
|
|
522
|
-
## Troubleshooting
|
|
523
|
-
|
|
524
|
-
### Common Issues
|
|
525
|
-
|
|
526
|
-
#### Logs Not Appearing
|
|
527
|
-
|
|
528
|
-
If your logs aren't showing up:
|
|
529
|
-
|
|
530
|
-
1. Check that your log level is correctly set. Remember that with `level: 'error'`, only error messages will be displayed.
|
|
531
|
-
2. Verify that `disabled` isn't set to `true`.
|
|
532
|
-
3. If using a custom log handler, ensure it's implemented correctly.
|
|
533
|
-
|
|
534
|
-
#### TypeScript Errors
|
|
535
|
-
|
|
536
|
-
If you encounter TypeScript errors:
|
|
537
|
-
|
|
538
|
-
```typescript
|
|
539
|
-
// If you get errors about Logger or LoggerOptions not being found
|
|
540
|
-
import type { Logger, LoggerOptions } from '@doubletie/logger';
|
|
541
|
-
|
|
542
|
-
// If you're extending BaseError and get errors
|
|
543
|
-
import type { BaseError } from '@doubletie/logger';
|
|
544
|
-
|
|
545
|
-
interface MyCustomError extends BaseError {
|
|
546
|
-
// Your custom properties
|
|
547
|
-
customField: string;
|
|
548
|
-
}
|
|
549
|
-
```
|
|
550
|
-
|
|
551
|
-
#### Performance Considerations
|
|
552
|
-
|
|
553
|
-
For high-volume logging in production:
|
|
554
|
-
|
|
555
|
-
1. Consider using a more efficient custom log handler that batches logs
|
|
556
|
-
2. Restrict log levels to only what's necessary
|
|
557
|
-
3. Use conditional logging for expensive operations:
|
|
558
|
-
|
|
559
|
-
```typescript
|
|
560
|
-
if (logger.shouldLog('debug')) {
|
|
561
|
-
// Only prepare this data if debug logging is enabled
|
|
562
|
-
const expensiveData = calculateExpensiveMetrics();
|
|
563
|
-
logger.debug('Performance metrics', expensiveData);
|
|
564
|
-
}
|
|
565
|
-
```
|
|
566
|
-
|
|
567
|
-
## License
|
|
568
|
-
|
|
569
|
-
The DoubleTie Logger is licensed under the MIT License.
|
package/src/pkgs/logger/index.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
* DoubleTie Logger Package
|
|
4
|
-
*
|
|
5
|
-
* A lightweight, customizable logging utility for Node.js and TypeScript applications.
|
|
6
|
-
* It provides structured logging capabilities, error logging utilities for the Result pattern,
|
|
7
|
-
* and flexible configuration options.
|
|
8
|
-
*
|
|
9
|
-
* @remarks
|
|
10
|
-
* This package is designed to work standalone or as part of the DoubleTie SDK.
|
|
11
|
-
* It includes:
|
|
12
|
-
* - Configurable log levels and filters
|
|
13
|
-
* - Color-coded console output
|
|
14
|
-
* - Error logging for Result/ResultAsync types from neverthrow
|
|
15
|
-
* - Custom log handlers
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* import { createLogger, logResult } from '@doubletie/logger';
|
|
20
|
-
*
|
|
21
|
-
* // Create a custom logger
|
|
22
|
-
* const logger = createLogger({ level: 'debug', appName: 'c15t' });
|
|
23
|
-
*
|
|
24
|
-
* // Log messages at different levels
|
|
25
|
-
* logger.info('Application started');
|
|
26
|
-
* logger.debug('Initializing components', { component: 'database' });
|
|
27
|
-
* logger.warn('Configuration missing, using defaults');
|
|
28
|
-
* logger.error('Failed to connect', { retry: true });
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
// Types
|
|
33
|
-
export type {
|
|
34
|
-
LogLevel,
|
|
35
|
-
Logger,
|
|
36
|
-
LoggerOptions,
|
|
37
|
-
LogEntry,
|
|
38
|
-
LoggableError,
|
|
39
|
-
} from './types';
|
|
40
|
-
|
|
41
|
-
// Log level handling
|
|
42
|
-
export {
|
|
43
|
-
levels,
|
|
44
|
-
shouldPublishLog,
|
|
45
|
-
} from './log-levels';
|
|
46
|
-
|
|
47
|
-
// Logger creation
|
|
48
|
-
export {
|
|
49
|
-
createLogger,
|
|
50
|
-
logger,
|
|
51
|
-
} from './logger-factory';
|
|
52
|
-
|
|
53
|
-
// Result-based error logging
|
|
54
|
-
export {
|
|
55
|
-
logResult,
|
|
56
|
-
logResultAsync,
|
|
57
|
-
logResult as logError,
|
|
58
|
-
logResultAsync as logErrorAsync,
|
|
59
|
-
} from './result-logging';
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { LogLevel } from './types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Array of all available log levels in order of importance.
|
|
5
|
-
*
|
|
6
|
-
* @remarks
|
|
7
|
-
* This const array ensures type safety when working with log levels
|
|
8
|
-
* and provides a reference for level comparisons.
|
|
9
|
-
*
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
export const levels = ['error', 'warn', 'info', 'success', 'debug'] as const;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Determines if a log message should be published based on configured log level.
|
|
16
|
-
*
|
|
17
|
-
* @param currentLogLevel - The configured log level threshold for the logger
|
|
18
|
-
* @param logLevel - The level of the message being evaluated
|
|
19
|
-
* @returns Boolean indicating whether the message should be published
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* // Only publish if error level is at or above the current log level
|
|
24
|
-
* if (shouldPublishLog('warn', 'error')) {
|
|
25
|
-
* // This will return true as error is more severe than warn
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
* @public
|
|
29
|
-
*/
|
|
30
|
-
export function shouldPublishLog(
|
|
31
|
-
currentLogLevel: LogLevel,
|
|
32
|
-
logLevel: LogLevel
|
|
33
|
-
): boolean {
|
|
34
|
-
// Lower indexes are more severe (error is first)
|
|
35
|
-
const currentLevelIndex = levels.indexOf(currentLogLevel);
|
|
36
|
-
const messageLevelIndex = levels.indexOf(logLevel);
|
|
37
|
-
|
|
38
|
-
// For 'debug' level, only show debug messages
|
|
39
|
-
if (currentLogLevel === 'debug') {
|
|
40
|
-
return logLevel === 'debug';
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// For other levels, show messages that are at the same level or more severe
|
|
44
|
-
// Lower index = more important.
|
|
45
|
-
return messageLevelIndex <= currentLevelIndex;
|
|
46
|
-
}
|