@nocobase/plugin-multi-app-manager 0.14.0-alpha.6 → 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.6",
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.6",
9
- "@nocobase/server": "0.14.0-alpha.6",
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,12 +1,17 @@
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;
7
+ export type SubAppUpgradeHandler = (mainApp: Application) => Promise<void>;
5
8
  export declare class PluginMultiAppManager extends Plugin {
6
9
  appDbCreator: AppDbCreator;
7
10
  appOptionsFactory: AppOptionsFactory;
11
+ subAppUpgradeHandler: SubAppUpgradeHandler;
8
12
  private beforeGetApplicationMutex;
9
13
  static getDatabaseConfig(app: Application): IDatabaseOptions;
14
+ setSubAppUpgradeHandler(handler: SubAppUpgradeHandler): void;
10
15
  setAppOptionsFactory(factory: AppOptionsFactory): void;
11
16
  setAppDbCreator(appDbCreator: AppDbCreator): void;
12
17
  beforeLoad(): void;
@@ -35,9 +35,41 @@ 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");
39
+ const defaultSubAppUpgradeHandle = async (mainApp) => {
40
+ const repository = mainApp.db.getRepository("applications");
41
+ const findOptions = {};
42
+ const appSupervisor = import_server.AppSupervisor.getInstance();
43
+ if (appSupervisor.runningMode == "single") {
44
+ findOptions["filter"] = {
45
+ name: appSupervisor.singleAppName
46
+ };
47
+ }
48
+ const instances = await repository.find(findOptions);
49
+ for (const instance of instances) {
50
+ const instanceOptions = instance.get("options");
51
+ if ((instanceOptions == null ? void 0 : instanceOptions.standaloneDeployment) && appSupervisor.runningMode !== "single") {
52
+ continue;
53
+ }
54
+ const beforeSubAppStatus = import_server.AppSupervisor.getInstance().getAppStatus(instance.name);
55
+ const subApp = await appSupervisor.getApp(instance.name, {
56
+ upgrading: true
57
+ });
58
+ console.log({ beforeSubAppStatus });
59
+ try {
60
+ mainApp.setMaintainingMessage(`upgrading sub app ${instance.name}...`);
61
+ console.log(`${instance.name}: upgrading...`);
62
+ await subApp.runAsCLI(["upgrade"], { from: "user" });
63
+ if (!beforeSubAppStatus && import_server.AppSupervisor.getInstance().getAppStatus(instance.name) === "initialized") {
64
+ await import_server.AppSupervisor.getInstance().removeApp(instance.name);
65
+ }
66
+ } catch (error) {
67
+ console.log(`${instance.name}: upgrade failed`);
68
+ mainApp.logger.error(error);
69
+ console.error(error);
70
+ }
71
+ }
72
+ };
41
73
  const defaultDbCreator = async (app) => {
42
74
  const databaseOptions = app.options.database;
43
75
  const { host, port, username, password, dialect, database } = databaseOptions;
@@ -90,11 +122,18 @@ const defaultAppOptionsFactory = (appName, mainApp) => {
90
122
  class PluginMultiAppManager extends import_server.Plugin {
91
123
  appDbCreator = defaultDbCreator;
92
124
  appOptionsFactory = defaultAppOptionsFactory;
125
+ subAppUpgradeHandler = defaultSubAppUpgradeHandle;
93
126
  beforeGetApplicationMutex = new import_async_mutex.Mutex();
94
127
  static getDatabaseConfig(app) {
95
- 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
+ }
96
132
  return import_lodash.default.cloneDeep(import_lodash.default.omit(oldConfig, ["migrator"]));
97
133
  }
134
+ setSubAppUpgradeHandler(handler) {
135
+ this.subAppUpgradeHandler = handler;
136
+ }
98
137
  setAppOptionsFactory(factory) {
99
138
  this.appOptionsFactory = factory;
100
139
  }
@@ -110,18 +149,24 @@ class PluginMultiAppManager extends import_server.Plugin {
110
149
  await this.db.import({
111
150
  directory: (0, import_path.resolve)(__dirname, "collections")
112
151
  });
113
- this.db.on("applications.afterCreateWithAssociations", async (model, options) => {
114
- var _a;
115
- const { transaction } = options;
116
- const subApp = model.registerToSupervisor(this.app, {
117
- appOptionsFactory: this.appOptionsFactory
118
- });
119
- await this.appDbCreator(subApp, transaction);
120
- const startPromise = subApp.runAsCLI(["start", "--quickstart"], { from: "user" });
121
- if ((_a = options == null ? void 0 : options.context) == null ? void 0 : _a.waitSubAppInstall) {
122
- 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
+ }
123
168
  }
124
- });
169
+ );
125
170
  this.db.on("applications.afterDestroy", async (model) => {
126
171
  await import_server.AppSupervisor.getInstance().removeApp(model.get("name"));
127
172
  });
@@ -131,6 +176,7 @@ class PluginMultiAppManager extends import_server.Plugin {
131
176
  appName,
132
177
  options
133
178
  }) {
179
+ const loadButNotStart = options == null ? void 0 : options.upgrading;
134
180
  const name = appName;
135
181
  if (appSupervisor.hasApp(name)) {
136
182
  return;
@@ -153,24 +199,18 @@ class PluginMultiAppManager extends import_server.Plugin {
153
199
  const subApp = applicationRecord.registerToSupervisor(self.app, {
154
200
  appOptionsFactory: self.appOptionsFactory
155
201
  });
156
- if (!(options == null ? void 0 : options.upgrading)) {
157
- await subApp.runCommand("start");
202
+ if (!loadButNotStart) {
203
+ await subApp.runCommand("start", "--quickstart");
158
204
  }
159
205
  }
160
206
  import_server.AppSupervisor.getInstance().setAppBootstrapper(LazyLoadApplication);
161
- import_server.Gateway.getInstance().setAppSelector(async (req) => {
162
- var _a;
163
- const appName = (_a = import_qs.default.parse((0, import_url.parse)(req.url).query)) == null ? void 0 : _a.__appName;
164
- if (appName) {
165
- return appName;
166
- }
167
- if (req.headers["x-app"]) {
168
- return req.headers["x-app"];
169
- }
170
- 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"]) {
171
210
  const repository = this.db.getRepository("applications");
172
211
  if (!repository) {
173
- return null;
212
+ await next();
213
+ return;
174
214
  }
175
215
  const appInstance = await repository.findOne({
176
216
  filter: {
@@ -178,17 +218,17 @@ class PluginMultiAppManager extends import_server.Plugin {
178
218
  }
179
219
  });
180
220
  if (appInstance) {
181
- return appInstance.name;
221
+ ctx.resolvedAppName = appInstance.name;
182
222
  }
183
223
  }
184
- return null;
224
+ await next();
185
225
  });
186
226
  this.app.on("afterStart", async (app) => {
187
227
  const repository = this.db.getRepository("applications");
188
228
  const appSupervisor = import_server.AppSupervisor.getInstance();
189
229
  this.app.setMaintainingMessage("starting sub applications...");
190
230
  if (appSupervisor.runningMode == "single") {
191
- import_server.Gateway.getInstance().setAppSelector(() => appSupervisor.singleAppName);
231
+ import_server.Gateway.getInstance().addAppSelectorMiddleware((ctx) => ctx.resolvedAppName = appSupervisor.singleAppName);
192
232
  try {
193
233
  await import_server.AppSupervisor.getInstance().getApp(appSupervisor.singleAppName);
194
234
  } catch (err) {
@@ -206,7 +246,11 @@ class PluginMultiAppManager extends import_server.Plugin {
206
246
  for (const subAppInstance of subApps) {
207
247
  promises.push(
208
248
  (async () => {
209
- 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
+ }
210
254
  })()
211
255
  );
212
256
  }
@@ -216,39 +260,7 @@ class PluginMultiAppManager extends import_server.Plugin {
216
260
  }
217
261
  });
218
262
  this.app.on("afterUpgrade", async (app, options) => {
219
- const cliArgs = options == null ? void 0 : options.cliArgs;
220
- const repository = this.db.getRepository("applications");
221
- const findOptions = {};
222
- const appSupervisor = import_server.AppSupervisor.getInstance();
223
- if (appSupervisor.runningMode == "single") {
224
- findOptions["filter"] = {
225
- name: appSupervisor.singleAppName
226
- };
227
- }
228
- const instances = await repository.find(findOptions);
229
- for (const instance of instances) {
230
- const instanceOptions = instance.get("options");
231
- if ((instanceOptions == null ? void 0 : instanceOptions.standaloneDeployment) && appSupervisor.runningMode !== "single") {
232
- continue;
233
- }
234
- const beforeSubAppStatus = import_server.AppSupervisor.getInstance().getAppStatus(instance.name);
235
- const subApp = await appSupervisor.getApp(instance.name, {
236
- upgrading: true
237
- });
238
- console.log({ beforeSubAppStatus });
239
- try {
240
- this.app.setMaintainingMessage(`upgrading sub app ${instance.name}...`);
241
- console.log(`${instance.name}: upgrading...`);
242
- await subApp.runAsCLI(["upgrade"], { from: "user" });
243
- if (!beforeSubAppStatus && import_server.AppSupervisor.getInstance().getAppStatus(instance.name) === "initialized") {
244
- await import_server.AppSupervisor.getInstance().removeApp(instance.name);
245
- }
246
- } catch (error) {
247
- console.log(`${instance.name}: upgrade failed`);
248
- this.app.logger.error(error);
249
- console.error(error);
250
- }
251
- }
263
+ await this.subAppUpgradeHandler(app);
252
264
  });
253
265
  this.app.resourcer.registerActionHandlers({
254
266
  "applications:listPinned": async (ctx, next) => {
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.6",
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": "7f2858222231c207030b57704a0bb6ebc98e4e45"
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
- }