densing 0.1.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.
@@ -0,0 +1,13 @@
1
+ import { BoolField, IntField, EnumField, FixedPointField, DenseField, ArrayField, UnionField, EnumArrayField, OptionalField, ObjectField } from '../schema-type';
2
+ export declare const bool: (name: string, defaultValue?: boolean) => BoolField;
3
+ export declare const int: (name: string, min: number, max: number, defaultValue?: number) => IntField;
4
+ export declare const enumeration: (name: string, options: readonly string[], defaultValue?: string) => EnumField;
5
+ export declare const fixed: (name: string, min: number, max: number, precision: number, defaultValue?: number) => FixedPointField;
6
+ export declare const array: (name: string, minLength: number, maxLength: number, items: DenseField) => ArrayField;
7
+ export declare const union: (name: string, discriminator: EnumField, variants: Record<string, DenseField[]>) => UnionField;
8
+ export declare const enumArray: (name: string, enumDef: EnumField, minLength: number, maxLength: number, defaultValue?: string[]) => EnumArrayField;
9
+ export declare const optional: (name: string, field: DenseField, defaultValue?: any) => OptionalField;
10
+ export declare const object: (name: string, ...fields: DenseField[]) => ObjectField;
11
+ export declare const schema: <const T extends DenseField[]>(...fields: T) => {
12
+ readonly fields: T;
13
+ };
@@ -0,0 +1,7 @@
1
+ import { DenseSchema } from '../schema-type';
2
+ /**
3
+ * Helper method to get the default state as defined by a schema
4
+ * @param schema - `Schema` definition
5
+ * @returns `Object` - A javascript object with the default state described in the schema
6
+ */
7
+ export declare const getDefaultData: (schema: DenseSchema) => any;
@@ -0,0 +1,5 @@
1
+ export * from './builder';
2
+ export * from './default-data';
3
+ export * from './recursive-builder-helper';
4
+ export * from './type-generator';
5
+ export * from './validation';
@@ -0,0 +1,6 @@
1
+ import { DenseField } from '../schema-type';
2
+ /**
3
+ * Helper function to create a recursive union field with a specified max depth.
4
+ * This allows you to define the structure ONCE and it gets expanded automatically.
5
+ */
6
+ export declare const createRecursiveUnion: (name: string, discriminatorOptions: readonly string[], createVariants: (recurse: (fieldName: string, depth?: number) => DenseField) => Record<string, DenseField[]>, maxDepth: number, currentDepth?: number) => DenseField;
@@ -0,0 +1,13 @@
1
+ import { DenseSchema } from '../schema-type';
2
+ /**
3
+ * Generate TypeScript type definitions from a schema
4
+ */
5
+ export declare const generateTypes: (schema: DenseSchema, rootTypeName?: string) => string;
6
+ /**
7
+ * Generate types and write to a .d.ts file
8
+ */
9
+ export declare const generateTypesFile: (schema: DenseSchema, outputPath: string, rootTypeName?: string) => void;
10
+ /**
11
+ * Generate types and write to console (for convenience)
12
+ */
13
+ export declare const printTypes: (schema: DenseSchema, rootTypeName?: string) => void;
@@ -0,0 +1,10 @@
1
+ import { DenseSchema } from '../schema-type';
2
+ export interface ValidationError {
3
+ path: string;
4
+ message: string;
5
+ }
6
+ export interface ValidationResult {
7
+ valid: boolean;
8
+ errors: ValidationError[];
9
+ }
10
+ export declare const validate: (schema: DenseSchema, data: any) => ValidationResult;
@@ -0,0 +1,63 @@
1
+ export type DenseField = BoolField | IntField | EnumField | FixedPointField | ArrayField | EnumArrayField | UnionField | OptionalField | ObjectField;
2
+ export interface BoolField {
3
+ type: 'bool';
4
+ name: string;
5
+ defaultValue: boolean;
6
+ }
7
+ export interface IntField {
8
+ type: 'int';
9
+ name: string;
10
+ min: number;
11
+ max: number;
12
+ defaultValue: number;
13
+ }
14
+ export interface EnumField {
15
+ type: 'enum';
16
+ name: string;
17
+ options: readonly string[];
18
+ defaultValue: string;
19
+ }
20
+ export interface FixedPointField {
21
+ type: 'fixed';
22
+ name: string;
23
+ min: number;
24
+ max: number;
25
+ precision: number;
26
+ defaultValue: number;
27
+ }
28
+ export interface ArrayField {
29
+ type: 'array';
30
+ name: string;
31
+ items: DenseField;
32
+ minLength: number;
33
+ maxLength: number;
34
+ }
35
+ export interface UnionField {
36
+ type: 'union';
37
+ name: string;
38
+ discriminator: EnumField;
39
+ variants: Record<string, DenseField[]>;
40
+ }
41
+ export interface EnumArrayField {
42
+ type: 'enum_array';
43
+ name: string;
44
+ enum: EnumField;
45
+ minLength: number;
46
+ maxLength: number;
47
+ defaultValue: string[];
48
+ }
49
+ export interface OptionalField {
50
+ type: 'optional';
51
+ name: string;
52
+ field: DenseField;
53
+ defaultValue?: any;
54
+ }
55
+ export interface ObjectField {
56
+ type: 'object';
57
+ name: string;
58
+ fields: DenseField[];
59
+ }
60
+ export interface DenseSchema {
61
+ fields: DenseField[];
62
+ }
63
+ export type ConstantBitWidthField = BoolField | IntField | EnumField | FixedPointField;
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "densing",
3
+ "version": "0.1.0",
4
+ "description": "Bit and base level packing for TypeScript. Perfect for URLs, QR codes, and other storage constrained contexts.",
5
+ "author": "Jonas Ward",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/JonasWard/densing.git"
10
+ },
11
+ "keywords": [
12
+ "serialization",
13
+ "compression",
14
+ "encoding",
15
+ "base64",
16
+ "bit-packing",
17
+ "schema",
18
+ "typescript",
19
+ "url-encoding",
20
+ "qr-code",
21
+ "data-compression"
22
+ ],
23
+ "main": "dist/index.js",
24
+ "types": "dist/index.d.ts",
25
+ "files": [
26
+ "dist",
27
+ "README.md",
28
+ "LICENSE"
29
+ ],
30
+ "type": "module",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js"
35
+ }
36
+ },
37
+ "scripts": {
38
+ "build": "bun build --target=node ./src/index.ts --outfile=dist/index.js && bun run build:declaration",
39
+ "build:declaration": "tsc --emitDeclarationOnly --isolatedDeclarations --project tsconfig.types.json",
40
+ "postbuild": "rimraf tsconfig.types.tsbuildinfo",
41
+ "benchmark": "bun run benchmark.ts",
42
+ "test": "bun test",
43
+ "prepublishOnly": "bun test && bun run build"
44
+ },
45
+ "devDependencies": {
46
+ "bun-types": "latest",
47
+ "rimraf": "^6.0.1",
48
+ "typescript": "^5.9.3",
49
+ "@types/bun": "latest"
50
+ },
51
+ "engines": {
52
+ "node": ">=18.0.0"
53
+ }
54
+ }