@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.
Files changed (147) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +4 -2
  3. package/dist/index.d.ts +12 -0
  4. package/dist/index.js +9 -0
  5. package/dist/main.d.ts +2 -0
  6. package/dist/main.js +18 -0
  7. package/dist/modules/app/internal/checks.d.ts +30 -0
  8. package/dist/modules/app/internal/checks.js +99 -0
  9. package/dist/modules/app/internal/describe.d.ts +6 -0
  10. package/dist/modules/app/internal/describe.js +59 -0
  11. package/dist/modules/app/internal/hash.d.ts +1 -0
  12. package/dist/modules/app/internal/hash.js +7 -0
  13. package/dist/modules/app/internal/known.d.ts +19 -0
  14. package/dist/modules/app/internal/known.js +45 -0
  15. package/dist/modules/app/internal/read.d.ts +6 -0
  16. package/dist/modules/app/internal/read.js +45 -0
  17. package/dist/modules/app/service.d.ts +2 -0
  18. package/dist/modules/app/service.js +3 -0
  19. package/dist/modules/app/types.d.ts +87 -0
  20. package/dist/modules/app/types.js +1 -0
  21. package/dist/modules/compare/internal/assets.d.ts +4 -0
  22. package/dist/modules/compare/internal/assets.js +40 -0
  23. package/dist/modules/compare/internal/chain.d.ts +4 -0
  24. package/dist/modules/compare/internal/chain.js +37 -0
  25. package/dist/modules/compare/internal/diff.d.ts +3 -0
  26. package/dist/modules/compare/internal/diff.js +27 -0
  27. package/dist/modules/compare/internal/versions.d.ts +9 -0
  28. package/dist/modules/compare/internal/versions.js +75 -0
  29. package/dist/modules/compare/service.d.ts +2 -0
  30. package/dist/modules/compare/service.js +43 -0
  31. package/dist/modules/compare/types.d.ts +47 -0
  32. package/dist/modules/compare/types.js +1 -0
  33. package/dist/modules/lock/internal/evolve.d.ts +7 -0
  34. package/dist/modules/lock/internal/evolve.js +52 -0
  35. package/dist/modules/lock/internal/runtime.d.ts +3 -0
  36. package/dist/modules/lock/internal/runtime.js +12 -0
  37. package/dist/modules/lock/service.d.ts +4 -0
  38. package/dist/modules/lock/service.js +20 -0
  39. package/dist/modules/lock/types.d.ts +101 -0
  40. package/dist/modules/lock/types.js +6 -0
  41. package/dist/modules/model/internal/allowed.d.ts +26 -0
  42. package/dist/modules/model/internal/allowed.js +78 -0
  43. package/dist/modules/model/internal/approval.d.ts +4 -0
  44. package/dist/modules/model/internal/approval.js +10 -0
  45. package/dist/modules/model/internal/assets.d.ts +5 -0
  46. package/dist/modules/model/internal/assets.js +31 -0
  47. package/dist/modules/model/internal/bits.d.ts +6 -0
  48. package/dist/modules/model/internal/bits.js +9 -0
  49. package/dist/modules/model/internal/chain.d.ts +9 -0
  50. package/dist/modules/model/internal/chain.js +47 -0
  51. package/dist/modules/model/internal/codes.d.ts +59 -0
  52. package/dist/modules/model/internal/codes.js +80 -0
  53. package/dist/modules/model/internal/derive.d.ts +11 -0
  54. package/dist/modules/model/internal/derive.js +31 -0
  55. package/dist/modules/model/internal/describe.d.ts +8 -0
  56. package/dist/modules/model/internal/describe.js +248 -0
  57. package/dist/modules/model/internal/device.d.ts +5 -0
  58. package/dist/modules/model/internal/device.js +12 -0
  59. package/dist/modules/model/internal/environments.d.ts +7 -0
  60. package/dist/modules/model/internal/environments.js +90 -0
  61. package/dist/modules/model/internal/exits.d.ts +49 -0
  62. package/dist/modules/model/internal/exits.js +85 -0
  63. package/dist/modules/model/internal/fields.d.ts +23 -0
  64. package/dist/modules/model/internal/fields.js +50 -0
  65. package/dist/modules/model/internal/fillable.d.ts +3 -0
  66. package/dist/modules/model/internal/fillable.js +9 -0
  67. package/dist/modules/model/internal/forms.d.ts +47 -0
  68. package/dist/modules/model/internal/forms.js +75 -0
  69. package/dist/modules/model/internal/found.d.ts +40 -0
  70. package/dist/modules/model/internal/found.js +60 -0
  71. package/dist/modules/model/internal/handler-files.d.ts +18 -0
  72. package/dist/modules/model/internal/handler-files.js +23 -0
  73. package/dist/modules/model/internal/hash.d.ts +4 -0
  74. package/dist/modules/model/internal/hash.js +7 -0
  75. package/dist/modules/model/internal/holds.d.ts +19 -0
  76. package/dist/modules/model/internal/holds.js +65 -0
  77. package/dist/modules/model/internal/invariants.d.ts +38 -0
  78. package/dist/modules/model/internal/invariants.js +134 -0
  79. package/dist/modules/model/internal/journeys.d.ts +15 -0
  80. package/dist/modules/model/internal/journeys.js +135 -0
  81. package/dist/modules/model/internal/layout.d.ts +143 -0
  82. package/dist/modules/model/internal/layout.js +203 -0
  83. package/dist/modules/model/internal/lock-fields.d.ts +3 -0
  84. package/dist/modules/model/internal/lock-fields.js +17 -0
  85. package/dist/modules/model/internal/money.d.ts +17 -0
  86. package/dist/modules/model/internal/money.js +49 -0
  87. package/dist/modules/model/internal/nullable.d.ts +7 -0
  88. package/dist/modules/model/internal/nullable.js +21 -0
  89. package/dist/modules/model/internal/operations.d.ts +27 -0
  90. package/dist/modules/model/internal/operations.js +81 -0
  91. package/dist/modules/model/internal/reads.d.ts +16 -0
  92. package/dist/modules/model/internal/reads.js +58 -0
  93. package/dist/modules/model/internal/rules.d.ts +2 -0
  94. package/dist/modules/model/internal/rules.js +33 -0
  95. package/dist/modules/model/internal/same-value.d.ts +10 -0
  96. package/dist/modules/model/internal/same-value.js +50 -0
  97. package/dist/modules/model/internal/secrets.d.ts +4 -0
  98. package/dist/modules/model/internal/secrets.js +35 -0
  99. package/dist/modules/model/internal/source-refusals.d.ts +7 -0
  100. package/dist/modules/model/internal/source-refusals.js +52 -0
  101. package/dist/modules/model/internal/sources.d.ts +12 -0
  102. package/dist/modules/model/internal/sources.js +65 -0
  103. package/dist/modules/model/internal/stores.d.ts +20 -0
  104. package/dist/modules/model/internal/stores.js +44 -0
  105. package/dist/modules/model/internal/things.d.ts +33 -0
  106. package/dist/modules/model/internal/things.js +99 -0
  107. package/dist/modules/model/service.d.ts +4 -0
  108. package/dist/modules/model/service.js +105 -0
  109. package/dist/modules/model/types.d.ts +485 -0
  110. package/dist/modules/model/types.js +5 -0
  111. package/dist/modules/mounts/fixtures/both/things/echo/thing.d.ts +1 -0
  112. package/dist/modules/mounts/fixtures/both/things/echo/thing.js +1 -0
  113. package/dist/modules/mounts/fixtures/both/things/echo/verbs/only.d.ts +1 -0
  114. package/dist/modules/mounts/fixtures/both/things/echo/verbs/only.js +1 -0
  115. package/dist/modules/mounts/internal/attribute.d.ts +2 -0
  116. package/dist/modules/mounts/internal/attribute.js +4 -0
  117. package/dist/modules/mounts/internal/calls.d.ts +12 -0
  118. package/dist/modules/mounts/internal/calls.js +42 -0
  119. package/dist/modules/mounts/internal/choices.d.ts +11 -0
  120. package/dist/modules/mounts/internal/choices.js +34 -0
  121. package/dist/modules/mounts/internal/fold.d.ts +6 -0
  122. package/dist/modules/mounts/internal/fold.js +8 -0
  123. package/dist/modules/mounts/internal/needs.d.ts +14 -0
  124. package/dist/modules/mounts/internal/needs.js +26 -0
  125. package/dist/modules/mounts/internal/verbs.d.ts +11 -0
  126. package/dist/modules/mounts/internal/verbs.js +44 -0
  127. package/dist/modules/mounts/service.d.ts +2 -0
  128. package/dist/modules/mounts/service.js +165 -0
  129. package/dist/modules/mounts/types.d.ts +78 -0
  130. package/dist/modules/mounts/types.js +1 -0
  131. package/dist/modules/source/internal/plugins.d.ts +25 -0
  132. package/dist/modules/source/internal/plugins.js +49 -0
  133. package/dist/modules/source/service.d.ts +6 -0
  134. package/dist/modules/source/service.js +86 -0
  135. package/dist/modules/source/types.d.ts +55 -0
  136. package/dist/modules/source/types.js +6 -0
  137. package/dist/modules/time/internal/anchor.d.ts +2 -0
  138. package/dist/modules/time/internal/anchor.js +48 -0
  139. package/dist/modules/time/internal/keeper.d.ts +13 -0
  140. package/dist/modules/time/internal/keeper.js +19 -0
  141. package/dist/modules/time/internal/zones.d.ts +1 -0
  142. package/dist/modules/time/internal/zones.js +3 -0
  143. package/dist/modules/time/service.d.ts +2 -0
  144. package/dist/modules/time/service.js +56 -0
  145. package/dist/modules/time/types.d.ts +89 -0
  146. package/dist/modules/time/types.js +1 -0
  147. package/package.json +35 -3
@@ -0,0 +1,13 @@
1
+ import type { Move } from "orthograph";
2
+ /** Whether any operation or read lists the keeper: a blank's `allowed` isn't written yet, so it says nothing. */
3
+ export declare const keeperUsed: (declared: ReadonlyArray<unknown>) => boolean;
4
+ /** The problems with who an operation or a read allows, naming it: `move` is absent for a read and for an operation with no move. */
5
+ export declare const keeperProblems: (spec: {
6
+ readonly file: string;
7
+ readonly name: string;
8
+ readonly kind: "operation" | "read";
9
+ readonly move: Move | undefined;
10
+ readonly allowed: ReadonlyArray<{
11
+ readonly kind: string;
12
+ }>;
13
+ }) => ReadonlyArray<string>;
@@ -0,0 +1,19 @@
1
+ const lists = (allowed) => allowed.some((a) => a.kind === "keeper");
2
+ /** Whether any operation or read lists the keeper: a blank's `allowed` isn't written yet, so it says nothing. */
3
+ export const keeperUsed = (declared) => declared.some((allowed) => Array.isArray(allowed) && lists(allowed));
4
+ /** The problems with who an operation or a read allows, naming it: `move` is absent for a read and for an operation with no move. */
5
+ export const keeperProblems = (spec) => {
6
+ const madeByTime = spec.move?.by !== undefined;
7
+ const keeper = lists(spec.allowed);
8
+ // Access accepts any entry that matches, so one more entry beside the keeper lets that caller run the move too.
9
+ const others = spec.allowed.filter((a) => a.kind !== "keeper");
10
+ if (madeByTime && keeper && others.length > 0)
11
+ return [`${spec.file}: ${spec.name} makes the move ${spec.move.key}, which is made by time, so it is allowed to the keeper alone, but it also allows ${others.map((a) => a.kind).join(", ")}`];
12
+ if (madeByTime && !keeper)
13
+ return [`${spec.file}: ${spec.name} makes the move ${spec.move.key}, which is made by time, so it must be allowed to the keeper (allowed: [Blueprint.keeper])`];
14
+ if (keeper && !madeByTime) {
15
+ const why = spec.kind === "read" ? "is a read" : spec.move ? `makes the move ${spec.move.key}, which is not made by time` : "makes no move";
16
+ return [`${spec.file}: ${spec.name} allows the keeper, but it ${why}: the keeper calls only moves made by time`];
17
+ }
18
+ return [];
19
+ };
@@ -0,0 +1 @@
1
+ export declare const isZone: (name: string) => boolean;
@@ -0,0 +1,3 @@
1
+ // The tz database as the runtime knows it: `Intl` carries it, so no dependency is added. `UTC` is a zone but not always listed.
2
+ const known = new Set([...Intl.supportedValuesOf("timeZone"), "UTC"]);
3
+ export const isZone = (name) => known.has(name);
@@ -0,0 +1,2 @@
1
+ import type { TimesApi } from "./types.ts";
2
+ export declare const Times: TimesApi;
@@ -0,0 +1,56 @@
1
+ import { DateTime, Option } from "effect";
2
+ import { Spans } from "orthograph/server";
3
+ import { anchorProblems } from "./internal/anchor.js";
4
+ import { keeperProblems, keeperUsed } from "./internal/keeper.js";
5
+ const spanProblem = (where, what, span) => {
6
+ const read = Spans.read(span);
7
+ return read !== undefined && read.count >= 1 ? [] : [`${where} is made by time, but its ${what} "${span}" isn't a span: a whole number of seconds, minutes, hours, days, weeks, months or years, like "1 month" or "14 days"`];
8
+ };
9
+ const moveOf = ({ name, thing, key, move }) => {
10
+ const where = `${name}.${key}`;
11
+ const { by, late, lazy } = move;
12
+ if (by === undefined) {
13
+ const stray = [late === undefined ? "" : "late", lazy === undefined ? "" : "lazy"].filter((s) => s !== "");
14
+ return { time: undefined, problems: stray.length === 0 ? [] : [`${where} declares ${stray.join(" and ")} but is not made by time: give it a \`by\``] };
15
+ }
16
+ const problems = [
17
+ ...(move.from.length === 0 ? [`${where} is made by time, but it has no from state: a move that creates the thing has nothing to count from`] : []),
18
+ ...spanProblem(where, "span", by.span),
19
+ ...(late === undefined ? [] : spanProblem(where, "late", late)),
20
+ ...anchorProblems(where, thing, by),
21
+ ];
22
+ const time = {
23
+ by: by.kind === "after"
24
+ ? { kind: "after", field: by.field, span: by.span }
25
+ : { kind: "every", span: by.span, ...(by.from === undefined ? {} : { from: by.from }), ...(by.on === undefined ? {} : { on: by.on }), ...(by.zone === undefined ? {} : { zone: by.zone }) },
26
+ ...(late === undefined ? {} : { late }),
27
+ ...(lazy === true ? { lazy: true } : {}),
28
+ };
29
+ return { time, problems };
30
+ };
31
+ export const Times = {
32
+ move: moveOf,
33
+ timed: ({ file, problems, ...spec }) => {
34
+ const found = moveOf(spec);
35
+ problems.push(...found.problems.map((p) => `${file}: ${p}`));
36
+ return found.time;
37
+ },
38
+ keeperUsed,
39
+ keeper: keeperProblems,
40
+ clock: ({ file, clock, environment, promotes }) => {
41
+ if (clock.which === "real")
42
+ return { clock: { kind: "real" }, problems: [] };
43
+ if (promotes === true) {
44
+ return { clock: undefined, problems: [`${file}: environment "${environment ?? "this one"}" promotes to production, so its clock must be real: a ${clock.which} clock is for local and test worlds (ortho check refuses it here)`] };
45
+ }
46
+ const starts = DateTime.make(clock.starts);
47
+ if (Option.isNone(starts))
48
+ return { clock: undefined, problems: [`${file}: the clock starts at "${clock.starts}", which isn't an instant (ISO 8601, like 2027-01-10T09:00:00Z)`] };
49
+ const at = DateTime.formatIso(starts.value);
50
+ if (clock.which === "stepped")
51
+ return { clock: { kind: "stepped", starts: at }, problems: [] };
52
+ if (!(clock.speed > 0) || !Number.isFinite(clock.speed))
53
+ return { clock: undefined, problems: [`${file}: the scaled clock's speed ${String(clock.speed)} must be a number above 0`] };
54
+ return { clock: { kind: "scaled", starts: at, speed: clock.speed }, problems: [] };
55
+ },
56
+ };
@@ -0,0 +1,89 @@
1
+ import type { Clock, Move, Thing } from "orthograph";
2
+ export type ByModel = {
3
+ readonly kind: "every";
4
+ /** As written: `"1 month"`. */
5
+ readonly span: string;
6
+ /** The thing's own instant field the period counts from. */
7
+ readonly from?: string;
8
+ /** A day on the calendar, worked out in `zone`. */
9
+ readonly on?: {
10
+ readonly day: number | "last";
11
+ } | {
12
+ readonly weekday: string;
13
+ };
14
+ /** A tz database name, or a text field of the thing. */
15
+ readonly zone?: string;
16
+ } | {
17
+ readonly kind: "after";
18
+ readonly field: string;
19
+ readonly span: string;
20
+ };
21
+ /** What a move made by time adds to its machine entry, beside `from`, `to` and `emits`. */
22
+ export interface MoveTimeModel {
23
+ readonly by: ByModel;
24
+ /** How long after its due instant the move may still run on time. Absent: it must run exactly when due. */
25
+ readonly late?: string;
26
+ /** Worked out at the thing's next use; the keeper never fires it. */
27
+ readonly lazy?: true;
28
+ }
29
+ /** An environment's clock, its start normalised to ISO 8601 with milliseconds. */
30
+ export type ClockModel = {
31
+ readonly kind: "real";
32
+ } | {
33
+ readonly kind: "stepped";
34
+ readonly starts: string;
35
+ } | {
36
+ readonly kind: "scaled";
37
+ readonly starts: string;
38
+ readonly speed: number;
39
+ };
40
+ export interface TimesApi {
41
+ /**
42
+ * A move's time declaration, checked against its thing: every problem is named by the move (`membership.renew`) and its
43
+ * machine file. A move with no `by` has none to check, and `late` or `lazy` beside no `by` is a problem.
44
+ */
45
+ readonly move: (spec: {
46
+ readonly name: string;
47
+ readonly thing: Thing;
48
+ readonly key: string;
49
+ readonly move: Move;
50
+ }) => {
51
+ readonly time: MoveTimeModel | undefined;
52
+ readonly problems: ReadonlyArray<string>;
53
+ };
54
+ /** `move`, pushing its problems (each led by `file`) onto `problems` and handing back what the model adds to the move. */
55
+ readonly timed: (spec: {
56
+ readonly name: string;
57
+ readonly thing: Thing;
58
+ readonly key: string;
59
+ readonly move: Move;
60
+ readonly file: string;
61
+ readonly problems: Array<string>;
62
+ }) => MoveTimeModel | undefined;
63
+ /** Whether any operation or read lists the keeper, given each one's declared `allowed` (a blank's says nothing). */
64
+ readonly keeperUsed: (declared: ReadonlyArray<unknown>) => boolean;
65
+ /** What is wrong with who an operation or a read allows: the keeper only on a move made by time, and only there. */
66
+ readonly keeper: (spec: {
67
+ readonly file: string;
68
+ readonly name: string;
69
+ readonly kind: "operation" | "read";
70
+ readonly move: Move | undefined;
71
+ readonly allowed: ReadonlyArray<{
72
+ readonly kind: string;
73
+ }>;
74
+ }) => ReadonlyArray<string>;
75
+ /**
76
+ * An environment's clock, or the problems with it. `promotes` says the environment is in a promotion chain (it promotes
77
+ * from another, or another promotes from it): only a real clock may be there, since a stepped or scaled one is for worlds
78
+ * that are made and thrown away (K23 section 1).
79
+ */
80
+ readonly clock: (spec: {
81
+ readonly file: string;
82
+ readonly clock: Clock;
83
+ readonly environment?: string;
84
+ readonly promotes?: boolean;
85
+ }) => {
86
+ readonly clock: ClockModel | undefined;
87
+ readonly problems: ReadonlyArray<string>;
88
+ };
89
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@orthograph/compiler",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0-next.2",
4
+ "license": "Apache-2.0",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ },
11
+ "./main": {
12
+ "types": "./dist/main.d.ts",
13
+ "default": "./dist/main.js"
14
+ }
15
+ },
16
+ "dependencies": {
17
+ "effect": "4.1.4",
18
+ "orthograph": "0.1.0-next.2"
19
+ },
20
+ "imports": {
21
+ "#modules/*.js": "./dist/modules/*.js"
22
+ },
23
+ "bin": {
24
+ "ortho-model": "./dist/main.js"
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public",
31
+ "tag": "next"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/Open-Harness/orthograph.git",
36
+ "directory": "packages/compiler"
37
+ }
6
38
  }