@polytric/openws-spec 0.0.1 → 0.0.3
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/README.md +399 -71
- package/dist/builder.cjs +380 -0
- package/dist/builder.cjs.map +1 -0
- package/dist/builder.d.cts +77 -0
- package/dist/builder.d.ts +77 -0
- package/dist/builder.js +345 -0
- package/dist/builder.js.map +1 -0
- package/dist/index.cjs +162 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +139 -0
- package/dist/index.d.ts +139 -0
- package/dist/index.js +123 -0
- package/dist/index.js.map +1 -0
- package/dist/types.cjs +19 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +42 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/package.json +41 -14
- package/index.js +0 -11
- package/spec.js +0 -62
- package/spec.json +0 -1
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
var type = "object";
|
|
2
|
+
var properties = {
|
|
3
|
+
openws: {
|
|
4
|
+
type: "string",
|
|
5
|
+
"enum": [
|
|
6
|
+
"0.0.1",
|
|
7
|
+
"0.0.2"
|
|
8
|
+
],
|
|
9
|
+
description: "The OpenWS schema version"
|
|
10
|
+
},
|
|
11
|
+
name: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "A title for the overall system."
|
|
14
|
+
},
|
|
15
|
+
description: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "A high level description of the overall system, including all networks and all roles"
|
|
18
|
+
},
|
|
19
|
+
version: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "A version string"
|
|
22
|
+
},
|
|
23
|
+
networks: {
|
|
24
|
+
type: "object",
|
|
25
|
+
minProperties: 1,
|
|
26
|
+
patternProperties: {
|
|
27
|
+
"^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$": {
|
|
28
|
+
type: "object",
|
|
29
|
+
properties: {
|
|
30
|
+
roles: {
|
|
31
|
+
type: "object",
|
|
32
|
+
minProperties: 1,
|
|
33
|
+
description: "A network is a collection of roles that exchange messages. Multiple roles can coexist in the same network. The simplest network contains a server-client pair.",
|
|
34
|
+
patternProperties: {
|
|
35
|
+
"^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$": {
|
|
36
|
+
type: "object",
|
|
37
|
+
properties: {
|
|
38
|
+
endpoints: {
|
|
39
|
+
type: "array",
|
|
40
|
+
items: {
|
|
41
|
+
type: "object",
|
|
42
|
+
properties: {
|
|
43
|
+
host: {
|
|
44
|
+
type: "string"
|
|
45
|
+
},
|
|
46
|
+
port: {
|
|
47
|
+
type: "integer",
|
|
48
|
+
minimum: 1,
|
|
49
|
+
maximum: 65535
|
|
50
|
+
},
|
|
51
|
+
path: {
|
|
52
|
+
type: "string"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
required: [
|
|
56
|
+
"host",
|
|
57
|
+
"port",
|
|
58
|
+
"path"
|
|
59
|
+
],
|
|
60
|
+
additionalProperties: true
|
|
61
|
+
},
|
|
62
|
+
minItems: 1,
|
|
63
|
+
description: "A role can declare an endpoint to accept connections from other roles, normally used by servers"
|
|
64
|
+
},
|
|
65
|
+
messages: {
|
|
66
|
+
type: "object",
|
|
67
|
+
patternProperties: {
|
|
68
|
+
"^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$": {
|
|
69
|
+
type: "object",
|
|
70
|
+
properties: {
|
|
71
|
+
payload: {
|
|
72
|
+
type: "object",
|
|
73
|
+
description: "Must be a valid JSON schema spec. For brevity, openws omits this spec, but implementations should valid this",
|
|
74
|
+
additionalProperties: true
|
|
75
|
+
},
|
|
76
|
+
description: {
|
|
77
|
+
type: "string"
|
|
78
|
+
},
|
|
79
|
+
from: {
|
|
80
|
+
type: "array",
|
|
81
|
+
items: {
|
|
82
|
+
type: "string"
|
|
83
|
+
},
|
|
84
|
+
description: "A list of roles that can send this message"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
required: [
|
|
88
|
+
"payload"
|
|
89
|
+
],
|
|
90
|
+
additionalProperties: true
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
description: "A message accepted by the role and handled by the role, and roles can send messages other roles accepts. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (through through description the behavior can be documented).",
|
|
94
|
+
additionalProperties: false
|
|
95
|
+
},
|
|
96
|
+
description: {
|
|
97
|
+
type: "string"
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
required: [
|
|
101
|
+
"messages"
|
|
102
|
+
],
|
|
103
|
+
additionalProperties: true
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
additionalProperties: false
|
|
107
|
+
},
|
|
108
|
+
description: {
|
|
109
|
+
type: "string"
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
required: [
|
|
113
|
+
"roles"
|
|
114
|
+
],
|
|
115
|
+
additionalProperties: true
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
additionalProperties: false
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var required = [
|
|
122
|
+
"openws",
|
|
123
|
+
"networks"
|
|
124
|
+
];
|
|
125
|
+
var additionalProperties = true;
|
|
126
|
+
var $schema = "http://json-schema.org/draft-07/schema#";
|
|
127
|
+
var specSchema = {
|
|
128
|
+
type: type,
|
|
129
|
+
properties: properties,
|
|
130
|
+
required: required,
|
|
131
|
+
additionalProperties: additionalProperties,
|
|
132
|
+
$schema: $schema
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
declare const VERSION: string;
|
|
136
|
+
|
|
137
|
+
declare function validate(spec: any): void;
|
|
138
|
+
|
|
139
|
+
export { VERSION, specSchema, validate };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
var type = "object";
|
|
2
|
+
var properties = {
|
|
3
|
+
openws: {
|
|
4
|
+
type: "string",
|
|
5
|
+
"enum": [
|
|
6
|
+
"0.0.1",
|
|
7
|
+
"0.0.2"
|
|
8
|
+
],
|
|
9
|
+
description: "The OpenWS schema version"
|
|
10
|
+
},
|
|
11
|
+
name: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "A title for the overall system."
|
|
14
|
+
},
|
|
15
|
+
description: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "A high level description of the overall system, including all networks and all roles"
|
|
18
|
+
},
|
|
19
|
+
version: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "A version string"
|
|
22
|
+
},
|
|
23
|
+
networks: {
|
|
24
|
+
type: "object",
|
|
25
|
+
minProperties: 1,
|
|
26
|
+
patternProperties: {
|
|
27
|
+
"^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$": {
|
|
28
|
+
type: "object",
|
|
29
|
+
properties: {
|
|
30
|
+
roles: {
|
|
31
|
+
type: "object",
|
|
32
|
+
minProperties: 1,
|
|
33
|
+
description: "A network is a collection of roles that exchange messages. Multiple roles can coexist in the same network. The simplest network contains a server-client pair.",
|
|
34
|
+
patternProperties: {
|
|
35
|
+
"^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$": {
|
|
36
|
+
type: "object",
|
|
37
|
+
properties: {
|
|
38
|
+
endpoints: {
|
|
39
|
+
type: "array",
|
|
40
|
+
items: {
|
|
41
|
+
type: "object",
|
|
42
|
+
properties: {
|
|
43
|
+
host: {
|
|
44
|
+
type: "string"
|
|
45
|
+
},
|
|
46
|
+
port: {
|
|
47
|
+
type: "integer",
|
|
48
|
+
minimum: 1,
|
|
49
|
+
maximum: 65535
|
|
50
|
+
},
|
|
51
|
+
path: {
|
|
52
|
+
type: "string"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
required: [
|
|
56
|
+
"host",
|
|
57
|
+
"port",
|
|
58
|
+
"path"
|
|
59
|
+
],
|
|
60
|
+
additionalProperties: true
|
|
61
|
+
},
|
|
62
|
+
minItems: 1,
|
|
63
|
+
description: "A role can declare an endpoint to accept connections from other roles, normally used by servers"
|
|
64
|
+
},
|
|
65
|
+
messages: {
|
|
66
|
+
type: "object",
|
|
67
|
+
patternProperties: {
|
|
68
|
+
"^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$": {
|
|
69
|
+
type: "object",
|
|
70
|
+
properties: {
|
|
71
|
+
payload: {
|
|
72
|
+
type: "object",
|
|
73
|
+
description: "Must be a valid JSON schema spec. For brevity, openws omits this spec, but implementations should valid this",
|
|
74
|
+
additionalProperties: true
|
|
75
|
+
},
|
|
76
|
+
description: {
|
|
77
|
+
type: "string"
|
|
78
|
+
},
|
|
79
|
+
from: {
|
|
80
|
+
type: "array",
|
|
81
|
+
items: {
|
|
82
|
+
type: "string"
|
|
83
|
+
},
|
|
84
|
+
description: "A list of roles that can send this message"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
required: [
|
|
88
|
+
"payload"
|
|
89
|
+
],
|
|
90
|
+
additionalProperties: true
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
description: "A message accepted by the role and handled by the role, and roles can send messages other roles accepts. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (through through description the behavior can be documented).",
|
|
94
|
+
additionalProperties: false
|
|
95
|
+
},
|
|
96
|
+
description: {
|
|
97
|
+
type: "string"
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
required: [
|
|
101
|
+
"messages"
|
|
102
|
+
],
|
|
103
|
+
additionalProperties: true
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
additionalProperties: false
|
|
107
|
+
},
|
|
108
|
+
description: {
|
|
109
|
+
type: "string"
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
required: [
|
|
113
|
+
"roles"
|
|
114
|
+
],
|
|
115
|
+
additionalProperties: true
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
additionalProperties: false
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var required = [
|
|
122
|
+
"openws",
|
|
123
|
+
"networks"
|
|
124
|
+
];
|
|
125
|
+
var additionalProperties = true;
|
|
126
|
+
var $schema = "http://json-schema.org/draft-07/schema#";
|
|
127
|
+
var specSchema = {
|
|
128
|
+
type: type,
|
|
129
|
+
properties: properties,
|
|
130
|
+
required: required,
|
|
131
|
+
additionalProperties: additionalProperties,
|
|
132
|
+
$schema: $schema
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
declare const VERSION: string;
|
|
136
|
+
|
|
137
|
+
declare function validate(spec: any): void;
|
|
138
|
+
|
|
139
|
+
export { VERSION, specSchema, validate };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// package.json
|
|
2
|
+
var package_default = {
|
|
3
|
+
name: "@polytric/openws-spec",
|
|
4
|
+
version: "0.0.3",
|
|
5
|
+
description: "Polytric OpenWS Specification",
|
|
6
|
+
type: "module",
|
|
7
|
+
main: "./dist/index.js",
|
|
8
|
+
types: "./dist/index.d.ts",
|
|
9
|
+
exports: {
|
|
10
|
+
".": {
|
|
11
|
+
types: "./dist/index.d.ts",
|
|
12
|
+
import: "./dist/index.js",
|
|
13
|
+
require: "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./builder": {
|
|
16
|
+
types: "./dist/builder.d.ts",
|
|
17
|
+
import: "./dist/builder.js",
|
|
18
|
+
require: "./dist/builder.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./types": {
|
|
21
|
+
types: "./dist/types.d.ts",
|
|
22
|
+
import: "./dist/types.js",
|
|
23
|
+
require: "./dist/types.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
files: [
|
|
27
|
+
"dist",
|
|
28
|
+
"LICENSE",
|
|
29
|
+
"README.md"
|
|
30
|
+
],
|
|
31
|
+
keywords: [
|
|
32
|
+
"openws",
|
|
33
|
+
"specification",
|
|
34
|
+
"websocket"
|
|
35
|
+
],
|
|
36
|
+
author: "Polytric",
|
|
37
|
+
license: "Apache-2.0",
|
|
38
|
+
scripts: {
|
|
39
|
+
build: "pnpm emit && tsup",
|
|
40
|
+
emit: `tsx -e "import schema from './src/spec-schema.ts'; console.log(JSON.stringify(schema.jsonSchema()))" > ./src/spec-schema.json`,
|
|
41
|
+
prepublishOnly: "pnpm build",
|
|
42
|
+
"test:builder": "nodemon -w dist -w test/builder.cjs test/builder.cjs",
|
|
43
|
+
"test:validate": "tsx test/validate-spec.ts",
|
|
44
|
+
typecheck: "tsc --noEmit"
|
|
45
|
+
},
|
|
46
|
+
dependencies: {
|
|
47
|
+
"@pocketgems/schema": "^0.1.3",
|
|
48
|
+
ajv: "^8.17.1"
|
|
49
|
+
},
|
|
50
|
+
devDependencies: {
|
|
51
|
+
nodemon: "^3.1.11",
|
|
52
|
+
tsup: "^8.5.1",
|
|
53
|
+
tsx: "^4.21.0",
|
|
54
|
+
typescript: "^5.9.3"
|
|
55
|
+
},
|
|
56
|
+
packageManager: "pnpm@10.26.1",
|
|
57
|
+
publishConfig: {
|
|
58
|
+
access: "public"
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/spec-schema.ts
|
|
63
|
+
import S from "@pocketgems/schema";
|
|
64
|
+
var keyPattern = "[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?";
|
|
65
|
+
var messageSchema = S.obj({
|
|
66
|
+
payload: S.obj({}).desc(
|
|
67
|
+
"Must be a valid JSON schema spec. For brevity, openws omits this spec, but implementations should valid this"
|
|
68
|
+
),
|
|
69
|
+
description: S.str.optional(),
|
|
70
|
+
from: S.arr(S.str).desc("A list of roles that can send this message").optional()
|
|
71
|
+
});
|
|
72
|
+
messageSchema.additionalProperties = true;
|
|
73
|
+
var endpointSchema = S.obj({
|
|
74
|
+
host: S.str,
|
|
75
|
+
port: S.int.min(1).max(65535),
|
|
76
|
+
path: S.str
|
|
77
|
+
});
|
|
78
|
+
endpointSchema.additionalProperties = true;
|
|
79
|
+
var roleSchema = S.obj({
|
|
80
|
+
endpoints: S.arr(endpointSchema).min(1).optional().desc(
|
|
81
|
+
"A role can declare an endpoint to accept connections from other roles, normally used by servers"
|
|
82
|
+
),
|
|
83
|
+
messages: S.map.keyPattern(keyPattern).value(messageSchema).desc(
|
|
84
|
+
"A message accepted by the role and handled by the role, and roles can send messages other roles accepts. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (through through description the behavior can be documented)."
|
|
85
|
+
),
|
|
86
|
+
description: S.str.optional()
|
|
87
|
+
});
|
|
88
|
+
roleSchema.additionalProperties = true;
|
|
89
|
+
var networkSchema = S.obj({
|
|
90
|
+
roles: S.map.min(1).keyPattern(keyPattern).desc(
|
|
91
|
+
"A network is a collection of roles that exchange messages. Multiple roles can coexist in the same network. The simplest network contains a server-client pair."
|
|
92
|
+
).value(roleSchema),
|
|
93
|
+
description: S.str.optional()
|
|
94
|
+
});
|
|
95
|
+
networkSchema.additionalProperties = true;
|
|
96
|
+
var openWsSchema = S.obj({
|
|
97
|
+
openws: S.str.enum("0.0.1", "0.0.2").desc("The OpenWS schema version"),
|
|
98
|
+
name: S.str.desc("A title for the overall system.").optional(),
|
|
99
|
+
description: S.str.desc(
|
|
100
|
+
"A high level description of the overall system, including all networks and all roles"
|
|
101
|
+
).optional(),
|
|
102
|
+
version: S.str.desc("A version string").optional(),
|
|
103
|
+
networks: S.map.min(1).keyPattern(keyPattern).value(networkSchema)
|
|
104
|
+
});
|
|
105
|
+
openWsSchema.additionalProperties = true;
|
|
106
|
+
var spec_schema_default = openWsSchema;
|
|
107
|
+
|
|
108
|
+
// src/spec-schema.json
|
|
109
|
+
var spec_schema_default2 = { type: "object", properties: { openws: { type: "string", enum: ["0.0.1", "0.0.2"], description: "The OpenWS schema version" }, name: { type: "string", description: "A title for the overall system." }, description: { type: "string", description: "A high level description of the overall system, including all networks and all roles" }, version: { type: "string", description: "A version string" }, networks: { type: "object", minProperties: 1, patternProperties: { "^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$": { type: "object", properties: { roles: { type: "object", minProperties: 1, description: "A network is a collection of roles that exchange messages. Multiple roles can coexist in the same network. The simplest network contains a server-client pair.", patternProperties: { "^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$": { type: "object", properties: { endpoints: { type: "array", items: { type: "object", properties: { host: { type: "string" }, port: { type: "integer", minimum: 1, maximum: 65535 }, path: { type: "string" } }, required: ["host", "port", "path"], additionalProperties: true }, minItems: 1, description: "A role can declare an endpoint to accept connections from other roles, normally used by servers" }, messages: { type: "object", patternProperties: { "^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$": { type: "object", properties: { payload: { type: "object", description: "Must be a valid JSON schema spec. For brevity, openws omits this spec, but implementations should valid this", additionalProperties: true }, description: { type: "string" }, from: { type: "array", items: { type: "string" }, description: "A list of roles that can send this message" } }, required: ["payload"], additionalProperties: true } }, description: "A message accepted by the role and handled by the role, and roles can send messages other roles accepts. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (through through description the behavior can be documented).", additionalProperties: false }, description: { type: "string" } }, required: ["messages"], additionalProperties: true } }, additionalProperties: false }, description: { type: "string" } }, required: ["roles"], additionalProperties: true } }, additionalProperties: false } }, required: ["openws", "networks"], additionalProperties: true, $schema: "http://json-schema.org/draft-07/schema#" };
|
|
110
|
+
|
|
111
|
+
// src/index.ts
|
|
112
|
+
var VERSION = package_default.version;
|
|
113
|
+
var validator;
|
|
114
|
+
function validate(spec) {
|
|
115
|
+
validator = validator ?? spec_schema_default.compile("Validator");
|
|
116
|
+
validator(spec);
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
VERSION,
|
|
120
|
+
spec_schema_default2 as specSchema,
|
|
121
|
+
validate
|
|
122
|
+
};
|
|
123
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/spec-schema.ts","../src/spec-schema.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@polytric/openws-spec\",\n \"version\": \"0.0.3\",\n \"description\": \"Polytric OpenWS Specification\",\n \"type\": \"module\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./builder\": {\n \"types\": \"./dist/builder.d.ts\",\n \"import\": \"./dist/builder.js\",\n \"require\": \"./dist/builder.cjs\"\n },\n \"./types\": {\n \"types\": \"./dist/types.d.ts\",\n \"import\": \"./dist/types.js\",\n \"require\": \"./dist/types.cjs\"\n }\n },\n \"files\": [\n \"dist\",\n \"LICENSE\",\n \"README.md\"\n ],\n \"keywords\": [\n \"openws\",\n \"specification\",\n \"websocket\"\n ],\n \"author\": \"Polytric\",\n \"license\": \"Apache-2.0\",\n \"scripts\": {\n \"build\": \"pnpm emit && tsup\",\n \"emit\": \"tsx -e \\\"import schema from './src/spec-schema.ts'; console.log(JSON.stringify(schema.jsonSchema()))\\\" > ./src/spec-schema.json\",\n \"prepublishOnly\": \"pnpm build\",\n \"test:builder\": \"nodemon -w dist -w test/builder.cjs test/builder.cjs\",\n \"test:validate\": \"tsx test/validate-spec.ts\",\n \"typecheck\": \"tsc --noEmit\"\n },\n \"dependencies\": {\n \"@pocketgems/schema\": \"^0.1.3\",\n \"ajv\": \"^8.17.1\"\n },\n \"devDependencies\": {\n \"nodemon\": \"^3.1.11\",\n \"tsup\": \"^8.5.1\",\n \"tsx\": \"^4.21.0\",\n \"typescript\": \"^5.9.3\"\n },\n \"packageManager\": \"pnpm@10.26.1\",\n \"publishConfig\": {\n \"access\": \"public\"\n }\n}\n","import S from '@pocketgems/schema'\n\nconst keyPattern = '[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?'\n\nconst messageSchema = S.obj({\n payload: S.obj({}).desc(\n 'Must be a valid JSON schema spec. For brevity, openws omits this spec, but implementations should valid this'\n ),\n description: S.str.optional(),\n from: S.arr(S.str).desc('A list of roles that can send this message').optional(),\n})\n\nmessageSchema.additionalProperties = true\n\nconst endpointSchema = S.obj({\n host: S.str,\n port: S.int.min(1).max(65535),\n path: S.str,\n})\n\nendpointSchema.additionalProperties = true\n\nconst roleSchema = S.obj({\n endpoints: S.arr(endpointSchema)\n .min(1)\n .optional()\n .desc(\n 'A role can declare an endpoint to accept connections from other roles, normally used by servers'\n ),\n messages: S.map\n .keyPattern(keyPattern)\n .value(messageSchema)\n .desc(\n \"A message accepted by the role and handled by the role, and roles can send messages other roles accepts. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (through through description the behavior can be documented).\"\n ),\n description: S.str.optional(),\n})\n\nroleSchema.additionalProperties = true\n\nconst networkSchema = S.obj({\n roles: S.map\n .min(1)\n .keyPattern(keyPattern)\n .desc(\n 'A network is a collection of roles that exchange messages. Multiple roles can coexist in the same network. The simplest network contains a server-client pair.'\n )\n .value(roleSchema),\n description: S.str.optional(),\n})\n\nnetworkSchema.additionalProperties = true\n\nconst openWsSchema = S.obj({\n openws: S.str.enum('0.0.1', '0.0.2').desc('The OpenWS schema version'),\n name: S.str.desc('A title for the overall system.').optional(),\n description: S.str\n .desc(\n 'A high level description of the overall system, including all networks and all roles'\n )\n .optional(),\n version: S.str.desc('A version string').optional(),\n networks: S.map.min(1).keyPattern(keyPattern).value(networkSchema),\n})\n\nopenWsSchema.additionalProperties = true\n\nexport default openWsSchema\n","{\"type\":\"object\",\"properties\":{\"openws\":{\"type\":\"string\",\"enum\":[\"0.0.1\",\"0.0.2\"],\"description\":\"The OpenWS schema version\"},\"name\":{\"type\":\"string\",\"description\":\"A title for the overall system.\"},\"description\":{\"type\":\"string\",\"description\":\"A high level description of the overall system, including all networks and all roles\"},\"version\":{\"type\":\"string\",\"description\":\"A version string\"},\"networks\":{\"type\":\"object\",\"minProperties\":1,\"patternProperties\":{\"^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$\":{\"type\":\"object\",\"properties\":{\"roles\":{\"type\":\"object\",\"minProperties\":1,\"description\":\"A network is a collection of roles that exchange messages. Multiple roles can coexist in the same network. The simplest network contains a server-client pair.\",\"patternProperties\":{\"^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$\":{\"type\":\"object\",\"properties\":{\"endpoints\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"host\":{\"type\":\"string\"},\"port\":{\"type\":\"integer\",\"minimum\":1,\"maximum\":65535},\"path\":{\"type\":\"string\"}},\"required\":[\"host\",\"port\",\"path\"],\"additionalProperties\":true},\"minItems\":1,\"description\":\"A role can declare an endpoint to accept connections from other roles, normally used by servers\"},\"messages\":{\"type\":\"object\",\"patternProperties\":{\"^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$\":{\"type\":\"object\",\"properties\":{\"payload\":{\"type\":\"object\",\"description\":\"Must be a valid JSON schema spec. For brevity, openws omits this spec, but implementations should valid this\",\"additionalProperties\":true},\"description\":{\"type\":\"string\"},\"from\":{\"type\":\"array\",\"items\":{\"type\":\"string\"},\"description\":\"A list of roles that can send this message\"}},\"required\":[\"payload\"],\"additionalProperties\":true}},\"description\":\"A message accepted by the role and handled by the role, and roles can send messages other roles accepts. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (through through description the behavior can be documented).\",\"additionalProperties\":false},\"description\":{\"type\":\"string\"}},\"required\":[\"messages\"],\"additionalProperties\":true}},\"additionalProperties\":false},\"description\":{\"type\":\"string\"}},\"required\":[\"roles\"],\"additionalProperties\":true}},\"additionalProperties\":false}},\"required\":[\"openws\",\"networks\"],\"additionalProperties\":true,\"$schema\":\"http://json-schema.org/draft-07/schema#\"}\n","import pkg from '../package.json'\n\nimport specSchemaValidator from './spec-schema'\n\nexport const VERSION = pkg.version\n\nexport { default as specSchema } from './spec-schema.json'\n\nlet validator: (spec: any) => void\n\nexport function validate(spec: any): void {\n validator = validator ?? specSchemaValidator.compile('Validator')\n validator(spec)\n}\n"],"mappings":";AAAA;AAAA,EACI,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,aAAe;AAAA,EACf,MAAQ;AAAA,EACR,MAAQ;AAAA,EACR,OAAS;AAAA,EACT,SAAW;AAAA,IACP,KAAK;AAAA,MACD,OAAS;AAAA,MACT,QAAU;AAAA,MACV,SAAW;AAAA,IACf;AAAA,IACA,aAAa;AAAA,MACT,OAAS;AAAA,MACT,QAAU;AAAA,MACV,SAAW;AAAA,IACf;AAAA,IACA,WAAW;AAAA,MACP,OAAS;AAAA,MACT,QAAU;AAAA,MACV,SAAW;AAAA,IACf;AAAA,EACJ;AAAA,EACA,OAAS;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AAAA,EACA,UAAY;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AAAA,EACA,QAAU;AAAA,EACV,SAAW;AAAA,EACX,SAAW;AAAA,IACP,OAAS;AAAA,IACT,MAAQ;AAAA,IACR,gBAAkB;AAAA,IAClB,gBAAgB;AAAA,IAChB,iBAAiB;AAAA,IACjB,WAAa;AAAA,EACjB;AAAA,EACA,cAAgB;AAAA,IACZ,sBAAsB;AAAA,IACtB,KAAO;AAAA,EACX;AAAA,EACA,iBAAmB;AAAA,IACf,SAAW;AAAA,IACX,MAAQ;AAAA,IACR,KAAO;AAAA,IACP,YAAc;AAAA,EAClB;AAAA,EACA,gBAAkB;AAAA,EAClB,eAAiB;AAAA,IACb,QAAU;AAAA,EACd;AACJ;;;AC1DA,OAAO,OAAO;AAEd,IAAM,aAAa;AAEnB,IAAM,gBAAgB,EAAE,IAAI;AAAA,EACxB,SAAS,EAAE,IAAI,CAAC,CAAC,EAAE;AAAA,IACf;AAAA,EACJ;AAAA,EACA,aAAa,EAAE,IAAI,SAAS;AAAA,EAC5B,MAAM,EAAE,IAAI,EAAE,GAAG,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,SAAU,0CAAyC;;;ACIv1E,IAAM,UAAU,gBAAI;AAI3B,IAAI;AAEG,SAAS,SAAS,MAAiB;AACtC,cAAY,aAAa,oBAAoB,QAAQ,WAAW;AAChE,YAAU,IAAI;AAClB;","names":["spec_schema_default"]}
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { SchemaObject } from 'ajv'\n\ntype PrimitiveValue = string | number | boolean | null\ntype JsonObject = { [key: string]: JsonValue }\nexport type JsonValue = PrimitiveValue | Array<JsonValue> | JsonObject\n\nexport interface CommonMetadata {\n name: string\n description?: string\n version?: string\n\n [key: string]: any\n}\n\nexport interface Message extends CommonMetadata {\n payload: SchemaObject\n from?: string[]\n}\n\nexport interface Endpoint {\n scheme: string\n host: string\n port: number\n path: string\n}\n\nexport interface Role extends CommonMetadata {\n messages: { [key: string]: Message }\n endpoints?: Endpoint[]\n}\n\nexport interface Network extends CommonMetadata {\n roles: { [key: string]: Role }\n}\n\nexport interface Spec extends CommonMetadata {\n openws: string\n networks: { [key: string]: Network }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { SchemaObject } from 'ajv';
|
|
2
|
+
|
|
3
|
+
type PrimitiveValue = string | number | boolean | null;
|
|
4
|
+
type JsonObject = {
|
|
5
|
+
[key: string]: JsonValue;
|
|
6
|
+
};
|
|
7
|
+
type JsonValue = PrimitiveValue | Array<JsonValue> | JsonObject;
|
|
8
|
+
interface CommonMetadata {
|
|
9
|
+
name: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
version?: string;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
interface Message extends CommonMetadata {
|
|
15
|
+
payload: SchemaObject;
|
|
16
|
+
from?: string[];
|
|
17
|
+
}
|
|
18
|
+
interface Endpoint {
|
|
19
|
+
scheme: string;
|
|
20
|
+
host: string;
|
|
21
|
+
port: number;
|
|
22
|
+
path: string;
|
|
23
|
+
}
|
|
24
|
+
interface Role extends CommonMetadata {
|
|
25
|
+
messages: {
|
|
26
|
+
[key: string]: Message;
|
|
27
|
+
};
|
|
28
|
+
endpoints?: Endpoint[];
|
|
29
|
+
}
|
|
30
|
+
interface Network extends CommonMetadata {
|
|
31
|
+
roles: {
|
|
32
|
+
[key: string]: Role;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
interface Spec extends CommonMetadata {
|
|
36
|
+
openws: string;
|
|
37
|
+
networks: {
|
|
38
|
+
[key: string]: Network;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type { CommonMetadata, Endpoint, JsonValue, Message, Network, Role, Spec };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { SchemaObject } from 'ajv';
|
|
2
|
+
|
|
3
|
+
type PrimitiveValue = string | number | boolean | null;
|
|
4
|
+
type JsonObject = {
|
|
5
|
+
[key: string]: JsonValue;
|
|
6
|
+
};
|
|
7
|
+
type JsonValue = PrimitiveValue | Array<JsonValue> | JsonObject;
|
|
8
|
+
interface CommonMetadata {
|
|
9
|
+
name: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
version?: string;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
interface Message extends CommonMetadata {
|
|
15
|
+
payload: SchemaObject;
|
|
16
|
+
from?: string[];
|
|
17
|
+
}
|
|
18
|
+
interface Endpoint {
|
|
19
|
+
scheme: string;
|
|
20
|
+
host: string;
|
|
21
|
+
port: number;
|
|
22
|
+
path: string;
|
|
23
|
+
}
|
|
24
|
+
interface Role extends CommonMetadata {
|
|
25
|
+
messages: {
|
|
26
|
+
[key: string]: Message;
|
|
27
|
+
};
|
|
28
|
+
endpoints?: Endpoint[];
|
|
29
|
+
}
|
|
30
|
+
interface Network extends CommonMetadata {
|
|
31
|
+
roles: {
|
|
32
|
+
[key: string]: Role;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
interface Spec extends CommonMetadata {
|
|
36
|
+
openws: string;
|
|
37
|
+
networks: {
|
|
38
|
+
[key: string]: Network;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type { CommonMetadata, Endpoint, JsonValue, Message, Network, Role, Spec };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1,30 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polytric/openws-spec",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Polytric OpenWS Specification",
|
|
5
|
-
"
|
|
6
|
-
"main": "index.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
},
|
|
14
|
+
"./builder": {
|
|
15
|
+
"types": "./dist/builder.d.ts",
|
|
16
|
+
"import": "./dist/builder.js",
|
|
17
|
+
"require": "./dist/builder.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./types": {
|
|
20
|
+
"types": "./dist/types.d.ts",
|
|
21
|
+
"import": "./dist/types.js",
|
|
22
|
+
"require": "./dist/types.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
7
25
|
"files": [
|
|
8
|
-
"
|
|
9
|
-
"spec.json",
|
|
26
|
+
"dist",
|
|
10
27
|
"LICENSE",
|
|
11
|
-
"
|
|
28
|
+
"README.md"
|
|
12
29
|
],
|
|
13
30
|
"keywords": [
|
|
14
|
-
"websocket",
|
|
15
31
|
"openws",
|
|
16
|
-
"specification"
|
|
32
|
+
"specification",
|
|
33
|
+
"websocket"
|
|
17
34
|
],
|
|
18
|
-
"publishConfig": {
|
|
19
|
-
"access": "public"
|
|
20
|
-
},
|
|
21
35
|
"author": "Polytric",
|
|
22
36
|
"license": "Apache-2.0",
|
|
23
37
|
"dependencies": {
|
|
24
|
-
"@pocketgems/schema": "^0.1.3"
|
|
38
|
+
"@pocketgems/schema": "^0.1.3",
|
|
39
|
+
"ajv": "^8.17.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"nodemon": "^3.1.11",
|
|
43
|
+
"tsup": "^8.5.1",
|
|
44
|
+
"tsx": "^4.21.0",
|
|
45
|
+
"typescript": "^5.9.3"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
25
49
|
},
|
|
26
50
|
"scripts": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
51
|
+
"build": "pnpm emit && tsup",
|
|
52
|
+
"emit": "tsx -e \"import schema from './src/spec-schema.ts'; console.log(JSON.stringify(schema.jsonSchema()))\" > ./src/spec-schema.json",
|
|
53
|
+
"test:builder": "nodemon -w dist -w test/builder.cjs test/builder.cjs",
|
|
54
|
+
"test:validate": "tsx test/validate-spec.ts",
|
|
55
|
+
"typecheck": "tsc --noEmit"
|
|
29
56
|
}
|
|
30
57
|
}
|