diff --git a/CHANGELOG.md b/CHANGELOG.md index 2acf5224b..128faff86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - removed /items/get-all import, unneeded, use async iterator patterns - ./operations.ts methods moved to ./spqueryable.ts - startUpload, continueUpload, finishUpload File protected methods removed + - removed legacy support for @target query param - nodejs - removed stream extensions, moved into sp @@ -49,6 +50,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - queryable - moved add-props.ts and request-builders.ts to index.ts + - Changed interface for `query` property - graph - IGraphQueryableCollection now supports async iterator pattern @@ -58,6 +60,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - ISites.getByUrl is now async - @pnp/graph/outlook is not in @pnp/graph/mail, included all mail endpoints - mailCategory.add() returns Microsoft Graph types OutlookCategory vs object with data property. + - Changed how query params are parsed to custom logic - sp - _Items and IItems now supports async iterator pattern diff --git a/packages/core/moments.ts b/packages/core/moments.ts index 05ddc442b..7aede8879 100644 --- a/packages/core/moments.ts +++ b/packages/core/moments.ts @@ -1,4 +1,4 @@ -import { ObserverAction, ObserverFunction, Timeline } from "./timeline.js"; +import { ObserverAction, ObserverFunction, ObserverSyncFunction, Timeline } from "./timeline.js"; import { isArray } from "./util.js"; /** @@ -49,7 +49,7 @@ export function asyncBroadcast>(): (observers: * * @returns The final set of arguments */ -export function reduce]>>(): (observers: T[], ...args: [...Parameters]) => [...Parameters] { +export function reduce]>>(): (observers: T[], ...args: [...Parameters]) => [...Parameters] { return function (this: Timeline, observers: T[], ...args: [...Parameters]): [...Parameters] { diff --git a/packages/core/timeline.ts b/packages/core/timeline.ts index 032c7a7e1..557d1c96e 100644 --- a/packages/core/timeline.ts +++ b/packages/core/timeline.ts @@ -6,6 +6,11 @@ import { objectDefinedNotNull, isArray, isFunc } from "./util.js"; */ export type ObserverAction = (this: Timeline, ...args: any[]) => void; +/** + * Represents an observer with side effects within the timeline + */ +export type ObserverSyncFunction = (this: Timeline, ...args: any[]) => R; + /** * Represents an observer with side effects within the timeline */ diff --git a/packages/queryable/queryable.ts b/packages/queryable/queryable.ts index 4e933fb51..afe87e4e0 100644 --- a/packages/queryable/queryable.ts +++ b/packages/queryable/queryable.ts @@ -14,7 +14,7 @@ export type QueryablePostObserver = (this: IQueryableInternal, url: URL, result: export type QueryableDataObserver = (this: IQueryableInternal, result: T) => void; -type QueryablePromiseObserver = (this: IQueryableInternal, promise: Promise) => Promise<[Promise]>; +type QueryablePromiseObserver = (this: IQueryableInternal, promise: Promise) => [Promise]; const DefaultMoments = { construct: lifecycle(), @@ -29,9 +29,6 @@ const DefaultMoments = { export type QueryableInit = Queryable | string | [Queryable, string]; export type QueryParams = { - - // new(init?: string[][] | Record | string | QueryParams): QueryParams; - /** * Sets the value associated to a given search parameter to the given value. If there were several values, delete the others. * @@ -234,20 +231,15 @@ export class Queryable extends Timeline implements IQu }, 0); - // this is the promise that the calling code will recieve and await - let promise = new Promise((resolve, reject) => { + // this allows us to internally hook the promise creation and modify it. This was introduced to allow for + // cancelable to work as envisioned, but may have other users. Meant for internal use in the library accessed via behaviors. + return this.emit[this.InternalPromise](new Promise((resolve, reject) => { // we overwrite any pre-existing internal events as a // given queryable only processes a single request at a time this.on[this.InternalResolve].replace(resolve); this.on[this.InternalReject].replace(reject); - }); - - // this allows us to internally hook the promise creation and modify it. This was introduced to allow for - // cancelable to work as envisioned, but may have other users. Meant for internal use in the library accessed via behaviors. - [promise] = this.emit[this.InternalPromise](promise); - - return promise; + }))[0]; } } @@ -317,24 +309,6 @@ export function queryableFactory( }; } -// // extends IQueryableInternal -// export function queryableFactory2(constructor: InstanceType): -// (...args: ConstructorParameters) => InstanceType & IInvokable { - -// return (...args: ConstructorParameters) => { - -// // construct the concrete instance -// const instance: InstanceType = new constructor(...args); - -// // we emit the construct event from the factory because we need all of the decorators and constructors -// // to have fully finished before we emit, which is now true. We type the instance to any to get around -// // the protected nature of emit -// (instance).emit.construct(...args); - -// return instance; -// }; -// } - /** * Allows a decorated object to be invoked as a function, optionally providing an implementation for that action * diff --git a/packages/sp/spqueryable.ts b/packages/sp/spqueryable.ts index 3e864c1d8..7c8cc0a97 100644 --- a/packages/sp/spqueryable.ts +++ b/packages/sp/spqueryable.ts @@ -1,4 +1,4 @@ -import { combine, isUrlAbsolute, isArray, objectDefinedNotNull, stringIsNullOrEmpty } from "@pnp/core"; +import { combine, isUrlAbsolute, isArray, stringIsNullOrEmpty } from "@pnp/core"; import { Queryable, queryableFactory, op, get, post, patch, del, IInvokable } from "@pnp/queryable"; export type SPInit = string | ISPQueryable | [ISPQueryable, string]; @@ -13,20 +13,6 @@ export const spInvokableFactory = (f: any): ISPInvokable return queryableFactory(f); }; - - -// export type ISPInvokableFactory2 = (...args: any[]) => R & IInvokable; - -// export const spInvokableFactory2 = , T extends ISPQueryable>(f: T): ISPInvokableFactory2 => { - - - - - -// return queryableFactory2(f); -// }; - - /** * SharePointQueryable Base Class * @@ -79,11 +65,6 @@ export class _SPQueryable extends Queryable { const q: Queryable = isArray(base) ? base[0] : base; this.parentUrl = isArray(base) ? base[1] : q.toUrl(); - - const target = q.query.get("@target"); - if (objectDefinedNotNull(target)) { - this.query.set("@target", target); - } } } @@ -149,14 +130,7 @@ export class _SPQueryable extends Queryable { path?: string, base: string = this.parentUrl): T { - const parent = factory([this, base], path); - - const t = "@target"; - if (this.query.has(t)) { - parent.query.set(t, this.query.get(t)); - } - - return parent; + return factory([this, base], path); } } export interface ISPQueryable extends _SPQueryable { }