@dinoxx/dinox-cli 3.3.0 → 3.5.0
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/chunks/{chunk-2S4U3MRS.js → chunk-D7QTW6N6.js} +1 -1
- package/dist/chunks/{chunk-BFSYRVWX.js → chunk-EPY4F7CC.js} +11 -11
- package/dist/chunks/{chunk-5KBJHX5A.js → chunk-K3VX75DA.js} +2 -2
- package/dist/chunks/{chunk-SWSIHKCM.js → chunk-QOKO7V6A.js} +2 -2
- package/dist/chunks/{chunk-PDJ3VQDJ.js → chunk-YERBRBQV.js} +2 -2
- package/dist/chunks/{chunk-3QWGIINW.js → chunk-ZPE53YBS.js} +987 -307
- package/dist/chunks/{ensure-QBWY7EPP.js → ensure-PW3HZZSJ.js} +3 -3
- package/dist/chunks/{execute-ZMADEDW2.js → execute-DSHVATUX.js} +2 -2
- package/dist/chunks/{mcp-YTZZHRYJ.js → mcp-OF7C72WL.js} +2 -2
- package/dist/chunks/{mcpServer-WQYHJHUK.js → mcpServer-WURTU2CQ.js} +7 -7
- package/dist/chunks/{run-DQDOKDZC.js → run-FUEARSZ2.js} +3 -3
- package/dist/chunks/{runCli-TIPCBGV7.js → runCli-NSGPBNXJ.js} +6 -6
- package/dist/dinox.js +4 -4
- package/dist/dsh-plugin/lib/client.js +230 -230
- package/dist/dsh-plugin/lib/index.js +1 -1
- package/dist/dsh-plugin/package.json +1 -1
- package/dist/dsh-plugin/runtime.json +2 -2
- package/dist/editor-ui/mcp-app.html +269 -269
- package/package.json +11 -10
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
toAuthorizationHeaderValue,
|
|
25
25
|
withAsyncRelease,
|
|
26
26
|
writeDaemonLogLine
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-D7QTW6N6.js";
|
|
28
28
|
import {
|
|
29
29
|
DEFAULT_TODO_FILTER,
|
|
30
30
|
TASK_STATUS_MARKDOWN_MARKER,
|
|
@@ -6545,6 +6545,203 @@ function buildJsonArrayHasValuesSql(noteAlias, field, itemAlias) {
|
|
|
6545
6545
|
`;
|
|
6546
6546
|
}
|
|
6547
6547
|
|
|
6548
|
+
// ../../packages/shared/src/protocol/channels.ts
|
|
6549
|
+
var RPC_CHANNELS = {
|
|
6550
|
+
codexSubscription: {
|
|
6551
|
+
STATE: "codex-subscription:state",
|
|
6552
|
+
COMMAND: "codex-subscription:command",
|
|
6553
|
+
CHANGED: "codex-subscription:changed"
|
|
6554
|
+
},
|
|
6555
|
+
auth: {
|
|
6556
|
+
SIGN_IN: "auth:sign-in",
|
|
6557
|
+
SIGN_UP: "auth:sign-up",
|
|
6558
|
+
SEND_SIGN_UP_CODE: "auth:send-sign-up-code",
|
|
6559
|
+
RESET_PASSWORD: "auth:reset-password",
|
|
6560
|
+
SEND_PASSWORD_RESET_CODE: "auth:send-password-reset-code",
|
|
6561
|
+
SIGN_OUT: "auth:sign-out",
|
|
6562
|
+
GET_SESSION: "auth:get-session",
|
|
6563
|
+
GET_TOKEN: "auth:get-token",
|
|
6564
|
+
SESSION_CHANGED: "auth:session-changed",
|
|
6565
|
+
UPDATE_MEMBERSHIP: "auth:update-membership",
|
|
6566
|
+
REPORT_UNAUTHORIZED: "auth:report-unauthorized"
|
|
6567
|
+
},
|
|
6568
|
+
ai: {
|
|
6569
|
+
/** Streaming chat run (request/response start; chunks pushed via CHAT_CHUNK). */
|
|
6570
|
+
CHAT: "ai:chat",
|
|
6571
|
+
/** Server → client event: streamed chat chunk. */
|
|
6572
|
+
CHAT_CHUNK: "ai:chat-chunk",
|
|
6573
|
+
/** Domain-owned editor continuation pipeline (config, retrieval, prompt, model). */
|
|
6574
|
+
CONTINUE_WRITING: "ai:continue-writing",
|
|
6575
|
+
/** Cancel retrieval and model streams for one continuation batch. */
|
|
6576
|
+
CANCEL_CONTINUE_WRITING: "ai:continue-writing-cancel",
|
|
6577
|
+
/** Server → client editor continuation candidate events. */
|
|
6578
|
+
CONTINUE_WRITING_EVENT: "ai:continue-writing-event",
|
|
6579
|
+
COMPLETE: "ai:complete",
|
|
6580
|
+
CANCEL: "ai:cancel",
|
|
6581
|
+
PROVIDER_TEST: "ai:provider-test",
|
|
6582
|
+
PROVIDER_MODELS: "ai:provider-models",
|
|
6583
|
+
/** Generate note title/tags/zettel-box proposals against backend catalogs. */
|
|
6584
|
+
/** Fill note property values against backend property definitions. */
|
|
6585
|
+
GENERATE_NOTE_PROPERTIES: "ai:generate-note-properties",
|
|
6586
|
+
/** Choose a property template with Jev. Abstaining returns null. */
|
|
6587
|
+
MATCH_NOTE_PROPERTY_TEMPLATE: "ai:match-note-property-template",
|
|
6588
|
+
/** Generate project-scoped, editor-anchored note review annotations. */
|
|
6589
|
+
GENERATE_NOTE_REVIEW: "ai:generate-note-review",
|
|
6590
|
+
/** Generate a replacement proposal for a live editor selection. */
|
|
6591
|
+
REWRITE_EDITOR_SELECTION: "ai:rewrite-editor-selection",
|
|
6592
|
+
/** Generate timestamp-grounded media highlights. */
|
|
6593
|
+
GENERATE_MEDIA_HIGHLIGHTS: "ai:generate-media-highlights",
|
|
6594
|
+
/** Generate typed flashcard proposals. */
|
|
6595
|
+
GENERATE_FLASHCARDS: "ai:generate-flashcards",
|
|
6596
|
+
/** Generate a title for a supported product context. */
|
|
6597
|
+
GENERATE_TITLE: "ai:generate-title",
|
|
6598
|
+
/** Generate and normalize an editable saved-view plan from natural language. */
|
|
6599
|
+
GENERATE_SAVED_VIEW_PLAN: "ai:generate-saved-view-plan",
|
|
6600
|
+
/** Generate one saved-view chart or stat from natural language (editable, not persisted). */
|
|
6601
|
+
GENERATE_SAVED_VIEW_ANALYTICS: "ai:generate-saved-view-analytics",
|
|
6602
|
+
/** Synthesize a user self-portrait suggestion from long-term memory (not persisted). */
|
|
6603
|
+
GENERATE_SELF_PORTRAIT: "ai:generate-self-portrait",
|
|
6604
|
+
/** Read-only, restricted headless diagnostics for Direct/Deferred tool selection. */
|
|
6605
|
+
TOOL_SELECTION_DIAGNOSTICS: "ai:tool-selection-diagnostics",
|
|
6606
|
+
/** Restricted snapshot-backed retrieval and production Agent evaluations. */
|
|
6607
|
+
AGENT_EVAL: "ai:agent-eval"
|
|
6608
|
+
},
|
|
6609
|
+
backendApi: {
|
|
6610
|
+
REQUEST: "backend-api:request"
|
|
6611
|
+
},
|
|
6612
|
+
bizApi: {
|
|
6613
|
+
REQUEST: "biz-api:request"
|
|
6614
|
+
},
|
|
6615
|
+
localLibrary: {
|
|
6616
|
+
/** Create a new local library (pglite-backed, main-process only). */
|
|
6617
|
+
CREATE: "local-library:create",
|
|
6618
|
+
/** List all local libraries. */
|
|
6619
|
+
LIST: "local-library:list",
|
|
6620
|
+
/** Update a local library (name/config/active). */
|
|
6621
|
+
UPDATE: "local-library:update",
|
|
6622
|
+
/** Delete a local library by id. */
|
|
6623
|
+
DELETE: "local-library:delete",
|
|
6624
|
+
/** Run an import sync for a local library. */
|
|
6625
|
+
SYNC: "local-library:sync",
|
|
6626
|
+
/** Cheap check whether the source changed since last sync. */
|
|
6627
|
+
DETECT_STALE: "local-library:detect-stale",
|
|
6628
|
+
/** List imported items for a library. */
|
|
6629
|
+
LIST_ITEMS: "local-library:list-items",
|
|
6630
|
+
/** Hybrid (full-text + vector) search across libraries. */
|
|
6631
|
+
SEARCH: "local-library:search",
|
|
6632
|
+
/** Open an imported item in its owning desktop application. */
|
|
6633
|
+
OPEN_ITEM: "local-library:open-item"
|
|
6634
|
+
},
|
|
6635
|
+
localOcr: {
|
|
6636
|
+
/** Run in-process PaddleOCR for a renderer-provided image input. */
|
|
6637
|
+
RECOGNIZE_IMAGE: "localOcr:recognizeImage",
|
|
6638
|
+
/** Reindex one uploaded image resource through local OCR + semantic fallback. */
|
|
6639
|
+
REINDEX_RESOURCE: "localOcr:reindexResource",
|
|
6640
|
+
/** Reindex uploaded image resources in a bounded background batch. */
|
|
6641
|
+
REINDEX_RESOURCES: "localOcr:reindexResources"
|
|
6642
|
+
},
|
|
6643
|
+
/** Delegated tasks: the user's own decisions (approve / decline) sent to the scheduler. */
|
|
6644
|
+
agentTask: {
|
|
6645
|
+
DECIDE: "agent-task:decide"
|
|
6646
|
+
},
|
|
6647
|
+
remoteDevice: {
|
|
6648
|
+
GET_HOST_STATUS: "remote-device:get-host-status",
|
|
6649
|
+
UPDATE_HOST_CONFIG: "remote-device:update-host-config"
|
|
6650
|
+
},
|
|
6651
|
+
/**
|
|
6652
|
+
* The desktop as a remote-device CLIENT: computer agents (`dino gateway` robots) an agent can
|
|
6653
|
+
* be bound to. Run control for bound agents reuses the thread-run channels.
|
|
6654
|
+
*/
|
|
6655
|
+
remoteAgent: {
|
|
6656
|
+
/** Gateway robots (c_robot, `gw-` devices) merged with live presence. */
|
|
6657
|
+
LIST_DEVICES: "remote-agent:list-devices",
|
|
6658
|
+
/** Ask online devices to announce themselves now, then return the merged list. */
|
|
6659
|
+
DISCOVER: "remote-agent:discover",
|
|
6660
|
+
/** Push: the robot list or a device's presence changed. Payload: RemoteAgentDevicesChangedEvent. */
|
|
6661
|
+
DEVICES_CHANGED: "remote-agent:devices-changed",
|
|
6662
|
+
/** A bound agent's computer-agent choices + option catalog (cached; `refresh` asks the agent). */
|
|
6663
|
+
GET_RUN_CONFIG: "remote-agent:get-run-config",
|
|
6664
|
+
/** Saves one choice in `c_project.meta_data.runSettings` (synced to every device). */
|
|
6665
|
+
SET_RUN_SETTING: "remote-agent:set-run-setting",
|
|
6666
|
+
/** How the computer runs the agent: approval, pause, note access, folder. */
|
|
6667
|
+
GET_HOST_SETTINGS: "remote-agent:get-host-settings",
|
|
6668
|
+
UPDATE_HOST_SETTINGS: "remote-agent:update-host-settings",
|
|
6669
|
+
/** Folders on the computer for the working-folder picker. */
|
|
6670
|
+
LIST_FOLDERS: "remote-agent:list-folders",
|
|
6671
|
+
/** Checks / prepares a folder on the computer, then saves it as the agent's working folder. */
|
|
6672
|
+
SET_WORKING_FOLDER: "remote-agent:set-working-folder"
|
|
6673
|
+
}
|
|
6674
|
+
};
|
|
6675
|
+
|
|
6676
|
+
// ../../packages/shared/src/auth.ts
|
|
6677
|
+
import { z } from "zod";
|
|
6678
|
+
var AUTH_CODE_OK2 = "000000";
|
|
6679
|
+
var AUTH_RPC_CHANNELS = RPC_CHANNELS.auth;
|
|
6680
|
+
var AUTH_UNAUTHORIZED_SOURCE_SCHEMA = z.enum([
|
|
6681
|
+
"backend",
|
|
6682
|
+
"gateway",
|
|
6683
|
+
"powersync",
|
|
6684
|
+
"embedding",
|
|
6685
|
+
"collab",
|
|
6686
|
+
"renderer-api",
|
|
6687
|
+
"asr"
|
|
6688
|
+
]);
|
|
6689
|
+
var AUTH_UNAUTHORIZED_REPORT_DETAILS_SCHEMA = z.object({
|
|
6690
|
+
status: z.number().int().min(100).max(599).optional(),
|
|
6691
|
+
code: z.string().trim().min(1).max(512).nullable().optional(),
|
|
6692
|
+
requestId: z.string().trim().min(1).max(128).regex(/^[A-Za-z0-9._:-]+$/).nullable().optional(),
|
|
6693
|
+
expectedToken: z.string().min(1).max(16384).nullable().optional()
|
|
6694
|
+
}).strict();
|
|
6695
|
+
var AUTH_UNAUTHORIZED_REPORT_OBJECT_SCHEMA = AUTH_UNAUTHORIZED_REPORT_DETAILS_SCHEMA.extend({
|
|
6696
|
+
source: AUTH_UNAUTHORIZED_SOURCE_SCHEMA
|
|
6697
|
+
});
|
|
6698
|
+
var AUTH_UNAUTHORIZED_REPORT_SCHEMA = z.union([
|
|
6699
|
+
AUTH_UNAUTHORIZED_SOURCE_SCHEMA.transform((source) => ({ source })),
|
|
6700
|
+
AUTH_UNAUTHORIZED_REPORT_OBJECT_SCHEMA
|
|
6701
|
+
]);
|
|
6702
|
+
var SIGN_IN_PARAM_SCHEMA = z.object({
|
|
6703
|
+
email: z.string().trim().min(1).max(320),
|
|
6704
|
+
password: z.string().min(1).max(1024)
|
|
6705
|
+
}).strict();
|
|
6706
|
+
var SIGN_UP_PARAM_SCHEMA = z.object({
|
|
6707
|
+
email: z.string().trim().min(1).max(320),
|
|
6708
|
+
password: z.string().min(6).max(1024),
|
|
6709
|
+
verifyCode: z.string().trim().min(1).max(64),
|
|
6710
|
+
username: z.string().trim().min(1).max(128)
|
|
6711
|
+
}).strict();
|
|
6712
|
+
var SEND_SIGN_UP_CODE_PARAM_SCHEMA = z.object({
|
|
6713
|
+
email: z.string().trim().min(1).max(320)
|
|
6714
|
+
}).strict();
|
|
6715
|
+
var RESET_PASSWORD_PARAM_SCHEMA = z.object({
|
|
6716
|
+
email: z.string().trim().min(1).max(320),
|
|
6717
|
+
password: z.string().min(6).max(1024),
|
|
6718
|
+
checkCode: z.string().trim().min(1).max(64)
|
|
6719
|
+
}).strict();
|
|
6720
|
+
var AUTH_MEMBERSHIP_UPDATE_SCHEMA = z.object({
|
|
6721
|
+
level: z.union([z.string(), z.number()]).nullable().optional(),
|
|
6722
|
+
expireAt: z.string().nullable().optional(),
|
|
6723
|
+
username: z.string().nullable().optional(),
|
|
6724
|
+
email: z.string().nullable().optional()
|
|
6725
|
+
}).strict();
|
|
6726
|
+
|
|
6727
|
+
// ../../packages/shared/src/constants/service-endpoints.ts
|
|
6728
|
+
var BACKEND_API_BASE_URL = "https://dinoai.chatgo.pro";
|
|
6729
|
+
var NOTE_SHARE_WEB_BASE_URL = "https://share.dinox.info";
|
|
6730
|
+
var POWERSYNC_DEFAULT_TOKEN_ENDPOINT = `${BACKEND_API_BASE_URL}/auth/v2/token`;
|
|
6731
|
+
var AI_SERVICE_HOST = "https://aisdk.chatgo.pro";
|
|
6732
|
+
var AI_SDK_API_BASE_URL = `${AI_SERVICE_HOST}/api`;
|
|
6733
|
+
var AI_SDK_GATEWAY_V1_BASE_URL = `${AI_SERVICE_HOST}/api/gateway/v1`;
|
|
6734
|
+
var AI_SDK_GATEWAY_V2_BASE_URL = `${AI_SERVICE_HOST}/api/gateway/v2`;
|
|
6735
|
+
var AI_SDK_MODELS_DEV_CATALOG_URL = `${AI_SERVICE_HOST}/api/model/models-dev`;
|
|
6736
|
+
var AI_SDK_VERSION_LIST_URL = `${AI_SERVICE_HOST}/api/version/list`;
|
|
6737
|
+
var AI_SDK_VERSION_LATEST_URL = `${AI_SERVICE_HOST}/api/version/latest`;
|
|
6738
|
+
var NATS_DEVICE_CREDENTIALS_URL = `${AI_SERVICE_HOST}/api/nats/credentials`;
|
|
6739
|
+
var AI_SDK_WEB_SEARCH_URL = `${AI_SERVICE_HOST}/api/openapi/web/search`;
|
|
6740
|
+
var AI_SDK_ASR_REALTIME_WS_URL = `${AI_SERVICE_HOST.replace(
|
|
6741
|
+
/^http/,
|
|
6742
|
+
"ws"
|
|
6743
|
+
)}/api/openapi/asr/realtime`;
|
|
6744
|
+
|
|
6548
6745
|
// ../../packages/agent-contracts/src/chat-order.ts
|
|
6549
6746
|
function normalizeChatOrderIndex(value) {
|
|
6550
6747
|
if (typeof value === "number") {
|
|
@@ -7925,24 +8122,69 @@ function upgradeDiagram(node, type) {
|
|
|
7925
8122
|
...source ? { content: [{ type: "text", text: source }] } : {}
|
|
7926
8123
|
};
|
|
7927
8124
|
}
|
|
7928
|
-
function
|
|
7929
|
-
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7933
|
-
|
|
7934
|
-
|
|
7935
|
-
|
|
7936
|
-
|
|
8125
|
+
function blockId(attrs) {
|
|
8126
|
+
return typeof attrs.id === "string" && attrs.id ? { id: attrs.id } : {};
|
|
8127
|
+
}
|
|
8128
|
+
function nodeText(node) {
|
|
8129
|
+
if (typeof node.text === "string") return node.text;
|
|
8130
|
+
return Array.isArray(node.content) ? node.content.map((child) => nodeText(child)).join("") : "";
|
|
8131
|
+
}
|
|
8132
|
+
function firstStringAttr(attrs, keys) {
|
|
8133
|
+
for (const key of keys) {
|
|
8134
|
+
if (typeof attrs[key] === "string") return attrs[key];
|
|
7937
8135
|
}
|
|
8136
|
+
return null;
|
|
8137
|
+
}
|
|
8138
|
+
function stripFrontmatterDelimiters(raw) {
|
|
8139
|
+
const text = raw.replace(/\r\n?/g, "\n").replace(/^\uFEFF/, "");
|
|
8140
|
+
const fenced = /^---[ \t]*\n([\s\S]*?)\n---[ \t]*$/.exec(text);
|
|
8141
|
+
return (fenced ? fenced[1] : text).replace(/^\n+|\n+$/g, "");
|
|
8142
|
+
}
|
|
8143
|
+
function upgradeFrontmatter(node) {
|
|
8144
|
+
const attrs = node.attrs ?? {};
|
|
8145
|
+
const source = stripFrontmatterDelimiters(firstStringAttr(attrs, ["raw"]) ?? nodeText(node));
|
|
8146
|
+
return {
|
|
8147
|
+
type: "codeBlock",
|
|
8148
|
+
attrs: { ...blockId(attrs), language: "yaml" },
|
|
8149
|
+
...source ? { content: [{ type: "text", text: source }] } : {}
|
|
8150
|
+
};
|
|
8151
|
+
}
|
|
8152
|
+
var LEGACY_MATH_NODES = /* @__PURE__ */ new Set(["math", "mathBlock", "mathInline"]);
|
|
8153
|
+
function upgradeMath(node, type, inline) {
|
|
8154
|
+
const attrs = node.attrs ?? {};
|
|
8155
|
+
const latex = firstStringAttr(attrs, ["latex", "content"]) ?? nodeText(node);
|
|
8156
|
+
const isInline = type === "mathInline" || type === "math" && inline;
|
|
8157
|
+
return isInline ? { type: "inlineMath", attrs: { latex } } : { type: "blockMath", attrs: { ...blockId(attrs), latex } };
|
|
8158
|
+
}
|
|
8159
|
+
function upgradeNode(value, inline) {
|
|
8160
|
+
if (Array.isArray(value)) return upgradeChildren(value, false);
|
|
7938
8161
|
if (!value || typeof value !== "object") return value;
|
|
7939
8162
|
const node = value;
|
|
7940
8163
|
const type = typeof node.type === "string" ? node.type : "";
|
|
7941
8164
|
if (type in LEGACY_NOTE_DIAGRAM_NODES) return upgradeDiagram(node, type);
|
|
8165
|
+
if (type === "frontmatter") return upgradeFrontmatter(node);
|
|
8166
|
+
if (LEGACY_MATH_NODES.has(type)) return upgradeMath(node, type, inline);
|
|
7942
8167
|
if (!Array.isArray(node.content)) return value;
|
|
7943
|
-
const content =
|
|
8168
|
+
const content = upgradeChildren(node.content, TEXTBLOCK_TYPES.has(type));
|
|
7944
8169
|
return content === node.content ? value : { ...node, content };
|
|
7945
8170
|
}
|
|
8171
|
+
var TEXTBLOCK_TYPES = /* @__PURE__ */ new Set(["paragraph", "heading"]);
|
|
8172
|
+
function upgradeChildren(children, inTextblock) {
|
|
8173
|
+
const inline = inTextblock || children.some((child) => {
|
|
8174
|
+
const type = child?.type;
|
|
8175
|
+
return type === "text" || type === "hardBreak" || type === "mathInline";
|
|
8176
|
+
});
|
|
8177
|
+
let changed = false;
|
|
8178
|
+
const next = children.map((child) => {
|
|
8179
|
+
const upgraded = upgradeNode(child, inline);
|
|
8180
|
+
if (upgraded !== child) changed = true;
|
|
8181
|
+
return upgraded;
|
|
8182
|
+
});
|
|
8183
|
+
return changed ? next : children;
|
|
8184
|
+
}
|
|
8185
|
+
function upgradeLegacyNoteNodes(value) {
|
|
8186
|
+
return upgradeNode(value, false);
|
|
8187
|
+
}
|
|
7946
8188
|
|
|
7947
8189
|
// ../../packages/note-schema/src/spec/index.ts
|
|
7948
8190
|
var nul = { default: null };
|
|
@@ -18796,9 +19038,54 @@ function guardSave(stored, incoming, schema) {
|
|
|
18796
19038
|
// src/commands/domain/run.ts
|
|
18797
19039
|
import { ZodError } from "zod";
|
|
18798
19040
|
|
|
18799
|
-
// ../../packages/
|
|
18800
|
-
|
|
18801
|
-
|
|
19041
|
+
// ../../packages/powersync/child-notes.ts
|
|
19042
|
+
var topLevelNoteCondition = (alias) => `${alias ? `${alias}.` : ""}parent_id IS NULL`;
|
|
19043
|
+
function parseExtraData(raw) {
|
|
19044
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
19045
|
+
return { ...raw };
|
|
19046
|
+
}
|
|
19047
|
+
if (typeof raw !== "string" || !raw.trim()) return {};
|
|
19048
|
+
try {
|
|
19049
|
+
const parsed = JSON.parse(raw);
|
|
19050
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
19051
|
+
} catch {
|
|
19052
|
+
return {};
|
|
19053
|
+
}
|
|
19054
|
+
}
|
|
19055
|
+
function markCascadeDeleted(extraData, parentId) {
|
|
19056
|
+
return JSON.stringify({ ...parseExtraData(extraData), cascadeDeletedBy: parentId });
|
|
19057
|
+
}
|
|
19058
|
+
|
|
19059
|
+
// ../../packages/powersync/mutation-timestamps.ts
|
|
19060
|
+
var tableColumns = new Map(
|
|
19061
|
+
AppSchema.tables.map((table) => [table.name, /* @__PURE__ */ new Set(["id", ...table.columns.map((column4) => column4.name)])])
|
|
19062
|
+
);
|
|
19063
|
+
function resolveTimestamp(options2) {
|
|
19064
|
+
return options2?.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
19065
|
+
}
|
|
19066
|
+
function parseSyncTimestampMs(value) {
|
|
19067
|
+
if (typeof value !== "string") {
|
|
19068
|
+
return null;
|
|
19069
|
+
}
|
|
19070
|
+
const trimmed = value.trim();
|
|
19071
|
+
if (!trimmed) {
|
|
19072
|
+
return null;
|
|
19073
|
+
}
|
|
19074
|
+
const parsed = Date.parse(trimmed.replace(" ", "T"));
|
|
19075
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
19076
|
+
}
|
|
19077
|
+
function nextMonotonicUpdatedAt(previous, options2) {
|
|
19078
|
+
const timestamp = resolveTimestamp(options2);
|
|
19079
|
+
const candidate = parseSyncTimestampMs(timestamp);
|
|
19080
|
+
const floor = parseSyncTimestampMs(previous);
|
|
19081
|
+
if (candidate == null || floor == null || candidate > floor) {
|
|
19082
|
+
return timestamp;
|
|
19083
|
+
}
|
|
19084
|
+
return new Date(floor + 1).toISOString();
|
|
19085
|
+
}
|
|
19086
|
+
|
|
19087
|
+
// ../../packages/core/src/powersync/typed-rpc/domain/note-lifecycle.ts
|
|
19088
|
+
import { z as z2 } from "zod";
|
|
18802
19089
|
|
|
18803
19090
|
// ../../packages/core/src/powersync/typed-rpc/PowerSyncRpcDefinitions.ts
|
|
18804
19091
|
function defineReadModel(definition) {
|
|
@@ -18808,6 +19095,129 @@ function defineCommand(definition) {
|
|
|
18808
19095
|
return definition;
|
|
18809
19096
|
}
|
|
18810
19097
|
|
|
19098
|
+
// ../../packages/core/src/powersync/typed-rpc/domain/note-lifecycle.ts
|
|
19099
|
+
var NOTE_TYPE_UPDATE_INPUT = z2.object({
|
|
19100
|
+
noteId: z2.string().trim().min(1),
|
|
19101
|
+
type: z2.enum(["note", "crawl"]),
|
|
19102
|
+
updatedAt: z2.string().trim().min(1).max(64)
|
|
19103
|
+
});
|
|
19104
|
+
var NOTE_SOFT_DELETE_INPUT = z2.object({
|
|
19105
|
+
noteId: z2.string().trim().min(1),
|
|
19106
|
+
updatedAt: z2.string().trim().min(1).max(64)
|
|
19107
|
+
});
|
|
19108
|
+
function createNoteLifecycleCommands() {
|
|
19109
|
+
return [
|
|
19110
|
+
defineCommand({
|
|
19111
|
+
name: "notes.updateType",
|
|
19112
|
+
inputSchema: NOTE_TYPE_UPDATE_INPUT,
|
|
19113
|
+
run: async (db, input) => {
|
|
19114
|
+
await updateNoteType(db, input);
|
|
19115
|
+
return { result: true, affectedTables: ["c_note"] };
|
|
19116
|
+
}
|
|
19117
|
+
}),
|
|
19118
|
+
defineCommand({
|
|
19119
|
+
name: "notes.softDelete",
|
|
19120
|
+
inputSchema: NOTE_SOFT_DELETE_INPUT,
|
|
19121
|
+
run: async (db, input) => {
|
|
19122
|
+
await softDeleteNote2(db, input);
|
|
19123
|
+
return { result: true, affectedTables: ["c_note"] };
|
|
19124
|
+
}
|
|
19125
|
+
})
|
|
19126
|
+
];
|
|
19127
|
+
}
|
|
19128
|
+
function createNoteLifecycleReadModels() {
|
|
19129
|
+
return [
|
|
19130
|
+
defineReadModel({
|
|
19131
|
+
name: "notes.maxActiveTop",
|
|
19132
|
+
inputSchema: z2.unknown().optional(),
|
|
19133
|
+
tables: () => ["c_note"],
|
|
19134
|
+
fetch: async (db) => fetchNoteMaxActiveTop(db)
|
|
19135
|
+
})
|
|
19136
|
+
];
|
|
19137
|
+
}
|
|
19138
|
+
async function fetchNoteMaxActiveTop(db) {
|
|
19139
|
+
return await db.getAll(
|
|
19140
|
+
`
|
|
19141
|
+
SELECT MAX(CAST(COALESCE(is_top, 0) AS INTEGER)) AS max_top
|
|
19142
|
+
FROM c_note
|
|
19143
|
+
WHERE is_del IS NULL OR is_del = 0
|
|
19144
|
+
`
|
|
19145
|
+
);
|
|
19146
|
+
}
|
|
19147
|
+
async function updateNoteType(db, input) {
|
|
19148
|
+
const noteId = input.noteId.trim();
|
|
19149
|
+
const updatedAt = input.updatedAt.trim();
|
|
19150
|
+
if (!noteId || !updatedAt) {
|
|
19151
|
+
throw new Error("Invalid note type update input");
|
|
19152
|
+
}
|
|
19153
|
+
await db.writeTransaction(async (tx) => {
|
|
19154
|
+
const row = await tx.getOptional(
|
|
19155
|
+
"SELECT updated_at FROM c_note WHERE id = ? AND (is_del IS NULL OR is_del = 0) LIMIT 1",
|
|
19156
|
+
[noteId]
|
|
19157
|
+
);
|
|
19158
|
+
if (!row) {
|
|
19159
|
+
throw new Error("NOTE_NOT_FOUND");
|
|
19160
|
+
}
|
|
19161
|
+
await tx.execute(
|
|
19162
|
+
`
|
|
19163
|
+
UPDATE c_note
|
|
19164
|
+
SET type = ?,
|
|
19165
|
+
updated_at = ?
|
|
19166
|
+
WHERE id = ?
|
|
19167
|
+
AND (is_del IS NULL OR is_del = 0)
|
|
19168
|
+
`,
|
|
19169
|
+
[input.type, nextMonotonicUpdatedAt(row.updated_at, { timestamp: updatedAt }), noteId]
|
|
19170
|
+
);
|
|
19171
|
+
});
|
|
19172
|
+
}
|
|
19173
|
+
async function softDeleteNote2(db, input) {
|
|
19174
|
+
const noteId = input.noteId.trim();
|
|
19175
|
+
const updatedAt = input.updatedAt.trim();
|
|
19176
|
+
if (!noteId || !updatedAt) {
|
|
19177
|
+
throw new Error("Invalid note soft delete input");
|
|
19178
|
+
}
|
|
19179
|
+
await db.writeTransaction(async (tx) => {
|
|
19180
|
+
const row = await tx.getOptional(
|
|
19181
|
+
"SELECT updated_at FROM c_note WHERE id = ? AND (is_del IS NULL OR is_del = 0) LIMIT 1",
|
|
19182
|
+
[noteId]
|
|
19183
|
+
);
|
|
19184
|
+
if (!row) {
|
|
19185
|
+
throw new Error("NOTE_NOT_FOUND");
|
|
19186
|
+
}
|
|
19187
|
+
await tx.execute(
|
|
19188
|
+
`
|
|
19189
|
+
UPDATE c_note
|
|
19190
|
+
SET is_del = 1,
|
|
19191
|
+
updated_at = ?
|
|
19192
|
+
WHERE id = ?
|
|
19193
|
+
AND (is_del IS NULL OR is_del = 0)
|
|
19194
|
+
`,
|
|
19195
|
+
[nextMonotonicUpdatedAt(row.updated_at, { timestamp: updatedAt }), noteId]
|
|
19196
|
+
);
|
|
19197
|
+
await softDeleteChildNotesOfParent(tx, noteId, updatedAt);
|
|
19198
|
+
});
|
|
19199
|
+
}
|
|
19200
|
+
async function softDeleteChildNotesOfParent(tx, parentId, updatedAt) {
|
|
19201
|
+
const children = await tx.getAll(
|
|
19202
|
+
"SELECT id, extra_data, updated_at FROM c_note WHERE parent_id = ? AND (is_del IS NULL OR is_del = 0)",
|
|
19203
|
+
[parentId]
|
|
19204
|
+
);
|
|
19205
|
+
for (const child of children) {
|
|
19206
|
+
await tx.execute(
|
|
19207
|
+
"UPDATE c_note SET is_del = 1, extra_data = ?, updated_at = ? WHERE id = ?",
|
|
19208
|
+
[
|
|
19209
|
+
markCascadeDeleted(child.extra_data, parentId),
|
|
19210
|
+
nextMonotonicUpdatedAt(child.updated_at, { timestamp: updatedAt }),
|
|
19211
|
+
child.id
|
|
19212
|
+
]
|
|
19213
|
+
);
|
|
19214
|
+
}
|
|
19215
|
+
}
|
|
19216
|
+
|
|
19217
|
+
// ../../packages/core/src/powersync/typed-rpc/domain/note-templates.ts
|
|
19218
|
+
import { uuidv7 } from "uuidv7";
|
|
19219
|
+
import { z as z3 } from "zod";
|
|
19220
|
+
|
|
18811
19221
|
// ../../packages/core/src/powersync/typed-rpc/sql-utils.ts
|
|
18812
19222
|
function normalizeLimit(value, fallback, max) {
|
|
18813
19223
|
const numeric = Number(value ?? fallback);
|
|
@@ -18827,38 +19237,38 @@ var NOTE_TEMPLATE_COLUMNS = `
|
|
|
18827
19237
|
id, user_id, name, content, priority, is_show, extra_data, property_def,
|
|
18828
19238
|
insert_at, update_at, is_del
|
|
18829
19239
|
`;
|
|
18830
|
-
var PROPERTY_KEYS_INPUT =
|
|
18831
|
-
var NOTE_TEMPLATE_CATALOG_INPUT =
|
|
18832
|
-
userId:
|
|
18833
|
-
limit:
|
|
19240
|
+
var PROPERTY_KEYS_INPUT = z3.array(z3.string().min(1).max(64).refine(isPropertyKeyValid)).max(50);
|
|
19241
|
+
var NOTE_TEMPLATE_CATALOG_INPUT = z3.object({
|
|
19242
|
+
userId: z3.string().trim().min(1),
|
|
19243
|
+
limit: z3.number().int().positive().max(2e3).optional()
|
|
18834
19244
|
});
|
|
18835
|
-
var TEMPLATE_CONTENT_INPUT =
|
|
18836
|
-
var NOTE_TEMPLATE_CREATE_INPUT =
|
|
18837
|
-
userId:
|
|
18838
|
-
name:
|
|
19245
|
+
var TEMPLATE_CONTENT_INPUT = z3.string().max(2e5);
|
|
19246
|
+
var NOTE_TEMPLATE_CREATE_INPUT = z3.object({
|
|
19247
|
+
userId: z3.string().trim().min(1),
|
|
19248
|
+
name: z3.string().trim().min(1).max(120),
|
|
18839
19249
|
propertyKeys: PROPERTY_KEYS_INPUT,
|
|
18840
19250
|
content: TEMPLATE_CONTENT_INPUT.nullable().optional(),
|
|
18841
19251
|
/** Initial extra_data JSON object (e.g. the workshop's catalogOrigin); defaults to `{}`. */
|
|
18842
|
-
extraData:
|
|
18843
|
-
updatedAt:
|
|
19252
|
+
extraData: z3.record(z3.string(), z3.unknown()).nullable().optional(),
|
|
19253
|
+
updatedAt: z3.string().trim().min(1).max(64)
|
|
18844
19254
|
});
|
|
18845
|
-
var NOTE_TEMPLATE_UPDATE_INPUT =
|
|
18846
|
-
id:
|
|
18847
|
-
userId:
|
|
18848
|
-
name:
|
|
19255
|
+
var NOTE_TEMPLATE_UPDATE_INPUT = z3.object({
|
|
19256
|
+
id: z3.string().trim().min(1),
|
|
19257
|
+
userId: z3.string().trim().min(1),
|
|
19258
|
+
name: z3.string().trim().min(1).max(120).optional(),
|
|
18849
19259
|
propertyKeys: PROPERTY_KEYS_INPUT.optional(),
|
|
18850
19260
|
content: TEMPLATE_CONTENT_INPUT.nullable().optional(),
|
|
18851
|
-
updatedAt:
|
|
19261
|
+
updatedAt: z3.string().trim().min(1).max(64)
|
|
18852
19262
|
}).refine(
|
|
18853
19263
|
(input) => input.name !== void 0 || input.propertyKeys !== void 0 || input.content !== void 0,
|
|
18854
19264
|
{
|
|
18855
19265
|
message: "At least one note-template field must be updated"
|
|
18856
19266
|
}
|
|
18857
19267
|
);
|
|
18858
|
-
var NOTE_TEMPLATE_SOFT_DELETE_INPUT =
|
|
18859
|
-
id:
|
|
18860
|
-
userId:
|
|
18861
|
-
updatedAt:
|
|
19268
|
+
var NOTE_TEMPLATE_SOFT_DELETE_INPUT = z3.object({
|
|
19269
|
+
id: z3.string().trim().min(1),
|
|
19270
|
+
userId: z3.string().trim().min(1),
|
|
19271
|
+
updatedAt: z3.string().trim().min(1).max(64)
|
|
18862
19272
|
});
|
|
18863
19273
|
function createNoteTemplateReadModels() {
|
|
18864
19274
|
return [
|
|
@@ -19048,7 +19458,7 @@ async function softDeleteNoteTemplate(db, input) {
|
|
|
19048
19458
|
}
|
|
19049
19459
|
|
|
19050
19460
|
// ../../packages/saved-views/src/saved-views.ts
|
|
19051
|
-
import { z as
|
|
19461
|
+
import { z as z4 } from "zod";
|
|
19052
19462
|
var SAVED_VIEW_DISPLAY_ONLY_SYSTEM_FIELDS = [
|
|
19053
19463
|
"cover",
|
|
19054
19464
|
"audio",
|
|
@@ -19092,7 +19502,7 @@ function isSavedViewFieldRef(value) {
|
|
|
19092
19502
|
function isSavedViewSelfSourceFieldRef(value) {
|
|
19093
19503
|
return value === SAVED_VIEW_SELF_ID_FIELD || isSavedViewFieldRef(value);
|
|
19094
19504
|
}
|
|
19095
|
-
var savedViewFieldRefSchema =
|
|
19505
|
+
var savedViewFieldRefSchema = z4.custom(
|
|
19096
19506
|
isSavedViewFieldRef,
|
|
19097
19507
|
"Invalid saved view field reference"
|
|
19098
19508
|
);
|
|
@@ -19192,11 +19602,11 @@ function canSortSavedViewField(field, type) {
|
|
|
19192
19602
|
var MAX_SAVED_VIEW_FILTER_DEPTH = 8;
|
|
19193
19603
|
var MAX_SAVED_VIEW_FILTER_NODES = 100;
|
|
19194
19604
|
var MAX_SAVED_VIEW_FILTER_VALUE_LENGTH = 2e3;
|
|
19195
|
-
var savedViewFilterValueSchema =
|
|
19196
|
-
|
|
19197
|
-
|
|
19198
|
-
|
|
19199
|
-
|
|
19605
|
+
var savedViewFilterValueSchema = z4.union([
|
|
19606
|
+
z4.string().max(MAX_SAVED_VIEW_FILTER_VALUE_LENGTH),
|
|
19607
|
+
z4.number(),
|
|
19608
|
+
z4.boolean(),
|
|
19609
|
+
z4.null()
|
|
19200
19610
|
]);
|
|
19201
19611
|
var SAVED_VIEW_VALUE_REQUIRED_OPERATORS = /* @__PURE__ */ new Set([
|
|
19202
19612
|
"contains",
|
|
@@ -19239,17 +19649,17 @@ function canSavedViewSelfSourceField(field) {
|
|
|
19239
19649
|
if (!isSavedViewFieldRef(field) || isSavedViewDisplayOnlyField(field)) return false;
|
|
19240
19650
|
return field !== "sys.primary_resource_type" && field !== "sys.images";
|
|
19241
19651
|
}
|
|
19242
|
-
var savedViewSelfValueRefSchema =
|
|
19243
|
-
kind:
|
|
19244
|
-
field:
|
|
19652
|
+
var savedViewSelfValueRefSchema = z4.object({
|
|
19653
|
+
kind: z4.literal("self"),
|
|
19654
|
+
field: z4.custom(
|
|
19245
19655
|
isSavedViewSelfSourceFieldRef,
|
|
19246
19656
|
"Invalid saved view self source field reference"
|
|
19247
19657
|
)
|
|
19248
19658
|
});
|
|
19249
|
-
var savedViewFilterConditionSchema =
|
|
19250
|
-
kind:
|
|
19659
|
+
var savedViewFilterConditionSchema = z4.object({
|
|
19660
|
+
kind: z4.literal("condition"),
|
|
19251
19661
|
field: savedViewFieldRefSchema,
|
|
19252
|
-
operator:
|
|
19662
|
+
operator: z4.enum(SAVED_VIEW_FILTER_OPERATORS),
|
|
19253
19663
|
value: savedViewFilterValueSchema.optional(),
|
|
19254
19664
|
valueRef: savedViewSelfValueRefSchema.optional()
|
|
19255
19665
|
}).superRefine((condition, context) => {
|
|
@@ -19258,7 +19668,7 @@ var savedViewFilterConditionSchema = z2.object({
|
|
|
19258
19668
|
const allowedPresence = condition.operator === "isEmpty" || condition.operator === "isNotEmpty";
|
|
19259
19669
|
if (!comparesValue && !allowedPresence || comparesValue && !SAVED_VIEW_PRIMARY_RESOURCE_TYPES.some((option) => option === condition.value)) {
|
|
19260
19670
|
context.addIssue({
|
|
19261
|
-
code:
|
|
19671
|
+
code: z4.ZodIssueCode.custom,
|
|
19262
19672
|
path: ["value"],
|
|
19263
19673
|
message: "Invalid primary resource type filter"
|
|
19264
19674
|
});
|
|
@@ -19268,7 +19678,7 @@ var savedViewFilterConditionSchema = z2.object({
|
|
|
19268
19678
|
const hasLiteralValue = condition.value !== void 0 && condition.value !== null;
|
|
19269
19679
|
if (hasSelfValue && hasLiteralValue) {
|
|
19270
19680
|
context.addIssue({
|
|
19271
|
-
code:
|
|
19681
|
+
code: z4.ZodIssueCode.custom,
|
|
19272
19682
|
path: ["valueRef"],
|
|
19273
19683
|
message: "Saved view condition cannot combine a literal value with a self value ref"
|
|
19274
19684
|
});
|
|
@@ -19276,14 +19686,14 @@ var savedViewFilterConditionSchema = z2.object({
|
|
|
19276
19686
|
if (hasSelfValue) {
|
|
19277
19687
|
if (!canSavedViewFilterConditionUseSelfValue(condition.field, condition.operator)) {
|
|
19278
19688
|
context.addIssue({
|
|
19279
|
-
code:
|
|
19689
|
+
code: z4.ZodIssueCode.custom,
|
|
19280
19690
|
path: ["valueRef"],
|
|
19281
19691
|
message: `Saved view operator ${condition.operator} does not accept a self value`
|
|
19282
19692
|
});
|
|
19283
19693
|
}
|
|
19284
19694
|
if (condition.valueRef && !canSavedViewSelfSourceField(condition.valueRef.field)) {
|
|
19285
19695
|
context.addIssue({
|
|
19286
|
-
code:
|
|
19696
|
+
code: z4.ZodIssueCode.custom,
|
|
19287
19697
|
path: ["valueRef", "field"],
|
|
19288
19698
|
message: `${condition.valueRef.field} cannot be used as a self filter value`
|
|
19289
19699
|
});
|
|
@@ -19291,28 +19701,28 @@ var savedViewFilterConditionSchema = z2.object({
|
|
|
19291
19701
|
}
|
|
19292
19702
|
if (SAVED_VIEW_VALUE_REQUIRED_OPERATORS.has(condition.operator) && !hasSelfValue && !hasLiteralValue) {
|
|
19293
19703
|
context.addIssue({
|
|
19294
|
-
code:
|
|
19704
|
+
code: z4.ZodIssueCode.custom,
|
|
19295
19705
|
path: ["value"],
|
|
19296
19706
|
message: `Saved view operator ${condition.operator} requires a value`
|
|
19297
19707
|
});
|
|
19298
19708
|
}
|
|
19299
19709
|
if (SAVED_VIEW_VALUE_REQUIRED_OPERATORS.has(condition.operator) && !hasSelfValue && typeof condition.value === "string" && condition.value.trim().length === 0) {
|
|
19300
19710
|
context.addIssue({
|
|
19301
|
-
code:
|
|
19711
|
+
code: z4.ZodIssueCode.custom,
|
|
19302
19712
|
path: ["value"],
|
|
19303
19713
|
message: `Saved view operator ${condition.operator} requires a non-empty value`
|
|
19304
19714
|
});
|
|
19305
19715
|
}
|
|
19306
19716
|
if (SAVED_VIEW_VALUELESS_OPERATORS.has(condition.operator) && (hasLiteralValue || hasSelfValue)) {
|
|
19307
19717
|
context.addIssue({
|
|
19308
|
-
code:
|
|
19718
|
+
code: z4.ZodIssueCode.custom,
|
|
19309
19719
|
path: hasSelfValue ? ["valueRef"] : ["value"],
|
|
19310
19720
|
message: `Saved view operator ${condition.operator} does not accept a value`
|
|
19311
19721
|
});
|
|
19312
19722
|
}
|
|
19313
19723
|
if (condition.operator === "withinLastDays" && (typeof condition.value !== "number" || !Number.isInteger(condition.value) || condition.value < 1 || condition.value > MAX_SAVED_VIEW_RELATIVE_DAYS)) {
|
|
19314
19724
|
context.addIssue({
|
|
19315
|
-
code:
|
|
19725
|
+
code: z4.ZodIssueCode.custom,
|
|
19316
19726
|
path: ["value"],
|
|
19317
19727
|
message: `Saved view operator withinLastDays requires an integer from 1 to ${MAX_SAVED_VIEW_RELATIVE_DAYS}`
|
|
19318
19728
|
});
|
|
@@ -19346,27 +19756,27 @@ function isRawFilterNodeWithinLimits(value) {
|
|
|
19346
19756
|
return true;
|
|
19347
19757
|
}
|
|
19348
19758
|
var invalidSavedViewFilterNode = { kind: "__invalid_saved_view_filter__" };
|
|
19349
|
-
var savedViewFilterNodeSchema =
|
|
19759
|
+
var savedViewFilterNodeSchema = z4.preprocess(
|
|
19350
19760
|
(value) => isRawFilterNodeWithinLimits(value) ? value : invalidSavedViewFilterNode,
|
|
19351
|
-
|
|
19352
|
-
() =>
|
|
19761
|
+
z4.lazy(
|
|
19762
|
+
() => z4.union([
|
|
19353
19763
|
savedViewFilterConditionSchema,
|
|
19354
|
-
|
|
19355
|
-
kind:
|
|
19356
|
-
operator:
|
|
19357
|
-
children:
|
|
19764
|
+
z4.object({
|
|
19765
|
+
kind: z4.literal("group"),
|
|
19766
|
+
operator: z4.enum(["and", "or"]),
|
|
19767
|
+
children: z4.array(savedViewFilterNodeSchema).max(MAX_SAVED_VIEW_FILTER_NODES)
|
|
19358
19768
|
}),
|
|
19359
|
-
|
|
19360
|
-
kind:
|
|
19769
|
+
z4.object({
|
|
19770
|
+
kind: z4.literal("not"),
|
|
19361
19771
|
child: savedViewFilterNodeSchema
|
|
19362
19772
|
})
|
|
19363
19773
|
])
|
|
19364
19774
|
)
|
|
19365
19775
|
);
|
|
19366
|
-
var savedViewFilterGroupSchema =
|
|
19367
|
-
kind:
|
|
19368
|
-
operator:
|
|
19369
|
-
children:
|
|
19776
|
+
var savedViewFilterGroupSchema = z4.object({
|
|
19777
|
+
kind: z4.literal("group"),
|
|
19778
|
+
operator: z4.enum(["and", "or"]),
|
|
19779
|
+
children: z4.array(savedViewFilterNodeSchema).max(100)
|
|
19370
19780
|
});
|
|
19371
19781
|
function inspectSavedViewFilterNode(node, depth, state) {
|
|
19372
19782
|
state.count += 1;
|
|
@@ -19492,22 +19902,22 @@ function bindDetailSavedView(view, host) {
|
|
|
19492
19902
|
if (context.resolve(rule.field) !== rule.value) return null;
|
|
19493
19903
|
return bindSavedViewFilter(view.filter, context);
|
|
19494
19904
|
}
|
|
19495
|
-
var savedViewFilterSchema =
|
|
19496
|
-
version:
|
|
19905
|
+
var savedViewFilterSchema = z4.object({
|
|
19906
|
+
version: z4.union([z4.literal(1), z4.literal(2), z4.literal(3)]),
|
|
19497
19907
|
root: savedViewFilterNodeSchema.nullable()
|
|
19498
19908
|
}).superRefine((filter, context) => {
|
|
19499
19909
|
const usesSelf = savedViewFilterNodeUsesSelf(filter.root);
|
|
19500
19910
|
const usesDynamicDate = savedViewFilterNodeUsesDynamicDate(filter.root);
|
|
19501
19911
|
if (filter.version === 1 && (usesDynamicDate || usesSelf)) {
|
|
19502
19912
|
context.addIssue({
|
|
19503
|
-
code:
|
|
19913
|
+
code: z4.ZodIssueCode.custom,
|
|
19504
19914
|
path: ["version"],
|
|
19505
19915
|
message: usesSelf ? "Self filter values require saved view filter version 3" : "Dynamic date filters require saved view filter version 2"
|
|
19506
19916
|
});
|
|
19507
19917
|
}
|
|
19508
19918
|
if (filter.version === 2 && usesSelf) {
|
|
19509
19919
|
context.addIssue({
|
|
19510
|
-
code:
|
|
19920
|
+
code: z4.ZodIssueCode.custom,
|
|
19511
19921
|
path: ["version"],
|
|
19512
19922
|
message: "Self filter values require saved view filter version 3"
|
|
19513
19923
|
});
|
|
@@ -19517,14 +19927,14 @@ var savedViewFilterSchema = z2.object({
|
|
|
19517
19927
|
inspectSavedViewFilterNode(filter.root, 1, state);
|
|
19518
19928
|
if (state.count > MAX_SAVED_VIEW_FILTER_NODES) {
|
|
19519
19929
|
context.addIssue({
|
|
19520
|
-
code:
|
|
19930
|
+
code: z4.ZodIssueCode.custom,
|
|
19521
19931
|
path: ["root"],
|
|
19522
19932
|
message: `Saved view filters support at most ${MAX_SAVED_VIEW_FILTER_NODES} nodes`
|
|
19523
19933
|
});
|
|
19524
19934
|
}
|
|
19525
19935
|
if (state.maxDepth > MAX_SAVED_VIEW_FILTER_DEPTH) {
|
|
19526
19936
|
context.addIssue({
|
|
19527
|
-
code:
|
|
19937
|
+
code: z4.ZodIssueCode.custom,
|
|
19528
19938
|
path: ["root"],
|
|
19529
19939
|
message: `Saved view filters support at most ${MAX_SAVED_VIEW_FILTER_DEPTH} levels`
|
|
19530
19940
|
});
|
|
@@ -19555,12 +19965,12 @@ var MAX_SAVED_VIEW_CHART_LIMIT = 500;
|
|
|
19555
19965
|
var MAX_SAVED_VIEW_COMPUTED_COLUMNS = 10;
|
|
19556
19966
|
var MAX_SAVED_VIEW_SUMMARY_ITEMS = 20;
|
|
19557
19967
|
var MAX_SAVED_VIEW_COMPUTED_COLUMN_TITLE_LENGTH = 80;
|
|
19558
|
-
var savedViewColumnSchema =
|
|
19968
|
+
var savedViewColumnSchema = z4.object({
|
|
19559
19969
|
field: savedViewFieldRefSchema
|
|
19560
19970
|
});
|
|
19561
|
-
var savedViewSortSchema =
|
|
19971
|
+
var savedViewSortSchema = z4.object({
|
|
19562
19972
|
field: savedViewFieldRefSchema,
|
|
19563
|
-
direction:
|
|
19973
|
+
direction: z4.enum(["asc", "desc"])
|
|
19564
19974
|
});
|
|
19565
19975
|
var SYS_DATE_FIELD_REFS = /* @__PURE__ */ new Set([
|
|
19566
19976
|
"sys.created_at",
|
|
@@ -19589,13 +19999,13 @@ function canGroupSavedViewChartByField(field, type) {
|
|
|
19589
19999
|
function canUseSavedViewChartMeasureField(field, type) {
|
|
19590
20000
|
return field.startsWith("prop.") && type === "number";
|
|
19591
20001
|
}
|
|
19592
|
-
var savedViewChartDimensionSchema =
|
|
20002
|
+
var savedViewChartDimensionSchema = z4.object({
|
|
19593
20003
|
field: savedViewFieldRefSchema,
|
|
19594
|
-
timeBucket:
|
|
20004
|
+
timeBucket: z4.enum(SAVED_VIEW_CHART_TIME_BUCKETS).optional()
|
|
19595
20005
|
}).superRefine((dimension, context) => {
|
|
19596
20006
|
if (dimension.field === "sys.primary_resource_type" || dimension.field === "sys.title" || dimension.field === "sys.images" || isSavedViewDisplayOnlyField(dimension.field)) {
|
|
19597
20007
|
context.addIssue({
|
|
19598
|
-
code:
|
|
20008
|
+
code: z4.ZodIssueCode.custom,
|
|
19599
20009
|
path: ["field"],
|
|
19600
20010
|
message: `${dimension.field} cannot be used as a chart dimension`
|
|
19601
20011
|
});
|
|
@@ -19604,56 +20014,56 @@ var savedViewChartDimensionSchema = z2.object({
|
|
|
19604
20014
|
const isDate = SYS_DATE_FIELD_REFS.has(dimension.field);
|
|
19605
20015
|
if (isDate && !dimension.timeBucket) {
|
|
19606
20016
|
context.addIssue({
|
|
19607
|
-
code:
|
|
20017
|
+
code: z4.ZodIssueCode.custom,
|
|
19608
20018
|
path: ["timeBucket"],
|
|
19609
20019
|
message: "Date chart dimensions require a timeBucket"
|
|
19610
20020
|
});
|
|
19611
20021
|
}
|
|
19612
20022
|
if (!isDate && dimension.timeBucket) {
|
|
19613
20023
|
context.addIssue({
|
|
19614
|
-
code:
|
|
20024
|
+
code: z4.ZodIssueCode.custom,
|
|
19615
20025
|
path: ["timeBucket"],
|
|
19616
20026
|
message: "timeBucket is only allowed on date chart dimensions"
|
|
19617
20027
|
});
|
|
19618
20028
|
}
|
|
19619
20029
|
}
|
|
19620
20030
|
});
|
|
19621
|
-
var savedViewChartBinaryExprSchema =
|
|
19622
|
-
op:
|
|
20031
|
+
var savedViewChartBinaryExprSchema = z4.object({
|
|
20032
|
+
op: z4.enum(SAVED_VIEW_CHART_EXPR_OPS),
|
|
19623
20033
|
left: savedViewFieldRefSchema,
|
|
19624
20034
|
right: savedViewFieldRefSchema
|
|
19625
20035
|
}).superRefine((expr, context) => {
|
|
19626
20036
|
if (!expr.left.startsWith("prop.")) {
|
|
19627
20037
|
context.addIssue({
|
|
19628
|
-
code:
|
|
20038
|
+
code: z4.ZodIssueCode.custom,
|
|
19629
20039
|
path: ["left"],
|
|
19630
20040
|
message: "Chart expressions only support number property fields on the left"
|
|
19631
20041
|
});
|
|
19632
20042
|
}
|
|
19633
20043
|
if (!expr.right.startsWith("prop.")) {
|
|
19634
20044
|
context.addIssue({
|
|
19635
|
-
code:
|
|
20045
|
+
code: z4.ZodIssueCode.custom,
|
|
19636
20046
|
path: ["right"],
|
|
19637
20047
|
message: "Chart expressions only support number property fields on the right"
|
|
19638
20048
|
});
|
|
19639
20049
|
}
|
|
19640
20050
|
});
|
|
19641
|
-
var savedViewChartMeasureSchema =
|
|
20051
|
+
var savedViewChartMeasureSchema = z4.object({
|
|
19642
20052
|
field: savedViewFieldRefSchema.nullable(),
|
|
19643
|
-
aggregation:
|
|
20053
|
+
aggregation: z4.enum(SAVED_VIEW_CHART_AGGREGATIONS),
|
|
19644
20054
|
expr: savedViewChartBinaryExprSchema.optional()
|
|
19645
20055
|
}).superRefine((measure, context) => {
|
|
19646
20056
|
if (measure.aggregation === "count") {
|
|
19647
20057
|
if (measure.field !== null) {
|
|
19648
20058
|
context.addIssue({
|
|
19649
|
-
code:
|
|
20059
|
+
code: z4.ZodIssueCode.custom,
|
|
19650
20060
|
path: ["field"],
|
|
19651
20061
|
message: "count does not accept a measure field"
|
|
19652
20062
|
});
|
|
19653
20063
|
}
|
|
19654
20064
|
if (measure.expr) {
|
|
19655
20065
|
context.addIssue({
|
|
19656
|
-
code:
|
|
20066
|
+
code: z4.ZodIssueCode.custom,
|
|
19657
20067
|
path: ["expr"],
|
|
19658
20068
|
message: "count does not accept a measure expression"
|
|
19659
20069
|
});
|
|
@@ -19664,43 +20074,43 @@ var savedViewChartMeasureSchema = z2.object({
|
|
|
19664
20074
|
const hasExpr = measure.expr !== void 0;
|
|
19665
20075
|
if (hasField === hasExpr) {
|
|
19666
20076
|
context.addIssue({
|
|
19667
|
-
code:
|
|
20077
|
+
code: z4.ZodIssueCode.custom,
|
|
19668
20078
|
path: hasExpr ? ["field"] : ["expr"],
|
|
19669
20079
|
message: `${measure.aggregation} requires either a measure field or an expression, not both`
|
|
19670
20080
|
});
|
|
19671
20081
|
}
|
|
19672
20082
|
if (hasField && measure.field && !measure.field.startsWith("prop.")) {
|
|
19673
20083
|
context.addIssue({
|
|
19674
|
-
code:
|
|
20084
|
+
code: z4.ZodIssueCode.custom,
|
|
19675
20085
|
path: ["field"],
|
|
19676
20086
|
message: `${measure.aggregation} only supports number property fields`
|
|
19677
20087
|
});
|
|
19678
20088
|
}
|
|
19679
20089
|
});
|
|
19680
|
-
var savedViewChartSchema =
|
|
19681
|
-
id:
|
|
19682
|
-
title:
|
|
19683
|
-
type:
|
|
19684
|
-
dimensions:
|
|
19685
|
-
measures:
|
|
19686
|
-
orderBy:
|
|
19687
|
-
by:
|
|
19688
|
-
direction:
|
|
20090
|
+
var savedViewChartSchema = z4.object({
|
|
20091
|
+
id: z4.string().trim().min(1).max(64),
|
|
20092
|
+
title: z4.string().max(MAX_SAVED_VIEW_CHART_TITLE_LENGTH).optional(),
|
|
20093
|
+
type: z4.enum(SAVED_VIEW_CHART_TYPES),
|
|
20094
|
+
dimensions: z4.tuple([savedViewChartDimensionSchema]),
|
|
20095
|
+
measures: z4.tuple([savedViewChartMeasureSchema]),
|
|
20096
|
+
orderBy: z4.object({
|
|
20097
|
+
by: z4.enum(["bucket", "value"]),
|
|
20098
|
+
direction: z4.enum(["asc", "desc"])
|
|
19689
20099
|
}).optional(),
|
|
19690
|
-
limit:
|
|
20100
|
+
limit: z4.number().int().min(1).max(MAX_SAVED_VIEW_CHART_LIMIT).optional()
|
|
19691
20101
|
}).superRefine((chart, context) => {
|
|
19692
20102
|
if (chart.type === "contribute" && chart.dimensions[0]?.timeBucket !== "day") {
|
|
19693
20103
|
context.addIssue({
|
|
19694
|
-
code:
|
|
20104
|
+
code: z4.ZodIssueCode.custom,
|
|
19695
20105
|
path: ["dimensions", 0, "timeBucket"],
|
|
19696
20106
|
message: "contribute charts require a day timeBucket dimension"
|
|
19697
20107
|
});
|
|
19698
20108
|
}
|
|
19699
20109
|
});
|
|
19700
|
-
var savedViewStatSchema =
|
|
19701
|
-
id:
|
|
19702
|
-
title:
|
|
19703
|
-
unit:
|
|
20110
|
+
var savedViewStatSchema = z4.object({
|
|
20111
|
+
id: z4.string().trim().min(1).max(64),
|
|
20112
|
+
title: z4.string().max(MAX_SAVED_VIEW_STAT_TITLE_LENGTH).optional(),
|
|
20113
|
+
unit: z4.string().trim().max(MAX_SAVED_VIEW_STAT_UNIT_LENGTH).optional(),
|
|
19704
20114
|
measure: savedViewChartMeasureSchema
|
|
19705
20115
|
});
|
|
19706
20116
|
var CALC_COLUMN_KEY_PATTERN = /^calc\.[0-9A-Za-z_-]{1,64}$/;
|
|
@@ -19708,36 +20118,36 @@ function isSavedViewTableColumnKey(value) {
|
|
|
19708
20118
|
if (isSavedViewFieldRef(value)) return true;
|
|
19709
20119
|
return typeof value === "string" && CALC_COLUMN_KEY_PATTERN.test(value);
|
|
19710
20120
|
}
|
|
19711
|
-
var savedViewTableColumnKeySchema =
|
|
20121
|
+
var savedViewTableColumnKeySchema = z4.custom(
|
|
19712
20122
|
isSavedViewTableColumnKey,
|
|
19713
20123
|
"Invalid saved view table column key"
|
|
19714
20124
|
);
|
|
19715
|
-
var savedViewComputedColumnSchema =
|
|
19716
|
-
id:
|
|
19717
|
-
title:
|
|
20125
|
+
var savedViewComputedColumnSchema = z4.object({
|
|
20126
|
+
id: z4.string().trim().min(1).max(64),
|
|
20127
|
+
title: z4.string().max(MAX_SAVED_VIEW_COMPUTED_COLUMN_TITLE_LENGTH).optional(),
|
|
19718
20128
|
expr: savedViewChartBinaryExprSchema
|
|
19719
20129
|
});
|
|
19720
|
-
var savedViewSummaryItemSchema =
|
|
20130
|
+
var savedViewSummaryItemSchema = z4.object({
|
|
19721
20131
|
column: savedViewTableColumnKeySchema,
|
|
19722
|
-
aggregation:
|
|
20132
|
+
aggregation: z4.enum(SAVED_VIEW_CHART_AGGREGATIONS)
|
|
19723
20133
|
});
|
|
19724
|
-
var savedViewConfigSchema =
|
|
19725
|
-
version:
|
|
19726
|
-
noteDetail:
|
|
20134
|
+
var savedViewConfigSchema = z4.object({
|
|
20135
|
+
version: z4.literal(1),
|
|
20136
|
+
noteDetail: z4.object({
|
|
19727
20137
|
field: savedViewFieldRefSchema,
|
|
19728
|
-
value:
|
|
20138
|
+
value: z4.union([z4.string().min(1), z4.number().finite(), z4.boolean()])
|
|
19729
20139
|
}).optional(),
|
|
19730
|
-
layout:
|
|
19731
|
-
columns:
|
|
19732
|
-
sort:
|
|
19733
|
-
stats:
|
|
19734
|
-
charts:
|
|
19735
|
-
computedColumns:
|
|
19736
|
-
summary:
|
|
20140
|
+
layout: z4.enum(SAVED_VIEW_LAYOUTS),
|
|
20141
|
+
columns: z4.array(savedViewColumnSchema).min(1).max(100),
|
|
20142
|
+
sort: z4.array(savedViewSortSchema).max(20).optional(),
|
|
20143
|
+
stats: z4.array(savedViewStatSchema).max(MAX_SAVED_VIEW_STATS).optional(),
|
|
20144
|
+
charts: z4.array(savedViewChartSchema).max(MAX_SAVED_VIEW_CHARTS).optional(),
|
|
20145
|
+
computedColumns: z4.array(savedViewComputedColumnSchema).max(MAX_SAVED_VIEW_COMPUTED_COLUMNS).optional(),
|
|
20146
|
+
summary: z4.array(savedViewSummaryItemSchema).max(MAX_SAVED_VIEW_SUMMARY_ITEMS).optional()
|
|
19737
20147
|
}).superRefine((config, context) => {
|
|
19738
20148
|
if (config.columns[0]?.field !== "sys.title") {
|
|
19739
20149
|
context.addIssue({
|
|
19740
|
-
code:
|
|
20150
|
+
code: z4.ZodIssueCode.custom,
|
|
19741
20151
|
path: ["columns", 0, "field"],
|
|
19742
20152
|
message: "The title field must be the first saved view column"
|
|
19743
20153
|
});
|
|
@@ -19746,7 +20156,7 @@ var savedViewConfigSchema = z2.object({
|
|
|
19746
20156
|
config.columns.forEach((column4, index) => {
|
|
19747
20157
|
if (columnFields.has(column4.field)) {
|
|
19748
20158
|
context.addIssue({
|
|
19749
|
-
code:
|
|
20159
|
+
code: z4.ZodIssueCode.custom,
|
|
19750
20160
|
path: ["columns", index, "field"],
|
|
19751
20161
|
message: "Saved view columns must be unique"
|
|
19752
20162
|
});
|
|
@@ -19757,7 +20167,7 @@ var savedViewConfigSchema = z2.object({
|
|
|
19757
20167
|
config.sort?.forEach((sort, index) => {
|
|
19758
20168
|
if (sortFields.has(sort.field)) {
|
|
19759
20169
|
context.addIssue({
|
|
19760
|
-
code:
|
|
20170
|
+
code: z4.ZodIssueCode.custom,
|
|
19761
20171
|
path: ["sort", index, "field"],
|
|
19762
20172
|
message: "Saved view sort fields must be unique"
|
|
19763
20173
|
});
|
|
@@ -19768,7 +20178,7 @@ var savedViewConfigSchema = z2.object({
|
|
|
19768
20178
|
config.stats?.forEach((stat, index) => {
|
|
19769
20179
|
if (statIds.has(stat.id)) {
|
|
19770
20180
|
context.addIssue({
|
|
19771
|
-
code:
|
|
20181
|
+
code: z4.ZodIssueCode.custom,
|
|
19772
20182
|
path: ["stats", index, "id"],
|
|
19773
20183
|
message: "Saved view stat ids must be unique"
|
|
19774
20184
|
});
|
|
@@ -19779,7 +20189,7 @@ var savedViewConfigSchema = z2.object({
|
|
|
19779
20189
|
config.charts?.forEach((chart, index) => {
|
|
19780
20190
|
if (chartIds.has(chart.id)) {
|
|
19781
20191
|
context.addIssue({
|
|
19782
|
-
code:
|
|
20192
|
+
code: z4.ZodIssueCode.custom,
|
|
19783
20193
|
path: ["charts", index, "id"],
|
|
19784
20194
|
message: "Saved view chart ids must be unique"
|
|
19785
20195
|
});
|
|
@@ -19790,7 +20200,7 @@ var savedViewConfigSchema = z2.object({
|
|
|
19790
20200
|
config.computedColumns?.forEach((column4, index) => {
|
|
19791
20201
|
if (computedColumnIds.has(column4.id)) {
|
|
19792
20202
|
context.addIssue({
|
|
19793
|
-
code:
|
|
20203
|
+
code: z4.ZodIssueCode.custom,
|
|
19794
20204
|
path: ["computedColumns", index, "id"],
|
|
19795
20205
|
message: "Saved view computed column ids must be unique"
|
|
19796
20206
|
});
|
|
@@ -19801,7 +20211,7 @@ var savedViewConfigSchema = z2.object({
|
|
|
19801
20211
|
config.summary?.forEach((item, index) => {
|
|
19802
20212
|
if (summaryColumns.has(item.column)) {
|
|
19803
20213
|
context.addIssue({
|
|
19804
|
-
code:
|
|
20214
|
+
code: z4.ZodIssueCode.custom,
|
|
19805
20215
|
path: ["summary", index, "column"],
|
|
19806
20216
|
message: "Saved view summary columns must be unique"
|
|
19807
20217
|
});
|
|
@@ -19821,33 +20231,33 @@ function createDefaultSavedViewConfig() {
|
|
|
19821
20231
|
};
|
|
19822
20232
|
}
|
|
19823
20233
|
var MAX_SAVED_VIEW_NAME_LENGTH = 120;
|
|
19824
|
-
var generatedSavedViewPlanSchema =
|
|
19825
|
-
name:
|
|
20234
|
+
var generatedSavedViewPlanSchema = z4.object({
|
|
20235
|
+
name: z4.string().trim().min(1).max(MAX_SAVED_VIEW_NAME_LENGTH),
|
|
19826
20236
|
filter: savedViewFilterSchema,
|
|
19827
20237
|
config: savedViewConfigSchema
|
|
19828
20238
|
});
|
|
19829
|
-
var aiGenerateSavedViewPlanRequestSchema =
|
|
19830
|
-
prompt:
|
|
19831
|
-
modelSelector:
|
|
19832
|
-
locale:
|
|
19833
|
-
timeZone:
|
|
20239
|
+
var aiGenerateSavedViewPlanRequestSchema = z4.object({
|
|
20240
|
+
prompt: z4.string().trim().min(1).max(4e3),
|
|
20241
|
+
modelSelector: z4.string().trim().min(1).max(512).optional(),
|
|
20242
|
+
locale: z4.string().trim().min(1).max(35).optional(),
|
|
20243
|
+
timeZone: z4.string().trim().min(1).max(100).optional(),
|
|
19834
20244
|
current: generatedSavedViewPlanSchema.optional(),
|
|
19835
|
-
embedded:
|
|
20245
|
+
embedded: z4.boolean().optional()
|
|
19836
20246
|
}).strict();
|
|
19837
|
-
var savedViewEmbedInputSchema =
|
|
19838
|
-
userId:
|
|
19839
|
-
timeZone:
|
|
19840
|
-
noteId:
|
|
19841
|
-
viewId:
|
|
20247
|
+
var savedViewEmbedInputSchema = z4.object({
|
|
20248
|
+
userId: z4.string().trim().min(1),
|
|
20249
|
+
timeZone: z4.string().trim().min(1).max(100).optional(),
|
|
20250
|
+
noteId: z4.string().trim().min(1).max(200).optional(),
|
|
20251
|
+
viewId: z4.string().trim().min(1).max(200).optional(),
|
|
19842
20252
|
definition: generatedSavedViewPlanSchema.optional(),
|
|
19843
|
-
limit:
|
|
20253
|
+
limit: z4.number().int().positive().max(100).optional()
|
|
19844
20254
|
}).refine((input) => input.viewId === void 0 !== (input.definition === void 0), {
|
|
19845
20255
|
message: "Pass exactly one of viewId and definition"
|
|
19846
20256
|
});
|
|
19847
|
-
var savedViewZettelBoxDetailsSchema =
|
|
19848
|
-
|
|
19849
|
-
fullPath:
|
|
19850
|
-
color:
|
|
20257
|
+
var savedViewZettelBoxDetailsSchema = z4.array(
|
|
20258
|
+
z4.object({
|
|
20259
|
+
fullPath: z4.string().trim().min(1).max(1e3),
|
|
20260
|
+
color: z4.string().trim().max(200).nullable()
|
|
19851
20261
|
})
|
|
19852
20262
|
).max(100);
|
|
19853
20263
|
function parseSavedViewZettelBoxDetails(value) {
|
|
@@ -19859,171 +20269,171 @@ function parseSavedViewZettelBoxDetails(value) {
|
|
|
19859
20269
|
return [];
|
|
19860
20270
|
}
|
|
19861
20271
|
}
|
|
19862
|
-
var nullableShortStringSchema =
|
|
19863
|
-
var nullableIdSchema =
|
|
19864
|
-
var nullableTimestampSchema =
|
|
19865
|
-
var savedViewCatalogInputSchema =
|
|
19866
|
-
userId:
|
|
19867
|
-
limit:
|
|
20272
|
+
var nullableShortStringSchema = z4.string().trim().max(120).nullable();
|
|
20273
|
+
var nullableIdSchema = z4.string().trim().min(1).max(200).nullable();
|
|
20274
|
+
var nullableTimestampSchema = z4.string().trim().min(1).max(64).nullable();
|
|
20275
|
+
var savedViewCatalogInputSchema = z4.object({
|
|
20276
|
+
userId: z4.string().trim().min(1),
|
|
20277
|
+
limit: z4.number().int().positive().max(5e3).optional()
|
|
19868
20278
|
});
|
|
19869
|
-
var savedViewCreateInputSchema =
|
|
19870
|
-
userId:
|
|
19871
|
-
name:
|
|
20279
|
+
var savedViewCreateInputSchema = z4.object({
|
|
20280
|
+
userId: z4.string().trim().min(1),
|
|
20281
|
+
name: z4.string().trim().min(1).max(120),
|
|
19872
20282
|
emoji: nullableShortStringSchema.optional(),
|
|
19873
20283
|
filter: savedViewFilterSchema,
|
|
19874
20284
|
config: savedViewConfigSchema,
|
|
19875
20285
|
templateId: nullableIdSchema.optional(),
|
|
19876
20286
|
groupId: nullableIdSchema.optional(),
|
|
19877
|
-
sortRank:
|
|
20287
|
+
sortRank: z4.number().int().nullable().optional(),
|
|
19878
20288
|
pinnedAt: nullableTimestampSchema.optional(),
|
|
19879
|
-
updatedAt:
|
|
20289
|
+
updatedAt: z4.string().trim().min(1).max(64)
|
|
19880
20290
|
});
|
|
19881
|
-
var savedViewUpdateInputSchema =
|
|
19882
|
-
id:
|
|
19883
|
-
userId:
|
|
19884
|
-
name:
|
|
20291
|
+
var savedViewUpdateInputSchema = z4.object({
|
|
20292
|
+
id: z4.string().trim().min(1),
|
|
20293
|
+
userId: z4.string().trim().min(1),
|
|
20294
|
+
name: z4.string().trim().min(1).max(120).optional(),
|
|
19885
20295
|
emoji: nullableShortStringSchema.optional(),
|
|
19886
20296
|
filter: savedViewFilterSchema.optional(),
|
|
19887
20297
|
config: savedViewConfigSchema.optional(),
|
|
19888
20298
|
templateId: nullableIdSchema.optional(),
|
|
19889
20299
|
groupId: nullableIdSchema.optional(),
|
|
19890
|
-
sortRank:
|
|
20300
|
+
sortRank: z4.number().int().nullable().optional(),
|
|
19891
20301
|
pinnedAt: nullableTimestampSchema.optional(),
|
|
19892
|
-
updatedAt:
|
|
20302
|
+
updatedAt: z4.string().trim().min(1).max(64)
|
|
19893
20303
|
}).refine(
|
|
19894
20304
|
(input) => input.name !== void 0 || input.emoji !== void 0 || input.filter !== void 0 || input.config !== void 0 || input.templateId !== void 0 || input.groupId !== void 0 || input.sortRank !== void 0 || input.pinnedAt !== void 0,
|
|
19895
20305
|
{ message: "At least one saved-view field must be updated" }
|
|
19896
20306
|
);
|
|
19897
|
-
var savedViewSoftDeleteInputSchema =
|
|
19898
|
-
id:
|
|
19899
|
-
userId:
|
|
19900
|
-
updatedAt:
|
|
20307
|
+
var savedViewSoftDeleteInputSchema = z4.object({
|
|
20308
|
+
id: z4.string().trim().min(1),
|
|
20309
|
+
userId: z4.string().trim().min(1),
|
|
20310
|
+
updatedAt: z4.string().trim().min(1).max(64)
|
|
19901
20311
|
});
|
|
19902
|
-
var savedViewPageInputSchema =
|
|
19903
|
-
viewId:
|
|
19904
|
-
userId:
|
|
19905
|
-
timeZone:
|
|
19906
|
-
limit:
|
|
19907
|
-
offset:
|
|
20312
|
+
var savedViewPageInputSchema = z4.object({
|
|
20313
|
+
viewId: z4.string().trim().min(1),
|
|
20314
|
+
userId: z4.string().trim().min(1),
|
|
20315
|
+
timeZone: z4.string().trim().min(1).max(100).optional(),
|
|
20316
|
+
limit: z4.number().int().positive().max(500).optional(),
|
|
20317
|
+
offset: z4.number().int().nonnegative().optional()
|
|
19908
20318
|
});
|
|
19909
|
-
var savedViewCountInputSchema =
|
|
19910
|
-
viewId:
|
|
19911
|
-
userId:
|
|
19912
|
-
timeZone:
|
|
20319
|
+
var savedViewCountInputSchema = z4.object({
|
|
20320
|
+
viewId: z4.string().trim().min(1),
|
|
20321
|
+
userId: z4.string().trim().min(1),
|
|
20322
|
+
timeZone: z4.string().trim().min(1).max(100).optional()
|
|
19913
20323
|
});
|
|
19914
|
-
var savedViewAnalyticsInputSchema =
|
|
19915
|
-
viewId:
|
|
19916
|
-
userId:
|
|
19917
|
-
timeZone:
|
|
19918
|
-
draft:
|
|
19919
|
-
stats:
|
|
19920
|
-
charts:
|
|
19921
|
-
computedColumns:
|
|
19922
|
-
summary:
|
|
20324
|
+
var savedViewAnalyticsInputSchema = z4.object({
|
|
20325
|
+
viewId: z4.string().trim().min(1),
|
|
20326
|
+
userId: z4.string().trim().min(1),
|
|
20327
|
+
timeZone: z4.string().trim().min(1).max(100).optional(),
|
|
20328
|
+
draft: z4.object({
|
|
20329
|
+
stats: z4.array(savedViewStatSchema).max(MAX_SAVED_VIEW_STATS).optional(),
|
|
20330
|
+
charts: z4.array(savedViewChartSchema).max(MAX_SAVED_VIEW_CHARTS).optional(),
|
|
20331
|
+
computedColumns: z4.array(savedViewComputedColumnSchema).max(MAX_SAVED_VIEW_COMPUTED_COLUMNS).optional(),
|
|
20332
|
+
summary: z4.array(savedViewSummaryItemSchema).max(MAX_SAVED_VIEW_SUMMARY_ITEMS).optional()
|
|
19923
20333
|
}).optional()
|
|
19924
20334
|
});
|
|
19925
|
-
var savedViewNoteDetailInputSchema =
|
|
19926
|
-
userId:
|
|
19927
|
-
noteId:
|
|
19928
|
-
timeZone:
|
|
19929
|
-
limit:
|
|
20335
|
+
var savedViewNoteDetailInputSchema = z4.object({
|
|
20336
|
+
userId: z4.string().trim().min(1),
|
|
20337
|
+
noteId: z4.string().trim().min(1),
|
|
20338
|
+
timeZone: z4.string().trim().min(1).max(100).optional(),
|
|
20339
|
+
limit: z4.number().int().positive().max(100).optional()
|
|
19930
20340
|
});
|
|
19931
20341
|
|
|
19932
20342
|
// ../../packages/core/src/powersync/typed-rpc/domain/properties.ts
|
|
19933
20343
|
import { uuidv7 as uuidv72 } from "uuidv7";
|
|
19934
|
-
import { z as
|
|
20344
|
+
import { z as z5 } from "zod";
|
|
19935
20345
|
var PROPERTY_DEF_TABLE = "c_property_def";
|
|
19936
20346
|
var CONFIG_PROPERTY_TABLE = "c_config_property";
|
|
19937
20347
|
var NOTE_TABLE = "c_note";
|
|
19938
20348
|
var SAVED_VIEW_TABLE = "c_saved_view";
|
|
19939
20349
|
var PROPERTY_DEF_CONFIG_KEY_SQL_PREFIX = PROPERTY_DEF_CONFIG_KEY_PREFIX.replaceAll("'", "''");
|
|
19940
|
-
var NOTE_PROPERTY_KEY =
|
|
19941
|
-
var NOTE_PROPERTY_TEXT =
|
|
19942
|
-
var NOTE_PROPERTY_VALUE =
|
|
20350
|
+
var NOTE_PROPERTY_KEY = z5.string().min(1).max(NOTE_PROPERTY_LIMITS.keyLength).refine(isPropertyKeyValid);
|
|
20351
|
+
var NOTE_PROPERTY_TEXT = z5.string().max(NOTE_PROPERTY_LIMITS.textLength).refine((value) => value.trim().length > 0, "Property value cannot be blank");
|
|
20352
|
+
var NOTE_PROPERTY_VALUE = z5.union([
|
|
19943
20353
|
NOTE_PROPERTY_TEXT,
|
|
19944
|
-
|
|
19945
|
-
|
|
19946
|
-
|
|
19947
|
-
|
|
20354
|
+
z5.number().finite(),
|
|
20355
|
+
z5.boolean(),
|
|
20356
|
+
z5.array(NOTE_PROPERTY_TEXT).min(1).max(NOTE_PROPERTY_LIMITS.arrayLength),
|
|
20357
|
+
z5.custom(
|
|
19948
20358
|
(value) => {
|
|
19949
20359
|
const files = normalizeFilePropertyValue(value);
|
|
19950
20360
|
return files !== null && files.length > 0;
|
|
19951
20361
|
},
|
|
19952
20362
|
"Invalid file property value"
|
|
19953
20363
|
),
|
|
19954
|
-
|
|
20364
|
+
z5.custom(
|
|
19955
20365
|
(value) => normalizePlacePropertyValue(value) !== null,
|
|
19956
20366
|
"Invalid place property value"
|
|
19957
20367
|
)
|
|
19958
20368
|
]);
|
|
19959
|
-
var NOTE_PROPERTIES_PATCH =
|
|
20369
|
+
var NOTE_PROPERTIES_PATCH = z5.preprocess((patch, context) => {
|
|
19960
20370
|
if (patch && typeof patch === "object" && !Array.isArray(patch)) {
|
|
19961
20371
|
const invalidKey = Object.keys(patch).find((key) => !isPropertyKeyValid(key));
|
|
19962
20372
|
if (invalidKey !== void 0) {
|
|
19963
20373
|
context.addIssue({ code: "custom", message: "Invalid property key" });
|
|
19964
|
-
return
|
|
20374
|
+
return z5.NEVER;
|
|
19965
20375
|
}
|
|
19966
20376
|
}
|
|
19967
20377
|
return patch;
|
|
19968
|
-
},
|
|
20378
|
+
}, z5.record(NOTE_PROPERTY_KEY, NOTE_PROPERTY_VALUE.nullable())).refine((patch) => Object.keys(patch).length > 0, "Property patch cannot be empty").refine(
|
|
19969
20379
|
(patch) => Object.keys(patch).length <= NOTE_PROPERTY_LIMITS.mutationKeys,
|
|
19970
20380
|
"Property patch is too large"
|
|
19971
20381
|
);
|
|
19972
|
-
var NOTE_PROPERTY_VALUES =
|
|
20382
|
+
var NOTE_PROPERTY_VALUES = z5.preprocess((values, context) => {
|
|
19973
20383
|
if (values && typeof values === "object" && !Array.isArray(values)) {
|
|
19974
20384
|
const invalidKey = Object.keys(values).find((key) => !isPropertyKeyValid(key));
|
|
19975
20385
|
if (invalidKey !== void 0) {
|
|
19976
20386
|
context.addIssue({ code: "custom", message: "Invalid property key" });
|
|
19977
|
-
return
|
|
20387
|
+
return z5.NEVER;
|
|
19978
20388
|
}
|
|
19979
20389
|
}
|
|
19980
20390
|
return values;
|
|
19981
|
-
},
|
|
20391
|
+
}, z5.record(NOTE_PROPERTY_KEY, NOTE_PROPERTY_VALUE)).refine((values) => Object.keys(values).length > 0, "Property values cannot be empty").refine(
|
|
19982
20392
|
(values) => Object.keys(values).length <= NOTE_PROPERTY_LIMITS.mutationKeys,
|
|
19983
20393
|
"Property values are too large"
|
|
19984
20394
|
);
|
|
19985
|
-
var PROPERTY_OPTION_INPUT_SCHEMA =
|
|
19986
|
-
id:
|
|
19987
|
-
label:
|
|
19988
|
-
color:
|
|
19989
|
-
sortRank:
|
|
19990
|
-
archived:
|
|
19991
|
-
group:
|
|
20395
|
+
var PROPERTY_OPTION_INPUT_SCHEMA = z5.object({
|
|
20396
|
+
id: z5.string().trim().min(1).max(200).optional(),
|
|
20397
|
+
label: z5.string().min(1).max(PROPERTY_OPTION_LABEL_MAX_LENGTH),
|
|
20398
|
+
color: z5.enum(PROPERTY_OPTION_COLORS).optional(),
|
|
20399
|
+
sortRank: z5.number().int().safe().optional(),
|
|
20400
|
+
archived: z5.boolean().optional(),
|
|
20401
|
+
group: z5.enum(STATUS_PROPERTY_GROUPS).optional()
|
|
19992
20402
|
});
|
|
19993
|
-
var PROPERTY_DEF_CONFIG_INPUT_SCHEMA =
|
|
20403
|
+
var PROPERTY_DEF_CONFIG_INPUT_SCHEMA = z5.custom(
|
|
19994
20404
|
(value) => normalizePropertyDefConfig(value) !== void 0
|
|
19995
20405
|
);
|
|
19996
|
-
var PROPERTY_DEF_CATALOG_INPUT =
|
|
19997
|
-
userId:
|
|
19998
|
-
limit:
|
|
20406
|
+
var PROPERTY_DEF_CATALOG_INPUT = z5.object({
|
|
20407
|
+
userId: z5.string().trim().min(1),
|
|
20408
|
+
limit: z5.number().int().positive().max(5e3).optional()
|
|
19999
20409
|
});
|
|
20000
|
-
var PROPERTY_DEF_ENSURE_INPUT =
|
|
20001
|
-
key:
|
|
20002
|
-
name:
|
|
20003
|
-
type:
|
|
20004
|
-
optionItems:
|
|
20005
|
-
uniqueIdPrefix:
|
|
20006
|
-
numberPreset:
|
|
20410
|
+
var PROPERTY_DEF_ENSURE_INPUT = z5.object({
|
|
20411
|
+
key: z5.string().trim().min(1).max(64).refine(isPropertyKeyValid),
|
|
20412
|
+
name: z5.string().trim().max(120).nullable().optional(),
|
|
20413
|
+
type: z5.enum(ACTIVE_PROPERTY_TYPES).nullable().optional(),
|
|
20414
|
+
optionItems: z5.array(PROPERTY_OPTION_INPUT_SCHEMA).max(PROPERTY_OPTION_LIMITS.items).optional(),
|
|
20415
|
+
uniqueIdPrefix: z5.string().max(64).nullable().optional(),
|
|
20416
|
+
numberPreset: z5.enum(NUMBER_PROPERTY_PRESETS).nullable().optional(),
|
|
20007
20417
|
config: PROPERTY_DEF_CONFIG_INPUT_SCHEMA.optional(),
|
|
20008
|
-
description:
|
|
20009
|
-
icon:
|
|
20010
|
-
source:
|
|
20011
|
-
userId:
|
|
20012
|
-
updatedAt:
|
|
20418
|
+
description: z5.string().max(2e3).nullable().optional(),
|
|
20419
|
+
icon: z5.string().max(120).nullable().optional(),
|
|
20420
|
+
source: z5.enum(["manual", "ai"]).nullable().optional(),
|
|
20421
|
+
userId: z5.string().trim().min(1),
|
|
20422
|
+
updatedAt: z5.string().trim().min(1).max(64)
|
|
20013
20423
|
});
|
|
20014
|
-
var PROPERTY_DEF_CONFIGURE_INPUT =
|
|
20015
|
-
id:
|
|
20016
|
-
userId:
|
|
20017
|
-
name:
|
|
20018
|
-
description:
|
|
20019
|
-
icon:
|
|
20020
|
-
showOnCard:
|
|
20021
|
-
sortRank:
|
|
20022
|
-
options:
|
|
20023
|
-
uniqueIdPrefix:
|
|
20024
|
-
repairInvalidOptions:
|
|
20424
|
+
var PROPERTY_DEF_CONFIGURE_INPUT = z5.object({
|
|
20425
|
+
id: z5.string().trim().min(1),
|
|
20426
|
+
userId: z5.string().trim().min(1),
|
|
20427
|
+
name: z5.string().trim().max(120).nullable().optional(),
|
|
20428
|
+
description: z5.string().max(2e3).nullable().optional(),
|
|
20429
|
+
icon: z5.string().max(120).nullable().optional(),
|
|
20430
|
+
showOnCard: z5.boolean().nullable().optional(),
|
|
20431
|
+
sortRank: z5.number().int().nullable().optional(),
|
|
20432
|
+
options: z5.array(PROPERTY_OPTION_INPUT_SCHEMA).max(PROPERTY_OPTION_LIMITS.items).optional(),
|
|
20433
|
+
uniqueIdPrefix: z5.string().max(64).nullable().optional(),
|
|
20434
|
+
repairInvalidOptions: z5.boolean().optional(),
|
|
20025
20435
|
config: PROPERTY_DEF_CONFIG_INPUT_SCHEMA.nullable().optional(),
|
|
20026
|
-
updatedAt:
|
|
20436
|
+
updatedAt: z5.string().trim().min(1).max(64)
|
|
20027
20437
|
}).refine(
|
|
20028
20438
|
(input) => input.name !== void 0 || input.description !== void 0 || input.icon !== void 0 || input.showOnCard !== void 0 || input.sortRank !== void 0 || input.options !== void 0 || input.uniqueIdPrefix !== void 0 || input.config !== void 0,
|
|
20029
20439
|
{
|
|
@@ -20032,52 +20442,52 @@ var PROPERTY_DEF_CONFIGURE_INPUT = z3.object({
|
|
|
20032
20442
|
).refine((input) => !input.repairInvalidOptions || input.options !== void 0, {
|
|
20033
20443
|
message: "repairInvalidOptions requires replacement options"
|
|
20034
20444
|
});
|
|
20035
|
-
var PROPERTY_DEF_MIGRATE_LEGACY_OPTIONS_INPUT =
|
|
20036
|
-
userId:
|
|
20037
|
-
updatedAt:
|
|
20445
|
+
var PROPERTY_DEF_MIGRATE_LEGACY_OPTIONS_INPUT = z5.object({
|
|
20446
|
+
userId: z5.string().trim().min(1),
|
|
20447
|
+
updatedAt: z5.string().trim().min(1).max(64)
|
|
20038
20448
|
});
|
|
20039
|
-
var PROPERTY_DEF_UPDATE_INPUT =
|
|
20040
|
-
id:
|
|
20041
|
-
userId:
|
|
20042
|
-
name:
|
|
20043
|
-
description:
|
|
20044
|
-
icon:
|
|
20045
|
-
showOnCard:
|
|
20046
|
-
sortRank:
|
|
20047
|
-
updatedAt:
|
|
20449
|
+
var PROPERTY_DEF_UPDATE_INPUT = z5.object({
|
|
20450
|
+
id: z5.string().trim().min(1),
|
|
20451
|
+
userId: z5.string().trim().min(1),
|
|
20452
|
+
name: z5.string().trim().max(120).nullable().optional(),
|
|
20453
|
+
description: z5.string().max(2e3).nullable().optional(),
|
|
20454
|
+
icon: z5.string().max(120).nullable().optional(),
|
|
20455
|
+
showOnCard: z5.boolean().nullable().optional(),
|
|
20456
|
+
sortRank: z5.number().int().nullable().optional(),
|
|
20457
|
+
updatedAt: z5.string().trim().min(1).max(64)
|
|
20048
20458
|
});
|
|
20049
|
-
var PROPERTY_DEF_SOFT_DELETE_INPUT =
|
|
20050
|
-
id:
|
|
20051
|
-
userId:
|
|
20052
|
-
updatedAt:
|
|
20459
|
+
var PROPERTY_DEF_SOFT_DELETE_INPUT = z5.object({
|
|
20460
|
+
id: z5.string().trim().min(1),
|
|
20461
|
+
userId: z5.string().trim().min(1),
|
|
20462
|
+
updatedAt: z5.string().trim().min(1).max(64)
|
|
20053
20463
|
});
|
|
20054
|
-
var NOTE_PROPERTIES_UPDATE_INPUT =
|
|
20055
|
-
noteId:
|
|
20056
|
-
userId:
|
|
20464
|
+
var NOTE_PROPERTIES_UPDATE_INPUT = z5.object({
|
|
20465
|
+
noteId: z5.string().trim().min(1),
|
|
20466
|
+
userId: z5.string().trim().min(1),
|
|
20057
20467
|
patch: NOTE_PROPERTIES_PATCH,
|
|
20058
|
-
updatedAt:
|
|
20468
|
+
updatedAt: z5.string().trim().min(1).max(64)
|
|
20059
20469
|
});
|
|
20060
|
-
var NOTE_PROPERTY_SLOTS_UPDATE_INPUT =
|
|
20061
|
-
noteId:
|
|
20062
|
-
userId:
|
|
20063
|
-
operation:
|
|
20064
|
-
keys:
|
|
20065
|
-
updatedAt:
|
|
20470
|
+
var NOTE_PROPERTY_SLOTS_UPDATE_INPUT = z5.object({
|
|
20471
|
+
noteId: z5.string().trim().min(1),
|
|
20472
|
+
userId: z5.string().trim().min(1),
|
|
20473
|
+
operation: z5.enum(["declare", "clear", "remove"]),
|
|
20474
|
+
keys: z5.array(NOTE_PROPERTY_KEY).min(1).max(NOTE_PROPERTY_LIMITS.mutationKeys),
|
|
20475
|
+
updatedAt: z5.string().trim().min(1).max(64)
|
|
20066
20476
|
});
|
|
20067
|
-
var NOTE_PROPERTY_SLOTS_REORDER_INPUT =
|
|
20068
|
-
noteId:
|
|
20069
|
-
userId:
|
|
20070
|
-
orderedKeys:
|
|
20477
|
+
var NOTE_PROPERTY_SLOTS_REORDER_INPUT = z5.object({
|
|
20478
|
+
noteId: z5.string().trim().min(1),
|
|
20479
|
+
userId: z5.string().trim().min(1),
|
|
20480
|
+
orderedKeys: z5.array(NOTE_PROPERTY_KEY).min(2).max(NOTE_PROPERTY_LIMITS.mutationKeys).refine(
|
|
20071
20481
|
(keys) => new Set(keys).size === keys.length,
|
|
20072
20482
|
"Property slot order contains duplicates"
|
|
20073
20483
|
),
|
|
20074
|
-
updatedAt:
|
|
20484
|
+
updatedAt: z5.string().trim().min(1).max(64)
|
|
20075
20485
|
});
|
|
20076
|
-
var NOTE_PROPERTIES_FILL_EMPTY_INPUT =
|
|
20077
|
-
noteId:
|
|
20078
|
-
userId:
|
|
20486
|
+
var NOTE_PROPERTIES_FILL_EMPTY_INPUT = z5.object({
|
|
20487
|
+
noteId: z5.string().trim().min(1),
|
|
20488
|
+
userId: z5.string().trim().min(1),
|
|
20079
20489
|
values: NOTE_PROPERTY_VALUES,
|
|
20080
|
-
updatedAt:
|
|
20490
|
+
updatedAt: z5.string().trim().min(1).max(64)
|
|
20081
20491
|
});
|
|
20082
20492
|
function createPropertyReadModels() {
|
|
20083
20493
|
return [
|
|
@@ -21491,14 +21901,11 @@ var AGENT_WRITABLE_PROPERTY_TYPES = new Set(
|
|
|
21491
21901
|
)
|
|
21492
21902
|
);
|
|
21493
21903
|
|
|
21494
|
-
// ../../packages/powersync/child-notes.ts
|
|
21495
|
-
var topLevelNoteCondition = (alias) => `${alias ? `${alias}.` : ""}parent_id IS NULL`;
|
|
21496
|
-
|
|
21497
21904
|
// ../../packages/core/src/powersync/typed-rpc/domain/saved-views.ts
|
|
21498
21905
|
import { uuidv7 as uuidv73 } from "uuidv7";
|
|
21499
21906
|
|
|
21500
21907
|
// ../../packages/core/src/powersync/PowerSyncTransportUtils.ts
|
|
21501
|
-
import { z as
|
|
21908
|
+
import { z as z6 } from "zod";
|
|
21502
21909
|
function rowsFromResult(result) {
|
|
21503
21910
|
if (!result) {
|
|
21504
21911
|
return [];
|
|
@@ -23225,10 +23632,10 @@ async function softDeleteSavedView(db, input) {
|
|
|
23225
23632
|
|
|
23226
23633
|
// src/commands/domain/run.ts
|
|
23227
23634
|
var COMMANDS = new Map(
|
|
23228
|
-
[...createPropertyCommands(), ...createSavedViewCommands(), ...createNoteTemplateCommands()].map((definition) => [definition.name, definition])
|
|
23635
|
+
[...createPropertyCommands(), ...createSavedViewCommands(), ...createNoteTemplateCommands(), ...createNoteLifecycleCommands()].map((definition) => [definition.name, definition])
|
|
23229
23636
|
);
|
|
23230
23637
|
var READ_MODELS = new Map(
|
|
23231
|
-
[...createPropertyReadModels(), ...createSavedViewReadModels(), ...createNoteTemplateReadModels()].map((definition) => [definition.name, definition])
|
|
23638
|
+
[...createPropertyReadModels(), ...createSavedViewReadModels(), ...createNoteTemplateReadModels(), ...createNoteLifecycleReadModels()].map((definition) => [definition.name, definition])
|
|
23232
23639
|
);
|
|
23233
23640
|
var DOMAIN_CODE_PATTERN = /^[A-Z][A-Z0-9_]+$/;
|
|
23234
23641
|
function zodIssues(error) {
|
|
@@ -23619,6 +24026,12 @@ function parseMetaPatch(input) {
|
|
|
23619
24026
|
if (raw.tags !== void 0) patch.tags = stringList(raw.tags, "tags");
|
|
23620
24027
|
if (raw.boxes !== void 0) patch.boxes = stringList(raw.boxes, "boxes");
|
|
23621
24028
|
if (raw.starred !== void 0) patch.starred = Boolean(raw.starred);
|
|
24029
|
+
if (raw.pinned !== void 0) patch.pinned = Boolean(raw.pinned);
|
|
24030
|
+
if (raw.isPublic !== void 0) patch.isPublic = Boolean(raw.isPublic);
|
|
24031
|
+
if (raw.type !== void 0) {
|
|
24032
|
+
if (raw.type !== "note" && raw.type !== "crawl") throw usage('type must be "note" or "crawl"');
|
|
24033
|
+
patch.type = raw.type;
|
|
24034
|
+
}
|
|
23622
24035
|
if (raw.declare !== void 0) patch.declare = stringList(raw.declare, "declare");
|
|
23623
24036
|
if (raw.remove !== void 0) patch.remove = stringList(raw.remove, "remove");
|
|
23624
24037
|
if (raw.properties !== void 0) {
|
|
@@ -23630,7 +24043,7 @@ function parseMetaPatch(input) {
|
|
|
23630
24043
|
function createMetaStore(db, userId) {
|
|
23631
24044
|
const row = async (noteId) => {
|
|
23632
24045
|
const found = await db.getOptional(
|
|
23633
|
-
"SELECT id, title, tags, zettel_boxes, starred_at, created_at, updated_at, version, is_del FROM c_note WHERE id = ?",
|
|
24046
|
+
"SELECT id, title, tags, zettel_boxes, starred_at, is_top, is_pub, type, created_at, updated_at, version, is_del FROM c_note WHERE id = ?",
|
|
23634
24047
|
[noteId]
|
|
23635
24048
|
);
|
|
23636
24049
|
if (!found || Number(found.is_del ?? 0) !== 0) {
|
|
@@ -23655,6 +24068,9 @@ function createMetaStore(db, userId) {
|
|
|
23655
24068
|
return { id, name: box?.name || "\u672A\u77E5\u6587\u4EF6\u5939", path: box?.path || "", color: box?.color || "" };
|
|
23656
24069
|
}),
|
|
23657
24070
|
starred: Boolean(note.starred_at),
|
|
24071
|
+
pinned: Number(note.is_top ?? 0) > 0,
|
|
24072
|
+
isPublic: isPublicFlag(note.is_pub),
|
|
24073
|
+
type: note.type === "crawl" ? "crawl" : "note",
|
|
23658
24074
|
createdAt: note.created_at ?? null,
|
|
23659
24075
|
updatedAt: note.updated_at ?? null,
|
|
23660
24076
|
version: version(note.version),
|
|
@@ -23713,6 +24129,14 @@ function createMetaStore(db, userId) {
|
|
|
23713
24129
|
const result = await updateNote(db, fields);
|
|
23714
24130
|
changed.push(...result.changed);
|
|
23715
24131
|
}
|
|
24132
|
+
if (patch.pinned !== void 0 || patch.isPublic !== void 0) changed.push(...await setFlags(noteId, patch));
|
|
24133
|
+
if (patch.type !== void 0) {
|
|
24134
|
+
const current = await row(noteId);
|
|
24135
|
+
if ((current.type === "crawl" ? "crawl" : "note") !== patch.type) {
|
|
24136
|
+
await runDomainCommand(db, "notes.updateType", { noteId, type: patch.type, updatedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
24137
|
+
changed.push("type");
|
|
24138
|
+
}
|
|
24139
|
+
}
|
|
23716
24140
|
if (patch.declare?.length) {
|
|
23717
24141
|
const result = await updateNotePropertySlots2(db, { userId, noteId, operation: "declare", keys: patch.declare });
|
|
23718
24142
|
if (result.changed) changed.push("properties");
|
|
@@ -23736,7 +24160,127 @@ function createMetaStore(db, userId) {
|
|
|
23736
24160
|
}
|
|
23737
24161
|
return { changed: [...new Set(changed)], meta: await meta(noteId) };
|
|
23738
24162
|
}
|
|
23739
|
-
|
|
24163
|
+
async function setFlags(noteId, patch) {
|
|
24164
|
+
const current = await row(noteId);
|
|
24165
|
+
const sets = [];
|
|
24166
|
+
const params = [];
|
|
24167
|
+
const changed = [];
|
|
24168
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
24169
|
+
if (patch.pinned !== void 0 && patch.pinned !== Number(current.is_top ?? 0) > 0) {
|
|
24170
|
+
let top = 0;
|
|
24171
|
+
if (patch.pinned) {
|
|
24172
|
+
const [max] = await fetchDomainReadModel(db, "notes.maxActiveTop", void 0);
|
|
24173
|
+
top = (Number(max?.max_top ?? 0) || 0) + 1;
|
|
24174
|
+
}
|
|
24175
|
+
sets.push("is_top = ?", "pinned_at = ?");
|
|
24176
|
+
params.push(top, patch.pinned ? now : null);
|
|
24177
|
+
changed.push("pinned");
|
|
24178
|
+
}
|
|
24179
|
+
if (patch.isPublic !== void 0 && patch.isPublic !== isPublicFlag(current.is_pub)) {
|
|
24180
|
+
sets.push("is_pub = ?");
|
|
24181
|
+
params.push(patch.isPublic ? 1 : 0);
|
|
24182
|
+
changed.push("isPublic");
|
|
24183
|
+
}
|
|
24184
|
+
if (!sets.length) return [];
|
|
24185
|
+
sets.push("updated_at = ?", "version = COALESCE(version, 0) + 1");
|
|
24186
|
+
params.push(nextMonotonicUpdatedAt(current.updated_at, { timestamp: now }), noteId);
|
|
24187
|
+
await db.execute(`UPDATE c_note SET ${sets.join(", ")} WHERE id = ?`, params);
|
|
24188
|
+
return changed;
|
|
24189
|
+
}
|
|
24190
|
+
async function trash(noteId) {
|
|
24191
|
+
await row(noteId);
|
|
24192
|
+
await runDomainCommand(db, "notes.softDelete", { noteId, updatedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
24193
|
+
}
|
|
24194
|
+
return { meta, catalog, update, trash };
|
|
24195
|
+
}
|
|
24196
|
+
function isPublicFlag(value) {
|
|
24197
|
+
if (value === true) return true;
|
|
24198
|
+
if (typeof value === "string") return ["1", "true"].includes(value.trim().toLowerCase());
|
|
24199
|
+
return Number(value) === 1;
|
|
24200
|
+
}
|
|
24201
|
+
|
|
24202
|
+
// src/editor/tree.ts
|
|
24203
|
+
var TREE_INBOX = "inbox";
|
|
24204
|
+
var ACTIVE_TOP_LEVEL = `(n.is_del IS NULL OR n.is_del = 0) AND (n.parent_id IS NULL OR TRIM(n.parent_id) = '')`;
|
|
24205
|
+
var BOX_ITEMS = `json_each(CASE WHEN json_valid(COALESCE(n.zettel_boxes, '')) THEN n.zettel_boxes ELSE '[]' END)`;
|
|
24206
|
+
var NO_BOX = `NOT EXISTS (SELECT 1 FROM ${BOX_ITEMS} b WHERE TRIM(CAST(b.value AS TEXT)) <> '')`;
|
|
24207
|
+
function createTreeSource(db) {
|
|
24208
|
+
async function level(parent, offset, limit) {
|
|
24209
|
+
if (parent === TREE_INBOX) return { folders: [], ...await notesIn(null, offset, limit) };
|
|
24210
|
+
const boxes = await listBoxes(db);
|
|
24211
|
+
const known = new Set(boxes.map((box) => box.id));
|
|
24212
|
+
const counts = new Map(
|
|
24213
|
+
(await db.getAll(
|
|
24214
|
+
`SELECT TRIM(CAST(b.value AS TEXT)) AS id, COUNT(DISTINCT n.id) AS n FROM c_note n, ${BOX_ITEMS} b WHERE ${ACTIVE_TOP_LEVEL} GROUP BY 1`
|
|
24215
|
+
)).map((row) => [row.id, Number(row.n) || 0])
|
|
24216
|
+
);
|
|
24217
|
+
const subfolders = /* @__PURE__ */ new Map();
|
|
24218
|
+
for (const box of boxes) {
|
|
24219
|
+
const at = box.parentId && known.has(box.parentId) ? box.parentId : "";
|
|
24220
|
+
subfolders.set(at, (subfolders.get(at) ?? 0) + 1);
|
|
24221
|
+
}
|
|
24222
|
+
const folders = boxes.filter((box) => (box.parentId && known.has(box.parentId) ? box.parentId : null) === parent).sort((a, b) => a.name.localeCompare(b.name, "zh-Hans-CN", { numeric: true })).map((box) => ({
|
|
24223
|
+
id: box.id,
|
|
24224
|
+
name: box.name,
|
|
24225
|
+
path: box.path,
|
|
24226
|
+
color: box.color,
|
|
24227
|
+
folders: subfolders.get(box.id) ?? 0,
|
|
24228
|
+
notes: counts.get(box.id) ?? 0
|
|
24229
|
+
}));
|
|
24230
|
+
if (parent === null) {
|
|
24231
|
+
const inbox = await db.getOptional(`SELECT COUNT(*) AS n FROM c_note n WHERE ${ACTIVE_TOP_LEVEL} AND ${NO_BOX}`);
|
|
24232
|
+
return { folders, notes: [], more: 0, inbox: Number(inbox?.n) || 0 };
|
|
24233
|
+
}
|
|
24234
|
+
return { folders, ...await notesIn(parent, offset, limit) };
|
|
24235
|
+
}
|
|
24236
|
+
async function notesIn(boxId, offset, limit) {
|
|
24237
|
+
const where = boxId === null ? `${ACTIVE_TOP_LEVEL} AND ${NO_BOX}` : `${ACTIVE_TOP_LEVEL} AND EXISTS (SELECT 1 FROM ${BOX_ITEMS} b WHERE TRIM(CAST(b.value AS TEXT)) = ?)`;
|
|
24238
|
+
const params = boxId === null ? [] : [boxId];
|
|
24239
|
+
const total = Number((await db.getOptional(`SELECT COUNT(*) AS n FROM c_note n WHERE ${where}`, params))?.n) || 0;
|
|
24240
|
+
const rows = await db.getAll(
|
|
24241
|
+
`SELECT n.id, n.title, n.updated_at, n.created_at, n.is_top, n.type FROM c_note n WHERE ${where}
|
|
24242
|
+
ORDER BY CAST(COALESCE(n.is_top, 0) AS INTEGER) DESC, COALESCE(n.updated_at, n.created_at) DESC, n.id DESC
|
|
24243
|
+
LIMIT ? OFFSET ?`,
|
|
24244
|
+
[...params, limit, offset]
|
|
24245
|
+
);
|
|
24246
|
+
return {
|
|
24247
|
+
notes: rows.map((row) => ({
|
|
24248
|
+
id: row.id,
|
|
24249
|
+
title: row.title?.trim() ?? "",
|
|
24250
|
+
updatedAt: row.updated_at ?? row.created_at ?? null,
|
|
24251
|
+
pinned: Number(row.is_top ?? 0) > 0,
|
|
24252
|
+
type: row.type === "crawl" ? "crawl" : "note"
|
|
24253
|
+
})),
|
|
24254
|
+
more: Math.max(0, total - offset - rows.length)
|
|
24255
|
+
};
|
|
24256
|
+
}
|
|
24257
|
+
async function expandTags(names) {
|
|
24258
|
+
if (!names.length) return [];
|
|
24259
|
+
const all = await listTags(db);
|
|
24260
|
+
return names.map((name) => {
|
|
24261
|
+
const wanted = name.toLowerCase();
|
|
24262
|
+
const matches = all.filter((tag) => {
|
|
24263
|
+
const lower = tag.toLowerCase();
|
|
24264
|
+
return lower === wanted || lower.startsWith(`${wanted}/`);
|
|
24265
|
+
});
|
|
24266
|
+
return matches.length ? matches : [name];
|
|
24267
|
+
});
|
|
24268
|
+
}
|
|
24269
|
+
return { level, expandTags };
|
|
24270
|
+
}
|
|
24271
|
+
function parseTreeQuery(query) {
|
|
24272
|
+
const tags = [];
|
|
24273
|
+
const text = query.split(/\s+/).filter((term) => {
|
|
24274
|
+
const match = /^[##](.+)$/.exec(term);
|
|
24275
|
+
if (!match) return true;
|
|
24276
|
+
tags.push(match[1].replace(/[##]+$/, ""));
|
|
24277
|
+
return false;
|
|
24278
|
+
}).join(" ").trim();
|
|
24279
|
+
return { text, tags: [...new Set(tags.filter(Boolean))] };
|
|
24280
|
+
}
|
|
24281
|
+
function tagExpression(groups) {
|
|
24282
|
+
const parts = groups.map((group) => group.filter((tag) => !tag.includes('"')).map((tag) => `"${tag}"`)).filter((group) => group.length).map((group) => group.length > 1 ? `(${group.join(" OR ")})` : group[0]);
|
|
24283
|
+
return parts.length ? parts.join(" AND ") : void 0;
|
|
23740
24284
|
}
|
|
23741
24285
|
|
|
23742
24286
|
// src/commands/savedViews/fields.ts
|
|
@@ -24560,10 +25104,13 @@ function createEditorStore(db, options2) {
|
|
|
24560
25104
|
return row;
|
|
24561
25105
|
};
|
|
24562
25106
|
const meta = createMetaStore(db, options2.userId);
|
|
25107
|
+
const tree = createTreeSource(db);
|
|
24563
25108
|
return {
|
|
24564
25109
|
meta: meta.meta,
|
|
24565
25110
|
catalog: meta.catalog,
|
|
24566
25111
|
updateMeta: meta.update,
|
|
25112
|
+
trash: meta.trash,
|
|
25113
|
+
tree: tree.level,
|
|
24567
25114
|
views: () => listEditorViews(db, options2.userId),
|
|
24568
25115
|
viewEmbed: (request) => fetchEditorViewEmbed(db, options2.userId, request),
|
|
24569
25116
|
async load(noteId) {
|
|
@@ -24577,8 +25124,10 @@ function createEditorStore(db, options2) {
|
|
|
24577
25124
|
return { status: result.status, hash: result.hash, version: result.version, updatedAt: result.updatedAt };
|
|
24578
25125
|
},
|
|
24579
25126
|
async search(query, limit) {
|
|
24580
|
-
|
|
24581
|
-
|
|
25127
|
+
const { text, tags } = parseTreeQuery(query);
|
|
25128
|
+
if (text) await syncNoteTokenIndex(db);
|
|
25129
|
+
const tagsExpression = tagExpression(await tree.expandTags(tags));
|
|
25130
|
+
const { rows } = await searchNotesPage(db, text, { includeDeleted: false, limit, offset: 0, tagsExpression });
|
|
24582
25131
|
if (!rows.length) return [];
|
|
24583
25132
|
const dates = await db.getAll(
|
|
24584
25133
|
`SELECT id, updated_at FROM c_note WHERE id IN (${rows.map(() => "?").join(",")})`,
|
|
@@ -24610,6 +25159,59 @@ function createEditorStore(db, options2) {
|
|
|
24610
25159
|
};
|
|
24611
25160
|
}
|
|
24612
25161
|
|
|
25162
|
+
// src/editor/share.ts
|
|
25163
|
+
var SHARE_MISSING_CODE = "000404";
|
|
25164
|
+
var REQUEST_TIMEOUT_MS = 2e4;
|
|
25165
|
+
function createShareClient(deps) {
|
|
25166
|
+
async function request(method, pathname, body, missingOk = false) {
|
|
25167
|
+
let response;
|
|
25168
|
+
try {
|
|
25169
|
+
response = await (deps.fetchImpl ?? fetch)(`${deps.baseUrl ?? AI_SERVICE_URL}${pathname}`, {
|
|
25170
|
+
method,
|
|
25171
|
+
headers: {
|
|
25172
|
+
Authorization: toAuthorizationHeaderValue(deps.authorization),
|
|
25173
|
+
Accept: "application/json",
|
|
25174
|
+
...body === void 0 ? {} : { "Content-Type": "application/json" }
|
|
25175
|
+
},
|
|
25176
|
+
...body === void 0 ? {} : { body: JSON.stringify(body) },
|
|
25177
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
25178
|
+
});
|
|
25179
|
+
} catch (error) {
|
|
25180
|
+
throw new DinoxError(`Share request failed: ${error instanceof Error ? error.message : String(error)}`, { code: "COMMAND_FAILED", recoverable: true });
|
|
25181
|
+
}
|
|
25182
|
+
const json2 = await response.json().catch(() => null);
|
|
25183
|
+
if (missingOk && json2?.code === SHARE_MISSING_CODE) return null;
|
|
25184
|
+
if (response.status === 401 || response.status === 403) {
|
|
25185
|
+
throw new DinoxError("Sign in to Dinox again to share notes.", { code: "AUTH_REQUIRED", recoverable: true });
|
|
25186
|
+
}
|
|
25187
|
+
if (!response.ok || json2?.code !== AUTH_CODE_OK2 || json2.data == null) {
|
|
25188
|
+
throw new DinoxError(json2?.msg || `Share request failed (HTTP ${response.status})`, { code: "COMMAND_FAILED", recoverable: true });
|
|
25189
|
+
}
|
|
25190
|
+
return json2.data;
|
|
25191
|
+
}
|
|
25192
|
+
return async (action, noteId) => {
|
|
25193
|
+
const path14 = `/api/share/notes/${encodeURIComponent(noteId)}`;
|
|
25194
|
+
if (action === "revoke") {
|
|
25195
|
+
await request("POST", `${path14}/revoke`);
|
|
25196
|
+
return null;
|
|
25197
|
+
}
|
|
25198
|
+
const share = action === "create" ? await request("POST", path14, { expiresAt: null }) : await request("GET", path14, void 0, true);
|
|
25199
|
+
return share ? toEditorShare(share) : null;
|
|
25200
|
+
};
|
|
25201
|
+
}
|
|
25202
|
+
function toEditorShare(share) {
|
|
25203
|
+
if (!/^[a-z0-9]{12}$/.test(share.token)) {
|
|
25204
|
+
throw new DinoxError("The share link returned by Dinox is invalid.", { code: "COMMAND_FAILED", recoverable: true });
|
|
25205
|
+
}
|
|
25206
|
+
return {
|
|
25207
|
+
url: `${NOTE_SHARE_WEB_BASE_URL}/s/${share.token}`,
|
|
25208
|
+
hasPassword: Boolean(share.hasPassword),
|
|
25209
|
+
viewCount: Number(share.viewCount) || 0,
|
|
25210
|
+
expiresAt: share.expiresAt ?? null,
|
|
25211
|
+
status: share.status === "expired" ? "expired" : "active"
|
|
25212
|
+
};
|
|
25213
|
+
}
|
|
25214
|
+
|
|
24613
25215
|
// src/editor/persistence.ts
|
|
24614
25216
|
import { randomUUID } from "node:crypto";
|
|
24615
25217
|
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
@@ -25119,6 +25721,7 @@ function parseEditorUpload(input) {
|
|
|
25119
25721
|
|
|
25120
25722
|
// src/editor/service.ts
|
|
25121
25723
|
var MAX_TODO_SUGGESTIONS = 10;
|
|
25724
|
+
var TREE_PAGE = 100;
|
|
25122
25725
|
var MAX_KEY_LENGTH = 200;
|
|
25123
25726
|
var MAX_ACTIVITY = 80;
|
|
25124
25727
|
var MAX_SUGGESTIONS = 50;
|
|
@@ -25414,19 +26017,19 @@ var EditorService = class {
|
|
|
25414
26017
|
const edit = raw;
|
|
25415
26018
|
const reason = str2(edit.reason, "reason", { optional: true, max: 2e3 }) ?? "";
|
|
25416
26019
|
const base = { id: `s${randomUUID2().slice(0, 8)}`, reason, status: "pending", createdAt: new Date(this.now()).toISOString() };
|
|
25417
|
-
const
|
|
26020
|
+
const blockId2 = typeof edit.block === "string" ? blockRef(session.blocks, edit.block.trim()) : void 0;
|
|
25418
26021
|
if (edit.comment !== void 0 || edit.kind === "comment") {
|
|
25419
26022
|
const comment = str2(edit.comment, "comment", { max: 4e3 }).trim();
|
|
25420
26023
|
if (!comment) throw usage2("comment must not be empty");
|
|
25421
26024
|
const find2 = edit.find === void 0 || edit.find === "" ? void 0 : str2(edit.find, "find", { max: 2e4 });
|
|
25422
|
-
if (
|
|
25423
|
-
const block = session.blocks[this.blockIndex(session,
|
|
26025
|
+
if (blockId2) {
|
|
26026
|
+
const block = session.blocks[this.blockIndex(session, blockId2)];
|
|
25424
26027
|
if (find2 === void 0) {
|
|
25425
|
-
if (!block.text) throw usage2(`${
|
|
25426
|
-
return { ...base, kind: "comment", block:
|
|
26028
|
+
if (!block.text) throw usage2(`${blockId2} is empty; there is nothing to comment on`);
|
|
26029
|
+
return { ...base, kind: "comment", block: blockId2, find: block.text, comment, anchor: block.text, at: block.start };
|
|
25427
26030
|
}
|
|
25428
|
-
const located3 = this.locate(block.text, find2, "find",
|
|
25429
|
-
return { ...base, kind: "comment", block:
|
|
26031
|
+
const located3 = this.locate(block.text, find2, "find", blockId2);
|
|
26032
|
+
return { ...base, kind: "comment", block: blockId2, find: find2, comment, anchor: located3.anchor, at: block.start + located3.start };
|
|
25430
26033
|
}
|
|
25431
26034
|
if (find2 === void 0) throw usage2("a comment needs block (and optionally find), or find");
|
|
25432
26035
|
const located2 = this.locate(session.plainText, find2, "find");
|
|
@@ -25435,7 +26038,7 @@ var EditorService = class {
|
|
|
25435
26038
|
if (edit.markdown !== void 0 || edit.kind === "insert") {
|
|
25436
26039
|
const markdown = str2(edit.markdown, "markdown", { max: 5e4 });
|
|
25437
26040
|
if (!markdown.trim()) throw usage2("markdown must not be empty");
|
|
25438
|
-
const after = blockRef(session.blocks, (str2(edit.after ??
|
|
26041
|
+
const after = blockRef(session.blocks, (str2(edit.after ?? blockId2, "after", { max: 2e4 }) ?? "").trim());
|
|
25439
26042
|
if (!after) throw usage2('an insert needs after: a block id, "start" or "end"');
|
|
25440
26043
|
if (after === "end" || after === "<end>") return { ...base, kind: "insert", after: "<end>", markdown, anchor: "<end>" };
|
|
25441
26044
|
if (after === "start" || after === "<start>") return { ...base, kind: "insert", after: "<start>", markdown, anchor: "<start>" };
|
|
@@ -25451,22 +26054,22 @@ var EditorService = class {
|
|
|
25451
26054
|
if (edit.replace === void 0) throw usage2("each edit needs {block, replace}, {block, find, replace}, {after, markdown} or {block, find?, comment}");
|
|
25452
26055
|
const replace = str2(edit.replace, "replace", { max: 5e4 });
|
|
25453
26056
|
const find = edit.find === void 0 || edit.find === "" ? void 0 : str2(edit.find, "find", { max: 2e4 });
|
|
25454
|
-
if (
|
|
25455
|
-
const block = session.blocks[this.blockIndex(session,
|
|
26057
|
+
if (blockId2) {
|
|
26058
|
+
const block = session.blocks[this.blockIndex(session, blockId2)];
|
|
25456
26059
|
if (find !== void 0) {
|
|
25457
|
-
const located2 = this.locate(block.text, find, "find",
|
|
25458
|
-
return { ...base, kind: "replace", block:
|
|
26060
|
+
const located2 = this.locate(block.text, find, "find", blockId2);
|
|
26061
|
+
return { ...base, kind: "replace", block: blockId2, find, replace, anchor: located2.anchor, at: block.start + located2.start };
|
|
25459
26062
|
}
|
|
25460
|
-
if (!block.text) throw usage2(`${
|
|
25461
|
-
return { ...base, kind: "replace", block:
|
|
26063
|
+
if (!block.text) throw usage2(`${blockId2} is empty; add content with {after: "${blockId2}", markdown} instead`);
|
|
26064
|
+
return { ...base, kind: "replace", block: blockId2, find: block.text, replace: withoutLinePrefix(block.md, replace), anchor: block.text, at: block.start };
|
|
25462
26065
|
}
|
|
25463
26066
|
if (find === void 0) throw usage2("a replace needs block (and optionally find), or find");
|
|
25464
26067
|
const located = this.locate(session.plainText, find, "find");
|
|
25465
26068
|
return { ...base, kind: "replace", find, replace, anchor: located.anchor, at: located.start, block: this.blockAt(session, located.start)?.id };
|
|
25466
26069
|
}
|
|
25467
|
-
locate(text, find, name,
|
|
26070
|
+
locate(text, find, name, blockId2) {
|
|
25468
26071
|
const located = locateAnchor(text, find);
|
|
25469
|
-
const where =
|
|
26072
|
+
const where = blockId2 ? ` in ${blockId2}` : " in the note";
|
|
25470
26073
|
if (located.status === "missing") {
|
|
25471
26074
|
throw new DinoxError(`${name} "${clip2(find, 60)}" does not occur${where}; read the note again and quote it exactly.`, {
|
|
25472
26075
|
code: "EDITOR_ANCHOR_MISSING",
|
|
@@ -25474,7 +26077,7 @@ var EditorService = class {
|
|
|
25474
26077
|
});
|
|
25475
26078
|
}
|
|
25476
26079
|
if (located.status === "ambiguous") {
|
|
25477
|
-
throw new DinoxError(`${name} "${clip2(find, 60)}" occurs ${located.count} times${where}; ${
|
|
26080
|
+
throw new DinoxError(`${name} "${clip2(find, 60)}" occurs ${located.count} times${where}; ${blockId2 ? "quote more of the block" : "name the block, or quote more text"} so it is unique.`, {
|
|
25478
26081
|
code: "EDITOR_ANCHOR_AMBIGUOUS",
|
|
25479
26082
|
recoverable: true,
|
|
25480
26083
|
details: { count: located.count }
|
|
@@ -25557,9 +26160,16 @@ var EditorService = class {
|
|
|
25557
26160
|
}
|
|
25558
26161
|
async search(input) {
|
|
25559
26162
|
const query = str2(input.query ?? "", "query", { max: 500 });
|
|
25560
|
-
const limit = Math.max(1, Math.min(
|
|
26163
|
+
const limit = Math.max(1, Math.min(50, Number(input.limit) || 10));
|
|
25561
26164
|
return this.options.store.search(query, limit);
|
|
25562
26165
|
}
|
|
26166
|
+
/** One level of the sidebar's file tree: `parent` null is the root, `'inbox'` the unfiled notes. */
|
|
26167
|
+
async tree(input) {
|
|
26168
|
+
if (!this.options.store.tree) throw new DinoxError("This editor has no note tree.", { code: "COMMAND_FAILED", recoverable: false });
|
|
26169
|
+
const parent = input.parent == null || input.parent === "" ? null : str2(input.parent, "parent", { max: 200 });
|
|
26170
|
+
const offset = Math.max(0, Math.min(1e6, Math.trunc(Number(input.offset) || 0)));
|
|
26171
|
+
return this.options.store.tree(parent, offset, TREE_PAGE);
|
|
26172
|
+
}
|
|
25563
26173
|
/** The todo list for the panel; a `filter` it sends becomes the session's, so a reopened panel keeps it. */
|
|
25564
26174
|
async todos(key, input) {
|
|
25565
26175
|
const session = this.session(key);
|
|
@@ -25764,6 +26374,63 @@ var EditorService = class {
|
|
|
25764
26374
|
}
|
|
25765
26375
|
return { changed, meta, metaSeq: session.metaSeq };
|
|
25766
26376
|
}
|
|
26377
|
+
/**
|
|
26378
|
+
* Moves the open note (and its child cards) to the trash, like the desktop's delete, and
|
|
26379
|
+
* leaves the session without a note. The panel saves pending edits first.
|
|
26380
|
+
*/
|
|
26381
|
+
async trash(key, input) {
|
|
26382
|
+
const session = this.requireOpen(key);
|
|
26383
|
+
if (Number(input.openSeq) !== session.openSeq) {
|
|
26384
|
+
throw new DinoxError("The session has opened another note; this change was discarded.", { code: "EDITOR_STALE_SEQUENCE", recoverable: true });
|
|
26385
|
+
}
|
|
26386
|
+
if (session.dirty || session.saving !== null) {
|
|
26387
|
+
throw new DinoxError("The open note has unsaved changes; wait for them to save before deleting it.", { code: "EDITOR_UNSAVED_CHANGES", recoverable: true });
|
|
26388
|
+
}
|
|
26389
|
+
if (!this.options.store.trash) throw new DinoxError("This editor cannot delete notes.", { code: "COMMAND_FAILED", recoverable: false });
|
|
26390
|
+
const title = session.title;
|
|
26391
|
+
await this.options.store.trash(session.noteId);
|
|
26392
|
+
const blank = this.blank(session.key);
|
|
26393
|
+
Object.assign(session, {
|
|
26394
|
+
noteId: null,
|
|
26395
|
+
title: "",
|
|
26396
|
+
knownHash: null,
|
|
26397
|
+
knownVersion: null,
|
|
26398
|
+
doc: null,
|
|
26399
|
+
plainText: "",
|
|
26400
|
+
blocks: [],
|
|
26401
|
+
blocksDoc: null,
|
|
26402
|
+
mirrorRev: null,
|
|
26403
|
+
selection: blank.selection,
|
|
26404
|
+
dirty: false,
|
|
26405
|
+
suggestions: [],
|
|
26406
|
+
upload: null,
|
|
26407
|
+
remote: null,
|
|
26408
|
+
openSeq: session.openSeq + 1,
|
|
26409
|
+
route: "note"
|
|
26410
|
+
});
|
|
26411
|
+
session.meta = null;
|
|
26412
|
+
session.metaSeq++;
|
|
26413
|
+
this.record(session, "user", "save", { key: "\u628A\u300C{title}\u300D\u79FB\u5230\u4E86\u56DE\u6536\u7AD9", params: { title: title || "\u672A\u547D\u540D\u7B46\u8A18" } });
|
|
26414
|
+
void this.options.store.waitForUpload(UPLOAD_TIMEOUT_MS).catch(() => false);
|
|
26415
|
+
this.changed(session);
|
|
26416
|
+
this.updateWatch();
|
|
26417
|
+
return { ok: true, openSeq: session.openSeq };
|
|
26418
|
+
}
|
|
26419
|
+
/** Reads, creates or revokes the open note's share link. */
|
|
26420
|
+
async share(key, input) {
|
|
26421
|
+
const session = this.requireOpen(key);
|
|
26422
|
+
const action = input.action;
|
|
26423
|
+
if (action !== "get" && action !== "create" && action !== "revoke") throw usage2("action must be get, create or revoke");
|
|
26424
|
+
if (!this.options.share) {
|
|
26425
|
+
throw new DinoxError("Sharing needs a signed-in Dinox daemon.", { code: "AUTH_REQUIRED", recoverable: true });
|
|
26426
|
+
}
|
|
26427
|
+
const share = await this.options.share(action, session.noteId);
|
|
26428
|
+
if (action !== "get") {
|
|
26429
|
+
this.record(session, "user", "save", { key: action === "create" ? "\u5EFA\u7ACB\u4E86\u5206\u4EAB\u9023\u7D50" : "\u505C\u6B62\u5206\u4EAB" });
|
|
26430
|
+
this.changed(session);
|
|
26431
|
+
}
|
|
26432
|
+
return { share };
|
|
26433
|
+
}
|
|
25767
26434
|
note(key, input) {
|
|
25768
26435
|
const session = this.session(key);
|
|
25769
26436
|
const text = str2(input.text, "text", { max: 2e3 });
|
|
@@ -26222,6 +26889,9 @@ function describeMetaChange(changed, before, after) {
|
|
|
26222
26889
|
}
|
|
26223
26890
|
if (changed.includes("boxes")) parts.push(after.boxes.length ? { key: "\u79FB\u5230\u6587\u4EF6\u5939\u300C{boxes}\u300D", params: { boxes: after.boxes.map((box) => box.name) } } : { key: "\u79FB\u51FA\u4E86\u6587\u4EF6\u5939" });
|
|
26224
26891
|
if (changed.includes("is_starred")) parts.push({ key: after.starred ? "\u52A0\u4E0A\u661F\u6A19" : "\u53D6\u6D88\u661F\u6A19" });
|
|
26892
|
+
if (changed.includes("pinned")) parts.push({ key: after.pinned ? "\u7F6E\u9802\u4E86\u7B46\u8A18" : "\u53D6\u6D88\u7F6E\u9802" });
|
|
26893
|
+
if (changed.includes("isPublic")) parts.push({ key: after.isPublic ? "\u8A2D\u70BA\u516C\u958B" : "\u8A2D\u70BA\u79C1\u5BC6" });
|
|
26894
|
+
if (changed.includes("type")) parts.push({ key: after.type === "crawl" ? "\u8F49\u70BA\u7D20\u6750" : "\u8F49\u70BA\u7B46\u8A18" });
|
|
26225
26895
|
if (changed.includes("properties")) parts.push({ key: "\u66F4\u65B0\u4E86\u5C6C\u6027" });
|
|
26226
26896
|
return { key: "{clauses}", params: { clauses: parts } };
|
|
26227
26897
|
}
|
|
@@ -26255,6 +26925,7 @@ async function createDaemonEditorService(db, options2) {
|
|
|
26255
26925
|
restore: (entries) => uploaded(restoreTodoTasks(db, entries))
|
|
26256
26926
|
},
|
|
26257
26927
|
...options2.authorization ? {
|
|
26928
|
+
share: createShareClient({ authorization: options2.authorization }),
|
|
26258
26929
|
upload: async ({ name, mediaType, data, maxBytes }) => {
|
|
26259
26930
|
const sent = await uploadToOfficialStorage(
|
|
26260
26931
|
{ db, userId: options2.userId, authorization: options2.authorization },
|
|
@@ -26295,6 +26966,9 @@ var EDITOR_METHODS = /* @__PURE__ */ new Set([
|
|
|
26295
26966
|
"editor.log",
|
|
26296
26967
|
"editor.catalog",
|
|
26297
26968
|
"editor.updateMeta",
|
|
26969
|
+
"editor.trash",
|
|
26970
|
+
"editor.share",
|
|
26971
|
+
"editor.tree",
|
|
26298
26972
|
"editor.watchOpens",
|
|
26299
26973
|
"editor.showTodos",
|
|
26300
26974
|
"editor.todos",
|
|
@@ -26339,6 +27013,12 @@ async function handleEditorRequest(service, method, params, signal) {
|
|
|
26339
27013
|
return service.catalog();
|
|
26340
27014
|
case "editor.updateMeta":
|
|
26341
27015
|
return service.updateMeta(session, input);
|
|
27016
|
+
case "editor.trash":
|
|
27017
|
+
return service.trash(session, input);
|
|
27018
|
+
case "editor.share":
|
|
27019
|
+
return service.share(session, input);
|
|
27020
|
+
case "editor.tree":
|
|
27021
|
+
return service.tree(input);
|
|
26342
27022
|
case "editor.watchOpens":
|
|
26343
27023
|
return service.watchOpens(input, signal);
|
|
26344
27024
|
case "editor.showTodos":
|
|
@@ -26532,7 +27212,7 @@ var DaemonServer = class {
|
|
|
26532
27212
|
}
|
|
26533
27213
|
};
|
|
26534
27214
|
const execute = async () => {
|
|
26535
|
-
const { runCli } = await import("./runCli-
|
|
27215
|
+
const { runCli } = await import("./runCli-NSGPBNXJ.js");
|
|
26536
27216
|
const exitCode = await requestContext.run(context, () => runCli(input.argv));
|
|
26537
27217
|
return { stdout: context.stdout.join(""), stderr: context.stderr.join(""), exitCode };
|
|
26538
27218
|
};
|