@niscorp/tide 0.1.6 → 0.1.8
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/CHANGELOG.md +29 -0
- package/DESIGN.md +7 -6
- package/DOCS.md +38 -10
- package/README.md +5 -1
- package/dist/agent.cjs +12 -14
- package/dist/agent.cjs.map +1 -1
- package/dist/agent.d.cts +1 -1
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +2 -4
- package/dist/agent.js.map +1 -1
- package/dist/{chunk-4CUQXWVY.js → chunk-7KHOAJNL.js} +3 -4
- package/dist/chunk-7KHOAJNL.js.map +1 -0
- package/dist/{chunk-UEG3UZDG.js → chunk-ZEEJLISU.js} +13 -17
- package/dist/chunk-ZEEJLISU.js.map +1 -0
- package/dist/index.cjs +21 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -5
- package/dist/index.d.ts +29 -5
- package/dist/index.js +13 -56
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.cjs +156 -0
- package/dist/migrations/index.cjs.map +1 -0
- package/dist/migrations/index.d.cts +198 -0
- package/dist/migrations/index.d.ts +198 -0
- package/dist/migrations/index.js +21 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/postgres.cjs +12 -10
- package/dist/postgres.cjs.map +1 -1
- package/dist/postgres.js +6 -3
- package/dist/postgres.js.map +1 -1
- package/dist/{reflex.schema-DeiyN5eN.d.cts → reflex.schema-DW1znJfS.d.cts} +29 -5
- package/dist/{reflex.schema-DeiyN5eN.d.ts → reflex.schema-DW1znJfS.d.ts} +29 -5
- package/dist/testing.cjs +0 -6
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.js +0 -6
- package/dist/testing.js.map +1 -1
- package/package.json +15 -5
- package/dist/chunk-4CUQXWVY.js.map +0 -1
- package/dist/chunk-UEG3UZDG.js.map +0 -1
|
@@ -8,14 +8,18 @@ var LOCAL_DATETIME = /^\d{4}-\d{2}-\d{2}T([01]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$/;
|
|
|
8
8
|
var ClockUnitSchema = z.enum(["day", "week", "month", "year"]);
|
|
9
9
|
var ClockRecurringSchema = z.object({
|
|
10
10
|
every: ClockUnitSchema.describe("The calendar period it repeats on. A repeating clock fires on every such period until the reflex is removed \u2014 only for a request that says it repeats."),
|
|
11
|
-
on: z.union([z.number().int().min(1).max(31), z.enum(WEEKDAYS), z.string().regex(MMDD)]).optional().describe(
|
|
11
|
+
on: z.union([z.number().int().min(1).max(31), z.enum(WEEKDAYS), z.array(z.enum(WEEKDAYS)).min(1), z.string().regex(MMDD)]).optional().describe(
|
|
12
|
+
'week \u2192 a weekday, or a list of them: ["mon","tue","wed","thu","fri"] is every weekday; month \u2192 1..31, where 31 is the last day of every month (a shorter month clamps to its end); year \u2192 "MM-DD". Omitted for day.'
|
|
13
|
+
),
|
|
12
14
|
at: z.string().regex(HHMM).describe('Local wall-clock time, "HH:MM".'),
|
|
13
15
|
tz: z.string().describe("IANA timezone name.")
|
|
14
16
|
}).strict().superRefine((clock, ctx) => {
|
|
15
17
|
const fail = (message) => ctx.addIssue({ code: "custom", message, path: ["on"] });
|
|
16
18
|
if (clock.every === "day" && clock.on !== void 0) fail("a daily clock takes no `on`");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
const weekday = (value) => typeof value === "string" && WEEKDAYS.some((d) => d === value);
|
|
20
|
+
const weekdays = Array.isArray(clock.on) && clock.on.length > 0 && new Set(clock.on).size === clock.on.length;
|
|
21
|
+
if (clock.every === "week" && !weekday(clock.on) && !weekdays) fail("a weekly clock needs `on` as a weekday (mon..sun), or a list of different weekdays");
|
|
22
|
+
if (clock.every !== "week" && Array.isArray(clock.on)) fail("only a weekly clock takes a list of weekdays");
|
|
19
23
|
if (clock.every === "month" && typeof clock.on !== "number") fail("a monthly clock needs `on` as a day number");
|
|
20
24
|
if (clock.every === "year" && !(typeof clock.on === "string" && MMDD.test(clock.on)))
|
|
21
25
|
fail('a yearly clock needs `on` as "MM-DD"');
|
|
@@ -56,15 +60,11 @@ var RetrySchema = z.object({
|
|
|
56
60
|
var PolicySchema = z.object({
|
|
57
61
|
retry: RetrySchema.optional(),
|
|
58
62
|
timeoutMs: z.number().int().positive().default(3e4),
|
|
59
|
-
// May a firing start while the previous one is unsettled? The long
|
|
60
|
-
// billing run still going at the next tick must not double-start.
|
|
61
63
|
overlap: z.enum(["skip", "allow"]).default("skip"),
|
|
62
64
|
catchUp: z.enum(["run", "skip", "latest"]).default("run"),
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
// `
|
|
66
|
-
// repeats of one another, so under 'skip' the oldest runs and the rest
|
|
67
|
-
// are recorded as overlap skips.
|
|
65
|
+
// Read by `catchUp: 'skip'` only. What `catchUp` opens still passes
|
|
66
|
+
// `overlap`: occurrences missed together are repeats of one another, so
|
|
67
|
+
// under `overlap: 'skip'` the oldest runs and the rest are skipped.
|
|
68
68
|
lateMs: z.number().int().positive().default(36e5),
|
|
69
69
|
order: z.enum(["any", "serial"]).default("any")
|
|
70
70
|
}).strict();
|
|
@@ -72,19 +72,15 @@ var DEFAULT_POLICY = PolicySchema.parse({});
|
|
|
72
72
|
var FactKindSchema = z.enum(["write", "signal", "manual", "run"]);
|
|
73
73
|
var FactInputSchema = z.object({
|
|
74
74
|
kind: FactKindSchema,
|
|
75
|
-
// write facts
|
|
76
75
|
entity: z.string().optional().describe("Which table or entity was written."),
|
|
77
76
|
op: OpSchema.optional().describe('Ops are distinct stimuli \u2014 "only on create" is op: "insert".'),
|
|
78
77
|
row: z.record(z.string(), z.unknown()).optional().describe("The row, as the write returned it."),
|
|
79
|
-
// signal facts
|
|
80
78
|
name: z.string().optional().describe("Which named intake this arrived on."),
|
|
81
79
|
payload: z.unknown().optional().describe("The event body \u2014 validated at the HOST boundary before it gets here."),
|
|
82
|
-
// run facts (minted by tide when a run settles — the fan-in mechanism)
|
|
83
80
|
reflex: z.string().optional(),
|
|
84
81
|
runId: z.string().optional(),
|
|
85
82
|
occurrence: z.string().optional().describe("The calendar key, when the clock was the cause."),
|
|
86
83
|
stats: z.object({ total: z.number().int(), done: z.number().int(), failed: z.number().int() }).strict().optional(),
|
|
87
|
-
// manual facts (minted by `fire`)
|
|
88
84
|
target: z.string().optional().describe("The one reflex a manual fact is aimed at."),
|
|
89
85
|
by: z.string().optional().describe("Who fired it \u2014 recorded on the firing as manual:<who>."),
|
|
90
86
|
at: z.number().int().describe("Supplied by the caller. Tide reads no clocks."),
|
|
@@ -171,7 +167,7 @@ var DRAFT_TRIGGERS = {
|
|
|
171
167
|
};
|
|
172
168
|
var ALL_DRAFT_TRIGGERS = ["clock", "timer", "write", "signal", "run", "manual"];
|
|
173
169
|
var draftCore = {
|
|
174
|
-
id: z.string().min(1).describe(
|
|
170
|
+
id: z.string().min(1).describe('A short name you make up from the request, like "call-mum". Never ask the person for it.'),
|
|
175
171
|
intent: reflexFields.intent,
|
|
176
172
|
effect: EffectRefSchema
|
|
177
173
|
};
|
|
@@ -195,5 +191,5 @@ var draftSchemaOf = (choice = {}) => {
|
|
|
195
191
|
var ReflexDraftSchema = draftSchemaOf();
|
|
196
192
|
|
|
197
193
|
export { ClockOnceSchema, ClockRecurringSchema, ClockTriggerSchema, ClockUnitSchema, DRAFT_TRIGGERS, EffectRefSchema, FactInputSchema, FactKindSchema, ManualTriggerSchema, OpSchema, PolicySchema, ReflexDraftSchema, ReflexSchema, RetrySchema, RunTriggerSchema, SelectionSchema, SignalTriggerSchema, TimerSchema, TimerTriggerSchema, TriggerSchema, WEEKDAYS, WriteTriggerSchema, clockOf, draftSchemaOf, factOf, isManual, isRecurring };
|
|
198
|
-
//# sourceMappingURL=chunk-
|
|
199
|
-
//# sourceMappingURL=chunk-
|
|
194
|
+
//# sourceMappingURL=chunk-ZEEJLISU.js.map
|
|
195
|
+
//# sourceMappingURL=chunk-ZEEJLISU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schemas/trigger.schema.ts","../src/schemas/policy.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DATETIME = /^\\d{4}-\\d{2}-\\d{2}T([01]\\d|2[0-3]):[0-5]\\d(:[0-5]\\d)?$/;\n\nexport const ClockUnitSchema = z.enum(['day', 'week', 'month', 'year']);\n\nexport const ClockRecurringSchema = z\n .object({\n every: ClockUnitSchema.describe('The calendar period it repeats on. A repeating clock fires on every such period until the reflex is removed — only for a request that says it repeats.'),\n on: z\n .union([z.number().int().min(1).max(31), z.enum(WEEKDAYS), z.array(z.enum(WEEKDAYS)).min(1), z.string().regex(MMDD)])\n .optional()\n .describe(\n 'week → a weekday, or a list of them: [\"mon\",\"tue\",\"wed\",\"thu\",\"fri\"] is every weekday; month → 1..31, where 31 is the last day of every month (a shorter month clamps to its end); year → \"MM-DD\". Omitted for day.',\n ),\n at: z.string().regex(HHMM).describe('Local wall-clock time, \"HH:MM\".'),\n tz: z.string().describe('IANA timezone name.'),\n })\n .strict()\n .superRefine((clock, ctx) => {\n const fail = (message: string) => ctx.addIssue({ code: 'custom', message, path: ['on'] });\n if (clock.every === 'day' && clock.on !== undefined) fail('a daily clock takes no `on`');\n const weekday = (value: unknown): boolean => typeof value === 'string' && WEEKDAYS.some((d) => d === value);\n const weekdays = Array.isArray(clock.on) && clock.on.length > 0 && new Set(clock.on).size === clock.on.length;\n if (clock.every === 'week' && !weekday(clock.on) && !weekdays) fail('a weekly clock needs `on` as a weekday (mon..sun), or a list of different weekdays');\n if (clock.every !== 'week' && Array.isArray(clock.on)) fail('only a weekly clock takes a list of weekdays');\n if (clock.every === 'month' && typeof clock.on !== 'number') fail('a monthly clock needs `on` as a day number');\n if (clock.every === 'year' && !(typeof clock.on === 'string' && MMDD.test(clock.on)))\n fail('a yearly clock needs `on` as \"MM-DD\"');\n })\n .describe('Repeats: fires on every day, week, month or year, at a time of day, until the reflex is removed.');\n\nexport const ClockOnceSchema = z\n .object({\n at: z.string().regex(LOCAL_DATETIME).describe('A fixed local date and time, once: \"YYYY-MM-DDTHH:MM\" or, to the second, \"YYYY-MM-DDTHH:MM:SS\".'),\n tz: z.string().describe('IANA timezone name.'),\n })\n .strict()\n .describe('Once: fires at one date and time, then never again.');\n\nexport const ClockTriggerSchema = z\n .object({ clock: z.union([ClockRecurringSchema, ClockOnceSchema]) })\n .strict()\n .describe('Fires on the calendar: once, at a date and time, or repeating at a time of day.');\n\nexport const OpSchema = z.enum(['insert', 'update', 'delete']);\n\nexport const WriteTriggerSchema = z\n .object({\n fact: z\n .object({\n entity: z.string().describe('The table or entity whose writes wake this reflex.'),\n op: OpSchema.optional().describe('Narrow to one op — \"only on create\" is op: \"insert\".'),\n })\n .strict(),\n })\n .strict()\n .describe('Fires when a row of an entity is written — created, changed or deleted.');\n\nexport const SignalTriggerSchema = z\n .object({ fact: z.object({ signal: z.string().describe('A named external intake.') }).strict() })\n .strict()\n .describe('Fires when an event arrives from outside, on a named intake.');\n\nexport const RunTriggerSchema = z\n .object({\n fact: z\n .object({ run: z.string().describe('A reflex id — fires when THAT reflex\\'s run settles. Fan-in and dependency.') })\n .strict(),\n })\n .strict()\n .describe('Fires when another reflex has run: one automation after another.');\n\nexport const ManualTriggerSchema = z\n .object({ manual: z.object({}).strict() })\n .strict()\n .describe('Fires only when somebody fires it by hand.');\n\nexport const TriggerSchema = z.union([\n ClockTriggerSchema,\n WriteTriggerSchema,\n SignalTriggerSchema,\n RunTriggerSchema,\n ManualTriggerSchema,\n]);\n\nexport type ClockRecurring = z.infer<typeof ClockRecurringSchema>;\nexport type ClockOnce = z.infer<typeof ClockOnceSchema>;\nexport type Clock = ClockRecurring | ClockOnce;\nexport type Trigger = z.infer<typeof TriggerSchema>;\nexport type Op = z.infer<typeof OpSchema>;\nexport type Weekday = (typeof WEEKDAYS)[number];\n\nexport const clockOf = (trigger: Trigger): Clock | undefined => ('clock' in trigger ? trigger.clock : undefined);\n\nexport const isRecurring = (clock: Clock): clock is ClockRecurring => 'every' in clock;\n\nexport const factOf = (\n trigger: Trigger,\n): { entity?: string; op?: Op; signal?: string; run?: string } | undefined =>\n 'fact' in trigger ? trigger.fact : undefined;\n\nexport const isManual = (trigger: Trigger): boolean => 'manual' in trigger;\n","import { z } from 'zod';\n\nexport const RetrySchema = z\n .object({\n max: z.number().int().min(0).default(3).describe('Attempts after the first before the task parks `failed`.'),\n backoff: z.enum(['fixed', 'exponential']).default('exponential'),\n baseMs: z.number().int().positive().default(60_000),\n })\n .strict();\n\nexport const PolicySchema = z\n .object({\n retry: RetrySchema.optional(),\n timeoutMs: z.number().int().positive().default(30_000),\n overlap: z.enum(['skip', 'allow']).default('skip'),\n catchUp: z.enum(['run', 'skip', 'latest']).default('run'),\n // Read by `catchUp: 'skip'` only. What `catchUp` opens still passes\n // `overlap`: occurrences missed together are repeats of one another, so\n // under `overlap: 'skip'` the oldest runs and the rest are skipped.\n lateMs: z.number().int().positive().default(3_600_000),\n order: z.enum(['any', 'serial']).default('any'),\n })\n .strict();\n\nexport type Retry = z.infer<typeof RetrySchema>;\nexport type Policy = z.infer<typeof PolicySchema>;\n\nexport const DEFAULT_POLICY: Policy = PolicySchema.parse({});\n","import { z } from 'zod';\nimport { OpSchema } from './trigger.schema';\n\nexport const FactKindSchema = z.enum(['write', 'signal', 'manual', 'run']);\n\nexport const FactInputSchema = z\n .object({\n kind: FactKindSchema,\n\n entity: z.string().optional().describe('Which table or entity was written.'),\n op: OpSchema.optional().describe('Ops are distinct stimuli — \"only on create\" is op: \"insert\".'),\n row: z.record(z.string(), z.unknown()).optional().describe('The row, as the write returned it.'),\n\n name: z.string().optional().describe('Which named intake this arrived on.'),\n payload: z.unknown().optional().describe('The event body — validated at the HOST boundary before it gets here.'),\n\n reflex: z.string().optional(),\n runId: z.string().optional(),\n occurrence: z.string().optional().describe('The calendar key, when the clock was the cause.'),\n stats: z\n .object({ total: z.number().int(), done: z.number().int(), failed: z.number().int() })\n .strict()\n .optional(),\n\n target: z.string().optional().describe('The one reflex a manual fact is aimed at.'),\n by: z.string().optional().describe('Who fired it — recorded on the firing as manual:<who>.'),\n\n at: z.number().int().describe('Supplied by the caller. Tide reads no clocks.'),\n notBefore: z.number().int().optional().describe('A delayed fact — timers as data, visible and queryable.'),\n dedupeKey: z.string().optional().describe('Provider event ids. A repeat is refused and announced as fact.deduped; it is not an error.'),\n cause: z.string().optional().describe('Set by tide when an effect emits — the causality chain.'),\n })\n .strict()\n .superRefine((fact, ctx) => {\n const require = (field: keyof typeof fact, why: string) => {\n if (fact[field] === undefined)\n ctx.addIssue({ code: 'custom', message: `a ${fact.kind} fact needs \\`${String(field)}\\` — ${why}`, path: [field] });\n };\n const refuse = (field: keyof typeof fact) => {\n if (fact[field] !== undefined)\n ctx.addIssue({ code: 'custom', message: `\\`${String(field)}\\` is not part of a ${fact.kind} fact`, path: [field] });\n };\n\n if (fact.kind === 'write') {\n require('entity', 'it is what a write trigger matches on');\n refuse('name');\n refuse('target');\n refuse('runId');\n }\n if (fact.kind === 'signal') {\n require('name', 'it is which named intake this arrived on');\n refuse('entity');\n refuse('op');\n refuse('target');\n refuse('runId');\n }\n if (fact.kind === 'manual') {\n require('target', 'a manual fact is aimed at exactly one reflex');\n refuse('entity');\n refuse('name');\n refuse('runId');\n }\n if (fact.kind === 'run') {\n require('reflex', 'it is whose run settled');\n require('runId', 'it is which run settled');\n refuse('entity');\n refuse('name');\n refuse('target');\n }\n });\n\nexport type FactInput = z.infer<typeof FactInputSchema>;\nexport type FactKind = z.infer<typeof FactKindSchema>;\n","import { z } from 'zod';\nimport { ClockTriggerSchema, ManualTriggerSchema, RunTriggerSchema, SignalTriggerSchema, TriggerSchema, WriteTriggerSchema } from './trigger.schema';\nimport { DEFAULT_POLICY, PolicySchema } from './policy.schema';\n\nexport const SelectionSchema = z\n .object({\n query: z.unknown().describe('Handed to the `select` seam verbatim. Under moss: a vex { fingerprint, context } replay.'),\n mode: z\n .enum(['each', 'batch'])\n .default('each')\n .describe('each → one task per row; batch → one task carrying all rows (bounded sets only).'),\n unitKey: z.string().optional().describe('The row field keying a unit task. `each` mode only; duplicates fail the firing.'),\n })\n .strict();\n\nexport const EffectRefSchema = z\n .object({\n name: z.string().describe('A registered effect. The reflex names it; the registry supplies the handler.'),\n input: z.unknown().optional().describe('A template, evaluated per unit by the `transform` seam.'),\n })\n .strict();\n\nconst reflexFields = {\n id: z.string().min(1).describe(\"Unique. A tenant's reflex is the tenant's own row, with its own id.\"),\n intent: z.string().min(1).describe(\"One factual sentence — what this does, in the person's language.\"),\n on: TriggerSchema,\n as: z.string().optional().describe('The identity this runs under. Opaque to tide; the host resolves it.'),\n params: z.record(z.string(), z.unknown()).optional().describe('Authored knobs, visible to templates as $.params.'),\n select: SelectionSchema.optional().describe('Omitted = the trigger itself is the unit.'),\n when: z.unknown().optional().describe('A predicate template. FACT triggers only — a query belongs in `select`.'),\n effect: EffectRefSchema,\n policy: PolicySchema.default(DEFAULT_POLICY),\n enabled: z.boolean().default(true).describe('A switch on the row, not part of the definition — flipping it is not an edit.'),\n};\n\nconst reflexRules = (reflex: { on: object; when?: unknown; select?: { mode: string; unitKey?: string | undefined } | undefined }, ctx: z.RefinementCtx): void => {\n if (reflex.when !== undefined && !('fact' in reflex.on))\n ctx.addIssue({ code: 'custom', message: '`when` is for fact triggers; a clock condition belongs in `select`', path: ['when'] });\n if (reflex.select?.mode === 'each' && reflex.select.unitKey === undefined)\n ctx.addIssue({ code: 'custom', message: \"`each` mode needs a unitKey — it is the task's idempotency grain\", path: ['select', 'unitKey'] });\n};\n\nexport const ReflexSchema = z.object(reflexFields).strict().superRefine(reflexRules);\n\nexport const TimerSchema = z\n .object({\n hours: z.number().int().min(0).optional(),\n minutes: z.number().int().min(0).optional(),\n seconds: z.number().int().min(0).optional(),\n })\n .strict()\n .refine((timer) => (timer.hours ?? 0) + (timer.minutes ?? 0) + (timer.seconds ?? 0) > 0, { message: 'a timer needs a length' });\n\nexport const TimerTriggerSchema = z\n .object({ timer: TimerSchema.describe('A length of time from now, as hours, minutes and seconds (each optional, together more than zero). Fires once, that long after the reflex is saved — not after it is written. A clock is for a time of day or a date.') })\n .strict();\n\nexport const DRAFT_TRIGGERS = {\n clock: ClockTriggerSchema,\n timer: TimerTriggerSchema,\n write: WriteTriggerSchema,\n signal: SignalTriggerSchema,\n run: RunTriggerSchema,\n manual: ManualTriggerSchema,\n} as const;\nexport type DraftTrigger = keyof typeof DRAFT_TRIGGERS;\nconst ALL_DRAFT_TRIGGERS: readonly DraftTrigger[] = ['clock', 'timer', 'write', 'signal', 'run', 'manual'];\n\nexport type DraftField = 'params' | 'select' | 'when';\n\nexport type DraftChoice = { triggers?: readonly DraftTrigger[]; fields?: readonly DraftField[] };\n\nconst draftCore = {\n id: z.string().min(1).describe('A short name you make up from the request, like \"call-mum\". Never ask the person for it.'),\n intent: reflexFields.intent,\n effect: EffectRefSchema,\n};\n\nconst WidestDraftSchema = z\n .object({ ...draftCore, on: z.union([TriggerSchema, TimerTriggerSchema]), params: reflexFields.params, select: reflexFields.select, when: reflexFields.when })\n .strict();\nexport type ReflexDraft = z.infer<typeof WidestDraftSchema>;\n\nexport const draftSchemaOf = (choice: DraftChoice = {}): z.ZodType<ReflexDraft> => {\n const [first, ...rest] = (choice.triggers ?? ALL_DRAFT_TRIGGERS).map((kind): z.ZodType<ReflexDraft['on']> => DRAFT_TRIGGERS[kind]);\n if (first === undefined) throw new Error('tide: a draft needs at least one trigger kind');\n const on: z.ZodType<ReflexDraft['on']> = rest.length === 0 ? first : z.union([first, ...rest]);\n const has = (field: DraftField): boolean => choice.fields?.includes(field) ?? false;\n const keep: { [key in keyof ReflexDraft]?: true } = {\n id: true,\n intent: true,\n effect: true,\n on: true,\n ...(has('params') ? { params: true as const } : {}),\n ...(has('select') ? { select: true as const } : {}),\n ...(has('when') ? { when: true as const } : {}),\n };\n return WidestDraftSchema.pick(keep).extend({ on }).strict().superRefine(reflexRules);\n};\n\nexport const ReflexDraftSchema = draftSchemaOf();\n\nexport type Selection = z.infer<typeof SelectionSchema>;\nexport type EffectRef = z.infer<typeof EffectRefSchema>;\nexport type Reflex = z.infer<typeof ReflexSchema>;\nexport type ReflexInput = z.input<typeof ReflexSchema>;\nexport type Timer = z.infer<typeof TimerSchema>;\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -10,14 +10,18 @@ var LOCAL_DATETIME = /^\d{4}-\d{2}-\d{2}T([01]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$/;
|
|
|
10
10
|
var ClockUnitSchema = zod.z.enum(["day", "week", "month", "year"]);
|
|
11
11
|
var ClockRecurringSchema = zod.z.object({
|
|
12
12
|
every: ClockUnitSchema.describe("The calendar period it repeats on. A repeating clock fires on every such period until the reflex is removed \u2014 only for a request that says it repeats."),
|
|
13
|
-
on: zod.z.union([zod.z.number().int().min(1).max(31), zod.z.enum(WEEKDAYS), zod.z.string().regex(MMDD)]).optional().describe(
|
|
13
|
+
on: zod.z.union([zod.z.number().int().min(1).max(31), zod.z.enum(WEEKDAYS), zod.z.array(zod.z.enum(WEEKDAYS)).min(1), zod.z.string().regex(MMDD)]).optional().describe(
|
|
14
|
+
'week \u2192 a weekday, or a list of them: ["mon","tue","wed","thu","fri"] is every weekday; month \u2192 1..31, where 31 is the last day of every month (a shorter month clamps to its end); year \u2192 "MM-DD". Omitted for day.'
|
|
15
|
+
),
|
|
14
16
|
at: zod.z.string().regex(HHMM).describe('Local wall-clock time, "HH:MM".'),
|
|
15
17
|
tz: zod.z.string().describe("IANA timezone name.")
|
|
16
18
|
}).strict().superRefine((clock, ctx) => {
|
|
17
19
|
const fail = (message) => ctx.addIssue({ code: "custom", message, path: ["on"] });
|
|
18
20
|
if (clock.every === "day" && clock.on !== void 0) fail("a daily clock takes no `on`");
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
const weekday = (value) => typeof value === "string" && WEEKDAYS.some((d) => d === value);
|
|
22
|
+
const weekdays = Array.isArray(clock.on) && clock.on.length > 0 && new Set(clock.on).size === clock.on.length;
|
|
23
|
+
if (clock.every === "week" && !weekday(clock.on) && !weekdays) fail("a weekly clock needs `on` as a weekday (mon..sun), or a list of different weekdays");
|
|
24
|
+
if (clock.every !== "week" && Array.isArray(clock.on)) fail("only a weekly clock takes a list of weekdays");
|
|
21
25
|
if (clock.every === "month" && typeof clock.on !== "number") fail("a monthly clock needs `on` as a day number");
|
|
22
26
|
if (clock.every === "year" && !(typeof clock.on === "string" && MMDD.test(clock.on)))
|
|
23
27
|
fail('a yearly clock needs `on` as "MM-DD"');
|
|
@@ -58,15 +62,11 @@ var RetrySchema = zod.z.object({
|
|
|
58
62
|
var PolicySchema = zod.z.object({
|
|
59
63
|
retry: RetrySchema.optional(),
|
|
60
64
|
timeoutMs: zod.z.number().int().positive().default(3e4),
|
|
61
|
-
// May a firing start while the previous one is unsettled? The long
|
|
62
|
-
// billing run still going at the next tick must not double-start.
|
|
63
65
|
overlap: zod.z.enum(["skip", "allow"]).default("skip"),
|
|
64
66
|
catchUp: zod.z.enum(["run", "skip", "latest"]).default("run"),
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
// `
|
|
68
|
-
// repeats of one another, so under 'skip' the oldest runs and the rest
|
|
69
|
-
// are recorded as overlap skips.
|
|
67
|
+
// Read by `catchUp: 'skip'` only. What `catchUp` opens still passes
|
|
68
|
+
// `overlap`: occurrences missed together are repeats of one another, so
|
|
69
|
+
// under `overlap: 'skip'` the oldest runs and the rest are skipped.
|
|
70
70
|
lateMs: zod.z.number().int().positive().default(36e5),
|
|
71
71
|
order: zod.z.enum(["any", "serial"]).default("any")
|
|
72
72
|
}).strict();
|
|
@@ -74,19 +74,15 @@ var DEFAULT_POLICY = PolicySchema.parse({});
|
|
|
74
74
|
var FactKindSchema = zod.z.enum(["write", "signal", "manual", "run"]);
|
|
75
75
|
var FactInputSchema = zod.z.object({
|
|
76
76
|
kind: FactKindSchema,
|
|
77
|
-
// write facts
|
|
78
77
|
entity: zod.z.string().optional().describe("Which table or entity was written."),
|
|
79
78
|
op: OpSchema.optional().describe('Ops are distinct stimuli \u2014 "only on create" is op: "insert".'),
|
|
80
79
|
row: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe("The row, as the write returned it."),
|
|
81
|
-
// signal facts
|
|
82
80
|
name: zod.z.string().optional().describe("Which named intake this arrived on."),
|
|
83
81
|
payload: zod.z.unknown().optional().describe("The event body \u2014 validated at the HOST boundary before it gets here."),
|
|
84
|
-
// run facts (minted by tide when a run settles — the fan-in mechanism)
|
|
85
82
|
reflex: zod.z.string().optional(),
|
|
86
83
|
runId: zod.z.string().optional(),
|
|
87
84
|
occurrence: zod.z.string().optional().describe("The calendar key, when the clock was the cause."),
|
|
88
85
|
stats: zod.z.object({ total: zod.z.number().int(), done: zod.z.number().int(), failed: zod.z.number().int() }).strict().optional(),
|
|
89
|
-
// manual facts (minted by `fire`)
|
|
90
86
|
target: zod.z.string().optional().describe("The one reflex a manual fact is aimed at."),
|
|
91
87
|
by: zod.z.string().optional().describe("Who fired it \u2014 recorded on the firing as manual:<who>."),
|
|
92
88
|
at: zod.z.number().int().describe("Supplied by the caller. Tide reads no clocks."),
|
|
@@ -173,7 +169,7 @@ var DRAFT_TRIGGERS = {
|
|
|
173
169
|
};
|
|
174
170
|
var ALL_DRAFT_TRIGGERS = ["clock", "timer", "write", "signal", "run", "manual"];
|
|
175
171
|
var draftCore = {
|
|
176
|
-
id: zod.z.string().min(1).describe(
|
|
172
|
+
id: zod.z.string().min(1).describe('A short name you make up from the request, like "call-mum". Never ask the person for it.'),
|
|
177
173
|
intent: reflexFields.intent,
|
|
178
174
|
effect: EffectRefSchema
|
|
179
175
|
};
|
|
@@ -419,7 +415,7 @@ var ordinalOf = (day) => day.year * 1e4 + day.month * 100 + day.day;
|
|
|
419
415
|
var pad2 = (value) => String(value).padStart(2, "0");
|
|
420
416
|
var isDueOn = (clock, day) => {
|
|
421
417
|
if (clock.every === "day") return true;
|
|
422
|
-
if (clock.every === "week") return weekdayOf(day) === clock.on;
|
|
418
|
+
if (clock.every === "week") return Array.isArray(clock.on) ? clock.on.some((one) => one === weekdayOf(day)) : weekdayOf(day) === clock.on;
|
|
423
419
|
if (clock.every === "month")
|
|
424
420
|
return typeof clock.on === "number" && day.day === Math.min(clock.on, daysInMonth(day.year, day.month));
|
|
425
421
|
if (typeof clock.on !== "string") return false;
|
|
@@ -471,8 +467,6 @@ var openRun = async (deps, loaded, input) => {
|
|
|
471
467
|
const base = {
|
|
472
468
|
reflexId: reflex.id,
|
|
473
469
|
version,
|
|
474
|
-
// Written down so the ledger is scopeable by an ordinary host rule
|
|
475
|
-
// rather than by parsing reflex ids. Opaque to tide.
|
|
476
470
|
as: reflex.as,
|
|
477
471
|
cause: input.cause,
|
|
478
472
|
occurrence: input.occurrence,
|
|
@@ -495,8 +489,6 @@ var openRun = async (deps, loaded, input) => {
|
|
|
495
489
|
...base,
|
|
496
490
|
state: "skipped",
|
|
497
491
|
settledAt: input.now,
|
|
498
|
-
// Nothing waits on it and nothing announces it: a run that never
|
|
499
|
-
// started has no settlement to report.
|
|
500
492
|
drained: true,
|
|
501
493
|
note: `overlap: the previous run (${unsettled.id}) is still unsettled`
|
|
502
494
|
});
|
|
@@ -576,8 +568,6 @@ var matchFacts = async (deps, now, limit) => {
|
|
|
576
568
|
now,
|
|
577
569
|
occurrence: fact.occurrence,
|
|
578
570
|
factIds: [fact.id],
|
|
579
|
-
// A write, a signal or another reflex's settlement happened once and
|
|
580
|
-
// will not happen again; a human pressing the button twice will.
|
|
581
571
|
repeat: fact.kind === "manual"
|
|
582
572
|
});
|
|
583
573
|
if (run !== void 0) report.runsCreated += 1;
|
|
@@ -713,8 +703,6 @@ var commitFanout = async (deps, run, tasks, selected, now) => deps.store.transac
|
|
|
713
703
|
{
|
|
714
704
|
selected,
|
|
715
705
|
total: written,
|
|
716
|
-
// A zero-task run settles immediately and still announces itself —
|
|
717
|
-
// "nothing was due" is an answer a digest may legitimately want.
|
|
718
706
|
state: settledNow ? "settled" : "fanned",
|
|
719
707
|
settledAt: settledNow ? now : void 0
|
|
720
708
|
}
|
|
@@ -725,12 +713,9 @@ var taskOf = (unit, run, loaded, now) => ({
|
|
|
725
713
|
runId: run.id,
|
|
726
714
|
reflexId: loaded.reflex.id,
|
|
727
715
|
unit: unit.unit,
|
|
728
|
-
// UNIQUE(runId, unit) — the idempotency grain, written BEFORE the effect
|
|
729
|
-
// runs. There is no path to the effect that skips this row.
|
|
730
716
|
cause: run.cause,
|
|
731
717
|
env: unit.env,
|
|
732
|
-
// Carried
|
|
733
|
-
// ceiling for work that is still in flight.
|
|
718
|
+
// Carried on the task: a swept run must not reset the chain ceiling.
|
|
734
719
|
depth: run.depth,
|
|
735
720
|
state: "pending",
|
|
736
721
|
attempt: 0,
|
|
@@ -817,22 +802,13 @@ var claimTasks = async (deps, now, limit, token) => {
|
|
|
817
802
|
where: {
|
|
818
803
|
state: { in: ["pending", "retrying", "claimed"] },
|
|
819
804
|
notBefore: { lte: now },
|
|
820
|
-
// Either it was never claimed, or the claim has lapsed. Expressed as
|
|
821
|
-
// one predicate because a second query would be a second decision.
|
|
822
805
|
claimedUntil: { lte: now }
|
|
823
806
|
},
|
|
824
|
-
// `unit`
|
|
825
|
-
//
|
|
826
|
-
// order was whatever the storage engine felt like — insertion order in a
|
|
827
|
-
// Map, heap order in Postgres. Two stores answering differently is the
|
|
828
|
-
// thing the contract exists to prevent, and a headless check asserting on
|
|
829
|
-
// the order effects ran in deserves the same answer everywhere.
|
|
807
|
+
// `unit` breaks ties: one fan-out's tasks share `notBefore` and `createdAt`,
|
|
808
|
+
// and two stores must order them the same way.
|
|
830
809
|
order: [{ by: "notBefore" }, { by: "createdAt" }, { by: "unit" }],
|
|
831
810
|
limit,
|
|
832
811
|
set: { state: "claimed", token, claimedUntil: now + deps.leaseMs, attempt: { inc: 1 } },
|
|
833
|
-
// `order: 'serial'` — at most one live claim per reflex, counting what
|
|
834
|
-
// another claim already holds. Inside the claim, because a caller that
|
|
835
|
-
// looks first and claims second loses the race to its own second tick.
|
|
836
812
|
onePer: serialReflexIds.length === 0 ? void 0 : { column: "reflexId", held: { state: "claimed", claimedUntil: { gt: now } }, only: serialReflexIds }
|
|
837
813
|
});
|
|
838
814
|
};
|
|
@@ -868,21 +844,8 @@ var executeTasks = async (deps, now, limit) => {
|
|
|
868
844
|
depth: task.depth,
|
|
869
845
|
now,
|
|
870
846
|
actor: deps.actorFor(reflex.as),
|
|
871
|
-
//
|
|
872
|
-
//
|
|
873
|
-
// `emit` used to accept anything: a handler could emit `kind: 'manual'`
|
|
874
|
-
// and fire a DISARMED reflex, because manual facts are checked before
|
|
875
|
-
// enablement on purpose — arming gates triggers, not people. A handler
|
|
876
|
-
// is not a person. `run` is tide's own bookkeeping and is minted by the
|
|
877
|
-
// settler, so it is refused for the same reason.
|
|
878
|
-
//
|
|
879
|
-
// A malformed emit THROWS, inside the handler, so the attempt fails
|
|
880
|
-
// visibly. The alternative is a fact that stores, matches nothing and
|
|
881
|
-
// vanishes — a chain that silently stops one hop in.
|
|
882
|
-
//
|
|
883
|
-
// Depth is stamped from the task below — the handler never sets it,
|
|
884
|
-
// because a handler that could choose its own depth could escape the
|
|
885
|
-
// chain ceiling.
|
|
847
|
+
// `write` and `signal` only: a `manual` fact fires a disabled reflex, and
|
|
848
|
+
// `run` facts are minted by the settler alone.
|
|
886
849
|
emit: (fact) => {
|
|
887
850
|
if (fact.kind !== "write" && fact.kind !== "signal")
|
|
888
851
|
throw new TideError("invalid_fact", `${reflex.id}: an effect may emit \`write\` or \`signal\` facts, not \`${fact.kind}\``);
|
|
@@ -924,8 +887,7 @@ var executeTasks = async (deps, now, limit) => {
|
|
|
924
887
|
notBefore: next.state === "retrying" ? next.notBefore : task.notBefore,
|
|
925
888
|
output,
|
|
926
889
|
error,
|
|
927
|
-
// A
|
|
928
|
-
// emit-then-throw handler would double-mint facts and fire the chain twice.
|
|
890
|
+
// A failed attempt's emits are dropped: its retry would mint them again.
|
|
929
891
|
emits: outcome === "ok" ? emits : [],
|
|
930
892
|
at: now
|
|
931
893
|
});
|
|
@@ -1012,8 +974,6 @@ var settleRuns = async (deps, now) => {
|
|
|
1012
974
|
at: now,
|
|
1013
975
|
depth: run.depth + 1,
|
|
1014
976
|
cause: `run:${run.id}`,
|
|
1015
|
-
// A settlement is news about THIS reflex's work — counts of rows it
|
|
1016
|
-
// selected. Another tenant's digest has no business waking on it.
|
|
1017
977
|
as: run.as
|
|
1018
978
|
}, deps.maxChainFacts);
|
|
1019
979
|
announceFact(deps.emit, admission);
|
|
@@ -1257,8 +1217,6 @@ var createTide = (config) => {
|
|
|
1257
1217
|
if (!loaded.has(reflexId)) throw new TideError("unknown_reflex", `no reflex "${reflexId}" is loaded`);
|
|
1258
1218
|
return ingest(
|
|
1259
1219
|
{ kind: "manual", target: reflexId, payload: options.input, by: options.by ?? "operator", at: options.now },
|
|
1260
|
-
// Carried so the ledger reads consistently. Matching a manual fact does
|
|
1261
|
-
// not depend on it — `target` names one reflex, which is narrower.
|
|
1262
1220
|
{ as: loaded.get(reflexId)?.reflex.as }
|
|
1263
1221
|
);
|
|
1264
1222
|
};
|
|
@@ -1318,19 +1276,14 @@ var createTide = (config) => {
|
|
|
1318
1276
|
},
|
|
1319
1277
|
fact: (id) => one("fact", id),
|
|
1320
1278
|
causeChain,
|
|
1321
|
-
//
|
|
1322
|
-
//
|
|
1323
|
-
// parked it has not changed and never will.
|
|
1279
|
+
// `released` as well: with `parked` alone cleared, the depth check would
|
|
1280
|
+
// park the fact again on the next advance.
|
|
1324
1281
|
releaseParked: async (factId) => {
|
|
1325
1282
|
const fact = await one("fact", factId);
|
|
1326
1283
|
if (fact?.parked === void 0) return false;
|
|
1327
1284
|
return config.store.cas("fact", factId, {}, { parked: void 0, released: true });
|
|
1328
1285
|
}
|
|
1329
1286
|
},
|
|
1330
|
-
// RETENTION, and the one place the ledger shrinks. Runs cascade to their
|
|
1331
|
-
// tasks in the store: a run and its members are one fact about the world,
|
|
1332
|
-
// and keeping half destroys the UNIQUE(runId, unit) row that IS the "this
|
|
1333
|
-
// unit already ran" record.
|
|
1334
1287
|
sweep: async (now, retention) => {
|
|
1335
1288
|
let removed = 0;
|
|
1336
1289
|
if (retention.facts !== void 0)
|
|
@@ -1352,8 +1305,7 @@ var PRIMARY_KEY = {
|
|
|
1352
1305
|
state: "reflexId"
|
|
1353
1306
|
};
|
|
1354
1307
|
var UNIQUE_BY = {
|
|
1355
|
-
// `entity` is
|
|
1356
|
-
// that happened to agree on a cursor value silently ate each other's rows.
|
|
1308
|
+
// `entity` is in the key: two polls over different tables can agree on a cursor value.
|
|
1357
1309
|
fact: { by: ["kind", "entity", "name", "dedupeKey"], when: "dedupeKey" },
|
|
1358
1310
|
run: { by: ["reflexId", "cause"] },
|
|
1359
1311
|
task: { by: ["runId", "unit"] },
|