@palantir/pack.schema 0.0.1-beta.1
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/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-transpileBrowser.log +5 -0
- package/.turbo/turbo-transpileCjs.log +5 -0
- package/.turbo/turbo-transpileEsm.log +5 -0
- package/.turbo/turbo-transpileTypes.log +5 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/LICENSE.txt +13 -0
- package/README.md +87 -0
- package/build/browser/index.js +176 -0
- package/build/browser/index.js.map +1 -0
- package/build/cjs/index.cjs +192 -0
- package/build/cjs/index.cjs.map +1 -0
- package/build/cjs/index.d.cts +131 -0
- package/build/esm/index.js +176 -0
- package/build/esm/index.js.map +1 -0
- package/build/types/__tests__/defineMigration.test.d.ts +1 -0
- package/build/types/__tests__/defineMigration.test.d.ts.map +1 -0
- package/build/types/__tests__/defineRecord.test.d.ts +1 -0
- package/build/types/__tests__/defineRecord.test.d.ts.map +1 -0
- package/build/types/__tests__/defineUnion.test.d.ts +1 -0
- package/build/types/__tests__/defineUnion.test.d.ts.map +1 -0
- package/build/types/__tests__/integration.test.d.ts +1 -0
- package/build/types/__tests__/integration.test.d.ts.map +1 -0
- package/build/types/__tests__/primitives.test.d.ts +1 -0
- package/build/types/__tests__/primitives.test.d.ts.map +1 -0
- package/build/types/__tests__/testTypeUtils.d.ts +74 -0
- package/build/types/__tests__/testTypeUtils.d.ts.map +1 -0
- package/build/types/defineMigration.d.ts +21 -0
- package/build/types/defineMigration.d.ts.map +1 -0
- package/build/types/defineRecord.d.ts +14 -0
- package/build/types/defineRecord.d.ts.map +1 -0
- package/build/types/defineUnion.d.ts +12 -0
- package/build/types/defineUnion.d.ts.map +1 -0
- package/build/types/defs.d.ts +24 -0
- package/build/types/defs.d.ts.map +1 -0
- package/build/types/index.d.ts +6 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/primitives.d.ts +41 -0
- package/build/types/primitives.d.ts.map +1 -0
- package/build/types/utils.d.ts +20 -0
- package/build/types/utils.d.ts.map +1 -0
- package/package.json +55 -0
- package/src/__tests__/defineMigration.test.ts +265 -0
- package/src/__tests__/defineRecord.test.ts +167 -0
- package/src/__tests__/defineUnion.test.ts +231 -0
- package/src/__tests__/integration.test.ts +126 -0
- package/src/__tests__/primitives.test.ts +153 -0
- package/src/__tests__/testTypeUtils.ts +92 -0
- package/src/defineMigration.ts +159 -0
- package/src/defineRecord.ts +83 -0
- package/src/defineUnion.ts +58 -0
- package/src/defs.ts +46 -0
- package/src/index.ts +22 -0
- package/src/primitives.ts +80 -0
- package/src/utils.ts +62 -0
- package/tsconfig.json +21 -0
- package/vitest.config.mjs +26 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
declare const TypeKind: {
|
|
2
|
+
readonly ARRAY: "array";
|
|
3
|
+
readonly DOUBLE: "double";
|
|
4
|
+
readonly OPTIONAL: "optional";
|
|
5
|
+
readonly REF: "ref";
|
|
6
|
+
readonly STRING: "string";
|
|
7
|
+
readonly UNKNOWN: "unknown";
|
|
8
|
+
};
|
|
9
|
+
type TypeKind = typeof TypeKind[keyof typeof TypeKind];
|
|
10
|
+
interface TypeBase {
|
|
11
|
+
readonly type: TypeKind;
|
|
12
|
+
}
|
|
13
|
+
type Ref = {
|
|
14
|
+
readonly type: typeof TypeKind.REF;
|
|
15
|
+
readonly refType: "record" | "union";
|
|
16
|
+
readonly name: string;
|
|
17
|
+
};
|
|
18
|
+
type Type = String | Double | Array | Ref | Optional | Unknown;
|
|
19
|
+
type String = {
|
|
20
|
+
readonly type: typeof TypeKind.STRING;
|
|
21
|
+
};
|
|
22
|
+
declare const String: String;
|
|
23
|
+
type Double = {
|
|
24
|
+
readonly type: typeof TypeKind.DOUBLE;
|
|
25
|
+
};
|
|
26
|
+
declare const Double: Double;
|
|
27
|
+
type Unknown = {
|
|
28
|
+
readonly type: typeof TypeKind.UNKNOWN;
|
|
29
|
+
};
|
|
30
|
+
declare const Unknown: Unknown;
|
|
31
|
+
type Array<T extends TypeBase = TypeBase> = {
|
|
32
|
+
readonly type: typeof TypeKind.ARRAY;
|
|
33
|
+
readonly items: T;
|
|
34
|
+
};
|
|
35
|
+
declare const Array: <T extends TypeBase>(item: T) => Array<T>;
|
|
36
|
+
type Optional<T extends TypeBase = TypeBase> = {
|
|
37
|
+
readonly type: typeof TypeKind.OPTIONAL;
|
|
38
|
+
readonly item: T;
|
|
39
|
+
};
|
|
40
|
+
declare const Optional: <T extends TypeBase>(item: T) => Optional<T>;
|
|
41
|
+
|
|
42
|
+
declare const ModelDefType: {
|
|
43
|
+
readonly RECORD: "record";
|
|
44
|
+
readonly UNION: "union";
|
|
45
|
+
};
|
|
46
|
+
type ModelDefType = typeof ModelDefType[keyof typeof ModelDefType];
|
|
47
|
+
interface ModelDefBase {
|
|
48
|
+
readonly type: ModelDefType;
|
|
49
|
+
readonly name: string;
|
|
50
|
+
readonly docs?: string;
|
|
51
|
+
}
|
|
52
|
+
type RecordFields = Record<string, Type>;
|
|
53
|
+
type UnionVariants = Record<string, Ref>;
|
|
54
|
+
interface UnionDef<TVariants extends UnionVariants = UnionVariants> extends ModelDefBase {
|
|
55
|
+
readonly type: typeof ModelDefType.UNION;
|
|
56
|
+
readonly variants: TVariants;
|
|
57
|
+
readonly discriminant: string;
|
|
58
|
+
}
|
|
59
|
+
interface RecordDef<TFields extends RecordFields = RecordFields> extends ModelDefBase {
|
|
60
|
+
readonly type: typeof ModelDefType.RECORD;
|
|
61
|
+
readonly fields: TFields;
|
|
62
|
+
}
|
|
63
|
+
type ModelDef = RecordDef | UnionDef;
|
|
64
|
+
|
|
65
|
+
type UnionVariantArgExplicit = Ref | ModelDef;
|
|
66
|
+
type UnionVariantArg = UnionVariantArgExplicit | (() => UnionVariantArgExplicit);
|
|
67
|
+
type UnionVariantArgs = Record<string, UnionVariantArg>;
|
|
68
|
+
type ResolvedUnionVariants<T extends UnionVariantArgs> = {
|
|
69
|
+
readonly [K in keyof T]: Ref;
|
|
70
|
+
};
|
|
71
|
+
type UnionArgs<T extends UnionVariantArgs> = {
|
|
72
|
+
readonly docs: string;
|
|
73
|
+
readonly variants: T;
|
|
74
|
+
};
|
|
75
|
+
declare function defineUnion<const TVariants extends UnionVariantArgs>(name: string, union: UnionArgs<TVariants>): UnionDef<ResolvedUnionVariants<TVariants>>;
|
|
76
|
+
declare function resolveUnionVariantArg(arg: UnionVariantArg): Ref;
|
|
77
|
+
|
|
78
|
+
type ReturnedSchema = Record<string, RecordDef | UnionDef>;
|
|
79
|
+
type Schema<T extends ReturnedSchema> = T;
|
|
80
|
+
type SchemaBuilder<T extends ReturnedSchema> = {
|
|
81
|
+
[k in keyof T]: T[k] extends UnionDef<infer R> ? UnionBuilder<R> : T[k] extends RecordDef<infer R> ? RecordBuilder<R> : never;
|
|
82
|
+
};
|
|
83
|
+
interface RecordBuilder<T extends Record<string, Type>> {
|
|
84
|
+
addField<const K extends string, V extends Type>(name: K, type: V): RecordBuilder<T & {
|
|
85
|
+
[k in K]: V;
|
|
86
|
+
}>;
|
|
87
|
+
build(): RecordDef<T>;
|
|
88
|
+
}
|
|
89
|
+
interface UnionBuilder<S extends UnionVariants> {
|
|
90
|
+
addVariant<const K extends string>(name: K, modelDefOrRef: UnionVariantArg): UnionBuilder<S & {
|
|
91
|
+
[k in K]: Ref;
|
|
92
|
+
}>;
|
|
93
|
+
build(): UnionDef<S>;
|
|
94
|
+
}
|
|
95
|
+
declare function defineMigration<const T extends ReturnedSchema, const S extends ReturnedSchema>(previous: Schema<T>, migration: (schema: SchemaBuilder<T>) => S): Schema<T & S>;
|
|
96
|
+
|
|
97
|
+
type FieldArgExplicit = Type | RecordDef | UnionDef;
|
|
98
|
+
type FieldArg = FieldArgExplicit | (() => FieldArgExplicit);
|
|
99
|
+
type FieldArgExplicitOf<T extends FieldArg> = T extends () => infer R ? R : T;
|
|
100
|
+
type FieldArgs = Record<string, FieldArg>;
|
|
101
|
+
type ResolvedFieldArgExplicit<T extends FieldArgExplicit> = T extends RecordDef | UnionDef ? Ref : T;
|
|
102
|
+
type ResolvedFieldArg<T extends FieldArg> = ResolvedFieldArgExplicit<FieldArgExplicitOf<T>>;
|
|
103
|
+
type ResolvedFields<T extends FieldArgs> = {
|
|
104
|
+
readonly [K in keyof T]: ResolvedFieldArg<T[K]>;
|
|
105
|
+
};
|
|
106
|
+
type RecordArgs<T extends FieldArgs> = {
|
|
107
|
+
readonly docs: string;
|
|
108
|
+
readonly fields: T;
|
|
109
|
+
};
|
|
110
|
+
declare function defineRecord<const T extends FieldArgs>(name: string, record: RecordArgs<T>): RecordDef<ResolvedFields<T>>;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Helper function to safely transform a record definition to a reference.
|
|
114
|
+
* This function helps TypeScript track type transformations better.
|
|
115
|
+
*/
|
|
116
|
+
declare function modelToRef(model: ModelDef): Ref;
|
|
117
|
+
/**
|
|
118
|
+
* Helper function to create a reference with proper typing.
|
|
119
|
+
* This avoids type assertions in multiple places.
|
|
120
|
+
*/
|
|
121
|
+
declare function createRef(name: string, refType: "record" | "union"): Ref;
|
|
122
|
+
/**
|
|
123
|
+
* Type guard to check if a value is a RecordDef
|
|
124
|
+
*/
|
|
125
|
+
declare function isRecordDef(value: unknown): value is RecordDef;
|
|
126
|
+
/**
|
|
127
|
+
* Type guard to check if a value is a UnionDef
|
|
128
|
+
*/
|
|
129
|
+
declare function isUnionDef(value: unknown): value is UnionDef;
|
|
130
|
+
|
|
131
|
+
export { Array, Double, type FieldArg, type FieldArgExplicit, type FieldArgExplicitOf, type FieldArgs, type ModelDef, ModelDefType, Optional, type RecordArgs, type RecordBuilder, type RecordDef, type RecordFields, type Ref, type ResolvedFieldArg, type ResolvedFieldArgExplicit, type ResolvedFields, type ResolvedUnionVariants, type ReturnedSchema, type Schema, type SchemaBuilder, String, type Type, TypeKind, type UnionArgs, type UnionBuilder, type UnionDef, type UnionVariantArg, type UnionVariantArgExplicit, type UnionVariantArgs, type UnionVariants, Unknown, createRef, defineMigration, defineRecord, defineUnion, isRecordDef, isUnionDef, modelToRef, resolveUnionVariantArg };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// src/defs.ts
|
|
2
|
+
var ModelDefType = {
|
|
3
|
+
RECORD: "record",
|
|
4
|
+
UNION: "union"
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/primitives.ts
|
|
8
|
+
var TypeKind = {
|
|
9
|
+
ARRAY: "array",
|
|
10
|
+
DOUBLE: "double",
|
|
11
|
+
OPTIONAL: "optional",
|
|
12
|
+
REF: "ref",
|
|
13
|
+
STRING: "string",
|
|
14
|
+
UNKNOWN: "unknown"
|
|
15
|
+
};
|
|
16
|
+
var String = {
|
|
17
|
+
type: TypeKind.STRING
|
|
18
|
+
};
|
|
19
|
+
var Double = {
|
|
20
|
+
type: TypeKind.DOUBLE
|
|
21
|
+
};
|
|
22
|
+
var Unknown = {
|
|
23
|
+
type: TypeKind.UNKNOWN
|
|
24
|
+
};
|
|
25
|
+
var Array = (item) => ({
|
|
26
|
+
type: TypeKind.ARRAY,
|
|
27
|
+
items: item
|
|
28
|
+
});
|
|
29
|
+
var Optional = (item) => ({
|
|
30
|
+
type: TypeKind.OPTIONAL,
|
|
31
|
+
item
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// src/utils.ts
|
|
35
|
+
function modelToRef(model) {
|
|
36
|
+
return createRef(model.name, model.type);
|
|
37
|
+
}
|
|
38
|
+
function createRef(name, refType) {
|
|
39
|
+
return {
|
|
40
|
+
type: TypeKind.REF,
|
|
41
|
+
name,
|
|
42
|
+
refType
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function isRecordDef(value) {
|
|
46
|
+
return value != null && typeof value === "object" && "type" in value && value.type === ModelDefType.RECORD && "fields" in value;
|
|
47
|
+
}
|
|
48
|
+
function isUnionDef(value) {
|
|
49
|
+
return value != null && typeof value === "object" && "type" in value && value.type === ModelDefType.UNION && "variants" in value;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/defineUnion.ts
|
|
53
|
+
function defineUnion(name, union) {
|
|
54
|
+
const entries = Object.entries(union.variants).map(([key, value]) => [key, resolveUnionVariantArg(value)]);
|
|
55
|
+
const variants = Object.fromEntries(entries);
|
|
56
|
+
return {
|
|
57
|
+
type: ModelDefType.UNION,
|
|
58
|
+
discriminant: "type",
|
|
59
|
+
name,
|
|
60
|
+
docs: union.docs,
|
|
61
|
+
variants
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function resolveUnionVariantArg(arg) {
|
|
65
|
+
const resolved = typeof arg === "function" ? arg() : arg;
|
|
66
|
+
return resolved.type === TypeKind.REF ? resolved : modelToRef(resolved);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/defineMigration.ts
|
|
70
|
+
var UnionBuilderImpl = class _UnionBuilderImpl {
|
|
71
|
+
name;
|
|
72
|
+
docs;
|
|
73
|
+
variants;
|
|
74
|
+
constructor({
|
|
75
|
+
name,
|
|
76
|
+
docs,
|
|
77
|
+
variants
|
|
78
|
+
}) {
|
|
79
|
+
this.name = name;
|
|
80
|
+
this.docs = docs;
|
|
81
|
+
this.variants = {
|
|
82
|
+
...variants
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
addVariant(variantName, modelDefOrRef) {
|
|
86
|
+
const ref = resolveUnionVariantArg(modelDefOrRef);
|
|
87
|
+
const newVariants = {
|
|
88
|
+
...this.variants,
|
|
89
|
+
[variantName]: ref
|
|
90
|
+
};
|
|
91
|
+
return new _UnionBuilderImpl({
|
|
92
|
+
type: ModelDefType.UNION,
|
|
93
|
+
name: this.name,
|
|
94
|
+
variants: newVariants,
|
|
95
|
+
discriminant: "type"
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
build() {
|
|
99
|
+
return {
|
|
100
|
+
type: ModelDefType.UNION,
|
|
101
|
+
variants: this.variants,
|
|
102
|
+
discriminant: "type",
|
|
103
|
+
name: this.name
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var RecordBuilderImpl = class _RecordBuilderImpl {
|
|
108
|
+
name;
|
|
109
|
+
fields;
|
|
110
|
+
constructor(initialRecordDef) {
|
|
111
|
+
this.name = initialRecordDef.name;
|
|
112
|
+
this.fields = {
|
|
113
|
+
...initialRecordDef.fields
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
// TODO: resolve field value from arg instead
|
|
117
|
+
addField(name, value) {
|
|
118
|
+
return new _RecordBuilderImpl({
|
|
119
|
+
type: ModelDefType.RECORD,
|
|
120
|
+
name: this.name,
|
|
121
|
+
fields: {
|
|
122
|
+
...this.fields,
|
|
123
|
+
[name]: value
|
|
124
|
+
},
|
|
125
|
+
docs: ""
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
build() {
|
|
129
|
+
return {
|
|
130
|
+
type: ModelDefType.RECORD,
|
|
131
|
+
name: this.name,
|
|
132
|
+
fields: this.fields,
|
|
133
|
+
docs: ""
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
function defineMigration(previous, migration) {
|
|
138
|
+
const builders = {};
|
|
139
|
+
for (const key in previous) {
|
|
140
|
+
const v = previous[key];
|
|
141
|
+
if (isRecordDef(v)) {
|
|
142
|
+
const recordBuilder = new RecordBuilderImpl(v);
|
|
143
|
+
builders[key] = recordBuilder;
|
|
144
|
+
} else if (isUnionDef(v)) {
|
|
145
|
+
const unionBuilder = new UnionBuilderImpl(v);
|
|
146
|
+
builders[key] = unionBuilder;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
...previous,
|
|
151
|
+
...migration(builders)
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/defineRecord.ts
|
|
156
|
+
function resolveFieldArg(value) {
|
|
157
|
+
const resolved = typeof value === "function" ? value() : value;
|
|
158
|
+
if (isRecordDef(resolved) || isUnionDef(resolved)) {
|
|
159
|
+
return modelToRef(resolved);
|
|
160
|
+
}
|
|
161
|
+
return resolved;
|
|
162
|
+
}
|
|
163
|
+
function defineRecord(name, record) {
|
|
164
|
+
const entries = Object.entries(record.fields).map(([key, value]) => [key, resolveFieldArg(value)]);
|
|
165
|
+
const fields = Object.fromEntries(entries);
|
|
166
|
+
return {
|
|
167
|
+
type: ModelDefType.RECORD,
|
|
168
|
+
name,
|
|
169
|
+
docs: record.docs,
|
|
170
|
+
fields
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export { Array, Double, ModelDefType, Optional, String, TypeKind, Unknown, createRef, defineMigration, defineRecord, defineUnion, isRecordDef, isUnionDef, modelToRef, resolveUnionVariantArg };
|
|
175
|
+
//# sourceMappingURL=index.js.map
|
|
176
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/defs.ts","../../src/primitives.ts","../../src/utils.ts","../../src/defineUnion.ts","../../src/defineMigration.ts","../../src/defineRecord.ts"],"names":[],"mappings":";AAgBO,IAAM,YAAA,GAAe;AAAA,EAC1B,MAAA,EAAQ,QAAA;AAAA,EACR,KAAA,EAAO;AACT;;;ACHO,IAAM,QAAA,GAAW;AAAA,EACtB,KAAA,EAAO,OAAA;AAAA,EACP,MAAA,EAAQ,QAAA;AAAA,EACR,QAAA,EAAU,UAAA;AAAA,EACV,GAAA,EAAK,KAAA;AAAA,EACL,MAAA,EAAQ,QAAA;AAAA,EACR,OAAA,EAAS;AACX;AAMO,IAAM,MAAA,GAAS;AAAA,EACpB,MAAM,QAAA,CAAS;AACjB;AACO,IAAM,MAAA,GAAS;AAAA,EACpB,MAAM,QAAA,CAAS;AACjB;AACO,IAAM,OAAA,GAAU;AAAA,EACrB,MAAM,QAAA,CAAS;AACjB;AACO,IAAM,QAAQ,CAAA,IAAA,MAAS;AAAA,EAC5B,MAAM,QAAA,CAAS,KAAA;AAAA,EACf,KAAA,EAAO;AACT,CAAA;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AU,QAAQ;AAAA,GACvB;AACF;;;ACpGA,SAAS,gBAAgB,KAAA,EAAO;AAE9B,EAAA,MAAM,QAAA,GAAW,OAAO,KAAA,KAAU,UAAA,GAAa,OAAM,GAAI,KAAA;AACzD,EAAA,IAAI,WAAA,CAAY,QAAQ,CAAA,IAAK,UAAA,CAAW,QAAQ,CAAA,EAAG;AACjD,IAAA,OAAO,WAAW,QAAQ,CAAA;AAAA,EAC5B;AAGA,EAAA,OAAO,QAAA;AACT;AACO,SAAS,YAAA,CAAa,MAAM,MAAA,EAAQ;AACzC,EAAA,MAAM,UAAU,MAAA,CAAO,OAAA,CAAQ,MAAA,CAAO,MAAM,EAAE,GAAA,CAAI,CAAC,CAAC,GAAA,EAAK,KAAK,CAAA,KAAM,CAAC,KAAK,eAAA,CAAgB,KAAK,CAAC,CAAC,CAAA;AACjG,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,WAAA,CAAY,OAAO,CAAA;AACzC,EAAA,OAAO;AAAA,IACL,MAAM,YAAA,CAAa,MAAA;AAAA,IACnB,IAAA;AAAA,IACA,MAAM,MAAA,CAAO,IAAA;AAAA,IACb;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const ModelDefType = {\n RECORD: \"record\",\n UNION: \"union\"\n};","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const TypeKind = {\n ARRAY: \"array\",\n DOUBLE: \"double\",\n OPTIONAL: \"optional\",\n REF: \"ref\",\n STRING: \"string\",\n UNKNOWN: \"unknown\"\n};\n\n// Forward declaration to avoid circular reference\n\n// A reference to a record or a union type\n\nexport const String = {\n type: TypeKind.STRING\n};\nexport const Double = {\n type: TypeKind.DOUBLE\n};\nexport const Unknown = {\n type: TypeKind.UNKNOWN\n};\nexport const Array = item => ({\n type: TypeKind.ARRAY,\n items: item\n});\nexport const Optional = item => ({\n type: TypeKind.OPTIONAL,\n item\n});","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ModelDefType } from \"./defs.js\";\nimport { TypeKind } from \"./primitives.js\";\n\n/**\n * Helper function to safely transform a record definition to a reference.\n * This function helps TypeScript track type transformations better.\n */\nexport function modelToRef(model) {\n return createRef(model.name, model.type);\n}\n\n/**\n * Helper function to create a reference with proper typing.\n * This avoids type assertions in multiple places.\n */\nexport function createRef(name, refType) {\n return {\n type: TypeKind.REF,\n name,\n refType\n };\n}\n\n/**\n * Type guard to check if a value is a RecordDef\n */\nexport function isRecordDef(value) {\n return value != null && typeof value === \"object\" && \"type\" in value && value.type === ModelDefType.RECORD && \"fields\" in value;\n}\n\n/**\n * Type guard to check if a value is a UnionDef\n */\nexport function isUnionDef(value) {\n return value != null && typeof value === \"object\" && \"type\" in value && value.type === ModelDefType.UNION && \"variants\" in value;\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ModelDefType } from \"./defs.js\";\nimport { TypeKind } from \"./primitives.js\";\nimport { modelToRef } from \"./utils.js\";\nexport function defineUnion(name, union) {\n const entries = Object.entries(union.variants).map(([key, value]) => [key, resolveUnionVariantArg(value)]);\n const variants = Object.fromEntries(entries);\n return {\n type: ModelDefType.UNION,\n discriminant: \"type\",\n name: name,\n docs: union.docs,\n variants\n };\n}\nexport function resolveUnionVariantArg(arg) {\n const resolved = typeof arg === \"function\" ? arg() : arg;\n return resolved.type === TypeKind.REF ? resolved : modelToRef(resolved);\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { resolveUnionVariantArg } from \"./defineUnion.js\";\nimport { ModelDefType } from \"./defs.js\";\nimport { isRecordDef, isUnionDef } from \"./utils.js\";\nclass UnionBuilderImpl {\n name;\n docs;\n variants;\n constructor({\n name,\n docs,\n variants\n }) {\n this.name = name;\n this.docs = docs;\n this.variants = {\n ...variants\n };\n }\n addVariant(variantName, modelDefOrRef) {\n const ref = resolveUnionVariantArg(modelDefOrRef);\n const newVariants = {\n ...this.variants,\n [variantName]: ref\n };\n return new UnionBuilderImpl({\n type: ModelDefType.UNION,\n name: this.name,\n variants: newVariants,\n discriminant: \"type\"\n });\n }\n build() {\n return {\n type: ModelDefType.UNION,\n variants: this.variants,\n discriminant: \"type\",\n name: this.name\n };\n }\n}\nclass RecordBuilderImpl {\n name;\n fields;\n constructor(initialRecordDef) {\n this.name = initialRecordDef.name;\n this.fields = {\n ...initialRecordDef.fields\n };\n }\n\n // TODO: resolve field value from arg instead\n addField(name, value) {\n return new RecordBuilderImpl({\n type: ModelDefType.RECORD,\n name: this.name,\n fields: {\n ...this.fields,\n [name]: value\n },\n docs: \"\"\n });\n }\n build() {\n return {\n type: ModelDefType.RECORD,\n name: this.name,\n fields: this.fields,\n docs: \"\"\n };\n }\n}\nexport function defineMigration(previous, migration) {\n /**\n * Create a map of builders for the schema.\n *\n * Note about type assertions:\n * We use a type assertion here (SchemaBuilder<T>) because TypeScript cannot\n * track the relationship between the keys in the original schema and the\n * corresponding builder types. This is a fundamental limitation of TypeScript's\n * type system when dealing with dynamically constructed objects.\n *\n * The assertion is safe because:\n * 1. We're only adding keys that exist in the original schema\n * 2. For each key, we're creating a builder of the correct type\n * 3. The resulting object exactly matches the SchemaBuilder<T> type\n */\n const builders = {};\n for (const key in previous) {\n const v = previous[key];\n\n // Use our type guards for safer type narrowing\n if (isRecordDef(v)) {\n // This assertion is necessary because TypeScript can't track the field types\n // through the dynamic property access and object construction\n const recordBuilder = new RecordBuilderImpl(v);\n builders[key] = recordBuilder;\n } else if (isUnionDef(v)) {\n // Similar assertion needed for union builders\n const unionBuilder = new UnionBuilderImpl(v);\n builders[key] = unionBuilder;\n }\n }\n return {\n ...previous,\n ...migration(builders)\n };\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ModelDefType } from \"./defs.js\";\nimport { isRecordDef, isUnionDef, modelToRef } from \"./utils.js\";\n/**\n * Helper function to resolve a field value, handling functions and transforming\n * types as needed.\n */\nfunction resolveFieldArg(value) {\n // Handle function values\n const resolved = typeof value === \"function\" ? value() : value;\n if (isRecordDef(resolved) || isUnionDef(resolved)) {\n return modelToRef(resolved);\n }\n\n // For primitive types and other Types\n return resolved;\n}\nexport function defineRecord(name, record) {\n const entries = Object.entries(record.fields).map(([key, value]) => [key, resolveFieldArg(value)]);\n const fields = Object.fromEntries(entries);\n return {\n type: ModelDefType.RECORD,\n name: name,\n docs: record.docs,\n fields\n };\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"","names":[],"sources":["../../../src/__tests__/defineMigration.test.ts"],"version":3,"file":"defineMigration.test.d.ts"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"","names":[],"sources":["../../../src/__tests__/defineRecord.test.ts"],"version":3,"file":"defineRecord.test.d.ts"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"","names":[],"sources":["../../../src/__tests__/defineUnion.test.ts"],"version":3,"file":"defineUnion.test.d.ts"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"","names":[],"sources":["../../../src/__tests__/integration.test.ts"],"version":3,"file":"integration.test.d.ts"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"","names":[],"sources":["../../../src/__tests__/primitives.test.ts"],"version":3,"file":"primitives.test.d.ts"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if two types are exactly equal
|
|
3
|
+
*/
|
|
4
|
+
export type Equals<
|
|
5
|
+
X,
|
|
6
|
+
Y
|
|
7
|
+
> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
|
|
8
|
+
/**
|
|
9
|
+
* Asserts that two types are exactly equal. Causes a compile error if not.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // This will compile only if PersonRecord.fields.name is exactly String
|
|
13
|
+
* assertTypeEquals<typeof PersonRecord.fields.name, String>();
|
|
14
|
+
*/
|
|
15
|
+
export declare function assertTypeEquals<
|
|
16
|
+
T,
|
|
17
|
+
U
|
|
18
|
+
>(_witness?: Equals<T, U> extends true ? unknown : never): void;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if T extends U
|
|
21
|
+
*/
|
|
22
|
+
export type Extends<
|
|
23
|
+
T,
|
|
24
|
+
U
|
|
25
|
+
> = T extends U ? true : false;
|
|
26
|
+
/**
|
|
27
|
+
* Asserts that T extends U. Causes a compile error if not.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // This will compile only if T extends Record<string, unknown>
|
|
31
|
+
* assertTypeExtends<T, Record<string, unknown>>();
|
|
32
|
+
*/
|
|
33
|
+
export declare function assertTypeExtends<
|
|
34
|
+
T,
|
|
35
|
+
U
|
|
36
|
+
>(_witness?: Extends<T, U> extends true ? unknown : never): void;
|
|
37
|
+
/**
|
|
38
|
+
* Asserts that a type has the specified keys. Causes a compile error if not.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* // This will compile only if PersonRecord.fields has exactly keys 'name' and 'age'
|
|
42
|
+
* assertExactKeys<typeof PersonRecord.fields, 'name' | 'age'>();
|
|
43
|
+
*/
|
|
44
|
+
export declare function assertExactKeys<
|
|
45
|
+
T,
|
|
46
|
+
K extends string
|
|
47
|
+
>(_witness?: Equals<keyof T, K> extends true ? unknown : never): void;
|
|
48
|
+
/**
|
|
49
|
+
* Asserts that a type has at least the specified keys. Causes a compile error if not.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // This will compile only if PersonRecord.fields has at least keys 'name' and 'age'
|
|
53
|
+
* assertHasKeys<typeof PersonRecord.fields, 'name' | 'age'>();
|
|
54
|
+
*/
|
|
55
|
+
export declare function assertHasKeys<
|
|
56
|
+
T,
|
|
57
|
+
K extends string
|
|
58
|
+
>(_witness?: K extends keyof T ? unknown : never): void;
|
|
59
|
+
/**
|
|
60
|
+
* Assert that a value is never. Useful for exhaustiveness checks.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* function handleShape(shape: Shape) {
|
|
64
|
+
* if (shape.type === 'circle') {
|
|
65
|
+
* // handle circle
|
|
66
|
+
* } else if (shape.type === 'rectangle') {
|
|
67
|
+
* // handle rectangle
|
|
68
|
+
* } else {
|
|
69
|
+
* // This will cause a compile error if we forget to handle a shape type
|
|
70
|
+
* assertNever(shape);
|
|
71
|
+
* }
|
|
72
|
+
* }
|
|
73
|
+
*/
|
|
74
|
+
export declare function assertNever(_value: never): never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAoBA,YAAY;CAAO;CAAG;MAAO,QAAQ,UAAU,IAAI,IAAI,aAAa,QAAQ,UAAU,IAAI,IAAI,KAC1F,OACA;;;;;;;;AASJ,OAAO,iBAAS;CAAiB;CAAG;EAClC,WAAW,OAAO,GAAG,WAAW;;;;AAMlC,YAAY;CAAQ;CAAG;IAAK,UAAU,IAAI,OAAO;;;;;;;;AASjD,OAAO,iBAAS;CAAkB;CAAG;EACnC,WAAW,QAAQ,GAAG,WAAW;;;;;;;;AAUnC,OAAO,iBAAS;CAAgB;CAAG;EACjC,WAAW,aAAa,GAAG,WAAW;;;;;;;;AAWxC,OAAO,iBAAS;CAAc;CAAG;EAC/B,WAAW,gBAAgB;;;;;;;;;;;;;;;;AAkB7B,OAAO,iBAAS,YAAY","names":[],"sources":["../../../src/__tests__/testTypeUtils.ts"],"version":3,"file":"testTypeUtils.d.ts"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { UnionVariantArg } from "./defineUnion.js";
|
|
2
|
+
import type { RecordDef, UnionDef, UnionVariants } from "./defs.js";
|
|
3
|
+
import type { Ref, Type } from "./primitives.js";
|
|
4
|
+
export type ReturnedSchema = Record<string, RecordDef | UnionDef>;
|
|
5
|
+
export type Schema<T extends ReturnedSchema> = T;
|
|
6
|
+
export type SchemaBuilder<T extends ReturnedSchema> = { [k in keyof T] : T[k] extends UnionDef<infer R> ? UnionBuilder<R> : T[k] extends RecordDef<infer R> ? RecordBuilder<R> : never };
|
|
7
|
+
export interface RecordBuilder<T extends Record<string, Type>> {
|
|
8
|
+
addField<
|
|
9
|
+
const K extends string,
|
|
10
|
+
V extends Type
|
|
11
|
+
>(name: K, type: V): RecordBuilder<T & { [k in K] : V }>;
|
|
12
|
+
build(): RecordDef<T>;
|
|
13
|
+
}
|
|
14
|
+
export interface UnionBuilder<S extends UnionVariants> {
|
|
15
|
+
addVariant<const K extends string>(name: K, modelDefOrRef: UnionVariantArg): UnionBuilder<S & { [k in K] : Ref }>;
|
|
16
|
+
build(): UnionDef<S>;
|
|
17
|
+
}
|
|
18
|
+
export declare function defineMigration<
|
|
19
|
+
const T extends ReturnedSchema,
|
|
20
|
+
const S extends ReturnedSchema
|
|
21
|
+
>(previous: Schema<T>, migration: (schema: SchemaBuilder<T>) => S): Schema<T & S>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,uBAAuB;AAErC,cAAc,WAAyB,UAAU,qBAAqB;AAEtE,cAAc,KAAK,YAAY;AAG/B,YAAY,iBAAiB,eAAe,YAAY;AAExD,YAAY,OAAO,UAAU,kBAAkB;AAE/C,YAAY,cAAc,UAAU,qBACjC,WAAW,KAAI,EAAE,WAAW,eAAe,KAAK,aAAa,KAC1D,EAAE,WAAW,gBAAgB,KAAK,cAAc;AAItD,iBAAiB,cAAc,UAAU,eAAe,OAAO;CAE7D;QAAe;EAAkB,UAAU;GACzC,MAAM,GACN,MAAM,IACL,cAAc,OAAO,KAAK,KAAI;CACjC,SAAS,UAAU;;AAGrB,iBAAiB,aAAa,UAAU,eAAe;CAErD,iBAAiB,kBACf,MAAM,GACN,eAAe,kBACd,aAAa,OAAO,KAAK,KAAI;CAChC,SAAS,SAAS;;AAmEpB,OAAO,iBAAS;OACR,UAAU;OACV,UAAU;EAEhB,UAAU,OAAO,IACjB,YAAY,QAAQ,cAAc,OAAO,IACxC,OAAO,IAAI","names":[],"sources":["../../src/defineMigration.ts"],"version":3,"file":"defineMigration.d.ts"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RecordDef, UnionDef } from "./defs.js";
|
|
2
|
+
import type { Ref, Type } from "./primitives.js";
|
|
3
|
+
export type FieldArgExplicit = Type | RecordDef | UnionDef;
|
|
4
|
+
export type FieldArg = FieldArgExplicit | (() => FieldArgExplicit);
|
|
5
|
+
export type FieldArgExplicitOf<T extends FieldArg> = T extends () => infer R ? R : T;
|
|
6
|
+
export type FieldArgs = Record<string, FieldArg>;
|
|
7
|
+
export type ResolvedFieldArgExplicit<T extends FieldArgExplicit> = T extends RecordDef | UnionDef ? Ref : T;
|
|
8
|
+
export type ResolvedFieldArg<T extends FieldArg> = ResolvedFieldArgExplicit<FieldArgExplicitOf<T>>;
|
|
9
|
+
export type ResolvedFields<T extends FieldArgs> = { readonly [K in keyof T] : ResolvedFieldArg<T[K]> };
|
|
10
|
+
export type RecordArgs<T extends FieldArgs> = {
|
|
11
|
+
readonly docs: string;
|
|
12
|
+
readonly fields: T;
|
|
13
|
+
};
|
|
14
|
+
export declare function defineRecord<const T extends FieldArgs>(name: string, record: RecordArgs<T>): RecordDef<ResolvedFields<T>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,WAAW,gBAAgB;AAEzC,cAAc,KAAK,YAAY;AAG/B,YAAY,mBACR,OACA,YACA;AAEJ,YAAY,WACR,0BACO;AAEX,YAAY,mBAAmB,UAAU,YAAY,sBAAsB,IAAI,IAC3E;AAEJ,YAAY,YAAY,eAAe;AAEvC,YAAY,yBAAyB,UAAU,oBAAoB,UAAU,YAAY,WACrF,MACA;AAEJ,YAAY,iBAAiB,UAAU,YAAY,yBAAyB,mBAAmB;AAE/F,YAAY,eAAe,UAAU,yBACzB,WAAW,KAAI,iBAAiB,EAAE;AAG9C,YAAY,WAAW,UAAU,aAAa;UACnC;UACA,QAAQ;;AAmBnB,OAAO,iBAAS,mBAAmB,UAAU,WAC3C,cACA,QAAQ,WAAW,KAClB,UAAU,eAAe","names":[],"sources":["../../src/defineRecord.ts"],"version":3,"file":"defineRecord.d.ts"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ModelDef, UnionDef } from "./defs.js";
|
|
2
|
+
import type { Ref } from "./primitives.js";
|
|
3
|
+
export type UnionVariantArgExplicit = Ref | ModelDef;
|
|
4
|
+
export type UnionVariantArg = UnionVariantArgExplicit | (() => UnionVariantArgExplicit);
|
|
5
|
+
export type UnionVariantArgs = Record<string, UnionVariantArg>;
|
|
6
|
+
export type ResolvedUnionVariants<T extends UnionVariantArgs> = { readonly [K in keyof T] : Ref };
|
|
7
|
+
export type UnionArgs<T extends UnionVariantArgs> = {
|
|
8
|
+
readonly docs: string;
|
|
9
|
+
readonly variants: T;
|
|
10
|
+
};
|
|
11
|
+
export declare function defineUnion<const TVariants extends UnionVariantArgs>(name: string, union: UnionArgs<TVariants>): UnionDef<ResolvedUnionVariants<TVariants>>;
|
|
12
|
+
export declare function resolveUnionVariantArg(arg: UnionVariantArg): Ref;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,UAAU,gBAAgB;AAExC,cAAc,WAAW;AAIzB,YAAY,0BAA0B,MAAM;AAC5C,YAAY,kBAAkB,iCAAiC;AAC/D,YAAY,mBAAmB,eAAe;AAE9C,YAAY,sBAAsB,UAAU,gCAChC,WAAW,KAAI;AAG3B,YAAY,UAAU,UAAU,oBAAoB;UACzC;UACA,UAAU;;AAGrB,OAAO,iBAAS,kBAAkB,kBAAkB,kBAClD,cACA,OAAO,UAAU,aAChB,SAAS,sBAAsB;AAgBlC,OAAO,iBAAS,uBAAuB,KAAK,kBAAkB","names":[],"sources":["../../src/defineUnion.ts"],"version":3,"file":"defineUnion.d.ts"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Ref, Type } from "./primitives.js";
|
|
2
|
+
export declare const ModelDefType: {
|
|
3
|
+
readonly RECORD: "record";
|
|
4
|
+
readonly UNION: "union";
|
|
5
|
+
};
|
|
6
|
+
export type ModelDefType = typeof ModelDefType[keyof typeof ModelDefType];
|
|
7
|
+
interface ModelDefBase {
|
|
8
|
+
readonly type: ModelDefType;
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly docs?: string;
|
|
11
|
+
}
|
|
12
|
+
export type RecordFields = Record<string, Type>;
|
|
13
|
+
export type UnionVariants = Record<string, Ref>;
|
|
14
|
+
export interface UnionDef<TVariants extends UnionVariants = UnionVariants> extends ModelDefBase {
|
|
15
|
+
readonly type: typeof ModelDefType.UNION;
|
|
16
|
+
readonly variants: TVariants;
|
|
17
|
+
readonly discriminant: string;
|
|
18
|
+
}
|
|
19
|
+
export interface RecordDef<TFields extends RecordFields = RecordFields> extends ModelDefBase {
|
|
20
|
+
readonly type: typeof ModelDefType.RECORD;
|
|
21
|
+
readonly fields: TFields;
|
|
22
|
+
}
|
|
23
|
+
export type ModelDef = RecordDef | UnionDef;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,KAAK,YAAY;AAE/B,OAAO,cAAM;UACX,QAAQ;UACR,OAAO;;AAGT,YAAY,sBAAsB,0BAA0B;UAElD,aAAa;UACZ,MAAM;UACN;UACA;;AAGX,YAAY,eAAe,eAAe;AAC1C,YAAY,gBAAgB,eAAe;AAE3C,iBAAiB,SAAS,kBAAkB,gBAAgB,uBAAuB,aAAa;UACrF,aAAa,aAAa;UAC1B,UAAU;UACV;;AAGX,iBAAiB,UAAU,gBAAgB,eAAe,sBAAsB,aAAa;UAClF,aAAa,aAAa;UAC1B,QAAQ;;AAGnB,YAAY,WAAW,YAAY","names":[],"sources":["../../src/defs.ts"],"version":3,"file":"defs.d.ts"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","names":[],"sources":["../../src/index.ts"],"version":3,"file":"index.d.ts"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare const TypeKind: {
|
|
2
|
+
readonly ARRAY: "array";
|
|
3
|
+
readonly DOUBLE: "double";
|
|
4
|
+
readonly OPTIONAL: "optional";
|
|
5
|
+
readonly REF: "ref";
|
|
6
|
+
readonly STRING: "string";
|
|
7
|
+
readonly UNKNOWN: "unknown";
|
|
8
|
+
};
|
|
9
|
+
export type TypeKind = typeof TypeKind[keyof typeof TypeKind];
|
|
10
|
+
export type String = {
|
|
11
|
+
readonly type: typeof TypeKind.STRING;
|
|
12
|
+
};
|
|
13
|
+
export type Double = {
|
|
14
|
+
readonly type: typeof TypeKind.DOUBLE;
|
|
15
|
+
};
|
|
16
|
+
interface TypeBase {
|
|
17
|
+
readonly type: TypeKind;
|
|
18
|
+
}
|
|
19
|
+
export type Array<T extends TypeBase = TypeBase> = {
|
|
20
|
+
readonly type: typeof TypeKind.ARRAY;
|
|
21
|
+
readonly items: T;
|
|
22
|
+
};
|
|
23
|
+
export type Ref = {
|
|
24
|
+
readonly type: typeof TypeKind.REF;
|
|
25
|
+
readonly refType: "record" | "union";
|
|
26
|
+
readonly name: string;
|
|
27
|
+
};
|
|
28
|
+
export type Optional<T extends TypeBase = TypeBase> = {
|
|
29
|
+
readonly type: typeof TypeKind.OPTIONAL;
|
|
30
|
+
readonly item: T;
|
|
31
|
+
};
|
|
32
|
+
export type Unknown = {
|
|
33
|
+
readonly type: typeof TypeKind.UNKNOWN;
|
|
34
|
+
};
|
|
35
|
+
export type Type = String | Double | Array | Ref | Optional | Unknown;
|
|
36
|
+
export declare const String: String;
|
|
37
|
+
export declare const Double: Double;
|
|
38
|
+
export declare const Unknown: Unknown;
|
|
39
|
+
export declare const Array: <T extends TypeBase>(item: T) => Array<T>;
|
|
40
|
+
export declare const Optional: <T extends TypeBase>(item: T) => Optional<T>;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,OAAO,cAAM;UACX,OAAO;UACP,QAAQ;UACR,UAAU;UACV,KAAK;UACL,QAAQ;UACR,SAAS;;AAGX,YAAY,kBAAkB,sBAAsB;AAEpD,YAAY,SAAS;UACV,aAAa,SAAS;;AAGjC,YAAY,SAAS;UACV,aAAa,SAAS;;UAIvB,SAAS;UACR,MAAM;;AAGjB,YAAY,MAAM,UAAU,WAAW,YAAY;UACxC,aAAa,SAAS;UACtB,OAAO;;AAIlB,YAAY,MAAM;UACP,aAAa,SAAS;UACtB,SAAS,WAAW;UACpB;;AAGX,YAAY,SAAS,UAAU,WAAW,YAAY;UAC3C,aAAa,SAAS;UACtB,MAAM;;AAGjB,YAAY,UAAU;UACX,aAAa,SAAS;;AAGjC,YAAY,OACR,SACA,SACA,QACA,MACA,WACA;AAEJ,OAAO,cAAMA,QAAQ;AACrB,OAAO,cAAMC,QAAQ;AACrB,OAAO,cAAMC,SAAS;AACtB,OAAO,cAAM,QAAS,UAAU,UAAU,MAAM,MAAI,MAAM;AAI1D,OAAO,cAAM,WAAY,UAAU,UAAU,MAAM,MAAI,SAAS","names":["String: String","Double: Double","Unknown: Unknown"],"sources":["../../src/primitives.ts"],"version":3,"file":"primitives.d.ts"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ModelDef, RecordDef, UnionDef } from "./defs.js";
|
|
2
|
+
import type { Ref } from "./primitives.js";
|
|
3
|
+
/**
|
|
4
|
+
* Helper function to safely transform a record definition to a reference.
|
|
5
|
+
* This function helps TypeScript track type transformations better.
|
|
6
|
+
*/
|
|
7
|
+
export declare function modelToRef(model: ModelDef): Ref;
|
|
8
|
+
/**
|
|
9
|
+
* Helper function to create a reference with proper typing.
|
|
10
|
+
* This avoids type assertions in multiple places.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createRef(name: string, refType: "record" | "union"): Ref;
|
|
13
|
+
/**
|
|
14
|
+
* Type guard to check if a value is a RecordDef
|
|
15
|
+
*/
|
|
16
|
+
export declare function isRecordDef(value: unknown): value is RecordDef;
|
|
17
|
+
/**
|
|
18
|
+
* Type guard to check if a value is a UnionDef
|
|
19
|
+
*/
|
|
20
|
+
export declare function isUnionDef(value: unknown): value is UnionDef;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,UAAU,WAAW,gBAAgB;AAEnD,cAAc,WAAW;;;;;AAOzB,OAAO,iBAAS,WAAW,OAAO,WAAW;;;;;AAQ7C,OAAO,iBAAS,UAAU,cAAc,SAAS,WAAW,UAAU;;;;AAWtE,OAAO,iBAAS,YAAY,iBAAiB,SAAS;;;;AAWtD,OAAO,iBAAS,WAAW,iBAAiB,SAAS","names":[],"sources":["../../src/utils.ts"],"version":3,"file":"utils.d.ts"}
|