@lotics/app-sdk 0.101.0 → 0.101.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/dist/index.js +34 -12
- package/dist/written.d.ts +2 -0
- package/docs/mutations.md +2 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -27408,14 +27408,22 @@ var appWriteModelSchema = zod_default.object({
|
|
|
27408
27408
|
tables: zod_default.array(zod_default.object({ id: zod_default.string(), name: zod_default.string(), fields: tableFieldsSchema })).describe("The tables the plans and queries touch, with only the fields they name.")
|
|
27409
27409
|
});
|
|
27410
27410
|
var PREDICTION_MISSES_MAX = 50;
|
|
27411
|
-
var predictionMissSchema = zod_default.
|
|
27412
|
-
|
|
27413
|
-
|
|
27414
|
-
|
|
27415
|
-
|
|
27416
|
-
|
|
27417
|
-
|
|
27418
|
-
|
|
27411
|
+
var predictionMissSchema = zod_default.union([
|
|
27412
|
+
zod_default.object({
|
|
27413
|
+
kind: zod_default.enum(["cell", "not_removed"]).describe("A predicted value the stored one differs from, or a row predicted gone that the server still holds."),
|
|
27414
|
+
workflow: zod_default.string().max(200).describe("The alias of the workflow whose run was predicted."),
|
|
27415
|
+
table_id: zod_default.string().max(64),
|
|
27416
|
+
field_key: zod_default.string().max(64).nullable().describe("The field that missed; null for a whole row."),
|
|
27417
|
+
column: zod_default.enum(["own", "via", "row"]).describe("A field of the row itself, one read through its link, or the row."),
|
|
27418
|
+
count: zod_default.number().int().min(1).max(1e3)
|
|
27419
|
+
}).strict(),
|
|
27420
|
+
zod_default.object({
|
|
27421
|
+
kind: zod_default.enum(["model_unavailable", "predict_error"]).describe("The app's write model could not be read, or predicting a run threw: its writes wait for the server."),
|
|
27422
|
+
workflow: zod_default.string().max(200).nullable().describe("The workflow whose run was not predicted; null for the model."),
|
|
27423
|
+
error: zod_default.string().regex(/^[A-Za-z_$][\w$]{0,63}$/).describe("The error's class name alone (`TypeError`, `WorkflowEvalError`)."),
|
|
27424
|
+
count: zod_default.number().int().min(1).max(1e3)
|
|
27425
|
+
}).strict()
|
|
27426
|
+
]);
|
|
27419
27427
|
var predictionMissesBodySchema = zod_default.object({ misses: zod_default.array(predictionMissSchema).min(1).max(PREDICTION_MISSES_MAX) });
|
|
27420
27428
|
|
|
27421
27429
|
// src/new_record.ts
|
|
@@ -27526,6 +27534,7 @@ function loadModel() {
|
|
|
27526
27534
|
attempt2.catch((cause) => {
|
|
27527
27535
|
console.error("The app's write model could not be read; writes show once the server answers", cause);
|
|
27528
27536
|
if (modelPromise === attempt2) failedAtMs = Date.now();
|
|
27537
|
+
reportMisses([{ kind: "model_unavailable", workflow: null, error: errorName(cause), count: 1 }]);
|
|
27529
27538
|
});
|
|
27530
27539
|
modelPromise = attempt2;
|
|
27531
27540
|
}
|
|
@@ -27687,7 +27696,7 @@ async function stageWrite(workflow, inputs) {
|
|
|
27687
27696
|
});
|
|
27688
27697
|
} catch (cause) {
|
|
27689
27698
|
if (cause instanceof UnknownValue) return null;
|
|
27690
|
-
|
|
27699
|
+
unpredicted(workflow, cause);
|
|
27691
27700
|
return null;
|
|
27692
27701
|
}
|
|
27693
27702
|
if (prediction.outcome === "refused") return null;
|
|
@@ -27788,8 +27797,21 @@ function judgePredictions(shape, rows, askedAt) {
|
|
|
27788
27797
|
}
|
|
27789
27798
|
if (checked.size > 0) entries2 = entries2.map((entry) => checked.has(entry.token) ? { ...entry, checked: /* @__PURE__ */ new Set([...entry.checked, ...checked.get(entry.token) ?? []]) } : entry);
|
|
27790
27799
|
if (counts.size === 0) return;
|
|
27791
|
-
|
|
27792
|
-
|
|
27800
|
+
reportMisses([...counts.values()]);
|
|
27801
|
+
}
|
|
27802
|
+
function errorName(cause) {
|
|
27803
|
+
const name = cause instanceof Error ? cause.name : "";
|
|
27804
|
+
return /^[A-Za-z_$][\w$]{0,63}$/.test(name) ? name : "Error";
|
|
27805
|
+
}
|
|
27806
|
+
function unpredicted(workflow, cause) {
|
|
27807
|
+
console.error(`The write "${workflow}" could not be predicted; it shows once the server answers`, cause);
|
|
27808
|
+
reportMisses([{ kind: "predict_error", workflow, error: errorName(cause), count: 1 }]);
|
|
27809
|
+
}
|
|
27810
|
+
function reportMisses(misses) {
|
|
27811
|
+
if (misses.length === 0 || hasMockFlag()) return;
|
|
27812
|
+
rpc("prediction_miss", { misses: misses.slice(0, PREDICTION_MISSES_MAX) }).catch(
|
|
27813
|
+
(cause) => console.warn("Where the app's writes were drawn wrong or not at all could not be reported", cause)
|
|
27814
|
+
);
|
|
27793
27815
|
}
|
|
27794
27816
|
function readsAfter(workflow, token2) {
|
|
27795
27817
|
const described = loaded?.model.workflows[workflow];
|
|
@@ -27893,7 +27915,7 @@ async function runStaged(alias, inputs) {
|
|
|
27893
27915
|
}
|
|
27894
27916
|
const given = inputs ?? {};
|
|
27895
27917
|
const staged = await stageWrite(alias, given).catch((cause) => {
|
|
27896
|
-
|
|
27918
|
+
unpredicted(alias, cause);
|
|
27897
27919
|
return null;
|
|
27898
27920
|
});
|
|
27899
27921
|
const token2 = staged?.token ?? null;
|
package/dist/written.d.ts
CHANGED
|
@@ -44,6 +44,8 @@ export declare function writesRecords(workflow: string): boolean;
|
|
|
44
44
|
* different times, when its oldest was (`since`).
|
|
45
45
|
*/
|
|
46
46
|
export declare function noteAnswer(key: string, alias: string, askedAt: number, rows: readonly Row[], since?: number): void;
|
|
47
|
+
/** A run whose writes wait for the server because predicting it threw: said in the console, reported by class. */
|
|
48
|
+
export declare function unpredicted(workflow: string, cause: unknown): void;
|
|
47
49
|
/**
|
|
48
50
|
* The queries a successful run of `workflow` re-reads: those over a table its body names. Undefined — every
|
|
49
51
|
* mounted query — until the model is read, or where a write names a table only at run time.
|
package/docs/mutations.md
CHANGED
|
@@ -539,7 +539,8 @@ every read before the request answers:
|
|
|
539
539
|
asked after the write settled answers — the stored value then replaces the prediction, whatever
|
|
540
540
|
it said, so a server that rounds or trims wins with no flicker back to the old value. Where the
|
|
541
541
|
stored value differs from the one drawn, the SDK tells the server where — the workflow, table,
|
|
542
|
-
field and kind of miss, never the value.
|
|
542
|
+
field and kind of miss, never the value. A write model that cannot be read and a prediction that
|
|
543
|
+
throws are reported too, by the error's class name alone.
|
|
543
544
|
|
|
544
545
|
What the steps cannot tell before they run is never guessed:
|
|
545
546
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lotics/app-sdk",
|
|
3
|
-
"version": "0.101.
|
|
3
|
+
"version": "0.101.1",
|
|
4
4
|
"description": "The SDK a Lotics custom-code app reads and writes through \u2014 typed hooks over the host bridge, cell readers, mount() and AppRouter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|