@trytilde/ontology 0.0.0-stage → 3.1.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.
- package/LICENSE +5 -0
- package/dist/catalog.d.ts +53 -0
- package/dist/catalog.js +7 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +129 -0
- package/dist/mod.d.ts +1132 -0
- package/dist/mod.js +1083 -0
- package/package.json +36 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Copyright (c) Tilde. All rights reserved.
|
|
2
|
+
|
|
3
|
+
This software is proprietary. Use is permitted only with Tilde Cloud, under its terms of
|
|
4
|
+
service. No other right or licence is granted, and this software may not be copied, modified,
|
|
5
|
+
distributed or used except as those terms allow.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Every `kind` of a ducktail pipeline. */
|
|
2
|
+
export type PipelineKind = "postgres" | "kafka" | "webhook" | "linear" | "sentry" | "cloudwatch" | "plaid" | "quickbooks" | "xero" | "gmail" | "google_calendar" | "google_contacts" | "slack" | "cell_edits";
|
|
3
|
+
/** Polled kinds (one leased task each). */
|
|
4
|
+
export type PolledKind = "linear" | "sentry" | "cloudwatch" | "plaid" | "quickbooks" | "xero" | "gmail" | "google_calendar" | "google_contacts" | "slack";
|
|
5
|
+
/** Each polled kind's streams. */
|
|
6
|
+
export interface PolledStreams {
|
|
7
|
+
linear: "teams" | "users" | "workflow_states" | "projects" | "cycles" | "issues" | "comments";
|
|
8
|
+
sentry: "projects" | "issues";
|
|
9
|
+
cloudwatch: "ecs_clusters" | "ecs_services" | "load_balancers" | "target_groups" | "target_health" | "metric_data" | "alarms" | "alarm_history";
|
|
10
|
+
plaid: "item" | "accounts" | "transactions" | "holdings" | "securities" | "investment_transactions" | "liabilities_credit" | "liabilities_mortgage" | "liabilities_student";
|
|
11
|
+
quickbooks: "company_info" | "accounts" | "classes" | "departments" | "customers" | "vendors" | "employees" | "items" | "tax_codes" | "terms" | "payment_methods" | "journal_entries" | "invoices" | "sales_receipts" | "credit_memos" | "refund_receipts" | "payments" | "bills" | "bill_payments" | "vendor_credits" | "purchases" | "deposits" | "transfers" | "estimates" | "purchase_orders";
|
|
12
|
+
xero: "organisation" | "accounts" | "tracking_categories" | "tax_rates" | "items" | "contacts" | "journals" | "manual_journals" | "invoices" | "credit_notes" | "bank_transactions" | "bank_transfers" | "payments" | "overpayments" | "prepayments";
|
|
13
|
+
gmail: "labels" | "messages" | "threads";
|
|
14
|
+
google_calendar: "calendars" | "events" | "event_instances";
|
|
15
|
+
google_contacts: "contacts" | "other_contacts" | "contact_groups";
|
|
16
|
+
slack: "conversations" | "users" | "messages" | "replies";
|
|
17
|
+
}
|
|
18
|
+
/** The Tilde connection provider each polled kind takes its slot of. */
|
|
19
|
+
export interface PolledProvider {
|
|
20
|
+
linear: "linear";
|
|
21
|
+
sentry: "sentry";
|
|
22
|
+
cloudwatch: "aws";
|
|
23
|
+
plaid: "plaid";
|
|
24
|
+
quickbooks: "quickbooks";
|
|
25
|
+
xero: "xero";
|
|
26
|
+
gmail: "google";
|
|
27
|
+
google_calendar: "google";
|
|
28
|
+
google_contacts: "google";
|
|
29
|
+
slack: "slack";
|
|
30
|
+
}
|
|
31
|
+
/** Providers whose webhooks a webhook pipeline routes by event. */
|
|
32
|
+
export type WebhookProvider = "github" | "linear" | "sentry";
|
|
33
|
+
/** Each provider's event names (the values of its event header). */
|
|
34
|
+
export interface WebhookEvents {
|
|
35
|
+
github: "check_run" | "check_suite" | "code_scanning_alert" | "create" | "delete" | "dependabot_alert" | "deployment" | "deployment_status" | "discussion" | "discussion_comment" | "fork" | "installation" | "installation_repositories" | "issue_comment" | "issues" | "label" | "member" | "merge_group" | "milestone" | "ping" | "pull_request" | "pull_request_review" | "pull_request_review_comment" | "pull_request_review_thread" | "push" | "release" | "repository" | "secret_scanning_alert" | "status" | "workflow_job" | "workflow_run";
|
|
36
|
+
linear: "Attachment" | "AuditEntry" | "Comment" | "Customer" | "CustomerNeed" | "Cycle" | "Document" | "Initiative" | "InitiativeUpdate" | "Issue" | "IssueLabel" | "IssueSLA" | "OAuthApp" | "Project" | "ProjectUpdate" | "Reaction" | "User";
|
|
37
|
+
sentry: "comment" | "error" | "event_alert" | "installation" | "issue" | "metric_alert" | "seer";
|
|
38
|
+
}
|
|
39
|
+
/** Each provider's delivery key header and event header. */
|
|
40
|
+
export declare const webhookHeaders: {
|
|
41
|
+
readonly github: {
|
|
42
|
+
readonly key: "x-github-delivery";
|
|
43
|
+
readonly event: "x-github-event";
|
|
44
|
+
};
|
|
45
|
+
readonly linear: {
|
|
46
|
+
readonly key: "linear-delivery";
|
|
47
|
+
readonly event: "linear-event";
|
|
48
|
+
};
|
|
49
|
+
readonly sentry: {
|
|
50
|
+
readonly key: "request-id";
|
|
51
|
+
readonly event: "sentry-hook-resource";
|
|
52
|
+
};
|
|
53
|
+
};
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Generated from ducktail's catalog (crates/ducktail/src/catalog.rs) by `task ducktail:catalog`: do not edit.
|
|
2
|
+
/** Each provider's delivery key header and event header. */
|
|
3
|
+
export const webhookHeaders = {
|
|
4
|
+
github: { key: "x-github-delivery", event: "x-github-event" },
|
|
5
|
+
linear: { key: "linear-delivery", event: "linear-event" },
|
|
6
|
+
sentry: { key: "request-id", event: "sentry-hook-resource" },
|
|
7
|
+
};
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
3
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
4
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
5
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
return path;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The client build of an ontology, which `tilde deploy` runs from the project's own
|
|
12
|
+
* `node_modules` (never on Tilde's servers):
|
|
13
|
+
*
|
|
14
|
+
* - `ir <root>`: evaluate `<root>/ontology.ts` and print its IR (JSON, with the project's package
|
|
15
|
+
* name, which names its contract) on stdout. The project's
|
|
16
|
+
* files are bundled (TypeScript, with source maps so definitions keep their locations); its
|
|
17
|
+
* packages, this SDK and zod among them, load from its own `node_modules`, so the definitions
|
|
18
|
+
* and `toIR` share one SDK.
|
|
19
|
+
* - `worker <root> <out>`: bundle `<root>/ontology.ts` into one ES module for Workers: the
|
|
20
|
+
* handler module of the version. The SDK and zod stay imports (`./sdk.js`, `./zod.js`), which
|
|
21
|
+
* Tilde supplies beside its own runtime, so the definitions and the runtime share them.
|
|
22
|
+
*/
|
|
23
|
+
import * as esbuild from "esbuild";
|
|
24
|
+
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
25
|
+
import { join, resolve } from "node:path";
|
|
26
|
+
import { pathToFileURL } from "node:url";
|
|
27
|
+
/** Node's built-ins, left to the Workers runtime's `nodejs_compat` (bare and `node:`-prefixed). */
|
|
28
|
+
const NODE_BUILTINS = [
|
|
29
|
+
"assert", "async_hooks", "buffer", "child_process", "crypto", "diagnostics_channel", "dns", "events", "fs", "http",
|
|
30
|
+
"https", "net", "os", "path", "perf_hooks", "process", "querystring", "stream", "string_decoder", "timers", "tls",
|
|
31
|
+
"url", "util", "worker_threads", "zlib",
|
|
32
|
+
];
|
|
33
|
+
/** Node's built-ins, left to `nodejs_compat`: an ES module imports one as it is (`node:x`); a
|
|
34
|
+
* CommonJS `require()` of one, which an ES module bundle cannot emit, goes through a module that
|
|
35
|
+
* imports it and exports it as the CommonJS module's value (as wrangler bundles). */
|
|
36
|
+
const BUILTIN = new RegExp(`^(node:)?(${NODE_BUILTINS.join("|")})(/.*)?$`);
|
|
37
|
+
const builtins = {
|
|
38
|
+
name: "tilde-node-builtins",
|
|
39
|
+
setup(build) {
|
|
40
|
+
build.onResolve({ filter: BUILTIN }, (args) => {
|
|
41
|
+
const path = args.path.startsWith("node:") ? args.path : `node:${args.path}`;
|
|
42
|
+
return args.kind === "require-call" ? { path, namespace: "tilde-builtin" } : { path, external: true };
|
|
43
|
+
});
|
|
44
|
+
build.onLoad({ filter: /.*/, namespace: "tilde-builtin" }, (args) => ({
|
|
45
|
+
contents: `import builtin from ${JSON.stringify(args.path)};\nmodule.exports = builtin;\n`,
|
|
46
|
+
loader: "js",
|
|
47
|
+
}));
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
/** The imports Tilde's runtime supplies: one SDK and one zod for the definitions and the runtime. */
|
|
51
|
+
const shared = {
|
|
52
|
+
name: "tilde-shared",
|
|
53
|
+
setup(build) {
|
|
54
|
+
build.onResolve({ filter: /^@trytilde\/ontology$/ }, () => ({ path: "./sdk.js", external: true }));
|
|
55
|
+
build.onResolve({ filter: /^zod(\/v4)?$/ }, () => ({ path: "./zod.js", external: true }));
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
async function ir(root) {
|
|
59
|
+
const dir = join(root, ".tilde");
|
|
60
|
+
mkdirSync(dir, { recursive: true });
|
|
61
|
+
// Build scratch, never part of the tree (tilde deploy builds a clean HEAD).
|
|
62
|
+
writeFileSync(join(dir, ".gitignore"), "*\n");
|
|
63
|
+
const out = join(dir, `ir-${process.pid}.mjs`);
|
|
64
|
+
const entry = `import def from ${JSON.stringify(join(root, "ontology.ts"))};
|
|
65
|
+
import { toIR } from "@trytilde/ontology";
|
|
66
|
+
export default { def, toIR };
|
|
67
|
+
`;
|
|
68
|
+
await esbuild.build({
|
|
69
|
+
stdin: { contents: entry, resolveDir: root, sourcefile: "tilde-ir.ts", loader: "ts" },
|
|
70
|
+
bundle: true,
|
|
71
|
+
packages: "external",
|
|
72
|
+
platform: "node",
|
|
73
|
+
format: "esm",
|
|
74
|
+
target: "es2022",
|
|
75
|
+
sourcemap: "inline",
|
|
76
|
+
outfile: out,
|
|
77
|
+
logLevel: "error",
|
|
78
|
+
});
|
|
79
|
+
process.setSourceMapsEnabled(true);
|
|
80
|
+
try {
|
|
81
|
+
const { def, toIR } = (await import(__rewriteRelativeImportExtension(pathToFileURL(out).href))).default;
|
|
82
|
+
if (!def || def.kind !== "ontology")
|
|
83
|
+
throw new Error("ontology.ts must `export default ontology({ ... })`");
|
|
84
|
+
const readFile = (path) => readFileSync(join(root, path.replace(/^\.\//, "")), "utf8");
|
|
85
|
+
// The project's package name names its contract (`<name>.v1`): Tilde has only the IR.
|
|
86
|
+
let packageName;
|
|
87
|
+
try {
|
|
88
|
+
packageName = JSON.parse(readFileSync(join(root, "package.json"), "utf8")).name;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// No package.json: the contract's default package.
|
|
92
|
+
}
|
|
93
|
+
const ir = { ...toIR(def, root, readFile), ...(packageName ? { package: packageName } : {}) };
|
|
94
|
+
process.stdout.write(JSON.stringify(ir, null, 2) + "\n");
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
rmSync(out, { force: true });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function worker(root, out) {
|
|
101
|
+
const result = await esbuild.build({
|
|
102
|
+
entryPoints: [join(root, "ontology.ts")],
|
|
103
|
+
bundle: true,
|
|
104
|
+
format: "esm",
|
|
105
|
+
platform: "neutral",
|
|
106
|
+
target: "es2022",
|
|
107
|
+
conditions: ["workerd", "worker", "browser"],
|
|
108
|
+
mainFields: ["workerd", "worker", "browser", "module", "main"],
|
|
109
|
+
external: ["cloudflare:*"],
|
|
110
|
+
plugins: [shared, builtins],
|
|
111
|
+
write: false,
|
|
112
|
+
logLevel: "error",
|
|
113
|
+
});
|
|
114
|
+
mkdirSync(resolve(out, ".."), { recursive: true });
|
|
115
|
+
writeFileSync(out, result.outputFiles[0].contents);
|
|
116
|
+
}
|
|
117
|
+
const [command, root, out] = process.argv.slice(2);
|
|
118
|
+
try {
|
|
119
|
+
if (command === "ir" && root)
|
|
120
|
+
await ir(resolve(root));
|
|
121
|
+
else if (command === "worker" && root && out)
|
|
122
|
+
await worker(resolve(root), resolve(out));
|
|
123
|
+
else
|
|
124
|
+
throw new Error("usage: tilde-ontology-build ir <root> | worker <root> <out>");
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.error(error instanceof Error ? error.message : error);
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|