@niscorp/tide 0.1.7 → 0.1.9
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 +27 -0
- package/DESIGN.md +5 -3
- package/DOCS.md +28 -6
- package/README.md +6 -2
- package/dist/agent.cjs +84 -9
- 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 +78 -6
- package/dist/agent.js.map +1 -1
- package/dist/{chunk-4TXWZFRE.js → chunk-ZEEJLISU.js} +10 -6
- package/dist/chunk-ZEEJLISU.js.map +1 -0
- package/dist/index.cjs +9 -5
- 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 +3 -3
- 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 +11 -3
- package/dist/postgres.cjs.map +1 -1
- package/dist/postgres.js +5 -1
- 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/package.json +11 -1
- package/dist/chunk-4TXWZFRE.js.map +0 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
|
|
5
|
+
// src/schemas/trigger.schema.ts
|
|
6
|
+
var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
7
|
+
var HHMM = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
8
|
+
var MMDD = /^(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
|
|
9
|
+
var LOCAL_DATETIME = /^\d{4}-\d{2}-\d{2}T([01]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$/;
|
|
10
|
+
var ClockUnitSchema = zod.z.enum(["day", "week", "month", "year"]);
|
|
11
|
+
var ClockRecurringSchema = zod.z.object({
|
|
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.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
|
+
),
|
|
16
|
+
at: zod.z.string().regex(HHMM).describe('Local wall-clock time, "HH:MM".'),
|
|
17
|
+
tz: zod.z.string().describe("IANA timezone name.")
|
|
18
|
+
}).strict().superRefine((clock, ctx) => {
|
|
19
|
+
const fail = (message) => ctx.addIssue({ code: "custom", message, path: ["on"] });
|
|
20
|
+
if (clock.every === "day" && clock.on !== void 0) fail("a daily clock takes no `on`");
|
|
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");
|
|
25
|
+
if (clock.every === "month" && typeof clock.on !== "number") fail("a monthly clock needs `on` as a day number");
|
|
26
|
+
if (clock.every === "year" && !(typeof clock.on === "string" && MMDD.test(clock.on)))
|
|
27
|
+
fail('a yearly clock needs `on` as "MM-DD"');
|
|
28
|
+
}).describe("Repeats: fires on every day, week, month or year, at a time of day, until the reflex is removed.");
|
|
29
|
+
var ClockOnceSchema = zod.z.object({
|
|
30
|
+
at: zod.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".'),
|
|
31
|
+
tz: zod.z.string().describe("IANA timezone name.")
|
|
32
|
+
}).strict().describe("Once: fires at one date and time, then never again.");
|
|
33
|
+
var ClockTriggerSchema = zod.z.object({ clock: zod.z.union([ClockRecurringSchema, ClockOnceSchema]) }).strict().describe("Fires on the calendar: once, at a date and time, or repeating at a time of day.");
|
|
34
|
+
var OpSchema = zod.z.enum(["insert", "update", "delete"]);
|
|
35
|
+
var WriteTriggerSchema = zod.z.object({
|
|
36
|
+
fact: zod.z.object({
|
|
37
|
+
entity: zod.z.string().describe("The table or entity whose writes wake this reflex."),
|
|
38
|
+
op: OpSchema.optional().describe('Narrow to one op \u2014 "only on create" is op: "insert".')
|
|
39
|
+
}).strict()
|
|
40
|
+
}).strict().describe("Fires when a row of an entity is written \u2014 created, changed or deleted.");
|
|
41
|
+
var SignalTriggerSchema = zod.z.object({ fact: zod.z.object({ signal: zod.z.string().describe("A named external intake.") }).strict() }).strict().describe("Fires when an event arrives from outside, on a named intake.");
|
|
42
|
+
var RunTriggerSchema = zod.z.object({
|
|
43
|
+
fact: zod.z.object({ run: zod.z.string().describe("A reflex id \u2014 fires when THAT reflex's run settles. Fan-in and dependency.") }).strict()
|
|
44
|
+
}).strict().describe("Fires when another reflex has run: one automation after another.");
|
|
45
|
+
var ManualTriggerSchema = zod.z.object({ manual: zod.z.object({}).strict() }).strict().describe("Fires only when somebody fires it by hand.");
|
|
46
|
+
var TriggerSchema = zod.z.union([
|
|
47
|
+
ClockTriggerSchema,
|
|
48
|
+
WriteTriggerSchema,
|
|
49
|
+
SignalTriggerSchema,
|
|
50
|
+
RunTriggerSchema,
|
|
51
|
+
ManualTriggerSchema
|
|
52
|
+
]);
|
|
53
|
+
var RetrySchema = zod.z.object({
|
|
54
|
+
max: zod.z.number().int().min(0).default(3).describe("Attempts after the first before the task parks `failed`."),
|
|
55
|
+
backoff: zod.z.enum(["fixed", "exponential"]).default("exponential"),
|
|
56
|
+
baseMs: zod.z.number().int().positive().default(6e4)
|
|
57
|
+
}).strict();
|
|
58
|
+
var PolicySchema = zod.z.object({
|
|
59
|
+
retry: RetrySchema.optional(),
|
|
60
|
+
timeoutMs: zod.z.number().int().positive().default(3e4),
|
|
61
|
+
overlap: zod.z.enum(["skip", "allow"]).default("skip"),
|
|
62
|
+
catchUp: zod.z.enum(["run", "skip", "latest"]).default("run"),
|
|
63
|
+
// Read by `catchUp: 'skip'` only. What `catchUp` opens still passes
|
|
64
|
+
// `overlap`: occurrences missed together are repeats of one another, so
|
|
65
|
+
// under `overlap: 'skip'` the oldest runs and the rest are skipped.
|
|
66
|
+
lateMs: zod.z.number().int().positive().default(36e5),
|
|
67
|
+
order: zod.z.enum(["any", "serial"]).default("any")
|
|
68
|
+
}).strict();
|
|
69
|
+
var DEFAULT_POLICY = PolicySchema.parse({});
|
|
70
|
+
var SelectionSchema = zod.z.object({
|
|
71
|
+
query: zod.z.unknown().describe("Handed to the `select` seam verbatim. Under moss: a vex { fingerprint, context } replay."),
|
|
72
|
+
mode: zod.z.enum(["each", "batch"]).default("each").describe("each \u2192 one task per row; batch \u2192 one task carrying all rows (bounded sets only)."),
|
|
73
|
+
unitKey: zod.z.string().optional().describe("The row field keying a unit task. `each` mode only; duplicates fail the firing.")
|
|
74
|
+
}).strict();
|
|
75
|
+
var EffectRefSchema = zod.z.object({
|
|
76
|
+
name: zod.z.string().describe("A registered effect. The reflex names it; the registry supplies the handler."),
|
|
77
|
+
input: zod.z.unknown().optional().describe("A template, evaluated per unit by the `transform` seam.")
|
|
78
|
+
}).strict();
|
|
79
|
+
var reflexFields = {
|
|
80
|
+
id: zod.z.string().min(1).describe("Unique. A tenant's reflex is the tenant's own row, with its own id."),
|
|
81
|
+
intent: zod.z.string().min(1).describe("One factual sentence \u2014 what this does, in the person's language."),
|
|
82
|
+
on: TriggerSchema,
|
|
83
|
+
as: zod.z.string().optional().describe("The identity this runs under. Opaque to tide; the host resolves it."),
|
|
84
|
+
params: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe("Authored knobs, visible to templates as $.params."),
|
|
85
|
+
select: SelectionSchema.optional().describe("Omitted = the trigger itself is the unit."),
|
|
86
|
+
when: zod.z.unknown().optional().describe("A predicate template. FACT triggers only \u2014 a query belongs in `select`."),
|
|
87
|
+
effect: EffectRefSchema,
|
|
88
|
+
policy: PolicySchema.default(DEFAULT_POLICY),
|
|
89
|
+
enabled: zod.z.boolean().default(true).describe("A switch on the row, not part of the definition \u2014 flipping it is not an edit.")
|
|
90
|
+
};
|
|
91
|
+
var reflexRules = (reflex, ctx) => {
|
|
92
|
+
if (reflex.when !== void 0 && !("fact" in reflex.on))
|
|
93
|
+
ctx.addIssue({ code: "custom", message: "`when` is for fact triggers; a clock condition belongs in `select`", path: ["when"] });
|
|
94
|
+
if (reflex.select?.mode === "each" && reflex.select.unitKey === void 0)
|
|
95
|
+
ctx.addIssue({ code: "custom", message: "`each` mode needs a unitKey \u2014 it is the task's idempotency grain", path: ["select", "unitKey"] });
|
|
96
|
+
};
|
|
97
|
+
var ReflexSchema = zod.z.object(reflexFields).strict().superRefine(reflexRules);
|
|
98
|
+
var TimerSchema = zod.z.object({
|
|
99
|
+
hours: zod.z.number().int().min(0).optional(),
|
|
100
|
+
minutes: zod.z.number().int().min(0).optional(),
|
|
101
|
+
seconds: zod.z.number().int().min(0).optional()
|
|
102
|
+
}).strict().refine((timer) => (timer.hours ?? 0) + (timer.minutes ?? 0) + (timer.seconds ?? 0) > 0, { message: "a timer needs a length" });
|
|
103
|
+
var TimerTriggerSchema = zod.z.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 \u2014 not after it is written. A clock is for a time of day or a date.") }).strict();
|
|
104
|
+
var DRAFT_TRIGGERS = {
|
|
105
|
+
clock: ClockTriggerSchema,
|
|
106
|
+
timer: TimerTriggerSchema,
|
|
107
|
+
write: WriteTriggerSchema,
|
|
108
|
+
signal: SignalTriggerSchema,
|
|
109
|
+
run: RunTriggerSchema,
|
|
110
|
+
manual: ManualTriggerSchema
|
|
111
|
+
};
|
|
112
|
+
var ALL_DRAFT_TRIGGERS = ["clock", "timer", "write", "signal", "run", "manual"];
|
|
113
|
+
var draftCore = {
|
|
114
|
+
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.'),
|
|
115
|
+
intent: reflexFields.intent,
|
|
116
|
+
effect: EffectRefSchema
|
|
117
|
+
};
|
|
118
|
+
var WidestDraftSchema = zod.z.object({ ...draftCore, on: zod.z.union([TriggerSchema, TimerTriggerSchema]), params: reflexFields.params, select: reflexFields.select, when: reflexFields.when }).strict();
|
|
119
|
+
var draftSchemaOf = (choice = {}) => {
|
|
120
|
+
const [first, ...rest] = (choice.triggers ?? ALL_DRAFT_TRIGGERS).map((kind) => DRAFT_TRIGGERS[kind]);
|
|
121
|
+
if (first === void 0) throw new Error("tide: a draft needs at least one trigger kind");
|
|
122
|
+
const on = rest.length === 0 ? first : zod.z.union([first, ...rest]);
|
|
123
|
+
const has = (field) => choice.fields?.includes(field) ?? false;
|
|
124
|
+
const keep = {
|
|
125
|
+
id: true,
|
|
126
|
+
intent: true,
|
|
127
|
+
effect: true,
|
|
128
|
+
on: true,
|
|
129
|
+
...has("params") ? { params: true } : {},
|
|
130
|
+
...has("select") ? { select: true } : {},
|
|
131
|
+
...has("when") ? { when: true } : {}
|
|
132
|
+
};
|
|
133
|
+
return WidestDraftSchema.pick(keep).extend({ on }).strict().superRefine(reflexRules);
|
|
134
|
+
};
|
|
135
|
+
var ReflexDraftSchema = draftSchemaOf();
|
|
136
|
+
|
|
137
|
+
// src/migrations/index.ts
|
|
138
|
+
var TIDE_GRAMMAR = {
|
|
139
|
+
id: "nisc.tide",
|
|
140
|
+
documents: { reflex: {}, draft: {} },
|
|
141
|
+
migrations: [
|
|
142
|
+
{
|
|
143
|
+
description: "A weekly clock may name several weekdays: `on` takes a list of them",
|
|
144
|
+
steps: []
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
};
|
|
148
|
+
var TIDE_SCHEMAS = {
|
|
149
|
+
"nisc.tide/reflex": ReflexSchema,
|
|
150
|
+
"nisc.tide/draft": ReflexDraftSchema
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
exports.TIDE_GRAMMAR = TIDE_GRAMMAR;
|
|
154
|
+
exports.TIDE_SCHEMAS = TIDE_SCHEMAS;
|
|
155
|
+
//# sourceMappingURL=index.cjs.map
|
|
156
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/schemas/trigger.schema.ts","../../src/schemas/policy.schema.ts","../../src/schemas/reflex.schema.ts","../../src/migrations/index.ts"],"names":["z"],"mappings":";;;;;AAEO,IAAM,QAAA,GAAW,CAAC,KAAA,EAAO,KAAA,EAAO,OAAO,KAAA,EAAO,KAAA,EAAO,OAAO,KAAK,CAAA;AAExE,IAAM,IAAA,GAAO,2BAAA;AACb,IAAM,IAAA,GAAO,yCAAA;AACb,IAAM,cAAA,GAAiB,wDAAA;AAEhB,IAAM,eAAA,GAAkBA,MAAE,IAAA,CAAK,CAAC,OAAO,MAAA,EAAQ,OAAA,EAAS,MAAM,CAAC,CAAA;AAE/D,IAAM,oBAAA,GAAuBA,MACjC,MAAA,CAAO;AAAA,EACN,KAAA,EAAO,eAAA,CAAgB,QAAA,CAAS,6JAAwJ,CAAA;AAAA,EACxL,IAAIA,KAAA,CACD,KAAA,CAAM,CAACA,KAAA,CAAE,QAAO,CAAE,GAAA,EAAI,CAAE,GAAA,CAAI,CAAC,CAAA,CAAE,GAAA,CAAI,EAAE,CAAA,EAA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IAAK,KAAA;AAC9E,EAAA,MAAM,IAAA,GAA8C;AAAA,IAClD,EAAA,EAAI,IAAA;AAAA,IACJ,MAAA,EAAQ,IAAA;AAAA,IACR,MAAA,EAAQ,IAAA;AAAA,IACR,EAAA,EAAI,IAAA;AAAA,IACJ,GAAI,IAAI,QAAQ,CAAA,GAAI,EAAE,MAAA,EAAQ,IAAA,KAAkB,EAAC;AAAA,IACjD,GAAI,IAAI,QAAQ,CAAA,GAAI,EAAE,MAAA,EAAQ,IAAA,KAAkB,EAAC;AAAA,IACjD,GAAI,IAAI,MAAM,CAAA,GAAI,EAAE,IAAA,EAAM,IAAA,KAAkB;AAAC,GAC/C;AACA,EAAA,OAAO,iBAAA,CAAkB,IAAA,CAAK,IAAI,CAAA,CAAE,MAAA,CAAO,EAAE,EAAA,EAAI,CAAA,CAAE,MAAA,EAAO,CAAE,WAAA,CAAY,WAAW,CAAA;AACrF,CAAA;AAEO,IAAM,oBAAoB,aAAA,EAAc;;;AC/FxC,IAAM,YAAA,GAAyB;AAAA,EACpC,EAAA,EAAI,WAAA;AAAA,EACJ,WAAW,EAAE,MAAA,EAAQ,EAAC,EAAG,KAAA,EAAO,EAAC,EAAE;AAAA,EACnC,UAAA,EAAY;AAAA,IACV;AAAA,MACE,WAAA,EAAa,qEAAA;AAAA,MACb,OAAO;AAAC;AACV;AAEJ;AAEO,IAAM,YAAA,GAAe;AAAA,EAC1B,kBAAA,EAAoB,YAAA;AAAA,EACpB,iBAAA,EAAmB;AACrB","file":"index.cjs","sourcesContent":["import { z } from 'zod';\n\nexport const WEEKDAYS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'] as const;\n\nconst HHMM = /^([01]\\d|2[0-3]):[0-5]\\d$/;\nconst MMDD = /^(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$/;\nconst LOCAL_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 { 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","import type { Sequence } from '@niscorp/strata';\nimport { ReflexDraftSchema, ReflexSchema } from '../schemas';\n\n// A host keeps a reflex or a draft with the grammar it was written at, and upgrades it where it reads it. An addition\n// rewrites no stored document, but a reader at an older version refuses one that uses it.\nexport const TIDE_GRAMMAR: Sequence = {\n id: 'nisc.tide',\n documents: { reflex: {}, draft: {} },\n migrations: [\n {\n description: 'A weekly clock may name several weekdays: `on` takes a list of them',\n steps: [],\n },\n ],\n};\n\nexport const TIDE_SCHEMAS = {\n 'nisc.tide/reflex': ReflexSchema,\n 'nisc.tide/draft': ReflexDraftSchema,\n} as const;\n"]}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import * as zod_v4_core from 'zod/v4/core';
|
|
2
|
+
import * as zod from 'zod';
|
|
3
|
+
import { Sequence } from '@niscorp/strata';
|
|
4
|
+
|
|
5
|
+
declare const TIDE_GRAMMAR: Sequence;
|
|
6
|
+
declare const TIDE_SCHEMAS: {
|
|
7
|
+
readonly 'nisc.tide/reflex': zod.ZodObject<{
|
|
8
|
+
id: zod.ZodString;
|
|
9
|
+
intent: zod.ZodString;
|
|
10
|
+
on: zod.ZodUnion<readonly [zod.ZodObject<{
|
|
11
|
+
clock: zod.ZodUnion<readonly [zod.ZodObject<{
|
|
12
|
+
every: zod.ZodEnum<{
|
|
13
|
+
day: "day";
|
|
14
|
+
week: "week";
|
|
15
|
+
month: "month";
|
|
16
|
+
year: "year";
|
|
17
|
+
}>;
|
|
18
|
+
on: zod.ZodOptional<zod.ZodUnion<readonly [zod.ZodNumber, zod.ZodEnum<{
|
|
19
|
+
mon: "mon";
|
|
20
|
+
tue: "tue";
|
|
21
|
+
wed: "wed";
|
|
22
|
+
thu: "thu";
|
|
23
|
+
fri: "fri";
|
|
24
|
+
sat: "sat";
|
|
25
|
+
sun: "sun";
|
|
26
|
+
}>, zod.ZodArray<zod.ZodEnum<{
|
|
27
|
+
mon: "mon";
|
|
28
|
+
tue: "tue";
|
|
29
|
+
wed: "wed";
|
|
30
|
+
thu: "thu";
|
|
31
|
+
fri: "fri";
|
|
32
|
+
sat: "sat";
|
|
33
|
+
sun: "sun";
|
|
34
|
+
}>>, zod.ZodString]>>;
|
|
35
|
+
at: zod.ZodString;
|
|
36
|
+
tz: zod.ZodString;
|
|
37
|
+
}, zod_v4_core.$strict>, zod.ZodObject<{
|
|
38
|
+
at: zod.ZodString;
|
|
39
|
+
tz: zod.ZodString;
|
|
40
|
+
}, zod_v4_core.$strict>]>;
|
|
41
|
+
}, zod_v4_core.$strict>, zod.ZodObject<{
|
|
42
|
+
fact: zod.ZodObject<{
|
|
43
|
+
entity: zod.ZodString;
|
|
44
|
+
op: zod.ZodOptional<zod.ZodEnum<{
|
|
45
|
+
insert: "insert";
|
|
46
|
+
update: "update";
|
|
47
|
+
delete: "delete";
|
|
48
|
+
}>>;
|
|
49
|
+
}, zod_v4_core.$strict>;
|
|
50
|
+
}, zod_v4_core.$strict>, zod.ZodObject<{
|
|
51
|
+
fact: zod.ZodObject<{
|
|
52
|
+
signal: zod.ZodString;
|
|
53
|
+
}, zod_v4_core.$strict>;
|
|
54
|
+
}, zod_v4_core.$strict>, zod.ZodObject<{
|
|
55
|
+
fact: zod.ZodObject<{
|
|
56
|
+
run: zod.ZodString;
|
|
57
|
+
}, zod_v4_core.$strict>;
|
|
58
|
+
}, zod_v4_core.$strict>, zod.ZodObject<{
|
|
59
|
+
manual: zod.ZodObject<{}, zod_v4_core.$strict>;
|
|
60
|
+
}, zod_v4_core.$strict>]>;
|
|
61
|
+
as: zod.ZodOptional<zod.ZodString>;
|
|
62
|
+
params: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodUnknown>>;
|
|
63
|
+
select: zod.ZodOptional<zod.ZodObject<{
|
|
64
|
+
query: zod.ZodUnknown;
|
|
65
|
+
mode: zod.ZodDefault<zod.ZodEnum<{
|
|
66
|
+
each: "each";
|
|
67
|
+
batch: "batch";
|
|
68
|
+
}>>;
|
|
69
|
+
unitKey: zod.ZodOptional<zod.ZodString>;
|
|
70
|
+
}, zod_v4_core.$strict>>;
|
|
71
|
+
when: zod.ZodOptional<zod.ZodUnknown>;
|
|
72
|
+
effect: zod.ZodObject<{
|
|
73
|
+
name: zod.ZodString;
|
|
74
|
+
input: zod.ZodOptional<zod.ZodUnknown>;
|
|
75
|
+
}, zod_v4_core.$strict>;
|
|
76
|
+
policy: zod.ZodDefault<zod.ZodObject<{
|
|
77
|
+
retry: zod.ZodOptional<zod.ZodObject<{
|
|
78
|
+
max: zod.ZodDefault<zod.ZodNumber>;
|
|
79
|
+
backoff: zod.ZodDefault<zod.ZodEnum<{
|
|
80
|
+
fixed: "fixed";
|
|
81
|
+
exponential: "exponential";
|
|
82
|
+
}>>;
|
|
83
|
+
baseMs: zod.ZodDefault<zod.ZodNumber>;
|
|
84
|
+
}, zod_v4_core.$strict>>;
|
|
85
|
+
timeoutMs: zod.ZodDefault<zod.ZodNumber>;
|
|
86
|
+
overlap: zod.ZodDefault<zod.ZodEnum<{
|
|
87
|
+
skip: "skip";
|
|
88
|
+
allow: "allow";
|
|
89
|
+
}>>;
|
|
90
|
+
catchUp: zod.ZodDefault<zod.ZodEnum<{
|
|
91
|
+
run: "run";
|
|
92
|
+
skip: "skip";
|
|
93
|
+
latest: "latest";
|
|
94
|
+
}>>;
|
|
95
|
+
lateMs: zod.ZodDefault<zod.ZodNumber>;
|
|
96
|
+
order: zod.ZodDefault<zod.ZodEnum<{
|
|
97
|
+
any: "any";
|
|
98
|
+
serial: "serial";
|
|
99
|
+
}>>;
|
|
100
|
+
}, zod_v4_core.$strict>>;
|
|
101
|
+
enabled: zod.ZodDefault<zod.ZodBoolean>;
|
|
102
|
+
}, zod_v4_core.$strict>;
|
|
103
|
+
readonly 'nisc.tide/draft': zod.ZodType<{
|
|
104
|
+
on: {
|
|
105
|
+
clock: {
|
|
106
|
+
every: "day" | "week" | "month" | "year";
|
|
107
|
+
at: string;
|
|
108
|
+
tz: string;
|
|
109
|
+
on?: string | number | ("mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun")[] | undefined;
|
|
110
|
+
} | {
|
|
111
|
+
at: string;
|
|
112
|
+
tz: string;
|
|
113
|
+
};
|
|
114
|
+
} | {
|
|
115
|
+
fact: {
|
|
116
|
+
entity: string;
|
|
117
|
+
op?: "insert" | "update" | "delete" | undefined;
|
|
118
|
+
};
|
|
119
|
+
} | {
|
|
120
|
+
fact: {
|
|
121
|
+
signal: string;
|
|
122
|
+
};
|
|
123
|
+
} | {
|
|
124
|
+
fact: {
|
|
125
|
+
run: string;
|
|
126
|
+
};
|
|
127
|
+
} | {
|
|
128
|
+
manual: Record<string, never>;
|
|
129
|
+
} | {
|
|
130
|
+
timer: {
|
|
131
|
+
hours?: number | undefined;
|
|
132
|
+
minutes?: number | undefined;
|
|
133
|
+
seconds?: number | undefined;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
id: string;
|
|
137
|
+
intent: string;
|
|
138
|
+
effect: {
|
|
139
|
+
name: string;
|
|
140
|
+
input?: unknown;
|
|
141
|
+
};
|
|
142
|
+
params?: Record<string, unknown> | undefined;
|
|
143
|
+
select?: {
|
|
144
|
+
query: unknown;
|
|
145
|
+
mode: "each" | "batch";
|
|
146
|
+
unitKey?: string | undefined;
|
|
147
|
+
} | undefined;
|
|
148
|
+
when?: unknown;
|
|
149
|
+
}, unknown, zod_v4_core.$ZodTypeInternals<{
|
|
150
|
+
on: {
|
|
151
|
+
clock: {
|
|
152
|
+
every: "day" | "week" | "month" | "year";
|
|
153
|
+
at: string;
|
|
154
|
+
tz: string;
|
|
155
|
+
on?: string | number | ("mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun")[] | undefined;
|
|
156
|
+
} | {
|
|
157
|
+
at: string;
|
|
158
|
+
tz: string;
|
|
159
|
+
};
|
|
160
|
+
} | {
|
|
161
|
+
fact: {
|
|
162
|
+
entity: string;
|
|
163
|
+
op?: "insert" | "update" | "delete" | undefined;
|
|
164
|
+
};
|
|
165
|
+
} | {
|
|
166
|
+
fact: {
|
|
167
|
+
signal: string;
|
|
168
|
+
};
|
|
169
|
+
} | {
|
|
170
|
+
fact: {
|
|
171
|
+
run: string;
|
|
172
|
+
};
|
|
173
|
+
} | {
|
|
174
|
+
manual: Record<string, never>;
|
|
175
|
+
} | {
|
|
176
|
+
timer: {
|
|
177
|
+
hours?: number | undefined;
|
|
178
|
+
minutes?: number | undefined;
|
|
179
|
+
seconds?: number | undefined;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
id: string;
|
|
183
|
+
intent: string;
|
|
184
|
+
effect: {
|
|
185
|
+
name: string;
|
|
186
|
+
input?: unknown;
|
|
187
|
+
};
|
|
188
|
+
params?: Record<string, unknown> | undefined;
|
|
189
|
+
select?: {
|
|
190
|
+
query: unknown;
|
|
191
|
+
mode: "each" | "batch";
|
|
192
|
+
unitKey?: string | undefined;
|
|
193
|
+
} | undefined;
|
|
194
|
+
when?: unknown;
|
|
195
|
+
}, unknown>>;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export { TIDE_GRAMMAR, TIDE_SCHEMAS };
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import * as zod_v4_core from 'zod/v4/core';
|
|
2
|
+
import * as zod from 'zod';
|
|
3
|
+
import { Sequence } from '@niscorp/strata';
|
|
4
|
+
|
|
5
|
+
declare const TIDE_GRAMMAR: Sequence;
|
|
6
|
+
declare const TIDE_SCHEMAS: {
|
|
7
|
+
readonly 'nisc.tide/reflex': zod.ZodObject<{
|
|
8
|
+
id: zod.ZodString;
|
|
9
|
+
intent: zod.ZodString;
|
|
10
|
+
on: zod.ZodUnion<readonly [zod.ZodObject<{
|
|
11
|
+
clock: zod.ZodUnion<readonly [zod.ZodObject<{
|
|
12
|
+
every: zod.ZodEnum<{
|
|
13
|
+
day: "day";
|
|
14
|
+
week: "week";
|
|
15
|
+
month: "month";
|
|
16
|
+
year: "year";
|
|
17
|
+
}>;
|
|
18
|
+
on: zod.ZodOptional<zod.ZodUnion<readonly [zod.ZodNumber, zod.ZodEnum<{
|
|
19
|
+
mon: "mon";
|
|
20
|
+
tue: "tue";
|
|
21
|
+
wed: "wed";
|
|
22
|
+
thu: "thu";
|
|
23
|
+
fri: "fri";
|
|
24
|
+
sat: "sat";
|
|
25
|
+
sun: "sun";
|
|
26
|
+
}>, zod.ZodArray<zod.ZodEnum<{
|
|
27
|
+
mon: "mon";
|
|
28
|
+
tue: "tue";
|
|
29
|
+
wed: "wed";
|
|
30
|
+
thu: "thu";
|
|
31
|
+
fri: "fri";
|
|
32
|
+
sat: "sat";
|
|
33
|
+
sun: "sun";
|
|
34
|
+
}>>, zod.ZodString]>>;
|
|
35
|
+
at: zod.ZodString;
|
|
36
|
+
tz: zod.ZodString;
|
|
37
|
+
}, zod_v4_core.$strict>, zod.ZodObject<{
|
|
38
|
+
at: zod.ZodString;
|
|
39
|
+
tz: zod.ZodString;
|
|
40
|
+
}, zod_v4_core.$strict>]>;
|
|
41
|
+
}, zod_v4_core.$strict>, zod.ZodObject<{
|
|
42
|
+
fact: zod.ZodObject<{
|
|
43
|
+
entity: zod.ZodString;
|
|
44
|
+
op: zod.ZodOptional<zod.ZodEnum<{
|
|
45
|
+
insert: "insert";
|
|
46
|
+
update: "update";
|
|
47
|
+
delete: "delete";
|
|
48
|
+
}>>;
|
|
49
|
+
}, zod_v4_core.$strict>;
|
|
50
|
+
}, zod_v4_core.$strict>, zod.ZodObject<{
|
|
51
|
+
fact: zod.ZodObject<{
|
|
52
|
+
signal: zod.ZodString;
|
|
53
|
+
}, zod_v4_core.$strict>;
|
|
54
|
+
}, zod_v4_core.$strict>, zod.ZodObject<{
|
|
55
|
+
fact: zod.ZodObject<{
|
|
56
|
+
run: zod.ZodString;
|
|
57
|
+
}, zod_v4_core.$strict>;
|
|
58
|
+
}, zod_v4_core.$strict>, zod.ZodObject<{
|
|
59
|
+
manual: zod.ZodObject<{}, zod_v4_core.$strict>;
|
|
60
|
+
}, zod_v4_core.$strict>]>;
|
|
61
|
+
as: zod.ZodOptional<zod.ZodString>;
|
|
62
|
+
params: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodUnknown>>;
|
|
63
|
+
select: zod.ZodOptional<zod.ZodObject<{
|
|
64
|
+
query: zod.ZodUnknown;
|
|
65
|
+
mode: zod.ZodDefault<zod.ZodEnum<{
|
|
66
|
+
each: "each";
|
|
67
|
+
batch: "batch";
|
|
68
|
+
}>>;
|
|
69
|
+
unitKey: zod.ZodOptional<zod.ZodString>;
|
|
70
|
+
}, zod_v4_core.$strict>>;
|
|
71
|
+
when: zod.ZodOptional<zod.ZodUnknown>;
|
|
72
|
+
effect: zod.ZodObject<{
|
|
73
|
+
name: zod.ZodString;
|
|
74
|
+
input: zod.ZodOptional<zod.ZodUnknown>;
|
|
75
|
+
}, zod_v4_core.$strict>;
|
|
76
|
+
policy: zod.ZodDefault<zod.ZodObject<{
|
|
77
|
+
retry: zod.ZodOptional<zod.ZodObject<{
|
|
78
|
+
max: zod.ZodDefault<zod.ZodNumber>;
|
|
79
|
+
backoff: zod.ZodDefault<zod.ZodEnum<{
|
|
80
|
+
fixed: "fixed";
|
|
81
|
+
exponential: "exponential";
|
|
82
|
+
}>>;
|
|
83
|
+
baseMs: zod.ZodDefault<zod.ZodNumber>;
|
|
84
|
+
}, zod_v4_core.$strict>>;
|
|
85
|
+
timeoutMs: zod.ZodDefault<zod.ZodNumber>;
|
|
86
|
+
overlap: zod.ZodDefault<zod.ZodEnum<{
|
|
87
|
+
skip: "skip";
|
|
88
|
+
allow: "allow";
|
|
89
|
+
}>>;
|
|
90
|
+
catchUp: zod.ZodDefault<zod.ZodEnum<{
|
|
91
|
+
run: "run";
|
|
92
|
+
skip: "skip";
|
|
93
|
+
latest: "latest";
|
|
94
|
+
}>>;
|
|
95
|
+
lateMs: zod.ZodDefault<zod.ZodNumber>;
|
|
96
|
+
order: zod.ZodDefault<zod.ZodEnum<{
|
|
97
|
+
any: "any";
|
|
98
|
+
serial: "serial";
|
|
99
|
+
}>>;
|
|
100
|
+
}, zod_v4_core.$strict>>;
|
|
101
|
+
enabled: zod.ZodDefault<zod.ZodBoolean>;
|
|
102
|
+
}, zod_v4_core.$strict>;
|
|
103
|
+
readonly 'nisc.tide/draft': zod.ZodType<{
|
|
104
|
+
on: {
|
|
105
|
+
clock: {
|
|
106
|
+
every: "day" | "week" | "month" | "year";
|
|
107
|
+
at: string;
|
|
108
|
+
tz: string;
|
|
109
|
+
on?: string | number | ("mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun")[] | undefined;
|
|
110
|
+
} | {
|
|
111
|
+
at: string;
|
|
112
|
+
tz: string;
|
|
113
|
+
};
|
|
114
|
+
} | {
|
|
115
|
+
fact: {
|
|
116
|
+
entity: string;
|
|
117
|
+
op?: "insert" | "update" | "delete" | undefined;
|
|
118
|
+
};
|
|
119
|
+
} | {
|
|
120
|
+
fact: {
|
|
121
|
+
signal: string;
|
|
122
|
+
};
|
|
123
|
+
} | {
|
|
124
|
+
fact: {
|
|
125
|
+
run: string;
|
|
126
|
+
};
|
|
127
|
+
} | {
|
|
128
|
+
manual: Record<string, never>;
|
|
129
|
+
} | {
|
|
130
|
+
timer: {
|
|
131
|
+
hours?: number | undefined;
|
|
132
|
+
minutes?: number | undefined;
|
|
133
|
+
seconds?: number | undefined;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
id: string;
|
|
137
|
+
intent: string;
|
|
138
|
+
effect: {
|
|
139
|
+
name: string;
|
|
140
|
+
input?: unknown;
|
|
141
|
+
};
|
|
142
|
+
params?: Record<string, unknown> | undefined;
|
|
143
|
+
select?: {
|
|
144
|
+
query: unknown;
|
|
145
|
+
mode: "each" | "batch";
|
|
146
|
+
unitKey?: string | undefined;
|
|
147
|
+
} | undefined;
|
|
148
|
+
when?: unknown;
|
|
149
|
+
}, unknown, zod_v4_core.$ZodTypeInternals<{
|
|
150
|
+
on: {
|
|
151
|
+
clock: {
|
|
152
|
+
every: "day" | "week" | "month" | "year";
|
|
153
|
+
at: string;
|
|
154
|
+
tz: string;
|
|
155
|
+
on?: string | number | ("mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun")[] | undefined;
|
|
156
|
+
} | {
|
|
157
|
+
at: string;
|
|
158
|
+
tz: string;
|
|
159
|
+
};
|
|
160
|
+
} | {
|
|
161
|
+
fact: {
|
|
162
|
+
entity: string;
|
|
163
|
+
op?: "insert" | "update" | "delete" | undefined;
|
|
164
|
+
};
|
|
165
|
+
} | {
|
|
166
|
+
fact: {
|
|
167
|
+
signal: string;
|
|
168
|
+
};
|
|
169
|
+
} | {
|
|
170
|
+
fact: {
|
|
171
|
+
run: string;
|
|
172
|
+
};
|
|
173
|
+
} | {
|
|
174
|
+
manual: Record<string, never>;
|
|
175
|
+
} | {
|
|
176
|
+
timer: {
|
|
177
|
+
hours?: number | undefined;
|
|
178
|
+
minutes?: number | undefined;
|
|
179
|
+
seconds?: number | undefined;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
id: string;
|
|
183
|
+
intent: string;
|
|
184
|
+
effect: {
|
|
185
|
+
name: string;
|
|
186
|
+
input?: unknown;
|
|
187
|
+
};
|
|
188
|
+
params?: Record<string, unknown> | undefined;
|
|
189
|
+
select?: {
|
|
190
|
+
query: unknown;
|
|
191
|
+
mode: "each" | "batch";
|
|
192
|
+
unitKey?: string | undefined;
|
|
193
|
+
} | undefined;
|
|
194
|
+
when?: unknown;
|
|
195
|
+
}, unknown>>;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export { TIDE_GRAMMAR, TIDE_SCHEMAS };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ReflexDraftSchema, ReflexSchema } from '../chunk-ZEEJLISU.js';
|
|
2
|
+
|
|
3
|
+
// src/migrations/index.ts
|
|
4
|
+
var TIDE_GRAMMAR = {
|
|
5
|
+
id: "nisc.tide",
|
|
6
|
+
documents: { reflex: {}, draft: {} },
|
|
7
|
+
migrations: [
|
|
8
|
+
{
|
|
9
|
+
description: "A weekly clock may name several weekdays: `on` takes a list of them",
|
|
10
|
+
steps: []
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
};
|
|
14
|
+
var TIDE_SCHEMAS = {
|
|
15
|
+
"nisc.tide/reflex": ReflexSchema,
|
|
16
|
+
"nisc.tide/draft": ReflexDraftSchema
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { TIDE_GRAMMAR, TIDE_SCHEMAS };
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/migrations/index.ts"],"names":[],"mappings":";;;AAKO,IAAM,YAAA,GAAyB;AAAA,EACpC,EAAA,EAAI,WAAA;AAAA,EACJ,WAAW,EAAE,MAAA,EAAQ,EAAC,EAAG,KAAA,EAAO,EAAC,EAAE;AAAA,EACnC,UAAA,EAAY;AAAA,IACV;AAAA,MACE,WAAA,EAAa,qEAAA;AAAA,MACb,OAAO;AAAC;AACV;AAEJ;AAEO,IAAM,YAAA,GAAe;AAAA,EAC1B,kBAAA,EAAoB,YAAA;AAAA,EACpB,iBAAA,EAAmB;AACrB","file":"index.js","sourcesContent":["import type { Sequence } from '@niscorp/strata';\nimport { ReflexDraftSchema, ReflexSchema } from '../schemas';\n\n// A host keeps a reflex or a draft with the grammar it was written at, and upgrades it where it reads it. An addition\n// rewrites no stored document, but a reader at an older version refuses one that uses it.\nexport const TIDE_GRAMMAR: Sequence = {\n id: 'nisc.tide',\n documents: { reflex: {}, draft: {} },\n migrations: [\n {\n description: 'A weekly clock may name several weekdays: `on` takes a list of them',\n steps: [],\n },\n ],\n};\n\nexport const TIDE_SCHEMAS = {\n 'nisc.tide/reflex': ReflexSchema,\n 'nisc.tide/draft': ReflexDraftSchema,\n} as const;\n"]}
|
package/dist/postgres.cjs
CHANGED
|
@@ -26,14 +26,18 @@ var LOCAL_DATETIME = /^\d{4}-\d{2}-\d{2}T([01]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$/;
|
|
|
26
26
|
var ClockUnitSchema = zod.z.enum(["day", "week", "month", "year"]);
|
|
27
27
|
var ClockRecurringSchema = zod.z.object({
|
|
28
28
|
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."),
|
|
29
|
-
on: zod.z.union([zod.z.number().int().min(1).max(31), zod.z.enum(WEEKDAYS), zod.z.string().regex(MMDD)]).optional().describe(
|
|
29
|
+
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(
|
|
30
|
+
'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.'
|
|
31
|
+
),
|
|
30
32
|
at: zod.z.string().regex(HHMM).describe('Local wall-clock time, "HH:MM".'),
|
|
31
33
|
tz: zod.z.string().describe("IANA timezone name.")
|
|
32
34
|
}).strict().superRefine((clock, ctx) => {
|
|
33
35
|
const fail = (message) => ctx.addIssue({ code: "custom", message, path: ["on"] });
|
|
34
36
|
if (clock.every === "day" && clock.on !== void 0) fail("a daily clock takes no `on`");
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
const weekday = (value) => typeof value === "string" && WEEKDAYS.some((d) => d === value);
|
|
38
|
+
const weekdays = Array.isArray(clock.on) && clock.on.length > 0 && new Set(clock.on).size === clock.on.length;
|
|
39
|
+
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");
|
|
40
|
+
if (clock.every !== "week" && Array.isArray(clock.on)) fail("only a weekly clock takes a list of weekdays");
|
|
37
41
|
if (clock.every === "month" && typeof clock.on !== "number") fail("a monthly clock needs `on` as a day number");
|
|
38
42
|
if (clock.every === "year" && !(typeof clock.on === "string" && MMDD.test(clock.on)))
|
|
39
43
|
fail('a yearly clock needs `on` as "MM-DD"');
|
|
@@ -505,6 +509,10 @@ var TIDE_SEQUENCE = {
|
|
|
505
509
|
{ kind: "sql", sql: "ALTER TABLE tide_fact ADD COLUMN IF NOT EXISTS root text" },
|
|
506
510
|
{ kind: "sql", sql: "ALTER TABLE tide_fact ADD COLUMN IF NOT EXISTS descendants integer" }
|
|
507
511
|
]
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
description: "A run is found by whose it was: a host scopes its reads of the ledger on as_who",
|
|
515
|
+
steps: [{ kind: "sql", sql: "CREATE INDEX IF NOT EXISTS tide_run_as_who ON tide_run (as_who)" }]
|
|
508
516
|
}
|
|
509
517
|
]
|
|
510
518
|
};
|