ozone-typescript-client
Advanced tools
Comparing version 6.0.4 to 6.0.5-sha
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=blobClient.js.map |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=filetypeClient.js.map |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=importExportClient.js.map |
@@ -31,2 +31,3 @@ import * as clientState from './ozoneClient/clientState'; | ||
export import SearchIterator = itemClient.SearchIterator; | ||
export import GraphQLSearchIterator = itemClient.GraphQLSearchIterator; | ||
export import PermissionClient = permissionClient.PermissionClient; | ||
@@ -33,0 +34,0 @@ export import RoleClient = roleClient.RoleClient; |
import { FromOzone, Item, Query, SearchRequest, UUID, Patch, AggregationItem } from 'ozone-type'; | ||
export interface SearchResults<T extends Item> { | ||
import { TypedDocumentNode } from '@apollo/client/core'; | ||
interface ISearchResulsts<T> { | ||
id?: number; | ||
@@ -7,4 +8,7 @@ total?: number; | ||
results?: T[]; | ||
} | ||
export interface SearchResults<T extends Item> extends ISearchResulsts<T> { | ||
aggregations?: Array<AggregationItem>; | ||
} | ||
export declare type SearchIdsResults = ISearchResulsts<UUID>; | ||
export interface ItemClient<T extends Item> { | ||
@@ -19,2 +23,3 @@ save(item: Patch<T>): Promise<FromOzone<T>>; | ||
search(searchRequest: SearchRequest): Promise<SearchResults<FromOzone<T>>>; | ||
searchIds(searchRequest: SearchRequest): Promise<SearchIdsResults>; | ||
count(query?: Query): Promise<number>; | ||
@@ -24,3 +29,4 @@ deleteById(id: UUID, permanent?: boolean): Promise<UUID | null>; | ||
searchGenerator(searchRequest: SearchRequest): SearchIterator<T>; | ||
queryDelete(searchQuery: Query): Promise<UUID[]>; | ||
graphQLSearchGenerator<TData, TVariables>(query: TypedDocumentNode<TData, TVariables>, variables?: TVariables): GraphQLSearchIterator<TData>; | ||
queryDelete(searchQuery: Query, permanent?: boolean): Promise<UUID[]>; | ||
} | ||
@@ -34,1 +40,9 @@ export interface SearchIterator<T> extends AsyncIterableIterator<SearchResults<FromOzone<T>>> { | ||
} | ||
export interface GraphQLSearchIterator<T = any> extends AsyncIterableIterator<T> { | ||
/** | ||
* Cancel ongoing http request | ||
* It will end the generator | ||
*/ | ||
cancel(): void; | ||
} | ||
export {}; |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=itemClient.js.map |
import { FromOzone, Item, Query, SearchRequest, UUID, Patch } from 'ozone-type'; | ||
import { ItemClient, SearchResults, SearchIterator } from './itemClient'; | ||
import { ItemClient, SearchResults, SearchIterator, GraphQLSearchIterator, SearchIdsResults } from './itemClient'; | ||
import { OzoneClient } from '../ozoneClient/ozoneClient'; | ||
import { OperationVariables, TypedDocumentNode } from '@apollo/client/core'; | ||
export declare class ItemClientImpl<T extends Item> implements ItemClient<T> { | ||
@@ -18,6 +19,8 @@ private client; | ||
search(searchRequest: SearchRequest): Promise<SearchResults<FromOzone<T>>>; | ||
searchIds(searchRequest: SearchRequest): Promise<SearchIdsResults>; | ||
searchGenerator(searchRequest: SearchRequest): SearchIterator<T>; | ||
graphQLSearchGenerator<TData = any, TVariables = OperationVariables>(query: TypedDocumentNode<TData, TVariables>, variables?: TVariables): GraphQLSearchIterator<TData>; | ||
broadcast(item: T): Promise<FromOzone<T>>; | ||
bulkBroadcast(items: T[]): Promise<FromOzone<T>[]>; | ||
queryDelete(searchQuery: Query): Promise<UUID[]>; | ||
queryDelete(searchQuery: Query, permanent?: boolean): Promise<UUID[]>; | ||
} |
@@ -14,2 +14,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { returnNullOn404 } from '../utility/utility'; | ||
import { ApolloClient, gql, HttpLink, InMemoryCache } from '@apollo/client/core'; | ||
export class ItemClientImpl { | ||
@@ -90,5 +91,14 @@ constructor(client, baseUrl, typeIdentifier) { | ||
} | ||
searchIds(searchRequest) { | ||
const request = new Request(`${this.baseUrl}/rest/v3/items/${this.typeIdentifier}/searchIds`) | ||
.setMethod('POST') | ||
.setBody(searchRequest); | ||
return this.client.call(request); | ||
} | ||
searchGenerator(searchRequest) { | ||
return new SearchIteratorImpl(this.client, this.baseUrl, this.typeIdentifier, searchRequest); | ||
} | ||
graphQLSearchGenerator(query, variables) { | ||
return new GraphQLSearchIteratorImpl(this.client, this.baseUrl, query, variables); | ||
} | ||
broadcast(item) { | ||
@@ -118,5 +128,6 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
queryDelete(searchQuery) { | ||
queryDelete(searchQuery, permanent = false) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const request = new Request(`${this.baseUrl}/rest/v3/items/${this.typeIdentifier}/queryDelete`) | ||
const url = `${this.baseUrl}/rest/v3/items/${this.typeIdentifier}/queryDelete${permanent ? '?permanent=true' : ''}`; | ||
const request = new Request(url) | ||
.setMethod('POST') | ||
@@ -138,2 +149,3 @@ .setBody(searchQuery); | ||
_search(searchRequest) { | ||
var _a; | ||
try { | ||
@@ -146,3 +158,3 @@ this.currentRequest = new Request(`${this.baseUrl}/rest/v3/items/${this.typeIdentifier}/search`) | ||
catch (err) { | ||
if (err.request && err.request.isAborted) { | ||
if ((_a = err.request) === null || _a === void 0 ? void 0 : _a.isAborted) { | ||
throw Error('search aborted'); | ||
@@ -156,2 +168,3 @@ } | ||
next(forceOffset) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -169,3 +182,3 @@ try { | ||
catch (err) { | ||
if (!(err.request && err.request.isAborted)) { | ||
if (!((_a = err.request) === null || _a === void 0 ? void 0 : _a.isAborted)) { | ||
throw err; | ||
@@ -186,2 +199,117 @@ } | ||
} | ||
class GraphQLSearchIteratorImpl { | ||
constructor(client, baseUrl, query, variables) { | ||
this.client = client; | ||
this.baseUrl = baseUrl; | ||
this.query = query; | ||
this.variables = variables; | ||
this.hasMoreData = true; | ||
this.loadingSize = 0; | ||
} | ||
// query<T = any, TVariables = OperationVariables>(options: QueryOptions<TVariables, T>): Promise<ApolloQueryResult<T>>; | ||
_search(query, variables) { | ||
var _a; | ||
try { | ||
const gqlQuery = gql(` | ||
query { | ||
flowrPackages { | ||
items { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
`); | ||
this.getGraphqlClient().query({ | ||
query: gqlQuery | ||
}).then(result => console.log(result)).catch(it => `obligatory catch: ${it}`); | ||
// this.getGraphqlClient().query({ | ||
// query: PackageMediasDocument, variables: { "package": "Valtteri Bottas" } | ||
// }).then(result => console.log(result)); | ||
this.getGraphqlClient().query({ | ||
query: query, variables: variables | ||
}).then(result => { | ||
console.log(result); | ||
}).catch(it => `obligatory catch: ${it}`); | ||
return this.getGraphqlClient().query({ | ||
query: query, variables: variables | ||
}).then(result => result.data); | ||
// if (loading); if (error)... | ||
// this.currentRequest = new Request(`${this.baseUrl}/rest/v3/graphql`) | ||
// .setMethod('POST') | ||
// .setBody(new GraphQLBody(this.typeIdentifier, searchRequest, selectionSet)) // e.g. selectionSet = 'items { name }' | ||
// return this.client.call<FromGraphQL<T>>(this.currentRequest) | ||
} | ||
catch (err) { | ||
if ((_a = err.request) === null || _a === void 0 ? void 0 : _a.isAborted) { | ||
throw Error('search aborted'); | ||
} | ||
else { | ||
throw err; | ||
} | ||
} | ||
} | ||
next(forceOffset) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
if (this.hasMoreData || forceOffset !== undefined) { | ||
console.log('TODO'); | ||
// this.searchRequest.offset = forceOffset !== undefined ? forceOffset : this.loadingSize | ||
const response = yield this._search(this.query, this.variables); | ||
// const data = response.data[`${this.typeIdentifier}s`] | ||
// const totalCount: number = data.totalCount | ||
// const items: any[] = data.items | ||
// const size: number = items.length | ||
// this.loadingSize = this.searchRequest.offset + (size || 0) | ||
// const done = !this.hasMoreData | ||
// this.hasMoreData = this.loadingSize < Number(totalCount || 0) | ||
return { value: response, done: true }; // done | ||
// throw new Error('Not implemented yet') | ||
} | ||
} | ||
catch (err) { | ||
if ((_a = err.request) === null || _a === void 0 ? void 0 : _a.isAborted) { | ||
throw Error('search aborted'); | ||
} | ||
else { | ||
throw err; | ||
} | ||
} | ||
return { done: true, value: {} }; | ||
}); | ||
} | ||
cancel() { | ||
if (this.currentRequest) { | ||
this.currentRequest.abort(); | ||
} | ||
} | ||
[Symbol.asyncIterator]() { | ||
return this; | ||
} | ||
getGraphqlClient() { | ||
const link = new HttpLink({ | ||
fetch: (uri, options) => { | ||
const uriString = typeof uri === 'string' ? uri : uri.url; | ||
const body = options === null || options === void 0 ? void 0 : options.body; | ||
const method = options === null || options === void 0 ? void 0 : options.method; | ||
// const contentType = ?; | ||
const req = new Request('https://graphql.ozone.dev/rest/v3/graphql', { method: method, body: body }); // TODO SHA: options | ||
const myResult = this.client.call(req); | ||
return myResult.then(it => { | ||
let obj = {}; | ||
const jsonString = JSON.stringify(it); | ||
// @ts-ignore | ||
obj.text = () => new Promise(function (resolve, reject) { resolve(jsonString); }); | ||
return obj; | ||
}); | ||
} | ||
}); | ||
return new ApolloClient({ | ||
uri: `${this.baseUrl}/rest/v3/graphql`, | ||
cache: new InMemoryCache(), | ||
link | ||
}); | ||
} | ||
} | ||
//# sourceMappingURL=itemClientImpl.js.map |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=ozoneClient.js.map |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=permissionClient.js.map |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=roleClient.js.map |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=taskClient.js.map |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=typeCache.js.map |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=typeClient.js.map |
{ | ||
"name": "ozone-typescript-client", | ||
"version": "6.0.4", | ||
"version": "6.0.5-sha", | ||
"description": "", | ||
@@ -33,3 +33,3 @@ "main": "dist/src/index.js", | ||
"typescript-http-client": "0.10.1", | ||
"typescript-state-machine": "0.9.6" | ||
"typescript-state-machine": "0.9.7" | ||
}, | ||
@@ -39,3 +39,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "30ec557cc07557685a96df7a468a7c09c781972d" | ||
"gitHead": "83e5e26fcede38ad052d8c9be335f8b54a3c028e" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
481441
5271
1
1
+ Addedtypescript-state-machine@0.9.7(transitive)
- Removedtypescript-state-machine@0.9.6(transitive)