initial
This commit is contained in:
8
ts_api/00_commitinfo_data.ts
Normal file
8
ts_api/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@bellini/api',
|
||||
version: '1.1.0',
|
||||
description: 'the main bellini api package'
|
||||
}
|
58
ts_api/api.classes.belliniclient.ts
Normal file
58
ts_api/api.classes.belliniclient.ts
Normal file
@ -0,0 +1,58 @@
|
||||
import * as plugins from './api.plugins.js';
|
||||
|
||||
export interface IBelliniClientOptions {
|
||||
publicationName: string;
|
||||
smartstatePart?: plugins.smartstate.StatePart<any, IBelliniClientState>;
|
||||
}
|
||||
|
||||
export interface IBelliniClientState {
|
||||
articles: plugins.belliniInterfaces.IBelliniArticle[];
|
||||
}
|
||||
|
||||
export class BelliniClient {
|
||||
private apiEndpoint = 'https://connect.api.global/bellini';
|
||||
public smartstatePart: plugins.smartstate.StatePart<any, IBelliniClientState>;
|
||||
public options: IBelliniClientOptions;
|
||||
|
||||
constructor(optionsArg: IBelliniClientOptions) {
|
||||
this.options = optionsArg;
|
||||
this.init();
|
||||
}
|
||||
|
||||
public initPromise: Promise<void>;
|
||||
public async init() {
|
||||
if (this.initPromise) {
|
||||
return this.initPromise;
|
||||
}
|
||||
const deferred = plugins.smartpromise.defer<void>();
|
||||
this.initPromise = deferred.promise;
|
||||
if (this.options.smartstatePart) {
|
||||
this.smartstatePart = this.options.smartstatePart;
|
||||
} else {
|
||||
const smartstate = new plugins.smartstate.Smartstate();
|
||||
this.smartstatePart = await smartstate.getStatePart<IBelliniClientState>('bellini', {} as any);
|
||||
}
|
||||
await this.smartstatePart.setState({
|
||||
articles: [],
|
||||
});
|
||||
deferred.resolve();
|
||||
}
|
||||
|
||||
public async fetchArticles() {
|
||||
await this.init();
|
||||
const getArticles =
|
||||
new plugins.typedrequest.TypedRequest<plugins.belliniInterfaces.IRequest_Any_Bellini_GetArticles>(
|
||||
this.apiEndpoint,
|
||||
'getArticles',
|
||||
);
|
||||
const response = await getArticles.fire({
|
||||
from: Date.now() - 1000000000,
|
||||
to: Date.now(),
|
||||
publicationName: this.options.publicationName,
|
||||
});
|
||||
this.smartstatePart.setState({
|
||||
articles: response.articles,
|
||||
});
|
||||
return response.articles;
|
||||
}
|
||||
}
|
15
ts_api/api.plugins.ts
Normal file
15
ts_api/api.plugins.ts
Normal file
@ -0,0 +1,15 @@
|
||||
// @bellini scope
|
||||
import * as belliniInterfaces from '@bellini/interfaces';
|
||||
|
||||
export { belliniInterfaces };
|
||||
|
||||
// @apiglobal scope
|
||||
import * as typedrequest from '@api.global/typedrequest';
|
||||
|
||||
export { typedrequest };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smartstate from '@push.rocks/smartstate';
|
||||
|
||||
export { smartpromise, smartstate };
|
1
ts_api/index.ts
Normal file
1
ts_api/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './api.classes.belliniclient.js';
|
12
ts_api/tspublish.json
Normal file
12
ts_api/tspublish.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"order": 1,
|
||||
"name": "@bellini.io/api",
|
||||
"dependencies": [
|
||||
"@api.global/typedrequest-interfaces",
|
||||
"@tsclass/tsclass"
|
||||
],
|
||||
"registries": [
|
||||
"registry.npmjs.org:public",
|
||||
"verdaccio.lossless.digital:public"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user