New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

convex-selections

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

convex-selections - npm Package Compare versions

Comparing version 0.0.29 to 0.1.0

types/convex.d.ts

64

bundle.d.ts

@@ -1,5 +0,19 @@

import { UnionToIntersection, Exact } from 'type-fest';
import { AnyDataModel } from 'convex/server';
import { UnionToIntersection, Exact, Simplify } from 'type-fest';
import { GenericId } from 'convex/values';
type Deprecated = `Deprecated: ${string}` | undefined;
type PickCurrent<$Document> = {
[$Key in keyof $Document as '__new__' extends keyof NonNullable<$Document[$Key]> ? never : '__deprecated__' extends keyof NonNullable<$Document[$Key]> ? never : $Key]: $Document[$Key];
} & {
[$Key in keyof $Document as '__deprecated__' extends keyof NonNullable<$Document[$Key]> ? $Key : never]?: undefined;
} & {
[$Key in keyof $Document as '__new__' extends keyof NonNullable<$Document[$Key]> ? $Key : never]-?: Exclude<$Document[$Key], undefined>;
};
type PickDeprecated<$Document> = {
[$Key in keyof $Document as '__new__' extends keyof NonNullable<$Document[$Key]> ? never : '__deprecated__' extends keyof NonNullable<$Document[$Key]> ? never : $Key]: $Document[$Key];
} & {
[$Key in keyof $Document as '__new__' extends keyof NonNullable<$Document[$Key]> ? $Key : never]?: undefined;
} & {
[$Key in keyof $Document as '__deprecated__' extends keyof NonNullable<$Document[$Key]> ? $Key : never]-?: Exclude<$Document[$Key], undefined>;
};

@@ -9,6 +23,6 @@ type Virtual<$TableName extends string> = `__VIRTUAL__:${$TableName}` | undefined | null;

type SelectInputFromDataModel<$DataModel, $TableName extends string, $WithCid extends boolean = false> = ($WithCid extends true ? {
type SelectInputFromDataModel<$DataModel extends AnyDataModel, $TableName extends string, $WithCid extends boolean = false> = ($WithCid extends true ? {
cid: true;
} : {}) & {
[K in keyof $DataModel[$TableName]['document'] as $DataModel[$TableName]['document'][K] extends Deprecated ? never : K]?: NonNullable<$DataModel[$TableName]['document'][K]> extends Array<infer $Item> ? NonNullable<$Item> extends GenericId<infer $SelectedTableName> ? $SelectedTableName extends $TableName ? true : {
[K in keyof $DataModel[$TableName]['document']]?: NonNullable<$DataModel[$TableName]['document'][K]> extends Array<infer $Item> ? NonNullable<$Item> extends GenericId<infer $SelectedTableName> ? $SelectedTableName extends $TableName ? true : {
select: SelectInputFromDataModel<$DataModel, $SelectedTableName, $WithCid>;

@@ -27,5 +41,3 @@ } : NonNullable<$Item> extends VirtualArray<infer $SelectedTableName> ? {

};
type SelectOutputFromDataModel<$DataModel, $TableName extends string, $Select extends Omit<SelectInputFromDataModel<$DataModel, $TableName>, 'id'>> = {
__tableName?: $TableName;
} & {
type SelectOutputValue<$DataModel extends AnyDataModel, $TableName extends string, $Select extends Omit<SelectInputFromDataModel<$DataModel, $TableName>, 'id'>> = {
[K in keyof $Select]: $Select[K] extends true ? K extends keyof $DataModel[$TableName]['document'] ? $DataModel[$TableName]['document'][K] : never : $Select[K] extends {

@@ -35,13 +47,13 @@ select: infer $NestedSelect;

};
type SelectOutputFromDataModel<$DataModel extends AnyDataModel, $TableName extends string, $Select extends Omit<SelectInputFromDataModel<$DataModel, $TableName>, 'id'>> = {
__tableName?: $TableName;
} & (PickCurrent<SelectOutputValue<$DataModel, $TableName, $Select>> | PickDeprecated<SelectOutputValue<$DataModel, $TableName, $Select>>);
interface SelectionDefinition<_$Select, _$SelectionMappings extends Record<`$${string}`, unknown>> extends Record<`$${string}`, unknown> {
}
type InferSelectionDefinition<$SelectionDefinitionGetter extends (...args: any) => any> = Awaited<ReturnType<$SelectionDefinitionGetter>>;
type ExpandMapping<$SelectionMappings, $Options> = {
[$OptionKey in keyof $Options]: $OptionKey extends keyof $SelectionMappings ? ExpandMapping<$SelectionMappings, $SelectionMappings[$OptionKey]> : Record<$OptionKey, $Options[$OptionKey]>;
}[keyof $Options];
type SelectionSelect<$Definition extends SelectionDefinition<any, any>, $Options> = $Definition extends SelectionDefinition<any, infer $SelectionMappings> ? UnionToIntersection<ExpandMapping<$SelectionMappings, $Options>> : never;
type WithOptions<$DataModel, $Definition extends SelectionDefinition<any, any>, $TableName extends string> = $Definition extends SelectionDefinition<any, infer $SelectionMappings> ? SelectInputFromDataModel<$DataModel, $TableName> & {
[Key in keyof $SelectionMappings]?: boolean;
} : never;
type WithOptions<$DataModel extends AnyDataModel, $Selections extends Record<string, unknown>, $TableName extends string> = SelectInputFromDataModel<$DataModel, $TableName> & {
[Key in keyof $Selections]?: boolean;
};
type SelectionSelect<$Selections extends Record<string, unknown>, $Options> = UnionToIntersection<ExpandMapping<$Selections, $Options>>;
type Selections<$SelectionMappingObject> = keyof {

@@ -58,6 +70,7 @@ [$K in keyof $SelectionMappingObject as $K extends `$${string}` ? $K : never]: true;

declare function expandSelections<$SelectionMapping extends Record<string, Record<string, unknown>>>(selectionMapping: $SelectionMapping): ExpandSelections<$SelectionMapping>;
declare function createSelectionFunction<$SelectionDefinition extends SelectionDefinition<any, any>>(selectionDefinition: $SelectionDefinition): <const $Selections extends Exact<($SelectionDefinition extends SelectionDefinition<infer Select, any> ? Select : never) & { [K in keyof ($SelectionDefinition extends SelectionDefinition<any, infer SelectionMappings extends Record<`$${string}`, unknown>> ? SelectionMappings : never)]?: boolean | undefined; }, $Selections>>(selections: $Selections) => UnionToIntersection<{ [$SelectionKey in keyof $Selections]: $SelectionKey extends `$${string}` ? ExpandSelections<$SelectionDefinition extends SelectionDefinition<any, infer SelectionMappings_1 extends Record<`$${string}`, unknown>> ? SelectionMappings_1 : never>[$SelectionKey] : Record<$SelectionKey, $Selections[$SelectionKey]>; }[keyof $Selections]>;
declare function unscopeSelections<Selections extends Record<string, () => any>>(selections: Selections): {
[SelectionIdentifier in keyof Selections as SelectionIdentifier extends `${string}_${infer UnscopedIdentifier}` ? UnscopedIdentifier : never]: ReturnType<Selections[SelectionIdentifier]>;
};
declare function createSelectionFunction<$DataModel extends AnyDataModel, $TableName extends string, $Selections extends Record<string, Record<string, unknown>>>(selections: $Selections): <const $Selection extends Exact<SelectInputFromDataModel<$DataModel, $TableName> & {
[K in keyof $Selections]?: boolean | undefined;
}, $Selection>>(selection: $Selection) => Simplify<UnionToIntersection<{
[$SelectionKey in keyof $Selection]: $SelectionKey extends `$${string}` ? ExpandSelections<$Selections>[$SelectionKey] : Record<$SelectionKey, $Selection[$SelectionKey]>;
}[keyof $Selection]>>;
declare function combineSelections<Selections extends Array<Record<string, any>>>(...selections: Selections): UnionToIntersection<Selections[number]>;

@@ -67,17 +80,8 @@

type TableNameFromProcedureCallback<$DataModel, $ProcedureCallback extends (selection: any) => any> = Exclude<ProcedureReturnType<$ProcedureCallback>, null> extends SelectOutputFromDataModel<$DataModel, any, any>[] ? NonNullable<Exclude<ProcedureReturnType<$ProcedureCallback>, null>[number]['__tableName']> : Exclude<ProcedureReturnType<$ProcedureCallback>, null> extends SelectOutputFromDataModel<$DataModel, any, any> ? NonNullable<Exclude<ProcedureReturnType<$ProcedureCallback>, null>['__tableName']> : never;
type TableNameFromProcedureCallback<$DataModel extends AnyDataModel, $ProcedureCallback extends (selection: any) => any> = Exclude<ProcedureReturnType<$ProcedureCallback>, null> extends SelectOutputFromDataModel<$DataModel, any, any>[] ? NonNullable<Exclude<ProcedureReturnType<$ProcedureCallback>, null>[number]['__tableName']> : Exclude<ProcedureReturnType<$ProcedureCallback>, null> extends SelectOutputFromDataModel<$DataModel, any, any> ? NonNullable<Exclude<ProcedureReturnType<$ProcedureCallback>, null>['__tableName']> : never;
declare function createWithSelection<$DataModel>({ selectionHashes }: {
declare function createWithSelection<$DataModel extends AnyDataModel>({ selectionHashes }: {
selectionHashes: Record<string, unknown>;
}): <$ProcedureCallback extends (selection: string) => any, const Selection extends SelectInputFromDataModel<$DataModel, TableNameFromProcedureCallback<$DataModel, $ProcedureCallback>>>(cb: $ProcedureCallback, selection: Selection) => Promise<(ProcedureReturnType<$ProcedureCallback> extends Array<any> ? SelectOutputFromDataModel<$DataModel, TableNameFromProcedureCallback<$DataModel, $ProcedureCallback>, Selection>[] : SelectOutputFromDataModel<$DataModel, TableNameFromProcedureCallback<$DataModel, $ProcedureCallback>, Selection>) | (null extends ProcedureReturnType<$ProcedureCallback> ? null : never)>;
/**
Creates a type-safe wrapper function for defining selections
*/
declare function defineSelectionMappings<$DataModel, $TableName extends string>(): {
set<$SelectionMappings extends Record<`$${string}`, SelectInputFromDataModel<$DataModel, $TableName> & {
[K in keyof $SelectionMappings]?: boolean;
}>>(mappings: () => $SelectionMappings): () => SelectionDefinition<SelectInputFromDataModel<$DataModel, $TableName>, $SelectionMappings>;
};
export { type ExpandMapping, type ExpandSelections, type InferSelectionDefinition, type ProcedureReturnType, type RecursivelyExpandSelection, type SelectInputFromDataModel, type SelectOutputFromDataModel, type SelectionDefinition, type SelectionSelect, type Selections, type TableNameFromProcedureCallback, type Virtual, type VirtualArray, type WithOptions, combineSelections, createSelectionFunction, createWithSelection, defineSelectionMappings, expandSelections, unscopeSelections };
export { type ExpandMapping, type ExpandSelections, type ProcedureReturnType, type RecursivelyExpandSelection, type SelectInputFromDataModel, type SelectOutputFromDataModel, type SelectOutputValue, type SelectionSelect, type Selections, type TableNameFromProcedureCallback, type Virtual, type VirtualArray, type WithOptions, combineSelections, createSelectionFunction, createWithSelection, expandSelections };

@@ -1,4 +0,3 @@

export { createSelectionFunction, expandSelections, unscopeSelections, combineSelections } from './utils/selection.js';
export { createSelectionFunction, expandSelections, combineSelections } from './utils/selection.js';
export { createWithSelection } from './utils/with-selection.js';
export { defineSelectionMappings } from './utils/selection-mappings.js';
export type * from './types/procedure.js';

@@ -5,0 +4,0 @@ export type * from './types/schema.js';

@@ -1,3 +0,2 @@

export { createSelectionFunction, expandSelections, unscopeSelections, combineSelections } from './utils/selection.js';
export { createSelectionFunction, expandSelections, combineSelections } from './utils/selection.js';
export { createWithSelection } from './utils/with-selection.js';
export { defineSelectionMappings } from './utils/selection-mappings.js';

@@ -5,7 +5,7 @@ {

"type": "module",
"version": "0.0.29",
"version": "0.1.0",
"exports": {
".": "./index.js",
"./hashes": "./hashes.js",
"./values": "./values.js"
"./validators": "./validators.js"
},

@@ -12,0 +12,0 @@ "scripts": {

@@ -0,3 +1,4 @@

import { AnyDataModel } from 'convex/server';
import type { ProcedureReturnType } from '../types/procedure.js';
import type { SelectOutputFromDataModel } from '../types/select.js';
export type TableNameFromProcedureCallback<$DataModel, $ProcedureCallback extends (selection: any) => any> = Exclude<ProcedureReturnType<$ProcedureCallback>, null> extends SelectOutputFromDataModel<$DataModel, any, any>[] ? NonNullable<Exclude<ProcedureReturnType<$ProcedureCallback>, null>[number]['__tableName']> : Exclude<ProcedureReturnType<$ProcedureCallback>, null> extends SelectOutputFromDataModel<$DataModel, any, any> ? NonNullable<Exclude<ProcedureReturnType<$ProcedureCallback>, null>['__tableName']> : never;
export type TableNameFromProcedureCallback<$DataModel extends AnyDataModel, $ProcedureCallback extends (selection: any) => any> = Exclude<ProcedureReturnType<$ProcedureCallback>, null> extends SelectOutputFromDataModel<$DataModel, any, any>[] ? NonNullable<Exclude<ProcedureReturnType<$ProcedureCallback>, null>[number]['__tableName']> : Exclude<ProcedureReturnType<$ProcedureCallback>, null> extends SelectOutputFromDataModel<$DataModel, any, any> ? NonNullable<Exclude<ProcedureReturnType<$ProcedureCallback>, null>['__tableName']> : never;

@@ -0,8 +1,9 @@

import { AnyDataModel } from 'convex/server';
import type { GenericId } from 'convex/values';
import { Deprecated } from '../types/deprecated.js';
import { PickCurrent, PickDeprecated } from '../types/variant.js';
import type { Virtual, VirtualArray } from '../types/virtual.js';
export type SelectInputFromDataModel<$DataModel, $TableName extends string, $WithCid extends boolean = false> = ($WithCid extends true ? {
export type SelectInputFromDataModel<$DataModel extends AnyDataModel, $TableName extends string, $WithCid extends boolean = false> = ($WithCid extends true ? {
cid: true;
} : {}) & {
[K in keyof $DataModel[$TableName]['document'] as $DataModel[$TableName]['document'][K] extends Deprecated ? never : K]?: NonNullable<$DataModel[$TableName]['document'][K]> extends Array<infer $Item> ? NonNullable<$Item> extends GenericId<infer $SelectedTableName> ? $SelectedTableName extends $TableName ? true : {
[K in keyof $DataModel[$TableName]['document']]?: NonNullable<$DataModel[$TableName]['document'][K]> extends Array<infer $Item> ? NonNullable<$Item> extends GenericId<infer $SelectedTableName> ? $SelectedTableName extends $TableName ? true : {
select: SelectInputFromDataModel<$DataModel, $SelectedTableName, $WithCid>;

@@ -21,5 +22,3 @@ } : NonNullable<$Item> extends VirtualArray<infer $SelectedTableName> ? {

};
export type SelectOutputFromDataModel<$DataModel, $TableName extends string, $Select extends Omit<SelectInputFromDataModel<$DataModel, $TableName>, 'id'>> = {
__tableName?: $TableName;
} & {
export type SelectOutputValue<$DataModel extends AnyDataModel, $TableName extends string, $Select extends Omit<SelectInputFromDataModel<$DataModel, $TableName>, 'id'>> = {
[K in keyof $Select]: $Select[K] extends true ? K extends keyof $DataModel[$TableName]['document'] ? $DataModel[$TableName]['document'][K] : never : $Select[K] extends {

@@ -29,1 +28,4 @@ select: infer $NestedSelect;

};
export type SelectOutputFromDataModel<$DataModel extends AnyDataModel, $TableName extends string, $Select extends Omit<SelectInputFromDataModel<$DataModel, $TableName>, 'id'>> = {
__tableName?: $TableName;
} & (PickCurrent<SelectOutputValue<$DataModel, $TableName, $Select>> | PickDeprecated<SelectOutputValue<$DataModel, $TableName, $Select>>);

@@ -0,13 +1,11 @@

import { AnyDataModel } from 'convex/server';
import type { UnionToIntersection } from 'type-fest';
import type { SelectInputFromDataModel } from '../types/select.js';
export interface SelectionDefinition<_$Select, _$SelectionMappings extends Record<`$${string}`, unknown>> extends Record<`$${string}`, unknown> {
}
export type InferSelectionDefinition<$SelectionDefinitionGetter extends (...args: any) => any> = Awaited<ReturnType<$SelectionDefinitionGetter>>;
export type ExpandMapping<$SelectionMappings, $Options> = {
[$OptionKey in keyof $Options]: $OptionKey extends keyof $SelectionMappings ? ExpandMapping<$SelectionMappings, $SelectionMappings[$OptionKey]> : Record<$OptionKey, $Options[$OptionKey]>;
}[keyof $Options];
export type SelectionSelect<$Definition extends SelectionDefinition<any, any>, $Options> = $Definition extends SelectionDefinition<any, infer $SelectionMappings> ? UnionToIntersection<ExpandMapping<$SelectionMappings, $Options>> : never;
export type WithOptions<$DataModel, $Definition extends SelectionDefinition<any, any>, $TableName extends string> = $Definition extends SelectionDefinition<any, infer $SelectionMappings> ? SelectInputFromDataModel<$DataModel, $TableName> & {
[Key in keyof $SelectionMappings]?: boolean;
} : never;
export type WithOptions<$DataModel extends AnyDataModel, $Selections extends Record<string, unknown>, $TableName extends string> = SelectInputFromDataModel<$DataModel, $TableName> & {
[Key in keyof $Selections]?: boolean;
};
export type SelectionSelect<$Selections extends Record<string, unknown>, $Options> = UnionToIntersection<ExpandMapping<$Selections, $Options>>;
export type Selections<$SelectionMappingObject> = keyof {

@@ -14,0 +12,0 @@ [$K in keyof $SelectionMappingObject as $K extends `$${string}` ? $K : never]: true;

@@ -1,8 +0,11 @@

import type { Exact, UnionToIntersection } from 'type-fest';
import type { SelectionDefinition, ExpandSelections } from '../types/selections.js';
import type { AnyDataModel } from 'convex/server';
import type { Exact, Simplify, UnionToIntersection } from 'type-fest';
import type { ExpandSelections } from '../types/selections.js';
import type { SelectInputFromDataModel } from '../types/select.js';
export declare function expandSelections<$SelectionMapping extends Record<string, Record<string, unknown>>>(selectionMapping: $SelectionMapping): ExpandSelections<$SelectionMapping>;
export declare function createSelectionFunction<$SelectionDefinition extends SelectionDefinition<any, any>>(selectionDefinition: $SelectionDefinition): <const $Selections extends Exact<($SelectionDefinition extends SelectionDefinition<infer Select, any> ? Select : never) & { [K in keyof ($SelectionDefinition extends SelectionDefinition<any, infer SelectionMappings extends Record<`$${string}`, unknown>> ? SelectionMappings : never)]?: boolean | undefined; }, $Selections>>(selections: $Selections) => UnionToIntersection<{ [$SelectionKey in keyof $Selections]: $SelectionKey extends `$${string}` ? ExpandSelections<$SelectionDefinition extends SelectionDefinition<any, infer SelectionMappings_1 extends Record<`$${string}`, unknown>> ? SelectionMappings_1 : never>[$SelectionKey] : Record<$SelectionKey, $Selections[$SelectionKey]>; }[keyof $Selections]>;
export declare function unscopeSelections<Selections extends Record<string, () => any>>(selections: Selections): {
[SelectionIdentifier in keyof Selections as SelectionIdentifier extends `${string}_${infer UnscopedIdentifier}` ? UnscopedIdentifier : never]: ReturnType<Selections[SelectionIdentifier]>;
};
export declare function createSelectionFunction<$DataModel extends AnyDataModel, $TableName extends string, $Selections extends Record<string, Record<string, unknown>>>(selections: $Selections): <const $Selection extends Exact<SelectInputFromDataModel<$DataModel, $TableName> & {
[K in keyof $Selections]?: boolean | undefined;
}, $Selection>>(selection: $Selection) => Simplify<UnionToIntersection<{
[$SelectionKey in keyof $Selection]: $SelectionKey extends `$${string}` ? ExpandSelections<$Selections>[$SelectionKey] : Record<$SelectionKey, $Selection[$SelectionKey]>;
}[keyof $Selection]>>;
export declare function combineSelections<Selections extends Array<Record<string, any>>>(...selections: Selections): UnionToIntersection<Selections[number]>;
import { deepmerge } from 'deepmerge-ts';
import mapObject, { mapObjectSkip } from 'map-obj';
import { merge } from 'merge';

@@ -20,7 +19,7 @@ export function expandSelections(selectionMapping) {

}
export function createSelectionFunction(selectionDefinition) {
const expandedSelections = expandSelections(selectionDefinition);
return function select(selections) {
export function createSelectionFunction(selections) {
const expandedSelections = expandSelections(selections);
return function select(selection) {
const selectionsArray = [];
for (const [selectionKey, selectionValue] of Object.entries(selections)) {
for (const [selectionKey, selectionValue] of Object.entries(selection)) {
if (selectionKey.startsWith('$')) {

@@ -36,16 +35,4 @@ selectionsArray.push(expandedSelections[selectionKey]);

}
export function unscopeSelections(selections) {
return mapObject(selections, (key, selection) => {
if (key === 'default') {
return mapObjectSkip;
}
const identifier = key.split('_')[1];
if (identifier === undefined) {
throw new Error(`Invalid selection identifier: ${String(key)}`);
}
return [identifier, selection()];
});
}
export function combineSelections(...selections) {
return merge(...selections);
}

@@ -0,6 +1,7 @@

import { AnyDataModel } from 'convex/server';
import type { ProcedureReturnType } from '../types/procedure.js';
import type { TableNameFromProcedureCallback } from '../types/schema.js';
import type { SelectInputFromDataModel, SelectOutputFromDataModel } from '../types/select.js';
import type { TableNameFromProcedureCallback } from '../types/schema.js';
import type { ProcedureReturnType } from '../types/procedure.js';
export declare function createWithSelection<$DataModel>({ selectionHashes }: {
export declare function createWithSelection<$DataModel extends AnyDataModel>({ selectionHashes }: {
selectionHashes: Record<string, unknown>;
}): <$ProcedureCallback extends (selection: string) => any, const Selection extends SelectInputFromDataModel<$DataModel, TableNameFromProcedureCallback<$DataModel, $ProcedureCallback>>>(cb: $ProcedureCallback, selection: Selection) => Promise<(ProcedureReturnType<$ProcedureCallback> extends Array<any> ? SelectOutputFromDataModel<$DataModel, TableNameFromProcedureCallback<$DataModel, $ProcedureCallback>, Selection>[] : SelectOutputFromDataModel<$DataModel, TableNameFromProcedureCallback<$DataModel, $ProcedureCallback>, Selection>) | (null extends ProcedureReturnType<$ProcedureCallback> ? null : never)>;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc