@spinque/query-api
Advanced tools
Comparing version 0.0.1 to 0.2.0
@@ -1,1 +0,2 @@ | ||
export declare const Greeter: (name: string) => string; | ||
export { Api } from './Api'; | ||
export { ApiConfig, ApiAuthenticationConfig, Query, RequestType, RequestOptions, ResponseType, ResultsResponse, StatisticsResponse, ErrorResponse, UnauthorizedError, ServerError, } from './types'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Greeter = void 0; | ||
var Greeter = function (name) { return "Hello ".concat(name); }; | ||
exports.Greeter = Greeter; | ||
exports.ServerError = exports.UnauthorizedError = exports.ErrorResponse = exports.Api = void 0; | ||
var Api_1 = require("./Api"); | ||
Object.defineProperty(exports, "Api", { enumerable: true, get: function () { return Api_1.Api; } }); | ||
var types_1 = require("./types"); | ||
Object.defineProperty(exports, "ErrorResponse", { enumerable: true, get: function () { return types_1.ErrorResponse; } }); | ||
Object.defineProperty(exports, "UnauthorizedError", { enumerable: true, get: function () { return types_1.UnauthorizedError; } }); | ||
Object.defineProperty(exports, "ServerError", { enumerable: true, get: function () { return types_1.ServerError; } }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var index_1 = require("../index"); | ||
test('My Greeter', function () { | ||
expect((0, index_1.Greeter)('Carl')).toBe('Hello Carl'); | ||
var Api_1 = require("../Api"); | ||
// jest.setMock("cross-fetch", fetchMock); | ||
describe('Api', function () { | ||
it('should be constructable without ApiConfig', function () { | ||
var api = new Api_1.Api(); | ||
expect(api).toBeDefined(); | ||
}); | ||
it('should be constructable with only a partial ApiConfig', function () { | ||
var api = new Api_1.Api({ | ||
workspace: 'my-workspace', | ||
}); | ||
expect(api.workspace).toEqual('my-workspace'); | ||
api = new Api_1.Api({ | ||
config: 'my-config', | ||
}); | ||
expect(api.config).toEqual('my-config'); | ||
api = new Api_1.Api({ | ||
version: 'my-version', | ||
}); | ||
expect(api.version).toEqual('my-version'); | ||
api = new Api_1.Api({ | ||
baseUrl: 'my-base-url', | ||
}); | ||
expect(api.baseUrl).toEqual('my-base-url'); | ||
api = new Api_1.Api({ | ||
workspace: 'my-workspace', | ||
version: 'my-version', | ||
}); | ||
expect(api.workspace).toEqual('my-workspace'); | ||
expect(api.version).toEqual('my-version'); | ||
}); | ||
it('should have a default base URL', function () { | ||
var api = new Api_1.Api(); | ||
expect(api.baseUrl).toEqual('https://rest.spinque.com/'); | ||
}); | ||
// it('should not try to fetch 0 queries', async () => { | ||
// const api = new Api({ workspace: 'my-workspace' }); | ||
// const queries: Query[] = []; | ||
// const res = api.fetch(queries).catch((error) => { | ||
// console.log(error); | ||
// expect(error).toEqual(''); | ||
// }); | ||
// await res; | ||
// expect(1).toEqual(1); | ||
// // expect(() => { | ||
// // }).toThrow(); | ||
// }); | ||
// it('should not try to fetch without workspace', () => { | ||
// const api = new Api(); | ||
// const queries: Query[] = [{ endpoint: 'my-endpoint' }]; | ||
// expect(() => { | ||
// api.fetch(queries); | ||
// }).toThrow(); | ||
// }); | ||
// it('should try to fetch single query', async () => { | ||
// const api = new Api({ workspace: 'my-workspace' }); | ||
// const queries: Query[] = [{ endpoint: 'my-endpoint' }]; | ||
// const response = await api.fetch(queries); | ||
// expect(response).toBeDefined(); | ||
// }); | ||
}); |
{ | ||
"name": "@spinque/query-api", | ||
"version": "0.0.1", | ||
"version": "0.2.0", | ||
"description": "", | ||
@@ -9,10 +9,11 @@ "main": "dist/index.js", | ||
"build": "tsc", | ||
"demo": "npx ts-node -r tsconfig-paths/register ./demo", | ||
"format": "prettier --write \"src/**/*.ts\"", | ||
"lint": "tslint -p tsconfig.json", | ||
"test": "jest --config jestconfig.json", | ||
"prepare" : "npm run build", | ||
"prepublishOnly" : "npm test && npm run lint", | ||
"preversion" : "npm run lint", | ||
"version" : "npm run format && git add -A src", | ||
"postversion" : "git push && git push --tags" | ||
"prepare": "npm run build", | ||
"prepublishOnly": "npm test && npm run lint", | ||
"preversion": "npm run lint", | ||
"version": "npm run format && git add -A src", | ||
"postversion": "git push && git push --tags" | ||
}, | ||
@@ -28,8 +29,16 @@ "files": [ | ||
"jest": "^27.5.1", | ||
"jest-fetch-mock": "^3.0.3", | ||
"prettier": "^2.5.1", | ||
"ts-jest": "^27.1.3", | ||
"ts-node": "^10.6.0", | ||
"tsconfig-paths": "^3.13.0", | ||
"tslint": "^6.1.3", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "^4.6.2" | ||
}, | ||
"dependencies": { | ||
"browser-or-node": "^2.0.0", | ||
"cross-fetch": "^3.1.5", | ||
"path-browserify": "^1.0.1" | ||
} | ||
} |
@@ -0,8 +1,60 @@ | ||
# @spinque/query-api | ||
# spinque-query-api-ts | ||
TypeScript library to use the Spinque Query API in your project. | ||
Bootstrapped with TS-Proj | ||
Visit https://npmjs.com/package/ts-proj to install the CLI! | ||
## Basic usage | ||
Defining a single query: | ||
```typescript | ||
import { Query } from '@spinque/query-api'; | ||
const single_query: Query = { | ||
endpoint: 'movie_search', | ||
parameters: { terms: 'call me' } | ||
}; | ||
``` | ||
Stacking queries, for example for faceted search: | ||
```typescript | ||
const stacked_queries: Query[] = [{ | ||
endpoint: 'movie_search', | ||
parameters: { terms: 'call me' } | ||
}, { | ||
endpoint: 'genres' | ||
}]; | ||
``` | ||
Fetching results for a single query using an instance of the Api class: | ||
```typescript | ||
import { Api } from '@spinque/query-api'; | ||
const api = new Api({ | ||
workspace: 'my-workspace', | ||
config: 'default', | ||
api: 'movies' | ||
}); | ||
try { | ||
const response = await api.fetch(query, { count: 10, offset: 0 }); | ||
} catch (error: any) { | ||
console.error(error); | ||
} | ||
``` | ||
Getting the URL for a request to fetch it using your own HTTP-library of preference: | ||
```typescript | ||
import { Api } from '@spinque/query-api'; | ||
const apiConfig = { | ||
workspace: 'my-workspace', | ||
config: 'default', | ||
api: 'movies' | ||
}; | ||
const url = urlFromQueries(apiConfig, query, { count: 10, offset: 0 }); | ||
``` | ||
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
26011
12
584
61
3
10
1
+ Addedbrowser-or-node@^2.0.0
+ Addedcross-fetch@^3.1.5
+ Addedpath-browserify@^1.0.1
+ Addedbrowser-or-node@2.1.1(transitive)
+ Addedcross-fetch@3.1.8(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedpath-browserify@1.0.1(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)