@nxtedition/types 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.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # @nxtedition/types
2
+
3
+ ## Description
4
+
5
+ This package contains:
6
+
7
+ - TypeScript types to be shared between nxtedition packages.
8
+ - Runtime validatiors and JSON functions for those types.
9
+
10
+ ## Usage
11
+
12
+ Import types and validators like this in TypeScript:
13
+
14
+ ```typescript
15
+ import type { TemplateRecord } from '@nxtedition/types'
16
+ import { isTemplateRecord } from '@nxtedition/types'
17
+ ```
18
+
19
+ const templateRecord: TemplateRecord = {
20
+ ...
21
+ }
22
+
23
+ ````
24
+
25
+ And like this in JavaScript:
26
+
27
+ ```javascript
28
+ import { isTemplateRecord } from '@nxtedition/types'
29
+
30
+ /**
31
+ * @typedef { import("@nxtedition/types").TemplateRecord } TemplateRecord
32
+ */
33
+
34
+ /** @type {TemplateRecord} */
35
+ const templateRecord = { ... }
36
+ ````
37
+
38
+ If bundle size is an issue, you can import only the parts you need like this:
39
+
40
+ ```typescript
41
+ import { isTemplateRecord } from '@nxtedition/types/domains/template'
42
+ ```
43
+
44
+ ## Development
45
+
46
+ ### Generate runtime code
47
+
48
+ Generally, we only manually specify types in this package. A code generator is
49
+ used to generate the runtime validators and JSON functions. It will do so for
50
+ all types that are exported. To run the generator, use the following command:
51
+
52
+ ```bash
53
+ yarn build
54
+ ```
55
+
56
+ This will build the output to the `dist` directory.
57
+
58
+ ### Exports
59
+
60
+ We export all types up to the root of the package, so they can be imported
61
+ directly from `@nxtedition/types`. This means that all exported types must
62
+ be uniquely named.
@@ -0,0 +1,25 @@
1
+ import { type AssertionGuard as __AssertionGuard } from "typia";
2
+ import { tags } from 'typia';
3
+ export interface Block {
4
+ fileId: string;
5
+ locationId: string;
6
+ blockId: string;
7
+ offset?: number & tags.Type<"uint32">;
8
+ position?: number & tags.Type<"uint32">;
9
+ size?: number & tags.Type<"uint32">;
10
+ hash?: string;
11
+ btime?: number & tags.Type<"uint32">;
12
+ }
13
+ export declare const isBlock: (input: unknown) => input is Block;
14
+ export declare const assertBlock: (input: unknown) => Block;
15
+ export declare const randomBlock: () => Block;
16
+ export declare const assertGuardBlock: __AssertionGuard<Block>;
17
+ export declare const stringifyBlock: (input: Block) => string;
18
+ export declare const assertStringifyBlock: (input: unknown) => string;
19
+ export type Blocks = Block[];
20
+ export declare const isBlocks: (input: unknown) => input is Blocks;
21
+ export declare const assertBlocks: (input: unknown) => Blocks;
22
+ export declare const randomBlocks: () => Blocks;
23
+ export declare const assertGuardBlocks: __AssertionGuard<Blocks>;
24
+ export declare const stringifyBlocks: (input: Blocks) => string;
25
+ export declare const assertStringifyBlocks: (input: unknown) => string;