@polytric/openws-spec 0.0.3 → 0.0.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.
- package/README.md +22 -16
- package/dist/builder.cjs +4 -4
- package/dist/builder.cjs.map +1 -1
- package/dist/builder.js +4 -4
- package/dist/builder.js.map +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# OpenWS Specification <!-- omit in toc -->
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@polytric/openws-spec)
|
|
4
|
+
[](https://github.com/polytric/openws/blob/main/LICENSE)
|
|
5
|
+
|
|
3
6
|
OpenWS is a specification for describing **WebSocket-based systems** in the same way OpenAPI describes HTTP APIs. It models WebSocket communication as an **asymmetrical 2-way request-response mesh**: multiple components exchange named messages, and "responses" are simply messages sent back through the same network.
|
|
4
7
|
|
|
5
8
|
An OpenWS document describes:
|
|
@@ -23,16 +26,16 @@ This spec intentionally does **not** describe behavior or execution.
|
|
|
23
26
|
- [Document Structure](#document-structure)
|
|
24
27
|
- [Ecosystem](#ecosystem)
|
|
25
28
|
- [Core Concepts](#core-concepts)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
- [Networks](#networks)
|
|
30
|
+
- [Roles](#roles)
|
|
31
|
+
- [Messages](#messages)
|
|
32
|
+
- [Request/response modeling](#requestresponse-modeling)
|
|
33
|
+
- [Payload](#payload)
|
|
34
|
+
- [Metadata \& Connection Hints](#metadata--connection-hints)
|
|
35
|
+
- [Document metadata](#document-metadata)
|
|
36
|
+
- [Connection hints](#connection-hints)
|
|
37
|
+
- [Custom metadata and extensions](#custom-metadata-and-extensions)
|
|
38
|
+
- [Complete Example](#complete-example)
|
|
36
39
|
|
|
37
40
|
# Conventions
|
|
38
41
|
|
|
@@ -90,14 +93,17 @@ This repository/spec is intended to support a full "fleet" of packages, includin
|
|
|
90
93
|
|
|
91
94
|
- **Spec & validation**
|
|
92
95
|
- [`@polytric/openws-spec`](https://www.npmjs.com/package/@polytric/openws-spec) - This library
|
|
93
|
-
- [`@polytric/fastify-openws-spec`](https://www.npmjs.com/package/@polytric/fastify-openws-spec) -- Fastify plugin to generate OpenWS spec from code
|
|
94
96
|
|
|
95
97
|
- **Runtime framework**
|
|
96
|
-
- [`@polytric/
|
|
97
|
-
- [`@polytric/fastify-openws`](https://www.npmjs.com/package/@polytric/fastify-openws)
|
|
98
|
+
- [`@polytric/openws`](https://www.npmjs.com/package/@polytric/openws) - OpenWS framework for JavaScript/TypeScript
|
|
99
|
+
- [`@polytric/fastify-openws`](https://www.npmjs.com/package/@polytric/fastify-openws) - Fastify WebSocket integration
|
|
100
|
+
|
|
101
|
+
- **UI & tooling**
|
|
102
|
+
- [`@polytric/openws-ui`](https://www.npmjs.com/package/@polytric/openws-ui) - Swagger-like spec explorer
|
|
103
|
+
- [`@polytric/fastify-openws-ui`](https://www.npmjs.com/package/@polytric/fastify-openws-ui) - Mount OpenWS UI in Fastify
|
|
98
104
|
|
|
99
105
|
- **SDK generation**
|
|
100
|
-
- [`@polytric/openws-sdkgen`](https://www.npmjs.com/package/@polytric/openws-sdkgen)
|
|
106
|
+
- [`@polytric/openws-sdkgen`](https://www.npmjs.com/package/@polytric/openws-sdkgen) - CLI for generating typed SDKs
|
|
101
107
|
|
|
102
108
|
> The spec intentionally stays framework-agnostic; framework integrations and SDKs belong to the ecosystem layer.
|
|
103
109
|
|
|
@@ -326,7 +332,7 @@ The following example is a minimal but complete OpenWS document modeling a chat
|
|
|
326
332
|
- connection hints via `endpoints`
|
|
327
333
|
- one extension field (`x-routingNotes`) to document intended flows
|
|
328
334
|
|
|
329
|
-
|
|
335
|
+
```<!-- embed:./test/chat-spec.json:scope:{ -->
|
|
330
336
|
{
|
|
331
337
|
"openws": "0.0.2",
|
|
332
338
|
"title": "Example Chat Service",
|
|
@@ -450,4 +456,4 @@ The following example is a minimal but complete OpenWS document modeling a chat
|
|
|
450
456
|
}
|
|
451
457
|
}
|
|
452
458
|
}
|
|
453
|
-
```
|
|
459
|
+
```
|
package/dist/builder.cjs
CHANGED
|
@@ -254,17 +254,17 @@ var Network = class _Network extends Base {
|
|
|
254
254
|
}
|
|
255
255
|
assertValid() {
|
|
256
256
|
const hostRoles = [];
|
|
257
|
-
const
|
|
257
|
+
const remoteRoles = [];
|
|
258
258
|
for (const role2 of Object.values(this.#roles)) {
|
|
259
259
|
role2.assertValid();
|
|
260
260
|
if (role2.isHost) {
|
|
261
261
|
hostRoles.push(role2);
|
|
262
262
|
} else {
|
|
263
|
-
|
|
263
|
+
remoteRoles.push(role2);
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
|
-
if (
|
|
267
|
-
throw new Error("At least one
|
|
266
|
+
if (remoteRoles.length === 0) {
|
|
267
|
+
throw new Error("At least one remote role must be defined");
|
|
268
268
|
}
|
|
269
269
|
const messages = /* @__PURE__ */ new Set();
|
|
270
270
|
for (const role2 of Object.values(this.#roles)) {
|
package/dist/builder.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/builder.ts"],"sourcesContent":["import type * as Types from './types'\n\nconst WELL_KNOWN_METADATA_KEYS = new Set<string>(['description', 'version', 'openws', 'name'])\n\nexport class Base {\n #metadata: Types.CommonMetadata\n\n constructor(name: string) {\n this.#metadata = { name }\n }\n\n #setMetadata(name: string, value: Types.JsonValue): this {\n this.#metadata[name] = value\n return this\n }\n\n #getMetadataKey(name: string): string {\n if (WELL_KNOWN_METADATA_KEYS.has(name)) {\n return name\n }\n if (!name.startsWith('x-')) {\n return `x-${name}`\n }\n return name\n }\n\n get name(): string {\n return this.#metadata['name'] as string\n }\n\n metadata(name: string, value: Types.JsonValue): this {\n return this.#setMetadata(this.#getMetadataKey(name), value)\n }\n\n getMetadata(name: string): Types.JsonValue | undefined {\n return this.#metadata[this.#getMetadataKey(name)] as Types.JsonValue | undefined\n }\n\n desc(description: string): this {\n return this.description(description)\n }\n\n description(description: string): this {\n return this.#setMetadata('description', description)\n }\n\n version(version: string): this {\n return this.#setMetadata('version', version)\n }\n\n title(title: string): this {\n return this.#setMetadata('title', title)\n }\n\n valueOf(): Types.CommonMetadata {\n return { ...this.#metadata }\n }\n\n toJson(): Types.CommonMetadata {\n return this.valueOf()\n }\n\n isValid(): boolean {\n return false\n }\n}\n\nexport class Message extends Base {\n get isPolytricMessage(): boolean {\n return true\n }\n #payload?: any\n #from?: string[]\n\n constructor(name: string) {\n super(name)\n }\n\n getPayload(): any | undefined {\n return this.#payload\n }\n\n payload(payload: any): this {\n this.#payload = payload.valueOf()\n return this\n }\n\n from(...from: string[]): this {\n this.#from ??= []\n this.#from.push(...from)\n return this\n }\n\n valueOf(): Types.Message {\n if (!this.#payload) {\n throw new Error('Payload is required')\n }\n const ret: Types.Message = {\n ...super.valueOf(),\n payload: this.#payload,\n }\n if (this.#from) {\n ret.from = this.#from\n }\n return ret\n }\n\n static fromJson(json: Types.Message): Message {\n const { payload, from, ...metadata } = json\n const ret = new Message(json.name as string)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n ret.payload(payload)\n if (from) {\n ret.from(...from)\n }\n return ret\n }\n\n assertValid(): boolean {\n if (this.#payload === undefined) {\n throw new Error('Payload is required')\n }\n return true\n }\n}\n\nexport class Endpoint {\n #scheme: string = 'ws'\n #host: string\n #port: number = 433\n #path: string\n\n constructor(scheme: string, host: string, port: number, path: string) {\n this.#scheme = scheme\n this.#host = host\n this.#port = port\n this.#path = path\n }\n\n valueOf(): Types.Endpoint {\n return {\n scheme: this.#scheme,\n host: this.#host,\n port: this.#port,\n path: this.#path,\n }\n }\n\n toJson(): Types.Endpoint {\n return this.valueOf()\n }\n\n static fromJson(json: Types.Endpoint): Endpoint {\n return new Endpoint(json.scheme, json.host, json.port, json.path)\n }\n}\n\nexport class Role extends Base {\n get isPolytricRole(): boolean {\n return true\n }\n #messages: { [key: string]: Message } = {}\n #endpoints: Endpoint[] = []\n\n isHost: boolean = false\n\n asHost(): this {\n this.isHost = true\n return this\n }\n\n message(message: Message): this {\n this.#messages[message.name] = message\n return this\n }\n\n get messages(): Record<string, Message> {\n return this.#messages\n }\n\n endpoint(endpoint: Endpoint): this {\n this.#endpoints.push(endpoint)\n return this\n }\n\n valueOf(): Types.Role {\n const messages: { [key: string]: Types.Message } = {}\n for (const [name, message] of Object.entries(this.#messages)) {\n messages[name] = message.valueOf()\n }\n const ret: Types.Role = {\n ...super.valueOf(),\n messages,\n }\n if (this.#endpoints.length > 0) {\n ret.endpoints = this.#endpoints.map(endpoint => endpoint.valueOf())\n }\n return ret\n }\n\n static fromJson(json: Types.Role): Role {\n const { messages, endpoints, ...metadata } = json\n const ret = new Role(json.name)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n for (const message of Object.values(messages)) {\n ret.message(Message.fromJson(message))\n }\n for (const endpoint of endpoints ?? []) {\n ret.endpoint(Endpoint.fromJson(endpoint))\n }\n return ret\n }\n\n assertValid(): boolean {\n for (const message of Object.values(this.#messages)) {\n message.assertValid()\n }\n return true\n }\n}\n\nexport class Network extends Base {\n get isPolytricNetwork(): boolean {\n return true\n }\n #roles: { [key: string]: Role } = {}\n\n role(role: Role): this {\n this.#roles[role.name] = role\n return this\n }\n\n get roles(): { [key: string]: Role } {\n return this.#roles\n }\n\n valueOf(): Types.Network {\n const roles: { [key: string]: Types.Role } = {}\n for (const [name, role] of Object.entries(this.#roles)) {\n roles[name] = role.valueOf()\n }\n return {\n ...super.valueOf(),\n roles,\n }\n }\n\n static fromJson(json: Types.Network): Network {\n const { roles, ...metadata } = json\n const ret = new Network(json.name as string)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n for (const role of Object.values(roles)) {\n ret.role(Role.fromJson(role))\n }\n return ret\n }\n\n assertValid(): boolean {\n const hostRoles: Role[] = []\n const consumerRoles: Role[] = []\n for (const role of Object.values(this.#roles)) {\n role.assertValid()\n\n if (role.isHost) {\n hostRoles.push(role as Role)\n } else {\n consumerRoles.push(role as Role)\n }\n }\n if (consumerRoles.length === 0) {\n throw new Error('At least one consumer role must be defined')\n }\n const messages = new Set<string>()\n for (const role of Object.values(this.#roles)) {\n if (!role.isHost) {\n continue\n }\n for (const message of Object.values(role.messages)) {\n if (messages.has(message.name)) {\n throw new Error(\n `Message '${message.name}' is defined in multiple host roles: ${hostRoles.map(role => role.name).join(', ')}`\n )\n }\n messages.add(message.name)\n }\n }\n\n return true\n }\n}\n\nexport class Spec extends Base {\n get isPolytricSpec(): boolean {\n return true\n }\n #networks: { [key: string]: Network } = {}\n\n constructor(openws: string, name: string) {\n super(name)\n this.metadata('openws', openws)\n }\n\n network(network: Network): this {\n this.#networks[network.name] = network\n return this\n }\n\n get networks(): Record<string, Network> {\n return this.#networks\n }\n\n valueOf(): Types.Spec {\n const networks: { [key: string]: Types.Network } = {}\n for (const [name, network] of Object.entries(this.#networks)) {\n networks[name] = network.valueOf()\n }\n return {\n ...super.valueOf(),\n openws: this.getMetadata('openws') as string,\n networks,\n }\n }\n\n static fromJson(json: Types.Spec): Spec {\n const { networks, ...metadata } = json\n const ret = new Spec(json.openws as string, json.name as string)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n for (const network of Object.values(networks)) {\n ret.network(Network.fromJson(network))\n }\n return ret\n }\n\n assertValid(): boolean {\n for (const network of Object.values(this.#networks)) {\n network.assertValid()\n }\n return true\n }\n}\n\nexport function spec(openws: string, name: string): Spec\nexport function spec(spec: Types.Spec): Spec\nexport function spec(openwsOrSpec: string | Types.Spec, name?: string): Spec {\n if (typeof openwsOrSpec === 'string') {\n return new Spec(openwsOrSpec, name!)\n } else {\n return Spec.fromJson(openwsOrSpec)\n }\n}\n\nexport function network(network: string | Types.Network): Network {\n if (typeof network === 'string') {\n return new Network(network)\n } else {\n return Network.fromJson(network)\n }\n}\n\nexport function role(role: string | Types.Role): Role {\n if (typeof role === 'string') {\n return new Role(role)\n } else {\n return Role.fromJson(role)\n }\n}\n\nexport function message(msg: string | Types.Message): Message {\n if (typeof msg === 'string') {\n return new Message(msg)\n } else {\n return Message.fromJson(msg)\n }\n}\n\nexport function endpoint(endpoint: Types.Endpoint): Endpoint\nexport function endpoint(scheme: string, host: string, port: number, path: string): Endpoint\nexport function endpoint(\n schemeOrEndpoint: string | Types.Endpoint,\n host?: string,\n port?: number,\n path?: string\n): Endpoint {\n if (typeof schemeOrEndpoint === 'string') {\n return new Endpoint(schemeOrEndpoint, host!, port!, path!)\n } else {\n return Endpoint.fromJson(schemeOrEndpoint)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAM,2BAA2B,oBAAI,IAAY,CAAC,eAAe,WAAW,UAAU,MAAM,CAAC;AAEtF,IAAM,OAAN,MAAW;AAAA,EACd;AAAA,EAEA,YAAY,MAAc;AACtB,SAAK,YAAY,EAAE,KAAK;AAAA,EAC5B;AAAA,EAEA,aAAa,MAAc,OAA8B;AACrD,SAAK,UAAU,IAAI,IAAI;AACvB,WAAO;AAAA,EACX;AAAA,EAEA,gBAAgB,MAAsB;AAClC,QAAI,yBAAyB,IAAI,IAAI,GAAG;AACpC,aAAO;AAAA,IACX;AACA,QAAI,CAAC,KAAK,WAAW,IAAI,GAAG;AACxB,aAAO,KAAK,IAAI;AAAA,IACpB;AACA,WAAO;AAAA,EACX;AAAA,EAEA,IAAI,OAAe;AACf,WAAO,KAAK,UAAU,MAAM;AAAA,EAChC;AAAA,EAEA,SAAS,MAAc,OAA8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,QAAQ,QAAQ,GAAG;AACjD,UAAI,SAAS,KAAK,KAAK;AAAA,IAC3B;AACA,eAAWA,YAAW,OAAO,OAAO,QAAQ,GAAG;AAC3C,UAAI,QAAQ,QAAQ,SAASA,QAAO,CAAC;AAAA,IACzC;AACA,WAAO;AAAA,EACX;AAAA,EAEA,cAAuB;AACnB,eAAWA,YAAW,OAAO,OAAO,KAAK,SAAS,GAAG;AACjD,MAAAA,SAAQ,YAAY;AAAA,IACxB;AACA,WAAO;AAAA,EACX;AACJ;AAIO,SAAS,KAAK,cAAmC,MAAqB;AACzE,MAAI,OAAO,iBAAiB,UAAU;AAClC,WAAO,IAAI,KAAK,cAAc,IAAK;AAAA,EACvC,OAAO;AACH,WAAO,KAAK,SAAS,YAAY;AAAA,EACrC;AACJ;AAEO,SAAS,QAAQA,UAA0C;AAC9D,MAAI,OAAOA,aAAY,UAAU;AAC7B,WAAO,IAAI,QAAQA,QAAO;AAAA,EAC9B,OAAO;AACH,WAAO,QAAQ,SAASA,QAAO;AAAA,EACnC;AACJ;AAEO,SAAS,KAAKD,OAAiC;AAClD,MAAI,OAAOA,UAAS,UAAU;AAC1B,WAAO,IAAI,KAAKA,KAAI;AAAA,EACxB,OAAO;AACH,WAAO,KAAK,SAASA,KAAI;AAAA,EAC7B;AACJ;AAEO,SAAS,QAAQ,KAAsC;AAC1D,MAAI,OAAO,QAAQ,UAAU;AACzB,WAAO,IAAI,QAAQ,GAAG;AAAA,EAC1B,OAAO;AACH,WAAO,QAAQ,SAAS,GAAG;AAAA,EAC/B;AACJ;AAIO,SAAS,SACZ,kBACA,MACA,MACA,MACQ;AACR,MAAI,OAAO,qBAAqB,UAAU;AACtC,WAAO,IAAI,SAAS,kBAAkB,MAAO,MAAO,IAAK;AAAA,EAC7D,OAAO;AACH,WAAO,SAAS,SAAS,gBAAgB;AAAA,EAC7C;AACJ;","names":["message","endpoint","role","network"]}
|
|
1
|
+
{"version":3,"sources":["../src/builder.ts"],"sourcesContent":["import type * as Types from './types'\n\nconst WELL_KNOWN_METADATA_KEYS = new Set<string>(['description', 'version', 'openws', 'name'])\n\nexport class Base {\n #metadata: Types.CommonMetadata\n\n constructor(name: string) {\n this.#metadata = { name }\n }\n\n #setMetadata(name: string, value: Types.JsonValue): this {\n this.#metadata[name] = value\n return this\n }\n\n #getMetadataKey(name: string): string {\n if (WELL_KNOWN_METADATA_KEYS.has(name)) {\n return name\n }\n if (!name.startsWith('x-')) {\n return `x-${name}`\n }\n return name\n }\n\n get name(): string {\n return this.#metadata['name'] as string\n }\n\n metadata(name: string, value: Types.JsonValue): this {\n return this.#setMetadata(this.#getMetadataKey(name), value)\n }\n\n getMetadata(name: string): Types.JsonValue | undefined {\n return this.#metadata[this.#getMetadataKey(name)] as Types.JsonValue | undefined\n }\n\n desc(description: string): this {\n return this.description(description)\n }\n\n description(description: string): this {\n return this.#setMetadata('description', description)\n }\n\n version(version: string): this {\n return this.#setMetadata('version', version)\n }\n\n title(title: string): this {\n return this.#setMetadata('title', title)\n }\n\n valueOf(): Types.CommonMetadata {\n return { ...this.#metadata }\n }\n\n toJson(): Types.CommonMetadata {\n return this.valueOf()\n }\n\n isValid(): boolean {\n return false\n }\n}\n\nexport class Message extends Base {\n get isPolytricMessage(): boolean {\n return true\n }\n #payload?: any\n #from?: string[]\n\n constructor(name: string) {\n super(name)\n }\n\n getPayload(): any | undefined {\n return this.#payload\n }\n\n payload(payload: any): this {\n this.#payload = payload.valueOf()\n return this\n }\n\n from(...from: string[]): this {\n this.#from ??= []\n this.#from.push(...from)\n return this\n }\n\n valueOf(): Types.Message {\n if (!this.#payload) {\n throw new Error('Payload is required')\n }\n const ret: Types.Message = {\n ...super.valueOf(),\n payload: this.#payload,\n }\n if (this.#from) {\n ret.from = this.#from\n }\n return ret\n }\n\n static fromJson(json: Types.Message): Message {\n const { payload, from, ...metadata } = json\n const ret = new Message(json.name as string)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n ret.payload(payload)\n if (from) {\n ret.from(...from)\n }\n return ret\n }\n\n assertValid(): boolean {\n if (this.#payload === undefined) {\n throw new Error('Payload is required')\n }\n return true\n }\n}\n\nexport class Endpoint {\n #scheme: string = 'ws'\n #host: string\n #port: number = 433\n #path: string\n\n constructor(scheme: string, host: string, port: number, path: string) {\n this.#scheme = scheme\n this.#host = host\n this.#port = port\n this.#path = path\n }\n\n valueOf(): Types.Endpoint {\n return {\n scheme: this.#scheme,\n host: this.#host,\n port: this.#port,\n path: this.#path,\n }\n }\n\n toJson(): Types.Endpoint {\n return this.valueOf()\n }\n\n static fromJson(json: Types.Endpoint): Endpoint {\n return new Endpoint(json.scheme, json.host, json.port, json.path)\n }\n}\n\nexport class Role extends Base {\n get isPolytricRole(): boolean {\n return true\n }\n #messages: { [key: string]: Message } = {}\n #endpoints: Endpoint[] = []\n\n isHost: boolean = false\n\n asHost(): this {\n this.isHost = true\n return this\n }\n\n message(message: Message): this {\n this.#messages[message.name] = message\n return this\n }\n\n get messages(): Record<string, Message> {\n return this.#messages\n }\n\n endpoint(endpoint: Endpoint): this {\n this.#endpoints.push(endpoint)\n return this\n }\n\n valueOf(): Types.Role {\n const messages: { [key: string]: Types.Message } = {}\n for (const [name, message] of Object.entries(this.#messages)) {\n messages[name] = message.valueOf()\n }\n const ret: Types.Role = {\n ...super.valueOf(),\n messages,\n }\n if (this.#endpoints.length > 0) {\n ret.endpoints = this.#endpoints.map(endpoint => endpoint.valueOf())\n }\n return ret\n }\n\n static fromJson(json: Types.Role): Role {\n const { messages, endpoints, ...metadata } = json\n const ret = new Role(json.name)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n for (const message of Object.values(messages)) {\n ret.message(Message.fromJson(message))\n }\n for (const endpoint of endpoints ?? []) {\n ret.endpoint(Endpoint.fromJson(endpoint))\n }\n return ret\n }\n\n assertValid(): boolean {\n for (const message of Object.values(this.#messages)) {\n message.assertValid()\n }\n return true\n }\n}\n\nexport class Network extends Base {\n get isPolytricNetwork(): boolean {\n return true\n }\n #roles: { [key: string]: Role } = {}\n\n role(role: Role): this {\n this.#roles[role.name] = role\n return this\n }\n\n get roles(): { [key: string]: Role } {\n return this.#roles\n }\n\n valueOf(): Types.Network {\n const roles: { [key: string]: Types.Role } = {}\n for (const [name, role] of Object.entries(this.#roles)) {\n roles[name] = role.valueOf()\n }\n return {\n ...super.valueOf(),\n roles,\n }\n }\n\n static fromJson(json: Types.Network): Network {\n const { roles, ...metadata } = json\n const ret = new Network(json.name as string)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n for (const role of Object.values(roles)) {\n ret.role(Role.fromJson(role))\n }\n return ret\n }\n\n assertValid(): boolean {\n const hostRoles: Role[] = []\n const remoteRoles: Role[] = []\n for (const role of Object.values(this.#roles)) {\n role.assertValid()\n\n if (role.isHost) {\n hostRoles.push(role as Role)\n } else {\n remoteRoles.push(role as Role)\n }\n }\n if (remoteRoles.length === 0) {\n throw new Error('At least one remote role must be defined')\n }\n const messages = new Set<string>()\n for (const role of Object.values(this.#roles)) {\n if (!role.isHost) {\n continue\n }\n for (const message of Object.values(role.messages)) {\n if (messages.has(message.name)) {\n throw new Error(\n `Message '${message.name}' is defined in multiple host roles: ${hostRoles.map(role => role.name).join(', ')}`\n )\n }\n messages.add(message.name)\n }\n }\n\n return true\n }\n}\n\nexport class Spec extends Base {\n get isPolytricSpec(): boolean {\n return true\n }\n #networks: { [key: string]: Network } = {}\n\n constructor(openws: string, name: string) {\n super(name)\n this.metadata('openws', openws)\n }\n\n network(network: Network): this {\n this.#networks[network.name] = network\n return this\n }\n\n get networks(): Record<string, Network> {\n return this.#networks\n }\n\n valueOf(): Types.Spec {\n const networks: { [key: string]: Types.Network } = {}\n for (const [name, network] of Object.entries(this.#networks)) {\n networks[name] = network.valueOf()\n }\n return {\n ...super.valueOf(),\n openws: this.getMetadata('openws') as string,\n networks,\n }\n }\n\n static fromJson(json: Types.Spec): Spec {\n const { networks, ...metadata } = json\n const ret = new Spec(json.openws as string, json.name as string)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n for (const network of Object.values(networks)) {\n ret.network(Network.fromJson(network))\n }\n return ret\n }\n\n assertValid(): boolean {\n for (const network of Object.values(this.#networks)) {\n network.assertValid()\n }\n return true\n }\n}\n\nexport function spec(openws: string, name: string): Spec\nexport function spec(spec: Types.Spec): Spec\nexport function spec(openwsOrSpec: string | Types.Spec, name?: string): Spec {\n if (typeof openwsOrSpec === 'string') {\n return new Spec(openwsOrSpec, name!)\n } else {\n return Spec.fromJson(openwsOrSpec)\n }\n}\n\nexport function network(network: string | Types.Network): Network {\n if (typeof network === 'string') {\n return new Network(network)\n } else {\n return Network.fromJson(network)\n }\n}\n\nexport function role(role: string | Types.Role): Role {\n if (typeof role === 'string') {\n return new Role(role)\n } else {\n return Role.fromJson(role)\n }\n}\n\nexport function message(msg: string | Types.Message): Message {\n if (typeof msg === 'string') {\n return new Message(msg)\n } else {\n return Message.fromJson(msg)\n }\n}\n\nexport function endpoint(endpoint: Types.Endpoint): Endpoint\nexport function endpoint(scheme: string, host: string, port: number, path: string): Endpoint\nexport function endpoint(\n schemeOrEndpoint: string | Types.Endpoint,\n host?: string,\n port?: number,\n path?: string\n): Endpoint {\n if (typeof schemeOrEndpoint === 'string') {\n return new Endpoint(schemeOrEndpoint, host!, port!, path!)\n } else {\n return Endpoint.fromJson(schemeOrEndpoint)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAM,2BAA2B,oBAAI,IAAY,CAAC,eAAe,WAAW,UAAU,MAAM,CAAC;AAEtF,IAAM,OAAN,MAAW;AAAA,EACd;AAAA,EAEA,YAAY,MAAc;AACtB,SAAK,YAAY,EAAE,KAAK;AAAA,EAC5B;AAAA,EAEA,aAAa,MAAc,OAA8B;AACrD,SAAK,UAAU,IAAI,IAAI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AQ,SAAS,GAAG;AAAA,EAC/B;AACJ;AAIO,SAAS,SACZ,kBACA,MACA,MACA,MACQ;AACR,MAAI,OAAO,qBAAqB,UAAU;AACtC,WAAO,IAAI,SAAS,kBAAkB,MAAO,MAAO,IAAK;AAAA,EAC7D,OAAO;AACH,WAAO,SAAS,SAAS,gBAAgB;AAAA,EAC7C;AACJ;","names":["message","endpoint","role","network"]}
|
package/dist/builder.js
CHANGED
|
@@ -220,17 +220,17 @@ var Network = class _Network extends Base {
|
|
|
220
220
|
}
|
|
221
221
|
assertValid() {
|
|
222
222
|
const hostRoles = [];
|
|
223
|
-
const
|
|
223
|
+
const remoteRoles = [];
|
|
224
224
|
for (const role2 of Object.values(this.#roles)) {
|
|
225
225
|
role2.assertValid();
|
|
226
226
|
if (role2.isHost) {
|
|
227
227
|
hostRoles.push(role2);
|
|
228
228
|
} else {
|
|
229
|
-
|
|
229
|
+
remoteRoles.push(role2);
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
-
if (
|
|
233
|
-
throw new Error("At least one
|
|
232
|
+
if (remoteRoles.length === 0) {
|
|
233
|
+
throw new Error("At least one remote role must be defined");
|
|
234
234
|
}
|
|
235
235
|
const messages = /* @__PURE__ */ new Set();
|
|
236
236
|
for (const role2 of Object.values(this.#roles)) {
|
package/dist/builder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/builder.ts"],"sourcesContent":["import type * as Types from './types'\n\nconst WELL_KNOWN_METADATA_KEYS = new Set<string>(['description', 'version', 'openws', 'name'])\n\nexport class Base {\n #metadata: Types.CommonMetadata\n\n constructor(name: string) {\n this.#metadata = { name }\n }\n\n #setMetadata(name: string, value: Types.JsonValue): this {\n this.#metadata[name] = value\n return this\n }\n\n #getMetadataKey(name: string): string {\n if (WELL_KNOWN_METADATA_KEYS.has(name)) {\n return name\n }\n if (!name.startsWith('x-')) {\n return `x-${name}`\n }\n return name\n }\n\n get name(): string {\n return this.#metadata['name'] as string\n }\n\n metadata(name: string, value: Types.JsonValue): this {\n return this.#setMetadata(this.#getMetadataKey(name), value)\n }\n\n getMetadata(name: string): Types.JsonValue | undefined {\n return this.#metadata[this.#getMetadataKey(name)] as Types.JsonValue | undefined\n }\n\n desc(description: string): this {\n return this.description(description)\n }\n\n description(description: string): this {\n return this.#setMetadata('description', description)\n }\n\n version(version: string): this {\n return this.#setMetadata('version', version)\n }\n\n title(title: string): this {\n return this.#setMetadata('title', title)\n }\n\n valueOf(): Types.CommonMetadata {\n return { ...this.#metadata }\n }\n\n toJson(): Types.CommonMetadata {\n return this.valueOf()\n }\n\n isValid(): boolean {\n return false\n }\n}\n\nexport class Message extends Base {\n get isPolytricMessage(): boolean {\n return true\n }\n #payload?: any\n #from?: string[]\n\n constructor(name: string) {\n super(name)\n }\n\n getPayload(): any | undefined {\n return this.#payload\n }\n\n payload(payload: any): this {\n this.#payload = payload.valueOf()\n return this\n }\n\n from(...from: string[]): this {\n this.#from ??= []\n this.#from.push(...from)\n return this\n }\n\n valueOf(): Types.Message {\n if (!this.#payload) {\n throw new Error('Payload is required')\n }\n const ret: Types.Message = {\n ...super.valueOf(),\n payload: this.#payload,\n }\n if (this.#from) {\n ret.from = this.#from\n }\n return ret\n }\n\n static fromJson(json: Types.Message): Message {\n const { payload, from, ...metadata } = json\n const ret = new Message(json.name as string)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n ret.payload(payload)\n if (from) {\n ret.from(...from)\n }\n return ret\n }\n\n assertValid(): boolean {\n if (this.#payload === undefined) {\n throw new Error('Payload is required')\n }\n return true\n }\n}\n\nexport class Endpoint {\n #scheme: string = 'ws'\n #host: string\n #port: number = 433\n #path: string\n\n constructor(scheme: string, host: string, port: number, path: string) {\n this.#scheme = scheme\n this.#host = host\n this.#port = port\n this.#path = path\n }\n\n valueOf(): Types.Endpoint {\n return {\n scheme: this.#scheme,\n host: this.#host,\n port: this.#port,\n path: this.#path,\n }\n }\n\n toJson(): Types.Endpoint {\n return this.valueOf()\n }\n\n static fromJson(json: Types.Endpoint): Endpoint {\n return new Endpoint(json.scheme, json.host, json.port, json.path)\n }\n}\n\nexport class Role extends Base {\n get isPolytricRole(): boolean {\n return true\n }\n #messages: { [key: string]: Message } = {}\n #endpoints: Endpoint[] = []\n\n isHost: boolean = false\n\n asHost(): this {\n this.isHost = true\n return this\n }\n\n message(message: Message): this {\n this.#messages[message.name] = message\n return this\n }\n\n get messages(): Record<string, Message> {\n return this.#messages\n }\n\n endpoint(endpoint: Endpoint): this {\n this.#endpoints.push(endpoint)\n return this\n }\n\n valueOf(): Types.Role {\n const messages: { [key: string]: Types.Message } = {}\n for (const [name, message] of Object.entries(this.#messages)) {\n messages[name] = message.valueOf()\n }\n const ret: Types.Role = {\n ...super.valueOf(),\n messages,\n }\n if (this.#endpoints.length > 0) {\n ret.endpoints = this.#endpoints.map(endpoint => endpoint.valueOf())\n }\n return ret\n }\n\n static fromJson(json: Types.Role): Role {\n const { messages, endpoints, ...metadata } = json\n const ret = new Role(json.name)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n for (const message of Object.values(messages)) {\n ret.message(Message.fromJson(message))\n }\n for (const endpoint of endpoints ?? []) {\n ret.endpoint(Endpoint.fromJson(endpoint))\n }\n return ret\n }\n\n assertValid(): boolean {\n for (const message of Object.values(this.#messages)) {\n message.assertValid()\n }\n return true\n }\n}\n\nexport class Network extends Base {\n get isPolytricNetwork(): boolean {\n return true\n }\n #roles: { [key: string]: Role } = {}\n\n role(role: Role): this {\n this.#roles[role.name] = role\n return this\n }\n\n get roles(): { [key: string]: Role } {\n return this.#roles\n }\n\n valueOf(): Types.Network {\n const roles: { [key: string]: Types.Role } = {}\n for (const [name, role] of Object.entries(this.#roles)) {\n roles[name] = role.valueOf()\n }\n return {\n ...super.valueOf(),\n roles,\n }\n }\n\n static fromJson(json: Types.Network): Network {\n const { roles, ...metadata } = json\n const ret = new Network(json.name as string)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n for (const role of Object.values(roles)) {\n ret.role(Role.fromJson(role))\n }\n return ret\n }\n\n assertValid(): boolean {\n const hostRoles: Role[] = []\n const consumerRoles: Role[] = []\n for (const role of Object.values(this.#roles)) {\n role.assertValid()\n\n if (role.isHost) {\n hostRoles.push(role as Role)\n } else {\n consumerRoles.push(role as Role)\n }\n }\n if (consumerRoles.length === 0) {\n throw new Error('At least one consumer role must be defined')\n }\n const messages = new Set<string>()\n for (const role of Object.values(this.#roles)) {\n if (!role.isHost) {\n continue\n }\n for (const message of Object.values(role.messages)) {\n if (messages.has(message.name)) {\n throw new Error(\n `Message '${message.name}' is defined in multiple host roles: ${hostRoles.map(role => role.name).join(', ')}`\n )\n }\n messages.add(message.name)\n }\n }\n\n return true\n }\n}\n\nexport class Spec extends Base {\n get isPolytricSpec(): boolean {\n return true\n }\n #networks: { [key: string]: Network } = {}\n\n constructor(openws: string, name: string) {\n super(name)\n this.metadata('openws', openws)\n }\n\n network(network: Network): this {\n this.#networks[network.name] = network\n return this\n }\n\n get networks(): Record<string, Network> {\n return this.#networks\n }\n\n valueOf(): Types.Spec {\n const networks: { [key: string]: Types.Network } = {}\n for (const [name, network] of Object.entries(this.#networks)) {\n networks[name] = network.valueOf()\n }\n return {\n ...super.valueOf(),\n openws: this.getMetadata('openws') as string,\n networks,\n }\n }\n\n static fromJson(json: Types.Spec): Spec {\n const { networks, ...metadata } = json\n const ret = new Spec(json.openws as string, json.name as string)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n for (const network of Object.values(networks)) {\n ret.network(Network.fromJson(network))\n }\n return ret\n }\n\n assertValid(): boolean {\n for (const network of Object.values(this.#networks)) {\n network.assertValid()\n }\n return true\n }\n}\n\nexport function spec(openws: string, name: string): Spec\nexport function spec(spec: Types.Spec): Spec\nexport function spec(openwsOrSpec: string | Types.Spec, name?: string): Spec {\n if (typeof openwsOrSpec === 'string') {\n return new Spec(openwsOrSpec, name!)\n } else {\n return Spec.fromJson(openwsOrSpec)\n }\n}\n\nexport function network(network: string | Types.Network): Network {\n if (typeof network === 'string') {\n return new Network(network)\n } else {\n return Network.fromJson(network)\n }\n}\n\nexport function role(role: string | Types.Role): Role {\n if (typeof role === 'string') {\n return new Role(role)\n } else {\n return Role.fromJson(role)\n }\n}\n\nexport function message(msg: string | Types.Message): Message {\n if (typeof msg === 'string') {\n return new Message(msg)\n } else {\n return Message.fromJson(msg)\n }\n}\n\nexport function endpoint(endpoint: Types.Endpoint): Endpoint\nexport function endpoint(scheme: string, host: string, port: number, path: string): Endpoint\nexport function endpoint(\n schemeOrEndpoint: string | Types.Endpoint,\n host?: string,\n port?: number,\n path?: string\n): Endpoint {\n if (typeof schemeOrEndpoint === 'string') {\n return new Endpoint(schemeOrEndpoint, host!, port!, path!)\n } else {\n return Endpoint.fromJson(schemeOrEndpoint)\n }\n}\n"],"mappings":";AAEA,IAAM,2BAA2B,oBAAI,IAAY,CAAC,eAAe,WAAW,UAAU,MAAM,CAAC;AAEtF,IAAM,OAAN,MAAW;AAAA,EACd;AAAA,EAEA,YAAY,MAAc;AACtB,SAAK,YAAY,EAAE,KAAK;AAAA,EAC5B;AAAA,EAEA,aAAa,MAAc,OAA8B;AACrD,SAAK,UAAU,IAAI,IAAI;AACvB,WAAO;AAAA,EACX;AAAA,EAEA,gBAAgB,MAAsB;AAClC,QAAI,yBAAyB,IAAI,IAAI,GAAG;AACpC,aAAO;AAAA,IACX;AACA,QAAI,CAAC,KAAK,WAAW,IAAI,GAAG;AACxB,aAAO,KAAK,IAAI;AAAA,IACpB;AACA,WAAO;AAAA,EACX;AAAA,EAEA,IAAI,OAAe;AACf,WAAO,KAAK,UAAU,MAAM;AAAA,EAChC;AAAA,EAEA,SAAS,MAAc,OAA8B;AACjD,WAAO,KAAK,aAAa,KAAK,gBAAgB,IAAI,GAAG,KAAK;AAAA,EAC9D;AAAA,EAEA,YAAY,MAA2C;AACnD,WAAO,KAAK,UAAU,KAAK,gBAAgB,IA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ASA,QAAO,CAAC;AAAA,IACzC;AACA,WAAO;AAAA,EACX;AAAA,EAEA,cAAuB;AACnB,eAAWA,YAAW,OAAO,OAAO,KAAK,SAAS,GAAG;AACjD,MAAAA,SAAQ,YAAY;AAAA,IACxB;AACA,WAAO;AAAA,EACX;AACJ;AAIO,SAAS,KAAK,cAAmC,MAAqB;AACzE,MAAI,OAAO,iBAAiB,UAAU;AAClC,WAAO,IAAI,KAAK,cAAc,IAAK;AAAA,EACvC,OAAO;AACH,WAAO,KAAK,SAAS,YAAY;AAAA,EACrC;AACJ;AAEO,SAAS,QAAQA,UAA0C;AAC9D,MAAI,OAAOA,aAAY,UAAU;AAC7B,WAAO,IAAI,QAAQA,QAAO;AAAA,EAC9B,OAAO;AACH,WAAO,QAAQ,SAASA,QAAO;AAAA,EACnC;AACJ;AAEO,SAAS,KAAKD,OAAiC;AAClD,MAAI,OAAOA,UAAS,UAAU;AAC1B,WAAO,IAAI,KAAKA,KAAI;AAAA,EACxB,OAAO;AACH,WAAO,KAAK,SAASA,KAAI;AAAA,EAC7B;AACJ;AAEO,SAAS,QAAQ,KAAsC;AAC1D,MAAI,OAAO,QAAQ,UAAU;AACzB,WAAO,IAAI,QAAQ,GAAG;AAAA,EAC1B,OAAO;AACH,WAAO,QAAQ,SAAS,GAAG;AAAA,EAC/B;AACJ;AAIO,SAAS,SACZ,kBACA,MACA,MACA,MACQ;AACR,MAAI,OAAO,qBAAqB,UAAU;AACtC,WAAO,IAAI,SAAS,kBAAkB,MAAO,MAAO,IAAK;AAAA,EAC7D,OAAO;AACH,WAAO,SAAS,SAAS,gBAAgB;AAAA,EAC7C;AACJ;","names":["message","endpoint","role","network"]}
|
|
1
|
+
{"version":3,"sources":["../src/builder.ts"],"sourcesContent":["import type * as Types from './types'\n\nconst WELL_KNOWN_METADATA_KEYS = new Set<string>(['description', 'version', 'openws', 'name'])\n\nexport class Base {\n #metadata: Types.CommonMetadata\n\n constructor(name: string) {\n this.#metadata = { name }\n }\n\n #setMetadata(name: string, value: Types.JsonValue): this {\n this.#metadata[name] = value\n return this\n }\n\n #getMetadataKey(name: string): string {\n if (WELL_KNOWN_METADATA_KEYS.has(name)) {\n return name\n }\n if (!name.startsWith('x-')) {\n return `x-${name}`\n }\n return name\n }\n\n get name(): string {\n return this.#metadata['name'] as string\n }\n\n metadata(name: string, value: Types.JsonValue): this {\n return this.#setMetadata(this.#getMetadataKey(name), value)\n }\n\n getMetadata(name: string): Types.JsonValue | undefined {\n return this.#metadata[this.#getMetadataKey(name)] as Types.JsonValue | undefined\n }\n\n desc(description: string): this {\n return this.description(description)\n }\n\n description(description: string): this {\n return this.#setMetadata('description', description)\n }\n\n version(version: string): this {\n return this.#setMetadata('version', version)\n }\n\n title(title: string): this {\n return this.#setMetadata('title', title)\n }\n\n valueOf(): Types.CommonMetadata {\n return { ...this.#metadata }\n }\n\n toJson(): Types.CommonMetadata {\n return this.valueOf()\n }\n\n isValid(): boolean {\n return false\n }\n}\n\nexport class Message extends Base {\n get isPolytricMessage(): boolean {\n return true\n }\n #payload?: any\n #from?: string[]\n\n constructor(name: string) {\n super(name)\n }\n\n getPayload(): any | undefined {\n return this.#payload\n }\n\n payload(payload: any): this {\n this.#payload = payload.valueOf()\n return this\n }\n\n from(...from: string[]): this {\n this.#from ??= []\n this.#from.push(...from)\n return this\n }\n\n valueOf(): Types.Message {\n if (!this.#payload) {\n throw new Error('Payload is required')\n }\n const ret: Types.Message = {\n ...super.valueOf(),\n payload: this.#payload,\n }\n if (this.#from) {\n ret.from = this.#from\n }\n return ret\n }\n\n static fromJson(json: Types.Message): Message {\n const { payload, from, ...metadata } = json\n const ret = new Message(json.name as string)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n ret.payload(payload)\n if (from) {\n ret.from(...from)\n }\n return ret\n }\n\n assertValid(): boolean {\n if (this.#payload === undefined) {\n throw new Error('Payload is required')\n }\n return true\n }\n}\n\nexport class Endpoint {\n #scheme: string = 'ws'\n #host: string\n #port: number = 433\n #path: string\n\n constructor(scheme: string, host: string, port: number, path: string) {\n this.#scheme = scheme\n this.#host = host\n this.#port = port\n this.#path = path\n }\n\n valueOf(): Types.Endpoint {\n return {\n scheme: this.#scheme,\n host: this.#host,\n port: this.#port,\n path: this.#path,\n }\n }\n\n toJson(): Types.Endpoint {\n return this.valueOf()\n }\n\n static fromJson(json: Types.Endpoint): Endpoint {\n return new Endpoint(json.scheme, json.host, json.port, json.path)\n }\n}\n\nexport class Role extends Base {\n get isPolytricRole(): boolean {\n return true\n }\n #messages: { [key: string]: Message } = {}\n #endpoints: Endpoint[] = []\n\n isHost: boolean = false\n\n asHost(): this {\n this.isHost = true\n return this\n }\n\n message(message: Message): this {\n this.#messages[message.name] = message\n return this\n }\n\n get messages(): Record<string, Message> {\n return this.#messages\n }\n\n endpoint(endpoint: Endpoint): this {\n this.#endpoints.push(endpoint)\n return this\n }\n\n valueOf(): Types.Role {\n const messages: { [key: string]: Types.Message } = {}\n for (const [name, message] of Object.entries(this.#messages)) {\n messages[name] = message.valueOf()\n }\n const ret: Types.Role = {\n ...super.valueOf(),\n messages,\n }\n if (this.#endpoints.length > 0) {\n ret.endpoints = this.#endpoints.map(endpoint => endpoint.valueOf())\n }\n return ret\n }\n\n static fromJson(json: Types.Role): Role {\n const { messages, endpoints, ...metadata } = json\n const ret = new Role(json.name)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n for (const message of Object.values(messages)) {\n ret.message(Message.fromJson(message))\n }\n for (const endpoint of endpoints ?? []) {\n ret.endpoint(Endpoint.fromJson(endpoint))\n }\n return ret\n }\n\n assertValid(): boolean {\n for (const message of Object.values(this.#messages)) {\n message.assertValid()\n }\n return true\n }\n}\n\nexport class Network extends Base {\n get isPolytricNetwork(): boolean {\n return true\n }\n #roles: { [key: string]: Role } = {}\n\n role(role: Role): this {\n this.#roles[role.name] = role\n return this\n }\n\n get roles(): { [key: string]: Role } {\n return this.#roles\n }\n\n valueOf(): Types.Network {\n const roles: { [key: string]: Types.Role } = {}\n for (const [name, role] of Object.entries(this.#roles)) {\n roles[name] = role.valueOf()\n }\n return {\n ...super.valueOf(),\n roles,\n }\n }\n\n static fromJson(json: Types.Network): Network {\n const { roles, ...metadata } = json\n const ret = new Network(json.name as string)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n for (const role of Object.values(roles)) {\n ret.role(Role.fromJson(role))\n }\n return ret\n }\n\n assertValid(): boolean {\n const hostRoles: Role[] = []\n const remoteRoles: Role[] = []\n for (const role of Object.values(this.#roles)) {\n role.assertValid()\n\n if (role.isHost) {\n hostRoles.push(role as Role)\n } else {\n remoteRoles.push(role as Role)\n }\n }\n if (remoteRoles.length === 0) {\n throw new Error('At least one remote role must be defined')\n }\n const messages = new Set<string>()\n for (const role of Object.values(this.#roles)) {\n if (!role.isHost) {\n continue\n }\n for (const message of Object.values(role.messages)) {\n if (messages.has(message.name)) {\n throw new Error(\n `Message '${message.name}' is defined in multiple host roles: ${hostRoles.map(role => role.name).join(', ')}`\n )\n }\n messages.add(message.name)\n }\n }\n\n return true\n }\n}\n\nexport class Spec extends Base {\n get isPolytricSpec(): boolean {\n return true\n }\n #networks: { [key: string]: Network } = {}\n\n constructor(openws: string, name: string) {\n super(name)\n this.metadata('openws', openws)\n }\n\n network(network: Network): this {\n this.#networks[network.name] = network\n return this\n }\n\n get networks(): Record<string, Network> {\n return this.#networks\n }\n\n valueOf(): Types.Spec {\n const networks: { [key: string]: Types.Network } = {}\n for (const [name, network] of Object.entries(this.#networks)) {\n networks[name] = network.valueOf()\n }\n return {\n ...super.valueOf(),\n openws: this.getMetadata('openws') as string,\n networks,\n }\n }\n\n static fromJson(json: Types.Spec): Spec {\n const { networks, ...metadata } = json\n const ret = new Spec(json.openws as string, json.name as string)\n for (const [key, value] of Object.entries(metadata)) {\n ret.metadata(key, value)\n }\n for (const network of Object.values(networks)) {\n ret.network(Network.fromJson(network))\n }\n return ret\n }\n\n assertValid(): boolean {\n for (const network of Object.values(this.#networks)) {\n network.assertValid()\n }\n return true\n }\n}\n\nexport function spec(openws: string, name: string): Spec\nexport function spec(spec: Types.Spec): Spec\nexport function spec(openwsOrSpec: string | Types.Spec, name?: string): Spec {\n if (typeof openwsOrSpec === 'string') {\n return new Spec(openwsOrSpec, name!)\n } else {\n return Spec.fromJson(openwsOrSpec)\n }\n}\n\nexport function network(network: string | Types.Network): Network {\n if (typeof network === 'string') {\n return new Network(network)\n } else {\n return Network.fromJson(network)\n }\n}\n\nexport function role(role: string | Types.Role): Role {\n if (typeof role === 'string') {\n return new Role(role)\n } else {\n return Role.fromJson(role)\n }\n}\n\nexport function message(msg: string | Types.Message): Message {\n if (typeof msg === 'string') {\n return new Message(msg)\n } else {\n return Message.fromJson(msg)\n }\n}\n\nexport function endpoint(endpoint: Types.Endpoint): Endpoint\nexport function endpoint(scheme: string, host: string, port: number, path: string): Endpoint\nexport function endpoint(\n schemeOrEndpoint: string | Types.Endpoint,\n host?: string,\n port?: number,\n path?: string\n): Endpoint {\n if (typeof schemeOrEndpoint === 'string') {\n return new Endpoint(schemeOrEndpoint, host!, port!, path!)\n } else {\n return Endpoint.fromJson(schemeOrEndpoint)\n }\n}\n"],"mappings":";AAEA,IAAM,2BAA2B,oBAAI,IAAY,CAAC,eAAe,WAAW,UAAU,MAAM,CAAC;AAEtF,IAAM,OAAN,MAAW;AAAA,EACd;AAAA,EAEA,YAAY,MAAc;AACtB,SAAK,YAAY,EAAE,KAAK;AAAA,EAC5B;AAAA,EAEA,aAAa,MAAc,OAA8B;AACrD,SAAK,UAAU,IAAI,IAAI;AACvB,WAAO;AAAA,EACX;AAAA,EAEA,gBAAgB,MAAsB;AAClC,QAAI,yBAAyB,IAAI,IAAI,GAAG;AACpC,aAAO;AAAA,IACX;AACA,QAAI,CAAC,KAAK,WAAW,IAAI,GAAG;AACxB,aAAO,KAAK,IAAI;AAAA,IACpB;AACA,WAAO;AAAA,EACX;AAAA,EAEA,IAAI,OAAe;AACf,WAAO,KAAK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package/dist/index.cjs
CHANGED
|
@@ -39,7 +39,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
39
39
|
// package.json
|
|
40
40
|
var package_default = {
|
|
41
41
|
name: "@polytric/openws-spec",
|
|
42
|
-
version: "0.0.
|
|
42
|
+
version: "0.0.4",
|
|
43
43
|
description: "Polytric OpenWS Specification",
|
|
44
44
|
type: "module",
|
|
45
45
|
main: "./dist/index.js",
|
|
@@ -116,10 +116,10 @@ var endpointSchema = import_schema.default.obj({
|
|
|
116
116
|
endpointSchema.additionalProperties = true;
|
|
117
117
|
var roleSchema = import_schema.default.obj({
|
|
118
118
|
endpoints: import_schema.default.arr(endpointSchema).min(1).optional().desc(
|
|
119
|
-
"A role can declare an endpoint to accept connections from
|
|
119
|
+
"A role can declare an endpoint to accept connections from remote roles, normally used by servers"
|
|
120
120
|
),
|
|
121
121
|
messages: import_schema.default.map.keyPattern(keyPattern).value(messageSchema).desc(
|
|
122
|
-
"A message accepted by the role and handled by the role, and roles can send messages
|
|
122
|
+
"A message accepted by the role and handled by the role, and roles can send messages to remote roles that accept them. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (though description can document the behavior)."
|
|
123
123
|
),
|
|
124
124
|
description: import_schema.default.str.optional()
|
|
125
125
|
});
|
|
@@ -144,7 +144,7 @@ openWsSchema.additionalProperties = true;
|
|
|
144
144
|
var spec_schema_default = openWsSchema;
|
|
145
145
|
|
|
146
146
|
// src/spec-schema.json
|
|
147
|
-
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
|
|
147
|
+
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 remote 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 to remote roles that accept them. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (though description can document the behavior).", 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#" };
|
|
148
148
|
|
|
149
149
|
// src/index.ts
|
|
150
150
|
var VERSION = package_default.version;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../package.json","../src/spec-schema.ts","../src/spec-schema.json"],"sourcesContent":["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","{\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,oBAAAA;AAAA,EAAA;AAAA;AAAA;;;ACAA;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;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EAAC,MAAO,SAAQ,GAAE,MAAO,EAAC,MAAO,SAAQ,OAAQ,EAAC,MAAO,SAAQ,GAAE,aAAc,6CAA4C,EAAC,GAAE,UAAW,CAAC,SAAS,GAAE,sBAAuB,KAAI,EAAC,GAAE,aAAc,iTAAgT,sBAAuB,MAAK,GAAE,aAAc,EAAC,MAAO,SAAQ,EAAC,GAAE,UAAW,CAAC,UAAU,GAAE,sBAAuB,KAAI,EAAC,GAAE,sBAAuB,MAAK,GAAE,aAAc,EAAC,MAAO,SAAQ,EAAC,GAAE,UAAW,CAAC,OAAO,GAAE,sBAAuB,KAAI,EAAC,GAAE,sBAAuB,MAAK,EAAC,GAAE,UAAW,CAAC,UAAS,UAAU,GAAE,sBAAuB,MAAK,SAAU,0CAAyC;;;AHIv1E,IAAM,UAAU,gBAAI;AAI3B,IAAI;AAEG,SAAS,SAAS,MAAiB;AACtC,cAAY,aAAa,oBAAoB,QAAQ,WAAW;AAChE,YAAU,IAAI;AAClB;","names":["spec_schema_default","S","spec_schema_default"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../package.json","../src/spec-schema.ts","../src/spec-schema.json"],"sourcesContent":["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","{\n \"name\": \"@polytric/openws-spec\",\n \"version\": \"0.0.4\",\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 remote 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 to remote roles that accept them. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (though description can document the behavior).\"\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 remote 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 to remote roles that accept them. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (though description can document the behavior).\",\"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,oBAAAA;AAAA,EAAA;AAAA;AAAA;;;ACAA;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,E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AC,4CAA2C,EAAC,MAAO,UAAS,YAAa,EAAC,WAAY,EAAC,MAAO,SAAQ,OAAQ,EAAC,MAAO,UAAS,YAAa,EAAC,MAAO,EAAC,MAAO,SAAQ,GAAE,MAAO,EAAC,MAAO,WAAU,SAAU,GAAE,SAAU,MAAK,GAAE,MAAO,EAAC,MAAO,SAAQ,EAAC,GAAE,UAAW,CAAC,QAAO,QAAO,MAAM,GAAE,sBAAuB,KAAI,GAAE,UAAW,GAAE,aAAc,mGAAkG,GAAE,UAAW,EAAC,MAAO,UAAS,mBAAoB,EAAC,4CAA2C,EAAC,MAAO,UAAS,YAAa,EAAC,SAAU,EAAC,MAAO,UAAS,aAAc,gHAA+G,sBAAuB,KAAI,GAAE,aAAc,EAAC,MAAO,SAAQ,GAAE,MAAO,EAAC,MAAO,SAAQ,OAAQ,EAAC,MAAO,SAAQ,GAAE,aAAc,6CAA4C,EAAC,GAAE,UAAW,CAAC,SAAS,GAAE,sBAAuB,KAAI,EAAC,GAAE,aAAc,gTAA+S,sBAAuB,MAAK,GAAE,aAAc,EAAC,MAAO,SAAQ,EAAC,GAAE,UAAW,CAAC,UAAU,GAAE,sBAAuB,KAAI,EAAC,GAAE,sBAAuB,MAAK,GAAE,aAAc,EAAC,MAAO,SAAQ,EAAC,GAAE,UAAW,CAAC,OAAO,GAAE,sBAAuB,KAAI,EAAC,GAAE,sBAAuB,MAAK,EAAC,GAAE,UAAW,CAAC,UAAS,UAAU,GAAE,sBAAuB,MAAK,SAAU,0CAAyC;;;AHIv1E,IAAM,UAAU,gBAAI;AAI3B,IAAI;AAEG,SAAS,SAAS,MAAiB;AACtC,cAAY,aAAa,oBAAoB,QAAQ,WAAW;AAChE,YAAU,IAAI;AAClB;","names":["spec_schema_default","S","spec_schema_default"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -60,7 +60,7 @@ var properties = {
|
|
|
60
60
|
additionalProperties: true
|
|
61
61
|
},
|
|
62
62
|
minItems: 1,
|
|
63
|
-
description: "A role can declare an endpoint to accept connections from
|
|
63
|
+
description: "A role can declare an endpoint to accept connections from remote roles, normally used by servers"
|
|
64
64
|
},
|
|
65
65
|
messages: {
|
|
66
66
|
type: "object",
|
|
@@ -90,7 +90,7 @@ var properties = {
|
|
|
90
90
|
additionalProperties: true
|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
|
-
description: "A message accepted by the role and handled by the role, and roles can send messages
|
|
93
|
+
description: "A message accepted by the role and handled by the role, and roles can send messages to remote roles that accept them. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (though description can document the behavior).",
|
|
94
94
|
additionalProperties: false
|
|
95
95
|
},
|
|
96
96
|
description: {
|
package/dist/index.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ var properties = {
|
|
|
60
60
|
additionalProperties: true
|
|
61
61
|
},
|
|
62
62
|
minItems: 1,
|
|
63
|
-
description: "A role can declare an endpoint to accept connections from
|
|
63
|
+
description: "A role can declare an endpoint to accept connections from remote roles, normally used by servers"
|
|
64
64
|
},
|
|
65
65
|
messages: {
|
|
66
66
|
type: "object",
|
|
@@ -90,7 +90,7 @@ var properties = {
|
|
|
90
90
|
additionalProperties: true
|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
|
-
description: "A message accepted by the role and handled by the role, and roles can send messages
|
|
93
|
+
description: "A message accepted by the role and handled by the role, and roles can send messages to remote roles that accept them. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (though description can document the behavior).",
|
|
94
94
|
additionalProperties: false
|
|
95
95
|
},
|
|
96
96
|
description: {
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "@polytric/openws-spec",
|
|
4
|
-
version: "0.0.
|
|
4
|
+
version: "0.0.4",
|
|
5
5
|
description: "Polytric OpenWS Specification",
|
|
6
6
|
type: "module",
|
|
7
7
|
main: "./dist/index.js",
|
|
@@ -78,10 +78,10 @@ var endpointSchema = S.obj({
|
|
|
78
78
|
endpointSchema.additionalProperties = true;
|
|
79
79
|
var roleSchema = S.obj({
|
|
80
80
|
endpoints: S.arr(endpointSchema).min(1).optional().desc(
|
|
81
|
-
"A role can declare an endpoint to accept connections from
|
|
81
|
+
"A role can declare an endpoint to accept connections from remote roles, normally used by servers"
|
|
82
82
|
),
|
|
83
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
|
|
84
|
+
"A message accepted by the role and handled by the role, and roles can send messages to remote roles that accept them. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (though description can document the behavior)."
|
|
85
85
|
),
|
|
86
86
|
description: S.str.optional()
|
|
87
87
|
});
|
|
@@ -106,7 +106,7 @@ openWsSchema.additionalProperties = true;
|
|
|
106
106
|
var spec_schema_default = openWsSchema;
|
|
107
107
|
|
|
108
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
|
|
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 remote 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 to remote roles that accept them. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (though description can document the behavior).", 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
110
|
|
|
111
111
|
// src/index.ts
|
|
112
112
|
var VERSION = package_default.version;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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"],"m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AY,aAAa,oBAAoB,QAAQ,WAAW;AAChE,YAAU,IAAI;AAClB;","names":["spec_schema_default"]}
|
|
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.4\",\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 remote 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 to remote roles that accept them. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (though description can document the behavior).\"\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 remote 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 to remote roles that accept them. The OpenWS spec only defines the shape of the payload, and how things get encoded / decoded on the wire, it doesn't determine behavior (though description can document the behavior).\",\"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,E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