@orthograph/projections 0.0.0-stage → 0.1.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +26 -2
  3. package/dist/main.d.ts +9 -0
  4. package/dist/main.js +12 -0
  5. package/dist/modules/actions/internal/actions.d.ts +7 -0
  6. package/dist/modules/actions/internal/actions.js +22 -0
  7. package/dist/modules/actions/service.d.ts +5 -0
  8. package/dist/modules/actions/service.js +14 -0
  9. package/dist/modules/actions/types.d.ts +9 -0
  10. package/dist/modules/actions/types.js +5 -0
  11. package/dist/modules/api/internal/api.d.ts +4 -0
  12. package/dist/modules/api/internal/api.js +99 -0
  13. package/dist/modules/api/service.d.ts +5 -0
  14. package/dist/modules/api/service.js +16 -0
  15. package/dist/modules/api/types.d.ts +1 -0
  16. package/dist/modules/api/types.js +1 -0
  17. package/dist/modules/app/internal/links.d.ts +2 -0
  18. package/dist/modules/app/internal/links.js +22 -0
  19. package/dist/modules/app/internal/palette.d.ts +6 -0
  20. package/dist/modules/app/internal/palette.js +55 -0
  21. package/dist/modules/app/internal/render.d.ts +4 -0
  22. package/dist/modules/app/internal/render.js +30 -0
  23. package/dist/modules/app/internal/view.d.ts +3 -0
  24. package/dist/modules/app/internal/view.js +52 -0
  25. package/dist/modules/app/service.d.ts +5 -0
  26. package/dist/modules/app/service.js +17 -0
  27. package/dist/modules/app/types.d.ts +52 -0
  28. package/dist/modules/app/types.js +1 -0
  29. package/dist/modules/cli/internal/cli.d.ts +3 -0
  30. package/dist/modules/cli/internal/cli.js +35 -0
  31. package/dist/modules/cli/internal/session.d.ts +11 -0
  32. package/dist/modules/cli/internal/session.js +55 -0
  33. package/dist/modules/cli/service.d.ts +2 -0
  34. package/dist/modules/cli/service.js +10 -0
  35. package/dist/modules/cli/types.d.ts +1 -0
  36. package/dist/modules/cli/types.js +1 -0
  37. package/dist/modules/handlers/internal/body.d.ts +5 -0
  38. package/dist/modules/handlers/internal/body.js +79 -0
  39. package/dist/modules/handlers/internal/calls.d.ts +17 -0
  40. package/dist/modules/handlers/internal/calls.js +80 -0
  41. package/dist/modules/handlers/internal/header.d.ts +18 -0
  42. package/dist/modules/handlers/internal/header.js +106 -0
  43. package/dist/modules/handlers/internal/paths.d.ts +18 -0
  44. package/dist/modules/handlers/internal/paths.js +11 -0
  45. package/dist/modules/handlers/internal/scaffold.d.ts +7 -0
  46. package/dist/modules/handlers/internal/scaffold.js +73 -0
  47. package/dist/modules/handlers/internal/stubs.d.ts +3 -0
  48. package/dist/modules/handlers/internal/stubs.js +120 -0
  49. package/dist/modules/handlers/internal/words.d.ts +43 -0
  50. package/dist/modules/handlers/internal/words.js +87 -0
  51. package/dist/modules/handlers/service.d.ts +5 -0
  52. package/dist/modules/handlers/service.js +9 -0
  53. package/dist/modules/handlers/types.d.ts +2 -0
  54. package/dist/modules/handlers/types.js +1 -0
  55. package/dist/modules/infra/internal/stack.d.ts +3 -0
  56. package/dist/modules/infra/internal/stack.js +15 -0
  57. package/dist/modules/infra/service.d.ts +5 -0
  58. package/dist/modules/infra/service.js +13 -0
  59. package/dist/modules/infra/types.d.ts +1 -0
  60. package/dist/modules/infra/types.js +1 -0
  61. package/dist/modules/mcp/internal/mcp.d.ts +3 -0
  62. package/dist/modules/mcp/internal/mcp.js +20 -0
  63. package/dist/modules/mcp/service.d.ts +5 -0
  64. package/dist/modules/mcp/service.js +13 -0
  65. package/dist/modules/mcp/types.d.ts +1 -0
  66. package/dist/modules/mcp/types.js +1 -0
  67. package/dist/modules/model/internal/edges.d.ts +4 -0
  68. package/dist/modules/model/internal/edges.js +12 -0
  69. package/dist/modules/model/service.d.ts +6 -0
  70. package/dist/modules/model/service.js +20 -0
  71. package/dist/modules/model/types.d.ts +1 -0
  72. package/dist/modules/model/types.js +1 -0
  73. package/dist/modules/names/internal/names.d.ts +51 -0
  74. package/dist/modules/names/internal/names.js +47 -0
  75. package/dist/modules/names/internal/when.d.ts +5 -0
  76. package/dist/modules/names/internal/when.js +19 -0
  77. package/dist/modules/names/internal/words.d.ts +34 -0
  78. package/dist/modules/names/internal/words.js +61 -0
  79. package/dist/modules/names/service.d.ts +19 -0
  80. package/dist/modules/names/service.js +19 -0
  81. package/dist/modules/names/types.d.ts +16 -0
  82. package/dist/modules/names/types.js +5 -0
  83. package/dist/modules/sdk/internal/client.d.ts +2 -0
  84. package/dist/modules/sdk/internal/client.js +31 -0
  85. package/dist/modules/sdk/internal/sdk.d.ts +3 -0
  86. package/dist/modules/sdk/internal/sdk.js +68 -0
  87. package/dist/modules/sdk/internal/types.d.ts +8 -0
  88. package/dist/modules/sdk/internal/types.js +38 -0
  89. package/dist/modules/sdk/service.d.ts +5 -0
  90. package/dist/modules/sdk/service.js +13 -0
  91. package/dist/modules/sdk/types.d.ts +1 -0
  92. package/dist/modules/sdk/types.js +1 -0
  93. package/dist/modules/server/internal/actors.d.ts +3 -0
  94. package/dist/modules/server/internal/actors.js +5 -0
  95. package/dist/modules/server/internal/doors.d.ts +10 -0
  96. package/dist/modules/server/internal/doors.js +26 -0
  97. package/dist/modules/server/internal/helpers.d.ts +13 -0
  98. package/dist/modules/server/internal/helpers.js +70 -0
  99. package/dist/modules/server/internal/server.d.ts +3 -0
  100. package/dist/modules/server/internal/server.js +65 -0
  101. package/dist/modules/server/internal/versioned.d.ts +13 -0
  102. package/dist/modules/server/internal/versioned.js +17 -0
  103. package/dist/modules/server/internal/worker-config.d.ts +16 -0
  104. package/dist/modules/server/internal/worker-config.js +90 -0
  105. package/dist/modules/server/service.d.ts +10 -0
  106. package/dist/modules/server/service.js +20 -0
  107. package/dist/modules/server/types.d.ts +1 -0
  108. package/dist/modules/server/types.js +1 -0
  109. package/dist/shared.d.ts +6 -0
  110. package/dist/shared.js +6 -0
  111. package/package.json +32 -3
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,27 @@
1
- # Temporary Holding Version
1
+ # @orthograph/projections
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The projections Orthograph ships, each a plugin of kind `projection` that an app mounts in `blueprint/projections/<name>.ts`
4
+ ([`design/decisions/M1-plugins.md`](../../design/decisions/M1-plugins.md) sections 2, 3 and 15;
5
+ [`design/history/retired-2026-11-23/frame/projections.md`](../../design/history/retired-2026-11-23/frame/projections.md) sections 1 and 2):
6
+
7
+ ```ts
8
+ // blueprint/projections/server.ts
9
+ import { Blueprint } from "orthograph";
10
+ import { server } from "@orthograph/projections";
11
+
12
+ export default Blueprint.use(server);
13
+ ```
14
+
15
+ Part one (M1.11) has `model`, `api` and `server`. The SDK, the CLI and MCP (M1.12), and the docs and portal (M1.13)
16
+ still render from the fixed list in `@orthograph/generators` and arrive here when those slices land.
17
+
18
+ A mount is what makes the output: `ortho generate` writes `generated/<mount>/` for each projection mounted and nothing for
19
+ one that isn't. A project that mounts no projection at all gets the three as if it had mounted them (see
20
+ `packages/generators/src/modules/render/internal/mounted.ts`).
21
+
22
+ The package is `env:build`: it runs where `ortho generate` runs and never in production. What it generates imports only
23
+ the language's runtime, `orthograph`, the host and the project's own code, never this package. The project may import it
24
+ (`scope:project` may depend on `scope:projections`, because a blueprint mounts it as it mounts any plugin).
25
+
26
+ `./shared` is for `@orthograph/generators` while the other projections wait on its fixed list: the names every renderer
27
+ shares, the handler scaffold and the empty server `prove` uses. It goes when M1.13 is done.
package/dist/main.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export { model } from "#modules/model/service.js";
2
+ export { api } from "#modules/api/service.js";
3
+ export { server } from "#modules/server/service.js";
4
+ export { sdk } from "#modules/sdk/service.js";
5
+ export { cli } from "#modules/cli/service.js";
6
+ export { mcp } from "#modules/mcp/service.js";
7
+ export { actions } from "#modules/actions/service.js";
8
+ export { infra } from "#modules/infra/service.js";
9
+ export { app } from "#modules/app/service.js";
package/dist/main.js ADDED
@@ -0,0 +1,12 @@
1
+ // @orthograph/projections: the projections Orthograph ships, each one a plugin an app mounts in `blueprint/projections/`
2
+ // (`export default Blueprint.use(server, (p) => [])`). Parts one and two of M1.11 to M1.13: `model`, `api`, `server`, `sdk`, `cli`, `mcp`, `infra` and `actions` (M1.22); the docs
3
+ // and the portal follow, and arrive here too (M1-plugins section 15, X-10).
4
+ export { model } from "#modules/model/service.js";
5
+ export { api } from "#modules/api/service.js";
6
+ export { server } from "#modules/server/service.js";
7
+ export { sdk } from "#modules/sdk/service.js";
8
+ export { cli } from "#modules/cli/service.js";
9
+ export { mcp } from "#modules/mcp/service.js";
10
+ export { actions } from "#modules/actions/service.js";
11
+ export { infra } from "#modules/infra/service.js";
12
+ export { app } from "#modules/app/service.js";
@@ -0,0 +1,7 @@
1
+ import { Effect } from "effect";
2
+ import type { Model, OperationModel } from "@orthograph/compiler";
3
+ import type { RenderedFile } from "#modules/names/types.js";
4
+ import { UnknownRefusal } from "../types.ts";
5
+ /** `readOnly` is true when the operation can write nothing: no `move`, and every step a `load` (no steps counts). WEB-actions-projection call 1. */
6
+ export declare const readsOnly: (op: OperationModel) => boolean;
7
+ export declare const renderActions: (model: Model, name: string) => Effect.Effect<ReadonlyArray<RenderedFile>, UnknownRefusal>;
@@ -0,0 +1,22 @@
1
+ // generated/actions: one module per operation, K29 section 3.1's shape. Every field is the model's; `run` is one `host.call` of the SDK's call.
2
+ import { Effect } from "effect";
3
+ import { camel, lines, member, pascal } from "#modules/names/service.js";
4
+ import { UnknownRefusal } from "../types.js";
5
+ /** `readOnly` is true when the operation can write nothing: no `move`, and every step a `load` (no steps counts). WEB-actions-projection call 1. */
6
+ export const readsOnly = (op) => !op.move && Object.keys(op.steps).every((step) => step === "load");
7
+ /** A sentence inside a doc comment: its own comment end would close the comment early. */
8
+ const comment = (text) => text.replace(/\*\//g, "*\\/").replace(/\s*\n\s*/g, " ");
9
+ const one = (op, client, errors) => {
10
+ const call = `Sdk.${camel(op.thing)}.${camel(op.verb)}`;
11
+ return {
12
+ path: `generated/actions/${op.thing}/${op.verb}.ts`,
13
+ scaffold: false,
14
+ content: lines(`// Generated from ${op.file}. Do not edit.`, `import type { Effect } from "effect";`, `import type { PayloadOf } from "orthograph";`, `import type { ActionHost, ActionOptions } from "orthograph/actions";`, `import type * as Sdk from "../../sdk/src/index.ts";`, `import { declaration } from "../../api/src/${op.thing}/${op.verb}.ts";`, "", `type Payload = PayloadOf<typeof declaration>;`, `type Answer = Effect.Success<ReturnType<typeof ${call}>>;`, "", `/** ${comment(op.description)} */`, `export const options = (host: ActionHost<Sdk.${client}["Service"]>): ActionOptions<Payload, Answer> => ({`, ` name: ${JSON.stringify(op.name)},`, ` description: ${JSON.stringify(op.description)},`, ` schema: declaration.payloadSchema,`, ` readOnly: ${readsOnly(op)},`, ` needsApproval: ${op.needsApproval === true},`, ` agentTool: ${op.agentTool},`, ` errors: { ${errors.join(", ")} },`, ` run: (args, ctx) => host.call((client) => client${member(op.thing)}${member(op.verb)}({ payload: args }), ctx),`, `});`),
15
+ };
16
+ };
17
+ /** Each refusal an operation declares, with its code from the model; one the model has no code for fails the render. */
18
+ const errorsOf = (model, op) => Effect.forEach(op.refusals, (tag) => {
19
+ const code = model.refusals[tag];
20
+ return code === undefined ? Effect.fail(new UnknownRefusal({ message: `${op.file}: ${op.name} declares the refusal ${tag}, and the model has no code for it` })) : Effect.succeed(`${tag}: ${JSON.stringify(code)}`);
21
+ });
22
+ export const renderActions = (model, name) => Effect.forEach(Object.values(model.operations), (op) => Effect.map(errorsOf(model, op), (errors) => one(op, pascal(name), errors)));
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The actions (`generated/actions/`): one module per operation exporting `options(host)`, an agent-native action's fields read from
3
+ * the model, whose `run` is the SDK's own call made through the host. It never calls `defineAction`.
4
+ */
5
+ export declare const actions: import("orthograph").Projection<{}>;
@@ -0,0 +1,14 @@
1
+ import { Effect } from "effect";
2
+ import { Blueprint, Host, Ships } from "orthograph";
3
+ import { modelOf, serverModel, within } from "#modules/names/service.js";
4
+ import { renderActions } from "./internal/actions.js";
5
+ /**
6
+ * The actions (`generated/actions/`): one module per operation exporting `options(host)`, an agent-native action's fields read from
7
+ * the model, whose `run` is the SDK's own call made through the host. It never calls `defineAction`.
8
+ */
9
+ export const actions = Blueprint.projection({
10
+ description: "The actions: a module per operation, its name, flags, refusals and schema from the model, its run the SDK's call through the host.",
11
+ host: [Host.node, Host.browser],
12
+ ships: [Ships.release],
13
+ render: (input) => Effect.flatMap(renderActions(serverModel(modelOf(input)), input.name), (files) => within(input, "actions", files)),
14
+ });
@@ -0,0 +1,9 @@
1
+ export type { Projection } from "orthograph";
2
+ declare const UnknownRefusal_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
3
+ readonly _tag: "UnknownRefusal";
4
+ } & Readonly<A>;
5
+ /** An operation declares a refusal the model has no code for: the model is wrong, and no action is written from it. */
6
+ export declare class UnknownRefusal extends UnknownRefusal_base<{
7
+ readonly message: string;
8
+ }> {
9
+ }
@@ -0,0 +1,5 @@
1
+ // The `actions` projection is a `Projection` (orthograph's plugins module).
2
+ import { Data } from "effect";
3
+ /** An operation declares a refusal the model has no code for: the model is wrong, and no action is written from it. */
4
+ export class UnknownRefusal extends Data.TaggedError("UnknownRefusal") {
5
+ }
@@ -0,0 +1,4 @@
1
+ import type { Model } from "@orthograph/compiler";
2
+ import type { RenderedFile } from "#modules/names/types.js";
3
+ /** `served` is the model without its device operations; each of those still gets its declaration in the API folder. */
4
+ export declare const renderApi: (model: Model, name: string, served?: Model) => ReadonlyArray<RenderedFile>;
@@ -0,0 +1,99 @@
1
+ // generated/api: the contract. Endpoints from each operation's own declaration, wire errors, the handler types.
2
+ import { Names } from "orthograph/server";
3
+ import { GENERATED, IDEMPOTENCY_CONFLICT, IDEMPOTENCY_CONFLICT_EXIT, NOT_ALLOWED_EXIT, READ_NOT_SERVED, READ_NOT_SERVED_EXIT, STATUS, declarationAt, lines, onDevice, opVar, pascal, thingFileAt } from "#modules/names/service.js";
4
+ const file = (path, content) => ({ path, content, scaffold: false });
5
+ const errors = (model) => {
6
+ const path = "generated/api/src/errors.ts";
7
+ const things = Object.values(model.things);
8
+ const declaring = things.filter((t) => Object.keys(t.errors).length > 0);
9
+ const rows = [];
10
+ const declared = [];
11
+ const body = [];
12
+ // One row per refusal: its code, its exit and its HTTP status, written once and read by every surface (K16, M1.47).
13
+ const row = (name, code, exit, status) => {
14
+ rows.push(` ${name}: { code: "${code}", exit: ${exit}, status: ${status} },`);
15
+ };
16
+ // Each refusal's code is beside its tag: a field on the wire class, and a static the runtime reads it from.
17
+ const cls = (name, fields) => `export class ${name} extends Schema.TaggedError<${name}>()("${name}", { code: Schema.Literal(refusals.${name}.code), ...${fields} }, { httpApiStatus: refusals.${name}.status }) { static readonly code = refusals.${name}.code; }`;
18
+ for (const t of declaring) {
19
+ for (const [name, e] of Object.entries(t.errors)) {
20
+ body.push(`ErrorNames.name(${t.identifier}.${name}, "${name}");`);
21
+ body.push(cls(name, `wireStruct(${t.identifier}.${name}.fields).fields`));
22
+ // A thing's declared `<Thing>NotFound` is its not-found refusal, adopted by the runtime (K16): 404, not 422.
23
+ row(name, e.code, e.exit, name === `${t.identifier}NotFound` ? STATUS.notFound : STATUS.declared);
24
+ declared.push(` ${name}: ${t.identifier}.${name},`);
25
+ }
26
+ }
27
+ for (const t of things) {
28
+ if (!t.machine)
29
+ continue;
30
+ const { error, exit, code } = t.machine.notFrom;
31
+ // The state the thing was found in: one of the machine's own, so a caller can match on it.
32
+ body.push(cls(error, `{ state: Schema.Literals([${t.machine.states.map((s) => JSON.stringify(s)).join(", ")}]) }`));
33
+ row(error, code, exit, STATUS.notFrom);
34
+ }
35
+ for (const t of things) {
36
+ // The generated `<Thing>NotFound`, carrying the id that named nothing; a declared one is already above.
37
+ if (!t.notFound || t.notFound.error in t.errors)
38
+ continue;
39
+ const { error, exit, code } = t.notFound;
40
+ body.push(cls(error, "{ id: Schema.String }"));
41
+ row(error, code, exit, STATUS.notFound);
42
+ }
43
+ body.push(cls("NotAllowed", "{}"));
44
+ row("NotAllowed", model.refusals["NotAllowed"] ?? "AR-001", NOT_ALLOWED_EXIT, STATUS.notAllowed);
45
+ body.push(cls(IDEMPOTENCY_CONFLICT, "{}"));
46
+ row(IDEMPOTENCY_CONFLICT, model.refusals[IDEMPOTENCY_CONFLICT] ?? "AR-002", IDEMPOTENCY_CONFLICT_EXIT, STATUS.idempotencyConflict);
47
+ // A derived read that looks at problems is not served yet: it refuses by name, 501, never as a defect (the rest are served, slice 7 of Goal 17).
48
+ if (READ_NOT_SERVED in model.refusals) {
49
+ body.push(cls(READ_NOT_SERVED, "{ read: Schema.String, message: Schema.String }"));
50
+ row(READ_NOT_SERVED, model.refusals[READ_NOT_SERVED], READ_NOT_SERVED_EXIT, STATUS.notServed);
51
+ }
52
+ const names = rows.map((e) => e.trim().split(":")[0]);
53
+ return file(path, lines(GENERATED, `import { Schema } from "effect";`, `import { ErrorNames, wireStruct } from "${Names.frontDoor}/server";`, declaring.map((t) => `import * as ${t.identifier} from "${thingFileAt(path, t, "errors")}";`), "", "/** Every refusal's code, its exit for the CLI and its HTTP status: one row each, read by the CLI, HTTP and MCP. */", "export const refusals = {", rows, "} as const;", "type Refusal = keyof typeof refusals;", "", body, "", "/** Each refusal's exit code, for the CLI: read from `refusals`. */", "export const exits = Object.fromEntries(Object.entries(refusals).map(([k, r]) => [k, r.exit])) as { readonly [K in Refusal]: (typeof refusals)[K][\"exit\"] };", "", "/** Each refusal's code, stable across targets: `[AL-002] Name { field: value }`. Beside the tag, never in place of it. Read from `refusals`. */", "export const codes = Object.fromEntries(Object.entries(refusals).map(([k, r]) => [k, r.code])) as { readonly [K in Refusal]: (typeof refusals)[K][\"code\"] };", "", "/** The declared errors themselves, by name: their fields say who may see a value (the visibility rule cuts a refusal by them). */", "export const declared = {", declared, "} as const;", "", "/** The wire class of each refusal, by name. */", `export const wire = { ${names.join(", ")} };`));
54
+ };
55
+ /** The names of the fields a client may not be shown: private to roles, or secret and not issued by this call. */
56
+ const cut = (fields, issuing) => Object.entries(fields).filter(([, f]) => f.visibility !== undefined && !(issuing && f.issued === true)).map(([k]) => `"${k}"`);
57
+ const endpoint = (op, model) => {
58
+ const path = `generated/api/src/${op.thing}/${op.verb}.ts`;
59
+ // What the SDK is typed to decode: a field the server may cut for a caller is optional, in the answer and in each list item.
60
+ const keys = cut(op.answer, op.kind === "operation");
61
+ const itemKeys = op.list ? cut(Object.fromEntries(Object.entries(model.things[op.thing]?.fields ?? {}).filter(([k]) => k !== "state")), false) : [];
62
+ const typed = keys.length > 0 || itemKeys.length > 0;
63
+ return file(path, lines(`// Generated from ${op.file}. Do not edit.`, `import { HttpApiEndpoint } from "effect/http-api";`, `import { ${op.list ? "listItemFields, " : ""}wireStruct${typed ? ", type Wired" : ""} } from "${Names.frontDoor}/server";`, `import declaration from "${declarationAt(path, op.file)}";`, `import { ${op.refusals.join(", ")} } from "../errors.ts";`, "", "export { declaration };", `export const endpoint = HttpApiEndpoint.post("${op.verb}", "/${op.thing}/${op.verb}", {`, " payload: declaration.payloadSchema,", ` // What the wire carries: the declared answer, the fields not every caller is shown optional. The server cuts each answer by who is asking.`, ` // Typed as the declaration types it: the schema is built from fields known only at run time, which TypeScript cannot follow.`, ` success: wireStruct(declaration.answer, { issuing: true${op.list ? ", items: listItemFields(declaration.thing)" : ""} }) as unknown as ${typed ? `Wired<typeof declaration.answerSchema, ${keys.length > 0 ? keys.join(" | ") : "never"}${itemKeys.length > 0 ? `, ${itemKeys.join(" | ")}` : ""}>` : "typeof declaration.answerSchema"},`, ` error: [${op.refusals.join(", ")}],`, "});"));
64
+ };
65
+ /** An operation that runs on the device has no route: only its declaration, which the SDK and the CLI read. */
66
+ const declarationOnly = (op) => {
67
+ const path = `generated/api/src/${op.thing}/${op.verb}.ts`;
68
+ return file(path, lines(`// Generated from ${op.file}. Do not edit.`, `import declaration from "${declarationAt(path, op.file)}";`, "", "export { declaration };"));
69
+ };
70
+ /** Some environment's clock is stepped or scaled (K23): the runtime then provides `Timers` to handlers, and the handler's type says so. */
71
+ const isTimed = (model) => Object.values(model.environments ?? {}).some((e) => e.clock !== undefined && e.clock.kind !== "real");
72
+ const handlerType = (op, timed) => {
73
+ const path = `generated/api/src/${op.thing}/${op.verb}.handler.ts`;
74
+ return file(path, lines(GENERATED, "// What the handler is given: its payload and steps; what it may return: its answer or a declared error.", `import type { SqlClient } from "effect/sql";`, `import type { Auth, Handler as Of, Records${timed ? ", Timers" : ""} } from "${Names.pkg("language-effect")}";`, `import type declaration from "${declarationAt(path, op.file)}";`, "", `export type Handler<R = Records | SqlClient.SqlClient | Auth${timed ? " | Timers" : ""}> = Of<typeof declaration, R>;`,
75
+ // Where the move can end, as the machine's literal states: a handler's `Match` over it is exhaustive (K16).
76
+ (op.move?.to.length ?? 0) > 1 ? ["/** Where the move can end: one of its outcomes, as the machine declares them. */", `export type Outcome = NonNullable<(typeof declaration)["move"]>["to"][number];`] : []));
77
+ };
78
+ const index = (model, name) => {
79
+ const ops = Object.values(model.operations);
80
+ const things = [...new Set(ops.map((o) => o.thing))];
81
+ return file("generated/api/src/index.ts", lines(GENERATED, `import { HttpApi, HttpApiGroup } from "effect/http-api";`, ops.map((o) => `import * as ${opVar(o)} from "./${o.thing}/${o.verb}.ts";`), "", things.map((t) => {
82
+ const adds = ops.filter((o) => o.thing === t).map((o) => `.add(${opVar(o)}.endpoint)`).join("");
83
+ return `export class ${pascal(t)} extends HttpApiGroup.make("${t}")${adds} {}`;
84
+ }), `export class Api extends HttpApi.make("${name}")${things.map((t) => `.add(${pascal(t)})`).join("")} {}`, "", `export * as Errors from "./errors.ts";`, `export * as Events from "./events.ts";`, `export const operations = { ${ops.map((o) => `"${o.name}": ${opVar(o)}`).join(", ")} } as const;`));
85
+ };
86
+ /** Events take their names from their exports; the runtime journals them by that name. */
87
+ const events = (model) => {
88
+ const path = "generated/api/src/events.ts";
89
+ const emitting = Object.values(model.things).filter((t) => Object.keys(t.events).length > 0);
90
+ return file(path, lines(GENERATED, `import { EventNames } from "${Names.frontDoor}/server";`, emitting.map((t) => `import * as ${t.identifier} from "${thingFileAt(path, t, "events")}";`), "", emitting.flatMap((t) => Object.keys(t.events).map((e) => `EventNames.name(${t.identifier}.${e}, "${e}");`)), "", `export const names = [${emitting.flatMap((t) => Object.keys(t.events).map((e) => `"${e}"`)).join(", ")}] as const;`));
91
+ };
92
+ /** `served` is the model without its device operations; each of those still gets its declaration in the API folder. */
93
+ export const renderApi = (model, name, served = model) => [
94
+ errors(served),
95
+ events(served),
96
+ index(served, name),
97
+ ...Object.values(served.operations).flatMap((op) => (op.kind === "read" ? [endpoint(op, served)] : [endpoint(op, served), handlerType(op, isTimed(served))])),
98
+ ...Object.values(model.operations).filter(onDevice).map(declarationOnly),
99
+ ];
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The contract: an endpoint built from each operation's own declaration, the wire errors, the events and the handler type
3
+ * (`generated/api/`). An operation that runs on the device has its declaration there and no route.
4
+ */
5
+ export declare const api: import("orthograph").Projection<{}>;
@@ -0,0 +1,16 @@
1
+ import { Blueprint, Ships } from "orthograph";
2
+ import { modelOf, serverModel, within } from "#modules/names/service.js";
3
+ import { renderApi } from "./internal/api.js";
4
+ /**
5
+ * The contract: an endpoint built from each operation's own declaration, the wire errors, the events and the handler type
6
+ * (`generated/api/`). An operation that runs on the device has its declaration there and no route.
7
+ */
8
+ export const api = Blueprint.projection({
9
+ description: "The API contract: each operation's endpoint, built from its own declaration, with the wire errors, the events and the handler's type.",
10
+ host: [],
11
+ ships: [Ships.kept],
12
+ render: (input) => {
13
+ const model = modelOf(input);
14
+ return within(input, "api", renderApi(model, input.name, serverModel(model)));
15
+ },
16
+ });
@@ -0,0 +1 @@
1
+ export type { Projection } from "orthograph";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { MapView } from "../types.ts";
2
+ export declare const linksModule: (view: MapView) => string;
@@ -0,0 +1,22 @@
1
+ const GENERATED = "// Generated from the blueprint. Do not edit.";
2
+ const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
3
+ const PARAM = /:([A-Za-z_][A-Za-z0-9_]*)/g;
4
+ /** The address as a string expression: its fixed parts as strings, each parameter encoded. */
5
+ const expression = (path) => {
6
+ const parts = path.split(PARAM);
7
+ // `split` with a capture alternates the fixed text and the parameter's name.
8
+ return parts.map((part, i) => (i % 2 === 1 ? `encodeURIComponent(params.${part})` : JSON.stringify(part))).filter((p) => p !== '""').join(" + ") || '""';
9
+ };
10
+ export const linksModule = (view) => [
11
+ GENERATED,
12
+ "",
13
+ "/** The address of each page of the app, by the page's name. */",
14
+ "export const links = {",
15
+ ...view.pages.map((p) => {
16
+ const key = IDENTIFIER.test(p.name) ? p.name : JSON.stringify(p.name);
17
+ const params = p.params.length === 0 ? "" : `params: { ${p.params.map((n) => `readonly ${n}: string`).join("; ")} }`;
18
+ return ` ${key}: (${params}): string => ${expression(p.path)},`;
19
+ }),
20
+ "} as const;",
21
+ "",
22
+ ].join("\n");
@@ -0,0 +1,6 @@
1
+ import type { Model } from "@orthograph/compiler";
2
+ import type { MapView, PaletteEntry } from "../types.ts";
3
+ /** The pages by name, then each page's offered operations (its effective offers), by page and then operation. */
4
+ export declare const paletteOf: (view: MapView, model: Model) => ReadonlyArray<PaletteEntry>;
5
+ /** `palette.ts`: the entries as data, and `visibleTo`: what an anonymous caller or a signed-in person may open and call. */
6
+ export declare const paletteModule: (entries: ReadonlyArray<PaletteEntry>) => string;
@@ -0,0 +1,55 @@
1
+ const byName = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
2
+ /** The pages by name, then each page's offered operations (its effective offers), by page and then operation. */
3
+ export const paletteOf = (view, model) => [
4
+ ...view.pages.map((p) => ({ kind: "page", name: p.name, path: p.path, description: p.description, allowed: p.allowed })),
5
+ ...view.pages.flatMap((p) => [...p.offers].sort(byName).map((op) => ({
6
+ kind: "operation",
7
+ name: op,
8
+ page: p.name,
9
+ component: p.components.find((c) => c.offers.includes(op))?.name ?? null,
10
+ description: model.operations[op]?.description ?? "",
11
+ allowed: model.operations[op]?.allowed ?? [],
12
+ }))),
13
+ ];
14
+ const GENERATED = "// Generated from the blueprint. Do not edit.";
15
+ /** `palette.ts`: the entries as data, and `visibleTo`: what an anonymous caller or a signed-in person may open and call. */
16
+ export const paletteModule = (entries) => [
17
+ GENERATED,
18
+ "",
19
+ "export type Allowed =",
20
+ ' | { readonly kind: "anyone" }',
21
+ ' | { readonly kind: "signed-in"; readonly via?: ReadonlyArray<string> }',
22
+ ' | { readonly kind: "system" }',
23
+ ' | { readonly kind: "keeper" }',
24
+ ' | { readonly kind: "role"; readonly role: string; readonly via?: ReadonlyArray<string>; readonly service?: string }',
25
+ ' | { readonly kind: "role-of"; readonly role: string; readonly path: string; readonly via?: ReadonlyArray<string>; readonly service?: string };',
26
+ "",
27
+ "export type PaletteEntry =",
28
+ ' | { readonly kind: "page"; readonly name: string; readonly path: string; readonly description: string; readonly allowed: ReadonlyArray<Allowed> }',
29
+ ' | { readonly kind: "operation"; readonly name: string; readonly page: string; readonly component: string | null; readonly description: string; readonly allowed: ReadonlyArray<Allowed> };',
30
+ "",
31
+ "export type Caller = \"anonymous\" | \"person\";",
32
+ "",
33
+ `export const entries: ReadonlyArray<PaletteEntry> = ${JSON.stringify(entries, null, 2)};`,
34
+ "",
35
+ "/**",
36
+ " * The rule. An anonymous caller passes only `anyone`. A person passes `anyone` and `signed-in`. A role (`role`, or `role-of` by its",
37
+ " * role's name) is decided on an instance: it passes only when `roles` (the names the caller",
38
+ " * holds, such as `link.linkOwner`) has it, and no `roles` means none held. `system`, `keeper` and a service role are never a person; `via` (the ways in a mount kept) does not change who may open a page, so the entry's own rule decides. Nobody passes an empty `allowed`.",
39
+ " */",
40
+ "const passes = (allowed: ReadonlyArray<Allowed>, caller: Caller, roles?: ReadonlyArray<string>): boolean =>",
41
+ " allowed.some((a) => {",
42
+ ' if (a.kind === "anyone") return true;',
43
+ ' if (caller !== "person") return false;',
44
+ ' if (a.kind === "system" || a.kind === "keeper") return false;',
45
+ ' if (a.kind === "signed-in") return true;',
46
+ ' return a.service === undefined && (roles ?? []).includes(a.role);',
47
+ " });",
48
+ "",
49
+ "/** What the caller may open and call: a page whose `allowed` they pass, and an operation of such a page whose own `allowed` they pass. */",
50
+ "export const visibleTo = (caller: Caller, roles?: ReadonlyArray<string>): ReadonlyArray<PaletteEntry> => {",
51
+ ' const pages = new Set(entries.flatMap((e) => (e.kind === "page" && passes(e.allowed, caller, roles) ? [e.name] : [])));',
52
+ ' return entries.filter((e) => (e.kind === "page" ? pages.has(e.name) : pages.has(e.page) && passes(e.allowed, caller, roles)));',
53
+ "};",
54
+ "",
55
+ ].join("\n");
@@ -0,0 +1,4 @@
1
+ import type { Model } from "@orthograph/compiler";
2
+ import type { RenderedFile } from "#modules/names/types.js";
3
+ import type { MapView } from "../types.ts";
4
+ export declare const renderApp: (view: MapView, model: Model) => ReadonlyArray<RenderedFile>;
@@ -0,0 +1,30 @@
1
+ import { linksModule } from "./links.js";
2
+ import { paletteModule, paletteOf } from "./palette.js";
3
+ const json = (path, value) => ({ path: `generated/app/${path}`, content: `${JSON.stringify(value, null, 2)}\n`, scaffold: false });
4
+ const ts = (path, content) => ({ path: `generated/app/${path}`, content, scaffold: false });
5
+ export const renderApp = (view, model) => {
6
+ const entries = paletteOf(view, model);
7
+ return [
8
+ ts("links.ts", linksModule(view)),
9
+ json("map.json", {
10
+ layout: view.layout,
11
+ home: view.home,
12
+ pages: view.pages.map((p) => ({
13
+ name: p.name, path: p.path, params: p.params, description: p.description,
14
+ ...(p.parent === undefined ? {} : { parent: p.parent }),
15
+ allowed: p.allowed, shows: p.shows, offers: p.offers, components: p.components,
16
+ })),
17
+ groups: view.groups,
18
+ }),
19
+ json("navigation.json", { layout: view.layout, home: view.home, groups: view.groups }),
20
+ json("palette.json", { entries }),
21
+ ts("palette.ts", paletteModule(entries)),
22
+ json("routes.json", {
23
+ routes: view.pages.map((p) => ({
24
+ page: p.name, path: p.path, params: p.params,
25
+ ...(p.parent === undefined ? {} : { parent: p.parent }),
26
+ allowed: p.allowed, description: p.description,
27
+ })),
28
+ }),
29
+ ];
30
+ };
@@ -0,0 +1,3 @@
1
+ import type { Model } from "@orthograph/compiler";
2
+ import type { MapView } from "../types.ts";
3
+ export declare const viewOf: (model: Model, project: string) => MapView;