@type-map-for/typesense 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.
- package/dist/index.d.ts +25 -0
- package/package.json +22 -0
- package/src/index.ts +37 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { FieldTypeFor, MapType } from '@type-map-for/core';
|
|
2
|
+
type TsTypeMap = {
|
|
3
|
+
string: 'string';
|
|
4
|
+
'string[]': 'string[]';
|
|
5
|
+
int32: 'int32';
|
|
6
|
+
'int32[]': 'int32[]';
|
|
7
|
+
float: 'float';
|
|
8
|
+
'float[]': 'float[]';
|
|
9
|
+
bool: 'bool';
|
|
10
|
+
'bool[]': 'bool[]';
|
|
11
|
+
object: 'object';
|
|
12
|
+
'object[]': 'object[]';
|
|
13
|
+
};
|
|
14
|
+
type TsType<T> = MapType<FieldTypeFor<NonNullable<T>>, TsTypeMap>;
|
|
15
|
+
type TsOptional<T> = undefined extends T ? true : false;
|
|
16
|
+
export type TypesenseField<T, K extends keyof T> = {
|
|
17
|
+
name: K;
|
|
18
|
+
type: TsType<T[K]>;
|
|
19
|
+
optional: TsOptional<T[K]>;
|
|
20
|
+
index?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export type TypesenseFieldMap<T> = Array<{
|
|
23
|
+
[K in keyof T]-?: TypesenseField<T, K>;
|
|
24
|
+
}[keyof T]>;
|
|
25
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@type-map-for/typesense",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Compile-time TypeScript → Typesense field mapping",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Nathan Frenette",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": { "types": "./dist/index.d.ts" }
|
|
10
|
+
},
|
|
11
|
+
"files": ["dist", "src"],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc -p tsconfig.json"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": { "access": "public" },
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@type-map-for/core": "*"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "*"
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { FieldTypeFor, MapType } from '@type-map-for/core';
|
|
2
|
+
|
|
3
|
+
/* ------------------------------------------------------------------ *
|
|
4
|
+
* @type-map-for/typesense *
|
|
5
|
+
* *
|
|
6
|
+
* - Output shape: Array<{ name, type, optional, index? }> *
|
|
7
|
+
* - Arrays: type suffix, e.g. string[] *
|
|
8
|
+
* - Optional: optional: true *
|
|
9
|
+
* - Required: optional: false *
|
|
10
|
+
* ------------------------------------------------------------------ */
|
|
11
|
+
|
|
12
|
+
type TsTypeMap = {
|
|
13
|
+
string: 'string';
|
|
14
|
+
'string[]': 'string[]';
|
|
15
|
+
int32: 'int32';
|
|
16
|
+
'int32[]': 'int32[]';
|
|
17
|
+
float: 'float';
|
|
18
|
+
'float[]': 'float[]';
|
|
19
|
+
bool: 'bool';
|
|
20
|
+
'bool[]': 'bool[]';
|
|
21
|
+
object: 'object';
|
|
22
|
+
'object[]': 'object[]';
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type TsType<T> = MapType<FieldTypeFor<NonNullable<T>>, TsTypeMap>;
|
|
26
|
+
type TsOptional<T> = undefined extends T ? true : false;
|
|
27
|
+
|
|
28
|
+
export type TypesenseField<T, K extends keyof T> = {
|
|
29
|
+
name: K;
|
|
30
|
+
type: TsType<T[K]>;
|
|
31
|
+
optional: TsOptional<T[K]>;
|
|
32
|
+
index?: boolean;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type TypesenseFieldMap<T> = Array<{
|
|
36
|
+
[K in keyof T]-?: TypesenseField<T, K>
|
|
37
|
+
}[keyof T]>;
|