typed-csv 1.0.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,65 @@
1
+ type SchemaType = "string" | "number" | "int" | "float" | "boolean";
2
+ interface PrimitiveSchema {
3
+ type: SchemaType;
4
+ }
5
+ interface NamedSchema {
6
+ name?: string;
7
+ schema: Schema;
8
+ }
9
+ interface TupleSchema {
10
+ type: "tuple";
11
+ elements: NamedSchema[];
12
+ }
13
+ interface ArraySchema {
14
+ type: "array";
15
+ element: Schema;
16
+ }
17
+ interface ReferenceSchema {
18
+ type: "reference";
19
+ /** Referenced table name (e.g., 'parts' from '@parts[]') */
20
+ tableName: string;
21
+ /** Whether it's an array reference */
22
+ isArray: boolean;
23
+ /** Whether it's optional (allows empty input resolving to null) */
24
+ isOptional?: boolean;
25
+ }
26
+ interface ReverseReferenceSchema {
27
+ type: "reverseReference";
28
+ /** Referenced table name (e.g., 'orders' from '~orders(user)') */
29
+ tableName: string;
30
+ /** The foreign key field name in the referenced table (e.g., 'user' from '~orders(user)') */
31
+ foreignKey: string;
32
+ /** Whether it's optional (null if no matches, instead of empty array) */
33
+ isOptional?: boolean;
34
+ }
35
+ interface StringLiteralSchema {
36
+ type: "stringLiteral";
37
+ value: string;
38
+ }
39
+ interface UnionSchema {
40
+ type: "union";
41
+ members: Schema[];
42
+ }
43
+ type Schema = PrimitiveSchema | TupleSchema | ArraySchema | ReferenceSchema | ReverseReferenceSchema | StringLiteralSchema | UnionSchema;
44
+ interface ParsedSchema {
45
+ schema: Schema;
46
+ validator: (value: unknown) => boolean;
47
+ parse: (valueString: string) => unknown;
48
+ }
49
+
50
+ declare class ParseError extends Error {
51
+ position?: number | undefined;
52
+ schema?: string | undefined;
53
+ value?: string | undefined;
54
+ constructor(message: string, position?: number | undefined, schema?: string | undefined, value?: string | undefined);
55
+ }
56
+ declare function parseSchema(schemaString: string): Schema;
57
+
58
+ declare function parseValue(schema: Schema, valueString: string, schemaString?: string): unknown;
59
+
60
+ declare function schemaToTypeString(schema: Schema, resourceNames?: Map<string, string>): string;
61
+ declare function createValidator(schema: Schema): (value: unknown) => boolean;
62
+
63
+ declare function defineSchema(schemaString: string): ParsedSchema;
64
+
65
+ export { type ArraySchema, ParseError, type ParsedSchema, type PrimitiveSchema, type ReferenceSchema, type ReverseReferenceSchema, type Schema, type StringLiteralSchema, type TupleSchema, type UnionSchema, createValidator, defineSchema, parseSchema, parseValue, schemaToTypeString };
@@ -0,0 +1,65 @@
1
+ type SchemaType = "string" | "number" | "int" | "float" | "boolean";
2
+ interface PrimitiveSchema {
3
+ type: SchemaType;
4
+ }
5
+ interface NamedSchema {
6
+ name?: string;
7
+ schema: Schema;
8
+ }
9
+ interface TupleSchema {
10
+ type: "tuple";
11
+ elements: NamedSchema[];
12
+ }
13
+ interface ArraySchema {
14
+ type: "array";
15
+ element: Schema;
16
+ }
17
+ interface ReferenceSchema {
18
+ type: "reference";
19
+ /** Referenced table name (e.g., 'parts' from '@parts[]') */
20
+ tableName: string;
21
+ /** Whether it's an array reference */
22
+ isArray: boolean;
23
+ /** Whether it's optional (allows empty input resolving to null) */
24
+ isOptional?: boolean;
25
+ }
26
+ interface ReverseReferenceSchema {
27
+ type: "reverseReference";
28
+ /** Referenced table name (e.g., 'orders' from '~orders(user)') */
29
+ tableName: string;
30
+ /** The foreign key field name in the referenced table (e.g., 'user' from '~orders(user)') */
31
+ foreignKey: string;
32
+ /** Whether it's optional (null if no matches, instead of empty array) */
33
+ isOptional?: boolean;
34
+ }
35
+ interface StringLiteralSchema {
36
+ type: "stringLiteral";
37
+ value: string;
38
+ }
39
+ interface UnionSchema {
40
+ type: "union";
41
+ members: Schema[];
42
+ }
43
+ type Schema = PrimitiveSchema | TupleSchema | ArraySchema | ReferenceSchema | ReverseReferenceSchema | StringLiteralSchema | UnionSchema;
44
+ interface ParsedSchema {
45
+ schema: Schema;
46
+ validator: (value: unknown) => boolean;
47
+ parse: (valueString: string) => unknown;
48
+ }
49
+
50
+ declare class ParseError extends Error {
51
+ position?: number | undefined;
52
+ schema?: string | undefined;
53
+ value?: string | undefined;
54
+ constructor(message: string, position?: number | undefined, schema?: string | undefined, value?: string | undefined);
55
+ }
56
+ declare function parseSchema(schemaString: string): Schema;
57
+
58
+ declare function parseValue(schema: Schema, valueString: string, schemaString?: string): unknown;
59
+
60
+ declare function schemaToTypeString(schema: Schema, resourceNames?: Map<string, string>): string;
61
+ declare function createValidator(schema: Schema): (value: unknown) => boolean;
62
+
63
+ declare function defineSchema(schemaString: string): ParsedSchema;
64
+
65
+ export { type ArraySchema, ParseError, type ParsedSchema, type PrimitiveSchema, type ReferenceSchema, type ReverseReferenceSchema, type Schema, type StringLiteralSchema, type TupleSchema, type UnionSchema, createValidator, defineSchema, parseSchema, parseValue, schemaToTypeString };