Registry / database / forge-database-utils

forge-database-utils

JSON →
library1.4.1jsnpmunverified

`forge-database-utils` is a JavaScript/TypeScript package designed to provide shared database utility functions specifically for Forge services. Currently at version 1.4.1, it centralizes common database-related logic to ensure consistency and reduce code duplication across various internal Forge components like control, authentication, metadata, and UI services. Key features include a centralized definition of supported field types, utility functions for validating and querying field type properties (e.g., `isSupportedFieldType`, `getPostgresColumnType`), and functions for generating PostgreSQL-compatible base names from instance IDs. The package is developed to align with the specific architectural needs of the Forge ecosystem, serving as a foundational library rather than a general-purpose database utility. Its release cadence is typically tied to internal project development cycles, ensuring tight integration and stability within the Forge suite.

npm install forge-database-utils
INSTALL
IMPORT
SIG · FORGE-DATABASE-UTI
F
forge-database-utils
databasejavascriptv1.4.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

getSupportedFieldTypes
import { getSupportedFieldTypes } from 'forge-database-utils';
const { getSupportedFieldTypes } = require('forge-database-utils');
Package primarily designed for ESM imports; CJS `require` might lead to issues in some environments or configurations due to mixed module types.
SUPPORTED_FIELD_TYPES
import { SUPPORTED_FIELD_TYPES } from 'forge-database-utils';
import SUPPORTED_FIELD_TYPES from 'forge-database-utils';
Constants are exported as named exports; there is no default export from this package.
FieldType
import type { FieldType } from 'forge-database-utils';
Always use `import type` for type-only imports to ensure they are stripped during compilation and prevent accidental runtime dependencies.

Demonstrates importing various utility functions and types, using `getSupportedFieldTypes`, checking field type support, deriving PostgreSQL column types, handling 'Generated' field properties, and generating base names.

import { getSupportedFieldTypes, isSupportedFieldType, getPostgresColumnType, buildGeneratedColumnDefinition, generateBaseName, type FieldType } from 'forge-database-utils'; // 1. Get and process supported field types const fieldTypes = getSupportedFieldTypes(); console.log('All supported field types:', fieldTypes.slice(0, 5).join(', ') + '...'); const exampleField: FieldType = 'ShortText'; if (isSupportedFieldType(exampleField)) { const columnType = getPostgresColumnType(exampleField); console.log(`'${exampleField}' maps to PostgreSQL type: ${columnType}`); } // 2. Handle 'Generated' field type with properties const generatedFieldProps = { data_type: 'ShortText', generation_type: 'VIRTUAL', column_defn: "first_name || ' ' || last_name" }; const generatedColumnDef = getPostgresColumnType('Generated', generatedFieldProps); console.log(`'Generated' field type (full name) column definition: ${generatedColumnDef}`); // 3. Generate a PostgreSQL-compatible base name const instanceId = 'My New Service 2024-Q2'; const baseName = generateBaseName(instanceId); console.log(`Base name for '${instanceId}': ${baseName}`); // Example of using the FieldType type function displayFieldInfo(fieldType: FieldType) { console.log(`Processing field: ${fieldType}`); } displayFieldInfo('Email');
Debug
Known issues
gotchaWhen using `getPostgresColumnType` for the `Generated` field type, an explicit `fieldTypeProperties` object with `data_type`, `generation_type`, and `column_defn` is mandatory. Failing to provide this will result in an error or incorrect column definition.
fix
Ensure the second argument to `getPostgresColumnType` is a complete `fieldTypeProperties` object when `fieldType` is 'Generated'.
affects: >=1.0.0
gotchaThis package is designed for an ESM-first environment. While bundlers usually handle CommonJS compatibility, direct `require()` calls in Node.js projects not configured for ESM might lead to `TypeError: ... is not a function` errors due to differences in module resolution.
fix
Prefer `import` statements over `require()`. If using Node.js, ensure your `package.json` specifies `"type": "module"` or use a transpiler like Babel/TypeScript to convert to ESM.
affects: >=1.0.0
gotchaThe `SUPPORTED_FIELD_TYPES` constant and `getSupportedFieldTypes()` function provide a list of currently supported types. If new field types are introduced in a newer version of `forge-database-utils`, consuming services must update their package version to correctly validate and utilize these new types.
fix
Regularly update `forge-database-utils` to benefit from new features and synchronize with the latest field type definitions across Forge services. Always validate user input against `isSupportedFieldType` or `SUPPORTED_FIELD_TYPES`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: forge_database_utils__WEBPACK_IMPORTED_MODULE_0__.getSupportedFieldTypes is not a function
Incorrect import syntax, typically when a bundler (like Webpack) processes a CJS `require` for an ESM-only package, or when trying to destructure a module object incorrectly.
fix
Change `const { getSupportedFieldTypes } = require('forge-database-utils');` to `import { getSupportedFieldTypes } from 'forge-database-utils';`. Ensure your project and bundler are configured for ESM.
Error: field_type must be a supported field type
Attempted to use an unsupported or misspelled field type in a validation context, often when integrating with a validation library like `express-validator`.
fix
Verify the field type string against `SUPPORTED_FIELD_TYPES` or use `isSupportedFieldType()` to check validity before processing. Correct any typos or ensure the field type is part of the Forge system.
Argument of type '"CustomType"' is not assignable to parameter of type 'FieldType'.
TypeScript error indicating that a string literal or variable passed to a function expecting `FieldType` (a union of supported types) does not match any of the allowed types.
fix
Ensure the value passed is one of the types defined in the `FieldType` union. If it's a new custom type, it needs to be added to the internal Forge system and the `forge-database-utils` package.
Upgrade
Version history
1.4.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources