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

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.
Files changed (43) hide show
  1. package/package.json +16 -32
  2. package/src/index.ts +23 -19
  3. package/src/schemas/activity-object.ts +15 -15
  4. package/src/schemas/activity-stream.ts +40 -41
  5. package/{dist → src}/schemas/json/activity-object.json +1 -1
  6. package/{dist → src}/schemas/json/activity-stream.json +1 -1
  7. package/{dist → src}/schemas/json/platform.json +1 -0
  8. package/src/schemas/json/sockethub-config.json +144 -0
  9. package/src/schemas/platform.ts +22 -22
  10. package/src/schemas/sockethub-config.ts +140 -0
  11. package/dist/helpers/error-parser.d.ts +0 -9
  12. package/dist/helpers/error-parser.js +0 -90
  13. package/dist/helpers/objects.d.ts +0 -206
  14. package/dist/helpers/objects.js +0 -217
  15. package/dist/index.d.ts +0 -15
  16. package/dist/index.js +0 -37
  17. package/dist/index.test.data.credentials.d.ts +0 -37
  18. package/dist/index.test.data.credentials.js +0 -69
  19. package/dist/index.test.data.objects.d.ts +0 -50
  20. package/dist/index.test.data.objects.js +0 -214
  21. package/dist/index.test.data.platform.d.ts +0 -44
  22. package/dist/index.test.data.platform.js +0 -47
  23. package/dist/index.test.data.streams.d.ts +0 -274
  24. package/dist/index.test.data.streams.js +0 -473
  25. package/dist/schemas/activity-object.d.ts +0 -16
  26. package/dist/schemas/activity-object.js +0 -18
  27. package/dist/schemas/activity-stream.d.ts +0 -239
  28. package/dist/schemas/activity-stream.js +0 -53
  29. package/dist/schemas/platform.d.ts +0 -41
  30. package/dist/schemas/platform.js +0 -44
  31. package/dist/types.d.ts +0 -34
  32. package/dist/types.js +0 -2
  33. package/dist/validator.d.ts +0 -8
  34. package/dist/validator.js +0 -80
  35. package/src/helpers/error-parser.ts +0 -96
  36. package/src/helpers/objects.ts +0 -230
  37. package/src/index.test.data.credentials.ts +0 -71
  38. package/src/index.test.data.objects.ts +0 -235
  39. package/src/index.test.data.platform.ts +0 -45
  40. package/src/index.test.data.streams.ts +0 -495
  41. package/src/index.test.ts +0 -85
  42. package/src/types.ts +0 -42
  43. package/src/validator.ts +0 -81
package/package.json CHANGED
@@ -1,10 +1,18 @@
1
1
  {
2
2
  "name": "@sockethub/schemas",
3
3
  "description": "JSON schema files for validating Sockethub Activity Streams",
4
- "version": "3.0.0-alpha.4",
4
+ "version": "3.0.0-alpha.5",
5
+ "type": "module",
5
6
  "private": false,
6
7
  "author": "Nick Jennings <nick@silverbucket.net>",
7
8
  "license": "MIT",
9
+ "main": "src/index.ts",
10
+ "files": [
11
+ "src/schemas"
12
+ ],
13
+ "engines": {
14
+ "bun": ">=1.2"
15
+ },
8
16
  "keywords": [
9
17
  "sockethub",
10
18
  "sockethub schema",
@@ -12,12 +20,6 @@
12
20
  "activity objects",
13
21
  "sockethub platforms"
14
22
  ],
15
- "main": "dist/index.js",
16
- "types": "dist/index.d.ts",
17
- "files": [
18
- "dist/",
19
- "src/"
20
- ],
21
23
  "repository": {
22
24
  "type": "git",
23
25
  "url": "git+https://github.com/sockethub/sockethub.git",
@@ -25,35 +27,17 @@
25
27
  },
26
28
  "homepage": "https://github.com/sockethub/sockethub/tree/master/packages/schemas",
27
29
  "devDependencies": {
28
- "@types/chai": "4.3.3",
29
- "@types/debug": "4.1.7",
30
- "@types/eslint": "8.4.6",
31
- "@types/mocha": "9.1.1",
32
- "@types/node": "17.0.13",
33
- "@typescript-eslint/parser": "5.37.0",
34
- "c8": "7.12.0",
35
- "chai": "4.3.6",
36
- "eslint": "8.23.1",
37
- "eslint-cli": "1.1.1",
38
- "mocha": "10.0.0",
39
- "ts-node": "10.9.1",
40
- "typescript": "4.8.3"
30
+ "@types/bun": "latest",
31
+ "@types/debug": "4.1.12"
41
32
  },
42
33
  "scripts": {
43
- "build": "npx rimraf dist && tsc && ./scripts/export-json-schema.js",
44
- "clean": "npx rimraf coverage dist",
45
- "clean:deps": "npx rimraf node_modules",
46
- "compliance": "yarn test && yarn coverage",
47
- "coverage": "c8 check-coverage --statements 95 --branches 95 --functions 95 --lines 95",
48
- "lint": "eslint \"**/*.ts\"",
49
- "lint:fix": "eslint --fix \"**/*.ts\"",
50
- "test": "c8 mocha -r ts-node/register src/**/*.test.ts"
34
+ "build": "bun ./scripts/export-json-schema.ts"
51
35
  },
52
36
  "dependencies": {
53
- "ajv": "8.11.0",
54
- "ajv-formats": "^2.1.1",
37
+ "ajv": "8.12.0",
38
+ "ajv-formats": "2.1.1",
55
39
  "ajv-formats-draft2019": "1.6.1",
56
- "debug": "^4.3.1"
40
+ "debug": "4.3.4"
57
41
  },
58
- "gitHead": "c6d34ff44d2be479e4ea42c46da649612342a680"
42
+ "gitHead": "341ea9eeca6afd1442fe6e01457bc21d112b91a4"
59
43
  }
package/src/index.ts CHANGED
@@ -1,23 +1,27 @@
1
- import {addPlatformSchema, validateActivityObject, validateActivityStream, validateCredentials,
2
- validatePlatformSchema} from "./validator";
3
- import { ObjectTypesList } from "./helpers/objects";
4
- import ActivityObjectSchema from "./schemas/activity-object";
5
- import ActivityStreamSchema from "./schemas/activity-stream";
6
- import PlatformSchema from "./schemas/platform";
7
-
8
- export default {
9
- addPlatformSchema,
10
- validatePlatformSchema,
11
- validateCredentials,
12
- validateActivityStream,
13
- validateActivityObject,
14
- };
1
+ import { ObjectTypesList } from "./helpers/objects.js";
2
+ import { ActivityObjectSchema } from "./schemas/activity-object.js";
3
+ import { ActivityStreamSchema } from "./schemas/activity-stream.js";
4
+ import { PlatformSchema } from "./schemas/platform.js";
5
+ import {
6
+ addPlatformSchema,
7
+ getPlatformSchema,
8
+ validateActivityObject,
9
+ validateActivityStream,
10
+ validateCredentials,
11
+ validatePlatformSchema,
12
+ } from "./validator.js";
15
13
 
16
14
  export {
17
- PlatformSchema,
18
- ActivityObjectSchema,
19
- ActivityStreamSchema,
20
- ObjectTypesList
15
+ addPlatformSchema,
16
+ getPlatformSchema,
17
+ validatePlatformSchema,
18
+ validateCredentials,
19
+ validateActivityStream,
20
+ validateActivityObject,
21
+ PlatformSchema,
22
+ ActivityObjectSchema,
23
+ ActivityStreamSchema,
24
+ ObjectTypesList,
21
25
  };
22
26
 
23
- export * from "./types";
27
+ export * from "./types.js";
@@ -1,19 +1,19 @@
1
- import { validObjectRefs, validObjectDefs } from "../helpers/objects";
1
+ import { validObjectDefs, validObjectRefs } from "../helpers/objects.js";
2
2
 
3
- export default {
4
- "$id": "https://sockethub.org/schemas/v0/activity-object#",
5
- "description": "Schema for Sockethub Activity Objects",
3
+ export const ActivityObjectSchema = {
4
+ $id: "https://sockethub.org/schemas/v/activity-object.json",
5
+ description: "Schema for Sockethub Activity Objects",
6
6
 
7
- "type": "object",
8
- "required" : [ "object" ],
9
- "properties": {
10
- "object": {
11
- "type": "object",
12
- "oneOf": validObjectRefs
13
- }
14
- },
7
+ type: "object",
8
+ required: ["object"],
9
+ properties: {
10
+ object: {
11
+ type: "object",
12
+ oneOf: validObjectRefs,
13
+ },
14
+ },
15
15
 
16
- "definitions": {
17
- "type": validObjectDefs
18
- }
16
+ definitions: {
17
+ type: validObjectDefs,
18
+ },
19
19
  };
@@ -1,55 +1,54 @@
1
- import activityObject from "./activity-object";
2
- import { ObjectTypesList, ObjectTypesSchema } from "../helpers/objects";
1
+ import { ObjectTypesList, ObjectTypesSchema } from "../helpers/objects.js";
2
+ import { ActivityObjectSchema } from "./activity-object.js";
3
3
 
4
- const validActorRefs = activityObject.properties.object.oneOf;
5
- const validTargetRefs = activityObject.properties.object.oneOf;
6
- // eslint-disable-next-line security-node/detect-crlf
7
- console.log(validActorRefs);
4
+ const validActorRefs = ActivityObjectSchema.properties.object.oneOf;
5
+ const validTargetRefs = ActivityObjectSchema.properties.object.oneOf;
6
+ // console.log(validActorRefs);
8
7
 
9
8
  const validObjectRefs = [];
10
9
 
11
- ObjectTypesList.forEach(function (type) {
12
- validObjectRefs.push({ "$ref": "#/definitions/type/" + type });
13
- });
10
+ for (const type of ObjectTypesList) {
11
+ validObjectRefs.push({ $ref: `#/definitions/type/${type}` });
12
+ }
14
13
 
15
14
  const contextSchema = {
16
- "type": "string"
15
+ type: "string",
17
16
  };
18
17
  const typeSchema = {
19
- "type": "string"
18
+ type: "string",
20
19
  };
21
20
 
22
- export default {
23
- "$id": "https://sockethub.org/schemas/v0/activity-stream#",
24
- "description": "Schema for Sockethub Activity Streams",
21
+ export const ActivityStreamSchema = {
22
+ $id: "https://sockethub.org/schemas/v/activity-stream.json",
23
+ description: "Schema for Sockethub Activity Streams",
25
24
 
26
- "type": "object",
27
- "required" : [ "context", "type", "actor" ],
28
- "properties": {
29
- "id": {
30
- "type": "string"
25
+ type: "object",
26
+ required: ["context", "type", "actor"],
27
+ properties: {
28
+ id: {
29
+ type: "string",
30
+ },
31
+ type: typeSchema,
32
+ context: contextSchema,
33
+ actor: {
34
+ type: "object",
35
+ oneOf: validActorRefs,
36
+ },
37
+ target: {
38
+ type: "object",
39
+ oneOf: validTargetRefs,
40
+ },
41
+ object: {
42
+ type: "object",
43
+ oneOf: validObjectRefs,
44
+ },
45
+ published: {
46
+ type: "string",
47
+ format: "date-time",
48
+ },
31
49
  },
32
- "type": typeSchema,
33
- "context": contextSchema,
34
- "actor": {
35
- "type": "object",
36
- "oneOf": validActorRefs
37
- },
38
- "target": {
39
- "type": "object",
40
- "oneOf": validTargetRefs
41
- },
42
- "object": {
43
- "type": "object",
44
- "oneOf": validObjectRefs
45
- },
46
- "published": {
47
- "type": "string",
48
- "format": "date-time"
49
- }
50
- },
51
50
 
52
- "definitions": {
53
- "type": ObjectTypesSchema
54
- }
51
+ definitions: {
52
+ type: ObjectTypesSchema,
53
+ },
55
54
  };
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://sockethub.org/schemas/v0/activity-object#",
2
+ "$id": "https://sockethub.org/schemas/3.0.0-alpha.5/activity-object.json",
3
3
  "description": "Schema for Sockethub Activity Objects",
4
4
  "type": "object",
5
5
  "required": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://sockethub.org/schemas/v0/activity-stream#",
2
+ "$id": "https://sockethub.org/schemas/3.0.0-alpha.5/activity-stream.json",
3
3
  "description": "Schema for Sockethub Activity Streams",
4
4
  "type": "object",
5
5
  "required": [
@@ -1,4 +1,5 @@
1
1
  {
2
+ "$id": "https://sockethub.org/schemas/3.0.0-alpha.5/platform.json",
2
3
  "type": "object",
3
4
  "required": [
4
5
  "name",
@@ -0,0 +1,144 @@
1
+ {
2
+ "$id": "https://sockethub.org/schemas/3.0.0-alpha.5/sockethub-config.json",
3
+ "description": "Sockethub Config Schema",
4
+ "type": "object",
5
+ "required": [
6
+ "platforms"
7
+ ],
8
+ "properties": {
9
+ "examples": {
10
+ "type": "object",
11
+ "properties": {
12
+ "enabled": {
13
+ "type": "boolean",
14
+ "default": false
15
+ },
16
+ "secret": {
17
+ "type": "string",
18
+ "default": "1234567890"
19
+ }
20
+ },
21
+ "additionalProperties": false
22
+ },
23
+ "log_file": {
24
+ "type": "string"
25
+ },
26
+ "packageConfig": {
27
+ "type": "object",
28
+ "properties": {
29
+ "@sockethub/activity-streams": {
30
+ "type": "object",
31
+ "properties": {
32
+ "specialObjs": {
33
+ "type": "array",
34
+ "items": {
35
+ "type": "string"
36
+ },
37
+ "default": [
38
+ "credentials"
39
+ ]
40
+ },
41
+ "failOnUnknownObjectProperties": {
42
+ "type": "boolean",
43
+ "default": true
44
+ }
45
+ },
46
+ "additionalProperties": false
47
+ },
48
+ "@sockethub/platform-dummy": {
49
+ "type": "object",
50
+ "properties": {
51
+ "greeting": {
52
+ "type": "string",
53
+ "default": "Hello"
54
+ }
55
+ },
56
+ "additionalProperties": false
57
+ },
58
+ "@sockethub/platform-feeds": {
59
+ "type": "object",
60
+ "properties": {
61
+ "connectTimeoutMs": {
62
+ "type": "number"
63
+ }
64
+ },
65
+ "additionalProperties": false
66
+ },
67
+ "@sockethub/platform-irc": {
68
+ "type": "object",
69
+ "properties": {
70
+ "connectTimeoutMs": {
71
+ "type": "number"
72
+ }
73
+ },
74
+ "additionalProperties": false
75
+ },
76
+ "@sockethub/platform-xmpp": {
77
+ "type": "object",
78
+ "properties": {
79
+ "connectTimeoutMs": {
80
+ "type": "number"
81
+ }
82
+ },
83
+ "additionalProperties": false
84
+ }
85
+ }
86
+ },
87
+ "platforms": {
88
+ "type": "array",
89
+ "items": {
90
+ "type": "string"
91
+ }
92
+ },
93
+ "public": {
94
+ "type": "object",
95
+ "properties": {
96
+ "protocol": {
97
+ "type": "string",
98
+ "default": "http"
99
+ },
100
+ "host": {
101
+ "type": "string",
102
+ "default": "localhost"
103
+ },
104
+ "port": {
105
+ "type": "number",
106
+ "default": 10550
107
+ },
108
+ "path": {
109
+ "type": "string",
110
+ "default": "/"
111
+ }
112
+ },
113
+ "additionalProperties": false
114
+ },
115
+ "redis": {
116
+ "type": "object",
117
+ "properties": {
118
+ "url": {
119
+ "type": "string",
120
+ "default": "redis://127.0.0.1:6379"
121
+ }
122
+ },
123
+ "additionalProperties": false
124
+ },
125
+ "sockethub": {
126
+ "type": "object",
127
+ "properties": {
128
+ "port": {
129
+ "type": "number",
130
+ "default": 10550
131
+ },
132
+ "host": {
133
+ "type": "string",
134
+ "default": "localhost"
135
+ },
136
+ "path": {
137
+ "type": "string",
138
+ "default": "/sockethub"
139
+ }
140
+ },
141
+ "additionalProperties": false
142
+ }
143
+ }
144
+ }
@@ -18,30 +18,30 @@
18
18
 
19
19
  // this schema defines the general structure of the schema object which should
20
20
  // be returned from platforms.
21
- export default {
22
- 'type' : 'object',
23
- 'required': [ 'name', 'version', 'messages' ],
24
- 'additionalProperties': false,
25
- 'properties' : {
21
+ export const PlatformSchema = {
22
+ $id: "https://sockethub.org/schemas/v/platform.json",
23
+ type: "object",
24
+ required: ["name", "version", "messages"],
25
+ additionalProperties: false,
26
+ properties: {
27
+ credentials: {
28
+ title: "credentials",
29
+ type: "object",
30
+ },
26
31
 
27
- 'credentials' : {
28
- 'title': 'credentials',
29
- 'type': 'object'
30
- },
32
+ messages: {
33
+ title: "messages",
34
+ type: "object",
35
+ },
31
36
 
32
- 'messages' : {
33
- 'title': 'messages',
34
- 'type': 'object',
35
- },
37
+ name: {
38
+ title: "name",
39
+ type: "string",
40
+ },
36
41
 
37
- 'name' : {
38
- 'title': 'name',
39
- 'type': 'string',
42
+ version: {
43
+ title: "version",
44
+ type: "string",
45
+ },
40
46
  },
41
-
42
- 'version' : {
43
- 'title': 'version',
44
- 'type': 'string',
45
- }
46
- }
47
47
  };
@@ -0,0 +1,140 @@
1
+ const connectConfigPlatforms = {
2
+ connectTimeoutMs: {
3
+ type: "number",
4
+ },
5
+ };
6
+
7
+ export const SockethubConfigSchema = {
8
+ $id: "https://sockethub.org/schemas/v/sockethub-config.json",
9
+ description: "Sockethub Config Schema",
10
+ type: "object",
11
+ required: ["platforms"],
12
+ properties: {
13
+ examples: {
14
+ type: "object",
15
+ properties: {
16
+ enabled: {
17
+ type: "boolean",
18
+ default: false,
19
+ },
20
+ secret: {
21
+ type: "string",
22
+ default: "1234567890",
23
+ },
24
+ },
25
+ additionalProperties: false,
26
+ },
27
+ log_file: {
28
+ type: "string",
29
+ },
30
+ packageConfig: {
31
+ type: "object",
32
+ properties: {
33
+ "@sockethub/activity-streams": {
34
+ type: "object",
35
+ properties: {
36
+ specialObjs: {
37
+ type: "array",
38
+ items: {
39
+ type: "string",
40
+ },
41
+ default: ["credentials"],
42
+ },
43
+ failOnUnknownObjectProperties: {
44
+ type: "boolean",
45
+ default: true,
46
+ },
47
+ },
48
+ additionalProperties: false,
49
+ },
50
+ "@sockethub/platform-dummy": {
51
+ type: "object",
52
+ properties: {
53
+ greeting: {
54
+ type: "string",
55
+ default: "Hello",
56
+ },
57
+ },
58
+ additionalProperties: false,
59
+ },
60
+ "@sockethub/platform-feeds": {
61
+ type: "object",
62
+ properties: {
63
+ ...connectConfigPlatforms,
64
+ },
65
+ additionalProperties: false,
66
+ },
67
+ "@sockethub/platform-irc": {
68
+ type: "object",
69
+ properties: {
70
+ ...connectConfigPlatforms,
71
+ },
72
+ additionalProperties: false,
73
+ },
74
+ "@sockethub/platform-xmpp": {
75
+ type: "object",
76
+ properties: {
77
+ ...connectConfigPlatforms,
78
+ },
79
+ additionalProperties: false,
80
+ },
81
+ },
82
+ },
83
+ platforms: {
84
+ type: "array",
85
+ items: {
86
+ type: "string",
87
+ },
88
+ },
89
+ public: {
90
+ type: "object",
91
+ properties: {
92
+ protocol: {
93
+ type: "string",
94
+ default: "http",
95
+ },
96
+ host: {
97
+ type: "string",
98
+ default: "localhost",
99
+ },
100
+ port: {
101
+ type: "number",
102
+ default: 10550,
103
+ },
104
+ path: {
105
+ type: "string",
106
+ default: "/",
107
+ },
108
+ },
109
+ additionalProperties: false,
110
+ },
111
+ redis: {
112
+ type: "object",
113
+ properties: {
114
+ url: {
115
+ type: "string",
116
+ default: "redis://127.0.0.1:6379",
117
+ },
118
+ },
119
+ additionalProperties: false,
120
+ },
121
+ sockethub: {
122
+ type: "object",
123
+ properties: {
124
+ port: {
125
+ type: "number",
126
+ default: 10550,
127
+ },
128
+ host: {
129
+ type: "string",
130
+ default: "localhost",
131
+ },
132
+ path: {
133
+ type: "string",
134
+ default: "/sockethub",
135
+ },
136
+ },
137
+ additionalProperties: false,
138
+ },
139
+ },
140
+ };
@@ -1,9 +0,0 @@
1
- import { ErrorObject } from "ajv";
2
- /**
3
- * Traverses the errors array from ajv, and makes a series of filtering decisions to
4
- * try to arrive at the most useful error.
5
- * @param msg
6
- * @param errors
7
- * @returns {string}
8
- */
9
- export default function getErrorMessage(msg: any, errors: Array<ErrorObject>): string;