@kravc/dos 1.10.5 → 1.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kravc/dos",
3
- "version": "1.10.5",
3
+ "version": "1.10.6",
4
4
  "description": "Convention-based, easy-to-use library for building API-driven serverless services.",
5
5
  "keywords": [
6
6
  "Service",
@@ -25,7 +25,7 @@
25
25
  "author": "Alexander Kravets <a@kra.vc>",
26
26
  "license": "ISC",
27
27
  "dependencies": {
28
- "@kravc/schema": "^2.7.1",
28
+ "@kravc/schema": "^2.7.3",
29
29
  "cookie": "^1.0.1",
30
30
  "js-yaml": "^4.1.0",
31
31
  "jsonwebtoken": "^9.0.2",
package/src/Service.js CHANGED
@@ -26,7 +26,7 @@ class Service {
26
26
 
27
27
  if (!url.endsWith('/')) { url = url + '/' }
28
28
 
29
- const schemasMap = createSchemasMap(path)
29
+ const schemasMap = createSchemasMap(path, modules)
30
30
 
31
31
  let components = modules.filter(Component => !Component.types)
32
32
 
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ const { Schema } = require('@kravc/schema')
4
+
3
5
  const Health = require('examples/Health')
4
6
  const { expect } = require('chai')
5
7
  const ReadProfile = require('examples/ReadProfile')
@@ -16,7 +18,14 @@ const {
16
18
  Component,
17
19
  } = require('src')
18
20
 
21
+ const testSchema = new Schema({
22
+ test: {
23
+ type: 'string'
24
+ }
25
+ }, 'Test')
26
+
19
27
  const modules = [
28
+ testSchema,
20
29
  Health,
21
30
  ReadProfile,
22
31
  CreateProfile,
@@ -5,6 +5,8 @@ const { keyBy } = require('lodash')
5
5
  const loadSync = require('./loadSync')
6
6
  const { readdirSync, statSync } = require('fs')
7
7
 
8
+ const SCHEMA_CLASS_NAME = 'Schema'
9
+
8
10
  const listFilesSync = dir =>
9
11
  readdirSync(dir)
10
12
  .reduce((files, file) =>
@@ -18,10 +20,17 @@ const readSchemasSync = path =>
18
20
  .filter(fileName => fileName.endsWith('.yaml'))
19
21
  .map(schemaPath => loadSync(schemaPath))
20
22
 
21
- const createSchemasMap = path => {
23
+ const createSchemasMap = (path, modules) => {
22
24
  const yamlSchemas = readSchemasSync(path)
23
25
  const schemasMap = keyBy(yamlSchemas, 'id')
24
26
 
27
+ const schemas = modules
28
+ .filter(item => item.constructor.name === SCHEMA_CLASS_NAME)
29
+
30
+ for (const schema of schemas) {
31
+ schemasMap[schema.id] = schema
32
+ }
33
+
25
34
  return schemasMap
26
35
  }
27
36
 
package/src/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { Schema, SchemaAttributes } from '@kravc/schema';
1
2
 
2
3
  export declare type SortOrder = 'asc' | 'desc';
3
4
  export declare type Context = Record<string, any>;
@@ -30,6 +31,9 @@ export declare class Document<T> {
30
31
  static get idKeyPrefix(): string;
31
32
  static get documentName(): string;
32
33
 
34
+ static set schema(schema: Schema): void;
35
+ static get schema(): Schema;
36
+
33
37
  static _read(query: QueryMap): Promise<AttributesMap>;
34
38
  static _create(attributes: AttributesMap): Promise<Boolean>;
35
39
  static _update(query: QueryMap, mutation: UpdateMutationMap): Promise<AttributesMap>;
@@ -149,3 +153,90 @@ export declare function verifyToken(
149
153
  publicKey: string,
150
154
  algorithm: string,
151
155
  ): Promise<[ boolean, string | undefined ]>;
156
+
157
+ export declare class JwtAuthorization {
158
+ static createRequirement(options: {
159
+ publicKey: string;
160
+ name?: string;
161
+ publicKey?: string;
162
+ algorithm?: string;
163
+ cookieName?: string;
164
+ normalizePayload?: Function;
165
+ tokenVerificationMethod?: Function;
166
+ accessVerificationMethod?: Function;
167
+ }): Record<string, any>
168
+ };
169
+
170
+ export declare class SystemAuthorization {
171
+ static createRequirement(options?: {
172
+ name?: string;
173
+ } = {}): Record<string, any>
174
+ };
175
+
176
+ type ComponentConstructor = new (...args: any[]) => any;
177
+ type OperationConstructor = new (...args: any[]) => any;
178
+
179
+ export declare class Operation {
180
+ public context: Context;
181
+ static get query(): SchemaAttributes | null;
182
+ static get mutation(): Schema | SchemaAttributes | null;
183
+ static get output(): Schema | SchemaAttributes | null;
184
+ }
185
+
186
+ export declare function Read(
187
+ Component: ComponentConstructor,
188
+ componentAction?: string
189
+ ): typeof Operation;
190
+
191
+ export declare function Create(
192
+ Component: ComponentConstructor,
193
+ componentAction?: string
194
+ ): typeof Operation;
195
+
196
+ export declare function Update(
197
+ Component: ComponentConstructor,
198
+ componentAction?: string
199
+ ): typeof Operation;
200
+
201
+ export declare function Delete(
202
+ Component: ComponentConstructor,
203
+ componentAction?: string
204
+ ): typeof Operation;
205
+
206
+ export declare function Index(
207
+ Component: ComponentConstructor,
208
+ componentAction?: string
209
+ ): typeof Operation;
210
+
211
+ declare type Module = Operation | Schema | ComponentConstructor;
212
+
213
+ interface ISpec {
214
+ paths: Record<string, unknown>;
215
+ }
216
+
217
+ interface IRequest {
218
+ url: string;
219
+ body?: string | Record<string, unknown>;
220
+ method: string;
221
+ headers: Record<string, any>;
222
+ operationId?: string;
223
+ };
224
+
225
+ interface IResponse {
226
+ body?: string,
227
+ headers: Record<string, string>,
228
+ statusCode: number,
229
+ }
230
+
231
+ export declare class Service {
232
+ constructor(modules: Module[], options: {
233
+ url?: string;
234
+ path?: string;
235
+ skipOperations?: string[];
236
+ });
237
+
238
+ get spec(): ISpec;
239
+ get baseUrl(): string;
240
+
241
+ async handler(request: IRequest, Context): Promise<IResponse>;
242
+ }