@sockethub/schemas 3.0.0-alpha.3 → 3.0.0-alpha.4

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.
@@ -12,15 +12,11 @@ function parseMsg(error) {
12
12
  return err;
13
13
  }
14
14
  function getTypeList(msg) {
15
+ var _a;
15
16
  let types = [];
16
- if ((typeof msg === 'object') && (msg.type)) {
17
- types.push(msg.type);
18
- }
19
- else {
20
- types.push(undefined);
21
- }
22
- for (let prop in msg) {
23
- if ((typeof msg[prop] === 'object') && (msg[prop].type)) {
17
+ types.push(msg === null || msg === void 0 ? void 0 : msg.type);
18
+ for (const prop in msg) {
19
+ if ((_a = msg[prop]) === null || _a === void 0 ? void 0 : _a.type) {
24
20
  types = [...types, ...getTypeList(msg[prop])];
25
21
  }
26
22
  }
@@ -31,7 +27,7 @@ function getSchemaType(error) {
31
27
  return schemaTypeRes ? schemaTypeRes[1] : undefined;
32
28
  }
33
29
  function getErrType(error) {
34
- const errTypeRes = error.instancePath.match(/\/([\w]+)/);
30
+ const errTypeRes = error.instancePath.match(/\/(\w+)/);
35
31
  return errTypeRes ? errTypeRes[1] : undefined;
36
32
  }
37
33
  function getPartsCount(error, types) {
@@ -40,6 +36,9 @@ function getPartsCount(error, types) {
40
36
  if (!errType) {
41
37
  return -1;
42
38
  }
39
+ if (!types[errType]) {
40
+ return -1;
41
+ }
43
42
  if (!types[errType].includes(schemaType)) {
44
43
  return -1;
45
44
  }
@@ -78,7 +77,7 @@ exports.default = getErrorMessage;
78
77
  function composeFinalError(error) {
79
78
  // if we have yet to build an error message, assume this is an invalid type value (oneOf),
80
79
  // try to build a list of valid types
81
- let msg = "";
80
+ let msg;
82
81
  if (error.keyword === 'oneOf') {
83
82
  msg = `${error.instancePath}: ${error.message}: ` +
84
83
  `${objects_1.ObjectTypesList.join(', ')}`;
@@ -208,7 +208,7 @@ exports.ObjectTypesSchema = {
208
208
  }
209
209
  };
210
210
  exports.ObjectTypesList = Object.keys(exports.ObjectTypesSchema);
211
- exports.ObjectTypesList.forEach(function (type, i) {
211
+ exports.ObjectTypesList.forEach(function (type) {
212
212
  if (type === 'credentials') {
213
213
  return;
214
214
  }
package/dist/index.d.ts CHANGED
@@ -12,4 +12,4 @@ declare const _default: {
12
12
  };
13
13
  export default _default;
14
14
  export { PlatformSchema, ActivityObjectSchema, ActivityStreamSchema, ObjectTypesList };
15
- export { IActivityStream, IActivityObject } from "./types";
15
+ export * from "./types";
package/dist/index.js CHANGED
@@ -1,4 +1,18 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
18
  };
@@ -20,3 +34,4 @@ exports.default = {
20
34
  validateActivityStream: validator_1.validateActivityStream,
21
35
  validateActivityObject: validator_1.validateActivityObject,
22
36
  };
37
+ __exportStar(require("./types"), exports);
@@ -15,6 +15,24 @@ declare const _default: ((string | boolean | {
15
15
  type: string;
16
16
  content: string;
17
17
  };
18
+ })[] | (string | boolean | {
19
+ type: string;
20
+ context: string;
21
+ published: string;
22
+ actor: {
23
+ id: string;
24
+ type: string;
25
+ name: string;
26
+ };
27
+ target: {
28
+ id: string;
29
+ type: string;
30
+ name: string;
31
+ };
32
+ object: {
33
+ type: string;
34
+ content: string;
35
+ };
18
36
  })[] | (string | boolean | {
19
37
  type: string;
20
38
  context: string;
@@ -25,6 +25,30 @@ exports.default = [
25
25
  true,
26
26
  ''
27
27
  ],
28
+ [
29
+ 'type:send, object:message bad published value',
30
+ {
31
+ type: 'send',
32
+ context: 'irc',
33
+ published: "foo",
34
+ actor: {
35
+ id: 'dood@irc.freenode.net',
36
+ type: 'person',
37
+ name: 'dood'
38
+ },
39
+ target: {
40
+ id: 'irc.freenode.net/server',
41
+ type: 'room',
42
+ name: 'sockethub'
43
+ },
44
+ object: {
45
+ type: 'message',
46
+ content: 'some kind of message'
47
+ }
48
+ },
49
+ false,
50
+ '/published: must match format "date-time"'
51
+ ],
28
52
  [
29
53
  'type:credentials, object:credentials',
30
54
  {
@@ -25,6 +25,10 @@ declare const _default: {
25
25
  type: string;
26
26
  oneOf: any[];
27
27
  };
28
+ published: {
29
+ type: string;
30
+ format: string;
31
+ };
28
32
  };
29
33
  definitions: {
30
34
  type: {
@@ -9,8 +9,8 @@ const validActorRefs = activity_object_1.default.properties.object.oneOf;
9
9
  const validTargetRefs = activity_object_1.default.properties.object.oneOf;
10
10
  // eslint-disable-next-line security-node/detect-crlf
11
11
  console.log(validActorRefs);
12
- let validObjectRefs = [];
13
- objects_1.ObjectTypesList.forEach(function (type, i) {
12
+ const validObjectRefs = [];
13
+ objects_1.ObjectTypesList.forEach(function (type) {
14
14
  validObjectRefs.push({ "$ref": "#/definitions/type/" + type });
15
15
  });
16
16
  const contextSchema = {
@@ -41,6 +41,10 @@ exports.default = {
41
41
  "object": {
42
42
  "type": "object",
43
43
  "oneOf": validObjectRefs
44
+ },
45
+ "published": {
46
+ "type": "string",
47
+ "format": "date-time"
44
48
  }
45
49
  },
46
50
  "definitions": {
@@ -142,6 +142,10 @@
142
142
  "$ref": "#/definitions/type/address"
143
143
  }
144
144
  ]
145
+ },
146
+ "published": {
147
+ "type": "string",
148
+ "format": "date-time"
145
149
  }
146
150
  },
147
151
  "definitions": {
package/dist/types.d.ts CHANGED
@@ -16,5 +16,19 @@ export interface IActivityObjectActor extends IActivityObject {
16
16
  name?: string;
17
17
  }
18
18
  export interface IActivityObjectObject extends IActivityObject {
19
- content?: any;
19
+ content?: never;
20
20
  }
21
+ declare type ErrorMsg = string | Error;
22
+ export interface CallbackInterface {
23
+ (err?: ErrorMsg, data?: unknown): void;
24
+ }
25
+ export interface CallbackActivityStreamInterface {
26
+ (data: IActivityStream | Error): void;
27
+ }
28
+ export interface CompletedJobHandler {
29
+ (data: IActivityStream): void;
30
+ }
31
+ export interface LogInterface {
32
+ (msg: string): void;
33
+ }
34
+ export {};
package/dist/validator.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getPlatformSchema = exports.addPlatformSchema = exports.validatePlatformSchema = exports.validateCredentials = exports.validateActivityStream = exports.validateActivityObject = void 0;
7
7
  const debug_1 = __importDefault(require("debug"));
8
8
  const ajv_1 = __importDefault(require("ajv"));
9
+ const ajv_formats_1 = __importDefault(require("ajv-formats"));
9
10
  const ajv_formats_draft2019_1 = __importDefault(require("ajv-formats-draft2019"));
10
11
  const error_parser_1 = __importDefault(require("./helpers/error-parser"));
11
12
  const platform_1 = __importDefault(require("./schemas/platform"));
@@ -13,12 +14,13 @@ const activity_stream_1 = __importDefault(require("./schemas/activity-stream"));
13
14
  const activity_object_1 = __importDefault(require("./schemas/activity-object"));
14
15
  const log = (0, debug_1.default)('sockethub:schemas');
15
16
  const ajv = new ajv_1.default({ strictTypes: false, allErrors: true });
17
+ (0, ajv_formats_1.default)(ajv);
16
18
  (0, ajv_formats_draft2019_1.default)(ajv);
17
19
  const schemaURL = 'https://sockethub.org/schemas/v0';
18
20
  const schemas = {};
19
21
  schemas[`${schemaURL}/activity-stream`] = activity_stream_1.default;
20
22
  schemas[`${schemaURL}/activity-object`] = activity_object_1.default;
21
- for (let uri in schemas) {
23
+ for (const uri in schemas) {
22
24
  log(`registering schema ${uri}`);
23
25
  ajv.addSchema(schemas[uri], uri);
24
26
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sockethub/schemas",
3
3
  "description": "JSON schema files for validating Sockethub Activity Streams",
4
- "version": "3.0.0-alpha.3",
4
+ "version": "3.0.0-alpha.4",
5
5
  "private": false,
6
6
  "author": "Nick Jennings <nick@silverbucket.net>",
7
7
  "license": "MIT",
@@ -25,19 +25,19 @@
25
25
  },
26
26
  "homepage": "https://github.com/sockethub/sockethub/tree/master/packages/schemas",
27
27
  "devDependencies": {
28
- "@types/chai": "4.3.0",
28
+ "@types/chai": "4.3.3",
29
29
  "@types/debug": "4.1.7",
30
- "@types/eslint": "8.4.1",
31
- "@types/mocha": "9.1.0",
30
+ "@types/eslint": "8.4.6",
31
+ "@types/mocha": "9.1.1",
32
32
  "@types/node": "17.0.13",
33
- "@typescript-eslint/parser": "5.12.1",
34
- "c8": "7.11.0",
33
+ "@typescript-eslint/parser": "5.37.0",
34
+ "c8": "7.12.0",
35
35
  "chai": "4.3.6",
36
- "eslint": "8.9.0",
36
+ "eslint": "8.23.1",
37
37
  "eslint-cli": "1.1.1",
38
- "mocha": "9.2.1",
39
- "ts-node": "10.5.0",
40
- "typescript": "4.5.5"
38
+ "mocha": "10.0.0",
39
+ "ts-node": "10.9.1",
40
+ "typescript": "4.8.3"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "npx rimraf dist && tsc && ./scripts/export-json-schema.js",
@@ -50,9 +50,10 @@
50
50
  "test": "c8 mocha -r ts-node/register src/**/*.test.ts"
51
51
  },
52
52
  "dependencies": {
53
- "ajv": "8.10.0",
53
+ "ajv": "8.11.0",
54
+ "ajv-formats": "^2.1.1",
54
55
  "ajv-formats-draft2019": "1.6.1",
55
56
  "debug": "^4.3.1"
56
57
  },
57
- "gitHead": "f02238a478b7ffd3f31d8deea292eb67e630a86b"
58
+ "gitHead": "c6d34ff44d2be479e4ea42c46da649612342a680"
58
59
  }
@@ -20,13 +20,9 @@ function parseMsg(error: ErrorObject): string {
20
20
 
21
21
  function getTypeList(msg: IActivityStream | IActivityObject): Array<string> {
22
22
  let types = [];
23
- if ((typeof msg === 'object') && (msg.type)) {
24
- types.push(msg.type);
25
- } else {
26
- types.push(undefined);
27
- }
28
- for (let prop in msg) {
29
- if ((typeof msg[prop] === 'object') && (msg[prop].type)) {
23
+ types.push(msg?.type);
24
+ for (const prop in msg) {
25
+ if (msg[prop]?.type) {
30
26
  types = [...types, ...getTypeList(msg[prop])];
31
27
  }
32
28
  }
@@ -39,7 +35,7 @@ function getSchemaType(error: ErrorObject): string {
39
35
  }
40
36
 
41
37
  function getErrType(error: ErrorObject): string {
42
- const errTypeRes = error.instancePath.match(/\/([\w]+)/);
38
+ const errTypeRes = error.instancePath.match(/\/(\w+)/);
43
39
  return errTypeRes ? errTypeRes[1] : undefined;
44
40
  }
45
41
 
@@ -47,6 +43,7 @@ function getPartsCount(error: ErrorObject, types: TypeBreakdown): number {
47
43
  const schemaType = getSchemaType(error);
48
44
  const errType = getErrType(error);
49
45
  if (!errType) { return -1; }
46
+ if (!types[errType]) { return -1; }
50
47
  if (!types[errType].includes(schemaType)) { return -1; }
51
48
  const parts = error.instancePath.split('/');
52
49
  return parts.length;
@@ -87,7 +84,7 @@ export default function getErrorMessage(msg, errors: Array<ErrorObject>): string
87
84
  function composeFinalError(error) {
88
85
  // if we have yet to build an error message, assume this is an invalid type value (oneOf),
89
86
  // try to build a list of valid types
90
- let msg = "";
87
+ let msg: string;
91
88
  if (error.keyword === 'oneOf') {
92
89
  msg = `${error.instancePath}: ${error.message}: ` +
93
90
  `${ObjectTypesList.join(', ')}`;
@@ -221,7 +221,7 @@ export const ObjectTypesSchema = {
221
221
 
222
222
  export const ObjectTypesList = Object.keys(ObjectTypesSchema);
223
223
 
224
- ObjectTypesList.forEach(function (type, i) {
224
+ ObjectTypesList.forEach(function (type) {
225
225
  if (type === 'credentials') {
226
226
  return;
227
227
  }
@@ -25,6 +25,31 @@ export default [
25
25
  ''
26
26
  ],
27
27
 
28
+ [
29
+ 'type:send, object:message bad published value',
30
+ {
31
+ type: 'send',
32
+ context: 'irc',
33
+ published: "foo",
34
+ actor: {
35
+ id: 'dood@irc.freenode.net',
36
+ type: 'person',
37
+ name: 'dood'
38
+ },
39
+ target: {
40
+ id: 'irc.freenode.net/server',
41
+ type: 'room',
42
+ name: 'sockethub'
43
+ },
44
+ object: {
45
+ type: 'message',
46
+ content: 'some kind of message'
47
+ }
48
+ },
49
+ false,
50
+ '/published: must match format "date-time"'
51
+ ],
52
+
28
53
  [
29
54
  'type:credentials, object:credentials',
30
55
  {
package/src/index.test.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import {IActivityStream} from "./types";
2
+
1
3
  const chai = require('chai');
2
4
  const expect = chai.expect;
3
5
 
@@ -56,8 +58,7 @@ describe('ActivityObject', () => {
56
58
  testActivityObjectsData.forEach(([name, ao, expectedResult, expectedFailureMessage]) => {
57
59
  describe("validateActivityObject " + name, () => {
58
60
  it(`returns expected result`, () => {
59
- // @ts-ignore
60
- const err = validateActivityObject(ao);
61
+ const err = validateActivityObject(ao as IActivityStream);
61
62
  expect(err).to.equal(expectedFailureMessage);
62
63
  expect(!err).to.equal(expectedResult);
63
64
  });
package/src/index.ts CHANGED
@@ -20,7 +20,4 @@ export {
20
20
  ObjectTypesList
21
21
  };
22
22
 
23
- export {
24
- IActivityStream,
25
- IActivityObject
26
- } from "./types";
23
+ export * from "./types";
@@ -6,9 +6,9 @@ const validTargetRefs = activityObject.properties.object.oneOf;
6
6
  // eslint-disable-next-line security-node/detect-crlf
7
7
  console.log(validActorRefs);
8
8
 
9
- let validObjectRefs = [];
9
+ const validObjectRefs = [];
10
10
 
11
- ObjectTypesList.forEach(function (type, i) {
11
+ ObjectTypesList.forEach(function (type) {
12
12
  validObjectRefs.push({ "$ref": "#/definitions/type/" + type });
13
13
  });
14
14
 
@@ -42,6 +42,10 @@ export default {
42
42
  "object": {
43
43
  "type": "object",
44
44
  "oneOf": validObjectRefs
45
+ },
46
+ "published": {
47
+ "type": "string",
48
+ "format": "date-time"
45
49
  }
46
50
  },
47
51
 
package/src/types.ts CHANGED
@@ -19,5 +19,24 @@ export interface IActivityObjectActor extends IActivityObject {
19
19
  }
20
20
 
21
21
  export interface IActivityObjectObject extends IActivityObject {
22
- content?: any;
22
+ content?: never;
23
23
  }
24
+
25
+ type ErrorMsg = string | Error;
26
+
27
+ export interface CallbackInterface {
28
+ (err?: ErrorMsg, data?: unknown): void;
29
+ }
30
+
31
+ export interface CallbackActivityStreamInterface {
32
+ (data: IActivityStream | Error): void;
33
+ }
34
+
35
+ export interface CompletedJobHandler {
36
+ (data: IActivityStream): void;
37
+ }
38
+
39
+ export interface LogInterface {
40
+ (msg: string): void;
41
+ }
42
+
package/src/validator.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import debug from 'debug';
2
2
  import Ajv, {Schema} from 'ajv';
3
- import ajvFormat2019 from 'ajv-formats-draft2019';
3
+ import addFormats from 'ajv-formats';
4
+ import additionsFormats2019 from 'ajv-formats-draft2019';
4
5
  import getErrorMessage from "./helpers/error-parser";
5
6
  import {IActivityStream} from "./types";
6
7
  import PlatformSchema from './schemas/platform';
@@ -8,7 +9,8 @@ import ActivityStreamsSchema from './schemas/activity-stream';
8
9
  import ActivityObjectSchema from './schemas/activity-object';
9
10
  const log = debug('sockethub:schemas');
10
11
  const ajv = new Ajv({strictTypes: false, allErrors: true});
11
- ajvFormat2019(ajv);
12
+ addFormats(ajv);
13
+ additionsFormats2019(ajv);
12
14
 
13
15
  interface SchemasDict {
14
16
  string?: Schema
@@ -20,7 +22,7 @@ const schemas: SchemasDict = {};
20
22
  schemas[`${schemaURL}/activity-stream`] = ActivityStreamsSchema;
21
23
  schemas[`${schemaURL}/activity-object`] = ActivityObjectSchema;
22
24
 
23
- for (let uri in schemas) {
25
+ for (const uri in schemas) {
24
26
  log(`registering schema ${uri}`);
25
27
  ajv.addSchema(schemas[uri], uri);
26
28
  }