@engenty/wizards-runtime 0.13.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/runtime/dist/agents/architect.js +8 -7
- package/apps/runtime/dist/agents/goose-connections.js +82 -0
- package/apps/runtime/dist/agents/space-agent.js +9 -2
- package/apps/runtime/dist/agents/studio-assistant.js +101 -67
- package/apps/runtime/dist/agents/website.js +1 -1
- package/apps/runtime/dist/app.js +17 -1
- package/apps/runtime/dist/assistant/knows.js +6 -5
- package/apps/runtime/dist/authoring/guide.js +25 -5
- package/apps/runtime/dist/broker/account.js +166 -0
- package/apps/runtime/dist/broker/call.js +417 -0
- package/apps/runtime/dist/broker/caller.js +10 -0
- package/apps/runtime/dist/broker/grant.js +152 -0
- package/apps/runtime/dist/broker/host.js +51 -0
- package/apps/runtime/dist/broker/index.js +8 -0
- package/apps/runtime/dist/broker/kept.js +31 -0
- package/apps/runtime/dist/broker/log.js +240 -0
- package/apps/runtime/dist/broker/registry.js +9 -0
- package/apps/runtime/dist/broker/rwx.js +367 -0
- package/apps/runtime/dist/broker/send.js +189 -0
- package/apps/runtime/dist/connectors/builtin.js +1 -1
- package/apps/runtime/dist/connectors/external.js +38 -37
- package/apps/runtime/dist/connectors/index.js +30 -91
- package/apps/runtime/dist/connectors/mail.js +0 -8
- package/apps/runtime/dist/connectors/person-sign-ins.js +73 -0
- package/apps/runtime/dist/connectors/plugin-connections.js +65 -92
- package/apps/runtime/dist/connectors/smtp.js +1 -1
- package/apps/runtime/dist/connectors/space-connections.js +436 -0
- package/apps/runtime/dist/db/adopt.js +3 -3
- package/apps/runtime/dist/db/client.js +26 -0
- package/apps/runtime/dist/db/live-triggers.js +65 -23
- package/apps/runtime/dist/db/migrations/tenant/0027_work_chats.sql +52 -0
- package/apps/runtime/dist/db/migrations/tenant/0028_chat_approvals.sql +17 -0
- package/apps/runtime/dist/db/migrations/tenant/0029_work_chats_live.sql +49 -0
- package/apps/runtime/dist/db/migrations/tenant/{0027_space_skill.sql → 0030_space_skill.sql} +8 -8
- package/apps/runtime/dist/db/migrations/tenant/0031_space.sql +624 -0
- package/apps/runtime/dist/db/migrations/tenant/0032_rwx_rule.sql +18 -0
- package/apps/runtime/dist/db/migrations/tenant/0033_broker_log.sql +23 -0
- package/apps/runtime/dist/db/migrations/tenant/0034_space_connection.sql +35 -0
- package/apps/runtime/dist/db/migrations/tenant/0035_run_grant.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/0036_approval_held_for.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/0037_ways_out.sql +5 -0
- package/apps/runtime/dist/db/migrations/tenant/0038_heard.sql +11 -0
- package/apps/runtime/dist/db/migrations/tenant/0039_members_studio.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0027_snapshot.json +383 -155
- package/apps/runtime/dist/db/migrations/tenant/meta/0028_snapshot.json +4468 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0029_snapshot.json +4475 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0030_snapshot.json +4629 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0031_snapshot.json +4629 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0032_snapshot.json +4757 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0033_snapshot.json +5039 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0034_snapshot.json +5022 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0035_snapshot.json +5029 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0036_snapshot.json +5037 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0037_snapshot.json +5076 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0038_snapshot.json +5145 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0039_snapshot.json +5153 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +86 -2
- package/apps/runtime/dist/db/schema.js +295 -72
- package/apps/runtime/dist/docs/dev/architecture.md +215 -0
- package/apps/runtime/dist/docs/dev/broker.md +298 -0
- package/apps/runtime/dist/docs/dev/index.md +5 -1
- package/apps/runtime/dist/docs/dev/integration/index.md +2 -0
- package/apps/runtime/dist/docs/dev/meta.json +3 -0
- package/apps/runtime/dist/docs/dev/plugins/connections.md +8 -5
- package/apps/runtime/dist/docs/dev/plugins/events.md +1 -1
- package/apps/runtime/dist/docs/dev/plugins/examples.md +1 -0
- package/apps/runtime/dist/docs/dev/plugins/index.md +2 -2
- package/apps/runtime/dist/docs/dev/plugins/reference.md +3 -2
- package/apps/runtime/dist/docs/dev/plugins/space.md +16 -6
- package/apps/runtime/dist/docs/dev/plugins/studio.md +2 -2
- package/apps/runtime/dist/docs/dev/plugins/tools.md +0 -1
- package/apps/runtime/dist/docs/dev/skills.md +16 -9
- package/apps/runtime/dist/docs/dev/wizard-format/agent-steps.md +40 -5
- package/apps/runtime/dist/docs/dev/wizard-format/lists-and-connections.md +17 -2
- package/apps/runtime/dist/docs/dev/wizard-format/templates.md +2 -0
- package/apps/runtime/dist/docs/dev/wizard-format/views-and-widgets.md +22 -2
- package/apps/runtime/dist/docs/user-guide/capabilities.md +132 -0
- package/apps/runtime/dist/docs/user-guide/cloud-sync.md +2 -0
- package/apps/runtime/dist/docs/user-guide/command-line.md +1 -0
- package/apps/runtime/dist/docs/user-guide/connectors.md +63 -7
- package/apps/runtime/dist/docs/user-guide/index.md +10 -1
- package/apps/runtime/dist/docs/user-guide/meta.json +6 -1
- package/apps/runtime/dist/docs/user-guide/protocol.md +80 -0
- package/apps/runtime/dist/docs/user-guide/skills.md +8 -4
- package/apps/runtime/dist/docs/user-guide/space.md +5 -4
- package/apps/runtime/dist/docs/user-guide/together.md +16 -2
- package/apps/runtime/dist/docs/user-guide/troubleshooting.md +2 -2
- package/apps/runtime/dist/docs/user-guide/work-mode.md +128 -0
- package/apps/runtime/dist/engenty/connections-external/build-connector.js +2 -5
- package/apps/runtime/dist/engenty/connections-external/importer/classify.js +72 -0
- package/apps/runtime/dist/engenty/connections-google/connectors/gmail.js +1 -1
- package/apps/runtime/dist/engenty/connections-microsoft/outlook.js +3 -2
- package/apps/runtime/dist/engenty/connections-sdk/types.js +2 -0
- package/apps/runtime/dist/engenty/connections-slack/connector.js +2 -1
- package/apps/runtime/dist/engine/resources.js +43 -12
- package/apps/runtime/dist/engine/runner.js +75 -23
- package/apps/runtime/dist/engine/steps.js +30 -12
- package/apps/runtime/dist/engine/template.js +18 -1
- package/apps/runtime/dist/env.js +9 -4
- package/apps/runtime/dist/index.js +18 -2
- package/apps/runtime/dist/live/feed.js +2 -2
- package/apps/runtime/dist/live/origin.js +2 -2
- package/apps/runtime/dist/live/views.js +51 -26
- package/apps/runtime/dist/manage.js +7 -0
- package/apps/runtime/dist/mcp/flow-app.js +1 -1
- package/apps/runtime/dist/mcp/tools.js +75 -34
- package/apps/runtime/dist/models.js +1 -1
- package/apps/runtime/dist/motion-graphics/project.js +8 -8
- package/apps/runtime/dist/motion-graphics/tools.js +1 -1
- package/apps/runtime/dist/plugins/events.js +2 -2
- package/apps/runtime/dist/plugins/jobs.js +4 -1
- package/apps/runtime/dist/plugins/loader.js +2 -2
- package/apps/runtime/dist/prompts/architect.md +3 -3
- package/apps/runtime/dist/prompts/authoring.md +46 -12
- package/apps/runtime/dist/prompts/goose.md +7 -7
- package/apps/runtime/dist/prompts/mcp.md +6 -6
- package/apps/runtime/dist/prompts/services.md +4 -4
- package/apps/runtime/dist/prompts/step.md +2 -2
- package/apps/runtime/dist/prompts/tools.md +39 -10
- package/apps/runtime/dist/routes/api.js +31 -20
- package/apps/runtime/dist/routes/broker.js +316 -0
- package/apps/runtime/dist/routes/connections.js +71 -0
- package/apps/runtime/dist/routes/delivery.js +25 -0
- package/apps/runtime/dist/routes/discover.js +17 -0
- package/apps/runtime/dist/routes/live.js +11 -1
- package/apps/runtime/dist/routes/person.js +4 -1
- package/apps/runtime/dist/routes/plugins.js +3 -1
- package/apps/runtime/dist/routes/rules.js +26 -0
- package/apps/runtime/dist/routes/runs.js +54 -33
- package/apps/runtime/dist/routes/skills.js +6 -6
- package/apps/runtime/dist/routes/studio.js +153 -144
- package/apps/runtime/dist/routes/work.js +199 -0
- package/apps/runtime/dist/sandbox/index.js +27 -0
- package/apps/runtime/dist/services/access.js +38 -17
- package/apps/runtime/dist/services/api.js +38 -13
- package/apps/runtime/dist/services/architect.js +3 -3
- package/apps/runtime/dist/services/assistant-chats.js +9 -1
- package/apps/runtime/dist/services/brand.js +12 -12
- package/apps/runtime/dist/services/broker-bell.js +69 -0
- package/apps/runtime/dist/services/broker-notify.js +127 -0
- package/apps/runtime/dist/services/client-steps.js +79 -0
- package/apps/runtime/dist/services/cloud.js +42 -42
- package/apps/runtime/dist/services/command-risk.js +51 -0
- package/apps/runtime/dist/services/discover.js +85 -0
- package/apps/runtime/dist/services/knowledge-model.js +13 -13
- package/apps/runtime/dist/services/knowledge.js +117 -80
- package/apps/runtime/dist/services/manage-reports.js +74 -7
- package/apps/runtime/dist/services/members-studio.js +165 -0
- package/apps/runtime/dist/services/onboarding.js +22 -22
- package/apps/runtime/dist/services/package-file.js +1 -1
- package/apps/runtime/dist/services/package.js +22 -22
- package/apps/runtime/dist/services/pages.js +7 -7
- package/apps/runtime/dist/services/runs.js +4 -3
- package/apps/runtime/dist/services/seen.js +55 -0
- package/apps/runtime/dist/services/shares.js +23 -13
- package/apps/runtime/dist/services/site.js +23 -23
- package/apps/runtime/dist/services/skills-registry.js +15 -15
- package/apps/runtime/dist/services/skills.js +44 -44
- package/apps/runtime/dist/services/space-categories.js +35 -35
- package/apps/runtime/dist/services/space-data.js +130 -111
- package/apps/runtime/dist/services/{project-files.js → space-files.js} +84 -75
- package/apps/runtime/dist/services/{project-index.js → space-index.js} +116 -73
- package/apps/runtime/dist/services/space-origin.js +19 -11
- package/apps/runtime/dist/services/spaces.js +478 -612
- package/apps/runtime/dist/services/synced-spaces.js +668 -0
- package/apps/runtime/dist/services/themes.js +15 -15
- package/apps/runtime/dist/services/widgets.js +6 -6
- package/apps/runtime/dist/services/wizards.js +112 -38
- package/apps/runtime/dist/services/work-ai.js +257 -0
- package/apps/runtime/dist/services/work-approvals.js +104 -0
- package/apps/runtime/dist/services/work-chats.js +908 -0
- package/apps/runtime/dist/services/work-connections.js +90 -0
- package/apps/runtime/dist/services/work-files.js +85 -0
- package/apps/runtime/dist/services/work-mastra.js +73 -0
- package/apps/runtime/dist/services/work-sandbox.js +42 -0
- package/apps/runtime/dist/sharing/files.js +14 -4
- package/apps/runtime/dist/sharing/index.js +40 -39
- package/apps/runtime/dist/sharing/jobs.js +67 -17
- package/apps/runtime/dist/sharing/targets/connector.js +10 -6
- package/apps/runtime/dist/sharing/targets/email.js +10 -8
- package/apps/runtime/dist/sharing/targets/slack.js +10 -8
- package/apps/runtime/dist/sharing/targets/storage.js +6 -4
- package/apps/runtime/dist/store/index.js +14 -3
- package/apps/runtime/dist/store/shared-lists.js +4 -2
- package/apps/runtime/dist/sync/apply.js +2 -2
- package/apps/runtime/dist/sync/client.js +113 -113
- package/apps/runtime/dist/sync/hub.js +41 -41
- package/apps/runtime/dist/sync/log.js +12 -12
- package/apps/runtime/dist/sync/records.js +118 -120
- package/apps/runtime/dist/texts.js +38 -2
- package/apps/runtime/dist/tools/connections.js +112 -0
- package/apps/runtime/dist/tools/connector.js +157 -67
- package/apps/runtime/dist/tools/index.js +28 -13
- package/apps/runtime/dist/tools/mail.js +40 -11
- package/apps/runtime/dist/tools/pages.js +11 -5
- package/apps/runtime/dist/tools/plugin.js +43 -7
- package/apps/runtime/dist/tools/skills.js +1 -1
- package/apps/runtime/dist/tools/{project.js → space.js} +30 -25
- package/apps/runtime/dist/tools/store.js +3 -2
- package/apps/runtime/dist/widgets/step.js +10 -10
- package/apps/web/dist/assets/AboutDialog-SpDcn8VZ.js +1 -0
- package/apps/web/dist/assets/CapabilitiesPage-Bgnm_3dk.js +2 -0
- package/apps/web/dist/assets/{ChangelogDialog-SwyId00t.js → ChangelogDialog-DAnjV6cZ.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-BwZsk5Al.js → CodeEditor-nxoOt8ge.js} +1 -1
- package/apps/web/dist/assets/EditorPage-B98C-9Nv.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-DtSpjVTl.js → FlowPreview-aMfwcPul.js} +1 -1
- package/apps/web/dist/assets/LangSwitch-DpD0inR4.js +1 -0
- package/apps/web/dist/assets/Marketplace-CpzD9pNQ.js +2 -0
- package/apps/web/dist/assets/NewWizardChannels-D8IYLg_S.js +1 -0
- package/apps/web/dist/assets/NewWizardPage-DlBt0Mfq.js +7 -0
- package/apps/web/dist/assets/OnboardingPage-ztHT01ah.js +1 -0
- package/apps/web/dist/assets/PreviewPane-DC1kAi3x.js +9 -0
- package/apps/web/dist/assets/PublicRunner-D6lKP0j8.js +1 -0
- package/apps/web/dist/assets/ReadOnly-DFsuKPCw.js +1 -0
- package/apps/web/dist/assets/SettingsPage-DkHeCO2c.js +2 -0
- package/apps/web/dist/assets/SetupPage-DZ8xRkfS.js +1 -0
- package/apps/web/dist/assets/SharePage-494ZPsjQ.js +1 -0
- package/apps/web/dist/assets/SkillEditor-CqQMg2MC.js +1 -0
- package/apps/web/dist/assets/Skills-CnhpgoOA.js +9 -0
- package/apps/web/dist/assets/SpacePage-CWlU_BZP.js +2 -0
- package/apps/web/dist/assets/UpdateCheck-BKNkNJyG.js +2 -0
- package/apps/web/dist/assets/changelog-BhMZS-rs.js +1 -0
- package/apps/web/dist/assets/circle-alert-C8Ma-bPY.js +1 -0
- package/apps/web/dist/assets/circle-check-Bu9Z3mlJ.js +1 -0
- package/apps/web/dist/assets/code-editor-CfTGqOpp.js +2 -0
- package/apps/web/dist/assets/{code-xml-TwKzzMtA.js → code-xml-B4kLFZSj.js} +1 -1
- package/apps/web/dist/assets/connection-sign-in-Cngd_QDO.js +1 -0
- package/apps/web/dist/assets/esm-Xwn4GtqG.js +7 -0
- package/apps/web/dist/assets/{eye-Brd-xPUJ.js → eye-BpoKpIdt.js} +1 -1
- package/apps/web/dist/assets/host-BrP-ENHg.css +1 -0
- package/apps/web/dist/assets/host-C0WQlRKB.js +118 -0
- package/apps/web/dist/assets/i18n-BJ7Ld6O6.js +55 -0
- package/apps/web/dist/assets/index-ClVtdDUZ.js +10 -0
- package/apps/web/dist/assets/index-D18DvnxX.css +1 -0
- package/apps/web/dist/assets/logo-BpnjXTRy.js +1 -0
- package/apps/web/dist/assets/oss-credits-IdX5bc71.js +1 -0
- package/apps/web/dist/assets/{phone-DhkHteoJ.js → phone-Ctvf-Am-.js} +1 -1
- package/apps/web/dist/assets/read-aloud-Da_RSm2S.js +1 -0
- package/apps/web/dist/assets/{runners-G-XYaDgR.js → runners-CyIvJIHr.js} +1 -1
- package/apps/web/dist/assets/scroll-text-ChrjRu9Y.js +1 -0
- package/apps/web/dist/assets/session-SXPtTWRK.js +2 -0
- package/apps/web/dist/assets/theme-BCau3f6O.js +11 -0
- package/apps/web/dist/assets/ui-Uqnx1UpK.js +82 -0
- package/apps/web/dist/assets/{upload-BYZTwJTD.js → upload-BchUnQGV.js} +1 -1
- package/apps/web/dist/assets/{useMutation-D0QP_k2-.js → useMutation-DEkZhp5c.js} +1 -1
- package/apps/web/dist/assets/{volume-2-CVHoxdGM.js → volume-2-CU_oy81Z.js} +1 -1
- package/apps/web/dist/assets/with-selector-CoMyWBAX.js +1 -0
- package/apps/web/dist/index.html +17 -10
- package/apps/web/dist/mcp/flow.html +119 -64
- package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +20 -10
- package/node_modules/@engenty/wizards-shared/dist/assistant.d.ts +6 -1
- package/node_modules/@engenty/wizards-shared/dist/assistant.js +6 -1
- package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +236 -2
- package/node_modules/@engenty/wizards-shared/dist/connectors.js +52 -2
- package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +150 -8
- package/node_modules/@engenty/wizards-shared/dist/definition.js +46 -11
- package/node_modules/@engenty/wizards-shared/dist/discover.d.ts +21 -0
- package/node_modules/@engenty/wizards-shared/dist/discover.js +1 -0
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +26 -2
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +26 -2
- package/node_modules/@engenty/wizards-shared/dist/fit.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/json-schema.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/json-schema.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/live.d.ts +2 -2
- package/node_modules/@engenty/wizards-shared/dist/live.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/marketplace.js +3 -1
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +54 -6
- package/node_modules/@engenty/wizards-shared/dist/run.js +85 -0
- package/node_modules/@engenty/wizards-shared/dist/runner-texts.d.ts +15 -1
- package/node_modules/@engenty/wizards-shared/dist/runner-texts.js +14 -0
- package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +42 -0
- package/node_modules/@engenty/wizards-shared/dist/rwx.js +29 -0
- package/node_modules/@engenty/wizards-shared/dist/skills.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/space-data.d.ts +2 -2
- package/node_modules/@engenty/wizards-shared/dist/{projects.d.ts → spaces.d.ts} +39 -15
- package/node_modules/@engenty/wizards-shared/dist/{projects.js → spaces.js} +16 -9
- package/node_modules/@engenty/wizards-shared/dist/store.d.ts +7 -2
- package/node_modules/@engenty/wizards-shared/dist/surface.d.ts +35 -4
- package/node_modules/@engenty/wizards-shared/dist/surface.js +121 -3
- package/node_modules/@engenty/wizards-shared/dist/sync.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/theme-look.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/wizard-package.d.ts +2 -2
- package/node_modules/@engenty/wizards-shared/dist/wizard-package.js +3 -3
- package/package.json +4 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/plugin/skills/build-wizard/SKILL.md +1 -1
- package/apps/runtime/dist/services/projects.js +0 -473
- package/apps/web/dist/assets/AboutDialog-B-JxkELB.js +0 -1
- package/apps/web/dist/assets/EditorPage-DQ_2FOzI.js +0 -3
- package/apps/web/dist/assets/Marketplace-DoH4YO3D.js +0 -2
- package/apps/web/dist/assets/NewWizardChannels-Tgoexgj4.js +0 -1
- package/apps/web/dist/assets/NewWizardPage-B24AF482.js +0 -7
- package/apps/web/dist/assets/OnboardingPage-BEvq4slJ.js +0 -1
- package/apps/web/dist/assets/PreviewPane-B_v7Y8R7.js +0 -10
- package/apps/web/dist/assets/ProjectPage-ClRuhFJo.js +0 -10
- package/apps/web/dist/assets/PublicRunner-MicrpVsv.js +0 -1
- package/apps/web/dist/assets/ReadOnly-BXjv-MSv.js +0 -1
- package/apps/web/dist/assets/SettingsPage-DY8O1r43.js +0 -2
- package/apps/web/dist/assets/SetupPage-BOVkVpMu.js +0 -1
- package/apps/web/dist/assets/SharePage-DXGzJSnR.js +0 -1
- package/apps/web/dist/assets/SkillEditor-BzzTDeaU.js +0 -1
- package/apps/web/dist/assets/changelog-BLdS-0Bj.js +0 -1
- package/apps/web/dist/assets/esm-BdxDT9Km.js +0 -7
- package/apps/web/dist/assets/i18n-8-Sw11tB.js +0 -55
- package/apps/web/dist/assets/index-OsdQFHmh.js +0 -49
- package/apps/web/dist/assets/index-QPipX5Fi.css +0 -1
- package/apps/web/dist/assets/lock-C0uxcOlq.js +0 -1
- package/apps/web/dist/assets/logo-CGNoptDg.js +0 -1
- package/apps/web/dist/assets/oss-credits-DpRWUPjD.js +0 -1
- package/apps/web/dist/assets/session-BWI-KENJ.js +0 -2
- package/apps/web/dist/assets/theme-D7krsx0_.js +0 -11
- package/apps/web/dist/assets/ui-DSXG3f49.js +0 -83
|
@@ -14,9 +14,9 @@ import { asSync } from "../services/access.js";
|
|
|
14
14
|
import { emitDraftChanged } from "../services/draft-events.js";
|
|
15
15
|
import { forgetWizardLinks } from "../services/links.js";
|
|
16
16
|
import { pushPages } from "../services/pages.js";
|
|
17
|
-
import {
|
|
18
|
-
import { dropIndex, queueIndex } from "../services/
|
|
19
|
-
import {
|
|
17
|
+
import { removeSpaceFile } from "../services/space-files.js";
|
|
18
|
+
import { dropIndex, queueIndex } from "../services/space-index.js";
|
|
19
|
+
import { removeSpace } from "../services/spaces.js";
|
|
20
20
|
import { parseDraft } from "../services/wizards.js";
|
|
21
21
|
import { putLink } from "../tenants/control.js";
|
|
22
22
|
import { currentTenant } from "../tenants/tenant.js";
|
|
@@ -43,14 +43,14 @@ async function categoriesOf(column, id) {
|
|
|
43
43
|
by: r.by,
|
|
44
44
|
}));
|
|
45
45
|
}
|
|
46
|
-
async function writeCategories(
|
|
46
|
+
async function writeCategories(spaceId, column, id, list) {
|
|
47
47
|
await db.delete(schema.spaceItemCategory).where(eq(schema.spaceItemCategory[column], id));
|
|
48
48
|
const rows = arr(list).filter((a) => str(a.categoryId));
|
|
49
49
|
if (!rows.length) {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
await db.insert(schema.spaceItemCategory).values(rows.map((a) => ({
|
|
53
|
-
|
|
53
|
+
spaceId,
|
|
54
54
|
categoryId: a.categoryId,
|
|
55
55
|
pageId: column === "pageId" ? id : null,
|
|
56
56
|
rowId: column === "rowId" ? id : null,
|
|
@@ -65,7 +65,7 @@ async function writeCategories(projectId, column, id, list) {
|
|
|
65
65
|
})));
|
|
66
66
|
}
|
|
67
67
|
/** An item a plugin wrote under a key: another one under the same key here gives way to it. */
|
|
68
|
-
async function clearOrigin(table,
|
|
68
|
+
async function clearOrigin(table, spaceId, id, record) {
|
|
69
69
|
const origin = str(record.origin);
|
|
70
70
|
const key = str(record.originKey);
|
|
71
71
|
if (!origin || !key) {
|
|
@@ -73,19 +73,19 @@ async function clearOrigin(table, projectId, id, record) {
|
|
|
73
73
|
}
|
|
74
74
|
await db
|
|
75
75
|
.delete(table)
|
|
76
|
-
.where(and(eq(table.
|
|
76
|
+
.where(and(eq(table.spaceId, spaceId), eq(table.origin, origin), eq(table.originKey, key), ne(table.id, id)));
|
|
77
77
|
}
|
|
78
78
|
// --- the kinds ----------------------------------------------------------------------------
|
|
79
79
|
const space = {
|
|
80
80
|
async read(id) {
|
|
81
|
-
const p = await db.query.
|
|
82
|
-
where: and(eq(schema.
|
|
81
|
+
const p = await db.query.space.findFirst({
|
|
82
|
+
where: and(eq(schema.space.id, id), eq(schema.space.tenantId, currentTenant())),
|
|
83
83
|
});
|
|
84
84
|
if (!p) {
|
|
85
85
|
return null;
|
|
86
86
|
}
|
|
87
87
|
return {
|
|
88
|
-
|
|
88
|
+
spaceId: p.id,
|
|
89
89
|
record: {
|
|
90
90
|
name: p.name,
|
|
91
91
|
brand: p.brand,
|
|
@@ -96,7 +96,7 @@ const space = {
|
|
|
96
96
|
};
|
|
97
97
|
},
|
|
98
98
|
async write(id, _item, r) {
|
|
99
|
-
const before = await db.query.
|
|
99
|
+
const before = await db.query.space.findFirst({ where: eq(schema.space.id, id) });
|
|
100
100
|
const values = {
|
|
101
101
|
name: str(r.name) ?? before?.name ?? "Space",
|
|
102
102
|
brand: obj(r.brand),
|
|
@@ -106,12 +106,12 @@ const space = {
|
|
|
106
106
|
};
|
|
107
107
|
if (before) {
|
|
108
108
|
await db
|
|
109
|
-
.update(schema.
|
|
109
|
+
.update(schema.space)
|
|
110
110
|
.set({ ...values, updatedAt: new Date() })
|
|
111
|
-
.where(eq(schema.
|
|
111
|
+
.where(eq(schema.space.id, id));
|
|
112
112
|
}
|
|
113
113
|
else {
|
|
114
|
-
await db.insert(schema.
|
|
114
|
+
await db.insert(schema.space).values({ id, tenantId: currentTenant(), ...values });
|
|
115
115
|
}
|
|
116
116
|
return () => {
|
|
117
117
|
spaceChanged(before ? "space.updated" : "space.created", id);
|
|
@@ -119,10 +119,10 @@ const space = {
|
|
|
119
119
|
};
|
|
120
120
|
},
|
|
121
121
|
async remove(id) {
|
|
122
|
-
await asSync(() =>
|
|
122
|
+
await asSync(() => removeSpace(id));
|
|
123
123
|
return undefined;
|
|
124
124
|
},
|
|
125
|
-
list: async (
|
|
125
|
+
list: async (spaceId) => [spaceId],
|
|
126
126
|
title: (r, item) => str(r?.name) ?? item,
|
|
127
127
|
check(merged) {
|
|
128
128
|
const issues = [];
|
|
@@ -145,9 +145,9 @@ const wizard = {
|
|
|
145
145
|
orderBy: [asc(schema.wizardFile.path)],
|
|
146
146
|
});
|
|
147
147
|
return {
|
|
148
|
-
|
|
148
|
+
spaceId: w.spaceId,
|
|
149
149
|
record: {
|
|
150
|
-
|
|
150
|
+
spaceId: w.spaceId,
|
|
151
151
|
// The title is the draft's: it travels once, in the draft.
|
|
152
152
|
draft: w.draft,
|
|
153
153
|
shareEnabled: w.shareEnabled,
|
|
@@ -167,12 +167,12 @@ const wizard = {
|
|
|
167
167
|
},
|
|
168
168
|
};
|
|
169
169
|
},
|
|
170
|
-
async write(
|
|
170
|
+
async write(spaceId, id, r) {
|
|
171
171
|
const files = arr(r.files).filter((f) => str(f.path) && str(f.hash));
|
|
172
172
|
const { draft } = parseDraft(r.draft, files.map((f) => f.path));
|
|
173
173
|
const before = await db.query.wizard.findFirst({ where: eq(schema.wizard.id, id) });
|
|
174
174
|
const values = {
|
|
175
|
-
|
|
175
|
+
spaceId,
|
|
176
176
|
title: draft.title,
|
|
177
177
|
draft,
|
|
178
178
|
shareEnabled: bool(r.shareEnabled, true),
|
|
@@ -225,18 +225,18 @@ const wizard = {
|
|
|
225
225
|
});
|
|
226
226
|
};
|
|
227
227
|
},
|
|
228
|
-
async remove(
|
|
228
|
+
async remove(_spaceId, id) {
|
|
229
229
|
await forgetWizardLinks(id);
|
|
230
230
|
await db
|
|
231
231
|
.delete(schema.wizard)
|
|
232
232
|
.where(and(eq(schema.wizard.id, id), eq(schema.wizard.tenantId, currentTenant())));
|
|
233
233
|
return () => pushPages();
|
|
234
234
|
},
|
|
235
|
-
async list(
|
|
235
|
+
async list(spaceId) {
|
|
236
236
|
const rows = await db
|
|
237
237
|
.select({ id: schema.wizard.id })
|
|
238
238
|
.from(schema.wizard)
|
|
239
|
-
.where(eq(schema.wizard.
|
|
239
|
+
.where(eq(schema.wizard.spaceId, spaceId));
|
|
240
240
|
return rows.map((r) => r.id);
|
|
241
241
|
},
|
|
242
242
|
title: (r, item) => str(obj(r?.draft).title) ?? item,
|
|
@@ -276,14 +276,12 @@ const translation = {
|
|
|
276
276
|
const w = row
|
|
277
277
|
? await db.query.wizard.findFirst({
|
|
278
278
|
where: eq(schema.wizard.id, wizardId),
|
|
279
|
-
columns: {
|
|
279
|
+
columns: { spaceId: true },
|
|
280
280
|
})
|
|
281
281
|
: null;
|
|
282
|
-
return row && w
|
|
283
|
-
? { projectId: w.projectId, record: { wizardId, lang, texts: row.texts } }
|
|
284
|
-
: null;
|
|
282
|
+
return row && w ? { spaceId: w.spaceId, record: { wizardId, lang, texts: row.texts } } : null;
|
|
285
283
|
},
|
|
286
|
-
async write(
|
|
284
|
+
async write(_spaceId, item, r) {
|
|
287
285
|
const [wizardId, lang] = splitTwo(item);
|
|
288
286
|
const texts = obj(r.texts);
|
|
289
287
|
await db
|
|
@@ -295,19 +293,19 @@ const translation = {
|
|
|
295
293
|
});
|
|
296
294
|
return undefined;
|
|
297
295
|
},
|
|
298
|
-
async remove(
|
|
296
|
+
async remove(_spaceId, item) {
|
|
299
297
|
const [wizardId, lang] = splitTwo(item);
|
|
300
298
|
await db
|
|
301
299
|
.delete(schema.wizardTranslation)
|
|
302
300
|
.where(and(eq(schema.wizardTranslation.wizardId, wizardId), eq(schema.wizardTranslation.lang, lang)));
|
|
303
301
|
return undefined;
|
|
304
302
|
},
|
|
305
|
-
async list(
|
|
303
|
+
async list(spaceId) {
|
|
306
304
|
const rows = await db
|
|
307
305
|
.select({ wizardId: schema.wizardTranslation.wizardId, lang: schema.wizardTranslation.lang })
|
|
308
306
|
.from(schema.wizardTranslation)
|
|
309
307
|
.innerJoin(schema.wizard, eq(schema.wizard.id, schema.wizardTranslation.wizardId))
|
|
310
|
-
.where(eq(schema.wizard.
|
|
308
|
+
.where(eq(schema.wizard.spaceId, spaceId));
|
|
311
309
|
return rows.map((r) => `${r.wizardId}:${r.lang}`);
|
|
312
310
|
},
|
|
313
311
|
title: (_r, item) => splitTwo(item)[1],
|
|
@@ -318,14 +316,14 @@ const message = {
|
|
|
318
316
|
const w = m
|
|
319
317
|
? await db.query.wizard.findFirst({
|
|
320
318
|
where: eq(schema.wizard.id, m.wizardId),
|
|
321
|
-
columns: {
|
|
319
|
+
columns: { spaceId: true },
|
|
322
320
|
})
|
|
323
321
|
: null;
|
|
324
322
|
if (!m || !w) {
|
|
325
323
|
return null;
|
|
326
324
|
}
|
|
327
325
|
return {
|
|
328
|
-
|
|
326
|
+
spaceId: w.spaceId,
|
|
329
327
|
record: {
|
|
330
328
|
wizardId: m.wizardId,
|
|
331
329
|
role: m.role,
|
|
@@ -337,7 +335,7 @@ const message = {
|
|
|
337
335
|
},
|
|
338
336
|
};
|
|
339
337
|
},
|
|
340
|
-
async write(
|
|
338
|
+
async write(_spaceId, id, r) {
|
|
341
339
|
const values = {
|
|
342
340
|
wizardId: String(r.wizardId),
|
|
343
341
|
role: (r.role === "assistant" ? "assistant" : "user"),
|
|
@@ -353,16 +351,16 @@ const message = {
|
|
|
353
351
|
.onConflictDoUpdate({ target: schema.wizardMessage.id, set: values });
|
|
354
352
|
return undefined;
|
|
355
353
|
},
|
|
356
|
-
async remove(
|
|
354
|
+
async remove(_spaceId, id) {
|
|
357
355
|
await db.delete(schema.wizardMessage).where(eq(schema.wizardMessage.id, id));
|
|
358
356
|
return undefined;
|
|
359
357
|
},
|
|
360
|
-
async list(
|
|
358
|
+
async list(spaceId) {
|
|
361
359
|
const rows = await db
|
|
362
360
|
.select({ id: schema.wizardMessage.id })
|
|
363
361
|
.from(schema.wizardMessage)
|
|
364
362
|
.innerJoin(schema.wizard, eq(schema.wizard.id, schema.wizardMessage.wizardId))
|
|
365
|
-
.where(eq(schema.wizard.
|
|
363
|
+
.where(eq(schema.wizard.spaceId, spaceId));
|
|
366
364
|
return rows.map((r) => r.id);
|
|
367
365
|
},
|
|
368
366
|
title: (r) => (str(r?.content) ?? "").slice(0, 60),
|
|
@@ -380,9 +378,9 @@ const page = {
|
|
|
380
378
|
return "skip";
|
|
381
379
|
}
|
|
382
380
|
return {
|
|
383
|
-
|
|
381
|
+
spaceId: p.spaceId,
|
|
384
382
|
record: {
|
|
385
|
-
|
|
383
|
+
spaceId: p.spaceId,
|
|
386
384
|
title: p.title,
|
|
387
385
|
slug: p.slug,
|
|
388
386
|
markdown: p.markdown,
|
|
@@ -398,10 +396,10 @@ const page = {
|
|
|
398
396
|
},
|
|
399
397
|
};
|
|
400
398
|
},
|
|
401
|
-
async write(
|
|
402
|
-
await clearOrigin(schema.spacePage,
|
|
399
|
+
async write(spaceId, id, r) {
|
|
400
|
+
await clearOrigin(schema.spacePage, spaceId, id, r);
|
|
403
401
|
const values = {
|
|
404
|
-
|
|
402
|
+
spaceId,
|
|
405
403
|
title: str(r.title) ?? "",
|
|
406
404
|
slug: str(r.slug),
|
|
407
405
|
markdown: str(r.markdown) ?? "",
|
|
@@ -421,18 +419,18 @@ const page = {
|
|
|
421
419
|
target: schema.spacePage.id,
|
|
422
420
|
set: { ...values, updatedAt: new Date() },
|
|
423
421
|
});
|
|
424
|
-
await writeCategories(
|
|
422
|
+
await writeCategories(spaceId, "pageId", id, r.categories);
|
|
425
423
|
return () => queueIndex(`P:${id}`);
|
|
426
424
|
},
|
|
427
|
-
async remove(
|
|
425
|
+
async remove(_spaceId, id) {
|
|
428
426
|
await db.delete(schema.spacePage).where(eq(schema.spacePage.id, id));
|
|
429
427
|
return undefined;
|
|
430
428
|
},
|
|
431
|
-
async list(
|
|
429
|
+
async list(spaceId) {
|
|
432
430
|
const rows = await db
|
|
433
431
|
.select({ id: schema.spacePage.id })
|
|
434
432
|
.from(schema.spacePage)
|
|
435
|
-
.where(and(eq(schema.spacePage.
|
|
433
|
+
.where(and(eq(schema.spacePage.spaceId, spaceId), isNull(schema.spacePage.wizardId)));
|
|
436
434
|
return rows.map((r) => r.id);
|
|
437
435
|
},
|
|
438
436
|
title: (r, item) => str(r?.title) ?? item,
|
|
@@ -449,9 +447,9 @@ const table = {
|
|
|
449
447
|
return "skip";
|
|
450
448
|
}
|
|
451
449
|
return {
|
|
452
|
-
|
|
450
|
+
spaceId: t.spaceId,
|
|
453
451
|
record: {
|
|
454
|
-
|
|
452
|
+
spaceId: t.spaceId,
|
|
455
453
|
title: t.title,
|
|
456
454
|
slug: t.slug,
|
|
457
455
|
format: t.format,
|
|
@@ -466,10 +464,10 @@ const table = {
|
|
|
466
464
|
},
|
|
467
465
|
};
|
|
468
466
|
},
|
|
469
|
-
async write(
|
|
470
|
-
await clearOrigin(schema.spaceTable,
|
|
467
|
+
async write(spaceId, id, r) {
|
|
468
|
+
await clearOrigin(schema.spaceTable, spaceId, id, r);
|
|
471
469
|
const values = {
|
|
472
|
-
|
|
470
|
+
spaceId,
|
|
473
471
|
title: str(r.title) ?? "",
|
|
474
472
|
slug: str(r.slug),
|
|
475
473
|
format: (r.format === "faq" ? "faq" : null),
|
|
@@ -488,18 +486,18 @@ const table = {
|
|
|
488
486
|
target: schema.spaceTable.id,
|
|
489
487
|
set: { ...values, updatedAt: new Date() },
|
|
490
488
|
});
|
|
491
|
-
await writeCategories(
|
|
489
|
+
await writeCategories(spaceId, "tableId", id, r.categories);
|
|
492
490
|
return () => queueIndex(`t:${id}`);
|
|
493
491
|
},
|
|
494
|
-
async remove(
|
|
492
|
+
async remove(_spaceId, id) {
|
|
495
493
|
await db.delete(schema.spaceTable).where(eq(schema.spaceTable.id, id));
|
|
496
494
|
return undefined;
|
|
497
495
|
},
|
|
498
|
-
async list(
|
|
496
|
+
async list(spaceId) {
|
|
499
497
|
const rows = await db
|
|
500
498
|
.select({ id: schema.spaceTable.id })
|
|
501
499
|
.from(schema.spaceTable)
|
|
502
|
-
.where(and(eq(schema.spaceTable.
|
|
500
|
+
.where(and(eq(schema.spaceTable.spaceId, spaceId), isNull(schema.spaceTable.wizardId)));
|
|
503
501
|
return rows.map((r) => r.id);
|
|
504
502
|
},
|
|
505
503
|
title: (r, item) => str(r?.title) ?? item,
|
|
@@ -513,7 +511,7 @@ const row = {
|
|
|
513
511
|
const t = r
|
|
514
512
|
? await db.query.spaceTable.findFirst({
|
|
515
513
|
where: and(eq(schema.spaceTable.id, r.tableId), eq(schema.spaceTable.tenantId, currentTenant())),
|
|
516
|
-
columns: {
|
|
514
|
+
columns: { spaceId: true, wizardId: true },
|
|
517
515
|
})
|
|
518
516
|
: null;
|
|
519
517
|
if (!r || !t) {
|
|
@@ -523,9 +521,9 @@ const row = {
|
|
|
523
521
|
return "skip";
|
|
524
522
|
}
|
|
525
523
|
return {
|
|
526
|
-
|
|
524
|
+
spaceId: t.spaceId,
|
|
527
525
|
record: {
|
|
528
|
-
|
|
526
|
+
spaceId: t.spaceId,
|
|
529
527
|
tableId: r.tableId,
|
|
530
528
|
key: r.key,
|
|
531
529
|
cells: r.cells,
|
|
@@ -534,7 +532,7 @@ const row = {
|
|
|
534
532
|
},
|
|
535
533
|
};
|
|
536
534
|
},
|
|
537
|
-
async write(
|
|
535
|
+
async write(spaceId, id, r) {
|
|
538
536
|
const values = {
|
|
539
537
|
tableId: String(r.tableId),
|
|
540
538
|
key: str(r.key),
|
|
@@ -548,19 +546,19 @@ const row = {
|
|
|
548
546
|
target: schema.spaceTableRow.id,
|
|
549
547
|
set: { ...values, updatedAt: new Date() },
|
|
550
548
|
});
|
|
551
|
-
await writeCategories(
|
|
549
|
+
await writeCategories(spaceId, "rowId", id, r.categories);
|
|
552
550
|
return () => queueIndex(`r:${id}`);
|
|
553
551
|
},
|
|
554
|
-
async remove(
|
|
552
|
+
async remove(_spaceId, id) {
|
|
555
553
|
await db.delete(schema.spaceTableRow).where(eq(schema.spaceTableRow.id, id));
|
|
556
554
|
return undefined;
|
|
557
555
|
},
|
|
558
|
-
async list(
|
|
556
|
+
async list(spaceId) {
|
|
559
557
|
const rows = await db
|
|
560
558
|
.select({ id: schema.spaceTableRow.id })
|
|
561
559
|
.from(schema.spaceTableRow)
|
|
562
560
|
.innerJoin(schema.spaceTable, eq(schema.spaceTable.id, schema.spaceTableRow.tableId))
|
|
563
|
-
.where(and(eq(schema.spaceTable.
|
|
561
|
+
.where(and(eq(schema.spaceTable.spaceId, spaceId), isNull(schema.spaceTable.wizardId)));
|
|
564
562
|
return rows.map((r) => r.id);
|
|
565
563
|
},
|
|
566
564
|
title(r, item) {
|
|
@@ -593,9 +591,9 @@ async function rekeyValue(from, to) {
|
|
|
593
591
|
.set({ valueId: to })
|
|
594
592
|
.where(eq(schema.spaceItemCategory.valueId, from));
|
|
595
593
|
await db
|
|
596
|
-
.update(schema.
|
|
594
|
+
.update(schema.spaceChunk)
|
|
597
595
|
.set({ valueId: to })
|
|
598
|
-
.where(eq(schema.
|
|
596
|
+
.where(eq(schema.spaceChunk.valueId, from));
|
|
599
597
|
}
|
|
600
598
|
const category = {
|
|
601
599
|
async read(id) {
|
|
@@ -610,9 +608,9 @@ const category = {
|
|
|
610
608
|
orderBy: [asc(schema.spaceCategoryValue.position), asc(schema.spaceCategoryValue.id)],
|
|
611
609
|
});
|
|
612
610
|
return {
|
|
613
|
-
|
|
611
|
+
spaceId: c.spaceId,
|
|
614
612
|
record: {
|
|
615
|
-
|
|
613
|
+
spaceId: c.spaceId,
|
|
616
614
|
name: c.name,
|
|
617
615
|
type: c.type,
|
|
618
616
|
unit: c.unit,
|
|
@@ -633,10 +631,10 @@ const category = {
|
|
|
633
631
|
},
|
|
634
632
|
};
|
|
635
633
|
},
|
|
636
|
-
async write(
|
|
634
|
+
async write(spaceId, id, r) {
|
|
637
635
|
const name = str(r.name) ?? "";
|
|
638
636
|
const same = await db.query.spaceCategory.findFirst({
|
|
639
|
-
where: and(eq(schema.spaceCategory.
|
|
637
|
+
where: and(eq(schema.spaceCategory.spaceId, spaceId), eq(schema.spaceCategory.name, name), ne(schema.spaceCategory.id, id)),
|
|
640
638
|
columns: { id: true },
|
|
641
639
|
});
|
|
642
640
|
if (same) {
|
|
@@ -645,7 +643,7 @@ const category = {
|
|
|
645
643
|
}
|
|
646
644
|
const type = r.type ?? "text";
|
|
647
645
|
const values = {
|
|
648
|
-
|
|
646
|
+
spaceId,
|
|
649
647
|
name,
|
|
650
648
|
type: (["choice", "date", "number", "text", "boolean"].includes(type) ? type : "text"),
|
|
651
649
|
unit: str(r.unit),
|
|
@@ -709,15 +707,15 @@ const category = {
|
|
|
709
707
|
}
|
|
710
708
|
};
|
|
711
709
|
},
|
|
712
|
-
async remove(
|
|
710
|
+
async remove(_spaceId, id) {
|
|
713
711
|
await db.delete(schema.spaceCategory).where(eq(schema.spaceCategory.id, id));
|
|
714
712
|
return undefined;
|
|
715
713
|
},
|
|
716
|
-
async list(
|
|
714
|
+
async list(spaceId) {
|
|
717
715
|
const rows = await db
|
|
718
716
|
.select({ id: schema.spaceCategory.id })
|
|
719
717
|
.from(schema.spaceCategory)
|
|
720
|
-
.where(eq(schema.spaceCategory.
|
|
718
|
+
.where(eq(schema.spaceCategory.spaceId, spaceId));
|
|
721
719
|
return rows.map((r) => r.id);
|
|
722
720
|
},
|
|
723
721
|
title: (r, item) => str(r?.name) ?? item,
|
|
@@ -725,10 +723,10 @@ const category = {
|
|
|
725
723
|
const assetKey = (path) => `assets/${path}`;
|
|
726
724
|
const file = {
|
|
727
725
|
async read(id) {
|
|
728
|
-
const f = await db.query.
|
|
726
|
+
const f = await db.query.spaceFile.findFirst({ where: eq(schema.spaceFile.id, id) });
|
|
729
727
|
const p = f
|
|
730
|
-
? await db.query.
|
|
731
|
-
where: and(eq(schema.
|
|
728
|
+
? await db.query.space.findFirst({
|
|
729
|
+
where: and(eq(schema.space.id, f.spaceId), eq(schema.space.tenantId, currentTenant())),
|
|
732
730
|
columns: { id: true },
|
|
733
731
|
})
|
|
734
732
|
: null;
|
|
@@ -745,9 +743,9 @@ const file = {
|
|
|
745
743
|
return "skip";
|
|
746
744
|
}
|
|
747
745
|
return {
|
|
748
|
-
|
|
746
|
+
spaceId: f.spaceId,
|
|
749
747
|
record: {
|
|
750
|
-
|
|
748
|
+
spaceId: f.spaceId,
|
|
751
749
|
kind: f.kind,
|
|
752
750
|
name: f.name,
|
|
753
751
|
mime: f.mime,
|
|
@@ -766,8 +764,8 @@ const file = {
|
|
|
766
764
|
},
|
|
767
765
|
};
|
|
768
766
|
},
|
|
769
|
-
async write(
|
|
770
|
-
await clearOrigin(schema.
|
|
767
|
+
async write(spaceId, id, r) {
|
|
768
|
+
await clearOrigin(schema.spaceFile, spaceId, id, r);
|
|
771
769
|
const mime = str(r.mime) ?? "application/octet-stream";
|
|
772
770
|
const name = str(r.name) ?? "file";
|
|
773
771
|
const kind = (["logo", "asset", "document", "pattern"].includes(r.kind) ? r.kind : "asset");
|
|
@@ -776,7 +774,7 @@ const file = {
|
|
|
776
774
|
const path = `${id}-${nanoid(6)}.${extFor(mime)}`;
|
|
777
775
|
await objects.put(assetKey(path), bytes);
|
|
778
776
|
const assetValues = {
|
|
779
|
-
kind: kind === "logo" ? "logo" : "
|
|
777
|
+
kind: kind === "logo" ? "logo" : "space",
|
|
780
778
|
mime,
|
|
781
779
|
name,
|
|
782
780
|
path,
|
|
@@ -787,7 +785,7 @@ const file = {
|
|
|
787
785
|
.values({ id, tenantId: currentTenant(), ...assetValues })
|
|
788
786
|
.onConflictDoUpdate({ target: schema.asset.id, set: assetValues });
|
|
789
787
|
const values = {
|
|
790
|
-
|
|
788
|
+
spaceId,
|
|
791
789
|
kind,
|
|
792
790
|
name,
|
|
793
791
|
mime,
|
|
@@ -805,13 +803,13 @@ const file = {
|
|
|
805
803
|
originLabel: str(r.originLabel),
|
|
806
804
|
};
|
|
807
805
|
await db
|
|
808
|
-
.insert(schema.
|
|
806
|
+
.insert(schema.spaceFile)
|
|
809
807
|
.values({ id, ...values })
|
|
810
808
|
.onConflictDoUpdate({
|
|
811
|
-
target: schema.
|
|
809
|
+
target: schema.spaceFile.id,
|
|
812
810
|
set: { ...values, updatedAt: new Date() },
|
|
813
811
|
});
|
|
814
|
-
await writeCategories(
|
|
812
|
+
await writeCategories(spaceId, "fileId", id, r.categories);
|
|
815
813
|
return async () => {
|
|
816
814
|
if (before && before.path !== path) {
|
|
817
815
|
await objects.remove(assetKey(before.path));
|
|
@@ -828,15 +826,15 @@ const file = {
|
|
|
828
826
|
}
|
|
829
827
|
};
|
|
830
828
|
},
|
|
831
|
-
async remove(
|
|
832
|
-
await asSync(() =>
|
|
829
|
+
async remove(spaceId, id) {
|
|
830
|
+
await asSync(() => removeSpaceFile(spaceId, id)).catch(() => undefined);
|
|
833
831
|
return undefined;
|
|
834
832
|
},
|
|
835
|
-
async list(
|
|
833
|
+
async list(spaceId) {
|
|
836
834
|
const rows = await db
|
|
837
|
-
.select({ id: schema.
|
|
838
|
-
.from(schema.
|
|
839
|
-
.where(and(eq(schema.
|
|
835
|
+
.select({ id: schema.spaceFile.id })
|
|
836
|
+
.from(schema.spaceFile)
|
|
837
|
+
.where(and(eq(schema.spaceFile.spaceId, spaceId), eq(schema.spaceFile.status, "ready")));
|
|
840
838
|
return rows.map((r) => r.id);
|
|
841
839
|
},
|
|
842
840
|
title: (r, item) => str(r?.name) ?? item,
|
|
@@ -844,43 +842,43 @@ const file = {
|
|
|
844
842
|
};
|
|
845
843
|
const connector = {
|
|
846
844
|
async read(item) {
|
|
847
|
-
const [
|
|
848
|
-
const c = await db.query.
|
|
849
|
-
where: and(eq(schema.
|
|
845
|
+
const [spaceId, id] = splitTwo(item);
|
|
846
|
+
const c = await db.query.spaceConnector.findFirst({
|
|
847
|
+
where: and(eq(schema.spaceConnector.spaceId, spaceId), eq(schema.spaceConnector.id, id)),
|
|
850
848
|
});
|
|
851
849
|
const p = c
|
|
852
|
-
? await db.query.
|
|
853
|
-
where: and(eq(schema.
|
|
850
|
+
? await db.query.space.findFirst({
|
|
851
|
+
where: and(eq(schema.space.id, spaceId), eq(schema.space.tenantId, currentTenant())),
|
|
854
852
|
columns: { id: true },
|
|
855
853
|
})
|
|
856
854
|
: null;
|
|
857
|
-
return c && p ? {
|
|
855
|
+
return c && p ? { spaceId, record: { spaceId, record: c.record } } : null;
|
|
858
856
|
},
|
|
859
|
-
async write(
|
|
857
|
+
async write(spaceId, item, r) {
|
|
860
858
|
const [, id] = splitTwo(item);
|
|
861
859
|
const record = obj(r.record);
|
|
862
860
|
await db
|
|
863
|
-
.insert(schema.
|
|
864
|
-
.values({
|
|
861
|
+
.insert(schema.spaceConnector)
|
|
862
|
+
.values({ spaceId, id, record })
|
|
865
863
|
.onConflictDoUpdate({
|
|
866
|
-
target: [schema.
|
|
864
|
+
target: [schema.spaceConnector.spaceId, schema.spaceConnector.id],
|
|
867
865
|
set: { record, updatedAt: new Date() },
|
|
868
866
|
});
|
|
869
867
|
return undefined;
|
|
870
868
|
},
|
|
871
|
-
async remove(
|
|
869
|
+
async remove(spaceId, item) {
|
|
872
870
|
const [, id] = splitTwo(item);
|
|
873
871
|
await db
|
|
874
|
-
.delete(schema.
|
|
875
|
-
.where(and(eq(schema.
|
|
872
|
+
.delete(schema.spaceConnector)
|
|
873
|
+
.where(and(eq(schema.spaceConnector.spaceId, spaceId), eq(schema.spaceConnector.id, id)));
|
|
876
874
|
return undefined;
|
|
877
875
|
},
|
|
878
|
-
async list(
|
|
876
|
+
async list(spaceId) {
|
|
879
877
|
const rows = await db
|
|
880
|
-
.select({ id: schema.
|
|
881
|
-
.from(schema.
|
|
882
|
-
.where(eq(schema.
|
|
883
|
-
return rows.map((r) => `${
|
|
878
|
+
.select({ id: schema.spaceConnector.id })
|
|
879
|
+
.from(schema.spaceConnector)
|
|
880
|
+
.where(eq(schema.spaceConnector.spaceId, spaceId));
|
|
881
|
+
return rows.map((r) => `${spaceId}:${r.id}`);
|
|
884
882
|
},
|
|
885
883
|
title: (r, item) => str(obj(r?.record).name) ?? splitTwo(item)[1],
|
|
886
884
|
};
|
|
@@ -893,9 +891,9 @@ const skill = {
|
|
|
893
891
|
return null;
|
|
894
892
|
}
|
|
895
893
|
return {
|
|
896
|
-
|
|
894
|
+
spaceId: k.spaceId,
|
|
897
895
|
record: {
|
|
898
|
-
|
|
896
|
+
spaceId: k.spaceId,
|
|
899
897
|
name: k.name,
|
|
900
898
|
description: k.description,
|
|
901
899
|
body: k.body,
|
|
@@ -910,11 +908,11 @@ const skill = {
|
|
|
910
908
|
},
|
|
911
909
|
};
|
|
912
910
|
},
|
|
913
|
-
async write(
|
|
911
|
+
async write(spaceId, id, r) {
|
|
914
912
|
const mode = SKILL_MODES.find((m) => m === r.mode) ?? "demand";
|
|
915
913
|
const source = SKILL_SOURCES.find((m) => m === r.source) ?? "own";
|
|
916
914
|
const values = {
|
|
917
|
-
|
|
915
|
+
spaceId,
|
|
918
916
|
name: str(r.name) ?? id.toLowerCase(),
|
|
919
917
|
description: str(r.description) ?? "",
|
|
920
918
|
body: str(r.body) ?? "",
|
|
@@ -931,7 +929,7 @@ const skill = {
|
|
|
931
929
|
};
|
|
932
930
|
// Two sides named a skill alike: the one arriving takes the name with its id behind it.
|
|
933
931
|
const clash = await db.query.spaceSkill.findFirst({
|
|
934
|
-
where: and(eq(schema.spaceSkill.
|
|
932
|
+
where: and(eq(schema.spaceSkill.spaceId, spaceId), eq(schema.spaceSkill.name, values.name), ne(schema.spaceSkill.id, id)),
|
|
935
933
|
columns: { id: true },
|
|
936
934
|
});
|
|
937
935
|
if (clash) {
|
|
@@ -947,15 +945,15 @@ const skill = {
|
|
|
947
945
|
});
|
|
948
946
|
return undefined;
|
|
949
947
|
},
|
|
950
|
-
async remove(
|
|
948
|
+
async remove(_spaceId, id) {
|
|
951
949
|
await db.delete(schema.spaceSkill).where(eq(schema.spaceSkill.id, id));
|
|
952
950
|
return undefined;
|
|
953
951
|
},
|
|
954
|
-
async list(
|
|
952
|
+
async list(spaceId) {
|
|
955
953
|
const rows = await db
|
|
956
954
|
.select({ id: schema.spaceSkill.id })
|
|
957
955
|
.from(schema.spaceSkill)
|
|
958
|
-
.where(eq(schema.spaceSkill.
|
|
956
|
+
.where(eq(schema.spaceSkill.spaceId, spaceId));
|
|
959
957
|
return rows.map((r) => r.id);
|
|
960
958
|
},
|
|
961
959
|
title: (r, item) => str(r?.name) ?? item,
|
|
@@ -1004,10 +1002,10 @@ export function canonical(record) {
|
|
|
1004
1002
|
*/
|
|
1005
1003
|
export async function letDanglingGo() {
|
|
1006
1004
|
await db.run(sql `UPDATE space_page SET parent_id = NULL WHERE parent_id IS NOT NULL AND parent_id NOT IN (SELECT id FROM space_page)`);
|
|
1007
|
-
await db.run(sql `UPDATE space_page SET file_id = NULL WHERE file_id IS NOT NULL AND file_id NOT IN (SELECT id FROM
|
|
1008
|
-
await db.run(sql `UPDATE space_table SET file_id = NULL WHERE file_id IS NOT NULL AND file_id NOT IN (SELECT id FROM
|
|
1005
|
+
await db.run(sql `UPDATE space_page SET file_id = NULL WHERE file_id IS NOT NULL AND file_id NOT IN (SELECT id FROM space_file)`);
|
|
1006
|
+
await db.run(sql `UPDATE space_table SET file_id = NULL WHERE file_id IS NOT NULL AND file_id NOT IN (SELECT id FROM space_file)`);
|
|
1009
1007
|
await db.run(sql `UPDATE space_category SET table_id = NULL, column_id = NULL WHERE table_id IS NOT NULL AND table_id NOT IN (SELECT id FROM space_table)`);
|
|
1010
|
-
await db.run(sql `DELETE FROM space_item_category WHERE category_id NOT IN (SELECT id FROM space_category) OR (value_id IS NOT NULL AND value_id NOT IN (SELECT id FROM space_category_value)) OR (page_id IS NOT NULL AND page_id NOT IN (SELECT id FROM space_page)) OR (row_id IS NOT NULL AND row_id NOT IN (SELECT id FROM space_table_row)) OR (table_id IS NOT NULL AND table_id NOT IN (SELECT id FROM space_table)) OR (file_id IS NOT NULL AND file_id NOT IN (SELECT id FROM
|
|
1008
|
+
await db.run(sql `DELETE FROM space_item_category WHERE category_id NOT IN (SELECT id FROM space_category) OR (value_id IS NOT NULL AND value_id NOT IN (SELECT id FROM space_category_value)) OR (page_id IS NOT NULL AND page_id NOT IN (SELECT id FROM space_page)) OR (row_id IS NOT NULL AND row_id NOT IN (SELECT id FROM space_table_row)) OR (table_id IS NOT NULL AND table_id NOT IN (SELECT id FROM space_table)) OR (file_id IS NOT NULL AND file_id NOT IN (SELECT id FROM space_file))`);
|
|
1011
1009
|
await db.run(sql `DELETE FROM space_table_row WHERE table_id NOT IN (SELECT id FROM space_table)`);
|
|
1012
1010
|
await db.run(sql `DELETE FROM wizard_translation WHERE wizard_id NOT IN (SELECT id FROM wizard)`);
|
|
1013
1011
|
await db.run(sql `DELETE FROM wizard_message WHERE wizard_id NOT IN (SELECT id FROM wizard)`);
|