Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 19 additions & 3 deletions docs/3.results/4.table_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,25 @@ Field types describe the structure of each field:

```typescript
type FieldType =
| string // Primitive type name (e.g., "string", "number")
| Array<FieldType> // Array of a given type
| { [subfield: string]: FieldType }; // Nested object
| string // Primitive type name (e.g., "string", "number")
| Array<StringFieldType> // Array of a given type
| { [subfield: string]: StringFieldType } // Nested object
| import("io-ts").Mixed; // io-ts codec at the field root
```

A field can be described either with the string-token vocabulary (primitives, arrays, nested records) or with a single [io-ts](https://github.com/gcanti/io-ts) codec at the root of the field. Codecs are not mixed inside string-tree records — use io-ts combinators (`t.type`, `t.array`, …) to nest within a codec.

```typescript
import * as t from "io-ts";

const Order = {
fields: {
id: "string",
status: t.union([t.literal("open"), t.literal("closed")]),
meta: t.type({ source: t.string, retries: t.number }),
},
indexes: {},
};
```

## Define Tables in a Schema
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"@types/node": "^22.19.15",
"@types/semver": "^7.7.1",
"chai": "^4.5.0",
"fp-ts": "^2.16.0",
"io-ts": "^2.2.0",
"mongodb-memory-server-core": "^11.0.1",
"release-it": "^19.2.4",
"release-it-changelogen": "^0.1.0",
Expand Down
20 changes: 20 additions & 0 deletions pnpm-lock.yaml

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

18 changes: 15 additions & 3 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,22 @@ export interface IndexDefinition {
multi?: boolean;
}

export type FieldType =
export type StringFieldType =
| string
| Array<FieldType>
| { [subfield: string]: FieldType };
| Array<StringFieldType>
| { [subfield: string]: StringFieldType };

interface IoTsCodec {
readonly _A: unknown;
readonly _O: unknown;
readonly _I: unknown;
readonly name: string;
is(u: unknown): boolean;
encode(a: never): unknown;
decode(i: unknown): unknown;
}

export type FieldType = StringFieldType | IoTsCodec;

/**
* Schema table definition
Expand Down
16 changes: 16 additions & 0 deletions src/tests/datasets/codec_fields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as t from "io-ts";
import type { SchemaDefinition } from "../../schema";

export const definition: SchemaDefinition = {
orders: {
fields: {
id: "string",
status: t.union([t.literal("open"), t.literal("closed")]),
meta: t.type({ source: t.string, retries: t.number }),
tags: "string[]",
},
indexes: {
status: {},
},
},
};
Loading