UNPKG

9.05 kBTypeScriptView Raw
1import { Queryable, IInvokable } from "@pnp/queryable";
2export type SPInit = string | ISPQueryable | [ISPQueryable, string];
3export interface ISPConstructor<T extends ISPQueryable = ISPQueryable> {
4 new (base: SPInit, path?: string): T;
5}
6export type ISPInvokableFactory<R extends ISPQueryable> = (base: SPInit, path?: string) => R & IInvokable;
7export declare const spInvokableFactory: <R extends ISPQueryable<any>>(f: any) => ISPInvokableFactory<R>;
8/**
9 * SharePointQueryable Base Class
10 *
11 */
12export declare class _SPQueryable<GetType = any> extends Queryable<GetType> {
13 protected parentUrl: string;
14 /**
15 * Creates a new instance of the SharePointQueryable class
16 *
17 * @constructor
18 * @param base A string or SharePointQueryable that should form the base part of the url
19 *
20 */
21 constructor(base: SPInit, path?: string);
22 /**
23 * Gets the full url with query information
24 */
25 toRequestUrl(): string;
26 /**
27 * Choose which fields to return
28 *
29 * @param selects One or more fields to return
30 */
31 select(...selects: string[]): this;
32 /**
33 * Expands fields such as lookups to get additional data
34 *
35 * @param expands The Fields for which to expand the values
36 */
37 expand(...expands: string[]): this;
38 /**
39 * Gets a parent for this instance as specified
40 *
41 * @param factory The contructor for the class to create
42 */
43 protected getParent<T extends ISPQueryable>(factory: ISPInvokableFactory<any>, path?: string, base?: string): T;
44}
45export interface ISPQueryable<GetType = any> extends _SPQueryable<GetType> {
46}
47export declare const SPQueryable: ISPInvokableFactory<ISPQueryable<any>>;
48/**
49 * Represents a REST collection which can be filtered, paged, and selected
50 *
51 */
52export declare class _SPCollection<GetType = any[]> extends _SPQueryable<GetType> {
53 /**
54 * Filters the returned collection (https://msdn.microsoft.com/en-us/library/office/fp142385.aspx#bk_supported)
55 *
56 * @param filter The string representing the filter query
57 */
58 filter<T = UnwrapArray<GetType>>(filter: string | ComparisonResult<T> | ((f: InitialFieldQuery<T>) => ComparisonResult<T>)): this;
59 /**
60 * Orders based on the supplied fields
61 *
62 * @param orderby The name of the field on which to sort
63 * @param ascending If false DESC is appended, otherwise ASC (default)
64 */
65 orderBy(orderBy: string, ascending?: boolean): this;
66 /**
67 * Skips the specified number of items
68 *
69 * @param skip The number of items to skip
70 */
71 skip(skip: number): this;
72 /**
73 * Limits the query to only return the specified number of items
74 *
75 * @param top The query row limit
76 */
77 top(top: number): this;
78}
79export interface ISPCollection<GetType = any[]> extends _SPCollection<GetType> {
80}
81export declare const SPCollection: ISPInvokableFactory<ISPCollection<any[]>>;
82/**
83 * Represents an instance that can be selected
84 *
85 */
86export declare class _SPInstance<GetType = any> extends _SPQueryable<GetType> {
87}
88export interface ISPInstance<GetType = any> extends _SPInstance<GetType> {
89}
90export declare const SPInstance: ISPInvokableFactory<ISPInstance<any>>;
91/**
92 * Adds the a delete method to the tagged class taking no parameters and calling spPostDelete
93 */
94export declare function deleteable(): (this: ISPQueryable) => Promise<void>;
95export interface IDeleteable {
96 /**
97 * Delete this instance
98 */
99 delete(): Promise<void>;
100}
101export declare function deleteableWithETag(): (this: ISPQueryable, eTag?: string) => Promise<void>;
102export interface IDeleteableWithETag {
103 /**
104 * Delete this instance
105 *
106 * @param eTag Value used in the IF-Match header, by default "*"
107 */
108 delete(eTag?: string): Promise<void>;
109}
110export declare const spGet: <T = any>(o: ISPQueryable<any>, init?: RequestInit) => Promise<T>;
111export declare const spPost: <T = any>(o: ISPQueryable<any>, init?: RequestInit) => Promise<T>;
112export declare const spPostMerge: <T = any>(o: ISPQueryable<any>, init?: RequestInit) => Promise<T>;
113export declare const spPostDelete: <T = any>(o: ISPQueryable<any>, init?: RequestInit) => Promise<T>;
114export declare const spPostDeleteETag: <T = any>(o: ISPQueryable<any>, init?: RequestInit, eTag?: string) => Promise<T>;
115export declare const spDelete: <T = any>(o: ISPQueryable<any>, init?: RequestInit) => Promise<T>;
116export declare const spPatch: <T = any>(o: ISPQueryable<any>, init?: RequestInit) => Promise<T>;
117type KeysMatching<T, V> = {
118 [K in keyof T]: T[K] extends V ? K : never;
119}[keyof T];
120type KeysMatchingObjects<T> = {
121 [K in keyof T]: T[K] extends object ? (T[K] extends Date ? never : K) : never;
122}[keyof T];
123type UnwrapArray<T> = T extends (infer U)[] ? U : T;
124declare class BaseQuery {
125 protected query: string[];
126 constructor(query: string[]);
127}
128declare class QueryableFields<T> extends BaseQuery {
129 constructor(q: string[]);
130 text(internalName: KeysMatching<T, string>): TextField<T>;
131 choice(internalName: KeysMatching<T, string>): TextField<T>;
132 multiChoice(internalName: KeysMatching<T, string[]>): TextField<T>;
133 number(internalName: KeysMatching<T, number>): NumberField<T>;
134 date(internalName: KeysMatching<T, Date>): DateField<T>;
135 boolean(internalName: KeysMatching<T, boolean>): BooleanField<T>;
136 lookup<TKey extends KeysMatchingObjects<T>>(internalName: TKey): LookupQueryableFields<T, T[TKey]>;
137 lookupId<TKey extends KeysMatching<T, number>>(internalName: TKey): NumberField<T>;
138}
139declare class QueryableAndResult<T> extends QueryableFields<T> {
140 or(...queries: (ComparisonResult<T> | ((f: QueryableFields<T>) => ComparisonResult<T>))[]): ComparisonResult<T>;
141}
142declare class QueryableOrResult<T> extends QueryableFields<T> {
143 and(...queries: (ComparisonResult<T> | ((f: QueryableFields<T>) => ComparisonResult<T>))[]): ComparisonResult<T>;
144}
145declare class InitialFieldQuery<T> extends QueryableFields<T> {
146 or(): QueryableFields<T>;
147 or(...queries: (ComparisonResult<T> | ((f: QueryableFields<T>) => ComparisonResult<T>))[]): ComparisonResult<T>;
148 and(): QueryableFields<T>;
149 and(...queries: (ComparisonResult<T> | ((f: QueryableFields<T>) => ComparisonResult<T>))[]): ComparisonResult<T>;
150}
151declare class LookupQueryableFields<TBaseInterface, TExpandedType> extends BaseQuery {
152 private LookupField;
153 constructor(q: string[], LookupField: string);
154 Id(id: number): ComparisonResult<TBaseInterface>;
155 text(internalName: KeysMatching<TExpandedType, string>): TextField<TBaseInterface>;
156 number(internalName: KeysMatching<TExpandedType, number>): NumberField<TBaseInterface>;
157}
158declare class NullableField<TBaseInterface, TInputValueType> extends BaseQuery {
159 protected LastIndex: number;
160 protected InternalName: string;
161 constructor(q: string[]);
162 protected toODataValue(value: TInputValueType): string;
163 isNull(): ComparisonResult<TBaseInterface>;
164 isNotNull(): ComparisonResult<TBaseInterface>;
165}
166declare class ComparableField<T, TInputValueType> extends NullableField<T, TInputValueType> {
167 equals(value: TInputValueType): ComparisonResult<T>;
168 notEquals(value: TInputValueType): ComparisonResult<T>;
169 in(...values: TInputValueType[]): ComparisonResult<T>;
170 notIn(...values: TInputValueType[]): ComparisonResult<T>;
171}
172declare class TextField<TBaseInterface> extends ComparableField<TBaseInterface, string> {
173 startsWith(value: string): ComparisonResult<TBaseInterface>;
174 contains(value: string): ComparisonResult<TBaseInterface>;
175}
176declare class BooleanField<TBaseInterface> extends NullableField<TBaseInterface, boolean> {
177 protected toODataValue(value: boolean | null): string;
178 isTrue(): ComparisonResult<TBaseInterface>;
179 isFalse(): ComparisonResult<TBaseInterface>;
180 isFalseOrNull(): ComparisonResult<TBaseInterface>;
181}
182declare class NumericField<T, TInputValueType> extends ComparableField<T, TInputValueType> {
183 greaterThan(value: TInputValueType): ComparisonResult<T>;
184 greaterThanOrEquals(value: TInputValueType): ComparisonResult<T>;
185 lessThan(value: TInputValueType): ComparisonResult<T>;
186 lessThanOrEquals(value: TInputValueType): ComparisonResult<T>;
187}
188declare class NumberField<T> extends NumericField<T, number> {
189 protected toODataValue(value: number): string;
190}
191declare class DateField<TBaseInterface> extends NumericField<TBaseInterface, Date> {
192 protected toODataValue(value: Date): string;
193 isBetween(startDate: Date, endDate: Date): ComparisonResult<TBaseInterface>;
194 isToday(): ComparisonResult<TBaseInterface>;
195}
196declare class ComparisonResult<T> extends BaseQuery {
197 and(): QueryableAndResult<T>;
198 and(...queries: (ComparisonResult<T> | ((f: QueryableFields<T>) => ComparisonResult<T>))[]): ComparisonResult<T>;
199 or(): QueryableOrResult<T>;
200 or(...queries: (ComparisonResult<T> | ((f: QueryableFields<T>) => ComparisonResult<T>))[]): ComparisonResult<T>;
201 toString(): string;
202}
203export {};
204//# sourceMappingURL=spqueryable.d.ts.map
\No newline at end of file