@yongdall/scene 0.4.0 → 0.5.2

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.
@@ -0,0 +1,80 @@
1
+ import { createField, createModel, uuid } from "@yongdall/model";
2
+
3
+ //#region plugins/scene/models/Scene.mjs
4
+ const SceneField = createModel("scene.field", {
5
+ sceneId: createField("uuid", {
6
+ nullable: false,
7
+ label: "ID",
8
+ primary: 1,
9
+ layout: { hidden: true }
10
+ }),
11
+ model: createField("string", {
12
+ label: "model",
13
+ primary: 2
14
+ }),
15
+ column: createField("string", { label: "Table Field" }),
16
+ field: createField("string", {
17
+ label: "Field",
18
+ primary: 3
19
+ }),
20
+ fixedValue: createField("json", { label: "固定值" }),
21
+ no: createField("i32")
22
+ });
23
+ const SceneTable = createModel("scene.table", {
24
+ sceneId: createField("uuid", {
25
+ nullable: false,
26
+ label: "ID",
27
+ primary: 1,
28
+ layout: { hidden: true }
29
+ }),
30
+ model: createField("string", {
31
+ label: "Model",
32
+ primary: 2
33
+ }),
34
+ table: createField("string", { label: "Table" }),
35
+ no: createField("i32"),
36
+ fields: createField(SceneField, {
37
+ array: true,
38
+ constraints: {
39
+ sceneId: { field: "sceneId" },
40
+ model: { field: "model" },
41
+ no: { noField: true }
42
+ },
43
+ label: "Fields"
44
+ })
45
+ });
46
+ var Scene_default = createModel("scene", {
47
+ id: createField("uuid", {
48
+ nullable: false,
49
+ default: uuid,
50
+ label: "ID",
51
+ primary: 1,
52
+ layout: { hidden: true }
53
+ }),
54
+ label: createField("string", {
55
+ nullable: false,
56
+ default: "",
57
+ label: "Label"
58
+ }),
59
+ dbId: createField("string", {
60
+ nullable: false,
61
+ default: "",
62
+ label: "Database"
63
+ }),
64
+ type: createField("string", {
65
+ nullable: false,
66
+ label: "Type"
67
+ }),
68
+ tables: createField(SceneTable, {
69
+ array: true,
70
+ constraints: {
71
+ sceneId: { field: "id" },
72
+ no: { noField: true }
73
+ },
74
+ label: "tables"
75
+ })
76
+ });
77
+
78
+ //#endregion
79
+ export { Scene_default as t };
80
+ //# sourceMappingURL=Scene-B_dHIwLD.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Scene-B_dHIwLD.mjs","names":[],"sources":["../../plugins/scene/models/Scene.mjs"],"sourcesContent":["import { createField, createModel, uuid } from '@yongdall/model';\n\nconst SceneField = createModel('scene.field', {\n\tsceneId: createField('uuid', { nullable: false, label: 'ID', primary: 1, layout: {hidden: true} }),\n\tmodel: createField('string', {label: 'model', primary: 2}),\n\n\tcolumn: createField('string', { label: 'Table Field'}),\n\n\tfield: createField('string', { label: 'Field', primary: 3}),\n\tfixedValue: createField('json', { label: '固定值'}),\n\n\tno: createField('i32'),\n\n\t// TODO: 类型、样式、渲染\n});\n\nconst SceneTable = createModel('scene.table', {\n\tsceneId: createField('uuid', { nullable: false, label: 'ID', primary: 1, layout: {hidden: true} }),\n\tmodel: createField('string', {label: 'Model', primary: 2}),\n\t\n\ttable: createField('string', {label: 'Table'}),\n\tno: createField('i32'),\n\tfields: createField(SceneField, { array: true, constraints: {sceneId: {field: 'sceneId'}, model: {field: 'model'}, no: {noField: true}}, label: 'Fields' }),\n});\n\nexport default createModel('scene', {\n\tid: createField('uuid', { nullable: false, default: uuid, label: 'ID', primary: 1, layout: {hidden: true} }),\n\n\tlabel: createField('string', { nullable: false, default: '', label: 'Label' }),\n\n\tdbId: createField('string', { nullable: false, default: '', label: 'Database' }),\n\ttype: createField('string', { nullable: false, label: 'Type' }),\n\ttables: createField(SceneTable, { array: true, constraints: {sceneId: {field: 'id'}, no: {noField: true}}, label: 'tables' }),\n});\n"],"mappings":";;;AAEA,MAAM,aAAa,YAAY,eAAe;CAC7C,SAAS,YAAY,QAAQ;EAAE,UAAU;EAAO,OAAO;EAAM,SAAS;EAAG,QAAQ,EAAC,QAAQ,MAAK;EAAE,CAAC;CAClG,OAAO,YAAY,UAAU;EAAC,OAAO;EAAS,SAAS;EAAE,CAAC;CAE1D,QAAQ,Y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Define<"uuid", false, false>;
8
8
  label: imodel1.FieldDefine<"string", false, false>;
9
9
  dbId: imodel1.FieldDefine<"string", false, false>;
10
- type: imodel1.FieldDefine<"string", false, true>;
10
+ type: imodel1.FieldDefine<"string", false, false>;
11
11
  tables: imodel1.FieldDefine<_yongdall_model0.ModelTable<{
12
12
  sceneId: imodel1.FieldDefine<"uuid", false, false>;
13
13
  model: imodel1.FieldDefine<"string", false, false>;
package/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
- import { n as Scene_default, t as loadSceneTable } from "./loadScene-C7txwTmV.mjs";
1
+ import { t as Scene_default } from "./Scene-B_dHIwLD.mjs";
2
+ import { t as loadSceneTable } from "./loadScene-Bv4NEas2.mjs";
2
3
 
3
4
  export { Scene_default as Scene, loadSceneTable };
@@ -1,86 +1,13 @@
1
- import { Query, Scene, createField, createModel, uuid } from "@yongdall/model";
1
+ import { t as Scene_default } from "./Scene-B_dHIwLD.mjs";
2
+ import { Query, Scene } from "@yongdall/model";
2
3
  import { useDatabase } from "@yongdall/connection";
3
4
  import { hooks } from "@yongdall/core";
5
+ import { loadPluginProfiles } from "@yongdall/plugins";
6
+ import { LazyPromise } from "@yongdall/common";
4
7
 
5
- //#region plugins/scene/models/Scene.mjs
6
- const SceneField = createModel("scene.field", {
7
- sceneId: createField("uuid", {
8
- nullable: false,
9
- label: "ID",
10
- primary: 1,
11
- layout: { hidden: true }
12
- }),
13
- model: createField("string", {
14
- label: "model",
15
- primary: 2
16
- }),
17
- column: createField("string", { label: "Table Field" }),
18
- field: createField("string", {
19
- label: "Field",
20
- primary: 3
21
- }),
22
- fixedValue: createField("json", { label: "固定值" }),
23
- no: createField("i32")
24
- });
25
- const SceneTable = createModel("scene.table", {
26
- sceneId: createField("uuid", {
27
- nullable: false,
28
- label: "ID",
29
- primary: 1,
30
- layout: { hidden: true }
31
- }),
32
- model: createField("string", {
33
- label: "Model",
34
- primary: 2
35
- }),
36
- table: createField("string", { label: "Table" }),
37
- no: createField("i32"),
38
- fields: createField(SceneField, {
39
- array: true,
40
- constraints: {
41
- sceneId: { field: "sceneId" },
42
- model: { field: "model" },
43
- no: { noField: true }
44
- },
45
- label: "Fields"
46
- })
47
- });
48
- var Scene_default = createModel("scene", {
49
- id: createField("uuid", {
50
- nullable: false,
51
- default: uuid,
52
- label: "ID",
53
- primary: 1,
54
- layout: { hidden: true }
55
- }),
56
- label: createField("string", {
57
- nullable: false,
58
- default: "",
59
- label: "Label"
60
- }),
61
- dbId: createField("string", {
62
- nullable: false,
63
- default: "",
64
- label: "Database"
65
- }),
66
- type: createField("string", {
67
- nullable: true,
68
- label: "Type"
69
- }),
70
- tables: createField(SceneTable, {
71
- array: true,
72
- constraints: {
73
- sceneId: { field: "id" },
74
- no: { noField: true }
75
- },
76
- label: "tables"
77
- })
78
- });
79
-
80
- //#endregion
81
8
  //#region plugins/scene/loadScene.mjs
82
- /** @import { Fields } from '@yongdall/model' */
83
- /** @import {SceneType} from './types.mjs' */
9
+ /** @import { Fields, TableValue } from '@yongdall/model' */
10
+ /** @import { SceneType } from './types.mjs' */
84
11
  /**
85
12
  *
86
13
  * @param {Fields} fields
@@ -139,25 +66,42 @@ function toScene({ models, ...define }) {
139
66
  tables
140
67
  };
141
68
  }
142
- /** @type {Record<string, SceneType>} */
69
+ /** @deprecated @type {Record<string, SceneType>} */
143
70
  let scenes = Object.create(null);
144
71
  hooks.listen(() => {
145
72
  scenes = Object.assign(Object.create(null), Object.entries([...hooks.get("scenes").entriesObject()].map(([plugin, k, v]) => [`${plugin}:${k}`, toScene(v)])));
146
73
  }, -1e6);
74
+ const scenePromise = LazyPromise.try(async function() {
75
+ const scenes = await Array.fromAsync(loadPluginProfiles("scene", function* (v, plugin) {
76
+ yield* v ? Object.entries(v).map(([k, v]) => [`${plugin}:${k}`, v]) : [];
77
+ }));
78
+ return Object.fromEntries(scenes);
79
+ });
80
+ /**
81
+ *
82
+ * @param {string} type
83
+ */
84
+ async function findScene(type) {
85
+ const allScenes = await scenePromise;
86
+ if (Object.hasOwn(allScenes, type)) return allScenes[type];
87
+ return Object.hasOwn(allScenes, type) ? allScenes[type] : scenes[type];
88
+ }
147
89
  /**
148
90
  *
149
91
  * @param {string} id
150
92
  * @param {string} table
151
93
  */
152
94
  async function loadSceneTable(id, table) {
153
- /** @type {SceneModel} */
95
+ /** @type {TableValue<SceneModel>} */
154
96
  const sceneDefine = await useDatabase().first(new Query(Scene_default).primary(id));
155
97
  if (!sceneDefine) return;
156
- const sceneModel = scenes[sceneDefine.type].models[table];
98
+ const type = await findScene(sceneDefine.type);
99
+ if (!type) return;
100
+ const sceneModel = type.models[table];
157
101
  if (!sceneModel || typeof sceneModel.table !== "string") return;
158
102
  return new Scene(new Map(sceneDefine.tables.map((t) => [t.table, t]))).table(sceneModel);
159
103
  }
160
104
 
161
105
  //#endregion
162
- export { Scene_default as n, loadSceneTable as t };
163
- //# sourceMappingURL=loadScene-C7txwTmV.mjs.map
106
+ export { loadSceneTable as t };
107
+ //# sourceMappingURL=loadScene-Bv4NEas2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadScene-Bv4NEas2.mjs","names":["SceneModel"],"sources":["../../plugins/scene/loadScene.mjs"],"sourcesContent":["/** @import { Fields, TableValue } from '@yongdall/model' */\n/** @import { SceneType } from './types.mjs' */\nimport { useDatabase } from '@yongdall/connection';\nimport { hooks } from '@yongdall/core';\nimport { Query, Scene } from '@yongdall/model';\nimport { loadPluginProfiles } from '@yongdall/plugins';\nimport SceneModel from './models/Scene.mjs';\nimport { LazyPromise } from '@yongdall/common';\n\n/**\n *\n * @param {Fields} fields\n * @returns {Record<string, SceneType.Field>}\n */\nfunction toColumns(fields) {\n\t/** @type {Record<string, SceneType.Field>} */\n\tconst columns = Object.create(null);\n\tfor (const [k, v] of Object.entries(fields)) {\n\t\tconst {type, array, nullable, primary} = v;\n\t\tif (!type) { continue; }\n\t\tconst column = v.column || k;\n\t\tif (typeof type === 'string') {\n\t\t\tcolumns[column] = {type, array: array ? 1 : 0, nullable, primary};\n\t\t\tcontinue;\n\t\t}\n\t\tif (!type.table) {\n\t\t\tcolumns[column] = {type: 'object', array: array ? 1 : 0, nullable, primary: 0};\n\t\t\tcontinue;\n\t\t}\n\t}\n\treturn columns;\n}\n\n/**\n * \n * @param {SceneType.Define} define \n * @returns {SceneType}\n */\nfunction toScene({models, ...define}) {\n\tconst tables = Object.create(null);\n\tconst list = Object.values(models);\n\tfor (let model = list.pop(); model; model = list.pop()) {\n\t\tconst table = model.table;\n\t\tif (typeof table !== 'string') { continue; }\n\t\tif (table in tables) { continue; }\n\t\tconst fields = toColumns(model.fields)\n\t\ttables[table] = {fields};\n\t\tfor (const {type} of Object.values(model.fields)) {\n\t\t\tif (!type) { continue; }\n\t\t\tif (typeof type === 'string') { continue; }\n\t\t\tlist.push(type);\n\t\t}\n\t}\n\n\treturn {\n\t\t...define,\n\t\tmodels: Object.assign(Object.create(null), models),\n\t\ttables,\n\t}\n}\n/** @deprecated @type {Record<string, SceneType>} */\nexport let scenes = Object.create(null);\nhooks.listen(() => {\n\tscenes = Object.assign(\n\t\tObject.create(null),\n\t\tObject.entries([...hooks.get('scenes').entriesObject()]\n\t\t\t.map(([plugin, k, v]) => [`${plugin}:${k}`, toScene(v)])),\n\t);\n}, -1000000);\n\nconst scenePromise = LazyPromise.try(async function () {\n\tconst scenes = await Array.fromAsync(loadPluginProfiles('scene', function *(/** @type {Record<string, SceneType>}*/v, plugin) {\n\t\tyield* v ? Object.entries(v).map(([k, v]) => /** @type {[string, SceneType]} */([`${plugin}:${k}`, v])) : [];\n\t}));\n\treturn Object.fromEntries(scenes);\n});\n/**\n * \n * @param {string} id \n */\nexport default async function loadScene(id) {\n\t/** @type {TableValue<SceneModel>} */\n\tconst sceneDefine = await useDatabase().first(new Query(SceneModel).primary(id));\n\t// TODO: 缓存 sceneDefine\n\tif (!sceneDefine) { return; }\n\tconst scene = new Scene(new Map(sceneDefine.tables.map(t => [t.table, t])));\n\treturn scene\n}\n/**\n * \n * @param {string} type \n */\nasync function findScene(type) {\n\tconst allScenes = await scenePromise;\n\tif (Object.hasOwn(allScenes, type)) { return allScenes[type]; }\n\treturn Object.hasOwn(allScenes, type) ? allScenes[type] : scenes[type];\n}\n/**\n * \n * @param {string} id \n * @param {string} table \n */\nexport async function loadSceneTable(id, table) {\n\t/** @type {TableValue<SceneModel>} */\n\tconst sceneDefine = await useDatabase().first(new Query(SceneModel).primary(id));\n\t// TODO: 缓存 sceneDefine\n\tif (!sceneDefine) { return; }\n\tconst type = await findScene(sceneDefine.type);\n\tif (!type) { return; }\n\tconst sceneModel = type.models[table];\n\tif (!sceneModel || typeof sceneModel.table !== 'string') { return }\n\tconst scene = new Scene(new Map(sceneDefine.tables.map(t => [t.table, t])));\n\t// @ts-ignore\n\treturn scene.table(sceneModel);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAS,UAAU,QAAQ;;CAE1B,MAAM,UAAU,OAAO,OAAO,KAAK;AACnC,MAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,OAAO,EAAE;EAC5C,MAAM,EAAC,MAAM,OAAO,UAAU,YAAW;AACzC,MAAI,CAAC,KAAQ;EACb,MAAM,SAAS,EAAE,UAAU;AAC3B,MAAI,OAAO,SAAS,UAAU;AAC7B,WAAQ,UAAU;IAAC;IAAM,OAAO,QAAQ,IAAI;IAAG;IAAU;IAAQ;AACjE;;AAED,MAAI,CAAC,KAAK,OAAO;AAChB,WAAQ,UAAU;IAAC,MAAM;IAAU,OAAO,QAAQ,IAAI;IAAG;IAAU,SAAS;IAAE;AAC9E;;;AAGF,QAAO;;;;;;;AAQR,SAAS,QAAQ,EAAC,QAAQ,GAAG,UAAS;CACrC,MAAM,SAAS,OAAO,OAAO,KAAK;CAClC,MAAM,OAAO,OAAO,OAAO,OAAO;AAClC,MAAK,IAAI,QAAQ,KAAK,KAAK,EAAE,OAAO,QAAQ,KAAK,KAAK,EAAE;EACvD,MAAM,QAAQ,MAAM;AACpB,MAAI,OAAO,UA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AU,YAAY,KAAK;AAC9C,KAAI,CAAC,KAAQ;CACb,MAAM,aAAa,KAAK,OAAO;AAC/B,KAAI,CAAC,cAAc,OAAO,WAAW,UAAU,SAAY;AAG3D,QAFc,IAAI,MAAM,IAAI,IAAI,YAAY,OAAO,KAAI,MAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAE9D,MAAM,WAAW"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yongdall/scene",
3
- "version": "0.4.0",
3
+ "version": "0.5.2",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "type": "module",
@@ -8,9 +8,14 @@
8
8
  "author": "",
9
9
  "license": "ISC",
10
10
  "dependencies": {
11
- "@yongdall/connection": "^0.4.0",
12
- "@yongdall/model": "^0.4.0",
13
- "@yongdall/core": "^0.4.0"
11
+ "@yongdall/common": "^0.5.0",
12
+ "@yongdall/connection": "^0.5.0",
13
+ "@yongdall/core": "^0.5.0",
14
+ "@yongdall/model": "^0.5.0",
15
+ "@yongdall/plugins": "^0.5.0"
16
+ },
17
+ "devDependencies": {
18
+ "@yongdall/migrate": "^0.5.0"
14
19
  },
15
20
  "exports": {
16
21
  ".": "./index.mjs"
@@ -0,0 +1,10 @@
1
+ import { t as Scene_default } from "../Scene-B_dHIwLD.mjs";
2
+
3
+ //#region plugins/scene/yongdall/migration.mjs
4
+ /** @import { Profile } from '@yongdall/migrate' */
5
+ /** @type {Profile['models']} */
6
+ const models = [Scene_default];
7
+
8
+ //#endregion
9
+ export { models };
10
+ //# sourceMappingURL=migration.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.mjs","names":["Scene"],"sources":["../../../plugins/scene/yongdall/migration.mjs"],"sourcesContent":["/** @import { Profile } from '@yongdall/migrate' */\nimport Scene from '../models/Scene.mjs';\n\n\n/** @type {Profile['models']} */\nexport const models = [\n\tScene\n]\n"],"mappings":";;;;;AAKA,MAAa,SAAS,CACrBA,cACA"}
@@ -0,0 +1,16 @@
1
+ import { t as Scene_default } from "../Scene-B_dHIwLD.mjs";
2
+ import { t as loadSceneTable } from "../loadScene-Bv4NEas2.mjs";
3
+
4
+ //#region plugins/scene/yongdall/model.mjs
5
+ /** @import { ModelProfile } from '@yongdall/core' */
6
+ /** @type {ModelProfile['models']} */
7
+ const models = { scene: Scene_default };
8
+ /** @type {ModelProfile['modelLoaders']} */
9
+ const modelLoaders = { async scene([sceneId, table, ...other]) {
10
+ if (!table || other.length) return null;
11
+ return await loadSceneTable(sceneId, table);
12
+ } };
13
+
14
+ //#endregion
15
+ export { modelLoaders, models };
16
+ //# sourceMappingURL=model.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.mjs","names":["Scene"],"sources":["../../../plugins/scene/yongdall/model.mjs"],"sourcesContent":["/** @import { ModelProfile } from '@yongdall/core' */\nimport { loadSceneTable } from '../loadScene.mjs';\nimport Scene from '../models/Scene.mjs';\n\n/** @type {ModelProfile['models']} */\nexport const models = {\n\tscene: Scene,\n};\n\n/** @type {ModelProfile['modelLoaders']} */\nexport const modelLoaders = {\n\t/** @param {string[]} collection */\n\tasync scene([sceneId, table, ...other]) {\n\t\tif (!table || other.length) { return null }\n\t\treturn await loadSceneTable(sceneId, table);\n\t}\n}\n"],"mappings":";;;;;;AAKA,MAAa,SAAS,EACrB,OAAOA,eACP;;AAGD,MAAa,eAAe,EAE3B,MAAM,MAAM,CAAC,SAAS,OAAO,GAAG,QAAQ;AACvC,KAAI,CAAC,SAAS,MAAM,OAAU,QAAO;AACrC,QAAO,MAAM,eAAe,SAAS,MAAM;GAE5C"}
@@ -0,0 +1 @@
1
+ label: 场景支持
@@ -1,16 +0,0 @@
1
- import { n as Scene_default, t as loadSceneTable } from "./loadScene-C7txwTmV.mjs";
2
-
3
- //#region plugins/scene/hooks.yongdall.mjs
4
- /** @import { Hooks } from '@yongdall/core' */
5
- const models = { scene: Scene_default };
6
- /** @type {Hooks.Define['migrationModels']} */
7
- const migrationModels = [Scene_default];
8
- /** @type {Hooks.Define['modelLoaders']} */
9
- const modelLoaders = { async scene([sceneId, table, ...other]) {
10
- if (!table || other.length) return null;
11
- return await loadSceneTable(sceneId, table);
12
- } };
13
-
14
- //#endregion
15
- export { migrationModels, modelLoaders, models };
16
- //# sourceMappingURL=hooks.yongdall.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hooks.yongdall.mjs","names":["Scene"],"sources":["../../plugins/scene/hooks.yongdall.mjs"],"sourcesContent":["import { loadSceneTable } from './loadScene.mjs';\nimport Scene from './models/Scene.mjs';\n/** @import { Hooks } from '@yongdall/core' */\n\nexport const models = {\n\tscene: Scene,\n};\n\n/** @type {Hooks.Define['migrationModels']} */\nexport const migrationModels = [\n\tScene\n]\n\n/** @type {Hooks.Define['modelLoaders']} */\nexport const modelLoaders = {\n\t/** @param {string[]} collection */\n\tasync scene([sceneId, table, ...other]) {\n\t\tif (!table || other.length) { return null }\n\t\treturn await loadSceneTable(sceneId, table);\n\t}\n}\n"],"mappings":";;;;AAIA,MAAa,SAAS,EACrB,OAAOA,eACP;;AAGD,MAAa,kBAAkB,CAC9BA,cACA;;AAGD,MAAa,eAAe,EAE3B,MAAM,MAAM,CAAC,SAAS,OAAO,GAAG,QAAQ;AACvC,KAAI,CAAC,SAAS,MAAM,OAAU,QAAO;AACrC,QAAO,MAAM,eAAe,SAAS,MAAM;GAE5C"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"loadScene-C7txwTmV.mjs","names":["SceneModel"],"sources":["../../plugins/scene/models/Scene.mjs","../../plugins/scene/loadScene.mjs"],"sourcesContent":["import { createField, createModel, uuid } from '@yongdall/model';\n\nconst SceneField = createModel('scene.field', {\n\tsceneId: createField('uuid', { nullable: false, label: 'ID', primary: 1, layout: {hidden: true} }),\n\tmodel: createField('string', {label: 'model', primary: 2}),\n\n\tcolumn: createField('string', { label: 'Table Field'}),\n\n\tfield: createField('string', { label: 'Field', primary: 3}),\n\tfixedValue: createField('json', { label: '固定值'}),\n\n\tno: createField('i32'),\n\n\t// TODO: 类型、样式、渲染\n});\n\nconst SceneTable = createModel('scene.table', {\n\tsceneId: createField('uuid', { nullable: false, label: 'ID', primary: 1, layout: {hidden: true} }),\n\tmodel: createField('string', {label: 'Model', primary: 2}),\n\t\n\ttable: createField('string', {label: 'Table'}),\n\tno: createField('i32'),\n\tfields: createField(SceneField, { array: true, constraints: {sceneId: {field: 'sceneId'}, model: {field: 'model'}, no: {noField: true}}, label: 'Fields' }),\n});\n\nexport default createModel('scene', {\n\tid: createField('uuid', { nullable: false, default: uuid, label: 'ID', primary: 1, layout: {hidden: true} }),\n\n\tlabel: createField('string', { nullable: false, default: '', label: 'Label' }),\n\n\tdbId: createField('string', { nullable: false, default: '', label: 'Database' }),\n\ttype: createField('string', { nullable: true, label: 'Type' }),\n\ttables: createField(SceneTable, { array: true, constraints: {sceneId: {field: 'id'}, no: {noField: true}}, label: 'tables' }),\n});\n","/** @import { Fields } from '@yongdall/model' */\n/** @import {SceneType} from './types.mjs' */\nimport SceneModel from './models/Scene.mjs';\nimport { useDatabase } from '@yongdall/connection';\nimport { hooks } from '@yongdall/core';\nimport { Query, Scene } from '@yongdall/model';\n\n/**\n *\n * @param {Fields} fields\n * @returns {Record<string, SceneType.Field>}\n */\nfunction toColumns(fields) {\n\t/** @type {Record<string, SceneType.Field>} */\n\tconst columns = Object.create(null);\n\tfor (const [k, v] of Object.entries(fields)) {\n\t\tconst {type, array, nullable, primary} = v;\n\t\tif (!type) { continue; }\n\t\tconst column = v.column || k;\n\t\tif (typeof type === 'string') {\n\t\t\tcolumns[column] = {type, array: array ? 1 : 0, nullable, primary};\n\t\t\tcontinue;\n\t\t}\n\t\tif (!type.table) {\n\t\t\tcolumns[column] = {type: 'object', array: array ? 1 : 0, nullable, primary: 0};\n\t\t\tcontinue;\n\t\t}\n\t}\n\treturn columns;\n}\n\n/**\n * \n * @param {SceneType.Define} define \n * @returns {SceneType}\n */\nfunction toScene({models, ...define}) {\n\tconst tables = Object.create(null);\n\tconst list = Object.values(models);\n\tfor (let model = list.pop(); model; model = list.pop()) {\n\t\tconst table = model.table;\n\t\tif (typeof table !== 'string') { continue; }\n\t\tif (table in tables) { continue; }\n\t\tconst fields = toColumns(model.fields)\n\t\ttables[table] = {fields};\n\t\tfor (const {type} of Object.values(model.fields)) {\n\t\t\tif (!type) { continue; }\n\t\t\tif (typeof type === 'string') { continue; }\n\t\t\tlist.push(type);\n\t\t}\n\t}\n\n\treturn {\n\t\t...define,\n\t\tmodels: Object.assign(Object.create(null), models),\n\t\ttables,\n\t}\n}\n/** @type {Record<string, SceneType>} */\nexport let scenes = Object.create(null);\nhooks.listen(() => {\n\tscenes = Object.assign(\n\t\tObject.create(null),\n\t\tObject.entries([...hooks.get('scenes').entriesObject()]\n\t\t\t.map(([plugin, k, v]) => [`${plugin}:${k}`, toScene(v)])),\n\t);\n}, -1000000);\n\n/**\n * \n * @param {string} id \n */\nexport default async function loadScene(id) {\n\t/** @type {SceneModel} */\n\tconst sceneDefine = await useDatabase().first(new Query(SceneModel).primary(id));\n\t// TODO: 缓存 sceneDefine\n\tif (!sceneDefine) { return; }\n\tconst scene = new Scene(new Map(sceneDefine.tables.map(t => [t.table, t])));\n\treturn scene\n}\n\n/**\n * \n * @param {string} id \n * @param {string} table \n */\nexport async function loadSceneTable(id, table) {\n\t/** @type {SceneModel} */\n\tconst sceneDefine = await useDatabase().first(new Query(SceneModel).primary(id));\n\t// TODO: 缓存 sceneDefine\n\tif (!sceneDefine) { return; }\n\tconst type = scenes[sceneDefine.type];\n\tconst sceneModel = type.models[table];\n\tif (!sceneModel || typeof sceneModel.table !== 'string') { return }\n\tconst scene = new Scene(new Map(sceneDefine.tables.map(t => [t.table, t])));\n\t// @ts-ignore\n\treturn scene.table(sceneModel);\n}\n"],"mappings":";;;;;AAEA,MAAM,aAAa,YAAY,eAAe;CAC7C,SAAS,YAAY,QAAQ;EAAE,UAAU;EAAO,OAAO;EAAM,SAAS;EAAG,QAAQ,EAAC,QAAQ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