Skip to content

Commit

Permalink
Merge pull request #2984 from patrick-rodgers/version-4
Browse files Browse the repository at this point in the history
code cleanup for v4
  • Loading branch information
patrick-rodgers authored Apr 5, 2024
2 parents 8e3250c + 5802302 commit 08e8008
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 61 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/core/moments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObserverAction, ObserverFunction, Timeline } from "./timeline.js";
import { ObserverAction, ObserverFunction, ObserverSyncFunction, Timeline } from "./timeline.js";
import { isArray } from "./util.js";

/**
Expand Down Expand Up @@ -49,7 +49,7 @@ export function asyncBroadcast<T extends ObserverFunction<void>>(): (observers:
*
* @returns The final set of arguments
*/
export function reduce<T extends ObserverFunction<[...Parameters<T>]>>(): (observers: T[], ...args: [...Parameters<T>]) => [...Parameters<T>] {
export function reduce<T extends ObserverSyncFunction<[...Parameters<T>]>>(): (observers: T[], ...args: [...Parameters<T>]) => [...Parameters<T>] {

return function (this: Timeline<any>, observers: T[], ...args: [...Parameters<T>]): [...Parameters<T>] {

Expand Down
5 changes: 5 additions & 0 deletions packages/core/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { objectDefinedNotNull, isArray, isFunc } from "./util.js";
*/
export type ObserverAction = (this: Timeline<any>, ...args: any[]) => void;

/**
* Represents an observer with side effects within the timeline
*/
export type ObserverSyncFunction<R = any> = (this: Timeline<any>, ...args: any[]) => R;

/**
* Represents an observer with side effects within the timeline
*/
Expand Down
36 changes: 5 additions & 31 deletions packages/queryable/queryable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type QueryablePostObserver = (this: IQueryableInternal, url: URL, result:

export type QueryableDataObserver<T = any> = (this: IQueryableInternal, result: T) => void;

type QueryablePromiseObserver = (this: IQueryableInternal, promise: Promise<any>) => Promise<[Promise<any>]>;
type QueryablePromiseObserver = (this: IQueryableInternal, promise: Promise<any>) => [Promise<any>];

const DefaultMoments = {
construct: lifecycle<QueryableConstructObserver>(),
Expand All @@ -29,9 +29,6 @@ const DefaultMoments = {
export type QueryableInit = Queryable<any> | string | [Queryable<any>, string];

export type QueryParams = {

// new(init?: string[][] | Record<string, string> | string | QueryParams): QueryParams;

/**
* Sets the value associated to a given search parameter to the given value. If there were several values, delete the others.
*
Expand Down Expand Up @@ -234,20 +231,15 @@ export class Queryable<R> extends Timeline<typeof DefaultMoments> implements IQu

}, 0);

// this is the promise that the calling code will recieve and await
let promise = new Promise<void>((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<void>((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];
}
}

Expand Down Expand Up @@ -317,24 +309,6 @@ export function queryableFactory<InstanceType>(
};
}

// // extends IQueryableInternal
// export function queryableFactory2<InstanceType extends IQueryableInternal>(constructor: InstanceType):
// (...args: ConstructorParameters<InstanceType>) => InstanceType & IInvokable {

// return (...args: ConstructorParameters<InstanceType>) => {

// // 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
// (<any>instance).emit.construct(...args);

// return instance;
// };
// }

/**
* Allows a decorated object to be invoked as a function, optionally providing an implementation for that action
*
Expand Down
30 changes: 2 additions & 28 deletions packages/sp/spqueryable.ts
Original file line number Diff line number Diff line change
@@ -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];
Expand All @@ -13,20 +13,6 @@ export const spInvokableFactory = <R extends ISPQueryable>(f: any): ISPInvokable
return queryableFactory<R>(f);
};



// export type ISPInvokableFactory2<R extends ISPQueryable> = (...args: any[]) => R & IInvokable;

// export const spInvokableFactory2 = <R extends ISPQueryable<T>, T extends ISPQueryable>(f: T): ISPInvokableFactory2<R> => {





// return queryableFactory2<R>(f);
// };


/**
* SharePointQueryable Base Class
*
Expand Down Expand Up @@ -79,11 +65,6 @@ export class _SPQueryable<GetType = any> extends Queryable<GetType> {

const q: Queryable<any> = 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);
}
}
}

Expand Down Expand Up @@ -149,14 +130,7 @@ export class _SPQueryable<GetType = any> extends Queryable<GetType> {
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<GetType = any> extends _SPQueryable<GetType> { }
Expand Down

0 comments on commit 08e8008

Please sign in to comment.