@orthograph/compiler 0.0.0-stage → 0.1.0-next.2
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 +202 -0
- package/README.md +4 -2
- package/dist/index.d.ts +12 -0
- package/dist/index.js +9 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +18 -0
- package/dist/modules/app/internal/checks.d.ts +30 -0
- package/dist/modules/app/internal/checks.js +99 -0
- package/dist/modules/app/internal/describe.d.ts +6 -0
- package/dist/modules/app/internal/describe.js +59 -0
- package/dist/modules/app/internal/hash.d.ts +1 -0
- package/dist/modules/app/internal/hash.js +7 -0
- package/dist/modules/app/internal/known.d.ts +19 -0
- package/dist/modules/app/internal/known.js +45 -0
- package/dist/modules/app/internal/read.d.ts +6 -0
- package/dist/modules/app/internal/read.js +45 -0
- package/dist/modules/app/service.d.ts +2 -0
- package/dist/modules/app/service.js +3 -0
- package/dist/modules/app/types.d.ts +87 -0
- package/dist/modules/app/types.js +1 -0
- package/dist/modules/compare/internal/assets.d.ts +4 -0
- package/dist/modules/compare/internal/assets.js +40 -0
- package/dist/modules/compare/internal/chain.d.ts +4 -0
- package/dist/modules/compare/internal/chain.js +37 -0
- package/dist/modules/compare/internal/diff.d.ts +3 -0
- package/dist/modules/compare/internal/diff.js +27 -0
- package/dist/modules/compare/internal/versions.d.ts +9 -0
- package/dist/modules/compare/internal/versions.js +75 -0
- package/dist/modules/compare/service.d.ts +2 -0
- package/dist/modules/compare/service.js +43 -0
- package/dist/modules/compare/types.d.ts +47 -0
- package/dist/modules/compare/types.js +1 -0
- package/dist/modules/lock/internal/evolve.d.ts +7 -0
- package/dist/modules/lock/internal/evolve.js +52 -0
- package/dist/modules/lock/internal/runtime.d.ts +3 -0
- package/dist/modules/lock/internal/runtime.js +12 -0
- package/dist/modules/lock/service.d.ts +4 -0
- package/dist/modules/lock/service.js +20 -0
- package/dist/modules/lock/types.d.ts +101 -0
- package/dist/modules/lock/types.js +6 -0
- package/dist/modules/model/internal/allowed.d.ts +26 -0
- package/dist/modules/model/internal/allowed.js +78 -0
- package/dist/modules/model/internal/approval.d.ts +4 -0
- package/dist/modules/model/internal/approval.js +10 -0
- package/dist/modules/model/internal/assets.d.ts +5 -0
- package/dist/modules/model/internal/assets.js +31 -0
- package/dist/modules/model/internal/bits.d.ts +6 -0
- package/dist/modules/model/internal/bits.js +9 -0
- package/dist/modules/model/internal/chain.d.ts +9 -0
- package/dist/modules/model/internal/chain.js +47 -0
- package/dist/modules/model/internal/codes.d.ts +59 -0
- package/dist/modules/model/internal/codes.js +80 -0
- package/dist/modules/model/internal/derive.d.ts +11 -0
- package/dist/modules/model/internal/derive.js +31 -0
- package/dist/modules/model/internal/describe.d.ts +8 -0
- package/dist/modules/model/internal/describe.js +248 -0
- package/dist/modules/model/internal/device.d.ts +5 -0
- package/dist/modules/model/internal/device.js +12 -0
- package/dist/modules/model/internal/environments.d.ts +7 -0
- package/dist/modules/model/internal/environments.js +90 -0
- package/dist/modules/model/internal/exits.d.ts +49 -0
- package/dist/modules/model/internal/exits.js +85 -0
- package/dist/modules/model/internal/fields.d.ts +23 -0
- package/dist/modules/model/internal/fields.js +50 -0
- package/dist/modules/model/internal/fillable.d.ts +3 -0
- package/dist/modules/model/internal/fillable.js +9 -0
- package/dist/modules/model/internal/forms.d.ts +47 -0
- package/dist/modules/model/internal/forms.js +75 -0
- package/dist/modules/model/internal/found.d.ts +40 -0
- package/dist/modules/model/internal/found.js +60 -0
- package/dist/modules/model/internal/handler-files.d.ts +18 -0
- package/dist/modules/model/internal/handler-files.js +23 -0
- package/dist/modules/model/internal/hash.d.ts +4 -0
- package/dist/modules/model/internal/hash.js +7 -0
- package/dist/modules/model/internal/holds.d.ts +19 -0
- package/dist/modules/model/internal/holds.js +65 -0
- package/dist/modules/model/internal/invariants.d.ts +38 -0
- package/dist/modules/model/internal/invariants.js +134 -0
- package/dist/modules/model/internal/journeys.d.ts +15 -0
- package/dist/modules/model/internal/journeys.js +135 -0
- package/dist/modules/model/internal/layout.d.ts +143 -0
- package/dist/modules/model/internal/layout.js +203 -0
- package/dist/modules/model/internal/lock-fields.d.ts +3 -0
- package/dist/modules/model/internal/lock-fields.js +17 -0
- package/dist/modules/model/internal/money.d.ts +17 -0
- package/dist/modules/model/internal/money.js +49 -0
- package/dist/modules/model/internal/nullable.d.ts +7 -0
- package/dist/modules/model/internal/nullable.js +21 -0
- package/dist/modules/model/internal/operations.d.ts +27 -0
- package/dist/modules/model/internal/operations.js +81 -0
- package/dist/modules/model/internal/reads.d.ts +16 -0
- package/dist/modules/model/internal/reads.js +58 -0
- package/dist/modules/model/internal/rules.d.ts +2 -0
- package/dist/modules/model/internal/rules.js +33 -0
- package/dist/modules/model/internal/same-value.d.ts +10 -0
- package/dist/modules/model/internal/same-value.js +50 -0
- package/dist/modules/model/internal/secrets.d.ts +4 -0
- package/dist/modules/model/internal/secrets.js +35 -0
- package/dist/modules/model/internal/source-refusals.d.ts +7 -0
- package/dist/modules/model/internal/source-refusals.js +52 -0
- package/dist/modules/model/internal/sources.d.ts +12 -0
- package/dist/modules/model/internal/sources.js +65 -0
- package/dist/modules/model/internal/stores.d.ts +20 -0
- package/dist/modules/model/internal/stores.js +44 -0
- package/dist/modules/model/internal/things.d.ts +33 -0
- package/dist/modules/model/internal/things.js +99 -0
- package/dist/modules/model/service.d.ts +4 -0
- package/dist/modules/model/service.js +105 -0
- package/dist/modules/model/types.d.ts +485 -0
- package/dist/modules/model/types.js +5 -0
- package/dist/modules/mounts/fixtures/both/things/echo/thing.d.ts +1 -0
- package/dist/modules/mounts/fixtures/both/things/echo/thing.js +1 -0
- package/dist/modules/mounts/fixtures/both/things/echo/verbs/only.d.ts +1 -0
- package/dist/modules/mounts/fixtures/both/things/echo/verbs/only.js +1 -0
- package/dist/modules/mounts/internal/attribute.d.ts +2 -0
- package/dist/modules/mounts/internal/attribute.js +4 -0
- package/dist/modules/mounts/internal/calls.d.ts +12 -0
- package/dist/modules/mounts/internal/calls.js +42 -0
- package/dist/modules/mounts/internal/choices.d.ts +11 -0
- package/dist/modules/mounts/internal/choices.js +34 -0
- package/dist/modules/mounts/internal/fold.d.ts +6 -0
- package/dist/modules/mounts/internal/fold.js +8 -0
- package/dist/modules/mounts/internal/needs.d.ts +14 -0
- package/dist/modules/mounts/internal/needs.js +26 -0
- package/dist/modules/mounts/internal/verbs.d.ts +11 -0
- package/dist/modules/mounts/internal/verbs.js +44 -0
- package/dist/modules/mounts/service.d.ts +2 -0
- package/dist/modules/mounts/service.js +165 -0
- package/dist/modules/mounts/types.d.ts +78 -0
- package/dist/modules/mounts/types.js +1 -0
- package/dist/modules/source/internal/plugins.d.ts +25 -0
- package/dist/modules/source/internal/plugins.js +49 -0
- package/dist/modules/source/service.d.ts +6 -0
- package/dist/modules/source/service.js +86 -0
- package/dist/modules/source/types.d.ts +55 -0
- package/dist/modules/source/types.js +6 -0
- package/dist/modules/time/internal/anchor.d.ts +2 -0
- package/dist/modules/time/internal/anchor.js +48 -0
- package/dist/modules/time/internal/keeper.d.ts +13 -0
- package/dist/modules/time/internal/keeper.js +19 -0
- package/dist/modules/time/internal/zones.d.ts +1 -0
- package/dist/modules/time/internal/zones.js +3 -0
- package/dist/modules/time/service.d.ts +2 -0
- package/dist/modules/time/service.js +56 -0
- package/dist/modules/time/types.d.ts +89 -0
- package/dist/modules/time/types.js +1 -0
- package/package.json +35 -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,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @orthograph/compiler
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Reads a project's `blueprint/` by path and builds the model: `Compiler.model`, an Effect that needs a `BlueprintSource`
|
|
4
|
+
and fails with `BlueprintInvalid` or `SourceError`. Never runs in production. Modules: `source` (where files come from)
|
|
5
|
+
and `model` (what they mean).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { IDEMPOTENCY_CONFLICT, READ_NOT_SERVED } from "#modules/model/internal/codes.js";
|
|
2
|
+
export { Compiler, canonical, handlerFiles, isVersioned, type HandlerFile } from "#modules/model/service.js";
|
|
3
|
+
export { BlueprintInvalid } from "#modules/model/types.js";
|
|
4
|
+
export type { Model, ThingModel, OperationModel, FieldModel, FieldsModel, VisibilityModel, AllowedModel, ValueMeta, MoneyAssetModel, AssetModel, EnvironmentModel, PublicationModel, SinkModel, MountModel, FromModel, StoreModel, StoreFromModel, StepModel } from "#modules/model/types.js";
|
|
5
|
+
export type { ByModel, ClockModel, MoveTimeModel } from "#modules/time/types.js";
|
|
6
|
+
export { nodeSource } from "#modules/source/service.js";
|
|
7
|
+
export { packageDir, pluginFolder, resolveFrom } from "#modules/source/service.js";
|
|
8
|
+
export { BlueprintSource, SourceError, type PluginPackage, type PluginFiles } from "#modules/source/types.js";
|
|
9
|
+
export { Compare } from "#modules/compare/service.js";
|
|
10
|
+
export type { Bump, Change, Depends, Release as ModelRelease, Versioned } from "#modules/compare/types.js";
|
|
11
|
+
export { RefusalLock } from "#modules/lock/service.js";
|
|
12
|
+
export type { Lock, LockEntry, LockValue, Wire } from "#modules/lock/types.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @orthograph/compiler: reads blueprint/ by path and builds the model. Never runs in production.
|
|
2
|
+
export { IDEMPOTENCY_CONFLICT, READ_NOT_SERVED } from "#modules/model/internal/codes.js";
|
|
3
|
+
export { Compiler, canonical, handlerFiles, isVersioned } from "#modules/model/service.js";
|
|
4
|
+
export { BlueprintInvalid } from "#modules/model/types.js";
|
|
5
|
+
export { nodeSource } from "#modules/source/service.js";
|
|
6
|
+
export { packageDir, pluginFolder, resolveFrom } from "#modules/source/service.js";
|
|
7
|
+
export { BlueprintSource, SourceError } from "#modules/source/types.js";
|
|
8
|
+
export { Compare } from "#modules/compare/service.js";
|
|
9
|
+
export { RefusalLock } from "#modules/lock/service.js";
|
package/dist/main.d.ts
ADDED
package/dist/main.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `ortho-model <project-root>`: the model as JSON on stdout. Generators run this in a fresh process, so a
|
|
3
|
+
// long-lived Nx daemon never reads a blueprint file it imported before an edit. With `--locked`, the output is
|
|
4
|
+
// `{ "model": …, "lock": "…" }`: the model and the text `blueprint/refusals.lock` must have for it (M6-chain item 4).
|
|
5
|
+
import { Effect } from "effect";
|
|
6
|
+
import { Compiler } from "#modules/model/service.js";
|
|
7
|
+
import { nodeSource } from "#modules/source/service.js";
|
|
8
|
+
const args = process.argv.slice(2);
|
|
9
|
+
const root = args.find((a) => !a.startsWith("--")) ?? process.cwd();
|
|
10
|
+
const asked = args.includes("--locked") ? Effect.map(Compiler.locked, (c) => JSON.stringify(c)) : Effect.map(Compiler.model, (m) => JSON.stringify(m, null, 2) + "\n");
|
|
11
|
+
const result = await Effect.runPromise(Effect.result(Effect.provide(asked, nodeSource(root))));
|
|
12
|
+
if (result._tag === "Success")
|
|
13
|
+
process.stdout.write(result.success);
|
|
14
|
+
else {
|
|
15
|
+
const e = result.failure;
|
|
16
|
+
process.stderr.write(e._tag === "BlueprintInvalid" ? e.problems.map((p) => `${p}\n`).join("") : `${e.message}\n`);
|
|
17
|
+
process.exitCode = 2;
|
|
18
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AllowedModel, FieldModel, Model } from "#modules/model/types.js";
|
|
2
|
+
export declare const paramsOf: (path: string) => ReadonlyArray<string>;
|
|
3
|
+
/** A read or operation named on a page or in one of its components, and the file that names it. */
|
|
4
|
+
export interface Item {
|
|
5
|
+
readonly op: string;
|
|
6
|
+
readonly file: string;
|
|
7
|
+
}
|
|
8
|
+
export interface PageFacts {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly file: string;
|
|
11
|
+
readonly path: string;
|
|
12
|
+
readonly params: Readonly<Record<string, FieldModel>>;
|
|
13
|
+
readonly allowed: ReadonlyArray<AllowedModel>;
|
|
14
|
+
readonly shows: ReadonlyArray<Item>;
|
|
15
|
+
readonly offers: ReadonlyArray<Item>;
|
|
16
|
+
}
|
|
17
|
+
/** The path and its parameters agree; each shown read gets what its payload needs; each parameter is used by one. */
|
|
18
|
+
export declare const routeProblems: (page: PageFacts, model: Model) => ReadonlyArray<string>;
|
|
19
|
+
/** Each offered operation can be called by someone who may open the page. */
|
|
20
|
+
export declare const offerProblems: (page: PageFacts, model: Model) => ReadonlyArray<string>;
|
|
21
|
+
/** A read or operation named more than once among a page and its components (K36: one owner for each fact). */
|
|
22
|
+
export declare const twiceProblems: (page: PageFacts) => ReadonlyArray<string>;
|
|
23
|
+
/** Two pages at one address. */
|
|
24
|
+
export declare const duplicateRoutes: (pages: ReadonlyArray<{
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly file: string;
|
|
27
|
+
readonly path: string;
|
|
28
|
+
}>) => ReadonlyArray<string>;
|
|
29
|
+
/** Pages whose parents lead back to themselves: each cycle once. */
|
|
30
|
+
export declare const cycles: (parents: ReadonlyMap<string, string>, files: ReadonlyMap<string, string>) => ReadonlyArray<string>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const PARAM = /:([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
2
|
+
export const paramsOf = (path) => [...path.matchAll(PARAM)].map((m) => m[1]);
|
|
3
|
+
/** An address with its parameters' names taken out: `/@:handle` and `/@:name` are one. */
|
|
4
|
+
const shape = (path) => path.replace(PARAM, ":");
|
|
5
|
+
const also = (page, item) => (item.file === page.file ? "" : ` (named in ${item.file})`);
|
|
6
|
+
const tagged = (file, tag, words) => `${file}: [${tag}] ${words}`;
|
|
7
|
+
/** A segment is literal text with at most one parameter that ends it (`@:handle`, `:name`): what the shell's router reads. */
|
|
8
|
+
const SEGMENT = /^[^:]*(:[A-Za-z_][A-Za-z0-9_]*)?$/;
|
|
9
|
+
const badSegments = (path) => path.split("/").filter((s) => !SEGMENT.test(s));
|
|
10
|
+
/** The root is `/`; any other route has no empty segment, since the router drops them (`/account/` would be `/account`). */
|
|
11
|
+
const emptySegments = (path) => path !== "/" && path.startsWith("/") && path.split("/").slice(1).some((s) => s === "");
|
|
12
|
+
/** The path and its parameters agree; each shown read gets what its payload needs; each parameter is used by one. */
|
|
13
|
+
export const routeProblems = (page, model) => {
|
|
14
|
+
const named = paramsOf(page.path);
|
|
15
|
+
const typed = Object.keys(page.params);
|
|
16
|
+
const out = [];
|
|
17
|
+
if (!page.path.startsWith("/"))
|
|
18
|
+
out.push(tagged(page.file, "app-route-param", `the route "${page.path}" must start with /`));
|
|
19
|
+
if (emptySegments(page.path))
|
|
20
|
+
out.push(tagged(page.file, "app-route-param", `the route "${page.path}" has an empty segment (a trailing or doubled slash): the router drops it, so it would be the address of another page`));
|
|
21
|
+
for (const s of badSegments(page.path))
|
|
22
|
+
out.push(tagged(page.file, "app-route-param", `the segment "${s}" of the route "${page.path}" is not literal text with at most one :name at its end`));
|
|
23
|
+
for (const p of named.filter((n) => !typed.includes(n)))
|
|
24
|
+
out.push(tagged(page.file, "app-route-param", `the route "${page.path}" has :${p}, which route.params doesn't type`));
|
|
25
|
+
for (const p of typed.filter((n) => !named.includes(n)))
|
|
26
|
+
out.push(tagged(page.file, "app-route-param", `route.params types ${p}, which the route "${page.path}" doesn't have`));
|
|
27
|
+
const shown = page.shows.map((item) => ({ item, op: model.operations[item.op] }));
|
|
28
|
+
if (shown.length === 0 || shown.some((s) => s.op === undefined))
|
|
29
|
+
return out;
|
|
30
|
+
const supplies = (key, field) => Object.entries(page.params).some(([p, f]) => p === key || (field.ref !== undefined && f.ref === field.ref));
|
|
31
|
+
for (const { item, op } of shown) {
|
|
32
|
+
for (const [key, field] of Object.entries(op.payload)) {
|
|
33
|
+
const byRole = page.allowed.some((a) => a.kind === "role-of" && a.path.split(".")[0] === key);
|
|
34
|
+
if (!field.optional && !supplies(key, field) && !byRole) {
|
|
35
|
+
out.push(tagged(page.file, "app-route-param", `${page.name} shows ${item.op}${also(page, item)}, whose payload field "${key}" no route parameter, session or allowed role supplies (route "${page.path}")`));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const [p, f] of Object.entries(page.params)) {
|
|
40
|
+
const taken = shown.some(({ op }) => Object.entries(op.payload).some(([key, field]) => key === p || (f.ref !== undefined && field.ref === f.ref)));
|
|
41
|
+
if (!taken)
|
|
42
|
+
out.push(tagged(page.file, "app-route-param", `route parameter ${p} is taken by no read ${page.name} shows (${shown.map((s) => s.item.op).join(", ")})`));
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
};
|
|
46
|
+
/** Callable: the page allows anyone or a signed-in caller, or the operation allows anyone or a signed-in one, or they share a role. */
|
|
47
|
+
const callable = (page, op) => {
|
|
48
|
+
const roleOf = (a) => (a.kind === "role" || a.kind === "role-of" ? a.role : undefined);
|
|
49
|
+
return page.some((a) => a.kind === "anyone" || a.kind === "signed-in")
|
|
50
|
+
|| op.some((a) => a.kind === "anyone" || a.kind === "signed-in")
|
|
51
|
+
|| page.some((a) => roleOf(a) !== undefined && op.some((o) => roleOf(o) === roleOf(a)));
|
|
52
|
+
};
|
|
53
|
+
/** Each offered operation can be called by someone who may open the page. */
|
|
54
|
+
export const offerProblems = (page, model) => page.offers.flatMap((item) => {
|
|
55
|
+
const op = model.operations[item.op];
|
|
56
|
+
return op === undefined || callable(page.allowed, op.allowed)
|
|
57
|
+
? []
|
|
58
|
+
: [tagged(page.file, "app-offer-uncallable", `${page.name} offers ${item.op}${also(page, item)}, which none of the page's allowed roles may call`)];
|
|
59
|
+
});
|
|
60
|
+
/** A read or operation named more than once among a page and its components (K36: one owner for each fact). */
|
|
61
|
+
export const twiceProblems = (page) => {
|
|
62
|
+
const all = [...page.shows, ...page.offers];
|
|
63
|
+
return [...new Set(all.map((i) => i.op))].flatMap((op) => {
|
|
64
|
+
const where = all.filter((i) => i.op === op);
|
|
65
|
+
if (where.length < 2)
|
|
66
|
+
return [];
|
|
67
|
+
const files = [...new Set([page.file, ...where.map((i) => i.file)])];
|
|
68
|
+
return [tagged(page.file, "app-named-twice", `${op} is named ${where.length} times among ${page.name} and its components (${files.join(", ")}): name it in exactly one`)];
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
/** Two pages at one address. */
|
|
72
|
+
export const duplicateRoutes = (pages) => {
|
|
73
|
+
const by = new Map();
|
|
74
|
+
for (const p of pages)
|
|
75
|
+
by.set(shape(p.path), [...(by.get(shape(p.path)) ?? []), p]);
|
|
76
|
+
return [...by.values()].filter((group) => group.length > 1).map((group) => tagged(group[0].file, "app-duplicate-route", `${group.map((p) => `${p.name} (${p.file}, "${p.path}")`).join(" and ")} are at one address`));
|
|
77
|
+
};
|
|
78
|
+
/** Pages whose parents lead back to themselves: each cycle once. */
|
|
79
|
+
export const cycles = (parents, files) => {
|
|
80
|
+
const seen = new Set();
|
|
81
|
+
const out = [];
|
|
82
|
+
for (const start of [...parents.keys()].sort()) {
|
|
83
|
+
const path = [];
|
|
84
|
+
let at = start;
|
|
85
|
+
while (at !== undefined && !path.includes(at)) {
|
|
86
|
+
path.push(at);
|
|
87
|
+
at = parents.get(at);
|
|
88
|
+
}
|
|
89
|
+
if (at === undefined)
|
|
90
|
+
continue;
|
|
91
|
+
const loop = path.slice(path.indexOf(at)).sort();
|
|
92
|
+
const key = loop.join(",");
|
|
93
|
+
if (seen.has(key))
|
|
94
|
+
continue;
|
|
95
|
+
seen.add(key);
|
|
96
|
+
out.push(tagged(files.get(loop[0]) ?? "?", "app-parent-cycle", `the parents of ${loop.join(", ")} lead back to themselves (${loop.map((n) => files.get(n)).join(", ")})`));
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Model } from "#modules/model/types.js";
|
|
2
|
+
import type { AppFiles, AppModel, AppWorld } from "../types.ts";
|
|
3
|
+
export declare const describeApp: (files: AppFiles, world: AppWorld, model: Model) => {
|
|
4
|
+
readonly app?: AppModel;
|
|
5
|
+
readonly problems: ReadonlyArray<string>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { cycles, duplicateRoutes, offerProblems, routeProblems, twiceProblems } from "./checks.js";
|
|
2
|
+
import { hashOf } from "./hash.js";
|
|
3
|
+
import { allowedOf, knownOf, paramOf } from "./known.js";
|
|
4
|
+
const byName = (m) => [...m].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
5
|
+
const once = (items) => [...new Set(items.map((i) => i.op))];
|
|
6
|
+
export const describeApp = (files, world, model) => {
|
|
7
|
+
const problems = [...files.problems];
|
|
8
|
+
if (!files.present || files.app === undefined)
|
|
9
|
+
return { problems };
|
|
10
|
+
const known = knownOf(world);
|
|
11
|
+
const pageNames = new Map([...files.pages].map(([n, p]) => [p.declaration, n]));
|
|
12
|
+
const componentNames = new Map([...files.components].map(([n, c]) => [c.declaration, n]));
|
|
13
|
+
const undeclared = (file, what) => (problems.push(`${file}: [app-undeclared-page] ${what} isn't a file of blueprint/app/pages/`), "?");
|
|
14
|
+
const opName = (file, x) => known.operations.get(x) ?? (problems.push(`${file}: names an operation or read that isn't in the blueprint`), "?");
|
|
15
|
+
const named = (file, list) => (list ?? []).map((x) => ({ op: opName(file, x), file }));
|
|
16
|
+
const components = {};
|
|
17
|
+
const ownItems = new Map();
|
|
18
|
+
for (const [name, { file, declaration: c }] of byName(files.components)) {
|
|
19
|
+
const shows = named(file, c.shows);
|
|
20
|
+
const offers = named(file, c.offers);
|
|
21
|
+
ownItems.set(name, { shows, offers });
|
|
22
|
+
const entry = { name, file, description: c.description, shows: once(shows), offers: once(offers) };
|
|
23
|
+
components[name] = { ...entry, hash: hashOf(entry) };
|
|
24
|
+
}
|
|
25
|
+
const pages = {};
|
|
26
|
+
const facts = [];
|
|
27
|
+
const parents = new Map();
|
|
28
|
+
const fileOf = new Map([...files.pages].map(([n, p]) => [n, p.file]));
|
|
29
|
+
for (const [name, { file, declaration: p }] of byName(files.pages)) {
|
|
30
|
+
const parent = typeof p.parent === "function" ? p.parent() : p.parent;
|
|
31
|
+
const parentName = parent === undefined ? undefined : pageNames.get(parent) ?? undeclared(file, "its parent");
|
|
32
|
+
if (parentName !== undefined && parentName !== "?")
|
|
33
|
+
parents.set(name, parentName);
|
|
34
|
+
const held = (p.components ?? []).map((c) => componentNames.get(c) ?? (problems.push(`${file}: holds a component that isn't a file of blueprint/app/components/`), "?"));
|
|
35
|
+
const heldItems = held.map((c) => ownItems.get(c));
|
|
36
|
+
const shows = [...named(file, p.shows), ...heldItems.flatMap((i) => i?.shows ?? [])];
|
|
37
|
+
const offers = [...named(file, p.offers), ...heldItems.flatMap((i) => i?.offers ?? [])];
|
|
38
|
+
const params = Object.fromEntries(Object.entries(p.route.params).map(([k, v]) => [k, paramOf(v, known, `${file} parameter ${k}`, problems)]));
|
|
39
|
+
const allowed = p.allowed.map((a) => allowedOf(a, known, file, problems));
|
|
40
|
+
const page = { name, file, path: p.route.path, params, allowed, shows, offers };
|
|
41
|
+
problems.push(...routeProblems(page, model), ...offerProblems(page, model), ...twiceProblems(page));
|
|
42
|
+
facts.push({ name, file, path: p.route.path });
|
|
43
|
+
const entry = {
|
|
44
|
+
name, file, description: p.description, route: { path: p.route.path, params },
|
|
45
|
+
...(parentName === undefined ? {} : { parent: parentName }),
|
|
46
|
+
allowed, shows: once(shows), offers: once(offers), components: held,
|
|
47
|
+
};
|
|
48
|
+
pages[name] = { ...entry, hash: hashOf(entry) };
|
|
49
|
+
}
|
|
50
|
+
problems.push(...duplicateRoutes(facts), ...cycles(parents, fileOf));
|
|
51
|
+
const { file, declaration: app } = files.app;
|
|
52
|
+
const pageIn = (page, what) => pageNames.get(page) ?? undeclared(file, what);
|
|
53
|
+
const home = pageIn(app.home, "home");
|
|
54
|
+
const nav = app.nav.map((g) => ({ title: g.title, pages: g.pages.map((p) => pageIn(p, `a page of the navigation group "${g.title}"`)), folded: g.folded }));
|
|
55
|
+
const entry = { description: app.description, layout: app.layout.which, home, nav };
|
|
56
|
+
const pageHashes = Object.fromEntries(Object.entries(pages).map(([n, p]) => [n, p.hash]));
|
|
57
|
+
const componentHashes = Object.fromEntries(Object.entries(components).map(([n, c]) => [n, c.hash]));
|
|
58
|
+
return { app: { ...entry, pages, components, hash: hashOf({ ...entry, pages: pageHashes, components: componentHashes }) }, problems };
|
|
59
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const hashOf: (entry: unknown) => string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// The same hash the model gives things and operations (`model/internal/hash.ts`, which a module's neighbours may not import):
|
|
2
|
+
// sha256 over the entry as JSON with keys sorted at every level, so equal inputs give equal hashes whatever the file's formatting.
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
const canonical = (x) => JSON.stringify(x, (_, v) => v && typeof v === "object" && !Array.isArray(v)
|
|
5
|
+
? Object.fromEntries(Object.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)))
|
|
6
|
+
: v);
|
|
7
|
+
export const hashOf = (entry) => createHash("sha256").update(canonical(entry)).digest("hex").slice(0, 16);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Allowed, RouteParam } from "orthograph";
|
|
2
|
+
import type { AllowedModel, FieldModel } from "#modules/model/types.js";
|
|
3
|
+
import type { AppWorld } from "../types.ts";
|
|
4
|
+
export interface Known {
|
|
5
|
+
/** An operation or read, to its name (`profile.get`). */
|
|
6
|
+
readonly operations: ReadonlyMap<unknown, string>;
|
|
7
|
+
readonly roles: ReadonlyMap<unknown, string>;
|
|
8
|
+
readonly things: ReadonlyMap<unknown, string>;
|
|
9
|
+
readonly values: ReadonlyMap<unknown, string>;
|
|
10
|
+
}
|
|
11
|
+
export declare const knownOf: (world: AppWorld) => Known;
|
|
12
|
+
/**
|
|
13
|
+
* Who may open a page, as an operation's `allowed` is written into the model. A page is opened by a caller of a request, so the
|
|
14
|
+
* runtime's own principals (`system`, `keeper`) and a role made for an outside service are refused as a problem naming the file;
|
|
15
|
+
* a narrowed entry (its ways in) is the entry it narrows, since a page has no ways in of its own.
|
|
16
|
+
*/
|
|
17
|
+
export declare const allowedOf: (a: Allowed, known: Known, file: string, problems: Array<string>) => AllowedModel;
|
|
18
|
+
/** A route parameter's type, as a payload field's is in the model: the value, the field it came from, the named value it is. */
|
|
19
|
+
export declare const paramOf: (p: RouteParam, known: Known, where: string, problems: Array<string>) => FieldModel;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const knownOf = (world) => ({
|
|
2
|
+
operations: new Map([...world.things].flatMap(([thing, t]) => [...t.verbs].map(([verb, v]) => [v.declaration, `${thing}.${verb}`]))),
|
|
3
|
+
roles: new Map([...world.things].flatMap(([thing, t]) => [...t.roles].map(([role, r]) => [r, `${thing}.${role}`]))),
|
|
4
|
+
things: new Map([...world.things].flatMap(([name, t]) => (t.thing ? [[t.thing, name]] : []))),
|
|
5
|
+
values: new Map([...world.values].map(([name, v]) => [v, name])),
|
|
6
|
+
});
|
|
7
|
+
/**
|
|
8
|
+
* Who may open a page, as an operation's `allowed` is written into the model. A page is opened by a caller of a request, so the
|
|
9
|
+
* runtime's own principals (`system`, `keeper`) and a role made for an outside service are refused as a problem naming the file;
|
|
10
|
+
* a narrowed entry (its ways in) is the entry it narrows, since a page has no ways in of its own.
|
|
11
|
+
*/
|
|
12
|
+
export const allowedOf = (a, known, file, problems) => {
|
|
13
|
+
if (a.kind === "narrowed")
|
|
14
|
+
return allowedOf(a.entry, known, file, problems);
|
|
15
|
+
if (a.kind === "anyone" || a.kind === "signed-in")
|
|
16
|
+
return { kind: a.kind };
|
|
17
|
+
if (a.kind === "system" || a.kind === "keeper") {
|
|
18
|
+
problems.push(`${file}: allows ${a.kind}, which has no credential and never opens a page: a page is allowed to anyone, signed-in callers or a role`);
|
|
19
|
+
return { kind: a.kind };
|
|
20
|
+
}
|
|
21
|
+
const nameOf = (r) => known.roles.get(r) ?? (problems.push(`${file}: uses a role not exported from a roles.ts`), "?");
|
|
22
|
+
const service = a.kind === "role" ? a.service : a.role.service;
|
|
23
|
+
if (service !== undefined)
|
|
24
|
+
problems.push(`${file}: allows ${nameOf(a.kind === "role" ? a : a.role)}, a role for an outside service${a.kind === "role-of" ? ` (scoped by ${a.path})` : ""}, which never opens a page`);
|
|
25
|
+
return a.kind === "role" ? { kind: "role", role: nameOf(a) } : { kind: "role-of", role: nameOf(a.role), path: a.path };
|
|
26
|
+
};
|
|
27
|
+
/** A route parameter's type, as a payload field's is in the model: the value, the field it came from, the named value it is. */
|
|
28
|
+
export const paramOf = (p, known, where, problems) => {
|
|
29
|
+
const value = p.kind === "field" ? p.value : p;
|
|
30
|
+
const named = known.values.get(value);
|
|
31
|
+
const thing = p.kind === "field" ? known.things.get(p.of) : undefined;
|
|
32
|
+
if (p.kind === "field" && thing === undefined)
|
|
33
|
+
problems.push(`${where}: uses a field of a thing that isn't in the blueprint`);
|
|
34
|
+
const description = p.description;
|
|
35
|
+
const meta = value.meta;
|
|
36
|
+
// An address carries text, never an amount and its asset (M6-money): a money parameter is refused, and the placeholder never reaches a model.
|
|
37
|
+
if (meta.type === "money")
|
|
38
|
+
problems.push(`${where}: a route parameter can't be money: an address carries an id or text, not an amount and its asset`);
|
|
39
|
+
return {
|
|
40
|
+
value: meta.type === "money" ? { type: "text", max: 0 } : meta,
|
|
41
|
+
...(named ? { named } : {}),
|
|
42
|
+
...(p.kind === "field" && thing ? { ref: `${thing}.${p.key}` } : {}),
|
|
43
|
+
...(description === undefined ? {} : { description }),
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const NAME = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
|
|
2
|
+
const kindOf = (x) => typeof x === "object" && x !== null ? x.kind : undefined;
|
|
3
|
+
export const setAside = (files) => {
|
|
4
|
+
const rest = [];
|
|
5
|
+
const pages = new Map();
|
|
6
|
+
const components = new Map();
|
|
7
|
+
const problems = [];
|
|
8
|
+
let app;
|
|
9
|
+
let present = false;
|
|
10
|
+
for (const f of files) {
|
|
11
|
+
const parts = f.path.replace(/\.(ts|js)$/, "").split("/");
|
|
12
|
+
if (parts[0] !== "app") {
|
|
13
|
+
rest.push(f);
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
present = true;
|
|
17
|
+
const file = `blueprint/${f.path}`;
|
|
18
|
+
const d = f.exports["default"];
|
|
19
|
+
if (parts.length === 2 && parts[1] === "app") {
|
|
20
|
+
if (kindOf(d) !== "app")
|
|
21
|
+
problems.push(`${file}: the default export must be a Blueprint.app`);
|
|
22
|
+
else
|
|
23
|
+
app = { file, declaration: d };
|
|
24
|
+
}
|
|
25
|
+
else if (parts.length === 3 && (parts[1] === "pages" || parts[1] === "components")) {
|
|
26
|
+
const name = parts[2];
|
|
27
|
+
const what = parts[1] === "pages" ? "page" : "component";
|
|
28
|
+
if (!NAME.test(name))
|
|
29
|
+
problems.push(`${file}: ${what} "${name}" must be lowercase words joined by dashes`);
|
|
30
|
+
if (what === "page") {
|
|
31
|
+
if (kindOf(d) !== "app-page")
|
|
32
|
+
problems.push(`${file}: the default export must be a Blueprint.page`);
|
|
33
|
+
else
|
|
34
|
+
pages.set(name, { file, declaration: d });
|
|
35
|
+
}
|
|
36
|
+
else if (kindOf(d) !== "app-component")
|
|
37
|
+
problems.push(`${file}: the default export must be a Blueprint.component`);
|
|
38
|
+
else
|
|
39
|
+
components.set(name, { file, declaration: d });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (present && app === undefined && !problems.some((p) => p.endsWith("must be a Blueprint.app")))
|
|
43
|
+
problems.push("blueprint/app/: has no app.ts");
|
|
44
|
+
return { app: { present, app, pages, components, problems }, rest };
|
|
45
|
+
};
|