@spine-event-engine/client-node 2.0.0-snapshot.11

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # Spine client for Node.js
2
+
3
+ Use this package from a Node.js ESM application to post commands, send queries,
4
+ or create subscriptions for query-side views. It owns the Node HTTP/2 transport;
5
+ the request and subscription API is shared with the browser client.
6
+
7
+ This is an experimental snapshot. Install the snapshot explicitly while its API
8
+ and packaging continue to evolve:
9
+
10
+ ```sh
11
+ pnpm add @spine-event-engine/client-node@snapshot
12
+ ```
13
+
14
+ For detailed public contracts, lifecycle rules, and limits, read the
15
+ [reference](REFERENCE.md).
16
+
17
+ ## 💡 Who should use it?
18
+
19
+ - ✅ Node.js services, workers, and command-line applications that call a Spine
20
+ application gateway.
21
+ - ✅ Applications that already own a generated Spine model package and a
22
+ reachable local or deployed Spine service.
23
+ - ❌ Browser applications; use `@spine-event-engine/client-web` instead.
24
+
25
+ ## 🚀 Post a command to a local application
26
+
27
+ Before running this example, use Node.js with ESM support, generate and build
28
+ your application's Proto model, and start that application's local Spine
29
+ service. For the concrete Message Board workspace walkthrough, clone this
30
+ repository, run `pnpm install --frozen-lockfile && pnpm typecheck:build`, then
31
+ start `pnpm --dir examples/message-board/app start`. That command starts the
32
+ single-tenant local service at `http://127.0.0.1:8090`.
33
+
34
+ The imports below are the Message Board workspace model contract: its
35
+ `package.json` exports compiled `generated/*.js` modules after the setup above.
36
+ They are not an installable dependency for an external application. In your
37
+ application, depend on your own generated model package and replace this model
38
+ package name and generated export paths with the ones declared by its
39
+ `package.json` and `spine-proto.json`.
40
+
41
+ Create one client for the component that manages the connection. A client from
42
+ `connectTo()` owns its HTTP/2 session, so always close it.
43
+
44
+ <!-- docs-snippet-path: examples/message-board/app/src/index.ts -->
45
+
46
+ ```ts
47
+ import { create } from "@bufbuild/protobuf";
48
+ import { timestampFromDate } from "@bufbuild/protobuf/wkt";
49
+ import { Client } from "@spine-event-engine/client-node";
50
+ import { PostMessageSchema } from "@spine-event-engine/example-message-board-model/generated/spine/examples/messageboard/commands_pb.js";
51
+ import {
52
+ BoardIdSchema,
53
+ MessageIdSchema,
54
+ } from "@spine-event-engine/example-message-board-model/generated/spine/examples/messageboard/message_board_pb.js";
55
+ import { UserIdSchema } from "@spine-event-engine/example-message-board-model/generated/spine/examples/messageboard/user_pb.js";
56
+
57
+ const client = Client.connectTo("http://127.0.0.1:8090");
58
+ const request = client.onBehalfOf("alice");
59
+ const result = await request.post(
60
+ PostMessageSchema,
61
+ create(PostMessageSchema, {
62
+ id: create(MessageIdSchema, { value: "message-1" }),
63
+ board: create(BoardIdSchema, { value: "general" }),
64
+ author: create(UserIdSchema, { value: "alice" }),
65
+ username: "Alice",
66
+ text: "Hello, Message Board.",
67
+ postedAt: timestampFromDate(new Date()),
68
+ }),
69
+ );
70
+ if (result.kind !== "ok") throw new Error(`Message was not accepted: ${result.kind}`);
71
+ await client.close();
72
+ ```
73
+
74
+ The URL is an application gateway URL. It is not an instruction to expose a
75
+ Spine server directly to the internet. A successful call is an observation that
76
+ the local service accepted the command; handle rejection and error outcomes in
77
+ your application instead of assuming every command succeeds.
78
+
79
+ ## 🔎 Query generated entities
80
+
81
+ Generate entity columns from the model package, register them once, and build
82
+ queries with those declared columns. The `./codegen` entry point is for model
83
+ generation; applications use the generated definition and `EntityQuery`.
84
+ `limit()` requires an ordering. Only generated columns for the selected Entity
85
+ may be used in its predicates.
86
+
87
+ The [reference](REFERENCE.md) documents the query builder and its column-safety
88
+ rules.
89
+
90
+ ## ⚠️ Cleanup and limits
91
+
92
+ The client does not make a server safe for public access. Put the authenticated
93
+ application gateway at the network boundary. Commands are not retried
94
+ automatically, and an interrupted subscription must be recreated before the
95
+ application re-reads current entity state.
96
+
97
+ Node subscriptions use the same `createSubscription`, `activate`, and `cancel`
98
+ API as the browser client; see the [client-web reference](https://github.com/SpineEventEngine/spine-ts/blob/master/packages/client-web/REFERENCE.md)
99
+ for lifecycle and recovery limits. Close the client during process shutdown so
100
+ its owned HTTP/2 session and subscriptions can finish cleanup.
101
+
102
+ ## 🔗 Learn more
103
+
104
+ - [Browser client](https://github.com/SpineEventEngine/spine-ts/blob/master/packages/client-web/README.md)
105
+ - [Server](https://github.com/SpineEventEngine/spine-ts/blob/master/packages/server/README.md)
106
+ - [Detailed coding-agent reference](REFERENCE.md)
package/REFERENCE.md ADDED
@@ -0,0 +1,22 @@
1
+ # @spine-event-engine/client-node reference
2
+
3
+ This reference records the exact public contract of `@spine-event-engine/client-node`.
4
+ Start with the [Node client overview](README.md) for the shortest connection path.
5
+
6
+ ## Client construction
7
+
8
+ `Client.connectTo(baseUrl, options)` creates a shared `client-web` `Client` with a Node Connect HTTP/2 session. `client.close()` closes subscriptions and then aborts that session. `Client.usingTransport(transport, options)` uses a Connect transport supplied by the caller; closing the returned client does not close the supplied transport. Each `post()` creates its Command through the shared core signal-envelope helper, which assigns a fresh secure UUID-based Command ID.
9
+
10
+ The returned kernel supports `asGuest()` and `onBehalfOf(user)` request scopes. A scope has `post(schema, value, options)`, `send(query, options)`, and `createSubscription(topic, options)`. See the [client-web reference](../client-web/REFERENCE.md) for command outcomes, cancellation, subscription lifecycle, recovery, and terminal behavior shared by both clients.
11
+
12
+ ## Entity query API
13
+
14
+ `EntityColumn.register(schema, definition)` validates and binds generated columns to one Entity schema. The generated `EntityColumnDefinition` comes from the package's `./codegen` entry point. `EntityQuery.select({ schema, columns, context })` starts a builder. It supports `where`, `orderBy`, `limit`, and `build`, plus static predicates `eq`, `gt`, `lt`, `ge`, `le`, `all`, and `either`.
15
+
16
+ Predicates accept only columns registered for the selected Entity. `limit()` requires at least one order clause. The compiler packs declared values and the `version`, `archived`, and `deleted` system columns into the wire query. Builders and columns are immutable, so a predicate cannot be reused for a different Entity target.
17
+
18
+ ## Code generation
19
+
20
+ Use `protoc-gen-spine-entity-columns` or the `@spine-event-engine/client-node/codegen` entry point only from a model-generation workflow. Generated code uses `GeneratedEntityColumns`; application code should import the generated definition, register it, and construct queries through the public API above.
21
+
22
+ This package is Node-only because it imports Node HTTP/2 and code-generation dependencies. Browser applications use `@spine-event-engine/client-web`.
@@ -0,0 +1,25 @@
1
+ import type { DescField } from "@bufbuild/protobuf";
2
+
3
+ export type EntityFieldClassification =
4
+ | Readonly<{ supported: false; reason: "singular" | "oneof" }>
5
+ | Readonly<{
6
+ supported: true;
7
+ valueKind: "bigint" | "boolean" | "bytes" | "enum" | "message" | "number" | "string";
8
+ messageType?: string;
9
+ comparison: "equality" | "ordering";
10
+ }>;
11
+
12
+ /**
13
+ * Classifies Protobuf descriptors used by the Entity-column generator.
14
+ */
15
+ export declare const EntityFieldClassification: Readonly<{
16
+ // prettier-ignore
17
+
18
+ /**
19
+ * Classifies one Protobuf field descriptor.
20
+ *
21
+ * @param field Field descriptor supplied by the generator.
22
+ * @returns The Entity-column classification.
23
+ */
24
+ classify(field: DescField): EntityFieldClassification;
25
+ }>;
@@ -0,0 +1,68 @@
1
+ const scalarBool = 8;
2
+ const scalarBytes = 12;
3
+ const scalarInt64 = 3;
4
+ const scalarUint64 = 4;
5
+ const scalarFixed64 = 6;
6
+ const scalarSfixed64 = 16;
7
+ const scalarSint64 = 18;
8
+
9
+ /**
10
+ * Classifies Protobuf fields for Entity-column generation and registration.
11
+ */
12
+ export const EntityFieldClassification = Object.freeze({
13
+ // prettier-ignore
14
+
15
+ /**
16
+ * Classifies one field without depending on generated Spine descriptors.
17
+ *
18
+ * @param field Protobuf field descriptor supplied by the generator.
19
+ * @returns The supported value and comparison classification.
20
+ */
21
+ classify(field) {
22
+ if (field.fieldKind === "list" || field.fieldKind === "map") {
23
+ return { supported: false, reason: "singular" };
24
+ }
25
+ if (field.oneof !== undefined) {
26
+ return { supported: false, reason: "oneof" };
27
+ }
28
+ if (field.fieldKind === "enum") {
29
+ return { supported: true, valueKind: "enum", comparison: "equality" };
30
+ }
31
+ if (field.fieldKind === "message") {
32
+ const messageType = field.message.typeName;
33
+ return {
34
+ supported: true,
35
+ valueKind: "message",
36
+ messageType,
37
+ comparison:
38
+ messageType === "google.protobuf.Timestamp" || messageType === "spine.core.Version"
39
+ ? "ordering"
40
+ : "equality",
41
+ };
42
+ }
43
+ if (field.scalar === scalarBool) {
44
+ return { supported: true, valueKind: "boolean", comparison: "equality" };
45
+ }
46
+ if (field.scalar === scalarBytes) {
47
+ return { supported: true, valueKind: "bytes", comparison: "equality" };
48
+ }
49
+ if (
50
+ field.scalar === scalarInt64 ||
51
+ field.scalar === scalarUint64 ||
52
+ field.scalar === scalarFixed64 ||
53
+ field.scalar === scalarSfixed64 ||
54
+ field.scalar === scalarSint64
55
+ ) {
56
+ return {
57
+ supported: true,
58
+ valueKind: field.longAsString ? "string" : "bigint",
59
+ comparison: "ordering",
60
+ };
61
+ }
62
+ return {
63
+ supported: true,
64
+ valueKind: field.scalar === 9 ? "string" : "number",
65
+ comparison: "ordering",
66
+ };
67
+ },
68
+ });
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env node
2
+ import { getOption, hasOption } from "@bufbuild/protobuf";
3
+ import { createEcmaScriptPlugin, runNodeJs } from "@bufbuild/protoplugin";
4
+ import { fileURLToPath } from "node:url";
5
+ import { resolve } from "node:path";
6
+ import process from "node:process";
7
+ import { EntityFieldClassification } from "./entity-field-classification.mjs";
8
+
9
+ /**
10
+ * Generates typed Entity-column companions from Spine Protobuf input.
11
+ */
12
+ export const EntityColumnGenerator = Object.freeze({
13
+ // prettier-ignore
14
+
15
+ /**
16
+ * Resolves Spine option descriptors supplied in the protoc plugin request.
17
+ *
18
+ * @param schema Plugin schema containing input files and dependencies.
19
+ * @returns The Entity and column option descriptors.
20
+ */
21
+ resolveOptions(schema) {
22
+ let entity;
23
+ let column;
24
+ const pending = [...schema.allFiles];
25
+ const visited = new Set();
26
+ while (pending.length > 0) {
27
+ const file = pending.pop();
28
+ if (file === undefined || visited.has(file)) continue;
29
+ visited.add(file);
30
+ pending.push(...(file.dependencies ?? []));
31
+ const descriptors = [...(file.extensions ?? []), ...schema.typesInFile(file)];
32
+ for (const descriptor of descriptors) {
33
+ if (descriptor.kind !== "extension") continue;
34
+ if (
35
+ descriptor.name === "entity" &&
36
+ descriptor.extendee.typeName === "google.protobuf.MessageOptions" &&
37
+ descriptor.file.proto.name === "spine/options.proto"
38
+ ) {
39
+ entity = descriptor;
40
+ }
41
+ if (
42
+ descriptor.name === "column" &&
43
+ descriptor.extendee.typeName === "google.protobuf.FieldOptions" &&
44
+ descriptor.file.proto.name === "spine/options.proto"
45
+ ) {
46
+ column = descriptor;
47
+ }
48
+ }
49
+ }
50
+ if (entity === undefined || column === undefined) {
51
+ throw new Error("The plugin request must include spine/options.proto descriptors.");
52
+ }
53
+ const kindField = entity.message.fields.find((field) => field.name === "kind");
54
+ if (kindField?.fieldKind !== "enum") {
55
+ throw new Error("The Spine entity option descriptor must declare entity kinds.");
56
+ }
57
+ return { entity, column };
58
+ },
59
+
60
+ /**
61
+ * Returns top-level queryable Entity messages in an input file.
62
+ *
63
+ * @param file Protobuf file being generated.
64
+ * @param options Resolved Spine option descriptors.
65
+ * @returns Queryable Entity message descriptors.
66
+ */
67
+ entities(file, options) {
68
+ return file.messages.filter(
69
+ (message) =>
70
+ message.parent === undefined &&
71
+ hasOption(message, options.entity) &&
72
+ ["AGGREGATE", "PROJECTION", "PROCESS_MANAGER"].includes(
73
+ options.entity.message.fields
74
+ .find((field) => field.name === "kind")
75
+ ?.enum?.values.find((value) => value.number === getOption(message, options.entity).kind)
76
+ ?.name,
77
+ ),
78
+ );
79
+ },
80
+
81
+ /**
82
+ * Reports whether a field carries Spine's `(column) = true` option.
83
+ *
84
+ * @param field Candidate Entity state field.
85
+ * @param options Resolved Spine option descriptors.
86
+ * @returns Whether the field is queryable.
87
+ */
88
+ isColumn(field, options) {
89
+ return hasOption(field, options.column) && getOption(field, options.column);
90
+ },
91
+
92
+ /**
93
+ * Derives the comparison family for a Protobuf field descriptor.
94
+ *
95
+ * @param field Candidate queryable Entity field.
96
+ * @returns The generated comparison family.
97
+ */
98
+ comparison(field) {
99
+ const classification = EntityFieldClassification.classify(field);
100
+ if (!classification.supported) {
101
+ throw new TypeError(
102
+ classification.reason === "singular"
103
+ ? `Entity column "${field.localName}" must be singular; repeated and map fields are unsupported.`
104
+ : `Entity column "${field.localName}" cannot belong to a oneof.`,
105
+ );
106
+ }
107
+ return classification.comparison;
108
+ },
109
+
110
+ /**
111
+ * Generates deterministic companions for all queryable Entities in a request.
112
+ *
113
+ * @param schema Plugin schema used to create generated files.
114
+ * @returns Nothing after emitting zero or more companions.
115
+ */
116
+ generate(schema) {
117
+ const candidateFiles = schema.files.filter((file) =>
118
+ (file.proto.dependency ?? []).includes("spine/options.proto"),
119
+ );
120
+ if (candidateFiles.length === 0) return;
121
+ const options = EntityColumnGenerator.resolveOptions(schema);
122
+ for (const file of candidateFiles) {
123
+ const entities = EntityColumnGenerator.entities(file, options);
124
+ if (entities.length === 0) continue;
125
+
126
+ const output = schema.generateFile(`${file.name}_columns.ts`);
127
+ const generatedColumns = output.import(
128
+ "GeneratedEntityColumns",
129
+ "@spine-event-engine/client-node/codegen",
130
+ );
131
+ const definitionType = output.import(
132
+ "EntityColumnDefinition",
133
+ "@spine-event-engine/client-node/codegen",
134
+ true,
135
+ );
136
+ output.preamble(file);
137
+
138
+ for (const entity of entities) {
139
+ const entitySchema = output.importSchema(entity);
140
+ const columnFields = entity.fields.filter((field) =>
141
+ EntityColumnGenerator.isColumn(field, options),
142
+ );
143
+ output.print(
144
+ output.export("const", `${entity.name}ColumnDefinition`),
145
+ ": ",
146
+ definitionType,
147
+ "<typeof ",
148
+ entitySchema,
149
+ ", {",
150
+ );
151
+ for (const field of columnFields) {
152
+ output.print(
153
+ ` readonly ${JSON.stringify(field.localName)}: { readonly field: typeof `,
154
+ entitySchema,
155
+ `.field[${JSON.stringify(field.localName)}]; readonly comparison: ${JSON.stringify(EntityColumnGenerator.comparison(field))} };`,
156
+ );
157
+ }
158
+ output.print("}> = ", generatedColumns, ".define(", entitySchema, ", {");
159
+ for (const field of columnFields) {
160
+ output.print(
161
+ ` ${JSON.stringify(field.localName)}: { field: `,
162
+ entitySchema,
163
+ `.field[${JSON.stringify(field.localName)}], comparison: ${JSON.stringify(EntityColumnGenerator.comparison(field))} },`,
164
+ );
165
+ }
166
+ output.print("});");
167
+ }
168
+ }
169
+ },
170
+ });
171
+
172
+ const entityColumnPlugin = createEcmaScriptPlugin({
173
+ name: "protoc-gen-spine-entity-columns",
174
+ version: "1.0.0",
175
+ generateTs: EntityColumnGenerator.generate,
176
+ });
177
+
178
+ if (process.argv[1] !== undefined && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
179
+ runNodeJs(entityColumnPlugin);
180
+ }
@@ -0,0 +1,24 @@
1
+ import { Client as WebClient, type ClientOptions } from "@spine-event-engine/client-web";
2
+ import type { Transport } from "@connectrpc/connect";
3
+ /**
4
+ * Creates Node transport-backed instances of the shared browser-safe client kernel.
5
+ */
6
+ export declare const Client: Readonly<{
7
+ /**
8
+ * Connects through a Node-owned HTTP/2 session.
9
+ *
10
+ * @param baseUrl Gateway base URL.
11
+ * @param options Shared client construction options.
12
+ * @returns A client that closes its owned HTTP/2 session.
13
+ */
14
+ connectTo(baseUrl: string, options?: ClientOptions): WebClient;
15
+ /**
16
+ * Uses a caller-owned Connect transport.
17
+ *
18
+ * @param transport Connect transport that remains caller-owned.
19
+ * @param options Shared client construction options.
20
+ * @returns A client that does not close the supplied transport.
21
+ */
22
+ usingTransport(transport: Transport, options?: ClientOptions): WebClient;
23
+ }>;
24
+ //# sourceMappingURL=node-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-client.d.ts","sourceRoot":"","sources":["../../src/client/node-client.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,MAAM,IAAI,SAAS,EACnB,KAAK,aAAa,EAEnB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,QAAQ,CAAC;IAG5B;;;;;;OAMG;IACH,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IAE/D;;;;;;OAMG;IACH,cAAc,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;CAC1E,CAsBC,CAAC"}