@instantdb/core
Advanced tools
Comparing version 0.17.3 to 0.17.4
@@ -17,3 +17,2 @@ import type { RoomSchemaShape } from "./presence"; | ||
} | ||
type ExtractValueType<T> = T extends DataAttrDef<infer ValueType, infer isRequired> ? isRequired extends true ? ValueType : ValueType | undefined : never; | ||
export declare class LinkAttrDef<Cardinality extends CardinalityKind, EntityName extends string> { | ||
@@ -35,5 +34,3 @@ cardinality: Cardinality; | ||
constructor(attrs: Attrs, links: Links); | ||
asType<_AsType extends Partial<{ | ||
[AttrName in keyof Attrs]: ExtractValueType<Attrs[AttrName]>; | ||
}>>(): EntityDef<Attrs, Links, _AsType>; | ||
asType<_AsType extends Partial<MappedAttrs<Attrs>>>(): EntityDef<Attrs, Links, _AsType>; | ||
} | ||
@@ -74,5 +71,19 @@ export type EntitiesDef = Record<string, EntityDef<any, any, any>>; | ||
}; | ||
export type ResolveEntityAttrs<EDef extends EntityDef<any, any, any>, ResolvedAttrs = { | ||
[AttrName in keyof EDef["attrs"]]: ExtractValueType<EDef["attrs"][AttrName]>; | ||
}> = EDef extends EntityDef<any, any, infer AsType> ? AsType extends void ? ResolvedAttrs : Omit<ResolvedAttrs, keyof AsType> & AsType : ResolvedAttrs; | ||
type RequiredKeys<Attrs extends AttrsDefs> = { | ||
[K in keyof Attrs]: Attrs[K] extends DataAttrDef<any, infer R> ? R extends true ? K : never : never; | ||
}[keyof Attrs]; | ||
type OptionalKeys<Attrs extends AttrsDefs> = { | ||
[K in keyof Attrs]: Attrs[K] extends DataAttrDef<any, infer R> ? R extends false ? K : never : never; | ||
}[keyof Attrs]; | ||
/** | ||
* MappedAttrs: | ||
* - Required keys => `key: ValueType` | ||
* - Optional keys => `key?: ValueType` | ||
*/ | ||
type MappedAttrs<Attrs extends AttrsDefs> = { | ||
[K in RequiredKeys<Attrs>]: Attrs[K] extends DataAttrDef<infer V, any> ? V : never; | ||
} & { | ||
[K in OptionalKeys<Attrs>]?: Attrs[K] extends DataAttrDef<infer V, any> ? V : never; | ||
}; | ||
export type ResolveEntityAttrs<EDef extends EntityDef<any, any, any>, ResolvedAttrs = MappedAttrs<EDef["attrs"]>> = EDef extends EntityDef<any, any, infer AsType> ? AsType extends void ? ResolvedAttrs : Omit<ResolvedAttrs, keyof AsType> & AsType : ResolvedAttrs; | ||
export type ResolveAttrs<Entities extends EntitiesDef, EntityName extends keyof Entities> = ResolveEntityAttrs<Entities[EntityName]>; | ||
@@ -79,0 +90,0 @@ export type RoomsFromDef<RDef extends RoomsDef> = { |
export default version; | ||
declare const version: "v0.17.3"; | ||
declare const version: "v0.17.4"; | ||
//# sourceMappingURL=version.d.ts.map |
// Autogenerated by publish_packages.clj | ||
const version = "v0.17.3"; | ||
const version = "v0.17.4"; | ||
export default version; | ||
//# sourceMappingURL=version.js.map |
@@ -17,3 +17,2 @@ import type { RoomSchemaShape } from "./presence"; | ||
} | ||
type ExtractValueType<T> = T extends DataAttrDef<infer ValueType, infer isRequired> ? isRequired extends true ? ValueType : ValueType | undefined : never; | ||
export declare class LinkAttrDef<Cardinality extends CardinalityKind, EntityName extends string> { | ||
@@ -35,5 +34,3 @@ cardinality: Cardinality; | ||
constructor(attrs: Attrs, links: Links); | ||
asType<_AsType extends Partial<{ | ||
[AttrName in keyof Attrs]: ExtractValueType<Attrs[AttrName]>; | ||
}>>(): EntityDef<Attrs, Links, _AsType>; | ||
asType<_AsType extends Partial<MappedAttrs<Attrs>>>(): EntityDef<Attrs, Links, _AsType>; | ||
} | ||
@@ -74,5 +71,19 @@ export type EntitiesDef = Record<string, EntityDef<any, any, any>>; | ||
}; | ||
export type ResolveEntityAttrs<EDef extends EntityDef<any, any, any>, ResolvedAttrs = { | ||
[AttrName in keyof EDef["attrs"]]: ExtractValueType<EDef["attrs"][AttrName]>; | ||
}> = EDef extends EntityDef<any, any, infer AsType> ? AsType extends void ? ResolvedAttrs : Omit<ResolvedAttrs, keyof AsType> & AsType : ResolvedAttrs; | ||
type RequiredKeys<Attrs extends AttrsDefs> = { | ||
[K in keyof Attrs]: Attrs[K] extends DataAttrDef<any, infer R> ? R extends true ? K : never : never; | ||
}[keyof Attrs]; | ||
type OptionalKeys<Attrs extends AttrsDefs> = { | ||
[K in keyof Attrs]: Attrs[K] extends DataAttrDef<any, infer R> ? R extends false ? K : never : never; | ||
}[keyof Attrs]; | ||
/** | ||
* MappedAttrs: | ||
* - Required keys => `key: ValueType` | ||
* - Optional keys => `key?: ValueType` | ||
*/ | ||
type MappedAttrs<Attrs extends AttrsDefs> = { | ||
[K in RequiredKeys<Attrs>]: Attrs[K] extends DataAttrDef<infer V, any> ? V : never; | ||
} & { | ||
[K in OptionalKeys<Attrs>]?: Attrs[K] extends DataAttrDef<infer V, any> ? V : never; | ||
}; | ||
export type ResolveEntityAttrs<EDef extends EntityDef<any, any, any>, ResolvedAttrs = MappedAttrs<EDef["attrs"]>> = EDef extends EntityDef<any, any, infer AsType> ? AsType extends void ? ResolvedAttrs : Omit<ResolvedAttrs, keyof AsType> & AsType : ResolvedAttrs; | ||
export type ResolveAttrs<Entities extends EntitiesDef, EntityName extends keyof Entities> = ResolveEntityAttrs<Entities[EntityName]>; | ||
@@ -79,0 +90,0 @@ export type RoomsFromDef<RDef extends RoomsDef> = { |
export default version; | ||
declare const version: "v0.17.3"; | ||
declare const version: "v0.17.4"; | ||
//# sourceMappingURL=version.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// Autogenerated by publish_packages.clj | ||
const version = "v0.17.3"; | ||
const version = "v0.17.4"; | ||
exports.default = version; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@instantdb/core", | ||
"version": "v0.17.3", | ||
"version": "v0.17.4", | ||
"description": "Instant's core local abstraction", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -48,9 +48,2 @@ import type { RoomSchemaShape } from "./presence"; | ||
type ExtractValueType<T> = | ||
T extends DataAttrDef<infer ValueType, infer isRequired> | ||
? isRequired extends true | ||
? ValueType | ||
: ValueType | undefined | ||
: never; | ||
export class LinkAttrDef< | ||
@@ -94,5 +87,3 @@ Cardinality extends CardinalityKind, | ||
asType< | ||
_AsType extends Partial<{ | ||
[AttrName in keyof Attrs]: ExtractValueType<Attrs[AttrName]>; | ||
}>, | ||
_AsType extends Partial<MappedAttrs<Attrs>>, | ||
>() { | ||
@@ -236,9 +227,32 @@ return new EntityDef<Attrs, Links, _AsType>(this.attrs, this.links); | ||
type RequiredKeys<Attrs extends AttrsDefs> = { | ||
[K in keyof Attrs]: Attrs[K] extends DataAttrDef<any, infer R> | ||
? R extends true | ||
? K | ||
: never | ||
: never; | ||
}[keyof Attrs]; | ||
type OptionalKeys<Attrs extends AttrsDefs> = { | ||
[K in keyof Attrs]: Attrs[K] extends DataAttrDef<any, infer R> | ||
? R extends false | ||
? K | ||
: never | ||
: never; | ||
}[keyof Attrs]; | ||
/** | ||
* MappedAttrs: | ||
* - Required keys => `key: ValueType` | ||
* - Optional keys => `key?: ValueType` | ||
*/ | ||
type MappedAttrs<Attrs extends AttrsDefs> = { | ||
[K in RequiredKeys<Attrs>]: Attrs[K] extends DataAttrDef<infer V, any> ? V : never; | ||
} & { | ||
[K in OptionalKeys<Attrs>]?: Attrs[K] extends DataAttrDef<infer V, any> ? V : never; | ||
}; | ||
export type ResolveEntityAttrs< | ||
EDef extends EntityDef<any, any, any>, | ||
ResolvedAttrs = { | ||
[AttrName in keyof EDef["attrs"]]: ExtractValueType< | ||
EDef["attrs"][AttrName] | ||
>; | ||
}, | ||
ResolvedAttrs = MappedAttrs<EDef["attrs"]> | ||
> = | ||
@@ -245,0 +259,0 @@ EDef extends EntityDef<any, any, infer AsType> |
// Autogenerated by publish_packages.clj | ||
const version = "v0.17.3"; | ||
const version = "v0.17.4"; | ||
export default version; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
2575170
45823