@nocobase/plugin-multi-app-manager 0.14.0-alpha.7 → 0.14.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,4 +3,4 @@ export declare class MultiAppManagerPlugin extends Plugin {
3
3
  load(): Promise<void>;
4
4
  }
5
5
  export default MultiAppManagerPlugin;
6
- export { tableActionColumnSchema } from './settings/schemas/applications';
6
+ export { formSchema, tableActionColumnSchema } from './settings/schemas/applications';
@@ -1 +1 @@
1
- (function(n,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("antd"),require("react-router-dom"),require("@formily/shared"),require("react-i18next"),require("@formily/react")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","antd","react-router-dom","@formily/shared","react-i18next","@formily/react"],t):(n=typeof globalThis!="undefined"?globalThis:n||self,t(n["@nocobase/plugin-multi-app-manager"]={},n["@nocobase/client"],n.jsxRuntime,n.antd,n["react-router-dom"],n["@formily/shared"],n["react-i18next"],n["@formily/react"]))})(this,function(n,t,o,c,l,m,d,s){"use strict";var V=Object.defineProperty,j=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var h=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var F=(n,t,o)=>t in n?V(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,y=(n,t)=>{for(var o in t||(t={}))$.call(t,o)&&F(n,o,t[o]);if(h)for(var o of h(t))z.call(t,o)&&F(n,o,t[o]);return n},D=(n,t)=>j(n,_(t));var A=(n,t,o)=>new Promise((c,l)=>{var m=a=>{try{s(o.next(a))}catch(i){l(i)}},d=a=>{try{s(o.throw(a))}catch(i){l(i)}},s=a=>a.done?c(a.value):Promise.resolve(a.value).then(m,d);s((o=o.apply(n,t)).next())});const a=()=>{const{t:e}=d.useTranslation("multi-app-manager");return{t:e}},i=e=>`{{t("${e}", { ns: 'multi-app-manager' })}}`,f={name:"applications",targetKey:"name",fields:[{type:"uid",name:"name",primaryKey:!0,prefix:"a",interface:"input",uiSchema:{type:"string",title:i("App ID"),required:!0,"x-component":"Input","x-validator":"uid"}},{type:"string",name:"displayName",interface:"input",uiSchema:{type:"string",title:i("App display name"),required:!0,"x-component":"Input"}},{type:"string",name:"pinned",interface:"checkbox",uiSchema:{type:"boolean","x-content":i("Pin to menu"),"x-component":"Checkbox"}},{type:"string",name:"status",interface:"radioGroup",defaultValue:"pending",uiSchema:{type:"string",title:i("App status"),enum:[{label:"Initializing",value:"initializing"},{label:"Initialized",value:"initialized"},{label:"Running",value:"running"},{label:"Commanding",value:"commanding"},{label:"Stopped",value:"stopped"},{label:"Error",value:"error"},{label:"Not found",value:"not_found"}],"x-component":"Radio.Group"}}]},S=()=>{const{state:e,setState:r,refresh:u}=t.useResourceActionContext(),{resource:x}=t.useResourceContext();return{run(){return A(this,null,function*(){yield x.destroy({filterByTk:(e==null?void 0:e.selectedRowKeys)||[]}),r==null||r({selectedRowKeys:[]}),u()})}}},C={properties:{view:{type:"void","x-component":"AppVisitor","x-component-props":{}},update:{type:"void",title:'{{t("Edit")}}',"x-component":"Action.Link","x-component-props":{},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues:"{{ cm.useValuesFromRecord }}"},title:'{{t("Edit")}}',properties:{displayName:{"x-component":"CollectionField","x-decorator":"FormItem"},pinned:{"x-component":"CollectionField","x-decorator":"FormItem"},"options.standaloneDeployment":{"x-component":"Checkbox","x-decorator":"FormItem","x-content":i("Standalone deployment")},"options.autoStart":{"x-component":"Checkbox","x-decorator":"FormItem","x-content":i("Auto start")},cname:{title:i("Custom domain"),"x-component":"Input","x-decorator":"FormItem"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useUpdateAction }}"}}}}}}}},delete:{type:"void",title:'{{ t("Delete") }}',"x-component":"Action.Link","x-component-props":{confirm:{title:"{{t('Delete')}}",content:"{{t('Are you sure you want to delete it?')}}"},useAction:"{{cm.useDestroyAction}}"}}}},I={type:"object",properties:{[m.uid()]:{type:"void","x-decorator":"ResourceActionProvider","x-decorator-props":{collection:f,resourceName:"applications",request:{resource:"applications",action:"list",params:{pageSize:50,sort:["-createdAt"],appends:[]}}},"x-component":"CollectionProvider","x-component-props":{collection:f},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{delete:{type:"void",title:'{{ t("Delete") }}',"x-component":"Action","x-component-props":{useAction:S,confirm:{title:"{{t('Delete')}}",content:"{{t('Are you sure you want to delete it?')}}"}}},create:{type:"void",title:'{{t("Add new")}}',"x-component":"Action","x-component-props":{type:"primary"},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues(e){const r=t.useActionContext();return t.useRequest(()=>Promise.resolve({data:{name:`a_${m.uid()}`}}),D(y({},e),{refreshDeps:[r.visible]}))}},title:'{{t("Add new")}}',properties:{displayName:{"x-component":"CollectionField","x-decorator":"FormItem"},name:{"x-component":"CollectionField","x-decorator":"FormItem"},pinned:{"x-component":"CollectionField","x-decorator":"FormItem"},"options.standaloneDeployment":{"x-component":"Checkbox","x-decorator":"FormItem","x-content":i("Standalone deployment")},"options.autoStart":{"x-component":"Checkbox","x-decorator":"FormItem","x-content":i("Auto start")},cname:{title:i("Custom domain"),"x-component":"Input","x-decorator":"FormItem"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useCreateAction }}"}}}}}}}}}},table:{type:"void","x-uid":"input","x-component":"Table.Void","x-component-props":{rowKey:"name",rowSelection:{type:"checkbox"},useDataSource:"{{ cm.useDataSourceFromRAC }}"},properties:{displayName:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{displayName:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},name:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{name:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},pinned:{type:"void",title:i("Pin to menu"),"x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{pinned:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},status:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{status:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},actions:{type:"void",title:'{{t("Actions")}}',"x-component":"Table.Column",properties:{actions:y({type:"void","x-component":"Space","x-component-props":{split:"|"}},C)}}}}}}}},k=()=>{var r;const e=t.useRecord();return(r=e.options)!=null&&r.standaloneDeployment&&e.cname?`//${e.cname}`:`/apps/${e.name}/admin/`},w=()=>{const{t:e}=a(),r=k();return o.jsx("a",{href:r,target:"_blank",rel:"noreferrer",children:e("View",{ns:"client"})})},P=()=>o.jsx(c.Card,{bordered:!1,children:o.jsx(t.SchemaComponent,{schema:I,components:{AppVisitor:w}})}),T=e=>{const r=e.value&&o.jsx("a",{target:"_blank",href:`/apps/${e.value}/admin`,rel:"noreferrer",children:e.value});return o.jsxs("div",{style:e.style,children:[e.addonBefore,e.prefix,r,e.suffix,e.addonAfter]})},M=s.connect(c.Input,s.mapReadPretty(T)),q=()=>{const{data:e,run:r}=t.useRequest({resource:"applications",action:"listPinned"},{manual:!0}),{t:u}=a(),x=[...((e==null?void 0:e.data)||[]).map(p=>{var v;let g=`/apps/${p.name}/admin/`;return(v=p.options)!=null&&v.standaloneDeployment&&p.cname&&(g=`//${p.cname}`),{key:p.name,label:o.jsx("a",{href:g,target:"_blank",rel:"noopener noreferrer",children:p.displayName||p.name})}}),{key:".manager",label:o.jsx(l.Link,{to:"/admin/settings/multi-app-manager/applications",children:u("Manage applications")})}];return o.jsx(c.Dropdown,{onOpenChange:p=>{r()},menu:{items:x},children:o.jsx(c.Button,{title:"Apps",icon:o.jsx(t.Icon,{type:"AppstoreOutlined"})})})},N=e=>{const{t:r}=a();return o.jsx(t.PinnedPluginListProvider,{items:{am:{order:201,component:"MultiAppManager",pin:!0}},children:o.jsx(t.SchemaComponentOptions,{components:{MultiAppManager:q,AppNameInput:M},children:o.jsx(t.SettingsCenterProvider,{settings:{"multi-app-manager":{title:r("Multi-app manager"),icon:"AppstoreOutlined",tabs:{applications:{title:r("Applications"),component:()=>o.jsx(P,{})}}}},children:e.children})})})};class b extends t.Plugin{load(){return A(this,null,function*(){this.app.use(N)})}}n.MultiAppManagerPlugin=b,n.default=b,n.tableActionColumnSchema=C,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(n,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("antd"),require("react-router-dom"),require("@formily/shared"),require("react"),require("react-i18next"),require("@formily/react")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","antd","react-router-dom","@formily/shared","react","react-i18next","@formily/react"],t):(n=typeof globalThis!="undefined"?globalThis:n||self,t(n["@nocobase/plugin-multi-app-manager"]={},n["@nocobase/client"],n.jsxRuntime,n.antd,n["react-router-dom"],n["@formily/shared"],n.react,n["react-i18next"],n["@formily/react"]))})(this,function(n,t,o,s,m,u,x,l,i){"use strict";var j=Object.defineProperty,_=Object.defineProperties;var $=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var w=(n,t,o)=>t in n?j(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,d=(n,t)=>{for(var o in t||(t={}))z.call(t,o)&&w(n,o,t[o]);if(F)for(var o of F(t))B.call(t,o)&&w(n,o,t[o]);return n},v=(n,t)=>_(n,$(t));var g=(n,t,o)=>new Promise((s,m)=>{var u=i=>{try{l(o.next(i))}catch(c){m(c)}},x=i=>{try{l(o.throw(i))}catch(c){m(c)}},l=i=>i.done?s(i.value):Promise.resolve(i.value).then(u,x);l((o=o.apply(n,t)).next())});const c=()=>{const{t:e}=l.useTranslation("multi-app-manager");return{t:e}},a=e=>`{{t("${e}", { ns: 'multi-app-manager' })}}`,b={name:"applications",targetKey:"name",fields:[{type:"uid",name:"name",primaryKey:!0,prefix:"a",interface:"input",uiSchema:{type:"string",title:a("App ID"),required:!0,"x-component":"Input","x-validator":"uid"}},{type:"string",name:"displayName",interface:"input",uiSchema:{type:"string",title:a("App display name"),required:!0,"x-component":"Input"}},{type:"string",name:"pinned",interface:"checkbox",uiSchema:{type:"boolean","x-content":a("Pin to menu"),"x-component":"Checkbox"}},{type:"string",name:"status",interface:"radioGroup",defaultValue:"pending",uiSchema:{type:"string",title:a("App status"),enum:[{label:"Initializing",value:"initializing"},{label:"Initialized",value:"initialized"},{label:"Running",value:"running"},{label:"Commanding",value:"commanding"},{label:"Stopped",value:"stopped"},{label:"Error",value:"error"},{label:"Not found",value:"not_found"}],"x-component":"Radio.Group"}}]},P=()=>{const{state:e,setState:r,refresh:A}=t.useResourceActionContext(),{resource:f}=t.useResourceContext();return{run(){return g(this,null,function*(){yield f.destroy({filterByTk:(e==null?void 0:e.selectedRowKeys)||[]}),r==null||r({selectedRowKeys:[]}),A()})}}},y={type:"void","x-component":"div",properties:{displayName:{"x-component":"CollectionField","x-decorator":"FormItem"},name:{"x-component":"CollectionField","x-decorator":"FormItem","x-disabled":"{{ !createOnly }}"},pinned:{"x-component":"CollectionField","x-decorator":"FormItem"},"options.standaloneDeployment":{"x-component":"Checkbox","x-decorator":"FormItem","x-content":a("Standalone deployment")},"options.autoStart":{"x-component":"Checkbox","x-decorator":"FormItem","x-content":a("Auto start")},cname:{title:a("Custom domain"),"x-component":"Input","x-decorator":"FormItem"}}},h={properties:{view:{type:"void","x-component":"AppVisitor","x-component-props":{}},update:{type:"void",title:'{{t("Edit")}}',"x-component":"Action.Link","x-component-props":{},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues:"{{ cm.useValuesFromRecord }}"},title:'{{t("Edit")}}',properties:{formSchema:y,footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useUpdateAction }}"}}}}}}}},delete:{type:"void",title:'{{ t("Delete") }}',"x-component":"Action.Link","x-component-props":{confirm:{title:"{{t('Delete')}}",content:"{{t('Are you sure you want to delete it?')}}"},useAction:"{{cm.useDestroyAction}}"}}}},k={type:"object",properties:{[u.uid()]:{type:"void","x-decorator":"ResourceActionProvider","x-decorator-props":{collection:b,resourceName:"applications",request:{resource:"applications",action:"list",params:{pageSize:50,sort:["-createdAt"],appends:[]}}},"x-component":"CollectionProvider","x-component-props":{collection:b},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{delete:{type:"void",title:'{{ t("Delete") }}',"x-component":"Action","x-component-props":{useAction:P,confirm:{title:"{{t('Delete')}}",content:"{{t('Are you sure you want to delete it?')}}"}}},create:{type:"void",title:'{{t("Add new")}}',"x-decorator":e=>x.createElement(t.SchemaComponentOptions,v(d({},e),{scope:{createOnly:!0}})),"x-component":"Action","x-component-props":{type:"primary"},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues(e){const r=t.useActionContext();return t.useRequest(()=>Promise.resolve({data:{name:`a_${u.uid()}`}}),v(d({},e),{refreshDeps:[r.visible]}))}},title:'{{t("Add new")}}',properties:{formSchema:y,footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useCreateAction }}"}}}}}}}}}},table:{type:"void","x-uid":"input","x-component":"Table.Void","x-component-props":{rowKey:"name",rowSelection:{type:"checkbox"},useDataSource:"{{ cm.useDataSourceFromRAC }}"},properties:{displayName:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{displayName:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},name:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{name:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},pinned:{type:"void",title:a("Pin to menu"),"x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{pinned:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},status:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{status:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},actions:{type:"void",title:'{{t("Actions")}}',"x-component":"Table.Column",properties:{actions:d({type:"void","x-component":"Space","x-component-props":{split:"|"}},h)}}}}}}}},T=()=>{var r;const e=t.useRecord();return(r=e.options)!=null&&r.standaloneDeployment&&e.cname?`//${e.cname}`:`/apps/${e.name}/admin/`},I=()=>{const{t:e}=c(),r=T();return o.jsx("a",{href:r,target:"_blank",rel:"noreferrer",children:e("View",{ns:"client"})})},M=()=>o.jsx(s.Card,{bordered:!1,children:o.jsx(t.SchemaComponent,{schema:k,components:{AppVisitor:I}})}),q=e=>{const r=e.value&&o.jsx("a",{target:"_blank",href:`/apps/${e.value}/admin`,rel:"noreferrer",children:e.value});return o.jsxs("div",{style:e.style,children:[e.addonBefore,e.prefix,r,e.suffix,e.addonAfter]})},N=i.connect(s.Input,i.mapReadPretty(q)),O=()=>{const{data:e,run:r}=t.useRequest({resource:"applications",action:"listPinned"},{manual:!0}),{t:A}=c(),f=[...((e==null?void 0:e.data)||[]).map(p=>{var D;let S=`/apps/${p.name}/admin/`;return(D=p.options)!=null&&D.standaloneDeployment&&p.cname&&(S=`//${p.cname}`),{key:p.name,label:o.jsx("a",{href:S,target:"_blank",rel:"noopener noreferrer",children:p.displayName||p.name})}}),{key:".manager",label:o.jsx(m.Link,{to:"/admin/settings/multi-app-manager/applications",children:A("Manage applications")})}];return o.jsx(s.Dropdown,{onOpenChange:p=>{r()},menu:{items:f},children:o.jsx(s.Button,{title:"Apps",icon:o.jsx(t.Icon,{type:"AppstoreOutlined"})})})},V=e=>{const{t:r}=c();return o.jsx(t.PinnedPluginListProvider,{items:{am:{order:201,component:"MultiAppManager",pin:!0}},children:o.jsx(t.SchemaComponentOptions,{components:{MultiAppManager:O,AppNameInput:N},children:o.jsx(t.SettingsCenterProvider,{settings:{"multi-app-manager":{title:r("Multi-app manager"),icon:"AppstoreOutlined",tabs:{applications:{title:r("Applications"),component:()=>o.jsx(M,{})}}}},children:e.children})})})};class C extends t.Plugin{load(){return g(this,null,function*(){this.app.use(V)})}}n.MultiAppManagerPlugin=C,n.default=C,n.formSchema=y,n.tableActionColumnSchema=h,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -5,88 +5,6 @@ export declare const useDestroy: () => {
5
5
  export declare const useDestroyAll: () => {
6
6
  run(): Promise<void>;
7
7
  };
8
- export declare const tableActionColumnSchema: {
9
- properties: {
10
- view: {
11
- type: string;
12
- 'x-component': string;
13
- 'x-component-props': {};
14
- };
15
- update: {
16
- type: string;
17
- title: string;
18
- 'x-component': string;
19
- 'x-component-props': {};
20
- properties: {
21
- drawer: {
22
- type: string;
23
- 'x-component': string;
24
- 'x-decorator': string;
25
- 'x-decorator-props': {
26
- useValues: string;
27
- };
28
- title: string;
29
- properties: {
30
- displayName: {
31
- 'x-component': string;
32
- 'x-decorator': string;
33
- };
34
- pinned: {
35
- 'x-component': string;
36
- 'x-decorator': string;
37
- };
38
- 'options.standaloneDeployment': {
39
- 'x-component': string;
40
- 'x-decorator': string;
41
- 'x-content': string;
42
- };
43
- 'options.autoStart': {
44
- 'x-component': string;
45
- 'x-decorator': string;
46
- 'x-content': string;
47
- };
48
- cname: {
49
- title: string;
50
- 'x-component': string;
51
- 'x-decorator': string;
52
- };
53
- footer: {
54
- type: string;
55
- 'x-component': string;
56
- properties: {
57
- cancel: {
58
- title: string;
59
- 'x-component': string;
60
- 'x-component-props': {
61
- useAction: string;
62
- };
63
- };
64
- submit: {
65
- title: string;
66
- 'x-component': string;
67
- 'x-component-props': {
68
- type: string;
69
- useAction: string;
70
- };
71
- };
72
- };
73
- };
74
- };
75
- };
76
- };
77
- };
78
- delete: {
79
- type: string;
80
- title: string;
81
- 'x-component': string;
82
- 'x-component-props': {
83
- confirm: {
84
- title: string;
85
- content: string;
86
- };
87
- useAction: string;
88
- };
89
- };
90
- };
91
- };
8
+ export declare const formSchema: ISchema;
9
+ export declare const tableActionColumnSchema: ISchema;
92
10
  export declare const schema: ISchema;
@@ -1,12 +1,12 @@
1
1
  module.exports = {
2
- "@nocobase/client": "0.14.0-alpha.7",
2
+ "@nocobase/client": "0.14.0-alpha.8",
3
3
  "antd": "5.8.6",
4
4
  "react": "18.2.0",
5
5
  "@formily/react": "2.2.27",
6
6
  "react-router-dom": "6.14.1",
7
7
  "react-i18next": "11.18.6",
8
- "@nocobase/database": "0.14.0-alpha.7",
9
- "@nocobase/server": "0.14.0-alpha.7",
8
+ "@nocobase/database": "0.14.0-alpha.8",
9
+ "@nocobase/server": "0.14.0-alpha.8",
10
10
  "async-mutex": "0.3.2",
11
11
  "lodash": "4.17.21",
12
12
  "mysql2": "2.3.3",
@@ -1,6 +1,8 @@
1
1
  import { IDatabaseOptions, Transactionable } from '@nocobase/database';
2
2
  import Application, { Plugin } from '@nocobase/server';
3
- export type AppDbCreator = (app: Application, transaction?: Transactionable) => Promise<void>;
3
+ export type AppDbCreator = (app: Application, options?: Transactionable & {
4
+ context?: any;
5
+ }) => Promise<void>;
4
6
  export type AppOptionsFactory = (appName: string, mainApp: Application) => any;
5
7
  export type SubAppUpgradeHandler = (mainApp: Application) => Promise<void>;
6
8
  export declare class PluginMultiAppManager extends Plugin {
@@ -35,8 +35,6 @@ var import_server = require("@nocobase/server");
35
35
  var import_async_mutex = require("async-mutex");
36
36
  var import_lodash = __toESM(require("lodash"));
37
37
  var import_path = __toESM(require("path"));
38
- var import_qs = __toESM(require("qs"));
39
- var import_url = require("url");
40
38
  var import_server2 = require("../server");
41
39
  const defaultSubAppUpgradeHandle = async (mainApp) => {
42
40
  const repository = mainApp.db.getRepository("applications");
@@ -127,7 +125,10 @@ class PluginMultiAppManager extends import_server.Plugin {
127
125
  subAppUpgradeHandler = defaultSubAppUpgradeHandle;
128
126
  beforeGetApplicationMutex = new import_async_mutex.Mutex();
129
127
  static getDatabaseConfig(app) {
130
- const oldConfig = app.options.database instanceof import_database.Database ? app.options.database.options : app.options.database;
128
+ let oldConfig = app.options.database instanceof import_database.Database ? app.options.database.options : app.options.database;
129
+ if (!oldConfig && app.db) {
130
+ oldConfig = app.db.options;
131
+ }
131
132
  return import_lodash.default.cloneDeep(import_lodash.default.omit(oldConfig, ["migrator"]));
132
133
  }
133
134
  setSubAppUpgradeHandler(handler) {
@@ -148,18 +149,24 @@ class PluginMultiAppManager extends import_server.Plugin {
148
149
  await this.db.import({
149
150
  directory: (0, import_path.resolve)(__dirname, "collections")
150
151
  });
151
- this.db.on("applications.afterCreateWithAssociations", async (model, options) => {
152
- var _a;
153
- const { transaction } = options;
154
- const subApp = model.registerToSupervisor(this.app, {
155
- appOptionsFactory: this.appOptionsFactory
156
- });
157
- await this.appDbCreator(subApp, transaction);
158
- const startPromise = subApp.runAsCLI(["start", "--quickstart"], { from: "user" });
159
- if ((_a = options == null ? void 0 : options.context) == null ? void 0 : _a.waitSubAppInstall) {
160
- await startPromise;
152
+ this.db.on(
153
+ "applications.afterCreateWithAssociations",
154
+ async (model, options) => {
155
+ var _a;
156
+ const { transaction } = options;
157
+ const subApp = model.registerToSupervisor(this.app, {
158
+ appOptionsFactory: this.appOptionsFactory
159
+ });
160
+ await this.appDbCreator(subApp, {
161
+ transaction,
162
+ context: options.context
163
+ });
164
+ const startPromise = subApp.runCommand("start", "--quickstart");
165
+ if ((_a = options == null ? void 0 : options.context) == null ? void 0 : _a.waitSubAppInstall) {
166
+ await startPromise;
167
+ }
161
168
  }
162
- });
169
+ );
163
170
  this.db.on("applications.afterDestroy", async (model) => {
164
171
  await import_server.AppSupervisor.getInstance().removeApp(model.get("name"));
165
172
  });
@@ -169,6 +176,7 @@ class PluginMultiAppManager extends import_server.Plugin {
169
176
  appName,
170
177
  options
171
178
  }) {
179
+ const loadButNotStart = options == null ? void 0 : options.upgrading;
172
180
  const name = appName;
173
181
  if (appSupervisor.hasApp(name)) {
174
182
  return;
@@ -191,24 +199,18 @@ class PluginMultiAppManager extends import_server.Plugin {
191
199
  const subApp = applicationRecord.registerToSupervisor(self.app, {
192
200
  appOptionsFactory: self.appOptionsFactory
193
201
  });
194
- if (!(options == null ? void 0 : options.upgrading)) {
195
- await subApp.runCommand("start");
202
+ if (!loadButNotStart) {
203
+ await subApp.runCommand("start", "--quickstart");
196
204
  }
197
205
  }
198
206
  import_server.AppSupervisor.getInstance().setAppBootstrapper(LazyLoadApplication);
199
- import_server.Gateway.getInstance().setAppSelector(async (req) => {
200
- var _a;
201
- const appName = (_a = import_qs.default.parse((0, import_url.parse)(req.url).query)) == null ? void 0 : _a.__appName;
202
- if (appName) {
203
- return appName;
204
- }
205
- if (req.headers["x-app"]) {
206
- return req.headers["x-app"];
207
- }
208
- if (req.headers["x-hostname"]) {
207
+ import_server.Gateway.getInstance().addAppSelectorMiddleware(async (ctx, next) => {
208
+ const { req } = ctx;
209
+ if (!ctx.resolvedAppName && req.headers["x-hostname"]) {
209
210
  const repository = this.db.getRepository("applications");
210
211
  if (!repository) {
211
- return null;
212
+ await next();
213
+ return;
212
214
  }
213
215
  const appInstance = await repository.findOne({
214
216
  filter: {
@@ -216,17 +218,17 @@ class PluginMultiAppManager extends import_server.Plugin {
216
218
  }
217
219
  });
218
220
  if (appInstance) {
219
- return appInstance.name;
221
+ ctx.resolvedAppName = appInstance.name;
220
222
  }
221
223
  }
222
- return null;
224
+ await next();
223
225
  });
224
226
  this.app.on("afterStart", async (app) => {
225
227
  const repository = this.db.getRepository("applications");
226
228
  const appSupervisor = import_server.AppSupervisor.getInstance();
227
229
  this.app.setMaintainingMessage("starting sub applications...");
228
230
  if (appSupervisor.runningMode == "single") {
229
- import_server.Gateway.getInstance().setAppSelector(() => appSupervisor.singleAppName);
231
+ import_server.Gateway.getInstance().addAppSelectorMiddleware((ctx) => ctx.resolvedAppName = appSupervisor.singleAppName);
230
232
  try {
231
233
  await import_server.AppSupervisor.getInstance().getApp(appSupervisor.singleAppName);
232
234
  } catch (err) {
@@ -244,7 +246,11 @@ class PluginMultiAppManager extends import_server.Plugin {
244
246
  for (const subAppInstance of subApps) {
245
247
  promises.push(
246
248
  (async () => {
247
- await import_server.AppSupervisor.getInstance().getApp(subAppInstance.name);
249
+ if (!appSupervisor.hasApp(subAppInstance.name)) {
250
+ await import_server.AppSupervisor.getInstance().getApp(subAppInstance.name);
251
+ } else if (appSupervisor.getAppStatus(subAppInstance.name) === "initialized") {
252
+ (await import_server.AppSupervisor.getInstance().getApp(subAppInstance.name)).runCommand("start", "--quickstart");
253
+ }
248
254
  })()
249
255
  );
250
256
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "多应用管理器",
5
5
  "description": "Dynamically create multiple apps without separate deployments",
6
6
  "description.zh-CN": "无需单独部署即可动态创建多个应用",
7
- "version": "0.14.0-alpha.7",
7
+ "version": "0.14.0-alpha.8",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "devDependencies": {
@@ -25,5 +25,5 @@
25
25
  "@nocobase/test": "0.x",
26
26
  "@nocobase/utils": "0.x"
27
27
  },
28
- "gitHead": "dc958417d27ed0753439bcef192be91a03dfc30f"
28
+ "gitHead": "59c82fef6e34707802b5841f5ec4d9b3b6b68abb"
29
29
  }
@@ -1,43 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- indent_style = space
5
- indent_size = 4
6
- end_of_line = lf
7
- charset = utf-8
8
- trim_trailing_whitespace = true
9
- insert_final_newline = true
10
- max_line_length = 160
11
- quote_type = single
12
-
13
- [test/*]
14
- max_line_length = off
15
-
16
- [LICENSE.md]
17
- indent_size = off
18
-
19
- [*.md]
20
- max_line_length = off
21
-
22
- [*.json]
23
- max_line_length = off
24
-
25
- [Makefile]
26
- max_line_length = off
27
-
28
- [CHANGELOG.md]
29
- indent_style = space
30
- indent_size = 2
31
-
32
- [LICENSE]
33
- indent_size = 2
34
- max_line_length = off
35
-
36
- [coverage/**/*]
37
- indent_size = off
38
- indent_style = off
39
- indent = off
40
- max_line_length = off
41
-
42
- [.nycrc]
43
- indent_style = tab
@@ -1,38 +0,0 @@
1
- {
2
- "root": true,
3
-
4
- "extends": "@ljharb",
5
-
6
- "ignorePatterns": [
7
- "dist/",
8
- ],
9
-
10
- "rules": {
11
- "complexity": 0,
12
- "consistent-return": 1,
13
- "func-name-matching": 0,
14
- "id-length": [2, { "min": 1, "max": 25, "properties": "never" }],
15
- "indent": [2, 4],
16
- "max-lines-per-function": [2, { "max": 150 }],
17
- "max-params": [2, 16],
18
- "max-statements": [2, 100],
19
- "multiline-comment-style": 0,
20
- "no-continue": 1,
21
- "no-magic-numbers": 0,
22
- "no-restricted-syntax": [2, "BreakStatement", "DebuggerStatement", "ForInStatement", "LabeledStatement", "WithStatement"],
23
- },
24
-
25
- "overrides": [
26
- {
27
- "files": "test/**",
28
- "rules": {
29
- "function-paren-newline": 0,
30
- "max-lines-per-function": 0,
31
- "max-statements": 0,
32
- "no-buffer-constructor": 0,
33
- "no-extend-native": 0,
34
- "no-throw-literal": 0,
35
- },
36
- },
37
- ],
38
- }
@@ -1,12 +0,0 @@
1
- # These are supported funding model platforms
2
-
3
- github: [ljharb]
4
- patreon: # Replace with a single Patreon username
5
- open_collective: # Replace with a single Open Collective username
6
- ko_fi: # Replace with a single Ko-fi username
7
- tidelift: npm/qs
8
- community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
- liberapay: # Replace with a single Liberapay username
10
- issuehunt: # Replace with a single IssueHunt username
11
- otechie: # Replace with a single Otechie username
12
- custom: # Replace with a single custom sponsorship URL
@@ -1,13 +0,0 @@
1
- {
2
- "all": true,
3
- "check-coverage": false,
4
- "reporter": ["text-summary", "text", "html", "json"],
5
- "lines": 86,
6
- "statements": 85.93,
7
- "functions": 82.43,
8
- "branches": 76.06,
9
- "exclude": [
10
- "coverage",
11
- "dist"
12
- ]
13
- }