@composable-os/cli 0.0.0-stage → 0.1.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +109 -0
- package/README.md +24 -2
- package/dist/accounts-UHYLCLEY.js +45 -0
- package/dist/blocks-5IFU25J6.js +233 -0
- package/dist/chunk-2ABSVMGB.js +13 -0
- package/dist/chunk-2IVEVPMY.js +669 -0
- package/dist/chunk-2TWV3SVB.js +349 -0
- package/dist/chunk-2XC5JLBO.js +1931 -0
- package/dist/chunk-324WJXNP.js +320 -0
- package/dist/chunk-5KSXSK7Y.js +47 -0
- package/dist/chunk-6ELZRNUU.js +116 -0
- package/dist/chunk-6UWRT4VM.js +220 -0
- package/dist/chunk-6WGFA2IV.js +643 -0
- package/dist/chunk-6XTU2MTP.js +11278 -0
- package/dist/chunk-7CQGMVDO.js +63 -0
- package/dist/chunk-7D4GKZOX.js +615 -0
- package/dist/chunk-7OGCMQXG.js +284 -0
- package/dist/chunk-DHS2CV2M.js +139 -0
- package/dist/chunk-DU6OIFOU.js +2358 -0
- package/dist/chunk-E4WCYTCT.js +347 -0
- package/dist/chunk-E64SG24J.js +88 -0
- package/dist/chunk-FJIZGS5Q.js +698 -0
- package/dist/chunk-GYTEW66E.js +50 -0
- package/dist/chunk-HDIOVFAZ.js +544 -0
- package/dist/chunk-K34UKWEI.js +298 -0
- package/dist/chunk-KGHA67HG.js +765 -0
- package/dist/chunk-LAAL4YGR.js +365 -0
- package/dist/chunk-LO6WGU5Y.js +26189 -0
- package/dist/chunk-MBIKVRAC.js +1425 -0
- package/dist/chunk-P6UWZ6QQ.js +426 -0
- package/dist/chunk-PDD2ETVF.js +1302 -0
- package/dist/chunk-UB4I2QKR.js +31575 -0
- package/dist/chunk-WHKJGF36.js +2418 -0
- package/dist/chunk-XIDLW3EP.js +15471 -0
- package/dist/chunk-YFTLIEWU.js +504 -0
- package/dist/chunk-YNUZRTPH.js +182 -0
- package/dist/chunk-ZAWES2UD.js +9364 -0
- package/dist/chunk-ZZFWMVJO.js +704 -0
- package/dist/cli-5UNY5G5L.js +136 -0
- package/dist/cli-UYZMVQMR.js +24534 -0
- package/dist/cli.js +25 -0
- package/dist/client-repo-SE4EKG6W.js +55 -0
- package/dist/create.js +25 -0
- package/dist/fields-FTWWMD7N.js +50 -0
- package/dist/grants-LOW6TSWD.js +32 -0
- package/dist/invoke-6KVT6WJI.js +41 -0
- package/dist/moves-E2HKYCTK.js +41 -0
- package/dist/order-U4KZLLSJ.js +19 -0
- package/dist/person-UHLVBVLR.js +67 -0
- package/dist/plan-on-sale-TJPFCNL7.js +26 -0
- package/dist/platform/migrations/0001_init.sql +59 -0
- package/dist/platform/migrations/0002_users_settings.sql +34 -0
- package/dist/platform/migrations/0003_people_organisations.sql +225 -0
- package/dist/platform/migrations/0004_activities_tasks.sql +88 -0
- package/dist/platform/migrations/0005_views_audit.sql +79 -0
- package/dist/platform/migrations/0006_search.sql +223 -0
- package/dist/platform/migrations/0007_crm_views.sql +141 -0
- package/dist/platform/migrations/0008_audit_redaction.sql +116 -0
- package/dist/platform/migrations/0010_approval_queue.sql +90 -0
- package/dist/platform/migrations/0011_connected_apps.sql +36 -0
- package/dist/platform/migrations/0020_extensions.sql +373 -0
- package/dist/platform/migrations/0030_extension_proposals.sql +29 -0
- package/dist/platform/migrations/0050_live_row_indexes.sql +32 -0
- package/dist/platform/migrations/0060_audit_read_counts.sql +31 -0
- package/dist/platform/migrations/0061_audit_retention.sql +95 -0
- package/dist/platform/migrations/0062_run_history_retention.sql +6 -0
- package/dist/platform/migrations/0063_pending_action_compaction.sql +18 -0
- package/dist/platform/migrations/0064_drop_rate_limit.sql +6 -0
- package/dist/platform/migrations/0065_storage_stats.sql +13 -0
- package/dist/platform/migrations/0070_drop_proposals_ext_idx.sql +9 -0
- package/dist/platform/migrations/0080_views_dashboards.sql +46 -0
- package/dist/platform/migrations/0100_stage_history.sql +54 -0
- package/dist/platform/migrations/0110_integrations.sql +103 -0
- package/dist/platform/migrations/0111_email_calendar_sync.sql +137 -0
- package/dist/platform/migrations/0112_sync_item_occurred_at.sql +8 -0
- package/dist/platform/migrations/0130_automations.sql +113 -0
- package/dist/platform/migrations/0131_notifications.sql +29 -0
- package/dist/platform/migrations/0132_automation_runtime.sql +14 -0
- package/dist/platform/migrations/0150_ai_summaries_embeddings.sql +48 -0
- package/dist/platform/migrations/0160_releases.sql +41 -0
- package/dist/platform/migrations/0161_setup_wizard.sql +30 -0
- package/dist/platform/migrations/0170_automation_connections.sql +32 -0
- package/dist/platform/migrations/0171_automation_outbox.sql +23 -0
- package/dist/platform/migrations/0172_notification_delivery.sql +46 -0
- package/dist/platform/migrations/0200_assistant_conversations.sql +25 -0
- package/dist/platform/migrations/0205_policy_adjudicator.sql +61 -0
- package/dist/platform/migrations/0210_daily_digest.sql +33 -0
- package/dist/platform/migrations/0220_entitlements.sql +13 -0
- package/dist/platform/migrations/0221_support_grants.sql +33 -0
- package/dist/platform/migrations/0250_judge.sql +11 -0
- package/dist/platform/migrations/0251_adjudication_judgement.sql +8 -0
- package/dist/platform/migrations/0252_judge_usage.sql +14 -0
- package/dist/platform/migrations/0255_summary_checks.sql +9 -0
- package/dist/platform/migrations/0256_outbound_check.sql +9 -0
- package/dist/platform/migrations/0260_ai_usage.sql +20 -0
- package/dist/platform/migrations/0270_assistant_conversation_refs.sql +29 -0
- package/dist/platform/migrations/0310_assignment_rules.sql +54 -0
- package/dist/platform/migrations/0320_duplicates.sql +41 -0
- package/dist/platform/migrations/0330_erase_completeness.sql +54 -0
- package/dist/platform/migrations/0350_assistant_thread.sql +38 -0
- package/dist/platform/migrations/0351_assistant_model_roles.sql +26 -0
- package/dist/platform/migrations/0352_assistant_memory.sql +74 -0
- package/dist/platform/migrations/0358_ai_cache_observation.sql +24 -0
- package/dist/platform/migrations/0359_ai_compaction_decision.sql +25 -0
- package/dist/platform/migrations/0360_ai_cache_estimate.sql +35 -0
- package/dist/platform/migrations/0361_voice_preferences.sql +27 -0
- package/dist/platform/migrations/0362_voice_usage.sql +17 -0
- package/dist/platform/migrations/0365_routines.sql +38 -0
- package/dist/platform/migrations/0370_approval_execution.sql +20 -0
- package/dist/platform/migrations/0371_agent_jobs.sql +65 -0
- package/dist/platform/migrations/0380_rec_views.sql +94 -0
- package/dist/platform/migrations/0400_customer_audit_actor.sql +142 -0
- package/dist/platform/migrations/0401_customer_accounts.sql +61 -0
- package/dist/platform/migrations/0402_erase_requests.sql +34 -0
- package/dist/platform/migrations/0410_idempotency_keys.sql +45 -0
- package/dist/platform/migrations/0411_device_sessions.sql +33 -0
- package/dist/platform/migrations/0420_transition_history.sql +100 -0
- package/dist/platform/migrations/0421_orders.sql +134 -0
- package/dist/platform/migrations/0422_order_payments.sql +109 -0
- package/dist/platform/migrations/0440_capacity.sql +100 -0
- package/dist/platform/migrations/0441_capacity_views.sql +40 -0
- package/dist/platform/migrations/0450_order_grants.sql +21 -0
- package/dist/platform/migrations/0451_pack_roles.sql +18 -0
- package/dist/platform/migrations/0460_content.sql +59 -0
- package/dist/platform/migrations/0461_media.sql +52 -0
- package/dist/platform/migrations/0470_publish_versions.sql +36 -0
- package/dist/platform/migrations/0471_permission_grants.sql +18 -0
- package/dist/platform/migrations/0490_staff_invites.sql +40 -0
- package/dist/platform/migrations/0491_sign_in_mail_kind.sql +10 -0
- package/dist/platform/migrations/0492_email_confirmation_and_sign_in_confirm.sql +30 -0
- package/dist/platform/migrations/0500_published_media_field.sql +25 -0
- package/dist/platform/migrations/0501_import_keys.sql +23 -0
- package/dist/platform/migrations/0510_video_and_file_media.sql +109 -0
- package/dist/platform/migrations/0516_order_tax.sql +63 -0
- package/dist/platform/migrations/0520_publish_requests.sql +20 -0
- package/dist/platform/migrations/0530_subscriptions.sql +173 -0
- package/dist/platform/migrations/0531_subscription_trials.sql +56 -0
- package/dist/platform/migrations/0532_subscription_offers.sql +80 -0
- package/dist/platform/migrations/0533_allowances.sql +262 -0
- package/dist/platform/migrations/0560_recurring.sql +75 -0
- package/dist/platform/migrations/0580_subscription_grants.sql +21 -0
- package/dist/platform/migrations/0581_once_per_person.sql +34 -0
- package/dist/platform/migrations/0600_tool_actions_ran_at_queue.sql +22 -0
- package/dist/platform/migrations/0610_waitlists.sql +54 -0
- package/dist/platform/migrations/0630_subscription_changes.sql +122 -0
- package/dist/platform/migrations/0650_person_links.sql +90 -0
- package/dist/platform/migrations/0670_unmoved_guard.sql +52 -0
- package/dist/platform/migrations/0690_sellable_refund_due.sql +98 -0
- package/dist/platform/sdk/allowance.ts +522 -0
- package/dist/platform/sdk/automation-check.ts +534 -0
- package/dist/platform/sdk/automation.ts +743 -0
- package/dist/platform/sdk/behaviour.ts +215 -0
- package/dist/platform/sdk/capacity.ts +303 -0
- package/dist/platform/sdk/contract.ts +909 -0
- package/dist/platform/sdk/document.ts +935 -0
- package/dist/platform/sdk/field-types.ts +111 -0
- package/dist/platform/sdk/formula/ast.ts +72 -0
- package/dist/platform/sdk/formula/compile.ts +454 -0
- package/dist/platform/sdk/formula/index.ts +4 -0
- package/dist/platform/sdk/formula/parser.ts +417 -0
- package/dist/platform/sdk/index.ts +36 -0
- package/dist/platform/sdk/manifest.ts +1785 -0
- package/dist/platform/sdk/media.ts +108 -0
- package/dist/platform/sdk/permissions.ts +60 -0
- package/dist/platform/sdk/recurring.ts +321 -0
- package/dist/platform/sdk/renamed.ts +63 -0
- package/dist/platform/sdk/rich-text-fixture.ts +68 -0
- package/dist/platform/sdk/rich-text.ts +221 -0
- package/dist/platform/sdk/runtime.ts +410 -0
- package/dist/platform/sdk/sellable.ts +1138 -0
- package/dist/platform/sdk/slug.ts +25 -0
- package/dist/platform/sdk/states.ts +598 -0
- package/dist/platform/sdk/testing.ts +847 -0
- package/dist/platform/sdk/unique.ts +81 -0
- package/dist/products-2H5DR232.js +11 -0
- package/dist/run-7P4RQALH.js +648 -0
- package/dist/run-PO3W5BFA.js +508 -0
- package/dist/run-ZCGFMEZF.js +309 -0
- package/dist/src-CRO35DYY.js +46 -0
- package/dist/src-I3IJ4NKC.js +354 -0
- package/dist/token-MOJUA2U6.js +70 -0
- package/dist/token-util-TENRN4V7.js +6 -0
- package/dist/visibility-TVXZ67FD.js +41 -0
- package/package.json +33 -4
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
// Formula lexer and recursive-descent parser. Fail-closed: any character outside the grammar is a
|
|
2
|
+
// syntax error, so input such as `x; DROP TABLE y` or a stray quote never reaches the compiler.
|
|
3
|
+
import {
|
|
4
|
+
type BinaryOperator,
|
|
5
|
+
FORMULA_LIMITS,
|
|
6
|
+
type FormulaNode,
|
|
7
|
+
formulaError,
|
|
8
|
+
type Span,
|
|
9
|
+
} from "./ast.ts";
|
|
10
|
+
|
|
11
|
+
type TokenKind = "number" | "string" | "ident" | "op" | "lparen" | "rparen" | "comma" | "eof";
|
|
12
|
+
|
|
13
|
+
interface Token {
|
|
14
|
+
kind: TokenKind;
|
|
15
|
+
text: string;
|
|
16
|
+
/** Decoded value for string tokens. */
|
|
17
|
+
value?: string;
|
|
18
|
+
span: Span;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const OPERATORS = [
|
|
22
|
+
"<=",
|
|
23
|
+
">=",
|
|
24
|
+
"!=",
|
|
25
|
+
"<>",
|
|
26
|
+
"==",
|
|
27
|
+
"&&",
|
|
28
|
+
"||",
|
|
29
|
+
"+",
|
|
30
|
+
"-",
|
|
31
|
+
"*",
|
|
32
|
+
"/",
|
|
33
|
+
"%",
|
|
34
|
+
"&",
|
|
35
|
+
"=",
|
|
36
|
+
"<",
|
|
37
|
+
">",
|
|
38
|
+
"!",
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
export function tokenize(source: string): Token[] {
|
|
42
|
+
if (source.length > FORMULA_LIMITS.maxLength) {
|
|
43
|
+
throw formulaError(
|
|
44
|
+
"formula_too_complex",
|
|
45
|
+
`Formulas are limited to ${FORMULA_LIMITS.maxLength} characters`,
|
|
46
|
+
{ start: 0, end: source.length },
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
const tokens: Token[] = [];
|
|
50
|
+
let i = 0;
|
|
51
|
+
while (i < source.length) {
|
|
52
|
+
const char = source[i] as string;
|
|
53
|
+
if (char === " " || char === "\t" || char === "\n" || char === "\r") {
|
|
54
|
+
i += 1;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const start = i;
|
|
58
|
+
if (/[0-9]/.test(char) || (char === "." && /[0-9]/.test(source[i + 1] ?? ""))) {
|
|
59
|
+
const match = /^(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?/.exec(source.slice(i));
|
|
60
|
+
const text = match?.[0] ?? char;
|
|
61
|
+
i += text.length;
|
|
62
|
+
if (/[A-Za-z_]/.test(source[i] ?? "")) {
|
|
63
|
+
throw formulaError("formula_syntax", "A number cannot run into a name", {
|
|
64
|
+
start,
|
|
65
|
+
end: i + 1,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
tokens.push({ kind: "number", text, span: { start, end: i } });
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (/[A-Za-z_]/.test(char)) {
|
|
72
|
+
const match = /^[A-Za-z_][A-Za-z0-9_]*/.exec(source.slice(i));
|
|
73
|
+
const text = match?.[0] ?? char;
|
|
74
|
+
i += text.length;
|
|
75
|
+
tokens.push({ kind: "ident", text, span: { start, end: i } });
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (char === '"' || char === "'") {
|
|
79
|
+
let value = "";
|
|
80
|
+
i += 1;
|
|
81
|
+
let closed = false;
|
|
82
|
+
while (i < source.length) {
|
|
83
|
+
const c = source[i] as string;
|
|
84
|
+
if (c === "\\") {
|
|
85
|
+
const next = source[i + 1];
|
|
86
|
+
if (next === char || next === "\\") {
|
|
87
|
+
value += next;
|
|
88
|
+
i += 2;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (next === "n") {
|
|
92
|
+
value += "\n";
|
|
93
|
+
i += 2;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
throw formulaError("formula_syntax", "Unknown escape in string", {
|
|
97
|
+
start: i,
|
|
98
|
+
end: i + 2,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (c === char) {
|
|
102
|
+
closed = true;
|
|
103
|
+
i += 1;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if (c === "\0") {
|
|
107
|
+
throw formulaError("formula_syntax", "Strings cannot contain NUL", {
|
|
108
|
+
start: i,
|
|
109
|
+
end: i + 1,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
value += c;
|
|
113
|
+
i += 1;
|
|
114
|
+
}
|
|
115
|
+
if (!closed) {
|
|
116
|
+
throw formulaError("formula_syntax", "Unterminated string", { start, end: source.length });
|
|
117
|
+
}
|
|
118
|
+
if (value.length > FORMULA_LIMITS.maxStringLength) {
|
|
119
|
+
throw formulaError("formula_too_complex", "String literal is too long", { start, end: i });
|
|
120
|
+
}
|
|
121
|
+
tokens.push({ kind: "string", text: source.slice(start, i), value, span: { start, end: i } });
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (char === "(") {
|
|
125
|
+
tokens.push({ kind: "lparen", text: char, span: { start, end: i + 1 } });
|
|
126
|
+
i += 1;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (char === ")") {
|
|
130
|
+
tokens.push({ kind: "rparen", text: char, span: { start, end: i + 1 } });
|
|
131
|
+
i += 1;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (char === ",") {
|
|
135
|
+
tokens.push({ kind: "comma", text: char, span: { start, end: i + 1 } });
|
|
136
|
+
i += 1;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const op = OPERATORS.find((candidate) => source.startsWith(candidate, i));
|
|
140
|
+
if (op) {
|
|
141
|
+
tokens.push({ kind: "op", text: op, span: { start, end: i + op.length } });
|
|
142
|
+
i += op.length;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
throw formulaError("formula_syntax", `Unexpected character ${JSON.stringify(char)}`, {
|
|
146
|
+
start,
|
|
147
|
+
end: start + 1,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
tokens.push({ kind: "eof", text: "", span: { start: source.length, end: source.length } });
|
|
151
|
+
return tokens;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const COMPARISON: Record<string, BinaryOperator> = {
|
|
155
|
+
"=": "=",
|
|
156
|
+
"==": "=",
|
|
157
|
+
"!=": "!=",
|
|
158
|
+
"<>": "!=",
|
|
159
|
+
"<": "<",
|
|
160
|
+
"<=": "<=",
|
|
161
|
+
">": ">",
|
|
162
|
+
">=": ">=",
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
class Parser {
|
|
166
|
+
#pos = 0;
|
|
167
|
+
#nodes = 0;
|
|
168
|
+
#depth = 0;
|
|
169
|
+
|
|
170
|
+
constructor(readonly tokens: Token[]) {}
|
|
171
|
+
|
|
172
|
+
get peek(): Token {
|
|
173
|
+
return this.tokens[this.#pos] as Token;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
next(): Token {
|
|
177
|
+
const token = this.peek;
|
|
178
|
+
if (token.kind !== "eof") this.#pos += 1;
|
|
179
|
+
return token;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
isWord(word: string): boolean {
|
|
183
|
+
return this.peek.kind === "ident" && this.peek.text.toLowerCase() === word;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
isOp(...ops: string[]): boolean {
|
|
187
|
+
return this.peek.kind === "op" && ops.includes(this.peek.text);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
node<N extends FormulaNode>(node: N): N {
|
|
191
|
+
this.#nodes += 1;
|
|
192
|
+
if (this.#nodes > FORMULA_LIMITS.maxNodes) {
|
|
193
|
+
throw formulaError("formula_too_complex", "Formula is too long", node.span);
|
|
194
|
+
}
|
|
195
|
+
return node;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
enter(span: Span) {
|
|
199
|
+
this.#depth += 1;
|
|
200
|
+
if (this.#depth > FORMULA_LIMITS.maxDepth) {
|
|
201
|
+
throw formulaError("formula_too_complex", "Formula is nested too deeply", span);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
leave() {
|
|
206
|
+
this.#depth -= 1;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
parse(): FormulaNode {
|
|
210
|
+
if (this.peek.kind === "eof") {
|
|
211
|
+
throw formulaError("formula_syntax", "Formula is empty", this.peek.span);
|
|
212
|
+
}
|
|
213
|
+
const expr = this.expression();
|
|
214
|
+
const rest: Token = this.peek;
|
|
215
|
+
if (rest.kind !== "eof") {
|
|
216
|
+
throw formulaError("formula_syntax", `Unexpected ${describe(rest)}`, rest.span);
|
|
217
|
+
}
|
|
218
|
+
return expr;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
expression(): FormulaNode {
|
|
222
|
+
this.enter(this.peek.span);
|
|
223
|
+
const result = this.or();
|
|
224
|
+
this.leave();
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
binary(op: BinaryOperator, left: FormulaNode, right: FormulaNode): FormulaNode {
|
|
229
|
+
return this.node({
|
|
230
|
+
kind: "binary",
|
|
231
|
+
op,
|
|
232
|
+
left,
|
|
233
|
+
right,
|
|
234
|
+
span: { start: left.span.start, end: right.span.end },
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
or(): FormulaNode {
|
|
239
|
+
let left = this.and();
|
|
240
|
+
while (this.isWord("or") || this.isOp("||")) {
|
|
241
|
+
this.next();
|
|
242
|
+
left = this.binary("or", left, this.and());
|
|
243
|
+
}
|
|
244
|
+
return left;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
and(): FormulaNode {
|
|
248
|
+
let left = this.not();
|
|
249
|
+
while (this.isWord("and") || this.isOp("&&")) {
|
|
250
|
+
this.next();
|
|
251
|
+
left = this.binary("and", left, this.not());
|
|
252
|
+
}
|
|
253
|
+
return left;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
not(): FormulaNode {
|
|
257
|
+
if (this.isWord("not") || this.isOp("!")) {
|
|
258
|
+
const token = this.next();
|
|
259
|
+
this.enter(token.span);
|
|
260
|
+
const operand = this.not();
|
|
261
|
+
this.leave();
|
|
262
|
+
return this.node({
|
|
263
|
+
kind: "unary",
|
|
264
|
+
op: "not",
|
|
265
|
+
operand,
|
|
266
|
+
span: { start: token.span.start, end: operand.span.end },
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
return this.comparison();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
comparison(): FormulaNode {
|
|
273
|
+
const left = this.concat();
|
|
274
|
+
if (this.peek.kind === "op" && this.peek.text in COMPARISON) {
|
|
275
|
+
const op = COMPARISON[this.next().text] as BinaryOperator;
|
|
276
|
+
const right = this.concat();
|
|
277
|
+
if (this.peek.kind === "op" && this.peek.text in COMPARISON) {
|
|
278
|
+
throw formulaError(
|
|
279
|
+
"formula_syntax",
|
|
280
|
+
"Comparisons cannot be chained; combine them with and",
|
|
281
|
+
this.peek.span,
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
return this.binary(op, left, right);
|
|
285
|
+
}
|
|
286
|
+
return left;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
concat(): FormulaNode {
|
|
290
|
+
let left = this.additive();
|
|
291
|
+
while (this.isOp("&")) {
|
|
292
|
+
this.next();
|
|
293
|
+
left = this.binary("&", left, this.additive());
|
|
294
|
+
}
|
|
295
|
+
return left;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
additive(): FormulaNode {
|
|
299
|
+
let left = this.multiplicative();
|
|
300
|
+
while (this.isOp("+", "-")) {
|
|
301
|
+
const op = this.next().text as "+" | "-";
|
|
302
|
+
left = this.binary(op, left, this.multiplicative());
|
|
303
|
+
}
|
|
304
|
+
return left;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
multiplicative(): FormulaNode {
|
|
308
|
+
let left = this.unary();
|
|
309
|
+
while (this.isOp("*", "/", "%")) {
|
|
310
|
+
const op = this.next().text as "*" | "/" | "%";
|
|
311
|
+
left = this.binary(op, left, this.unary());
|
|
312
|
+
}
|
|
313
|
+
return left;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
unary(): FormulaNode {
|
|
317
|
+
if (this.isOp("-")) {
|
|
318
|
+
const token = this.next();
|
|
319
|
+
this.enter(token.span);
|
|
320
|
+
const operand = this.unary();
|
|
321
|
+
this.leave();
|
|
322
|
+
return this.node({
|
|
323
|
+
kind: "unary",
|
|
324
|
+
op: "-",
|
|
325
|
+
operand,
|
|
326
|
+
span: { start: token.span.start, end: operand.span.end },
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
if (this.isOp("+")) {
|
|
330
|
+
this.next();
|
|
331
|
+
return this.unary();
|
|
332
|
+
}
|
|
333
|
+
return this.primary();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
primary(): FormulaNode {
|
|
337
|
+
const token = this.next();
|
|
338
|
+
switch (token.kind) {
|
|
339
|
+
case "number": {
|
|
340
|
+
const value = Number(token.text);
|
|
341
|
+
if (!Number.isFinite(value)) {
|
|
342
|
+
throw formulaError("formula_syntax", "Number is out of range", token.span);
|
|
343
|
+
}
|
|
344
|
+
return this.node({ kind: "number", value, text: token.text, span: token.span });
|
|
345
|
+
}
|
|
346
|
+
case "string":
|
|
347
|
+
return this.node({ kind: "string", value: token.value ?? "", span: token.span });
|
|
348
|
+
case "lparen": {
|
|
349
|
+
const inner = this.expression();
|
|
350
|
+
const close = this.next();
|
|
351
|
+
if (close.kind !== "rparen") {
|
|
352
|
+
throw formulaError(
|
|
353
|
+
"formula_syntax",
|
|
354
|
+
`Expected ) but found ${describe(close)}`,
|
|
355
|
+
close.span,
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
return inner;
|
|
359
|
+
}
|
|
360
|
+
case "ident": {
|
|
361
|
+
const lower = token.text.toLowerCase();
|
|
362
|
+
if (this.peek.kind === "lparen") return this.call(token);
|
|
363
|
+
if (lower === "true" || lower === "false") {
|
|
364
|
+
return this.node({ kind: "boolean", value: lower === "true", span: token.span });
|
|
365
|
+
}
|
|
366
|
+
if (lower === "null") return this.node({ kind: "null", span: token.span });
|
|
367
|
+
if (lower === "and" || lower === "or" || lower === "not") {
|
|
368
|
+
throw formulaError("formula_syntax", `Unexpected ${token.text}`, token.span);
|
|
369
|
+
}
|
|
370
|
+
return this.node({ kind: "field", name: token.text, span: token.span });
|
|
371
|
+
}
|
|
372
|
+
default:
|
|
373
|
+
throw formulaError("formula_syntax", `Unexpected ${describe(token)}`, token.span);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
call(name: Token): FormulaNode {
|
|
378
|
+
this.next(); // (
|
|
379
|
+
this.enter(name.span);
|
|
380
|
+
const args: FormulaNode[] = [];
|
|
381
|
+
if (this.peek.kind !== "rparen") {
|
|
382
|
+
for (;;) {
|
|
383
|
+
args.push(this.expression());
|
|
384
|
+
if (this.peek.kind === "comma") {
|
|
385
|
+
this.next();
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
const close = this.next();
|
|
392
|
+
if (close.kind !== "rparen") {
|
|
393
|
+
throw formulaError(
|
|
394
|
+
"formula_syntax",
|
|
395
|
+
`Expected , or ) in ${name.text}(...) but found ${describe(close)}`,
|
|
396
|
+
close.span,
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
this.leave();
|
|
400
|
+
return this.node({
|
|
401
|
+
kind: "call",
|
|
402
|
+
name: name.text,
|
|
403
|
+
args,
|
|
404
|
+
span: { start: name.span.start, end: close.span.end },
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function describe(token: Token): string {
|
|
410
|
+
if (token.kind === "eof") return "end of formula";
|
|
411
|
+
return JSON.stringify(token.text);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** Parses a formula expression into an AST. Throws FormulaError. */
|
|
415
|
+
export function parseFormula(source: string): FormulaNode {
|
|
416
|
+
return new Parser(tokenize(source)).parse();
|
|
417
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @composable-os/sdk: the extension contract (ADR 0005, ADR 0023). See README.md.
|
|
2
|
+
//
|
|
3
|
+
// import { defineExtension, defineTool, z } from "@composable-os/sdk";
|
|
4
|
+
// export default defineExtension({ id: "example", version: "1.0.0", contractVersion: 1, ... });
|
|
5
|
+
export { z } from "zod";
|
|
6
|
+
export * from "./allowance.ts";
|
|
7
|
+
export * from "./automation.ts";
|
|
8
|
+
export * from "./automation-check.ts";
|
|
9
|
+
export * from "./capacity.ts";
|
|
10
|
+
export * from "./contract.ts";
|
|
11
|
+
export * from "./document.ts";
|
|
12
|
+
export * from "./field-types.ts";
|
|
13
|
+
export * from "./manifest.ts";
|
|
14
|
+
export * from "./media.ts";
|
|
15
|
+
export * from "./permissions.ts";
|
|
16
|
+
export * from "./recurring.ts";
|
|
17
|
+
export * from "./renamed.ts";
|
|
18
|
+
export * from "./rich-text.ts";
|
|
19
|
+
export * from "./rich-text-fixture.ts";
|
|
20
|
+
export {
|
|
21
|
+
type AutomationRunValue,
|
|
22
|
+
AutomationStepError,
|
|
23
|
+
buildAutomationContext,
|
|
24
|
+
buildContext,
|
|
25
|
+
OpsCallError,
|
|
26
|
+
type OpsReply,
|
|
27
|
+
type RawHostModules,
|
|
28
|
+
type RunRequest,
|
|
29
|
+
type RunResponse,
|
|
30
|
+
runAutomation,
|
|
31
|
+
runExtension,
|
|
32
|
+
} from "./runtime.ts";
|
|
33
|
+
export * from "./sellable.ts";
|
|
34
|
+
export * from "./slug.ts";
|
|
35
|
+
export * from "./states.ts";
|
|
36
|
+
export * from "./unique.ts";
|